我正在尝试合并幻灯片,但我不知道该怎么做。我发现了一个看起来很有前途的 python moduel pptx。我尝试将幻灯片内容从 2 个幻灯片复制到一个新的幻灯片。但我遇到了很多问题,比如如何获取现有的幻灯片布局或形状(所有形状,包括图片、自动形状等)的高度、宽度、位置。我查看了Python-pptx上的python-pptx示例:复制幻灯片。我尝试做类似的事情,但这不起作用。
这是我的代码:
from pptx import Presentation
prs1 = Presentation("C:/Users/number/Documents/Test1.pptx")
prs2 = Presentation("C:/Users/number/Documents/Test2.pptx")
slidelst = []
for layout in prs2.slide_layouts:
slidelst.append(prs1.slides.add_slide(layout))
index = 0
for slide in slidelst:
for shape in prs2.slides[prs2.slides.index(slide)].shapes:
slide.shapes._spTree.insert_element_before(shape.element, 'p:extLst')
index+=1
prs1.save("C:/Users/I505168/Documents/newpresentation.pptx")
Run Code Online (Sandbox Code Playgroud)
我收到错误:
Traceback (most recent call last):
File "C:\Users\I505168\Desktop\testpptx.py", line 12, in <module>
for shape in prs2.slides[prs2.slides.index(slide)].shapes:
File "C:\Users\I505168\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pptx\slide.py", line 315, in index
raise ValueError("%s is not in slide collection" % slide)
ValueError: <pptx.slide.Slide object at 0x03B53A50> is not …Run Code Online (Sandbox Code Playgroud)