コード例 #1
0
        public static (int Column, int Row)? TranslateCell(this System.Data.DataTable table, string cell)
        {
            ArgumentGuards.GuardAgainstNullCell(cell);

            var tuple = CellIndex.Translate(cell, Offset.ZeroBased);

            if (!table.Contains(tuple))
            {
                return(null);
            }

            return(tuple);
        }
コード例 #2
0
        public static ((int Column, int Row), (int Column, int Row))? TranslateRange(this System.Data.DataTable table, string range)
        {
            ArgumentGuards.GuardAgainstNullRange(range);

            range = TranslateUnknown(table, range);

            var tuple = CellRange.Translate(range, Offset.ZeroBased);

            if (!table.Contains(tuple))
            {
                return(null);
            }

            return(tuple);
        }
コード例 #3
0
        public static string Shift(this System.Data.DataTable table, string range, string toColumn)
        {
            ArgumentGuards.GuardAgainstNullTable(table);
            ArgumentGuards.GuardAgainstNullRange(range);

            if (string.IsNullOrEmpty(toColumn))
            {
                throw new ArgumentNullException(nameof(toColumn));
            }

            var tuple = table.TranslateRange(range);

            if (!tuple.HasValue)
            {
                throw new ArgumentOutOfRangeException(nameof(range), $"The data table does not contain the range {range}.");
            }

            if (!CellRange.IsSameColumn(tuple.Value))
            {
                throw new ArgumentException("A shift cannot be performed across multiple columns.", nameof(range));
            }

            return($"{toColumn}{tuple.Value.Item1.Row + 1}:{toColumn}{tuple.Value.Item2.Row + 1}");
        }