Exemple #1
0
        public string RangeReallocateCases(string address, ReallocateDirection direction, int count)
        {
            var range = Range.FromString(address);

            range.Reallocate(direction, count);
            return($"{range.UpperLeft.Column.ReferencePosition}{range.UpperLeft.Row.ReferencePosition}:{range.BottomRight.Column.ReferencePosition}{range.BottomRight.Row.ReferencePosition}");
        }
Exemple #2
0
        public void Reallocate(ReallocateDirection direction, int count)
        {
            var growthPoint = direction switch
            {
                ReallocateDirection.Up => UpperLeft.Row.NumericPosition,
                ReallocateDirection.Left => UpperLeft.Column.NumericPosition,
                ReallocateDirection.Down => BottomRight.Row.NumericPosition,
                ReallocateDirection.Right => BottomRight.Column.NumericPosition,
                _ => throw new ArgumentOutOfRangeException(nameof(direction), direction, "Unknown direction.")
            };

            var adjustedCount = direction == ReallocateDirection.Up || direction == ReallocateDirection.Left
                ? -count
                : count;

            if (growthPoint + adjustedCount < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(count), count, "Reallocated range goes outside of sheet (coordinate value < 1).");
            }

            switch (direction)
            {
            case ReallocateDirection.Up:
                UpperLeft = new Address(UpperLeft.Column.ReferencePosition + UpperLeft.Row.Move(adjustedCount).ReferencePosition);
                break;

            case ReallocateDirection.Left:
                UpperLeft = new Address(UpperLeft.Column.Move(adjustedCount).ReferencePosition + UpperLeft.Row.ReferencePosition);
                break;

            case ReallocateDirection.Down:
                BottomRight = new Address(BottomRight.Column.ReferencePosition + BottomRight.Row.Move(adjustedCount).ReferencePosition);
                break;

            case ReallocateDirection.Right:
                BottomRight = new Address(BottomRight.Column.Move(adjustedCount).ReferencePosition + BottomRight.Row.ReferencePosition);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(direction), direction, "Unknown direction.");
            }

            Normalize();
        }