From 9147f07e308e6aabec08548336e9a02598bc5cf9 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Sat, 28 Jun 2008 18:21:21 +0000 Subject: Avoid spurious missing lines with the MissingRecordAware event code, and odd files that contain RowRecords in the middle of the cell Records. git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@672562 13f79535-47bb-0310-9956-ffa450edef68 --- .../MissingRecordAwareHSSFListener.java | 68 +++++++++++++--------- 1 file changed, 40 insertions(+), 28 deletions(-) (limited to 'src/java/org/apache/poi/hssf/eventusermodel') diff --git a/src/java/org/apache/poi/hssf/eventusermodel/MissingRecordAwareHSSFListener.java b/src/java/org/apache/poi/hssf/eventusermodel/MissingRecordAwareHSSFListener.java index a727d064b9..0bdcb1d3d9 100644 --- a/src/java/org/apache/poi/hssf/eventusermodel/MissingRecordAwareHSSFListener.java +++ b/src/java/org/apache/poi/hssf/eventusermodel/MissingRecordAwareHSSFListener.java @@ -46,8 +46,14 @@ import org.apache.poi.hssf.record.RowRecord; */ public class MissingRecordAwareHSSFListener implements HSSFListener { private HSSFListener childListener; - private int lastSeenRow = -1; - private int lastSeenColumn = -1; + + // Need to have different counters for cell rows and + // row rows, as you sometimes get a RowRecord in the + // middle of some cells, and that'd break everything + private int lastRowRow = -1; + + private int lastCellRow = -1; + private int lastCellColumn = -1; /** * Constructs a new MissingRecordAwareHSSFListener, which @@ -71,14 +77,16 @@ public class MissingRecordAwareHSSFListener implements HSSFListener { if (bof.getType() == bof.TYPE_WORKBOOK) { // Reset the row and column counts - new workbook - lastSeenRow = -1; - lastSeenColumn = -1; + lastRowRow = -1; + lastCellRow = -1; + lastCellColumn = -1; //System.out.println("Encountered workbook"); } else if (bof.getType() == bof.TYPE_WORKSHEET) { // Reset the row and column counts - new sheet - lastSeenRow = -1; - lastSeenColumn = -1; + lastRowRow = -1; + lastCellRow = -1; + lastCellColumn = -1; //System.out.println("Encountered sheet reference"); } break; @@ -92,15 +100,15 @@ public class MissingRecordAwareHSSFListener implements HSSFListener { // + rowrec.getFirstCol() + " last column at " + rowrec.getLastCol()); // If there's a jump in rows, fire off missing row records - if(lastSeenRow+1 < rowrec.getRowNumber()) { - for(int i=(lastSeenRow+1); i -1) { + for(int i=lastCellRow; i