当前位置: 首页 > news >正文

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

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

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

Spire.Doc for.NET 最新下载(qun:767755948)icon-default.png?t=N176https://www.evget.com/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 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 中插入书签,如果您有其他问题也可以继续浏览本系列文章,获取相关教程,你还可以给我留言或者加入我们的官方技术交流群。

 

http://www.lryc.cn/news/22784.html

相关文章:

  • 微服务框架-学习笔记
  • 实验心理学笔记01:引论
  • 预备3-如何学习编程
  • 操作系统权限提升(十七)之绕过UAC提权-Windows令牌概述和令牌窃取攻击
  • 【时间之外】系统管人,能行?(冷眼旁观连载之二)
  • 【数据结构必会基础】关于树,你所必须知道的亿些概念
  • 设计模式的应用(已在大型项目中使用)
  • Git的相关用法
  • Linux服务:Nginx反向代理与负载均衡
  • 数据结构与算法——2.算法概述
  • BPMN2.0是什么,BPMN能解决企业流程管理中哪些问题?
  • Java线程池的基本工作原理及案例
  • Stacked hourglass networks for human pose estimation代码学习
  • SpringCloud(五)MQ消息队列
  • SQL语法基础汇总
  • 惠普星14Pro电脑开机不了显示错误代码界面怎么办?
  • 顺序表的构造及功能
  • cesium: 绘制线段(008)
  • HTML、CSS学习笔记4(3D转换、动画)
  • java的分布式锁
  • 17- TensorFlow实现手写数字识别 (tensorflow系列) (项目十七)
  • Polkadot 基础
  • spring源码编译
  • 防盗链是什么?带你了解什么是防盗链
  • Linux基础命令-fdisk管理磁盘分区表
  • (四)K8S 安装 Nginx Ingress Controller
  • 高频面试题
  • js 字节数组操作,TCP协议组装
  • JavaScript的引入并执行-包含动态引入与静态引入
  • 第四阶段01-酷鲨商城项目准备