public void exportData(HttpServletResponse response, TRbstReimbursementDeptDto deptDto) {
String fileName = "预算表";
try {
fileName = URLEncoder.encode(fileName, "UTF-8");
response.setContentType("application/vnd.ms-excel;charset=utf-8");
response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".xlsx");
// 写入list之前的数据
Map<String, Object> map = new HashMap<String, Object>();
map.put("year", year);
String templateFileName = FileUtil.getPath() + "templates/年度预算导入模板.xlsx";
ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).withTemplate(templateFileName).build();
WriteSheet writeSheet = EasyExcel.writerSheet().build();
// 直接写入数据
excelWriter.fill(data(deptDto), writeSheet);
excelWriter.fill(map, writeSheet);
excelWriter.finish();
} catch (IOException e) {
e.printStackTrace();
}
}
private List<Map<String, Object>> data(TRbstReimbursementDeptDto deptDto) {
List<Long> deptIds = deptDto.getIdList();
List<Map<String, Object>> list = new ArrayList<>();
Map<String, Object> map = new HashMap<>();
map.put("test", "111);
list.add(map);
return list;
}