Search in sources :

Example 6 with StringPtg

use of org.apache.poi.ss.formula.ptg.StringPtg in project poi by apache.

the class TestFormulaParserIf method testYN.

public void testYN() {
    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("tAttrSkip ptg exists", goto1.isSkip());
}
Also used : IntPtg(org.apache.poi.ss.formula.ptg.IntPtg) Ptg(org.apache.poi.ss.formula.ptg.Ptg) LessEqualPtg(org.apache.poi.ss.formula.ptg.LessEqualPtg) FuncVarPtg(org.apache.poi.ss.formula.ptg.FuncVarPtg) RefPtg(org.apache.poi.ss.formula.ptg.RefPtg) NotEqualPtg(org.apache.poi.ss.formula.ptg.NotEqualPtg) FuncPtg(org.apache.poi.ss.formula.ptg.FuncPtg) AttrPtg(org.apache.poi.ss.formula.ptg.AttrPtg) AddPtg(org.apache.poi.ss.formula.ptg.AddPtg) MultiplyPtg(org.apache.poi.ss.formula.ptg.MultiplyPtg) StringPtg(org.apache.poi.ss.formula.ptg.StringPtg) LessThanPtg(org.apache.poi.ss.formula.ptg.LessThanPtg) BoolPtg(org.apache.poi.ss.formula.ptg.BoolPtg) BoolPtg(org.apache.poi.ss.formula.ptg.BoolPtg) StringPtg(org.apache.poi.ss.formula.ptg.StringPtg) AttrPtg(org.apache.poi.ss.formula.ptg.AttrPtg)

Example 7 with StringPtg

use of org.apache.poi.ss.formula.ptg.StringPtg in project poi by apache.

the class TestFormulaParser method testParseStringLiterals_bug28754.

@Test
public void testParseStringLiterals_bug28754() throws IOException {
    StringPtg sp;
    try {
        sp = (StringPtg) parseSingleToken("\"test\"\"ing\"", StringPtg.class);
    } catch (RuntimeException e) {
        if (e.getMessage().startsWith("Cannot Parse")) {
            fail("Identified bug 28754a");
        }
        throw e;
    }
    assertEquals("test\"ing", sp.getValue());
    HSSFWorkbook wb = new HSSFWorkbook();
    try {
        HSSFSheet sheet = wb.createSheet();
        wb.setSheetName(0, "Sheet1");
        HSSFRow row = sheet.createRow(0);
        HSSFCell cell = row.createCell(0);
        cell.setCellFormula("right(\"test\"\"ing\", 3)");
        String actualCellFormula = cell.getCellFormula();
        if ("RIGHT(\"test\"ing\",3)".equals(actualCellFormula)) {
            fail("Identified bug 28754b");
        }
        assertEquals("RIGHT(\"test\"\"ing\",3)", actualCellFormula);
    } finally {
        wb.close();
    }
}
Also used : HSSFCell(org.apache.poi.hssf.usermodel.HSSFCell) HSSFRow(org.apache.poi.hssf.usermodel.HSSFRow) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) StringPtg(org.apache.poi.ss.formula.ptg.StringPtg) UnicodeString(org.apache.poi.hssf.record.common.UnicodeString) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Test(org.junit.Test)

Example 8 with StringPtg

use of org.apache.poi.ss.formula.ptg.StringPtg in project poi by apache.

the class TestFormulaParser method testLeadingSpaceInString.

