设置单元格颜色代码:
CellStyle st = workbook.createCellStyle(); st.setFillForegroundColor(clr.getIndex()); st.setFillPattern(FillPatternType.SOLID_FOREGROUND); cell.setCellStyle(st);
以下代码遍历全部颜色并输出对照:
Sheet sheet = workbook.createSheet("name");
int row = 0;
int col = 0;
Row prow = sheet.createRow(row);
for(IndexedColors clr : IndexedColors.values()){
Cell cell = prow.createCell(col);
cell.setCellValue(clr.toString());
cell = prow.createCell(col+1);
CellStyle st = workbook.createCellStyle();
st.setFillForegroundColor(clr.getIndex());
st.setFillPattern(FillPatternType.SOLID_FOREGROUND);
cell.setCellStyle(st);
col+=3;
if(col >= 10){
col = 0;
row++;
prow = sheet.createRow(row);
}
}
颜色及代码枚举对应关系: