vue springboot 实现excel导出
实现excel 导出
一、需求
实现 excel 的导出
二、技术
选用 easypoi
官网:
https://gitee.com/lemur/easypoi#http://doc.wupaas.com/docs/easypoi/easypoi-1c0u4mo8p4ro8
三、实现
1、前端
<el-button type="success" @click="handleExport">导出<i class="el-icon-upload el-icon--right"></i></el-button>
handleExport() {
let a = document.createElement('a')
a.href = "/xxx/export"
a.click()
}
2、后端
a、引入pom依赖
<!-- 引入EasyPoi包 -->
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-spring-boot-starter</artifactId>
<version>4.1.0</version>
</dependency> <dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.4</version>
</dependency>
b、实体注解
@Data
public class UnitMaterialRecommendVo {
@Excel(name = "序号", width = 10)
private Integer num;
@Excel(name = "体系", width = 25, orderNum = "1")
private String unitSystem;
@Excel(name = "单位", width = 25, orderNum = "2")
private String unitName;
@Excel(name = "参评类型", width = 25, orderNum = "3", replace = { "参评单位申报推荐_10", "文明单位复查审核_20" })
private Integer reportType;
@Excel(name = "审核结果", width = 25, orderNum = "4", replace = { "审核中_0", "审核通过_1", "审核不通过_-1" })
private Integer state;
@Excel(name = "联系方式", width = 25, orderNum = "5")
private String unitDirectorPhone;
@Excel(name = "所属省市", width = 25, orderNum = "6")
private String unitCityName;
@Excel(name = "文明单位类型", width = 25, orderNum = "7", replace = { "四川省文明单位_10", "四川省最佳文明单位_20"})
private Integer civilizedUnitType;
@Excel(name = "备注", width = 30, orderNum = "8")
private String remark;
}
c、导出方法
List<UnitMaterialRecommend> list = this.list(wrapper);
String fileName = new String("文件名称.xls".getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1);
response.addHeader("Content-Disposition", "attachment;filename=" + fileName);
response.setContentType("application/vnd.ms-excel;charset=gb2312");
List<UnitMaterialRecommendVo> result = new ArrayList<>();
AtomicInteger num = new AtomicInteger(1);
// 设置序号
list.forEach(item -> item.setNum(num.getAndIncrement()));
Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), UnitMaterialRecommendVo.class, result);
workbook.write(response.getOutputStream());
三、备注
通过模板批量导出,采用 ExcelExportUtil.exportExcelClone 方法,详见下面示例:
private static final String SHEET_NAME = "sheetName";
@Override
public void multipleExport(HttpServletResponse response, UnitMaterialRecommend recommend) throws IOException { String fileName = new String("template.xls".getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1);
response.addHeader("Content-Disposition", "attachment;filename=" + fileName);
response.setContentType("application/vnd.ms-excel;charset=gb2312");
TemplateExportParams params = new TemplateExportParams("template/materialTemplate.xls"); List<UnitMaterialRecommend> models = this.getModels(recommend);
List<Map<String, Object>> listMap = new ArrayList<>();
for (int j = models.size() - 1; j >= 0; j--) {
Map<String, Object> modelMap = this.getModelMap(models.get(j));
modelMap.put(SHEET_NAME, "sheet" + j);
listMap.add(modelMap);
}
Map<Integer, List<Map<String, Object>>> realMap = new HashMap<>();
realMap.put(0, listMap);
Workbook workbook = ExcelExportUtil.exportExcelClone(realMap, params);
workbook.write(response.getOutputStream());
}
~~~以上
vue springboot 实现excel导出的更多相关文章
- Vue项目实现excel导出
1.package.json里面安装三个插件 npm install xlsx --save npm install script-loader –save-dev npm install ...
- vue如何使用excel导出后台数据
let params = { // 请求参数 要下载Excel的id 'id':this.excelId }; //导入的接口名 api_excel_exportExcel().then(res =& ...
- Vue + axios + SpringBoot 2实现导出Excel
Vue + axios + SpringBoot 2实现导出Excel 1. 前端js代码-发送Http请求 /** * 文件下载 * @param url 下载地址 * @param fileNam ...
- vue springboot利用easypoi实现简单导出
vue springboot利用easypoi实现简单导出 前言 一.easypoi是什么? 二.使用步骤 1.传送门 2.前端vue 3.后端springboot 3.1编写实体类(我这里是dto, ...
- 使用VUE+SpringBoot+EasyExcel 整合导入导出数据
使用VUE+SpringBoot+EasyExcel 整合导入导出数据 创建一个普通的maven项目即可 项目目录结构 1 前端 存放在resources/static 下 index.html &l ...
- SpringBoot加Poi仿照EasyPoi实现Excel导出
POI提供API给Java程序对Microsoft Office格式档案读和写的功能,详细功能可以直接查阅API,因为使用EasyPoi过程中总是缺少依赖,没有搞明白到底是什么坑,索性自己写一个简单工 ...
- 基于springboot跟poi封装的最便捷的excel导出
发布时间:2018-11-15 技术:springboot1.5.6 + maven3.0.5 + jdk1.8 概述 Springboot最便捷的Excel导出,只需要一个配置文件即可搞定 ...
- SpringBoot使用Easypoi导出excel示例
SpringBoot使用Easypoi导出excel示例 https://blog.csdn.net/justry_deng/article/details/84842111
- abp框架Excel导出——基于vue
abp框架Excel导出--基于vue 目录 abp框架Excel导出--基于vue 1.技术栈 1.1 前端采用vue,官方提供 1.2 后台是abp--aspnetboilerplate 2. E ...
- springboot通过poi导出excel
Maven引入依赖 <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi< ...
随机推荐
- C++ Constructor And Destructor
if you have problems with constructors and destructors, you can insert such print statements in cons ...
- IDEA之调试或运行的小助手日志插件Grep Console:不同颜色区分,查看日志看方便【工欲善其事必先利其器】
简介 Grep Console是一款方便开发者对idea控制台输出日志进行个性化管理的插件.这个插件还是很用的,在满屏的日志中,迅速找到自己关注的内容,调试程序的绝佳工具. 功能特性 Grep Con ...
- C# 一维数组与二维数组相互转换
class Program { static void Main(string[] args) { double[] a = { 1, 2, 3, 4, 5, 6 }; double[,] b = R ...
- PointNet笔记
可能遇到的问题 在windows上运行pointnet的代码时,可能会遇到一些问题: 1.比如提示OSError: no file with expected extension, 这是因为可视化的s ...
- Bash 技巧
Bash 使用技巧 Bash 是 GNU 项目的 Bourne Again SHell, 具有交互式命令行编辑.支持它的体系结构上的作业控制.类似 csh 的功能 Bash 是免费软件,根据 GNU ...
- app备案证明需要提供md5值和公钥的解决方案
现在app上架华为市场.小米市场.苹果市场等大型的应用商店,都需要提供国内的app备案证明.无论是安卓还是ios,都需要备案了. 但是问题是备案的时候需要填写app的bundle ID.公钥和MD5值 ...
- windows edge浏览器免费复制网页文字
复制时,出现上面提示时候 使用edge浏览器打开链接,在http前面加入read: ,然后打开,即可复制 如果用js,可以参考https://www.cnblogs.com/rmticocean/p/ ...
- Segment-anything学习到微调系列_SAM初步了解
Segment-anything学习到微调系列_SAM初步了解 前言 本系列文章是博主在工作中使用SAM模型时的学习笔记,包含三部分: SAM初步理解,简单介绍模型框架,不涉及细节和代码 SAM细节理 ...
- 【OracleDB】 09 创建和管理表
Oracle常见的数据库对象 - 表 基本的数据存储集合,行与列组成 - 视图 抽取的逻辑集合 - 序列 提供规律性的数值 - 索引 提高查询效率 - 同义词 对象别名 TABLE 表 用户定义的表: ...
- 为python安装扩展模块时报错——error: invalid command 'bdist_wheel'
具体过程: devil@hp:~/lab$ ./bazel-bin/python/pip_package/build_pip_package /tmp/dmlab_pkg2022年 10月 03日 星 ...