- 2 minutes to read
A comment is a note that you attach to a cell, separate from other cell content. Comments can make a worksheet easier to understand by providing additional context for the data it contains.
The image below illustrates how a comment is displayed in Microsoft® Excel®.
A worksheet stores comments in the CommentCollection object that is accessed via the Worksheet.Comments property. The CommentCollection interface provides the basic methods to work with comments. For example, to add a comment to a cell, use the CommentCollection.Add method (see How To: Add a Comment To a Cell example). To delete an individual comment from the collection, use the CommentCollection.Remove or CommentCollection.RemoveAt method. To delete all comments from the worksheet, use CommentCollection.Clear method.
Each comment is represented by the Comment object, which provides the following properties to specify a comment.
|Comment.Author||Gets or sets the author of the comment.|
|Comment.Text||Gets or sets the comment text.|
|Comment.Runs||Provides access to the comment text regions, each of which has specific formatting.|
|Comment.Reference||Returns an absolute reference to the commented cell.|
|Comment.Visible||Specifies whether the comment should be displayed in a cell.|
Comment text is grouped into one or more runs. Each run is specified by the CommentRun object and defines a region of the comment text with its own set of font characteristics. Use the CommentRun.Text property to define the text region within a comment, to which you want to apply specific formatting (CommentRun.Font).
When you create a new comment via the CommentCollection.Add method or set the Comment.Text of an existing comment, the CommentRunCollection collection includes a single run that holds the full text of the comment formatted with the default font. You can access this run object and change the font to be applied to the comment text.
The CommentRunCollection interface provides methods to operate with comment runs. To add a new comment run, use the CommentRunCollection.Add method (see How To: Add a Comment To a Cell example). To delete the specified comment run from the collection, use the CommentRunCollection.Remove or CommentRunCollection.RemoveAt method. To delete all text from the comment, use the CommentRunCollection.Clear method.