You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
2.9 KiB

7 years ago
package com.alibaba.excel;
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;
7 years ago
import com.alibaba.excel.metadata.Sheet;
import com.alibaba.excel.parameter.AnalysisParam;
7 years ago
import com.alibaba.excel.support.ExcelTypeEnum;
import java.io.InputStream;
import java.util.List;
7 years ago
/**
* Excel thread unsafe
7 years ago
*
* @author jipengfei
*/
public class ExcelReader {
/**
* analyser
7 years ago
*/
private ExcelAnalyser analyser = new ExcelAnalyserImpl();
/**
* @param in
* @param excelTypeEnum 0307
* @param customContent {@link AnalysisEventListener#invoke(Object, AnalysisContext)
* }AnalysisContext
* @param eventListener
7 years ago
*/
public ExcelReader(InputStream in, ExcelTypeEnum excelTypeEnum, Object customContent,
AnalysisEventListener eventListener) {
this(in, excelTypeEnum, customContent, eventListener, true);
}
/**
* old 1.1.0
* @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
7 years ago
*/
public ExcelReader(InputStream in, ExcelTypeEnum excelTypeEnum, Object customContent,
AnalysisEventListener eventListener, boolean trim) {
validateParam(in, excelTypeEnum, eventListener);
analyser.init(in, excelTypeEnum, customContent, eventListener, trim);
}
/**
*/
public void read() {
analyser.analysis();
}
/**
*
* @param sheet
7 years ago
*/
public void read(Sheet sheet) {
analyser.analysis(sheet);
}
@Deprecated
public void read(Sheet sheet,Class<? extends BaseRowModel> clazz){
sheet.setClazz(clazz);
analyser.analysis(sheet);
}
7 years ago
/**
*
* @return
7 years ago
*/
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");
}
}
}