[英]get the title of slides of pptx file using Python
我正在嘗試使用 Python 獲取幻燈片文件的每張幻燈片的標題。 我在 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)
以@eyllanesc 的回答為基礎,正如@scanny 指出的那樣, slide.shapes.title
是一個占位符。
這意味着您可以訪問標題文本,如:
from pptx import Presentation
prs = Presentation(ppt_filename)
slide = prs.slides[0]
slide.shapes.title.text = 'New Title'
print('New Title is:')
print(slide.shapes.title.text)
並更改任何其他標題占位符屬性,例如:
slide.shapes.title.top = 100
slide.shapes.title.left = 100
slide.shapes.title.height = 200
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.