示例#1
0
        /// <summary>
        ///     Notifies the engine that a range has moved
        /// </summary>
        /// <param name="range">The range that has moved</param>
        /// <param name="rowOffset">The number of rows range has moved.  Can be negative.</param>
        /// <param name="colOffset">The number of columns the range has moved.  Can be negative.</param>
        /// <remarks>
        ///     Use this method to notify the engine that a range on a sheet has moved.  The engine will update all references
        ///     in, or that depend on, the moved range accordingly.
        /// </remarks>
        /// <exception cref="System.ArgumentOutOfRangeException">
        ///     The given range, when offset by the given offsets, is not within the bounds
        ///     of the active sheet
        /// </exception>
        public void OnRangeMoved(ISheetReference range, int rowOffset, int colOffset)
        {
            ValidateNonNull(range, "range");
            var sourceRef = (SheetReference)range;

            Rectangle destRect = range.Area;

            destRect.Offset(colOffset, rowOffset);
            var destRef = (SheetReference)ReferenceFactory.FromRectangle(destRect);

            ReferencePredicateBase pred;

            if (ReferenceEquals(sourceRef.Sheet, destRef.Sheet))
            {
                pred = new SheetReferencePredicate(Sheets.ActiveSheet);
            }
            else
            {
                pred = new CrossSheetReferencePredicate(sourceRef.Sheet, destRef.Sheet);
            }

            DoReferenceOperation(new RangeMovedOperator(this, sourceRef, destRef), pred);
        }