1
votes

In Apache POI 4.0 I want to set an Excel cell background color like this :

IndexedColorMap colorMap = workbook.getStylesSource().getIndexedColors();
style.setFillForegroundColor(new XSSFColor(java.awt.Color.BLUE, colorMap).getIndex());
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);

    Row header = sheet.createRow(0);
    header.createCell(0).setCellValue("Title");
    header.getCell(0).setCellStyle(style);

.. but all I get are black cells. I've tried many things, but result is always the same.

How can I set the background color of an Excel cell in Apache POI 4.0 ?

1
Did you ever figure out how to do this for a hex or rgb value?Tom Swifty
No, I stopped looking for it. I used @Vasif's answer.Wolf359

1 Answers

1
votes

Try to use below code for background style

style.setFillForegroundColor(IndexedColors.YELLOW.getIndex());