Spire.Doc for .NET是一款专门对 Word 文档进行操作的 .NET 类库 。在于帮助开发人员无需安装Word情况下,轻松快捷高效地创建、编辑、转换和打印Word 文档 。拥有近10年专业开发经验Spire系列办公文档开发工具,专注于创建、编辑、转换和打印Word/PDF/Excel等格式文件处理,小巧便捷 。
Spire.Doc for.NET 最新下载(qun:)
Word 文档中的超链接使读者能够从其位置跳转到文档中的不同位置,或者跳转到不同的文件或网站,或者跳转到新的电子邮件消息 。超链接使读者可以快速轻松地导航到相关信息 。本文演示了如何使用Spire.Doc for .NET在 C# 和 VB.NET 中向文本或图像添加超链接 。
步骤一:为 .NET 安装 Spire.Doc
首先,您需要将 Spire.Doc for.NET 包中包含的 DLL 文件添加为 .NET 项目中的引用 。
PM> Install-Package Spire.Doc
步骤二:向 Word 添加段落时插入超链接
Spire.Doc 提供了.()方法,用于将 Web 链接、电子邮件链接、文件链接或书签链接添加到段落中的一段文本或图像 。以下是详细步骤 。
【C#】
using Spire.Doc;using Spire.Doc.Documents;using System.Drawing;namespace InsertHyperlinks{class Program{static void Main(string[] args){//Create a Word documentDocument doc = new Document();//Add a sectionSection section = doc.AddSection();//Add a paragraphParagraph paragraph = section.AddParagraph();paragraph.AppendHyperlink("https://www-iceblue.com/", "Home Page", HyperlinkType.WebLink);//Append line breaksparagraph.AppendBreak(BreakType.LineBreak);paragraph.AppendBreak(BreakType.LineBreak);//Add an email linkparagraph.AppendHyperlink("mailto:support@e-iceblue.com", "Mail Us", HyperlinkType.EMailLink);//Append line breaksparagraph.AppendBreak(BreakType.LineBreak);paragraph.AppendBreak(BreakType.LineBreak);//Add a file linkstring filePath = @"C:\Users\Administrator\Desktop\report.xlsx";paragraph.AppendHyperlink(filePath, "Click to open the report", HyperlinkType.FileLink);//Append line breaksparagraph.AppendBreak(BreakType.LineBreak);paragraph.AppendBreak(BreakType.LineBreak);//Add another section and create a bookmarkSection section2 = doc.AddSection();Paragraph bookmarkParagrapg = section2.AddParagraph();bookmarkParagrapg.AppendText("Here is a bookmark");BookmarkStart start = bookmarkParagrapg.AppendBookmarkStart("myBookmark");bookmarkParagrapg.Items.Insert(0, start);bookmarkParagrapg.AppendBookmarkEnd("myBookmark");//Link to the bookmarkparagraph.AppendHyperlink("myBookmark", "Jump to a location inside this document", HyperlinkType.Bookmark);//Append line breaksparagraph.AppendBreak(BreakType.LineBreak);paragraph.AppendBreak(BreakType.LineBreak);//Add an image linkImage image = Image.FromFile(@"C:\Users\Administrator\Desktop\logo.png");Spire.Doc.Fields.DocPicture picture = paragraph.AppendPicture(image);paragraph.AppendHyperlink("https://docs.microsoft.com/en-us/dotnet/", picture, HyperlinkType.WebLink);//Save to filedoc.SaveToFile("InsertHyperlinks.docx", FileFormat.Docx2013);}}}
【VB.NET】
Imports Spire.DocImports Spire.Doc.DocumentsImports System.DrawingNamespace InsertHyperlinksClass ProgramShared Sub Main(ByVal args() As String)'Create a Word documentDocument doc = New Document()'Add a sectionDim section As Section = doc.AddSection()'Add a paragraphDim paragraph As Paragraph = section.AddParagraph()paragraph.AppendHyperlink("https://www.e-iceblue.com/", "Home Page", HyperlinkType.WebLink)'Append line breaksparagraph.AppendBreak(BreakType.LineBreak)paragraph.AppendBreak(BreakType.LineBreak)'Add an email linkparagraph.AppendHyperlink("mailto:support@e-iceblue.com", "Mail Us", HyperlinkType.EMailLink)'Append line breaksparagraph.AppendBreak(BreakType.LineBreak)paragraph.AppendBreak(BreakType.LineBreak)'Add a file linkDim filePath As String = "C:\Users\Administrator\Desktop\report.xlsx"paragraph.AppendHyperlink(filePath, "Click to open the report", HyperlinkType.FileLink)'Append line breaksparagraph.AppendBreak(BreakType.LineBreak)paragraph.AppendBreak(BreakType.LineBreak)'Add another section and create a bookmarkDim section2 As Section = doc.AddSection()Dim bookmarkParagrapg As Paragraph = section2.AddParagraph()bookmarkParagrapg.AppendText("Here is a bookmark")Dim start As BookmarkStart = bookmarkParagrapg.AppendBookmarkStart("myBookmark")bookmarkParagrapg.Items.Insert(0, start)bookmarkParagrapg.AppendBookmarkEnd("myBookmark")'Link to the bookmarkparagraph.AppendHyperlink("myBookmark", "Jump to a location inside this document", HyperlinkType.Bookmark)'Append line breaksparagraph.AppendBreak(BreakType.LineBreak)paragraph.AppendBreak(BreakType.LineBreak)'Add an image linkDim image As Image = Image.FromFile("C:\Users\Administrator\Desktop\logo.png")Dim picture As Spire.Doc.Fields.DocPicture = paragraph.AppendPicture(image)paragraph.AppendHyperlink("https://docs.microsoft.com/en-us/dotnet/", picture, HyperlinkType.WebLink)'Save to filedoc.SaveToFile("InsertHyperlinks.docx", FileFormat.Docx2013)System.Diagnostics.Process.Start("InsertHyperlinks.docx")End SubEnd ClassEnd Namespace
- word填充颜色 word填充颜色深色25%
- 未来星计算机答案,这些年律师百思不解的10个Word难题,答案全在这里了!
- Word公式编辑器在哪里
- Word怎么横向排版
- Word表格怎么调整行高间距
- Word中如何设置文本轮廓
- 如何裁剪Word中的图片
- 如何对Word表格进行快速计算
- Word中输入网址如何取消设置超链接
- Word怎么设置首字下沉效果