我正在尝试使用Python获取PowerPoint文件的每张幻灯片的标题。我在Python中使用Presentation包,但找不到任何指定标题的内容。
我有这段代码可以返回PowerPoint文件的内容。但我需要指定标题。

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)

最佳答案

这是我的解决方案:

from pptx import Presentation

filename = path_of_pptx

prs = Presentation(filename)

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

输入:

python - 使用Python获取pptx文件的幻灯片标题-LMLPHP

输出:
Hello, World!
Hello, World2!
Hello, World3!

关于python - 使用Python获取pptx文件的幻灯片标题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40818692/

10-17 02:55