Introduction
In MS Excel, you must be familiar with the comments feature that allows users to add comments to cells. This feature is helpful in those cases when it is required to provide some information to the users when they are about to enter values into the cells. Whenever a user places his mouse cursor on a commented cell, a small popup message is appeared to provide some information to the user. Using Aspose.Grid.Desktop, developers can create comments on cells. In this topic, we will explain the usage of this feature in detail.
Managing Comments in a Worksheet
Adding Comments
To add a comment to a cell using Aspose.Grid.Desktop, please follow the steps below:
- Add Aspose.Grid.Desktop control to your Form
- Access any desired Worksheet
- Add Comment to the worksheet by specifying the cell (using its name or row & column number) in which the comment would be added
NOTE: Comments collection in the Worksheet object provides an overloaded Add method. Developers can use any overloaded version of Add method according to their specific needs.
Example:
[C#]
//Accessing first worksheet of the Grid
Worksheet sheet = gridDesktop1.Worksheets[0];
//Adding comment to "b2" cell
sheet.Comments.Add("b2", "Please write your name.");
//Adding another comment to "b4" cell using its row & column number
sheet.Comments.Add(3, 1, "Please write your email.")
[VB.NET]
'Accessing first worksheet of the Grid
Dim sheet As Worksheet = gridDesktop1.Worksheets(0)
'Adding comment to "b2" cell
sheet.Comments.Add("b2", "Please write your name.")
'Adding another comment to "b4" cell using its row & column number
sheet.Comments.Add(3, 1, "Please write your email.")
The output of above code snippet is displayed in the figure shown below:
|
Figure: Comments added to B2 & B4 cells
|
Accessing Comments
To access and modify an existing comment in the worksheet, developers can access the comment from the Comments collection of the Worksheet by specifying the cell (using cell name or its location in terms of row and column number) in which the comment is inserted. Once the comment is accessed, developers can modify its Text at runtime.
Example:
[C#]
//Accessing first worksheet of the Grid
Worksheet sheet = gridDesktop1.Worksheets[0];
//Accessing a comment added to "c3" cell (specified using its row & column number)
Comment comment1 = sheet.Comments[2, 2];
//Modifying the text of comment
comment1.Text = "The 1st comment.";
[VB.NET]
'Accessing first worksheet of the Grid
Dim sheet As Worksheet = gridDesktop1.Worksheets(0)
'Accessing a comment added to "c3" cell (specified using its row & column number)
Dim comment1 As Comment = sheet.Comments(2, 2)
'Modifying the text of comment
comment1.Text = "The 1st comment."
Removing Comments
To remove an existing comment, developers can simply access a desired worksheet and then Remove comment from the Comments collection of the Worksheet by specifying the cell (using its name or row & column number) containing comment.
Example:
[C#]
//Accessing first worksheet of the Grid
Worksheet sheet = gridDesktop1.Worksheets[0];
//Removing comment from "c3" cell
sheet.Comments.Remove(2, 2);
[VB.NET]
'Accessing first worksheet of the Grid
Dim sheet As Worksheet = gridDesktop1.Worksheets(0)
'Removing comment from "c3" cell
sheet.Comments.Remove(2, 2)