简单的POI背景填充问题

我使用poi 3.14,我想要的是将单元格的背景设置为橙色。 我不想要一个模式填充,只是一个坚实的橙色,但我不能得到它的工作。 这是我有:

Row row = sheet.createRow(currentRow); CellStyle style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.AUTOMATIC.getIndex()); style.setFillBackgroundColor(IndexedColors.ORANGE.getIndex()); style.setFillPattern(CellStyle.ALIGN_FILL); Cell cell = row.createCell(0); cell.setCellValue("ABCDEFG"); cell.setCellStyle(style); 

我最终得到的是一个small dots图案的橙色背景。 在Excel的属性表上,它说我有bg=orange, fg=automatic, pattern=25% Gray 。 我怎样才能使用一个空白的图案样式?

这看起来不直观,但setFillForegroundColor方法实际上设置的背景填充的前景色不是文本(首先想到的前景)。 同样,您需要使用CellStyle.SOLID_FOREGROUND填充模式。 请参阅下面的工作版本。

 Row row = sheet.createRow(currentRow); CellStyle style = workbook.createCellStyle(); style.setFillForegroundColor(IndexedColors.ORANGE.getIndex()); style.setFillPattern(CellStyle.SOLID_FOREGROUND); Cell cell = row.createCell(0); cell.setCellValue("ABCDEFG"); cell.setCellStyle(style); 

您可以参考poi用户指南了解更多示例: http : //poi.apache.org/spreadsheet/quick-guide.html#FillsAndFrills 。