本文介绍了使用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 Presentationprs = Presentation("pp.pptx")# text_runs will be populated with a list of strings,# one for each text run in presentationtext_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 Presentationfilename = path_of_pptxprs = Presentation(filename)for slide in prs.slides: title = slide.shapes.title.text print(title)输入: 输出:Hello, World!Hello, World2!Hello, World3! 这篇关于使用Python获取pptx文件的幻灯片标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-19 06:17