微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

C# /VB.NET操作Word批注一—— 插入、修改、删除Word批注

批注内容可以是对某段文字内容的注释,也可以是对文段中心思想的概括提要,或者是对文章内容的评判、疑问,以及在阅读时给自己或他人起到提示作用。本篇文章中将介绍如何在C#中操作Word批注,主要包含以下要点:

使用工具Free Spire.Doc for .NET 6.3(最新社区版)

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

1.插入Word批注

C#

using Spire.Doc;
 Spire.Doc.Documents;
 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[];

            添加文本到批注
            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();
        }
    }
}

VB.NET

Imports Spire.Doc
 Spire.Doc.Documents
 Spire.Doc.Fields

Namespace InsertComment_Word
    
    Class Program
        
        Private Shared Sub Main(ByVal args() As String)
            '实例化一个Document类对象,并加载Word文档
            Dim document As Document = New Document
            document.LoadFromFile(获取第一段第一节
            Dim section As Section = document.Sections(Dim paragraph As Paragraph = section.Paragraphs(Dim str String = "
            Dim comment As Comment = paragraph.AppendComment(strstem.Diagnostics.Process.Start()
        End Sub
    End Class
End Namespace

 

测试结果:

2.修改删除批注

测试文档:

C#

 Spire.Doc;

 ReplaceAndRemoveComment_Word
{
    [] args)
        {
            初始化Document类实例,加载带有批注的Word文档
            Document document = test.docx修改一个批注内容
            document.Comments[0].Body.Paragraphs[0].Replace(",What is the WEF ?false,1)">false移除第二个批注
            document.Comments.RemoveAt(1RemoveAndReplace.docxstem.Diagnostics.Process.Start();
        }
    }
}

 

VB.NET

 Spire.Doc

 ReplaceAndRemoveComment_Word
    
    初始化Document类实例,加载带有批注的Word文档
            修改一个批注内容
            document.Comments(0).Body.Paragraphs(0).Replace(stem.Diagnostics.Process.Start(End Namespace

 

测试结果:

以上是本次关于操作Word批注的全部内容。感谢浏览!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