从 PPTx 文件中提取演示者注释 (powerpoint)

Rav*_*ven 2 php python powerpoint python-pptx

python 或 php 中是否有解决方案可以让我从 Power Point 文件中的每张幻灯片中获取演示者注释?

谢谢

小智 6

您可以使用python-pptx

pip install python-pptx

您可以执行以下操作来提取演示者注释:

import collections 
import collections.abc
from pptx import Presentation

file = 'path/to/presentation.pptx'

ppt=Presentation(file)

notes = []

for page, slide in enumerate(ppt.slides):
    # this is the notes that doesn't appear on the ppt slide,
    # but really the 'presenter' note. 
    textNote = slide.notes_slide.notes_text_frame.text
    notes.append((page,textNote)) 

print(notes)

Run Code Online (Sandbox Code Playgroud)

notes列表将包含不同页面上的所有注释。

如果你想提取幻灯片上的文本内容,你需要这样做:

for page, slide in enumerate(ppt.slides):
    temp = []
    for shape in slide.shapes:
        # this will extract all text in text boxes on the slide.
        if shape.has_text_frame and shape.text.strip():
            temp.append(shape.text)
    notes.append((page,temp))
Run Code Online (Sandbox Code Playgroud)

  • 干得好@fusion!:) 请注意,`Shape` 有一个“.has_text_frame”属性,您可以使用它来代替 `hasattr(shape, "text")`。 (2认同)