I am trying to combine powerpoint slides and I am not sure how to do it. I found a python moduel pptx that looked promising. I tried copying the slide contents from 2 powerpoints to one new power point. But I ran into many issues like how to grab the existing slides layout or shape (all shapes including pictures, auto shapes, and more) height, width, position. I looked at the python-pptx example on Python-pptx: copy slide. I tried doing something similar but that isn't working.

这是我的代码:

from pptx import Presentation

prs1 = Presentation("C:/Users/I505168/Documents/Test1.pptx")

prs2 = Presentation("C:/Users/I505168/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")

我得到错误:

Traceback (most recent call last):

File "C:\Users\I505168\Desktop\testpptx.py", line 12, in

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: is not in slide collection

预期结果是将两个单独的幻灯片合并为一张幻灯片。

Logo

技术共进,成长同行——讯飞AI开发者社区

更多推荐