public static string TranslateForSheetChange(string range, SheetChange sheetChange, string currentSheetName) { if (range == null) { return(null); } RangeComponents er = Parse(range); if (((er.SheetName != "") || (currentSheetName != sheetChange.SheetName)) && !(er.SheetName == sheetChange.SheetName)) { return(range); } return(TranslateInternal(er, sheetChange.RowStart, sheetChange.ColumnStart, sheetChange.RowDelta, sheetChange.ColumnDelta, false)); }
public static string TranslateForSheetChange(string formula, SheetChange sheetChange, string currentSheetName) { if (formula == null) { return(null); } ParseTree tree = Parse(formula); StringBuilder buf = new StringBuilder(); if (tree.Errors.Count > 0) { throw new ArgumentException("Error in parsing formula"); } BuildTranslated(buf, tree, n => TranslateRangeParseNodeForSheetChange(n, sheetChange, currentSheetName)); return(buf.ToString()); }
/// <summary> /// Translate a range due to a sheet change, e.g. insertion of rows. /// </summary> /// <param name="range">Range, e.g. A1, Sheet1!A1</param> /// <param name="sheetChange">Details of change</param> /// <param name="currentSheetName">The sheet where the range is, to determine if this range is affected. If sheetChange.SheetName is null and currentSheetName is null, translation is always applied.</param> /// <returns></returns> public static string TranslateForSheetChange(string range, SheetChange sheetChange, string currentSheetName) { if (range == null) { return(null); } RangeComponents er = ExcelRange.Parse(range); if ((er.SheetName == "" && currentSheetName == sheetChange.SheetName) || er.SheetName == sheetChange.SheetName) { return(TranslateInternal(er, sheetChange.RowStart, sheetChange.ColumnStart, sheetChange.RowDelta, sheetChange.ColumnDelta, false // Don't allow absolute refs i.e. $ to affect translate )); } else { return(range); } }
private static string TranslateRangeParseNodeForSheetChange(ParseNode rangeNode, SheetChange sheetChange, string currentSheetName) { string range = ""; foreach (ParseNode sub in rangeNode.Nodes) { range += sub.Token.Text; } return(ExcelRange.TranslateForSheetChange(range, sheetChange, currentSheetName)); }