easy poi实现不定列导出excel -map方式- 以及指定某些列是数字格式
为什么使用不定列转出
由于业务需求,有时会需要进行行转列之后导出,而因为大多数的行转列后的数据列数是不固定的,所以此时传统的使用实体类加注解的方式就无法解决该问题了。
使用map方式导出
首先引入:
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-spring-boot-starter</artifactId>
<version>3.3.0</version>
</dependency>
导出方法:
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
public void downloadTest(HttpServletResponse response) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Random random = new Random();
//主表数据
List<Map<String,Object>> datas = new LinkedList<>();
for (int i = 0;i<10;i++){
Map<String,Object> mainMap = new HashMap<>();
mainMap.put("plan_no",i);
mainMap.put("name","chanpin"+i);
mainMap.put("erp_code","chanpinbianma"+i);
for (int t = 0;t<5;t++) {
Date date = new Date();
Calendar calendar = new GregorianCalendar();
calendar.setTime(date);
calendar.add(Calendar.DATE, t);
date = calendar.getTime();
mainMap.put(format.format(date), random.nextInt());
}
datas.add(mainMap);
}
Map<String,Object> data = datas.get(0);
List<String> dateList = new LinkedList<>();
for (Object key : data.keySet()

本文介绍如何使用 Easypoi 实现 Excel 的不定列导出功能,适用于业务需求中需要将行数据转换为列数据的场景。通过 Map 方式导出并指定特定列为数字格式。
最低0.47元/天 解锁文章
22万+

被折叠的 条评论
为什么被折叠?



