当前位置:网站首页>easyexcel的使用
easyexcel的使用
2022-07-01 11:56:00 【qq_46198929】

<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.17</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>3.17</version>
</dependency>
<dependency>
<groupId>org.apche.poi</groupId>
<artifactId>poi</artifactId>
<version>3.17</version>
</dependency>
package com.example.demo.excel;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;
@Data
public class DemoData {
//设置excel表头名称
@ExcelProperty(value = "学生编号",index = 0)
private Integer sno;
@ExcelProperty(value = "学生姓名",index = 1)
private String sname;
}
package com.example.demo.excel;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import java.util.Map;
public class ExcelListener extends AnalysisEventListener<DemoData> {
//一行一行读取excel内容
@Override
public void invoke(DemoData data, AnalysisContext analysisContext) {
System.out.println("****"+data);
}
//读取表头内容
@Override
public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) {
System.out.println("表头:"+headMap);
}
//读取完成之后
@Override
public void doAfterAllAnalysed(AnalysisContext analysisContext) {
}
}
package com.example.demo.excel;
import com.alibaba.excel.EasyExcel;
import java.util.ArrayList;
import java.util.List;
public class TestEasyExcel {
public static void main(String[] args) {
//实现excel写的操作
//1 设置写入文件夹地址和excel文件名称
//String filename = "D:\\write.xlsx";
//2 调用easyexcel里面的方法实现写操作
//write方法两个参数:第一个参数文件路径名称,第二个参数实体类class
//EasyExcel.write(filename,DemoData.class).sheet("学生列表").doWrite(getData());
//实现excel读操作
String filename = "D:\\write.xlsx";
EasyExcel.read(filename,DemoData.class,new ExcelListener()).sheet().doRead();
}
//创建方法返回list集合
private static List<DemoData> getData() {
List<DemoData> list = new ArrayList<>();
for (int i = 0; i < 10; i++) {
DemoData data = new DemoData();
data.setSno(i);
data.setSname("lucy"+i);
list.add(data);
}
return list;
}
}
边栏推荐
- Mechanism and type of CPU context switch
- 伸展树(一) - 概念和C实现
- Value/sortedset in redis
- 自组织是管理者和成员的双向奔赴
- Theoretical basis of graph
- Adjacency matrix undirected graph (I) - basic concepts and C language
- Binary stack (I) - principle and C implementation
- Brief explanation of the working principle, usage scenarios and importance of fingerprint browser
- Huawei HMS core joins hands with hypergraph to inject new momentum into 3D GIS
- Redis startup and library entry
猜你喜欢

使用set_handler过滤掉特定的SystemC Wraning &Error Message

Neo4j 中文开发者月刊 - 202206期

Neo4j Chinese developer monthly - issue 202206

Seckill system 03 - redis cache and distributed lock

Exploration and practice of inress in kubernetes

CPI tutorial - asynchronous interface creation and use

2022/6/28学习总结

91.(cesium篇)cesium火箭发射模拟

How to understand the developed query statements
![[MCU] [nixie tube] nixie tube display](/img/5e/9e14302b4e4f5e03601392ac90479d.png)
[MCU] [nixie tube] nixie tube display
随机推荐
用实际例子详细探究OpenCV的轮廓检测函数findContours(),彻底搞清每个参数、每种模式的真正作用与含义
研发效能度量框架解读
Skip the test cases to be executed in the unittest framework
Implementation of address book management system with C language
I'm in Zhongshan. Where is a better place to open an account? Is it actually safe to open an account online?
redis配置环境变量
uniapp 使用 uni-upgrade-center
CPI tutorial - asynchronous interface creation and use
Matrix of numpy
如何看懂开发的查询语句
Summary of JFrame knowledge points 1
Value/hush in redis
CAD如何设置标注小数位
LeetCode 454. 四数相加 II
Comment Nike a - t - il dominé la première place toute l'année? Voici les derniers résultats financiers.
Width and widthstep of iplimage
Summary of JFrame knowledge points 2
Force button homepage introduction animation
耐克如何常年霸榜第一名?最新財報答案來了
Learning summary on June 29, 2022