当前位置:网站首页>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
边栏推荐
- Go语学习笔记 - 处理超时问题 - Context使用 | 从零开始Go语言
- EasyExcel的简单读取操作
- 关于出现大量close_wait状态的理解
- MySQL optimization: from ten seconds to three hundred milliseconds
- Musk talks to the "virtual version" of Musk, how far is the brain-computer interaction technology from us
- MySQL fuzzy query can use INSTR instead of LIKE
- 【C语言】操作符详解
- 开源社区三十年 | 2022开放原子全球开源峰会开源社区三十年专题活动圆满召开
- ENSP,划分VLAN、静态路由,三层交换机综合配置
- HCIP第十天_BGP路由汇总实验
猜你喜欢

DVWA安装教程(懂你的不懂·详细)

mysql数据库安装(详细)

Minesweeper game - C language

VScode+ESP32快速安装ESP-IDF插件

MySQL based operations

The input input box displays the precision of two decimal places

EasyExcel的简单读取操作

C language confession code?

On Governance and Innovation | 2022 OpenAtom Global Open Source Summit OpenAnolis sub-forum was successfully held

产学研用 共建开源人才生态 | 2022开放原子全球开源峰会教育分论坛圆满召开
随机推荐
Gaussian distribution and its maximum likelihood estimation
MySQL database must add, delete, search and modify operations (CRUD)
[R language] [3] apply, tapply, lapply, sapply, mapply and par function related parameters
Go语学习笔记 - 处理超时问题 - Context使用 | 从零开始Go语言
MySQL fuzzy query can use INSTR instead of LIKE
参考代码系列_1.各种语言的Hello World
SQL injection of DVWA
SQL row-column conversion
Win10 CUDA CUDNN installation configuration (torch paddlepaddle)
【线性神经网络】softmax回归
ERP Production Operation Control Kingdee
SQL行列转换
两个地址池r2负责管地址池r1负责管dhcp中继
A complete introduction to JSqlParse of Sql parsing and conversion
sql statement - how to query data in another table based on the data in one table
MySQL事务隔离级别详解
Unity教程:URP渲染管线实战教程系列【1】
DVWA安装教程(懂你的不懂·详细)
Visual studio shortcuts that improve efficiency, summary (updated from time to time)
行业落地呈现新进展 | 2022开放原子全球开源峰会OpenAtom OpenHarmony分论坛圆满召开