使用Python获取pptx文件的幻灯片标题 [英] get the title of slides of pptx file using Python

查看:700
本文介绍了使用Python获取pptx文件的幻灯片标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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)


推荐答案

这是我的解决方案:

from pptx import Presentation

filename = path_of_pptx

prs = Presentation(filename)

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

输入:

< a href = https://i.stack.imgur.com/x2769.png rel = noreferrer>

输出:

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

这篇关于使用Python获取pptx文件的幻灯片标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