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.

65 lines
2.1 KiB

package com.alibaba.excel.analysis;
7 years ago
import com.alibaba.excel.analysis.v03.XlsSaxAnalyser;
import com.alibaba.excel.analysis.v07.XlsxSaxAnalyser;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.context.AnalysisContextImpl;
import com.alibaba.excel.exception.ExcelAnalysisException;
import com.alibaba.excel.write.metadata.Sheet;
import com.alibaba.excel.write.metadata.Workbook;
7 years ago
import com.alibaba.excel.support.ExcelTypeEnum;
/**
* @author jipengfei
*/
public class ExcelAnalyserImpl implements ExcelAnalyser {
private AnalysisContext analysisContext;
private ExcelExecutor excelExecutor;
public ExcelAnalyserImpl(Workbook workbook) {
analysisContext = new AnalysisContextImpl(workbook);
choiceExcelExecutor();
}
private void choiceExcelExecutor() {
try {
ExcelTypeEnum excelType = analysisContext.currentWorkbookHolder().getExcelType();
if (excelType == null) {
excelExecutor = new XlsxSaxAnalyser(analysisContext);
return;
}
switch (excelType) {
case XLS:
excelExecutor = new XlsSaxAnalyser(analysisContext);
break;
case XLSX:
excelExecutor = new XlsxSaxAnalyser(analysisContext);
break;
default:
7 years ago
}
} catch (Exception e) {
throw new ExcelAnalysisException("File type error,io must be available markSupported,you can do like "
+ "this <code> new BufferedInputStream(new FileInputStream(\\\"/xxxx\\\"))</code> \"", e);
7 years ago
}
}
@Override
public void analysis(Sheet sheet) {
analysisContext.currentSheet(sheet);
excelExecutor.execute();
7 years ago
analysisContext.getEventListener().doAfterAllAnalysed(analysisContext);
}
@Override
public com.alibaba.excel.analysis.ExcelExecutor excelExecutor() {
return excelExecutor;
7 years ago
}
@Override
public AnalysisContext analysisContext() {
return analysisContext;
}
7 years ago
}