Beispiel #1
0
        public static CellRange ExpandToTableColumn(this CellRange range)
        {
            if (range == null)
            {
                throw new ArgumentNullException(nameof(range));
            }

            CellRange dataRange;
            var       sheet        = range.Worksheet;
            var       resultRanges = new List <CellRange>();

            var table = range.GetRangeTable();

            if (table != null)
            {
                dataRange = table.DataRange;
            }
            else
            {
                dataRange = range.Worksheet.GetDataRange();
            }

            var leftColumnIndex  = dataRange.LeftColumnIndex;
            var rightColumnIndex = dataRange.RightColumnIndex;

            foreach (var area in range.Areas)
            {
                var resultArea = sheet.Range.FromLTRB(leftColumnIndex, area.TopRowIndex, rightColumnIndex, area.BottomRowIndex);
                resultRanges.Add(resultArea);
            }

            var result = sheet.Range.Union(resultRanges.ToArray());

            return(result);
        }