Skip to main content
Row

RichTextString.AddTextRun(String, RichTextRunFont) Method

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

Namespace: DevExpress.Spreadsheet

Assembly: DevExpress.Spreadsheet.v24.1.Core.dll

NuGet Package: DevExpress.Spreadsheet.Core

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

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the AddTextRun(String, RichTextRunFont) 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.

See Also