EASYPOI合并导出(20200721)

这篇博客详细介绍了如何使用注解进行Excel数据导出,包括对象定义、时间统计集合的封装以及导出过程。通过@ExcelTarget、@Excel和@ExcelCollection等注解实现业务员数据的格式化,并通过示例展示了如何将数据转化为Excel表格,最后展示了导出的图表效果。
摘要由CSDN通过智能技术生成

对象定义

@ExcelTarget("salesman")
@Data
public class Salesman {
   
private String id;
   
@Excel(name = "业务员", orderNum = "1", width = 20)
   
private String name;
   
@ExcelCollection(name = "6:00:01-8:30:00", orderNum = "4")
   
private List<TimeCount> timeCount1;
   
@ExcelCollection(name = "8:30:01-12:00:00", orderNum = "4")
   
private List<TimeCount> timeCount2;
   
@ExcelCollection(name = "12:00:01-18:00:00", orderNum = "4")
   
private List<TimeCount> timeCount3;
   
@ExcelCollection(name = "18:00:01-21:00:00", orderNum = "4")
   
private List<TimeCount> timeCount4;
   
@ExcelCollection(name = "21:00:01-6:00:00", orderNum = "4")
   
private List<TimeCount> timeCount5;
   
@ExcelCollection(name = "总计", orderNum = "4")
   
private List<TimeCount> timeCount6;
}

 

 

备注:@ExcelCollection表示为集合表格,orderNum指占多少列,为该集合对象导出列的个数。如TimeCount中有6列,列名为拨打量、总案量、接听,可联。对应的@ExcelCollectionname为总计,那么总计对应表格就会合并。

@Data
public class TimeCount {
   
private String  id;
   
@Excel(name = "拨打量", height = 20, width = 8)
   
private long count_call;
   
@Excel(name = "总案量", height = 20, width = 8)
   
private long count_case;
   
@Excel(name = "接听", height = 20, width = 8)
   
private long listen_count;
   
@Excel(name = "可联", height = 20, width = 8)
   
private long listen_case_count;
}

 

 

导出集合封装

List<Salesman> salesmanList = new ArrayList<>();
Iterator<Map.Entry<String, Object>> iter0 = salesmanMap.entrySet().iterator();
while
(iter0.hasNext()){
    Map.Entry<String
, Object> next = iter0.next();
   
Salesman salesman = new Salesman();
   
salesman.setName(next.getKey());
   
Map<String,Object > map  = (Map<String, Object>) next.getValue();
   
TimeCount timeCount6 = new TimeCount();
   
timeCount6.setCount_case((Integer) map.get("user_count_case"));
   
timeCount6.setListen_case_count((Integer) map.get("user_listen_case_count"));
   
timeCount6.setCount_call((Integer) map.get("user_count_call"));
   
timeCount6.setListen_count((Integer) map.get("user_listen_count"));
   
Map<String,Object> map2 = (Map<String, Object>) map.get("timeFlag");
   
List<TimeCount> t6 = new ArrayList<>();
   
t6.add(timeCount6);

   
List<TimeCount> t1 = new ArrayList<>();
   
t1.add(getTimeCount((Map<String, Object>) map2.get(1)));
   
List<TimeCount> t2 = new ArrayList<>();
   
t2.add(getTimeCount((Map<String, Object>) map2.get(2)));
   
List<TimeCount> t3 = new ArrayList<>();
   
t3.add(getTimeCount((Map<String, Object>) map2.get(3)));
   
List<TimeCount> t4 = new ArrayList<>();
   
t4.add(getTimeCount((Map<String, Object>) map2.get(4)));
   
List<TimeCount> t5 = new ArrayList<>();
   
t5.add(getTimeCount((Map<String, Object>) map2.get(5)));
   
salesman.setTimeCount1(t1);
   
salesman.setTimeCount2(t2);
   
salesman.setTimeCount3(t3);
   
salesman.setTimeCount4(t4);
   
salesman.setTimeCount5(t5);
   
salesman.setTimeCount6(t6);
   
salesmanList.add(salesman);
}

StringJoiner sj =
new StringJoiner(",","总计:","");
sj.add(startDate + " " + endDate).add("业务员" + salesmanList.size() +  "")
.add(
"接听总量"+total_listen_count).add("拨打总量"+total_count_call)
        .add(
"可联总案件量"+total_listen_case_count)
.add(
"跟进案件量"+total_count_case);

try
{
    ExportParams exportParams =
new ExportParams(sj.toString(), "开案进度表");
   
Workbook workbook = ExcelExportUtil.exportBigExcel(exportParams, Salesman.class, salesmanList);
   
ExcelExportUtil.closeExportBigExcel();
   
File successFilePath = new File("E:/urge/开案进度表.xls");
   
FileOutputStream fos = new FileOutputStream(successFilePath);
   
workbook.write(fos);
   
fos.close();
}catch(IOException e)
{
    e.printStackTrace()
;
}

 

 

导出效果图

参考内容

https://opensource.afterturn.cn/doc/easypoi.html#90101

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值