How to solve problems with Interop.Excel after uninstalling Office 2007 and installing Office 2003?
In one of our projects, we are using the Excel interop functionality to import data from an Excel sheet into the application (and after that into a database). If you work with Office 2007 and you need to deploy your application for Office 2003 environment, you catch some problems, like:
************** Exception Text **************
System.InvalidCastException: Unable to cast COM object of type 'Microsoft.Office.Interop.Excel.ApplicationClass' to interface type 'Microsoft.Office.Interop.Excel._Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{000208D5-0000-0000-C000-000000000046}' failed due to the following error: could not be found. (Exception from HRESULT: 0x80030002 (STG_E_FILENOTFOUND)).
at Microsoft.Office.Interop.Excel.ApplicationClass.get_Workbooks()
at RunExcel.Form1.btnRunOutsideForm_Click(Object sender, EventArgs e) in D:\FMI\Dev\NetPlay\VS2005\RunExcel2003\RunExcel\Form1.vb:line 22
at System.Windows.Forms.Control.OnClick(EventArgs e)
My colleague worked on a PC with Office 2003 and I am working on a PC with (only) Office 2007. We both using Visual Studio 2005 (SP1) and both of us are working on the same project. To solve this problem we discover the following way through:
During debugging, my colleague got his "Interop.Excel.dll" file (from Excel 2003) in the debug folder.
I took a copy of this dll and place it in the project folder. I removed all Office200x references in the project and add a reference to the "Interop.Excel.dll".
Note: use the following imports-statement in this case: Imports Excel
No comments:
Post a Comment