【发布时间】:2019-01-13 01:25:00
【问题描述】:
我的 PowerPoint 幻灯片有许多组形状,其中有子文本形状。
之前我使用过这段代码,但它不能处理组形状。
for eachfile in files:
prs = Presentation(eachfile)
textrun=[]
for slide in prs.slides:
for shape in slide.shapes:
if hasattr(shape, "text"):
print(shape.text)
textrun.append(shape.text)
new_list=" ".join(textrun)
text_list.append(new_list)
我正在尝试从这些子文本框中提取文本。我已经设法使用 GroupShape.shape 到达这些子元素 但我得到一个错误,这些是“属性”类型的,所以我无法访问文本或迭代它们(TypeError:“属性”对象不可迭代)。
from pptx.shapes.group import GroupShape
from pptx import Presentation
for eachfile in files:
prs = Presentation(eachfile)
textrun=[]
for slide in prs.slides:
for shape in slide.shapes:
for text in GroupShape.shapes:
print(text)
然后我想捕获文本并附加到字符串以进行进一步处理。
所以我的问题是,如何访问子文本元素并从中提取文本。
我花了很多时间查看文档和源代码,但一直无法弄清楚。任何帮助将不胜感激。
【问题讨论】:
标签: python text powerpoint python-pptx