diff --git a/src/main/java/com/alibaba/excel/metadata/AbstractHolder.java b/src/main/java/com/alibaba/excel/metadata/AbstractHolder.java index ffb54559..90a1bbbe 100644 --- a/src/main/java/com/alibaba/excel/metadata/AbstractHolder.java +++ b/src/main/java/com/alibaba/excel/metadata/AbstractHolder.java @@ -1,7 +1,6 @@ package com.alibaba.excel.metadata; import java.util.List; -import java.util.Locale; import java.util.Map; import com.alibaba.excel.converters.Converter; @@ -55,19 +54,16 @@ public abstract class AbstractHolder implements ConfigurationHolder { } this.globalConfiguration = new GlobalConfiguration(); if (basicParameter.getAutoTrim() == null) { - if (prentAbstractHolder == null) { - globalConfiguration.setAutoTrim(Boolean.TRUE); - } else { + if (prentAbstractHolder != null) { globalConfiguration.setAutoTrim(prentAbstractHolder.getGlobalConfiguration().getAutoTrim()); } } else { globalConfiguration.setAutoTrim(basicParameter.getAutoTrim()); } + if (basicParameter.getLocale() == null) { - if (prentAbstractHolder == null) { - globalConfiguration.setLocale(Locale.getDefault()); - } else { + if (prentAbstractHolder != null) { globalConfiguration.setLocale(prentAbstractHolder.getGlobalConfiguration().getLocale()); } } else { diff --git a/src/main/java/com/alibaba/excel/metadata/GlobalConfiguration.java b/src/main/java/com/alibaba/excel/metadata/GlobalConfiguration.java index 26f3720f..987e553b 100644 --- a/src/main/java/com/alibaba/excel/metadata/GlobalConfiguration.java +++ b/src/main/java/com/alibaba/excel/metadata/GlobalConfiguration.java @@ -2,11 +2,14 @@ package com.alibaba.excel.metadata; import java.util.Locale; +import lombok.Data; + /** * Global configuration * * @author Jiaju Zhuang */ +@Data public class GlobalConfiguration { /** * Automatic trim includes sheet name and content @@ -32,35 +35,10 @@ public class GlobalConfiguration { */ private Boolean useScientificFormat; - public Boolean getUse1904windowing() { - return use1904windowing; - } - - public void setUse1904windowing(Boolean use1904windowing) { - this.use1904windowing = use1904windowing; - } - - public Boolean getAutoTrim() { - return autoTrim; - } - - public void setAutoTrim(Boolean autoTrim) { - this.autoTrim = autoTrim; - } - - public Locale getLocale() { - return locale; - } - - public void setLocale(Locale locale) { - this.locale = locale; - } - - public Boolean getUseScientificFormat() { - return useScientificFormat; - } - - public void setUseScientificFormat(Boolean useScientificFormat) { - this.useScientificFormat = useScientificFormat; + public GlobalConfiguration() { + this.autoTrim = Boolean.TRUE; + this.use1904windowing = Boolean.FALSE; + this.locale = Locale.getDefault(); + this.useScientificFormat = Boolean.FALSE; } } 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 ab6dfb72..14a708b6 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 @@ -49,19 +49,20 @@ public abstract class AbstractReadHolder extends AbstractHolder implements ReadH public AbstractReadHolder(ReadBasicParameter readBasicParameter, AbstractReadHolder parentAbstractReadHolder, Boolean convertAllFiled) { super(readBasicParameter, parentAbstractReadHolder); - if (readBasicParameter.getUse1904windowing() == null && parentAbstractReadHolder != null) { - getGlobalConfiguration() - .setUse1904windowing(parentAbstractReadHolder.getGlobalConfiguration().getUse1904windowing()); + + if (readBasicParameter.getUse1904windowing() == null) { + if (parentAbstractReadHolder != null) { + getGlobalConfiguration() + .setUse1904windowing(parentAbstractReadHolder.getGlobalConfiguration().getUse1904windowing()); + } } else { getGlobalConfiguration().setUse1904windowing(readBasicParameter.getUse1904windowing()); } if (readBasicParameter.getUseScientificFormat() == null) { - if (parentAbstractReadHolder == null) { - getGlobalConfiguration().setUseScientificFormat(Boolean.FALSE); - } else { - getGlobalConfiguration() - .setUseScientificFormat(parentAbstractReadHolder.getGlobalConfiguration().getUseScientificFormat()); + if (parentAbstractReadHolder != null) { + getGlobalConfiguration().setUseScientificFormat( + parentAbstractReadHolder.getGlobalConfiguration().getUseScientificFormat()); } } else { getGlobalConfiguration().setUseScientificFormat(readBasicParameter.getUseScientificFormat()); @@ -114,7 +115,6 @@ public abstract class AbstractReadHolder extends AbstractHolder implements ReadH } } - @Override public List> readListenerList() { return getReadListenerList(); 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 d667b1b3..4be4907b 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 @@ -96,10 +96,9 @@ public abstract class AbstractWriteHolder extends AbstractHolder implements Writ public AbstractWriteHolder(WriteBasicParameter writeBasicParameter, AbstractWriteHolder parentAbstractWriteHolder, Boolean convertAllField) { super(writeBasicParameter, parentAbstractWriteHolder); + if (writeBasicParameter.getUse1904windowing() == null) { - if (parentAbstractWriteHolder == null) { - getGlobalConfiguration().setUse1904windowing(Boolean.FALSE); - } else { + if (parentAbstractWriteHolder != null) { getGlobalConfiguration() .setUse1904windowing(parentAbstractWriteHolder.getGlobalConfiguration().getUse1904windowing()); } @@ -210,7 +209,6 @@ public abstract class AbstractWriteHolder extends AbstractHolder implements Writ } } - protected void initAnnotationConfig(List handlerList, WriteBasicParameter writeBasicParameter) { if (!HeadKindEnum.CLASS.equals(getExcelWriteHeadProperty().getHeadKind())) { return; @@ -310,7 +308,6 @@ public abstract class AbstractWriteHolder extends AbstractHolder implements Writ handlerList.add(columnWidthStyleStrategy); } - protected Map, List> sortAndClearUpAllHandler( List handlerList, Map, List> parentHandlerMap) { // add @@ -330,7 +327,7 @@ public abstract class AbstractWriteHolder extends AbstractHolder implements Writ for (WriteHandler handler : handlerList) { int order = Integer.MIN_VALUE; if (handler instanceof Order) { - order = ((Order) handler).order(); + order = ((Order)handler).order(); } if (orderExcelWriteHandlerMap.containsKey(order)) { orderExcelWriteHandlerMap.get(order).add(handler); @@ -346,7 +343,7 @@ public abstract class AbstractWriteHolder extends AbstractHolder implements Writ for (Map.Entry> entry : orderExcelWriteHandlerMap.entrySet()) { for (WriteHandler handler : entry.getValue()) { if (handler instanceof NotRepeatExecutor) { - String uniqueValue = ((NotRepeatExecutor) handler).uniqueValue(); + String uniqueValue = ((NotRepeatExecutor)handler).uniqueValue(); if (alreadyExistedHandlerSet.contains(uniqueValue)) { continue; } diff --git a/src/test/java/com/alibaba/easyexcel/test/core/annotation/AnnotationIndexAndNameDataTest.java b/src/test/java/com/alibaba/easyexcel/test/core/annotation/AnnotationIndexAndNameDataTest.java index 5f12bb33..937cf665 100644 --- a/src/test/java/com/alibaba/easyexcel/test/core/annotation/AnnotationIndexAndNameDataTest.java +++ b/src/test/java/com/alibaba/easyexcel/test/core/annotation/AnnotationIndexAndNameDataTest.java @@ -39,7 +39,7 @@ public class AnnotationIndexAndNameDataTest { } @Test - public void t03ReadAndWrite03() { + public void t03ReadAndWriteCsv() { readAndWrite(fileCsv); } diff --git a/src/test/java/com/alibaba/easyexcel/test/core/celldata/CellDataDataTest.java b/src/test/java/com/alibaba/easyexcel/test/core/celldata/CellDataDataTest.java index db4bf80b..0fd2f225 100644 --- a/src/test/java/com/alibaba/easyexcel/test/core/celldata/CellDataDataTest.java +++ b/src/test/java/com/alibaba/easyexcel/test/core/celldata/CellDataDataTest.java @@ -25,11 +25,14 @@ public class CellDataDataTest { private static File file07; private static File file03; + private static File fileCsv; + @BeforeClass public static void init() { file07 = TestFileUtil.createNewFile("cellData07.xlsx"); file03 = TestFileUtil.createNewFile("cellData03.xls"); + fileCsv = TestFileUtil.createNewFile("cellDataCsv.csv"); } @Test @@ -42,6 +45,12 @@ public class CellDataDataTest { readAndWrite(file03); } + @Test + public void t03ReadAndWriteCsv() throws Exception { + readAndWrite(fileCsv); + } + + private void readAndWrite(File file) throws Exception { EasyExcel.write(file, CellDataWriteData.class).sheet().doWrite(data()); EasyExcel.read(file, CellDataReadData.class, new CellDataDataListener()).sheet().doRead();