We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Color in java - problem

I have a problem with Color element in Java. Can you help me?

Sample code:

{//ok!
Style style = workbook.createStyle();
Color color = new Color(0,0, 255);
//Color color = Color.BLUE;
style.setColor(color);
Cell cell = cells.getCell(3,3);
cell.setStyle(style);
cell.setValue(“TEST”);
}

{//problem!
Style style = workbook.createStyle();
Color color = new Color(0,0, 250);
style.setColor(color);
Cell cell = cells.getCell(4,4);
cell.setStyle(style);
cell.setValue(“TEST”);
}

The second element doesn’t work correctly (look at the attachment, the cell is black ).

Regards,
Pawel

Hi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for considering Aspose.

Well, I think you are saving the excel file in xls (excel 2003) file format. The color (0,0,250) is not supported in the Default Color Palette of MS Excel 2003 or versions before it. To use this color you can add it as a custom color to the Default Color Palette. Please see the following sample code in this regards,

Sample Code:

Workbook wb = new Workbook();

Cells cells = wb.getWorksheets().getSheet(0).getCells();

Style style = wb.createStyle();

Color color = new Color(0,0, 250);

//Adding custom color to the palette at 55th index

wb.getPalette().setColor(55, color);

style.setColor(color);

Cell cell = cells.getCell(4,4);

cell.setStyle(style);

cell.setValue("TEST");

wb.save("c:\\style.xls");

You can also see the following documentation topic regarding Color Palette as a reference,

http://www.aspose.com/documentation/file-format-components/aspose.cells-for-.net-and-java/colors-and-palette.html

Thank You & Best Regards,