Class FormulaParser

java.lang.Object
loci.poi.hssf.model.FormulaParser

public class FormulaParser extends 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 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

      public FormulaParser(String formula, Workbook 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 Details

    • parse

      public void parse()
      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 String toFormulaString(Workbook book, List lptgs)
      Convience 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 String toFormulaString(List lptgs)
      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

      public static String toFormulaString(Workbook 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 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
    • toString

      public String toString()
      toString on the parser instance returns the RPN ordered list of tokens Useful for testing
      Overrides:
      toString in class Object