Browse Source

移除弃用代码

pull/2077/head
Jiaju Zhuang 3 years ago
parent
commit
153d4c6e20
  1. 2
      src/main/java/com/alibaba/excel/context/WriteContextImpl.java
  2. 29
      src/main/java/com/alibaba/excel/metadata/property/ExcelHeadProperty.java
  3. 25
      src/main/java/com/alibaba/excel/read/listener/ModelBuildEventListener.java
  4. 140
      src/main/java/com/alibaba/excel/read/metadata/ReadWorkbook.java
  5. 5
      src/main/java/com/alibaba/excel/read/metadata/holder/AbstractReadHolder.java
  6. 2
      src/main/java/com/alibaba/excel/read/metadata/holder/ReadSheetHolder.java
  7. 22
      src/main/java/com/alibaba/excel/read/metadata/holder/ReadWorkbookHolder.java
  8. 4
      src/main/java/com/alibaba/excel/read/metadata/property/ExcelReadHeadProperty.java
  9. 27
      src/main/java/com/alibaba/excel/util/ClassUtils.java
  10. 15
      src/main/java/com/alibaba/excel/write/builder/ExcelWriterBuilder.java
  11. 3
      src/main/java/com/alibaba/excel/write/executor/ExcelWriteAddExecutor.java
  12. 11
      src/main/java/com/alibaba/excel/write/metadata/WriteWorkbook.java
  13. 6
      src/main/java/com/alibaba/excel/write/metadata/holder/AbstractWriteHolder.java
  14. 2
      src/main/java/com/alibaba/excel/write/metadata/holder/WriteSheetHolder.java
  15. 32
      src/main/java/com/alibaba/excel/write/metadata/holder/WriteTableHolder.java
  16. 2
      src/main/java/com/alibaba/excel/write/metadata/holder/WriteWorkbookHolder.java
  17. 24
      src/main/java/com/alibaba/excel/write/property/ExcelWriteHeadProperty.java

2
src/main/java/com/alibaba/excel/context/WriteContextImpl.java

