Browse Source

* 兼容某些特殊的xls: 缺少每个sheet的终止符

pull/3609/head
是仪 1 year ago
parent
commit
9be5755b89
  1. 4
      easyexcel-core/src/main/java/com/alibaba/excel/analysis/v03/XlsSaxAnalyser.java
  2. 5
      easyexcel-core/src/main/java/com/alibaba/excel/read/metadata/holder/ReadSheetHolder.java
  3. 34
      easyexcel-core/src/main/java/com/alibaba/excel/read/metadata/holder/xls/XlsReadSheetHolder.java
  4. 11
      easyexcel-core/src/main/java/com/alibaba/excel/read/processor/DefaultAnalysisEventProcessor.java

4
easyexcel-core/src/main/java/com/alibaba/excel/analysis/v03/XlsSaxAnalyser.java

@ -11,6 +11,7 @@ import org.apache.poi.hssf.eventusermodel.HSSFEventFactory;
import org.apache.poi.hssf.eventusermodel.HSSFListener;
import org.apache.poi.hssf.eventusermodel.HSSFRequest;
import org.apache.poi.hssf.eventusermodel.MissingRecordAwareHSSFListener;
import org.apache.poi.hssf.eventusermodel.dummyrecord.MissingRowDummyRecord;
import org.apache.poi.hssf.record.BOFRecord;
import org.apache.poi.hssf.record.BlankRecord;
import org.apache.poi.hssf.record.BoolErrRecord;
@ -137,6 +138,9 @@ public class XlsSaxAnalyser implements HSSFListener, ExcelReadExecutor {
} catch (IOException e) {
throw new ExcelAnalysisException(e);
}
// There are some special xls that do not have the terminator "[EOF]", so an additional
xlsReadContext.analysisEventProcessor().endSheet(xlsReadContext);
}
@Override

5
easyexcel-core/src/main/java/com/alibaba/excel/read/metadata/holder/ReadSheetHolder.java

@ -67,6 +67,11 @@ public class ReadSheetHolder extends AbstractReadHolder {
*/
private Integer maxNotEmptyDataHeadSize;
/**
* Reading this sheet has ended.
*/
private Boolean ended;
public ReadSheetHolder(ReadSheet readSheet, ReadWorkbookHolder readWorkbookHolder) {
super(readSheet, readWorkbookHolder);
this.readSheet = readSheet;

34
easyexcel-core/src/main/java/com/alibaba/excel/read/metadata/holder/xls/XlsReadSheetHolder.java

@ -8,11 +8,20 @@ import com.alibaba.excel.read.metadata.ReadSheet;
import com.alibaba.excel.read.metadata.holder.ReadSheetHolder;
import com.alibaba.excel.read.metadata.holder.ReadWorkbookHolder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
/**
* sheet holder
*
* @author Jiaju Zhuang
*/
@Getter
@Setter
@EqualsAndHashCode
@NoArgsConstructor
public class XlsReadSheetHolder extends ReadSheetHolder {
/**
* Row type.Temporary storage, last set in <code>ReadRowHolder</code>.
@ -32,29 +41,4 @@ public class XlsReadSheetHolder extends ReadSheetHolder {
tempRowType = RowTypeEnum.EMPTY;
objectCacheMap = new HashMap<Integer, String>(16);
}
public RowTypeEnum getTempRowType() {
return tempRowType;
}
public void setTempRowType(RowTypeEnum tempRowType) {
this.tempRowType = tempRowType;
}
public Integer getTempObjectIndex() {
return tempObjectIndex;
}
public void setTempObjectIndex(Integer tempObjectIndex) {
this.tempObjectIndex = tempObjectIndex;
}
public Map<Integer, String> getObjectCacheMap() {
return objectCacheMap;
}
public void setObjectCacheMap(Map<Integer, String> objectCacheMap) {
this.objectCacheMap = objectCacheMap;
}
}

11
easyexcel-core/src/main/java/com/alibaba/excel/read/processor/DefaultAnalysisEventProcessor.java

@ -3,8 +3,6 @@ package com.alibaba.excel.read.processor;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.enums.CellDataTypeEnum;
@ -16,11 +14,12 @@ import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.read.listener.ReadListener;
import com.alibaba.excel.read.metadata.holder.ReadRowHolder;
import com.alibaba.excel.read.metadata.holder.ReadSheetHolder;
import com.alibaba.excel.read.metadata.property.ExcelReadHeadProperty;
import com.alibaba.excel.util.BooleanUtils;
import com.alibaba.excel.util.ConverterUtils;
import com.alibaba.excel.util.StringUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -53,6 +52,12 @@ public class DefaultAnalysisEventProcessor implements AnalysisEventProcessor {
@Override
public void endSheet(AnalysisContext analysisContext) {
ReadSheetHolder readSheetHolder = analysisContext.readSheetHolder();
if (BooleanUtils.isTrue(readSheetHolder.getEnded())) {
return;
}
readSheetHolder.setEnded(Boolean.TRUE);
for (ReadListener readListener : analysisContext.currentReadHolder().readListenerList()) {
readListener.doAfterAllAnalysed(analysisContext);
}

Loading…
Cancel
Save