// Recursive function that will replace values from last to first private void ReplaceNode(Peg.Base.PegNode node, int id, string oldName, string newName, StringBuilder text) { if (node.next_ != null) { ReplaceNode(node.next_, id, oldName, newName, text); } if (node.id_ == id && parser.GetSource().Substring(node.match_.posBeg_, node.match_.Length) == oldName) { text.Remove(node.match_.posBeg_, node.match_.Length); text.Insert(node.match_.posBeg_, newName); } else if (node.child_ != null) { ReplaceNode(node.child_, id, oldName, newName, text); } }
// Recursive function that will adjust relative cells from last to first private void ReplaceRelativeCell(Peg.Base.PegNode node, int rowOffset, int colOffset, StringBuilder text) { if (node.next_ != null) { ReplaceRelativeCell(node.next_, rowOffset, colOffset, text); } if (node.id_ == (int)EExcelFormula.A1Row && parser.GetSource().Substring(node.match_.posBeg_, 1) != "$") { int rowNumber = Convert.ToInt32(parser.GetSource().Substring(node.match_.posBeg_, node.match_.Length)); text.Remove(node.match_.posBeg_, node.match_.Length); text.Insert(node.match_.posBeg_, Convert.ToString(rowNumber + rowOffset)); } else if (node.id_ == (int)EExcelFormula.A1Column && parser.GetSource().Substring(node.match_.posBeg_, 1) != "$") { int colNumber = GetColumnNumber(parser.GetSource().Substring(node.match_.posBeg_, node.match_.Length)); text.Remove(node.match_.posBeg_, node.match_.Length); text.Insert(node.match_.posBeg_, GetColumnId(colNumber + colOffset)); } else if (node.child_ != null) { ReplaceRelativeCell(node.child_, rowOffset, colOffset, text); } }