/**
 * @param formula     the formula to parse
 * @param workbook    the parent workbook
 * @param formulaType a constant from {@link FormulaType}
 * @param sheetIndex  the 0-based index of the sheet this formula belongs to.
 * The sheet index is required to resolve sheet-level names. <code>-1</code> means that
 * the scope of the name will be ignored and  the parser will match named ranges only by name
 *
 * @return the parsed formula tokens
 */
        public static Ptg[] Parse(String formula, HSSFWorkbook workbook, FormulaType formulaType, int sheetIndex)
        {
            return FormulaParser.Parse(formula, CreateParsingWorkbook(workbook), formulaType, sheetIndex);
        }
 public OperandClassTransformer(FormulaType formulaType)
 {
     _formulaType = formulaType;
 }
Example #3
0
 public static Ptg[] Parse(String formula, IFormulaParsingWorkbook workbook, FormulaType formulaType)
 {
     return Parse(formula, workbook, formulaType, -1);
 }
Example #4
0
 /**
  * Parse a formula into a array of tokens
  *
  * @param formula	 the formula to parse
  * @param workbook	the parent workbook
  * @param formulaType the type of the formula, see {@link FormulaType}
  * @param sheetIndex  the 0-based index of the sheet this formula belongs to.
  * The sheet index is required to resolve sheet-level names. <code>-1</code> means that
  * the scope of the name will be ignored and  the parser will match names only by name
  *
  * @return array of parsed tokens
  * @throws FormulaParseException if the formula is unparsable
  */
 public static Ptg[] Parse(String formula, IFormulaParsingWorkbook workbook, FormulaType formulaType, int sheetIndex)
 {
     FormulaParser fp = new FormulaParser(formula, workbook, sheetIndex);
     fp.Parse();
     return fp.GetRPNPtg(formulaType);
 }
Example #5
0
 private Ptg[] GetRPNPtg(FormulaType formulaType)
 {
     OperandClassTransformer oct = new OperandClassTransformer(formulaType);
     // RVA is for 'operand class': 'reference', 'value', 'array'
     oct.TransformFormula(_rootNode);
     return ParseNode.ToTokenArray(_rootNode);
 }
Example #6
0
        private void SetFormula(String formula, FormulaType formulaType)
        {
            IWorkbook wb = _row.Sheet.Workbook;
            if (formula == null)
            {
                ((XSSFWorkbook)wb).OnDeleteFormula(this);
                if (_cell.IsSetF()) _cell.unsetF();
                return;
            }

            IFormulaParsingWorkbook fpb = XSSFEvaluationWorkbook.Create(wb);
            //validate through the FormulaParser
            FormulaParser.Parse(formula, fpb, formulaType, wb.GetSheetIndex(this.Sheet));

            CT_CellFormula f = new CT_CellFormula();
            f.Value = formula;
            _cell.f= (f);
            if (_cell.IsSetV()) _cell.unsetV();
        }