怎样在vb中导入excel表格数据 如何将excel数据引入vb二维数组中

经验直达:

  • 如何将excel数据引入vb二维数组中
  • 怎样在vb中导入excel表格数据

一、如何将excel数据引入vb二维数组中


用数据库的查询方式
读取出来放入到 二维数组中
Dimcnn2 As New ADODB.Connection
Dim rs2 As New ADODB.Recordset
cnn2.Open "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & Text1.Text & ";Extended Properties='Excel 8.0;HDR=Yes'"
rs2.Open "Select 姓名,性别 From [sheet1$]", cnn2, adOpenKeyset, adLockOptimistic
i=0
s = rs2.ields.Item(0).Value'读取sheet1中的 姓名,性别
If IsNull(s) Then Exit Do
a(i)=rs2.fields.Item(0).Value'姓名
b(i)=rs2.Fields.Item(1).Value'性别
i=i 1
rs2.MoveNext
Loop
Set rs2 = Nothing
Set cnn2 = Nothing


二、怎样在vb中导入excel表格数据


【怎样在vb中导入excel表格数据 如何将excel数据引入vb二维数组中】可以看vb自带的例子visdata,其中对txt文件和对excel文件的操作都有很详细的说明 。
也可能通过以下方式:
引用micsosoft Excel x.0 object Library
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlsheet As Excel.Worksheet
FileCopy App.Path"rpf.xlt", App.Path"tmp.xlt"
FileName = App.Path"tmp.xls"
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open(FileName)
xlApp.Visible = True
Set xlsheet = xlBook.Sheets("sheet1")
with xlsheet
.Cells(1, 1) =变量
end with

相关经验推荐