officefileapi-devexpress-dot-spreadsheet-dot-comment.md
Obtains the collection of note text regions, each formatted with its own font.
Namespace : DevExpress.Spreadsheet
Assembly : DevExpress.Spreadsheet.v25.2.Core.dll
NuGet Package : DevExpress.Spreadsheet.Core
CommentRunCollection Runs { get; }
ReadOnly Property Runs As CommentRunCollection
| Type | Description |
|---|---|
| CommentRunCollection |
A collection of note runs.
|
Note text is grouped into one or more runs. Each run is specified by the CommentRun object and defines a region of the note text (CommentRun.Text) with its own set of font characteristics (CommentRun.Font). The Runs property returns the CommentRunCollection collection that stores note runs.
When you create a new note or set Text of an existing comment, the CommentRunCollection collection includes a single run that holds the full text of the note formatted with the default font. You can obtain this run object and change the font to be applied to the note text.
You can add more runs into the Runs collection to divide the note text into regions and specify font properties for each text region.
Important
The WinForms and WPF Spreadsheet controls do not support rich text within a note. 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 simple note (a legacy comment) to a cell and format the note text.
To create a new note and associate it with a cell, access the worksheet’s collection of notes from the Worksheet.Comments property and call the CommentCollection.Add method.
To apply different fonts to specific regions of the comment text, modify the CommentRunCollection collection returned by the Comment.Runs property. This collection stores the CommentRun objects 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.
using DevExpress.Spreadsheet;
//...
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
// 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[0].Font.Bold = true;
// Format the comment text.
runs[1].Font.Color = Color.Red;
runs[1].Font.Name = "Times New Roman";
runs[1].Font.Size = 14;
runs[1].Font.Italic = true;
// Add a new comment run.
runs.Add("\n Never delete this comment!");
runs[2].Font.Color = Color.MidnightBlue;
Imports DevExpress.Spreadsheet
'...
Dim workbook As New Workbook()
Dim worksheet As Worksheet = workbook.Worksheets(0)
'Get the system username.
Dim author As String = workbook.CurrentAuthor
'Add a comment to the A1 cell.
Dim cell As Cell = worksheet.Cells("A1")
Dim comment As Comment = worksheet.Comments.Add(cell, author, "This is important information for users.")
'Add the author name at the beginning of the comment.
Dim runs As CommentRunCollection = comment.Runs
runs.Insert(0, author & ": " & Constants.vbCrLf)
runs(0).Font.Bold = True
'Format the comment text.
runs(1).Font.Color = Color.Red
runs(1).Font.Name = "Times New Roman"
runs(1).Font.Size = 14
runs(1).Font.Italic = True
'Add a new comment run.
runs.Add(Constants.vbLf & "Never delete this comment!")
runs(2).Font.Color = Color.MidnightBlue
Use the following methods to remove simple notes:
The following code snippets (auto-collected from DevExpress Examples) contain references to the Runs property.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.
// Insert the author's name at the beginning of the comment.
CommentRunCollection commentRunsA2 = commentA2.Runs;
commentRunsA2.Insert(0, author + ": \r\n");
winforms-spreadsheetcontrol-api-part1/VB/SpreadsheetControl/SpreadsheetActions/CellActions.vb#L441
' Insert the author's name at the beginning of the comment.
Dim commentRunsA2 As CommentRunCollection = commentA2.Runs
commentRunsA2.Insert(0, author & ": " & ControlChars.CrLf)
' Insert the author's name at the beginning of the comment.
Dim commentRunsA2 As CommentRunCollection = commentA2.Runs
commentRunsA2.Insert(0, author & ": " & ControlChars.CrLf)
See Also