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;
WorkBook workBook = WorkBook.Create();
WorkSheet workSheet = workBook.DefaultWorkSheet;
// Set background pattern
workSheet["A1"].Style.FillPattern = FillPattern.AltBars;
workSheet["A2"].Style.FillPattern = FillPattern.ThickVerticalBands;
// Set background color
workSheet["A1"].Style.SetBackgroundColor(Color.Aquamarine);
workSheet["A2"].Style.BackgroundColor = "#ADFF2F";
workBook.SaveAs("setBackgroundPattern.xlsx");
Imports IronXL
Imports IronXL.Styles
Imports IronSoftware.Drawing
Private workBook As WorkBook = WorkBook.Create()
Private workSheet As WorkSheet = workBook.DefaultWorkSheet
' Set background pattern
Private workSheet("A1").Style.FillPattern = FillPattern.AltBars
Private workSheet("A2").Style.FillPattern = FillPattern.ThickVerticalBands
' Set background color
workSheet("A1").Style.SetBackgroundColor(Color.Aquamarine)
workSheet("A2").Style.BackgroundColor = "#ADFF2F"
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: