[]
A comment is a note or a type of annotation which is usually added to a document when a user wants to add remarks, notes, reminder, or a feedback to it. For instance, when multiple users work on the same document, it becomes easy for them to leave a note, remarks or feedback for each other’s reference.
In GcWord, comments are represented by the Comment class. It allows you to modify the content and other properties of the comments, such as, author, date of the comment, etc. GcWord allows you to add or insert comments in a Word document using Add or Insert method of the CommentCollection class respectively. In addition, it lets you add and delete the comment replies as well. You can use Reply method of the Comment class to add a new comment as a reply into the comments collection and the Delete method to delete it.
To add comments in a document:
Access the content object on which you want to add a comment. For example, access the first paragraph.
Access the comment collection using Comments property of the RangeBase class.
Add a comment to the paragraph using Add method of the CommentCollection class.
doc.Load("CommentInWord.docx");
//Access the first paragraph
Paragraph par = doc.Body.Sections.First.GetRange().Paragraphs[0];
//Add comment
Comment c=par.GetRange().Comments.Add("CommentByCode","GC");
//Save the document
doc.Save("AddComment.docx");
To modify a comment through code:
Access a comment from the comment collection using the Comments property. For example, access the first comment.
Get the property of the comment you want to modify. For example, access Author and Initials properties of the first comment.
Modify the value of the properties. For example, set value of the Author property to GcWordUser and Initials property to G.C.W.
doc.Load("AddComment.docx");
//Access the first paragraph
Paragraph par = doc.Body.Sections.First.GetRange().Paragraphs[0];
//Modify the first comment's author and initials
par.GetRange().Comments[0].Author = "GcWordUser";
par.GetRange().Comments[0].Initials = "G.C.W";
//Mark the comment reply as closed
par.GetRange().Comments[0].Done = true;
doc.Save("ModifiedComment.docx");
To delete a comment:
Access a comment from the comment collection using the Comments property. For example, access the fourth comment in the document.
Delete the comment using Delete method of the Comment class.
doc.Load("CommentInWord.docx");
//Delete the second comment
doc.Body.Comments[3].Delete();
doc.Save("DeleteComment.docx");
To add a reply on a comment:
Access a comment from the comment collection using the Comments property. For example, access the second comment.
Add a new comment in the comment collection as a reply for the accessed comment using Reply method of the Comment class.
doc.Load("CommentInWord.docx");
//Add comment reply for the last comment in the document
doc.Body.Comments.Last.Reply("Reply Comment", "Grapecity");
//Add a comment reply
Comment cReply = c.Reply("Reply of the added comment", "GC");
//Mark the comment reply as closed
cReply.Done = true;
//Save the document
doc.Save("AddComment.docx");
To delete a reply on the comment:
Access a reply comment using Replies property of the Comment class. For example, access first reply of the first comment.
Delete the comment reply using Delete method of the Comment class.
//Delete first comment's first reply
doc.Body.Comments.First.Replies[0].Delete();
doc.Save("DelComment.docx");
For more information on how implement comments using GcWord, see GcWord sample browser.