python - 在 python-pptx 中复制一个自由形式的对象
问题描述
我在模板幻灯片中有一个自由形式的对象,我想复制并制作多个对象。
我在文档中找不到从预先存在的形状创建形状的方法。我是在找错地方还是该功能不存在?
解决方案
API 不支持此python-pptx
操作,但您可以使用一些内部函数来完成此结果
from copy import deepcopy
# ---get the existing freeform shape however you do---
freeform = slide.shapes[n]
# ---get the underlying XML element for that shape---
sp = freeform._sp
for idx in range(3):
# ---duplicate original freeform---
new_sp = deepcopy(sp)
# ---create a unique id for it---
new_sp.nvSpPr.cNvPr.id = 1000 + idx
# ---insert it after original---
sp.addnext(new_sp)
这些都将直接堆叠在原始顶部,因此您可能需要添加一些以将它们移动到新位置。此外,如果现有的自由格式参与超链接,您可能会遇到麻烦,无论是本身是链接还是它包含的具有超链接的文本。
推荐阅读
- algorithm - 基于玩家偏好的团队创建算法
- javascript - ReactJS - 如何找到 paymentId 的值并呈现它的值作为回报
- ruby-on-rails - 续集模型属性(db 列)的 instance.attribute_name 和 instance[:attribute_name] 是否完全相同?
- ios - HTTP POST 不适用于我的 ios 应用程序中的 Route 类,swift 4.1
- c# - 出现频率最高的单词图表
- python-2.7 - 使用 BS4 抓取网站数据时出错
- c++ - 删除静态向量中的唯一类对象指针
- asp.net-mvc - 编辑用户删除密码 - ASP.NET MVC
- javascript - 在Node Js中一一读取目录中的多个文件
- linux - .xinitrc 中的 startx“if 语句”不起作用