package jnpf.util;

import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletResponse;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;

/**
 * 导出工具类
 *
 * @author yanwenfu
 * @create 2023-08-10
 */
@Component
public class ExportUtil {

    public void exportTemplateExcel(Workbook workbook, HttpServletResponse response, String excelName) throws Exception {
        // 3. 导出EXCEL
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        response.setCharacterEncoding("utf-8");
        response.setHeader("Content-Disposition", "attachment;filename=" +
                URLEncoder.encode(TemplateExcelUtils.getFileName(excelName), StandardCharsets.UTF_8));
        workbook.write(response.getOutputStream());
    }
}
