gpt4 book ai didi

python - 在 python-pptx 中复制自由格式对象

转载 作者:行者123 更新时间:2023-12-01 08:57:03 24 4
gpt4 key购买 nike

我在模板幻灯片中有一个自由形式的对象,我想复制该对象并从中创建多个对象。

我在文档中找不到从预先存在的形状创建形状的方法。我是找错地方了还是这个功能不存在?

最佳答案

python-pptx API 不支持此操作,但您也许可以使用一些内部功能来完成此结果

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)

这些都将直接堆叠在原始位置的顶部,因此您可能需要添加一些以将它们移动到新位置。此外,如果现有的自由格式参与超链接(无论是其本身是链接还是其中包含的文本具有超链接),您可能会遇到麻烦。

关于python - 在 python-pptx 中复制自由格式对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52728142/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com