导出动态列
导出功能,动态列设置
public void excel(HttpServletResponse response) {
ExcelExportEntity excelentity = new ExcelExportEntity();
List<ExcelExportEntity> entity = new ArrayList<>();
entity.add(new ExcelExportEntity("姓名", "name"));
entity.add(new ExcelExportEntity("性别", "sex"));
excelentity.setList(entity);
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
Map<String, Object> stringListHashMap = new HashMap<>();
stringListHashMap.put("name", "张三");
stringListHashMap.put("sex", "12");
Map<String, Object> stringListHashMap2 = new HashMap<>();
stringListHashMap2.put("name", "李四");
stringListHashMap2.put("sex", "32");
list.add(stringListHashMap);
list.add(stringListHashMap2);
try {
Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("统计详情", "统计详情"), entity,
list);
String fileName = URLEncoder.encode("1eewqewq", "UTF-8");
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setCharacterEncoding("utf-8");
response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
workbook.write(response.getOutputStream());
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}