*这么优秀的国产工具怎能错过呢!在线下单专享“一口价”,查看折扣价!想要获取更多福利的朋友可以咨询在线客服哦~
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.DocImports Spire.Doc.DocumentsNamespace 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 ClassEnd Namespace
效果图:

是E-iceblue官方友好合作伙伴,如果您对spire.Doc感兴趣,可以联系在线客服了解具体授权价格和使用机制。
标签:
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!