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.

175 lines
4.2 KiB

package com.alibaba.excel.context;
import java.io.InputStream;
import com.alibaba.excel.converters.ConverterRegistryCenter;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.excel.exception.ExcelAnalysisException;
import com.alibaba.excel.metadata.ExcelHeadProperty;
import com.alibaba.excel.metadata.Sheet;
import com.alibaba.excel.support.ExcelTypeEnum;
/**
*
* @author jipengfei
*/
public class AnalysisContextImpl implements AnalysisContext {
private Object custom;
private Sheet currentSheet;
private ExcelTypeEnum excelType;
private InputStream inputStream;
private AnalysisEventListener<Object> eventListener;
private Integer currentRowNum;
private Integer totalCount;
private ExcelHeadProperty excelHeadProperty;
private boolean trim;
private boolean use1904WindowDate = false;
private ConverterRegistryCenter converterRegistryCenter;
@Override
public void setUse1904WindowDate(boolean use1904WindowDate) {
this.use1904WindowDate = use1904WindowDate;
}
@Override
public Object getCurrentRowAnalysisResult() {
return currentRowAnalysisResult;
}
@Override
public void interrupt() {
throw new ExcelAnalysisException("interrupt error");
}
@Override
public boolean use1904WindowDate() {
return use1904WindowDate;
}
@Override
public void setCurrentRowAnalysisResult(Object currentRowAnalysisResult) {
this.currentRowAnalysisResult = currentRowAnalysisResult;
}
private Object currentRowAnalysisResult;
public AnalysisContextImpl(InputStream inputStream, ExcelTypeEnum excelTypeEnum, Object custom,
AnalysisEventListener<Object> listener, ConverterRegistryCenter converterRegistryCenter, boolean trim) {
this.custom = custom;
this.eventListener = listener;
this.inputStream = inputStream;
this.excelType = excelTypeEnum;
this.trim = trim;
this.converterRegistryCenter = converterRegistryCenter;
}
@Override
public void setCurrentSheet(Sheet currentSheet) {
cleanCurrentSheet();
this.currentSheet = currentSheet;
if (currentSheet.getClazz() != null) {
ExcelHeadProperty.buildExcelHeadProperty(this.excelHeadProperty, currentSheet.getClazz(), null);
}
}
private void cleanCurrentSheet() {
this.currentSheet = null;
this.excelHeadProperty = null;
this.totalCount = 0;
this.currentRowAnalysisResult = null;
this.currentRowNum =0;
}
@Override
public ExcelTypeEnum getExcelType() {
return excelType;
}
public void setExcelType(ExcelTypeEnum excelType) {
this.excelType = excelType;
}
public Object getCustom() {
return custom;
}
public void setCustom(Object custom) {
this.custom = custom;
}
@Override
public Sheet getCurrentSheet() {
return currentSheet;
}
@Override
public InputStream getInputStream() {
return inputStream;
}
public void setInputStream(InputStream inputStream) {
this.inputStream = inputStream;
}
@Override
public AnalysisEventListener<Object> getEventListener() {
return eventListener;
}
public void setEventListener(AnalysisEventListener<Object> eventListener) {
this.eventListener = eventListener;
}
@Override
public Integer getCurrentRowNum() {
return this.currentRowNum;
}
@Override
public void setCurrentRowNum(Integer row) {
this.currentRowNum = row;
}
@Override
public Integer getTotalCount() {
return totalCount;
}
@Override
public void setTotalCount(Integer totalCount) {
this.totalCount = totalCount;
}
@Override
public ExcelHeadProperty getExcelHeadProperty() {
return this.excelHeadProperty;
}
@Override
public void setExcelHeadProperty(ExcelHeadProperty excelHeadProperty) {
this.excelHeadProperty = excelHeadProperty;
}
@Override
public boolean trim() {
return this.trim;
}
@Override
public ConverterRegistryCenter getConverterRegistryCenter() {
return converterRegistryCenter;
}
}