zhoushihao
2025-05-12 fbd31387721424c65b173cbb23b03202f3e7dce6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package com.mes.utils.excel;
 
import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
 
/**
 * @Author : zhoush
 * @Date: 2025/5/12 17:03
 * @Description:
 */
public class ExcelUtil {
    public static void setExcelResponseProp(HttpServletResponse response, String rawFileName) throws UnsupportedEncodingException {
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        response.setCharacterEncoding("utf-8");
        String fileName = URLEncoder.encode(rawFileName, "UTF-8").replaceAll("\\+", "%20");
        response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
    }
}