当前位置:网站首页>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
边栏推荐
猜你喜欢
prompt.ml/15中<svg>标签使用解释
MySQL database must add, delete, search and modify operations (CRUD)
MySQL常见面试题汇总(建议收藏!!!)
城市内涝及桥洞隧道积水在线监测系统
A complete introduction to JSqlParse of Sql parsing and conversion
Explanation of
npm、nrm两种方式查看源和切换镜像
STM32HAL库修改Hal_Delay为us级延时
Open Source Database Innovation in the Digital Economy Era | 2022 Open Atom Global Open Source Summit Database Sub-Forum Successfully Held
HCIP第十天_BGP路由汇总实验
随机推荐
Lua,ILRuntime, HybridCLR(wolong)/huatuo hot update comparative analysis
【C语言】操作符详解
STM32HAL library modifies Hal_Delay to us-level delay
[py script] batch binarization processing images
ENSP,划分VLAN、静态路由,三层交换机综合配置
centos7安装mysql5.7步骤(图解版)
Blockbuster | foundation for platinum, gold, silver gave nameboards donors
矩池云快速安装torch-sparse、torch-geometric等包
Minesweeper game - C language
BUG destroyer!!Practical debugging skills are super comprehensive
ERROR 2003 (HY000) Can't connect to MySQL server on 'localhost3306' (10061)
CentOS7 —— yum安装mysql
打造基于ILRuntime热更新的组件化开发
Musk talks to the "virtual version" of Musk, how far is the brain-computer interaction technology from us
.NET-9.乱七八糟的理论笔记(概念,思想)
MySQL常见面试题汇总(建议收藏!!!)
Sql解析转换之JSqlParse完整介绍
The MySQL database installed configuration nanny level tutorial for 8.0.29 (for example) have hands
高斯分布及其极大似然估计
sql语句-如何以一个表中的数据为条件据查询另一个表中的数据