官网:
写Excel | Easy Excel注解https://easyexcel.opensource.alibaba.com/docs/current/api/write#writeworkbook
/**
* 导出xls
* @param response
* @param outClass 每行对应的类
* @param fileNameIn 名称
* @param list
* @throws IOException
*/
public static void outPutXls(HttpServletResponse response, Class outClass, String fileNameIn, List list) throws IOException {
response.setContentType("application/vnd.ms-excel");
response.setCharacterEncoding("utf-8");
// 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系
String fileName = URLEncoder.encode(fileNameIn, "UTF-8");
response.setHeader("Content-disposition", "attachment;filename=" + fileName + EXL_FILE_XLS);
EasyExcel.write(response.getOutputStream(), outClass).excelType(ExcelTypeEnum.XLS)
.sheet("sheet1").doWrite(list);
}
}