I am trying to open an excel file (.xlsx) using C# (VS2010 professional) code. I am getting an (untraceable, to me) exception when executing/single stepping the last 2 lines of the below code. Below mentioned is my code for opening an existing excel file.
string tesfile = "C:\\Users\\AWaheed3\\Desktop\\1.xlsx";
Microsoft.Office.Interop.Excel.Application xlApp;
Microsoft.Office.Interop.Excel.Workbook xlWorkBook;
object misValue = System.Reflection.Missing.Value;
xlApp = new Microsoft.Office.Interop.Excel.Application();
xlApp.Visible = true;
xlWorkBook = xlApp.Workbooks.Open(tesfile, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue);
Also I have included this below line at the start of the code. Further more I have Added the reference of the Microsoft.Office.Interop.Excel from Project->Add Reference (.NET Tab)
using Microsoft.Office.Interop.Excel;
Can anybody advise why my code is failing/throwing an error?
Regards Asad
EDITED***************************
Here is the message/error I am receiving. Note that the code is failing even while executing the xlApp.Visible = ture line. 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)).