C #/vb.net Action word--Inserting, modifying, deleting word annotations

Source: Internet
Author: User

Comments can be comments on a piece of text or content, or a summary of the central idea of a paragraph, or a critique of the content of the article, a question, and a hint to yourself or others when reading. This article describes how to manipulate word annotations in c#/vb, mainly with the following points:

    • Insert Word Annotations
    • Modify Word Annotations
    • Delete Word annotations
      Using tools: Free Spire.doc for. NET 6.3 (Latest Community Edition)
      Note: Before editing the code, note the Add Reference Sprie.Doc.dll (DLL file can be obtained in the Bin folder under the installation path)

1. Insert Word Annotations

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");        }    }}

vb.net

Imports Spire.DocImports Spire.Doc.DocumentsImports Spire.Doc.FieldsNamespace InsertComment_Word    Class Program        Private Shared Sub Main(ByVal args() As String)            Dim document As Document = New Document            document.LoadFromFile("sample.docx")            Dim section As Section = document.Sections(0)            Dim paragraph As Paragraph = section.Paragraphs(0)            Dim str As String = "This paragraph describes the origin and the purpose of WEF"            Dim comment As Comment = paragraph.AppendComment(str)            comment.Format.Author = "E-iceblue"            document.SaveToFile("Comments.docx", FileFormat.Docx2010)            System.Diagnostics.Process.Start("Comments.docx")        End Sub    End ClassEnd Namespace

Test results:

2. Modify and delete word annotations

Test Document:

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");        }    }}

vb.net

Imports Spire.DocNamespace ReplaceAndRemoveComment_Word    Class Program        Private Shared Sub Main(ByVal args() As String)                     Dim document As 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")        End Sub    End ClassEnd Namespace

Test results:

The above is about C #, VB. NET to manipulate the entire contents of Word annotations, thanks for reading!
Welcome reprint, Reproduced please indicate the source.

C #/vb.net Action word--Inserting, modifying, deleting word annotations

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.