使用easyexcal导出excal
需要的依赖
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>2.1.6</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>
代码,根据使用的类型和list导出
public ResponseEntity promotionMonitorListDownload(PromotionMonitorQueryDTO queryDTO) {
UserDTO currentUser = UserDTO.getCurrentUser();
try {
List<PromotionMonitorExcalInfo> list = promotionMonitorVOService.promotionMonitorListExcalDownload(currentUser, queryDTO);
Integer todayInt = ZonedDateUtil.todayInt(ZonedDateUtil.TIMEZONE_ASIN_SHANGHAI);
String fileName = new StringBuilder().append("deals管理_").append(todayInt).toString();
return buildExportResponse(fileName,PromotionMonitorExcalInfo.class,list);
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(ResultBean.fail("系统错误"));
}
}
//excal导出
private <T> ResponseEntity buildExportResponse(String fileName, Class<T> clazz, List<T> list) throws Exception {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
EasyExcel.write(outputStream,clazz).excelType(ExcelTypeEnum.XLSX).sheet(fileName).doWrite(list);
String contentDisposition = "attachment;filename=".concat(URLEncoder.encode(fileName, "UTF-8")).concat(".xlsx");
Resource resource = genResource(outputStream);
return ResponseEntity.status(HttpStatus.OK)
.header(HttpHeaders.CONTENT_DISPOSITION, contentDisposition)
.header(HttpHeaders.CONTENT_LENGTH, String.valueOf(resource.contentLength()))
.contentType(MediaType.APPLICATION_OCTET_STREAM)
.body(resource);
} private Resource genResource(ByteArrayOutputStream outputStream) {
Resource resource = null;
try {
resource = new ByteArrayResource(outputStream.toByteArray());
} finally {
IOUtils.closeQuietly(outputStream);
return resource;
}
}
使用的实体类上打好注解作为表头部分,例如
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class PromotionMonitorExcalInfo { @ExcelProperty("Deal ID")
@ApiModelProperty(value = "Deal ID")
private String dealID;private String dealPrice;
@ExcelProperty("时间")
@ApiModelProperty(value = "时间")
private String ntime;
@ExcelProperty("Sales")
@ApiModelProperty(value = "Sales")
private String trustee;
@ExcelProperty("创建时间")
@ApiModelProperty(value = "创建时间")
private String createTimeFormat; }
使用easyexcal导出excal的更多相关文章
- <table>导出excal
<table>导出excal 将<table>导出为excal文件,这里介绍两种方法. 1.直接写代码,拼接出excal文件的字符串,然后直接用a标签下载.本人没有是试过,在此 ...
- asp.net(C#) Excel导出类 导出.xls文件
---恢复内容开始--- using Microsoft.Office.Interop.Excel; 针对office 2003需添加引用Microsoft Excel 11.0 Obje ...
- webform的导出
呃 怎么说呢 我这个是公司大佬写好的 我直接调用 和以前写的百度上面的都不大一样 感觉很Nice 插个眼 说不定以后还得回来参考参考 具体是这样的 你先写好一个模板 就是你要导出的数据应该在Ex ...
- vue/axios请求拦截
import axios from 'axios';import { Message } from 'element-ui';import Cookies from 'js-cookie';impor ...
- angular6 导出json数据到excal表
1 首先使用npm下载插件依赖的安装包 npm install file-saver --save npm install xlsx --save 2 引入项目中的ts文件中 impo ...
- vue中excal表格的导入和导出
注意:vue中要实现表格的导入与导出,首先要install两个依赖, npm install -S file-saver xlsx 和 npm install -D script-loader.其 ...
- php 导出
//导出 //放在model层的类 <?phpnamespace frontend\models; use yii\base\model; /** * @copyright (c) 2014 a ...
- Handsontable vue如何实现在线编辑excal
官网地址:https://handsontable.com/ 1.实现效果 2.安装 import { HotTable } from '@handsontable/vue' import Hands ...
- 导出带图片的Excel——OOXML文件分析
需求: 普通js导出文件excel具有兼容性问题,通过js-xsl导出文件API未找到导出图片的方案,实例过少,因此针对07年后以.xlsx后缀的excel文件,通过修改后缀.zip参考文件模板来实现 ...
- premere cs4绿色版 安装 并且 视频导出 讲解
最近室友,开始在玩视频剪辑,用的是 premere cs4 绿色版.让他遇到的最大问题也是我之前遇到的最大问题,就是视频导出. 所以我在这里上传一套自己的一点点经验吧. 接下来,我就总结一下 我是怎么 ...
随机推荐
- python脚本监控定时任务
1.linux服务器中输入命令 crontab -l 查看当前系统的所有定时任务 2. 输入命令 crontab -e ,然后按"i"进行编辑(可新增.修改定时任务).具体定时任务 ...
- python:包含’e’和‘-’的 str 转 float
from functools import reduce def str2float(s): s = s.split('.') a = s[0] b = s[1] if a[0] == '-': a ...
- 通过VS Code轻松连接树莓派
如果您正在使用树莓派作为开发平台,那么通过远程连接VS Code到树莓派是非常方便的一种方法.这样,您可以在Windows或macOS等计算机上开发和测试代码,而不必在树莓派上进行. 以下是通过VS ...
- Java mysql批量关联插入数据
mysql 关联批量插入数据 INSERT INTO 表1 ( id, name, addTime ) SELECT UUID( ) AS id, v_Name, now( ) FROM 表2;
- Linux用户管理2
passwd给用户修改密码 用户自己给自己设置密码直接passwd root用户给普通用户设置密码passwd 用户名 --stdin从标准输入获取信息 echo "1" | pa ...
- 第12组 Beta冲刺 (1/5)
1.1基本情况 ·队名:美少女战士 ·组长博客: https://www.cnblogs.com/yaningscnblogs/p/14016591.html ·作业博客:https://edu.cn ...
- 05.常用 API 第二部分
一.Object 类 是类层次结构的根 (父) 类. String toString () 返回该对象的字符串表示,其实该字符串内容就是对象的类型 + @ + 内存地址值. 由于 toString ...
- 【基础知识】C++算法基础(快速排序)
快速排序: 1.执行流程(一趟快排): 2.一趟快排的结果:获得一个枢纽,在此左边皆小于此数,在此右边皆大于此数,因此可以继续使用递归获得最终的序列.
- CSS网页布局基础
CSS网页布局基础1.行布局-基础的行布局-行布局自适应-行布局自适应限制最大宽-行布局垂直水平居中-行布局某部位自适应-行布局固定宽-行布局导航随屏幕滚动2.多列布局-两列布局固定-两列布局自适应- ...
- 论zzy的苏州话
乘地铁(ceng) - 盛饭(seng) 无法无天 - 12345 掀被子 - 先干嘛,再干嘛 ?待更新