Skip to main content
A newer version of this page is available.
All docs
V18.2
Row

Range.SetRichText(RichTextString) Method

Assigns the rich formatted text to a cell.

Namespace: DevExpress.Spreadsheet

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

Declaration

void SetRichText(
    RichTextString value
)

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.

Spreadsheet_RichText

To apply rich formatting to the cell text, do one of the following:

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 Range.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.

See Also