Python 将图像插入现有 PowerPoint 的中间
Python Insert Image into the middle of an existing PowerPoint
我有一个包含 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')
我不是很熟悉这个模块,但是我看了他们的quickstart
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))
我有一个包含 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')
我不是很熟悉这个模块,但是我看了他们的quickstart
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))