IronXL 操作指南 背景图案和颜色 How to Set Cell Background Pattern & Color Chaknith Bin 已更新:七月 22, 2025 Download IronXL NuGet 下载 DLL 下载 Start Free Trial Copy for LLMs Copy for LLMs Copy page as Markdown for LLMs Open in ChatGPT Ask ChatGPT about this page Open in Gemini Ask Gemini about this page Open in Grok Ask Grok about this page Open in Perplexity Ask Perplexity about this page Share Share on Facebook Share on X (Twitter) Share on LinkedIn Copy URL Email article 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. Get started making PDFs with NuGet now: Install IronXL with NuGet Package Manager PM > Install-Package IronXL.Excel 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"); Deploy to test on your live environment Start using IronXL in your project today with a free trial Free 30 day Trial Minimal Workflow (5 steps) Download the C# library to set background pattern and color Open an existing or create a new Excel spreadsheet Set the FillPattern property of the cell, column, row, or range to define the fill pattern Use the SetBackgroundColor method to set the color Export all available fill patterns 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". 请注意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; 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 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: 常见问题解答 如何在Excel中使用C#设置单元格背景图案? 要在Excel中使用C#设置单元格背景图案,请使用单元格、列、行或范围的FillPattern属性,并从IronXL.Styles.FillPattern中选择一个枚举值。 应用实心背景色到单元格的方法是什么? 您可以使用SetBackgroundColor方法或在IronXL中设置BackgroundColor属性来应用实心背景色。 我可以在C#中为单元格背景使用自定义颜色代码吗? 是的,您可以使用十六进制颜色代码或从Color类中预定义的颜色中选择,以在IronXL中设置背景颜色。 是否可以在Excel中使用C#导出可用的填充图案? 是的,您可以使用C#通过IronXL.Styles.FillPattern枚举导出所有可用的填充图案,以探索和应用各种填充图案。 如何开始使用C#库自定义Excel工作表? 要开始自定义Excel工作表,下载来自NuGet的IronXL C#库,打开现有的或创建新的Excel电子表格,并使用库的方法自定义单元格外观。 管理IronXL中颜色和图案所需的命名空间是什么? 您需要导入IronXL, IronXL.Styles和System.Drawing命名空间来管理IronXL中的颜色和图案。 我可以在C#库中更改填充图案颜色本身吗? 目前,在IronXL中无法更改填充图案本身的颜色。 在C#中用于Excel自定义的不同填充图案有哪些? IronXL提供了一系列填充图案,可通过IronXL.Styles.FillPattern枚举访问,赋予Excel单元格外观多样化的自定义选项。 Chaknith Bin 立即与工程团队聊天 软件工程师 Chaknith 在 IronXL 和 IronBarcode 工作。他在 C# 和 .NET 方面有着深厚的专业知识,帮助改进软件并支持客户。他从用户互动中获得的见解有助于更好的产品、文档和整体体验。 准备开始了吗? Nuget 下载 1,686,155 | 版本: 2025.11 刚刚发布 免费 NuGet 下载 总下载量:1,686,155 查看许可证