* Read key:
@@ -58,6 +58,16 @@ public abstract class AbstractHolder implements ConfigurationHolder {
} else {
globalConfiguration.setAutoTrim(basicParameter.getAutoTrim());
}
+
+ if (basicParameter.getLocale() == null) {
+ if (prentAbstractHolder == null) {
+ globalConfiguration.setLocale(Locale.getDefault());
+ } else {
+ globalConfiguration.setLocale(prentAbstractHolder.getGlobalConfiguration().getLocale());
+ }
+ } else {
+ globalConfiguration.setLocale(basicParameter.getLocale());
+ }
}
public Boolean getNewInitialization() {
diff --git a/src/main/java/com/alibaba/excel/metadata/AbstractParameterBuilder.java b/src/main/java/com/alibaba/excel/metadata/AbstractParameterBuilder.java
new file mode 100644
index 00000000..58400465
--- /dev/null
+++ b/src/main/java/com/alibaba/excel/metadata/AbstractParameterBuilder.java
@@ -0,0 +1,93 @@
+package com.alibaba.excel.metadata;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+
+import com.alibaba.excel.converters.Converter;
+
+/**
+ * ExcelBuilder
+ *
+ * @author Jiaju Zhuang
+ */
+public abstract class AbstractParameterBuilder
+ * 0 - This Sheet has no head ,since the first row are the data
+ *
+ * 1 - This Sheet has one row head , this is the default
+ *
+ * 2 - This Sheet has two row head ,since the third row is the data
+ *
+ * @param headRowNumber
+ * @return
+ */
+ public T headRowNumber(Integer headRowNumber) {
+ parameter().setHeadRowNumber(headRowNumber);
+ return self();
+ }
+
+ /**
+ * Custom type listener run after default
+ *
+ * @param readListener
+ * @return
+ */
+ public T registerReadListener(ReadListener readListener) {
+ if (parameter().getCustomReadListenerList() == null) {
+ parameter().setCustomReadListenerList(new ArrayList
- * 0 - This Sheet has no head ,since the first row are the data
- *
- * 1 - This Sheet has one row head , this is the default
- *
- * 2 - This Sheet has two row head ,since the third row is the data
- *
- * @param headRowNumber
- * @return
- */
- public ExcelReaderBuilder headRowNumber(Integer headRowNumber) {
- readWorkbook.setHeadRowNumber(headRowNumber);
- return this;
- }
-
- /**
- * You can only choose one of the {@link ExcelReaderBuilder#head(List)} and {@link ExcelReaderBuilder#head(Class)}
- *
- * @param head
- * @return
- */
- public ExcelReaderBuilder head(List
- * 0 - This Sheet has no head ,since the first row are the data
- *
- * 1 - This Sheet has one row head , this is the default
- *
- * 2 - This Sheet has two row head ,since the third row is the data
- *
- * @param headRowNumber
- * @return
- */
- public ExcelReaderSheetBuilder headRowNumber(Integer headRowNumber) {
- readSheet.setHeadRowNumber(headRowNumber);
- return this;
- }
-
- /**
- * You can only choose one of the {@link ExcelReaderBuilder#head(List)} and {@link ExcelReaderBuilder#head(Class)}
- *
- * @param head
- * @return
- */
- public ExcelReaderSheetBuilder head(List
@@ -125,38 +58,6 @@ public class ExcelWriterBuilder {
return this;
}
- /**
- * Ignore the custom columns.
- */
- public ExcelWriterBuilder excludeColumnIndexes(Collection> head) {
+ parameter().setHead(head);
+ return self();
+ }
+
+ /**
+ * You can only choose one of the {@link #head(List)} and {@link #head(Class)}
+ *
+ * @param clazz
+ * @return
+ */
+ public T head(Class clazz) {
+ parameter().setClazz(clazz);
+ return self();
+ }
+
+ /**
+ * Custom type conversions override the default.
+ *
+ * @param converter
+ * @return
+ */
+ public T registerConverter(Converter converter) {
+ if (parameter().getCustomConverterList() == null) {
+ parameter().setCustomConverterList(new ArrayList
Locale
object represents a specific geographical, political, or cultural region. This parameter is
+ * used when formatting dates and numbers.
+ *
+ * @param locale
+ * @return
+ */
+ public T locale(Locale locale) {
+ parameter().setLocale(locale);
+ return self();
+ }
+
+ /**
+ * Automatic trim includes sheet name and content
+ *
+ * @param autoTrim
+ * @return
+ */
+ public T autoTrim(Boolean autoTrim) {
+ parameter().setAutoTrim(autoTrim);
+ return self();
+ }
+
+ @SuppressWarnings("unchecked")
+ protected T self() {
+ return (T)this;
+ }
+
+ protected abstract C parameter();
+}
diff --git a/src/main/java/com/alibaba/excel/metadata/DataFormatter.java b/src/main/java/com/alibaba/excel/metadata/DataFormatter.java
index 13bd1628..7467cd26 100644
--- a/src/main/java/com/alibaba/excel/metadata/DataFormatter.java
+++ b/src/main/java/com/alibaba/excel/metadata/DataFormatter.java
@@ -63,7 +63,8 @@ public class DataFormatter {
private static final Pattern daysAsText = Pattern.compile("([d]{3,})", Pattern.CASE_INSENSITIVE);
/** Pattern to find "AM/PM" marker */
- private static final Pattern amPmPattern = Pattern.compile("(([AP])[M/P]*)|(([上下])[午/下]*)", Pattern.CASE_INSENSITIVE);
+ private static final Pattern amPmPattern =
+ Pattern.compile("(([AP])[M/P]*)|(([上下])[午/下]*)", Pattern.CASE_INSENSITIVE);
/** Pattern to find formats with condition ranges e.g. [>=100] */
private static final Pattern rangeConditionalPattern =
@@ -152,7 +153,6 @@ public class DataFormatter {
public DataFormatter(Locale locale, Boolean use1904windowing) {
this.use1904windowing = use1904windowing != null ? use1904windowing : Boolean.FALSE;
this.locale = locale != null ? locale : Locale.getDefault();
- this.locale = Locale.US;
this.dateSymbols = DateFormatSymbols.getInstance(this.locale);
this.decimalSymbols = DecimalFormatSymbols.getInstance(this.locale);
}
diff --git a/src/main/java/com/alibaba/excel/read/builder/AbstractExcelReaderParameterBuilder.java b/src/main/java/com/alibaba/excel/read/builder/AbstractExcelReaderParameterBuilder.java
new file mode 100644
index 00000000..4e5e3702
--- /dev/null
+++ b/src/main/java/com/alibaba/excel/read/builder/AbstractExcelReaderParameterBuilder.java
@@ -0,0 +1,47 @@
+package com.alibaba.excel.read.builder;
+
+import java.util.ArrayList;
+
+import com.alibaba.excel.metadata.AbstractParameterBuilder;
+import com.alibaba.excel.read.listener.ReadListener;
+import com.alibaba.excel.read.metadata.ReadBasicParameter;
+
+/**
+ * Build ExcelBuilder
+ *
+ * @author Jiaju Zhuang
+ */
+public abstract class AbstractExcelReaderParameterBuilder> head) {
- readWorkbook.setHead(head);
- return this;
- }
-
- /**
- * You can only choose one of the {@link ExcelReaderBuilder#head(List)} and {@link ExcelReaderBuilder#head(Class)}
- *
- * @param clazz
- * @return
- */
- public ExcelReaderBuilder head(Class clazz) {
- readWorkbook.setClazz(clazz);
- return this;
- }
-
- /**
- * Custom type conversions override the default.
- *
- * @param converter
- * @return
- */
- public ExcelReaderBuilder registerConverter(Converter converter) {
- if (readWorkbook.getCustomConverterList() == null) {
- readWorkbook.setCustomConverterList(new ArrayList
> head) {
- readSheet.setHead(head);
- return this;
- }
-
- /**
- * You can only choose one of the {@link ExcelReaderBuilder#head(List)} and {@link ExcelReaderBuilder#head(Class)}
- *
- * @param clazz
- * @return
- */
- public ExcelReaderSheetBuilder head(Class clazz) {
- readSheet.setClazz(clazz);
- return this;
- }
-
- /**
- * Custom type conversions override the default.
- *
- * @param converter
- * @return
- */
- public ExcelReaderSheetBuilder registerConverter(Converter converter) {
- if (readSheet.getCustomConverterList() == null) {
- readSheet.setCustomConverterList(new ArrayList
> head) {
- writeWorkbook.setHead(head);
- return this;
- }
-
- /**
- * You can only choose one of the {@link ExcelWriterBuilder#head(List)} and {@link ExcelWriterBuilder#head(Class)}
- *
- * @param clazz
- * @return
- */
- public ExcelWriterBuilder head(Class clazz) {
- writeWorkbook.setClazz(clazz);
- return this;
- }
-
- /**
- * Need Head
- */
- public ExcelWriterBuilder needHead(Boolean needHead) {
- writeWorkbook.setNeedHead(needHead);
- return this;
- }
-
/**
* Default true
*
@@ -80,28 +35,6 @@ public class ExcelWriterBuilder {
return this;
}
- /**
- * Use the default style.Default is true.
- *
- * @param useDefaultStyle
- * @return
- */
- public ExcelWriterBuilder useDefaultStyle(Boolean useDefaultStyle) {
- writeWorkbook.setUseDefaultStyle(useDefaultStyle);
- return this;
- }
-
- /**
- * Whether to automatically merge headers.Default is true.
- *
- * @param automaticMergeHead
- * @return
- */
- public ExcelWriterBuilder automaticMergeHead(Boolean automaticMergeHead) {
- writeWorkbook.setAutomaticMergeHead(automaticMergeHead);
- return this;
- }
-
/**
* Whether the encryption.
*
> head) {
- writeSheet.setHead(head);
- return this;
- }
-
- /**
- * You can only choose one of the {@link ExcelWriterSheetBuilder#head(List)} and
- * {@link ExcelWriterSheetBuilder#head(Class)}
- *
- * @param clazz
- * @return
- */
- public ExcelWriterSheetBuilder head(Class clazz) {
- writeSheet.setClazz(clazz);
- return this;
- }
-
- /**
- * Need Head
- */
- public ExcelWriterSheetBuilder needHead(Boolean needHead) {
- writeSheet.setNeedHead(needHead);
- return this;
- }
-
- /**
- * Use the default style.Default is true.
- *
- * @param useDefaultStyle
- * @return
- */
- public ExcelWriterSheetBuilder useDefaultStyle(Boolean useDefaultStyle) {
- writeSheet.setUseDefaultStyle(useDefaultStyle);
- return this;
- }
-
- /**
- * Whether to automatically merge headers.Default is true.
- *
- * @param automaticMergeHead
- * @return
- */
- public ExcelWriterSheetBuilder automaticMergeHead(Boolean automaticMergeHead) {
- writeSheet.setAutomaticMergeHead(automaticMergeHead);
- return this;
- }
-
- /**
- * Custom type conversions override the default.
- *
- * @param converter
- * @return
- */
- public ExcelWriterSheetBuilder registerConverter(Converter converter) {
- if (writeSheet.getCustomConverterList() == null) {
- writeSheet.setCustomConverterList(new ArrayList
> head) {
- writeTable.setHead(head);
- return this;
- }
-
- /**
- * You can only choose one of the {@link ExcelWriterTableBuilder#head(List)} and
- * {@link ExcelWriterTableBuilder#head(Class)}
- *
- * @param clazz
- * @return
- */
- public ExcelWriterTableBuilder head(Class clazz) {
- writeTable.setClazz(clazz);
- return this;
- }
-
- /**
- * Need Head
- */
- public ExcelWriterTableBuilder needHead(Boolean needHead) {
- writeTable.setNeedHead(needHead);
- return this;
- }
-
- /**
- * Use the default style.Default is true.
- *
- * @param useDefaultStyle
- * @return
- */
- public ExcelWriterTableBuilder useDefaultStyle(Boolean useDefaultStyle) {
- writeTable.setUseDefaultStyle(useDefaultStyle);
- return this;
- }
-
- /**
- * Whether to automatically merge headers.Default is true.
- *
- * @param automaticMergeHead
- * @return
- */
- public ExcelWriterTableBuilder automaticMergeHead(Boolean automaticMergeHead) {
- writeTable.setAutomaticMergeHead(automaticMergeHead);
- return this;
- }
-
- /**
- * Custom type conversions override the default.
- *
- * @param converter
- * @return
- */
- public ExcelWriterTableBuilder registerConverter(Converter converter) {
- if (writeTable.getCustomConverterList() == null) {
- writeTable.setCustomConverterList(new ArrayList
> head() {
@@ -72,4 +101,14 @@ public class Wirte {
return list;
}
+ private List