Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlsheet As Excel.Worksheet
Dim itmx As ListItem
Private Sub Command1_Click()
Dim i As Integer
Set xlApp = CreateObject("Excel.Application") '创建
xlApp.Visible = True '设置可见,如不可见设为false
Set xlBook = xlApp.Workbooks.Open(App.Path & "\test.xls")
Set xlsheet = xlBook.Worksheets(1)
xlsheet.Activate '激活
ListView1.ColumnHeaders.Clear'清空列头
ListView1.ListItems.Clear’清空内容
For i = 1 To xlsheet.UsedRange.Cells.Columns.Count
ListView1.ColumnHeaders.Add , , xlsheet.Cells(1, i), 1500’添加列头
Next
For i = 2 To xlsheet.UsedRange.Cells.Rows.Count’添加内容
Set itmx = ListView1.ListItems.Add()
itmx.Text = xlsheet.Cells(i, 1)
For j = 2 To xlsheet.UsedRange.Cells.Columns.Count - 1
itmx.SubItems(j - 1) = xlsheet.Cells(i, j)
Next
Next
End Sub
判断文件存在否,打开否,关闭释放等操作自己完善,