例如,我有以下列表:
titles = ['A', 'B', 'C']
现在我希望每个标题都成为每个幻灯片的标题 因此,幻灯片1 = A,幻灯片2 = B,幻灯片3 = C。
你会怎么做?
答案 0 :(得分:2)
基于official quickstart guide,下面是创建演示文稿的方法,并为列表中的每个标题添加一张幻灯片并从列表中设置其标题:
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')
或者,如果您要编辑现有的Powerpoint演示文稿,则可以按以下方式更新幻灯片标题:
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')