python - 如何使用python将超链接添加到ppt中的图像
问题描述
下面是一段将图片插入幻灯片的脚本。我想为图片添加超链接,但它不起作用。
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 图像。
有什么建议么??
解决方案
超链接是对形状的一种单击操作,而不是直接属性。所以你需要shape.click_action.hyperlink
改用。
shape.click_action.hyperlink.address = 'https://github.com/scanny/python-pptx'
除了超链接之外,单击动作还可以提供跳转到演示文稿中另一张幻灯片的行为。这是在此处使用额外的间接级别而不是让超链接直接出现在形状对象上的基本原理。
推荐阅读
- php - 试图在和 ` 中显示来自 PHP 脚本的回显图像
目标:
1)我在网络根目录外有一个图像文件夹,其中放置了来自网络应用程序的所有图像(每个图像路径都保存在数据库表中);
2) 我想根据用户的请求获取该图像。
很简单,对吧?
我做了:
a)创建一个类来读取图像(具有我能记住的所有安全功能和保护措施)。它(成功地)返回使用相应的
- vue.js - 为什么浏览器会在路由/url 更改时显示缓存的 Vue.js 视图?
- javascript - 如何在 React/Preact 组件之间私下传递数据
- java - 正确检查用户是否登录。 Android
- python - 无法为同一服务器上的多个 mod_wsgi 应用导入 Pandas
- date - 时间和日期标准?
- html - 使用 CSS position-absolute 放置元素
- bash - BASH 测试文件名是否以 .dylib 结尾
- cypress - 寻找一种方法,您可以在 it 块之外对我的所有自定义命令使用赛普拉斯夹具
- r - Write.csv 写入 unix 可执行文件 mac