Problems when converting XSSFWorkbook to SXSSFWorkbook APACHE POI

3.6k views Asked by At

I'm triying to convert a xssfWorkbook file to a SXSSF because I'm generating a big report, but the problem is that I cannot convert, what I'm currently trying is this example.

public void export(Workbook hssfWorkbook, Map<String, Object> model) throws Exception {
    XSSFWorkbook workbook = (XSSFWorkbook)hssfWorkbook;
    Sheet sheet = workbook.getSheet(this.excelSheetName);
    try {
    this.initCommonCellStyles(workbook);
    List<ItemsToBillReport> itemsObject= (List<ItemsToBillReport>)model.get("the model name");

    CellStyle boldCellStyle = workbook.createCellStyle();
    this.setCellStyleBoldFont(workbook, boldCellStyle);
    new HSSFColor.GREY_40_PERCENT();
    boldCellStyle.setFillForegroundColor(GREY_40_PERCENT.index);
    boldCellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);

    Row bdmRow = sheet.getRow(0);
    Cell bdmCell = bdmRow.getCell(0);
    Bdm bdm = (Bdm)model.get("anoder model");
    if(bdm != null && bdm.getLastName()!=null && bdm.getFirstName()!=null){
        bdmCell.setCellValue("BDM : "+bdm.getLastName()+", "+bdm.getFirstName());
    }else{
        bdmCell.setCellValue("BDM : -");
    }
    bdmCell.setCellStyle(boldCellStyle);

    Row billDateRow = sheet.getRow(1);
    Cell billDateCell = billDateRow.getCell(0);
    String dateFrom = (String)model.get("date from model");
    String dateTo = (String)model.get("dateTo");
    billDateCell.setCellValue("title "+ dateFrom +" TO "+dateTo);
    billDateCell.setCellStyle(boldCellStyle);

    Row dateTimeRow = sheet.getRow(2);
    Cell dateTimeCell = dateTimeRow.getCell(0);
    Format formatter;
    final Date date = new Date();
    formatter = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
    String dateString = formatter.format(date);
    dateTimeCell.setCellValue("AS OF : "+dateString);
    dateTimeCell.setCellStyle(boldCellStyle);

    boolean includeFullData = (Boolean)model.get(thisExporter.INCLUDE_FULL_DATA);
    boolean isBriefView = (Boolean)model.get(thisExporter.ATTRIBUTE_ITB_BRIEF_VIEW);

    SXSSFWorkbook wb = new SXSSFWorkbook(workbook,1000);
    sheet = wb.createSheet(this.excelSheetName);
    final int totalColNum = this.printItemsToBillListDetails(sheet, itemsObject, includeFullData, isBriefView);
    //this.autosizeColumns(sheet, totalColNum);
    }catch(Exception e){
        Exception h = e;
    }

}

As you can see, I'm generating the report with a template file because there is some data that goes at the begining, when I try to convert to SXSSF at the beggining, it cannot be done because if I understood correctly, SXSSF has to write in an empty space, since this is a template it can't write it there.

So I tried to convert after the first rows but is not printing anything, it generates the first rows with the info but at the moment to write the data it writes nothing, so, how can I convert ot SXSSF using a template like this example of mine?

Thank you for your time, I just can't find an answer.

0

There are 0 answers