Class ExcelReader

java.lang.Object
  |
  +--ExcelReader

public class ExcelReader
extends java.lang.Object

This class is a simple and a fast way to use the Andy Khan's excelread library. Using ExcelReader you can read data from excel sequentially or specifing positions of the cell to read.
Sequential reading allows you to use excel sheets like sequential text files. Each value is read using the getValue() method without passing to it any parameters. The ExcelReader class gets values one by one until the eof() method returns true.
When you know the structure of your data or you are using a table as input, the direct reading method can be used. You get values asking ExcelRead to return the value of each cell giving its (row, col) position.
The row and column index start both from 0 value.

Author:
Michele Sonnessa

Constructor Summary
ExcelReader(java.lang.String fileName)
          Opens the file and sets the first excel sheet the current sheet.
ExcelReader(java.lang.String fileName, boolean skipEmptyCells)
          Opens the file and sets the first excel sheet the current sheet.
If skipEmptyCells parameter is set to false, during sequential reading each empty cell read will be considered as blank string or a 0 value.
ExcelReader(java.lang.String fileName, boolean skipEmptyCells, java.lang.String sheetName)
          This constuctor allows you to open and to select directly the source sheet.
 
Method Summary
 boolean checkForLabelCell()
          Checks if the next cell in reading sequence contains a label (leaving unchanged the counter)
 boolean checkForLabelCell(int atRow, int atCol)
          Checks if the cell at (atRow, atCol) position contains a label (leaving unchanged the counter)
 boolean eof()
          Tests if reading head reached the end of file (the last element in sequence).
 boolean eol()
          Tests if reading head reached the end of line.
 boolean existsSheetWithName(java.lang.String sheetName)
          Tests if the 'sheetName' sheet is present in the current Excel document.
 xlrd.Sheet getCurrentSheet()
          Returns the current sheet reference.
 double getDblValue()
          Gets the next value in reading sequence and returns it as a double value.
 double getDblValue(int atRow, int atCol)
          Gets the value at (atRow, atCol) position and returns it as a double value.
 int getIntValue()
          Gets the next value in reading sequence and returns it as an int value.
 int getIntValue(int atRow, int atCol)
          Gets the value at (atRow, atCol) position and returns it as an int value.
 java.lang.String getStrValue()
          Gets the next value in reading sequence and returns it as a String value.
 java.lang.String getStrValue(int atRow, int atCol)
          Gets the value at (atRow, atCol) position and returns it as a String value.
 void selectSheet(java.lang.String sheetName)
          Changes the current sheet to the 'sheetName'.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExcelReader

public ExcelReader(java.lang.String fileName)
Opens the file and sets the first excel sheet the current sheet. During sequential reading empty cells will be skipped.

ExcelReader

public ExcelReader(java.lang.String fileName,
                   boolean skipEmptyCells)
Opens the file and sets the first excel sheet the current sheet.
If skipEmptyCells parameter is set to false, during sequential reading each empty cell read will be considered as blank string or a 0 value.
For instance: consider a sequence like this: |3|0| |7|
If skipEmptyCells is true it returns 3, 0, 7
otherwise it returns 3, 0, 0, 7

ExcelReader

public ExcelReader(java.lang.String fileName,
                   boolean skipEmptyCells,
                   java.lang.String sheetName)
This constuctor allows you to open and to select directly the source sheet. If the sheet does not exist the program will be terminated printing an error message.
If skipEmptyCells parameter is set to false, during sequential reading each empty cell read will be considered as blank string or a 0 value.
For instance: consider a sequence like this: |3|0| |7|
If skipEmptyCells is true it returns 3, 0, 7
otherwise it returns 3, 0, 0, 7
Method Detail

existsSheetWithName

public boolean existsSheetWithName(java.lang.String sheetName)
Tests if the 'sheetName' sheet is present in the current Excel document. It is to be used before the selectSheet() method in order to avoid program termination.

selectSheet

public void selectSheet(java.lang.String sheetName)
Changes the current sheet to the 'sheetName'. If the sheet is not present the program is terminated. Before using this method is better to test its presence using the existsSheetWithName() method.

getCurrentSheet

public xlrd.Sheet getCurrentSheet()
Returns the current sheet reference.

getStrValue

public java.lang.String getStrValue(int atRow,
                                    int atCol)
Gets the value at (atRow, atCol) position and returns it as a String value.

getIntValue

public int getIntValue(int atRow,
                       int atCol)
Gets the value at (atRow, atCol) position and returns it as an int value. It uses the Interger.parseInt() method to cast the String original value.

getDblValue

public double getDblValue(int atRow,
                          int atCol)
Gets the value at (atRow, atCol) position and returns it as a double value. It uses the Double.parseDouble() method to cast the String original value. NOTICE: All ',' chars are automatically converted in '.' chars. [Italian settings]

checkForLabelCell

public boolean checkForLabelCell(int atRow,
                                 int atCol)
Checks if the cell at (atRow, atCol) position contains a label (leaving unchanged the counter)

getStrValue

public java.lang.String getStrValue()
Gets the next value in reading sequence and returns it as a String value.

getIntValue

public int getIntValue()
Gets the next value in reading sequence and returns it as an int value. It uses the Interger.parseInt() method to cast the String original value.

getDblValue

public double getDblValue()
Gets the next value in reading sequence and returns it as a double value. It uses the Double.parseDouble() method to cast the String original value.

checkForLabelCell

public boolean checkForLabelCell()
Checks if the next cell in reading sequence contains a label (leaving unchanged the counter)

eof

public boolean eof()
Tests if reading head reached the end of file (the last element in sequence).

eol

public boolean eol()
Tests if reading head reached the end of line.