예제 #1
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));
        }
예제 #2
0
 /**
  * Applies some conversion rules if the supplied value is not already a number.
  * Note - <c>BlankEval</c> is not supported and must be handled by the caller.
  * @param ev must be a <c>NumberEval</c>, <c>StringEval</c> or <c>BoolEval</c>
  * @return actual, Parsed or interpreted double value (respectively).
  * @throws EvaluationException(#VALUE!) only if a StringEval is supplied and cannot be Parsed
  * as a double (See <c>Parsedouble()</c> for allowable formats).
  * @throws Exception if the supplied parameter is not <c>NumberEval</c>,
  *  <c>StringEval</c> or <c>BoolEval</c>
  */
 public static double CoerceValueToDouble(ValueEval ev)
 {
     if (ev == BlankEval.instance)
     {
         return(0.0);
     }
     if (ev is NumericValueEval)
     {
         // this also handles bools
         return(((NumericValueEval)ev).NumberValue);
     }
     if (ev is StringEval)
     {
         double dd = ParseDouble(((StringEval)ev).StringValue);
         if (double.IsNaN(dd))
         {
             throw EvaluationException.InvalidValue();
         }
         return(dd);
     }
     throw new Exception("Unexpected arg eval type (" + ev.GetType().Name + ")");
 }