From 6d27673135ac72de6e8e20e56c748c4ef1be47b4 Mon Sep 17 00:00:00 2001
From: 陈昶聿 <chychen@nbjetron.com>
Date: 星期三, 17 十二月 2025 14:24:58 +0800
Subject: [PATCH] 【丽水】统计随访数据 增加redis记录结果 提高查询效率
---
ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java | 36 +++++++++++++++++++++++++++++-------
1 files changed, 29 insertions(+), 7 deletions(-)
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java
index 218c782..c81ec58 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java
@@ -20,8 +20,10 @@
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
+import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import com.ruoyi.common.utils.ServletUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.RegExUtils;
import org.apache.commons.lang3.reflect.FieldUtils;
@@ -455,13 +457,8 @@
*/
public void exportExcelWithFileName(HttpServletResponse response, List<T> list, String sheetName, String fileName) {
//璁剧疆鏂囦欢鍚�
- try {
- fileName = URLEncoder.encode(fileName, "UTF8") + ".xls";
- response.setHeader("Content-Disposition",
- "attachment;filename=" + fileName);
- } catch (UnsupportedEncodingException e) {
- throw new RuntimeException(e);
- }
+ HttpServletRequest request = ServletUtils.getRequest();
+ setExcelFileName(response, request, fileName);
exportExcel(response, list, sheetName, StringUtils.EMPTY);
}
@@ -1450,4 +1447,29 @@
}
return method;
}
+
+ /**
+ * 璁剧疆瀵煎嚭Excel鏂囦欢鍚嶇О
+ * @param response 杩斿洖鏁版嵁
+ * @param request 娴忚鍣ㄨ姹傚ご
+ * @param fileName 鏂囦欢鍚嶇О
+ */
+ public void setExcelFileName(HttpServletResponse response, HttpServletRequest request, String fileName) {
+ try {
+ //浼氭竻绌哄搷搴旂紦鍐插尯鐨勫唴瀹癸紝纭繚鍚庣画杈撳嚭涓嶄細鍙楀埌涔嬪墠鏁版嵁鐨勫奖鍝�
+ response.reset();
+ // 瀹氫箟娴忚鍣ㄥ搷搴旇〃澶达紝椤哄甫瀹氫箟涓嬭浇鍚�
+ fileName = fileName + ".xlsx";
+ // 瀵规枃浠跺悕杩涜URL缂栫爜锛屾敮鎸佷腑鏂囨枃浠跺悕
+ String encodedFileName = URLEncoder.encode(fileName, "UTF-8").replaceAll("\\+", "%20");
+ // 浣跨敤 filename* 鍙傛暟鏀寔 UTF-8 缂栫爜锛圧FC 5987锛夛紝鍚屾椂淇濈暀 filename 鍙傛暟鍏煎鏃ф祻瑙堝櫒
+ response.setHeader("Content-Disposition", "attachment; filename=\"" + encodedFileName +
+ "\"; filename*=utf-8''" + encodedFileName);
+ // 瀹氫箟涓嬭浇鐨勭被鍨嬶紝鏍囨槑鏄痚xcel鏂囦欢
+ response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
+ response.setCharacterEncoding("utf-8");
+ }catch (Exception e){
+ log.error("{}璁剧疆瀵煎嚭Excel鏂囦欢鍚嶇О寮傚父,{}", fileName, e.getMessage());
+ }
+ }
}
--
Gitblit v1.9.3