The requested page is not available for the requested platform. You are viewing the content for .NET Framework 4.5.2+ platform.

How to: Configure Cell Font Settings

  • 2 min to read

To set different font attributes for cells, use the properties of the SpreadsheetFont object.

To access this object for modifying the font of an individual cell, use the Cell object's Formatting.Font property that is inherited form the Formatting interface.

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

The SpreadsheetFont object provides the following properties to change cell font attributes.

To share font settings with multiple cells in a single step, create or modify the style with the Formatting.Font property specified as required, and assign this style to CellRange.Style for the desired cells.

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.

// 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.Double;

The image below shows the specified cell font (the workbook is opened in Microsoft® Excel®).

Spreadsheet_FontSettings