I try to copy a shape from one slide from a PPTX to another slide on another PPTX using the following code:
from pptx import Presentation
from pptx.dml.color import RGBColor
import os
import sys
if __name__ == '__main__':
path = os.path.abspath(os.path.dirname(sys.argv[0]))
fn = os.path.join(path, "templ2.pptx")
shapesPPT = Presentation(fn)
shapesIcons = shapesPPT.slides[0].shapes
fn = os.path.join(path, "templ.pptx")
ppt = Presentation(fn)
for slide in ppt.slides:
for shapeIDX, shape in enumerate(slide.shapes):
if shapeIDX == 7:
wColor = RGBColor(102, 255, 102)
# ppt.slides[0].shapes[7].fill.fore_color.rgb = wColor
ppt.slides[0].shapes[7] = shapesIcons[15]
fnPPT = os.path.join(path, "OUTPUT", f"output.pptx")
ppt.save(fnPPT)
But with that i only get this error:
(pptx) C:DEVFiverrTRYuserlutionsgmbh>python test.py
Traceback (most recent call last):
File "C:DEVFiverrTRYuserlutionsgmbhtest.py", line 22, in <module>
ppt.slides[0].shapes[7] = shapesIcons[15]
TypeError: 'SlideShapes' object does not support item assignment
When I try to change the fill color (see the commented line above) it works fine. But I want to copy a complete shape from on slide/pptx to another.
How can I do that?