81,092
社区成员
发帖
与我相关
我的任务
分享
public void exportHouseInfoList(HttpServletResponse response) throws Exception {
// 构建动态表头
List<List<String>> headList = new ArrayList<>();
String[] HouseCostHead = new String[]{"类型", "公司", "分公司", "需求部门"};
List<String> tempHead;
for (String head : HouseCostHead) {
tempHead = new ArrayList<>();
tempHead.add(head);
headList.add(tempHead);
}
// 封装数据
List<List<Object>> infoList = new ArrayList<>();
List<Object> hInfo = new ArrayList<>();
List<Map<String, Object>> hList = hostelDao.getHouseInfoList();
for (Map<String, Object> map : hList) {
hInfo.add(map.get("type"));
hInfo.add(map.get("company"));
hInfo.add(map.get("office"));
infoList.add(hInfo);
}
ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).build();
WriteSheet houseSheet = EasyExcel.writerSheet(1, "房屋信息").head(headList).build();
String houseExcel = BaseUtil.formatDate(new Date()) + "房屋信息表.xlsx";
response.setContentType("application/vnd.ms-excel");
response.setCharacterEncoding("utf-8");
String fileName = URLEncoder.encode(houseExcel, "UTF-8");
response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
excelWriter.write(infoList, houseSheet);
excelWriter.finish();
}
同学,这个地方怎样解决的