From c598a70424139594880623cfd3e02358e04f74c9 Mon Sep 17 00:00:00 2001 From: "jipengfei.jpf" Date: Mon, 15 Oct 2018 15:50:23 +0800 Subject: [PATCH] =?UTF-8?q?=E9=98=BF=E9=87=8C=E5=85=A7=E9=83=A8=E6=9C=80?= =?UTF-8?q?=E6=96=B0=E7=89=88=E6=9C=AC=E5=BC=80=E6=BA=90=EF=BC=8C=E4=B8=BA?= =?UTF-8?q?=E4=BA=86=E7=A8=B3=E5=AE=9A=E6=80=A707=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E8=A7=A3=E6=9E=90=E4=BF=AE=E6=94=B9=E4=B8=BA=E5=BA=95=E5=B1=82?= =?UTF-8?q?=E4=BD=BF=E7=94=A8POI=E8=A7=A3=E6=9E=90=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/alibaba/excel/ExcelReader.java | 27 +++++++++++++++++++ .../excel/analysis/v07/XlsxRowHandler.java | 1 - .../excel/analysis/v07/XlsxSaxAnalyser.java | 1 - .../excel/annotation/ExcelColumnNum.java | 1 - .../excel/context/GenerateContextImpl.java | 1 + .../event/AnalysisEventRegisterCenter.java | 6 ++--- .../event/OneRowAnalysisFinishEvent.java | 1 - .../com/alibaba/excel/metadata/CellRange.java | 1 - .../excel/metadata/ExcelColumnProperty.java | 1 - .../excel/metadata/ExcelHeadProperty.java | 1 - .../java/com/alibaba/excel/metadata/Font.java | 1 - .../com/alibaba/excel/metadata/Table.java | 1 - .../alibaba/excel/metadata/TableStyle.java | 1 - .../excel/parameter/ExcelWriteParam.java | 1 - .../alibaba/excel/support/ExcelTypeEnum.java | 20 ++++++++++++++ .../excel/util/IndexValueConverter.java | 1 - .../com/alibaba/excel/util/POITempFile.java | 1 - .../com/alibaba/excel/util/PositionUtils.java | 1 - .../java/com/alibaba/excel/util/TypeUtil.java | 1 - .../alibaba/excel/write/ExcelBuilderImpl.java | 1 - .../alibaba/excel/annotation/FieldType.java | 11 ++++++++ .../excel/constant/ExcelXmlConstants.java | 17 ++++++++++++ .../model/ExcelPropertyIndexModel.java | 1 - .../java/read/v03/XLS2003FunctionTest.java | 4 +-- src/test/java/read/v07/Read2007Xlsx.java | 4 +-- ...xcel2007WithJavaModelAnalysisListener.java | 1 - 26 files changed, 83 insertions(+), 25 deletions(-) create mode 100644 src/main`java/com/alibaba/excel/annotation/FieldType.java create mode 100644 src/main`java/com/alibaba/excel/constant/ExcelXmlConstants.java diff --git a/src/main/java/com/alibaba/excel/ExcelReader.java b/src/main/java/com/alibaba/excel/ExcelReader.java index a15c74d..a04a832 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 12be50f..4788ff2 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 5d761f4..cfc30f7 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 6a53efa..0958372 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 9c2f171..a79ca3c 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 5c557ec..7cc5067 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 a9e9966..9ebdb5a 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 7fac539..6805526 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 8b3ed71..cc6442f 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 675c1a4..7b15a5c 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 3eea50b..4533011 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 c4b3a8e..a0abeed 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 6618197..228019c 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 53e5d50..dd6ca1e 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 37a8478..8ba87fe 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 dc6f13f..90548a7 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 c342968..6382255 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 f5f084a..37a87dd 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 dbac004..564bf2e 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 998078d..b81b73d 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 0000000..7372995 --- /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 0000000..dcd2d5a --- /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 0009615..ad9a95d 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 3770375..a94de40 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 672caef..f2e39c3 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 2248a74..e52bcdf 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 {