Exemple #1
0
        public ValueEval Evaluate(ValueEval[] args, OperationEvaluationContext ec)
        {
            int srcCellRow = ec.RowIndex;
            int srcCellCol = ec.ColumnIndex;
            double result;
            try
            {
                int basis = 0; // default
                switch (args.Length)
                {
                    case 3:
                        basis = EvaluateIntArg(args[2], srcCellRow, srcCellCol);
                        break;
                    case 2:
                        //basis = EvaluateIntArg(args[2], srcCellRow, srcCellCol);
                        break;
                    default:
                        return ErrorEval.VALUE_INVALID;
                }
                double startDateVal = EvaluateDateArg(args[0], srcCellRow, srcCellCol);
                double endDateVal = EvaluateDateArg(args[1], srcCellRow, srcCellCol);
                result = YearFracCalculator.Calculate(startDateVal, endDateVal, basis);
            }
            catch (EvaluationException e)
            {
                return e.GetErrorEval();
            }

            return new NumberEval(result);
        }
        public ValueEval Evaluate(ValueEval[] args, OperationEvaluationContext ec)
        {
            int nIncomingArgs = args.Length;
            if (nIncomingArgs < 1)
            {
                throw new Exception("function name argument missing");
            }

            ValueEval nameArg = args[0];
            String functionName = string.Empty ;
            if (nameArg is NameEval)
            {
                functionName = ((NameEval)nameArg).FunctionName;
            }
            else if (nameArg is NameXEval)
            {
                functionName = ec.GetWorkbook().ResolveNameXText(((NameXEval)nameArg).Ptg);
            }
            else
            {
                throw new Exception("First argument should be a NameEval, but got ("
                        + nameArg.GetType().Name + ")");
            }
            FreeRefFunction targetFunc = ec.FindUserDefinedFunction(functionName);
            if (targetFunc == null)
            {
                throw new NotImplementedException(functionName);
            }
            int nOutGoingArgs = nIncomingArgs - 1;
            ValueEval[] outGoingArgs = new ValueEval[nOutGoingArgs];
            Array.Copy(args, 1, outGoingArgs, 0, nOutGoingArgs);
            return targetFunc.Evaluate(outGoingArgs, ec);
        }
Exemple #3
0
        public ValueEval Evaluate(ValueEval[] args, OperationEvaluationContext ec)
        {
            if (args.Length < 1)
            {
                return ErrorEval.VALUE_INVALID;
            }

            bool isA1style;
            String text;
            try
            {
                ValueEval ve = OperandResolver.GetSingleValue(args[0], ec.RowIndex, ec
                        .ColumnIndex);
                text = OperandResolver.CoerceValueToString(ve);
                switch (args.Length)
                {
                    case 1:
                        isA1style = true;
                        break;
                    case 2:
                        isA1style = EvaluateBooleanArg(args[1], ec);
                        break;
                    default:
                        return ErrorEval.VALUE_INVALID;
                }
            }
            catch (EvaluationException e)
            {
                return e.GetErrorEval();
            }

            return EvaluateIndirect(ec, text, isA1style);
        }
Exemple #4
0
        private static bool EvaluateBooleanArg(ValueEval arg, OperationEvaluationContext ec)
        {
            ValueEval ve = OperandResolver.GetSingleValue(arg, ec.RowIndex, ec.ColumnIndex);

            if (ve == BlankEval.instance || ve == MissingArgEval.instance)
            {
                return false;
            }
            // numeric quantities follow standard bool conversion rules
            // for strings, only "TRUE" and "FALSE" (case insensitive) are valid
            return (bool)OperandResolver.CoerceValueToBoolean(ve, false);
        }
        public ValueEval Evaluate(ValueEval[] args, OperationEvaluationContext ec) 
        {
            if (args.Length != 1)
            {
                return ErrorEval.VALUE_INVALID;
            }

            int val;
            try
            {
                val = EvaluateArgParity(args[0], ec.RowIndex, ec.ColumnIndex);
            }
            catch (EvaluationException e)
            {
                return e.GetErrorEval();
            }

            return BoolEval.ValueOf(val == _desiredParity);
        }
        /**
         * returns the OperationEval concrete impl instance corresponding
         * to the supplied operationPtg
         */
        public static ValueEval Evaluate(OperationPtg ptg, ValueEval[] args,
                OperationEvaluationContext ec)
        {
            if (ptg == null)
            {
                throw new ArgumentException("ptg must not be null");
            }
            Zephyr.Utils.NPOI.SS.Formula.Functions.Function result = _instancesByPtgClass[ptg] as Zephyr.Utils.NPOI.SS.Formula.Functions.Function;

            if (result != null)
            {
                return result.Evaluate(args, ec.RowIndex, (short)ec.ColumnIndex);
            }

            if (ptg is AbstractFunctionPtg)
            {
                AbstractFunctionPtg fptg = (AbstractFunctionPtg)ptg;
                int functionIndex = fptg.GetFunctionIndex();
                switch (functionIndex)
                {
                    case Zephyr.Utils.NPOI.SS.Formula.Function.FunctionMetadataRegistry.FUNCTION_INDEX_INDIRECT:
                        return Indirect.instance.Evaluate(args, ec);
                    case Zephyr.Utils.NPOI.SS.Formula.Function.FunctionMetadataRegistry.FUNCTION_INDEX_EXTERNAL:
                        return UserDefinedFunction.instance.Evaluate(args, ec);
                }

                return FunctionEval.GetBasicFunction(functionIndex).Evaluate(args, ec.RowIndex, ec.ColumnIndex);
            }
            throw new Exception("Unexpected operation ptg class (" + ptg.GetType().Name + ")");
        }
		public ValueEval Evaluate(ValueEval[] args, OperationEvaluationContext ec) {
			throw new NotImplementedException(_functionName);
		}
Exemple #8
0
        private static ValueEval EvaluateIndirect(OperationEvaluationContext ec, String text,
                bool isA1style)
        {
            // Search backwards for '!' because sheet names can contain '!'
            int plingPos = text.LastIndexOf('!');

            String workbookName;
            String sheetName;
            String refText; // whitespace around this Gets Trimmed OK
            if (plingPos < 0)
            {
                workbookName = null;
                sheetName = null;
                refText = text;
            }
            else
            {
                String[] parts = ParseWorkbookAndSheetName(text.Substring(0, plingPos));
                if (parts == null)
                {
                    return ErrorEval.REF_INVALID;
                }
                workbookName = parts[0];
                sheetName = parts[1];
                refText = text.Substring(plingPos + 1);
            }

            String refStrPart1;
            String refStrPart2;

            int colonPos = refText.IndexOf(':');
            if (colonPos < 0)
            {
                refStrPart1 = refText.Trim();
                refStrPart2 = null;
            }
            else
            {
                refStrPart1 = refText.Substring(0, colonPos).Trim();
                refStrPart2 = refText.Substring(colonPos + 1).Trim();
            }
            return ec.GetDynamicReference(workbookName, sheetName, refStrPart1, refStrPart2, isA1style);
        }