VB6.0读取excel数据存储到access中,在线等!~~~~ 10
要求,使用CommonDialog来选择excel文件,这样就可以使读入的excel的位置和名字可以随意了,然后读取的时候从指定的行开始导入数据,比如选择excel文件后...
要求,使用CommonDialog来选择excel文件,这样就可以使读入的excel的位置和名字可以随意了,然后读取的时候从指定的行开始导入数据,比如选择excel文件后,点击按钮,然后从excel的第6行开始读取数据并且将数据存储到access中,access中已经建立好了一张空表,结构和读取excel的结构相同,即字段个数相同,我要代码。详细的,别从百度,Google上找,我都找一天了,可以和我交流的把答案发上来,我在线等!~~~~
展开
1个回答
展开全部
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
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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询