MCPcopy Index your code
hub / github.com/Bit0r/java-util / download

Method download

src/main/java/util/EasyExcelUtil.java:66–74  ·  view source on GitHub ↗

文件下载(失败了会返回一个有部分数据的Excel),用于直接把excel返回到浏览器下载

(HttpServletResponse response, List<?> list, String sheetName)

Source from the content-addressed store, hash-verified

64 * 文件下载(失败了会返回一个有部分数据的Excel),用于直接把excel返回到浏览器下载
65 */
66 public static void download(HttpServletResponse response, List<?> list, String sheetName) throws IOException {
67 Class<?> clazz = list.get(0).getClass();
68 response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
69 response.setCharacterEncoding("utf-8");
70 // 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系
71 String fileName = URLEncoder.encode(sheetName, "UTF-8").replaceAll("\\+", "%20");
72 response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
73 EasyExcel.write(response.getOutputStream(), clazz).head(clazz).sheet(sheetName).doWrite(list);
74 }
75}
76
77class DataListener<T> extends AnalysisEventListener<T> {

Callers

nothing calls this directly

Calls 1

writeMethod · 0.80

Tested by

no test coverage detected