关于java导出excel加背景色部分不生效的问题
private void setCellGroudColor(Sheet sheet, Cell cell, short colorValue)
{
HSSFCellStyle style = (HSSFCellStyle) sheet.getWorkbook()
.createCellStyle();
style.setBorderTop(HSSFCellStyle.BORDER_THIN);
style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
style.setBorderRight(HSSFCellStyle.BORDER_THIN);
style.setTopBorderColor(HSSFColor.BLACK.index);
style.setBottomBorderColor(HSSFColor.BLACK.index);
style.setLeftBorderColor(HSSFColor.BLACK.index);
style.setRightBorderColor(HSSFColor.BLACK.index);
style.setFillForegroundColor(colorValue);
style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC
&& HSSFDateUtil.isCellDateFormatted(cell))
{
style.setDataFormat(sheet.getWorkbook().createDataFormat()
.getFormat("yyyy/m/d"));
cell.setCellStyle(style);
Date date = cell.getDateCellValue();
cell.setCellValue(date);
}
else
{
cell.setCellStyle(style);
}
}
我在for循环里多次调用这个方法,导出的excel里,为什么只有第一行的有背景色,而其他的没有呢?