C# 插入、修改、删除Word批注

 时间:2026-02-16 19:42:10

1、编辑代码前注意添加引用Sprie.Doc.dll(dll文件可在安装路径下的Bin文件夹中获取)

C# 插入、修改、删除Word批注

1、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");

        }

    }

}

2、测试结果:

C# 插入、修改、删除Word批注

1、测试文档:

C# 插入、修改、删除Word批注

2、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");

        }

    }

}

3、测试结果:

C# 插入、修改、删除Word批注

  • 自己做邻家女孩亲和感的发型
  • 怎样在windows下快速复制文件?
  • Discuz! X3.2(DiscuzX3.2)安装教程 环境塔建
  • 3.2米净高的楼层怎么装修?
  • 硬盘增量备份
  • 热门搜索
    飞快的近义词 单薄的近义词 男生短发型 首都博物馆官网 几乎的近义词 常常的近义词是什么 怎么翻译网页 感冒能喝牛奶吗 晶莹的近义词 怎么制作名片