Hi,
Does anyone know how to call the Excel functions from C#?
I found this link that helped a little:
http://www.experts-exchange.com/Programming/Languages/.NET/Visual_CSharp/Q_23258035.html
However, this approach doesn't expose all of the Excel functions. In
particular, I am looking for the YEARFRAC(start_date,end_date,basis)
function.
Below is the sample C# code for calling the worksheet function
Days360:
using System;
using System.Collections.Generic;
using System.Text;
using ExcelDna.Integration;
using IExcel = Microsoft.Office.Interop.Excel;
namespace NYUAddin
{
public class Test : XllAddin
{
/// <summary>
/// Dummy function for testing
/// </summary>
[ExcelFunction(Description = "Days360"
, Category = "Marvelous functions")]
public static double aDays360()
{
IExcel.Application myxl = (IExcel.Application)
ExcelDna.Integration.Excel.Application;
IExcel.WorksheetFunction wsf = myxl.WorksheetFunction;
double result = wsf.Days360(39092, 39823, true); //
should be 720
return result;
}
}
}
thanks,
-shamus