2

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")```
riQQ
  • 9,878
  • 7
  • 49
  • 66
abandoh
  • 23
  • 1
  • 3

1 Answers1

2

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.

scanny
  • 26,423
  • 5
  • 54
  • 80
  • Thanks Scanny. I have done that. How do change the Placeholder reference to picture – abandoh Nov 19 '20 at 18:31
  • 1
    Welcome to StackOverflow @abandoh. Don't neglect to accept an answer that resolves your question. That's how you say thank-you to the respondent and build your SO identity-rating. In PowerPoint, the placeholder type is a choice on the Insert Placeholder menu. I don't think you can convert a placeholder to a different type; you have to delete the old one and add the new one. – scanny Nov 19 '20 at 18:35
  • I went through the code again. I modified the code to check if the placeholder is of type picture – abandoh Nov 20 '20 at 13:04