Back to Devexpress

CellRange.FillColor Property

officefileapi-devexpress-dot-spreadsheet-dot-cellrange-8aab47f6.md

latest10.8 KB
Original Source

CellRange.FillColor Property

Gets or sets the cell background color.

Namespace : DevExpress.Spreadsheet

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

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
Color FillColor { get; set; }
vb
Property FillColor As Color

Property Value

TypeDescription
Color

The cell background color.

|

Remarks

Use properties of the Fill object to specify background settings for a cell:

When you specify FillColor or BackgroundColor for a cell with no background (Fill.PatternType is None), the cell background pattern is changed to Solid.

Important

The semi-transparent alpha component (the Color‘s alpha parameter with a value less than 255) is reset to opaque (255) when the document is rendered in the Spreadsheet control, printed, or exported to PDF and Excel formats.

To access the Fill object, use the Formatting.Fill property.

For examples on how to specify formatting for an individual cell and cell range or modify a style, refer to the How to: Format a Cell or Range of Cells or How to: Create or Modify a Style document.

Example

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

View Example

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

// Format a range of cells.
CellRange range = worksheet.Range["C3:H10"];
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);
vb
' Format an individual cell.
worksheet.Cells("A1").Font.Color = Color.Red
worksheet.Cells("A1").FillColor = Color.Yellow

' Format a range of cells.
Dim range As CellRange = worksheet.Range("C3:H10")
Dim rangeFormatting As Formatting = 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 following code snippets (auto-collected from DevExpress Examples) contain references to the FillColor property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-spreadsheetcontrol-api-part1/CS/SpreadsheetControl/SpreadsheetActions/FormulaActions.cs#L29

csharp
worksheet.Cells["B1"].Value = "Value";
worksheet.Range["A1:B1"].FillColor = Color.LightGray;
worksheet.Range["A1:B2"].Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;

wpf-spreadsheetcontrol-api-part-1/CS/SpreadsheetControl_WPF_API/SpreadsheetActions/FormulaActions.cs#L29

csharp
worksheet.Cells["B1"].Value = "Value";
worksheet.Range["A1:B1"].FillColor = Color.LightGray;
worksheet.Range["A1:B2"].Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;

spreadsheet-document-api-examples-part1/CS/SpreadsheetExamples/SpreadsheetActions/FormulaActions.cs#L26

csharp
worksheet.Cells["B1"].Value = "Value";
worksheet.Range["A1:B1"].FillColor = Color.LightGray;
worksheet.Cells["A2"].Value = "'= (1+5)*6";

wpf-spreadsheetcontrol-api-part-2/CS/SpreadsheetControl_WPF_API_Part02/SpreadsheetActions/DataValidationActions.cs#L53

csharp
// Highlight data validation ranges.
worksheet["H4:H9"].FillColor = Color.LightGray;
int[] MyColorScheme = new int[] { 0xFFC4C4, 0xFFD9D9, 0xFFF6F6, 0xFFECEC, 0xE9D3D3, 0xFFDFC4, 0xFFDAE9};

spreadsheet-document-api-examples-part2/CS/SpreadsheetDocServerAPIPart2/CodeExamples/DataValidationActions.cs#L59

csharp
// Highlight data validation ranges.
worksheet["H4:H9"].FillColor = Color.LightGray;
int[] MyColorScheme = new int[] { 0xFFC4C4, 0xFFD9D9, 0xFFF6F6, 0xFFECEC, 0xE9D3D3, 0xFFDFC4, 0xFFDAE9};

spreadsheet-document-api-examples-part1/VB/SpreadsheetExamples/SpreadsheetActions/FormulaActions.vb#L28

vb
worksheet.Cells("B1").Value = "Value"
worksheet.Range("A1:B1").FillColor = Color.LightGray
worksheet.Cells("A2").Value = "'= (1+5)*6"

winforms-spreadsheetcontrol-api-part1/VB/SpreadsheetControl/SpreadsheetActions/FormulaActions.vb#L26

vb
worksheet.Cells("B1").Value = "Value"
worksheet.Range("A1:B1").FillColor = Color.LightGray
worksheet.Range("A1:B2").Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center

wpf-spreadsheetcontrol-api-part-1/VB/SpreadsheetControl_WPF_API/SpreadsheetActions/FormulaActions.vb#L28

vb
worksheet.Cells("B1").Value = "Value"
worksheet.Range("A1:B1").FillColor = Color.LightGray
worksheet.Range("A1:B2").Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center

spreadsheet-document-api-examples-part2/VB/SpreadsheetDocServerAPIPart2/CodeExamples/DataValidationActions.vb#L57

vb
' Highlight data validation ranges.
worksheet("H4:H9").FillColor = Color.LightGray
Dim MyColorScheme() As Integer = { &HFFC4C4, &HFFD9D9, &HFFF6F6, &HFFECEC, &HE9D3D3, &HFFDFC4, &HFFDAE9}

winforms-spreadsheetcontrol-api-part-3/VB/SpreadsheetControl_API_Part03/CodeExamples/DataValidationActions.vb#L33

vb
' Highlight data validation ranges.
worksheet(CStr(("H4:H9"))).FillColor = System.Drawing.Color.LightGray
Dim MyColorScheme As Integer() = New Integer() {&HFFC4C4, &HFFD9D9, &HFFF6F6, &HFFECEC, &HE9D3D3, &HFFDFC4, &HFFDAE9}

See Also

CellRange Interface

CellRange Members

DevExpress.Spreadsheet Namespace