// Fetch the workbook this refers to, and the name as defined with that private ValueEval GetExternalNameXEval(ExternalName externName, String workbookName) { try { WorkbookEvaluator refWorkbookEvaluator = _bookEvaluator.GetOtherWorkbookEvaluator(workbookName); IEvaluationName evaluationName = refWorkbookEvaluator.GetName(externName.Name, externName.Ix - 1); if (evaluationName != null && evaluationName.HasFormula) { if (evaluationName.NameDefinition.Length > 1) { throw new Exception("Complex name formulas not supported yet"); } // Need to Evaluate the reference in the context of the other book OperationEvaluationContext refWorkbookContext = new OperationEvaluationContext( refWorkbookEvaluator, refWorkbookEvaluator.Workbook, -1, -1, -1, _tracker); Ptg ptg = evaluationName.NameDefinition[0]; if (ptg is Ref3DPtg) { Ref3DPtg ref3D = (Ref3DPtg)ptg; return(refWorkbookContext.GetRef3DEval(ref3D)); } else if (ptg is Ref3DPxg) { Ref3DPxg ref3D = (Ref3DPxg)ptg; return(refWorkbookContext.GetRef3DEval(ref3D)); } else if (ptg is Area3DPtg) { Area3DPtg area3D = (Area3DPtg)ptg; return(refWorkbookContext.GetArea3DEval(area3D)); } else if (ptg is Area3DPxg) { Area3DPxg area3D = (Area3DPxg)ptg; return(refWorkbookContext.GetArea3DEval(area3D)); } } return(ErrorEval.REF_INVALID); } catch (WorkbookNotFoundException) { return(ErrorEval.REF_INVALID); } }
/** * returns an appropriate Eval impl instance for the Ptg. The Ptg must be * one of: Area3DPtg, AreaPtg, ReferencePtg, Ref3DPtg, IntPtg, NumberPtg, * StringPtg, BoolPtg <br/>special Note: OperationPtg subtypes cannot be * passed here! */ private ValueEval GetEvalForPtg(Ptg ptg, OperationEvaluationContext ec) { // consider converting all these (ptg is XxxPtg) expressions To (ptg.GetType() == XxxPtg.class) if (ptg is NamePtg) { // named ranges, macro functions NamePtg namePtg = (NamePtg)ptg; EvaluationName nameRecord = _workbook.GetName(namePtg); if (nameRecord.IsFunctionName) { return new NameEval(nameRecord.NameText); } if (nameRecord.HasFormula) { return EvaluateNameFormula(nameRecord.NameDefinition, ec); } throw new Exception("Don't now how To evalate name '" + nameRecord.NameText + "'"); } if (ptg is NameXPtg) { return new NameXEval(((NameXPtg)ptg)); } if (ptg is IntPtg) { return new NumberEval(((IntPtg)ptg).Value); } if (ptg is NumberPtg) { return new NumberEval(((NumberPtg)ptg).Value); } if (ptg is StringPtg) { return new StringEval(((StringPtg)ptg).Value); } if (ptg is BoolPtg) { return BoolEval.ValueOf(((BoolPtg)ptg).Value); } if (ptg is ErrPtg) { return ErrorEval.ValueOf(((ErrPtg)ptg).ErrorCode); } if (ptg is MissingArgPtg) { return MissingArgEval.instance; } if (ptg is AreaErrPtg || ptg is RefErrorPtg || ptg is DeletedArea3DPtg || ptg is DeletedRef3DPtg) { return ErrorEval.REF_INVALID; } if (ptg is Ref3DPtg) { Ref3DPtg rptg = (Ref3DPtg)ptg; return ec.GetRef3DEval(rptg.Row, rptg.Column, rptg.ExternSheetIndex); } if (ptg is Area3DPtg) { Area3DPtg aptg = (Area3DPtg)ptg; return ec.GetArea3DEval(aptg.FirstRow, aptg.FirstColumn, aptg.LastRow, aptg.LastColumn, aptg.ExternSheetIndex); } if (ptg is RefPtg) { RefPtg rptg = (RefPtg)ptg; return ec.GetRefEval(rptg.Row, rptg.Column); } if (ptg is AreaPtg) { AreaPtg aptg = (AreaPtg)ptg; return ec.GetAreaEval(aptg.FirstRow, aptg.FirstColumn, aptg.LastRow, aptg.LastColumn); } if (ptg is UnknownPtg) { // POI uses UnknownPtg when the encoded Ptg array seems To be corrupted. // This seems To occur in very rare cases (e.g. unused name formulas in bug 44774, attachment 21790) // In any case, formulas are re-parsed before execution, so UnknownPtg should not Get here throw new Exception("UnknownPtg not allowed"); } throw new Exception("Unexpected ptg class (" + ptg.GetType().Name + ")"); }
/** * returns an appropriate Eval impl instance for the Ptg. The Ptg must be * one of: Area3DPtg, AreaPtg, ReferencePtg, Ref3DPtg, IntPtg, NumberPtg, * StringPtg, BoolPtg <br/>special Note: OperationPtg subtypes cannot be * passed here! */ private ValueEval GetEvalForPtg(Ptg ptg, OperationEvaluationContext ec) { // consider converting all these (ptg is XxxPtg) expressions To (ptg.GetType() == XxxPtg.class) if (ptg is NamePtg) { // Named ranges, macro functions NamePtg namePtg = (NamePtg)ptg; IEvaluationName nameRecord = _workbook.GetName(namePtg); return GetEvalForNameRecord(nameRecord, ec); } if (ptg is NameXPtg) { // Externally defined named ranges or macro functions return ProcessNameEval(ec.GetNameXEval((NameXPtg)ptg), ec); } if (ptg is NameXPxg) { // Externally defined named ranges or macro functions return ProcessNameEval(ec.GetNameXEval((NameXPxg)ptg), ec); } if (ptg is IntPtg) { return new NumberEval(((IntPtg)ptg).Value); } if (ptg is NumberPtg) { return new NumberEval(((NumberPtg)ptg).Value); } if (ptg is StringPtg) { return new StringEval(((StringPtg)ptg).Value); } if (ptg is BoolPtg) { return BoolEval.ValueOf(((BoolPtg)ptg).Value); } if (ptg is ErrPtg) { return ErrorEval.ValueOf(((ErrPtg)ptg).ErrorCode); } if (ptg is MissingArgPtg) { return MissingArgEval.instance; } if (ptg is AreaErrPtg || ptg is RefErrorPtg || ptg is DeletedArea3DPtg || ptg is DeletedRef3DPtg) { return ErrorEval.REF_INVALID; } if (ptg is Ref3DPtg) { return ec.GetRef3DEval((Ref3DPtg)ptg); } if (ptg is Ref3DPxg) { return ec.GetRef3DEval((Ref3DPxg)ptg); } if (ptg is Area3DPtg) { return ec.GetArea3DEval((Area3DPtg)ptg); } if (ptg is Area3DPxg) { return ec.GetArea3DEval((Area3DPxg)ptg); } if (ptg is RefPtg) { RefPtg rptg = (RefPtg)ptg; return ec.GetRefEval(rptg.Row, rptg.Column); } if (ptg is AreaPtg) { AreaPtg aptg = (AreaPtg)ptg; return ec.GetAreaEval(aptg.FirstRow, aptg.FirstColumn, aptg.LastRow, aptg.LastColumn); } if (ptg is UnknownPtg) { // POI uses UnknownPtg when the encoded Ptg array seems To be corrupted. // This seems To occur in very rare cases (e.g. unused name formulas in bug 44774, attachment 21790) // In any case, formulas are re-parsed before execution, so UnknownPtg should not Get here throw new RuntimeException("UnknownPtg not allowed"); } if (ptg is ExpPtg) { // ExpPtg is used for array formulas and shared formulas. // it is currently unsupported, and may not even get implemented here throw new RuntimeException("ExpPtg currently not supported"); } throw new RuntimeException("Unexpected ptg class (" + ptg.GetType().Name + ")"); }
/** * returns an appropriate Eval impl instance for the Ptg. The Ptg must be * one of: Area3DPtg, AreaPtg, ReferencePtg, Ref3DPtg, IntPtg, NumberPtg, * StringPtg, BoolPtg <br/>special Note: OperationPtg subtypes cannot be * passed here! */ private ValueEval GetEvalForPtg(Ptg ptg, OperationEvaluationContext ec) { // consider converting all these (ptg is XxxPtg) expressions To (ptg.GetType() == XxxPtg.class) if (ptg is NamePtg) { // named ranges, macro functions NamePtg namePtg = (NamePtg)ptg; IEvaluationName nameRecord = _workbook.GetName(namePtg); if (nameRecord.IsFunctionName) { return(new NameEval(nameRecord.NameText)); } if (nameRecord.HasFormula) { return(EvaluateNameFormula(nameRecord.NameDefinition, ec)); } throw new Exception("Don't now how To evalate name '" + nameRecord.NameText + "'"); } if (ptg is NameXPtg) { return(ec.GetNameXEval(((NameXPtg)ptg))); } if (ptg is IntPtg) { return(new NumberEval(((IntPtg)ptg).Value)); } if (ptg is NumberPtg) { return(new NumberEval(((NumberPtg)ptg).Value)); } if (ptg is StringPtg) { return(new StringEval(((StringPtg)ptg).Value)); } if (ptg is BoolPtg) { return(BoolEval.ValueOf(((BoolPtg)ptg).Value)); } if (ptg is ErrPtg) { return(ErrorEval.ValueOf(((ErrPtg)ptg).ErrorCode)); } if (ptg is MissingArgPtg) { return(MissingArgEval.instance); } if (ptg is AreaErrPtg || ptg is RefErrorPtg || ptg is DeletedArea3DPtg || ptg is DeletedRef3DPtg) { return(ErrorEval.REF_INVALID); } if (ptg is Ref3DPtg) { Ref3DPtg rptg = (Ref3DPtg)ptg; return(ec.GetRef3DEval(rptg.Row, rptg.Column, rptg.ExternSheetIndex)); } if (ptg is Area3DPtg) { Area3DPtg aptg = (Area3DPtg)ptg; return(ec.GetArea3DEval(aptg.FirstRow, aptg.FirstColumn, aptg.LastRow, aptg.LastColumn, aptg.ExternSheetIndex)); } if (ptg is RefPtg) { RefPtg rptg = (RefPtg)ptg; return(ec.GetRefEval(rptg.Row, rptg.Column)); } if (ptg is AreaPtg) { AreaPtg aptg = (AreaPtg)ptg; return(ec.GetAreaEval(aptg.FirstRow, aptg.FirstColumn, aptg.LastRow, aptg.LastColumn)); } if (ptg is UnknownPtg) { // POI uses UnknownPtg when the encoded Ptg array seems To be corrupted. // This seems To occur in very rare cases (e.g. unused name formulas in bug 44774, attachment 21790) // In any case, formulas are re-parsed before execution, so UnknownPtg should not Get here throw new RuntimeException("UnknownPtg not allowed"); } if (ptg is ExpPtg) { // ExpPtg is used for array formulas and shared formulas. // it is currently unsupported, and may not even get implemented here throw new RuntimeException("ExpPtg currently not supported"); } throw new RuntimeException("Unexpected ptg class (" + ptg.GetType().Name + ")"); }
// Fetch the workbook this refers to, and the name as defined with that private ValueEval GetExternalNameXEval(ExternalName externName, String workbookName) { try { WorkbookEvaluator refWorkbookEvaluator = _bookEvaluator.GetOtherWorkbookEvaluator(workbookName); IEvaluationName evaluationName = refWorkbookEvaluator.GetName(externName.Name, externName.Ix - 1); if (evaluationName != null && evaluationName.HasFormula) { if (evaluationName.NameDefinition.Length > 1) { throw new Exception("Complex name formulas not supported yet"); } // Need to Evaluate the reference in the context of the other book OperationEvaluationContext refWorkbookContext = new OperationEvaluationContext( refWorkbookEvaluator, refWorkbookEvaluator.Workbook, -1, -1, -1, _tracker); Ptg ptg = evaluationName.NameDefinition[0]; if (ptg is Ref3DPtg) { Ref3DPtg ref3D = (Ref3DPtg)ptg; return refWorkbookContext.GetRef3DEval(ref3D); } else if (ptg is Ref3DPxg) { Ref3DPxg ref3D = (Ref3DPxg)ptg; return refWorkbookContext.GetRef3DEval(ref3D); } else if (ptg is Area3DPtg) { Area3DPtg area3D = (Area3DPtg)ptg; return refWorkbookContext.GetArea3DEval(area3D); } else if (ptg is Area3DPxg) { Area3DPxg area3D = (Area3DPxg)ptg; return refWorkbookContext.GetArea3DEval(area3D); } } return ErrorEval.REF_INVALID; } catch (WorkbookNotFoundException) { return ErrorEval.REF_INVALID; } }