Use EasyExcel import and export Excel Excel Report -JAVA analytical tool

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

Write Excel

Filling Excel

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

Screen shot 2018-01-22 8.52.08.png am

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. Basic template 1 (2) .png

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)

Guess you like

Origin blog.csdn.net/m0_37609579/article/details/103568927