Search in sources :

Example 1 with Ref3DPxg

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

the class OperationEvaluationContext method getExternalNameXEval.

private ValueEval getExternalNameXEval(ExternalName externName, String workbookName) {
    try {
        // Fetch the workbook this refers to, and the name as defined with that
        WorkbookEvaluator refWorkbookEvaluator = _bookEvaluator.getOtherWorkbookEvaluator(workbookName);
        EvaluationName evaluationName = refWorkbookEvaluator.getName(externName.getName(), externName.getIx() - 1);
        if (evaluationName != null && evaluationName.hasFormula()) {
            if (evaluationName.getNameDefinition().length > 1) {
                throw new RuntimeException("Complex name formulas not supported yet");
            }
            // Need to evaluate the reference in the context of the other book
            OperationEvaluationContext refWorkbookContext = new OperationEvaluationContext(refWorkbookEvaluator, refWorkbookEvaluator.getWorkbook(), -1, -1, -1, _tracker);
            Ptg ptg = evaluationName.getNameDefinition()[0];
            if (ptg instanceof Ref3DPtg) {
                Ref3DPtg ref3D = (Ref3DPtg) ptg;
                return refWorkbookContext.getRef3DEval(ref3D);
            } else if (ptg instanceof Ref3DPxg) {
                Ref3DPxg ref3D = (Ref3DPxg) ptg;
                return refWorkbookContext.getRef3DEval(ref3D);
            } else if (ptg instanceof Area3DPtg) {
                Area3DPtg area3D = (Area3DPtg) ptg;
                return refWorkbookContext.getArea3DEval(area3D);
            } else if (ptg instanceof Area3DPxg) {
                Area3DPxg area3D = (Area3DPxg) ptg;
                return refWorkbookContext.getArea3DEval(area3D);
            }
        }
        return ErrorEval.REF_INVALID;
    } catch (WorkbookNotFoundException wnfe) {
        return ErrorEval.REF_INVALID;
    }
}
Also used : Area3DPxg(org.apache.poi.ss.formula.ptg.Area3DPxg) NameXPtg(org.apache.poi.ss.formula.ptg.NameXPtg) Ptg(org.apache.poi.ss.formula.ptg.Ptg) Area3DPtg(org.apache.poi.ss.formula.ptg.Area3DPtg) Ref3DPtg(org.apache.poi.ss.formula.ptg.Ref3DPtg) Area3DPtg(org.apache.poi.ss.formula.ptg.Area3DPtg) Ref3DPxg(org.apache.poi.ss.formula.ptg.Ref3DPxg) WorkbookNotFoundException(org.apache.poi.ss.formula.CollaboratingWorkbooksEnvironment.WorkbookNotFoundException) Ref3DPtg(org.apache.poi.ss.formula.ptg.Ref3DPtg)

Example 2 with Ref3DPxg

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

the class TestFormulaParser method testParseExternalReferencesWithQuotedSheetName.

// bug 60219: FormulaParser can't parse external references when sheet name is quoted
@Test
public void testParseExternalReferencesWithQuotedSheetName() throws Exception {
    XSSFWorkbook wb = new XSSFWorkbook();
    XSSFEvaluationWorkbook fpwb = XSSFEvaluationWorkbook.create(wb);
    Ptg[] ptgs = FormulaParser.parse("'[1]Sheet 1'!A1", fpwb, FormulaType.CELL, -1);
    // org.apache.poi.ss.formula.ptg.Ref3DPxg [ [workbook=1] sheet=Sheet 1 ! A1]
    assertEquals("Ptgs length", 1, ptgs.length);
    assertTrue("Ptg class", ptgs[0] instanceof Ref3DPxg);
    Ref3DPxg pxg = (Ref3DPxg) ptgs[0];
    assertEquals("External workbook number", 1, pxg.getExternalWorkbookNumber());
    assertEquals("Sheet name", "Sheet 1", pxg.getSheetName());
    assertEquals("Row", 0, pxg.getRow());
    assertEquals("Column", 0, pxg.getColumn());
    wb.close();
}
Also used : XSSFEvaluationWorkbook(org.apache.poi.xssf.usermodel.XSSFEvaluationWorkbook) Ptg(org.apache.poi.ss.formula.ptg.Ptg) StringPtg(org.apache.poi.ss.formula.ptg.StringPtg) AbstractFunctionPtg(org.apache.poi.ss.formula.ptg.AbstractFunctionPtg) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Ref3DPxg(org.apache.poi.ss.formula.ptg.Ref3DPxg) Test(org.junit.Test)

Example 3 with Ref3DPxg

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

the class TestFormulaParser method testParseExternalReferencesWithUnquotedSheetName.

// trivial case for bug 60219: FormulaParser can't parse external references when sheet name is quoted
@Test
public void testParseExternalReferencesWithUnquotedSheetName() throws Exception {
    XSSFWorkbook wb = new XSSFWorkbook();
    XSSFEvaluationWorkbook fpwb = XSSFEvaluationWorkbook.create(wb);
    Ptg[] ptgs = FormulaParser.parse("[1]Sheet1!A1", fpwb, FormulaType.CELL, -1);
    // org.apache.poi.ss.formula.ptg.Ref3DPxg [ [workbook=1] sheet=Sheet 1 ! A1]
    assertEquals("Ptgs length", 1, ptgs.length);
    assertTrue("Ptg class", ptgs[0] instanceof Ref3DPxg);
    Ref3DPxg pxg = (Ref3DPxg) ptgs[0];
    assertEquals("External workbook number", 1, pxg.getExternalWorkbookNumber());
    assertEquals("Sheet name", "Sheet1", pxg.getSheetName());
    assertEquals("Row", 0, pxg.getRow());
    assertEquals("Column", 0, pxg.getColumn());
    wb.close();
}
Also used : XSSFEvaluationWorkbook(org.apache.poi.xssf.usermodel.XSSFEvaluationWorkbook) Ptg(org.apache.poi.ss.formula.ptg.Ptg) StringPtg(org.apache.poi.ss.formula.ptg.StringPtg) AbstractFunctionPtg(org.apache.poi.ss.formula.ptg.AbstractFunctionPtg) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Ref3DPxg(org.apache.poi.ss.formula.ptg.Ref3DPxg) Test(org.junit.Test)

Aggregations

Ptg (org.apache.poi.ss.formula.ptg.Ptg)3 Ref3DPxg (org.apache.poi.ss.formula.ptg.Ref3DPxg)3 AbstractFunctionPtg (org.apache.poi.ss.formula.ptg.AbstractFunctionPtg)2 StringPtg (org.apache.poi.ss.formula.ptg.StringPtg)2 XSSFEvaluationWorkbook (org.apache.poi.xssf.usermodel.XSSFEvaluationWorkbook)2 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)2 Test (org.junit.Test)2 WorkbookNotFoundException (org.apache.poi.ss.formula.CollaboratingWorkbooksEnvironment.WorkbookNotFoundException)1 Area3DPtg (org.apache.poi.ss.formula.ptg.Area3DPtg)1 Area3DPxg (org.apache.poi.ss.formula.ptg.Area3DPxg)1 NameXPtg (org.apache.poi.ss.formula.ptg.NameXPtg)1 Ref3DPtg (org.apache.poi.ss.formula.ptg.Ref3DPtg)1