Wednesday, 05 January 2011 07:49

Set Cell Fill in Excel in C#, VB.NET

Cell Fill is one kind of cell format settings in Excel, which includes cell background color and pattern style. With cell fill, the appearance of Excel file can be beautified. Also, data in cell which is set background color or pattern style can be more obvious.

Spire.XLS for .NET, a professional .NET Excel component on manipulating Excel files, enables users to set in Excel. And this guide will focuses on how to realize Excel cell fill in C#, VB.NET, including cell background color and pattern style settings. User can set style property of CellRange class which Spire.XLS for .NET provides to get wanted background color and pattern style of one specified cell or a cell range. The following screenshot shows the result- workbook without cell fill setting.

Add Excel Cell Fill

Download and install Spire.XLS for .NET and use the following code to set cell fill.

Sample Code:

   worksheet.Range["A7:F7"].Style.Color = Color.Yellow;
   worksheet.Range["A8:F8"].Style.FillPattern = ExcelPatternType.Percent125Gray;
  worksheet.Range("A7:F7").Style.Color = Color.Yellow
  worksheet.Range("A8:F8").Style.FillPattern = ExcelPatternType.Percent125Gray
Published in Cells