473,387 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to get worksheet names from an excel file?

I want to get worksheet names from an Excel file using an
OleDbConnection. I tried using GetOleDbSchemaTable but it returns zero
rows.

How can I best get worksheet names from an Excel file?
*** Sent via Developersdex http://www.developersdex.com ***
Feb 9 '06 #1
4 21510
I think you'd need to be using the Excel Object Model via the Office Primary
InterOp Assemblies and then you can access the worksheets collection and
loop through them asking for each's name.
"Terry Olsen" <to******@hotmail.com> wrote in message
news:u2**************@TK2MSFTNGP09.phx.gbl...
I want to get worksheet names from an Excel file using an
OleDbConnection. I tried using GetOleDbSchemaTable but it returns zero
rows.

How can I best get worksheet names from an Excel file?
*** Sent via Developersdex http://www.developersdex.com ***

Feb 9 '06 #2
Would I have to distribute other files with the application using the
interop (such as excel.exe)? I'm trying to keep this a simple
stand-alone program. The target computers do not have Office installed.

*** Sent via Developersdex http://www.developersdex.com ***
Feb 9 '06 #3
Here's the code i'm using. I got it from a C# example at:
http://weblogs.asp.net/donxml/archiv.../21/24908.aspx

The Excel file i'm reading from has a single worksheet called "orders".

Whenever I run the code below, it returns zero rows in the Schema Table.

I need help! Thanks.

Dim ExcelConnectionStr As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
ExcelFile & ";" & _
"Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"""

Dim ExcelConnection As New _
OleDbConnection(ExcelConnectionStr)
Dim ExcelCommand = New OleDbCommand
ExcelCommand.connection = ExcelConnection
Dim ExcelAdapter As New OleDbDataAdapter(ExcelCommand)
ExcelConnection.Open()
Dim ExcelSheets As DataTable = _
ExcelConnection.GetOleDbSchemaTable
(OleDbSchemaGuid.Tables, _
New Object() {Nothing, Nothing, Nothing, "TABLE"})

MsgBox(ExcelSheets.Rows.Count)

For i As Integer = 0 To ExcelSheets.Rows.Count - 1
MsgBox(ExcelSheets.Rows(i).Item("TABLE_NAME"))
Next

ExcelConnection.Close()

*** Sent via Developersdex http://www.developersdex.com ***
Feb 9 '06 #4
I figured out what the problem may be. The Excel file in question is in
Excel 5.0/95 format.

I changed my connection string to show Excel 5.0 for Extended
Properties, but it still returns nothing in the SchemaTable. I tried
Excel 3.0 as well and still nothing.

I then saved a copy of the file in Excel 2003 format, and now the code
works great, it reads the worksheet name.

However, the file that the user will be using (downloading from a web
site) is in Excel 5.0 format. Is there any way to get this to work?

*** Sent via Developersdex http://www.developersdex.com ***
Feb 9 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: harshan | last post by:
Hi I am trying to read required worksheet from excel file using perl with module spreadsheet::parseexcel and spreadsheet::writeexcel but I am unable to read it, the error I am getting is...
1
by: mail2atulmehta | last post by:
Hi, I do not know if this is right place for this, but i need some help. I have a text file, whose values are seprated by a delimiter. I want to open this file in excel, ( not import it) . I have...
4
by: weboweb | last post by:
Hello group, I hope I've come to the right place to post my question! I am trying to get the worksheet names from an excel file using ODBC, but for some reason I get SQL_NO_DATA error code...
1
by: Davy | last post by:
Hi Can somebody help me to print a specific worksheet of an Excel file thru Visual Basic Thank Davy
1
by: Esmail Bonakarian | last post by:
Greetings all, What is the best way to access specific records in an Excel file? I have an Excel file, I want to randomly and repeatedly (maybe around up to 50 times) draw some rows of data...
7
by: shantanu | last post by:
Hi all i am trying to save a excel file as a tab delimited text file. can i do it some how? i using the code _sheet1.SaveAs(@"C:\PRP \PRPTemp.txt",Excel.XlFileFormat.xlTextWindows...
3
by: sejal17 | last post by:
hello Can any one tell me how to read multiple worksheets from a single excel file.I have stored that excel in xml file.so i want to read that xml that has multiple worksheet.And i want to store...
3
by: sejal17 | last post by:
hello Can any one tell me how to read multiple worksheets from a single excel file.I have stored that excel in xml file.so i want to read that xml that has multiple worksheet.And i want to store...
0
by: Ivan Stefanov | last post by:
Hello, I have the following problem: I created a website project and I want in that website to be make a button, which will export some data in an excel file. This is the code that I have: using...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.