使用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 绿色版.让他遇到的最大问题也是我之前遇到的最大问题,就是视频导出. 所以我在这里上传一套自己的一点点经验吧. 接下来,我就总结一下 我是怎么 ...
随机推荐
- gulp技术:自动化构建工具
作用:压缩css.js.img,合并文件,改名字,编译sass,拷贝 使用步骤: 1.安装node环境,下一步,下一步,安装C盘: 2.在你的根目录下,在地址栏输入cmd回车: 3.检测node和np ...
- Spring Boot中的JSON技术
Spring Boot中的JSON技术 平日里在项目中处理JSON一般用的都是阿里巴巴的Fastjson,后来发现使用Spring Boot内置的Jackson来完成JSON的序列化和反序列化操作也挺 ...
- springboot 注解属性配置
参考: https://blog.csdn.net/ouyangguangfly/article/details/106646378 https://www.cnblogs.com/cbzj/p/94 ...
- SQLServer 远程链接MySql数据库
第一步:安装MySQL odbc driver 在SQL SERVER所在主机上安装MYSQL ODBC Driver; 下载地址:http://dev.mysql.com/downloads/con ...
- 通过简单实现一个阻塞队列了解ReentraintLock
MyBlockingQueue 代码 package com.kms.test; import java.util.LinkedList; import java.util.concurrent.lo ...
- Git_基础理论
三个区域 Git本地有三个工作区域:工作目录(Working Directory).暂存区(Stage/Index).资源库(Repository或Git Directory).如果在加上远程的git ...
- Springboot中@RequestBody接收的对象传入首字母大写的参数时,无法接收到参数值的问题解决
在Vo对象中的变量上添加@JsonProperty("")注解 postman测试 转载:https://blog.csdn.net/qq_39069718/article/det ...
- 解决 SMTP Error: data not accepted php邮件发送失败的问题
php 发送邮件 出现 SMTP Error: data not accepted 1.正常情况下 都是正常的 但是偶尔 发送失败了 163.com 邮箱发送不了了. 所以去查了下问题所在 在 ...
- windows下创建虚拟环境
创建虚拟环境依赖以下两个模块 virtualenv 和virtualenvwrapper-win 1.下载 2.修改环境变量,增加一条 WORKON_HOME:路径 3. 同步配置 去向Pytho ...
- MySQL:查询语句 case when then 的用法
转载网址: https://blog.csdn.net/h123hlll/article/details/122366213