i have chosen some rows and cols in excel .
How can i pass them as parameter to a C# excel-dna function jusk like 'Sum(A1:C5)'?
Asked
Active
Viewed 1,043 times
-1

Leonard Zhou
- 447
- 1
- 4
- 9
2 Answers
1
Here is a sample code which can process parameter that was passed as a single cell or an array
public static object MyUDF(object param)
{
if(param is Array){
if (((Array)param).Rank == 2){
int columnCount = ((Array)param).GetLength(1);
int rowCount = ((Array)param).GetLength(0);
for (int i = 0; i < rowCount; i++)
{
for (int j = 0; j < columnCount; j++)
{
string cellValue = ((Array)param).GetValue(i, j).ToString();
}
}
}
}else{
string cellValue=param.ToString();
}
return "done";
}

EAA
- 45
- 5
0
[ExcelFunction(Description = "get param type")]
public static string getCSType(object o) {
return o.GetType().ToString();
}
i use this method to get the type of excel paramaters and found that cells chosen
are passed as Object[,].if only one single cell is passed, then it'll be passed as string type.
In c# excel-dna you can use an object to receive a paramater of any type passed by excel.

Leonard Zhou
- 447
- 1
- 4
- 9