473,386 Members | 1,973 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,386 software developers and data experts.

Q: Names of worksheets in Excel

Hi

Can anybody tell me how to get the names of the worksheets in an Excel file
without creating an Excel object i.e. Excel itself may not be on the machine
using the application which looks at the Excel files.

Thanks in advance

Geoff
Nov 20 '05 #1
2 1237
On Thu, 17 Jun 2004 15:33:39 +0100, "Geoff Jones" <ge***@NODAMNSPAM.com> wrote:

¤ Hi
¤
¤ Can anybody tell me how to get the names of the worksheets in an Excel file
¤ without creating an Excel object i.e. Excel itself may not be on the machine
¤ using the application which looks at the Excel files.
¤

You can use GetOleDbSchemaTable to retrieve the Excel Worksheet names:

Dim DatabaseConnection As New System.Data.OleDb.OleDbConnection
Dim SchemaTable As DataTable

DatabaseConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=e:\My Documents\Book10.xls;Extended Properties=Excel 8.0;"

DatabaseConnection.Open()

SchemaTable =
DatabaseConnection.GetOleDbSchemaTable(System.Data .OleDb.OleDbSchemaGuid.Tables, _
New Object() {Nothing, Nothing, Nothing, Nothing})

Dim RowCount As Int32

For RowCount = 0 To SchemaTable.Rows.Count - 1
Console.WriteLine(SchemaTable.Rows(RowCount)!TABLE _NAME.ToString)
Next RowCount

DataGrid1.DataSource = SchemaTable

DatabaseConnection.Close()
Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)
Nov 20 '05 #2

"Paul Clement" <Us***********************@swspectrum.com> wrote in message
news:8m********************************@4ax.com...
On Thu, 17 Jun 2004 15:33:39 +0100, "Geoff Jones" <ge***@NODAMNSPAM.com> wrote:
¤ Hi
¤
¤ Can anybody tell me how to get the names of the worksheets in an Excel file ¤ without creating an Excel object i.e. Excel itself may not be on the machine ¤ using the application which looks at the Excel files.
¤

You can use GetOleDbSchemaTable to retrieve the Excel Worksheet names:

Dim DatabaseConnection As New System.Data.OleDb.OleDbConnection
Dim SchemaTable As DataTable

DatabaseConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=e:\My Documents\Book10.xls;Extended Properties=Excel 8.0;"
DatabaseConnection.Open()

SchemaTable =
DatabaseConnection.GetOleDbSchemaTable(System.Data .OleDb.OleDbSchemaGuid.Tab
les, _ New Object() {Nothing, Nothing, Nothing, Nothing})

Dim RowCount As Int32

For RowCount = 0 To SchemaTable.Rows.Count - 1
Console.WriteLine(SchemaTable.Rows(RowCount)!TABLE _NAME.ToString) Next RowCount

DataGrid1.DataSource = SchemaTable

DatabaseConnection.Close()
Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)


Many thanks Paul

Goeff
Nov 20 '05 #3

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

Similar topics

0
by: Query Unknown Excel Worksheet Names | last post by:
I have been trying to write a dynamic application that would allow a user to import data from any Excel spreadsheet and populate that data into a Datagrid in .net. I am successful when i hardcode...
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...
0
by: dleh | last post by:
I have been tasked with producing a server application that will convert excel files to html. I have no experience of developing under Windows, (but plenty of UNIX/C++ experience) but I picked...
4
by: Terry Olsen | last post by:
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? ...
4
by: paul.chae | last post by:
I have a table in Access with about 3000 records. There are ~60 unique values in the ID field for the 3000 records. What I would like to do is automatically generate multiple Excel worksheets...
4
by: e.h.doxtator | last post by:
All I'm a Python newbie, and I'm just getting to the wonders of COM programming. I am trying to programmatically do the following: 1. Activate Excel 2. Add a Workbook 3. Add a Worksheet...
3
by: mike11d11 | last post by:
I was able to create three worksheets in my workbook, but when I go to add the 4th I get an Invalid Index error. I must be leaving something out to when adding 4 or more sheets. Thanks Dim...
0
by: pdettorre | last post by:
Info: original Env: VS2005 with Office 2003 using Microsoft.Office.Interop.Excel (11.0) Have upgraded to VS2008 with office 2007 still using library Microsoft.Office.Interop.Excel (11.0) Ok,...
1
by: MarkDotNet | last post by:
Hi I am trying to switch Excel worksheets in VBA. I get an error saying "subscript out of range". Please Help- Here is code (Fails on last 2 lines- Note that I ommited the recordset portion of...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.