officefileapi-devexpress-dot-spreadsheet-b0d864bd.md
Rich formatted text in a cell.
Namespace : DevExpress.Spreadsheet
Assembly : DevExpress.Spreadsheet.v25.2.Core.dll
NuGet Package : DevExpress.Spreadsheet.Core
public class RichTextString :
IEquatable<RichTextString>
Public Class RichTextString
Implements IEquatable(Of RichTextString)
The following members return RichTextString objects:
A cell in a worksheet may contain rich formatted text specified by the RichTextString object. Such rich text represents a cell text divided into one or more text regions (so-called text runs), each with its own set of font characteristics. An individual text run is defined by the RichTextRun object and is stored in the RichTextString.Runs collection.
To apply rich formatting to the cell text, do one of the following:
Pass the RichTextString instance to the CellRange.SetRichText method to assign the specified rich text to a cell.
Use the CellRange.HasRichText property to check whether a cell contains rich formatted text. To retrieve rich text from a cell, use the CellRange.GetRichText method.
For more information on how to apply different fonts to specific regions of the cell text, refer to the How to: Apply Rich Formatting to Cell Text example.
// Create a RichTextString instance.
RichTextString richText = new RichTextString();
// Specify the cell text.
richText.Text = "Rich text formatting";
// Change font characteristics of the first word.
richText.Characters(0, 4).SetFont(new RichTextRunFont("Calibri", 12, System.Drawing.Color.Red));
// Assign the rich formatted text to the cell B2.
worksheet["B2"].SetRichText(richText);
' Create a RichTextString instance.
Dim richText As New RichTextString()
' Specify the cell text.
richText.Text = "Rich text formatting"
' Change font characteristics of the first word.
richText.Characters(0, 4).SetFont(New RichTextRunFont("Calibri", 12, System.Drawing.Color.Red))
' Assign the rich formatted text to the cell B2.
worksheet("B2").SetRichText(richText)
Object RichTextString
See Also
AddTextRun(String, RichTextRunFont)