Can’t Set Fill Color Apache POI Excel Workbook

Use foreground color instead of Background color.

 errorOccured = true;
 XSSFCellStyle style = workbook.createCellStyle();
 style.setFillForegroundColor(IndexedColors.RED.getIndex());
 style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
 row.getCell(0).setCellStyle(style);

this will fill the cell background color with RED.

Leave a Comment