biz.c24.io.api.presentation.stream
Class SpreadSheetReader

java.lang.Object
  extended by biz.c24.io.api.presentation.stream.SpreadSheet
      extended by biz.c24.io.api.presentation.stream.SpreadSheetReader

public class SpreadSheetReader
extends SpreadSheet

SpreadSheet broker implementation for reading.

Represents the functional part for binding the SpreadSheet to the tree object. (Provides the inverse functionality for SpreadSheet writer broker.) Additionally to the generic SpreadSheet broker it provides the variety methods for reading the values with respect of their type definitions:

Formula support
The SpreadSheet cell with formula may be interpreted as usual text or as SpreadSheet formula depends on client. To interpret the SpreadSheet cell with formula as usual text, the value of cell needs to be read as textual data. In this case string will be always prepend by equal sign ("="). Otherwise the SpreadSheet cell with formula will be evaluated before and client may request its result. In case if result of SpreadSheet formula may represent the string value, the formula string will return only. See also SpreadSheet Formula support disclaimer.

Note. This implementation do not provide the way to get the formula value if its result has textual data type.

The sheet resolution procedure DO NOT creates the sheet "on the fly" if it is not exists. If requested sheet is absent the corresponding exception will be thrown. For details see the method description.

Version:
$Revision: 15830 $ $Date: 2009-08-12 07:41:51 -0400 (Wed, 12 Aug 2009) $
See Also:
SpreadSheet, SpreadSheetWriter

Nested Class Summary
 
Nested classes/interfaces inherited from class biz.c24.io.api.presentation.stream.SpreadSheet
SpreadSheet.Locator
 
Field Summary
protected  org.apache.poi.ss.usermodel.FormulaEvaluator evaluator
          SpreadSheet formula evaluator.
 
Fields inherited from class biz.c24.io.api.presentation.stream.SpreadSheet
ditches, location, workbook
 
Constructor Summary
  SpreadSheetReader(InputStream stream)
          Constructor with input stream.
protected SpreadSheetReader(org.apache.poi.ss.usermodel.Workbook workbook)
          Constructor with 3rd party workbook instance.
 
Method Summary
 boolean getBooleanValue()
          Returns the boolean value of current cell.
protected  org.apache.poi.ss.usermodel.Cell getCellAt(SpreadSheet.Locator position)
          Returns the evaluated cell at specified position.
protected  org.apache.poi.ss.usermodel.Cell getCellAt(SpreadSheet.Locator position, boolean evaluate)
          Returns the (optionally) evaluated cell at specified position.
protected  org.apache.poi.ss.usermodel.CellValue getCellValueAt(SpreadSheet.Locator position)
          Returns the cell value at specified position.
 Date getDateValue()
          Returns the date value of current cell.
 double getNumericValue()
          Returns the numeric value of current cell.
 String getStringValue()
          Reads the textual data from current cell.
protected  int resolveSheet(String name)
          Returns the sheet index in workbook used.
 
Methods inherited from class biz.c24.io.api.presentation.stream.SpreadSheet
calculateNext, getDitch, getLocation, getSheetName, mark, next, occupy, parse, rollback, setStartLocation, withdraw
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

evaluator

protected final org.apache.poi.ss.usermodel.FormulaEvaluator evaluator
SpreadSheet formula evaluator.

Constructor Detail

SpreadSheetReader

public SpreadSheetReader(InputStream stream)
                  throws Exception
Constructor with input stream.

Constructs the SpreadSheet reader broker with specified input stream. The data will be analysed and proper Workbook implementation will be instantiated. The format of incoming data should be listed in supported format list.

Parameters:
stream - The incoming data stream.
Throws:
IllegalArgumentException - If format could not be defined.
IOException - If I/O error occurred or data in BIFF format is failed to read.
org.apache.poi.POIXMLException - If data in OOXML format is failed to read.
Exception

SpreadSheetReader

protected SpreadSheetReader(org.apache.poi.ss.usermodel.Workbook workbook)
Constructor with 3rd party workbook instance.

Constructs the SpreadSheet broker instance with provided workbook. Also SpreadSheet formula evaluator is instantiated to provide the ability to evaluate the SpreadSheet formula.

Parameters:
workbook - The workbook implementation that will be used.
Method Detail

getStringValue

public String getStringValue()
Reads the textual data from current cell.

Analyse the current cell and returns the textual representation of its value. So, depends on cell type will return corresponding values: formula will be returned as prepend by equal character the formula string, the numeric and boolean string equivalent will be returned on corresponding cells.

Returns:
The text that from requested cell.
Throws:
IllegalStateException - If requested data type is not fit the current cell.

getNumericValue

public double getNumericValue()
Returns the numeric value of current cell.

Returns:
The number corresponding to current cell value.
Throws:
IllegalStateException - If requested data type is not fit the current cell.

getDateValue

public Date getDateValue()
Returns the date value of current cell.

Returns:
The date corresponding to current cell value.
Throws:
IllegalStateException - If requested data type is not fit the current cell.

getBooleanValue

public boolean getBooleanValue()
Returns the boolean value of current cell.

Returns:
The boolean corresponding to current cell value.
Throws:
IllegalStateException - If requested data type is not fit the current cell.

getCellAt

protected org.apache.poi.ss.usermodel.Cell getCellAt(SpreadSheet.Locator position)
Returns the evaluated cell at specified position.

Delegates call to the another cell getter.

Parameters:
position - The position at which the requested cell is.
Returns:
The requested cell.
See Also:
getCellAt(biz.c24.io.api.presentation.stream.SpreadSheet.Locator, boolean)

getCellAt

protected org.apache.poi.ss.usermodel.Cell getCellAt(SpreadSheet.Locator position,
                                                     boolean evaluate)
Returns the (optionally) evaluated cell at specified position.

Returns the cell at the specified position. If flag evaluate was set, the cell is evaluated before given away. In case if there is no cell at specified position (i.e. there is no such sheet, row or column), the special Null cell is returned.

Parameters:
position - The position at which the requested cell is.
evaluate - On true forces to evaluate cell (assumed with formula) before return.
Returns:
The requested cell.

getCellValueAt

protected org.apache.poi.ss.usermodel.CellValue getCellValueAt(SpreadSheet.Locator position)
Returns the cell value at specified position.

returns the already evaluated cell value as special object. The specified position defines the cell address. If specified address point to nowhere (no sheet, no row or column), the numeric zero ("0.0") value is returned.

Parameters:
position - The position at which the requested cell is.
Returns:
The requested cell value.

resolveSheet

protected int resolveSheet(String name)
Returns the sheet index in workbook used.

Returns the requested sheet by its name. If provided name is null the current existing sheet index is returned. If workbook has no requested sheet or there is no any current (if null is specified as name), the negative value (-1) is returned.

Specified by:
resolveSheet in class SpreadSheet
Parameters:
name - The requested sheet name, may be null.
Returns:
The requested sheet index, zero-based.


C24 Technologies © 2002-2012: All Rights Reserved.