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

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


                Match('(');
                ParseNode inside = comparisonExpression();
                Match(')');
                return new ParseNode(ParenthesisPtg.instance, inside);
            case '"':
                return new ParseNode(new StringPtg(parseStringLiteral()));
            case '{':
                Match('{');
                ParseNode arrayNode = parseArray();
                Match('}');
                return arrayNode;
View Full Code Here


  public void testNonAlphaFormula() {
    String currencyCell = "F3";
    Ptg[] ptgs = parseFormula("\"TOTAL[\"&"+currencyCell+"&\"]\"");
    assertEquals(5, ptgs.length);
    assertTrue ("Ptg[0] is a string", (ptgs[0] instanceof StringPtg));
    StringPtg firstString = (StringPtg)ptgs[0];

    assertEquals("TOTAL[", firstString.getValue());
    //the PTG order isn't 100% correct but it still works - dmui
  }
View Full Code Here

  private static void confirmStringParse(String singleQuotedValue) {
    // formula: internal quotes become double double, surround with double quotes
    String formula = '"' + singleQuotedValue.replaceAll("'", "\"\"") + '"';
    String expectedValue = singleQuotedValue.replace('\'', '"');

    StringPtg sp = (StringPtg) parseSingleToken(formula, StringPtg.class);
    assertEquals(expectedValue, sp.getValue());
  }
View Full Code Here

    StringPtg sp = (StringPtg) parseSingleToken(formula, StringPtg.class);
    assertEquals(expectedValue, sp.getValue());
  }
  public void testParseStringLiterals_bug28754() {

    StringPtg sp;
    try {
      sp = (StringPtg) parseSingleToken("\"test\"\"ing\"", StringPtg.class);
    } catch (RuntimeException e) {
      if(e.getMessage().startsWith("Cannot Parse")) {
        throw new AssertionFailedError("Identified bug 28754a");
      }
      throw e;
    }
    assertEquals("test\"ing", sp.getValue());

    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet = wb.createSheet();
    wb.setSheetName(0, "Sheet1");
View Full Code Here

        sb.append('\0'); // list delimiter is the nul char
      }
      sb.append(_explicitListValues[i]);
   
    }
    return new Ptg[] { new StringPtg(sb.toString()), };
  }
View Full Code Here

        Ptg[] asts = fp.getRPNPtg();
        assertEquals(7, asts.length);

        BoolPtg flag  = (BoolPtg) asts[0];
    AttrPtg funif = (AttrPtg) asts[1];
        StringPtg y = (StringPtg) asts[2];
    AttrPtg goto1 = (AttrPtg) asts[3];
        StringPtg n = (StringPtg) asts[4];


        assertEquals(true, flag.getValue());
        assertEquals("Y", y.getValue());
        assertEquals("N", n.getValue());
        assertEquals("IF", funif.toFormulaString((Workbook) null));
        assertTrue("Goto ptg exists", goto1.isGoto());
    }
View Full Code Here

    FormulaParser fp = new FormulaParser(function, null);
    fp.parse();
    Ptg[] asts = fp.getRPNPtg();
    assertEquals("5 ptgs expected", 5, asts.length);
    assertTrue ("Ptg[0] is a string", (asts[0] instanceof StringPtg));
    StringPtg firstString = (StringPtg)asts[0];   
   
    assertEquals("TOTAL[", firstString.getValue());
    //the PTG order isn't 100% correct but it still works - dmui
   
         
  }
View Full Code Here

    Ptg[] ptgs = parseFormula("IF(TRUE,\"Y\",\"N\")");
    assertEquals(7, ptgs.length);

    BoolPtg flag  = (BoolPtg) ptgs[0];
    AttrPtg funif = (AttrPtg) ptgs[1];
    StringPtg y = (StringPtg) ptgs[2];
    AttrPtg goto1 = (AttrPtg) ptgs[3];
    StringPtg n = (StringPtg) ptgs[4];


    assertEquals(true, flag.getValue());
    assertEquals("Y", y.getValue());
    assertEquals("N", n.getValue());
    assertEquals("IF", funif.toFormulaString());
    assertTrue("Goto ptg exists", goto1.isGoto());
  }
View Full Code Here

  public void testNonAlphaFormula() {
    String currencyCell = "F3";
    Ptg[] ptgs = parseFormula("\"TOTAL[\"&"+currencyCell+"&\"]\"");
    assertEquals(5, ptgs.length);
    assertTrue ("Ptg[0] is a string", (ptgs[0] instanceof StringPtg));
    StringPtg firstString = (StringPtg)ptgs[0];

    assertEquals("TOTAL[", firstString.getValue());
    //the PTG order isn't 100% correct but it still works - dmui
  }
View Full Code Here

  private static void confirmStringParse(String singleQuotedValue) {
    // formula: internal quotes become double double, surround with double quotes
    String formula = '"' + singleQuotedValue.replaceAll("'", "\"\"") + '"';
    String expectedValue = singleQuotedValue.replace('\'', '"');

    StringPtg sp = (StringPtg) parseSingleToken(formula, StringPtg.class);
    assertEquals(expectedValue, sp.getValue());
  }
View Full Code Here

TOP

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

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.