123456789101112131415161718192021222324252627 |
- package com.yunzhi.inte.common;
-
- import com.alibaba.excel.EasyExcel;
-
- import javax.servlet.http.HttpServletResponse;
- import java.io.IOException;
- import java.util.List;
-
- public class ExcelUtils {
-
- /**
- * 发送 excel 到客户端
- * 暂时只支持单 sheet 页
- * @param response
- * @param data
- * @param fileName
- * @throws IOException
- */
- public static void flush(HttpServletResponse response, Class dataClass, List data, String fileName) throws IOException {
- response.setContentType("application/vnd.ms-excel");
- response.setCharacterEncoding("utf-8");
- response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
- response.setHeader("Content-Disposition", "attachment;filename="+StringUtils.urlEncode(fileName)+".xlsx");
-
- EasyExcel.write(response.getOutputStream(), dataClass).sheet("sheet1").doWrite(data);
- }
- }
|