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

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 This class is not thread-safe.
Since:
0.1.0
Author:
Marten Deinum
  • Constructor Details

    • PoiItemReader

      public PoiItemReader()
  • Method Details

    • getSheet

      protected Sheet getSheet(int sheet)
      Description copied from class: AbstractExcelItemReader
      Get the sheet based on the given sheet index.
      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, String password) throws Exception
      Open the underlying file using the WorkbookFactory. Prefer File based access over an InputStream. 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:
      openExcelFile in class AbstractExcelItemReader<T>
      Parameters:
      resource - the Resource pointing 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 default false to leave the original behavior.
      Parameters:
      datesAsIso - default false