Reda
Reda

Reputation: 497

Select slides from PowerPoint presentation using Python

To print specific slides from a PowerPoint presentation, based on a list of items we use the basic PowerPoint tool Ctrl+F following this process:
-save the slide ID
-save the second slide ID
-print with those IDs and that takes a lot of workloads.

We think to automate this task with a Python script.

from pptx import Presentation

filename = "C:/Users/RElKassah/Desktop/test.pptx"

prs = Presentation(filename)
text="test"
for slide in prs.slides:
    if slide.shapes ==text:    
        title = slide.shapes.text.find = 'test'
        print(title)

Upvotes: 0

Views: 1245

Answers (1)

Ricky
Ricky

Reputation: 53

Here I wrote some simple loop to find text inside a pptx file, then print slide number of slides that contain that text. Hope it could help.

from pptx import Presentation

filename = 'test.pptx'

prs = Presentation(filename)
text="test"
for slide in prs.slides:
    for shape in slide.shapes:
        if shape.has_text_frame:
            for paragraph in shape.text_frame.paragraphs:
                for run in paragraph.runs:
                    if text in run.text:
                        print(prs.slides.index(slide)+1)

Upvotes: 1

Related Questions