下面是一个脚本,它将图片插入幻灯片。我想添加超链接到图片,但它不工作。
from pptx import Presentation
import pptx.util
from pptx.util import Inches, Pt
pptfile = r"C:\Users\prashant\NEW - Copy.pptx"
fgr = "gr.png"
prs = Presentation(pptfile)
slides = prs.slides
for slide in prs.slides:
for shape in slide.shapes:
pic = slide.shapes.add_picture(fgr, pptx.util.Inches(1),
pptx.util.Inches(0.2),width=pptx.util.Inches(0.8), height=pptx.util.Inches(0.5))
pic.name = "Picture 999"
for shape in slide.shapes:
if shape.name == "Picture 999":
shape.address = 'https://github.com/scanny/python-pptx'
# shape.hyperlink.address = 'https://github.com/scanny/python-pptx' >>Gives Error
prs.save(pptfile)
print("Done!")脚本成功运行,但超链接没有添加到表示文件中的png映像中。
有什么建议吗?
发布于 2019-12-03 18:46:26
超链接是对形状的一种单击操作,而不是直接属性.因此,您需要使用shape.click_action.hyperlink代替。
shape.click_action.hyperlink.address = 'https://github.com/scanny/python-pptx'除了超链接之外,单击操作还可以提供跳转到演示文稿中另一张幻灯片的行为。这是在这里增加一个间接方向的理由,而不是让超链接直接出现在shape对象上。
https://stackoverflow.com/questions/59158206
复制相似问题