# 导入库
from pptx import Presentation
from pptx.util import Inches
ppt = Presentation() #新建幻灯片
slide = ppt.slides.add_slide(ppt.slide_layouts[1]) #插入新的幻灯片页面
‘‘‘Picture‘‘‘
# 指定图片的左右边距和高、宽
# left = Inches(1)
# top = Inches(1)
# width = Inches(2)
# height = Inches(2)
# 插入图片
# pic = slide.shapes.add_picture(C:\Users\13375\Desktop\pythonxiaohuangya.jpg‘,left,top,width,height)
# ppt.save(r‘C:\Users\13375\Desktop\python\pptcharutupian.pptx‘)
‘‘‘表格的行列位置‘‘‘
rows = 4
cols = 4
left = Inches(3)
top = Inches(3)
width = Inches(6)
height = Inches(4)
table = slide.shapes.add_table(rows,cols,left,top,width,height).table #插入表格
table.columns[0].width = Inches(1) #设置第一列的宽度为1英寸
table.columns[1].width = Inches(3) # 设置第二列的宽度为3英寸
# 向表格里写入文字
table.cell(0,0).text = ‘1‘ #指定位置写入文本
table.cell(0,1).text = ‘2‘
table.cell(1,0).text = ‘3‘
table.cell(1,1).text = ‘4‘
ppt.save(r‘C:\Users\13375\Desktop\python\tables.pptx‘)
原文:https://www.cnblogs.com/tomhu/p/12342983.html