How to Delete Comments from Word Document in Java

In this topic, we will learn how to delete comments from Word document in Java. The comments are usually used to write review notes or changes in the DOCX or DOC format files. This article contains step-by-step details and runnable sample code to remove comment section from Word in Java.

Steps to Delete Comments from Word Document in Java

  1. Configure Aspose.Words API from the repository to delete comments
  2. Load the input Word file with comments using the Document class
  3. Access all the comments collection in the document with NodeType class
  4. Remove the comments with the clear() method of NodeCollection class
  5. Write the output Word file

These steps describe how to remove comments on Microsoft Word in Java. You need to load the input word document with comments and get the comments collection with the NodeType.Comment property. In the next step, delete all of the comments and write the output word file.

Code to Delete Comments from Word Document in Java

This running code snippet answers the simple question of how to delete comment in Microsoft Word in Java. However, this code can be customized to filter the comments depending on the author’s name, date and time, text contents, etc. in order to process only specific comments. Moreover, we neither need to install Microsoft Word nor any other tool to work with this feature.

This tutorial has explained the details to remove comments on Word document in Java. If you are interested to explore the reverse feature to insert comments, head to the article on how to insert comment into Word document using Java.

 English