Skip to content

Commit 8da7b5b

Browse files
committed
Adding test case
1 parent 05af95e commit 8da7b5b

File tree

3 files changed

+75
-3
lines changed

3 files changed

+75
-3
lines changed

fastexcel-reader/src/main/java/org/dhatim/fastexcel/reader/RowSpliterator.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ private Row next() throws XMLStreamException {
9292
}
9393

9494
int trackedColIndex = 0;
95-
int rowIndex = getRowIndexWithFallback(trackedRowIndex++);
95+
int rowIndex = getRowIndexWithFallback(trackedRowIndex);
9696

9797
List<Cell> cells = new ArrayList<>(rowCapacity);
9898
int physicalCellCount = 0;
@@ -102,7 +102,7 @@ private Row next() throws XMLStreamException {
102102
break;
103103
}
104104

105-
Cell cell = parseCell(trackedColIndex++, rowIndex);
105+
Cell cell = parseCell(trackedColIndex++);
106106
CellAddress addr = cell.getAddress();
107107
// we may have to adjust because we may have skipped blanks
108108
trackedColIndex = addr.getColumn() + 1;
@@ -111,6 +111,7 @@ private Row next() throws XMLStreamException {
111111
cells.set(addr.getColumn(), cell);
112112
physicalCellCount++;
113113
}
114+
trackedRowIndex++;
114115
rowCapacity = Math.max(rowCapacity, cells.size());
115116
return new Row(rowIndex, physicalCellCount, cells);
116117
}
@@ -127,7 +128,7 @@ private CellAddress getCellAddressWithFallback(int trackedColIndex, int trackedR
127128
new CellAddress(trackedRowIndex, trackedColIndex);
128129
}
129130

130-
private Cell parseCell(int trackedColIndex, int trackedRowIndex) throws XMLStreamException {
131+
private Cell parseCell(int trackedColIndex) throws XMLStreamException {
131132
CellAddress addr = getCellAddressWithFallback(trackedColIndex, trackedRowIndex);
132133
String type = r.getOptionalAttribute("t").orElse("n");
133134
String styleString = r.getAttribute("s");
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.dhatim.fastexcel.reader;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import java.io.InputStream;
6+
7+
import org.junit.jupiter.api.Test;
8+
9+
public class RowSpliteratorTest {
10+
11+
@Test
12+
void testBlankCells() throws Exception {
13+
InputStream is = Resources.open("/xml/blank_cells.xml");
14+
RowSpliterator it = new RowSpliterator(null, is);
15+
it.tryAdvance(row -> {
16+
assertEquals(8, row.getCellCount());
17+
Cell cell = row.getCell(7);
18+
assertEquals("H1", cell.getAddress().toString());
19+
});
20+
}
21+
22+
}
23+
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<sheetData>
2+
<row>
3+
<c t="b">
4+
<v>1</v>
5+
</c>
6+
<c r="C1" t="b">
7+
<v>1</v>
8+
</c>
9+
<c t="b">
10+
<v>1</v>
11+
</c>
12+
<c t="b">
13+
<v>1</v>
14+
</c>
15+
<c t="b">
16+
<v>1</v>
17+
</c>
18+
<c t="b">
19+
<v>1</v>
20+
</c>
21+
<c t="b">
22+
<v>1</v>
23+
</c>
24+
</row>
25+
<row>
26+
<c t="b">
27+
<v>1</v>
28+
</c>
29+
<c r="C2" t="b">
30+
<v>1</v>
31+
</c>
32+
<c t="b">
33+
<v>1</v>
34+
</c>
35+
<c t="b">
36+
<v>1</v>
37+
</c>
38+
<c t="b">
39+
<v>1</v>
40+
</c>
41+
<c t="b">
42+
<v>1</v>
43+
</c>
44+
<c t="b">
45+
<v>1</v>
46+
</c>
47+
</row>
48+
</sheetData>

0 commit comments

Comments
 (0)