提交 c598a704 编写于 作者: J jipengfei.jpf

阿里內部最新版本开源,为了稳定性07版本解析修改为底层使用POI解析。

上级 bde93f94
...@@ -31,11 +31,23 @@ public class ExcelReader { ...@@ -31,11 +31,23 @@ public class ExcelReader {
* }AnalysisContext * }AnalysisContext
* @param eventListener * @param eventListener
*/ */
@Deprecated
public ExcelReader(InputStream in, ExcelTypeEnum excelTypeEnum, Object customContent, public ExcelReader(InputStream in, ExcelTypeEnum excelTypeEnum, Object customContent,
AnalysisEventListener eventListener) { AnalysisEventListener eventListener) {
this(in, excelTypeEnum, customContent, eventListener, true); 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 * old 1.1.0
* @param param * @param param
...@@ -54,12 +66,27 @@ public class ExcelReader { ...@@ -54,12 +66,27 @@ public class ExcelReader {
* @param eventListener * @param eventListener
* @param trim * @param trim
*/ */
@Deprecated
public ExcelReader(InputStream in, ExcelTypeEnum excelTypeEnum, Object customContent, public ExcelReader(InputStream in, ExcelTypeEnum excelTypeEnum, Object customContent,
AnalysisEventListener eventListener, boolean trim) { AnalysisEventListener eventListener, boolean trim) {
validateParam(in, excelTypeEnum, eventListener); validateParam(in, excelTypeEnum, eventListener);
analyser.init(in, excelTypeEnum, customContent, eventListener, trim); 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() { public void read() {
......
...@@ -18,7 +18,6 @@ import static com.alibaba.excel.constant.ExcelXmlConstants.*; ...@@ -18,7 +18,6 @@ import static com.alibaba.excel.constant.ExcelXmlConstants.*;
/** /**
* @author jipengfei * @author jipengfei
* @date 2017/08/23
*/ */
public class XlsxRowHandler extends DefaultHandler { public class XlsxRowHandler extends DefaultHandler {
......
...@@ -25,7 +25,6 @@ import java.util.List; ...@@ -25,7 +25,6 @@ import java.util.List;
/** /**
* @author jipengfei * @author jipengfei
* @date 2017/08/27
*/ */
public class XlsxSaxAnalyser extends BaseSaxAnalyser { public class XlsxSaxAnalyser extends BaseSaxAnalyser {
......
...@@ -7,7 +7,6 @@ import java.lang.annotation.*; ...@@ -7,7 +7,6 @@ import java.lang.annotation.*;
* Field column num at excel head * Field column num at excel head
* *
* @author jipengfei * @author jipengfei
* @date 2017/03/19
*/ */
@Target(ElementType.FIELD) @Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
......
...@@ -3,6 +3,7 @@ package com.alibaba.excel.context; ...@@ -3,6 +3,7 @@ package com.alibaba.excel.context;
import com.alibaba.excel.metadata.*; import com.alibaba.excel.metadata.*;
import com.alibaba.excel.metadata.CellRange; import com.alibaba.excel.metadata.CellRange;
import com.alibaba.excel.metadata.Table; import com.alibaba.excel.metadata.Table;
import com.alibaba.excel.metadata.TableStyle;
import com.alibaba.excel.support.ExcelTypeEnum; import com.alibaba.excel.support.ExcelTypeEnum;
import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.poifs.filesystem.POIFSFileSystem;
......
...@@ -8,14 +8,14 @@ package com.alibaba.excel.event; ...@@ -8,14 +8,14 @@ package com.alibaba.excel.event;
public interface AnalysisEventRegisterCenter { public interface AnalysisEventRegisterCenter {
/** /**
* @param name * @param name 监听名定义
* @param listener * @param listener 具体实现
*/ */
void appendLister(String name, AnalysisEventListener listener); void appendLister(String name, AnalysisEventListener listener);
/** /**
* @param event * @param event 事件
*/ */
void notifyListeners(OneRowAnalysisFinishEvent event); void notifyListeners(OneRowAnalysisFinishEvent event);
......
...@@ -2,7 +2,6 @@ package com.alibaba.excel.event; ...@@ -2,7 +2,6 @@ package com.alibaba.excel.event;
/** /**
* @author jipengfei * @author jipengfei
* @date 2017/07/21
*/ */
public class OneRowAnalysisFinishEvent { public class OneRowAnalysisFinishEvent {
......
...@@ -2,7 +2,6 @@ package com.alibaba.excel.metadata; ...@@ -2,7 +2,6 @@ package com.alibaba.excel.metadata;
/** /**
* @author jipengfei * @author jipengfei
* @date 2017/06/02
*/ */
public class CellRange { public class CellRange {
......
...@@ -6,7 +6,6 @@ import java.util.List; ...@@ -6,7 +6,6 @@ import java.util.List;
/** /**
* @author jipengfei * @author jipengfei
* @date 2017/05/31
*/ */
public class ExcelColumnProperty implements Comparable<ExcelColumnProperty> { public class ExcelColumnProperty implements Comparable<ExcelColumnProperty> {
......
...@@ -9,7 +9,6 @@ import java.util.*; ...@@ -9,7 +9,6 @@ import java.util.*;
/** /**
* *
* @author jipengfei * @author jipengfei
* @date 2017/05/31
*/ */
public class ExcelHeadProperty { public class ExcelHeadProperty {
......
...@@ -3,7 +3,6 @@ package com.alibaba.excel.metadata; ...@@ -3,7 +3,6 @@ package com.alibaba.excel.metadata;
/** /**
* *
* @author jipengfei * @author jipengfei
* @date 2017/05/24
*/ */
public class Font { public class Font {
......
...@@ -4,7 +4,6 @@ import java.util.List; ...@@ -4,7 +4,6 @@ import java.util.List;
/** /**
* @author jipengfei * @author jipengfei
* @date 2017/05/16
*/ */
public class Table { public class Table {
/** /**
......
...@@ -4,7 +4,6 @@ import org.apache.poi.ss.usermodel.IndexedColors; ...@@ -4,7 +4,6 @@ import org.apache.poi.ss.usermodel.IndexedColors;
/** /**
* @author jipengfei * @author jipengfei
* @date 2017/05/24
*/ */
public class TableStyle { public class TableStyle {
......
...@@ -8,7 +8,6 @@ import java.io.OutputStream; ...@@ -8,7 +8,6 @@ import java.io.OutputStream;
* {@link com.alibaba.excel.ExcelWriter} * {@link com.alibaba.excel.ExcelWriter}
* *
* @author jipengfei * @author jipengfei
* @date 2017/05/15
*/ */
@Deprecated @Deprecated
public class ExcelWriteParam { public class ExcelWriteParam {
......
package com.alibaba.excel.support; package com.alibaba.excel.support;
import org.apache.poi.poifs.filesystem.FileMagic;
import java.io.IOException;
import java.io.InputStream;
/** /**
* *
* @author jipengfei * @author jipengfei
...@@ -21,4 +26,19 @@ public enum ExcelTypeEnum { ...@@ -21,4 +26,19 @@ public enum ExcelTypeEnum {
public void setValue(String value) { public void setValue(String value) {
this.value = 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);
}
}
} }
...@@ -9,7 +9,6 @@ import java.util.Stack; ...@@ -9,7 +9,6 @@ import java.util.Stack;
/** /**
* 去除空Cell * 去除空Cell
* @author jipengfei * @author jipengfei
* @date 2017/04/13
*/ */
public class IndexValueConverter { public class IndexValueConverter {
public static List<String> converter(List<IndexValue> i_list) { public static List<String> converter(List<IndexValue> i_list) {
......
...@@ -5,7 +5,6 @@ import java.io.File; ...@@ -5,7 +5,6 @@ import java.io.File;
/** /**
* *
* @author jipengfei * @author jipengfei
* @date 2017/06/22
*/ */
public class POITempFile { public class POITempFile {
......
...@@ -2,7 +2,6 @@ package com.alibaba.excel.util; ...@@ -2,7 +2,6 @@ package com.alibaba.excel.util;
/** /**
* @author jipengfei * @author jipengfei
* @date 2017/08/27
*/ */
public class PositionUtils { public class PositionUtils {
......
...@@ -14,7 +14,6 @@ import java.util.regex.Pattern; ...@@ -14,7 +14,6 @@ import java.util.regex.Pattern;
/** /**
* @author jipengfei * @author jipengfei
* @date 2017/03/15
*/ */
public class TypeUtil { public class TypeUtil {
......
...@@ -21,7 +21,6 @@ import java.util.List; ...@@ -21,7 +21,6 @@ import java.util.List;
/** /**
* @author jipengfei * @author jipengfei
* @date 2017/05/27
*/ */
public class ExcelBuilderImpl implements ExcelBuilder { public class ExcelBuilderImpl implements ExcelBuilder {
......
package com.alibaba.excel.annotation;
/**
*
* @author jipengfei
*/
public enum FieldType {
STRING, INT, LONG, DATE, BOOLEAN, DOUBLE,EMPTY;
}
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";
}
...@@ -5,7 +5,6 @@ import com.alibaba.excel.metadata.BaseRowModel; ...@@ -5,7 +5,6 @@ import com.alibaba.excel.metadata.BaseRowModel;
/** /**
* @author jipengfei * @author jipengfei
* @date 2017/05/31
*/ */
public class ExcelPropertyIndexModel extends BaseRowModel { public class ExcelPropertyIndexModel extends BaseRowModel {
......
...@@ -19,12 +19,12 @@ public class XLS2003FunctionTest extends TestCase { ...@@ -19,12 +19,12 @@ public class XLS2003FunctionTest extends TestCase {
@Test @Test
public void testExcel2003NoModel() { public void testExcel2003NoModel() {
InputStream inputStream = getInputStream("loan1.xls"); InputStream inputStream = getInputStream("2003.xls");
try { try {
// 解析每行结果在listener中处理 // 解析每行结果在listener中处理
ExcelListener listener = new ExcelListener(); ExcelListener listener = new ExcelListener();
ExcelReader excelReader = new ExcelReader(inputStream, ExcelTypeEnum.XLS, null, listener); ExcelReader excelReader = new ExcelReader(inputStream, null, listener);
excelReader.read(); excelReader.read();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
......
...@@ -23,11 +23,11 @@ public class Read2007Xlsx { ...@@ -23,11 +23,11 @@ public class Read2007Xlsx {
//创建没有自定义模型,没有sheet的解析器,默认解析所有sheet解析结果以List<String>的方式通知监听者 //创建没有自定义模型,没有sheet的解析器,默认解析所有sheet解析结果以List<String>的方式通知监听者
@Test @Test
public void noModel() { public void noModel() {
InputStream inputStream = getInputStream("需要分批关闭客户名单 2018.8.24.xlsx"); InputStream inputStream = getInputStream("2007.xlsx");
final List<List<String>> ll = new ArrayList<List<String>>(); final List<List<String>> ll = new ArrayList<List<String>>();
try { try {
ExcelReader reader = new ExcelReader(inputStream, ExcelTypeEnum.XLSX, null, ExcelReader reader = new ExcelReader(inputStream, null,
new AnalysisEventListener<List<String>>() { new AnalysisEventListener<List<String>>() {
@Override @Override
public void invoke(List<String> object, AnalysisContext context) { public void invoke(List<String> object, AnalysisContext context) {
......
...@@ -12,7 +12,6 @@ import java.util.List; ...@@ -12,7 +12,6 @@ import java.util.List;
/** /**
* @author jipengfei * @author jipengfei
* @date 2017/08/27
*/ */
public class Excel2007WithJavaModelAnalysisListener extends AnalysisEventListener { public class Excel2007WithJavaModelAnalysisListener extends AnalysisEventListener {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册