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.
Here is my code:
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")
I get the error:
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 in slide collection
The expected result is two separate slides merge into one slide.