0

I want to set my own backgroundcolor in XSSFWorkbook. So far i have this code:

 style = wb.createCellStyle();
    style.setAlignment(HorizontalAlignment.RIGHT);
    style.setFont(itemFont);
    style.setFillForegroundColor(new XSSFColor(new java.awt.Color(128, 0, 128)));  
    styles.put("item_right", style);

But i got the following error:

The method setFillForegroundColor(short) in the type CellStyle is not >applicable for the arguments (XSSFColor)

The constructor XSSFColor(Color) is deprecated

So how can i set my own color in XSSFWorkbook ?

Community
  • 1
  • 1
legalizeSINCE88
  • 97
  • 1
  • 11
  • 1
    Have you tried the suggestion here ? [Java Apache Poi, how to set background color and borders at same time](https://stackoverflow.com/questions/38874115/java-apache-poi-how-to-set-background-color-and-borders-at-same-time/46996790) or, in other words, ` backgroundStyle.setFillForegroundColor(IndexedColors.YELLOW.getIndex());` – anasmi Apr 15 '19 at 08:55
  • `cs.setFillForegroundColor( new XSSFColor(new java.awt.Color(128, 0, 128), new DefaultIndexedColorMap()).getIndex());` <-- not tested though – XtremeBaumer Apr 15 '19 at 09:00

1 Answers1

0

One of the solution :

style.setFillForegroundColor(new XSSFColor(new java.awt.Color(128, 0, 128), null));

It's not deprecated with last version.

Fizik26
  • 753
  • 2
  • 10
  • 25