liurunyu
2025-06-19 37068a7c3f4a0c985a16a92ff64c361b6e1f17d5
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");
    }
}