- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的 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”对象不可迭代)。
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)
然后我想捕获文本并附加到一个字符串以供进一步处理。
所以我的问题是,如何访问子文本元素并从中提取文本。
我花了很多时间浏览文档和源代码,但一直没弄明白。任何帮助将不胜感激。
最佳答案
我想你需要这样的东西:
from pptx.enum.shapes import MSO_SHAPE_TYPE
for slide in prs.slides:
# ---only operate on group shapes---
group_shapes = [
shp for shp in slide.shapes
if shp.shape_type == MSO_SHAPE_TYPE.GROUP
]
for group_shape in group_shapes:
for shape in group_shape.shapes:
if shape.has_text_frame:
print(shape.text)
组形状包含其他形状,可在其 .shapes
属性中访问。它不本身具有.text
属性。因此,您需要迭代组中的形状并从每个形状中获取文本。
请注意,此解决方案仅深入一层。可以使用递归方法按深度优先遍历树,并从包含组的组中获取文本(如果有的话)。
另请注意,并非所有形状都有文本,因此您必须检查 .has_text_frame
属性以避免在图片形状上引发异常。
关于python - 如何使用 python-pptx 从 powerpoint 中的组形状中的文本形状中提取文本。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51701626/
关闭。这个问题是off-topic .它目前不接受答案。 想改善这个问题吗? Update the question所以它是 on-topic对于堆栈溢出。 9年前关闭。 Improve this q
通过右键单击功能区并选择“从以下位置选择命令:宏”,可以从功能区的启用宏的 PowerPoint (pptm) 演示文稿中添加宏。 我希望它随时可用,所以我将 pptm 文件保存为加载项 (ppam)
我需要在 Latex Beamer 和 Powerpoint 中维护一些幻灯片。 (这是为了向其他地方的教师提供幻灯片,其中 90% 的教师不知道如何使用 Latex,也不愿意学习它。而我是 Linu
我有一个用于 PowerPoint 的任务 Pane 加载项,它可以帮助用户处理事件演示文稿上的任务。随着 Microsoft Office 在 Windows 以外的平台上越来越流行,使用 Java
已关闭。这个问题是 off-topic 。目前不接受答案。 想要改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 已关闭10 年前。 Improve th
不知何故,我丢失了 PowerPoint 中的 Storyboard 标签。我怎样才能恢复它?谢谢。 我同时使用 PowerPoint 2010 和 PowerPoint 2013 最佳答案 我遇到了
我用 plotly 生成了一个离线交互图。 我将绘图保存为 html 文件。有谁知道我可以将交互式绘图嵌入到 MS PowerPoint 中进行演示? 非常感谢! 最佳答案 PowerPoint 本身
我正在尝试从不同来源生成演示文稿。基本上我有大约 200 张幻灯片来自一些 PowerPoint 演示文稿。为了实现这一点,我使用了 OpenXml Sdk。程序流程如下: 打开模板演示 打开新演示文
是否可以在 PowerPoint 幻灯片中添加形状(或除纯文本或图像之外的任何其他内容)? 我在上面找不到任何东西,真的希望这是可能的。我已经在 UserVoice ( https://offices
我希望在 Linux 中以自动方式将 PPT 和 PPTX 文件转换为 Flash(或 flv)文件 - 所以我需要一个命令行实用程序。 有什么可用的选择吗? (目前我还没有找到)。 我也在寻找一个
我在 PowerPoint 2010 中制作了一个模块原型(prototype)。该模块在 PowerPoint 图表上绘制了一些线条和形状。我使用了 PowerPoint.Point(系列的数据点)
在 Word 中,您可以使用 Office.context.document.customXmlParts API 来访问自定义 xml。在 Excel 中,您必须使用 Excel.run((cont
我需要能够将 PowerPoint 2003 中的演示文稿(以编程方式)保存为 OpenXML(“.pptx”)。 我安装了 Microsoft Office 兼容包。这确实允许我从 PowerPoi
我的任务是在将当前 powerpoint 保存为 WMV 后获取电影帧。以下代码作为独立应用程序运行良好,但由于“CreateVideoStatus”作为 Powerpoint 加载项运行时始终为“P
我正在尝试从移动版 Safari 链接到一个 .pptx 文件,并在 PowerPoint 中打开该文件。根据 https://www.test.com/test.pptx 上的信息,我的链接看起来像
我为 PowerPoint (2010) 写了一个小的 VBA 宏,当鼠标悬停在某个形状上时,它会打开一个带有解释的弹出窗口。这很好用。 las,再次离开该区域时没有触发任何事件,所以我现在想扩展代码
我正在寻找注入(inject)的方法PresentationML 和/或 绘图ML 使用 Open XML SDK 或只是 System.IO.Packaging 进入打开的 PowerPoint 2
我有一个可以将幻灯片导出到 PowerPoint 的应用程序。我正在使用 Microsoft.Office.Interop.PowerPoint.dll 。这是汇编的第 11 个版本。我今天运行了应用
当 Microsoft Word 关闭时,可以取消关闭事件。对于 Excel 也是如此。 但是 PowerPoint 关闭事件没有取消标志。 是否可以通过其他方式取消事件? 最佳答案 在关闭事件中,您
我有一个 Excel 宏,可以从指定位置打开 PowerPoint 文件。 PowerPoint 文件是一个模板。 我需要根据模板设计创建一个新的演示文稿。 我的代码将打开模板而不是基于该模板的新演示
我是一名优秀的程序员,十分优秀!