Skip to main content
A newer version of this page is available. .
Row

RichTextString.AddTextRun(String, RichTextRunFont) Method

Appends a new text run to the current rich text string.

Namespace: DevExpress.Spreadsheet

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

Declaration

public RichTextString AddTextRun(
    string text,
    RichTextRunFont font
)

Parameters

Name Type Description
text String

A String value that specifies the current run’s text.

font RichTextRunFont

A RichTextRunFont object that specifies font attributes to be applied to the text.

Returns

Type Description
RichTextString

A RichTextString object that specifies rich text contained in a cell.

Remarks

Use the AddTextRun method to compose the cell text from individual text runs. Call the Range.SetRichText method to assign the rich formatted text to a cell.

// 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);

You can also use the RichTextString.Characters property to format specific characters within a cell text. Refer to the How to: Apply Rich Formatting to Cell Text article for more examples on how to apply rich formatting to the cell content.

See Also