Package loci.poi.hssf.model
Class FormulaParser
java.lang.Object
loci.poi.hssf.model.FormulaParser
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
FieldsModifier and TypeFieldDescriptionstatic intstatic intstatic intstatic intstatic int -
Constructor Summary
ConstructorsConstructorDescriptionFormulaParser(String formula, Workbook book) Create the formula parser, with the string that is to be parsed against the supplied workbook. -
Method Summary
Modifier and TypeMethodDescriptionPtg[]API call to retrive the array of Ptgs created as a result of the parsingPtg[]getRPNPtg(int formulaType) voidparse()API call to execute the parsing of the formulatoFormulaString(List lptgs) Convience method which takes in a list then passes it to the other toFormulaString signature.static StringtoFormulaString(Workbook book, List lptgs) Convience method which takes in a list then passes it to the other toFormulaString signature.static StringtoFormulaString(Workbook book, Ptg[] ptgs) Static method to convert an array of Ptgs in RPN order to a human readable string format in infix mode.toFormulaString(Ptg[] ptgs) Static method to convert an array of Ptgs in RPN order to a human readable string format in infix mode.toString()toString on the parser instance returns the RPN ordered list of tokens Useful for testing
-
Field Details
-
FORMULA_TYPE_CELL
public static int FORMULA_TYPE_CELL -
FORMULA_TYPE_SHARED
public static int FORMULA_TYPE_SHARED -
FORMULA_TYPE_ARRAY
public static int FORMULA_TYPE_ARRAY -
FORMULA_TYPE_CONDFOMRAT
public static int FORMULA_TYPE_CONDFOMRAT -
FORMULA_TYPE_NAMEDRANGE
public static int FORMULA_TYPE_NAMEDRANGE
-
-
Constructor Details
-
FormulaParser
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 Details
-
parse
public void parse()API call to execute the parsing of the formula -
getRPNPtg
API call to retrive the array of Ptgs created as a result of the parsing -
getRPNPtg
-
toFormulaString
Convience method which takes in a list then passes it to the other toFormulaString signature.- Parameters:
book- workbook for 3D and named referenceslptgs- list of Ptg, can be null or empty- Returns:
- a human readable String
-
toFormulaString
Convience 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
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 referencesptgs- array of Ptg, can be null or empty- Returns:
- a human readable String
-
toFormulaString
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
-
toString
toString on the parser instance returns the RPN ordered list of tokens Useful for testing
-