2

I am trying to get Sheet name from excel file. i am using Using following Code. But its returning Empty Datatable. I am working in VB.NET (Framework version 2) . Please check my code and provide me the idea.

Private Sub GetExcelSheetNames(ByVal fileName As String)
    Dim strconn As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & 
          fileName & ";Extended Properties=""Excel 12.0 Xml;HDR=YES"";"
    Dim conn As New OleDbConnection(strconn)

    conn.Open()

    Dim dtSheets As DataTable = 
              conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, Nothing)
    Dim drSheet As DataRow

    For Each drSheet In dtSheets.Rows
       Console.WriteLine(drSheet("TABLE_NAME").ToString())
    Next


    conn.Close()

End Sub
Monirul Islam
  • 985
  • 1
  • 8
  • 23

0 Answers0