Cells(1- 1).Style.BackgroundColor.ToString

Hi,

when I use this

Cells(r, 2).Style.BackgroundColor.ToString to obtain the backgroundColor of the cell, it always return Black color, even though it was yallow.

Benny.

Please try Style.ForegroundColor.

We get the same result. Although I cannot see how using the foreground property to get the background color could help. Is te Forground property used to set the Font Color, or the cell background?

Note: When the color is set from within Aspose, it works. but if we are using a template that was created in Excel, and we try to access those properties, we always get the color black.

Please try the following code:

Excel excel = new Excel();
excel.Open(“d:\book1.xls”);
Console.WriteLine(excel.Worksheets[0].Cells[“b2”].Style.ForegroundColor.ToString());

The output is:
Color [A=255, R=255, G=255, B=0]

You can use Font.Color to set font color. When the cell background pattern is solid, only foreground color will take effect. If you change the background pattern to other values, foreground color and background color will all take effect.

@EricP,
Aspose.Cells has replaced Aspose.Excel that is no more under active development now and is discontinued. This new product also supports formatting the cells using the style properties. As described above, if pattern is solid, only foreground color will take effect. You can check this behaviour in the following example where background color is set with solid pattern but it is ignored.

Workbook workbook = new Workbook();

Style SolidStyle = workbook.CreateStyle();
SolidStyle.Name = "SolidStyle";

// Set the Style fill color to Yellow
SolidStyle.Pattern = BackgroundType.Solid;
SolidStyle.ForegroundColor = Color.Yellow;
SolidStyle.BackgroundColor = Color.Red;

Style DiagonalStripe = workbook.CreateStyle();
DiagonalStripe.Name = "DiagonalStripe";

// Set the Style fill color to Yellow
DiagonalStripe.Pattern = BackgroundType.DiagonalStripe;
DiagonalStripe.ForegroundColor = Color.Yellow;
DiagonalStripe.BackgroundColor = Color.Red;

MemoryStream memoryStream = new MemoryStream();

// Save the workbook
workbook.Save(memoryStream, SaveFormat.Xlsx);

LoadOptions loadOptions = new LoadOptions(LoadFormat.Xlsx);
Workbook workbook2 = new Workbook(memoryStream, loadOptions);

SolidStyle = workbook2.GetNamedStyle("SolidStyle");
workbook2.Worksheets[0].Cells["A1"].SetStyle(SolidStyle);

Console.WriteLine("Pattern " + SolidStyle.Pattern);
Console.WriteLine("BackgroundColor " + SolidStyle.BackgroundColor + "=>It was set RED but result is White ");
Console.WriteLine("ForegroundColor " + SolidStyle.ForegroundColor);

DiagonalStripe = workbook2.GetNamedStyle("DiagonalStripe");
workbook2.Worksheets[0].Cells["A3"].SetStyle(DiagonalStripe);

Console.WriteLine("Pattern " + DiagonalStripe.Pattern);
Console.WriteLine("BackgroundColor " + DiagonalStripe.BackgroundColor);
Console.WriteLine("ForegroundColor " + DiagonalStripe.ForegroundColor);

workbook2.Save("output.xlsx");

Here is the program output:

BackgroundColor Color [White]=>It was set RED but result is White 
ForegroundColor Color [A=255, R=255, G=255, B=0]
Pattern DiagonalStripe
BackgroundColor Color [A=255, R=255, G=0, B=0]
ForegroundColor Color [A=255, R=255, G=255, B=0]

For more innformation on formatting cells, have a look at the following article:
Format Cells using GetStyle and SetStyle Methods

Here is the latest version that can be downloaded to test the features of this new product:
Download the latest version here to test the features of this new product:
Aspose.Cells for .NET (Latest Version)

Download a runnable solution here that can be used to test the product using variety of ready to run examples.