Search in sources :

Example 6 with RefPtg

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

the class TestSharedFormulaRecord method testConvertSharedFormulasOperandClasses_bug45123.

/**
     * The method <tt>SharedFormulaRecord.convertSharedFormulas()</tt> converts formulas from
     * 'shared formula' to 'single cell formula' format.  It is important that token operand
     * classes are preserved during this transformation, because Excel may not tolerate the
     * incorrect encoding.  The formula here is one such example (Excel displays #VALUE!).
     */
public void testConvertSharedFormulasOperandClasses_bug45123() {
    LittleEndianInput in = TestcaseRecordInputStream.createLittleEndian(SHARED_FORMULA_WITH_REF_ARRAYS_DATA);
    int encodedLen = in.readUShort();
    Ptg[] sharedFormula = Ptg.readTokens(encodedLen, in);
    SharedFormula sf = new SharedFormula(SpreadsheetVersion.EXCEL97);
    Ptg[] convertedFormula = sf.convertSharedFormulas(sharedFormula, 100, 200);
    RefPtg refPtg = (RefPtg) convertedFormula[1];
    assertEquals("$C101", refPtg.toFormulaString());
    if (refPtg.getPtgClass() == Ptg.CLASS_REF) {
        throw new AssertionFailedError("Identified bug 45123");
    }
    confirmOperandClasses(sharedFormula, convertedFormula);
}
Also used : Ptg(org.apache.poi.ss.formula.ptg.Ptg) RefPtg(org.apache.poi.ss.formula.ptg.RefPtg) LittleEndianInput(org.apache.poi.util.LittleEndianInput) RefPtg(org.apache.poi.ss.formula.ptg.RefPtg) AssertionFailedError(junit.framework.AssertionFailedError) SharedFormula(org.apache.poi.ss.formula.SharedFormula)

Example 7 with RefPtg

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

the class TestFormulaEvaluatorBugs method assertRefPtgA1.

private void assertRefPtgA1(char rv, Ptg[] ptgs, int at) {
    Ptg ptg = ptgs[at];
    assertEquals(RefPtg.class, ptg.getClass());
    assertEquals(0, ((RefPtg) ptg).getRow());
    assertEquals(0, ((RefPtg) ptg).getColumn());
    assertEquals(rv, ((RefPtg) ptg).getRVAType());
}
Also used : Ptg(org.apache.poi.ss.formula.ptg.Ptg) FuncVarPtg(org.apache.poi.ss.formula.ptg.FuncVarPtg) RefPtg(org.apache.poi.ss.formula.ptg.RefPtg) FuncPtg(org.apache.poi.ss.formula.ptg.FuncPtg) AreaPtg(org.apache.poi.ss.formula.ptg.AreaPtg)

Example 8 with RefPtg

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

the class TestFormulaRecord method testReserialize.

public void testReserialize() {
    FormulaRecord formulaRecord = new FormulaRecord();
    formulaRecord.setRow(1);
    formulaRecord.setColumn((short) 1);
    formulaRecord.setParsedExpression(new Ptg[] { new RefPtg("B$5") });
    formulaRecord.setValue(3.3);
    byte[] ser = formulaRecord.serialize();
    assertEquals(31, ser.length);
    RecordInputStream in = TestcaseRecordInputStream.create(ser);
    FormulaRecord fr2 = new FormulaRecord(in);
    assertEquals(3.3, fr2.getValue(), 0.0);
    Ptg[] ptgs = fr2.getParsedExpression();
    assertEquals(1, ptgs.length);
    RefPtg rp = (RefPtg) ptgs[0];
    assertEquals("B$5", rp.toFormulaString());
}
Also used : AttrPtg(org.apache.poi.ss.formula.ptg.AttrPtg) IntPtg(org.apache.poi.ss.formula.ptg.IntPtg) Ptg(org.apache.poi.ss.formula.ptg.Ptg) FuncVarPtg(org.apache.poi.ss.formula.ptg.FuncVarPtg) RefPtg(org.apache.poi.ss.formula.ptg.RefPtg) RefPtg(org.apache.poi.ss.formula.ptg.RefPtg)

Aggregations

RefPtg (org.apache.poi.ss.formula.ptg.RefPtg)8 Ptg (org.apache.poi.ss.formula.ptg.Ptg)7 AreaPtg (org.apache.poi.ss.formula.ptg.AreaPtg)4 FuncVarPtg (org.apache.poi.ss.formula.ptg.FuncVarPtg)4 Area3DPtg (org.apache.poi.ss.formula.ptg.Area3DPtg)3 AttrPtg (org.apache.poi.ss.formula.ptg.AttrPtg)3 FuncPtg (org.apache.poi.ss.formula.ptg.FuncPtg)3 IntPtg (org.apache.poi.ss.formula.ptg.IntPtg)3 Ref3DPtg (org.apache.poi.ss.formula.ptg.Ref3DPtg)3 Test (org.junit.Test)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 AssertionFailedError (junit.framework.AssertionFailedError)2 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)2 AbstractFunctionPtg (org.apache.poi.ss.formula.ptg.AbstractFunctionPtg)2 AddPtg (org.apache.poi.ss.formula.ptg.AddPtg)2 ArrayPtg (org.apache.poi.ss.formula.ptg.ArrayPtg)2 BoolPtg (org.apache.poi.ss.formula.ptg.BoolPtg)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