コード例 #1
0
        public ValueEval Evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0, ValueEval arg1)
        {
            double result;

            try
            {
                double rate = NumericFunction.SingleOperandEvaluate(arg0, srcRowIndex, srcColumnIndex);
                double d1   = NumericFunction.SingleOperandEvaluate(arg1, srcRowIndex, srcColumnIndex);
                result = Evaluate(rate, d1);
                NumericFunction.CheckValue(result);
            }
            catch (EvaluationException e)
            {
                return(e.GetErrorEval());
            }
            return(new NumberEval(result));
        }
コード例 #2
0
ファイル: DateFunc.cs プロジェクト: ruo2012/Npoi.Core
        public override ValueEval Evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0, ValueEval arg1, ValueEval arg2)
        {
            double result;

            try
            {
                double d0 = NumericFunction.SingleOperandEvaluate(arg0, srcRowIndex, srcColumnIndex);
                double d1 = NumericFunction.SingleOperandEvaluate(arg1, srcRowIndex, srcColumnIndex);
                double d2 = NumericFunction.SingleOperandEvaluate(arg2, srcRowIndex, srcColumnIndex);
                result = Evaluate(GetYear(d0), (int)d1, (int)d2);
                NumericFunction.CheckValue(result);
            }
            catch (EvaluationException e)
            {
                return(e.GetErrorEval());
            }
            return(new NumberEval(result));
        }
コード例 #3
0
        public override ValueEval Evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0, ValueEval arg1, ValueEval arg2)
        {
            double result;

            try
            {
                double    d0     = NumericFunction.SingleOperandEvaluate(arg0, srcRowIndex, srcColumnIndex);
                double    d1     = NumericFunction.SingleOperandEvaluate(arg1, srcRowIndex, srcColumnIndex);
                ValueEval ve     = OperandResolver.GetSingleValue(arg2, srcRowIndex, srcColumnIndex);
                bool?     method = OperandResolver.CoerceValueToBoolean(ve, false);
                result = Evaluate(d0, d1);
            }
            catch (EvaluationException e)
            {
                return(e.GetErrorEval());
            }
            return(new NumberEval(result));
        }
コード例 #4
0
ファイル: Poisson.cs プロジェクト: ruo2012/Npoi.Core
        public override ValueEval Evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0, ValueEval arg1, ValueEval arg2)
        {
            // arguments/result for this function
            double mean       = 0;
            double x          = 0;
            bool   cumulative = ((BoolEval)arg2).BooleanValue;
            double result     = 0;

            try
            {
                x    = NumericFunction.SingleOperandEvaluate(arg0, srcRowIndex, srcColumnIndex);
                mean = NumericFunction.SingleOperandEvaluate(arg1, srcRowIndex, srcColumnIndex);

                // check for default result : excel implementation for 0,0
                // is different to Math Common.
                if (IsDefaultResult(x, mean))
                {
                    return(new NumberEval(DEFAULT_RETURN_RESULT));
                }
                // check the arguments : as per excel function def
                CheckArgument(x);
                CheckArgument(mean);

                // truncate x : as per excel function def
                if (cumulative)
                {
                    result = cumulativeProbability((int)x, mean);
                }
                else
                {
                    result = probability((int)x, mean);
                }

                // check the result
                NumericFunction.CheckValue(result);
            }
            catch (EvaluationException e)
            {
                return(e.GetErrorEval());
            }

            return(new NumberEval(result));
        }
コード例 #5
0
        public ValueEval Evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0, ValueEval arg1,
                                  ValueEval arg2, ValueEval arg3, ValueEval arg4)
        {
            double result;

            try
            {
                double d0 = NumericFunction.SingleOperandEvaluate(arg0, srcRowIndex, srcColumnIndex);
                double d1 = NumericFunction.SingleOperandEvaluate(arg1, srcRowIndex, srcColumnIndex);
                double d2 = NumericFunction.SingleOperandEvaluate(arg2, srcRowIndex, srcColumnIndex);
                double d3 = NumericFunction.SingleOperandEvaluate(arg3, srcRowIndex, srcColumnIndex);
                double d4 = NumericFunction.SingleOperandEvaluate(arg4, srcRowIndex, srcColumnIndex);
                result = Evaluate(d0, d1, d2, d3, d4 != 0.0);
                NumericFunction.CheckValue(result);
            }
            catch (EvaluationException e)
            {
                return(e.GetErrorEval());
            }
            return(new NumberEval(result));
        }
