Springboot +easypoi模板导出Excel
程序员文章站
2022-06-24 23:49:37
...
依赖:
<!-- easypoi简单导出所需要的jar包 start -->
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-base</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-annotation</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-web</artifactId>
<version>3.1.0</version>
</dependency>
<!-- easypoi简单导出所需要的jar包 end-->
excel:
将表格放入
前端用什么框架什么框架都可以Controller主要接收两个参数response和前端传过来的参数params
Controller:
@GetMapping("export")
@ApiOperation("导出")
@LogOperation("导出")
@RequiresPermissions("fysjtsygt:fysjtsygt:export")
public void export(@ApiIgnore @RequestParam Map<String, Object> params, HttpServletResponse response) throws Exception {
List<FysjtsygtDTO> list = fysjtsygtService.list(params);
String fileNmae = "土地台账";
String date = DateUtils.format(new Date());
String year = params.get("ydYear").toString();
String orgName = params.get("orgName").toString();
TemplateExportParams param = new TemplateExportParams("/excelTemplates/土地台账.xlsx", true);
// 标题开始行
// param.setHeadingStartRow(0);
// 标题行数
// param.setHeadingRows(2);
// 设置sheetName,若不设置该参数,则使用得原本得sheet名称
//param.setSheetName("班级信息");
Map<String, Object> data = new HashMap<String, Object>();
data.put("date", date);//导出一般都要日期
data.put("year", year);//导出一个对象
data.put("orgName", orgName);//导出一个对象
data.put("list", list);//导出list集合
try {
Workbook book = ExcelExportUtil.exportExcel(param, data);
//下载方法
export(response, book, fileNmae);
} catch (Exception e) {
System.out.println("导出模板Excel,失败:" + e);
}
}
/**
* export导出请求头设置
*
* @param response
* @param workbook
* @param fileName
* @throws Exception
*/
private static void export(HttpServletResponse response, Workbook workbook, String fileName) throws Exception {
response.reset();
response.setContentType("application/x-msdownload");
response.setHeader("Content-disposition", "attachment; filename=" + java.net.URLEncoder.encode(fileName+".xlsx", "UTF-8"));
ServletOutputStream outStream = null;
try {
outStream = response.getOutputStream();
workbook.write(outStream);
} finally {
outStream.close();
}
}
上一篇: java:easypoi导出Excel
下一篇: iOS today插件毛玻璃效果
推荐阅读
-
建议收藏:.net core 使用EPPlus导入导出Excel详细案例,精心整理源码已更新至开源模板
-
java开发easypoi导出excel表格数据
-
.NET导出Gridview到excel 带模板列显示
-
【springboot+easypoi】一行代码搞定excel导入导出
-
【SpringBoot】SpringBoot整合EasyPoi自定义字典导出Excel
-
Java无模板导出Excel,Apache-POI插件实现
-
阿里easyexcel通过模板导出excel
-
Springboot导出excel文件并下载
-
.Net NPOI 根据excel模板导出excel
-
php导出excel图片格式,PHPExcel API接口用法大全,按模板导入excel,美化excel,导出图片,设置单元格字体颜色背景色边框,合并单元格,设置行高列宽...