dw 2 週之前
父節點
當前提交
9e115aa7a9
共有 1 個檔案被更改,包括 10 行新增1 行删除
  1. 10
    1
      src/main/java/com/th/demo/tools/Tools.java

+ 10
- 1
src/main/java/com/th/demo/tools/Tools.java 查看文件

@@ -138,12 +138,21 @@ public class Tools {
138 138
 
139 139
 
140 140
 
141
+
142
+
141 143
     ///123423456
142 144
     public static OutputStream getExportOutStream(String filename, HttpServletResponse response) {
143 145
         OutputStream out = null;
144 146
         try {
145
-            response.setContentType("application/vnd.ms-excel");
147
+            // 使用正确的 xlsx Content-Type
148
+            response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
146 149
             response.setHeader("Content-Disposition", "attachment;filename=" + new String(filename.getBytes("UTF-8"), "ISO8859-1"));
150
+            // 禁用缓存
151
+            response.setHeader("Pragma", "no-cache");
152
+            response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
153
+            response.setHeader("Expires", "0");
154
+            // 设置缓冲区大小为大文件优化
155
+            response.setBufferSize(8192); // 8KB buffer
147 156
             out = response.getOutputStream();
148 157
         } catch (Exception ex) {
149 158
             ex.printStackTrace();

Loading…
取消
儲存