vb讀取excel數據的教程
在Excle中錄入好數據以后,可能會需要用VB進行讀取Excle數據,具體該如何讀取數據呢?下面是學習啦小編帶來的關于vb讀取excel數據的教程,希望閱讀過后對你有所啟發(fā)!
vb讀取excel數據的教程:
Private Sub Form_Load()
Text1.Text = App.Path & "3.xls"
Text2.Text = App.Path & "3.mdb"
Text3.Text = "sheet1"
Text4.Text = "sheet1"
Data1.DatabaseName = App.Path & "3.mdb"
End Sub
Private Sub Command1_Click()
Dim db As Database
Dim sheet As String, excelpath As String, AccessPath As String, AccessTable As String
AccessPath = Text2.Text '數據庫路徑
excelpath = Text1.Text '電子表格路經
AccessTable = Text4.Text '數據庫內表格
sheet = Text3.Text '電子表格內工作表
Set db = OpenDatabase(excelpath, True, False, "Excel 5.0") '打開電子表格文件
SQL = ("Select * into [;database=" & AccessPath & "]." & AccessTable & " FROM [" & sheet & "$]")
db.Execute (SQL) '將電子表格導入數據庫
Data1.RecordSource = "sheet1"
Data1.Refresh
DBGrid1.Refresh '顯示電子表格導入到數據庫的數據
End Sub
上面的是把EXCEL讀取到數據庫中,你做點修改就行了.一個Data控件.
看了vb讀取excel數據的教程還看了: