In Word 2013 and later version, you can reply to a comment, so it's easier to follow the whole conversation. Spire.Doc also allows programmers to insert a comment as a reply to a selected comment through ReplyToComment method.
Step 1: Create an object of Document and load a Word document containing comments.
Document doc = new Document(); doc.LoadFromFile("Comment.docx");
Step 2: Get the first comment.
Comment comment = doc.Comments[0];
Step 3: Create a new comment and specify the author and content.
Comment replyComment = new Comment(doc); replyComment.Format.Author = "Adam"; replyComment.Body.AddParagraph().AppendText("Exactly.");
Step 4: Add the new comment as a reply to the selected comment.
comment.ReplyToComment(replyComment);
Step 5: Save to file.
doc.SaveToFile("ReplyToComment.docx", FileFormat.Docx2013);
Full Code:
[C#]
using Spire.Doc; using Spire.Doc.Fields; namespace ReplyComment { class Program { static void Main(string[] args) { Document doc = new Document(); doc.LoadFromFile("Comment.docx"); Comment comment = doc.Comments[0]; Comment replyComment = new Comment(doc); replyComment.Format.Author = "Adam"; replyComment.Body.AddParagraph().AppendText("Exactly."); comment.ReplyToComment(replyComment); doc.SaveToFile("ReplyToComment.docx", FileFormat.Docx2013); } } }
[VB.NET]
Imports Spire.Doc Imports Spire.Doc.Fields Namespace ReplyComment Class Program Private Shared Sub Main(args As String()) Dim doc As New Document() doc.LoadFromFile("Comment.docx") Dim comment As Comment = doc.Comments(0) Dim replyComment As New Comment(doc) replyComment.Format.Author = "Adam" replyComment.Body.AddParagraph().AppendText("Exactly.") comment.ReplyToComment(replyComment) doc.SaveToFile("ReplyToComment.docx", FileFormat.Docx2013) End Sub End Class End Namespace