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

Removing hyperlinks in PowerPoint with python-pptx

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

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

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

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

然后我重新压缩并将扩展名更改为 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 文件夹中得到我的 xmls。

我就是在这里卡住了 我可以用 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