diff options
author | Nick Burch <nick@apache.org> | 2014-07-24 14:56:23 +0000 |
---|---|---|
committer | Nick Burch <nick@apache.org> | 2014-07-24 14:56:23 +0000 |
commit | ca59e3137165d104b8b49a284da02f25e95d800d (patch) | |
tree | efecdbc14bf4bed11811da470e1237938b5fecfb /src/java/org/apache/poi | |
parent | 626d46ae95ba4332a40ca2c032a32b25ca73ce9d (diff) | |
download | poi-ca59e3137165d104b8b49a284da02f25e95d800d.tar.gz poi-ca59e3137165d104b8b49a284da02f25e95d800d.zip |
When evaluating a name in another workbook, need to use an OperationEvaluationContext tied to that Workbook, and do so such that XSSF references work too
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1613154 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/poi')
-rw-r--r-- | src/java/org/apache/poi/ss/formula/OperationEvaluationContext.java | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/src/java/org/apache/poi/ss/formula/OperationEvaluationContext.java b/src/java/org/apache/poi/ss/formula/OperationEvaluationContext.java index ab87208227..96eb89c9b3 100644 --- a/src/java/org/apache/poi/ss/formula/OperationEvaluationContext.java +++ b/src/java/org/apache/poi/ss/formula/OperationEvaluationContext.java @@ -377,25 +377,31 @@ public final class OperationEvaluationContext { 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; - int sheetIndex = refWorkbookEvaluator.getSheetIndexByExternIndex(ref3D.getExternSheetIndex()); - String sheetName = refWorkbookEvaluator.getSheetName(sheetIndex); - SheetRefEvaluator sre = createExternSheetRefEvaluator(workbookName, sheetName); - return new LazyRefEval(ref3D.getRow(), ref3D.getColumn(), sre); + 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; - int sheetIndex = refWorkbookEvaluator.getSheetIndexByExternIndex(area3D.getExternSheetIndex()); - String sheetName = refWorkbookEvaluator.getSheetName(sheetIndex); - SheetRefEvaluator sre = createExternSheetRefEvaluator(workbookName, sheetName); - return new LazyAreaEval(area3D.getFirstRow(), area3D.getFirstColumn(), area3D.getLastRow(), area3D.getLastColumn(), sre); + return refWorkbookContext.getArea3DEval(area3D); + } else if(ptg instanceof Area3DPxg){ + Area3DPxg area3D = (Area3DPxg)ptg; + return refWorkbookContext.getArea3DEval(area3D); } } return ErrorEval.REF_INVALID; |