Excel 2000 open using C# error - Unable to cast COM object of type

G

george

Hi,

I am using Excel 2000 with C# in VS 2008. I added the excel 9.0 reference
from COM tab under Reference. I am using VS 2008 and win forms.



The code snippet is given below :



Excel.Application appExcel = new Excel.Application();

appExcel.DisplayAlerts = false;


Excel.Workbook wbkExcel = appExcel.Workbooks.Open("C:\\emp.xls",
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing); //<--Error here

Excel.Worksheet wksExcel = (Excel.Worksheet)wbkExcel.Sheets[0];

wksExcel.Activate();



wbkExcel.Close(false, Type.Missing, Type.Missing);

appExcel.Quit();



System.Runtime.InteropServices.Marshal.ReleaseComObject(wksExcel);

System.Runtime.InteropServices.Marshal.ReleaseComObject(wbkExcel);

System.Runtime.InteropServices.Marshal.ReleaseComObject(appExcel);

wksExcel = null;

wbkExcel = null;

appExcel = null;

GC.Collect();



The error is :

"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:
Library not registered. (Exception from HRESULT: 0x8002801D
(TYPE_E_LIBNOTREGISTERED))."



Any help is appreciated.



Thanks.
george
 
R

Rashmi Pandey

I am getting the same error in my application. Have you come across any work around for this error? Please suggest...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top