https://bz.apache.org/bugzilla/show_bug.cgi?id=63302

Yegor Kozlov <[email protected]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEEDINFO                    |NEW

--- Comment #2 from Yegor Kozlov <[email protected]> ---
A good catch and it is reproducible in trunk.

WorkbookEvaluator#evaluateNameFormula was introduced in r910043 to support
evaluation of indirect names in INDIRECT, e.g.
=SUM(INDIRECT(A4))  where A4 is a string cell with a value referring to a named
range.

The logic supports plain cell references like Sheet1!A1:D1, but it was never
tested with names referring to functions like in the attached patch.

Another way to reproduce the problem is to modify TestIndirect#createWBA() to
create a name with a formula instead of a cell reference:

change 
        HSSFName name2 = wb.createName();
        name2.setNameName("sales2");
        name2.setRefersToFormula("Sheet2!B1:C3");

to
        HSSFName name2 = wb.createName();
        name2.setNameName("sales2");
        name2.setRefersToFormula("ROW()");


and the test will fail with 


java.lang.RuntimeException: Unexpected ptg class
(org.apache.poi.ss.formula.ptg.FuncVarPtg)

        at
org.apache.poi.ss.formula.WorkbookEvaluator.getEvalForPtg(WorkbookEvaluator.java:750)
        at
org.apache.poi.ss.formula.WorkbookEvaluator.evaluateNameFormula(WorkbookEvaluator.java:777)
        at
org.apache.poi.ss.formula.OperationEvaluationContext.getDynamicReference(OperationEvaluationContext.java:225)
        at
org.apache.poi.ss.formula.functions.Indirect.evaluateIndirect(Indirect.java:140)
        at
org.apache.poi.ss.formula.functions.Indirect.evaluate(Indirect.java:81)
        at
org.apache.poi.ss.formula.OperationEvaluatorFactory.evaluate(OperationEvaluatorFactory.java:155)


The proposed patch fixes the problem and I'm +1 to applying it.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to