使用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 绿色版.让他遇到的最大问题也是我之前遇到的最大问题,就是视频导出. 所以我在这里上传一套自己的一点点经验吧. 接下来,我就总结一下 我是怎么 ...
随机推荐
- gitt如何将本地分支同远程分支进行关联
将本地分支同远程分支进行关联,1.本地已经创建了分支test(test,是master以外自己创建的分支),而远程没有2种方法在远程创建分支test,并与本地分支进行关联: 方法1: git push ...
- binlog2sql 实战心得
原创:binlog2sql在GitHub的地址:https://github.com/danfengcao/binlog2sql 作者:danfengcao 功能:从MySQL binlog解析出你要 ...
- 机制设计原理与应用(三)Screening
目录 3 Screening 3.1 为单个不可分割的项目定价 3.1.1 对\(\theta\)的假设 3.1.2 问题描述 3.1.3 特性 3.2 为无限可分的项目定价 3.2.1 对\(\th ...
- 当前SAT主要关键技术及其相关文献2022-11-1
摘录自: Tasniem Nasser Al-Yahya, Mohamed El Bachir Menai, Hassan Mathkour:Boosting the Performance of C ...
- Linux系统管理实战-DNS
DNS 域名解析 DNS(domain name system) 解析方式 1.本地解析 /etc/hosts 127.0.0.1 localhost localhost.localdomain lo ...
- SpringBoot系列---【maven项目引入第三方jar包并打包发布】
一.问题 项目中经常会碰到这样的问题,我们做的项目依赖别人打好的jar包,这种我们可以有两种途径解决,第一种是上传到私服,再从我们的项目去引入pom坐标,这种适合有私服账号或者自己会搭建私服的,成本有 ...
- eclipse项目右键属性java Build Path等丢失
https://www.cnblogs.com/IDECIDETODOIT/p/3906831.html https://zhidao.baidu.com/question/133415688.htm ...
- OSIDP-文件管理-12(end)
概述 文件特性:可长期存储:可在进程间共享:有特定结构. 文件系统提供对文件操作的功能接口:创建.删除.打开.关闭.读和写. 域(field):基本数据单元,一个域包含一个值. 记录(record): ...
- idea创建maven + tomcat项目
移动文件夹: 找到tomcat文件目录 配置完成,添加测试html文件: 运行 修改默认路径:
- Java中int型数据类型对应MySQL数据库中哪种类型?
java类 mysql数据库 java.lang.Byte byte TINYINT java.lang.Short short SMALLINT java.lang.Integer intege ...