Package org.apache.poi.hssf.record.formula

Examples of org.apache.poi.hssf.record.formula.NamePtg


        Ptg[] ptg = fp.getRPNPtg();

        AbstractFunctionPtg tfunc = (AbstractFunctionPtg) ptg[0];
        assertEquals("externalflag", tfunc.getName());

        NamePtg tname = (NamePtg) ptg[1];
        assertEquals("FOO", tname.toFormulaString(w));
    }
View Full Code Here


            }
            if (ptg instanceof MemErrPtg) { continue; }
            if (ptg instanceof MissingArgPtg) { continue; }
            if (ptg instanceof NamePtg) {
                // named ranges, macro functions
                NamePtg namePtg = (NamePtg) ptg;
                stack.push(new NameEval(namePtg.getIndex()));
                continue;
            }
            if (ptg instanceof NameXPtg) {
                // TODO - external functions
                continue;
View Full Code Here

  public void testMacroFunction() {
    HSSFWorkbook w = new HSSFWorkbook();
    Ptg[] ptg = FormulaParser.parse("FOO()", w);

    // the name gets encoded as the first arg
    NamePtg tname = (NamePtg) ptg[0];
    assertEquals("FOO", tname.toFormulaString(w));

    AbstractFunctionPtg tfunc = (AbstractFunctionPtg) ptg[1];
    assertTrue(tfunc.isExternalFunction());
  }
View Full Code Here

  private ValueEval getEvalForPtg(Ptg ptg, OperationEvaluationContext ec) {
    //  consider converting all these (ptg instanceof XxxPtg) expressions to (ptg.getClass() == XxxPtg.class)

    if (ptg instanceof NamePtg) {
      // named ranges, macro functions
      NamePtg namePtg = (NamePtg) ptg;
      EvaluationName nameRecord = _workbook.getName(namePtg);
      if (nameRecord.isFunctionName()) {
        return new NameEval(nameRecord.getNameText());
      }
      if (nameRecord.hasFormula()) {
View Full Code Here

    Ptg[] ptg = HSSFFormulaParser.parse("myFunc()", w);
    // myFunc() actually takes 1 parameter.  Don't know if POI will ever be able to detect this problem

    // the name gets encoded as the first arg
    NamePtg tname = (NamePtg) ptg[0];
    assertEquals("myFunc", tname.toFormulaString(book));

    AbstractFunctionPtg tfunc = (AbstractFunctionPtg) ptg[1];
    assertTrue(tfunc.isExternalFunction());
  }
View Full Code Here

    }
    public boolean isRange() {
      return _nameRecord.hasFormula(); // TODO - is this right?
    }
    public NamePtg createPtg() {
      return new NamePtg(_index);
    }
View Full Code Here

    public boolean isRange() {
      return hasFormula(); // TODO - is this right?
    }
    public NamePtg createPtg() {
      return new NamePtg(_index);
    }
View Full Code Here

  private ValueEval getEvalForPtg(Ptg ptg, int sheetIndex, EvaluationTracker tracker) {
    //  consider converting all these (ptg instanceof XxxPtg) expressions to (ptg.getClass() == XxxPtg.class)

    if (ptg instanceof NamePtg) {
      // named ranges, macro functions
      NamePtg namePtg = (NamePtg) ptg;
      EvaluationName nameRecord = _workbook.getName(namePtg);
      if (nameRecord.isFunctionName()) {
        return new NameEval(nameRecord.getNameText());
      }
      if (nameRecord.hasFormula()) {
View Full Code Here

        }
        public boolean isRange() {
            return _nameRecord.hasFormula(); // TODO - is this right?
        }
        public NamePtg createPtg() {
            return new NamePtg(_index);
        }
View Full Code Here

        row.createCell(1).setCellFormula("sales_1");
        row.createCell(2).setCellFormula("sales_1*3");

        //check that NamePtg refers to the correct NameRecord
        Ptg[] ptgs1 = HSSFFormulaParser.parse("sales_1", wb, FormulaType.CELL, 0);
        NamePtg nPtg1 = (NamePtg)ptgs1[0];
        assertSame(nm1, wb.getNameAt(nPtg1.getIndex()));

        Ptg[] ptgs2 = HSSFFormulaParser.parse("sales_1", wb, FormulaType.CELL, 1);
        NamePtg nPtg2 = (NamePtg)ptgs2[0];
        assertSame(nm2, wb.getNameAt(nPtg2.getIndex()));

        //check that the formula evaluator returns the correct result
        HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(wb);
        assertEquals(3.0, evaluator.evaluate(sh1.getRow(0).getCell(1)).getNumberValue());
        assertEquals(6.0, evaluator.evaluate(sh1.getRow(0).getCell(2)).getNumberValue());
View Full Code Here

TOP

Related Classes of org.apache.poi.hssf.record.formula.NamePtg

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.