示例#1
0
        private static ValueEval Eval(int srcRowIndex, int srcColumnIndex, ValueEval arg1, AreaEval aeRange,
                                      AreaEval aeSum)
        {
            // TODO - junit to prove last arg must be srcColumnIndex and not srcRowIndex
            IMatchPredicate mp     = Countif.CreateCriteriaPredicate(arg1, srcRowIndex, srcColumnIndex);
            double          result = SumMatchingCells(aeRange, mp, aeSum);

            return(new NumberEval(result));
        }
示例#2
0
        /**
         * Resolves the last (optional) parameter (<b>range_lookup</b>) to the VLOOKUP and HLOOKUP functions.
         * @param rangeLookupArg
         * @param srcCellRow
         * @param srcCellCol
         * @return
         * @throws EvaluationException
         */

        public static bool ResolveRangeLookupArg(ValueEval rangeLookupArg, int srcCellRow, int srcCellCol)
        {
            if (rangeLookupArg == null)
            {
                // range_lookup arg not provided
                return(true); // default Is TRUE
            }
            ValueEval valEval = OperandResolver.GetSingleValue(rangeLookupArg, srcCellRow, srcCellCol);

            if (valEval is BlankEval)
            {
                // Tricky:
                // fourth arg supplied but Evaluates to blank
                // this does not Get the default value
                return(false);
            }
            if (valEval is BoolEval)
            {
                // Happy day flow
                BoolEval boolEval = (BoolEval)valEval;
                return(boolEval.BooleanValue);
            }

            if (valEval is StringEval)
            {
                string stringValue = ((StringEval)valEval).StringValue;
                if (stringValue.Length < 1)
                {
                    // More trickiness:
                    // Empty string Is not the same as BlankEval.  It causes #VALUE! error
                    throw EvaluationException.InvalidValue();
                }
                // TODO move parseBoolean to OperandResolver
                bool?b = Countif.ParseBoolean(stringValue);
                if (b != null)
                {
                    // string Converted to bool OK
                    return(b == true ? true : false);
                }
                //// Even more trickiness:
                //// Note - even if the StringEval represents a number value (for example "1"),
                //// Excel does not resolve it to a bool.
                throw EvaluationException.InvalidValue();
                //// This Is in contrast to the code below,, where NumberEvals values (for
                //// example 0.01) *do* resolve to equivalent bool values.
            }
            if (valEval is NumericValueEval)
            {
                NumericValueEval nve = (NumericValueEval)valEval;
                // zero Is FALSE, everything else Is TRUE
                return(0.0 != nve.NumberValue);
            }
            throw new Exception("Unexpected eval type (" + valEval.GetType().Name + ")");
        }