当前位置:网站首页>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
边栏推荐
- sql语句之多表查询
- PCL calculates the point cloud coordinate maximum and its index
- npm、nrm两种方式查看源和切换镜像
- MySQL模糊查询可以使用INSTR替代LIKE
- open failed: EACCES (Permission denied)
- Explanation of
- Duplicate entry ‘XXX‘ for key ‘XXX.PRIMARY‘解决方案。
- EasyExcel的简单读取操作
- centos7安装mysql5.7步骤(图解版)
- The idea project obviously has dependencies, but the file is not displayed, Cannot resolve symbol 'XXX'
猜你喜欢
MySQL数据库备份
扫雷小游戏——C语言
Unity URP渲染管线摄像机核心机制剖析
Basic knowledge of mysql (2)
ERROR 2003 (HY000) Can't connect to MySQL server on 'localhost3306' (10061)Solution
Industry landing presents new progress | 2022 OpenAtom Global Open Source Summit OpenAtom OpenHarmony sub-forum was successfully held
两个地址池r2负责管地址池r1负责管dhcp中继
Hand in hand to realize the picture preview plug-in (3)
开放原子开源基金会秘书长孙文龙 | 凝心聚力,共拓开源
MySQL事务隔离级别详解
随机推荐
【R语言】【3】apply,tapply,lapply,sapply,mapply与par函数相关参数
ENSP, VLAN division, static routing, comprehensive configuration of Layer 3 switches
打造基于ILRuntime热更新的组件化开发
MySQL database installation (detailed)
12个MySQL慢查询的原因分析
ERROR 1064 (42000) You have an error in your SQL syntax; check the manual that corresponds to your
Minio上传文件ssl证书不受信任
Fusion Cloud Native, Empowering New Milestones | 2022 Open Atom Global Open Source Summit Cloud Native Sub-Forum Successfully Held
MySQL forgot password
Visual studio shortcuts that improve efficiency, summary (updated from time to time)
PCL 计算点云坐标最值及其索引
open failed: EACCES (Permission denied)
SQL行列转换
数字经济时代的开源数据库创新 | 2022开放原子全球开源峰会数据库分论坛圆满召开
PCL calculates the point cloud coordinate maximum and its index
Heavyweight | The Open Atomic School Source Line activity was officially launched
centos7安装mysql5.7步骤(图解版)
Unity打灵狐者
ERP生产作业控制 金蝶
ERROR 1064 (42000) You have an error in your SQL syntax; check the manual that corresponds to your