Word控件Spire.Doc 【超链接】教程(8):在 C#/VB.NET 中链接到 Word 文档中的书签
Spire.Doc for .NET是一款专门对 Word 文档进行操作的 .NET 类库。在于帮助开发人员无需安装 Microsoft Word情况下,轻松快捷高效地创建、编辑、转换和打印 Microsoft Word 文档。拥有近10年专业开发经验Spire系列办公文档开发工具,专注于创建、编辑、转换和打印Word/PDF/Excel等格式文件处理,小巧便捷。
Spire.Doc for.NET 最新下载(qun:767755948)https://www.evget.com/product/3368/download
本文向您展示了如何使用带有 C# 和 VB.NET 的 Spire.Doc,在同一 Word 文档中创建指向书签的超链接。
[C#]
using Spire.Doc; using Spire.Doc.Documents; namespace LinkToBookmark { class Program { static void Main(string[] args) { //Create a Document object Document doc = new Document(); //Add two sections Section section1 = doc.AddSection(); Section section2 = doc.AddSection(); //Insert a paragraph in section 2 and add a bookmark named "myBookmark" to it 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 bookmark Paragraph paragraph = section1.AddParagraph(); paragraph.AppendText("Link to a bookmark: "); paragraph.AppendHyperlink("myBookmark", "Jump to a location in this document", HyperlinkType.Bookmark); //Save to file doc.SaveToFile("LinkToBookmark.docx", FileFormat.Docx2013); } } }
[VB.NET]
Imports Spire.Doc Imports Spire.Doc.Documents Namespace LinkToBookmark Class Program Shared Sub Main(ByVal args() As String) 'Create a Document object Document doc = New Document() 'Add two sections Dim section1 As Section = doc.AddSection() Dim section2 As Section = doc.AddSection() 'Insert a paragraph in section 2 and add a bookmark named "myBookmark" to it 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 bookmark Dim paragraph As Paragraph = section1.AddParagraph() paragraph.AppendText("Link to a bookmark: ") paragraph.AppendHyperlink("myBookmark", "Jump to a location in this document", HyperlinkType.Bookmark) 'Save to file doc.SaveToFile("LinkToBookmark.docx", FileFormat.Docx2013) End Sub End Class End Namespace
以上便是在 C#/VB.NET 中链接到 Word 文档中的书签,如果您有其他问题也可以继续浏览本系列文章,获取相关教程,你还可以给我留言或者加入我们的官方技术交流群。