2

I am using the below code to to write data to excel

XLSTransformer transformer = new XLSTransformer();

        InputStream is = this.getServlet().getServletContext()
                .getResourceAsStream(templateFilePath);
        HSSFWorkbook workBook = (HSSFWorkbook) transformer.transformXLS(is, beans);

But but the system hangs after HSSFWorkbook workBook = (HSSFWorkbook) transformer.transformXLS(is, beans); if number of rows is more than 1500. Is there any other way or suggetsion for writing data using template and beans objects for large data sets

user2025528
  • 155
  • 3
  • 9

2 Answers2

2

You can upgrade to Jxls-2 and use SXSSF Transformer support. The code may look like this

            Transformer transformer = PoiTransformer.createSxssfTransformer(workbook, 100, false);
            AreaBuilder areaBuilder = new XlsCommentAreaBuilder(transformer);
            List<Area> xlsAreaList = areaBuilder.build();
            Area xlsArea = xlsAreaList.get(0);
            xlsArea.applyAt(new CellRef("Result!A1"), context);

See full example in jxls-demo. Please note that this approach assumes some template restrictions given that only a subset of rows is kept in memory (in particular regarding to formula evaluation).

If you do not need formulas it is recommended to disable formula processing using context.getConfig().setIsFormulaProcessingRequired(false);

Leonid Vysochyn
  • 1,254
  • 1
  • 7
  • 12
1

You could try to use SXSSF - the streaming version of the POI workbook. This is a guess.

neal
  • 880
  • 6
  • 11