diff --git a/src/main/java/com/alibaba/excel/ExcelReader.java b/src/main/java/com/alibaba/excel/ExcelReader.java index a15c74da..a04a832a 100644 --- a/src/main/java/com/alibaba/excel/ExcelReader.java +++ b/src/main/java/com/alibaba/excel/ExcelReader.java @@ -31,11 +31,23 @@ public class ExcelReader { * }AnalysisContext * @param eventListener */ + @Deprecated public ExcelReader(InputStream in, ExcelTypeEnum excelTypeEnum, Object customContent, AnalysisEventListener eventListener) { this(in, excelTypeEnum, customContent, eventListener, true); } + /** + * @param in + * @param customContent {@link AnalysisEventListener#invoke(Object, AnalysisContext) + * }AnalysisContext + * @param eventListener + */ + public ExcelReader(InputStream in, Object customContent, + AnalysisEventListener eventListener) { + this(in, customContent, eventListener, true); + } + /** * old 1.1.0 * @param param @@ -54,12 +66,27 @@ public class ExcelReader { * @param eventListener * @param trim */ + @Deprecated public ExcelReader(InputStream in, ExcelTypeEnum excelTypeEnum, Object customContent, AnalysisEventListener eventListener, boolean trim) { validateParam(in, excelTypeEnum, eventListener); analyser.init(in, excelTypeEnum, customContent, eventListener, trim); } + /** + * @param in + * @param customContent {@link AnalysisEventListener#invoke(Object, AnalysisContext) + * }AnalysisContext + * @param eventListener + * @param trim + */ + public ExcelReader(InputStream in, Object customContent, + AnalysisEventListener eventListener, boolean trim) { + ExcelTypeEnum excelTypeEnum = ExcelTypeEnum.valueOf(in); + validateParam(in, excelTypeEnum, eventListener); + analyser.init(in, excelTypeEnum, customContent, eventListener, trim); + } + /** */ public void read() { diff --git a/src/main/java/com/alibaba/excel/analysis/v07/XlsxRowHandler.java b/src/main/java/com/alibaba/excel/analysis/v07/XlsxRowHandler.java index 12be50fe..4788ff21 100644 --- a/src/main/java/com/alibaba/excel/analysis/v07/XlsxRowHandler.java +++ b/src/main/java/com/alibaba/excel/analysis/v07/XlsxRowHandler.java @@ -18,7 +18,6 @@ import static com.alibaba.excel.constant.ExcelXmlConstants.*; /** * @author jipengfei - * @date 2017/08/23 */ public class XlsxRowHandler extends DefaultHandler { diff --git a/src/main/java/com/alibaba/excel/analysis/v07/XlsxSaxAnalyser.java b/src/main/java/com/alibaba/excel/analysis/v07/XlsxSaxAnalyser.java index 5d761f48..cfc30f7e 100644 --- a/src/main/java/com/alibaba/excel/analysis/v07/XlsxSaxAnalyser.java +++ b/src/main/java/com/alibaba/excel/analysis/v07/XlsxSaxAnalyser.java @@ -25,7 +25,6 @@ import java.util.List; /** * @author jipengfei - * @date 2017/08/27 */ public class XlsxSaxAnalyser extends BaseSaxAnalyser { diff --git a/src/main/java/com/alibaba/excel/annotation/ExcelColumnNum.java b/src/main/java/com/alibaba/excel/annotation/ExcelColumnNum.java index 6a53efa1..0958372a 100644 --- a/src/main/java/com/alibaba/excel/annotation/ExcelColumnNum.java +++ b/src/main/java/com/alibaba/excel/annotation/ExcelColumnNum.java @@ -7,7 +7,6 @@ import java.lang.annotation.*; * Field column num at excel head * * @author jipengfei - * @date 2017/03/19 */ @Target(ElementType.FIELD) @Retention(RetentionPolicy.RUNTIME) diff --git a/src/main/java/com/alibaba/excel/context/GenerateContextImpl.java b/src/main/java/com/alibaba/excel/context/GenerateContextImpl.java index 9c2f171c..a79ca3c4 100644 --- a/src/main/java/com/alibaba/excel/context/GenerateContextImpl.java +++ b/src/main/java/com/alibaba/excel/context/GenerateContextImpl.java @@ -3,6 +3,7 @@ package com.alibaba.excel.context; import com.alibaba.excel.metadata.*; import com.alibaba.excel.metadata.CellRange; import com.alibaba.excel.metadata.Table; +import com.alibaba.excel.metadata.TableStyle; import com.alibaba.excel.support.ExcelTypeEnum; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.poifs.filesystem.POIFSFileSystem; diff --git a/src/main/java/com/alibaba/excel/event/AnalysisEventRegisterCenter.java b/src/main/java/com/alibaba/excel/event/AnalysisEventRegisterCenter.java index 5c557ecf..7cc50678 100644 --- a/src/main/java/com/alibaba/excel/event/AnalysisEventRegisterCenter.java +++ b/src/main/java/com/alibaba/excel/event/AnalysisEventRegisterCenter.java @@ -8,14 +8,14 @@ package com.alibaba.excel.event; public interface AnalysisEventRegisterCenter { /** - * @param name - * @param listener + * @param name 监听名定义 + * @param listener 具体实现 */ void appendLister(String name, AnalysisEventListener listener); /** - * @param event + * @param event 事件 */ void notifyListeners(OneRowAnalysisFinishEvent event); diff --git a/src/main/java/com/alibaba/excel/event/OneRowAnalysisFinishEvent.java b/src/main/java/com/alibaba/excel/event/OneRowAnalysisFinishEvent.java index a9e9966d..9ebdb5a1 100644 --- a/src/main/java/com/alibaba/excel/event/OneRowAnalysisFinishEvent.java +++ b/src/main/java/com/alibaba/excel/event/OneRowAnalysisFinishEvent.java @@ -2,7 +2,6 @@ package com.alibaba.excel.event; /** * @author jipengfei - * @date 2017/07/21 */ public class OneRowAnalysisFinishEvent { diff --git a/src/main/java/com/alibaba/excel/metadata/CellRange.java b/src/main/java/com/alibaba/excel/metadata/CellRange.java index 7fac539b..6805526e 100644 --- a/src/main/java/com/alibaba/excel/metadata/CellRange.java +++ b/src/main/java/com/alibaba/excel/metadata/CellRange.java @@ -2,7 +2,6 @@ package com.alibaba.excel.metadata; /** * @author jipengfei - * @date 2017/06/02 */ public class CellRange { diff --git a/src/main/java/com/alibaba/excel/metadata/ExcelColumnProperty.java b/src/main/java/com/alibaba/excel/metadata/ExcelColumnProperty.java index 8b3ed714..cc6442f1 100644 --- a/src/main/java/com/alibaba/excel/metadata/ExcelColumnProperty.java +++ b/src/main/java/com/alibaba/excel/metadata/ExcelColumnProperty.java @@ -6,7 +6,6 @@ import java.util.List; /** * @author jipengfei - * @date 2017/05/31 */ public class ExcelColumnProperty implements Comparable { diff --git a/src/main/java/com/alibaba/excel/metadata/ExcelHeadProperty.java b/src/main/java/com/alibaba/excel/metadata/ExcelHeadProperty.java index 675c1a4d..7b15a5ce 100644 --- a/src/main/java/com/alibaba/excel/metadata/ExcelHeadProperty.java +++ b/src/main/java/com/alibaba/excel/metadata/ExcelHeadProperty.java @@ -9,7 +9,6 @@ import java.util.*; /** * * @author jipengfei - * @date 2017/05/31 */ public class ExcelHeadProperty { diff --git a/src/main/java/com/alibaba/excel/metadata/Font.java b/src/main/java/com/alibaba/excel/metadata/Font.java index 3eea50bf..45330119 100644 --- a/src/main/java/com/alibaba/excel/metadata/Font.java +++ b/src/main/java/com/alibaba/excel/metadata/Font.java @@ -3,7 +3,6 @@ package com.alibaba.excel.metadata; /** * * @author jipengfei - * @date 2017/05/24 */ public class Font { diff --git a/src/main/java/com/alibaba/excel/metadata/Table.java b/src/main/java/com/alibaba/excel/metadata/Table.java index c4b3a8ec..a0abeed6 100644 --- a/src/main/java/com/alibaba/excel/metadata/Table.java +++ b/src/main/java/com/alibaba/excel/metadata/Table.java @@ -4,7 +4,6 @@ import java.util.List; /** * @author jipengfei - * @date 2017/05/16 */ public class Table { /** diff --git a/src/main/java/com/alibaba/excel/metadata/TableStyle.java b/src/main/java/com/alibaba/excel/metadata/TableStyle.java index 6618197e..228019c3 100644 --- a/src/main/java/com/alibaba/excel/metadata/TableStyle.java +++ b/src/main/java/com/alibaba/excel/metadata/TableStyle.java @@ -4,7 +4,6 @@ import org.apache.poi.ss.usermodel.IndexedColors; /** * @author jipengfei - * @date 2017/05/24 */ public class TableStyle { diff --git a/src/main/java/com/alibaba/excel/parameter/ExcelWriteParam.java b/src/main/java/com/alibaba/excel/parameter/ExcelWriteParam.java index 53e5d509..dd6ca1ee 100644 --- a/src/main/java/com/alibaba/excel/parameter/ExcelWriteParam.java +++ b/src/main/java/com/alibaba/excel/parameter/ExcelWriteParam.java @@ -8,7 +8,6 @@ import java.io.OutputStream; * {@link com.alibaba.excel.ExcelWriter} * * @author jipengfei - * @date 2017/05/15 */ @Deprecated public class ExcelWriteParam { diff --git a/src/main/java/com/alibaba/excel/support/ExcelTypeEnum.java b/src/main/java/com/alibaba/excel/support/ExcelTypeEnum.java index 37a84782..8ba87fe7 100644 --- a/src/main/java/com/alibaba/excel/support/ExcelTypeEnum.java +++ b/src/main/java/com/alibaba/excel/support/ExcelTypeEnum.java @@ -1,5 +1,10 @@ package com.alibaba.excel.support; +import org.apache.poi.poifs.filesystem.FileMagic; + +import java.io.IOException; +import java.io.InputStream; + /** * * @author jipengfei @@ -21,4 +26,19 @@ public enum ExcelTypeEnum { public void setValue(String value) { this.value = value; } + public static ExcelTypeEnum valueOf(InputStream inputStream){ + try { + FileMagic fileMagic = FileMagic.valueOf(inputStream); + if(FileMagic.OLE2.equals(fileMagic)){ + return XLS; + } + if(FileMagic.OOXML.equals(fileMagic)){ + return XLSX; + } + throw new IllegalArgumentException("excelTypeEnum can not null"); + + } catch (IOException e) { + throw new RuntimeException(e); + } + } } diff --git a/src/main/java/com/alibaba/excel/util/IndexValueConverter.java b/src/main/java/com/alibaba/excel/util/IndexValueConverter.java index dc6f13f2..90548a7c 100644 --- a/src/main/java/com/alibaba/excel/util/IndexValueConverter.java +++ b/src/main/java/com/alibaba/excel/util/IndexValueConverter.java @@ -9,7 +9,6 @@ import java.util.Stack; /** * 去除空Cell * @author jipengfei - * @date 2017/04/13 */ public class IndexValueConverter { public static List converter(List i_list) { diff --git a/src/main/java/com/alibaba/excel/util/POITempFile.java b/src/main/java/com/alibaba/excel/util/POITempFile.java index c342968a..6382255f 100644 --- a/src/main/java/com/alibaba/excel/util/POITempFile.java +++ b/src/main/java/com/alibaba/excel/util/POITempFile.java @@ -5,7 +5,6 @@ import java.io.File; /** * * @author jipengfei - * @date 2017/06/22 */ public class POITempFile { diff --git a/src/main/java/com/alibaba/excel/util/PositionUtils.java b/src/main/java/com/alibaba/excel/util/PositionUtils.java index f5f084ac..37a87dd5 100644 --- a/src/main/java/com/alibaba/excel/util/PositionUtils.java +++ b/src/main/java/com/alibaba/excel/util/PositionUtils.java @@ -2,7 +2,6 @@ package com.alibaba.excel.util; /** * @author jipengfei - * @date 2017/08/27 */ public class PositionUtils { diff --git a/src/main/java/com/alibaba/excel/util/TypeUtil.java b/src/main/java/com/alibaba/excel/util/TypeUtil.java index dbac004b..564bf2e5 100644 --- a/src/main/java/com/alibaba/excel/util/TypeUtil.java +++ b/src/main/java/com/alibaba/excel/util/TypeUtil.java @@ -14,7 +14,6 @@ import java.util.regex.Pattern; /** * @author jipengfei - * @date 2017/03/15 */ public class TypeUtil { diff --git a/src/main/java/com/alibaba/excel/write/ExcelBuilderImpl.java b/src/main/java/com/alibaba/excel/write/ExcelBuilderImpl.java index 998078db..b81b73d8 100644 --- a/src/main/java/com/alibaba/excel/write/ExcelBuilderImpl.java +++ b/src/main/java/com/alibaba/excel/write/ExcelBuilderImpl.java @@ -21,7 +21,6 @@ import java.util.List; /** * @author jipengfei - * @date 2017/05/27 */ public class ExcelBuilderImpl implements ExcelBuilder { diff --git a/src/main`java/com/alibaba/excel/annotation/FieldType.java b/src/main`java/com/alibaba/excel/annotation/FieldType.java new file mode 100644 index 00000000..73729959 --- /dev/null +++ b/src/main`java/com/alibaba/excel/annotation/FieldType.java @@ -0,0 +1,11 @@ +package com.alibaba.excel.annotation; + +/** + * + * @author jipengfei + */ +public enum FieldType { + + STRING, INT, LONG, DATE, BOOLEAN, DOUBLE,EMPTY; + +} diff --git a/src/main`java/com/alibaba/excel/constant/ExcelXmlConstants.java b/src/main`java/com/alibaba/excel/constant/ExcelXmlConstants.java new file mode 100644 index 00000000..dcd2d5a4 --- /dev/null +++ b/src/main`java/com/alibaba/excel/constant/ExcelXmlConstants.java @@ -0,0 +1,17 @@ +package com.alibaba.excel.constant; + +/** + * @author jipengfei + */ +public class ExcelXmlConstants { + public static final String DIMENSION = "dimension"; + public static final String DIMENSION_REF = "ref"; + public static final String POSITION = "r"; + + public static final String ROW_TAG = "row"; + public static final String CELL_TAG = "c"; + public static final String CELL_VALUE_TAG = "v"; + + public static final String CELL_VALUE_TAG_1 = "t"; + +} diff --git a/src/test/java/function/model/ExcelPropertyIndexModel.java b/src/test/java/function/model/ExcelPropertyIndexModel.java index 0009615f..ad9a95de 100644 --- a/src/test/java/function/model/ExcelPropertyIndexModel.java +++ b/src/test/java/function/model/ExcelPropertyIndexModel.java @@ -5,7 +5,6 @@ import com.alibaba.excel.metadata.BaseRowModel; /** * @author jipengfei - * @date 2017/05/31 */ public class ExcelPropertyIndexModel extends BaseRowModel { diff --git a/src/test/java/read/v03/XLS2003FunctionTest.java b/src/test/java/read/v03/XLS2003FunctionTest.java index 3770375e..a94de404 100644 --- a/src/test/java/read/v03/XLS2003FunctionTest.java +++ b/src/test/java/read/v03/XLS2003FunctionTest.java @@ -19,12 +19,12 @@ public class XLS2003FunctionTest extends TestCase { @Test public void testExcel2003NoModel() { - InputStream inputStream = getInputStream("loan1.xls"); + InputStream inputStream = getInputStream("2003.xls"); try { // 解析每行结果在listener中处理 ExcelListener listener = new ExcelListener(); - ExcelReader excelReader = new ExcelReader(inputStream, ExcelTypeEnum.XLS, null, listener); + ExcelReader excelReader = new ExcelReader(inputStream, null, listener); excelReader.read(); } catch (Exception e) { e.printStackTrace(); diff --git a/src/test/java/read/v07/Read2007Xlsx.java b/src/test/java/read/v07/Read2007Xlsx.java index 672caef9..f2e39c34 100644 --- a/src/test/java/read/v07/Read2007Xlsx.java +++ b/src/test/java/read/v07/Read2007Xlsx.java @@ -23,11 +23,11 @@ public class Read2007Xlsx { //创建没有自定义模型,没有sheet的解析器,默认解析所有sheet解析结果以List的方式通知监听者 @Test public void noModel() { - InputStream inputStream = getInputStream("需要分批关闭客户名单 2018.8.24.xlsx"); + InputStream inputStream = getInputStream("2007.xlsx"); final List> ll = new ArrayList>(); try { - ExcelReader reader = new ExcelReader(inputStream, ExcelTypeEnum.XLSX, null, + ExcelReader reader = new ExcelReader(inputStream, null, new AnalysisEventListener>() { @Override public void invoke(List object, AnalysisContext context) { diff --git a/src/test/java/read/v07/listener/Excel2007WithJavaModelAnalysisListener.java b/src/test/java/read/v07/listener/Excel2007WithJavaModelAnalysisListener.java index 2248a749..e52bcdfd 100644 --- a/src/test/java/read/v07/listener/Excel2007WithJavaModelAnalysisListener.java +++ b/src/test/java/read/v07/listener/Excel2007WithJavaModelAnalysisListener.java @@ -12,7 +12,6 @@ import java.util.List; /** * @author jipengfei - * @date 2017/08/27 */ public class Excel2007WithJavaModelAnalysisListener extends AnalysisEventListener {