CellRange.SetRichText(RichTextString) Method
Assigns the rich formatted text to a cell.
Namespace: DevExpress.Spreadsheet
Assembly: DevExpress.Spreadsheet.v24.1.Core.dll
NuGet Package: DevExpress.Spreadsheet.Core
Declaration
Parameters
Name | Type | Description |
---|---|---|
value | RichTextString | A RichTextString object that is a combination of specifically formatted text regions. |
Remarks
Use the SetRichText method to add rich formatted text to a cell. Such rich text is defined by the RichTextString object and represents a cell text divided into separate regions (so-called text runs), each with its own set of font characteristics.
To apply rich formatting to the cell text, do one of the following:
- Explicitly add text runs with the specified font settings to the rich text string using the RichTextString.AddTextRun method.
- Use the RichTextString.Characters method overloads to format specific characters within the cell text. These methods return the RichTextRange object that represents the specified text subset and allows you to set its font characteristics using the RichTextRange.Font property or RichTextRange.SetFont method.
Pass the RichTextString instance to the SetRichText method to assign the specified rich text to a cell. The resulting text string is also set to the cell’s CellRange.Value as plain text.
// Create a RichTextString instance.
RichTextString richText = new RichTextString();
// Add three text runs. Each run has its own font settings.
richText.AddTextRun("Rich ", new RichTextRunFont("Arial", 14, System.Drawing.Color.FromArgb(0xc5, 0x9f, 0xc9)));
richText.AddTextRun("text ", new RichTextRunFont("Tahoma", 14, System.Drawing.Color.FromArgb(0x2c, 0x60, 0x8e)));
richText.AddTextRun("formatting", new RichTextRunFont("Castellar", 14, System.Drawing.Color.FromArgb(0x2f, 0x24, 0x4f)));
// Assign the rich formatted text to the cell B2.
worksheet["B2"].SetRichText(richText);
For more examples on how to apply different fonts to specific regions of the cell text, refer to the How to: Apply Rich Formatting to Cell Text document.
Related GitHub Examples
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the SetRichText(RichTextString) 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.