コード例 #6
0
ファイル: EOMonth.cs プロジェクト: xewn/Npoi.Core
        public ValueEval Evaluate(ValueEval[] args, OperationEvaluationContext ec)
        {
            if (args.Length != 2)
            {
                return(ErrorEval.VALUE_INVALID);
            }

            try
            {
                double startDateAsNumber = NumericFunction.SingleOperandEvaluate(args[0], ec.RowIndex, ec.ColumnIndex);
                int    months            = (int)NumericFunction.SingleOperandEvaluate(args[1], ec.RowIndex, ec.ColumnIndex);

                // Excel treats date 0 as 1900-01-00; EOMONTH results in 1900-01-31
                if (startDateAsNumber >= 0.0 && startDateAsNumber < 1.0)
                {
                    startDateAsNumber = 1.0;
                }

                DateTime startDate = DateUtil.GetJavaDate(startDateAsNumber, false);
                //the month
                DateTime dtEnd = startDate.AddMonths(months);
                //next month
                dtEnd = dtEnd.AddMonths(1);
                //first day of next month
                dtEnd = new DateTime(dtEnd.Year, dtEnd.Month, 1);
                //last day of the month
                dtEnd = dtEnd.AddDays(-1);


                return(new NumberEval(DateUtil.GetExcelDate(dtEnd)));
            }
            catch (EvaluationException e)
            {
                return(e.GetErrorEval());
            }
        }
コード例 #7
0
        public override ValueEval Evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0,
                                           ValueEval arg1)
        {
            double result;

            try {
                double d0    = NumericFunction.SingleOperandEvaluate(arg0, srcRowIndex, srcColumnIndex);
                double d1    = NumericFunction.SingleOperandEvaluate(arg1, srcRowIndex, srcColumnIndex);
                double logE  = Math.Log(d0);
                double base1 = d1;
                if (base1 == Math.E)
                {
                    result = logE;
                }
                else
                {
                    result = logE / Math.Log(base1);
                }
                NumericFunction.CheckValue(result);
            } catch (EvaluationException e) {
                return(e.GetErrorEval());
            }
            return(new NumberEval(result));
        }
コード例 #8
0
        public ValueEval Evaluate(ValueEval[] args, int srcRowIndex,
                                  int srcColumnIndex)
        {
            if (args.Length < 2 || args.Length > 5)
            {
                return(ErrorEval.VALUE_INVALID);
            }
            try
            {
                bool pAbsRow, pAbsCol;

                int row = (int)NumericFunction.SingleOperandEvaluate(args[0], srcRowIndex, srcColumnIndex);
                int col = (int)NumericFunction.SingleOperandEvaluate(args[1], srcRowIndex, srcColumnIndex);

                int refType;
                if (args.Length > 2 && args[2] != MissingArgEval.instance)
                {
                    refType = (int)NumericFunction.SingleOperandEvaluate(args[2], srcRowIndex, srcColumnIndex);
                }
                else
                {
                    refType = REF_ABSOLUTE; // this is also the default if parameter is not given
                }
                switch (refType)
                {
                case REF_ABSOLUTE:
                    pAbsRow = true;
                    pAbsCol = true;
                    break;

                case REF_ROW_ABSOLUTE_COLUMN_RELATIVE:
                    pAbsRow = true;
                    pAbsCol = false;
                    break;

                case REF_ROW_RELATIVE_RELATIVE_ABSOLUTE:
                    pAbsRow = false;
                    pAbsCol = true;
                    break;

                case REF_RELATIVE:
                    pAbsRow = false;
                    pAbsCol = false;
                    break;

                default:
                    throw new EvaluationException(ErrorEval.VALUE_INVALID);
                }

                bool a1;
                if (args.Length > 3)
                {
                    ValueEval ve = OperandResolver.GetSingleValue(args[3], srcRowIndex, srcColumnIndex);
                    // TODO R1C1 style is not yet supported
                    a1 = ve == MissingArgEval.instance ? true : OperandResolver.CoerceValueToBoolean(ve, false).Value;
                }
                else
                {
                    a1 = true;
                }

                string sheetName;
                if (args.Length == 5)
                {
                    ValueEval ve = OperandResolver.GetSingleValue(args[4], srcRowIndex, srcColumnIndex);
                    sheetName = ve == MissingArgEval.instance ? null : OperandResolver.CoerceValueToString(ve);
                }
                else
                {
                    sheetName = null;
                }

                CellReference ref1 = new CellReference(row - 1, col - 1, pAbsRow, pAbsCol);
                StringBuilder sb   = new StringBuilder(32);
                if (sheetName != null)
                {
                    SheetNameFormatter.AppendFormat(sb, sheetName);
                    sb.Append('!');
                }
                sb.Append(ref1.FormatAsString());

                return(new StringEval(sb.ToString()));
            }
            catch (EvaluationException e)
            {
                return(e.GetErrorEval());
            }
        }