Microsoft Word provides you the ability to add comments to Word documents. Comments can be helpful in cases such as suggesting improvements in documents or sharing thoughts on the text. There might be situations where you need to manage comments programmatically. To that end, this article will teach you how to work with comments in Word documents using C++.

C++ API for Working with Comments in Word Documents

Aspose.Words for C++ is a native C++ library that allows you to create, read, modify and convert Microsoft Word documents. In addition, it also supports working with comments in DOCX and DOC files. You can either install the API through NuGet or download it directly from the Downloads section.

PM> Install-Package Aspose.Words.Cpp

Add Comments to Word Documents using C++

Aspose.Words for C++ API provides the ability to add comments with the author name, initials, and date/time. The following are the steps to add comments to Word documents.

The following sample code demonstrates how to add comments to Word documents using C++.

The following is the image of the output generated by the sample code.

Image of the output generated by the sample code

Read Comments from a Word Document

The following are the steps to read comments from Word documents.

The following is the sample code to read comments from a Word document using C++.

Modify Comments in a Word Document using C++

In order to modify a comment, retrieve it using the NodeCollection->idx_get(int32_t index) method and change it according to your needs. The following are the steps to modify comments in a Word document.

The following sample code shows how to modify comments in a Word document using C++.

Delete Comments from a Word Document using C++

The Aspose.Words for C++ API provides multiple ways to delete comments from Word documents. In this section, you will learn how to delete a specific comment, comments by author, and all comments using C++.

Delete a Specific Comment

The following are the steps to delete a specific comment.

The following sample code shows how to delete a specific comment from a Word document using C++.

Deleting Comments by Author

The following are the steps to delete comments by author.

The following is the sample code to delete comments by author using C++.

Delete All Comments

Instead of deleting individual comments, you can delete all the comments at once using the NodeCollection->Clear() method. The following are the steps to delete all comments from a Word document.

The following sample code demonstrates how to delete all the comments from a Word document using C++.

Get a Free License

You can try the API without evaluation limitations by requesting a free temporary license.

Conclusion

In this article, you have learned how to work with comments in Word documents using C++. Specifically, you have learned how to add, read, edit and delete comments. Furthermore, you have seen how to delete a specific comment, comments by author, and all comments using Aspose.Words for C++ API. The API provides a vast number of additional features for automating your Word-related tasks. You can explore the API in detail by visiting the official documentation. In case of any questions, please feel free to reach us on our free support forum.

See Also