A, EasyExcel Overview
Java parsing, generating more famous Excel framework Apache poi, jxl. But they are there is a very serious problem is the memory consumption, poi set SAX API model can solve some memory overflow problem to some extent, but there are some flaws POI, such as version 07 Excel decompression, and after decompression are stored is done in memory, memory consumption is still great. easyexcel rewrote the parsing of poi 07 Excel version can be had with a 3M's excel POI sax still need about 100M memory is reduced to a few M, and then a big excel will not be out of memory, 03 POI's sax version-dependent mode. In the upper made a model conversion package, allowing users to more simple and convenient.
github Address: https://github.com/alibaba/easyexcel
Use document: https://alibaba-easyexcel.github.io/
Official data given, 64M memory read within 1 minute 75M (46W line 25) of Excel, of course, the rapid mode faster, but the memory footprint will be a little over 100M:
Two, EasyExcel common functions
Reading Excel
- The simplest reading
- The designated column index or column name
- Read more sheet
- Dates, numbers, or custom format conversion
- Multi-line head
- Synchronization of return
- Reading header data
- Exception handling data conversion
- Does not create the object read
- Read the web
Write Excel
- The easiest write
- Export only according to the parameters specified column
- Specified column written
- Complex write head
- Repeated many times writing (write single or multiple Sheet)
- Dates, numbers, or custom format conversion
- Picture Export
- Written according to the template
- Column width, row height
- Custom Style
- Merge Cells
- Use table to write
- Head dynamic, real-time generation write head
- Automatic column width (less accurate)
- Custom interceptor (with reference to the above points it is to be incompatible with the operation of this cell)
- Do not create an object to write
- The write web
- Write web of time and failed to return json
Filling Excel
- The easiest filling
- Fill the list
- Complex hatch
- Large amount of data to fill complex
- Lateral filling
Three, EasyExcel use and Tuning
In addition to official documents, but also provides a powerful demo code. The code is not posted, I only give maven coordinates:
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>2.1.4</version>
</dependency>
The default large file handling
The default handling large files will automatically determine, shared the following string 5M uses memory storage, taking up about 15-50M of memory, more than 5M use file storage, file storage and then have to set up multiple M memory used to store temporary shared string The default 20M. In addition to the shared memory for the string, the other less occupied, it can be estimated 10M, 30M so the default probably be able to read a super large files.
Memory configuration according to the actual needs
Four, EasyExcel core principles
1, unzip the file to read the file by the file format
2, to avoid all the all the data once loaded into memory
Sax parsing mode using the line by line, and the result of the analysis notification processing line in the viewer mode.
3, discard unimportant data
Excel will be included when parsing style, font, width and other data, but the data that we do not care if this part of the discarded data can greatly reduce memory usage. Style in Excel data accounted for a large space.
Fifth, the advantages and disadvantages of the project
The project is not focused on Ali project, currently only three people to maintain, but the project is very active, get a few star is also very high, it can be used as a production. But we know that there are still not yet achieved the following features:
- Concurrent writes a single file, reading
- Read picture
- Macros
- csv reading (the follow-up may be considered)