使用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 绿色版.让他遇到的最大问题也是我之前遇到的最大问题,就是视频导出. 所以我在这里上传一套自己的一点点经验吧. 接下来,我就总结一下 我是怎么 ...
随机推荐
- https://计算机三级
计算机三级内容:"网络技术","数据库技术","软件测试技术","信息安全技术","嵌入式系统开发技术&quo ...
- Jmeter六、采样器解析
一.HTTP request sampler 默认端口:80 协议protocol:http,https,file 参数中有特殊字符,勾选编码encode send files with reques ...
- UEC++学习(1)
第三章 流程控制 第一节 C++和蓝图循环 ForLoop蓝图节点相当于C++中的for循环,ForeLoopWithBreak节点相当于for循环体中加了break语句,当触发某个条件时直接结束. ...
- Mysql explain 每个属性含义
Mysql explain explain 常用于分析sql语句的执行效率,使用时在正常的select语句之前添加explain并执行就会返回执行信息,返回的执行信息如下: id:id列的编号是se ...
- K8S的基础概念
一.Kubernetes介绍 1.什么是Kubernetes? Kubernetes(通常称为K8s,K8s是将8个字母"ubernete"替换为"8"的缩写) ...
- 【Unity】Lua热重载
写在前面 本文讨论的"Lua热重载"是基于他人现成工具和相关博文上展开的,所以这里并不会重复实现一遍工具,主要记录我的理解过程. Lua热重载 探索 偶然在知乎上翻到一篇文章&qu ...
- 2020/03/25 CSS相关知识点
2020-03-25 16:35:03 又是一个风和日丽的下午!今天的内容比较多 真是令人头大 ,手速又慢所以缺的可能比较多,而且这东西还是多靠实践为好. 文件下载地址: https://share. ...
- 2020/5/26-笔记:Oracle数据库表空间的管理
1新建表空间 (1)普通(本地管理)表空间: create tablespace 表空间名 datafile'OS系统文件路径\文件名.dbf' size nM; 或 create tablespac ...
- .NET实验三
实验名称:实验三 Windows 应用程序开发 一. 实验目的 1. 掌握窗口控件的使用方法: 2. 掌握 Windows 的编程基础. 二. 实验要求 根据要求,编写 C#程序,并将程序代码和运 ...
- 助教工作总结(高级语言程序设计C语言)
* { font-family: 宋体 } zw { font-size: 20px; line-height: 2em } 一.助教工作的具体职责和任务 在本学期担任陈欣老师的计科专业21级c语 ...