我正在尝试阅读名为Book1.xls的电子表格文件,其中包含名为Sheet1的工作表
但是我收到以下错误:
The Microsoft Jet database engine could not find the object ‘Sheet1$’.
Make sure the object exists and that you spell its name and the path
name correctly.
这是我正在使用的代码片段:
Dim dt As DataTable = New DataTable() Select Case fileExt Case ".csv" Dim reader As New CsvReader dt = reader.GetDataTable(filePath) Case ".xls",".xlsx" Dim oleDbConnStr As String Select Case fileExt Case ".xls" oleDbConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & filePath & ";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=2""" Case ".xlsx" oleDbConnStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & filePath & ";Extended Properties=""Excel 12.0;HDR=Yes;IMEX=2""" End Select Using oleDbConn As OleDbConnection = New OleDbConnection(oleDbConnStr) oleDbConn.Open() Dim oleDbCmd As New OleDbCommand("SELECT * FROM [Sheet1$]",oleDbConn) Dim oleDbDa As New OleDbDataAdapter(oleDbCmd) oleDbDa.Fill(dt) oleDbConn.Close() End Using End Select