From 0bc9097f182de25549407263df7b2a5d92bb2d5c Mon Sep 17 00:00:00 2001 From: chengliejian <284067032@qq.com> Date: Thu, 7 Aug 2025 16:38:50 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=94=AF=E6=8C=81=20@ExcelIgnoreUnannotate?= =?UTF-8?q?d=20=E6=B3=A8=E8=A7=A3=EF=BC=8C=E4=BF=AE=E5=A4=8D=E6=9C=AA?= =?UTF-8?q?=E6=B3=A8=E8=A7=A3=E5=AD=97=E6=AE=B5=E5=AF=BC=E8=87=B4=E5=88=97?= =?UTF-8?q?=E5=90=88=E5=B9=B6=E9=94=99=E4=BD=8D=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/excel/core/CellMergeStrategy.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/ruoyi-common/ruoyi-common-excel/src/main/java/org/dromara/common/excel/core/CellMergeStrategy.java b/ruoyi-common/ruoyi-common-excel/src/main/java/org/dromara/common/excel/core/CellMergeStrategy.java index 515f68e1b..39697e186 100644 --- a/ruoyi-common/ruoyi-common-excel/src/main/java/org/dromara/common/excel/core/CellMergeStrategy.java +++ b/ruoyi-common/ruoyi-common-excel/src/main/java/org/dromara/common/excel/core/CellMergeStrategy.java @@ -3,6 +3,8 @@ package org.dromara.common.excel.core; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ReflectUtil; import cn.hutool.core.util.StrUtil; +import cn.idev.excel.annotation.ExcelIgnore; +import cn.idev.excel.annotation.ExcelIgnoreUnannotated; import cn.idev.excel.annotation.ExcelProperty; import cn.idev.excel.metadata.Head; import cn.idev.excel.write.handler.WorkbookWriteHandler; @@ -70,7 +72,16 @@ public class CellMergeStrategy extends AbstractMergeStrategy implements Workbook if (CollUtil.isEmpty(list)) { return cellList; } - Field[] fields = ReflectUtils.getFields(list.get(0).getClass(), field -> !"serialVersionUID".equals(field.getName())); + Class clazz = list.get(0).getClass(); + Field[] fields = ReflectUtils.getFields(clazz, field -> { + if ("serialVersionUID".equals(field.getName())) { + return false; + } + if (field.isAnnotationPresent(ExcelIgnore.class)) { + return false; + } + return !clazz.isAnnotationPresent(ExcelIgnoreUnannotated.class) || field.isAnnotationPresent(ExcelProperty.class); + }); // 有注解的字段 List mergeFields = new ArrayList<>(); @@ -91,9 +102,10 @@ public class CellMergeStrategy extends AbstractMergeStrategy implements Workbook Map map = new HashMap<>(); // 生成两两合并单元格 for (int i = 0; i < list.size(); i++) { + Object rowObj = list.get(i); for (int j = 0; j < mergeFields.size(); j++) { Field field = mergeFields.get(j); - Object val = ReflectUtils.invokeGetter(list.get(i), field.getName()); + Object val = ReflectUtils.invokeGetter(rowObj, field.getName()); int colNum = mergeFieldsIndex.get(j); if (!map.containsKey(field)) { From ba6015ca19e73d94416676b6f773b19218f7744d Mon Sep 17 00:00:00 2001 From: chengliejian <284067032@qq.com> Date: Thu, 7 Aug 2025 16:57:27 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=81=BF=E5=85=8D?= =?UTF-8?q?=E6=AF=8F=E4=B8=AA=E5=AD=97=E6=AE=B5=E9=83=BD=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?ExcelIgnoreUnannotated.class=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/dromara/common/excel/core/CellMergeStrategy.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ruoyi-common/ruoyi-common-excel/src/main/java/org/dromara/common/excel/core/CellMergeStrategy.java b/ruoyi-common/ruoyi-common-excel/src/main/java/org/dromara/common/excel/core/CellMergeStrategy.java index 39697e186..3e1ccfd67 100644 --- a/ruoyi-common/ruoyi-common-excel/src/main/java/org/dromara/common/excel/core/CellMergeStrategy.java +++ b/ruoyi-common/ruoyi-common-excel/src/main/java/org/dromara/common/excel/core/CellMergeStrategy.java @@ -73,6 +73,7 @@ public class CellMergeStrategy extends AbstractMergeStrategy implements Workbook return cellList; } Class clazz = list.get(0).getClass(); + boolean annotationPresent = clazz.isAnnotationPresent(ExcelIgnoreUnannotated.class); Field[] fields = ReflectUtils.getFields(clazz, field -> { if ("serialVersionUID".equals(field.getName())) { return false; @@ -80,7 +81,7 @@ public class CellMergeStrategy extends AbstractMergeStrategy implements Workbook if (field.isAnnotationPresent(ExcelIgnore.class)) { return false; } - return !clazz.isAnnotationPresent(ExcelIgnoreUnannotated.class) || field.isAnnotationPresent(ExcelProperty.class); + return !annotationPresent || field.isAnnotationPresent(ExcelProperty.class); }); // 有注解的字段