当前位置:网站首页>Easyexcel: read Excel data into the list set
Easyexcel: read Excel data into the list set
2022-06-27 06:38:00 【YUELEI118】
1. pom.xml
Add dependency
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>3.1.0</version>
</dependency>
2. Defining entity classes
annotation :@ExcelProperty(" Parameters "), Parameters of the corresponding Excel Column name in , There is no order , Write whatever column you want .
public class ReportDetail {
// ExcelIgnore annotation : Entity classes need , however Excel Columns not in , there id Is the self increment of the database ID Primary key
@ExcelIgnore
private Integer id;
@ExcelProperty(" full name ")//Excel Column name in
private String personName;
.
.
// No arguments structure : must
// There are parametric structures ,get/set Method
3. Define storage Excel Secondary data list aggregate
ArrayList<ReportDetail> reportDetails = new ArrayList<>();
4. Read Excel
read Method :
The first parameter :path:Excel File path or InputStream
The second parameter : Entity class
The third parameter :ReadListener Anonymous implementation class of , Parameters in generics : Entity class type
EasyExcel.read( route , Entity class name .class, new AnalysisEventListener< Entity class name >() {
@Override
public void invoke( Entity class name Shape parameter , AnalysisContext analysisContext) {
list aggregate .add( Shape parameter );
}
@Override
public void doAfterAllAnalysed(AnalysisContext analysisContext) {
}
}).sheet("Excel Table name in , Default first table ").doRead();
- Corresponding to the above entity class and list aggregate
EasyExcel.read(path, ReportDetail.class, new AnalysisEventListener<ReportDetail>() {
@Override
public void invoke(ReportDetail reportExcel, AnalysisContext analysisContext) {
// Save each read line into reportDetails Collection
reportDetails.add(reportExcel);
}
@Override
public void doAfterAllAnalysed(AnalysisContext analysisContext) {
}
}).sheet().doRead();
边栏推荐
- AHB2APB桥接器设计(2)——同步桥设计的介绍
- Assembly language - Wang Shuang Chapter 11 flag register - Notes
- Caldera安装及简单使用
- HTAP Quick Start Guide
- Block level elements & inline elements
- Configuration of vscode korofileheader
- The risk of multithreading -- thread safety
- Dev++ 环境设置C语言关键字显示颜色
- LeetCode 0086. Separate linked list
- Download CUDA and cudnn
猜你喜欢
随机推荐
Scala之偏函数Partial Function
427- binary tree (617. merge binary tree, 700. search in binary search tree, 98. verify binary search tree, 530. minimum absolute difference of binary search tree)
【LeetCode】Day90-二叉搜索树中第K小的元素
G1和ZGC垃圾收集器
[QT notes] simple understanding of QT meta object system
Active learning
观测电机转速转矩
IDEA一键生成Log日志
Restrictions on the use of tidb
Assembly language - Wang Shuang Chapter 8 two basic problems in data processing - Notes
2022 CISP-PTE(一)文件包含
线程间等待与唤醒机制、单例模式、阻塞队列、定时器
TiDB 数据库快速上手指南
HTAP 快速上手指南
TiDB的使用限制
Mathematical modeling contest for graduate students - optimal application of UAV in rescue and disaster relief
Crawler learning 5--- anti crawling identification picture verification code (ddddocr and pyteseract measured effect)
TiDB 中的SQL 基本操作
浅谈GPU:历史发展,架构
The fourth question of the 299th weekly match 6103 Minimum fraction of edges removed from the tree