Negative Values are coming in parentheses and in red colour

Hi All,

I am generating excel using Aspose Cells java . Negative values are getting displayed in parentheses and in red colour.

Ex : value -8457000000 is getting displayed as (8,457,000,000.00).

PLease help me.

Hi,


You got to specify/update Numbers formatting accordingly for your needs:
e.g
Sample code:

Workbook wb = new Workbook(“Book1.xlsx”);
Worksheet sheet = wb.getWorksheets().get(0);
Style style = sheet.getCells().get(“A1”).getStyle();
style.setCustom(“0”); //It will remove the red color and parentheses with decimal places for negative numbers.
sheet.getCells().get(“A1”).setStyle(style);
System.out.println(sheet.getCells().get(“A1”).getStringValue());


See the document for your reference:

Thank you.


Hi,

I need to display the negative values in parentheses but in the red colour.Is there any property to acheive it ..?

Hi,


Ok, sure, you may try “#,##0.00_);Red” custom number formatting for your needs:
e.g
Sample code:

Workbook wb = new Workbook(“Book1.xlsx”);
Worksheet sheet = wb.getWorksheets().get(0);
Style style = sheet.getCells().get(“A1”).getStyle();
style.setCustom("#,##0.00_);Red"); //The negative numbers would be in parenthesis with red color now.
sheet.getCells().get(“A1”).setStyle(style);

Thank you.