private void StoreFormula( IEnumerable <TableCell> cells, string expression, FormulaFormat format, int dplaces, TableSelectionRange rangeType, string tagIndex) { if (rangeType == TableSelectionRange.Single) { var cell = cells.First(); cell.SetMeta("omfx", new Formula(format, dplaces, expression).ToString()); if (!string.IsNullOrEmpty(tagIndex)) { cell.SetTag(tagIndex); } return; } var regex = new Regex(@"([a-zA-Z]{1,3})(\d{1,3})"); int offset = 0; foreach (var cell in cells) { var builder = new StringBuilder(expression); if (offset > 0) { var matches = regex.Matches(expression); foreach (Match match in matches) { string col; string row; if (rangeType == TableSelectionRange.Columns) { col = TableCell.IndexToLetters( TableCell.LettersToIndex(match.Groups[1].Value) + offset); row = match.Groups[2].Value; } else { col = match.Groups[1].Value; row = (int.Parse(match.Groups[2].Value) + offset).ToString(); } builder.Replace(match.Value, $"{col}{row}", match.Index, match.Length); } } cell.SetMeta("omfx", new Formula(format, dplaces, builder.ToString()).ToString()); if (!string.IsNullOrEmpty(tagIndex)) { cell.SetTag(tagIndex); } offset++; } }
public IEnumerable <TableCell> GetSelectedCells(out TableSelectionRange range) { var selections = from r in rows let cells = r.Cells from c in cells where c.Selected == Selection.all || c.Selected == Selection.partial select c; range = InferRangeType(selections); return(selections); }