@Test
public void testLeadingSpaceInString() {
    String value = "  hi  ";
    Ptg[] ptgs = parseFormula("\"" + value + "\"");
    confirmTokenClasses(ptgs, StringPtg.class);
    assertTrue("ptg0 contains exact value", ((StringPtg) ptgs[0]).getValue().equals(value));
}
Also used : NumberPtg(org.apache.poi.ss.formula.ptg.NumberPtg) ArrayPtg(org.apache.poi.ss.formula.ptg.ArrayPtg) AttrPtg(org.apache.poi.ss.formula.ptg.AttrPtg) PercentPtg(org.apache.poi.ss.formula.ptg.PercentPtg) RangePtg(org.apache.poi.ss.formula.ptg.RangePtg) AddPtg(org.apache.poi.ss.formula.ptg.AddPtg) EqualPtg(org.apache.poi.ss.formula.ptg.EqualPtg) UnaryMinusPtg(org.apache.poi.ss.formula.ptg.UnaryMinusPtg) NameXPtg(org.apache.poi.ss.formula.ptg.NameXPtg) RefPtg(org.apache.poi.ss.formula.ptg.RefPtg) DividePtg(org.apache.poi.ss.formula.ptg.DividePtg) GreaterThanPtg(org.apache.poi.ss.formula.ptg.GreaterThanPtg) MultiplyPtg(org.apache.poi.ss.formula.ptg.MultiplyPtg) Ref3DPtg(org.apache.poi.ss.formula.ptg.Ref3DPtg) StringPtg(org.apache.poi.ss.formula.ptg.StringPtg) ErrPtg(org.apache.poi.ss.formula.ptg.ErrPtg) Ptg(org.apache.poi.ss.formula.ptg.Ptg) Area3DPtg(org.apache.poi.ss.formula.ptg.Area3DPtg) NamePtg(org.apache.poi.ss.formula.ptg.NamePtg) MemAreaPtg(org.apache.poi.ss.formula.ptg.MemAreaPtg) ConcatPtg(org.apache.poi.ss.formula.ptg.ConcatPtg) UnaryPlusPtg(org.apache.poi.ss.formula.ptg.UnaryPlusPtg) BoolPtg(org.apache.poi.ss.formula.ptg.BoolPtg) IntersectionPtg(org.apache.poi.ss.formula.ptg.IntersectionPtg) AbstractFunctionPtg(org.apache.poi.ss.formula.ptg.AbstractFunctionPtg) IntPtg(org.apache.poi.ss.formula.ptg.IntPtg) UnionPtg(org.apache.poi.ss.formula.ptg.UnionPtg) FuncVarPtg(org.apache.poi.ss.formula.ptg.FuncVarPtg) SubtractPtg(org.apache.poi.ss.formula.ptg.SubtractPtg) FuncPtg(org.apache.poi.ss.formula.ptg.FuncPtg) MissingArgPtg(org.apache.poi.ss.formula.ptg.MissingArgPtg) MemFuncPtg(org.apache.poi.ss.formula.ptg.MemFuncPtg) PowerPtg(org.apache.poi.ss.formula.ptg.PowerPtg) AreaPtg(org.apache.poi.ss.formula.ptg.AreaPtg) ParenthesisPtg(org.apache.poi.ss.formula.ptg.ParenthesisPtg) UnicodeString(org.apache.poi.hssf.record.common.UnicodeString) StringPtg(org.apache.poi.ss.formula.ptg.StringPtg) Test(org.junit.Test)

Aggregations

StringPtg (org.apache.poi.ss.formula.ptg.StringPtg)8 UnicodeString (org.apache.poi.hssf.record.common.UnicodeString)4 Ptg (org.apache.poi.ss.formula.ptg.Ptg)4 Test (org.junit.Test)4 AbstractFunctionPtg (org.apache.poi.ss.formula.ptg.AbstractFunctionPtg)3 AddPtg (org.apache.poi.ss.formula.ptg.AddPtg)3 AttrPtg (org.apache.poi.ss.formula.ptg.AttrPtg)3 BoolPtg (org.apache.poi.ss.formula.ptg.BoolPtg)3 FuncPtg (org.apache.poi.ss.formula.ptg.FuncPtg)3 FuncVarPtg (org.apache.poi.ss.formula.ptg.FuncVarPtg)3 IntPtg (org.apache.poi.ss.formula.ptg.IntPtg)3 MultiplyPtg (org.apache.poi.ss.formula.ptg.MultiplyPtg)3 RefPtg (org.apache.poi.ss.formula.ptg.RefPtg)3 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)2 Area3DPtg (org.apache.poi.ss.formula.ptg.Area3DPtg)2 AreaPtg (org.apache.poi.ss.formula.ptg.AreaPtg)2 ArrayPtg (org.apache.poi.ss.formula.ptg.ArrayPtg)2 ConcatPtg (org.apache.poi.ss.formula.ptg.ConcatPtg)2 DividePtg (org.apache.poi.ss.formula.ptg.DividePtg)2 EqualPtg (org.apache.poi.ss.formula.ptg.EqualPtg)2