Reputation: 187
Workbook workbook = new HSSFWorkbook();
Sheet worksheet = workbook.createSheet("test sheet");
Row row1 = worksheet.createRow(0);
Cell cell0 = row1.createCell(0);
CellStyle testStyle = workbook.createCellStyle();
testStyle.setFillBackgroundColor(IndexedColors.RED.getIndex());
cell0.setCellStyle(testStyle);
I`m trying to change background color of the cell to red. But actually the background color of the cell is not changing. It is still white
Upvotes: 0
Views: 2547
Reputation: 1451
If @XtremeBaumer's solution does not work, after adding that line please change this line. from
testStyle.setFillBackgroundColor(IndexedColors.RED.getIndex());
to
testStyle.setFillForegroundColor(IndexedColors.RED.getIndex());
If you use Apache Poi HSSF this one more suitable.
Upvotes: 1
Reputation: 6435
you are missing the line:
testStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
This will tell apache-poi how visible the color should be.
Upvotes: 5