Exemplo n.º 1
0
 private ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval lookupEval, ValueEval indexEval,
                            ValueEval returnEval, String notFound, LookupUtils.MatchMode matchMode,
                            LookupUtils.SearchMode searchMode, bool isSingleValue)
 {
     try
     {
         ValueEval lookupValue = OperandResolver.GetSingleValue(lookupEval, srcRowIndex, srcColumnIndex);
         TwoDEval  tableArray  = LookupUtils.ResolveTableArrayArg(indexEval);
         int       matchedRow;
         try
         {
             matchedRow = LookupUtils.XlookupIndexOfValue(lookupValue, LookupUtils.CreateColumnVector(tableArray, 0), matchMode, searchMode);
         }
         catch (EvaluationException e)
         {
             if (ErrorEval.NA.Equals(e.GetErrorEval()))
             {
                 if (string.IsNullOrEmpty(notFound))
                 {
                     if (returnEval is AreaEval)
                     {
                         AreaEval area  = (AreaEval)returnEval;
                         int      width = area.Width;
                         if (isSingleValue || width <= 1)
                         {
                             return(new StringEval(notFound));
                         }
                         return(new NotFoundAreaEval(notFound, width));
                     }
                     else
                     {
                         return(new StringEval(notFound));
                     }
                 }
                 return(ErrorEval.NA);
             }
             else
             {
                 return(e.GetErrorEval());
             }
         }
         if (returnEval is AreaEval)
         {
             AreaEval area = (AreaEval)returnEval;
             if (isSingleValue)
             {
                 return(area.GetRelativeValue(matchedRow, 0));
             }
             return(area.Offset(matchedRow, matchedRow, 0, area.Width - 1));
         }
         else
         {
             return(returnEval);
         }
     }
     catch (EvaluationException e)
     {
         return(e.GetErrorEval());
     }
 }
Exemplo n.º 2
0
 public AreaEval Offset(int relFirstRowIx, int relLastRowIx, int relFirstColIx, int relLastColIx)
 {
     if (_refEval == null)
     {
         return(_areaEval.Offset(relFirstRowIx, relLastRowIx, relFirstColIx, relLastColIx));
     }
     return(_refEval.Offset(relFirstRowIx, relLastRowIx, relFirstColIx, relLastColIx));
 }
Exemplo n.º 3
0
        private static AreaEval ResolveRange(AreaEval aeA, AreaEval aeB)
        {
            int aeAfr = aeA.FirstRow;
            int aeAfc = aeA.FirstColumn;

            int top    = Math.Min(aeAfr, aeB.FirstRow);
            int bottom = Math.Max(aeA.LastRow, aeB.LastRow);
            int left   = Math.Min(aeAfc, aeB.FirstColumn);
            int right  = Math.Max(aeA.LastColumn, aeB.LastColumn);

            return(aeA.Offset(top - aeAfr, bottom - aeAfr, left - aeAfc, right - aeAfc));
        }
Exemplo n.º 4
0
        private static AreaEval ResolveRange(AreaEval aeA, AreaEval aeB)
        {
            int aeAfr = aeA.FirstRow;
            int aeAfc = aeA.FirstColumn;

            int top = Math.Min(aeAfr, aeB.FirstRow);
            int bottom = Math.Max(aeA.LastRow, aeB.LastRow);
            int left = Math.Min(aeAfc, aeB.FirstColumn);
            int right = Math.Max(aeA.LastColumn, aeB.LastColumn);

            return aeA.Offset(top - aeAfr, bottom - aeAfr, left - aeAfc, right - aeAfc);
        }
Exemplo n.º 5
0
        /**
         * @return simple rectangular {@link AreaEval} which represents the intersection of areas
         * <c>aeA</c> and <c>aeB</c>. If the two areas do not intersect, the result is <code>null</code>.
         */
        private static AreaEval ResolveRange(AreaEval aeA, AreaEval aeB)
        {
            int aeAfr = aeA.FirstRow;
            int aeAfc = aeA.FirstColumn;
            int aeBlc = aeB.LastColumn;

            if (aeAfc > aeBlc)
            {
                return(null);
            }
            int aeBfc = aeB.FirstColumn;

            if (aeBfc > aeA.LastColumn)
            {
                return(null);
            }
            int aeBlr = aeB.LastRow;

            if (aeAfr > aeBlr)
            {
                return(null);
            }
            int aeBfr = aeB.FirstRow;
            int aeAlr = aeA.LastRow;

            if (aeBfr > aeAlr)
            {
                return(null);
            }


            int top    = Math.Max(aeAfr, aeBfr);
            int bottom = Math.Min(aeAlr, aeBlr);
            int left   = Math.Max(aeAfc, aeBfc);
            int right  = Math.Min(aeA.LastColumn, aeBlc);

            return(aeA.Offset(top - aeAfr, bottom - aeAfr, left - aeAfc, right - aeAfc));
        }