Get started with IronXL

Start using IronXL in your project today with a free trial.

First Step:
green arrow pointer


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;

// 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")
$vbLabelText   $csharpLabel
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

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.

Chaknith related to Available Fill Patterns
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.