Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…eader into main
  • Loading branch information
pjfanning committed Jan 20, 2022
2 parents c5ae0c2 + 0c1f031 commit 944d6a4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ public Iterator<Row> rowIterator() {
return reader.iterator();
}

/**
* {@inheritDoc}
*/
@Override
public Spliterator<Row> spliterator() {
// Long.MAX_VALUE is the documented value to use if the size is unknown
return Spliterators.spliterator(rowIterator(), Long.MAX_VALUE, Spliterator.ORDERED);
}

/**
* {@inheritDoc}
*/
Expand Down
22 changes: 22 additions & 0 deletions src/test/java/com/github/pjfanning/xlsx/StreamingReaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;

import static org.apache.poi.ss.usermodel.CellType.*;
import static org.apache.poi.ss.usermodel.Row.MissingCellPolicy.CREATE_NULL_AS_BLANK;
Expand Down Expand Up @@ -1268,6 +1269,27 @@ public void testReadSharedFormulasStrictFomat() throws Exception {
}
}

@Test
public void testSpliterator() throws Exception {
try (
InputStream is = new FileInputStream("src/test/resources/data_types.xlsx");
Workbook wb = StreamingReader.builder().open(is);
) {
Map<String, Integer> map = new HashMap<>();
wb.spliterator().forEachRemaining(sheet -> {
AtomicInteger count = new AtomicInteger();
sheet.spliterator().forEachRemaining(row -> {
row.spliterator().forEachRemaining(cell -> {
count.incrementAndGet();
});
});
map.put(sheet.getSheetName(), count.get());
});
assertEquals(1, map.size());
assertEquals(new Integer(20), map.get("TestSheet1"));
}
}

private void testReadSharedFormulasDisabled(StreamingReader.Builder builder) throws Exception {
try (
InputStream inputStream = new FileInputStream("src/test/resources/bug65464.xlsx");
Expand Down

0 comments on commit 944d6a4

Please sign in to comment.