Springboot Easyexcel

------ excel 实体 ------
@Data //get、set
@ContentRowHeight(15) // 行高
@HeadRowHeight(15) // 头行高
@ColumnWidth(20) //默认宽
public class ExportZSRelationColumn {
private static final long serialVersionUID = -6128134517321485539L;

//设置excel表头名称,index 排序
@ExcelProperty(value = "目标应用系统", index = 0)
private String toProjectName;

@ExcelProperty(value = "目标表数据库", index = 1)
private String toModelName;

@ExcelProperty(value = "目标表", index = 2)
private String toTableEnName;

@ColumnWidth(30)  //某列宽
@ExcelProperty(value = "目标表字段", index = 3)
private String toColumnEnName;

@ExcelProperty(value = "源应用系统", index = 4)
private String fromProjectName;

@ExcelProperty(value = "源数据库", index = 5)
private String fromModelName;

@ExcelProperty(value = "源表名", index = 6)
private String fromTableEnName;

@ExcelProperty(value = "源字段名", index = 7)
private String fromColumnEnName;

@ExcelProperty(value = "映射方式", index = 8)
private String mapType;

@ExcelProperty(value = "映射描述", index = 9)
private String mapDesc;
}

------ 调用 ------
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
// 设置导出文件前缀
String fName = "ProcessRelation_" + sdf.format(new Date());try {
ExcelUtil.export(response, fName, "血缘", list, ExportZSRelationColumn.class);
} catch (Exception e) {
logger.error("导出失败", e.getMessage());
throw new ServiceException("导出失败");
}

------ 工具方法 ------
/**
* 导出excel
*
* @param response 响应类
* @param fileName 文件名
* @param sheetName sheet名
* @param dataList 数据列表
* @param clazz class类
* @param <T> 泛型
*/
@SneakyThrows
public static <T> void export(HttpServletResponse response, String fileName, String sheetName, List<T> dataList, Class<T> clazz) {
response.setContentType("application/vnd.ms-excel");
response.setCharacterEncoding(Charsets.UTF_8.name());
fileName = URLEncoder.encode(fileName, Charsets.UTF_8.name());
response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".xlsx");
EasyExcel.write(response.getOutputStream(), clazz).excelType(ExcelTypeEnum.XLSX).sheet(sheetName).doWrite(dataList);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值