liurunyu
2024-08-28 8d2b573ced32e6ca6fab7c1dc45e1fa108030ba1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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");
    }
 
}