How to Set Cell Background patterns and Color in Excel

Set Cell Background Pattern & Color in C# with IronXL

IronXL enables you to customize Excel cell backgrounds with patterns and colors programmatically in C#. Set visual patterns like diagonal crosshatch and apply colors using simple API calls to enhance spreadsheet visualization.

Quickstart: Customize Excel Background Patterns & Colors

Enhance your Excel spreadsheets with IronXL by customizing background patterns and colors. This quick guide demonstrates how to set a diagonal crosshatch pattern and a SeaGreen background color to a cell. Using IronXL's straightforward API, you can quickly improve the visual appeal of your data without relying on Interop.

Nuget IconGet started making PDFs with NuGet now:

  1. Install IronXL with NuGet Package Manager

    PM > Install-Package IronXL.Excel

  2. Copy and run this code snippet.

    var workbook = IronXL.Excel.Workbook.Load("example.xlsx");
    var sheet = workbook.Worksheets[0];
    sheet["A1"].Style.FillPattern = IronXL.Styles.FillPattern.DiagonalCrosshatch;
    sheet["A1"].Style.BackgroundColor = IronXL.Styles.Colors.SeaGreen;
    workbook.SaveAs("styled_example.xlsx");
  3. Deploy to test on your live environment

    Start using IronXL in your project today with a free trial
    arrow pointer


How Do I Set Cell Background Pattern & Color in IronXL?

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, use the SetBackgroundColor method or set the BackgroundColor property to apply the desired color. Choose the color from the Color class or input the hex color code. For example, SeaGreen is "#FFF5EE".

The background pattern and color functionality works seamlessly with other cell styling features like borders and fonts. When working with conditional formatting, you can combine patterns and colors to create sophisticated visual indicators for your data.

Please noteit is currently not possible to change the color of the fill pattern.

Which Properties Control Background Styling?

The two main properties for controlling background styling in IronXL are FillPattern and BackgroundColor. The FillPattern property accepts values from the IronXL.Styles.FillPattern enum, while BackgroundColor can be set using either the SetBackgroundColor method with a Color object or by directly assigning a hex color code string to the BackgroundColor property.

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

What's the Difference Between SetBackgroundColor and BackgroundColor Property?

Both SetBackgroundColor method and BackgroundColor property achieve the same result but offer different approaches. The SetBackgroundColor method accepts a Color object from the IronSoftware.Drawing namespace, providing access to predefined color names and RGB values. The BackgroundColor property accepts hex color codes as strings, offering precision when you need specific color values. Choose the approach that best fits your workflow—use SetBackgroundColor for named colors and BackgroundColor for hex values.

Spreadsheet cells A1-A2 showing solid green fill and green striped background patterns applied

Can I Apply Patterns to Multiple Cells at Once?

Yes, you can apply patterns and colors to multiple cells simultaneously using range selection. This approach is particularly useful when formatting large datasets or creating consistent visual themes across your spreadsheet. Here's how to apply patterns to entire rows, columns, or custom ranges:

using IronXL;
using IronXL.Styles;
using IronSoftware.Drawing;

WorkBook workBook = WorkBook.Load("data.xlsx");
WorkSheet workSheet = workBook.DefaultWorkSheet;

// Apply pattern to entire column
workSheet.GetColumn(0).Style.FillPattern = FillPattern.LightGrid;
workSheet.GetColumn(0).Style.SetBackgroundColor(Color.LightBlue);

// Apply pattern to entire row
workSheet.GetRow(0).Style.FillPattern = FillPattern.DarkHorizontal;
workSheet.GetRow(0).Style.BackgroundColor = "#F0F0F0";

// Apply pattern to custom range
var range = workSheet["B2:D5"];
range.Style.FillPattern = FillPattern.ThinDiagonalStripe;
range.Style.SetBackgroundColor(Color.PaleGreen);

workBook.SaveAs("formatted_data.xlsx");
using IronXL;
using IronXL.Styles;
using IronSoftware.Drawing;

WorkBook workBook = WorkBook.Load("data.xlsx");
WorkSheet workSheet = workBook.DefaultWorkSheet;

