C# 读取Word批注内容

2025-06-02 19:25:04

此条经验将介绍C#读取Word批注内容的方法。

工具/原料

Free Spire.Doc for .NET 6.3(社区版)

Visual Studio

dll引用

1、在E-iceblue官网或者Nuget网站上下载Free Spire.Doc for .NET的安装包后,注意在编辑代码时,添加引用Spire.Doc.dll到程序。dll文件可在安装路径下的Bin文件夹中获取。

C# 读取Word批注内容

C#(供参考)

1、using System.Text;using System.IO;using Spire.Doc;using Spire.Doc.Documents;using Spire.Doc.Fields;namespace ExtractComments{ class Program { static void Main(string[] args) { //创建实例,加载文档 Document doc = new Document(); doc.LoadFromFile("test.docx"); //实例化StringBuilder类 StringBuilder SB = new StringBuilder(); //遍历所有word批注,将批注内容写入Txt文档 foreach (Comment comment in doc.Comments) { foreach (Paragraph p in comment.Body.Paragraphs) { SB.AppendLine(p.Text); } } File.WriteAllText("CommentExtraction.txt", SB.ToString()); System.Diagnostics.Process.Start("CommentExtraction.txt"); } }}

2、调试运行程序后,生成读取结果,如下,

C# 读取Word批注内容
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