using System.Collections.Generic; using System.Linq; namespace FastExcel { /// /// Extensions to use on Dictionary of DefinedNames /// internal static class DefinedNamesExtensions { /// /// Finds all the cell names for a given cell /// /// /// Name of sheet containing cell /// Column letter of cell /// Row number of cell /// /// List of cell names that is assigned to this cell. Does not include names which this cell is within range. /// Empty List if none found /// internal static List FindCellNames(this IReadOnlyDictionary definedNames, string sheetName, string columnLetter, int rowNumber) { return (from e in definedNames where e.Value.Reference.Contains(sheetName + "!$" + columnLetter.ToUpper() + "$" + rowNumber.ToString()) select e.Value.Name).ToList(); } /// /// Finds the column name for a given column letter /// /// /// Name of sheet containing column /// Column letter /// internal static string FindColumnName(this IReadOnlyDictionary definedNames, string sheetName, string columnLetter) { columnLetter = columnLetter.ToUpper(); return (from e in definedNames where e.Value.Reference == sheetName + "!$" + columnLetter + ":$" + columnLetter select e.Value.Name).FirstOrDefault(); } } }