
// ==================== START of Function ====================
[ExcelFunction(Description = "Test function...first test for params (varying number of arguments in C#). Adds together all arguments.")]
public static double C_MySum(params double[] values)
{
return values.Sum();
}
// -------------------- END of Function --------------------
// ==================== START of Function ====================
// Description for IntelliSense Tool Tip
[ExcelFunction(Description = "Test function...test to Add together all arguments in range.")]
public static double C_RangeSum(
[ExcelArgument(AllowReference = true)]
double[,] values) // params object[,] values)
{
int rows = values.GetLength(0);
int cols = values.GetLength(1);
double value = 0;
for (int i = 0; i < rows; i++)
{
for(int j = 0; j < cols; j++)
{
value = value + values[i, j];
}
}
return value;
} // -------------------- END of Function --------------------
// ==================== START of Function ====================
// Description for IntelliSense Tool Tip
[ExcelFunction(Description = "Test function...test to Add together all arguments in defined ranges.")]
public static double C_SumRanges
([ExcelArgument(AllowReference = false)] // Don't use "AllowReference = true" for object arguments
object Range1, object Range2, object Range3, object Range4, object Range5
)
{
double dblSum = 0;
// Create List of function arguments and Loop through each
List<object> ArgList = new List<object> {Range1,Range2,Range3,Range4,Range5};
foreach (var i in ArgList)
{
// see "ArgOptional" helper class for more info
double dblArg = ArgOptional.GetDbl(i);
dblSum = dblSum + dblArg;
}
return dblSum;
} // -------------------- END of Function --------------------