我尝试使用 Apache POI 更改连续单元格的背景颜色。我使用以下代码在 xls
文件中处理它,但执行后文件没有任何变化。
FileInputStream fis = new FileInputStream(src);
HSSFWorkbook wb = new HSSFWorkbook(fis);
r = sheet.getRow(5);
CellStyle style = wb.createCellStyle();
style.setFillForegroundColor(IndexedColors.RED.getIndex());
r.setRowStyle(style);
最佳答案
单元格的样式必须像这样定义。
HSSFCellStyle tCs = wb.createCellStyle();
tCs.setFillPattern(FillPatternType.SOLID_FOREGROUND);
tCs.setFillForegroundColor(IndexedColors.YELLOW.getIndex());
它必须应用于需要这种样式的每个单元格。
for (int k = 0; k < sheet.getRow(5).getLastCellNum(); k++) {
sheet.getRow(i).getCell(k).setCellStyle(tCs);
}
关于java - 使用 Apache POI 更改行的背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55281346/