Current location - Loan Platform Complete Network - Big data management - How xssfworkbook solves scientific calculation method
How xssfworkbook solves scientific calculation method
Previous versions of POI did not support big data processing. If there is too much data, OOM errors are often reported, and sometimes the effect of adjusting JVM is not very good. POI version 3.8 has a new SXSFWorkbook, which can support the operation of large data, but SXSFWorkbook only supports it. Xlsx format, not. Xls format.

Usually only HSSFWorkbook and SXSFWorkbook are used to export excel from poi version 3.8. HSSFWorkbook is used to deal with less data, and SXSFWorkbook is used to deal with the export of big data and super-large data.

The usage of HSSFWorkbook is the same as that of the previous version, so I won't repeat it here.

Examples of the use of SXSSFWorkbook are as follows:

Import JUnit.framework.assert;

Import org.apache.poi.ss.usermodel.cell;

Import org.apache.poi.ss.usermodel.row;

Import org.apache.poi.ss.usermodel.sheet;

Import org.apache.poi.ss.usermodel.workbook;

Import org.apache.poi.ss.util.cellreference;

Import org.apache.poi.xssf.streaming.sxsfworkbook;

Public static void main(String[] args) throws Throwable {

Workbook WB = new sxss SF workbook (100); //Keep 100 lines in memory, and the lines that exceed will be refreshed to disk.

sheet sh = WB . create sheet();

for(int rownum = 0; rownum & lt 100000; rownum++){

row row = sh . create row(rownum);

for(int cell num = 0; cellnum & lt 10; cellnum++){

cell cell = row . create cell(cell num);

String address = new cell reference (cell). formatAsString();

Cell.setCellValue (address); }

}

file output stream out = new file output stream("/temp/sxssf . xlsx ");

WB . write(out);

out . close();

}