翻譯|使用教程|編輯:胡濤|2023-02-27 10:09:42.977|閱讀 152 次
概述:在本文中,您將了解如何使用Spire.Doc for .NET將書簽插入到現有的 Word 文檔中,歡迎查閱
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
Spire.Doc for .NET是一款專門對 Word 文檔進行操作的 .NET 類庫。在于幫助開發人員無需安裝 Microsoft Word情況下,輕松快捷高效地創建、編輯、轉換和打印 Microsoft Word 文檔。擁有近10年專業開發經驗Spire系列辦公文檔開發工具,專注于創建、編輯、轉換和打印Word/PDF/Excel等格式文件處理,小巧便捷。
E-iceblue 功能類庫Spire 系列文檔處理組件均由中國本土團隊研發,不依賴第三方軟件,不受其他國家的技術或法律法規限制,同時適配國產操作系統如中科方德、中標麒麟等,兼容國產文檔處理軟件 WPS(如 .wps/.et/.dps 等格式
在處理冗長的 Word 文檔時,插入不同名稱的書簽是標記文檔中位置的一種便捷方式。插入書簽后,您可以快速跳轉到指定位置,而無需逐頁滾動。在本文中,您將了解如何使用Spire.Doc for .NET將書簽插入到現有的 Word 文檔中。
首先,您需要將包含在 Spire.Doc for .NET 包中的 DLL 文件添加為您的 .NET 項目中的引用。DLL 文件可以從此鏈接下載或通過NuGet安裝。
PM> Install-Package Spire.Doc
Spire.Doc for .NET 提供了Paragraph.AppendBookmarkStart(string name)和Paragraph.AppendBookmarkEnd(string name)方法來將具有指定名稱的書簽插入到 Word 文檔的指定段落中。詳細步驟如下。
[C#]
using Spire.Doc; namespace WordBookmark { class Bookmark { static void Main(string[] args) { //Create a Document instance Document document = new Document(); //Load a sample Word document document.LoadFromFile(@"C:\Users\Administrator\Desktop\test.docx"); //Get the first section Section section = document.Sections[0]; //Insert a bookmark with specified name into the specified paragraphs section.Paragraphs[9].AppendBookmarkStart("SecurityTerm"); section.Paragraphs[11].AppendBookmarkEnd("SecurityTerm"); //Save the document to file document.SaveToFile("Bookmark.docx", FileFormat.Docx); } } }
[VB.NET]
using Spire.Doc; namespace WordBookmark { class Bookmark { static void Main(string[] args) { //Create a Document instance Document document = new Document(); //Load a sample Word document document.LoadFromFile(@"C:\Users\Administrator\Desktop\test.docx"); //Get the first section Section section = document.Sections[0]; //Insert a bookmark with specified name into the specified paragraphs section.Paragraphs[9].AppendBookmarkStart("SecurityTerm"); section.Paragraphs[11].AppendBookmarkEnd("SecurityTerm"); //Save the document to file document.SaveToFile("Bookmark.docx", FileFormat.Docx); } } }
以上便是如何C#/VB.NET:在 Word 中插入書簽,如果您有其他問題也可以繼續瀏覽本系列文章,獲取相關教程,你還可以給我留言或者加入我們的官方技術交流群。
歡迎下載|體驗更多E-iceblue產品
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn