700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > Word控件Spire.Doc 【书签】教程(1):在C#/VB.NET:在 Word 中插入书签

Word控件Spire.Doc 【书签】教程(1):在C#/VB.NET:在 Word 中插入书签

时间:2023-08-18 21:53:09

相关推荐

Word控件Spire.Doc 【书签】教程(1):在C#/VB.NET:在 Word 中插入书签

Spire.Doc for .NET是一款专门对 Word 文档进行操作的 .NET 类库。在于帮助开发人员无需安装 Microsoft Word情况下,轻松快捷高效地创建、编辑、转换和打印 Microsoft Word 文档。拥有近专业开发经验Spire系列办公文档开发工具,专注于创建、编辑、转换和打印Word/PDF/Excel等格式文件处理,小巧便捷。

E-iceblue功能类库Spire 系列文档处理组件均由中国本土团队研发,不依赖第三方软件,不受其他国家的技术或法律法规限制,同时适配国产操作系统如中科方德、中标麒麟等,兼容国产文档处理软件 WPS(如 .wps/.et/.dps 等格式

Spire.Doc 最新下载(qun:767755948)/product/3368/download

在处理冗长的 Word 文档时,插入不同名称的书签是标记文档中位置的一种便捷方式。插入书签后,您可以快速跳转到指定位置,而无需逐页滚动。在本文中,您将了解如何使用Spire.Doc for .NET将书签插入到现有的 Word 文档中。

安装适用于 .NET 的 Spire.Doc

首先,您需要将包含在 Spire.Doc for .NET 包中的 DLL 文件添加为您的 .NET 项目中的引用。DLL 文件可以从此链接下载或通过NuGet安装。

PM> Install-Package Spire.Doc

将书签插入现有 Word 文档

Spire.Doc for .NET 提供了Paragraph.AppendBookmarkStart(string name)Paragraph.AppendBookmarkEnd(string name)方法来将具有指定名称的书签插入到 Word 文档的指定段落中。详细步骤如下。

创建一个文档实例。使用Document.LoadFromFile()方法加载示例 Word 文档。使用Document.Sections[]属性获取 Word 文档的第一部分。使用Section.Paragraphs[]属性获取该部分的指定段落。使用Paragraph.AppendBookmarkStart(string name) 方法将具有指定名称的书签的开头追加到指定段落。使用Paragraph.AppendBookmarkEnd(string name) 方法将具有指定名称的书签结尾附加到指定段落。使用文档将文档保存到另一个文件。保存到文件()方法。

[C#]

using Spire.Doc;namespace WordBookmark{class Bookmark{static void Main(string[] args){//Create a Document instanceDocument document = new Document();//Load a sample Word documentdocument.LoadFromFile(@"C:\Users\Administrator\Desktop\test.docx");//Get the first sectionSection section = document.Sections[0];//Insert a bookmark with specified name into the specified paragraphssection.Paragraphs[9].AppendBookmarkStart("SecurityTerm");section.Paragraphs[11].AppendBookmarkEnd("SecurityTerm");//Save the document to filedocument.SaveToFile("Bookmark.docx", FileFormat.Docx);}}}

[]

using Spire.Doc;namespace WordBookmark{class Bookmark{static void Main(string[] args){//Create a Document instanceDocument document = new Document();//Load a sample Word documentdocument.LoadFromFile(@"C:\Users\Administrator\Desktop\test.docx");//Get the first sectionSection section = document.Sections[0];//Insert a bookmark with specified name into the specified paragraphssection.Paragraphs[9].AppendBookmarkStart("SecurityTerm");section.Paragraphs[11].AppendBookmarkEnd("SecurityTerm");//Save the document to filedocument.SaveToFile("Bookmark.docx", FileFormat.Docx);}}}

以上便是如何C#/:在 Word 中插入书签,如果您有其他问题也可以继续浏览本系列文章,获取相关教程,你还可以给我留言或者加入我们的官方技术交流群。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。