CommentRunCollection.Insert(Int32, String) Method
Inserts the specified text string at a specified index position within the simple note.
Namespace: DevExpress.Spreadsheet
Assembly: DevExpress.Spreadsheet.v24.1.Core.dll
NuGet Package: DevExpress.Spreadsheet.Core
Declaration
Parameters
Name | Type | Description |
---|---|---|
index | Int32 | The zero-based index position of the insertion. It should be non-negative and less than the number of elements in the collection. |
text | String | A String value, that specifies the text string to be inserted. |
Remarks
The new text region is inserted with the default formatting. To change its font characteristics, obtain the corresponding CommentRun object and use its CommentRun.Font property.
To delete note runs, use the Remove, RemoveAt or Clear method.
Example
This example demonstrates how to add a simple note (a legacy comment) to a cell and format the note text.
Create a Simple Note
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.
Format Note Content
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;
Remove Notes
Use the following methods to remove simple notes:
Related GitHub Examples
The following code snippets (auto-collected from DevExpress Examples) contain references to the Insert(Int32, String) method.
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.