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);
}
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());
}
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());
}
Aggregations