How to get list of Excel Sheets? 
Author Message
 How to get list of Excel Sheets?

Hi there!

I'm reading Excel 2000-files using Microsoft.Jet.OLEDB.4.0 provider in my
connection string, and it works fine (if sheet named as Sheet1$). Anyway I
need to know sheet-names of the selected Excel-file, and then it makes
possible to select correct sheet of the list to the SQL Select-query, so
please let me know how can I get sheet names? Or is there better way to read
Excel-files into VB.NET 2003 Windows Forms Datagrid?

Thanks in advance!

Mika from Finland



Sun, 04 Dec 2005 03:54:38 GMT  
 How to get list of Excel Sheets?

Hi there!

I'm reading Excel 2000-files using Microsoft.Jet.OLEDB.4.0 provider in my
connection string, and it works fine (if sheet named as Sheet1$). Anyway I
need to know sheet-names of the selected Excel-file, and then it makes
possible to select correct sheet of the list to the SQL Select-query, so
please let me know how can I get sheet names? Or is there better way to read
Excel-files into VB.NET 2003 Windows Forms Datagrid?

The following code should get you started:

    Public Function ListExcelTablesNET() As Boolean

        Dim ExcelConnection As System.Data.OleDb.OleDbConnection
        Dim ExcelTable As DataTable

        Try

            ExcelConnection = New
System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & _
                "Data Source=e:\My Documents\Book10.xls;Extended Properties=Excel 8.0;")

            ExcelConnection.Open()

            ExcelTable =
ExcelConnection.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, New Object() {Nothing,
Nothing, Nothing, "TABLE"})

            frmMain.DataGrid1.DataSource = ExcelTable

        Catch ex As Exception
            MessageBox.Show(ex.Message)
        Finally
            ExcelConnection.Close()

        End Try

    End Function


Microsoft MVP (Visual Basic)



Sun, 04 Dec 2005 21:03:38 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Getting the list of Excel Sheet Names using VBA

2. getting previous cell values in excel sheets

3. Getting the RIGHT Excel sheet with OLE automation - AddOLEObj

4. getting the name of the active sheet (Excel)

5. how getting data from EXCEL.sheets

6. VB 3.0 PRO/EXCEL/DDE Getting info from different sheets

7. Getting excel sheet names with DAO

8. getting sheet name in excel

9. Getting excel sheet names with DAO

10. sending email to a list in an excel sheet

11. Sending Excel Sheet to List

12. VB or Excel VBA, accessing list of all the sheets in a workbook

 

 
Powered by phpBB® Forum Software