到目前爲止,我使用Spring MVC進行了低層次編碼。如何使用java + poi在excel中設置單元格背景顏色
重要的 - 我不使用這裏HSSFWorkbook
那麼什麼是POI方法setCellStyle的StreamingReader相當於如果單元格的數據進行格式化以及例如
InputStream is = new FileInputStream(new File("file path"));
StreamingReader reader = StreamingReader.builder()
.rowCacheSize(90000000)
.bufferSize(4096)
.sheetIndex(0)
.read(is);
for (Row r : reader) {
Test_huge_excel_data data = new Test_huge_excel_data();
data.setCol1(r.getCell(0).getStringCellValue());
data.setCol2(r.getCell(1).getStringCellValue());
drtamminaService.saveExcelData(data);
}
我的要求是假設「錯誤的數據格式」,所以我想改變特定的單元格背景顏色。
但如果我使用這個我能做到這一點
XSSFWorkbook myWorkBook = new XSSFWorkbook (fileInputStream);
XSSFCellStyle style = myWorkBook.createCellStyle();
style.setFillForegroundColor(IndexedColors.RED.getIndex());
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
row.getCell(30).setCellStyle(style);
但是,當我使用這個代碼,我無法加載一個巨大的文件的數量。
在我上面的代碼中,我只需要修改添加樣式。
您是否收到任何錯誤?在做以上 –
你想要處理的文件有多大? – JensS
@RajuSharma不,我沒有得到任何錯誤..我不知道如何在上面的代碼上應用單元格背景顏色。 –