清涧县住房和成乡建设局 网站,连锁 加盟 网站模板,wordpress 表格程序,seo做子网站EasyPOI真的是一款非常好用的文件导出工具#xff0c;相较于传统的一行一列的数据导出#xff0c;这种以实体类绑定生成的方式真的非常方便#xff0c;也希望大家能够了解、掌握其使用方法#xff0c;下面就用一个实例来简单介绍一下EasyPOI的使用。
1.导入依赖 !-- e…EasyPOI真的是一款非常好用的文件导出工具相较于传统的一行一列的数据导出这种以实体类绑定生成的方式真的非常方便也希望大家能够了解、掌握其使用方法下面就用一个实例来简单介绍一下EasyPOI的使用。
1.导入依赖 !-- easypoi导出 --dependencygroupIdcn.afterturn/groupIdartifactIdeasypoi-base/artifactIdversion4.2.0/version/dependencydependencygroupIdcn.afterturn/groupIdartifactIdeasypoi-web/artifactIdversion4.2.0/version/dependencydependencygroupIdcn.afterturn/groupIdartifactIdeasypoi-annotation/artifactIdversion4.2.0/version/dependency2.创建对应实体类
package com.wulian.training.center.export;import cn.afterturn.easypoi.excel.annotation.Excel;
import lombok.Data;Data
public class TestScoreExportDTO {/*** 序号*/Excel(name 序号, orderNum 1, width 15)private Integer id;/*** 人员名称*/Excel(name 人员名称, orderNum 2, width 15)private String personName;/*** 达标天数*/Excel(name 达标天数, orderNum 3, width 15)private Integer passCount;/*** 积分总数*/Excel(name 积分总数, orderNum 4, width 15)private String totalScore;/*** 日平均积分*/Excel(name 日平均积分, orderNum 5, width 15)private String avgScore;/*** 积分排名*/Excel(name 积分排名, orderNum 6, width 15)private Integer number;}
3.导出方法 PostMapping(/export)ApiOperation(value 导出)public ResultMoudel export(RequestParam(required false)String name,HttpServletRequest request) throws IOException {Map mapnew HashMap();map.put(name,name);map.put(companyId,sysUser.getCompanyId());ListTestScoreExportDTO listappTestManageMapper.selectOrderByTypePage(map);AtomicInteger id new AtomicInteger(new Integer(1));list.stream().forEach(iter-{iter.setId(id.getAndIncrement());});String fileName 积分信息;//设置导出参数ExportParams exportParams new ExportParams(积分信息, 排名, ExcelType.XSSF);//设置表头exportParams.setCreateHeadRows(true);
// exportParams.setAddIndex(true);//数据渲染Workbook sheets ExcelExportUtil.exportExcel(exportParams, TestScoreExportDTO.class, list);//导出final String downloadName new String((fileName ExcelTypeEnum.XLSX.getValue()).getBytes(), StandardCharsets.ISO_8859_1);
// response.setCharacterEncoding(UTF-8);response.setHeader(content-Type, application/vnd.ms-excel);response.setHeader(Content-Disposition, attachment;filename downloadName);//获取输出流将excel输出ServletOutputStream outputStream response.getOutputStream();sheets.write(outputStream);return new ResultMoudel().success(导出成功);} 导出成功