zhubaomin
2025-04-14 4a2deb11b819dd78a8c75e244ef67ec2e48cf5f5
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/excel/ExcelUtil.java
New file
@@ -0,0 +1,22 @@
package com.dy.pipIrrGlobal.excel;
import jakarta.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
/**
 * @author ZhuBaoMin
 * @date 2024-08-26 10:28
 * @LastEditTime 2024-08-26 10:28
 * @Description 设置excel下载响应头属性
 */
public class ExcelUtil {
    public static void setExcelRespProp(HttpServletResponse response, String rawFileName) throws UnsupportedEncodingException {
        String fileName = URLEncoder.encode(rawFileName, "UTF-8").replaceAll("\\+", "%20");
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        response.setCharacterEncoding("utf-8");
        response.setHeader("Content-Disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
    }
}