From fb66e19783830d9afeae8fc8b8f0636f5e0c47e9 Mon Sep 17 00:00:00 2001
From: baizonghao <1719256278@qq.com>
Date: 星期六, 18 三月 2023 17:58:19 +0800
Subject: [PATCH] 导出优化文件名

---
 ycl-common/src/main/java/com/ycl/utils/EasyExcelUtils.java |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/ycl-common/src/main/java/com/ycl/utils/EasyExcelUtils.java b/ycl-common/src/main/java/com/ycl/utils/EasyExcelUtils.java
index 50156d9..4d9f1b7 100644
--- a/ycl-common/src/main/java/com/ycl/utils/EasyExcelUtils.java
+++ b/ycl-common/src/main/java/com/ycl/utils/EasyExcelUtils.java
@@ -8,6 +8,7 @@
 
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
+import java.net.URLEncoder;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
 import java.util.Collection;
@@ -30,6 +31,17 @@
     }
 
     @SneakyThrows
+    public static void export1(HttpServletResponse response, String sheetName, Class className, Collection<?> collection, String fileName) {
+        fileName = URLEncoder.encode(fileName, "UTF-8");
+        response.setContentType("application/vnd.ms-excel");
+        response.setCharacterEncoding("utf-8");
+        response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + fileName  + ".xlsx");
+        EasyExcel.write(response.getOutputStream(), className)
+                .sheet(sheetName)
+                .doWrite(collection);
+    }
+
+    @SneakyThrows
     public static void importDepartFile(MultipartFile file) throws IOException {
         EasyExcel.read(file.getInputStream())
                 .head(UmsDepartDto.class)

--
Gitblit v1.8.0