Skip to main content
A newer version of this page is available. .
.NET Framework 4.5.2+
Row

RichTextString.Characters(Int32, Int32) Method

Returns a range of characters that starts at the specified position and has the specified length.

Namespace: DevExpress.Spreadsheet

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

Declaration

public RichTextRange Characters(
    int start,
    int count
)

Parameters

Name Type Description
start Int32

An integer that is the zero-based character position from which the required text range starts.

count Int32

An integer that is the number of characters in the required text range.

Returns

Type Description
RichTextRange

A RichTextRange object that represents a range of characters within the cell text.

Remarks

Use the Characters method to format specific characters within the cell text. This method returns the RichTextRange object that represents the text subset and allows you to set its font characteristics using the RichTextRange.Font property or RichTextRange.SetFont method. To assign the rich formatted text to a cell, call the CellRange.SetRichText method.

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

When you use the Characters method to apply rich formatting to a region of cell text, a corresponding RichTextRun object is created and added to the RichTextString.Runs collection. However, if the font settings you specify for text characters coincide with the previous or next run of the cell’s rich text, these runs are combined into a single text run and a new item is not created.

To view font characteristics applied to a portion of cell text, use the RichTextRange.Font property. This property returns the SpreadsheetFontProperties object that contains font attributes of the specified text range. If this text range includes multiple text runs, the SpreadsheetFontProperties property values are null for differing font characteristics.

Refer to the How to: Apply Rich Formatting to Cell Text document for more examples on how to apply rich formatting to the cell content.

See Also