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.
Loading

Sam HobbsPosted Dec 12, 2011, 6:32 PM
Excel.Workbook xlWorkBook;
object misValue = System.Reflection.Missing.Value;
xlApp = new Excel.ApplicationClass();
xlWorkBook = xlApp.Workbooks.Open("152714.xls");
string[] strSheetName = new string[xlWorkBook.Worksheets.Count - 1];
int i = 0;
foreach (Excel.Worksheet xlWorkSheet in xlWorkBook.Worksheets)
{
if (xlWorkSheet.UsedRange.Cells.Count > 1)
{
strSheetName[i] = xlWorkSheet.Name;
i += 1;
}
}
xlWorkBook.Close(true, misValue, misValue);
xlApp.Quit();
Console.WriteLine(string.Join(" ", strSheetName));
VulpesPosted Dec 12, 2011, 2:20 PM
Excel.Worksheet tmpWorksheet = new Excel.Worksheet();
and changing the foreach statement to: