class="MsoNormal" style="line-height: 115%;">批注内容可以是对某段文字或内容的注释,也可以是对文段中心思想的概括提要,或者是对文章内容的评判、疑问,以及在阅读时给自己或他人起到提示作用。本篇文章中将介绍如何在C#中操作Word批注,主要包含以下要点:
使用工具:Free Spire.Doc for .NET 6.3(最新社区版)
?
注:编辑代码前注意添加引用Sprie.Doc.dll(dll文件可在安装路径下的Bin文件夹中获取)
?

?
<!--[if !supportLists]-->
?
【C#】
?
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
namespace InsertComment_Word
{
class Program
{
static void Main(string[] args)
{
//实例化一个Document类对象,并加载Word文档
Document document = new Document();
document.LoadFromFile("sample.docx");
//获取第一段第一节
Section section = document.Sections[0];
Paragraph paragraph = section.Paragraphs[0];
//添加文本到批注
string str = "This paragraph describes the origin and the purpose of WEF";
Comment comment = paragraph.AppendComment(str);
//添加批注作者
comment.Format.Author = "E-iceblue";
//保存并打开文档
document.SaveToFile("Comments.docx", FileFormat.Docx2010);
System.Diagnostics.Process.Start("Comments.docx");
}
}
}
?
?
测试结果:

?
测试文档如下:

?
C#
?
using Spire.Doc;
namespace ReplaceAndRemoveComment_Word
{
class Program
{
static void Main(string[] args)
{
//初始化Document类实例,加载带有批注的Word文档
Document document = new Document();
document.LoadFromFile("test.docx");
//修改第一个批注内容
document.Comments[0].Body.Paragraphs[0].Replace("This paragraph describes the origin and the purpose of WEF", "What is the WEF ?", false, false);
//移除第二个批注
document.Comments.RemoveAt(1);
//保存并打开文档
document.SaveToFile("RemoveAndReplace.docx", FileFormat.Docx);
System.Diagnostics.Process.Start("RemoveAndReplace.docx");
}
}
}
?测试结果:
?

?
以上是关于C#操作Word批注的全部内容
本文完。
(如需转载,请注明出处)