Free Support Forum -

Problems setting color to formula value cell

Hello, I open an excel file very simple ( cell A1=1, A2=2, A3=Suma(A1:A2) )
Later I define a new style, set the background and foreground color, and assign this style to the three cells (A1, A2 and A3).

When I save the file I see A1 and A2 have the color ok, but A3 don’t; …why?

If I set the formula Suma(A1:A2) at runtime in the code it works fine ( e.Worksheets.GetAt(0).Cells().GetAt(2, 0).Formula = "=Suma(A1:A2) )

Here is the code:

Dim e As New Excel()

Dim s As Style = e.Styles.GetAt(e.Styles.Add())
s.BackgroundColor = Color.Beige
s.ForegroundColor = Color.Yellow

e.Worksheets.GetAt(0).Cells().GetAt(0, 0).Style = s
e.Worksheets.GetAt(0).Cells().GetAt(1, 0).Style = s
e.Worksheets.GetAt(0).Cells().GetAt(2, 0).Style = s

e.Save(“test.xls”, FileFormatType.Default)

This is a bug. I have fixed it. You will get the new release soon.

Thank you very much.

We recommend you to use the following sample code using the latest version of Aspose.Cells for .NET.

Workbook workbook = new Workbook(); // Creating a Workbook object
Worksheet worksheet = workbook.Worksheets[0];
//Accessing cell from the worksheet
Cell cell = worksheet.Cells["B2"];
Style style = cell.GetStyle();            
//Setting the foreground color to yellow            
style.BackgroundColor = Color.Yellow;
//Setting the background pattern to vertical stripe
style.Pattern = BackgroundType.VerticalStripe;            
//Saving the modified style to the "B2" cell.
// === Setting Foreground ===
//Adding custom color to the palette at 55th index
Color color = Color.FromArgb(212, 213, 0);
workbook.ChangePalette(color, 55);
//Accessing cell from the worksheet
cell = worksheet.Cells["B3"];
//Adding some value to the cell
cell.PutValue("Hello Aspose!");
workbook.Save("test.xlsx", SaveFormat.Xlsx); //Workbooks can be saved in many formats

For more details have a look at the following article:
Working With Colors

Download the latest version of Aspose.Cells for .NET from the following link:
Aspose.Cells for .NET (Latest Version)

You can download the latest demos here.