Esempio n. 1
0
    protected Formula CreateFormula(string expression, int row, int col)
    {
        ISheetReference @ref = MyFormulaEngine.ReferenceFactory.Cell(row, col);
        Formula         f    = MyFormulaEngine.AddFormula(expression, @ref);

        return(f);
    }
Esempio n. 2
0
        private void DoTestReferenceParsing(string image, int expectedRow, int expectedColumn)
        {
            ISheetReference @ref = _formulaEngine.ReferenceFactory.Parse(image);

            Assert.AreEqual(expectedRow, @ref.Row);
            Assert.AreEqual(expectedColumn, @ref.Column);
        }
Esempio n. 3
0
        protected void CompareRanges(ISheetReference @ref, Range range)
        {
            Rectangle excelRect = ExcelRangeToRectangle(range);
            Rectangle refRect   = @ref.Area;

            Assert.AreEqual(excelRect, refRect);
        }
Esempio n. 4
0
        /// <summary>
        ///     Removes all sheet formulas in a given range
        /// </summary>
        /// <param name="range">The range to clear formulas in</param>
        /// <remarks>
        ///     This method is used when you need to clear all sheet formulas in a given range.  All formulas bound to references
        ///     on the same sheet as range and that intersect its area will be removed from the engine.
        /// </remarks>
        public void RemoveFormulasInRange(ISheetReference range)
        {
            ValidateNonNull(range, "range");
            var   realRange = (SheetReference)range;
            IList toRemove  = new ArrayList();

            foreach (Reference selfRef in _referenceFormulaMap.Keys)
            {
                if (realRange.Intersects(selfRef))
                {
                    toRemove.Add(_referenceFormulaMap[selfRef]);
                }
            }

            RemoveFormulas(toRemove);
        }
Esempio n. 5
0
        /// <summary>
        ///     Copies and adjusts a formula on a sheet
        /// </summary>
        /// <param name="source">The formula to copy</param>
        /// <param name="destRef">The destination of the copied formula</param>
        /// <remarks>
        ///     This method is used when wishing to implement copying of formulas similarly to Excel.  It makes a copy of the
        ///     source formula,
        ///     offsets its references by the difference between destRef and source's current location, and adds the copy to the
        ///     engine.
        ///     The engine will only adjust references marked as relative in the copied formula.
        /// </remarks>
        /// <exception cref="System.ArgumentException">The source formula is not bound to a sheet reference</exception>
        public void CopySheetFormula(Formula source, ISheetReference destRef)
        {
            ValidateNonNull(source, "source");
            ValidateNonNull(destRef, "destRef");
            if (!(source.SelfReference is SheetReference))
            {
                throw new ArgumentException("Source formula must be on a sheet");
            }
            var     sourceRef = (SheetReference)source.SelfReference;
            int     rowOffset = destRef.Row - sourceRef.Row;
            int     colOffset = destRef.Column - sourceRef.Column;
            Formula clone     = source.Clone();

            clone.OffsetReferencesForCopy(destRef.Sheet, rowOffset, colOffset);
            AddFormula(clone, destRef);
        }
Esempio n. 6
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);
        }