PowerPoint文件中的超链接不仅可以链接到外部URL,还可以链接到文档中的特定幻灯片。本文将介绍如何使用Spire.Presentation创建一个链接到指定幻灯片的超链接。
C#
//创建PowerPoint文档
Presentation presentation = new Presentation();
//添加幻灯片
presentation.Slides.Append();
//添加形状到第二张幻灯片
IAutoShape shape = presentation.Slides[1].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(20, 80, 200, 50));
//设置形状的填充颜色
shape.Fill.FillType = FillFormatType.Solid;
shape.Fill.SolidColor.Color = Color.Gold;
//在形状上添加文本
shape.TextFrame.Text = "跳转到第一页";
//创建ClickHyperlink对象,链接到第一张幻灯片
ClickHyperlink hyperlink = new ClickHyperlink(presentation.Slides[0]);
//在形状和文字上均设置跳转链接
shape.Click = hyperlink;
shape.TextFrame.TextRange.ClickAction = hyperlink;
//保存文档
presentation.SaveToFile("output.pptx", FileFormat.Pptx2010);
VB.NET
'创建PowerPoint文档
Dim presentation As New Presentation()
'添加幻灯片
presentation.Slides.Append()
'添加形状到第二张幻灯片
Dim shape As IAutoShape = presentation.Slides(1).Shapes.AppendShape(ShapeType.Rectangle, New RectangleF(20, 80, 200, 50))
'设置形状的填充颜色
shape.Fill.FillType = FillFormatType.Solid
shape.Fill.SolidColor.Color = Color.Gold
'在形状上添加文本
shape.TextFrame.Text = "跳转到第一页"
'创建ClickHyperlink对象,链接到第一张幻灯片
Dim hyperlink As New ClickHyperlink(presentation.Slides(0))
'在形状和文字上均设置跳转链接
shape.Click = hyperlink
shape.TextFrame.TextRange.ClickAction = hyperlink
'保存文档
presentation.SaveToFile("output.pptx", FileFormat.Pptx2010)