Browse Source

升级新版本,修复bug,提供编辑工具,提升模型转换性能

bugfix
jipengfei.jpf 6 years ago
parent
commit
5bfecbdbab
  1. 143
      README.md

143
README.md

@ -1,18 +1,12 @@
# JAVA解析Excel工具easyexcel
Java解析、生成Excel比较有名的框架有Apache poi、jxl。但他们都存在一个严重的问题就是非常的耗内存,poi有一套SAX模式的API可以一定程度的解决一些内存溢出的问题,但POI还是有一些缺陷,比如07版Excel解压缩以及解压后存储都是在内存中完成的,内存消耗依然很大。easyexcel重写了poi对07版Excel的解析,能够原本一个3M的excel用POI sax依然需要100M左右内存降低到KB级别,并且再大的excel不会出现内存溢出,03版依赖POI的sax模式。在上层做了模型转换的封装,让使用者更加简单方便
# 相关文档
## 相关文档
* [关于软件](/abouteasyexcel.md)
* [快速使用](/quickstart.md)
* [常见问题](/problem.md)
* [更新记事](/update.md)
* [English-README](/easyexcel_en.md)
# 二方包
## 二方包
```
<dependency>
<groupId>com.alibaba</groupId>
@ -20,49 +14,32 @@ Java解析、生成Excel比较有名的框架有Apache poi、jxl。但他们都
<version>{latestVersion}</version>
</dependency>
```
# 最新版本
### VERSION : 1.1.2-beat1
# 维护者
## 最新版本:1.1.2-beat1
## 维护者
姬朋飞(玉霄)
# 快速开始
## 读Excel
## 快速开始
### 读Excel
测试代码地址:[https://github.com/alibaba/easyexcel/blob/master/src/test/java/com/alibaba/easyexcel/test/ReadTest.java](/src/test/java/com/alibaba/easyexcel/test/ReadTest.java)
读07版小于1000行数据返回List<List<String>>
```
List<Object> data = EasyExcelFactory.read(inputStream, new Sheet(1, 0));
```List<Object> data = EasyExcelFactory.read(inputStream, new Sheet(1, 0));
```
读07版小于1000行数据返回List<? extend BaseRowModel>
```
List<Object> data = EasyExcelFactory.read(inputStream, new Sheet(2, 1,JavaModel.class));
```List<Object> data = EasyExcelFactory.read(inputStream, new Sheet(2, 1,JavaModel.class));
```
读07版大于1000行数据返回List<List<String>>
```
ExcelListener excelListener = new ExcelListener();
```ExcelListener excelListener = new ExcelListener();
EasyExcelFactory.readBySax(inputStream, new Sheet(1, 1), excelListener);
```
读07版大于1000行数据返回List<? extend BaseRowModel>
```
ExcelListener excelListener = new ExcelListener();
```ExcelListener excelListener = new ExcelListener();
EasyExcelFactory.readBySax(inputStream, new Sheet(2, 1,JavaModel.class), excelListener);
```
读03版方法同上
## 写Excel
### 写Excel
测试代码地址:[https://github.com/alibaba/easyexcel/blob/master/src/test/java/com/alibaba/easyexcel/test/WriteTest.java](/src/test/java/com/alibaba/easyexcel/test/WriteTest.java)
没有模板
```
OutputStream out = new FileOutputStream("/Users/jipengfei/2007.xlsx");
```OutputStream out = new FileOutputStream("/Users/jipengfei/2007.xlsx");
ExcelWriter writer = EasyExcelFactory.getWriter(out);
//写第一个sheet, sheet1 数据全是List<String> 无模型映射关系
@ -100,8 +77,7 @@ writer.finish();
out.close();
```
有模板
```
InputStream inputStream = new BufferedInputStream(new FileInputStream("/Users/jipengfei/temp.xlsx"));
```InputStream inputStream = new BufferedInputStream(new FileInputStream("/Users/jipengfei/temp.xlsx"));
OutputStream out = new FileOutputStream("/Users/jipengfei/2007.xlsx");
ExcelWriter writer = EasyExcelFactory.getWriterWithTemp(inputStream,out,ExcelTypeEnum.XLSX,true);
@ -140,93 +116,30 @@ writer.finish();
out.close();
```
# web下载实例写法
package com.alibaba.china.pte.web.seller.dingtalk.rpc;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.metadata.Sheet;
import com.alibaba.excel.support.ExcelTypeEnum;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author jipengfei
* @date 2018/05/25
*/
@RequestMapping("/api/dingtalk")
@RestController
### web下载实例写法
```
public class Down {
@GetMapping("/a.htm")
public void cooperation(HttpServletRequest request, HttpServletResponse response) {
ServletOutputStream out = null;
try {
out = response.getOutputStream();
} catch (IOException e) {
e.printStackTrace();
}
ServletOutputStream out = response.getOutputStream();
ExcelWriter writer = new ExcelWriter(out, ExcelTypeEnum.XLSX, true);
try {
String fileName = new String(("UserInfo " + new SimpleDateFormat("yyyy-MM-dd").format(new Date()))
String fileName = new String(("UserInfo " + new SimpleDateFormat("yyyy-MM-dd").format(new Date()))
.getBytes(), "UTF-8");
Sheet sheet1 = new Sheet(1, 0);
sheet1.setSheetName("第一个sheet");
writer.write0(getListString(), sheet1);
response.setContentType("multipart/form-data");
response.setCharacterEncoding("utf-8");
response.setHeader("Content-disposition", "attachment;filename="+fileName+".xlsx");
out.flush();
} catch (Exception e) {
e.printStackTrace();
}finally {
writer.finish();
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
Sheet sheet1 = new Sheet(1, 0);
sheet1.setSheetName("第一个sheet");
writer.write0(getListString(), sheet1);
response.setContentType("multipart/form-data");
response.setCharacterEncoding("utf-8");
response.setHeader("Content-disposition", "attachment;filename="+fileName+".xlsx");
out.flush();
}
}
private List<List<String>> getListString() {
List<String> list = new ArrayList<String>();
list.add("ooo1");
list.add("ooo2");
list.add("ooo3");
list.add("ooo4");
List<String> list1 = new ArrayList<String>();
list1.add("ooo1");
list1.add("ooo2");
list1.add("ooo3");
list1.add("ooo4");
List<List<String>> ll = new ArrayList<List<String>>();
ll.add(list);
ll.add(list1);
return ll;
}
}
# 联系我们
```
### 联系我们
有问题阿里同事可以通过钉钉找到我,阿里外同学可以通过git留言。其他技术非技术相关的也欢迎一起探讨。
# 招聘
### 招聘
阿里巴巴新零售事业部--诚招JAVA资深开发、技术专家。有意向可以微信联系,简历可以发我邮箱jipengfei.jpf@alibaba-inc.com
可以走内推流程
![img](https://github.com/alibaba/easyexcel/blob/master/img/weixin1.png)

Loading…
Cancel
Save