J
jworksinc
I have an application that needs to retrieve the name of the first
Worksheet in an Excel Workbook. This works great, unless an older
excel file is used with this routine that did not support multiple
sheets (i.e. Excel 2.1). What is the work around to retrieve the sheet
name?
Here is some code:
private string GetFirstSheetName(sExcelFile)
{
....
oExcel = new Excel.ApplicationClass();
oBooks = oExcel.Workbooks;
oBook =
oBooks.Open(sExcelFile,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing);
oSheets = oBook.Worksheets;
oSheet = (Excel.Worksheet)oSheets[1];
return oSheet.Name;
}
If sExcelFile is a 2.1 Excel file the name of the file gets returned
for some reason.
Thanks
Worksheet in an Excel Workbook. This works great, unless an older
excel file is used with this routine that did not support multiple
sheets (i.e. Excel 2.1). What is the work around to retrieve the sheet
name?
Here is some code:
private string GetFirstSheetName(sExcelFile)
{
....
oExcel = new Excel.ApplicationClass();
oBooks = oExcel.Workbooks;
oBook =
oBooks.Open(sExcelFile,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing);
oSheets = oBook.Worksheets;
oSheet = (Excel.Worksheet)oSheets[1];
return oSheet.Name;
}
If sExcelFile is a 2.1 Excel file the name of the file gets returned
for some reason.
Thanks