i use Microsoft.Office.Interop.Excel
and i have error in my code with it
an object reference is required for the non-static field method or property
public class CalculationsController : Controller
{
public double Irr(double a, double b)
{
Irr irr = new Irr()
{
a = a,
b = b
};
var y = IWorksheetFunction.Irr(irr.a, irr.b); // here error
return y;
}
public class Irr
{
public double a { get; set; }
public double b { get; set; }
}
}
i cant do change in IWorksheetFunction.Irr, beacause its package
CodePudding user response:
The first problem with your code as highlighted by @Fildor in the comments. You can't make calls to an Interface
. You should view Interfaces
as blueprints. You should be calling the WorksheetFunction
class instead since this implements the IWorksheetFunction
Interface
.
The second possible issue is that you haven't included the right library to access the WorksheetFunction
class. You can include it by placing this at the very top of the file.
using Microsoft.Office.Interop.Excel;
If this gives any issue you might need to install the Microsoft.Office.Interop.Excel
nuget package. Here is how you can do that