private static Ptg CreateDeletedRef(Ptg ptg) { if (ptg is RefPtg) { return(new RefErrorPtg()); } if (ptg is Ref3DPtg) { Ref3DPtg rptg = (Ref3DPtg)ptg; return(new DeletedRef3DPtg(rptg.ExternSheetIndex)); } if (ptg is AreaPtg) { return(new AreaErrPtg()); } if (ptg is Area3DPtg) { Area3DPtg area3DPtg = (Area3DPtg)ptg; return(new DeletedArea3DPtg(area3DPtg.ExternSheetIndex)); } if (ptg is Ref3DPxg) { Ref3DPxg pxg = (Ref3DPxg)ptg; return(new Deleted3DPxg(pxg.ExternalWorkbookNumber, pxg.SheetName)); } if (ptg is Area3DPxg) { Area3DPxg pxg = (Area3DPxg)ptg; return(new Deleted3DPxg(pxg.ExternalWorkbookNumber, pxg.SheetName)); } throw new ArgumentException("Unexpected ref ptg class (" + ptg.GetType().Name + ")"); }
/** * Call this on any ptg reference contained in a row of cells that was copied. * If the ptg reference is relative, the references will be shifted by the distance * that the rows were copied. * In the future similar functions could be written due to column copying or * individual cell copying. Just make sure to only call adjustPtgDueToRowCopy on * formula cells that are copied (unless row shifting, where references outside * of the shifted region need to be updated to reflect the shift, a copy is self-contained). * * @param ptg the ptg to shift * @return deleted ref ptg, in-place modified ptg, or null * If Ptg would be shifted off the first or last row of a sheet, return deleted ref * If Ptg needs to be changed, modifies Ptg in-place * If Ptg doesn't need to be changed, returns <code>null</code> */ private Ptg AdjustPtgDueToRowCopy(Ptg ptg) { if (ptg is RefPtg) { RefPtg rptg = (RefPtg)ptg; return(RowCopyRefPtg(rptg)); } if (ptg is Ref3DPtg) { Ref3DPtg rptg = (Ref3DPtg)ptg; return(RowCopyRefPtg(rptg)); } if (ptg is Ref3DPxg) { Ref3DPxg rpxg = (Ref3DPxg)ptg; return(RowCopyRefPtg(rpxg)); } if (ptg is Area2DPtgBase) { return(RowCopyAreaPtg((Area2DPtgBase)ptg)); } if (ptg is Area3DPtg) { Area3DPtg aptg = (Area3DPtg)ptg; return(RowCopyAreaPtg(aptg)); } if (ptg is Area3DPxg) { Area3DPxg apxg = (Area3DPxg)ptg; return(RowCopyAreaPtg(apxg)); } return(null); }
// 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); } }
public ValueEval GetRef3DEval(Ref3DPxg rptg) { SheetRangeEvaluator sre = CreateExternSheetRefEvaluator(rptg.SheetName, rptg.LastSheetName, rptg.ExternalWorkbookNumber); return(new LazyRefEval(rptg.Row, rptg.Column, sre)); }
/** * @return <c>true</c> if this Ptg needed to be changed */ private Ptg AdjustPtgDueToRowMove(Ptg ptg, int currentExternSheetIx) { if (ptg is RefPtg) { if (currentExternSheetIx != _externSheetIndex) { // local refs on other sheets are unaffected return(null); } RefPtg rptg = (RefPtg)ptg; return(RowMoveRefPtg(rptg)); } if (ptg is Ref3DPtg) { Ref3DPtg rptg = (Ref3DPtg)ptg; if (_externSheetIndex != rptg.ExternSheetIndex) { // only move 3D refs that refer to the sheet with cells being moved // (currentExternSheetIx is irrelevant) return(null); } return(RowMoveRefPtg(rptg)); } if (ptg is Ref3DPxg) { Ref3DPxg rpxg = (Ref3DPxg)ptg; if (rpxg.ExternalWorkbookNumber > 0 || !_sheetName.Equals(rpxg.SheetName)) { // only move 3D refs that refer to the sheet with cells being moved return(null); } return(RowMoveRefPtg(rpxg)); } if (ptg is Area2DPtgBase) { if (currentExternSheetIx != _externSheetIndex) { // local refs on other sheets are unaffected return(ptg); } return(RowMoveAreaPtg((Area2DPtgBase)ptg)); } if (ptg is Area3DPtg) { Area3DPtg aptg = (Area3DPtg)ptg; if (_externSheetIndex != aptg.ExternSheetIndex) { // only move 3D refs that refer to the sheet with cells being moved // (currentExternSheetIx is irrelevant) return(null); } return(RowMoveAreaPtg(aptg)); } if (ptg is Area3DPxg) { Area3DPxg apxg = (Area3DPxg)ptg; if (apxg.ExternalWorkbookNumber > 0 || !_sheetName.Equals(apxg.SheetName)) { // only move 3D refs that refer to the sheet with cells being moved return(null); } return(RowMoveAreaPtg(apxg)); } return(null); }