How to get the color of Number/Currency format through Aspose.Cells

Hi,


I’m trying to get the color of a negative value from a specific cell that is formatted with Number/Currency where the value is rendered in red if negative (as shown in the attached picture).

I’ve tried the following API:
cell.GetDisplayStyle().ForegroundColor = Collor [Empty]
cell.GetStyle().ForegroundColor = Collor [Empty]
cell.GetDisplayStyle().Font.Color = Collor [A=0, R=0,G=0, B=0]
cell.GetStyle().Font.Color = Collor [A=0, R=0,G=0, B=0]
cell.GetDisplayStyle().ForegroundThemeColor = null
cell.GetStyle().ForegroundThemeColor = null
cell.GetFormatConditions() = null
cell.GetConditionalStyle() = null
cell.GetDisplayStyle().Number = 0
cell.GetStyle().Number =0

I’ve opened the workbook and saved it as PDF and the cell is rendered with red color but there is no information in the API that the cell is going to be red.

Is there a way to get this color from the Aspose API?

Thanks.

Hi,


Thank you for using Aspose.Cells.

You can get the color associated with the Text of a cell using the color property of a cell’s style. Please have a look at the following code for your reference.

Workbook workbook = new Workbook("Source.Xls");
Cell cell = workbook.Worksheets[0].Cells["A1"];
Style style = cell.GetStyle();
Color color = style.Font.Color;
Console.WriteLine(color.Name);

Output: ff0000 (Red Color)

Hi,

Thanks for your posting and using Aspose.Cells for Java.

These negative numbers are always rendered as RED, so you can safely assume that if the number is negative, then its color will always be RED.

All you need to check is that your cell has been formatted as a negative number as you have shown in a screenshot.

You can check it using Style.Number and Style.Custom properties.