VB6.0读取excel数据存储到access中,在线等!~~~~
发布网友
发布时间:2022-04-22 05:45
我来回答
共1个回答
热心网友
时间:2023-11-01 10:26
Dim excel_app As New Excel.Application
Dim excel_sheet As Excel.Worksheet
dim obcnn As New ADODB.Connection
Dim newfield(1 to 10) As String
Dim row As Integer
Dim list As Integer
Dim fso As New FileSystemObject
Dim i As Integer
Dim j As Integer
obcnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:data Source=" c:\my.mdb"
obcnn.Open
If CommonDialog1.FileName = "" Then Exit Sub
excel_app.Workbooks.Open FileName:=CommonDialog1.FileName
'判断EXCEL文档是的版本是否在8以上,是否是单表版本
If Val(excel_app.Application.Version) >= 8 Then
Set excel_sheet = excel_app.ActiveSheet
Else
Set excel_sheet = excel_app
End If
'将EXCEL记录头导入ACESS数据库
row = 6'从第6行开始读
list = 1
i = 0
do while trim$(excel_sheet.Cells(row, list))<>"" '当记录为空时退出
Do While list <= 10'excel表数据有10列
newfield(list) = Trim$(excel_sheet.Cells(row, list))
list=list+1
loop
obcnn.Execute "insert into mymdb values('" & newfield(1) &"','" & newfield(2) &"',…………'" & newfield(10) &"')
row=row+1
loop