Everywhere I look for how to use excel function inside of a C# application tells me to do the following:
The problem im having is that while intellisense is detecting IExcel, it is not showing IWorksheetFunction. It is however showing WorksheetFunction. Either way, it is not letting me instantiate it as an object. I am getting the error: Cannot create an instance of the abstract class or interface 'Microsoft.Office.Interop.Excel.WorksheetFunction'
any ideas?
Try:
Microsoft.Office.Interop.Excel.Application xl = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.WorksheetFunction wsf = xl.WorksheetFunction;
int result = wsf.Percentile(obj, 0.75);
Basically it comes down to, instead of:
IExcel.IWorksheetFunction iwf =
new IExcel.IWorksheetFunction(); // You can't instantiate an interface
use the WorksheetFunction property in Excel.Application:
IExcel.IWorksheetFunction iwf = xl.WorksheetFunction;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With