Word控件Spire.Doc 【超链接】教程(7):在 C#、VB.NET 中的 Word 中创建图像超链接

本文将向您展示如何使用 Spire.Doc 在 Word 文档中创建图像超链接。

使用链接图像,您可以在用户单击图像时将他们定向到 URL。本文将向您展示如何使用 Spire.Doc 在 Word 文档中创建图像超链接。

第一步:创建一个Word文档,添加一个节和一个段落。

Document doc = new Document();Section section = doc.AddSection();Paragraph paragraph = section.AddParagraph();

第 2 步:将图像加载到 DocPicture 对象。

DocPicture picture = new DocPicture(doc);picture.LoadImage(Image.FromFile("logo.png"));

第 3 步:向段落添加图像超链接。

paragraph.AppendHyperlink("www.e-iceblue.com", picture, HyperlinkType.WebLink);

第 4 步:保存文件。

doc.SaveToFile("output.docx", FileFormat.Docx);

输出

在 C#、VB.NET 中的 Word 中创建图像超链接

完整代码

[C#]

using Spire.Doc;using Spire.Doc.Documents;using Spire.Doc.Fields;using System.Drawing;namespace CreateLink{class Program{static void Main(string[] args){Document doc = new Document();Section section = doc.AddSection();Paragraph paragraph = section.AddParagraph();Image image = Image.FromFile("logo.png");DocPicture picture = new DocPicture(doc);picture.LoadImage(image);paragraph.AppendHyperlink("www.e-iceblue.com", picture, HyperlinkType.WebLink);doc.SaveToFile("output.docx", FileFormat.Docx);}}}

[VB.NET]

Imports Spire.DocImports Spire.Doc.DocumentsImports Spire.Doc.FieldsImports System.DrawingNamespace CreateLinkClass ProgramPrivate Shared Sub Main(args As String())Dim doc As New Document()Dim section As Section = doc.AddSection()Dim paragraph As Paragraph = section.AddParagraph()Dim image__1 As Image = Image.FromFile("logo.png")Dim picture As New DocPicture(doc)picture.LoadImage(image__1)paragraph.AppendHyperlink("www.e-iceblue.com", picture, HyperlinkType.WebLink)doc.SaveToFile("output.docx", FileFormat.Docx)End SubEnd ClassEnd Namespace

以上便是如何在C#去除word文档中的超链接,如果您有其他问题也可以继续浏览本系列文章,获取相关教程,你还可以给我留言或者加入我们的官方技术交流群。


欢迎下载|体验更多E-iceblue产品

获取更多信息请咨询在线客服  


标签:

来源:慧都

声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2022年10月19日
下一篇 2022年10月19日

相关推荐

发表回复

登录后才能评论