org.apache.poi.hssf.usermodel
Class HSSFFormulaEvaluator

java.lang.Object
  extended by org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator

public class HSSFFormulaEvaluator
extends java.lang.Object

Author:
Amol S. Deshmukh < amolweb at ya hoo dot com > Limitations: Unfortunately, cyclic references will cause stackoverflow exception

Nested Class Summary
static class HSSFFormulaEvaluator.CellValue
          Mimics the 'data view' of a cell.
 
Field Summary
protected  HSSFRow row
           
protected  HSSFSheet sheet
           
protected  HSSFWorkbook workbook
           
 
Constructor Summary
HSSFFormulaEvaluator(HSSFSheet sheet, HSSFWorkbook workbook)
           
 
Method Summary
 HSSFFormulaEvaluator.CellValue evaluate(HSSFCell cell)
          If cell contains a formula, the formula is evaluated and returned, else the CellValue simply copies the appropriate cell value from the cell and also its cell type.
 HSSFCell evaluateInCell(HSSFCell cell)
          If cell contains formula, it evaluates the formula, and puts the formula result back into the cell.
protected static HSSFFormulaEvaluator.CellValue getCellValueForEval(ValueEval eval)
          Returns a CellValue wrapper around the supplied ValueEval instance.
protected static ValueEval getEvalForCell(HSSFCell cell, HSSFRow row, HSSFSheet sheet, HSSFWorkbook workbook)
          Given a cell, find its type and from that create an appropriate ValueEval impl instance and return that.
protected static Eval getEvalForPtg(Ptg ptg)
          returns an appropriate Eval impl instance for the Ptg.
protected static Eval getOperationEvalForPtg(OperationPtg ptg)
          returns the OperationEval concrete impl instance corresponding to the suplied operationPtg
protected static ValueEval internalEvaluate(HSSFCell srcCell, HSSFRow srcRow, HSSFSheet sheet, HSSFWorkbook workbook)
          Dev.
protected static void pushRef2DEval(ReferencePtg ptg, java.util.Stack stack, HSSFCell cell, HSSFRow row, HSSFSheet sheet, HSSFWorkbook workbook)
          create a Ref2DEval for ReferencePtg and push it on the stack.
protected static void pushRef3DEval(Ref3DPtg ptg, java.util.Stack stack, HSSFCell cell, HSSFRow row, HSSFSheet sheet, HSSFWorkbook workbook)
          create a Ref3DEval for Ref3DPtg and push it on the stack.
 void setCurrentRow(HSSFRow row)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

row

protected HSSFRow row

sheet

protected HSSFSheet sheet

workbook

protected HSSFWorkbook workbook
Constructor Detail

HSSFFormulaEvaluator

public HSSFFormulaEvaluator(HSSFSheet sheet,
                            HSSFWorkbook workbook)
Method Detail

setCurrentRow

public void setCurrentRow(HSSFRow row)

evaluate

public HSSFFormulaEvaluator.CellValue evaluate(HSSFCell cell)
If cell contains a formula, the formula is evaluated and returned, else the CellValue simply copies the appropriate cell value from the cell and also its cell type. This method should be preferred over evaluateInCell() when the call should not modify the contents of the original cell.

Parameters:
cell -
Returns:

evaluateInCell

public HSSFCell evaluateInCell(HSSFCell cell)
If cell contains formula, it evaluates the formula, and puts the formula result back into the cell. Else if cell does not contain formula, this method leaves the cell unchanged. Note that the same instance of HSSFCell is returned to allow chained calls like:
 int evaluatedCellType = evaluator.evaluateInCell(cell).getCellType();
 

Parameters:
cell -

getCellValueForEval

protected static HSSFFormulaEvaluator.CellValue getCellValueForEval(ValueEval eval)
Returns a CellValue wrapper around the supplied ValueEval instance.

Parameters:
eval -
Returns:

internalEvaluate

protected static ValueEval internalEvaluate(HSSFCell srcCell,
                                            HSSFRow srcRow,
                                            HSSFSheet sheet,
                                            HSSFWorkbook workbook)
Dev. Note: Internal evaluate must be passed only a formula cell else a runtime exception will be thrown somewhere inside the method. (Hence this is a private method.)

Parameters:
formula -
sheet -
workbook -
Returns:

getOperationEvalForPtg

protected static Eval getOperationEvalForPtg(OperationPtg ptg)
returns the OperationEval concrete impl instance corresponding to the suplied operationPtg

Parameters:
ptg -
Returns:

getEvalForPtg

protected static Eval getEvalForPtg(Ptg ptg)
returns an appropriate Eval impl instance for the Ptg. The Ptg must be one of: Area3DPtg, AreaPtg, ReferencePtg, Ref3DPtg, IntPtg, NumberPtg, StringPtg, BoolPtg
special Note: OperationPtg subtypes cannot be passed here!

Parameters:
ptg -
Returns:

getEvalForCell

protected static ValueEval getEvalForCell(HSSFCell cell,
                                          HSSFRow row,
                                          HSSFSheet sheet,
                                          HSSFWorkbook workbook)
Given a cell, find its type and from that create an appropriate ValueEval impl instance and return that. Since the cell could be an external reference, we need the sheet that this belongs to. Non existent cells are treated as empty.

Parameters:
cell -
sheet -
workbook -
Returns:

pushRef2DEval

protected static void pushRef2DEval(ReferencePtg ptg,
                                    java.util.Stack stack,
                                    HSSFCell cell,
                                    HSSFRow row,
                                    HSSFSheet sheet,
                                    HSSFWorkbook workbook)
create a Ref2DEval for ReferencePtg and push it on the stack. Non existent cells are treated as RefEvals containing BlankEval.

Parameters:
ptg -
stack -
cell -
sheet -
workbook -

pushRef3DEval

protected static void pushRef3DEval(Ref3DPtg ptg,
                                    java.util.Stack stack,
                                    HSSFCell cell,
                                    HSSFRow row,
                                    HSSFSheet sheet,
                                    HSSFWorkbook workbook)
create a Ref3DEval for Ref3DPtg and push it on the stack.

Parameters:
ptg -
stack -
cell -
sheet -
workbook -


Copyright 2007 The Apache Software Foundation or its licensors, as applicable.