This project has moved. For the latest updates, please go here.

Excel C# UDF Range Parameter

Jul 27, 2012 at 4:29 PM

I'm trying to create a UDF in C# that will pull in a range of cells and do something with the contents of those cells.  I cannot seem to get the correct fype for the formula parameter though.  I have other formulas that are successfully pulling in string parameters but I need to support a range of cell references too.  Examples:


public string myFormula1(string myParameter)


return myParameter;



public string myFormula(NetOffice.ExcelApi.Range myRange)       


var rowCount = myRange.Rows.Count;          

return rowCount.ToString();       



What is the correct type for the range of cells argument?

Jul 27, 2012 at 9:23 PM
Edited Jul 27, 2012 at 9:27 PM

just have a look:
you can see:

public double CalculateArea(object Range)
  Excel.Range r = Range as Excel.Range;
  return Convert.ToDouble(r.Width) * Convert.ToDouble(r.Height);

in NetOffice you have to use:

double CalculateArea(object Range)
  Excel.Range r = new Excel.Range(null, Range);
  int result = Convert.ToDouble(r.Width) * Convert.ToDouble(r.Height);
   return result;