get the title of slides of pptx file using Python

萝らか妹 提交于 2019-12-12 12:58:10

问题


I am trying to get the title of each slide of a powerpoint file using Python. I am using Presentation package in Python but I couldn't find anything that specifies the titles. I have this code that return the content of the powerpoint file. but I need to specify the titles.

from pptx import Presentation

prs = Presentation("pp.pptx")

# text_runs will be populated with a list of strings,
# one for each text run in presentation
text_runs = []

for slide in prs.slides:
    for shape in slide.shapes:
        if not shape.has_text_frame:
            continue
        for paragraph in shape.text_frame.paragraphs:
            for run in paragraph.runs:
                text_runs.append(run.text)

回答1:


This is my Solution:

from pptx import Presentation

filename = path_of_pptx

prs = Presentation(filename)

for slide in prs.slides:
    title = slide.shapes.title.text
    print(title)

Input:

Output:

Hello, World!
Hello, World2!
Hello, World3!


来源:https://stackoverflow.com/questions/40818692/get-the-title-of-slides-of-pptx-file-using-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!