- 3 minutes to read
The SpreadsheetControl allows you to attach notes to individual cells by using comments. Comments are extremely useful when you need to provide additional information, such as reminders, notifications, or feedback in a document without modifying cell content.
Comments are stored separately from a cell and displayed in a floating text box. A cell containing a comment has a red triangular indicator in the corner.
See Online Demo: Comments
Select the action you wish to perform.
Add a Comment
All comments embedded in a worksheet are stored in the comment collection (CommentCollection), which can be accessed by using the Worksheet.Comments property. The CommentCollection interface provides the basic methods to work with comments. Use the CommentCollection.Add method to attach a comment to a cell. For an example, refer to How to: Create, Edit and Copy Cell Comments.
|Comment.Author||Gets or sets the author of the comment.|
|Comment.Text||Gets or sets the comment text.|
|Comment.Runs||Provides access to the separate text regions of the comment.|
|Comment.Reference||Gets an absolute reference to the commented cell.|
|Comment.Visible||Specifies whether the comment should always be displayed in the UI.|
Edit a Comment
Comment text consists of one or more comment runs. Each run is represented by the CommentRun object and defines a region of the comment text with specific formatting. Currently, the SpreadsheetControl does not support text formatting for comments. However, you can use comment runs to change the text of the existing comments or add new text blocks to them.
All runs for an individual comment are stored in the CommentRunCollection accessible using the Comment.Runs property. After a comment is created, its text is defined by a single run contained in the collection. Use the collection’s CommentRunCollection.Add and CommentRunCollection.Insert methods to add new text to the required comment. To edit the text of the existing comment run, get access to this run by its index in the collection and utilize the CommentRun.Text property. To replace the text of the entire comment, use the Comment.Text property.
For an example, refer to How to: Create, Edit and Copy Cell Comments.
Copy a Comment
To copy a comment to another cell, call the CellRange.CopyFrom method for the target cell into which you wish to insert the comment. Pass the PasteSpecial.Comments enumerator value as a parameter to copy the comment only and ignore cell content. The copied comment will replace any existing comment contained in the target cell. For an example, refer to How to: Create, Edit and Copy Cell Comments.
To delete an individual comment from the collection, use the CommentCollection.Remove or CommentCollection.RemoveAt method. To remove comments from a specified range of cells, utilize the Worksheet.ClearComments method. To delete all comments from a worksheet, use the CommentCollection.Clear method. For an example, refer to How to: Clear Cells of Content, Formatting, Hyperlinks and Comments.
Manage Comments in the UI
End-users can insert, edit, hide or delete comments using one of the following ways.
Via the ribbon UI (by using the commands located in the Comments group of the Review tab)
Via the context menu
Moreover, end-users can resize a comment or move it to a new location by using the sizing handles (small rectangles at the corners and sides of the comment box) visible for a selected comment.