I'm trying to open a WorkBook in a C# application. When I call the Open method it returns a System__COMObject
instead of a Workbook. Here's my code:
Microsoft.Office.Interop.Excel._Application excelApp = new Application();
Microsoft.Office.Interop.Excel._Workbook wb = new WorkBook();
wb = excelApp.Workbooks.Open(filepath, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
The error is an System.InvalidCastException
. Any ideas what I'm doing wrong?
EDIT: I don't now install any COM packages or adjust any settings. Do I need any COM components to work with Interop?