[C#]
using Spire.Doc;using Spire.Doc.Documents;namespace LinkToBookmark{class Program{static void Main(string[] args){//Create a Document objectDocument doc = new Document();//Add two sectionsSection section1 = doc.AddSection();Section section2 = doc.AddSection();//Insert a paragraph in section 2 and add a bookmark named "myBookmark" to itParagraph 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 paragraph = section1.AddParagraph();paragraph.AppendText("Link to a bookmark: ");paragraph.AppendHyperlink("myBookmark", "Jump to a location in this document", HyperlinkType.Bookmark);//Save to filedoc.SaveToFile("LinkToBookmark.docx", FileFormat.Docx2013);}}}
[VB.NET]
Imports Spire.DocImports Spire.Doc.DocumentsNamespace LinkToBookmarkClass ProgramShared Sub Main(ByVal args() As String)'Create a Document objectDocument doc = New Document()'Add two sectionsDim section1 As Section = doc.AddSection()Dim section2 As Section = doc.AddSection()'Insert a paragraph in section 2 and add a bookmark named "myBookmark" to itDim 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 bookmarkDim 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 filedoc.SaveToFile("LinkToBookmark.docx", FileFormat.Docx2013)End SubEnd ClassEnd Namespace

以上便是在 C#/VB.NET 中链接到 Word 文档中的书签,如果您有其他问题也可以继续浏览本系列文章,获取相关教程,你还可以给我留言或者加入我们的官方技术交流群。
欢迎下载|体验更多E-iceblue产品
获取更多信息请咨询在线客服 ;
标签:
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!