org.apache.poi.hssf.model
Class FormulaParser

java.lang.Object
  extended by org.apache.poi.hssf.model.FormulaParser

public final class FormulaParser
extends java.lang.Object

This class parses a formula string into a List of tokens in RPN order. Inspired by Lets Build a Compiler, by Jack Crenshaw BNF for the formula expression is : ::= [ ]* ::= [ ]* ::= | () | | ::= ([expression [, expression]*])

Author:
Avik Sengupta , Andrew C. oliver (acoliver at apache dot org), Eric Ladner (eladner at goldinc dot com), Cameron Riley (criley at ekmail.com), Peter M. Murray (pete at quantrix dot com), Pavel Krupets (pkrupets at palmtreebusiness dot com)

Field Summary
static int FORMULA_TYPE_ARRAY
           
static int FORMULA_TYPE_CELL
           
static int FORMULA_TYPE_CONDFOMRAT
           
static int FORMULA_TYPE_NAMEDRANGE
           
static int FORMULA_TYPE_SHARED
           
 
Constructor Summary
FormulaParser(java.lang.String formula, HSSFWorkbook book)
          Create the formula parser, with the string that is to be parsed against the supplied workbook.
 
Method Summary
 Ptg[] getRPNPtg()
          API call to retrive the array of Ptgs created as a result of the parsing
 Ptg[] getRPNPtg(int formulaType)
           
 void parse()
          Deprecated. use Ptg[] FormulaParser.parse(String, HSSFWorkbook) directly
static Ptg[] parse(java.lang.String formula, HSSFWorkbook book)
           
static java.lang.String toFormulaString(HSSFWorkbook book, java.util.List lptgs)
          Convenience method which takes in a list then passes it to the other toFormulaString signature.
static java.lang.String toFormulaString(HSSFWorkbook book, Ptg[] ptgs)
          Static method to convert an array of Ptgs in RPN order to a human readable string format in infix mode.
 java.lang.String toFormulaString(java.util.List lptgs)
          Convenience method which takes in a list then passes it to the other toFormulaString signature.
 java.lang.String toFormulaString(Ptg[] ptgs)
          Static method to convert an array of Ptgs in RPN order to a human readable string format in infix mode.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FORMULA_TYPE_CELL

public static final int FORMULA_TYPE_CELL
See Also:
Constant Field Values

FORMULA_TYPE_SHARED

public static final int FORMULA_TYPE_SHARED
See Also:
Constant Field Values

FORMULA_TYPE_ARRAY

public static final int FORMULA_TYPE_ARRAY
See Also:
Constant Field Values

FORMULA_TYPE_CONDFOMRAT

public static final int FORMULA_TYPE_CONDFOMRAT
See Also:
Constant Field Values

FORMULA_TYPE_NAMEDRANGE

public static final int FORMULA_TYPE_NAMEDRANGE
See Also:
Constant Field Values
Constructor Detail

FormulaParser

public FormulaParser(java.lang.String formula,
                     HSSFWorkbook book)
Create the formula parser, with the string that is to be parsed against the supplied workbook. A later call the parse() method to return ptg list in rpn order, then call the getRPNPtg() to retrive the parse results. This class is recommended only for single threaded use. If you only have a usermodel.HSSFWorkbook, and not a model.Workbook, then use the convenience method on usermodel.HSSFFormulaEvaluator

Method Detail

parse

public static Ptg[] parse(java.lang.String formula,
                          HSSFWorkbook book)

parse

public void parse()
Deprecated. use Ptg[] FormulaParser.parse(String, HSSFWorkbook) directly

API call to execute the parsing of the formula


getRPNPtg

public Ptg[] getRPNPtg()
API call to retrive the array of Ptgs created as a result of the parsing


getRPNPtg

public Ptg[] getRPNPtg(int formulaType)

toFormulaString

public static java.lang.String toFormulaString(HSSFWorkbook book,
                                               java.util.List lptgs)
Convenience method which takes in a list then passes it to the other toFormulaString signature.

Parameters:
book - workbook for 3D and named references
lptgs - list of Ptg, can be null or empty
Returns:
a human readable String

toFormulaString

public java.lang.String toFormulaString(java.util.List lptgs)
Convenience method which takes in a list then passes it to the other toFormulaString signature. Works on the current workbook for 3D and named references

Parameters:
lptgs - list of Ptg, can be null or empty
Returns:
a human readable String

toFormulaString

public static java.lang.String toFormulaString(HSSFWorkbook book,
                                               Ptg[] ptgs)
Static method to convert an array of Ptgs in RPN order to a human readable string format in infix mode.

Parameters:
book - workbook for named and 3D references
ptgs - array of Ptg, can be null or empty
Returns:
a human readable String

toFormulaString

public java.lang.String toFormulaString(Ptg[] ptgs)
Static method to convert an array of Ptgs in RPN order to a human readable string format in infix mode. Works on the current workbook for named and 3D references.

Parameters:
ptgs - array of Ptg, can be null or empty
Returns:
a human readable String


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