|
|
@ -4,6 +4,64 @@ EasyExcel |
|
|
|
[![Maven central](https://maven-badges.herokuapp.com/maven-central/com.alibaba/easyexcel/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.alibaba/easyexcel) |
|
|
|
[![Maven central](https://maven-badges.herokuapp.com/maven-central/com.alibaba/easyexcel/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.alibaba/easyexcel) |
|
|
|
[![License](http://img.shields.io/:license-apache-brightgreen.svg)](http://www.apache.org/licenses/LICENSE-2.0.html) |
|
|
|
[![License](http://img.shields.io/:license-apache-brightgreen.svg)](http://www.apache.org/licenses/LICENSE-2.0.html) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# JAVA解析Excel工具 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Java解析、生成Excel比较有名的框架有Apache poi、jxl。但他们都存在一个严重的问题就是非常的耗内存,poi有一套SAX模式的API可以一定程度的解决一些内存溢出的问题,但POI还是有一些缺陷,比如07版Excel解压缩以及解压后存储都是在内存中完成的,内存消耗依然很大。 |
|
|
|
|
|
|
|
easyexcel重写了poi对07版Excel的解析,一个3M的excel用POI sax解析依然需要100M左右内存,改用easyexcel可以降低到几M,并且再大的excel也不会出现内存溢出;03版依赖POI的sax模式,在上层做了模型转换的封装,让使用者更加简单方便 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# github地址 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[https://github.com/alibaba/easyexcel](https://github.com/alibaba/easyexcel) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 官方网站 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[https://easyexcel.opensource.alibaba.com/](https://easyexcel.opensource.alibaba.com/) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 64M内存20秒读取75M(46W行25列)的Excel(3.0.2+版本) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
当然还有[极速模式](https://easyexcel.opensource.alibaba.com/qa/read#%E5%BC%80%E5%90%AF%E6%80%A5%E9%80%9F%E6%A8%A1%E5%BC%8F) |
|
|
|
|
|
|
|
能更快,但是内存占用会在100M多一点 |
|
|
|
|
|
|
|
![img](img/readme/large.png) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 最新版本 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```xml |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<dependency> |
|
|
|
|
|
|
|
<groupId>com.alibaba</groupId> |
|
|
|
|
|
|
|
<artifactId>easyexcel</artifactId> |
|
|
|
|
|
|
|
<version>3.1.5</version> |
|
|
|
|
|
|
|
</dependency> |
|
|
|
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 帮忙点个⭐Star |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
开源不易,如果觉得EasyExcel对您的工作还是有帮助的话,请帮忙在<a target="_blank" href='https://github.com/alibaba/easyexcel'><img src="https://img.shields.io/github/stars/alibaba/easyexcel.svg?style=flat-square&label=Stars&logo=github" alt="github star"/></a> |
|
|
|
|
|
|
|
的右上角点个⭐Star,您的支持是使EasyExcel变得更好最大的动力。 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 如何获取帮助 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## 优先建议自己通过文档来解决问题 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* [快速开始](https://easyexcel.opensource.alibaba.com/docs/current/) |
|
|
|
|
|
|
|
* [常见问题](https://easyexcel.opensource.alibaba.com/docs/qa/) |
|
|
|
|
|
|
|
* [API](https://easyexcel.opensource.alibaba.com/docs/current/api/) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## 其次建议通过`issues`来解决解决问题 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
可以尝试在以下2个链接搜索问题,如果不存在可以尝试创建`issue`。 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* 去 [github](https://github.com/alibaba/easyexcel/issues) 搜索`issues` |
|
|
|
|
|
|
|
* 去 [gitee](https://gitee.com/easyexcel/easyexcel/issues) 搜索`issues` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
通过 `issues` 解决问题,可以给后面遇到相同问题的同学查看,所以比较推荐这种方式。 |
|
|
|
|
|
|
|
不管`github`、`gitee`都会定期有人回答您的问题,比较紧急可以在提完`issue`以后在钉钉群艾特群主并发送`issue`地址帮忙解决。 |
|
|
|
|
|
|
|
`QQ` 公司不让用,有时候也会去看,但是核心肯定还是在钉钉。 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## 也可以加入钉钉&QQ群来解决问题 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
加入钉钉或QQ群,看完公告可以获得帮助 。 |
|
|
|
|
|
|
|
比较推荐钉钉群,`QQ` 公司不让用,当然QQ群也会有热心网友帮忙解决。 |
|
|
|
[QQ1群(已满): 662022184](https://jq.qq.com/?_wv=1027&k=1T21jJxh) |
|
|
|
[QQ1群(已满): 662022184](https://jq.qq.com/?_wv=1027&k=1T21jJxh) |
|
|
|
[QQ2群(已满): 1097936804](https://jq.qq.com/?_wv=1027&k=j5zEy6Xl) |
|
|
|
[QQ2群(已满): 1097936804](https://jq.qq.com/?_wv=1027&k=j5zEy6Xl) |
|
|
|
[QQ3群(已满): 453928496](https://qm.qq.com/cgi-bin/qm/qr?k=e2ULsA5A0GldhV2CXJ8sIbAyu9I6qqs7&jump_from=webapi) |
|
|
|
[QQ3群(已满): 453928496](https://qm.qq.com/cgi-bin/qm/qr?k=e2ULsA5A0GldhV2CXJ8sIbAyu9I6qqs7&jump_from=webapi) |
|
|
@ -21,40 +79,16 @@ EasyExcel |
|
|
|
[钉钉9群(已满): 11045002277](https://h5.dingtalk.com/circle/healthCheckin.html?dtaction=os&corpId=dinge338d2215891c0459c13cd6b2cb108a6&6972d=b92f9&cbdbhh=qwertyuiop) |
|
|
|
[钉钉9群(已满): 11045002277](https://h5.dingtalk.com/circle/healthCheckin.html?dtaction=os&corpId=dinge338d2215891c0459c13cd6b2cb108a6&6972d=b92f9&cbdbhh=qwertyuiop) |
|
|
|
[钉钉10群: 27360019755](https://qr.dingtalk.com/action/joingroup?code=v1,k1,v25LHn2liWmrWUKlkhIzOTcK7s7onp/sZP8mO5oIYSs=&_dt_no_comment=1&origin=11) |
|
|
|
[钉钉10群: 27360019755](https://qr.dingtalk.com/action/joingroup?code=v1,k1,v25LHn2liWmrWUKlkhIzOTcK7s7onp/sZP8mO5oIYSs=&_dt_no_comment=1&origin=11) |
|
|
|
|
|
|
|
|
|
|
|
[官方网站: https://easyexcel.opensource.alibaba.com/](https://easyexcel.opensource.alibaba.com/) |
|
|
|
# 维护者 |
|
|
|
|
|
|
|
|
|
|
|
## 获取帮助 |
|
|
|
姬朋飞(玉霄)、庄家钜、怀宇 |
|
|
|
* 加入钉钉或QQ群,看完公告可以获得帮助 |
|
|
|
|
|
|
|
* 自己参照 [文档](https://easyexcel.opensource.alibaba.com/docs/current/) 去尝试自己解决 |
|
|
|
|
|
|
|
* 上面文档的右下角有个`?`,在尝试过文档无法自助解决的情况下,可以点击人工支持 |
|
|
|
|
|
|
|
* 开源不易,如果觉得EasyExcel对您的工作还是有帮助的话,请帮忙在右上角点个⭐Star,您的支持是使EasyExcel变得更好最大的动力 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# JAVA解析Excel工具EasyExcel |
|
|
|
# 快速开始 |
|
|
|
Java解析、生成Excel比较有名的框架有Apache poi、jxl。但他们都存在一个严重的问题就是非常的耗内存,poi有一套SAX模式的API可以一定程度的解决一些内存溢出的问题,但POI还是有一些缺陷,比如07版Excel解压缩以及解压后存储都是在内存中完成的,内存消耗依然很大。easyexcel重写了poi对07版Excel的解析,一个3M的excel用POI sax解析依然需要100M左右内存,改用easyexcel可以降低到几M,并且再大的excel也不会出现内存溢出;03版依赖POI的sax模式,在上层做了模型转换的封装,让使用者更加简单方便 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## 64M内存20秒读取75M(46W行25列)的Excel(3.0.2+版本) |
|
|
|
## 读Excel |
|
|
|
当然还有[极速模式](https://easyexcel.opensource.alibaba.com/qa/read#%E5%BC%80%E5%90%AF%E6%80%A5%E9%80%9F%E6%A8%A1%E5%BC%8F)能更快,但是内存占用会在100M多一点 |
|
|
|
|
|
|
|
![img](img/readme/large.png) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### 最新版本 |
|
|
|
demo代码地址:[https://github.com/alibaba/easyexcel/blob/master/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/read/ReadTest.java](https://github.com/alibaba/easyexcel/blob/master/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/read/ReadTest.java) |
|
|
|
```xml |
|
|
|
详细文档地址:[https://easyexcel.opensource.alibaba.com/docs/current/quickstart/read](https://easyexcel.opensource.alibaba.com/docs/current/quickstart/read) |
|
|
|
<dependency> |
|
|
|
|
|
|
|
<groupId>com.alibaba</groupId> |
|
|
|
|
|
|
|
<artifactId>easyexcel</artifactId> |
|
|
|
|
|
|
|
<version>3.1.5</version> |
|
|
|
|
|
|
|
</dependency> |
|
|
|
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## 相关文档 |
|
|
|
|
|
|
|
* [快速开始](https://easyexcel.opensource.alibaba.com/docs/current/) |
|
|
|
|
|
|
|
* [更新记事](/update.md) |
|
|
|
|
|
|
|
* [贡献代码](https://easyexcel.opensource.alibaba.com/community/contribute) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## 维护者 |
|
|
|
|
|
|
|
姬朋飞(玉霄)、庄家钜、怀宇 |
|
|
|
|
|
|
|
## 快速开始 |
|
|
|
|
|
|
|
### 读Excel |
|
|
|
|
|
|
|
DEMO代码地址:[https://github.com/alibaba/easyexcel/blob/master/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/read/ReadTest.java](https://github.com/alibaba/easyexcel/blob/master/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/read/ReadTest.java) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```java |
|
|
|
```java |
|
|
|
/** |
|
|
|
/** |
|
|
@ -71,8 +105,11 @@ DEMO代码地址:[https://github.com/alibaba/easyexcel/blob/master/easyexcel-t |
|
|
|
} |
|
|
|
} |
|
|
|
``` |
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
### 写Excel |
|
|
|
## 写Excel |
|
|
|
DEMO代码地址:[https://github.com/alibaba/easyexcel/blob/master/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java](https://github.com/alibaba/easyexcel/blob/master/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java) |
|
|
|
|
|
|
|
|
|
|
|
demo代码地址:[https://github.com/alibaba/easyexcel/blob/master/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java](https://github.com/alibaba/easyexcel/blob/master/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java) |
|
|
|
|
|
|
|
详细文档地址:[https://easyexcel.opensource.alibaba.com/docs/current/quickstart/write](https://easyexcel.opensource.alibaba.com/docs/current/quickstart/write) |
|
|
|
|
|
|
|
|
|
|
|
```java |
|
|
|
```java |
|
|
|
/** |
|
|
|
/** |
|
|
|
* 最简单的写 |
|
|
|
* 最简单的写 |
|
|
@ -81,15 +118,17 @@ DEMO代码地址:[https://github.com/alibaba/easyexcel/blob/master/easyexcel-t |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void simpleWrite() { |
|
|
|
public void simpleWrite() { |
|
|
|
String fileName = TestFileUtil.getPath() + "write" + System.currentTimeMillis() + ".xlsx"; |
|
|
|
String fileName=TestFileUtil.getPath()+"write"+System.currentTimeMillis()+".xlsx"; |
|
|
|
// 这里 需要指定写用哪个class去读,然后写到第一个sheet,名字为模板 然后文件流会自动关闭 |
|
|
|
// 这里 需要指定写用哪个class去读,然后写到第一个sheet,名字为模板 然后文件流会自动关闭 |
|
|
|
// 如果这里想使用03 则 传入excelType参数即可 |
|
|
|
// 如果这里想使用03 则 传入excelType参数即可 |
|
|
|
EasyExcel.write(fileName, DemoData.class).sheet("模板").doWrite(data()); |
|
|
|
EasyExcel.write(fileName,DemoData.class).sheet("模板").doWrite(data()); |
|
|
|
} |
|
|
|
} |
|
|
|
``` |
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
### web上传、下载 |
|
|
|
## web上传、下载 |
|
|
|
DEMO代码地址:[https://github.com/alibaba/easyexcel/blob/master/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/web/WebTest.java](https://github.com/alibaba/easyexcel/blob/master/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/web/WebTest.java) |
|
|
|
|
|
|
|
|
|
|
|
demo代码地址:[https://github.com/alibaba/easyexcel/blob/master/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/web/WebTest.java](https://github.com/alibaba/easyexcel/blob/master/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/web/WebTest.java) |
|
|
|
|
|
|
|
|
|
|
|
```java |
|
|
|
```java |
|
|
|
/** |
|
|
|
/** |
|
|
|
* 文件下载(失败了会返回一个有部分数据的Excel) |
|
|
|
* 文件下载(失败了会返回一个有部分数据的Excel) |
|
|
@ -106,9 +145,9 @@ DEMO代码地址:[https://github.com/alibaba/easyexcel/blob/master/easyexcel-t |
|
|
|
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); |
|
|
|
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); |
|
|
|
response.setCharacterEncoding("utf-8"); |
|
|
|
response.setCharacterEncoding("utf-8"); |
|
|
|
// 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系 |
|
|
|
// 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系 |
|
|
|
String fileName = URLEncoder.encode("测试", "UTF-8").replaceAll("\\+", "%20"); |
|
|
|
String fileName=URLEncoder.encode("测试","UTF-8").replaceAll("\\+","%20"); |
|
|
|
response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx"); |
|
|
|
response.setHeader("Content-disposition","attachment;filename*=utf-8''"+fileName+".xlsx"); |
|
|
|
EasyExcel.write(response.getOutputStream(), DownloadData.class).sheet("模板").doWrite(data()); |
|
|
|
EasyExcel.write(response.getOutputStream(),DownloadData.class).sheet("模板").doWrite(data()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -119,10 +158,8 @@ DEMO代码地址:[https://github.com/alibaba/easyexcel/blob/master/easyexcel-t |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@PostMapping("upload") |
|
|
|
@PostMapping("upload") |
|
|
|
@ResponseBody |
|
|
|
@ResponseBody |
|
|
|
public String upload(MultipartFile file) throws IOException { |
|
|
|
public String upload(MultipartFile file)throws IOException{ |
|
|
|
EasyExcel.read(file.getInputStream(), UploadData.class, new UploadDataListener(uploadDAO)).sheet().doRead(); |
|
|
|
EasyExcel.read(file.getInputStream(),UploadData.class,new UploadDataListener(uploadDAO)).sheet().doRead(); |
|
|
|
return "success"; |
|
|
|
return"success"; |
|
|
|
} |
|
|
|
} |
|
|
|
``` |
|
|
|
``` |
|
|
|
### 联系我们 |
|
|
|
|
|
|
|
有问题阿里同事可以通过钉钉找到我,阿里外同学可以通过git留言。其他技术非技术相关的也欢迎一起探讨。 |
|
|
|
|
|
|
|