Comment définir les motifs et couleurs de fond des cellules dans 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".

Veuillez noterit 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

Questions Fréquemment Posées

Comment puis-je définir un motif de fond de cellule dans Excel en utilisant C# ?

Pour définir un motif de fond de cellule dans Excel en utilisant C#, utilisez la propriété FillPattern de la cellule, de la colonne, de la ligne ou de la plage avec l'une des énumérations de IronXL.Styles.FillPattern.

Quelle est la méthode pour appliquer une couleur de fond unie à une cellule en C# ?

Vous pouvez appliquer une couleur de fond unie à une cellule en utilisant la méthode SetBackgroundColor ou en définissant la propriété BackgroundColor dans IronXL.

Puis-je utiliser des codes couleurs personnalisés pour les fonds de cellules en C# ?

Oui, vous pouvez utiliser des codes couleurs hexadécimaux ou sélectionner parmi des couleurs prédéfinies dans la classe Color pour définir des couleurs de fond dans IronXL.

Est-il possible d'exporter les motifs de remplissage disponibles dans Excel en utilisant C# ?

Oui, vous pouvez exporter tous les motifs de remplissage disponibles dans Excel en utilisant C# en utilisant l'énumération IronXL.Styles.FillPattern pour explorer et appliquer divers motifs de remplissage.

Comment puis-je commencer à personnaliser des feuilles Excel avec une bibliothèque C# ?

Pour commencer à personnaliser des feuilles Excel, téléchargez la bibliothèque C# IronXL depuis NuGet, ouvrez un classeur Excel existant ou créez-en un nouveau, et utilisez les méthodes de la bibliothèque pour personnaliser l'apparence des cellules.

Quels espaces de noms sont requis pour gérer les couleurs et les motifs dans IronXL ?

Vous devez importer les espaces de noms IronXL, IronXL.Styles, et System.Drawing pour gérer les couleurs et les motifs dans IronXL.

Puis-je changer la couleur du motif de remplissage lui-même dans une bibliothèque C# ?

Actuellement, il n'est pas possible de changer la couleur du motif de remplissage lui-même dans IronXL.

Quels sont les différents motifs de remplissage disponibles pour personnaliser Excel en utilisant C# ?

IronXL fournit une variété de motifs de remplissage accessibles via l'énumération IronXL.Styles.FillPattern, offrant diverses options de personnalisation pour l'apparence des cellules dans Excel.

Chaknith Bin
Ingénieur logiciel
Chaknith travaille sur IronXL et IronBarcode. Il a une expertise approfondie en C# et .NET, aidant à améliorer le logiciel et à soutenir les clients. Ses idées issues des interactions avec les utilisateurs contribuent à de meilleurs produits, documentation et expérience globale.
Prêt à commencer?
Nuget Téléchargements 1,686,155 | Version : 2025.11 vient de sortir