Browse Source

修改忽略表格代码异常

developing
Jiaju Zhuang 5 years ago
parent
commit
bffb08d97c
  1. 2
      src/main/java/com/alibaba/excel/analysis/v03/XlsSaxAnalyser.java
  2. 6
      src/main/java/com/alibaba/excel/analysis/v03/handlers/BofRecordHandler.java
  3. 12
      src/main/java/com/alibaba/excel/read/metadata/holder/xls/XlsReadSheetHolder.java
  4. 13
      src/main/java/com/alibaba/excel/read/metadata/holder/xls/XlsReadWorkbookHolder.java

2
src/main/java/com/alibaba/excel/analysis/v03/XlsSaxAnalyser.java

@ -147,7 +147,7 @@ public class XlsSaxAnalyser implements HSSFListener, ExcelReadExecutor {
return; return;
} }
boolean ignoreRecord = (handler instanceof IgnorableXlsRecordHandler) boolean ignoreRecord = (handler instanceof IgnorableXlsRecordHandler)
&& xlsReadContext.xlsReadSheetHolder() != null && xlsReadContext.xlsReadSheetHolder().getIgnoreRecord(); && xlsReadContext.xlsReadSheetHolder() != null && xlsReadContext.xlsReadWorkbookHolder().getIgnoreRecord();
if (ignoreRecord) { if (ignoreRecord) {
// No need to read the current sheet // No need to read the current sheet
return; return;

6
src/main/java/com/alibaba/excel/analysis/v03/handlers/BofRecordHandler.java

@ -26,6 +26,7 @@ public class BofRecordHandler extends AbstractXlsRecordHandler {
XlsReadWorkbookHolder xlsReadWorkbookHolder = xlsReadContext.xlsReadWorkbookHolder(); XlsReadWorkbookHolder xlsReadWorkbookHolder = xlsReadContext.xlsReadWorkbookHolder();
if (br.getType() == BOFRecord.TYPE_WORKBOOK) { if (br.getType() == BOFRecord.TYPE_WORKBOOK) {
xlsReadWorkbookHolder.setReadSheetIndex(null); xlsReadWorkbookHolder.setReadSheetIndex(null);
xlsReadWorkbookHolder.setIgnoreRecord(Boolean.FALSE);
return; return;
} }
if (br.getType() != BOFRecord.TYPE_WORKSHEET) { if (br.getType() != BOFRecord.TYPE_WORKSHEET) {
@ -44,10 +45,9 @@ public class BofRecordHandler extends AbstractXlsRecordHandler {
ReadSheet readSheet = SheetUtils.match(actualReadSheet, xlsReadContext); ReadSheet readSheet = SheetUtils.match(actualReadSheet, xlsReadContext);
if (readSheet != null) { if (readSheet != null) {
xlsReadContext.currentSheet(readSheet); xlsReadContext.currentSheet(readSheet);
xlsReadContext.xlsReadSheetHolder().setIgnoreRecord(Boolean.FALSE); xlsReadContext.xlsReadWorkbookHolder().setIgnoreRecord(Boolean.FALSE);
} else { } else {
xlsReadContext.currentSheet(actualReadSheet); xlsReadContext.xlsReadWorkbookHolder().setIgnoreRecord(Boolean.TRUE);
xlsReadContext.xlsReadSheetHolder().setIgnoreRecord(Boolean.TRUE);
} }
// Go read the next one // Go read the next one
xlsReadWorkbookHolder.setReadSheetIndex(xlsReadWorkbookHolder.getReadSheetIndex() + 1); xlsReadWorkbookHolder.setReadSheetIndex(xlsReadWorkbookHolder.getReadSheetIndex() + 1);

12
src/main/java/com/alibaba/excel/read/metadata/holder/xls/XlsReadSheetHolder.java

@ -18,10 +18,6 @@ public class XlsReadSheetHolder extends ReadSheetHolder {
* Row type.Temporary storage, last set in <code>ReadRowHolder</code>. * Row type.Temporary storage, last set in <code>ReadRowHolder</code>.
*/ */
private RowTypeEnum tempRowType; private RowTypeEnum tempRowType;
/**
* Ignore record.
*/
private Boolean ignoreRecord;
/** /**
* Temp object index. * Temp object index.
*/ */
@ -33,7 +29,6 @@ public class XlsReadSheetHolder extends ReadSheetHolder {
public XlsReadSheetHolder(ReadSheet readSheet, ReadWorkbookHolder readWorkbookHolder) { public XlsReadSheetHolder(ReadSheet readSheet, ReadWorkbookHolder readWorkbookHolder) {
super(readSheet, readWorkbookHolder); super(readSheet, readWorkbookHolder);
ignoreRecord = Boolean.FALSE;
tempRowType = RowTypeEnum.EMPTY; tempRowType = RowTypeEnum.EMPTY;
objectCacheMap = new HashMap<Integer, String>(16); objectCacheMap = new HashMap<Integer, String>(16);
} }
@ -46,13 +41,6 @@ public class XlsReadSheetHolder extends ReadSheetHolder {
this.tempRowType = tempRowType; this.tempRowType = tempRowType;
} }
public Boolean getIgnoreRecord() {
return ignoreRecord;
}
public void setIgnoreRecord(Boolean ignoreRecord) {
this.ignoreRecord = ignoreRecord;
}
public Integer getTempObjectIndex() { public Integer getTempObjectIndex() {
return tempObjectIndex; return tempObjectIndex;

13
src/main/java/com/alibaba/excel/read/metadata/holder/xls/XlsReadWorkbookHolder.java

@ -42,6 +42,10 @@ public class XlsReadWorkbookHolder extends ReadWorkbookHolder {
* Sheet Index * Sheet Index
*/ */
private Integer readSheetIndex; private Integer readSheetIndex;
/**
* Ignore record.
*/
private Boolean ignoreRecord;
public XlsReadWorkbookHolder(ReadWorkbook readWorkbook) { public XlsReadWorkbookHolder(ReadWorkbook readWorkbook) {
super(readWorkbook); super(readWorkbook);
@ -51,6 +55,7 @@ public class XlsReadWorkbookHolder extends ReadWorkbookHolder {
if (getGlobalConfiguration().getUse1904windowing() == null) { if (getGlobalConfiguration().getUse1904windowing() == null) {
getGlobalConfiguration().setUse1904windowing(Boolean.FALSE); getGlobalConfiguration().setUse1904windowing(Boolean.FALSE);
} }
ignoreRecord = Boolean.FALSE;
} }
public POIFSFileSystem getPoifsFileSystem() { public POIFSFileSystem getPoifsFileSystem() {
@ -100,4 +105,12 @@ public class XlsReadWorkbookHolder extends ReadWorkbookHolder {
public void setReadSheetIndex(Integer readSheetIndex) { public void setReadSheetIndex(Integer readSheetIndex) {
this.readSheetIndex = readSheetIndex; this.readSheetIndex = readSheetIndex;
} }
public Boolean getIgnoreRecord() {
return ignoreRecord;
}
public void setIgnoreRecord(Boolean ignoreRecord) {
this.ignoreRecord = ignoreRecord;
}
} }

Loading…
Cancel
Save