vb读取excel数据的教程
在Excle中录入好数据以后,可能会需要用VB进行读取Excle数据,具体该如何读取数据呢?下面是读文网小编带来的关于vb读取excel数据的教程,希望阅读过后对你有所启发!
vb读取excel数据的教程:
Private Sub Form_Load()
Text1.Text = App.Path & "123.xls"
Text2.Text = App.Path & "123.mdb"
Text3.Text = "sheet1"
Text4.Text = "sheet1"
Data1.DatabaseName = App.Path & "123.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控件.