]> source.dussan.org Git - poi.git/commitdiff
Correct logic for the start-of-sheet missing rows, for event user model, and add...
authorNick Burch <nick@apache.org>
Wed, 30 Jul 2014 23:06:46 +0000 (23:06 +0000)
committerNick Burch <nick@apache.org>
Wed, 30 Jul 2014 23:06:46 +0000 (23:06 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1614789 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hssf/eventusermodel/MissingRecordAwareHSSFListener.java
src/java/org/apache/poi/hssf/eventusermodel/dummyrecord/LastCellOfRowDummyRecord.java
src/testcases/org/apache/poi/hssf/eventusermodel/TestMissingRecordAwareHSSFListener.java

index ef15ea7ce7f66858fba398069fb998a36ca706a5..503f8d81b17830cadfbbe28a5e080595758346e6 100644 (file)
@@ -86,7 +86,8 @@ public final class MissingRecordAwareHSSFListener implements HSSFListener {
                                // the workbook
                                case BOFRecord.sid:
                                        BOFRecord bof = (BOFRecord) record;
-                                       if (bof.getType() == bof.TYPE_WORKBOOK || bof.getType() == bof.TYPE_WORKSHEET) {
+                                       if (bof.getType() == BOFRecord.TYPE_WORKBOOK || 
+                                               bof.getType() == BOFRecord.TYPE_WORKSHEET) {
                                                // Reset the row and column counts - new workbook / worksheet
                                                resetCounts();
                                        }
@@ -106,6 +107,7 @@ public final class MissingRecordAwareHSSFListener implements HSSFListener {
 
                                        // Record this as the last row we saw
                                        lastRowRow = rowrec.getRowNumber();
+                                       lastCellColumn = -1;
                                        break;
 
                                case SharedFormulaRecord.sid:
@@ -144,7 +146,8 @@ public final class MissingRecordAwareHSSFListener implements HSSFListener {
                // If we're on cells, and this cell isn't in the same
                //  row as the last one, then fire the
                //  dummy end-of-row records
-               if(thisRow != lastCellRow && lastCellRow > -1) {
+               if(thisRow != lastCellRow && thisRow > 0) {
+                   if (lastCellRow == -1) lastCellRow = 0;
                        for(int i=lastCellRow; i<thisRow; i++) {
                                int cols = -1;
                                if(i == lastCellRow) {
index e0635930160f5ae9859ee8d548b87f9652ea5f6c..0b41df9b77e295c8b08069fc1f66c2054ae5c596 100644 (file)
@@ -44,4 +44,8 @@ public final class LastCellOfRowDummyRecord extends DummyRecordBase {
         *  for the row.
         */
        public int getLastColumnNumber() { return lastColumnNumber; }
+       
+       public String toString() {
+           return "End-of-Row for Row=" + row + " at Column=" + lastColumnNumber;
+       }
 }
index 5b834ad3d5a958d8e2af714a1320727e9bdca3e2..228071af2464049dac4c3ca929af7b996f2a9a6e 100644 (file)
@@ -567,7 +567,18 @@ public final class TestMissingRecordAwareHSSFListener extends TestCase {
         // Now onto the cells
         
         // Because the 3 first rows are missing, should have last-of-row records first
-        // TODO Fix!
+        assertEquals(LastCellOfRowDummyRecord.class, r[pos].getClass());
+        assertEquals(0, ((LastCellOfRowDummyRecord)r[pos]).getRow());
+        assertEquals(-1, ((LastCellOfRowDummyRecord)r[pos]).getLastColumnNumber());
+        pos++;
+        assertEquals(LastCellOfRowDummyRecord.class, r[pos].getClass());
+        assertEquals(1, ((LastCellOfRowDummyRecord)r[pos]).getRow());
+        assertEquals(-1, ((LastCellOfRowDummyRecord)r[pos]).getLastColumnNumber());
+        pos++;
+        assertEquals(LastCellOfRowDummyRecord.class, r[pos].getClass());
+        assertEquals(2, ((LastCellOfRowDummyRecord)r[pos]).getRow());
+        assertEquals(-1, ((LastCellOfRowDummyRecord)r[pos]).getLastColumnNumber());
+        pos++;
         
         
         // Onto row 4 (=3)