Well, the BackgroundColor is basically the Cells Fill Color and Foreground color is the outline color. If you use some other pattern than solid, you will see that BackgroundColor will fill the Cell and on top of that background color the ForgroundColor will be used as outline color for the pattern. As per the case of Solid Pattern, the Foreground Color will completely fill the cell, so Background color is not required then.
I use the following sample codes and they work abs fine.
Sample code:
1).
//Instantiating a Workbook object
Workbook workbook = new Workbook();
<strong>// Add sky blue color to the palette.
//This color is not present in the standard color palette (which has 56 colors (0-55 indexed))
//so you have to add to the color palette first on some index postion.</strong>
workbook.ChangePalette(System.Drawing.Color.SkyBlue, 55);
//Obtaining the first worksheet by passing its sheet index
Worksheet worksheet = workbook.Worksheets[0];
//Now setting the background and foreground color of the "A1" cell.
worksheet.Cells["A1"].Style.BackgroundColor = Color.Yellow;
worksheet.Cells["A1"].Style.ForegroundColor = Color.SkyBlue;
//Setting the background pattern of the "A1" cell.
worksheet.Cells["A1"].Style.Pattern = BackgroundType.ThinDiagonalStripe;
//Saving the Excel file
workbook.Save("f:\\test\\stylesfillcolors1.xls", FileFormatType.Default);
I am getting warning like this: CS1061 C# ‘Cell’ does not contain a definition for ‘Style’ and no extension method ‘Style’ accepting a first argument of type ‘Cell’ could be found #are you missing a using directive or an assembly reference?#
The above code segments shared in this thread are older, so it will work with older versions only. For your information, Cell.Style attribute is obsoleted. There are some changes we made (later on) in the way to apply style/formatting to a cell. In recent versions, Aspose.Cells now provides the GetStyle method in the Cell class to get the existing formatting of a cell. Similarly, the SetStyle method is used to set a cell’s formatting style. The sequence is simple: get the style/formatting of the cell using Cell.GetStyle(), specify the formatting as per your needs and finally apply the style to the cell using Cell.SetStyle() method. See the documents with example codes for your complete reference:
Let us know with sample code if you still find any issue, we will check it soon.