From 928e418f3f7884048ae3368bce88acd3c106f13d Mon Sep 17 00:00:00 2001
From: 疯狂的狮子Li <15040126243@163.com>
Date: 星期四, 18 一月 2024 17:48:07 +0800
Subject: [PATCH] add 增加 赞助商 数驼科技
---
ruoyi-common/ruoyi-common-excel/src/main/java/org/dromara/common/excel/utils/ExcelUtil.java | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 56 insertions(+), 0 deletions(-)
diff --git a/ruoyi-common/ruoyi-common-excel/src/main/java/org/dromara/common/excel/utils/ExcelUtil.java b/ruoyi-common/ruoyi-common-excel/src/main/java/org/dromara/common/excel/utils/ExcelUtil.java
index 329911d..a6c14ad 100644
--- a/ruoyi-common/ruoyi-common-excel/src/main/java/org/dromara/common/excel/utils/ExcelUtil.java
+++ b/ruoyi-common/ruoyi-common-excel/src/main/java/org/dromara/common/excel/utils/ExcelUtil.java
@@ -270,6 +270,26 @@
}
/**
+ * 澶歴heet妯℃澘瀵煎嚭 妯℃澘鏍煎紡涓� {key.灞炴�
+ *
+ * @param filename 鏂囦欢鍚�
+ * @param templatePath 妯℃澘璺緞 resource 鐩綍涓嬬殑璺緞鍖呮嫭妯℃澘鏂囦欢鍚�
+ * 渚嬪: excel/temp.xlsx
+ * 閲嶇偣: 妯℃澘鏂囦欢蹇呴』鏀剧疆鍒板惎鍔ㄧ被瀵瑰簲鐨� resource 鐩綍涓�
+ * @param data 妯℃澘闇�瑕佺殑鏁版嵁
+ * @param response 鍝嶅簲浣�
+ */
+ public static void exportTemplateMultiSheet(List<Map<String, Object>> data, String filename, String templatePath, HttpServletResponse response) {
+ try {
+ resetResponse(filename, response);
+ ServletOutputStream os = response.getOutputStream();
+ exportTemplateMultiSheet(data, templatePath, os);
+ } catch (IOException e) {
+ throw new RuntimeException("瀵煎嚭Excel寮傚父");
+ }
+ }
+
+ /**
* 澶氳〃澶氭暟鎹ā鏉垮鍑� 妯℃澘鏍煎紡涓� {key.灞炴�
*
* @param templatePath 妯℃澘璺緞 resource 鐩綍涓嬬殑璺緞鍖呮嫭妯℃澘鏂囦欢鍚�
@@ -304,6 +324,42 @@
}
/**
+ * 澶歴heet妯℃澘瀵煎嚭 妯℃澘鏍煎紡涓� {key.灞炴�
+ *
+ * @param templatePath 妯℃澘璺緞 resource 鐩綍涓嬬殑璺緞鍖呮嫭妯℃澘鏂囦欢鍚�
+ * 渚嬪: excel/temp.xlsx
+ * 閲嶇偣: 妯℃澘鏂囦欢蹇呴』鏀剧疆鍒板惎鍔ㄧ被瀵瑰簲鐨� resource 鐩綍涓�
+ * @param data 妯℃澘闇�瑕佺殑鏁版嵁
+ * @param os 杈撳嚭娴�
+ */
+ public static void exportTemplateMultiSheet(List<Map<String, Object>> data, String templatePath, OutputStream os) {
+ ClassPathResource templateResource = new ClassPathResource(templatePath);
+ ExcelWriter excelWriter = EasyExcel.write(os)
+ .withTemplate(templateResource.getStream())
+ .autoCloseStream(false)
+ // 澶ф暟鍊艰嚜鍔ㄨ浆鎹� 闃叉澶辩湡
+ .registerConverter(new ExcelBigNumberConvert())
+ .build();
+ if (CollUtil.isEmpty(data)) {
+ throw new IllegalArgumentException("鏁版嵁涓虹┖");
+ }
+ for (int i = 0; i < data.size(); i++) {
+ WriteSheet writeSheet = EasyExcel.writerSheet(i).build();
+ for (Map.Entry<String, Object> map : data.get(i).entrySet()) {
+ // 璁剧疆鍒楄〃鍚庣画杩樻湁鏁版嵁
+ FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
+ if (map.getValue() instanceof Collection) {
+ // 澶氳〃瀵煎嚭蹇呴』浣跨敤 FillWrapper
+ excelWriter.fill(new FillWrapper(map.getKey(), (Collection<?>) map.getValue()), fillConfig, writeSheet);
+ } else {
+ excelWriter.fill(map.getValue(), writeSheet);
+ }
+ }
+ }
+ excelWriter.finish();
+ }
+
+ /**
* 閲嶇疆鍝嶅簲浣�
*/
private static void resetResponse(String sheetName, HttpServletResponse response) throws UnsupportedEncodingException {
--
Gitblit v1.9.3