Provides access to the collection of comment text regions, each formatted with its own font.
A CommentRunCollection object specifying a collection of comment runs.
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 (CommentRun.Text) with its own set of font characteristics (CommentRun.Font). The Runs property returns the CommentRunCollection collection that stores comment runs.
When you create a new comment via the CommentCollection.Add method or set 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.
You can add more runs into the Runs collection to divide the comment text into regions and specify font properties for each text region.
The WinForms and WPF Spreadsheet controls do not support rich text within a comment at present. Rich format settings, however, are saved to a file, so you can use another spreadsheet application that can display rich text (e.g., Microsoft® Excel®) to view such comments.
This example demonstrates how to add a comment to a cell and format the comment text.
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:
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.
using DevExpress.Spreadsheet; //... Workbook workbook = new Workbook(); Worksheet worksheet = workbook.Worksheets; //Get the system username. string author = workbook.CurrentAuthor; //Add a comment to the A1 cell. Cell cell = worksheet.Cells["A1"]; Comment comment = worksheet.Comments.Add(cell, author, "This is important information for users."); //Add the author name at the beginning of the comment. CommentRunCollection runs = comment.Runs; runs.Insert(0, author + ": \r\n"); runs.Font.Bold = true; //Format the comment text. runs.Font.Color = Color.Red; runs.Font.Name = "Times New Roman"; runs.Font.Size = 14; runs.Font.Italic = true; //Add a new comment run. runs.Add("\n Never delete this comment!"); runs.Font.Color = Color.MidnightBlue;