In POI3.8, SXSSF only supports excel2007 format as an extension of a stream of XSSF. The purpose of this is to provide the efficiency of writing data by refreshing the Excel memory information to the hard disk when generating a large amount of data in the form of Excel.
The official text reads as follows:
SXSSF (streaming Usermodel API) Note SXSSF is a brand new contribution and some features were added after it was F Irst introduced in POI 3.8-beta3. Users is advised to try the latest build from trunk. Instructions how to build is here.
SXSSF (package:org.apache.poi.xssf.streaming) is a api-compatible streaming extension of XSSF to being used when very l Arge spreadsheets are produced, and heap space is limite d. SXSSF achieves it low memory footprint by limiting Access to the rows is within a sliding window, while XSSF gives access to all rows in the document. Older rows that is no longer in the window become inaccessible, as they is written to the disk.
You can specify the window size @ Workbook construction time via new Sxssfworkbook (int windowsize) or you can SE T it per-sheet via sxssfsheet#setrandomaccesswindowsize (int windowsize)
When a new row was created via CreateRow () and the total number of unflushed records would exceed the specified window Size, then the row with the lowest index value are flushed a nd cannot be accessed via GetRow () anymore.
The default window size is A and defined by Sxssfworkbook.default_window_size.
A windowsize of-1 indicates unlimited access. In the This is records that has not been flushed by a call to Flushrows () is available for random access.
The example below writes a sheet with a window of $ rows. When the row was Count reaches 101, the row with rownum=0 was flushed to disk and removed from memory, when RowNum reaches 102 Then the row with Rownum=1 is flushed, etc.
The test code is as follows:
Java code
- Package com.easyway.excel.events.stream;
- Import Java.io.FileOutputStream;
- 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.SXSSFWorkbook;
- /**
- * SXSSF (streaming Usermodel API)
- * When the file is written in a particularly large stream, flush the in-memory data to the hard disk, reducing the amount of memory used.
- * Play the role of space for time, to provide efficiency.
- *
- * @Title:
- * @version 1.0
- */
- Public class Sxssexcelevent {
- public static void Main (string[] args) throws Throwable {
- //Create a stream-based workbook object
- Workbook WB = new Sxssfworkbook (100); //Keep rows in memory, exceeding rows would be flushed to disk
- //sxssfworkbook wb = new Sxssfworkbook ();
- //wb.setcompresstempfiles (TRUE);//Temp files would be gzipped
- Sheet sh = wb.createsheet ();
- //Use CreateRow to write information in memory.
- For (int rownum = 0; rownum < ; rownum++) {
- Row row = Sh.createrow (rownum);
- For (int cellnum = 0; cellnum < cellnum++) {
- Cell cell = Row.createcell (Cellnum);
- String address = new cellreference (cell). formatasstring ();
- Cell.setcellvalue (address);
- }
- }
- //Rows with rownum < is flushed and not accessible
- //When accessing using the GetRow method, flush the in-memory information to the hard disk.
- For (int rownum = 0; rownum < ; rownum++) {
- System.out.println (Sh.getrow (rownum));
- }
- //ther last rows is still in memory
- For (int rownum = N, rownum < rownum++) {
- System.out.println (Sh.getrow (rownum));
- }
- //write in file
- FileOutputStream out = new FileOutputStream ("c://sxssf.xlsx");
- Wb.write (out);
- //Close File stream object
- Out.close ();
- System.out.println ("Based on stream write execution!");
- }
- }
SXSSF Flushes sheet data in temporary files (a temp file per sheet) and the size of these temporary files can grow to A very large value. For example, A-MB CSV data, the size of the temp XML becomes more than a gigabyte. If the size of the temp files is a issue, you can tell SXSSF to use gzip compression:
Sxssfworkbook wb = new Sxssfworkbook (); Wb.setcompresstempfiles (TRUE);//Temp files would be gzipped
Write files based on the SXSSF (streaming Usermodel API)