]> source.dussan.org Git - poi.git/commitdiff
Fixed HSSFSheet#getFirstRowNum and HSSFSheet#getLastRowNum to return correct values...
authorYegor Kozlov <yegor@apache.org>
Sat, 30 May 2009 11:31:05 +0000 (11:31 +0000)
committerYegor Kozlov <yegor@apache.org>
Sat, 30 May 2009 11:31:05 +0000 (11:31 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@780245 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/status.xml
src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java

index dc160de51d71cda2e9118a3615020246d4bd137e..0bd2ac472f81b49fa6f873010c7a6c5f4a8a0d24 100644 (file)
@@ -34,6 +34,7 @@
        <!-- Don't forget to update changes.xml too! -->
     <changes>
         <release version="3.5-beta6" date="2009-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">47069 - Fixed HSSFSheet#getFirstRowNum and HSSFSheet#getLastRowNum to return correct values after removal of all rows</action>
            <action dev="POI-DEVELOPERS" type="fix">47278 - Fixed XSSFCell to avoid generating xsi:nil entries in shared string table</action>
            <action dev="POI-DEVELOPERS" type="fix">47206 - Fixed XSSFCell to properly read inline strings</action>
            <action dev="POI-DEVELOPERS" type="add">47250 - Fixed FontRecord to expect unicode flags even when name length is zero</action>
index 64a5bc19090bb4712eee2f1ac18df293cd833958..0067a6bb8c6071037daa2582eddbbfd93bcc76f4 100644 (file)
@@ -253,7 +253,7 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
      */
     private int findLastRow(int lastrow) {
         if (lastrow < 1) {
-            return -1;
+            return 0;
         }
         int rownum = lastrow - 1;
         HSSFRow r = getRow(rownum);
@@ -262,7 +262,7 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
             r = getRow(--rownum);
         }
         if (r == null) {
-            return -1;
+            return 0;
         }
         return rownum;
     }
@@ -282,7 +282,7 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
         }
 
         if (rownum > getLastRowNum())
-            return -1;
+            return 0;
 
         return rownum;
     }
@@ -300,11 +300,12 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
         {
             _sheet.addRow(row.getRowRecord());
         }
-        if (row.getRowNum() > getLastRowNum())
+        boolean firstRow = _rows.size() == 1;
+        if (row.getRowNum() > getLastRowNum() || firstRow)
         {
             _lastrow = row.getRowNum();
         }
-        if (row.getRowNum() < getFirstRowNum())
+        if (row.getRowNum() < getFirstRowNum() || firstRow)
         {
             _firstrow = row.getRowNum();
         }
index 9c51656dd4738771b601393cc9ccbcdfbd61fe77..98284df7c8a42d1a3baf0f41be03bfa0dbc7f598 100755 (executable)
@@ -79,21 +79,32 @@ public abstract class BaseTestSheet extends TestCase {
         Workbook workbook = getTestDataProvider().createWorkbook();
         Sheet sheet1 = workbook.createSheet();
         assertEquals(0, sheet1.getPhysicalNumberOfRows());
+        assertEquals(0, sheet1.getFirstRowNum());
+        assertEquals(0, sheet1.getLastRowNum());
 
         Row row0 = sheet1.createRow(0);
         assertEquals(1, sheet1.getPhysicalNumberOfRows());
+        assertEquals(0, sheet1.getFirstRowNum());
+        assertEquals(0, sheet1.getLastRowNum());
         sheet1.removeRow(row0);
         assertEquals(0, sheet1.getPhysicalNumberOfRows());
+        assertEquals(0, sheet1.getFirstRowNum());
+        assertEquals(0, sheet1.getLastRowNum());
 
         Row row1 = sheet1.createRow(1);
         Row row2 = sheet1.createRow(2);
         assertEquals(2, sheet1.getPhysicalNumberOfRows());
+        assertEquals(1, sheet1.getFirstRowNum());
+        assertEquals(2, sheet1.getLastRowNum());
 
         assertNotNull(sheet1.getRow(1));
         assertNotNull(sheet1.getRow(2));
         sheet1.removeRow(row2);
         assertNotNull(sheet1.getRow(1));
         assertNull(sheet1.getRow(2));
+        assertEquals(1, sheet1.getPhysicalNumberOfRows());
+        assertEquals(1, sheet1.getFirstRowNum());
+        assertEquals(1, sheet1.getLastRowNum());
 
         Row row3 = sheet1.createRow(3);
         Sheet sheet2 = workbook.createSheet();