颜色不会被设置为工作簿

我正在使用java工作簿xls,但我无法设置颜色。我使用下面的代码。

CellStyle cellStyle = sheet.getWorkbook().createCellStyle(); cellStyle.setFillBackgroundColor(HSSFColor.DARK_RED.index); Cell celli = row0.createCell((short) i); celli.setCellValue(list.get(i).toString()); celli.setCellStyle(cellStyle); 

我正在使用cellstyle,但没有设置颜色。

你应该使用

 cellStyle.setFillForegroundColor(HSSFColor.DARK_RED.index); cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); 

代替

 cellStyle.setFillBackgroundColor(HSSFColor.DARK_RED.index);