Class ExcelReader
Obtains records from a Microsoft Excel document.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumIndicates how to handle failures when evaluating cell formulas/expressions.Nested classes/interfaces inherited from class com.northconcepts.datapipeline.core.DataEndpoint
DataEndpoint.State -
Field Summary
Fields inherited from class com.northconcepts.datapipeline.core.AbstractReader
currentRecord, fieldNames, lastRow, startingRowFields inherited from class com.northconcepts.datapipeline.core.DataReader
fieldLineage, recordLineageFields inherited from class com.northconcepts.datapipeline.core.DataEndpoint
lastRecord, PRODUCT, PRODUCT_VERSION, VENDOR, XML_INPUT_FACTORY_KEYFields inherited from class com.northconcepts.datapipeline.core.Endpoint
BUFFER_SIZE, captureElapsedTime, DEFAULT_READ_BUFFER_SIZEFields inherited from class com.northconcepts.datapipeline.core.DataObject
id, log, name, TIMESTAMP_FORMAT -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddExceptionProperties(DataException exception) Adds this endpoint's current state to aDataException.protected RecordaddLineage(Record record) Called byDataReader.read()for each record fromDataReader.readImpl()while lineage is saved; the default copiesrecordLineageinto every field along with its original index and name.voidclose()Indicates that this endpoint has finished reading or writing.protected booleanfillRecord(Record record) Populates the given record with the next row's values; returns false at the end of the input.Indicates how to handle failures when evaluating cell formulas/expressions (defaultExcelReader.FailedExpressionStrategy.FAIL).longReturns the 0-based index of the next sheet row to read.intReturns the 0-based index of the sheet to read when no sheet name is set (defaults to 0).Returns the name of the sheet to read; when set, it is used instead of the sheet index (default is null).intReturns the 0-based index of the first column read; earlier columns are skipped (defaults to 0).booleanIndicates if the ExcelDocument should be closed when this endpoint is closed.booleanIndicates 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.booleanIndicates if this reader can capture record and field lineage (false unless overridden by a reader that supports it).booleanReturns whether Excel metadata (such as hyperlinks and cell styles) should be read.booleanIndicates whether to use the entire worksheet (or just the current row) when determining each record's field count (default is false).voidopen()Makes this endpoint ready for reading or writing.read()Reads the next record from thisDataReaderand increases the record-count by 1.setAutoCloseDocument(boolean autoCloseDocument) Indicates if the ExcelDocument should be closed when this endpoint is closed.setDescription(String description) Sets the optional text shown for this endpoint inEndpoint.toString()and exception properties.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.setFailedExpressionStrategy(ExcelReader.FailedExpressionStrategy failedExpressionStrategy) Indicates how to handle failures when evaluating cell formulas/expressions (defaultExcelReader.FailedExpressionStrategy.FAIL).setFieldNames(String... fieldNames) Sets the names given to each record's fields, taking precedence over names in the first row; must be called beforeAbstractReader.open().setFieldNames(Collection<String> fieldNames) Sets the names given to each record's fields, taking precedence over names in the first row; must be called beforeAbstractReader.open().setFieldNamesInFirstRow(boolean fieldNamesInFirstRow) Indicates if the first row holds the field names instead of data (default is false); must be called beforeAbstractReader.open().setLastRow(int lastRow) Sets the 0-based index of the last row to read or -1 to read to the end (default is -1).setReadMetadata(boolean readMetadata) Sets whether Excel metadata (such as hyperlinks and cell styles) should be read.setSaveLineage(boolean saveLineage) Indicates if record and field lineage is captured for each record read (default is false); enabling it throws ifDataReader.isLineageSupported()is false or the product edition does not include lineage.setSheetIndex(int sheetIndex) Sets the 0-based index of the sheet to read when no sheet name is set (defaults to 0).setSheetName(String sheetName) Sets the name of the sheet to read; when set, it is used instead of the sheet index (default is null).setSkipEmptyRows(boolean skipEmptyRows) Indicates that rows with only null values should not be returned by the reader (default is false).setStartingColumn(int startingColumn) Sets the 0-based index of the first column read; earlier columns are skipped (defaults to 0).setStartingRow(int startingRow) Sets the 0-based index of the first row to read; earlier rows are skipped when the reader is opened (default is 0).setUseSheetColumnCount(boolean useSheetColumnCount) Set whether to use the entire worksheet (or just the current row) when determining each record's field count.Methods inherited from class com.northconcepts.datapipeline.core.AbstractReader
getFieldNames, getLastRow, getStartingRow, isFieldNamesInFirstRow, isSkipEmptyRows, readImplMethods inherited from class com.northconcepts.datapipeline.core.DataReader
available, getBufferSize, getNestedEndpoint, getNestedReader, getReader, getRootEndpoint, getRootReader, isExhausted, isSaveLineage, peek, pop, push, skipMethods inherited from class com.northconcepts.datapipeline.core.DataEndpoint
decrementRecordCount, enableJmx, getLastRecord, getRecordCount, getRecordCountAsBigInteger, getRecordCountAsString, incrementRecordCount, isRecordCountBigInteger, resetRecordCount, toStringMethods inherited from class com.northconcepts.datapipeline.core.Endpoint
addElapsedtime, assertClosed, assertNotOpened, assertOpened, finalize, getClosedOn, getDescription, getElapsedTime, getElapsedTimeAsString, getOpenedOn, getOpenElapsedTime, getOpenElapsedTimeAsString, getSelfTime, getSelfTimeAsString, getState, isCaptureElapsedTime, isClosed, isOpen, setCaptureElapsedTime
-
Constructor Details
-
ExcelReader
-
-
Method Details
-
open
public void open()Description copied from class:DataEndpointMakes this endpoint ready for reading or writing.- Overrides:
openin classAbstractReader
-
close
Description copied from class:DataEndpointIndicates that this endpoint has finished reading or writing.- Overrides:
closein classDataEndpoint- Throws:
DataException
-
getDocument
-
getSheetName
Returns the name of the sheet to read; when set, it is used instead of the sheet index (default is null). -
setSheetName
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
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
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
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
Indicates how to handle failures when evaluating cell formulas/expressions (defaultExcelReader.FailedExpressionStrategy.FAIL). This only applies whensetEvaluateExpressions(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 (defaultExcelReader.FailedExpressionStrategy.FAIL). This only applies whensetEvaluateExpressions(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
Set whether to use the entire worksheet (or just the current row) when determining each record's field count. Default isfalsemeaning each record may contain a different number of fields depending on the row. -
setAutoCloseDocument
Indicates if the ExcelDocument should be closed when this endpoint is closed. The default isfalse. -
isAutoCloseDocument
public boolean isAutoCloseDocument()Indicates if the ExcelDocument should be closed when this endpoint is closed. The default isfalse. -
setFieldNamesInFirstRow
Description copied from class:AbstractReaderIndicates if the first row holds the field names instead of data (default is false); must be called beforeAbstractReader.open().- Overrides:
setFieldNamesInFirstRowin classAbstractReader
-
setFieldNames
Description copied from class:AbstractReaderSets the names given to each record's fields, taking precedence over names in the first row; must be called beforeAbstractReader.open().- Overrides:
setFieldNamesin classAbstractReader
-
setFieldNames
Description copied from class:AbstractReaderSets the names given to each record's fields, taking precedence over names in the first row; must be called beforeAbstractReader.open().- Overrides:
setFieldNamesin classAbstractReader
-
setStartingRow
Description copied from class:AbstractReaderSets the 0-based index of the first row to read; earlier rows are skipped when the reader is opened (default is 0).- Overrides:
setStartingRowin classAbstractReader
-
setLastRow
Description copied from class:AbstractReaderSets the 0-based index of the last row to read or -1 to read to the end (default is -1).- Overrides:
setLastRowin classAbstractReader
-
setSkipEmptyRows
Description copied from class:AbstractReaderIndicates that rows with only null values should not be returned by the reader (default is false).- Overrides:
setSkipEmptyRowsin classAbstractReader
-
setSaveLineage
Description copied from class:DataReaderIndicates if record and field lineage is captured for each record read (default is false); enabling it throws ifDataReader.isLineageSupported()is false or the product edition does not include lineage.- Overrides:
setSaveLineagein classDataReader
-
setDescription
Description copied from class:EndpointSets the optional text shown for this endpoint inEndpoint.toString()and exception properties.- Overrides:
setDescriptionin classEndpoint
-
fillRecord
Description copied from class:AbstractReaderPopulates the given record with the next row's values; returns false at the end of the input.- Specified by:
fillRecordin classAbstractReader- Throws:
Throwable
-
read
Description copied from class:DataReaderReads the next record from thisDataReaderand 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,
nullwill 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
DataExceptionusingDataObject.exception(Throwable).Subclasses generally do not need to override this method, instead they should implement
DataReader.readImpl().- Overrides:
readin classAbstractReader- Throws:
DataException- See Also:
-
isLineageSupported
public boolean isLineageSupported()Description copied from class:DataReaderIndicates if this reader can capture record and field lineage (false unless overridden by a reader that supports it).- Overrides:
isLineageSupportedin classDataReader
-
addLineage
Description copied from class:DataReaderCalled byDataReader.read()for each record fromDataReader.readImpl()while lineage is saved; the default copiesrecordLineageinto every field along with its original index and name. Overrides set their source details onrecordLineagefirst and end withsuper.addLineage(record).- Overrides:
addLineagein classDataReader
-
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 usingExcelFieldMetadata.- Returns:
- true if metadata reading is enabled, false otherwise (default is false)
- See Also:
-
setReadMetadata
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 usingExcelFieldMetadata.- Parameters:
readMetadata- true to enable metadata reading, false to disable (default is false)- Returns:
- this ExcelReader instance for method chaining
- See Also:
-
addExceptionProperties
Description copied from class:EndpointAdds this endpoint's current state to aDataException. Since this method is called whenever an exception is thrown, subclasses should override it to add their specific information.- Overrides:
addExceptionPropertiesin classAbstractReader
-