SheetRefEvaluator CreateExternSheetRefEvaluator(int externSheetIndex) { ExternalSheet externalSheet = _workbook.GetExternalSheet(externSheetIndex); WorkbookEvaluator targetEvaluator; int otherSheetIndex; if (externalSheet == null) { // sheet is in same workbook otherSheetIndex = _workbook.ConvertFromExternSheetIndex(externSheetIndex); targetEvaluator = _bookEvaluator; } else { // look up sheet by name from external workbook String workbookName = externalSheet.GetWorkbookName(); try { targetEvaluator = _bookEvaluator.GetOtherWorkbookEvaluator(workbookName); } catch (WorkbookNotFoundException e) { throw new RuntimeException(e.Message, e); } otherSheetIndex = targetEvaluator.GetSheetIndex(externalSheet.GetSheetName()); if (otherSheetIndex < 0) { throw new Exception("Invalid sheet name '" + externalSheet.GetSheetName() + "' in bool '" + workbookName + "'."); } } return(new SheetRefEvaluator(targetEvaluator, _tracker, otherSheetIndex)); }
SheetRangeEvaluator CreateExternSheetRefEvaluator(ExternalSheet externalSheet) { WorkbookEvaluator targetEvaluator; int otherFirstSheetIndex; int otherLastSheetIndex = -1; if (externalSheet == null || externalSheet.WorkbookName == null) { // sheet is in same workbook targetEvaluator = _bookEvaluator; otherFirstSheetIndex = _workbook.GetSheetIndex(externalSheet.SheetName); if (externalSheet is ExternalSheetRange) { String lastSheetName = ((ExternalSheetRange)externalSheet).LastSheetName; otherLastSheetIndex = _workbook.GetSheetIndex(lastSheetName); } } else { // look up sheet by name from external workbook String workbookName = externalSheet.WorkbookName; try { targetEvaluator = _bookEvaluator.GetOtherWorkbookEvaluator(workbookName); } catch (WorkbookNotFoundException e) { throw new Exception(e.Message, e); } otherFirstSheetIndex = targetEvaluator.GetSheetIndex(externalSheet.SheetName); if (externalSheet is ExternalSheetRange) { String lastSheetName = ((ExternalSheetRange)externalSheet).LastSheetName; otherLastSheetIndex = targetEvaluator.GetSheetIndex(lastSheetName); } if (otherFirstSheetIndex < 0) { throw new Exception("Invalid sheet name '" + externalSheet.SheetName + "' in bool '" + workbookName + "'."); } } if (otherLastSheetIndex == -1) { // Reference to just one sheet otherLastSheetIndex = otherFirstSheetIndex; } SheetRefEvaluator[] Evals = new SheetRefEvaluator[otherLastSheetIndex - otherFirstSheetIndex + 1]; for (int i = 0; i < Evals.Length; i++) { int otherSheetIndex = i + otherFirstSheetIndex; Evals[i] = new SheetRefEvaluator(targetEvaluator, _tracker, otherSheetIndex); } return(new SheetRangeEvaluator(otherFirstSheetIndex, otherLastSheetIndex, Evals)); }
SheetRangeEvaluator CreateExternSheetRefEvaluator(ExternalSheet externalSheet) { WorkbookEvaluator targetEvaluator; int otherFirstSheetIndex; int otherLastSheetIndex = -1; if (externalSheet == null || externalSheet.WorkbookName == null) { // sheet is in same workbook targetEvaluator = _bookEvaluator; otherFirstSheetIndex = _workbook.GetSheetIndex(externalSheet.SheetName); if (externalSheet is ExternalSheetRange) { String lastSheetName = ((ExternalSheetRange)externalSheet).LastSheetName; otherLastSheetIndex = _workbook.GetSheetIndex(lastSheetName); } } else { // look up sheet by name from external workbook String workbookName = externalSheet.WorkbookName; try { targetEvaluator = _bookEvaluator.GetOtherWorkbookEvaluator(workbookName); } catch (WorkbookNotFoundException e) { throw new RuntimeException(e.Message, e); } otherFirstSheetIndex = targetEvaluator.GetSheetIndex(externalSheet.SheetName); if (externalSheet is ExternalSheetRange) { String lastSheetName = ((ExternalSheetRange)externalSheet).LastSheetName; otherLastSheetIndex = targetEvaluator.GetSheetIndex(lastSheetName); } if (otherFirstSheetIndex < 0) { throw new Exception("Invalid sheet name '" + externalSheet.SheetName + "' in bool '" + workbookName + "'."); } } if (otherLastSheetIndex == -1) { // Reference to just one sheet otherLastSheetIndex = otherFirstSheetIndex; } SheetRefEvaluator[] Evals = new SheetRefEvaluator[otherLastSheetIndex - otherFirstSheetIndex + 1]; for (int i = 0; i < Evals.Length; i++) { int otherSheetIndex = i + otherFirstSheetIndex; Evals[i] = new SheetRefEvaluator(targetEvaluator, _tracker, otherSheetIndex); } return new SheetRangeEvaluator(otherFirstSheetIndex, otherLastSheetIndex, Evals); }
public ValueEval GetNameXEval(NameXPtg nameXPtg) { ExternalSheet externSheet = _workbook.GetExternalSheet(nameXPtg.SheetRefIndex); if (externSheet == null) { return(new NameXEval(nameXPtg)); } String workbookName = externSheet.GetWorkbookName(); ExternalName externName = _workbook.GetExternalName( nameXPtg.SheetRefIndex, nameXPtg.NameIndex ); 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"); } Ptg ptg = evaluationName.NameDefinition[0]; if (ptg is Ref3DPtg) { Ref3DPtg ref3D = (Ref3DPtg)ptg; int sheetIndex = refWorkbookEvaluator.GetSheetIndexByExternIndex(ref3D.ExternSheetIndex); String sheetName = refWorkbookEvaluator.GetSheetName(sheetIndex); SheetRefEvaluator sre = CreateExternSheetRefEvaluator(workbookName, sheetName); return(new LazyRefEval(ref3D.Row, ref3D.Column, sre)); } else if (ptg is Area3DPtg) { Area3DPtg area3D = (Area3DPtg)ptg; int sheetIndex = refWorkbookEvaluator.GetSheetIndexByExternIndex(area3D.ExternSheetIndex); String sheetName = refWorkbookEvaluator.GetSheetName(sheetIndex); SheetRefEvaluator sre = CreateExternSheetRefEvaluator(workbookName, sheetName); return(new LazyAreaEval(area3D.FirstRow, area3D.FirstColumn, area3D.LastRow, area3D.LastColumn, sre)); } } return(ErrorEval.REF_INVALID); } catch (WorkbookNotFoundException) { return(ErrorEval.REF_INVALID); } }
public ValueEval GetNameXEval(NameXPtg nameXPtg) { ExternalSheet externSheet = _workbook.GetExternalSheet(nameXPtg.SheetRefIndex); if (externSheet == null || externSheet.WorkbookName == null) { // External reference to our own workbook's name return(GetLocalNameXEval(nameXPtg)); } // Look it up for the external workbook String workbookName = externSheet.WorkbookName; ExternalName externName = _workbook.GetExternalName( nameXPtg.SheetRefIndex, nameXPtg.NameIndex ); return(GetExternalNameXEval(externName, workbookName)); }
public ExternalSheet GetExternalSheet(int externSheetIndex) { ExternalSheet sheet = _iBook.GetExternalSheet(externSheetIndex); if (sheet == null) { // Try to treat it as a local sheet int localSheetIndex = ConvertFromExternSheetIndex(externSheetIndex); if (localSheetIndex == -1) { // The sheet referenced can't be found, sorry return null; } if (localSheetIndex == -2) { // Not actually sheet based at all - is workbook scoped return null; } // Look up the local sheet String sheetName = GetSheetName(localSheetIndex); // Is it a single local sheet, or a range? int lastLocalSheetIndex = _iBook.GetLastSheetIndexFromExternSheetIndex(externSheetIndex); if (lastLocalSheetIndex == localSheetIndex) { sheet = new ExternalSheet(null, sheetName); } else { String lastSheetName = GetSheetName(lastLocalSheetIndex); sheet = new ExternalSheetRange(null, sheetName, lastSheetName); } } return sheet; }
SheetRangeEvaluator CreateExternSheetRefEvaluator(int externSheetIndex) { ExternalSheet externalSheet = _workbook.GetExternalSheet(externSheetIndex); return(CreateExternSheetRefEvaluator(externalSheet)); }
SheetRangeEvaluator CreateExternSheetRefEvaluator(String firstSheetName, String lastSheetName, int externalWorkbookNumber) { ExternalSheet externalSheet = _workbook.GetExternalSheet(firstSheetName, lastSheetName, externalWorkbookNumber); return(CreateExternSheetRefEvaluator(externalSheet)); }