1515 */
1616package org .dhatim .fastexcel .reader ;
1717
18- import javax .xml .stream .XMLStreamException ;
18+ import static org .dhatim .fastexcel .reader .DefaultXMLInputFactory .factory ;
19+
1920import java .io .InputStream ;
2021import java .math .BigDecimal ;
21- import java .util .*;
22+ import java .util .ArrayList ;
23+ import java .util .HashMap ;
24+ import java .util .List ;
25+ import java .util .Map ;
26+ import java .util .NoSuchElementException ;
27+ import java .util .Optional ;
28+ import java .util .Spliterator ;
2229import java .util .function .Consumer ;
2330import java .util .function .Function ;
2431
25- import static org . dhatim . fastexcel . reader . DefaultXMLInputFactory . factory ;
32+ import javax . xml . stream . XMLStreamException ;
2633
2734class RowSpliterator implements Spliterator <Row > {
2835
@@ -85,7 +92,7 @@ private Row next() throws XMLStreamException {
8592 }
8693
8794 int trackedColIndex = 0 ;
88- int rowIndex = getRowIndexWithFallback (++ trackedRowIndex );
95+ int rowIndex = getRowIndexWithFallback (trackedRowIndex );
8996 boolean isHidden = "1" .equals (r .getAttribute ("hidden" ));
9097
9198 List <Cell > cells = new ArrayList <>(rowCapacity );
@@ -98,11 +105,14 @@ private Row next() throws XMLStreamException {
98105
99106 Cell cell = parseCell (trackedColIndex ++);
100107 CellAddress addr = cell .getAddress ();
108+ // we may have to adjust because we may have skipped blanks
109+ trackedColIndex = addr .getColumn () + 1 ;
101110 ensureSize (cells , addr .getColumn () + 1 );
102111
103112 cells .set (addr .getColumn (), cell );
104113 physicalCellCount ++;
105114 }
115+ trackedRowIndex ++;
106116 rowCapacity = Math .max (rowCapacity , cells .size ());
107117 return new Row (rowIndex , physicalCellCount , cells , isHidden );
108118 }
@@ -112,15 +122,15 @@ private int getRowIndexWithFallback(int fallbackRowIndex) {
112122 return rowIndexOrNull != null ? rowIndexOrNull : fallbackRowIndex ;
113123 }
114124
115- private CellAddress getCellAddressWithFallback (int trackedColIndex ) {
125+ private CellAddress getCellAddressWithFallback (int trackedColIndex , int trackedRowIndex ) {
116126 String cellRefOrNull = r .getAttribute ("r" );
117127 return cellRefOrNull != null ?
118128 new CellAddress (cellRefOrNull ) :
119129 new CellAddress (trackedRowIndex , trackedColIndex );
120130 }
121131
122132 private Cell parseCell (int trackedColIndex ) throws XMLStreamException {
123- CellAddress addr = getCellAddressWithFallback (trackedColIndex );
133+ CellAddress addr = getCellAddressWithFallback (trackedColIndex , trackedRowIndex );
124134 String type = r .getOptionalAttribute ("t" ).orElse ("n" );
125135 String styleString = r .getAttribute ("s" );
126136 String formatId = null ;
@@ -192,7 +202,7 @@ private Cell parseOther(CellAddress addr, String type, String dataFormatId, Stri
192202 if (formula == null && value == null && definedType == CellType .NUMBER ) {
193203 return new Cell (workbook , CellType .EMPTY , null , addr , null , rawValue );
194204 } else {
195- CellType cellType = ( formula != null ) ? CellType .FORMULA : definedType ;
205+ CellType cellType = formula != null ? CellType .FORMULA : definedType ;
196206 return new Cell (workbook , cellType , value , addr , formula , rawValue , dataFormatId , dataFormatString );
197207 }
198208 }
@@ -209,7 +219,7 @@ private String parseSharedFormula(Integer si, CellAddress addr) {
209219 * @see <a href="https://github.com/qax-os/excelize/blob/master/cell.go">here</a>
210220 */
211221 private String parseSharedFormula (Integer dCol , Integer dRow , String baseFormula ) {
212- String res = "" ;
222+ StringBuilder res = new StringBuilder () ;
213223 int start = 0 ;
214224 boolean stringLiteral = false ;
215225 for (int end = 0 ; end < baseFormula .length (); end ++) {
@@ -222,7 +232,7 @@ private String parseSharedFormula(Integer dCol, Integer dRow, String baseFormula
222232 }
223233 if (c >= 'A' && c <= 'Z' || c == '$' ) {
224234
225- res += baseFormula .substring (start , end );
235+ res . append ( baseFormula .substring (start , end ) );
226236 start = end ;
227237 end ++;
228238 boolean foundNum = false ;
@@ -240,17 +250,17 @@ private String parseSharedFormula(Integer dCol, Integer dRow, String baseFormula
240250 }
241251 if (foundNum ) {
242252 String cellID = baseFormula .substring (start , end );
243- res += shiftCell (cellID , dCol , dRow );
253+ res . append ( shiftCell (cellID , dCol , dRow ) );
244254 start = end ;
245255 }
246256 }
247257 }
248258
249259 if (start < baseFormula .length ()) {
250- res += baseFormula .substring (start );
260+ res . append ( baseFormula .substring (start ) );
251261 }
252262
253- return res ;
263+ return res . toString () ;
254264 }
255265
256266 /**
0 commit comments