当前位置:网站首页>Simple read operation of EasyExcel
Simple read operation of EasyExcel
2022-07-31 04:54:00 【geejkse_seff】
EasyExcel's Simple Read Operation
- The well-known frameworks for parsing and generating Excel in the Java field include Apache poi, jxl, etc.But they all have a serious problem that
consumes a lot of memory.If your system has a small amount of concurrency, it may be ok, but once the concurrency is up, it will definitely be OOM or
or the JVM will frequently perform full gc. - EasyExcel is an excel processing framework open sourced by Alibaba. It is famous for its simplicity of use and memory saving. The main reason why EasyExcel can greatly reduce
memory usage is that when parsing Excel, it does not load all file data into memory at one time, but reads data line by line
from the disk, one by one.Parse. - EasyExcel adopts a line-by-line analysis mode, and notifies the processing
(AnalysisEventListener) of the analysis result of a line in an observer mode.
From official website
Import dependencies
There is a correspondence between this version, otherwise an error will be reported.
org.apache.poi poi 3.17 org.apache.poi poi-ooxml 3.17 com.alibaba easyexcel 2.1.1 Create entity class
@[email protected][email protected] class DemoData {// Set the header name, index represents the index of the [email protected](value = "student number", index = 0)private Integer sno;@ExcelProperty(value = "student name", index = 1)private String sname;}Write Test with EasyExcel
/*** easyExcel write operation test*/@Testpublic void write() {String outputFile = "E:\write11.xlsx";EasyExcel.write(outputFile, DemoData.class).sheet("student list").doWrite(TestEasyExcel.getData());}private static List getData() {List list = new ArrayList<>();for (int i = 0; i < 10; i++) {String name = UUID.randomUUID().toString().replace("-", "").substring(0, 5);list.add(new DemoData(i, name));}return list;} 

Read with EasyExcel
The ExcelListener is required when reading.
Create an ExcelListener class to inherit AnalysisEventListener and bring the objects in the excel table
/*** Created with IntelliJ IDEA.* @Author: pzx* @Date: 2022/01/30 15:46* @Version:1.0*/public class ExcelListener extends AnalysisEventListener {// Read the content in excel line by line (the header will not be read)@Overridepublic void invoke(DemoData data, AnalysisContext context) {System.out.println("********" + data);}// read the contents of the [email protected] void invokeHeadMap(Map headMap, AnalysisContext context) {System.out.println("Header " + headMap);}// what to do after [email protected] void doAfterAllAnalysed(AnalysisContext context) {}} Code Test
/*** easyExcel read operation test*/@Testpublic void read() {String outputFile = "E:\write11.xlsx";// Add a listener that inherits the AnalysisEventListener classExcelListener excelListener = new ExcelListener();EasyExcel.read(outputFile,DemoData.class, excelListener).sheet().doRead();}
Let me introduce myself first. The editor graduated from Jiaotong University in 2013. I worked in a small company and went to big factories such as Huawei and OPPO. I joined Ali in 2018, until now.I know that most junior and intermediate java engineers want to upgrade their skills, they often need to explore their own growth or sign up to study, but for training institutions, the tuition fee is nearly 10,000 yuan, which is really stressful.Self-learning that is not systematic is very inefficient and lengthy, and it is easy to hit the ceiling and the technology stops.Therefore, I collected a "full set of learning materials for java development" for everyone. The original intention is also very simple. I hope to help friends who want to learn by themselves but don't know where to start, and at the same time reduce everyone's burden.Add the business card below to get a full set of learning materials
边栏推荐
猜你喜欢

【debug锦集】Expected input batch_size (1) to match target batch_size (0)

Musk talks to the "virtual version" of Musk, how far is the brain-computer interaction technology from us

sql statement - how to query data in another table based on the data in one table

ERROR 1819 (HY000) Your password does not satisfy the current policy requirements

Blockbuster | foundation for platinum, gold, silver gave nameboards donors

论治理与创新 | 2022开放原子全球开源峰会OpenAnolis分论坛圆满召开

两个地址池r2负责管地址池r1负责管dhcp中继

MySQL database backup

mysql存储过程

SQL row-column conversion
随机推荐
MySQL数据库增删改查(基础操作命令详解)
The 15th day of the special assault version of the sword offer
visual studio 那些提高效率的快捷键,总结(不时更新)
prompt.ml/15中<svg>标签使用解释
SQL injection of DVWA
【ORACLE Explain 详解】
Lua,ILRuntime, HybridCLR(wolong)/huatuo hot update comparative analysis
开源汇智创未来 | 2022开放原子全球开源峰会OpenAtom openEuler分论坛圆满召开
Sun Wenlong, Secretary General of the Open Atom Open Source Foundation |
PWN ROP
Open Source Smart Future | 2022 OpenAtom Global Open Source Summit OpenAtom openEuler sub-forum was successfully held
Basic knowledge of mysql (2)
参考代码系列_1.各种语言的Hello World
扫雷小游戏——C语言
ERROR 1819 (HY000) Your password does not satisfy the current policy requirements
Summary of MySQL common interview questions (recommended collection!!!)
开源社区三十年 | 2022开放原子全球开源峰会开源社区三十年专题活动圆满召开
Puzzle Game Level Design: Reverse Method--Explaining Puzzle Game Level Design
Musk talks to the "virtual version" of Musk, how far is the brain-computer interaction technology from us
数字经济时代的开源数据库创新 | 2022开放原子全球开源峰会数据库分论坛圆满召开