@ -291,7 +291,7 @@ public class WriteContextImpl implements WriteContext {
} }
private void initCurrentTableHolder(WriteTable writeTable) { private void initCurrentTableHolder(WriteTable writeTable) {
writeTableHolder = new WriteTableHolder(writeTable, writeSheetHolder, writeWorkbookHolder); writeTableHolder = new WriteTableHolder(writeTable, writeSheetHolder);
writeSheetHolder.getHasBeenInitializedTable().put(writeTable.getTableNo(), writeTableHolder); writeSheetHolder.getHasBeenInitializedTable().put(writeTable.getTableNo(), writeTableHolder);
currentWriteHolder = writeTableHolder; currentWriteHolder = writeTableHolder;
if (LOGGER.isDebugEnabled()) { if (LOGGER.isDebugEnabled()) {

29
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.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.TreeMap; 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.Head;
import com.alibaba.excel.metadata.Holder; import com.alibaba.excel.metadata.Holder;
import com.alibaba.excel.util.ClassUtils; import com.alibaba.excel.util.ClassUtils;
import com.alibaba.excel.util.MapUtils;
import com.alibaba.excel.util.StringUtils; import com.alibaba.excel.util.StringUtils;
import com.alibaba.excel.write.metadata.holder.AbstractWriteHolder; import com.alibaba.excel.write.metadata.holder.AbstractWriteHolder;
@ -64,19 +64,19 @@ public class ExcelHeadProperty {
*/ */
private Map<String, Field> ignoreMap; private Map<String, Field> ignoreMap;
public ExcelHeadProperty(Holder holder, Class headClazz, List<List<String>> head, Boolean convertAllFiled) { public ExcelHeadProperty(Holder holder, Class headClazz, List<List<String>> head) {
this.headClazz = headClazz; this.headClazz = headClazz;
headMap = new TreeMap<Integer, Head>(); headMap = new TreeMap<>();
contentPropertyMap = new TreeMap<Integer, ExcelContentProperty>(); contentPropertyMap = new TreeMap<>();
fieldNameContentPropertyMap = new HashMap<String, ExcelContentProperty>(); fieldNameContentPropertyMap = MapUtils.newHashMap();
ignoreMap = new HashMap<String, Field>(16); ignoreMap = MapUtils.newHashMap();
headKind = HeadKindEnum.NONE; headKind = HeadKindEnum.NONE;
headRowNumber = 0; headRowNumber = 0;
if (head != null && !head.isEmpty()) { if (head != null && !head.isEmpty()) {
int headIndex = 0; int headIndex = 0;
for (int i = 0; i < head.size(); i++) { for (int i = 0; i < head.size(); i++) {
if (holder instanceof AbstractWriteHolder) { if (holder instanceof AbstractWriteHolder) {
if (((AbstractWriteHolder) holder).ignore(null, i)) { if (((AbstractWriteHolder)holder).ignore(null, i)) {
continue; continue;
} }
} }
@ -87,7 +87,7 @@ public class ExcelHeadProperty {
headKind = HeadKindEnum.STRING; headKind = HeadKindEnum.STRING;
} }
// convert headClazz to head // convert headClazz to head
initColumnProperties(holder, convertAllFiled); initColumnProperties(holder);
initHeadRowNumber(); initHeadRowNumber();
if (LOGGER.isDebugEnabled()) { 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) { if (headClazz == null) {
return; return;
} }
@ -124,12 +124,11 @@ public class ExcelHeadProperty {
Map<Integer, Field> indexFiledMap = new TreeMap<Integer, Field>(); Map<Integer, Field> indexFiledMap = new TreeMap<Integer, Field>();
boolean needIgnore = (holder instanceof AbstractWriteHolder) && ( boolean needIgnore = (holder instanceof AbstractWriteHolder) && (
!CollectionUtils.isEmpty(((AbstractWriteHolder) holder).getExcludeColumnFieldNames()) || !CollectionUtils !CollectionUtils.isEmpty(((AbstractWriteHolder)holder).getExcludeColumnFieldNames()) || !CollectionUtils
.isEmpty(((AbstractWriteHolder) holder).getExcludeColumnIndexes()) || !CollectionUtils .isEmpty(((AbstractWriteHolder)holder).getExcludeColumnIndexes()) || !CollectionUtils
.isEmpty(((AbstractWriteHolder) holder).getIncludeColumnFieldNames()) || !CollectionUtils .isEmpty(((AbstractWriteHolder)holder).getIncludeColumnFieldNames()) || !CollectionUtils
.isEmpty(((AbstractWriteHolder) holder).getIncludeColumnIndexes())); .isEmpty(((AbstractWriteHolder)holder).getIncludeColumnIndexes()));
ClassUtils.declaredFields(headClazz, sortedAllFiledMap, indexFiledMap, ignoreMap, convertAllFiled, needIgnore, ClassUtils.declaredFields(headClazz, sortedAllFiledMap, indexFiledMap, ignoreMap, needIgnore, holder);
holder);
for (Map.Entry<Integer, Field> entry : sortedAllFiledMap.entrySet()) { for (Map.Entry<Integer, Field> entry : sortedAllFiledMap.entrySet()) {
initOneColumnProperty(entry.getKey(), entry.getValue(), indexFiledMap.containsKey(entry.getKey())); initOneColumnProperty(entry.getKey(), entry.getValue(), indexFiledMap.containsKey(entry.getKey()));

25
src/main/java/com/alibaba/excel/read/listener/ModelBuildEventListener.java

@ -1,7 +1,5 @@
package com.alibaba.excel.read.listener; package com.alibaba.excel.read.listener;
import java.util.ArrayList;
import java.util.List;
import java.util.Map; import java.util.Map;
import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.context.AnalysisContext;
@ -42,7 +40,6 @@ public class ModelBuildEventListener implements ReadListener<Map<Integer, ReadCe
private Object buildStringList(Map<Integer, ReadCellData<?>> cellDataMap, ReadSheetHolder readSheetHolder, private Object buildStringList(Map<Integer, ReadCellData<?>> cellDataMap, ReadSheetHolder readSheetHolder,
AnalysisContext context) { AnalysisContext context) {
int index = 0; int index = 0;
if (context.readWorkbookHolder().getDefaultReturnMap()) {
Map<Integer, String> map = MapUtils.newLinkedHashMapWithExpectedSize(cellDataMap.size()); Map<Integer, String> map = MapUtils.newLinkedHashMapWithExpectedSize(cellDataMap.size());
for (Map.Entry<Integer, ReadCellData<?>> entry : cellDataMap.entrySet()) { for (Map.Entry<Integer, ReadCellData<?>> entry : cellDataMap.entrySet()) {
Integer key = entry.getKey(); Integer key = entry.getKey();
@ -62,28 +59,6 @@ public class ModelBuildEventListener implements ReadListener<Map<Integer, ReadCe
index++; index++;
} }
return map; return map;
} else {
// Compatible with the old code the old code returns a list
List<String> list = new ArrayList<>();
for (Map.Entry<Integer, ReadCellData<?>> 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;
}
} }
private Object buildUserModel(Map<Integer, ReadCellData<?>> cellDataMap, ReadSheetHolder readSheetHolder, private Object buildUserModel(Map<Integer, ReadCellData<?>> cellDataMap, ReadSheetHolder readSheetHolder,

140
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.read.listener.ModelBuildEventListener;
import com.alibaba.excel.support.ExcelTypeEnum; import com.alibaba.excel.support.ExcelTypeEnum;
import lombok.Data;
/** /**
* Workbook * Workbook
* *
* @author Jiaju Zhuang * @author Jiaju Zhuang
**/ **/
@Data
public class ReadWorkbook extends ReadBasicParameter { public class ReadWorkbook extends ReadBasicParameter {
/** /**
* Excel type * Excel type
@ -91,141 +94,4 @@ public class ReadWorkbook extends ReadBasicParameter {
* @see CellExtraTypeEnum * @see CellExtraTypeEnum
*/ */
private Set<CellExtraTypeEnum> extraReadSet; private Set<CellExtraTypeEnum> extraReadSet;
/**
* The default is all excel objects.Default is true.
* <p>
* if true , you can use {@link com.alibaba.excel.annotation.ExcelIgnore} ignore a field.
* <p>
* 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<CellExtraTypeEnum> getExtraReadSet() {
return extraReadSet;
}
public void setExtraReadSet(Set<CellExtraTypeEnum> extraReadSet) {
this.extraReadSet = extraReadSet;
}
} }

5
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<ReadListener<?>> readListenerList; private List<ReadListener<?>> readListenerList;
public AbstractReadHolder(ReadBasicParameter readBasicParameter, AbstractReadHolder parentAbstractReadHolder, public AbstractReadHolder(ReadBasicParameter readBasicParameter, AbstractReadHolder parentAbstractReadHolder) {
Boolean convertAllFiled) {
super(readBasicParameter, parentAbstractReadHolder); super(readBasicParameter, parentAbstractReadHolder);
if (readBasicParameter.getUseScientificFormat() == null) { if (readBasicParameter.getUseScientificFormat() == null) {
@ -60,7 +59,7 @@ public abstract class AbstractReadHolder extends AbstractHolder implements ReadH
} }
// Initialization property // Initialization property
this.excelReadHeadProperty = new ExcelReadHeadProperty(this, getClazz(), getHead(), convertAllFiled); this.excelReadHeadProperty = new ExcelReadHeadProperty(this, getClazz(), getHead());
if (readBasicParameter.getHeadRowNumber() == null) { if (readBasicParameter.getHeadRowNumber() == null) {
if (parentAbstractReadHolder == null) { if (parentAbstractReadHolder == null) {
if (excelReadHeadProperty.hasHead()) { if (excelReadHeadProperty.hasHead()) {

2
src/main/java/com/alibaba/excel/read/metadata/holder/ReadSheetHolder.java

@ -59,7 +59,7 @@ public class ReadSheetHolder extends AbstractReadHolder {
private ReadCellData<?> tempCellData; private ReadCellData<?> tempCellData;
public ReadSheetHolder(ReadSheet readSheet, ReadWorkbookHolder readWorkbookHolder) { public ReadSheetHolder(ReadSheet readSheet, ReadWorkbookHolder readWorkbookHolder) {
super(readSheet, readWorkbookHolder, readWorkbookHolder.getReadWorkbook().getConvertAllFiled()); super(readSheet, readWorkbookHolder);
this.readSheet = readSheet; this.readSheet = readSheet;
this.parentReadWorkbookHolder = readWorkbookHolder; this.parentReadWorkbookHolder = readWorkbookHolder;
this.sheetNo = readSheet.getSheetNo(); this.sheetNo = readSheet.getSheetNo();

22
src/main/java/com/alibaba/excel/read/metadata/holder/ReadWorkbookHolder.java

@ -106,28 +106,13 @@ public class ReadWorkbookHolder extends AbstractReadHolder {
*/ */
private Boolean readAll; 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 * Prevent repeating sheet
*/ */
private Set<Integer> hasReadSheet; private Set<Integer> hasReadSheet;
public ReadWorkbookHolder(ReadWorkbook readWorkbook) { public ReadWorkbookHolder(ReadWorkbook readWorkbook) {
super(readWorkbook, null, readWorkbook.getConvertAllFiled()); super(readWorkbook, null);
this.readWorkbook = readWorkbook; this.readWorkbook = readWorkbook;
if (readWorkbook.getInputStream() != null) { if (readWorkbook.getInputStream() != null) {
this.inputStream = readWorkbook.getInputStream(); this.inputStream = readWorkbook.getInputStream();
@ -162,11 +147,6 @@ public class ReadWorkbookHolder extends AbstractReadHolder {
this.readCacheSelector = readWorkbook.getReadCacheSelector(); this.readCacheSelector = readWorkbook.getReadCacheSelector();
} }
} }
if (readWorkbook.getDefaultReturnMap() == null) {
this.defaultReturnMap = Boolean.TRUE;
} else {
this.defaultReturnMap = readWorkbook.getDefaultReturnMap();
}
if (readWorkbook.getExtraReadSet() == null) { if (readWorkbook.getExtraReadSet() == null) {
this.extraReadSet = new HashSet<CellExtraTypeEnum>(); this.extraReadSet = new HashSet<CellExtraTypeEnum>();
} else { } else {

4
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 class ExcelReadHeadProperty extends ExcelHeadProperty {
public ExcelReadHeadProperty(Holder holder, Class headClazz, List<List<String>> head, Boolean convertAllFiled) { public ExcelReadHeadProperty(Holder holder, Class headClazz, List<List<String>> head) {
super(holder, headClazz, head, convertAllFiled); super(holder, headClazz, head);
} }
} }

27
src/main/java/com/alibaba/excel/util/ClassUtils.java

@ -30,9 +30,8 @@ public class ClassUtils {
public static final Map<Class<?>, SoftReference<FieldCache>> FIELD_CACHE = new ConcurrentHashMap<>(); public static final Map<Class<?>, SoftReference<FieldCache>> FIELD_CACHE = new ConcurrentHashMap<>();
public static void declaredFields(Class<?> clazz, Map<Integer, Field> sortedAllFiledMap, public static void declaredFields(Class<?> clazz, Map<Integer, Field> sortedAllFiledMap,
Map<Integer, Field> indexFiledMap, Map<String, Field> ignoreMap, Boolean convertAllFiled, Map<Integer, Field> indexFiledMap, Map<String, Field> ignoreMap, Boolean needIgnore, Holder holder) {
Boolean needIgnore, Holder holder) { FieldCache fieldCache = getFieldCache(clazz);
FieldCache fieldCache = getFieldCache(clazz, convertAllFiled);
if (fieldCache == null) { if (fieldCache == null) {
return; return;
} }
@ -68,12 +67,12 @@ public class ClassUtils {
} }
} }
public static void declaredFields(Class<?> clazz, Map<Integer, Field> sortedAllFiledMap, Boolean convertAllFiled, public static void declaredFields(Class<?> clazz, Map<Integer, Field> sortedAllFiledMap, Boolean needIgnore,
Boolean needIgnore, WriteHolder writeHolder) { WriteHolder writeHolder) {
declaredFields(clazz, sortedAllFiledMap, null, null, convertAllFiled, needIgnore, 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) { if (clazz == null) {
return null; return null;
} }
@ -86,12 +85,12 @@ public class ClassUtils {
if (fieldCacheSoftReference != null && fieldCacheSoftReference.get() != null) { if (fieldCacheSoftReference != null && fieldCacheSoftReference.get() != null) {
return fieldCacheSoftReference.get(); return fieldCacheSoftReference.get();
} }
declaredFields(clazz, convertAllFiled); declaredFields(clazz);
} }
return FIELD_CACHE.get(clazz).get(); return FIELD_CACHE.get(clazz).get();
} }
private static void declaredFields(Class<?> clazz, Boolean convertAllFiled) { private static void declaredFields(Class<?> clazz) {
List<Field> tempFieldList = new ArrayList<>(); List<Field> tempFieldList = new ArrayList<>();
Class<?> tempClass = clazz; Class<?> tempClass = clazz;
// When the parent class is null, it indicates that the parent class (Object class) has reached the top // 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); ExcelIgnoreUnannotated excelIgnoreUnannotated = clazz.getAnnotation(ExcelIgnoreUnannotated.class);
for (Field field : tempFieldList) { for (Field field : tempFieldList) {
declaredOneField(field, orderFiledMap, indexFiledMap, ignoreMap, excelIgnoreUnannotated, convertAllFiled); declaredOneField(field, orderFiledMap, indexFiledMap, ignoreMap, excelIgnoreUnannotated);
} }
FIELD_CACHE.put(clazz, new SoftReference<FieldCache>( FIELD_CACHE.put(clazz, new SoftReference<FieldCache>(
new FieldCache(buildSortedAllFiledMap(orderFiledMap, indexFiledMap), indexFiledMap, ignoreMap))); new FieldCache(buildSortedAllFiledMap(orderFiledMap, indexFiledMap), indexFiledMap, ignoreMap)));
@ -138,16 +137,16 @@ public class ClassUtils {
} }
private static void declaredOneField(Field field, Map<Integer, List<Field>> orderFiledMap, private static void declaredOneField(Field field, Map<Integer, List<Field>> orderFiledMap,
Map<Integer, Field> indexFiledMap, Map<String, Field> ignoreMap, ExcelIgnoreUnannotated excelIgnoreUnannotated, Map<Integer, Field> indexFiledMap, Map<String, Field> ignoreMap,
Boolean convertAllFiled) { ExcelIgnoreUnannotated excelIgnoreUnannotated) {
ExcelIgnore excelIgnore = field.getAnnotation(ExcelIgnore.class); ExcelIgnore excelIgnore = field.getAnnotation(ExcelIgnore.class);
if (excelIgnore != null) { if (excelIgnore != null) {
ignoreMap.put(field.getName(), field); ignoreMap.put(field.getName(), field);
return; return;
} }
ExcelProperty excelProperty = field.getAnnotation(ExcelProperty.class); ExcelProperty excelProperty = field.getAnnotation(ExcelProperty.class);
boolean noExcelProperty = excelProperty == null boolean noExcelProperty = excelProperty == null && excelIgnoreUnannotated != null;
&& ((convertAllFiled != null && !convertAllFiled) || excelIgnoreUnannotated != null);
if (noExcelProperty) { if (noExcelProperty) {
ignoreMap.put(field.getName(), field); ignoreMap.put(field.getName(), field);
return; return;

15
src/main/java/com/alibaba/excel/write/builder/ExcelWriterBuilder.java

@ -65,21 +65,6 @@ public class ExcelWriterBuilder extends AbstractExcelWriterParameterBuilder<Exce
return this; return this;
} }
/**
* 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.
* <p>
* 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) { public ExcelWriterBuilder excelType(ExcelTypeEnum excelType) {
writeWorkbook.setExcelType(excelType); writeWorkbook.setExcelType(excelType);

3
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.getExcludeColumnIndexes()) || !CollectionUtils
.isEmpty(writeWorkbookHolder.getIncludeColumnFieldNames()) || !CollectionUtils .isEmpty(writeWorkbookHolder.getIncludeColumnFieldNames()) || !CollectionUtils
.isEmpty(writeWorkbookHolder.getIncludeColumnIndexes()); .isEmpty(writeWorkbookHolder.getIncludeColumnIndexes());
ClassUtils.declaredFields(clazz, sortedAllFiledMap, ClassUtils.declaredFields(clazz, sortedAllFiledMap, needIgnore, writeWorkbookHolder);
writeWorkbookHolder.getWriteWorkbook().getConvertAllFiled(), needIgnore, writeWorkbookHolder);
} }
} }

11
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. * Excel is also written in the event of an exception being thrown.The default false.
*/ */
private Boolean writeExcelOnException; private Boolean writeExcelOnException;
/**
* The default is all excel objects.Default is true.
* <p>
* if true , you can use {@link com.alibaba.excel.annotation.ExcelIgnore} ignore a field.
* <p>
* 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;
} }

6
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<String> includeColumnFieldNames; private Collection<String> includeColumnFieldNames;
public AbstractWriteHolder(WriteBasicParameter writeBasicParameter, AbstractWriteHolder parentAbstractWriteHolder, public AbstractWriteHolder(WriteBasicParameter writeBasicParameter, AbstractWriteHolder parentAbstractWriteHolder) {
Boolean convertAllField) {
super(writeBasicParameter, parentAbstractWriteHolder); super(writeBasicParameter, parentAbstractWriteHolder);
if (writeBasicParameter.getUseScientificFormat() != null) { if (writeBasicParameter.getUseScientificFormat() != null) {
throw new UnsupportedOperationException("Currently does not support setting useScientificFormat."); throw new UnsupportedOperationException("Currently does not support setting useScientificFormat.");
} }
@ -164,7 +162,7 @@ public abstract class AbstractWriteHolder extends AbstractHolder implements Writ
} }
// Initialization property // Initialization property
this.excelWriteHeadProperty = new ExcelWriteHeadProperty(this, getClazz(), getHead(), convertAllField); this.excelWriteHeadProperty = new ExcelWriteHeadProperty(this, getClazz(), getHead());
// Set writeHandlerMap // Set writeHandlerMap
List<WriteHandler> handlerList = new ArrayList<WriteHandler>(); List<WriteHandler> handlerList = new ArrayList<WriteHandler>();

2
src/main/java/com/alibaba/excel/write/metadata/holder/WriteSheetHolder.java

@ -77,7 +77,7 @@ public class WriteSheetHolder extends AbstractWriteHolder {
private Integer lastRowIndex; private Integer lastRowIndex;
public WriteSheetHolder(WriteSheet writeSheet, WriteWorkbookHolder writeWorkbookHolder) { public WriteSheetHolder(WriteSheet writeSheet, WriteWorkbookHolder writeWorkbookHolder) {
super(writeSheet, writeWorkbookHolder, writeWorkbookHolder.getWriteWorkbook().getConvertAllFiled()); super(writeSheet, writeWorkbookHolder);
this.writeSheet = writeSheet; this.writeSheet = writeSheet;
if (writeSheet.getSheetNo() == null && StringUtils.isEmpty(writeSheet.getSheetName())) { if (writeSheet.getSheetNo() == null && StringUtils.isEmpty(writeSheet.getSheetName())) {
this.sheetNo = 0; this.sheetNo = 0;

32
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.enums.HolderEnum;
import com.alibaba.excel.write.metadata.WriteTable; import com.alibaba.excel.write.metadata.WriteTable;
import lombok.Data;
/** /**
* sheet holder * sheet holder
* *
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@Data
public class WriteTableHolder extends AbstractWriteHolder { public class WriteTableHolder extends AbstractWriteHolder {
/*** /***
* poi sheet * poi sheet
@ -22,38 +25,13 @@ public class WriteTableHolder extends AbstractWriteHolder {
*/ */
private WriteTable writeTable; private WriteTable writeTable;
public WriteTableHolder(WriteTable writeTable, WriteSheetHolder writeSheetHolder, public WriteTableHolder(WriteTable writeTable, WriteSheetHolder writeSheetHolder) {
WriteWorkbookHolder writeWorkbookHolder) { super(writeTable, writeSheetHolder);
super(writeTable, writeSheetHolder, writeWorkbookHolder.getWriteWorkbook().getConvertAllFiled());
this.parentWriteSheetHolder = writeSheetHolder; this.parentWriteSheetHolder = writeSheetHolder;
this.tableNo = writeTable.getTableNo(); this.tableNo = writeTable.getTableNo();
this.writeTable = writeTable; 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 @Override
public HolderEnum holderType() { public HolderEnum holderType() {
return HolderEnum.TABLE; return HolderEnum.TABLE;

2
src/main/java/com/alibaba/excel/write/metadata/holder/WriteWorkbookHolder.java

@ -140,7 +140,7 @@ public class WriteWorkbookHolder extends AbstractWriteHolder {
private Map<DataFormatData, Short> dataFormatMap; private Map<DataFormatData, Short> dataFormatMap;
public WriteWorkbookHolder(WriteWorkbook writeWorkbook) { public WriteWorkbookHolder(WriteWorkbook writeWorkbook) {
super(writeWorkbook, null, writeWorkbook.getConvertAllFiled()); super(writeWorkbook, null);
this.writeWorkbook = writeWorkbook; this.writeWorkbook = writeWorkbook;
this.file = writeWorkbook.getFile(); this.file = writeWorkbook.getFile();
if (file != null) { if (file != null) {

24
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.Map;
import java.util.Set; 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.ColumnWidth;
import com.alibaba.excel.annotation.write.style.ContentFontStyle; import com.alibaba.excel.annotation.write.style.ContentFontStyle;
import com.alibaba.excel.annotation.write.style.ContentLoopMerge; 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.HeadRowHeight;
import com.alibaba.excel.annotation.write.style.HeadStyle; import com.alibaba.excel.annotation.write.style.HeadStyle;
import com.alibaba.excel.annotation.write.style.OnceAbsoluteMerge; 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.enums.HeadKindEnum;
import com.alibaba.excel.metadata.CellRange; import com.alibaba.excel.metadata.CellRange;
import com.alibaba.excel.metadata.Head; import com.alibaba.excel.metadata.Head;
@ -44,23 +40,23 @@ public class ExcelWriteHeadProperty extends ExcelHeadProperty {
private RowHeightProperty contentRowHeightProperty; private RowHeightProperty contentRowHeightProperty;
private OnceAbsoluteMergeProperty onceAbsoluteMergeProperty; private OnceAbsoluteMergeProperty onceAbsoluteMergeProperty;
public ExcelWriteHeadProperty(Holder holder, Class headClazz, List<List<String>> head, Boolean convertAllFiled) { public ExcelWriteHeadProperty(Holder holder, Class headClazz, List<List<String>> head) {
super(holder, headClazz, head, convertAllFiled); super(holder, headClazz, head);
if (getHeadKind() != HeadKindEnum.CLASS) { if (getHeadKind() != HeadKindEnum.CLASS) {
return; return;
} }
this.headRowHeightProperty = this.headRowHeightProperty =
RowHeightProperty.build((HeadRowHeight) headClazz.getAnnotation(HeadRowHeight.class)); RowHeightProperty.build((HeadRowHeight)headClazz.getAnnotation(HeadRowHeight.class));
this.contentRowHeightProperty = this.contentRowHeightProperty =
RowHeightProperty.build((ContentRowHeight) headClazz.getAnnotation(ContentRowHeight.class)); RowHeightProperty.build((ContentRowHeight)headClazz.getAnnotation(ContentRowHeight.class));
this.onceAbsoluteMergeProperty = this.onceAbsoluteMergeProperty =
OnceAbsoluteMergeProperty.build((OnceAbsoluteMerge) headClazz.getAnnotation(OnceAbsoluteMerge.class)); OnceAbsoluteMergeProperty.build((OnceAbsoluteMerge)headClazz.getAnnotation(OnceAbsoluteMerge.class));
ColumnWidth parentColumnWidth = (ColumnWidth) headClazz.getAnnotation(ColumnWidth.class); ColumnWidth parentColumnWidth = (ColumnWidth)headClazz.getAnnotation(ColumnWidth.class);
HeadStyle parentHeadStyle = (HeadStyle) headClazz.getAnnotation(HeadStyle.class); HeadStyle parentHeadStyle = (HeadStyle)headClazz.getAnnotation(HeadStyle.class);
HeadFontStyle parentHeadFontStyle = (HeadFontStyle) headClazz.getAnnotation(HeadFontStyle.class); HeadFontStyle parentHeadFontStyle = (HeadFontStyle)headClazz.getAnnotation(HeadFontStyle.class);
ContentStyle parentContentStyle = (ContentStyle) headClazz.getAnnotation(ContentStyle.class); ContentStyle parentContentStyle = (ContentStyle)headClazz.getAnnotation(ContentStyle.class);
ContentFontStyle parentContentFontStyle = (ContentFontStyle) headClazz.getAnnotation(ContentFontStyle.class); ContentFontStyle parentContentFontStyle = (ContentFontStyle)headClazz.getAnnotation(ContentFontStyle.class);
for (Map.Entry<Integer, ExcelContentProperty> entry : getContentPropertyMap().entrySet()) { for (Map.Entry<Integer, ExcelContentProperty> entry : getContentPropertyMap().entrySet()) {
Integer index = entry.getKey(); Integer index = entry.getKey();

Loading…
Cancel
Save