excel求助,单元格内容弄到类似listview控件里。

2024-12-16 01:21:48
推荐回答(1个)
回答1:

以下是VB中的代码,不是Excel表中的。VB中建立Listview1,不需作任何其他设置,代码如下。单击窗体查看效果。
==============
Option Explicit
Dim sht As Object
Private Sub Form_Click()
Dim i As Object
For Each i In sht.[A5:F5]
ListView1.ColumnHeaders.Add Text:=IIf(Len(i.Text), i.Text, i.Offset(-1).Text)
Next
For Each i In sht.[A6:A7] 'A7可以扩充为你的表的最下面一行
ListView1.ListItems.Add Key:="K" & i.Row, Text:=i.Text
Next
For Each i In sht.[B6:F7] '这里的F7也是,扩充为你需要的
ListView1.ListItems("K" & i.Row).SubItems(i.Column - 1) = i.Text
Next
End Sub

Private Sub Form_Load()
ListView1.View = lvwReport
Set sht = CreateObject("Excel.Application").Workbooks.Open("d:\z\1.xls").Worksheets(1) '这里有文件路径
End Sub

Private Sub Form_Unload(Cancel As Integer)
sht.Application.Quit
Set sht = Nothing
End Sub