Class ExcelReader


public class ExcelReader extends AbstractReader
Obtains records from a Microsoft Excel document.
  • Constructor Details

  • Method Details

    • open

      public void open()
      Description copied from class: DataEndpoint
      Makes this endpoint ready for reading or writing.
      Overrides:
      open in class AbstractReader
    • close

      public void close() throws DataException
      Description copied from class: DataEndpoint
      Indicates that this endpoint has finished reading or writing.
      Overrides:
      close in class DataEndpoint
      Throws:
      DataException
    • getDocument

      public ExcelDocument getDocument()
    • getSheetName

      public String getSheetName()
      Returns the name of the sheet to read; when set, it is used instead of the sheet index (default is null).
    • setSheetName

      public ExcelReader setSheetName(String sheetName)
      Sets the name of the sheet to read; when set, it is used instead of the sheet index (default is null).
    • getSheetIndex

      public int getSheetIndex()
      Returns the 0-based index of the sheet to read when no sheet name is set (defaults to 0).
    • setSheetIndex

      public ExcelReader setSheetIndex(int sheetIndex)
      Sets the 0-based index of the sheet to read when no sheet name is set (defaults to 0).
    • getStartingColumn

      public int getStartingColumn()
      Returns the 0-based index of the first column read; earlier columns are skipped (defaults to 0).
    • setStartingColumn

      public ExcelReader setStartingColumn(int startingColumn)
      Sets the 0-based index of the first column read; earlier columns are skipped (defaults to 0).
    • getLineNumber

      public long getLineNumber()
      Returns the 0-based index of the next sheet row to read.
    • isEvaluateExpressions

      public boolean isEvaluateExpressions()
      Indicates if cell formulas/expressions should be evaluated and the result set as the field's value (default true), otherwise, the cell's formula will be set as the field's value and no evaluation will take place.
    • setEvaluateExpressions

      public ExcelReader setEvaluateExpressions(boolean evaluateExpressions)
      Indicates if cell formulas/expressions should be evaluated and the result set as the field's value (default true), otherwise, the cell's formula will be set as the field's value and no evaluation will take place.
    • getFailedExpressionStrategy

      public ExcelReader.FailedExpressionStrategy getFailedExpressionStrategy()
      Indicates how to handle failures when evaluating cell formulas/expressions (default ExcelReader.FailedExpressionStrategy.FAIL). This only applies when setEvaluateExpressions(boolean) is set to true (the default) and evaluation fails.
    • setFailedExpressionStrategy

      public ExcelReader setFailedExpressionStrategy(ExcelReader.FailedExpressionStrategy failedExpressionStrategy)
      Indicates how to handle failures when evaluating cell formulas/expressions (default ExcelReader.FailedExpressionStrategy.FAIL). This only applies when setEvaluateExpressions(boolean) is set to true (the default) and evaluation fails.
    • isUseSheetColumnCount

      public boolean isUseSheetColumnCount()
      Indicates whether to use the entire worksheet (or just the current row) when determining each record's field count (default is false).
    • setUseSheetColumnCount

      public ExcelReader setUseSheetColumnCount(boolean useSheetColumnCount)
      Set whether to use the entire worksheet (or just the current row) when determining each record's field count. Default is false meaning each record may contain a different number of fields depending on the row.
    • setAutoCloseDocument

      public ExcelReader setAutoCloseDocument(boolean autoCloseDocument)
      Indicates if the ExcelDocument should be closed when this endpoint is closed. The default is false.
    • isAutoCloseDocument

      public boolean isAutoCloseDocument()
      Indicates if the ExcelDocument should be closed when this endpoint is closed. The default is false.
    • setFieldNamesInFirstRow

      public ExcelReader setFieldNamesInFirstRow(boolean fieldNamesInFirstRow)
      Description copied from class: AbstractReader
      Indicates if the first row holds the field names instead of data (default is false); must be called before AbstractReader.open().
      Overrides:
      setFieldNamesInFirstRow in class AbstractReader
    • setFieldNames

      public ExcelReader setFieldNames(String... fieldNames)
      Description copied from class: AbstractReader
      Sets the names given to each record's fields, taking precedence over names in the first row; must be called before AbstractReader.open().
      Overrides:
      setFieldNames in class AbstractReader
    • setFieldNames

      public ExcelReader setFieldNames(Collection<String> fieldNames)
      Description copied from class: AbstractReader
      Sets the names given to each record's fields, taking precedence over names in the first row; must be called before AbstractReader.open().
      Overrides:
      setFieldNames in class AbstractReader
    • setStartingRow

      public ExcelReader setStartingRow(int startingRow)
      Description copied from class: AbstractReader
      Sets the 0-based index of the first row to read; earlier rows are skipped when the reader is opened (default is 0).
      Overrides:
      setStartingRow in class AbstractReader
    • setLastRow

      public ExcelReader setLastRow(int lastRow)
      Description copied from class: AbstractReader
      Sets the 0-based index of the last row to read or -1 to read to the end (default is -1).
      Overrides:
      setLastRow in class AbstractReader
    • setSkipEmptyRows

      public ExcelReader setSkipEmptyRows(boolean skipEmptyRows)
      Description copied from class: AbstractReader
      Indicates that rows with only null values should not be returned by the reader (default is false).
      Overrides:
      setSkipEmptyRows in class AbstractReader
    • setSaveLineage

      public ExcelReader setSaveLineage(boolean saveLineage)
      Description copied from class: DataReader
      Indicates if record and field lineage is captured for each record read (default is false); enabling it throws if DataReader.isLineageSupported() is false or the product edition does not include lineage.
      Overrides:
      setSaveLineage in class DataReader
    • setDescription

      public ExcelReader setDescription(String description)
      Description copied from class: Endpoint
      Sets the optional text shown for this endpoint in Endpoint.toString() and exception properties.
      Overrides:
      setDescription in class Endpoint
    • fillRecord

      protected boolean fillRecord(Record record) throws Throwable
      Description copied from class: AbstractReader
      Populates the given record with the next row's values; returns false at the end of the input.
      Specified by:
      fillRecord in class AbstractReader
      Throws:
      Throwable
    • read

      public Record read() throws DataException
      Description copied from class: DataReader
      Reads the next record from this DataReader and increases the record-count by 1. This method will first read any pushed (DataReader.push(Record)) records before reading from the underlying source.

      If no record is available, null will be returned. This method blocks until a record is available, the end of the stream is reached, or an exception is thrown.

      Any exception raised while reading will be converted to a DataException using DataObject.exception(Throwable).

      Subclasses generally do not need to override this method, instead they should implement DataReader.readImpl().

      Overrides:
      read in class AbstractReader
      Throws:
      DataException
      See Also:
    • isLineageSupported

      public boolean isLineageSupported()
      Description copied from class: DataReader
      Indicates if this reader can capture record and field lineage (false unless overridden by a reader that supports it).
      Overrides:
      isLineageSupported in class DataReader
    • addLineage

      protected Record addLineage(Record record)
      Description copied from class: DataReader
      Called by DataReader.read() for each record from DataReader.readImpl() while lineage is saved; the default copies recordLineage into every field along with its original index and name. Overrides set their source details on recordLineage first and end with super.addLineage(record).
      Overrides:
      addLineage in class DataReader
    • isReadMetadata

      public boolean isReadMetadata()
      Returns whether Excel metadata (such as hyperlinks and cell styles) should be read. When enabled, metadata is attached to fields as session properties that can be retrieved using ExcelFieldMetadata.
      Returns:
      true if metadata reading is enabled, false otherwise (default is false)
      See Also:
    • setReadMetadata

      public ExcelReader setReadMetadata(boolean readMetadata)
      Sets whether Excel metadata (such as hyperlinks and cell styles) should be read. When enabled, metadata is attached to fields as session properties that can be retrieved using ExcelFieldMetadata.
      Parameters:
      readMetadata - true to enable metadata reading, false to disable (default is false)
      Returns:
      this ExcelReader instance for method chaining
      See Also:
    • addExceptionProperties

      public DataException addExceptionProperties(DataException exception)
      Description copied from class: Endpoint
      Adds this endpoint's current state to a DataException. Since this method is called whenever an exception is thrown, subclasses should override it to add their specific information.
      Overrides:
      addExceptionProperties in class AbstractReader