コード例 #1
0
        public override ValueEval Evaluate(int srcCellRow, int srcCellCol, ValueEval arg0)
        {
            double d;

            try
            {
                ValueEval ve = OperandResolver.GetSingleValue(arg0, srcCellRow, srcCellCol);
                if (ve is BlankEval)
                {
                    return(NumberEval.ZERO);
                }
                if (ve is StringEval)
                {
                    // Note - asymmetric with UnaryMinus
                    // -"hello" Evaluates to #VALUE!
                    // but +"hello" Evaluates to "hello"
                    return(ve);
                }
                d = OperandResolver.CoerceValueToDouble(ve);
            }
            catch (EvaluationException e)
            {
                return(e.GetErrorEval());
            }
            return(new NumberEval(+d));
        }
コード例 #2
0
 /**
  * uses the relevant flags to decode the StringEval
  * @param eval
  */
 private ValueEval XlateRefStringEval(StringEval sve)
 {
     if ((flags & REF_STRING_IS_PARSED) > 0)
     {
         String s = sve.StringValue;
         double d = OperandResolver.ParseDouble(s);
         if (double.IsNaN(d))
         {
             return(ErrorEval.VALUE_INVALID);
         }
         return(new NumberEval(d));
     }
     // strings are blanks
     return(BlankEval.instance);
 }
コード例 #3
0
        public override ValueEval Evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0, ValueEval arg1)
        {
            ValueEval vA;
            ValueEval vB;

            try
            {
                vA = OperandResolver.GetSingleValue(arg0, srcRowIndex, srcColumnIndex);
                vB = OperandResolver.GetSingleValue(arg1, srcRowIndex, srcColumnIndex);
            }
            catch (EvaluationException e)
            {
                return(e.GetErrorEval());
            }
            int  cmpResult = DoCompare(vA, vB);
            bool result    = ConvertComparisonResult(cmpResult);

            return(BoolEval.ValueOf(result));
        }
コード例 #4
0
ファイル: PercentEval.cs プロジェクト: yesonsik/npoi
        public override ValueEval Evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0)
        {
            double d0;

            try
            {
                ValueEval ve = OperandResolver.GetSingleValue(arg0, srcRowIndex, srcColumnIndex);
                d0 = OperandResolver.CoerceValueToDouble(ve);
            }
            catch (EvaluationException e)
            {
                return(e.GetErrorEval());
            }
            if (d0 == 0.0)
            { // this '==' matches +0.0 and -0.0
                return(NumberEval.ZERO);
            }
            return(new NumberEval(d0 / 100));
        }
コード例 #5
0
ファイル: ConcatEval.cs プロジェクト: FilRip/IMDEV.Commun
        public override ValueEval Evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0, ValueEval arg1)
        {
            ValueEval ve0;
            ValueEval ve1;

            try
            {
                ve0 = OperandResolver.GetSingleValue(arg0, srcRowIndex, srcColumnIndex);
                ve1 = OperandResolver.GetSingleValue(arg1, srcRowIndex, srcColumnIndex);
            }
            catch (EvaluationException e)
            {
                return(e.GetErrorEval());
            }
            StringBuilder sb = new StringBuilder();

            sb.Append(GetText(ve0));
            sb.Append(GetText(ve1));
            return(new StringEval(sb.ToString()));
        }
コード例 #6
0
        /**
         * uses the relevant flags to decode the StringEval
         * @param eval
         */
        private ValueEval XlateStringEval(StringEval eval)
        {
            if ((flags & STRING_IS_PARSED) > 0)
            {
                String s = eval.StringValue;
                double d = OperandResolver.ParseDouble(s);
                if (double.IsNaN(d))
                {
                    return(ErrorEval.VALUE_INVALID);
                }
                return(new NumberEval(d));
            }
            // strings are errors?
            if ((flags & STRING_IS_INVALID_VALUE) > 0)
            {
                return(ErrorEval.VALUE_INVALID);
            }

            // ignore strings
            return(XlateBlankEval(BLANK_IS_PARSED));
        }
コード例 #7
0
        protected double SingleOperandEvaluate(ValueEval arg, int srcCellRow, int srcCellCol)
        {
            ValueEval ve = OperandResolver.GetSingleValue(arg, srcCellRow, srcCellCol);

            return(OperandResolver.CoerceValueToDouble(ve));
        }
コード例 #8
0
        public ValueEval EvaluateArray(ValueEval[] args, int srcRowIndex, int srcColumnIndex)
        {
            ValueEval arg0 = args[0];
            ValueEval arg1 = args[1];

            int w1, w2, h1, h2;
            int a1FirstCol = 0, a1FirstRow = 0;

            if (arg0 is AreaEval)
            {
                AreaEval ae = (AreaEval)arg0;
                w1         = ae.Width;
                h1         = ae.Height;
                a1FirstCol = ae.FirstColumn;
                a1FirstRow = ae.FirstRow;
            }
            else if (arg0 is RefEval)
            {
                RefEval ref1 = (RefEval)arg0;
                w1         = 1;
                h1         = 1;
                a1FirstCol = ref1.Column;
                a1FirstRow = ref1.Row;
            }
            else
            {
                w1 = 1;
                h1 = 1;
            }
            int a2FirstCol = 0, a2FirstRow = 0;

            if (arg1 is AreaEval)
            {
                AreaEval ae = (AreaEval)arg1;
                w2         = ae.Width;
                h2         = ae.Height;
                a2FirstCol = ae.FirstColumn;
                a2FirstRow = ae.FirstRow;
            }
            else if (arg1 is RefEval)
            {
                RefEval ref1 = (RefEval)arg1;
                w2         = 1;
                h2         = 1;
                a2FirstCol = ref1.Column;
                a2FirstRow = ref1.Row;
            }
            else
            {
                w2 = 1;
                h2 = 1;
            }

            int width  = Math.Max(w1, w2);
            int height = Math.Max(h1, h2);

            ValueEval[] vals = new ValueEval[height * width];

            int idx = 0;

            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    ValueEval vA;
                    try
                    {
                        vA = OperandResolver.GetSingleValue(arg0, a1FirstRow + i, a1FirstCol + j);
                    }
                    catch (EvaluationException e)
                    {
                        vA = e.GetErrorEval();
                    }
                    ValueEval vB;
                    try
                    {
                        vB = OperandResolver.GetSingleValue(arg1, a2FirstRow + i, a2FirstCol + j);
                    }
                    catch (EvaluationException e)
                    {
                        vB = e.GetErrorEval();
                    }
                    if (vA is ErrorEval)
                    {
                        vals[idx++] = vA;
                    }
                    else if (vB is ErrorEval)
                    {
                        vals[idx++] = vB;
                    }
                    else
                    {
                        int  cmpResult = DoCompare(vA, vB);
                        bool result    = ConvertComparisonResult(cmpResult);
                        vals[idx++] = BoolEval.ValueOf(result);
                    }
                }
            }

            if (vals.Length == 1)
            {
                return(vals[0]);
            }

            return(new CacheAreaEval(srcRowIndex, srcColumnIndex, srcRowIndex + height - 1, srcColumnIndex + width - 1, vals));
        }