求教如何用vb读取excel文件内容
我想用vb读取一个excel文件(D:\a.xlsx),获取f1,f2,f3...一直到f50的内容,并显示在窗体的textbox控件内,应该如何实现呢[此贴子已经被作者于2016-12-5 11:02编辑过]
Dim xlApp As Excel.Application '定义EXCEL类 Dim xlBook As Excel.Workbook '定义工件簿类 Dim xlsheet As Excel.Worksheet '定义工作表类 Set xlApp = CreateObject("Excel.Application") '创建EXCEL应用类 Set xlBook = xlApp.Workbooks.Open("D:\a.xlsx") '打开EXCEL工作簿 Set xlsheet = xlBook.Worksheets(1) '打开EXCEL工作表 xlsheet.Activate '激活工作表 dim a as double a= xlsheet.range("A1").Value '或者 xlsheet.Cells(1, 1).Value
Private Sub Form_Load() Dim cn As New ADODB.Connection, RS As New ADODB.Recordset, XX As Integer List1.Clear List1.AddItem "行号" & Space(5) & "F列内容" cn.Open "provider=Microsoft.ACE.OLEDB.12.0;extended properties=excel 12.0;data source=" & App.Path & "\A.xlsx" RS.Open "Select * FROM [Sheet1$]", cn, 3, 2 Do While Not RS.EOF And XX < 50 XX = XX + 1 List1.AddItem XX & Space(8) & RS.Fields(5) RS.MoveNext Loop RS.Close cn.Close End Sub