本文整理汇总了C#中AreaEval类的典型用法代码示例。如果您正苦于以下问题:C# AreaEval类的具体用法?C# AreaEval怎么用?C# AreaEval使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AreaEval类属于命名空间,在下文中一共展示了AreaEval类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Evaluate
public ValueEval Evaluate(ValueEval[] args, OperationEvaluationContext ec)
{
if (args.Length < 3 || args.Length % 2 == 0)
{
return ErrorEval.VALUE_INVALID;
}
try
{
AreaEval sumRange = ConvertRangeArg(args[0]);
// collect pairs of ranges and criteria
AreaEval[] ae = new AreaEval[(args.Length - 1) / 2];
I_MatchPredicate[] mp = new I_MatchPredicate[ae.Length];
for (int i = 1, k = 0; i < args.Length; i += 2, k++)
{
ae[k] = ConvertRangeArg(args[i]);
mp[k] = Countif.CreateCriteriaPredicate(args[i + 1], ec.RowIndex, ec.ColumnIndex);
}
ValidateCriteriaRanges(ae, sumRange);
double result = SumMatchingCells(ae, mp, sumRange);
return new NumberEval(result);
}
catch (EvaluationException e)
{
return e.GetErrorEval();
}
}
示例2: ResolveRange
/**
* @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);
}
示例3: CreateResultColumnVector
/**
* Returns one column from an <tt>AreaEval</tt>
*
* @(#VALUE!) if colIndex Is negative, (#REF!) if colIndex Is too high
*/
private ValueVector CreateResultColumnVector(AreaEval tableArray, int rowIndex)
{
if (rowIndex >= tableArray.Height)
{
throw EvaluationException.InvalidRef();
}
return LookupUtils.CreateRowVector(tableArray, rowIndex);
}
示例4: CreateVector
private static ValueVector CreateVector(AreaEval ae)
{
ValueVector result = LookupUtils.CreateVector(ae);
if (result != null)
{
return result;
}
// extra complexity required to emulate the way LOOKUP can handles these abnormal cases.
throw new InvalidOperationException("non-vector lookup or result areas not supported yet");
}
示例5: Eval
private static ValueEval Eval(int srcRowIndex, int srcColumnIndex, ValueEval arg1, AreaEval aeRange,
AreaEval aeSum)
{
// TODO - junit to prove last arg must be srcColumnIndex and not srcRowIndex
I_MatchPredicate mp = Countif.CreateCriteriaPredicate(arg1, srcRowIndex, srcColumnIndex);
double result = SumMatchingCells(aeRange, mp, aeSum);
return new NumberEval(result);
}
示例6: ValidateCriteriaRanges
/**
* Verify that each <code>criteriaRanges</code> argument contains the same number of rows and columns
* as the <code>sumRange</code> argument
*
* @throws EvaluationException if
*/
private void ValidateCriteriaRanges(AreaEval[] criteriaRanges, AreaEval sumRange)
{
foreach (AreaEval r in criteriaRanges)
{
if (r.Height != sumRange.Height ||
r.Width != sumRange.Width)
{
throw EvaluationException.InvalidValue();
}
}
}
示例7: ColumnVector
public ColumnVector(AreaEval tableArray, int columnIndex)
{
_columnIndex = columnIndex;
int _columnAbsoluteIndex = tableArray.FirstColumn + columnIndex;
if (!tableArray.ContainsColumn((short)_columnAbsoluteIndex))
{
int lastColIx = tableArray.LastColumn - tableArray.FirstColumn;
throw new ArgumentException("Specified column index (" + columnIndex
+ ") is outside the allowed range (0.." + lastColIx + ")");
}
_tableArray = tableArray;
_size = _tableArray.Height;
}
示例8: RowVector
public RowVector(AreaEval tableArray, int rowIndex)
{
_rowIndex = rowIndex;
int _rowAbsoluteIndex = tableArray.FirstRow + rowIndex;
if (!tableArray.ContainsRow(_rowAbsoluteIndex))
{
int lastRowIx = tableArray.LastRow - tableArray.FirstRow;
throw new ArgumentException("Specified row index (" + rowIndex
+ ") is outside the allowed range (0.." + lastRowIx + ")");
}
_tableArray = tableArray;
_size = tableArray.Width;
}
示例9: SumMatchingCells
private static double SumMatchingCells(AreaEval aeRange, I_MatchPredicate mp, AreaEval aeSum)
{
int height = aeRange.Height;
int width = aeRange.Width;
double result = 0.0;
for (int r = 0; r < height; r++)
{
for (int c = 0; c < width; c++)
{
result += Accumulate(aeRange, mp, aeSum, r, c);
}
}
return result;
}
示例10: ChooseSingleElementFromArea
/**
* Implements (some perhaps not well known) Excel functionality to select a single cell from an
* area depending on the coordinates of the calling cell. Here is an example demonstrating
* both selection from a single row area and a single column area in the same formula.
*
* <table border="1" cellpAdding="1" cellspacing="1" summary="sample spReadsheet">
* <tr><th> </th><th> A </th><th> B </th><th> C </th><th> D </th></tr>
* <tr><th>1</th><td>15</td><td>20</td><td>25</td><td> </td></tr>
* <tr><th>2</th><td> </td><td> </td><td> </td><td>200</td></tr>
* <tr><th>3</th><td> </td><td> </td><td> </td><td>300</td></tr>
* <tr><th>3</th><td> </td><td> </td><td> </td><td>400</td></tr>
* </table>
*
* If the formula "=1000+A1:B1+D2:D3" is put into the 9 cells from A2 to C4, the spReadsheet
* will look like this:
*
* <table border="1" cellpAdding="1" cellspacing="1" summary="sample spReadsheet">
* <tr><th> </th><th> A </th><th> B </th><th> C </th><th> D </th></tr>
* <tr><th>1</th><td>15</td><td>20</td><td>25</td><td> </td></tr>
* <tr><th>2</th><td>1215</td><td>1220</td><td>#VALUE!</td><td>200</td></tr>
* <tr><th>3</th><td>1315</td><td>1320</td><td>#VALUE!</td><td>300</td></tr>
* <tr><th>4</th><td>#VALUE!</td><td>#VALUE!</td><td>#VALUE!</td><td>400</td></tr>
* </table>
*
* Note that the row area (A1:B1) does not include column C and the column area (D2:D3) does
* not include row 4, so the values in C1(=25) and D4(=400) are not accessible to the formula
* as written, but in the 4 cells A2:B3, the row and column selection works ok.<p/>
*
* The same concept is extended to references across sheets, such that even multi-row,
* multi-column areas can be useful.<p/>
*
* Of course with carefully (or carelessly) chosen parameters, cyclic references can occur and
* hence this method <b>can</b> throw a 'circular reference' EvaluationException. Note that
* this method does not attempt to detect cycles. Every cell in the specified Area <tt>ae</tt>
* has already been Evaluated prior to this method call. Any cell (or cell<b>s</b>) part of
* <tt>ae</tt> that would incur a cyclic reference error if selected by this method, will
* already have the value <t>ErrorEval.CIRCULAR_REF_ERROR</tt> upon entry to this method. It
* is assumed logic exists elsewhere to produce this behaviour.
*
* @return whatever the selected cell's Evaluated value Is. Never <c>null</c>. Never
* <tt>ErrorEval</tt>.
* @if there is a problem with indexing into the area, or if the
* Evaluated cell has an error.
*/
public static ValueEval ChooseSingleElementFromArea(AreaEval ae,
int srcCellRow, int srcCellCol)
{
ValueEval result = ChooseSingleElementFromAreaInternal(ae, srcCellRow, srcCellCol);
if (result == null)
{
// This seems to be required because AreaEval.Values array may contain nulls.
// perhaps that should not be allowed.
result = BlankEval.instance;
}
if (result is ErrorEval)
{
throw new EvaluationException((ErrorEval)result);
}
return result;
}
示例11: AreasAllSameSize
private static bool AreasAllSameSize(AreaEval[] args, int height, int width)
{
for (int i = 0; i < args.Length; i++)
{
AreaEval areaEval = args[i];
// check that height and width match
if (areaEval.Height != height)
{
return false;
}
if (areaEval.Width != width)
{
return false;
}
}
return true;
}
示例12: CountMatchingCellsInArea
/**
* @return the number of evaluated cells in the range that match the specified criteria
*/
public static int CountMatchingCellsInArea(AreaEval areaEval, I_MatchPredicate criteriaPredicate)
{
int result = 0;
int height = areaEval.Height;
int width = areaEval.Width;
for (int rrIx = 0; rrIx < height; rrIx++)
{
for (int rcIx = 0; rcIx < width; rcIx++)
{
ValueEval ve = areaEval.GetRelativeValue(rrIx, rcIx);
if (criteriaPredicate.Matches(ve))
{
result++;
}
}
}
return result;
}
示例13: eval
private static ValueEval eval(int srcRowIndex, int srcColumnIndex, double arg0, AreaEval aeRange, bool descending_order)
{
int rank = 1;
int height = aeRange.Height;
int width = aeRange.Width;
for (int r = 0; r < height; r++)
{
for (int c = 0; c < width; c++)
{
Double value = GetValue(aeRange, r, c);
if (Double.IsNaN(value)) continue;
if (descending_order && value > arg0 || !descending_order && value < arg0)
{
rank++;
}
}
}
return new NumberEval(rank);
}
示例14: BaseRef
public BaseRef(AreaEval ae)
{
_refEval = null;
_areaEval = ae;
_firstRowIndex = ae.FirstRow;
_firstColumnIndex = ae.FirstColumn;
_height = ae.LastRow - ae.FirstRow + 1;
_width = ae.LastColumn - ae.FirstColumn + 1;
}
示例15: AreaValueArray
public AreaValueArray(AreaEval ae)
: base(ae.Width * ae.Height)
{
_ae = ae;
_width = ae.Width;
}