# Comments

DsExcel allows you to add comments to a cell, set comment layout, show or hide comment, author comments, and more.

## Content

DsExcel Java enables you to annotate a worksheet by writing comments on cells in order to specify additional information about the data it contains.
For instance, let us assume you want to enter only the numeric information in an individual cell of a worksheet. To accomplish this, instead of populating a small cell with large notes, it is more ideal to use a short comment (something like "Please enter only numeric characters in this cell") in order to provide additional context for the data represented in that cell.
The cells annotated with comments will display a small red indicator (at the corner of the cell) which appear when your mouse pointer is placed on that particular cell. The text in the comments can be edited, copied and formatted. Also, the comments can be moved, resized or deleted, can be made hidden or visible and their indicators can also be customized as per your preferences.
![Comment](https://cdn.mescius.io/document-site-files/images/dd59ea42-cd61-4fa6-a018-6231c2a9c598/images/comment.png)
The following tasks can be performed while applying comments in cells of a spreadsheet:

* [Add comment to a cell](#add-comment-to-a-cell)
* [Set comment layout](#set-comment-layout)
* [Show/Hide comment](/document-solutions/java-excel-api/docs/online/Features/Comments#show/hide-comment)
* [Author comments](#author-comments)
* [Set rich text for comment](#set-rich-text-for-comment)
* [Delete comment](#delete-comment)

## Add comment to a cell

In DsExcel Java, a cell comment instance is represented by the [IComment](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/IComment.html) interface. You can insert comment to a cell or a range of cells using the [addComment](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/IRange.html#addComment) method of the [IRange](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/IRange.html) interface. You can also set the text of the comment using the [setText](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/IComment.html#setText) method of the [IComment](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/IComment.html) interface.
Refer to the following example code to add comment to a cell.

```Java
// Add new comments 
IComment commentC3 = worksheet.getRange("C3").addComment("Range C3's comment.");
IComment commentC4 = worksheet.getRange("C4").addComment("Range C4's comment.");
IComment commentC5 = worksheet.getRange("C5").addComment("Range C5's comment.");
        
// Change the text of a comment.
commentC3.setText("New Comment for Range C3.");
```

## Set comment layout

You can configure the layout of the comment added to an individual cell or a range of cells using [getShape](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/IComment.html#getShape) method of the [IComment](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/IComment.html) interface.
Refer to the following example code to set comment layout.

```Java
IComment commentC3 = worksheet.getRange("C3").addComment("Range C3's comment.");
// Configure comment layout
commentC3.getShape().getLine().getColor().setRGB(Color.GetGreen());
commentC3.getShape().getLine().setWeight(7);
commentC3.getShape().getLine().setStyle(LineStyle.ThickThin);
commentC3.getShape().getLine().setDashStyle(LineDashStyle.Solid);
commentC3.getShape().getFill().getColor().setRGB(Color.GetGray());
commentC3.getShape().setWidth(100);
commentC3.getShape().setHeight(200);
commentC3.getShape().getTextFrame().getTextRange().getFont().setBold(true);
commentC3.setVisible(true);
```

## Show/Hide comment

You can choose to keep comments hidden or visible by using the [setVisible](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/IComment.html#setVisible) method of the [IComment](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/IComment.html) interface.
In order to show/hide comment added to a cell, refer to the following example code.

```Java
// Add comment.
IComment commentC3 = worksheet.getRange("C3").addComment("Range C3's comment.");
// Show comment
commentC3.setVisible(true);
// Hide comment
commentC3.setVisible(false);
```

## Author comments

You can represent the author of the comment by using the [getAuthor](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/IComment.html#getAuthor) method of the [IComment](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/IComment.html) interface. Also, you can use this method to change the author of an existing comment.
In order to set comment author for a cell, refer to the following example code.

```Java
// Set comment author
workbook.setAuthor("joneshan");        
IWorksheet worksheet = workbook.getWorksheets().get(0);
worksheet.getRange("C3").addComment("Range C3's comment.");
// C3's comment author is "joneshan'
String authorC3 = worksheet.getRange("C3").getComment().getAuthor();
System.out.println(authorC3);
```

## Set rich text for comment

You can set the rich text for the comment using the methods of the [ITextFrame](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/drawing/ITextFrame.html) interface that control the text style.
In order to set rich text for the comment, refer to the following example code.

```Java
// Add a new comment
IComment commentC3 = worksheet.getRange("C3").addComment("Range C3's comment.");

// Configure the paragraph style using Rich Text and Text Frame.
commentC3.getShape().getTextFrame().getTextRange().getParagraphs().get(0).getFont().setBold(true);
commentC3.getShape().getTextFrame().getTextRange().getParagraphs().get(0).getRuns().add("ccc", 0);
commentC3.getShape().getTextFrame().getTextRange().getParagraphs().get(0).getRuns().add("eee", 1);
commentC3.getShape().getTextFrame().getTextRange().getParagraphs().get(0).getRuns().add("ddd");
commentC3.getShape().getTextFrame().getTextRange().getParagraphs().get(0).getRuns().get(2).getFont()
        .setItalic(true);
commentC3.getShape().getTextFrame().getTextRange().getParagraphs().get(0).getRuns().get(2).getFont().getColor()
        .setRGB(Color.GetGreen());
```

## Delete comment

You can delete the comment added to a cell or to a cell range using the [delete](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/IComment.html#delete) method of the [IComment](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/IComment.html) interface and the [IRange](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/IRange.html) interface respectively.
In order to delete comment from a cell, refer to the following example code.

```Java
// Add comments
 worksheet.getRange("C3").addComment("Range C3's comment.");
 worksheet.getRange("D4").addComment("Range D4's comment.");
 worksheet.getRange("D5").addComment("Range D5's comment.");

// Delete a single cell comment
 worksheet.getRange("D5").getComment().delete();

// Clear multiple comments from a range of cells 
 worksheet.getRange("C3:D4").clearComments();
```