3
Answers

Getting a error when Opening excel sheet on C#

diya

diya

14y
9.8k
1
Hi.....

I am using MS office 2003 and Visual studio 2008 .I have added a reference to Microsoft.Office.Interop.Excel 11.0 library .

Added the following code:

private void button1_Click(object sender, EventArgs e)
{
object format = 5;//Nothing value.

ApplicationClass xlApp = new ApplicationClass();
Workbook xlBook = xlApp.Workbooks.Open("D:\\WORKS\\App\\bin\\Debug", 0, false, format, null, null, false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, null, true, false, 0, true, false, false);
Sheets xlSheets = xlBook.Worksheets;
Worksheet xlSheet = (Worksheet)xlSheets.get_Item("Sheet1"); // open Sheet1.
xlApp.Visible = true;
}



Getting the error:

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: Error loading type library/DLL. (Exception from HRESULT: 0x80029C4A (TYPE_E_CANTLOADLIBRARY)).



Plz.. help me to solve this error

Answers (3)