C# 读取Word批注内容
此条经验将介绍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#(供参考)
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、调试运行程序后,生成读取结果,如下,