本文整理汇总了C#中ValueEval类的典型用法代码示例。如果您正苦于以下问题:C# ValueEval类的具体用法?C# ValueEval怎么用?C# ValueEval使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ValueEval类属于命名空间,在下文中一共展示了ValueEval类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Evaluate
/**
* 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");
}
Function result = _instancesByPtgClass[ptg] as 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 NPOI.HSSF.Record.Formula.Function.FunctionMetadataRegistry.FUNCTION_INDEX_INDIRECT:
return Indirect.instance.Evaluate(args, ec);
case NPOI.HSSF.Record.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 + ")");
}
示例2: ConfirmPercentile
private void ConfirmPercentile(ValueEval percentile, ValueEval[] args, double expected)
{
ValueEval result = invokePercentile(args, percentile);
Assert.AreEqual(typeof(NumberEval), result.GetType());
double delta = 0.00000001;
Assert.AreEqual(expected, ((NumberEval)result).NumberValue, delta);
}
示例3: EvaluateFunc
public override ValueEval EvaluateFunc(ValueEval[] args, int srcCellRow, int srcCellCol)
{
if (args.Length != 3)
{
return ErrorEval.VALUE_INVALID;
}
String text = EvaluateStringArg(args[0], srcCellRow, srcCellCol);
int startCharNum = EvaluateIntArg(args[1], srcCellRow, srcCellCol);
int numChars = EvaluateIntArg(args[2], srcCellRow, srcCellCol);
int startIx = startCharNum - 1; // convert to zero-based
// Note - for start_num arg, blank/zero causes error(#VALUE!),
// but for num_chars causes empty string to be returned.
if (startIx < 0)
{
return ErrorEval.VALUE_INVALID;
}
if (numChars < 0)
{
return ErrorEval.VALUE_INVALID;
}
int len = text.Length;
if (numChars < 0 || startIx > len)
{
return new StringEval("");
}
int endIx = Math.Min(startIx + numChars, len);
String result = text.Substring(startIx, endIx-startIx);
return new StringEval(result);
}
示例4: Calculate
private bool Calculate(ValueEval[] args)
{
bool result = InitialResultValue;
bool atleastOneNonBlank = false;
bool? tempVe;
/*
* Note: no short-circuit bool loop exit because any ErrorEvals will override the result
*/
for (int i = 0, iSize = args.Length; i < iSize; i++)
{
ValueEval arg = args[i];
if (arg is AreaEval)
{
AreaEval ae = (AreaEval)arg;
int height = ae.Height;
int width = ae.Width;
for (int rrIx = 0; rrIx < height; rrIx++)
{
for (int rcIx = 0; rcIx < width; rcIx++)
{
ValueEval ve = ae.GetRelativeValue(rrIx, rcIx);
tempVe = OperandResolver.CoerceValueToBoolean(ve, true);
if (tempVe != null)
{
result = PartialEvaluate(result, Convert.ToBoolean(tempVe));
atleastOneNonBlank = true;
}
}
}
continue;
}
if (arg is RefEval)
{
ValueEval ve = ((RefEval)arg).InnerValueEval;
tempVe = OperandResolver.CoerceValueToBoolean(ve, true);
}
else if (arg is ValueEval)
{
ValueEval ve = (ValueEval)arg;
tempVe = OperandResolver.CoerceValueToBoolean(ve, false);
}
else
{
throw new InvalidOperationException("Unexpected eval (" + arg.GetType().Name + ")");
}
if (tempVe != null)
{
result = PartialEvaluate(result, Convert.ToBoolean(tempVe));
atleastOneNonBlank = true;
}
}
if (!atleastOneNonBlank)
{
throw new EvaluationException(ErrorEval.VALUE_INVALID);
}
return result;
}
示例5: Evaluate
public override ValueEval Evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0, ValueEval arg1)
{
double result;
try
{
double d0 = SingleOperandEvaluate(arg0, srcRowIndex, srcColumnIndex);
double d1 = SingleOperandEvaluate(arg1, srcRowIndex, srcColumnIndex);
result = Evaluate(d0, d1);
if (result == 0.0)
{ // this '==' matches +0.0 and -0.0
// Excel Converts -0.0 to +0.0 for '*', '/', '%', '+' and '^'
if (!(this is SubtractEval))
{
return NumberEval.ZERO;
}
}
if (Double.IsNaN(result) || Double.IsInfinity(result))
{
return ErrorEval.NUM_ERROR;
}
}
catch (EvaluationException e)
{
return e.GetErrorEval();
}
return new NumberEval(result);
}
示例6: Evaluate
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);
}
示例7: Evaluate
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();
}
}
示例8: TestCountBlank
public void TestCountBlank()
{
AreaEval range;
ValueEval[] values;
values = new ValueEval[] {
new NumberEval(0),
new StringEval(""), // note - does not match blank
BoolEval.TRUE,
BoolEval.FALSE,
ErrorEval.DIV_ZERO,
BlankEval.instance,
};
range = EvalFactory.CreateAreaEval("A1:B3", values);
ConfirmCountBlank(1, range);
values = new ValueEval[] {
new NumberEval(0),
new StringEval(""), // note - does not match blank
BlankEval.instance,
BoolEval.FALSE,
BoolEval.TRUE,
BlankEval.instance,
};
range = EvalFactory.CreateAreaEval("A1:B3", values);
ConfirmCountBlank(2, range);
}
示例9: Evaluate
public override ValueEval Evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0)
{
ValueEval arg = arg0;
if (arg is RefEval)
{
// always use the first sheet
RefEval re = (RefEval)arg;
arg = re.GetInnerValueEval(re.FirstSheetIndex);
}
else if (arg is AreaEval)
{
// when the arg is an area, choose the top left cell
arg = ((AreaEval)arg).GetRelativeValue(0, 0);
}
if (arg is StringEval)
{
// Text values are returned unmodified
return arg;
}
if (arg is ErrorEval)
{
// Error values also returned unmodified
return arg;
}
// for all other argument types the result is empty string
return StringEval.EMPTY_INSTANCE;
}
示例10: EvaluateFunc
/**
*Substitutes text in a text string with new text, some number of times.
*
* @see org.apache.poi.hssf.record.formula.eval.Eval
*/
public override ValueEval EvaluateFunc(ValueEval[] args, int srcCellRow, int srcCellCol)
{
if (args.Length < 3 || args.Length > 4)
{
return ErrorEval.VALUE_INVALID;
}
String oldStr = EvaluateStringArg(args[0], srcCellRow, srcCellCol);
String searchStr = EvaluateStringArg(args[1], srcCellRow, srcCellCol);
String newStr = EvaluateStringArg(args[2], srcCellRow, srcCellCol);
String result;
switch (args.Length)
{
case 4:
int instanceNumber = EvaluateIntArg(args[3], srcCellRow, srcCellCol);
if (instanceNumber < 1)
{
return ErrorEval.VALUE_INVALID;
}
result = ReplaceOneOccurrence(oldStr, searchStr, newStr, instanceNumber);
break;
case 3:
result = ReplaceAllOccurrences(oldStr, searchStr, newStr);
break;
default:
throw new InvalidOperationException("Cannot happen");
}
return new StringEval(result);
}
示例11: TestCriteriaArgRange
public void TestCriteriaArgRange()
{
ValueEval[] arg0values = new ValueEval[] { _50, _60, _50, _50, _50, _30, };
ValueEval[] arg1values = new ValueEval[] { _30, _40, _50, _60, };
AreaEval arg0;
AreaEval arg1;
ValueEval ve;
arg0 = EvalFactory.CreateAreaEval("A3:B5", arg0values);
arg1 = EvalFactory.CreateAreaEval("A2:D2", arg1values); // single row range
ve = invokeSumif(0, 2, arg0, arg1); // invoking from cell C1
if (ve is NumberEval)
{
NumberEval ne = (NumberEval)ve;
if (ne.NumberValue == 30.0)
{
throw new AssertionException("identified error in SUMIF - criteria arg not Evaluated properly");
}
}
ConfirmDouble(200, ve);
arg0 = EvalFactory.CreateAreaEval("C1:D3", arg0values);
arg1 = EvalFactory.CreateAreaEval("B1:B4", arg1values); // single column range
ve = invokeSumif(3, 0, arg0, arg1); // invoking from cell A4
ConfirmDouble(60, ve);
}
示例12: Evaluate
public ValueEval Evaluate(ValueEval[] args, OperationEvaluationContext ec)
{
double result;
if (args.Length != 2)
{
return ErrorEval.VALUE_INVALID;
}
try
{
double startDateAsNumber = GetValue(args[0]);
NumberEval offsetInYearsValue = (NumberEval)args[1];
int offsetInMonthAsNumber = (int)offsetInYearsValue.NumberValue;
// resolve the arguments
DateTime startDate = DateUtil.GetJavaDate(startDateAsNumber);
DateTime resultDate = startDate.AddMonths(offsetInMonthAsNumber);
result = DateUtil.GetExcelDate(resultDate);
NumericFunction.CheckValue(result);
return new NumberEval(result);
}
catch (EvaluationException e)
{
return e.GetErrorEval();
}
}
示例13: Evaluate
public ValueEval Evaluate(ValueEval[] args, int srcRowIndex, int srcColumnIndex)
{
int nInnerArgs = args.Length - 1; // -1: first arg is used to select from a basic aggregate function
if (nInnerArgs < 1)
{
return ErrorEval.VALUE_INVALID;
}
Function innerFunc;
try
{
ValueEval ve = OperandResolver.GetSingleValue(args[0], srcRowIndex, srcColumnIndex);
int functionCode = OperandResolver.CoerceValueToInt(ve);
innerFunc = FindFunction(functionCode);
}
catch (EvaluationException e)
{
return e.GetErrorEval();
}
ValueEval[] innerArgs = new ValueEval[nInnerArgs];
Array.Copy(args, 1, innerArgs, 0, nInnerArgs);
return innerFunc.Evaluate(innerArgs, srcRowIndex, srcColumnIndex);
}
示例14: Evaluate
public ValueEval Evaluate(ValueEval[] args, OperationEvaluationContext ec)
{
DateTime date;
double numberOfMonths, result;
if (args.Length != 2)
{
return ErrorEval.VALUE_INVALID;
}
try
{
// resolve the arguments
date = DateUtil.GetJavaDate(OperandResolver.CoerceValueToDouble(OperandResolver.GetSingleValue(args[0], ec.RowIndex, ec.ColumnIndex)));
numberOfMonths = OperandResolver.CoerceValueToDouble(OperandResolver.GetSingleValue(args[1], ec.RowIndex, ec.ColumnIndex));
// calculate the result date (Excel rounds the second argument always to zero; but we have be careful about negative numbers)
DateTime resultDate = date.AddMonths((int)Math.Floor(Math.Abs(numberOfMonths)) * Math.Sign(numberOfMonths));
result = DateUtil.GetExcelDate(resultDate);
NumericFunction.CheckValue(result);
return new NumberEval(result);
}
catch (EvaluationException e)
{
return e.GetErrorEval();
}
}
示例15: EvaluateFunc
/**
* Replaces part of a text string based on the number of Chars
* you specify, with another text string.
*
* @see org.apache.poi.hssf.record.formula.eval.Eval
*/
public override ValueEval EvaluateFunc(ValueEval[] args, int srcCellRow, int srcCellCol)
{
if (args.Length != 4)
{
return ErrorEval.VALUE_INVALID;
}
String oldStr = EvaluateStringArg(args[0], srcCellRow, srcCellCol);
int startNum = EvaluateIntArg(args[1], srcCellRow, srcCellCol);
int numChars = EvaluateIntArg(args[2], srcCellRow, srcCellCol);
String newStr = EvaluateStringArg(args[3], srcCellRow, srcCellCol);
if (startNum < 1 || numChars < 0)
{
return ErrorEval.VALUE_INVALID;
}
StringBuilder strBuff = new StringBuilder(oldStr);
// remove any characters that should be replaced
if (startNum <= oldStr.Length && numChars != 0)
{
strBuff.Remove(startNum - 1, startNum - 1 + numChars);
}
// now insert (or append) newStr
if (startNum > strBuff.Length)
{
strBuff.Append(newStr);
}
else
{
strBuff.Insert(startNum - 1, newStr);
}
return new StringEval(strBuff.ToString());
}