这个写法目前是管用的,但是会有几个问题
package com.operative.base.utils;
import com.alibaba.excel.EasyExcel;
import org.apache.poi.ss.formula.functions.T;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.List;
public class ExcelUtil {
public static void generateExcel(HttpServletResponse response,List<?> data) throws IOException {
response.setContentType("application/vnd.ms-excel");
response.setCharacterEncoding("utf-8");
// 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系
String fileName = URLEncoder.encode("接种人员信息", "UTF-8").replaceAll("\\+", "%20");
System.out.println(fileName);
response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
EasyExcel.write(response.getOutputStream(), data.get(0).getClass()).sheet("接种人员信息").doWrite(data);
}
}
目前这个写法在data长度小于0的时候会出问题。
有想过直接传递类型,但是试了几个方法没成功,有时间这里需要研究一下
晚上找到一些博客,先码住,有时间的时候消化一下