From 153d4c6e2047b013e12b2cbb57e321d2817a7960 Mon Sep 17 00:00:00 2001 From: Jiaju Zhuang Date: Wed, 15 Sep 2021 16:14:15 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E5=BC=83=E7=94=A8=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../excel/context/WriteContextImpl.java | 2 +- .../metadata/property/ExcelHeadProperty.java | 29 ++-- .../listener/ModelBuildEventListener.java | 55 ++----- .../excel/read/metadata/ReadWorkbook.java | 140 +----------------- .../metadata/holder/AbstractReadHolder.java | 5 +- .../read/metadata/holder/ReadSheetHolder.java | 2 +- .../metadata/holder/ReadWorkbookHolder.java | 22 +-- .../property/ExcelReadHeadProperty.java | 4 +- .../com/alibaba/excel/util/ClassUtils.java | 27 ++-- .../write/builder/ExcelWriterBuilder.java | 15 -- .../write/executor/ExcelWriteAddExecutor.java | 3 +- .../excel/write/metadata/WriteWorkbook.java | 11 -- .../metadata/holder/AbstractWriteHolder.java | 6 +- .../metadata/holder/WriteSheetHolder.java | 2 +- .../metadata/holder/WriteTableHolder.java | 32 +--- .../metadata/holder/WriteWorkbookHolder.java | 2 +- .../property/ExcelWriteHeadProperty.java | 24 ++- 17 files changed, 72 insertions(+), 309 deletions(-) diff --git a/src/main/java/com/alibaba/excel/context/WriteContextImpl.java b/src/main/java/com/alibaba/excel/context/WriteContextImpl.java index 5766b4b3..8e50eb74 100644 --- a/src/main/java/com/alibaba/excel/context/WriteContextImpl.java +++ b/src/main/java/com/alibaba/excel/context/WriteContextImpl.java @@ -291,7 +291,7 @@ public class WriteContextImpl implements WriteContext { } private void initCurrentTableHolder(WriteTable writeTable) { - writeTableHolder = new WriteTableHolder(writeTable, writeSheetHolder, writeWorkbookHolder); + writeTableHolder = new WriteTableHolder(writeTable, writeSheetHolder); writeSheetHolder.getHasBeenInitializedTable().put(writeTable.getTableNo(), writeTableHolder); currentWriteHolder = writeTableHolder; if (LOGGER.isDebugEnabled()) { diff --git a/src/main/java/com/alibaba/excel/metadata/property/ExcelHeadProperty.java b/src/main/java/com/alibaba/excel/metadata/property/ExcelHeadProperty.java index 34c9d4d0..4b52e213 100644 --- a/src/main/java/com/alibaba/excel/metadata/property/ExcelHeadProperty.java +++ b/src/main/java/com/alibaba/excel/metadata/property/ExcelHeadProperty.java @@ -3,7 +3,6 @@ package com.alibaba.excel.metadata.property; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Collections; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.TreeMap; @@ -18,6 +17,7 @@ import com.alibaba.excel.exception.ExcelCommonException; import com.alibaba.excel.metadata.Head; import com.alibaba.excel.metadata.Holder; import com.alibaba.excel.util.ClassUtils; +import com.alibaba.excel.util.MapUtils; import com.alibaba.excel.util.StringUtils; import com.alibaba.excel.write.metadata.holder.AbstractWriteHolder; @@ -64,19 +64,19 @@ public class ExcelHeadProperty { */ private Map ignoreMap; - public ExcelHeadProperty(Holder holder, Class headClazz, List> head, Boolean convertAllFiled) { + public ExcelHeadProperty(Holder holder, Class headClazz, List> head) { this.headClazz = headClazz; - headMap = new TreeMap(); - contentPropertyMap = new TreeMap(); - fieldNameContentPropertyMap = new HashMap(); - ignoreMap = new HashMap(16); + headMap = new TreeMap<>(); + contentPropertyMap = new TreeMap<>(); + fieldNameContentPropertyMap = MapUtils.newHashMap(); + ignoreMap = MapUtils.newHashMap(); headKind = HeadKindEnum.NONE; headRowNumber = 0; if (head != null && !head.isEmpty()) { int headIndex = 0; for (int i = 0; i < head.size(); i++) { if (holder instanceof AbstractWriteHolder) { - if (((AbstractWriteHolder) holder).ignore(null, i)) { + if (((AbstractWriteHolder)holder).ignore(null, i)) { continue; } } @@ -87,7 +87,7 @@ public class ExcelHeadProperty { headKind = HeadKindEnum.STRING; } // convert headClazz to head - initColumnProperties(holder, convertAllFiled); + initColumnProperties(holder); initHeadRowNumber(); if (LOGGER.isDebugEnabled()) { @@ -115,7 +115,7 @@ public class ExcelHeadProperty { } } - private void initColumnProperties(Holder holder, Boolean convertAllFiled) { + private void initColumnProperties(Holder holder) { if (headClazz == null) { return; } @@ -124,12 +124,11 @@ public class ExcelHeadProperty { Map indexFiledMap = new TreeMap(); boolean needIgnore = (holder instanceof AbstractWriteHolder) && ( - !CollectionUtils.isEmpty(((AbstractWriteHolder) holder).getExcludeColumnFieldNames()) || !CollectionUtils - .isEmpty(((AbstractWriteHolder) holder).getExcludeColumnIndexes()) || !CollectionUtils - .isEmpty(((AbstractWriteHolder) holder).getIncludeColumnFieldNames()) || !CollectionUtils - .isEmpty(((AbstractWriteHolder) holder).getIncludeColumnIndexes())); - ClassUtils.declaredFields(headClazz, sortedAllFiledMap, indexFiledMap, ignoreMap, convertAllFiled, needIgnore, - holder); + !CollectionUtils.isEmpty(((AbstractWriteHolder)holder).getExcludeColumnFieldNames()) || !CollectionUtils + .isEmpty(((AbstractWriteHolder)holder).getExcludeColumnIndexes()) || !CollectionUtils + .isEmpty(((AbstractWriteHolder)holder).getIncludeColumnFieldNames()) || !CollectionUtils + .isEmpty(((AbstractWriteHolder)holder).getIncludeColumnIndexes())); + ClassUtils.declaredFields(headClazz, sortedAllFiledMap, indexFiledMap, ignoreMap, needIgnore, holder); for (Map.Entry entry : sortedAllFiledMap.entrySet()) { initOneColumnProperty(entry.getKey(), entry.getValue(), indexFiledMap.containsKey(entry.getKey())); diff --git a/src/main/java/com/alibaba/excel/read/listener/ModelBuildEventListener.java b/src/main/java/com/alibaba/excel/read/listener/ModelBuildEventListener.java index bba3e487..508a8a4b 100644 --- a/src/main/java/com/alibaba/excel/read/listener/ModelBuildEventListener.java +++ b/src/main/java/com/alibaba/excel/read/listener/ModelBuildEventListener.java @@ -1,7 +1,5 @@ package com.alibaba.excel.read.listener; -import java.util.ArrayList; -import java.util.List; import java.util.Map; import com.alibaba.excel.context.AnalysisContext; @@ -42,48 +40,25 @@ public class ModelBuildEventListener implements ReadListener> cellDataMap, ReadSheetHolder readSheetHolder, AnalysisContext context) { int index = 0; - if (context.readWorkbookHolder().getDefaultReturnMap()) { - Map map = MapUtils.newLinkedHashMapWithExpectedSize(cellDataMap.size()); - for (Map.Entry> entry : cellDataMap.entrySet()) { - Integer key = entry.getKey(); - ReadCellData cellData = entry.getValue(); - while (index < key) { - map.put(index, null); - index++; - } - index++; - map.put(key, - (String)ConverterUtils.convertToJavaObject(cellData, null, null, readSheetHolder.converterMap(), - context, context.readRowHolder().getRowIndex(), key)); - } - int headSize = readSheetHolder.excelReadHeadProperty().getHeadMap().size(); - while (index < headSize) { + Map map = MapUtils.newLinkedHashMapWithExpectedSize(cellDataMap.size()); + for (Map.Entry> entry : cellDataMap.entrySet()) { + Integer key = entry.getKey(); + ReadCellData cellData = entry.getValue(); + while (index < key) { map.put(index, null); index++; } - return map; - } else { - // Compatible with the old code the old code returns a list - List list = new ArrayList<>(); - for (Map.Entry> entry : cellDataMap.entrySet()) { - Integer key = entry.getKey(); - ReadCellData cellData = entry.getValue(); - while (index < key) { - list.add(null); - index++; - } - index++; - list.add( - (String)ConverterUtils.convertToJavaObject(cellData, null, null, readSheetHolder.converterMap(), - context, context.readRowHolder().getRowIndex(), key)); - } - int headSize = readSheetHolder.excelReadHeadProperty().getHeadMap().size(); - while (index < headSize) { - list.add(null); - index++; - } - return list; + index++; + map.put(key, + (String)ConverterUtils.convertToJavaObject(cellData, null, null, readSheetHolder.converterMap(), + context, context.readRowHolder().getRowIndex(), key)); + } + int headSize = readSheetHolder.excelReadHeadProperty().getHeadMap().size(); + while (index < headSize) { + map.put(index, null); + index++; } + return map; } private Object buildUserModel(Map> cellDataMap, ReadSheetHolder readSheetHolder, diff --git a/src/main/java/com/alibaba/excel/read/metadata/ReadWorkbook.java b/src/main/java/com/alibaba/excel/read/metadata/ReadWorkbook.java index c9e4db93..6db9be9f 100644 --- a/src/main/java/com/alibaba/excel/read/metadata/ReadWorkbook.java +++ b/src/main/java/com/alibaba/excel/read/metadata/ReadWorkbook.java @@ -14,11 +14,14 @@ import com.alibaba.excel.event.AnalysisEventListener; import com.alibaba.excel.read.listener.ModelBuildEventListener; import com.alibaba.excel.support.ExcelTypeEnum; +import lombok.Data; + /** * Workbook * * @author Jiaju Zhuang **/ +@Data public class ReadWorkbook extends ReadBasicParameter { /** * Excel type @@ -91,141 +94,4 @@ public class ReadWorkbook extends ReadBasicParameter { * @see CellExtraTypeEnum */ private Set extraReadSet; - /** - * The default is all excel objects.Default is true. - *

- * if true , you can use {@link com.alibaba.excel.annotation.ExcelIgnore} ignore a field. - *

- * if false , you must use {@link com.alibaba.excel.annotation.ExcelProperty} to use a filed. - * - * @deprecated Just to be compatible with historical data, The default is always going to be convert all filed. - */ - @Deprecated - private Boolean convertAllFiled; - - /** - * List is returned by default, now map is returned by default - */ - @Deprecated - private Boolean defaultReturnMap; - - public ExcelTypeEnum getExcelType() { - return excelType; - } - - public void setExcelType(ExcelTypeEnum excelType) { - this.excelType = excelType; - } - - public InputStream getInputStream() { - return inputStream; - } - - public void setInputStream(InputStream inputStream) { - this.inputStream = inputStream; - } - - public File getFile() { - return file; - } - - public void setFile(File file) { - this.file = file; - } - - public Boolean getAutoCloseStream() { - return autoCloseStream; - } - - public void setAutoCloseStream(Boolean autoCloseStream) { - this.autoCloseStream = autoCloseStream; - } - - public Object getCustomObject() { - return customObject; - } - - public void setCustomObject(Object customObject) { - this.customObject = customObject; - } - - public Boolean getMandatoryUseInputStream() { - return mandatoryUseInputStream; - } - - public void setMandatoryUseInputStream(Boolean mandatoryUseInputStream) { - this.mandatoryUseInputStream = mandatoryUseInputStream; - } - - public ReadCache getReadCache() { - return readCache; - } - - public void setReadCache(ReadCache readCache) { - this.readCache = readCache; - } - - public Boolean getConvertAllFiled() { - return convertAllFiled; - } - - public void setConvertAllFiled(Boolean convertAllFiled) { - this.convertAllFiled = convertAllFiled; - } - - public Boolean getDefaultReturnMap() { - return defaultReturnMap; - } - - public void setDefaultReturnMap(Boolean defaultReturnMap) { - this.defaultReturnMap = defaultReturnMap; - } - - public Boolean getIgnoreEmptyRow() { - return ignoreEmptyRow; - } - - public void setIgnoreEmptyRow(Boolean ignoreEmptyRow) { - this.ignoreEmptyRow = ignoreEmptyRow; - } - - public ReadCacheSelector getReadCacheSelector() { - return readCacheSelector; - } - - public void setReadCacheSelector(ReadCacheSelector readCacheSelector) { - this.readCacheSelector = readCacheSelector; - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } - - public String getXlsxSAXParserFactoryName() { - return xlsxSAXParserFactoryName; - } - - public void setXlsxSAXParserFactoryName(String xlsxSAXParserFactoryName) { - this.xlsxSAXParserFactoryName = xlsxSAXParserFactoryName; - } - - public Boolean getUseDefaultListener() { - return useDefaultListener; - } - - public void setUseDefaultListener(Boolean useDefaultListener) { - this.useDefaultListener = useDefaultListener; - } - - public Set getExtraReadSet() { - return extraReadSet; - } - - public void setExtraReadSet(Set extraReadSet) { - this.extraReadSet = extraReadSet; - } } diff --git a/src/main/java/com/alibaba/excel/read/metadata/holder/AbstractReadHolder.java b/src/main/java/com/alibaba/excel/read/metadata/holder/AbstractReadHolder.java index 1b313939..6561d377 100644 --- a/src/main/java/com/alibaba/excel/read/metadata/holder/AbstractReadHolder.java +++ b/src/main/java/com/alibaba/excel/read/metadata/holder/AbstractReadHolder.java @@ -46,8 +46,7 @@ public abstract class AbstractReadHolder extends AbstractHolder implements ReadH */ private List> readListenerList; - public AbstractReadHolder(ReadBasicParameter readBasicParameter, AbstractReadHolder parentAbstractReadHolder, - Boolean convertAllFiled) { + public AbstractReadHolder(ReadBasicParameter readBasicParameter, AbstractReadHolder parentAbstractReadHolder) { super(readBasicParameter, parentAbstractReadHolder); if (readBasicParameter.getUseScientificFormat() == null) { @@ -60,7 +59,7 @@ public abstract class AbstractReadHolder extends AbstractHolder implements ReadH } // Initialization property - this.excelReadHeadProperty = new ExcelReadHeadProperty(this, getClazz(), getHead(), convertAllFiled); + this.excelReadHeadProperty = new ExcelReadHeadProperty(this, getClazz(), getHead()); if (readBasicParameter.getHeadRowNumber() == null) { if (parentAbstractReadHolder == null) { if (excelReadHeadProperty.hasHead()) { diff --git a/src/main/java/com/alibaba/excel/read/metadata/holder/ReadSheetHolder.java b/src/main/java/com/alibaba/excel/read/metadata/holder/ReadSheetHolder.java index 73b00e71..12eb5dc4 100644 --- a/src/main/java/com/alibaba/excel/read/metadata/holder/ReadSheetHolder.java +++ b/src/main/java/com/alibaba/excel/read/metadata/holder/ReadSheetHolder.java @@ -59,7 +59,7 @@ public class ReadSheetHolder extends AbstractReadHolder { private ReadCellData tempCellData; public ReadSheetHolder(ReadSheet readSheet, ReadWorkbookHolder readWorkbookHolder) { - super(readSheet, readWorkbookHolder, readWorkbookHolder.getReadWorkbook().getConvertAllFiled()); + super(readSheet, readWorkbookHolder); this.readSheet = readSheet; this.parentReadWorkbookHolder = readWorkbookHolder; this.sheetNo = readSheet.getSheetNo(); diff --git a/src/main/java/com/alibaba/excel/read/metadata/holder/ReadWorkbookHolder.java b/src/main/java/com/alibaba/excel/read/metadata/holder/ReadWorkbookHolder.java index 6693467f..36577471 100644 --- a/src/main/java/com/alibaba/excel/read/metadata/holder/ReadWorkbookHolder.java +++ b/src/main/java/com/alibaba/excel/read/metadata/holder/ReadWorkbookHolder.java @@ -106,28 +106,13 @@ public class ReadWorkbookHolder extends AbstractReadHolder { */ private Boolean readAll; - /** - * The default is all excel objects.if true , you can use {@link com.alibaba.excel.annotation.ExcelIgnore} ignore a - * field. if false , you must use {@link com.alibaba.excel.annotation.ExcelProperty} to use a filed. - * - * @deprecated Just to be compatible with historical data, The default is always going to be convert all filed. - */ - @Deprecated - private Boolean convertAllFiled; - - /** - * List is returned by default, now map is returned by default - */ - @Deprecated - private Boolean defaultReturnMap; - /** * Prevent repeating sheet */ private Set hasReadSheet; public ReadWorkbookHolder(ReadWorkbook readWorkbook) { - super(readWorkbook, null, readWorkbook.getConvertAllFiled()); + super(readWorkbook, null); this.readWorkbook = readWorkbook; if (readWorkbook.getInputStream() != null) { this.inputStream = readWorkbook.getInputStream(); @@ -162,11 +147,6 @@ public class ReadWorkbookHolder extends AbstractReadHolder { this.readCacheSelector = readWorkbook.getReadCacheSelector(); } } - if (readWorkbook.getDefaultReturnMap() == null) { - this.defaultReturnMap = Boolean.TRUE; - } else { - this.defaultReturnMap = readWorkbook.getDefaultReturnMap(); - } if (readWorkbook.getExtraReadSet() == null) { this.extraReadSet = new HashSet(); } else { diff --git a/src/main/java/com/alibaba/excel/read/metadata/property/ExcelReadHeadProperty.java b/src/main/java/com/alibaba/excel/read/metadata/property/ExcelReadHeadProperty.java index 1b7ae17c..9c332ceb 100644 --- a/src/main/java/com/alibaba/excel/read/metadata/property/ExcelReadHeadProperty.java +++ b/src/main/java/com/alibaba/excel/read/metadata/property/ExcelReadHeadProperty.java @@ -12,7 +12,7 @@ import com.alibaba.excel.metadata.property.ExcelHeadProperty; */ public class ExcelReadHeadProperty extends ExcelHeadProperty { - public ExcelReadHeadProperty(Holder holder, Class headClazz, List> head, Boolean convertAllFiled) { - super(holder, headClazz, head, convertAllFiled); + public ExcelReadHeadProperty(Holder holder, Class headClazz, List> head) { + super(holder, headClazz, head); } } diff --git a/src/main/java/com/alibaba/excel/util/ClassUtils.java b/src/main/java/com/alibaba/excel/util/ClassUtils.java index 96cc11f8..4f14ac2c 100644 --- a/src/main/java/com/alibaba/excel/util/ClassUtils.java +++ b/src/main/java/com/alibaba/excel/util/ClassUtils.java @@ -30,9 +30,8 @@ public class ClassUtils { public static final Map, SoftReference> FIELD_CACHE = new ConcurrentHashMap<>(); public static void declaredFields(Class clazz, Map sortedAllFiledMap, - Map indexFiledMap, Map ignoreMap, Boolean convertAllFiled, - Boolean needIgnore, Holder holder) { - FieldCache fieldCache = getFieldCache(clazz, convertAllFiled); + Map indexFiledMap, Map ignoreMap, Boolean needIgnore, Holder holder) { + FieldCache fieldCache = getFieldCache(clazz); if (fieldCache == null) { return; } @@ -68,12 +67,12 @@ public class ClassUtils { } } - public static void declaredFields(Class clazz, Map sortedAllFiledMap, Boolean convertAllFiled, - Boolean needIgnore, WriteHolder writeHolder) { - declaredFields(clazz, sortedAllFiledMap, null, null, convertAllFiled, needIgnore, writeHolder); + public static void declaredFields(Class clazz, Map sortedAllFiledMap, Boolean needIgnore, + WriteHolder writeHolder) { + declaredFields(clazz, sortedAllFiledMap, null, null, needIgnore, writeHolder); } - private static FieldCache getFieldCache(Class clazz, Boolean convertAllFiled) { + private static FieldCache getFieldCache(Class clazz) { if (clazz == null) { return null; } @@ -86,12 +85,12 @@ public class ClassUtils { if (fieldCacheSoftReference != null && fieldCacheSoftReference.get() != null) { return fieldCacheSoftReference.get(); } - declaredFields(clazz, convertAllFiled); + declaredFields(clazz); } return FIELD_CACHE.get(clazz).get(); } - private static void declaredFields(Class clazz, Boolean convertAllFiled) { + private static void declaredFields(Class clazz) { List tempFieldList = new ArrayList<>(); Class tempClass = clazz; // When the parent class is null, it indicates that the parent class (Object class) has reached the top @@ -108,7 +107,7 @@ public class ClassUtils { ExcelIgnoreUnannotated excelIgnoreUnannotated = clazz.getAnnotation(ExcelIgnoreUnannotated.class); for (Field field : tempFieldList) { - declaredOneField(field, orderFiledMap, indexFiledMap, ignoreMap, excelIgnoreUnannotated, convertAllFiled); + declaredOneField(field, orderFiledMap, indexFiledMap, ignoreMap, excelIgnoreUnannotated); } FIELD_CACHE.put(clazz, new SoftReference( new FieldCache(buildSortedAllFiledMap(orderFiledMap, indexFiledMap), indexFiledMap, ignoreMap))); @@ -138,16 +137,16 @@ public class ClassUtils { } private static void declaredOneField(Field field, Map> orderFiledMap, - Map indexFiledMap, Map ignoreMap, ExcelIgnoreUnannotated excelIgnoreUnannotated, - Boolean convertAllFiled) { + Map indexFiledMap, Map ignoreMap, + ExcelIgnoreUnannotated excelIgnoreUnannotated) { + ExcelIgnore excelIgnore = field.getAnnotation(ExcelIgnore.class); if (excelIgnore != null) { ignoreMap.put(field.getName(), field); return; } ExcelProperty excelProperty = field.getAnnotation(ExcelProperty.class); - boolean noExcelProperty = excelProperty == null - && ((convertAllFiled != null && !convertAllFiled) || excelIgnoreUnannotated != null); + boolean noExcelProperty = excelProperty == null && excelIgnoreUnannotated != null; if (noExcelProperty) { ignoreMap.put(field.getName(), field); return; diff --git a/src/main/java/com/alibaba/excel/write/builder/ExcelWriterBuilder.java b/src/main/java/com/alibaba/excel/write/builder/ExcelWriterBuilder.java index 22196555..1bbdd950 100644 --- a/src/main/java/com/alibaba/excel/write/builder/ExcelWriterBuilder.java +++ b/src/main/java/com/alibaba/excel/write/builder/ExcelWriterBuilder.java @@ -65,21 +65,6 @@ public class ExcelWriterBuilder extends AbstractExcelWriterParameterBuilder - * Default true - * - * @param convertAllFiled - * @return - * @deprecated Just to be compatible with historical data, The default is always going to be convert all filed. - */ - @Deprecated - public ExcelWriterBuilder convertAllFiled(Boolean convertAllFiled) { - writeWorkbook.setConvertAllFiled(convertAllFiled); - return this; - } public ExcelWriterBuilder excelType(ExcelTypeEnum excelType) { writeWorkbook.setExcelType(excelType); diff --git a/src/main/java/com/alibaba/excel/write/executor/ExcelWriteAddExecutor.java b/src/main/java/com/alibaba/excel/write/executor/ExcelWriteAddExecutor.java index 01f9b53d..1b5e12a5 100644 --- a/src/main/java/com/alibaba/excel/write/executor/ExcelWriteAddExecutor.java +++ b/src/main/java/com/alibaba/excel/write/executor/ExcelWriteAddExecutor.java @@ -183,8 +183,7 @@ public class ExcelWriteAddExecutor extends AbstractExcelWriteExecutor { .isEmpty(writeWorkbookHolder.getExcludeColumnIndexes()) || !CollectionUtils .isEmpty(writeWorkbookHolder.getIncludeColumnFieldNames()) || !CollectionUtils .isEmpty(writeWorkbookHolder.getIncludeColumnIndexes()); - ClassUtils.declaredFields(clazz, sortedAllFiledMap, - writeWorkbookHolder.getWriteWorkbook().getConvertAllFiled(), needIgnore, writeWorkbookHolder); + ClassUtils.declaredFields(clazz, sortedAllFiledMap, needIgnore, writeWorkbookHolder); } } diff --git a/src/main/java/com/alibaba/excel/write/metadata/WriteWorkbook.java b/src/main/java/com/alibaba/excel/write/metadata/WriteWorkbook.java index 9f4bea5c..a3d99d2b 100644 --- a/src/main/java/com/alibaba/excel/write/metadata/WriteWorkbook.java +++ b/src/main/java/com/alibaba/excel/write/metadata/WriteWorkbook.java @@ -74,15 +74,4 @@ public class WriteWorkbook extends WriteBasicParameter { * Excel is also written in the event of an exception being thrown.The default false. */ private Boolean writeExcelOnException; - /** - * The default is all excel objects.Default is true. - *

- * if true , you can use {@link com.alibaba.excel.annotation.ExcelIgnore} ignore a field. - *

- * if false , you must use {@link com.alibaba.excel.annotation.ExcelProperty} to use a filed. - * - * @deprecated Just to be compatible with historical data, The default is always going to be convert all filed. - */ - @Deprecated - private Boolean convertAllFiled; } diff --git a/src/main/java/com/alibaba/excel/write/metadata/holder/AbstractWriteHolder.java b/src/main/java/com/alibaba/excel/write/metadata/holder/AbstractWriteHolder.java index 96d55396..2867bdc5 100644 --- a/src/main/java/com/alibaba/excel/write/metadata/holder/AbstractWriteHolder.java +++ b/src/main/java/com/alibaba/excel/write/metadata/holder/AbstractWriteHolder.java @@ -93,11 +93,9 @@ public abstract class AbstractWriteHolder extends AbstractHolder implements Writ */ private Collection includeColumnFieldNames; - public AbstractWriteHolder(WriteBasicParameter writeBasicParameter, AbstractWriteHolder parentAbstractWriteHolder, - Boolean convertAllField) { + public AbstractWriteHolder(WriteBasicParameter writeBasicParameter, AbstractWriteHolder parentAbstractWriteHolder) { super(writeBasicParameter, parentAbstractWriteHolder); - if (writeBasicParameter.getUseScientificFormat() != null) { throw new UnsupportedOperationException("Currently does not support setting useScientificFormat."); } @@ -164,7 +162,7 @@ public abstract class AbstractWriteHolder extends AbstractHolder implements Writ } // Initialization property - this.excelWriteHeadProperty = new ExcelWriteHeadProperty(this, getClazz(), getHead(), convertAllField); + this.excelWriteHeadProperty = new ExcelWriteHeadProperty(this, getClazz(), getHead()); // Set writeHandlerMap List handlerList = new ArrayList(); diff --git a/src/main/java/com/alibaba/excel/write/metadata/holder/WriteSheetHolder.java b/src/main/java/com/alibaba/excel/write/metadata/holder/WriteSheetHolder.java index 57f13584..dbce0b8b 100644 --- a/src/main/java/com/alibaba/excel/write/metadata/holder/WriteSheetHolder.java +++ b/src/main/java/com/alibaba/excel/write/metadata/holder/WriteSheetHolder.java @@ -77,7 +77,7 @@ public class WriteSheetHolder extends AbstractWriteHolder { private Integer lastRowIndex; public WriteSheetHolder(WriteSheet writeSheet, WriteWorkbookHolder writeWorkbookHolder) { - super(writeSheet, writeWorkbookHolder, writeWorkbookHolder.getWriteWorkbook().getConvertAllFiled()); + super(writeSheet, writeWorkbookHolder); this.writeSheet = writeSheet; if (writeSheet.getSheetNo() == null && StringUtils.isEmpty(writeSheet.getSheetName())) { this.sheetNo = 0; diff --git a/src/main/java/com/alibaba/excel/write/metadata/holder/WriteTableHolder.java b/src/main/java/com/alibaba/excel/write/metadata/holder/WriteTableHolder.java index f7242a2a..e353a44c 100644 --- a/src/main/java/com/alibaba/excel/write/metadata/holder/WriteTableHolder.java +++ b/src/main/java/com/alibaba/excel/write/metadata/holder/WriteTableHolder.java @@ -3,11 +3,14 @@ package com.alibaba.excel.write.metadata.holder; import com.alibaba.excel.enums.HolderEnum; import com.alibaba.excel.write.metadata.WriteTable; +import lombok.Data; + /** * sheet holder * * @author Jiaju Zhuang */ +@Data public class WriteTableHolder extends AbstractWriteHolder { /*** * poi sheet @@ -22,38 +25,13 @@ public class WriteTableHolder extends AbstractWriteHolder { */ private WriteTable writeTable; - public WriteTableHolder(WriteTable writeTable, WriteSheetHolder writeSheetHolder, - WriteWorkbookHolder writeWorkbookHolder) { - super(writeTable, writeSheetHolder, writeWorkbookHolder.getWriteWorkbook().getConvertAllFiled()); + public WriteTableHolder(WriteTable writeTable, WriteSheetHolder writeSheetHolder) { + super(writeTable, writeSheetHolder); this.parentWriteSheetHolder = writeSheetHolder; this.tableNo = writeTable.getTableNo(); this.writeTable = writeTable; } - public WriteSheetHolder getParentWriteSheetHolder() { - return parentWriteSheetHolder; - } - - public void setParentWriteSheetHolder(WriteSheetHolder parentWriteSheetHolder) { - this.parentWriteSheetHolder = parentWriteSheetHolder; - } - - public Integer getTableNo() { - return tableNo; - } - - public void setTableNo(Integer tableNo) { - this.tableNo = tableNo; - } - - public WriteTable getWriteTable() { - return writeTable; - } - - public void setWriteTable(WriteTable writeTable) { - this.writeTable = writeTable; - } - @Override public HolderEnum holderType() { return HolderEnum.TABLE; diff --git a/src/main/java/com/alibaba/excel/write/metadata/holder/WriteWorkbookHolder.java b/src/main/java/com/alibaba/excel/write/metadata/holder/WriteWorkbookHolder.java index a7871ba7..fe894454 100644 --- a/src/main/java/com/alibaba/excel/write/metadata/holder/WriteWorkbookHolder.java +++ b/src/main/java/com/alibaba/excel/write/metadata/holder/WriteWorkbookHolder.java @@ -140,7 +140,7 @@ public class WriteWorkbookHolder extends AbstractWriteHolder { private Map dataFormatMap; public WriteWorkbookHolder(WriteWorkbook writeWorkbook) { - super(writeWorkbook, null, writeWorkbook.getConvertAllFiled()); + super(writeWorkbook, null); this.writeWorkbook = writeWorkbook; this.file = writeWorkbook.getFile(); if (file != null) { diff --git a/src/main/java/com/alibaba/excel/write/property/ExcelWriteHeadProperty.java b/src/main/java/com/alibaba/excel/write/property/ExcelWriteHeadProperty.java index 26af5512..2e8cc9d2 100644 --- a/src/main/java/com/alibaba/excel/write/property/ExcelWriteHeadProperty.java +++ b/src/main/java/com/alibaba/excel/write/property/ExcelWriteHeadProperty.java @@ -7,7 +7,6 @@ import java.util.List; import java.util.Map; import java.util.Set; -import com.alibaba.excel.annotation.format.NumberFormat; import com.alibaba.excel.annotation.write.style.ColumnWidth; import com.alibaba.excel.annotation.write.style.ContentFontStyle; import com.alibaba.excel.annotation.write.style.ContentLoopMerge; @@ -17,9 +16,6 @@ import com.alibaba.excel.annotation.write.style.HeadFontStyle; import com.alibaba.excel.annotation.write.style.HeadRowHeight; import com.alibaba.excel.annotation.write.style.HeadStyle; import com.alibaba.excel.annotation.write.style.OnceAbsoluteMerge; -import com.alibaba.excel.converters.ConverterKeyBuild; -import com.alibaba.excel.converters.DefaultConverterLoader; -import com.alibaba.excel.enums.CellDataTypeEnum; import com.alibaba.excel.enums.HeadKindEnum; import com.alibaba.excel.metadata.CellRange; import com.alibaba.excel.metadata.Head; @@ -44,23 +40,23 @@ public class ExcelWriteHeadProperty extends ExcelHeadProperty { private RowHeightProperty contentRowHeightProperty; private OnceAbsoluteMergeProperty onceAbsoluteMergeProperty; - public ExcelWriteHeadProperty(Holder holder, Class headClazz, List> head, Boolean convertAllFiled) { - super(holder, headClazz, head, convertAllFiled); + public ExcelWriteHeadProperty(Holder holder, Class headClazz, List> head) { + super(holder, headClazz, head); if (getHeadKind() != HeadKindEnum.CLASS) { return; } this.headRowHeightProperty = - RowHeightProperty.build((HeadRowHeight) headClazz.getAnnotation(HeadRowHeight.class)); + RowHeightProperty.build((HeadRowHeight)headClazz.getAnnotation(HeadRowHeight.class)); this.contentRowHeightProperty = - RowHeightProperty.build((ContentRowHeight) headClazz.getAnnotation(ContentRowHeight.class)); + RowHeightProperty.build((ContentRowHeight)headClazz.getAnnotation(ContentRowHeight.class)); this.onceAbsoluteMergeProperty = - OnceAbsoluteMergeProperty.build((OnceAbsoluteMerge) headClazz.getAnnotation(OnceAbsoluteMerge.class)); + OnceAbsoluteMergeProperty.build((OnceAbsoluteMerge)headClazz.getAnnotation(OnceAbsoluteMerge.class)); - ColumnWidth parentColumnWidth = (ColumnWidth) headClazz.getAnnotation(ColumnWidth.class); - HeadStyle parentHeadStyle = (HeadStyle) headClazz.getAnnotation(HeadStyle.class); - HeadFontStyle parentHeadFontStyle = (HeadFontStyle) headClazz.getAnnotation(HeadFontStyle.class); - ContentStyle parentContentStyle = (ContentStyle) headClazz.getAnnotation(ContentStyle.class); - ContentFontStyle parentContentFontStyle = (ContentFontStyle) headClazz.getAnnotation(ContentFontStyle.class); + ColumnWidth parentColumnWidth = (ColumnWidth)headClazz.getAnnotation(ColumnWidth.class); + HeadStyle parentHeadStyle = (HeadStyle)headClazz.getAnnotation(HeadStyle.class); + HeadFontStyle parentHeadFontStyle = (HeadFontStyle)headClazz.getAnnotation(HeadFontStyle.class); + ContentStyle parentContentStyle = (ContentStyle)headClazz.getAnnotation(ContentStyle.class); + ContentFontStyle parentContentFontStyle = (ContentFontStyle)headClazz.getAnnotation(ContentFontStyle.class); for (Map.Entry entry : getContentPropertyMap().entrySet()) { Integer index = entry.getKey();