From 1c732150ad5e8b21efff07ecd923c4ff8fda60c1 Mon Sep 17 00:00:00 2001 From: zhanghua <314079846@qq.com> Date: 星期二, 05 九月 2023 20:47:41 +0800 Subject: [PATCH] 100路视频 --- 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