Class PoiItemReader<T>
java.lang.Object
org.springframework.batch.item.ItemStreamSupport
org.springframework.batch.item.support.AbstractItemStreamItemReader<T>
org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader<T>
org.springframework.batch.extensions.excel.AbstractExcelItemReader<T>
org.springframework.batch.extensions.excel.poi.PoiItemReader<T>
- Type Parameters:
T- the type
- All Implemented Interfaces:
org.springframework.batch.item.file.ResourceAwareItemReaderItemStream<T>,org.springframework.batch.item.ItemReader<T>,org.springframework.batch.item.ItemStream,org.springframework.batch.item.ItemStreamReader<T>,org.springframework.beans.factory.InitializingBean
ItemReader implementation which uses apache POI
to read an Excel file. It will read the file sheet for sheet and row for row. It is
based on the FlatFileItemReader
This class is not thread-safe.- Since:
- 0.1.0
- Author:
- Marten Deinum
-
Field Summary
Fields inherited from class org.springframework.batch.extensions.excel.AbstractExcelItemReader
logger -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voiddoClose()protected intThe number of sheets in the underlying workbook.protected SheetgetSheet(int sheet) Get the sheet based on the given sheet index.protected voidopenExcelFile(org.springframework.core.io.Resource resource, String password) Open the underlying file using theWorkbookFactory.voidsetDatesAsIso(boolean datesAsIso) Instead of using the format defined in the Excel sheet, read the date/time fields as an ISO formatted string instead.Methods inherited from class org.springframework.batch.extensions.excel.AbstractExcelItemReader
afterPropertiesSet, doOpen, doRead, jumpToItem, read, setEndAfterBlankLines, setLinesToSkip, setPassword, setResource, setRowMapper, setRowSetFactory, setSkippedRowsCallback, setStrictMethods inherited from class org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader
close, getCurrentItemCount, isSaveState, open, setCurrentItemCount, setMaxItemCount, setSaveState, updateMethods inherited from class org.springframework.batch.item.ItemStreamSupport
getExecutionContextKey, setExecutionContextName, setNameMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.batch.item.ItemStream
close, open, update
-
Constructor Details
-
PoiItemReader
public PoiItemReader()
-
-
Method Details
-
getSheet
Description copied from class:AbstractExcelItemReaderGet the sheet based on the given sheet index.- Specified by:
getSheetin classAbstractExcelItemReader<T>- Parameters:
sheet- the sheet index- Returns:
- the sheet or
nullwhen no sheet available.
-
getNumberOfSheets
protected int getNumberOfSheets()Description copied from class:AbstractExcelItemReaderThe number of sheets in the underlying workbook.- Specified by:
getNumberOfSheetsin classAbstractExcelItemReader<T>- Returns:
- the number of sheets.
-
doClose
- Overrides:
doClosein classAbstractExcelItemReader<T>- Throws:
Exception
-
openExcelFile
protected void openExcelFile(org.springframework.core.io.Resource resource, String password) throws Exception Open the underlying file using theWorkbookFactory. PreferFilebased access over anInputStream. Using a file will use fewer resources compared to an input stream. The latter will need to cache the whole sheet in-memory.- Specified by:
openExcelFilein classAbstractExcelItemReader<T>- Parameters:
resource- theResourcepointing to the Excel file.password- the password for opening the file- Throws:
Exception- is thrown for any errors.
-
setDatesAsIso
public void setDatesAsIso(boolean datesAsIso) Instead of using the format defined in the Excel sheet, read the date/time fields as an ISO formatted string instead. This is by defaultfalseto leave the original behavior.- Parameters:
datesAsIso- defaultfalse
-