2
Reply

Unable to cast COM object of type 'Excel.WorksheetClass' to interface type 'Excel._Worksheet'. This ...

Gomathi Palaniswamy

Gomathi Palaniswamy

Dec 12 2011 4:48 AM
6.3k
objExcel = new Excel.Application();                              
            Excel.Worksheet tmpWorksheet = new Excel.Worksheet();
            objExcel.Visible = true;
            objWorkBook = objExcel.Workbooks.Open(strExcelFile, 0, true, 5, "", "", true, Excel.XlPlatform.xlWindows, "\t", false, false, 0, true,false,false);
            string[] strSheetName = new string[objWorkBook.Worksheets.Count-1];
            int i = 0;
            foreach (Excel.Worksheet tmpWorkSheet in objWorkBook.Worksheets)
            {
                strSheetName[i] = tmpWorksheet.Name;//error occurs here
                i += 1;
            }
            objExcel.Quit();


the above coding sholwing the error below error

"Unable to cast COM object of type 'Excel.WorksheetClass' to interface type 'Excel._Worksheet'. This operation failed because the QueryInterface call on the COM component for the interface with IID "

help me pls.

Answers (2)
Next Recommended Forum