系列文章目录
一、EasyExcelUtil工具
public static <T> void export(HttpServletResponse response, String fileName, String sheetName, List<String> headNameList) throws IOException {
OutputStream out = null;
try {
response.setContentType("text/csv");
response.setCharacterEncoding(CharEncoding.UTF_8);
fileName = URLEncoder.encode(fileName, CharEncoding.UTF_8);
response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".csv");
out = response.getOutputStream();
EasyExcelFactory.write(out).excelType(ExcelTypeEnum.CSV).sheet(sheetName).head(EasyExcelUtil.headList(headNameList)).doWrite(new ArrayList<>());
} catch (Exception e) {
e.printStackTrace();
} finally {
IoUtil.close(out);
}
}
}