Commit 62e83eaef5e247777970ec971ce3fa2cc7e161f2
1 parent
4dca3260
Excel导出时,下拉选择列错位问题修改 #853
Showing
1 changed file
with
14 additions
and
9 deletions
yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/handler/SelectSheetWriteHandler.java
| ... | ... | @@ -3,6 +3,7 @@ package cn.iocoder.yudao.framework.excel.core.handler; |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.hutool.core.lang.Assert; |
| 5 | 5 | import cn.hutool.core.util.ObjectUtil; |
| 6 | +import cn.hutool.core.util.ReflectUtil; | |
| 6 | 7 | import cn.hutool.core.util.StrUtil; |
| 7 | 8 | import cn.hutool.extra.spring.SpringUtil; |
| 8 | 9 | import cn.hutool.poi.excel.ExcelUtil; |
| ... | ... | @@ -61,15 +62,18 @@ public class SelectSheetWriteHandler implements SheetWriteHandler { |
| 61 | 62 | int colIndex = 0; |
| 62 | 63 | boolean ignoreUnannotated = head.isAnnotationPresent(ExcelIgnoreUnannotated.class); |
| 63 | 64 | for (Field field : head.getDeclaredFields()) { |
| 64 | - // 忽略 static final 或 transient 的字段 | |
| 65 | - if(isStaticFinalOrTransient(field) ) { | |
| 65 | + // 关联 https://github.com/YunaiV/ruoyi-vue-pro/pull/853 | |
| 66 | + // 1.1 忽略 static final 或 transient 的字段 | |
| 67 | + if (isStaticFinalOrTransient(field) ) { | |
| 66 | 68 | continue; |
| 67 | 69 | } |
| 68 | - // 忽略的字段跳过 | |
| 69 | - if((ignoreUnannotated && !field.isAnnotationPresent(ExcelProperty.class)) | |
| 70 | - || field.isAnnotationPresent(ExcelIgnore.class)){ | |
| 70 | + // 1.2 忽略的字段跳过 | |
| 71 | + if ((ignoreUnannotated && !field.isAnnotationPresent(ExcelProperty.class)) | |
| 72 | + || field.isAnnotationPresent(ExcelIgnore.class)) { | |
| 71 | 73 | continue; |
| 72 | 74 | } |
| 75 | + | |
| 76 | + // 2. 核心:处理有 ExcelColumnSelect 注解的字段 | |
| 73 | 77 | if (field.isAnnotationPresent(ExcelColumnSelect.class)) { |
| 74 | 78 | ExcelProperty excelProperty = field.getAnnotation(ExcelProperty.class); |
| 75 | 79 | if (excelProperty != null && excelProperty.index() != -1) { |
| ... | ... | @@ -83,13 +87,14 @@ public class SelectSheetWriteHandler implements SheetWriteHandler { |
| 83 | 87 | |
| 84 | 88 | /** |
| 85 | 89 | * 判断字段是否是静态的、最终的、 transient 的 |
| 86 | - * EasyExcel 默认是忽略 static final 或 transient 的字段,所以需要判断 | |
| 90 | + * 原因:EasyExcel 默认是忽略 static final 或 transient 的字段,所以需要判断 | |
| 91 | + * | |
| 87 | 92 | * @param field 字段 |
| 88 | - * @return 是否是静态的、最终的、 transient 的 | |
| 93 | + * @return 是否是静态的、最终的、transient 的 | |
| 89 | 94 | */ |
| 90 | 95 | private boolean isStaticFinalOrTransient(Field field) { |
| 91 | - return (Modifier.isStatic(field.getModifiers()) && Modifier.isFinal(field.getModifiers())) | |
| 92 | - || Modifier.isTransient(field.getModifiers()); | |
| 96 | + return (Modifier.isStatic(field.getModifiers()) && Modifier.isFinal(field.getModifiers())) | |
| 97 | + || Modifier.isTransient(field.getModifiers()); | |
| 93 | 98 | } |
| 94 | 99 | |
| 95 | 100 | ... | ... |