#59746 XSSF support for files from certain alternate tools where the row XML is missing the row number

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1749971 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2016-06-23 18:59:48 +00:00
parent 4abd9f6cca
commit 05f704d112
2 changed files with 13 additions and 1 deletions

View File

@ -77,6 +77,16 @@ public class XSSFRow implements Row, Comparable<XSSFRow> {
_cells.put(colI, cell);
sheet.onReadCell(cell);
}
if (! row.isSetR()) {
// Certain file format writers skip the row number
// Assume no gaps, and give this the next row number
int nextRowNum = sheet.getLastRowNum()+2;
if (nextRowNum == 2 && sheet.getPhysicalNumberOfRows() == 0) {
nextRowNum = 1;
}
row.setR(nextRowNum);
}
}
/**

View File

@ -3088,7 +3088,6 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
* to include the row number on the row tags
*/
@Test
@Ignore("Not yet supported")
public void noRowNumbers59746() {
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("59746_NoRowNums.xlsx");
Sheet sheet = wb.getSheetAt(0);
@ -3096,5 +3095,8 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
assertEquals("Checked", sheet.getRow(0).getCell(0).getStringCellValue());
assertEquals("Checked", sheet.getRow(9).getCell(2).getStringCellValue());
assertEquals(false, sheet.getRow(70).getCell(8).getBooleanCellValue());
assertEquals(71, sheet.getPhysicalNumberOfRows());
assertEquals(70, sheet.getLastRowNum());
assertEquals(70, sheet.getRow(sheet.getLastRowNum()).getRowNum());
}
}