在本地搭建easyexcel源码环境
- EasyExcel
- 本地环境搭建
- 最新版本3.1.5,依赖问题,解决方案
- junit-读Excel
EasyExcel
本篇从github或官方文档来源参考
https://github.com/alibaba/easyexcel/tree/v3.1.5
https://easyexcel.opensource.alibaba.com/docs/current/quickstart/write
本地环境搭建
拉取代码
https://github.com/alibaba/easyexcel/tree/v3.1.5
Maven构建
最新版本3.1.5,依赖问题,解决方案
在父工程修改
<!-- 4.1.2找不到依赖,修改4.1.0即可-->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>4.1.0</version>
</dependency>
junit-读Excel
/**
* 最简单的读
* <p>1. 创建excel对应的实体对象 参照{@link DemoData}
* <p>2. 由于默认一行行的读取excel,所以需要创建excel一行一行的回调监听器,参照{@link DemoDataListener}
* <p>3. 直接读即可
*/
@Test
public void simpleRead() {
String fileName = TestFileUtil.getPath() + "demo" + File.separator + "demo.xlsx";
// 这里 需要指定读用哪个class去读,然后读取第一个sheet 文件流会自动关闭
EasyExcel.read(fileName, DemoData.class, new DemoDataListener()).sheet().doRead();
}
控制台
2023-01-10 10:07:45.344 INFO [main] com.alibaba.easyexcel.test.demo.read.DemoDataListener:56 - 解析到一条数据:{"date":1577811661000,"doubleData":1.0,"string":"字符串0"}
2023-01-10 10:07:45.345 INFO [main] com.alibaba.easyexcel.test.demo.read.DemoDataListener:56 - 解析到一条数据:{"date":1577898061000,"doubleData":2.0,"string":"字符串1"}
2023-01-10 10:07:45.345 INFO [main] com.alibaba.easyexcel.test.demo.read.DemoDataListener:56 - 解析到一条数据:{"date":1577984461000,"doubleData":3.0,"string":"字符串2"}
2023-01-10 10:07:45.346 INFO [main] com.alibaba.easyexcel.test.demo.read.DemoDataListener:56 - 解析到一条数据:{"date":1578070861000,"doubleData":4.0,"string":"字符串3"}
2023-01-10 10:07:45.347 INFO [main] com.alibaba.easyexcel.test.demo.read.DemoDataListener:56 - 解析到一条数据:{"date":1578157261000,"doubleData":5.0,"string":"字符串4"}
2023-01-10 10:07:45.347 INFO [main] com.alibaba.easyexcel.test.demo.read.DemoDataListener:56 - 解析到一条数据:{"date":1578243661000,"doubleData":6.0,"string":"字符串5"}
2023-01-10 10:07:45.348 INFO [main] com.alibaba.easyexcel.test.demo.read.DemoDataListener:56 - 解析到一条数据:{"date":1578330061000,"doubleData":7.0,"string":"字符串6"}
2023-01-10 10:07:45.348 INFO [main] com.alibaba.easyexcel.test.demo.read.DemoDataListener:56 - 解析到一条数据:{"date":1578416461000,"doubleData":8.0,"string":"字符串7"}
2023-01-10 10:07:45.348 INFO [main] com.alibaba.easyexcel.test.demo.read.DemoDataListener:56 - 解析到一条数据:{"date":1578502861000,"doubleData":9.0,"string":"字符串8"}
2023-01-10 10:07:45.349 INFO [main] com.alibaba.easyexcel.test.demo.read.DemoDataListener:56 - 解析到一条数据:{"date":1578589261000,"doubleData":10.0,"string":"字符串9"}
2023-01-10 10:07:45.350 INFO [main] com.alibaba.easyexcel.test.demo.read.DemoDataListener:82 - 10条数据,开始存储数据库!
2023-01-10 10:07:45.350 INFO [main] com.alibaba.easyexcel.test.demo.read.DemoDataListener:84 - 存储数据库成功!
2023-01-10 10:07:45.350 INFO [main] com.alibaba.easyexcel.test.demo.read.DemoDataListener:75 - 所有数据解析完成!