public class ExcelReader extends AbstractStreamTableReader
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 and 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(Workbook workbook)
Constructor to read from an existing workbook.
|
| Modifier and Type | Method and Description |
|---|---|
int |
computeMaxColumnCount()
Computes the max row length of any rows in this sheet.
|
Object |
evaluateCellValue(Cell cell)
Returns the evaluated cell content.
|
FormulaEvaluator |
getFormulaEvaluator()
Returns a formula evaluator for the current workbook.
|
Row |
getLastExcelRow()
Returns the last delivered row.
|
protected Row |
getOrCreateRow(int rowNum)
Ensures that the sheet contains a row at the given index.
|
Sheet |
getSheet()
Returns the current sheet.
|
Object |
getValue(Cell cell)
Returns the value of the specified cell.
|
Object |
getValue(int rownum,
int cellNum)
Returns the value of the specified cell.
|
Object |
getValue(Row row,
int cellNum)
Returns the value of the specified cell.
|
Object[] |
getValues(int rowNum)
Returns the row at the given index.
|
Object[] |
getValues(Row row)
Returns the row as Java objects.
|
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(Row row)
Checks whether row has only blank cells.
|
Sheet |
selectSheet(int index)
Select the given sheet to be read from.
|
Sheet |
selectSheet(Sheet sheet)
Select the given sheet to be read from.
|
Sheet |
selectSheet(String name)
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, notifyComment, registerCommentCallBack, registerTypeConversionHandler, removeCommentCallBack, setColumnType, setHasHeaderRow, setHeaderRow, setHeaderRowRead, setMinimumColumnCount, unregisterCommentCallBack, unregisterTypeConversionHandlerpublic 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(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 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 Sheet selectSheet(String name)
name - name of sheetpublic Sheet selectSheet(Sheet sheet)
sheet - sheet to be selectedpublic Sheet selectSheet(int index)
index - index of sheetpublic Sheet getSheet()
public 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(Row row)
row - row to readpublic Object getValue(int rownum, int cellNum)
rownum - row indexcellNum - column indexpublic Object getValue(Row row, int cellNum)
row - row objectcellNum - column indexpublic Object getValue(Cell cell)
cell - cell objectpublic Object evaluateCellValue(Cell cell)
cell - cell to evaluatepublic 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(Row row)
retrieveNextRow().protected Row getOrCreateRow(int rowNum)
rowNum - index of rowCopyright © 2014. All rights reserved.