Manage Comments in Worksheet
Contents
[
Hide
]
This topic discusses adding, accessing and removing comments from worksheets. Comments are useful for adding notes or useful information for users who will work with the sheet. Developers have the flexibility to add comments to any cell of the worksheet.
Working with Comments
Adding Comments
To add a comment to worksheet, please follow the steps below:
- Add the Aspose.Cells.GridWeb control to the Web Form.
- Access the worksheet you’re adding comments to.
- Add a comment to a cell.
- Set a note for the new comment.
A comment has been added to the worksheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Accessing the reference of the worksheet that is currently active and add a dummy value to cell A1 | |
GridWorksheet sheet = GridWeb1.WorkSheets[GridWeb1.ActiveSheetIndex]; | |
sheet.Cells["A1"].PutValue("This cell has a comment added, hover to view."); | |
// Resize first column | |
sheet.Cells.SetColumnWidth(0, 140); | |
// Adding comment to "A1" cell of the worksheet | |
GridComment comment = sheet.Comments[sheet.Comments.Add("A1")]; | |
// Setting the comment note | |
comment.Note = "These are my comments for the cell"; |
Accessing Comments
To access a comment:
- Access the cell that contains the comment.
- Get the cell’s reference.
- Pass the reference to the Comment collection’s to access the comment.
- It’s now possible to modify the comment’s properties.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Accessing the reference of the worksheet that is currently active | |
GridWorksheet sheet = GridWeb1.WorkSheets[GridWeb1.ActiveSheetIndex]; | |
// Accessing a specific cell that contains comment | |
GridCell cell = sheet.Cells["A1"]; | |
// Accessing the comment from the specific cell | |
GridComment comment = sheet.Comments[cell.Name]; | |
if (comment != null) | |
{ | |
// Modifying the comment note | |
comment.Note = "I have modified the comment note."; | |
} |
Removing Comments
To remove a comment:
- Access the cell as explained above.
- Use the Comment collection’s RemoveAt method to remove the comment.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Accessing the reference of the worksheet that is currently active | |
GridWorksheet sheet = GridWeb1.WorkSheets[GridWeb1.ActiveSheetIndex]; | |
// Accessing a specific cell that contains comment | |
GridCell cell = sheet.Cells["A1"]; | |
// Removing comment from the specific cell | |
sheet.Comments.RemoveAt(cell.Name); |