Mor*_*nis 6 python powerpoint python-pptx
我有一个包含 20 张幻灯片的现有 PowerPoint 演示文稿。此演示文稿用作模板,每张幻灯片都有不同的背景。我想使用这个(现有的)PowerPoint 演示文稿,在第 4 张幻灯片中插入一个图像(前 3 个不做任何处理)并将其另存为新的 PowerPoint 演示文稿。
这就是我到目前为止所拥有的。此代码加载现有演示文稿并将其另存为新演示文稿。现在我只需要知道如何使用它像上面描述的那样将图像插入第 4 号幻灯片。
注意:我使用的是普通的 Python。
from pptx import Presentation
def open_PowerPoint_Presentation(oldFileName, newFileName):
prs = Presentation(oldFileName)
#Here I guess I need to type something to complete the task.
prs.save(newFileName)
open_PowerPoint_Presentation('Template.pptx', 'NewTemplate.pptx')
Run Code Online (Sandbox Code Playgroud)
我对这个模块不是很熟悉,但我看了他们的快速入门
from pptx.util import Inches
from pptx import Presentation
def open_PowerPoint_Presentation(oldFileName, newFileName, img, left, top):
prs = Presentation(oldFileName)
slide = prs.slides[3]
pic = slide.shapes.add_picture(img, left, top)
prs.save(newFileName)
open_PowerPoint_Presentation('Template.pptx', 'NewTemplate.pptx',
'mypic.png', Inches(1), Inches(1))
Run Code Online (Sandbox Code Playgroud)