コード例 #1
0
ファイル: Hlookup.cs プロジェクト: zhgl7688/-
        public ValueEval Evaluate(ValueEval[] args, int srcCellRow, int srcCellCol)
        {
            ValueEval arg3 = null;

            switch (args.Length)
            {
            case 4:
                arg3 = args[3];     // important: assumed array element Is never null
                break;

            case 3:
                break;

            default:
                // wrong number of arguments
                return(ErrorEval.VALUE_INVALID);
            }
            try
            {
                // Evaluation order:
                // arg0 lookup_value, arg1 table_array, arg3 range_lookup, Find lookup value, arg2 row_index, fetch result
                ValueEval   lookupValue   = OperandResolver.GetSingleValue(args[0], srcCellRow, srcCellCol);
                AreaEval    tableArray    = LookupUtils.ResolveTableArrayArg(args[1]);
                bool        IsRangeLookup = LookupUtils.ResolveRangeLookupArg(arg3, srcCellRow, srcCellCol);
                int         colIndex      = LookupUtils.LookupIndexOfValue(lookupValue, LookupUtils.CreateRowVector(tableArray, 0), IsRangeLookup);
                int         rowIndex      = LookupUtils.ResolveRowOrColIndexArg(args[2], srcCellRow, srcCellCol);
                ValueVector resultCol     = CreateResultColumnVector(tableArray, rowIndex);
                return(resultCol.GetItem(colIndex));
            }
            catch (EvaluationException e)
            {
                return(e.GetErrorEval());
            }
        }
コード例 #2
0
ファイル: Vlookup.cs プロジェクト: zhgl7688/-
 public override ValueEval Evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0, ValueEval arg1,
                                    ValueEval arg2, ValueEval arg3)
 {
     try
     {
         // Evaluation order:
         // arg0 lookup_value, arg1 table_array, arg3 range_lookup, find lookup value, arg2 col_index, fetch result
         ValueEval   lookupValue   = OperandResolver.GetSingleValue(arg0, srcRowIndex, srcColumnIndex);
         TwoDEval    tableArray    = LookupUtils.ResolveTableArrayArg(arg1);
         bool        isRangeLookup = LookupUtils.ResolveRangeLookupArg(arg3, srcRowIndex, srcColumnIndex);
         int         rowIndex      = LookupUtils.LookupIndexOfValue(lookupValue, LookupUtils.CreateColumnVector(tableArray, 0), isRangeLookup);
         int         colIndex      = LookupUtils.ResolveRowOrColIndexArg(arg2, srcRowIndex, srcColumnIndex);
         ValueVector resultCol     = CreateResultColumnVector(tableArray, colIndex);
         return(resultCol.GetItem(rowIndex));
     }
     catch (EvaluationException e)
     {
         return(e.GetErrorEval());
     }
 }
コード例 #3
0
        public ValueEval Evaluate(ValueEval[] args, int srcCellRow, int srcCellCol)
        {
            switch (args.Length)
            {
            case 3:
                break;

            case 2:
                // complex rules to choose lookupVector and resultVector from the single area ref
                throw new Exception("Two arg version of LOOKUP not supported yet");

            default:
                return(ErrorEval.VALUE_INVALID);
            }


            try
            {
                ValueEval lookupValue    = OperandResolver.GetSingleValue(args[0], srcCellRow, srcCellCol);
                AreaEval  aeLookupVector = LookupUtils.ResolveTableArrayArg(args[1]);
                AreaEval  aeResultVector = LookupUtils.ResolveTableArrayArg(args[2]);

                ValueVector lookupVector = CreateVector(aeLookupVector);
                ValueVector resultVector = CreateVector(aeResultVector);
                if (lookupVector.Size > resultVector.Size)
                {
                    // Excel seems to handle this by accessing past the end of the result vector.
                    throw new Exception("Lookup vector and result vector of differing sizes not supported yet");
                }
                int index = LookupUtils.LookupIndexOfValue(lookupValue, lookupVector, true);

                return(resultVector.GetItem(index));
            }
            catch (EvaluationException e)
            {
                return(e.GetErrorEval());
            }
        }