How to Set Cell Background Pattern & Color
In Excel, a background cell pattern refers to the visual design or fill applied to a cell's background. Additionally, background cell color refers to the solid color applied to a cell's background.
By combining both features, users can create visually appealing cell backgrounds with a wide range of pattern styles, colors, and textures. With IronXL, you can leverage these features to customize cell backgrounds in Excel, enhancing data visualization and highlighting important information in your spreadsheets.
How to Set Cell Background Pattern & Color
Get started with IronXL
Start using IronXL in your project today with a free trial.
Set Cell Background Pattern & Color Example
To set a background pattern for a selected cell, column, row, or range, use the FillPattern
property with one of the enums from IronXL.Styles.FillPattern
. Then, utilize the SetBackgroundColor
method or set the BackgroundColor
property to apply the desired color. You can choose the color from the Color
class or input the Hex color code. For example, SeaGreen is "#FFF5EE".
Please note
:path=/static-assets/excel/content-code-examples/how-to/background-pattern-color-set-background-pattern-color.cs
using IronXL;
using IronXL.Styles;
using IronSoftware.Drawing;
// Create a new Excel workbook
WorkBook workBook = WorkBook.Create();
// Retrieve the default worksheet from the workbook
WorkSheet workSheet = workBook.DefaultWorkSheet;
// Set background pattern for cell A1
workSheet["A1"].Style.FillPattern = FillPattern.AlternateBars;
// Set background color of cell A1 using a predefined Color object
workSheet["A1"].Style.SetBackgroundColor(Color.Aquamarine);
// Set background pattern for cell A2
workSheet["A2"].Style.FillPattern = FillPattern.ThickVerticalBands;
// Set background color of cell A2 using a hex color string
workSheet["A2"].Style.SetBackgroundColor("#ADFF2F");
// Save the workbook to a file with the specified filename
workBook.SaveAs("setBackgroundPattern.xlsx");
Imports IronXL
Imports IronXL.Styles
Imports IronSoftware.Drawing
' Create a new Excel workbook
Private workBook As WorkBook = WorkBook.Create()
' Retrieve the default worksheet from the workbook
Private workSheet As WorkSheet = workBook.DefaultWorkSheet
' Set background pattern for cell A1
Private workSheet("A1").Style.FillPattern = FillPattern.AlternateBars
' Set background color of cell A1 using a predefined Color object
workSheet("A1").Style.SetBackgroundColor(Color.Aquamarine)
' Set background pattern for cell A2
workSheet("A2").Style.FillPattern = FillPattern.ThickVerticalBands
' Set background color of cell A2 using a hex color string
workSheet("A2").Style.SetBackgroundColor("#ADFF2F")
' Save the workbook to a file with the specified filename
workBook.SaveAs("setBackgroundPattern.xlsx")

Available Fill Patterns
Utilize the available fill patterns from the IronXL.Styles.FillPattern
enum to set the desired fill pattern in your Excel sheets. Below is an illustration showcasing all the available fill patterns offered by IronXL:

Frequently Asked Questions
What is a cell background pattern in Excel?
In Excel, a background cell pattern refers to the visual design or fill applied to a cell's background, allowing for various styles, colors, and textures.
How can I set a cell background color in Excel using IronXL?
You can set a cell background color by using the `SetBackgroundColor` method or setting the `BackgroundColor` property of a cell, column, row, or range in IronXL.
Which method is used to apply a fill pattern to a cell in IronXL?
To apply a fill pattern, you can set the `FillPattern` property of the cell, column, row, or range using one of the enums from `IronXL.Styles.FillPattern`.
Can I use Hex color codes to set background colors in IronXL?
Yes, you can use Hex color codes or select from the predefined colors in the `Color` class to set background colors in IronXL.
Is it possible to change the color of the fill pattern itself in IronXL?
No, it is currently not possible to change the color of the fill pattern itself in IronXL.
What libraries do I need to import to handle colors in IronXL?
You need to import the IronXL, IronXL.Styles, and System.Drawing namespaces to handle colors in IronXL.
How do I get started with IronXL to customize Excel sheets?
To get started with IronXL, download the C# library from NuGet, open an existing or create a new Excel spreadsheet, and then use the provided methods to customize the cell appearances.
What are the available fill patterns in IronXL?
IronXL offers a variety of fill patterns that can be accessed using the `IronXL.Styles.FillPattern` enum. These patterns can be applied to cells to enhance the visual appeal of Excel sheets.