TableReader, Iterable<Object[]>, Iterator<Object[]>public class ExcelReader extends AbstractStreamTableReader
This class reads Excel sheets like a stream, meaning
delivering rows one by one from the current sheet.
Use this reader if you want to load an Excel file by creating a File
and passing it to the constructor.
Example:
java.io.File f = new java.io.File("excel-test.xls");
ExcelReader in = new ExcelReader(f);
while (in.hasNext()) {
Object columns[] = in.next();
// Do something here
}
in.close();
selectSheet(int),
selectSheet(String)| Constructor | Description |
|---|---|
ExcelReader() |
Default constructor.
|
ExcelReader(File file) |
Constructor for reading from a file.
|
ExcelReader(InputStream in) |
Constructor to read from an existing stream.
|
ExcelReader(String file) |
Constructor for reading from a file.
|
ExcelReader(org.apache.poi.ss.usermodel.Workbook workbook) |
Constructor to read from an existing workbook.
|
| Modifier and Type | Method | Description |
|---|---|---|
int |
computeMaxColumnCount() |
Computes the max row length of any rows in this sheet.
|
Object |
evaluateCellValue(org.apache.poi.ss.usermodel.Cell cell) |
Returns the evaluated cell content.
|
org.apache.poi.ss.usermodel.FormulaEvaluator |
getFormulaEvaluator() |
Returns a formula evaluator for the current workbook.
|
org.apache.poi.ss.usermodel.Row |
getLastExcelRow() |
Returns the last delivered row.
|
protected org.apache.poi.ss.usermodel.Row |
getOrCreateRow(int rowNum) |
Ensures that the sheet contains a row at the given index.
|
org.apache.poi.ss.usermodel.Sheet |
getSheet() |
Returns the current sheet.
|
Object |
getValue(int rownum,
int cellNum) |
Returns the value of the specified cell.
|
Object |
getValue(org.apache.poi.ss.usermodel.Cell cell) |
Returns the value of the specified cell.
|
Object |
getValue(org.apache.poi.ss.usermodel.Row row,
int cellNum) |
Returns the value of the specified cell.
|
Object[] |
getValues(int rowNum) |
Returns the row at the given index.
|
Object[] |
getValues(org.apache.poi.ss.usermodel.Row row) |
Returns the row as Java objects.
|
org.apache.poi.ss.usermodel.Workbook |
getWorkbook() |
Returns the workbook.
|
boolean |
hasNext() |
Returns whether there is a row to be read in the current sheet.
|
boolean |
isEvaluateFormulas() |
Returns whether formulas shall be evaluated or not (default is
true). |
boolean |
isSkipBlankRows() |
Returns whether blank rows will be skipped or not while reading.
|
Object[] |
next() |
Returns the next row.
|
void |
open() |
Opens the stream by retrieving the workbook and selecting the first sheet.
|
protected void |
readHeaderRow() |
Reads the header row from next line.
|
void |
reset() |
Resets the reader by resetting the current row index
|
protected void |
retrieveNextRow() |
Retrieves the next row from the current sheet.
|
protected boolean |
rowHasOnlyBlankCells(org.apache.poi.ss.usermodel.Row row) |
Checks whether row has only blank cells.
|
org.apache.poi.ss.usermodel.Sheet |
selectSheet(int index) |
Select the given sheet to be read from.
|
org.apache.poi.ss.usermodel.Sheet |
selectSheet(String name) |
Select the given sheet to be read from.
|
org.apache.poi.ss.usermodel.Sheet |
selectSheet(org.apache.poi.ss.usermodel.Sheet sheet) |
Select the given sheet to be read from.
|
void |
setEvaluateFormulas(boolean evaluateFormulas) |
Sets whether formulas shall be evaluated or not (default is
true). |
void |
setSkipBlankRows(boolean skipBlankRows) |
Sets whether blank rows will be skipped or not while reading.
|
close, createInputStreamReader, createReader, getCharsetDecoder, getInputStream, getReader, remove, setCharset, setCharset, setCharsetDecoder, setInputStreamaddCommentCallBack, convert, convert, convertArray, convertArray, get, getColumnIndex, getColumnType, getHeaderRow, getLineCount, getMinimumColumnCount, getRowCount, getTypeConversionHandler, hasHeaderRow, incrementLineCount, incrementRowCount, isHeaderRowRead, iterator, notifyComment, registerCommentCallBack, registerTypeConversionHandler, removeCommentCallBack, setColumnType, setHasHeaderRow, setHeaderRow, setHeaderRowRead, setMinimumColumnCount, unregisterCommentCallBack, unregisterTypeConversionHandlerforEach, spliteratorforEachRemainingpublic ExcelReader()
public ExcelReader(File file) throws FileNotFoundException
file - file to read fromFileNotFoundException - when file does not existpublic ExcelReader(InputStream in)
in - input stream to be usedpublic ExcelReader(org.apache.poi.ss.usermodel.Workbook workbook)
workbook - the workbook be usedpublic ExcelReader(String file) throws FileNotFoundException
file - file to read fromFileNotFoundException - when file does not existpublic void open()
open in interface TableReaderopen in class AbstractTableReaderAbstractTableReader.open()public org.apache.poi.ss.usermodel.Workbook getWorkbook()
public boolean isSkipBlankRows()
true when blank rows are skipped (default), false otherwisepublic void setSkipBlankRows(boolean skipBlankRows)
skipBlankRows - true when blank rows are skipped (default), false otherwisepublic int computeMaxColumnCount()
public org.apache.poi.ss.usermodel.Sheet selectSheet(String name)
name - name of sheetpublic org.apache.poi.ss.usermodel.Sheet selectSheet(org.apache.poi.ss.usermodel.Sheet sheet)
sheet - sheet to be selectedpublic org.apache.poi.ss.usermodel.Sheet selectSheet(int index)
index - index of sheetpublic org.apache.poi.ss.usermodel.Sheet getSheet()
public org.apache.poi.ss.usermodel.Row getLastExcelRow()
next().next()public void reset()
reset in interface TableReaderreset in class AbstractStreamTableReaderAbstractStreamTableReader.reset(),
AbstractTableReader.getRowCount()public boolean hasNext()
Iterator.hasNext(),
selectSheet(int)public Object[] next()
Iterator.next(),
AbstractTableReader.getRowCount()public Object[] getValues(int rowNum)
rowNum - row index to readpublic Object[] getValues(org.apache.poi.ss.usermodel.Row row)
row - row to readpublic Object getValue(int rownum, int cellNum)
rownum - row indexcellNum - column indexpublic Object getValue(org.apache.poi.ss.usermodel.Row row, int cellNum)
row - row objectcellNum - column indexpublic Object getValue(org.apache.poi.ss.usermodel.Cell cell)
cell - cell objectpublic Object evaluateCellValue(org.apache.poi.ss.usermodel.Cell cell)
cell - cell to evaluatepublic org.apache.poi.ss.usermodel.FormulaEvaluator getFormulaEvaluator()
public boolean isEvaluateFormulas()
true).true when formulas are evaluatedpublic void setEvaluateFormulas(boolean evaluateFormulas)
true).evaluateFormulas - true or falseprotected void readHeaderRow()
readHeaderRow in class AbstractTableReaderAbstractTableReader.readHeaderRow()protected void retrieveNextRow()
hasNext()
and next(). Blank rows are skipped when isSkipBlankRows()
return true.protected boolean rowHasOnlyBlankCells(org.apache.poi.ss.usermodel.Row row)
retrieveNextRow().row - the row to checkprotected org.apache.poi.ss.usermodel.Row getOrCreateRow(int rowNum)
rowNum - index of rowCopyright © 2018. All rights reserved.