diff --git a/README.md b/README.md index 90b10c07..3438bc5d 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -# 🔥作者最新开源项目[Chat2DB](https://github.com/alibaba/Chat2DB) -[Chat2DB](https://github.com/alibaba/Chat2DB) 智能数据库客户端,比Navicat、DataGrip更智能,体验更好,永久免费无需破解。 GitHub地址 [https://github.com/alibaba/Chat2DB](https://github.com/alibaba/Chat2DB) +# 🔥作者最新开源项目[Chat2DB](https://github.com/chat2db/Chat2DB) +[Chat2DB](https://github.com/chat2db/Chat2DB) 智能数据库客户端,数据报表工具,自然语言生成SQL,生成报表。 GitHub地址 [https://github.com/chat2db/chat2db](https://github.com/chat2db/Chat2DB) EasyExcel ====================== @@ -31,7 +31,7 @@ easyexcel重写了poi对07版Excel的解析,一个3M的excel用POI sax解析 com.alibaba easyexcel - 3.3.1 + 3.3.2 ``` @@ -88,28 +88,14 @@ easyexcel重写了poi对07版Excel的解析,一个3M的excel用POI sax解析 ## 也可以加入钉钉&QQ群来解决问题 -加入钉钉或QQ群,看完公告可以获得帮助 。 -比较推荐钉钉群,`QQ` 公司不让用,当然QQ群也会有热心网友帮忙解决。 -[QQ1群(已满): 662022184](https://jq.qq.com/?_wv=1027&k=1T21jJxh) -[QQ2群(已满): 1097936804](https://jq.qq.com/?_wv=1027&k=j5zEy6Xl) -[QQ3群(已满): 453928496](https://qm.qq.com/cgi-bin/qm/qr?k=e2ULsA5A0GldhV2CXJ8sIbAyu9I6qqs7&jump_from=webapi) -[QQ4群(已满): 496594404](https://qm.qq.com/cgi-bin/qm/qr?k=e_aVG1Q7gi0PJUBkbrUGAgbeO3kUEInK&jump_from=webapi) -[QQ5群(已满): 451925680](https://jq.qq.com/?_wv=1027&k=6VHhvxyf) -[QQ6群: 784741035](https://jq.qq.com/?_wv=1027&k=BbLBIo9P) -[钉钉1群(已满): 21960511](https://qr.dingtalk.com/action/joingroup?code=v1,k1,cchz6k12ci9B08NNqhNRFGXocNVHrZtW0kaOtTKg/Rk=&_dt_no_comment=1&origin=11) -[钉钉2群(已满): 32796397](https://qr.dingtalk.com/action/joingroup?code=v1,k1,jyU9GtEuNU5S0QTyklqYcYJ8qDZtUuTPMM7uPZTS8Hs=&_dt_no_comment=1&origin=11) -[钉钉3群(已满): 33797247](https://qr.dingtalk.com/action/joingroup?code=v1,k1,3UGlEScTGQaHpW2cIRo+gkxJ9EVZ5fz26M6nW3uFP30=&_dt_no_comment=1&origin=11) -[钉钉4群(已满): 33491624](https://qr.dingtalk.com/action/joingroup?code=v1,k1,V14Pb65Too70rQkEaJ9ohb6lZBZbtp6jIL/q9EWh9vA=&_dt_no_comment=1&origin=11) -[钉钉5群(已满): 32134498](https://h5.dingtalk.com/circle/healthCheckin.html?dtaction=os&corpId=dingb9fa1325d9dccc3ecac589edd02f1650&5233a=71a83&cbdbhh=qwertyuiop) -[钉钉6群(已满): 34707941](https://h5.dingtalk.com/circle/healthCheckin.html?dtaction=os&corpId=dingcf68008a1d443ac012d5427bdb061b7a&6ae36c3d-0c80-4=22398493-6c2a-4&cbdbhh=qwertyuiop) -[钉钉7群(已满): 35235427](https://h5.dingtalk.com/circle/healthCheckin.html?dtaction=os&corpId=ding532b9018c06c7fc8660273c4b78e6440&167fb=ed003&cbdbhh=qwertyuiop) -[钉钉8群(已满): 44752220](https://h5.dingtalk.com/circle/healthCheckin.html?dtaction=os&corpId=dingea96808beee421693fd4ba7542d6e5da&0380092a-fa46=a6a40905-7951&cbdbhh=qwertyuiop) -[钉钉9群(已满): 11045002277](https://h5.dingtalk.com/circle/healthCheckin.html?dtaction=os&corpId=dinge338d2215891c0459c13cd6b2cb108a6&6972d=b92f9&cbdbhh=qwertyuiop) -[钉钉10群: 27360019755](https://qr.dingtalk.com/action/joingroup?code=v1,k1,v25LHn2liWmrWUKlkhIzOTcK7s7onp/sZP8mO5oIYSs=&_dt_no_comment=1&origin=11) +关注微信公众号(Text2SQL)回复 "群" or "加群" 加入微信群、钉钉群、QQ群探讨问题 + + + # 维护者 -姬朋飞(玉霄)、庄家钜、怀宇 +姬朋飞(玉霄)、庄家钜、怀宇、敖丙 # 快速开始 diff --git a/easyexcel-core/src/main/java/com/alibaba/excel/util/ClassUtils.java b/easyexcel-core/src/main/java/com/alibaba/excel/util/ClassUtils.java index 92b828b4..f9a53e08 100644 --- a/easyexcel-core/src/main/java/com/alibaba/excel/util/ClassUtils.java +++ b/easyexcel-core/src/main/java/com/alibaba/excel/util/ClassUtils.java @@ -36,6 +36,7 @@ import com.alibaba.excel.metadata.property.StyleProperty; import com.alibaba.excel.write.metadata.holder.WriteHolder; import lombok.AllArgsConstructor; +import lombok.Data; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; @@ -49,7 +50,7 @@ import org.springframework.cglib.beans.BeanMap; * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * + *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -63,11 +64,11 @@ public class ClassUtils { /** * memory cache */ - public static final ConcurrentHashMap, FieldCache> FIELD_CACHE = new ConcurrentHashMap<>(); + public static final Map FIELD_CACHE = new ConcurrentHashMap<>(); /** - * thread local cahe + * thread local cache */ - private static final ThreadLocal, FieldCache>> FIELD_THREAD_LOCAL = new ThreadLocal<>(); + private static final ThreadLocal> FIELD_THREAD_LOCAL = new ThreadLocal<>(); /** * The cache configuration information for each of the class @@ -102,7 +103,8 @@ public class ClassUtils { * @return */ public static ExcelContentProperty declaredExcelContentProperty(Map dataMap, Class headClazz, - String fieldName, ConfigurationHolder configurationHolder) { + String fieldName, + ConfigurationHolder configurationHolder) { Class clazz = null; if (dataMap instanceof BeanMap) { Object bean = ((BeanMap)dataMap).getBean(); @@ -137,7 +139,8 @@ public class ClassUtils { } private static ExcelContentProperty doGetExcelContentProperty(Class clazz, Class headClass, - String fieldName, ConfigurationHolder configurationHolder) { + String fieldName, + ConfigurationHolder configurationHolder) { ExcelContentProperty excelContentProperty = Optional.ofNullable( declaredFieldContentMap(clazz, configurationHolder)) .map(map -> map.get(fieldName)) @@ -277,16 +280,16 @@ public class ClassUtils { public static FieldCache declaredFields(Class clazz, ConfigurationHolder configurationHolder) { switch (configurationHolder.globalConfiguration().getFiledCacheLocation()) { case THREAD_LOCAL: - Map, FieldCache> fieldCacheMap = FIELD_THREAD_LOCAL.get(); + Map fieldCacheMap = FIELD_THREAD_LOCAL.get(); if (fieldCacheMap == null) { fieldCacheMap = MapUtils.newHashMap(); FIELD_THREAD_LOCAL.set(fieldCacheMap); } - return fieldCacheMap.computeIfAbsent(clazz, key -> { + return fieldCacheMap.computeIfAbsent(new FieldCacheKey(clazz, configurationHolder), key -> { return doDeclaredFields(clazz, configurationHolder); }); case MEMORY: - return FIELD_CACHE.computeIfAbsent(clazz, key -> { + return FIELD_CACHE.computeIfAbsent(new FieldCacheKey(clazz, configurationHolder), key -> { return doDeclaredFields(clazz, configurationHolder); }); case NONE: @@ -333,7 +336,7 @@ public class ClassUtils { return fieldCache; } // ignore filed - Map tempSortedFieldMapp = MapUtils.newHashMap(); + Map tempSortedFieldMap = MapUtils.newHashMap(); int index = 0; for (Map.Entry entry : sortedFieldMap.entrySet()) { Integer key = entry.getKey(); @@ -346,18 +349,18 @@ public class ClassUtils { } else { // Mandatory sorted fields if (indexFieldMap.containsKey(key)) { - tempSortedFieldMapp.put(key, field); + tempSortedFieldMap.put(key, field); } else { // Need to reorder automatically // Check whether the current key is already in use - while (tempSortedFieldMapp.containsKey(index)) { + while (tempSortedFieldMap.containsKey(index)) { index++; } - tempSortedFieldMapp.put(index++, field); + tempSortedFieldMap.put(index++, field); } } } - fieldCache.setSortedFieldMap(tempSortedFieldMapp); + fieldCache.setSortedFieldMap(tempSortedFieldMap); // resort field resortField(writeHolder, fieldCache); @@ -406,8 +409,8 @@ public class ClassUtils { // Index sorted map Map filedIndexMap = MapUtils.newHashMap(); int fieldIndex = 0; - for (Integer includeColumnIndexe : includeColumnIndexes) { - filedIndexMap.put(includeColumnIndexe, fieldIndex++); + for (Integer includeColumnIndex : includeColumnIndexes) { + filedIndexMap.put(includeColumnIndex, fieldIndex++); } // rebuild sortedFieldMap @@ -551,6 +554,26 @@ public class ClassUtils { private String fieldName; } + @Data + public static class FieldCacheKey { + private Class clazz; + private Collection excludeColumnFieldNames; + private Collection excludeColumnIndexes; + private Collection includeColumnFieldNames; + private Collection includeColumnIndexes; + + FieldCacheKey(Class clazz, ConfigurationHolder configurationHolder) { + this.clazz = clazz; + if (configurationHolder instanceof WriteHolder) { + WriteHolder writeHolder = (WriteHolder)configurationHolder; + this.excludeColumnFieldNames = writeHolder.excludeColumnFieldNames(); + this.excludeColumnIndexes = writeHolder.excludeColumnIndexes(); + this.includeColumnFieldNames = writeHolder.includeColumnFieldNames(); + this.includeColumnIndexes = writeHolder.includeColumnIndexes(); + } + } + } + public static void removeThreadLocalCache() { FIELD_THREAD_LOCAL.remove(); CLASS_CONTENT_THREAD_LOCAL.remove(); diff --git a/easyexcel-test/pom.xml b/easyexcel-test/pom.xml index 840d3f61..3174f4f0 100644 --- a/easyexcel-test/pom.xml +++ b/easyexcel-test/pom.xml @@ -42,6 +42,11 @@ + + org.slf4j + slf4j-simple + 1.7.36 + org.slf4j jcl-over-slf4j diff --git a/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/excludeorinclude/ExcludeOrIncludeDataTest.java b/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/excludeorinclude/ExcludeOrIncludeDataTest.java index 31244e15..314b5de4 100644 --- a/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/excludeorinclude/ExcludeOrIncludeDataTest.java +++ b/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/excludeorinclude/ExcludeOrIncludeDataTest.java @@ -1,20 +1,11 @@ package com.alibaba.easyexcel.test.core.excludeorinclude; -import java.io.File; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - import com.alibaba.easyexcel.test.util.TestFileUtil; import com.alibaba.excel.EasyExcel; +import org.junit.jupiter.api.*; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.MethodOrderer; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.TestMethodOrder; +import java.io.File; +import java.util.*; /** * @author Jiaju Zhuang @@ -159,7 +150,7 @@ public class ExcludeOrIncludeDataTest { excludeColumnIndexes.add(0); excludeColumnIndexes.add(3); EasyExcel.write(file, ExcludeOrIncludeData.class).excludeColumnIndexes(excludeColumnIndexes).sheet() - .doWrite(data()); + .doWrite(data()); List> dataMap = EasyExcel.read(file).sheet().doReadSync(); Assertions.assertEquals(1, dataMap.size()); Map record = dataMap.get(0); @@ -175,7 +166,7 @@ public class ExcludeOrIncludeDataTest { excludeColumnFieldNames.add("column3"); excludeColumnFieldNames.add("column4"); EasyExcel.write(file, ExcludeOrIncludeData.class).excludeColumnFieldNames(excludeColumnFieldNames).sheet() - .doWrite(data()); + .doWrite(data()); List> dataMap = EasyExcel.read(file).sheet().doReadSync(); Assertions.assertEquals(1, dataMap.size()); Map record = dataMap.get(0); @@ -189,7 +180,7 @@ public class ExcludeOrIncludeDataTest { includeColumnIndexes.add(1); includeColumnIndexes.add(2); EasyExcel.write(file, ExcludeOrIncludeData.class).includeColumnIndexes(includeColumnIndexes).sheet() - .doWrite(data()); + .doWrite(data()); List> dataMap = EasyExcel.read(file).sheet().doReadSync(); Assertions.assertEquals(1, dataMap.size()); Map record = dataMap.get(0); @@ -203,8 +194,10 @@ public class ExcludeOrIncludeDataTest { Set includeColumnFieldNames = new HashSet(); includeColumnFieldNames.add("column2"); includeColumnFieldNames.add("column3"); - EasyExcel.write(file, ExcludeOrIncludeData.class).includeColumnFieldNames(includeColumnFieldNames).sheet() - .doWrite(data()); + EasyExcel.write(file, ExcludeOrIncludeData.class) + .sheet() + .includeColumnFieldNames(includeColumnFieldNames) + .doWrite(data()); List> dataMap = EasyExcel.read(file).sheet().doReadSync(); Assertions.assertEquals(1, dataMap.size()); Map record = dataMap.get(0); @@ -220,10 +213,10 @@ public class ExcludeOrIncludeDataTest { includeColumnIndexes.add(2); includeColumnIndexes.add(0); EasyExcel.write(file, ExcludeOrIncludeData.class) - .includeColumnIndexes(includeColumnIndexes) - .orderByIncludeColumn(true). - sheet() - .doWrite(data()); + .includeColumnIndexes(includeColumnIndexes) + .orderByIncludeColumn(true). + sheet() + .doWrite(data()); List> dataMap = EasyExcel.read(file).sheet().doReadSync(); Assertions.assertEquals(1, dataMap.size()); Map record = dataMap.get(0); @@ -240,10 +233,10 @@ public class ExcludeOrIncludeDataTest { includeColumnFieldNames.add("column2"); includeColumnFieldNames.add("column3"); EasyExcel.write(file, ExcludeOrIncludeData.class) - .includeColumnFieldNames(includeColumnFieldNames) - .orderByIncludeColumn(true). - sheet() - .doWrite(data()); + .includeColumnFieldNames(includeColumnFieldNames) + .orderByIncludeColumn(true). + sheet() + .doWrite(data()); List> dataMap = EasyExcel.read(file).sheet().doReadSync(); Assertions.assertEquals(1, dataMap.size()); Map record = dataMap.get(0); diff --git a/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java b/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java index cd120e22..0e7cf2db 100644 --- a/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java +++ b/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java @@ -4,11 +4,13 @@ import java.io.File; import java.io.InputStream; import java.net.URL; import java.util.ArrayList; +import java.util.Arrays; import java.util.Date; import java.util.HashSet; import java.util.List; import java.util.Set; +import com.alibaba.easyexcel.test.core.head.ComplexHeadData; import com.alibaba.easyexcel.test.util.TestFileUtil; import com.alibaba.excel.EasyExcel; import com.alibaba.excel.ExcelWriter; @@ -409,7 +411,7 @@ public class WriteTest { /** * 列宽、行高 *

- * 1. 创建excel对应的实体对象 参照{@link WidthAndHeightData} + * 1. 创建excel对应的实体对象 参照{@link WidthAndHeightData } *

* 2. 使用注解{@link ColumnWidth}、{@link HeadRowHeight}、{@link ContentRowHeight}指定宽度或高度 *

diff --git a/pom.xml b/pom.xml index 926c91bd..9ed5cafb 100644 --- a/pom.xml +++ b/pom.xml @@ -20,7 +20,7 @@ - 3.3.1 + 3.3.2 UTF-8 1.8 true diff --git a/update.md b/update.md index 3b0b4e95..c448d238 100644 --- a/update.md +++ b/update.md @@ -1,3 +1,7 @@ +# 3.3.2 + +* 修复`includeColumnIndexes`和`includeColumnFieldNames`在sheet后面失效的问题 + # 3.3.1 * 修改版本发布问题