1
我想要使用Python获取每个幻灯片的PowerPoint演示文件的标题。我在Python中使用Presentation包,但找不到指定标题的任何内容。 我有这个代码,返回的Powerpoint文件的内容。但我需要指定标题。使用Python获得pptx文件幻灯片的标题
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)
文档建议您可以访问Shapes集合了幻灯片和检测每个形状的类型。如果它是一个Type 14,它将是一个居中的标题占位符。 –
@RadLexus试试我的解决方案 – eyllanesc
该文档专门提到它[这里](http://python-pptx.readthedocs.io/en/latest/user/placeholders-using.html#setting-the-slide-title)。这有点棘手,因为幻灯片标题形状是一个*占位符*,所以提及它是在占位符被引入之后。这也是从“幻灯片标题”搜索返回的第一个条目。 – scanny