5

I am trying to call excel functions from C#. I can use the following code to get the excel functions:

Application app = new Application();
WorksheetFunction functions = app.WorksheetFunction;
var sum = functions.Sum(1, 2);

I can get the function like SUM from the WorksheetFunction object. But now all the functions are there, like LEFT, RIGHT, DATE etc. Can I find them somewhere else?

Ryan
  • 1,963
  • 3
  • 25
  • 35

1 Answers1

0

Try something like below for example

using Microsoft.Office.Interop.Excel;

static void Main(string[] args)
{

     Application a = new Application();
     double x = a.WorksheetFunction.Sum(1, 2);
     Console.WriteLine("Sum = {0}", x);

}

EDIT

using IExcel = Microsoft.Office.Interop.Excel;

Then declare and initialise a IWorkSheetFunction object

IExcel.IWorksheetFunction iwf = new IExcel.IWorksheetFunction();

Now you can use the functions as in

double result = iwf.NormDist(1,2,3,4);
serge
  • 13,940
  • 35
  • 121
  • 205
tam tam
  • 1,870
  • 2
  • 21
  • 46