[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Collapse]Office File API
  Demo Application
  Redistribution and Deployment
 [Collapse]Spreadsheet Document API
   Product Structure
   Getting Started
  [Expand]Spreadsheet Document
   Supported Formats
  [Expand]Cell Basics
  [Expand]Spreadsheet Formulas
   Defined Names
   Data Binding
  [Expand]Pivot Tables
  [Expand]Shapes, Pictures, Charts
  [Expand]Mail Merge
  [Collapse]Examples
   [Expand]Files
   [Expand]Workbooks
   [Expand]Worksheets
   [Expand]Rows and Columns
   [Collapse]Cells
     How to: Access a Cell in a Worksheet
     How to: Access a Range of Cells
     How to: Insert a Cell or Cell Range
     How to: Delete a Cell or Range of Cells
     How to: Create a Named Range of Cells
     How to: Change a Cell or Cell Range Value
     How to: Add Formulas to Cells
     How to: Add a Hyperlink to a Cell
     How To: Add a Comment To a Cell
     How to: Clear Cells of Content, Formatting, Hyperlinks and Comments
     How to: Copy Cell Data Only, Cell Style Only, or Cell Data with Style
     How to: Merge Cells or Split Merged Cells
   [Expand]Formulas
   [Expand]Import and Export Data
   [Expand]Data Binding
    Sorting
   [Expand]Mail Merge
    Search
   [Expand]Shapes
   [Expand]Charts
   [Expand]Sparklines
   [Expand]Formatting Cells
   [Expand]Conditional Formatting
   [Expand]Grouping
   [Expand]Filtering
   [Expand]Tables
   [Expand]Pivot Tables
   [Expand]Printing
   [Expand]Pictures
   [Expand]Protection
 [Expand]Word Processing Document API
 [Expand]PDF Document API
 [Expand]Excel Export Library
 [Expand]Snap Report API
 [Expand]Zip Compression and Archive API
 [Expand]Barcode Generation API
 [Expand]Unit Conversion API
 [Expand]API Reference
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

How To: Add a Comment To a Cell

This example demonstrates how to add a comment to a cell and format the comment text.

  1. To create a new comment and associate it with a cell, access the worksheet's collection of cell comments from the Worksheet.Comments property and call the CommentCollection.Add method. Pass the following parameters:

    • a Cell object that specifies the cell to be commented;
    • a string that specifies the author of the comment. In this example, the system username is used. Access it from the Workbook.CurrentAuthor property;
    • a string that specifies the text of the comment.
  2. To apply different fonts to specific regions of the comment text, modify the CommentRunCollection collection, which is accessed from the Comment.Runs property. This collection stores the CommentRun objects (comment runs) that define regions of the comment text that are formatted specifically. After a comment has been created, its text is defined by a single run that is contained in the CommentRunCollection collection.

    Add more runs to the comment.

    • Insert the author's name at the beginning of the comment text (using the CommentRunCollection.Insert method) and format it as bold.
    • Access the comment text that was added initially. It is now defined by the second run in the collection of the comment runs. Modify font characteristics for this text region.
    • Add one more run to the end of the comment text using the CommentRunCollection.Add method.

As you can see, cell comments can be formatted using methods of the CommentRunCollection object.

To remove comments from cells, use the CommentCollection.Remove, CommentCollection.RemoveAt, CommentCollection.Clear or Worksheet.ClearComments methods.

The image below shows the comment (the workbook is opened in Microsoft® Excel®).

Is this topic helpful?​​​​​​​