Back to Devexpress

How to: Configure Cell Font Settings

officefileapi-12370-spreadsheet-document-api-examples-formatting-how-to-configure-cell-font-settings.md

latest4.4 KB
Original Source

How to: Configure Cell Font Settings

  • Sep 19, 2023
  • 2 minutes to read

Use the SpreadsheetFont object’s properties to specify font attributes for worksheet cells and cell ranges.

The Cell.Font property allows you to modify the font for an individual cell.

To change font characteristics for a cell range, call the CellRange.BeginUpdateFormatting method for this range, use the Font property of the returned object to access and modify the SpreadsheetFont properties, and call the CellRange.EndUpdateFormatting method to finalize modifications.

The SpreadsheetFont object contains the following properties used to change cell font attributes:

Create and modify cell styles to apply multiple format attributes to worksheet cells simultaneously.

This example demonstrates how to format cell font characteristics (e.g., font name, size, color, style) by modifying the SpreadsheetFont object accessed via the Formatting.Font property of the Cell object.

View Example

csharp
// Access the Font object.
SpreadsheetFont cellFont = worksheet.Cells["A1"].Font;
// Set the font name.
cellFont.Name = "Times New Roman";
// Set the font size.
cellFont.Size = 14;
// Set the font color.
cellFont.Color = Color.Blue;
// Format text as bold.
cellFont.Bold = true;
// Set font to be underlined.
cellFont.UnderlineType = UnderlineType.Single;
vb
' Access the Font object.
Dim cellFont As SpreadsheetFont = worksheet.Cells("A1").Font
' Set the font name.
cellFont.Name = "Times New Roman"
' Set the font size.
cellFont.Size = 14
' Set the font color.
cellFont.Color = Color.Blue
' Format text as bold.
cellFont.Bold = True
' Set font to be underlined.
cellFont.UnderlineType = UnderlineType.Single

The image below shows the result (the workbook is opened in Microsoft® Excel®).

See Also

Load and Use Custom Fonts Without Installation on the System