|
|
@ -68,11 +68,14 @@ DEMO代码地址:[https://github.com/alibaba/easyexcel/blob/master/src/test/ja |
|
|
|
### web上传、下载 |
|
|
|
### web上传、下载 |
|
|
|
DEMO代码地址:[https://github.com/alibaba/easyexcel/blob/master/src/test/java/com/alibaba/easyexcel/test/demo/web/WebTest.java](/src/test/java/com/alibaba/easyexcel/test/demo/web/WebTest.java) |
|
|
|
DEMO代码地址:[https://github.com/alibaba/easyexcel/blob/master/src/test/java/com/alibaba/easyexcel/test/demo/web/WebTest.java](/src/test/java/com/alibaba/easyexcel/test/demo/web/WebTest.java) |
|
|
|
```java |
|
|
|
```java |
|
|
|
/** |
|
|
|
/** |
|
|
|
* 文件下载(失败了会返回一个有部分数据的Excel) |
|
|
|
* 文件下载(失败了会返回一个有部分数据的Excel) |
|
|
|
* <p>1. 创建excel对应的实体对象 参照{@link DownloadData} |
|
|
|
* <p> |
|
|
|
* <p>2. 设置返回的 参数 |
|
|
|
* 1. 创建excel对应的实体对象 参照{@link DownloadData} |
|
|
|
* <p>3. 直接写,这里注意,finish的时候会自动关闭OutputStream,当然你外面再关闭流问题不大 |
|
|
|
* <p> |
|
|
|
|
|
|
|
* 2. 设置返回的 参数 |
|
|
|
|
|
|
|
* <p> |
|
|
|
|
|
|
|
* 3. 直接写,这里注意,finish的时候会自动关闭OutputStream,当然你外面再关闭流问题不大 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@GetMapping("download") |
|
|
|
@GetMapping("download") |
|
|
|
public void download(HttpServletResponse response) throws IOException { |
|
|
|
public void download(HttpServletResponse response) throws IOException { |
|
|
@ -80,8 +83,8 @@ DEMO代码地址:[https://github.com/alibaba/easyexcel/blob/master/src/test/ja |
|
|
|
response.setContentType("application/vnd.ms-excel"); |
|
|
|
response.setContentType("application/vnd.ms-excel"); |
|
|
|
response.setCharacterEncoding("utf-8"); |
|
|
|
response.setCharacterEncoding("utf-8"); |
|
|
|
// 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系 |
|
|
|
// 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系 |
|
|
|
String fileName = URLEncoder.encode("测试", "UTF-8"); |
|
|
|
String fileName = URLEncoder.encode("测试", "UTF-8").replaceAll("\\+", "%20"); |
|
|
|
response.setHeader("Content-disposition", "attachment;filename=" + 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()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|