diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java index 4b73e36ca5..ee956b437d 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java @@ -77,6 +77,16 @@ public class XSSFRow implements Row, Comparable { _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); + } } /** diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java index 97ace44e47..41adc133a8 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java @@ -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()); } }