officefileapi-devexpress-dot-spreadsheet-dot-richtextstring-dot-addtextrun-x28-system-dot-string-devexpress-dot-spreadsheet-dot-richtextrunfont-x29.md
Appends a new text run to the current rich text string.
Namespace : DevExpress.Spreadsheet
Assembly : DevExpress.Spreadsheet.v25.2.Core.dll
NuGet Package : DevExpress.Spreadsheet.Core
public RichTextString AddTextRun(
string text,
RichTextRunFont font
)
Public Function AddTextRun(
text As String,
font As RichTextRunFont
) As RichTextString
| 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.
|
| Type | Description |
|---|---|
| RichTextString |
A RichTextString object that specifies rich text contained in a cell.
|
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);
' Create a RichTextString instance.
Dim richText As New RichTextString()
' Add three text runs. Each run has its own font settings.
richText.AddTextRun("Rich ", New RichTextRunFont("Arial", 14, System.Drawing.Color.FromArgb(&Hc5, &H9f, &Hc9)))
richText.AddTextRun("text ", New RichTextRunFont("Tahoma", 14, System.Drawing.Color.FromArgb(&H2c, &H60, &H8e)))
richText.AddTextRun("formatting", New RichTextRunFont("Castellar", 14, System.Drawing.Color.FromArgb(&H2f, &H24, &H4f)))
' 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 snippets (auto-collected from DevExpress Examples) contain references 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.
winforms-spreadsheet-how-to-edit-rich-text/CS/SpreadsheetRichText/Form1.cs#L18
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)));
RichTextRunFont runFont = CreateRichTextRun(text.TextProperties);
richTextString.AddTextRun(text.Text, runFont);
}
winforms-spreadsheet-how-to-edit-rich-text/VB/SpreadsheetRichText/Form1.vb#L12
richText.AddTextRun("Rich ", New RichTextRunFont("Arial", 14, System.Drawing.Color.FromArgb(&HC5, &H9F, &HC9)))
richText.AddTextRun("text ", New RichTextRunFont("Tahoma", 14, System.Drawing.Color.FromArgb(&H2C, &H60, &H8E)))
See Also