ExcelReader.java 3.9 KB
Newer Older
J
update  
jipengfei.jpf 已提交
1 2
package com.alibaba.excel;

3 4 5 6 7
import com.alibaba.excel.analysis.ExcelAnalyser;
import com.alibaba.excel.analysis.ExcelAnalyserImpl;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.excel.metadata.BaseRowModel;
J
update  
jipengfei.jpf 已提交
8
import com.alibaba.excel.metadata.Sheet;
9
import com.alibaba.excel.parameter.AnalysisParam;
J
update  
jipengfei.jpf 已提交
10 11
import com.alibaba.excel.support.ExcelTypeEnum;

12 13 14
import java.io.InputStream;
import java.util.List;

J
update  
jipengfei.jpf 已提交
15
/**
16
 * Excel thread unsafe
J
update  
jipengfei.jpf 已提交
17 18 19 20 21 22
 *
 * @author jipengfei
 */
public class ExcelReader {

    /**
23
     * analyser
J
update  
jipengfei.jpf 已提交
24 25 26 27
     */
    private ExcelAnalyser analyser = new ExcelAnalyserImpl();

    /**
28 29 30 31 32
     * @param in
     * @param excelTypeEnum 0307
     * @param customContent {@link AnalysisEventListener#invoke(Object, AnalysisContext)
     *                      }AnalysisContext
     * @param eventListener
J
update  
jipengfei.jpf 已提交
33
     */
34
    @Deprecated
J
update  
jipengfei.jpf 已提交
35 36 37 38 39
    public ExcelReader(InputStream in, ExcelTypeEnum excelTypeEnum, Object customContent,
                       AnalysisEventListener eventListener) {
        this(in, excelTypeEnum, customContent, eventListener, true);
    }

40 41 42 43 44 45 46 47 48 49 50
    /**
     * @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);
    }

J
update  
jipengfei.jpf 已提交
51
    /**
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
     * @param param
     * @param eventListener
     */
    @Deprecated
    public ExcelReader(AnalysisParam param, AnalysisEventListener eventListener) {
        this(param.getIn(), param.getExcelTypeEnum(), param.getCustomContent(), eventListener, true);
    }

    /**
     * @param in
     * @param excelTypeEnum 03 07
     * @param customContent {@link AnalysisEventListener#invoke(Object, AnalysisContext)
     *                      }AnalysisContext
     * @param eventListener
     * @param trim
J
update  
jipengfei.jpf 已提交
67
     */
68
    @Deprecated
J
update  
jipengfei.jpf 已提交
69 70 71 72 73 74
    public ExcelReader(InputStream in, ExcelTypeEnum excelTypeEnum, Object customContent,
                       AnalysisEventListener eventListener, boolean trim) {
        validateParam(in, excelTypeEnum, eventListener);
        analyser.init(in, excelTypeEnum, customContent, eventListener, trim);
    }

75 76 77 78 79 80 81 82 83 84 85 86 87 88
    /**
     * @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);
    }

J
update  
jipengfei.jpf 已提交
89 90 91 92 93 94 95 96
    /**
     */
    public void read() {
        analyser.analysis();
    }

    /**
     *
97
     * @param sheet
J
update  
jipengfei.jpf 已提交
98 99 100 101 102
     */
    public void read(Sheet sheet) {
        analyser.analysis(sheet);
    }

103 104 105 106 107 108
    @Deprecated
    public void read(Sheet sheet,Class<? extends BaseRowModel> clazz){
        sheet.setClazz(clazz);
        analyser.analysis(sheet);
    }

J
update  
jipengfei.jpf 已提交
109 110
    /**
     *
111
     * @return
J
update  
jipengfei.jpf 已提交
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
     */
    public List<Sheet> getSheets() {
        return analyser.getSheets();
    }

    /**
     *
     * @param in
     * @param excelTypeEnum
     * @param eventListener
     */
    private void validateParam(InputStream in, ExcelTypeEnum excelTypeEnum, AnalysisEventListener eventListener) {
        if (eventListener == null) {
            throw new IllegalArgumentException("AnalysisEventListener can not null");
        } else if (in == null) {
            throw new IllegalArgumentException("InputStream can not null");
        } else if (excelTypeEnum == null) {
            throw new IllegalArgumentException("excelTypeEnum can not null");
        }
    }
}