Cómo establecer patrones y color de fondo de celda en Excel

How to Set Cell Background Pattern & Color

This article was translated from English: Does it need improvement?
Translated
View the article in English

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.

Quickstart: Customize Excel Background Patterns & Colors

Easily 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


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".

Por favor notait 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")
$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

Preguntas Frecuentes

¿Cómo puedo establecer un patrón de fondo de celda en Excel usando C#?

Para establecer un patrón de fondo de celda en Excel usando C#, usa la propiedad FillPattern de la celda, columna, fila o rango con uno de los enums de IronXL.Styles.FillPattern.

¿Cuál es el método para aplicar un color de fondo sólido a una celda en C#?

Puedes aplicar un color de fondo sólido a una celda usando el método SetBackgroundColor o estableciendo la propiedad BackgroundColor en IronXL.

¿Puedo usar códigos de color personalizados para fondos de celda en C#?

Sí, puedes usar códigos de color Hex o seleccionar de colores predefinidos en la clase Color para establecer colores de fondo en IronXL.

¿Es posible exportar los patrones de relleno disponibles en Excel usando C#?

Sí, puedes exportar todos los patrones de relleno disponibles en Excel usando C# aprovechando el enum IronXL.Styles.FillPattern para explorar y aplicar diversos patrones de relleno.

¿Cómo empiezo a personalizar hojas de Excel con una biblioteca C#?

Para comenzar a personalizar hojas de Excel, descarga la biblioteca C# IronXL desde NuGet, abre una hoja de cálculo de Excel existente o crea una nueva y utiliza los métodos de la biblioteca para personalizar la apariencia de las celdas.

¿Qué espacios de nombres son necesarios para gestionar colores y patrones en IronXL?

Necesitas importar los espacios de nombres IronXL, IronXL.Styles y System.Drawing para gestionar colores y patrones en IronXL.

¿Puedo cambiar el color del patrón de relleno en una biblioteca de C#?

Actualmente, no es posible cambiar el color del patrón de relleno en sí en IronXL.

¿Cuáles son los diferentes patrones de relleno disponibles para la personalización de Excel usando C#?

IronXL proporciona una variedad de patrones de relleno accesibles a través del enum IronXL.Styles.FillPattern, permitiendo diversas opciones de personalización para la apariencia de las celdas en Excel.

Chaknith Bin
Ingeniero de Software
Chaknith trabaja en IronXL e IronBarcode. Tiene un profundo conocimiento en C# y .NET, ayudando a mejorar el software y apoyar a los clientes. Sus conocimientos derivados de las interacciones con los usuarios contribuyen a mejores productos, documentación y experiencia en general.
¿Listo para empezar?
Nuget Descargas 1,686,155 | Versión: 2025.11 recién lanzado