Configuring a custom font for XSSFWorkbook in Apache POI

I'm having a little problem setting custom font color for XSSFWorkbook from Apache POI . When I do this:

  yellow = workbook.createCellStyle(); Font whiteFont = workbook.createFont(); whiteFont.setColor(new XSSFColor(new Color(255, 255, 255)).getIndexed()); yellow.setFillForegroundColor(new XSSFColor(yellowRGB)); yellow.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND); yellow.setFont(whiteFont); 

The font remains black; I'm not sure what I'm doing wrong though.

+7
java apache-poi
source share
2 answers

You can do whiteFont.setColor(new XSSFColor(new Color(255,255,255)));

However, there is an error in Apache POI where it switches in black and white. It looks like they put "fix" in XSSFColor.java (look at XSSFColor.correctRGB ()) to fix the problem in Excel. Excel was probably fixed, but the Apache POI was not updated.

Instead, you can do: whiteFont.setColor(HSSFColor.WHITE.index) or whiteFont.setColor(IndexedColors.WHITE.index); (it's out of date)

or if you do whiteFont.setColor(new XSSFColor(new Color(255,255,254))); It will be really close to white.

+6
source share
 XSSFFont font = (XSSFFont) wb.createFont(); font.setColor(new XSSFColor( Color.decode("#7CFC00"))); 
+1
source share

All Articles