- 实现效果
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/a24e2af806d0b00bb83d8b21109fec37.png)
- 代码实现
List<MesReportedWagesVo> list = reportedWages.getList();
try {
List<List<Object>> dataList = new ArrayList<>();
BigDecimal totalPricePd = new BigDecimal(0);
Integer totalCount = 0;
for (MesReportedWagesVo mesReportedWagesVo : list) {
List<Object> rowData = new ArrayList<>();
List<Object> rowDataTwo = new ArrayList<>();
String name = "姓名:" + mesReportedWagesVo.getRealName() + ",工号:"+mesReportedWagesVo.getStaffId();
String sum = "个人合计:" + mesReportedWagesVo.getSumCount() + "件,"+mesReportedWagesVo.getSumPricePd()+"元";
rowData.add(name);
totalPricePd.add(mesReportedWagesVo.getSumPricePd()) ;
totalCount += mesReportedWagesVo.getSumCount();
dataList.add(rowData);
for (MesEngineeringManagementDTO mesEngineeringManagementDTO : mesReportedWagesVo.getMesEngineeringManagementDTOList()) {
List<Object> itemData = new ArrayList<>();
itemData.add(mesEngineeringManagementDTO.getProduceNum());
itemData.add(mesEngineeringManagementDTO.getColorName());
itemData.add(mesEngineeringManagementDTO.getSizeCode());
itemData.add(mesEngineeringManagementDTO.getProductName());
itemData.add(mesEngineeringManagementDTO.getPricePd());
itemData.add(mesEngineeringManagementDTO.getCount());
itemData.add(mesEngineeringManagementDTO.getPrice());
dataList.add(itemData);
}
rowDataTwo.add(sum);
dataList.add(rowDataTwo);
}
String fileName ="报工工资统计表";
fileName = URLEncoder.encode(fileName, "UTF-8");
response.setContentType("application/vnd.ms-excel");
response.setCharacterEncoding("UTF-8");
response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
ExcelWriter writer = EasyExcel.write(response.getOutputStream()).build();
Sheet sheet = new Sheet(1, 0);
List<List<String>> data = new ArrayList<>();
data.add(Arrays.asList("报工工资统计表","合计:"+totalCount+"件,金额:"+totalPricePd,"生产单号"));
data.add(Arrays.asList("报工工资统计表","合计:"+totalCount+"件,金额:"+totalPricePd,"颜色"));
data.add(Arrays.asList("报工工资统计表","合计:"+totalCount+"件,金额:"+totalPricePd,"尺码"));
data.add(Arrays.asList("报工工资统计表","合计:"+totalCount+"件,金额:"+totalPricePd,"工序"));
data.add(Arrays.asList("报工工资统计表","合计:"+totalCount+"件,金额:"+totalPricePd,"单价"));
data.add(Arrays.asList("报工工资统计表","合计:"+totalCount+"件,金额:"+totalPricePd,"数量"));
data.add(Arrays.asList("报工工资统计表","合计:"+totalCount+"件,金额:"+totalPricePd,"金额"));
sheet.setHead(data);
sheet.setAutoWidth(true);
sheet.setSheetName("报工工资统计表");
writer.write0(dataList, sheet);
writer.finish();
} catch (Exception e) {
e.printStackTrace();
}