2

I am writing a python script using the pptx library, where I try to get the text at Title 4 box. Unfortunately python is not able to identify all the shape in the some slides, thus missing some of the shapes.

Here is my code

from pptx import Presentation
import glob

prs = Presentation('abc.pptx')
slides = prs.slides
for slide in prs.slides:
    print('\nslide number ', slides.index(slide)+1)
    for shape in slide.placeholders:
        print(shape.name)

#prs.save()

I am getting this output for slide 6

slide number  6
Chart Placeholder 8
Content Placeholder 10
Chart Placeholder 16
Chart Placeholder 12
Chart Placeholder 19

But as I can clearly see in the pptx file I have a few more elements/shapes than what the python script detects.

enter image description here

Any idea why the shapes/selection like Title 4,Textbox 6 etc is missed?

Prashant Kumar
  • 501
  • 8
  • 26
  • I don't know the library, but are all shapes considered to be "placeholders"? Looking at the documentation for the VBA powerpoint object model (which this python library seems to be a wrapper over) there is a `Shapes` collection which seems to be not the same thing as the `Placeholders` collection. – John Coleman Nov 26 '19 at 12:09
  • I'm not sure, I assumed textbox,title box and all other shapes comes under placeholders – Prashant Kumar Nov 26 '19 at 12:13
  • There is some distinction, I'm not sure what it is. Perhaps it has to do with *how* the shape was inserted and not what it is? In any event, the Python library also has a shapes collection for any slide object, so it couldn't hurt to iterate over that as an experiment. – John Coleman Nov 26 '19 at 12:18
  • Yes, Thanks for your suggestion @JohnColeman I will have a look at it. There is a very high chance I might have missed it from the documentation since I'm a newbie – Prashant Kumar Nov 26 '19 at 12:20

1 Answers1

2

Placeholders are a subset of the shapes on a slide and are contributed by the slide layout. Other shapes can be added after slide creation and placeholder shapes can be removed.

To get all shapes on a slide, use the slide.shapes property. slide.placeholders restricts that list to the placeholder shapes.

scanny
  • 26,423
  • 5
  • 54
  • 80