IRONSOFTWAREHOME

Set Cell Background Pattern & Color in C# with IronXL

Curtis Chau
Curtis Chau
Updated: August 2, 2026

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.

  1. 1Install IronXL with NuGet Package Manager

    PM > Install-Package IronXL.Excel

  2. 2Copy and run this code snippet.

    var workbook = IronXL.WorkBook.Load("example.xlsx");
    var sheet = workbook.WorkSheets[0];
    sheet["A1"].Style.FillPattern = IronXL.Styles.FillPattern.ThinForwardDiagonals;
    sheet["A1"].Style.BackgroundColor = "#2E8B57";
    workbook.SaveAs("styled_example.xlsx");
    C#
  3. 3Deploy to test on your live environment

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

FillPattern SetBackgroundColor BackgroundColor FillPattern BackgroundColor FillPattern


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 method SetBackgroundColor(...) 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 "#2E8B57".

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 note: it 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 enum FillPattern (from IronXL.Styles.FillPattern), 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.

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");

BackgroundColor SetBackgroundColor Color BackgroundColor SetBackgroundColor BackgroundColor SetBackgroundColor Color

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 namespace IronSoftware.Drawing, 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.Squares;
workSheet.GetColumn(0).Style.SetBackgroundColor(Color.LightBlue);

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

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

workBook.SaveAs("formatted_data.xlsx");
C#

BackgroundColor SetBackgroundColor BackgroundColor IronXL.Styles.FillPattern SolidForeground ThinForwardDiagonals ThinBackwardDiagonals FineDots SparseDots ThinHorizontalBands ThinVerticalBands FillPattern

What Fill Patterns Are Available in IronXL?

Use the available fill patterns from the 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. Solid patterns (SolidForeground) work best for highlighting important headers or totals. Diagonal patterns (ThinForwardDiagonals, ThickForwardDiagonals) 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 can I set a background pattern in Excel using C# with IronXL?

To set a background pattern in Excel using C#, use IronXL's `FillPattern` property. You can choose from various options like diagonal crosshatch or bars. For example, `sheet["A1"].Style.FillPattern = IronXL.Styles.FillPattern.ThinForwardDiagonals;` sets a diagonal pattern.

How do I apply a background color to cells in IronXL?

In IronXL, you can apply a background color to a cell by either using the `SetBackgroundColor(...)` method with a `Color` object or the `BackgroundColor` property with a hex code. For instance, `sheet["A1"].Style.SetBackgroundColor(Color.SeaGreen);` sets the color to SeaGreen.

Can I apply patterns and colors to multiple cells in IronXL?

Yes, IronXL allows you to apply patterns and colors to multiple cells at once using range selection. You can use methods like `GetColumn()` or `GetRow()` on worksheets to set styles for entire columns or rows.

What is the difference between the SetBackgroundColor method and the BackgroundColor property in IronXL?

The `SetBackgroundColor(...)` method in IronXL allows setting colors using a `Color` object, which provides predefined color names and RGB values. The `BackgroundColor` property lets you specify colors using hex color codes, offering more precision.

Which fill patterns are available in IronXL for styling Excel sheets?

IronXL provides 19 fill patterns, such as `SolidForeground`, `ThinForwardDiagonals`, and `SparseDots`, via the `FillPattern` enum. These patterns help enhance spreadsheet readability and aesthetics.

How do fill patterns affect the readability of Excel documents?

Fill patterns like `ThinHorizontalBands` or `ThinVerticalBands` improve readability by aiding in row tracking. Dense patterns should be used sparingly and usually for highlighting special sections.

Can I create custom fill patterns with IronXL?

IronXL currently supports 19 predefined fill patterns. While custom patterns aren't directly supported, you can combine existing patterns with color choices and cell borders for unique visuals.

Is it possible to use conditional formatting with fill patterns in IronXL?

Yes, IronXL supports combining fill patterns with conditional formatting to create dynamic data-driven visual indicators, enhancing the way data is presented in Excel files.

How can I choose the right fill pattern for my Excel data in IronXL?

Choosing the right fill pattern in IronXL depends on your visualization needs. For instance, solid patterns highlight headers, while diagonal patterns indicate calculated values. Consider printability and readability when selecting patterns.

Can I preserve custom Excel fill patterns when importing files in IronXL?

Yes, when importing Excel files, IronXL will preserve custom patterns where possible, ensuring that existing document styles are maintained.

Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...
Read More

Ready to Get Started?

Nuget Downloads 2,237,574Version:2026.9just released

Get your FREE

30-day Trial Key instantly.

bullet_checkedNo credit card or account creation required
bullet_testTest in production
without watermarks
bullet_calendar30 days fully
functional product
bullet_support24/5 technical
support during trial
Get your free 30-day Trial Key instantly.
No credit card or account creation required
C# NuGet Library for PDF
Install with NuGet

Version: 2026.9

PM > Install-Package IronXL.Excel
nuget.org/packages/IronXL.Excel/
  1. In Solution Explorer, right-click References, Manage NuGet Packages
  2. Select Browse and search "IronXL"
  3. Select the package and install
C# PDF DLL
Download DLL

Version: 2026.9

  1. Download and unzip IronXL to a location such as ~/Libs within your Solution directory
  2. In Visual Studio Solution Explorer, right click References. Select Browse, "IronXL.dll"

Licenses from $999

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required