我的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访问到了这些子元素。 但是,我遇到了一个错误,提示它们是“property”类型,因此我无法访问文本或迭代(TypeError: 'property' object is not iterable)。
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)
我希望能够获取文本并将其附加到一个字符串中以进行进一步处理。
我的问题是,如何访问子文本元素并从中提取文本。
我已经花了很多时间阅读文档和源代码,但还没有弄清楚。任何帮助都将不胜感激。