[Java Spring FAQs] Use Alibaba EasyExcel to read or write Excel
EasyExcel
EasyExcel rewrote Apache POI’s analysis of version 07 of Excel. A 3M excel using POI sax analysis still requires about 100M of memory. Switching to easyexcel can be reduced to a few M, and no amount of memory overflow will occur in the larger excel; version 03 depends on The sax mode of POI is encapsulated in the upper layer for model conversion, which makes users more simple and convenient.
Dependencies
Maven:
1 | <!-- pom.xml --> |
Gradle:
1 | // build.gradle |
Usages
Read Excel
1 | /** |
See Read Excel Demo - https://github.com/alibaba/easyexcel/blob/master/src/test/java/com/alibaba/easyexcel/test/demo/read/ReadTest.java to learn more.
See 读Excel · 语雀 - https://www.yuque.com/easyexcel/doc/read#205d07d1 to learn more.
Write Excel
1 | /** |
See [写excel · 语雀 - https://www.yuque.com/easyexcel/doc/write) to learn more.
Web upload and download
1 | /** |
See alibaba/easyexcel: 快速、简单避免OOM的java处理Excel工具 - https://github.com/alibaba/easyexcel/blob/master/src/test/java/com/alibaba/easyexcel/test/demo/web/WebTest.java to learn more.
FAQs
Could not initialize class net.sf.cglib.beans.BeanMap$Generator
1 | i.g.w.e.ErrorHandlingControllerAdvice : java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.beans.BeanMap$Generator |
Remember to import cglib
to solve that issue.
Maven:
1 | <!-- pom.xml --> |
Gradle:
1 | // build.gradle |
java.lang.reflect.InaccessibleObjectException: Unable to make protected final java.lang.Class java.lang
1 | Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @5c909414 |
Get your code running on the Java 9 Module System with the command line options --add-export
s, --add-opens
, --add-modules
, --add-reads
, and --patch-module
.
1 | java --add-opens java.base/java.lang=ALL-UNNAMED --class-path $dependencies -jar $appjar |
References
[1] alibaba/easyexcel: 快速、简单避免OOM的java处理Excel工具 - https://github.com/alibaba/easyexcel
[2] EasyExcel · 语雀 - https://www.yuque.com/easyexcel/doc/easyexcel
[3] Maven Repository: com.alibaba » easyexcel - https://mvnrepository.com/artifact/com.alibaba/easyexcel
[4] Maven Repository: cglib » cglib - https://mvnrepository.com/artifact/cglib/cglib
[5] Apache POI - the Java API for Microsoft Documents - https://poi.apache.org/