Skip to content

Commit dc80b07

Browse files
committed
Adding test case
1 parent 716caad commit dc80b07

File tree

3 files changed

+80
-3
lines changed

3 files changed

+80
-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
boolean isHidden = "1".equals(r.getAttribute("hidden"));
9797

9898
List<Cell> cells = new ArrayList<>(rowCapacity);
@@ -103,7 +103,7 @@ private Row next() throws XMLStreamException {
103103
break;
104104
}
105105

106-
Cell cell = parseCell(trackedColIndex++, rowIndex);
106+
Cell cell = parseCell(trackedColIndex++);
107107
CellAddress addr = cell.getAddress();
108108
// we may have to adjust because we may have skipped blanks
109109
trackedColIndex = addr.getColumn() + 1;
@@ -112,6 +112,7 @@ private Row next() throws XMLStreamException {
112112
cells.set(addr.getColumn(), cell);
113113
physicalCellCount++;
114114
}
115+
trackedRowIndex++;
115116
rowCapacity = Math.max(rowCapacity, cells.size());
116117
return new Row(rowIndex, physicalCellCount, cells, isHidden);
117118
}
@@ -128,7 +129,7 @@ private CellAddress getCellAddressWithFallback(int trackedColIndex, int trackedR
128129
new CellAddress(trackedRowIndex, trackedColIndex);
129130
}
130131

131-
private Cell parseCell(int trackedColIndex, int trackedRowIndex) throws XMLStreamException {
132+
private Cell parseCell(int trackedColIndex) throws XMLStreamException {
132133
CellAddress addr = getCellAddressWithFallback(trackedColIndex, trackedRowIndex);
133134
String type = r.getOptionalAttribute("t").orElse("n");
134135
String styleString = r.getAttribute("s");
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
it.tryAdvance(row -> {
21+
assertEquals(8, row.getCellCount());
22+
Cell cell = row.getCell(7);
23+
assertEquals("H2", cell.getAddress().toString());
24+
});
25+
}
26+
27+
}
28+
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)