Fill.BackgroundColor Property
Gets or sets the cell background color.
Namespace: DevExpress.Spreadsheet
Assembly: DevExpress.Spreadsheet.v24.1.Core.dll
NuGet Package: DevExpress.Spreadsheet.Core
Declaration
Property Value
Type | Description |
---|---|
Color | The cell background color. |
Remarks
Use properties of the Fill object to specify background settings for a cell:
BackgroundColor
(this property is equal to CellRange.FillColor)- Fill.PatternType and Fill.PatternColor
- Fill.Gradient
When you specify BackgroundColor
or FillColor 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.
- To specify the background of an individual cell, access the Fill object using the cell’s Formatting.Fill property directly.
- To specify the background of a cell range, modify the Fill object within the CellRange.BeginUpdateFormatting - CellRange.EndUpdateFormatting method pair.
- To share the same background settings between multiple cells in one step, apply the style with the specified background to the required cells. To specify the cell style background, access the Style object from the IWorkbook.Styles collection and use this style’s Formatting.Fill property within the Formatting.BeginUpdate-Formatting.EndUpdate paired methods to access and modify the Fill object.
- To clear the background, set the
BackgroundColor
to Empty or Transparent.
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.
Note
You can also set a background color for an individual cell or range of cells via the CellRange.FillColor property.
To specify the cell font color, use the SpreadsheetFont.Color property of the SpreadsheetFont object accessed via the Formatting.Font property. For details, review the How to: Change Cell Font and Background Color example.
Example
The following example specifies font and background colors for an individual cell and cell range:
using DevExpress.Spreadsheet;
using System.Drawing;
// ...
// Format an individual cell.
worksheet.Cells["A1"].Font.Color = Color.Red;
worksheet.Cells["A1"].FillColor = Color.Yellow;
// Format a cell range.
CellRange 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);
Related GitHub Examples
The following code snippets (auto-collected from DevExpress Examples) contain references to the BackgroundColor 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.