@@ -32,6 +32,7 @@ class RowSpliterator implements Spliterator<Row> {
3232 private final HashMap <Integer , BaseFormulaCell > sharedFormula = new HashMap <>();
3333 private final HashMap <CellRangeAddress , String > arrayFormula = new HashMap <>();
3434 private int rowCapacity = 16 ;
35+ private int trackedRowIndex = 0 ;
3536
3637 public RowSpliterator (ReadableWorkbook workbook , InputStream inputStream ) throws XMLStreamException {
3738 this .workbook = workbook ;
@@ -82,7 +83,10 @@ private Row next() throws XMLStreamException {
8283 if (!"row" .equals (r .getLocalName ())) {
8384 throw new NoSuchElementException ();
8485 }
85- int rowIndex = r .getIntAttribute ("r" );
86+
87+ int trackedColIndex = 0 ;
88+ int rowIndex = getRowIndexWithFallback (++trackedRowIndex );
89+
8690 List <Cell > cells = new ArrayList <>(rowCapacity );
8791 int physicalCellCount = 0 ;
8892
@@ -91,7 +95,7 @@ private Row next() throws XMLStreamException {
9195 break ;
9296 }
9397
94- Cell cell = parseCell ();
98+ Cell cell = parseCell (trackedColIndex ++ );
9599 CellAddress addr = cell .getAddress ();
96100 ensureSize (cells , addr .getColumn () + 1 );
97101
@@ -102,9 +106,20 @@ private Row next() throws XMLStreamException {
102106 return new Row (rowIndex , physicalCellCount , cells );
103107 }
104108
105- private Cell parseCell () throws XMLStreamException {
106- String cellRef = r .getAttribute ("r" );
107- CellAddress addr = new CellAddress (cellRef );
109+ private int getRowIndexWithFallback (int fallbackRowIndex ) {
110+ Integer rowIndexOrNull = r .getIntAttribute ("r" );
111+ return rowIndexOrNull != null ? rowIndexOrNull : fallbackRowIndex ;
112+ }
113+
114+ private CellAddress getCellAddressWithFallback (int trackedColIndex ) {
115+ String cellRefOrNull = r .getAttribute ("r" );
116+ return cellRefOrNull != null ?
117+ new CellAddress (cellRefOrNull ) :
118+ new CellAddress (trackedRowIndex , trackedColIndex );
119+ }
120+
121+ private Cell parseCell (int trackedColIndex ) throws XMLStreamException {
122+ CellAddress addr = getCellAddressWithFallback (trackedColIndex );
108123 String type = r .getOptionalAttribute ("t" ).orElse ("n" );
109124 String styleString = r .getAttribute ("s" );
110125 String formatId = null ;
0 commit comments