Specifies the font of the current comment run.
Namespace: DevExpress.Spreadsheet
Assembly: DevExpress.Spreadsheet.v19.2.Core.dll
Type | Description |
---|---|
SpreadsheetFont | A SpreadsheetFont object providing properties to change font attributes. |
Type | Description |
---|---|
SpreadsheetFont | A SpreadsheetFont object providing properties to change font attributes. |
Type | Description |
---|---|
SpreadsheetFont | A SpreadsheetFont object providing properties to change font attributes. |
To specify all the required font characteristics, use the Font object properties such as SpreadsheetFont.Color, SpreadsheetFont.Name, SpreadsheetFont.Size, SpreadsheetFont.FontStyle etc.
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.
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.
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