我正在尝试从excel文件中获取Sheet名称。我正在使用以下代码。但它返回的空数据表。我在VB.NET(框架版本2)工作。请检查我的代码并向我提供这个想法。
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