从 Python 打印 Powerpoint 幻灯片



我正在尝试从Powerpoint打印出一张幻灯片。我使用以下代码访问了幻灯片:

from win32com import client
powerpoint = client.Dispatch("Powerpoint.Application")
presentation = powerpoint.presentations.Open(filepath)
slide = presentation.Slides[10]
print(slide.name)  # Just to check I have in fact got the slide

打印Word文档时,我可以在文档上调用PrintOut(),但它似乎不适用于Powerpoint。

有人有任何解决方案吗?

presentation.PrintOut()

打印整个演示文稿,但我只想要一张特定的幻灯片。

好的,我想出我可以使用以下方法指定一个范围:

presentation.PrintOut(From=1, To=1)

我可以使用循环迭代幻灯片以匹配名称:

count = 1
for slide in presentation.Slides:
if slide.name == "Slide1":
presentation.PrintOut(From=count, To=count)
break
count += 1

最新更新