I'm having a little trouble with setting a custom font color for an XSSFWorkbook
from Apache POI
. When I do:
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 stays black, I'm not sure what I'm doing wrong though.
You can do whiteFont.setColor(new XSSFColor(new Color(255,255,255)));
However, there is a bug in Apache POI, where it is switching black and white. It looks like they put a 'fix' in XSSFColor.java (look at XSSFColor.correctRGB()) to correct for a problem in Excel. It's likely that Excel was fixed, but Apache POI wasn't updated.
Instead you can do: whiteFont.setColor(HSSFColor.WHITE.index)
or whiteFont.setColor(IndexedColors.WHITE.index);
(this is deprecated)
or if you do whiteFont.setColor(new XSSFColor(new Color(255,255,254)));
it'll be really close to white.
XSSFFont font = (XSSFFont) wb.createFont();
font.setColor(new XSSFColor( Color.decode("#7CFC00")));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With