I use the following code to set background color for cells:
XSSFCellStyle cellStyle = (XSSFCellStyle) excelStyle.getCellStyle();
cellStyle.setFillForegroundColor(new XSSFColor(java.awt.Color.decode("#FFFF99")));
cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
But it is not working for cells which are merged, it always becomes black no matter of what I try to set. It is working only if I set a predefined color like:
cellStyle.setFillForegroundColor(IndexedColors.CORAL.index);
The color is defined by user so I can't use IndexedColors
. Also, I can't create a custom palette color (as explained here) because my workbook is of type SXSSFWorkbook
, not HSSFWorkbook
.
How to set background color for merged cells?