由于Python pptx,我目前正在致力于创建PowerPoint的项目。但是,我试图将图像设置为幻灯片的背景,但似乎无法在Python pptx的文档中找到解决方案。如果有人可以帮助我,可以将图像设置为背景吗?如果不是,没有人知道使用python的另一种解决方案吗?
谢谢
import os
import fnmatch
from pptx import Presentation
#Create presentation and setting layout as blank (6)
prs = Presentation()
blank_slide_layout = prs.slide_layouts[6]
#Find number of slides to create
#First Method = Count number of images in screenshot files (change path depending on the user)
nbSlide = len(fnmatch.filter(os.listdir("mypath"), '*.jpeg'))
#Loop to create as number of slides as there is report pages
for i in range(nbSlide):
slide = prs.slides.add_slide(blank_slide_layout)
#change background with an image of the slide …
background=slide.background
#Final step = Creation and saving of pptx
prs.save('test.pptx')
答案 0 :(得分:0)
是否可以将图像设置为背景...?
到目前为止,python-pptx
尚无法直接将图像插入幻灯片的背景中
如果不是,没有人知道使用python的另一种解决方案吗?
您可以考虑适当的宽度/高度参数,定期将感兴趣的图片插入给定幻灯片:
#Loop to create as number of slides as there is report pages
for i in range(nbSlide):
slide = prs.slides.add_slide(blank_slide_layout)
#change background with an image of the slide …
left = top = 0
pic = slide.shapes.add_picture('/your_file.jpeg', left-0.1*prs.slide_width, top, height = prs.slide_height)