abandoh
abandoh

Reputation: 23

AttributeError: 'SlidePlaceholder' object has no attribute 'insert_picture'

Any help to debug? I just want to load images from a folder, put them in the placeholders and save the pptx under a new name.

I am getting this error from my code:

AttributeError: 'SlidePlaceholder' object has no attribute 'insert_picture'

import pptx
import pptx.util
import glob
import scipy.misc
       
prs_exists = pptx.Presentation("NEW_SITE_SSVT_REPORT_PYTHON.pptx")
src = "C:\\Work\\Test\\*.*"
    
files = glob.glob(src)
index = 0
for slide in prs_exists.slides:
    for pHolder in slide.shapes: #placeholders:
        if pHolder.is_placeholder:
            pHolder.insert_picture(files[index])
            index = index + 1
prs_exists.save("test.pptx")```

Upvotes: 2

Views: 5422

Answers (1)

scanny
scanny

Reputation: 28883

Only a picture-placeholder has the .insert_picture() method. In particular, the common "object" placeholder, the generic one that is most common as the body placeholder, does not have this method. So you will have to change the target placeholders in the appropriate slide-layout(s) of NEW_SITE_SSVT_REPORT_PYTHON.pptx to be picture placeholders. This is readily accomplished by hand, using PowerPoint.

Upvotes: 2

Related Questions