Comments are used in word documents, DOCX or DOC, for suggesting improvements and modifications. Let us explore how to insert comments as well as deleting or removing comments programmatically using Java. You can add author name, initials, comment text, date, and time based on your requirements. We will be performing all of these tasks using Aspose.Words for Java API.
Here we will be learning following use cases related to comments in word documents:
Insert or Delete Comments in Word files (DOCX/DOC) API – Installation
You can download the latest version of Aspose.Words for Java API from Downloads section or from Maven repository, as per the configurations mentioned below:
So the API has been configured now and we can proceed to explore different use cases of working with comments in Word documents.
Insert Comment in Existing Word Document using Java
You can insert or add comments in existing Microsoft Word files, DOCX or DOC, with Aspose.Words for Java API. This can be helpful when reviewing documents, like a supervisor can suggest several changes or improvements on a feasibility report. Moreover, anyone with edit permissions of a word document can work with comments. You need to follow the steps below to insert comments in word file (DOCX/DOC):
Load existing DOCX file with Document class
Create a comment
Save DOCX file
The following code snippet shows how to insert a comment in Word document using Java:
Below screenshot shows a sample comment added in existing Word documents:
Insert Comment in new Word Document using Java
Comments are also helpful when creating a new word document. For instance, some text may need elaboration which can be explained with the help of comment. Likewise, there could be hundreds of use cases where comments can assist while creating a new DOCX file. You can easily add or insert comments by following the steps below:
Initialize DocumentBuilder object
Add sample text
Create a custom comment
Save DOCX file
The code snippet below shows how to insert comments while creating a new word document from scratch, using Java:
The screenshot below shows the output where the comment is added on new word document:
Delete Specific Comments from Word Document using Java
Comments are often deleted when suggested improvements or modifications are incorporated into the word document. When you need to delete specific comments then you can follow the steps below:
Load source word document
Specify author name
Remove comments from the specified author
The code snippet below shows how to delete specific comments from word file using Java:
Delete All Comments from Word Documents using Java
All comments of Word document can be deleted at once. You can follow the steps below for removing all comments:
Open word docx file
Collect all comments in the file
Delete all comments
Following code snippet elaborates how to delete all comments from Word documents using Java:
Conclusion
To sum up, we have learned how to add, insert, delete, or remove comments from word documents programmatically with Java. If you have any doubts or confusion then please contact us at Free Support Forum.
Insert or Delete Comments in Word (DOCX/DOC) using Java
Comments are used in word documents, DOCX or DOC, for suggesting improvements and modifications. Let us explore how to insert comments as well as deleting or removing comments programmatically using Java. You can add author name, initials, comment text, date, and time based on your requirements. We will be performing all of these tasks using Aspose.Words for Java API.
Here we will be learning following use cases related to comments in word documents:
Insert or Delete Comments in Word files (DOCX/DOC) API – Installation
You can download the latest version of Aspose.Words for Java API from Downloads section or from Maven repository, as per the configurations mentioned below:
Repository
Dependency
So the API has been configured now and we can proceed to explore different use cases of working with comments in Word documents.
Insert Comment in Existing Word Document using Java
You can insert or add comments in existing Microsoft Word files, DOCX or DOC, with Aspose.Words for Java API. This can be helpful when reviewing documents, like a supervisor can suggest several changes or improvements on a feasibility report. Moreover, anyone with edit permissions of a word document can work with comments. You need to follow the steps below to insert comments in word file (DOCX/DOC):
The following code snippet shows how to insert a comment in Word document using Java:
Below screenshot shows a sample comment added in existing Word documents:
Insert Comment in new Word Document using Java
Comments are also helpful when creating a new word document. For instance, some text may need elaboration which can be explained with the help of comment. Likewise, there could be hundreds of use cases where comments can assist while creating a new DOCX file. You can easily add or insert comments by following the steps below:
The code snippet below shows how to insert comments while creating a new word document from scratch, using Java:
The screenshot below shows the output where the comment is added on new word document:
Delete Specific Comments from Word Document using Java
Comments are often deleted when suggested improvements or modifications are incorporated into the word document. When you need to delete specific comments then you can follow the steps below:
The code snippet below shows how to delete specific comments from word file using Java:
Delete All Comments from Word Documents using Java
All comments of Word document can be deleted at once. You can follow the steps below for removing all comments:
Following code snippet elaborates how to delete all comments from Word documents using Java:
Conclusion
To sum up, we have learned how to add, insert, delete, or remove comments from word documents programmatically with Java. If you have any doubts or confusion then please contact us at Free Support Forum.
See Also
Word Document (DOC/DOCX) to HTML Conversion using Java
This entry was posted in Aspose.Words Product Family and tagged delete comments in word, insert comments in word, insert comments in word java, remove comments in words. .