【问题标题】:Python Insert Image into the middle of an existing PowerPointPython 将图像插入现有 PowerPoint 的中间
【发布时间】:2016-03-08 04:50:11
【问题描述】:

我有一个包含 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')

【问题讨论】:

  • Powerpoint 是来自 open office 还是 microsoft?
  • 有幻灯片编号。 4 已经是图片了?
  • 它来自微软(如果您将鼠标悬停在帖子下方的“powerpoint”标签上,您将在说明中看到微软。)
  • 然后幻灯片。 4 中没有图像。

标签: python powerpoint python-pptx


【解决方案1】:

我对这个模块不是很熟悉,但是我看了他们的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))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-13
    • 1970-01-01
    • 1970-01-01
    • 2019-01-21
    • 1970-01-01
    • 2019-06-11
    • 2016-06-21
    • 2019-08-17
    相关资源
    最近更新 更多