Problem in opening an excel file using C#
-
OpenFileDialog ofd = new OpenFileDialog(); ofd.InitialDirectory = @":D\\"; ofd.Filter = "Excel Files(*.xls)|*.xls|" + "All Text Files(*.*)|*.*"; ofd.FilterIndex = 1; if (ofd.ShowDialog() == DialogResult.OK) { excelApp = new Excel.Application(); workBook = excelApp.Workbooks.Open(ofd.FileName, 0, true, 5, "", "", true, Excel.XlPlatform.xlWindows, "\t", false, false, 0, true,1,0); When i run this code i get an error as "Unable to cast COM object of type 'Excel.ApplicationClass' to interface type 'Excel._Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID "" plz any one help me in this Regards Ramya
-
OpenFileDialog ofd = new OpenFileDialog(); ofd.InitialDirectory = @":D\\"; ofd.Filter = "Excel Files(*.xls)|*.xls|" + "All Text Files(*.*)|*.*"; ofd.FilterIndex = 1; if (ofd.ShowDialog() == DialogResult.OK) { excelApp = new Excel.Application(); workBook = excelApp.Workbooks.Open(ofd.FileName, 0, true, 5, "", "", true, Excel.XlPlatform.xlWindows, "\t", false, false, 0, true,1,0); When i run this code i get an error as "Unable to cast COM object of type 'Excel.ApplicationClass' to interface type 'Excel._Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID "" plz any one help me in this Regards Ramya
use Excel.ApplicationClass() instead of Excel.Application() ..