上传者: kaifen2006
|
上传时间: 2021-12-27 21:40:28
|
文件大小: 4KB
|
文件类型: -
VB读取EXCEL源码Private Sub Command1_Click()
Dim i As Integer, j As Integer
Set xlApp = CreateObject("Excel.Application") '创建EXCEL应用类
xlApp.Visible = False '设置EXCEL不可见
Set xlBook = xlApp.Workbooks.Open(App.Path & "\data.xls") '打开EXCEL工作簿
Set xlsheet = xlBook.Worksheets(1) '打开EXCEL工作表
'xlsheet.Activate '激活工作表
Dim litem
For i = 2 To 7 '行/记录条数
Set litem = ListView1.ListItems.Add()
litem.Text = xlsheet.Cells(i, 1)
litem.SubItems(1) = xlsheet.Cells(i, 2)
litem.SubItems(2) = xlsheet.Cells(i, 3)
litem.SubItems(3) = xlsheet.Cells(i, 4)
'MsgBox xlsheet.Cells(i, j)
Next
xlBook.Close (True) '关闭EXCEL工作簿
xlApp.Quit '关闭EXCEL
Set xlApp = Nothing '释放EXCEL对象
End Sub