C# 插入书签到Word文档
书签的设置可以帮助我们快速的定位某段文字,使用起来很方便,也很节省时间。因此,本条经验将介绍如何通过C#编程来插入书签到Word文档。

C#代码示例(供参考)
1、using System;using Spire.Doc;using Spire.Doc.Documents;namespace WordBookmark{ class Bookmark { static void Main(string[] args) { //实例化Document类,加载文档 Document document = new Document(); document.LoadFromFile("test.docx"); //插入书签到指定段落,并命名书签 Section section = document.Sections[0]; section.Paragraphs[1].AppendBookmarkStart("Bookmark1"); section.Paragraphs[2].AppendBookmarkEnd("Bookmark1"); //保存并打开文档 document.SaveToFile("InsertBookmark.docx", FileFormat.Docx); System.Diagnostics.Process.Start("InsertBookmark.docx"); } }}
2、完成代码后,调试运行程序,生成文档。在新生成的文档中,指定的段落已经插入了书签,通过搜索书签名,可以快速定位到书签位置。(书签插入效果如下图所示)

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
阅读量:24
阅读量:27
阅读量:23
阅读量:90
阅读量:78