Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Excel 2.1 - .NET Automation

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,T ype.Missing,Type.Missing,Type.Missing,Type.Missing ,Type.Missing,Type.Missing,Type.Missing,Type.Missi ng,Type.Missing,Type.Missing,Type.Missing,Type.Mis sing);
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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default Excel 2.1 - .NET Automation

If sExcelFile is a 2.1 Excel file the name of the file gets returned for
some reason.


The reason is that prior to Excel 5 worksheets did not have names beyond
their file names.

--
Jim
wrote in message
oups.com...
|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,T ype.Missing,Type.Missing,Type.Missing,Type.Missing ,Type.Missing,Type.Missing,Type.Missing,Type.Missi ng,Type.Missing,Type.Missing,Type.Missing,Type.Mis sing);
| 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
|


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Excel 2.1 - .NET Automation

Any idea on how I could access a sheet in Excel 2.1 using OLEDB?

Most queries look like this with more recent version of excel:

SELECT * FROM [Sheet Name$]

What happens when there are no sheets as in the case of older excel
versions?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default Excel 2.1 - .NET Automation

Sorry, out of my depth here. Maybe the file name would work? (Q - Would a
DB driver that works with XL97+ files work with older Excel file formats?)

--
Jim
wrote in message
oups.com...
| Any idea on how I could access a sheet in Excel 2.1 using OLEDB?
|
| Most queries look like this with more recent version of excel:
|
| SELECT * FROM [Sheet Name$]
|
| What happens when there are no sheets as in the case of older excel
| versions?
|


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 2.1 - .NET Automation [email protected] Excel Programming 0 March 13th 06 06:50 PM
Excel automation Michelle Excel Programming 9 February 18th 04 03:29 PM
Ole automation with Excel 10 from Vb.net Richie Weldon \(MSFT\) Excel Programming 0 November 13th 03 06:08 PM
Excel Com Automation Tom Ogilvy Excel Programming 5 November 10th 03 02:05 PM


All times are GMT +1. The time now is 10:48 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"