From 3e0d4a625feb6dc3a6ea69ef5668fa04fc4daf5d Mon Sep 17 00:00:00 2001 From: Jiaju Zhuang Date: Wed, 6 Apr 2022 17:47:55 +0800 Subject: [PATCH] =?UTF-8?q?*=20=E4=BF=AE=E5=A4=8D`filed`=E6=8B=BC=E6=8E=A5?= =?UTF-8?q?=E9=94=99=E8=AF=AF=20[Issue=20#2390](https://github.com/alibaba?= =?UTF-8?q?/easyexcel/issues/2390)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../property/ExcelContentProperty.java | 2 +- .../metadata/property/ExcelHeadProperty.java | 10 +- .../com/alibaba/excel/util/ClassUtils.java | 94 +++++++++---------- .../com/alibaba/excel/util/FieldUtils.java | 4 +- .../AbstractExcelWriterParameterBuilder.java | 27 +++++- .../write/executor/ExcelWriteAddExecutor.java | 34 +++---- .../ExcludeOrIncludeDataTest.java | 70 +++++++------- .../easyexcel/test/demo/write/WriteTest.java | 12 +-- .../easyexcel/test/temp/StyleTest.java | 10 +- update.md | 1 + 10 files changed, 142 insertions(+), 122 deletions(-) diff --git a/easyexcel-core/src/main/java/com/alibaba/excel/metadata/property/ExcelContentProperty.java b/easyexcel-core/src/main/java/com/alibaba/excel/metadata/property/ExcelContentProperty.java index f0b72198..0b3ad1a5 100644 --- a/easyexcel-core/src/main/java/com/alibaba/excel/metadata/property/ExcelContentProperty.java +++ b/easyexcel-core/src/main/java/com/alibaba/excel/metadata/property/ExcelContentProperty.java @@ -18,7 +18,7 @@ public class ExcelContentProperty { public static final ExcelContentProperty EMPTY = new ExcelContentProperty(); /** - * Java filed + * Java field */ private Field field; /** diff --git a/easyexcel-core/src/main/java/com/alibaba/excel/metadata/property/ExcelHeadProperty.java b/easyexcel-core/src/main/java/com/alibaba/excel/metadata/property/ExcelHeadProperty.java index f3a8474a..61240d31 100644 --- a/easyexcel-core/src/main/java/com/alibaba/excel/metadata/property/ExcelHeadProperty.java +++ b/easyexcel-core/src/main/java/com/alibaba/excel/metadata/property/ExcelHeadProperty.java @@ -109,8 +109,8 @@ public class ExcelHeadProperty { return; } // Declared fields - Map sortedAllFiledMap = MapUtils.newTreeMap(); - Map indexFiledMap = MapUtils.newTreeMap(); + Map sortedAllFieldMap = MapUtils.newTreeMap(); + Map indexFieldMap = MapUtils.newTreeMap(); boolean needIgnore = (holder instanceof AbstractWriteHolder) && ( !CollectionUtils.isEmpty(((AbstractWriteHolder)holder).getExcludeColumnFieldNames()) || !CollectionUtils @@ -118,10 +118,10 @@ public class ExcelHeadProperty { .isEmpty(((AbstractWriteHolder)holder).getIncludeColumnFieldNames()) || !CollectionUtils .isEmpty(((AbstractWriteHolder)holder).getIncludeColumnIndexes())); - ClassUtils.declaredFields(headClazz, sortedAllFiledMap, indexFiledMap, ignoreMap, needIgnore, holder); + ClassUtils.declaredFields(headClazz, sortedAllFieldMap, indexFieldMap, ignoreMap, needIgnore, holder); - for (Map.Entry entry : sortedAllFiledMap.entrySet()) { - initOneColumnProperty(entry.getKey(), entry.getValue(), indexFiledMap.containsKey(entry.getKey())); + for (Map.Entry entry : sortedAllFieldMap.entrySet()) { + initOneColumnProperty(entry.getKey(), entry.getValue(), indexFieldMap.containsKey(entry.getKey())); } headKind = HeadKindEnum.CLASS; } 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 96ed8421..a6d5b1f5 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 @@ -195,17 +195,17 @@ public class ClassUtils { } /** - * Parsing filed in the class + * Parsing field in the class * * @param clazz Need to parse the class - * @param sortedAllFiledMap Complete the map of sorts - * @param indexFiledMap Use the index to sort fields + * @param sortedAllFieldMap Complete the map of sorts + * @param indexFieldMap Use the index to sort fields * @param ignoreMap You want to ignore field map * @param needIgnore If you want to ignore fields need to ignore * @param holder holder */ - public static void declaredFields(Class clazz, Map sortedAllFiledMap, - Map indexFiledMap, Map ignoreMap, Boolean needIgnore, Holder holder) { + public static void declaredFields(Class clazz, Map sortedAllFieldMap, + Map indexFieldMap, Map ignoreMap, Boolean needIgnore, Holder holder) { FieldCache fieldCache = declaredFields(clazz); if (fieldCache == null) { return; @@ -213,20 +213,20 @@ public class ClassUtils { if (ignoreMap != null) { ignoreMap.putAll(fieldCache.getIgnoreMap()); } - Map tempIndexFieldMap = indexFiledMap; + Map tempIndexFieldMap = indexFieldMap; if (tempIndexFieldMap == null) { tempIndexFieldMap = MapUtils.newTreeMap(); } - tempIndexFieldMap.putAll(fieldCache.getIndexFiledMap()); + tempIndexFieldMap.putAll(fieldCache.getIndexFieldMap()); - Map originSortedAllFiledMap = fieldCache.getSortedAllFiledMap(); + Map originSortedAllFieldMap = fieldCache.getSortedAllFieldMap(); if (!needIgnore) { - sortedAllFiledMap.putAll(originSortedAllFiledMap); + sortedAllFieldMap.putAll(originSortedAllFieldMap); return; } int index = 0; - for (Map.Entry entry : originSortedAllFiledMap.entrySet()) { + for (Map.Entry entry : originSortedAllFieldMap.entrySet()) { Integer key = entry.getKey(); Field field = entry.getValue(); @@ -239,22 +239,22 @@ public class ClassUtils { } else { // Mandatory sorted fields if (tempIndexFieldMap.containsKey(key)) { - sortedAllFiledMap.put(key, field); + sortedAllFieldMap.put(key, field); } else { // Need to reorder automatically // Check whether the current key is already in use - while (sortedAllFiledMap.containsKey(index)) { + while (sortedAllFieldMap.containsKey(index)) { index++; } - sortedAllFiledMap.put(index++, field); + sortedAllFieldMap.put(index++, field); } } } } - public static void declaredFields(Class clazz, Map sortedAllFiledMap, Boolean needIgnore, + public static void declaredFields(Class clazz, Map sortedAllFieldMap, Boolean needIgnore, WriteHolder writeHolder) { - declaredFields(clazz, sortedAllFiledMap, null, null, needIgnore, writeHolder); + declaredFields(clazz, sortedAllFieldMap, null, null, needIgnore, writeHolder); } private static FieldCache declaredFields(Class clazz) { @@ -272,43 +272,43 @@ public class ClassUtils { tempClass = tempClass.getSuperclass(); } // Screening of field - Map> orderFiledMap = new TreeMap>(); - Map indexFiledMap = new TreeMap(); + Map> orderFieldMap = new TreeMap>(); + Map indexFieldMap = new TreeMap(); Map ignoreMap = new HashMap(16); ExcelIgnoreUnannotated excelIgnoreUnannotated = clazz.getAnnotation(ExcelIgnoreUnannotated.class); for (Field field : tempFieldList) { - declaredOneField(field, orderFiledMap, indexFiledMap, ignoreMap, excelIgnoreUnannotated); + declaredOneField(field, orderFieldMap, indexFieldMap, ignoreMap, excelIgnoreUnannotated); } - return new FieldCache(buildSortedAllFiledMap(orderFiledMap, indexFiledMap), indexFiledMap, ignoreMap); + return new FieldCache(buildSortedAllFieldMap(orderFieldMap, indexFieldMap), indexFieldMap, ignoreMap); }); } - private static Map buildSortedAllFiledMap(Map> orderFiledMap, - Map indexFiledMap) { + private static Map buildSortedAllFieldMap(Map> orderFieldMap, + Map indexFieldMap) { - Map sortedAllFiledMap = new HashMap( - (orderFiledMap.size() + indexFiledMap.size()) * 4 / 3 + 1); + Map sortedAllFieldMap = new HashMap( + (orderFieldMap.size() + indexFieldMap.size()) * 4 / 3 + 1); - Map tempIndexFiledMap = new HashMap(indexFiledMap); + Map tempIndexFieldMap = new HashMap(indexFieldMap); int index = 0; - for (List fieldList : orderFiledMap.values()) { + for (List fieldList : orderFieldMap.values()) { for (Field field : fieldList) { - while (tempIndexFiledMap.containsKey(index)) { - sortedAllFiledMap.put(index, tempIndexFiledMap.get(index)); - tempIndexFiledMap.remove(index); + while (tempIndexFieldMap.containsKey(index)) { + sortedAllFieldMap.put(index, tempIndexFieldMap.get(index)); + tempIndexFieldMap.remove(index); index++; } - sortedAllFiledMap.put(index, field); + sortedAllFieldMap.put(index, field); index++; } } - sortedAllFiledMap.putAll(tempIndexFiledMap); - return sortedAllFiledMap; + sortedAllFieldMap.putAll(tempIndexFieldMap); + return sortedAllFieldMap; } - private static void declaredOneField(Field field, Map> orderFiledMap, - Map indexFiledMap, Map ignoreMap, + private static void declaredOneField(Field field, Map> orderFieldMap, + Map indexFieldMap, Map ignoreMap, ExcelIgnoreUnannotated excelIgnoreUnannotated) { ExcelIgnore excelIgnore = field.getAnnotation(ExcelIgnore.class); @@ -330,11 +330,11 @@ public class ClassUtils { return; } if (excelProperty != null && excelProperty.index() >= 0) { - if (indexFiledMap.containsKey(excelProperty.index())) { - throw new ExcelCommonException("The index of '" + indexFiledMap.get(excelProperty.index()).getName() + if (indexFieldMap.containsKey(excelProperty.index())) { + throw new ExcelCommonException("The index of '" + indexFieldMap.get(excelProperty.index()).getName() + "' and '" + field.getName() + "' must be inconsistent"); } - indexFiledMap.put(excelProperty.index(), field); + indexFieldMap.put(excelProperty.index(), field); return; } @@ -342,29 +342,29 @@ public class ClassUtils { if (excelProperty != null) { order = excelProperty.order(); } - List orderFiledList = orderFiledMap.computeIfAbsent(order, key -> ListUtils.newArrayList()); - orderFiledList.add(field); + List orderFieldList = orderFieldMap.computeIfAbsent(order, key -> ListUtils.newArrayList()); + orderFieldList.add(field); } private static class FieldCache { - private final Map sortedAllFiledMap; - private final Map indexFiledMap; + private final Map sortedAllFieldMap; + private final Map indexFieldMap; private final Map ignoreMap; - public FieldCache(Map sortedAllFiledMap, Map indexFiledMap, + public FieldCache(Map sortedAllFieldMap, Map indexFieldMap, Map ignoreMap) { - this.sortedAllFiledMap = sortedAllFiledMap; - this.indexFiledMap = indexFiledMap; + this.sortedAllFieldMap = sortedAllFieldMap; + this.indexFieldMap = indexFieldMap; this.ignoreMap = ignoreMap; } - public Map getSortedAllFiledMap() { - return sortedAllFiledMap; + public Map getSortedAllFieldMap() { + return sortedAllFieldMap; } - public Map getIndexFiledMap() { - return indexFiledMap; + public Map getIndexFieldMap() { + return indexFieldMap; } public Map getIgnoreMap() { diff --git a/easyexcel-core/src/main/java/com/alibaba/excel/util/FieldUtils.java b/easyexcel-core/src/main/java/com/alibaba/excel/util/FieldUtils.java index 583bc6f3..42cc3e4a 100644 --- a/easyexcel-core/src/main/java/com/alibaba/excel/util/FieldUtils.java +++ b/easyexcel-core/src/main/java/com/alibaba/excel/util/FieldUtils.java @@ -30,9 +30,9 @@ public class FieldUtils { private static final int START_RESOLVE_FIELD_LENGTH = 2; - public static Class getFieldClass(Map dataMap, String filedName, Object value) { + public static Class getFieldClass(Map dataMap, String fieldName, Object value) { if (dataMap instanceof BeanMap) { - Class fieldClass = ((BeanMap)dataMap).getPropertyType(filedName); + Class fieldClass = ((BeanMap)dataMap).getPropertyType(fieldName); if (fieldClass != null) { return fieldClass; } diff --git a/easyexcel-core/src/main/java/com/alibaba/excel/write/builder/AbstractExcelWriterParameterBuilder.java b/easyexcel-core/src/main/java/com/alibaba/excel/write/builder/AbstractExcelWriterParameterBuilder.java index 751ae5cd..f8844a52 100644 --- a/easyexcel-core/src/main/java/com/alibaba/excel/write/builder/AbstractExcelWriterParameterBuilder.java +++ b/easyexcel-core/src/main/java/com/alibaba/excel/write/builder/AbstractExcelWriterParameterBuilder.java @@ -77,11 +77,21 @@ public abstract class AbstractExcelWriterParameterBuilder excludeColumnFieldNames) { + parameter().setExcludeColumnFieldNames(excludeColumnFieldNames); + return self(); + } + /** * Ignore the custom columns. */ - public T excludeColumnFiledNames(Collection excludeColumnFiledNames) { - parameter().setExcludeColumnFieldNames(excludeColumnFiledNames); + public T excludeColumnFieldNames(Collection excludeColumnFieldNames) { + parameter().setExcludeColumnFieldNames(excludeColumnFieldNames); return self(); } @@ -95,10 +105,19 @@ public abstract class AbstractExcelWriterParameterBuilder includeColumnFiledNames) { - parameter().setIncludeColumnFieldNames(includeColumnFiledNames); + public T includeColumnFiledNames(Collection includeColumnFieldNames) { + parameter().setIncludeColumnFieldNames(includeColumnFieldNames); return self(); } + /** + * Only output the custom columns. + */ + public T includeColumnFieldNames(Collection includeColumnFieldNames) { + parameter().setIncludeColumnFieldNames(includeColumnFieldNames); + return self(); + } } diff --git a/easyexcel-core/src/main/java/com/alibaba/excel/write/executor/ExcelWriteAddExecutor.java b/easyexcel-core/src/main/java/com/alibaba/excel/write/executor/ExcelWriteAddExecutor.java index 459f0a7a..46ab5b63 100644 --- a/easyexcel-core/src/main/java/com/alibaba/excel/write/executor/ExcelWriteAddExecutor.java +++ b/easyexcel-core/src/main/java/com/alibaba/excel/write/executor/ExcelWriteAddExecutor.java @@ -50,18 +50,18 @@ public class ExcelWriteAddExecutor extends AbstractExcelWriteExecutor { if (writeSheetHolder.isNew() && !writeSheetHolder.getExcelWriteHeadProperty().hasHead()) { newRowIndex += writeContext.currentWriteHolder().relativeHeadRowIndex(); } - // BeanMap is out of order, so use sortedAllFiledMap - Map sortedAllFiledMap = new TreeMap<>(); + // BeanMap is out of order, so use sortedAllFieldMap + Map sortedAllFieldMap = new TreeMap<>(); int relativeRowIndex = 0; for (Object oneRowData : data) { int lastRowIndex = relativeRowIndex + newRowIndex; - addOneRowOfDataToExcel(oneRowData, lastRowIndex, relativeRowIndex, sortedAllFiledMap); + addOneRowOfDataToExcel(oneRowData, lastRowIndex, relativeRowIndex, sortedAllFieldMap); relativeRowIndex++; } } private void addOneRowOfDataToExcel(Object oneRowData, int rowIndex, int relativeRowIndex, - Map sortedAllFiledMap) { + Map sortedAllFieldMap) { if (oneRowData == null) { return; } @@ -79,7 +79,7 @@ public class ExcelWriteAddExecutor extends AbstractExcelWriteExecutor { } else if (oneRowData instanceof Map) { addBasicTypeToExcel(new MapRowData((Map)oneRowData), row, rowIndex, relativeRowIndex); } else { - addJavaObjectToExcel(oneRowData, row, rowIndex, relativeRowIndex, sortedAllFiledMap); + addJavaObjectToExcel(oneRowData, row, rowIndex, relativeRowIndex, sortedAllFieldMap); } WriteHandlerUtils.afterRowDispose(rowWriteHandlerContext); @@ -139,7 +139,7 @@ public class ExcelWriteAddExecutor extends AbstractExcelWriteExecutor { } private void addJavaObjectToExcel(Object oneRowData, Row row, int rowIndex, int relativeRowIndex, - Map sortedAllFiledMap) { + Map sortedAllFieldMap) { WriteHolder currentWriteHolder = writeContext.currentWriteHolder(); BeanMap beanMap = BeanMapUtils.create(oneRowData); // Bean the contains of the Map Key method with poor performance,So to create a keySet here @@ -186,18 +186,18 @@ public class ExcelWriteAddExecutor extends AbstractExcelWriteExecutor { maxCellIndex++; Map ignoreMap = writeContext.currentWriteHolder().excelWriteHeadProperty().getIgnoreMap(); - initSortedAllFiledMapFieldList(oneRowData.getClass(), sortedAllFiledMap); - for (Map.Entry entry : sortedAllFiledMap.entrySet()) { + initSortedAllFieldMapFieldList(oneRowData.getClass(), sortedAllFieldMap); + for (Map.Entry entry : sortedAllFieldMap.entrySet()) { Field field = entry.getValue(); - String filedName = FieldUtils.resolveCglibFieldName(field); - boolean uselessData = !beanKeySet.contains(filedName) || beanMapHandledSet.contains(filedName) - || ignoreMap.containsKey(filedName); + String fieldName = FieldUtils.resolveCglibFieldName(field); + boolean uselessData = !beanKeySet.contains(fieldName) || beanMapHandledSet.contains(fieldName) + || ignoreMap.containsKey(fieldName); if (uselessData) { continue; } - Object value = beanMap.get(filedName); + Object value = beanMap.get(fieldName); ExcelContentProperty excelContentProperty = ClassUtils.declaredExcelContentProperty(beanMap, - currentWriteHolder.excelWriteHeadProperty().getHeadClazz(), filedName); + currentWriteHolder.excelWriteHeadProperty().getHeadClazz(), fieldName); CellWriteHandlerContext cellWriteHandlerContext = WriteHandlerUtils.createCellWriteHandlerContext( writeContext, row, rowIndex, null, maxCellIndex, relativeRowIndex, Boolean.FALSE, excelContentProperty); WriteHandlerUtils.beforeCellCreate(cellWriteHandlerContext); @@ -210,7 +210,7 @@ public class ExcelWriteAddExecutor extends AbstractExcelWriteExecutor { WriteHandlerUtils.afterCellCreate(cellWriteHandlerContext); cellWriteHandlerContext.setOriginalValue(value); - cellWriteHandlerContext.setOriginalFieldClass(FieldUtils.getFieldClass(beanMap, filedName, value)); + cellWriteHandlerContext.setOriginalFieldClass(FieldUtils.getFieldClass(beanMap, fieldName, value)); converterAndSet(cellWriteHandlerContext); WriteHandlerUtils.afterCellDispose(cellWriteHandlerContext); @@ -218,8 +218,8 @@ public class ExcelWriteAddExecutor extends AbstractExcelWriteExecutor { } } - private void initSortedAllFiledMapFieldList(Class clazz, Map sortedAllFiledMap) { - if (!sortedAllFiledMap.isEmpty()) { + private void initSortedAllFieldMapFieldList(Class clazz, Map sortedAllFieldMap) { + if (!sortedAllFieldMap.isEmpty()) { return; } @@ -229,7 +229,7 @@ public class ExcelWriteAddExecutor extends AbstractExcelWriteExecutor { .isEmpty(writeSheetHolder.getExcludeColumnIndexes()) || !CollectionUtils .isEmpty(writeSheetHolder.getIncludeColumnFieldNames()) || !CollectionUtils .isEmpty(writeSheetHolder.getIncludeColumnIndexes()); - ClassUtils.declaredFields(clazz, sortedAllFiledMap, needIgnore, writeSheetHolder); + ClassUtils.declaredFields(clazz, sortedAllFieldMap, needIgnore, writeSheetHolder); } } diff --git a/easyexcel-core/src/test/java/com/alibaba/easyexcel/test/core/excludeorinclude/ExcludeOrIncludeDataTest.java b/easyexcel-core/src/test/java/com/alibaba/easyexcel/test/core/excludeorinclude/ExcludeOrIncludeDataTest.java index 54d9d5a4..9bf69821 100644 --- a/easyexcel-core/src/test/java/com/alibaba/easyexcel/test/core/excludeorinclude/ExcludeOrIncludeDataTest.java +++ b/easyexcel-core/src/test/java/com/alibaba/easyexcel/test/core/excludeorinclude/ExcludeOrIncludeDataTest.java @@ -25,30 +25,30 @@ public class ExcludeOrIncludeDataTest { private static File excludeIndex07; private static File excludeIndex03; private static File excludeIndexCsv; - private static File excludeFiledName07; - private static File excludeFiledName03; - private static File excludeFiledNameCsv; + private static File excludeFieldName07; + private static File excludeFieldName03; + private static File excludeFieldNameCsv; private static File includeIndex07; private static File includeIndex03; private static File includeIndexCsv; - private static File includeFiledName07; - private static File includeFiledName03; - private static File includeFiledNameCsv; + private static File includeFieldName07; + private static File includeFieldName03; + private static File includeFieldNameCsv; @BeforeClass public static void init() { excludeIndex07 = TestFileUtil.createNewFile("excludeIndex.xlsx"); excludeIndex03 = TestFileUtil.createNewFile("excludeIndex.xls"); excludeIndexCsv = TestFileUtil.createNewFile("excludeIndex.csv"); - excludeFiledName07 = TestFileUtil.createNewFile("excludeFiledName.xlsx"); - excludeFiledName03 = TestFileUtil.createNewFile("excludeFiledName.xls"); - excludeFiledNameCsv = TestFileUtil.createNewFile("excludeFiledName.csv"); + excludeFieldName07 = TestFileUtil.createNewFile("excludeFieldName.xlsx"); + excludeFieldName03 = TestFileUtil.createNewFile("excludeFieldName.xls"); + excludeFieldNameCsv = TestFileUtil.createNewFile("excludeFieldName.csv"); includeIndex07 = TestFileUtil.createNewFile("includeIndex.xlsx"); includeIndex03 = TestFileUtil.createNewFile("includeIndex.xls"); includeIndexCsv = TestFileUtil.createNewFile("includeIndex.csv"); - includeFiledName07 = TestFileUtil.createNewFile("includeFiledName.xlsx"); - includeFiledName03 = TestFileUtil.createNewFile("includeFiledName.xls"); - includeFiledNameCsv = TestFileUtil.createNewFile("includeFiledName.csv"); + includeFieldName07 = TestFileUtil.createNewFile("includeFieldName.xlsx"); + includeFieldName03 = TestFileUtil.createNewFile("includeFieldName.xls"); + includeFieldNameCsv = TestFileUtil.createNewFile("includeFieldName.csv"); } @Test @@ -67,18 +67,18 @@ public class ExcludeOrIncludeDataTest { } @Test - public void t11ExcludeFiledName07() { - excludeFiledName(excludeFiledName07); + public void t11ExcludeFieldName07() { + excludeFieldName(excludeFieldName07); } @Test - public void t12ExcludeFiledName03() { - excludeFiledName(excludeFiledName03); + public void t12ExcludeFieldName03() { + excludeFieldName(excludeFieldName03); } @Test - public void t13ExcludeFiledNameCsv() { - excludeFiledName(excludeFiledNameCsv); + public void t13ExcludeFieldNameCsv() { + excludeFieldName(excludeFieldNameCsv); } @@ -98,18 +98,18 @@ public class ExcludeOrIncludeDataTest { } @Test - public void t31IncludeFiledName07() { - includeFiledName(includeFiledName07); + public void t31IncludeFieldName07() { + includeFieldName(includeFieldName07); } @Test - public void t32IncludeFiledName03() { - includeFiledName(includeFiledName03); + public void t32IncludeFieldName03() { + includeFieldName(includeFieldName03); } @Test - public void t33IncludeFiledNameCsv() { - includeFiledName(includeFiledNameCsv); + public void t33IncludeFieldNameCsv() { + includeFieldName(includeFieldNameCsv); } private void excludeIndex(File file) { @@ -127,12 +127,12 @@ public class ExcludeOrIncludeDataTest { } - private void excludeFiledName(File file) { - Set excludeColumnFiledNames = new HashSet(); - excludeColumnFiledNames.add("column1"); - excludeColumnFiledNames.add("column3"); - excludeColumnFiledNames.add("column4"); - EasyExcel.write(file, ExcludeOrIncludeData.class).excludeColumnFiledNames(excludeColumnFiledNames).sheet() + private void excludeFieldName(File file) { + Set excludeColumnFieldNames = new HashSet(); + excludeColumnFieldNames.add("column1"); + excludeColumnFieldNames.add("column3"); + excludeColumnFieldNames.add("column4"); + EasyExcel.write(file, ExcludeOrIncludeData.class).excludeColumnFieldNames(excludeColumnFieldNames).sheet() .doWrite(data()); List> dataMap = EasyExcel.read(file).sheet().doReadSync(); Assert.assertEquals(1, dataMap.size()); @@ -157,11 +157,11 @@ public class ExcludeOrIncludeDataTest { } - private void includeFiledName(File file) { - Set includeColumnFiledNames = new HashSet(); - includeColumnFiledNames.add("column2"); - includeColumnFiledNames.add("column3"); - EasyExcel.write(file, ExcludeOrIncludeData.class).includeColumnFiledNames(includeColumnFiledNames).sheet() + private void includeFieldName(File file) { + Set includeColumnFieldNames = new HashSet(); + includeColumnFieldNames.add("column2"); + includeColumnFieldNames.add("column3"); + EasyExcel.write(file, ExcludeOrIncludeData.class).includeColumnFieldNames(includeColumnFieldNames).sheet() .doWrite(data()); List> dataMap = EasyExcel.read(file).sheet().doReadSync(); Assert.assertEquals(1, dataMap.size()); diff --git a/easyexcel-core/src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java b/easyexcel-core/src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java index 40357ed9..41372f6a 100644 --- a/easyexcel-core/src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java +++ b/easyexcel-core/src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java @@ -119,18 +119,18 @@ public class WriteTest { // 这里需要注意 在使用ExcelProperty注解的使用,如果想不空列则需要加入order字段,而不是index,order会忽略空列,然后继续往后,而index,不会忽略空列,在第几列就是第几列。 // 根据用户传入字段 假设我们要忽略 date - Set excludeColumnFiledNames = new HashSet<>(); - excludeColumnFiledNames.add("date"); + Set excludeColumnFieldNames = new HashSet<>(); + excludeColumnFieldNames.add("date"); // 这里 需要指定写用哪个class去写,然后写到第一个sheet,名字为模板 然后文件流会自动关闭 - EasyExcel.write(fileName, DemoData.class).excludeColumnFiledNames(excludeColumnFiledNames).sheet("模板") + EasyExcel.write(fileName, DemoData.class).excludeColumnFieldNames(excludeColumnFieldNames).sheet("模板") .doWrite(data()); fileName = TestFileUtil.getPath() + "excludeOrIncludeWrite" + System.currentTimeMillis() + ".xlsx"; // 根据用户传入字段 假设我们只要导出 date - Set includeColumnFiledNames = new HashSet<>(); - includeColumnFiledNames.add("date"); + Set includeColumnFieldNames = new HashSet<>(); + includeColumnFieldNames.add("date"); // 这里 需要指定写用哪个class去写,然后写到第一个sheet,名字为模板 然后文件流会自动关闭 - EasyExcel.write(fileName, DemoData.class).includeColumnFiledNames(includeColumnFiledNames).sheet("模板") + EasyExcel.write(fileName, DemoData.class).includeColumnFieldNames(includeColumnFieldNames).sheet("模板") .doWrite(data()); } diff --git a/easyexcel-core/src/test/java/com/alibaba/easyexcel/test/temp/StyleTest.java b/easyexcel-core/src/test/java/com/alibaba/easyexcel/test/temp/StyleTest.java index ece50bd6..c3a6654a 100644 --- a/easyexcel-core/src/test/java/com/alibaba/easyexcel/test/temp/StyleTest.java +++ b/easyexcel-core/src/test/java/com/alibaba/easyexcel/test/temp/StyleTest.java @@ -164,18 +164,18 @@ public class StyleTest { public void testFormatter2() throws Exception { StyleData styleData = new StyleData(); Field field = styleData.getClass().getDeclaredField("byteValue"); - LOGGER.info("filed:{}", field.getType().getName()); + LOGGER.info("field:{}", field.getType().getName()); field = styleData.getClass().getDeclaredField("byteValue2"); - LOGGER.info("filed:{}", field.getType().getName()); + LOGGER.info("field:{}", field.getType().getName()); field = styleData.getClass().getDeclaredField("byteValue4"); - LOGGER.info("filed:{}", field.getType()); + LOGGER.info("field:{}", field.getType()); field = styleData.getClass().getDeclaredField("byteValue3"); - LOGGER.info("filed:{}", field.getType()); + LOGGER.info("field:{}", field.getType()); } @Test public void testFormatter3() throws Exception { - LOGGER.info("filed:{}", Byte.class == Byte.class); + LOGGER.info("field:{}", Byte.class == Byte.class); } private void isDate(Cell cell) { diff --git a/update.md b/update.md index 33bce517..f35a7651 100644 --- a/update.md +++ b/update.md @@ -3,6 +3,7 @@ * 在有样式没有数据的情况下也算空行 [Issue #2294](https://github.com/alibaba/easyexcel/issues/2294) * 修复无法根据文件流判断csv的bug [Issue #2297](https://github.com/alibaba/easyexcel/issues/2297) * 修复CSV不关闭流的bug [Issue #2309](https://github.com/alibaba/easyexcel/issues/2309) +* 修复`filed`拼接错误 [Issue #2390](https://github.com/alibaba/easyexcel/issues/2390) # 3.0.5