已知在OpenXml有以下几种超链接
功能 | 说明 |
---|---|
跳转页面 | 跳转某一页:ppaction://hlinksldjump 跳转第一页:ppaction://hlinkshowjump?jump=firstslide 跳转最后一页:ppaction://hlinkshowjump?jump=lastslide 跳转下一页:ppaction://hlinkshowjump?jump=nextslide 跳转上一页:ppaction://hlinkshowjump?jump=previousslide |
跳转文件 | 跳转打开本地文件:ppaction://hlinkfile 跳转打开Office支持的主流文档类文件(office系文档、pdf、txt…):ppaction://hlinkpres?slideindex=1&slidetitle= |
跳转网页 |
例子
我们先准备好这样一份pptx文件,如图:
我们分别为四个形状插入超链接,代码如下:
internal class Program
{
static void Main(string[] args)
{
var mainExecuteDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var pptFilePath = Path.Combine(mainExecuteDirectory!, "YourPresentation.pptx");
// 打开一个PPTX文档
using PresentationDocument presentationDocument = PresentationDocument.Open(pptFilePath, true);
var slideIdList = presentationDocument.PresentationPart!.Presentation.SlideIdList;
if (slideIdList is null || !slideIdList.Any()服务器托管网)
{
return;
}
var firstSlideId =(SlideId) slideIdList.First();
// 获取页面内容
var firstSlidePart = (SlidePart) presentationDocument.PresentationPart.GetPartById(firstSlideId.RelationshipId!.Value!);
//设置跳转到第三页
var targetSlideId = (SlideId) slideIdList.ChildElements[2];
var targetSlidePart = (SlidePart) presentationDocument.PresentationPart.GetPartById(targetSlideId.RelationshipId!.Value!);
var relationshipId = firstSlidePart.CreateRelationshipToPart(targetSlidePart);
var shapeElements = firstSlidePart.Slide.CommonSlideData!.ShapeTree!.Elements().ToList();
//第一个形状设置跳转第三页
shapeElements[0]!.NonVisualShapeProperties!.NonVisualDrawingProperties!.HyperlinkOnClick = new HyperlinkOnClick()
服务器托管网 {
Action = PptAction.SlideJump,
Id = relationshipId
};
//第二个形状设置跳转下一页
var shapeElement = shapeElements[1];
shapeElement.NonVisualShapeProperties!.NonVisualDrawingProperties!.HyperlinkOnClick = new HyperlinkOnClick()
{
Action = PptAction.JumpNextSlide,
};
var filePath = Path.Combine(mainExecuteDirectory!, "两只老虎-原声.mp3");
var fileHyperlinkRelationship = firstSlidePart.AddHyperlinkRelationship(new Uri(filePath, UriKind.Absolute), true);
//第三个形状设置打开文件
shapeElements[2]!.NonVisualShapeProperties!.NonVisualDrawingProperties!.HyperlinkOnClick = new HyperlinkOnClick()
{
Action = PptAction.OpenFile,
Id = fileHyperlinkRelationship.Id
};
//第四个形状设置打开网页链接
var httpHyperlinkRelationship = firstSlidePart.AddHyperlinkRelationship(new Uri($"http://www.baidu.com", UriKind.Absolute), true);
shapeElements[3]!.NonVisualShapeProperties!.NonVisualDrawingProperties!.HyperlinkOnClick = new HyperlinkOnClick()
{
Id = httpHyperlinkRelationship.Id
};
// 保存并关闭文档
presentationDocument.Save();
}
}
public static class PptAction
{
///
/// 跳转页面
///
public const string SlideJump = "ppaction://hlinksldjump";
///
/// 跳转下一页
///
public const string JumpNextSlide = "ppaction://hlinkshowjump?jump=nextslide";
///
/// 打开文件
///
public const string OpenFile = "ppaction://hlinkfile";
}
效果如下:
源码
源码链接
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
机房租用,北京机房租用,IDC机房托管, http://www.fwqtg.net
应用场景: 多自由度机器人、双足、四足仿生机器人的决策规划 机器人仿真软件: mojuco, vrep, 服务器托管网gazebo, NVIDIA Isaac Mujoco/Bullet/Webots/Gazebo/服务器托管网CoppeliaSim/Isaa…