/**
         * @return possibly  <c>ErrorEval</c>, and <c>null</c>
         */
        private static ValueEval ChooseSingleElementFromAreaInternal(AreaEval ae,
                                                                     int srcCellRow, int srcCellCol)
        {
            //if (false)
            //{
            //    // this is too simplistic
            //    if (ae.ContainsRow(srcCellRow) && ae.ContainsColumn(srcCellCol))
            //    {
            //        throw new EvaluationException(ErrorEval.CIRCULAR_REF_ERROR);
            //    }
            //    /*
            //    Circular references are not dealt with directly here, but it is worth noting some Issues.

            //    ANY one of the return statements in this method could return a cell that is identical
            //    to the one immediately being Evaluated.  The evaluating cell is identified by srcCellRow,
            //    srcCellRow AND sheet.  The sheet is not available in any nearby calling method, so that's
            //    one reason why circular references are not easy to detect here. (The sheet of the returned
            //    cell can be obtained from ae if it is an Area3DEval.)

            //    Another reason there's little value in attempting to detect circular references here Is
            //    that only direct circular references could be detected.  If the cycle involved two or more
            //    cells this method could not detect it.

            //    Logic to detect evaluation cycles of all kinds has been coded in EvaluationCycleDetector
            //    (and HSSFFormulaEvaluator).
            //     */
            //}

            if (ae.IsColumn)
            {
                if (ae.IsRow)
                {
                    return(ae.GetRelativeValue(0, 0));
                }
                if (!ae.ContainsRow(srcCellRow))
                {
                    throw EvaluationException.InvalidValue();
                }
                return(ae.GetAbsoluteValue(srcCellRow, ae.FirstColumn));
            }
            if (!ae.IsRow)
            {
                // multi-column, multi-row area
                if (ae.ContainsRow(srcCellRow) && ae.ContainsColumn(srcCellCol))
                {
                    return(ae.GetAbsoluteValue(ae.FirstRow, ae.FirstColumn));
                }
                throw EvaluationException.InvalidValue();
            }
            if (!ae.ContainsColumn(srcCellCol))
            {
                throw EvaluationException.InvalidValue();
            }
            return(ae.GetAbsoluteValue(ae.FirstRow, srcCellCol));
        }
示例#2
0
        public void TestGetValue_bug44950()
        {
            // TODO - this Test probably isn't Testing much anymore
            AreaPtg    ptg = new AreaPtg("B2:D3");
            NumberEval one = new NumberEval(1);

            ValueEval[] values =
            {
                one,
                new NumberEval(2),
                new NumberEval(3),
                new NumberEval(4),
                new NumberEval(5),
                new NumberEval(6),
            };
            AreaEval ae = EvalFactory.CreateAreaEval(ptg, values);

            if (one == ae.GetAbsoluteValue(1, 2))
            {
                throw new AssertionException("Identified bug 44950 a");
            }
            Confirm(1, ae, 1, 1);
            Confirm(2, ae, 1, 2);
            Confirm(3, ae, 1, 3);
            Confirm(4, ae, 2, 1);
            Confirm(5, ae, 2, 2);
            Confirm(6, ae, 2, 3);
        }
示例#3
0
 private List <ValueEval> getValues(ValueEval eval, int srcRowIndex, int srcColumnIndex)
 {
     if (eval is AreaEval)
     {
         AreaEval         ae   = (AreaEval)eval;
         List <ValueEval> list = new List <ValueEval>();
         for (int r = ae.FirstRow; r <= ae.LastRow; r++)
         {
             for (int c = ae.FirstColumn; c <= ae.LastColumn; c++)
             {
                 list.Add(OperandResolver.GetSingleValue(ae.GetAbsoluteValue(r, c), r, c));
             }
         }
         return(list);
     }
     else
     {
         return(new List <ValueEval>()
         {
             OperandResolver.GetSingleValue(eval, srcRowIndex, srcColumnIndex)
         });
     }
 }
示例#4
0
        /**
         * @return possibly  <c>ErrorEval</c>, and <c>null</c> 
         */
        private static ValueEval ChooseSingleElementFromAreaInternal(AreaEval ae,
                int srcCellRow, int srcCellCol)
        {

            //if (false)
            //{
            //    // this is too simplistic
            //    if (ae.ContainsRow(srcCellRow) && ae.ContainsColumn(srcCellCol))
            //    {
            //        throw new EvaluationException(ErrorEval.CIRCULAR_REF_ERROR);
            //    }
            //    /*
            //    Circular references are not dealt with directly here, but it is worth noting some Issues.

            //    ANY one of the return statements in this method could return a cell that is identical
            //    to the one immediately being Evaluated.  The evaluating cell is identified by srcCellRow,
            //    srcCellRow AND sheet.  The sheet is not available in any nearby calling method, so that's
            //    one reason why circular references are not easy to detect here. (The sheet of the returned
            //    cell can be obtained from ae if it is an Area3DEval.)

            //    Another reason there's little value in attempting to detect circular references here Is
            //    that only direct circular references could be detected.  If the cycle involved two or more
            //    cells this method could not detect it.  

            //    Logic to detect evaluation cycles of all kinds has been coded in EvaluationCycleDetector
            //    (and HSSFFormulaEvaluator). 
            //     */
            //}

            if (ae.IsColumn)
            {
                if (ae.IsRow)
                {
                    return ae.GetRelativeValue(0, 0);
                }
                if (!ae.ContainsRow(srcCellRow))
                {
                    throw EvaluationException.InvalidValue();
                }
                return ae.GetAbsoluteValue(srcCellRow, ae.FirstColumn);
            }
            if (!ae.IsRow)
            {
                // multi-column, multi-row area
                if (ae.ContainsRow(srcCellRow) && ae.ContainsColumn(srcCellCol))
                {
                    return ae.GetAbsoluteValue(ae.FirstRow, ae.FirstColumn);
                }
                throw EvaluationException.InvalidValue();
            }
            if (!ae.ContainsColumn(srcCellCol))
            {
                throw EvaluationException.InvalidValue();
            }
            return ae.GetAbsoluteValue(ae.FirstRow, srcCellCol);
        }
示例#5
0
 private static void Confirm(int expectedValue, AreaEval ae, int row, int col)
 {
     NumberEval v = (NumberEval)ae.GetAbsoluteValue(row, col);
     Assert.AreEqual(expectedValue, v.NumberValue, 0.0);
 }
示例#6
0
        private static void Confirm(int expectedValue, AreaEval ae, int row, int col)
        {
            NumberEval v = (NumberEval)ae.GetAbsoluteValue(row, col);

            Assert.AreEqual(expectedValue, v.NumberValue, 0.0);
        }