org.springframework.batch.item.excel.poi
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.item.excel.AbstractExcelItemReader<T>
org.springframework.batch.item.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
public class PoiItemReader<T>
- extends AbstractExcelItemReader<T>
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
- Since:
- 0.5.0
- Author:
- Marten Deinum
|
Method Summary |
protected void |
doClose()
|
protected int |
getNumberOfSheets()
The number of sheets in the underlying workbook. |
protected Sheet |
getSheet(int sheet)
|
protected void |
openExcelFile(org.springframework.core.io.Resource resource)
Open the underlying file using the WorkbookFactory. |
| Methods inherited from class org.springframework.batch.item.excel.AbstractExcelItemReader |
afterPropertiesSet, doOpen, doRead, jumpToItem, read, setEndAfterBlankLines, setLinesToSkip, setResource, setRowMapper, setRowSetFactory, setSkippedRowsCallback, setStrict |
| Methods inherited from class org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader |
close, getCurrentItemCount, isSaveState, open, setCurrentItemCount, setMaxItemCount, setSaveState, update |
| Methods inherited from class org.springframework.batch.item.ItemStreamSupport |
getExecutionContextKey, setExecutionContextName, setName |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface org.springframework.batch.item.ItemStream |
close, open, update |
PoiItemReader
public PoiItemReader()
getSheet
protected Sheet getSheet(int sheet)
- Specified by:
getSheet in class AbstractExcelItemReader<T>
- Parameters:
sheet - the sheet index
- Returns:
- the sheet or
null when no sheet available.
getNumberOfSheets
protected int getNumberOfSheets()
- Description copied from class:
AbstractExcelItemReader
- The number of sheets in the underlying workbook.
- Specified by:
getNumberOfSheets in class AbstractExcelItemReader<T>
- Returns:
- the number of sheets.
doClose
protected void doClose()
throws Exception
- Overrides:
doClose in class AbstractExcelItemReader<T>
- Throws:
Exception
openExcelFile
protected void openExcelFile(org.springframework.core.io.Resource resource)
throws Exception
- Open the underlying file using the
WorkbookFactory. We keep track of the used InputStream so that
it can be closed cleanly on the end of reading the file. This to be able to release the resources used by
Apache POI.
- Specified by:
openExcelFile in class AbstractExcelItemReader<T>
- Parameters:
resource - the Resource pointing to the Excel file.
- Throws:
Exception - is thrown for any errors.
Copyright © 2017. All rights reserved.