Using custom colors with SXSSF (Apache POI)

后端 未结 3 759
广开言路
广开言路 2021-01-12 02:48

I am trying to write a huge excel file, my requirement allows me to write the row and forget, so i am using SXSSF which allows to keep only a few number of rows in memory an

3条回答
  •  孤街浪徒
    2021-01-12 03:39

    So, after a bit of searching through the web and reading the docs, i got a hint that SXSSF is actually a wrapper around XSSF, so i typecasted the CellStyle returned by SXSSF workbook to XSSF and was able to use XSSFColor directly for generating colors.

    SXSSFWorkbook workbook = new SXSSFWorkbook(50); 
    Sheet sheet = workbook.createSheet("Image Data"); 
    ....
    Cell cell = row.createCell(j);
    cell.setCellValue(j);
    XSSFCellStyle cs1 = (XSSFCellStyle) workbook.createCellStyle();
    cs1.setFillForegroundColor(new XSSFColor(new java.awt.Color(red,green,blue)));          
    cs1.setFillPattern(CellStyle.SOLID_FOREGROUND);
    cell.setCellStyle(cs1);
    

提交回复
热议问题