New file |
| | |
| | | package com.example.erp.tools; |
| | | |
| | | import com.alibaba.excel.EasyExcel; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.util.List; |
| | | |
| | | //exccel下载 |
| | | public class DownExcel { |
| | | public static void download(HttpServletResponse response, Class t, List list,String reportName) throws IOException, IllegalAccessException,InstantiationException { |
| | | response.setContentType("application/vnd.ms-excel");// 设置文本内省 |
| | | response.setCharacterEncoding("utf-8");// 设置字符编码 |
| | | response.setHeader("Content-disposition", "attachment;filename="+reportName+".xlsx"); // 设置响应头 |
| | | try { |
| | | EasyExcel.write(response.getOutputStream(), t).sheet("模板").doWrite(list); //用io流来写入数据 |
| | | }catch (Exception e){ |
| | | System.out.println("文件导出异常"+reportName+":"+e.getMessage()); |
| | | } |
| | | |
| | | } |
| | | } |