Fixed HSSFSheet#getFirstRowNum and HSSFSheet#getLastRowNum to return correct values after removal of all rows
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@780245 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
15a46deae0
commit
e7d06ec34c
@ -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>
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user