Пример #1
0
        public ValueEval Evaluate(ValueEval[] args, OperationEvaluationContext ec)
        {
            if (args.Length < 3 || args.Length % 2 == 0)
            {
                return(ErrorEval.VALUE_INVALID);
            }

            try
            {
                AreaEval avgRange = ConvertRangeArg(args[0]);

                // collect pairs of ranges and criteria
                AreaEval[]        ae = new AreaEval[(args.Length - 1) / 2];
                IMatchPredicate[] mp = new IMatchPredicate[ae.Length];
                for (int i = 1, k = 0; i < args.Length; i += 2, k++)
                {
                    ae[k] = ConvertRangeArg(args[i]);
                    mp[k] = Countif.CreateCriteriaPredicate(args[i + 1], ec.RowIndex, ec.ColumnIndex);
                }

                ValidateCriteriaRanges(ae, avgRange);

                double result = GetAvgFromMatchingCells(ae, mp, avgRange);
                return(new NumberEval(result));
            }
            catch (EvaluationException e)
            {
                return(e.GetErrorEval());
            }
        }
Пример #2
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));
        }
Пример #3
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);

            // handle empty cells
            if (mp == null)
            {
                return(NumberEval.ZERO);
            }
            try
            {
                double result = SumMatchingCells(aeRange, mp, aeSum);
                return(new NumberEval(result));
            }
            catch (EvaluationException var)
            {
                return(var.GetErrorEval());
            }
        }