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
This commit is contained in:
parent
f06915e95d
commit
fec4eb7a12
@ -377,25 +377,31 @@ public final class OperationEvaluationContext {
|
|||||||
|
|
||||||
private ValueEval getExternalNameXEval(ExternalName externName, String workbookName) {
|
private ValueEval getExternalNameXEval(ExternalName externName, String workbookName) {
|
||||||
try {
|
try {
|
||||||
|
// Fetch the workbook this refers to, and the name as defined with that
|
||||||
WorkbookEvaluator refWorkbookEvaluator = _bookEvaluator.getOtherWorkbookEvaluator(workbookName);
|
WorkbookEvaluator refWorkbookEvaluator = _bookEvaluator.getOtherWorkbookEvaluator(workbookName);
|
||||||
EvaluationName evaluationName = refWorkbookEvaluator.getName(externName.getName(),externName.getIx()-1);
|
EvaluationName evaluationName = refWorkbookEvaluator.getName(externName.getName(),externName.getIx()-1);
|
||||||
if (evaluationName != null && evaluationName.hasFormula()){
|
if (evaluationName != null && evaluationName.hasFormula()){
|
||||||
if (evaluationName.getNameDefinition().length > 1) {
|
if (evaluationName.getNameDefinition().length > 1) {
|
||||||
throw new RuntimeException("Complex name formulas not supported yet");
|
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];
|
Ptg ptg = evaluationName.getNameDefinition()[0];
|
||||||
if (ptg instanceof Ref3DPtg){
|
if (ptg instanceof Ref3DPtg){
|
||||||
Ref3DPtg ref3D = (Ref3DPtg)ptg;
|
Ref3DPtg ref3D = (Ref3DPtg)ptg;
|
||||||
int sheetIndex = refWorkbookEvaluator.getSheetIndexByExternIndex(ref3D.getExternSheetIndex());
|
return refWorkbookContext.getRef3DEval(ref3D);
|
||||||
String sheetName = refWorkbookEvaluator.getSheetName(sheetIndex);
|
} else if (ptg instanceof Ref3DPxg){
|
||||||
SheetRefEvaluator sre = createExternSheetRefEvaluator(workbookName, sheetName);
|
Ref3DPxg ref3D = (Ref3DPxg)ptg;
|
||||||
return new LazyRefEval(ref3D.getRow(), ref3D.getColumn(), sre);
|
return refWorkbookContext.getRef3DEval(ref3D);
|
||||||
} else if(ptg instanceof Area3DPtg){
|
} else if(ptg instanceof Area3DPtg){
|
||||||
Area3DPtg area3D = (Area3DPtg)ptg;
|
Area3DPtg area3D = (Area3DPtg)ptg;
|
||||||
int sheetIndex = refWorkbookEvaluator.getSheetIndexByExternIndex(area3D.getExternSheetIndex());
|
return refWorkbookContext.getArea3DEval(area3D);
|
||||||
String sheetName = refWorkbookEvaluator.getSheetName(sheetIndex);
|
} else if(ptg instanceof Area3DPxg){
|
||||||
SheetRefEvaluator sre = createExternSheetRefEvaluator(workbookName, sheetName);
|
Area3DPxg area3D = (Area3DPxg)ptg;
|
||||||
return new LazyAreaEval(area3D.getFirstRow(), area3D.getFirstColumn(), area3D.getLastRow(), area3D.getLastColumn(), sre);
|
return refWorkbookContext.getArea3DEval(area3D);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ErrorEval.REF_INVALID;
|
return ErrorEval.REF_INVALID;
|
||||||
|
@ -156,9 +156,8 @@ public final class TestXSSFFormulaEvaluation extends BaseTestFormulaEvaluator {
|
|||||||
|
|
||||||
// Evaluate and check results
|
// Evaluate and check results
|
||||||
assertEquals("\"Hello!\"", evaluator.evaluate(cXSLX_cell).formatAsString());
|
assertEquals("\"Hello!\"", evaluator.evaluate(cXSLX_cell).formatAsString());
|
||||||
// TODO Fix XSSF reference evaluations to work
|
assertEquals("\"Test A1\"", evaluator.evaluate(cXSLX_sNR).formatAsString());
|
||||||
// assertEquals("\"Test A1\"", evaluator.evaluate(cXSLX_sNR).formatAsString());
|
assertEquals("142.0", evaluator.evaluate(cXSLX_gNR).formatAsString());
|
||||||
// assertEquals("142.0", evaluator.evaluate(cXSLX_gNR).formatAsString());
|
|
||||||
|
|
||||||
assertEquals("\"Hello!\"", evaluator.evaluate(cXSL_cell).formatAsString());
|
assertEquals("\"Hello!\"", evaluator.evaluate(cXSL_cell).formatAsString());
|
||||||
assertEquals("\"Test A1\"", evaluator.evaluate(cXSL_sNR).formatAsString());
|
assertEquals("\"Test A1\"", evaluator.evaluate(cXSL_sNR).formatAsString());
|
||||||
|
Loading…
Reference in New Issue
Block a user