diff --git a/fastexcel-reader/src/main/java/org/dhatim/fastexcel/reader/RowSpliterator.java b/fastexcel-reader/src/main/java/org/dhatim/fastexcel/reader/RowSpliterator.java index b7fcd04b..18ed4aad 100644 --- a/fastexcel-reader/src/main/java/org/dhatim/fastexcel/reader/RowSpliterator.java +++ b/fastexcel-reader/src/main/java/org/dhatim/fastexcel/reader/RowSpliterator.java @@ -32,6 +32,7 @@ class RowSpliterator implements Spliterator { private final HashMap sharedFormula = new HashMap<>(); private final HashMap arrayFormula = new HashMap<>(); private int rowCapacity = 16; + private int trackedRowIndex = 0; public RowSpliterator(ReadableWorkbook workbook, InputStream inputStream) throws XMLStreamException { this.workbook = workbook; @@ -82,7 +83,10 @@ private Row next() throws XMLStreamException { if (!"row".equals(r.getLocalName())) { throw new NoSuchElementException(); } - int rowIndex = r.getIntAttribute("r"); + + int trackedColIndex = 0; + int rowIndex = getRowIndexWithFallback(++trackedRowIndex); + List cells = new ArrayList<>(rowCapacity); int physicalCellCount = 0; @@ -91,7 +95,7 @@ private Row next() throws XMLStreamException { break; } - Cell cell = parseCell(); + Cell cell = parseCell(trackedColIndex++); CellAddress addr = cell.getAddress(); ensureSize(cells, addr.getColumn() + 1); @@ -102,9 +106,20 @@ private Row next() throws XMLStreamException { return new Row(rowIndex, physicalCellCount, cells); } - private Cell parseCell() throws XMLStreamException { - String cellRef = r.getAttribute("r"); - CellAddress addr = new CellAddress(cellRef); + private int getRowIndexWithFallback(int fallbackRowIndex) { + Integer rowIndexOrNull = r.getIntAttribute("r"); + return rowIndexOrNull != null ? rowIndexOrNull : fallbackRowIndex; + } + + private CellAddress getCellAddressWithFallback(int trackedColIndex) { + String cellRefOrNull = r.getAttribute("r"); + return cellRefOrNull != null ? + new CellAddress(cellRefOrNull) : + new CellAddress(trackedRowIndex, trackedColIndex); + } + + private Cell parseCell(int trackedColIndex) throws XMLStreamException { + CellAddress addr = getCellAddressWithFallback(trackedColIndex); String type = r.getOptionalAttribute("t").orElse("n"); String styleString = r.getAttribute("s"); String formatId = null; diff --git a/fastexcel-reader/src/test/java/org/dhatim/fastexcel/reader/FastExcelReaderTest.java b/fastexcel-reader/src/test/java/org/dhatim/fastexcel/reader/FastExcelReaderTest.java index 09c2a1e7..6a2cd4bb 100644 --- a/fastexcel-reader/src/test/java/org/dhatim/fastexcel/reader/FastExcelReaderTest.java +++ b/fastexcel-reader/src/test/java/org/dhatim/fastexcel/reader/FastExcelReaderTest.java @@ -17,6 +17,7 @@ import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.WorkbookFactory; +import org.apache.poi.util.IOUtils; import org.apache.poi.xssf.usermodel.XSSFCell; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; @@ -155,6 +156,7 @@ private List readUsingFastExcel() throws IOException { "/xlsx/write.xlsx", "/xlsx/issue143.xlsx", "/xlsx/issue161.xlsx", + "/xlsx/issue514.xlsx", // "/xlsx/xlsx-stream-d-date-cell.xlsx" }) void testFile(String file) { diff --git a/fastexcel-reader/src/test/resources/xlsx/issue514.xlsx b/fastexcel-reader/src/test/resources/xlsx/issue514.xlsx new file mode 100644 index 00000000..71938f68 Binary files /dev/null and b/fastexcel-reader/src/test/resources/xlsx/issue514.xlsx differ