zl程序教程

您现在的位置是:首页 >  后端

当前栏目

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

c#Net教程 创建 控件 图像 word vb
2023-09-11 14:14:49 时间

Spire.Doc for .NET是一款专门对 Word 文档进行操作的 .NET 类库。在于帮助开发人员无需安装 Microsoft Word情况下,轻松快捷高效地创建、编辑、转换和打印 Microsoft Word 文档。拥有近10年专业开发经验Spire系列办公文档开发工具,专注于创建、编辑、转换和打印Word/PDF/Excel等格式文件处理,小巧便捷。

Spire.Doc for.NET 最新下载(qun:767755948)icon-default.png?t=M85Bhttps://www.evget.com/product/3368/download

使用链接图像,您可以在用户单击图像时将他们定向到 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#]

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.Doc
Imports Spire.Doc.Documents
Imports Spire.Doc.Fields
Imports System.Drawing
Namespace CreateLink
Class Program

Private 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 Sub
End Class
End Namespace

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