I am looking for code to extract only the titles from every power point slides. Is there any python function available. Any help is appreciated.
Asked
Active
Viewed 2,630 times
2
-
1Possible duplicate of [get the title of slides of pptx file using Python](https://stackoverflow.com/questions/40818692/get-the-title-of-slides-of-pptx-file-using-python) – YusufUMS Jul 05 '19 at 05:16
2 Answers
4
Not by Computer vision (this would be more complicated)
But using some libraries it is possible:
from pptx import Presentation
filename = "test.pptx" #your ppt filename
prs = Presentation(filename)
for slide in prs.slides:
title = slide.shapes.title.text
print(title)
Source: How to read PPT titles
Don't forget to install the library:
pip install python-pptx

pedro_bb7
- 1,601
- 3
- 12
- 28
-
it's showing this error: title = slide.shapes.title.text AttributeError: 'NoneType' object has no attribute 'text' – Ankit Kumar Jul 05 '19 at 05:10
-
File was not found probably, you have to save ppt in the same directory of python file – pedro_bb7 Jul 05 '19 at 05:50
-
file is found. i am printing the prs and the object is available there. – Ankit Kumar Jul 05 '19 at 06:31
-
-
check if you can find the file by: import os, then print(os.listdir()) that is your working directory. – pedro_bb7 Jul 05 '19 at 06:41
-
ptx.exc.PackageNotFoundError: Package not found at 'Inv.pptx' i am getting this error now – Ankit Kumar Jul 05 '19 at 08:43
-
-
i have that installed ..by removing 'text' from title.text i am getting 'none' as output – Ankit Kumar Jul 05 '19 at 09:41
-
for slide in prs.slides: for shape in slide.shapes: # print(slide.shapes.text) title = shape.text.title print(title) – Ankit Kumar Jul 05 '19 at 09:42
-
-
2Not all slides have a title placeholder. In this case, `slide.shapes.title` returns `None`. You need a guard in there like perhaps `if slide.shapes.title is None: continue`. – scanny Jul 05 '19 at 18:38
-1
in previous versions there was a function like this buitl-in. But it has been abandoned.
But if you right click in the Outline view you can choose collapse all, which will give you only the highest level. Then you can copy paste, the slide number of course will not be there, but if you paste to Word every title will be a paragraph so applying a number should do it

Jamal
- 1