user2025528
user2025528

Reputation: 155

Writing large number of rows using jxls to excel in java

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

Upvotes: 2

Views: 3624

Answers (2)

Leonid Vysochyn
Leonid Vysochyn

Reputation: 1264

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);

Upvotes: 2

neal
neal

Reputation: 905

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

Upvotes: 1

Related Questions