Wolf359
Wolf359

Reputation: 2715

Apache-POI : How to set background color of a cell when creating spreadsheet?

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 ?

Upvotes: 1

Views: 1474

Answers (1)

Vasif
Vasif

Reputation: 768

Try to use below code for background style

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

Upvotes: 1

Related Questions