C#/VB.NET: Word에서 주석 추가, 회신 또는 삭제

2023-09-27 06:33:19 zaki zou

Microsoft Word의 주석 기능은 사람들이 문서의 내용을 변경하거나 중단하지 않고도 Word 문서에 통찰력이나 의견을 추가할 수 있는 훌륭한 방법을 제공합니다. 누군가 문서에 댓글을 달면 문서 작성자나 다른 사용자는 동시에 문서를 보고 있지 않더라도 댓글에 답하여 그 사람과 토론할 수 있습니다. 이 문서에서는 다음 방법을 보여줍니다 C# 및 VB.NET의 Word에서 주석 추가, 회신 또는 삭제 사용하여 Spire.Doc for .NET 도서관.

Spire.Doc for .NET 설치

먼저 Spire.Doc for.NET 패키지에 포함된 DLL 파일을 .NET 프로젝트의 참조로 추가해야 합니다. DLL 파일은 이 링크 에서 다운로드하거나 NuGet을 통해 설치할 수 있습니다.

PM> Install-Package Spire.Doc

C# 및 VB.NET에서 Word의 단락에 설명 추가

Spire.Doc for .NET은 특정 단락에 주석을 추가하기 위한 Paragraph.AppendComment() 메서드를 제공합니다. 자세한 단계는 다음과 같습니다.

  • Document 클래스의 인스턴스를 초기화합니다.
  • Document.LoadFromFile() 메서드를 사용하여 Word 문서를 로드합니다.
  • Document.Sections[int] 속성을 통해 해당 인덱스로 문서의 특정 섹션에 액세스합니다.
  • Section.Paragraphs[int] 속성을 통해 해당 색인으로 섹션의 특정 단락에 액세스합니다.
  • Paragraph.AppendComment() 메서드를 사용하여 단락에 설명을 추가합니다.
  • Comment.Format.Author 속성을 통해 댓글 작성자를 설정합니다.
  • Document.SaveToFile() 메서드를 사용하여 결과 문서를 저장합니다.
  • C#
  • VB.NET
using Spire.Doc;
    using Spire.Doc.Documents;
    using Spire.Doc.Fields;
    
    namespace AddComments
    {
        internal class Program
        {
            static void Main(string[] args)
            {
                //Initialize an instance of the Document class
                Document document = new Document();
                //Load a Word document
                document.LoadFromFile(@"Sample.docx");
    
                //Get the first section in the document
                Section section = document.Sections[0];
    
                //Get the first paragraph in the section
                Paragraph paragraph = section.Paragraphs[0];
                //Add a comment to the paragraph
                Comment comment = paragraph.AppendComment("This comment is added using Spire.Doc for .NET.");
                //Set comment author
                comment.Format.Author = "Eiceblue";
                comment.Format.Initial = "CM";
    
                //Save the result document
                document.SaveToFile("AddCommentToParagraph.docx", FileFormat.Docx2013);
                document.Close();
            }
        }
    }

C#/VB.NET: Add, Reply to or Delete Comments in Word

C# 및 VB.NET에서 Word의 텍스트에 설명 추가

Paragraph.AppendComment() 메서드는 전체 단락에 주석을 추가하는 데 사용됩니다. 기본적으로 주석 표시는 단락 끝에 배치됩니다. 특정 텍스트에 주석을 추가하려면 Document.FindString() 메서드를 사용하여 텍스트를 검색한 다음 텍스트의 시작과 끝 부분에 주석 표시를 배치해야 합니다. 자세한 단계는 다음과 같습니다.

  • Document 클래스의 인스턴스를 초기화합니다.
  • Document.LoadFromFile() 메서드를 사용하여 Word 문서를 로드합니다.
  • Document.FindString() 메서드를 사용하여 문서에서 특정 텍스트를 찾습니다.
  • 찾은 텍스트의 시작과 끝 부분에 각각 배치될 주석 시작 표시와 주석 끝 표시를 만듭니다.
  • 새 댓글을 생성하려면 Comment 클래스의 인스턴스를 초기화하세요. 그런 다음 댓글의 내용과 작성자를 설정합니다.
  • 발견된 텍스트의 소유자 단락을 가져옵니다. 그런 다음 단락에 주석을 하위 개체로 추가합니다.
  • 텍스트 범위 앞에 주석 시작 표시를 삽입하고 텍스트 범위 뒤에 주석 끝 표시를 삽입합니다.
  • Document.SaveToFile() 메서드를 사용하여 결과 문서를 저장합니다.
  • C#
  • VB.NET
