Skip to main content
A newer version of this page is available. .

How to: Change Cell Font and Background Color

  • 2 minutes to read

You can change cell font color and cell background.

To specify these attributes for an individual cell, modify the Cell object’s Formatting.Font and Formatting.Fill properties, which are inherited form the Formatting interface.

To change color characteristics for a range of cells, call the Range.BeginUpdateFormatting method for this range, modify the Font and Fill properties of the returned Formatting object and call the Range.EndUpdateFormatting method to finalize the modification.

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

This example demonstrates how to format color characteristics (font and background colors) for an individual cell and range of cells.

// Format an individual cell.
worksheet.Cells["A1"].Font.Color = Color.Red;
worksheet.Cells["A1"].FillColor = Color.Yellow;

// Format a range of cells.
Range range = worksheet.Range["C3:D4"];
Formatting rangeFormatting = range.BeginUpdateFormatting();
rangeFormatting.Font.Color = Color.Blue;
rangeFormatting.Fill.BackgroundColor = Color.LightBlue;
rangeFormatting.Fill.PatternType = PatternType.LightHorizontal;
rangeFormatting.Fill.PatternColor = Color.Violet;
range.EndUpdateFormatting(rangeFormatting);

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

Spreadsheet_CellColors