使用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.首先需要一个钉钉群,群才有机器人 2.群设置->智能群助手->添加机器人->自定义机器人 3.添加自定义机器人,配置如下:给机器人命名,选择加签.保存机器人的秘钥.Webhook ...
- 【python】第一模块 步骤五 第二课、Python多线程
第二课.Python多线程 一.课程介绍 1.1 课程概要 章节概要 进程.线程与并发 对多核的利用 实现一个线程 线程之间的通信 线程的调度和优化 1.2 为什么要学习多线程 (线程)使用场景 快速 ...
- 微信小程序ECharts通过调用api接口实现图表的数据可视化
小程序ECharts使用接口调入数据 首先附上js文件链接:axios.js 提取码:AxIo 将此放到小程序目录下的utils文件夹下 在已经完成图表的js文件中完成以下修改: ①引用axios.j ...
- node后台项目所需中间件梳理
0.nodemon 全局工具,监听项目文件变动,并自动重启项目 一.node内置模块 1.fs fs.readFile() 读取指定文件中的内容fs.writeFile() 向指定的文件中写入内容 ...
- AT212 P-CASカードと高橋君
题目描述 高桥君为了准备即将到来的7月27日土用丑日,打算邮购一些高级鳗鱼食材,通过网上银行来支付. 高桥君使用的银行卡背面有下图所示的9×9密码表.支付的时候从表中某一位置开始根据指定的方向连续读4 ...
- SQL Server 分页问题
------------- SQL Server 1.使用row_number分页 declare @PageSize int = 5 declare @PageIndex int = 1 selec ...
- Delphi之不可思议
1.--------不可思议的函数调用--开始- 开发环境D7 1 function TForm1.GetssA: string; 2 begin 3 Result:=Result+'AA'; 4 e ...
- 2020/513-笔记:怎么知道Oracle数据库一个中文汉字占几个字节
1. 执行语句: select userenv('language') from dual; 如果显示如下: SIMPLIFIED CHINESE_CH ...
- GFF2GTF.py2
import sys inFile = open(sys.argv[1],'r') for line in inFile: #skip comment lines that start with th ...
- 持续集成环境(5)-Maven安装和配置
在Jenkins集成服务器上,我们需要安装Maven来编译和打包项目. 安装Maven 1.下载Maven软件到jenkins服务器上 wget https://mirrors.aliyun.com/ ...