/// <summary> /// Calculate reference of new cell with its relative address /// </summary> /// <param name="relativeRef">Address in A1 expression</param> /// <returns></returns> protected CellReference TranslateCellReference(String relativeRef) { var matchAchor = _RegexAnchor.Match(relativeRef); if (matchAchor.Success) { // This cell reference is anchored to another cell try { var anchor = matchAchor.Groups["Anchor"].Value; var offx = int.Parse(matchAchor.Groups["OffsetX"].Value); var offy = int.Parse(matchAchor.Groups["OffsetY"].Value); var anchorCell = TranslateCellReference(anchor); anchorCell.Move(offx, offy); return(anchorCell); } catch (Exception err) { throw new InvalidDataException(String.Format("Cannot get reference of Anchored cell {0}! Err:{1}", relativeRef, err.Message)); } } String address = null; if (!_RegexCell.IsMatch(relativeRef)) { // The cell reference might be defined name address = _doc.GetDefinedName(relativeRef); if (address == null) { throw new InvalidDataException(String.Format("Defined name '{0}' is not exist!", relativeRef)); } } else { address = relativeRef; } return(CalculateCellReference(address)); }