// Apply pattern to entire column
workSheet.GetColumn(0).Style.FillPattern = FillPattern.LightGrid;
workSheet.GetColumn(0).Style.SetBackgroundColor(Color.LightBlue);

// Apply pattern to entire row
workSheet.GetRow(0).Style.FillPattern = FillPattern.DarkHorizontal;
workSheet.GetRow(0).Style.BackgroundColor = "#F0F0F0";

// Apply pattern to custom range
var range = workSheet["B2:D5"];
range.Style.FillPattern = FillPattern.ThinDiagonalStripe;
range.Style.SetBackgroundColor(Color.PaleGreen);

workBook.SaveAs("formatted_data.xlsx");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

What Fill Patterns Are Available in IronXL?

Use 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:

Which Fill Pattern Should I Use for My Data?

Choosing the right fill pattern depends on your data visualization needs. For highlighting important headers or totals, solid patterns (SolidForeground) work best. Diagonal patterns (DiagonalStripe, DiagonalCrosshatch) are ideal for indicating calculated or derived values. Dot patterns (FineDots, SparseDots) can subtly distinguish alternating rows for improved readability. When creating reports or exporting data, consider your audience's printing capabilities—some intricate patterns may not reproduce well on all printers.

Chart showing 19 fill patterns with names and visual samples including dots, lines, diagonals, and geometric shapes

How Do Fill Patterns Affect Readability?

Fill patterns significantly impact spreadsheet readability. Light patterns like ThinHorizontalBands or ThinVerticalBands can improve row tracking without overwhelming the data. Dense patterns should be used sparingly, typically for separator rows or special sections. When working with formulas and calculations, avoid patterns that make text difficult to read. Consider color contrast—dark patterns require light text colors, which you can adjust using font styling options.

Can I Create Custom Fill Patterns?

Currently, IronXL provides 19 predefined fill patterns through the FillPattern enum. While custom pattern creation isn't directly supported, you can achieve unique visual effects by combining patterns with strategic color choices and cell borders. For advanced visualization needs, consider using patterns in conjunction with conditional formatting to create dynamic, data-driven visual indicators. When importing Excel files that contain custom patterns created in Excel, IronXL will preserve these patterns where possible.

For complex reporting requirements, you can combine background patterns with other formatting features like merging cells and adding images to create professional-looking spreadsheets that effectively communicate your data insights.

Frequently Asked Questions

How do I apply a background pattern to Excel cells in C#?

With IronXL, you can apply background patterns to Excel cells by using the FillPattern property. Simply select your cell, column, row, or range, then set the FillPattern property to one of the available patterns from the IronXL.Styles.FillPattern enum, such as DiagonalCrosshatch.

Can I set both a background pattern and color simultaneously?

Yes, IronXL allows you to set both background patterns and colors together. First set the FillPattern property to your desired pattern, then use either the SetBackgroundColor method or the BackgroundColor property to apply your chosen color from the Color class or a hex color code.

What background patterns are available for Excel cells?

IronXL provides various fill patterns through the IronXL.Styles.FillPattern enum, including options like DiagonalCrosshatch and other standard Excel patterns. These patterns can be applied to cells, columns, rows, or ranges to enhance visual presentation.

How do I specify custom colors for cell backgrounds?

IronXL offers two ways to specify custom colors: you can use the SetBackgroundColor method with a Color object from the system colors (like Colors.SeaGreen), or directly assign a hex color code string to the BackgroundColor property (e.g., '#FFF5EE' for SeaGreen).

Does this method require Microsoft Office Interop?

No, IronXL works independently without requiring Microsoft Office Interop. You can set background patterns and colors programmatically in C# without needing Excel installed on your machine, making it ideal for server environments.

Can background styling be combined with other cell formatting features?

Yes, IronXL's background pattern and color functionality works seamlessly with other cell styling features like borders, fonts, and conditional formatting. This allows you to create sophisticated visual indicators and enhance your spreadsheet's overall appearance.

Chaknith Bin
Software Engineer
Chaknith works on IronXL and IronBarcode. He has deep expertise in C# and .NET, helping improve the software and support customers. His insights from user interactions contribute to better products, documentation, and overall experience.
Ready to Get Started?
Nuget Downloads 1,765,830 | Version: 2025.12 just released