gpt4 book ai didi

python - 使用 python-pptx 删除 PowerPoint 中的超链接

转载 作者:行者123 更新时间:2023-12-01 06:32:10 25 4
gpt4 key购买 nike

对 XML 和 python-pptx 模块相当陌生,我想删除每个页面上存在的单个超链接

到目前为止,我自己的尝试是检索我的文件,更改为 zip格式化并将它们解压缩到单独的文件夹中

然后我找到以下属性 <a:hlinkClick r:id="RelId4">

并删除它,同时删除 Relationship xml.rels 内的属性与此幻灯片对应的文件。

然后我重新压缩并将扩展名更改为 pptx,这会加载罚款。然后我尝试在 Python 中复制这一点,以便我可以创建持续的自动化。

我的尝试:

from pathlib import Path
import zipfile as zf
from pptx import Presentation
import re
import xml.etree.ElementTree as ET

path = 'mypath'
ppts = [files for files in Path(path).glob('*.pptx')]
for file in ppts:
file.rename(file.with_suffix('.zip'))
zip_files = ppts = [files for files in Path(path).glob('*.zip')]

for zips in zip_files:
with zf.ZipFile(zips,'r') as zip_ref:
zip_ref.extractall(Path(path).joinpath('zipFiles',zips.stem))

然后,我进行一些进一步的过滤,最终得到 rels 文件夹和 ppt/slide 文件夹中的 xml。

正是在这里,我陷入了困境,我可以使用 ElementTree 读取我的 xml。模块但我找不到要删除的相关标签?

for file in normal_xmls:
tree = (ET.parse(file).getroot())
y = tree.findall('a')
print(y)

这不会产生任何结果,我尝试使用 python-pptx 模块,但 .Action.Hyperlink除非我误解了 API,否则这似乎不是一个完整的功能。

最佳答案

要从形状中删除超链接(单击形状即可导航到某处的类型),请将超链接地址设置为None:

shape.click_action.hyperlink.address = None

关于python - 使用 python-pptx 删除 PowerPoint 中的超链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59846721/

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