How to Set Cell Background Pattern & Color

by Chaknith Bin

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.




C# NuGet Library for Excel

Install with NuGet

Install-Package IronXL.Excel
or
C# Excel DLL

Download DLL

Download DLL

Manually install into your project

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
it is currently not possible to change the color of the fill pattern.

: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")
VB   C#
Output

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:

Available Fill Pattern

Chaknith Bin

Software Engineer

Chaknith is the Sherlock Holmes of developers. It first occurred to him he might have a future in software engineering, when he was doing code challenges for fun. His focus is on IronXL and IronBarcode, but he takes pride in helping customers with every product. Chaknith leverages his knowledge from talking directly with customers, to help further improve the products themselves. His anecdotal feedback goes beyond Jira tickets and supports product development, documentation and marketing, to improve customer’s overall experience.When he isn’t in the office, he can be found learning about machine learning, coding and hiking.