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

Free Support Forum - aspose.com

setForegroundColor bug

Hi,

Please check following source code :

Workbook workbook = new Workbook();

Worksheet sheet = workbook.getWorksheets().get(0);

sheet.getCells().get("A1").putValue("test");

Style style = sheet.getCells().get("A1").getStyle();

style.setForegroundColor(Color.getRed());

style.getFont().setColor(Color.getBlue());

sheet.getCells().get("A1").setStyle(style);

workbook.save("c:\\out.xls", FileFormatType.EXCEL_97_TO_2003);

I expect to see the first cell A1 with text "test" with font color blue on red background. Following javadoc, I use setForegroundColor and not setBackgroundColor. The result is that the cell's color remains white.

(Btw, if I use setBackgroundColor it's still white)

Using .cells 7.0.0.3 with JDK 1.4

Guillaume

Hi,


When you use Foreground Color or Background Color, you also have to set Pattern type. See your updated code, I only added one line there, it works fine.

Workbook workbook = new Workbook();

Worksheet sheet = workbook.getWorksheets().get(0);

sheet.getCells().get(“A1”).putValue(“test”);

Style style = sheet.getCells().get(“A1”).getStyle();

style.setForegroundColor(Color.getRed());

style.setPattern(BackgroundType.SOLID);

style.getFont().setColor(Color.getBlue());

sheet.getCells().get(“A1”).setStyle(style);

workbook.save(“c:\out.xls”, FileFormatType.EXCEL_97_TO_2003);


For complete reference, see the document:

http://www.aspose.com/documentation/java-components/aspose.cells-for-java/colors-background-patterns.html


Thank you.

Ok it works fine,

I didn't know the pattern was request.

Thank you

Well,

It seems Color.getLightGreen() returns light grey color, can you confirm it ?

Hi,

I found it returns color: 90ee90


It is actually a light green color as shown below



Screenshot:

I haven't the same result :

style.setPattern(BackgroundType.SOLID);

sheet.getCells().get(0,0).putValue("light green");

style.setForegroundColor(Color.getLightGreen());

sheet.getCells().get(1,0).setStyle(style);

But I decide to use RVB code, no surprise with it

Guillaume

Hi,


It works fine, here is my sample code and please find attached the output file.

Sample code:

Workbook workbook = new Workbook();
Worksheet sheet = workbook.getWorksheets().get(0);
sheet.getCells().get(“A1”).putValue(“test”);
Style style = sheet.getCells().get(“A1”).getStyle();
style.setForegroundColor(Color.getLightGreen());
style.setPattern(BackgroundType.SOLID);
style.getFont().setColor(Color.getBlue());
sheet.getCells().get(“A1”).setStyle(style);
workbook.save(“out_Background.xls”, FileFormatType.EXCEL_97_TO_2003);


I am using v7.0.1.1, please try it.

Thank you.

Hi,

Please see the code below and the output file generated by it from the attachment. It is working fine.

I am using the latest version:
Aspose.Cells for Java v7.0.1.1


Java


Workbook wk = new Workbook();


Worksheet sheet = wk.getWorksheets().get(0);


Cell cell = wk.getWorksheets().get(0).getCells().get(“A1”);


Style style = cell.getStyle();


style.setPattern(BackgroundType.SOLID);


cell.putValue(“light green”);


style.setForegroundColor(Color.getLightGreen());


cell.setStyle(style);


wk.save(“F:\Shak-Data-RW\Downloads\output.xlsx”, SaveFormat.XLSX);