int firstRowNum = wsheet.getFirstRowNum();
int lastRowNum = wsheet.getLastRowNum();
Row row = null;
Cell cell_a = null;
CellStyle style=wbModule.createCellStyle();
style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
style.setFillForegroundColor(HSSFColor.RED.index);
for (int i = firstRowNum+1; i <= lastRowNum; i++) {
row = wsheet.getRow(i); //取得第i行
cell_a = row.getCell(10); //取得i行的第10列
String cellValue = cell_a.getStringCellValue();
if("".equals(cellValue)){
cell_a.setCellStyle(style);
}
}
如图,我只想改变当前表格内容为空的填充颜色,可是边框和字体都改变了,怎么让保持以前,只改变颜色
你们的cellStyle都是整列的style.
如果要取得的单独的单元格style。应该这样
cellStyle = cell.getRow().getSheet().getWorkbook().createCellStyle();
cellStyle.cloneStyleFrom(cell.getCellStyle());
cell.setCellStyle(cellStyle);
cell.setCellValue(*);
这么久了,楼主应该不回来了。就是希望能帮到后来人吧!
你试试这个
https://blog.csdn.net/qq_27937043/article/details/72783512
你可以看看这个:POI中文文档https://download.csdn.net/download/qq_38361634/10775499
CellStyle style = cell.getCellStyle();
style.setFillForegroundColor(IndexedColors.RED.getIndex());
cell.setCellStyle(style);
试试这种方式。