Back to Devexpress

Fill.BackgroundColor Property

officefileapi-devexpress-dot-spreadsheet-dot-fill.md

latest12.0 KB
Original Source

Fill.BackgroundColor 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 BackgroundColor { get; set; }
vb
Property BackgroundColor 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 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.

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:

View Example: Spreadsheet Document API Examples

csharp
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);
vb
Imports DevExpress.Spreadsheet
Imports System.Drawing
' ...

' Format an individual cell.
worksheet.Cells("A1").Font.Color = Color.Red
worksheet.Cells("A1").FillColor = Color.Yellow

' Format a cell range.
Dim range As CellRange = worksheet.Range("C3:D4")
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 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.

spreadsheet-document-api-apply-conditional-formatting-to-cell-range/CS/ConditionalFormatting_Example/SpreadsheetActions/ConditionalFormatting.cs#L43

csharp
// Set the background color to yellow.
cfRule1.Formatting.Fill.BackgroundColor = Color.FromArgb(255, 0xFA, 0xF7, 0xAA);
// Set the font color to red.

winforms-spreadsheet-apply-conditional-formatting-to-a-range-of-cells/CS/SpreadsheetControl/SpreadsheetActions/ConditionalFormatting.cs#L41

csharp
// Set the background color to yellow.
cfRule1.Formatting.Fill.BackgroundColor = Color.FromArgb(255, 0xFA, 0xF7, 0xAA);
// Set the font color to red.

wpf-spreadsheet-how-to-apply-conditional-formatting-to-a-range-of-cells/CS/ConditionalFormatting_WPF_Examples/SpreadsheetActions/ConditionalFormatting.cs#L40

csharp
// Set the background color to yellow.
cfRule1.Formatting.Fill.BackgroundColor = Color.FromArgb(255, 0xFA, 0xF7, 0xAA);
// Set the font color to red.

spreadsheet-document-api-examples-part2/CS/SpreadsheetDocServerAPIPart2/CodeExamples/SearchActions.cs#L23

csharp
foreach (Cell cell in searchResult)
    cell.Fill.BackgroundColor = Color.LightGreen;
#endregion #SimpleSearch

winforms-spreadsheetcontrol-api-part-2/CS/SpreadsheetControl_API_Part02/SpreadsheetActions/SearchActions.cs#L25

csharp
foreach (Cell cell in searchResult)
    cell.Fill.BackgroundColor = Color.LightGreen;
#endregion #SimpleSearch

spreadsheet-document-api-apply-conditional-formatting-to-cell-range/VB/ConditionalFormatting_Example/SpreadsheetActions/ConditionalFormatting.vb#L48

vb
' Set the background color to yellow.
cfRule1.Formatting.Fill.BackgroundColor = Color.FromArgb(255, &HFA, &HF7, &HAA)
' Set the font color to red.

winforms-spreadsheet-apply-conditional-formatting-to-a-range-of-cells/VB/SpreadsheetControl/SpreadsheetActions/ConditionalFormatting.vb#L40

vb
' Set the background color to yellow.
cfRule1.Formatting.Fill.BackgroundColor = Color.FromArgb(255, &HFA, &HF7, &HAA)
' Set the font color to red.

wpf-spreadsheet-how-to-apply-conditional-formatting-to-a-range-of-cells/VB/ConditionalFormatting_WPF_Examples/SpreadsheetActions/ConditionalFormatting.vb#L38

vb
' Set the background color to yellow.
cfRule1.Formatting.Fill.BackgroundColor = Color.FromArgb(255, &HFA, &HF7, &HAA)
' Set the font color to red.

spreadsheet-document-api-examples-part1/VB/SpreadsheetExamples/SpreadsheetActions/FormattingActions.vb#L61

vb
' Set the background.
myStyle.Fill.BackgroundColor = Color.LightBlue
myStyle.Fill.PatternType = PatternType.LightGray

spreadsheet-document-api-examples-part2/VB/SpreadsheetDocServerAPIPart2/CodeExamples/SearchActions.vb#L20

vb
For Each cell As Cell In searchResult
    cell.Fill.BackgroundColor = Color.LightGreen
Next cell

See Also

PatternType

PatternColor

Fill Interface

Fill Members

DevExpress.Spreadsheet Namespace