Comments are used to add additional information or to explain a formula in the Excel worksheet. MS Excel also allows you to set the font size, height, width, etc. of the comments. In this article, you will learn how to add comments to the Excel files in Java. Furthermore, the article will also cover how to format the comments.
- API to Add Comments in Excel
- Easy Steps to Add Comments in Excel
- Add Comments in an Excel Worksheet
- Apply Formatting to Comments in Excel
- Free Online Excel App to Add Comments
Java API to Add Comments in Excel Files
In order to add comments to the cells in Excel worksheets, we will use Aspose.Cells for Java. The API lets you create, modify, and convert Excel files from within your Java applications. You can either download the API or install it using the following Maven configurations.
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>https://repository.aspose.com/repo/</url>
</repository>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-cells</artifactId>
<version>23.4</version>
</dependency>
How to Add Comments in an Excel File
Using Aspose.Cells for Java, you can add comments to the Excel files within a few steps. The following steps give an overview of how to insert comments to a worksheet in an Excel file.
- Load the Excel file from the disk.
- Access the desired worksheet.
- Add comment to the desired cell.
- Save the Excel file.
Now, let’s have a look at how to transform the above-mentioned steps into code and add comments in an Excel file in Java.
Add Comments in Excel File in Java
The following are the steps to add a comment to a cell in an Excel file in Java.
- Load the Excel file using Workbook class.
- Get reference of the desired Worksheet using Workbook.getWorksheets().get(index) method.
- Add comment to the cell using Worksheet.getComments().add(string cellName) method and get the reference of the comment in a Comment object.
- Set comment’s note using Comment.setNote() method.
- Save the updated Excel file using Workbook.save(string) method.
The following code sample shows how to insert a comment in an Excel file in Java.
Add Comments in Excel with Formatting
The following are the steps to apply formatting to the comments in Excel in Java.
- Load the Excel file using Workbook class.
- Get reference of the desired Worksheet using Workbook.getWorksheets().get(index) method.
- Add comment to the cell using Worksheet.getComments().add(string cellName) method and get the reference of the comment in a Comment object.
- Set comment’s note using Comment.setNote() method.
- Set the desired formatting of the comment using Comment object.
- Save the updated Excel file using Workbook.save(string) method.
The following code sample shows how to set formatting of the comments in Excel.
Free Online Excel App to Add Comments
You can use our free online Excel editor app to insert comments in Excel files. This application is based on Aspose.Cells and you can use it from anywhere only having an internet connection.
Get a Free License
You can use Aspose.Cells for Java without evaluation limitations using a temporary license.
Conclusion
In this article, you have learned how to add comments to the cells in Excel files in Java. Furthermore, you have seen how to apply formatting to the comments programmatically. You can visit the documentation to explore other features of Aspose.Cells for Java. In case you would have any queries, feel free to post to our forum.