response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");//.xlsx格式
//response.setContentType("application/application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8");
//response.setContentType("application/vnd.ms-excel");//xls格式
//response.setContentType("application/octet-stream;charset=UTF-8;");
//response.setHeader("Pragma", "no-cache");
//response.setHeader("Cache-Control", "no-cache");
//response.setDateHeader("Expires", 0);
//response.setContentType("application/octet-stream");
//response.setCharacterEncoding("utf-8");
//这里URLEncoder.encode可以防止中文乱码
response.setCharacterEncoding("utf-8");
response.setContentType("application/json;charset=utf-8");
下载excel response设置
最新推荐文章于 2024-09-05 14:40:56 发布
该代码段展示了如何设置HTTP响应以正确处理Excel文件的下载,包括设置application/vnd.openxmlformats-officedocument.spreadsheetml.sheet用于.xlsx格式,application/vnd.ms-excel用于.xls格式,以及确保使用UTF-8防止中文乱码。
摘要由CSDN通过智能技术生成