Map<String, Object> map = new HashMap<>();
//从其它方法获的得集合
List<PlanDetail> planManageList = planManageService.accordTimeSearch(startDate, stopDate, isComplete);
// 创建excel
HSSFWorkbook wk = new HSSFWorkbook();
// 创建一张工作表
HSSFSheet sheet = wk.createSheet();
// 2
sheet.setColumnWidth(0, 5000);
HSSFRow row = sheet.createRow(0);
// 创建第一行的第一个单元格
// 想单元格写值
HSSFCell cell = row.createCell((short) 0);
cell.setCellValue("材质");
cell = row.createCell((short) 1);
cell.setCellValue("砖型");
cell = row.createCell((short) 2);
cell.setCellValue("重量");
cell = row.createCell((short) 3);
cell.setCellValue("总重量 ");
cell = row.createCell((short) 4);
cell.setCellValue("实际完成数量");
cell = row.createCell((short) 5);
cell.setCellValue("计划结束时间 ");
cell = row.createCell((short) 6);
cell.setCellValue("差额 ");
cell = row.createCell((short) 7);
cell.setCellValue("派工数量 ");
cell = row.createCell((short) 8);
cell.setCellValue("是否结案");
for (int i = 0; i < planManageList.size(); i++) {
HSSFRow row1 = sheet.createRow(i + 1);
row1.createCell(0).setCellValue(planManageList.get(i).getMaterialModel());
row1.createCell(1).setCellValue(planManageList.get(i).getMaterialName());
row1.createCell(2).setCellValue(planManageList.get(i).getZll());
row1.createCell(3).setCellValue(planManageList.get(i).getZll() * planManageList.get(i).getDoneQuantity());
if (planManageList.get(i).getTotalDoneQuantity() == null) {
row1.createCell(4).setAsActiveCell();
row1.createCell(6).setCellValue(0 - planManageList.get(i).getDoneQuantity());
} else {
row1.createCell(4).setCellValue(planManageList.get(i).getTotalDoneQuantity());
row1.createCell(6).setCellValue(planManageList.get(i).getTotalDoneQuantity() - planManageList.get(i).getDoneQuantity());
}
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
String planEndTime = simpleDateFormat.format(planManageList.get(i).getPlanEndTime());
row1.createCell(5).setCellValue(planEndTime);
if (planManageList.get(i).getTaskNum() == null) {
row1.createCell(7).setAsActiveCell();
} else {
row1.createCell(7).setCellValue(planManageList.get(i).getTaskNum());
}
if (planManageList.get(i).getIsComplete().equals("1")) {
row1.createCell(8).setCellValue("已结案");
} else {
row1.createCell(8).setCellValue("未结案");
}
}
String url=null;
String datetime=null;
try {
datetime=String.valueOf(Calendar.getInstance().getTimeInMillis())+".xls";
url =excelPath+datetime;
FileOutputStream outputStream = new FileOutputStream(url);
wk.write(outputStream);
outputStream.close();
} catch (FileNotFoundException e) {
map.put("error","导出失败,找不到路径");
return map;
} catch (IOException e) {
}
if (url==null){
map.put("error","导出失败");
return map;
}
map.put("success", true);
map.put("url",datetime);
return map;