-1

So for example, I have this list:

titles =  ['A', 'B', 'C'] 

Now I want each title to be the title of each slide so slide 1 = A, slide 2 = B and slide 3 = C.

How would you do it?

snocc
  • 19
  • 4

1 Answers1

4

Based on the official quickstart guide, here's how you can create a presentation, and for each title in the list, add a slide and set its title from the list:

from pptx import Presentation

prs = Presentation()
title_slide_layout = prs.slide_layouts[0]

titles = ['A', 'B', 'C']
for slidetitle in titles:
    slide = prs.slides.add_slide(title_slide_layout)
    slide.shapes.title.text = slidetitle

prs.save('test.pptx')

Or if you want to edit an existing Powerpoint presentation, you can update the slide titles as follows:

from pptx import Presentation

prs = Presentation('test.pptx')

text_runs = []
titles = ['A', 'B', 'B']
for i,slide in enumerate(prs.slides):
    slide.shapes.title.text = titles[i]
    print(slide.shapes.title.text)

prs.save('test.pptx')
glhr
  • 4,439
  • 1
  • 15
  • 26