Browse Source

* 修复`filed`拼接错误 [Issue #2390](https://github.com/alibaba/easyexcel/issues/2390)

pull/2430/head
Jiaju Zhuang 3 years ago
parent
commit
3e0d4a625f
  1. 2
      easyexcel-core/src/main/java/com/alibaba/excel/metadata/property/ExcelContentProperty.java
  2. 10
      easyexcel-core/src/main/java/com/alibaba/excel/metadata/property/ExcelHeadProperty.java
  3. 94
      easyexcel-core/src/main/java/com/alibaba/excel/util/ClassUtils.java
  4. 4
      easyexcel-core/src/main/java/com/alibaba/excel/util/FieldUtils.java
  5. 27
      easyexcel-core/src/main/java/com/alibaba/excel/write/builder/AbstractExcelWriterParameterBuilder.java
  6. 34
      easyexcel-core/src/main/java/com/alibaba/excel/write/executor/ExcelWriteAddExecutor.java
  7. 70
      easyexcel-core/src/test/java/com/alibaba/easyexcel/test/core/excludeorinclude/ExcludeOrIncludeDataTest.java
  8. 12
      easyexcel-core/src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java
  9. 10
      easyexcel-core/src/test/java/com/alibaba/easyexcel/test/temp/StyleTest.java
  10. 1
      update.md

2
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;
/**

10
easyexcel-core/src/main/java/com/alibaba/excel/metadata/property/ExcelHeadProperty.java

@ -109,8 +109,8 @@ public class ExcelHeadProperty {
return;
}
// Declared fields
Map<Integer, Field> sortedAllFiledMap = MapUtils.newTreeMap();
Map<Integer, Field> indexFiledMap = MapUtils.newTreeMap();
Map<Integer, Field> sortedAllFieldMap = MapUtils.newTreeMap();
Map<Integer, Field> 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<Integer, Field> entry : sortedAllFiledMap.entrySet()) {
initOneColumnProperty(entry.getKey(), entry.getValue(), indexFiledMap.containsKey(entry.getKey()));
for (Map.Entry<Integer, Field> entry : sortedAllFieldMap.entrySet()) {
initOneColumnProperty(entry.getKey(), entry.getValue(), indexFieldMap.containsKey(entry.getKey()));
}
headKind = HeadKindEnum.CLASS;
}

94
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<Integer, Field> sortedAllFiledMap,
Map<Integer, Field> indexFiledMap, Map<String, Field> ignoreMap, Boolean needIgnore, Holder holder) {
public static void declaredFields(Class<?> clazz, Map<Integer, Field> sortedAllFieldMap,
Map<Integer, Field> indexFieldMap, Map<String, Field> 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<Integer, Field> tempIndexFieldMap = indexFiledMap;
Map<Integer, Field> tempIndexFieldMap = indexFieldMap;
if (tempIndexFieldMap == null) {
tempIndexFieldMap = MapUtils.newTreeMap();
}
tempIndexFieldMap.putAll(fieldCache.getIndexFiledMap());
tempIndexFieldMap.putAll(fieldCache.getIndexFieldMap());
Map<Integer, Field> originSortedAllFiledMap = fieldCache.getSortedAllFiledMap();
Map<Integer, Field> originSortedAllFieldMap = fieldCache.getSortedAllFieldMap();
if (!needIgnore) {
sortedAllFiledMap.putAll(originSortedAllFiledMap);
sortedAllFieldMap.putAll(originSortedAllFieldMap);
return;
}
int index = 0;
for (Map.Entry<Integer, Field> entry : originSortedAllFiledMap.entrySet()) {
for (Map.Entry<Integer, Field> 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<Integer, Field> sortedAllFiledMap, Boolean needIgnore,
public static void declaredFields(Class<?> clazz, Map<Integer, Field> 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<Integer, List<Field>> orderFiledMap = new TreeMap<Integer, List<Field>>();
Map<Integer, Field> indexFiledMap = new TreeMap<Integer, Field>();
Map<Integer, List<Field>> orderFieldMap = new TreeMap<Integer, List<Field>>();
Map<Integer, Field> indexFieldMap = new TreeMap<Integer, Field>();
Map<String, Field> ignoreMap = new HashMap<String, Field>(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<Integer, Field> buildSortedAllFiledMap(Map<Integer, List<Field>> orderFiledMap,
Map<Integer, Field> indexFiledMap) {
private static Map<Integer, Field> buildSortedAllFieldMap(Map<Integer, List<Field>> orderFieldMap,
Map<Integer, Field> indexFieldMap) {
Map<Integer, Field> sortedAllFiledMap = new HashMap<Integer, Field>(
(orderFiledMap.size() + indexFiledMap.size()) * 4 / 3 + 1);
Map<Integer, Field> sortedAllFieldMap = new HashMap<Integer, Field>(
(orderFieldMap.size() + indexFieldMap.size()) * 4 / 3 + 1);
Map<Integer, Field> tempIndexFiledMap = new HashMap<Integer, Field>(indexFiledMap);
Map<Integer, Field> tempIndexFieldMap = new HashMap<Integer, Field>(indexFieldMap);
int index = 0;
for (List<Field> fieldList : orderFiledMap.values()) {
for (List<Field> 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<Integer, List<Field>> orderFiledMap,
Map<Integer, Field> indexFiledMap, Map<String, Field> ignoreMap,
private static void declaredOneField(Field field, Map<Integer, List<Field>> orderFieldMap,
Map<Integer, Field> indexFieldMap, Map<String, Field> 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<Field> orderFiledList = orderFiledMap.computeIfAbsent(order, key -> ListUtils.newArrayList());
orderFiledList.add(field);
List<Field> orderFieldList = orderFieldMap.computeIfAbsent(order, key -> ListUtils.newArrayList());
orderFieldList.add(field);
}
private static class FieldCache {
private final Map<Integer, Field> sortedAllFiledMap;
private final Map<Integer, Field> indexFiledMap;
private final Map<Integer, Field> sortedAllFieldMap;
private final Map<Integer, Field> indexFieldMap;
private final Map<String, Field> ignoreMap;
public FieldCache(Map<Integer, Field> sortedAllFiledMap, Map<Integer, Field> indexFiledMap,
public FieldCache(Map<Integer, Field> sortedAllFieldMap, Map<Integer, Field> indexFieldMap,
Map<String, Field> ignoreMap) {
this.sortedAllFiledMap = sortedAllFiledMap;
this.indexFiledMap = indexFiledMap;
this.sortedAllFieldMap = sortedAllFieldMap;
this.indexFieldMap = indexFieldMap;
this.ignoreMap = ignoreMap;
}
public Map<Integer, Field> getSortedAllFiledMap() {
return sortedAllFiledMap;
public Map<Integer, Field> getSortedAllFieldMap() {
return sortedAllFieldMap;
}
public Map<Integer, Field> getIndexFiledMap() {
return indexFiledMap;
public Map<Integer, Field> getIndexFieldMap() {
return indexFieldMap;
}
public Map<String, Field> getIgnoreMap() {

4
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;
}

27
easyexcel-core/src/main/java/com/alibaba/excel/write/builder/AbstractExcelWriterParameterBuilder.java

@ -77,11 +77,21 @@ public abstract class AbstractExcelWriterParameterBuilder<T extends AbstractExce
return self();
}
/**
* Ignore the custom columns.
*
* @deprecated use {@link #excludeColumnFieldNames(Collection)}
*/
public T excludeColumnFiledNames(Collection<String> excludeColumnFieldNames) {
parameter().setExcludeColumnFieldNames(excludeColumnFieldNames);
return self();
}
/**
* Ignore the custom columns.
*/
public T excludeColumnFiledNames(Collection<String> excludeColumnFiledNames) {
parameter().setExcludeColumnFieldNames(excludeColumnFiledNames);
public T excludeColumnFieldNames(Collection<String> excludeColumnFieldNames) {
parameter().setExcludeColumnFieldNames(excludeColumnFieldNames);
return self();
}
@ -95,10 +105,19 @@ public abstract class AbstractExcelWriterParameterBuilder<T extends AbstractExce
/**
* Only output the custom columns.
*
* @deprecated use {@link #includeColumnFieldNames(Collection)}
*/
public T includeColumnFiledNames(Collection<String> includeColumnFiledNames) {
parameter().setIncludeColumnFieldNames(includeColumnFiledNames);
public T includeColumnFiledNames(Collection<String> includeColumnFieldNames) {
parameter().setIncludeColumnFieldNames(includeColumnFieldNames);
return self();
}
/**
* Only output the custom columns.
*/
public T includeColumnFieldNames(Collection<String> includeColumnFieldNames) {
parameter().setIncludeColumnFieldNames(includeColumnFieldNames);
return self();
}
}

34
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<Integer, Field> sortedAllFiledMap = new TreeMap<>();
// BeanMap is out of order, so use sortedAllFieldMap
Map<Integer, Field> 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<Integer, Field> sortedAllFiledMap) {
Map<Integer, Field> sortedAllFieldMap) {
if (oneRowData == null) {
return;
}
@ -79,7 +79,7 @@ public class ExcelWriteAddExecutor extends AbstractExcelWriteExecutor {
} else if (oneRowData instanceof Map) {
addBasicTypeToExcel(new MapRowData((Map<Integer, ?>)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<Integer, Field> sortedAllFiledMap) {
Map<Integer, Field> 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<String, Field> ignoreMap = writeContext.currentWriteHolder().excelWriteHeadProperty().getIgnoreMap();
initSortedAllFiledMapFieldList(oneRowData.getClass(), sortedAllFiledMap);
for (Map.Entry<Integer, Field> entry : sortedAllFiledMap.entrySet()) {
initSortedAllFieldMapFieldList(oneRowData.getClass(), sortedAllFieldMap);
for (Map.Entry<Integer, Field> 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<Integer, Field> sortedAllFiledMap) {
if (!sortedAllFiledMap.isEmpty()) {
private void initSortedAllFieldMapFieldList(Class<?> clazz, Map<Integer, Field> 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);
}
}

70
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<String> excludeColumnFiledNames = new HashSet<String>();
excludeColumnFiledNames.add("column1");
excludeColumnFiledNames.add("column3");
excludeColumnFiledNames.add("column4");
EasyExcel.write(file, ExcludeOrIncludeData.class).excludeColumnFiledNames(excludeColumnFiledNames).sheet()
private void excludeFieldName(File file) {
Set<String> excludeColumnFieldNames = new HashSet<String>();
excludeColumnFieldNames.add("column1");
excludeColumnFieldNames.add("column3");
excludeColumnFieldNames.add("column4");
EasyExcel.write(file, ExcludeOrIncludeData.class).excludeColumnFieldNames(excludeColumnFieldNames).sheet()
.doWrite(data());
List<Map<Integer, String>> dataMap = EasyExcel.read(file).sheet().doReadSync();
Assert.assertEquals(1, dataMap.size());
@ -157,11 +157,11 @@ public class ExcludeOrIncludeDataTest {
}
private void includeFiledName(File file) {
Set<String> includeColumnFiledNames = new HashSet<String>();
includeColumnFiledNames.add("column2");
includeColumnFiledNames.add("column3");
EasyExcel.write(file, ExcludeOrIncludeData.class).includeColumnFiledNames(includeColumnFiledNames).sheet()
private void includeFieldName(File file) {
Set<String> includeColumnFieldNames = new HashSet<String>();
includeColumnFieldNames.add("column2");
includeColumnFieldNames.add("column3");
EasyExcel.write(file, ExcludeOrIncludeData.class).includeColumnFieldNames(includeColumnFieldNames).sheet()
.doWrite(data());
List<Map<Integer, String>> dataMap = EasyExcel.read(file).sheet().doReadSync();
Assert.assertEquals(1, dataMap.size());

12
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<String> excludeColumnFiledNames = new HashSet<>();
excludeColumnFiledNames.add("date");
Set<String> 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<String> includeColumnFiledNames = new HashSet<>();
includeColumnFiledNames.add("date");
Set<String> 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());
}

10
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) {

1
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

Loading…
Cancel
Save