c# - 如何使用 Open XML 在 PowerPoint 幻灯片中插入超链接?
问题描述
我有一个场景,我必须用表格数据替换幻灯片模板中的某些变量,但在这种情况下,数据和幻灯片文本是重叠的,经过一些研究,我发现 PowerPoint 不是为这种情况设计的[MS Link](img 1 )。为了克服这个问题,我不应该用表格数据替换变量,而是应该用链接替换变量,该链接将指向新创建的幻灯片,我可以在其中发布表格数据(img 2)。
所以回到我的问题,有什么方法可以在不弄乱模板的情况下编写数据?或如何将变量替换为幻灯片的超链接?
解决方案
根据文档,您可以执行类似的操作,只需根据您的情况以及如何找到变量 1 进行调整。
// Open the presentation file as read-only.
using (PresentationDocument document = PresentationDocument.Open(fileName, false))
{
// Iterate through all the slide parts in the presentation part.
foreach (SlidePart slidePart in document.PresentationPart.SlideParts)
{
IEnumerable<Drawing.HyperlinkType> links = slidePart.Slide.Descendants<Drawing.HyperlinkType>();
// Iterate through all the links in the slide part.
foreach (Drawing.HyperlinkType link in links)
{
// Iterate through all the external relationships in the slide part.
foreach (HyperlinkRelationship relation in slidePart.HyperlinkRelationships)
{
// If the relationship ID matches the link ID…
if (relation.Id.Equals(link.Id))
{
// Add the URI of the external relationship to the list of strings.
ret.Add(relation.Uri.AbsoluteUri);
}
}
}
}
}
推荐阅读
- python - 允许多项选择但不可清除的短划线下拉菜单
- c - 从 C 语言到 MIPS 的解释
- google-apps-script - 谷歌脚本字符串日期格式到日期格式
- c++ - 如何在 c++builder6 中为我的表单设置背景?
- express - vscode 调试 Express Webapp 失败
- android - NFC 堆栈停止寻找新标签
- javascript - 在 redux 中使用 immutablejs(toJS 和 fromJS)的正确方法
- php - 如何将 Mongodb 安装到 WAMP
- c++ - 有没有办法只获取一行的一部分?
- php - 在php andoutlook上添加抄送邮箱