using Spire.Doc;
    using Spire.Doc.Documents;
    using Spire.Doc.Fields;
    
    namespace AddCommentsToText
    {
        internal class Program
        {
            static void Main(string[] args)
            {
                //Initialize an instance of the Document class
                Document document = new Document();
                //Load a Word document
                document.LoadFromFile(@"CommentTemplate.docx");
    
                //Find a specific string
                TextSelection find = document.FindString("Microsoft Office", false, true);
    
                //Create the comment start mark and comment end mark
                CommentMark commentmarkStart = new CommentMark(document);
                commentmarkStart.Type = CommentMarkType.CommentStart;
                CommentMark commentmarkEnd = new CommentMark(document);
                commentmarkEnd.Type = CommentMarkType.CommentEnd;
    
                //Create a comment and set its content and author
                Comment comment = new Comment(document);
                comment.Body.AddParagraph().Text = "Developed by Microsoft.";
                comment.Format.Author = "Shaun";
    
                //Get the found text as a single text range
                TextRange range = find.GetAsOneRange();
    
                //Get the owner paragraph of the text range
                Paragraph para = range.OwnerParagraph;
    
                //Add the comment to the paragraph
                para.ChildObjects.Add(comment);
    
                //Get the index of text range in the paragraph
                int index = para.ChildObjects.IndexOf(range);
    
                //Insert the comment start mark before the text range
                para.ChildObjects.Insert(index, commentmarkStart);
                //Insert the comment end mark after the text range
                para.ChildObjects.Insert(index + 2, commentmarkEnd);
    
                //Save the result document
                document.SaveToFile("AddCommentForText.docx", FileFormat.Docx2013);
                document.Close();
            }
        }
    }

C#/VB.NET: Add, Reply to or Delete Comments in Word

C# 및 VB.NET의 Word에서 주석에 응답

기존 댓글에 답글을 추가하려면 Comment.ReplyToComment() 메서드를 사용할 수 있습니다. 자세한 단계는 다음과 같습니다.

  • Document 클래스의 인스턴스를 초기화합니다.
  • Document.LoadFromFile() 메서드를 사용하여 Word 문서를 로드합니다.
  • Document.Comments[int] 속성을 통해 문서의 특정 설명을 가져옵니다.
  • 새 댓글을 생성하려면 Comment 클래스의 인스턴스를 초기화하세요. 그런 다음 댓글의 내용과 작성자를 설정합니다.
  • Comment.ReplyToComment() 메서드를 사용하여 특정 댓글에 대한 응답으로 새 댓글을 추가합니다.
  • Document.SaveToFile() 메서드를 사용하여 결과 문서를 저장합니다.
  • C#
  • VB.NET
using Spire.Doc;
    using Spire.Doc.Fields;
    
    namespace ReplyToComments
    {
        internal class Program
        {
            static void Main(string[] args)
            {
                //Initialize an instance of the Document class
                Document document = new Document();
                //Load a Word document
                document.LoadFromFile(@"AddCommentToParagraph.docx");
    
                //Get the first comment in the document
                Comment comment1 = document.Comments[0];
    
                //Create a new comment and specify its author and content
                Comment replyComment1 = new Comment(document);
                replyComment1.Format.Author = "Michael";
                replyComment1.Body.AddParagraph().AppendText("Spire.Doc is a wonderful Word library.");
    
                //Add the comment as a reply to the first comment
                comment1.ReplyToComment(replyComment1);
    
                //Save the result document
                document.SaveToFile("ReplyToComment.docx", FileFormat.Docx2013);
                document.Close();
            }
        }
    }

C#/VB.NET: Add, Reply to or Delete Comments in Word

C# 및 VB.NET의 Word에서 주석 삭제

Spire.Doc for .NET Word 문서에서 특정 주석을 제거하는 Document.Comments.RemoveAt(int) 메서드와 Word 문서에서 모든 주석을 제거하는 Document.Comments.Clear() 메서드를 제공합니다. 자세한 단계는 다음과 같습니다.

  • Document 클래스의 인스턴스를 초기화합니다.
  • Document.LoadFromFile() 메서드를 사용하여 Word 문서를 로드합니다.
  • Document.Comments.RemoveAt(int) 메서드 또는 Document.Comments.Clear() 메서드를 사용하여 문서의 특정 주석 또는 모든 주석을 삭제합니다.
  • Document.SaveToFile() 메서드를 사용하여 결과 문서를 저장합니다.
  • C#
  • VB.NET
using Spire.Doc;
    
    namespace DeleteComments
    {
        internal class Program
        {
            static void Main(string[] args)
            {
                //Initialize an instance of the Document class
                Document document = new Document();
                //Load a Word document
                document.LoadFromFile(@"AddCommentToParagraph.docx");
    
                //Delete the first comment in the document
                document.Comments.RemoveAt(0);
    
                //Delete all comments in the document
                //document.Comments.Clear();
    
                //Save the result document
                document.SaveToFile("DeleteComment.docx", FileFormat.Docx2013);
                document.Close();
            }
        }
    }

C#/VB.NET: Add, Reply to or Delete Comments in Word

임시 라이센스 신청

생성된 문서에서 평가 메시지를 제거하고 싶거나, 기능 제한을 없애고 싶다면 30일 평가판 라이센스 요청 자신을 위해.

또한보십시오