<!-- 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>
*/
private int findLastRow(int lastrow) {
if (lastrow < 1) {
- return -1;
+ return 0;
}
int rownum = lastrow - 1;
HSSFRow r = getRow(rownum);
r = getRow(--rownum);
}
if (r == null) {
- return -1;
+ return 0;
}
return rownum;
}
}
if (rownum > getLastRowNum())
- return -1;
+ return 0;
return rownum;
}
{
_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();
}
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();