Beispiel #1
0
        public RangeCellReference(SingleCellReference startingCell, SingleCellReference endingCell)
        {
            if (startingCell == null)
            {
                throw new ArgumentNullException("startingCell");
            }

            if (endingCell == null)
            {
                throw new ArgumentNullException("endingCell");
            }

            this.StartingCellReference = startingCell;
            this.EndingCellReference = endingCell;
            this.Value = startingCell.Value + ":" + endingCell.Value;
        }
Beispiel #2
0
        /// <inheritdoc/>
        /// <remarks>
        /// Scaling a single cell reference will always result in a ranged cell reference. For example,
        /// if you scale the single reference A1 by (2, 0) the result will be A1:A3. This works in both
        /// directions.
        /// </remarks>
        public override ICellReference Resize(int row, int col)
        {
            var rowIdx = Math.Max(1, this.RowIndex + row);
            var colIdx = Math.Max(1, this.ColumnIndex + col);

            // If no changes were made, i.e. we're at origin scaling negative or (0, 0) was passed
            if (rowIdx == this.RowIndex && colIdx == this.ColumnIndex)
            {
                return new SingleCellReference(this.RowIndex, this.ColumnIndex);
            }
            else
            {
                var start = new SingleCellReference(
                    Math.Min(this.RowIndex, rowIdx),
                    Math.Min(this.ColumnIndex, colIdx));

                var end = new SingleCellReference(
                    Math.Max(this.RowIndex, rowIdx),
                    Math.Max(this.ColumnIndex, colIdx));

                return new RangeCellReference(start, end);
            }
        }
Beispiel #3
0
 /// <summary>
 /// Detects if the target single cell reference lies within this range.
 /// </summary>
 /// <param name="cellRef">The cell reference to check.</param>
 /// <returns>True if this range cell reference contains the target single cell reference.</returns>
 private bool Contains(SingleCellReference cellRef)
 {
     // Always dealing with positive numbers.
     return cellRef.ColumnIndex <= this.EndingCellReference.ColumnIndex &&
         cellRef.RowIndex <= this.EndingCellReference.RowIndex;
 }