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
Amit ChoudharyPosted Mar 10, 2010, 2:30 AM
you can add the microsoft interop dll by downloading it from microsoft website no need to install the MS-Office
add the downloaded dll to your bin folder and be free from worry..
Download links are here:
1. For office 2003
2. For office 2007
Don't forget to mark as answer.
diyaPosted Mar 10, 2010, 12:01 AM
Thank u
yes it is file name here:
Amit ChoudharyPosted Mar 9, 2010, 5:09 AM
i have doubt on the following line:
Here it should be the file name. Not the directory name.... if error still persists then tell me..
Else if solved then mark as answer.