package com.skr.mdm.util;

import com.alibaba.excel.EasyExcel;

import javax.servlet.http.HttpServletResponse;
import java.net.URLEncoder;
import java.util.List;

/**
 * excel工具类
 */
public class ExcelMdmUtil {

    /**
     * 导出
     * @param fireName
     * @param data
     * @param excelClass
     * @param response
     * @throws Exception
     */
    public static void export(String fireName, List<?> data, Class<?> excelClass, HttpServletResponse response) throws Exception {
        response.setContentType("application/vnd.ms-excel");
        response.setCharacterEncoding("utf-8");
        String fileNameEncode = URLEncoder.encode(fireName, "UTF-8");
        response.setHeader("content-disposition", "attachment;filename=" + fileNameEncode + ".xlsx");
        EasyExcel.write(response.getOutputStream(), excelClass)
                .sheet()
                .doWrite(data);
    }
}
