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)