Package io.github.connellite.excel
Class AbstractExcelSheetRowIterator<V>
java.lang.Object
io.github.connellite.excel.AbstractExcelSheetRowIterator<V>
- Type Parameters:
V- map value type produced by subclasses
- All Implemented Interfaces:
AutoCloseable,Iterator<Map<String,V>>
- Direct Known Subclasses:
ExcelRowIterator,ExcelRowStringIterator
public abstract class AbstractExcelSheetRowIterator<V>
extends Object
implements Iterator<Map<String,V>>, AutoCloseable
Forward-only iterator over data rows of an Apache POI
Sheet. The first row is treated as a header;
column names are derived from that row (blank headers become Column_0, Column_1, …).
This type implements only Iterator (not Iterable) so APIs with overloads for both
(for example org.jooq.lambda.Seq.seq) remain unambiguous when passed this instance.
For enhanced for-loops use asIterable(); it is single-pass and delegates to this iterator.
close() closes the Workbook passed to the constructor. Do not close the same workbook
again afterward (for example avoid wrapping the workbook in a second try-with-resources if the iterator
already owns shutdown).
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final org.apache.poi.ss.usermodel.DataFormatterprotected final Iterator<org.apache.poi.ss.usermodel.Row> -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractExcelSheetRowIterator(org.apache.poi.ss.usermodel.Workbook workbook, String sheetName) -
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Iterator
forEachRemaining, remove
-
Field Details
-
columnNames
-
rowIterator
-
formatter
protected final org.apache.poi.ss.usermodel.DataFormatter formatter
-
-
Constructor Details
-
AbstractExcelSheetRowIterator
protected AbstractExcelSheetRowIterator(org.apache.poi.ss.usermodel.Workbook workbook, String sheetName) - Parameters:
workbook- workbook that contains the sheet; closed whenclose()is calledsheetName- name of the sheet to read- Throws:
IllegalArgumentException- if no sheet exists with the given name
-
-
Method Details
-
getCellObjectValue
-
asIterable
Single-passIterableview for enhanced for-loops.Iterable.iterator()returns -
hasNext
public boolean hasNext() -
next
-
getColumnNames
Column names from the first row of the sheet, in order. -
close
Closes the workbook from construction.- Specified by:
closein interfaceAutoCloseable- Throws:
Exception
-