查看本教程以从 excel 中获取数据,并在 DataTable 中处理,这种方式比 with 更快:
将 xlApp 调暗为 Excel.Application
将 xlWorkBook 调暗为 Excel.Workbook
*...*
或检查我的方式:
将 _con 调暗为 OleDbConnection
Dim _cmd As New OleDbCommand
Dim DtSet As DataSet
Dim _tabExtrato as new DataTable
Dim _adaptCommand As OleDbDataAdapter
Private Sub _readXLS(ByVal TXT 作为文本框,ByVal _linkFILE 作为字符串,ByVal _folha 作为字符串,ByVal DGV 作为 DataGridView)
_con = New OleDbConnection _
("provider=Microsoft.Jet.OLEDB.4.0; Data Source='" & _linkFILE & "'; Extended Properties=Excel 8.0;")
Dim trimTxt As String = "SELECT * FROM "
'_folha = the sheet
Dim _sqlQuery As String = " " & trimTxt & " [" & _folha & "$] "
_adaptCommand = New OleDbDataAdapter(_sqlQuery, _con)
_adaptCommand.TableMappings.Add("Table", "DSTable")
DtSet = New DataSet
'_adaptCommand.Fill(DtSet)
_adaptCommand.Fill(_tabExtrato)
DGV.DataSource = _tabExtrato
_con.Close()
End Sub