C# 在PowerPoint中给图片添加超链接和获取图片的超链接
在PowerPoint中,我们可以给幻灯片中的图片添加超链接,播放幻灯片时点击图片就能跳转到指定的网址。本文将介绍如何使用免费版Spire.Presentation组件和C#给PowerPoint文档中的图片添加超链接和获取图片的超链接。
给图片添加超链接
//创建Presentation实例
Presentation presentation = new Presentation();
//获取第一张幻灯片
ISlide slide = presentation.Slides[0];
RectangleF rect = new RectangleF(50,300, 100, 100);
//添加图片到幻灯片
IEmbedImage image =slide.Shapes.AppendEmbedImage(ShapeType.Rectangle,@"logo.png", rect);
//添加超链接到图片
ClickHyperlink hyperlink = new ClickHyperlink("https://www.e-iceblue.com");
image.Click = hyperlink;
//保存文档
presentation.SaveToFile("ImageHyperLink.pptx",FileFormat.Pptx2010);
效果图:
获取图片的超链接
//创建Presentation实例
Presentation presentation = new Presentation();
//加载PowerPoint文档
presentation.LoadFromFile("ImageHyperLink.pptx");
//获取第一张幻灯片
ISlide slide = presentation.Slides[0];
//获取幻灯片中图片的超链接
string hyperlink = (slide.Shapes[0] as IEmbedImage).Click.Address;
File.WriteAllText("hyperlinks.txt",hyperlink);
效果图:
还没有评论,来说两句吧...