Back to Devexpress

RichTextRange.SetFont(SpreadsheetFont) Method

officefileapi-devexpress-dot-spreadsheet-dot-richtextrange-dot-setfont-x28-devexpress-dot-spreadsheet-dot-spreadsheetfont-x29.md

latest3.1 KB
Original Source

RichTextRange.SetFont(SpreadsheetFont) Method

Applies the specified font settings to the current region of the cell text.

Namespace : DevExpress.Spreadsheet

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

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
void SetFont(
    SpreadsheetFont font
)
vb
Sub SetFont(
    font As SpreadsheetFont
)

Parameters

NameTypeDescription
fontSpreadsheetFont

A SpreadsheetFont object or its descendant, a RichTextRunFont object, containing the necessary font settings.

|

Remarks

Use the SetFont method to apply a custom font to a portion of the cell text specified by the RichTextString.Characters method. To assign the rich formatted text to a cell, call the CellRange.SetRichText method.

csharp
// 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);
vb
' 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)

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

Characters

How to: Apply Rich Formatting to Cell Text

RichTextRange Interface

RichTextRange Members

DevExpress.Spreadsheet Namespace