Skip to main content


  • 4 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 with a comment has a red triangular indicator in the corner. Handle the CustomDrawCommentIndicator event to customize an indicator’s appearance.


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.

An individual comment is represented by the Comment object and can be accessed by its index in the comment collection. The Comment object provides the following properties to specify a comment.

Property Description
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 comment text with specific formatting.


At present, the SpreadsheetControl does not support rich text formatting for comments. You can, however, use comment runs to add new information to a comment or change the existing comment text.

All runs for an individual comment are stored in the CommentRunCollection accessible via 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.

Delete 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.


End-User Restrictions

To restrict end-user actions over comments, use the SpreadsheetBehaviorOptions.Comment property, which provides access to restriction settings. The table below lists possible restrictions you can set to prevent modifications of comments in the SpreadsheetControl UI.

Restriction Description
SpreadsheetCommentBehaviorOptions.Insert Gets or sets whether a user can create new comments.
SpreadsheetCommentBehaviorOptions.Edit Gets or sets whether a user can edit the existing comments.
SpreadsheetCommentBehaviorOptions.Delete Gets or sets whether a user can delete comments.
SpreadsheetCommentBehaviorOptions.ShowHide Gets or sets whether a user can display or hide comments.
SpreadsheetCommentBehaviorOptions.ShowOnHover Gets or sets whether to show comments when a user hovers over a cell with a comment indicator.
SpreadsheetCommentBehaviorOptions.Resize Gets or sets whether a user can change the size of the comment box.
SpreadsheetCommentBehaviorOptions.Move Gets or sets whether a user can move comments to a new location.

Set the required property to DocumentCapability.Disabled or DocumentCapability.Hidden to disable or hide the corresponding command in the ribbon UI and the context menu.

See Also