Friday, August 2, 2013

to get excel sheet names from an excel file

If you want to list out all the sheet names in an excel file, use the following code

Dim ExcelPath As String = Server.MapPath("~/Data/Test.xlsx")
            ExcelconnString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & ExcelPath & ";Extended Properties=""Excel 12.0;HDR=Yes;IMEX=2"""
            ExcelConn = New OleDbConnection(ExcelconnString)
            If ExcelConn.State = ConnectionState.Closed Then ExcelConn.Open()
            dt = ExcelConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, Nothing)
            For Each row As DataRow In dt.Rows
                SheetName = row("TABLE_NAME").ToString
                Exit For
            Next


No comments:

Post a Comment