使用python-在ppt中插入图片
需要使用第三方库python-pptx
来操作PPT文件。可以使用以下代码来插入图片:
from pptx import Presentation
from pptx.util import Inches
# 创建PPT对象
prs = Presentation()
# 添加一页幻灯片
slide = prs.slides.add_slide(prs.slide_layouts[0])
# 插入图片
pic_path = 'path/to/picture.jpg'
pic = slide.shapes.add_picture(pic_path, left=Inches(1), top=Inches(2), width=Inches(3), height=Inches(4))
# 保存PPT文件
prs.save('example.pptx')
其中,slide.shapes.add_picture()
方法用于在当前幻灯片中插入一张图片。第一个参数为图片路径,后面的四个参数分别表示图片的左上角坐标以及图片的宽度和高度,使用Inches()
方法可以将长度转换为英寸。最后,使用prs.save()
方法保存PPT文件。

原文地址: http://www.cveoy.top/t/topic/reY 著作权归作者所有。请勿转载和采集!