The requested page is not available for the requested platform. You are viewing the content for .NET Framework 4.5.2+ platform.
.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+
.NET Core 3.0+
Row

CommentRunCollection.Add(String) Method

Adds the specified string to the end of the comment text and returns the created CommentRun object.

Namespace: DevExpress.Spreadsheet

Assembly: DevExpress.Spreadsheet.v19.2.Core.dll

Declaration

CommentRun Add(
    string text
)
Function Add(
    text As String
) As CommentRun
CommentRun Add(
    string text
)
Function Add(
    text As String
) As CommentRun
CommentRun Add(
    string text
)
Function Add(
    text As String
) As CommentRun

Parameters

Name Type Description
text String

A String value that specifies a text region within a comment. This value is assigned to the CommentRun.Text property.

Parameters

Name Type Description
text String

A String value that specifies a text region within a comment. This value is assigned to the CommentRun.Text property.

Parameters

Name Type Description
text String

A String value that specifies a text region within a comment. This value is assigned to the CommentRun.Text property.

Returns

Type Description
CommentRun

A CommentRun object that specifies the created comment run.

Returns

Type Description
CommentRun

A CommentRun object that specifies the created comment run.

Returns

Type Description
CommentRun

A CommentRun object that specifies the created comment run.

Remarks

The Add method inserts a new text region into the comment and formats this text region with the default font. To change its font characteristics, use the CommentRun.Font property.

To delete comment runs, use the CommentRunCollection.Remove, CommentRunCollection.RemoveAt or CommentRunCollection.Clear method.

Examples

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.

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;
See Also