0

I am writing a code to find out the number of placeholders present in an existing PowerPoint presentation. But for some reason i am unable to load the side values to shape. I am missing something here. Could someone guide me?

I read the documentation and i see that most examples add a line slide=prs.slides.add_slide(prs.slide_layouts[8]) I don't want to change my existing slide layout to slide_layouts style[8].

from pptx import Presentation
from pptx.util import Inches, Pt
from pptx.util import Inches
from pptx.enum.text import MSO_ANCHOR, MSO_AUTO_SIZE
prs = Presentation('test1.pptx')
slide = prs.slide_layouts(prs)
for shape in slide.placeholders:
print('%d %s' % (shape.placeholder_format.idx, shape.name))
jrswgtr
  • 2,287
  • 8
  • 23
  • 49
CN Gokul
  • 3
  • 3

1 Answers1

1

First you need to differ between the slide layouts and the slides itself. Do you want to get the information about the layouts or the currently existing slides?

For the currently existing slides you can access the slides from the slides object. To get all placeholders for every slide this will work:

for slide in prs.slides:
    for shape in slide.placeholders:
        print('%d %d %s' % (prs.slides.index(slide), shape.placeholder_format.idx, shape.name))

If you want to get the placeholders of the layouts (from the master) you need to acces the slide_layouts object.

for slide in prs.slide_layouts:
    for shape in slide.placeholders:
        print('%d %d %s' % (prs.slide_layouts.index(slide), shape.placeholder_format.idx, shape.name))
Fideldue
  • 217
  • 1
  • 10