给段代码你自己改吧Public Sub ListV2Html(HtmlFile As String, ll As ListView) '将LISTVIEW内容输出到HTML Dim f% Dim i% Dim j As Long Dim fa As String f = FreeFileOpen HtmlFile For Output As #fPrint #f, "<html>" Print #f, "<table border=""1"">"Print #f, "<tr>" '写表头 For i = 1 To ll.ColumnHeaders.Count Print #f, "<td width=""" & CInt(ll.ColumnHeaders(i).Width / 10) & """ bgcolor=""" & GetTableColor(&HFF8080) & """ nowrap>" & "<p align=""" & GetAlign(ll.ColumnHeaders(i).Alignment) & """><font color=""#" & GetTableColor(&HFF0000) & """>" & ll.ColumnHeaders(i).Text & "</font></p></td>" Next Print #f, "</tr>"For j = 1 To ll.ListItems.Count '写数据 Print #f, "<tr>" For i = 1 To ll.ColumnHeaders.Count If i = 1 Then Print #f, "<td width=""" & CInt(ll.ColumnHeaders(i).Width / 10) & """ bgcolor=""" & GetTableColor(ll.BackColor) & """ nowrap>" & "<p align=""" & GetAlign(ll.ColumnHeaders(i).Alignment) & """><font color=""#" & GetTableColor(ll.ListItems(j).ForeColor) & """> " & ll.ListItems(j).Text & "</font></p></td>" Else Print #f, "<td width=""" & CInt(ll.ColumnHeaders(i).Width / 10) & """ bgcolor=""" & GetTableColor(ll.BackColor) & """ nowrap >" & "<p align=""" & GetAlign(ll.ColumnHeaders(i).Alignment) & """><font color=""#" & GetTableColor(ll.ListItems(j).ListSubItems(i - 1).ForeColor) & """> " & ll.ListItems(j).SubItems(i - 1) & "</font></p></td>" End If Next Print #f, "</tr>" Next Print #f, "</table>" Print #f, "</html>" Close #f End Sub Public Function GetAlign(i As Integer) Select Case i Case 0 GetAlign = "left" Case 1 GetAlign = "right" Case 2 GetAlign = "center" End Select End Function Public Function GetTableColor(c As Long) Dim b$ b = Format(Hex(c), "00000000") If Len(b) >= 8 Then If left(b, 2) = "80" Then '为系统颜色 b = "000000" End If Else If Len(b) < 6 Then '为调色板颜色 b = String(6 - Len(b), "0") & b '不足6位的加零 Else b = right(b, 6) '超过6位的取后6位 End If End If b = right(b, 2) & Mid(b, 3, 2) & left(b, 2) '把RBB中的蓝色分量与红色分量调换,(VB中的RGB对应IE中的BGR,VB中的不对) GetTableColor = b End Function
还有个就是把文件复制到粘贴板的代码 如何写文件 就你自己写吧 Dim i As Integer Dim t As Integer Dim ZTB Clipboard.Clear ZTB = "" For i = 1 To ListView2.ListItems.Count ZTB = ZTB & Replace(ListView2.ListItems(i).Text, vbCrLf, "") & Chr(9) For t = 1 To ListView2.ColumnHeaders.Count - 1 ZTB = ZTB & Replace(ListView2.ListItems(i).SubItems(t), vbCrLf, "") & Chr(9) Next ZTB = ZTB & vbCrLf Next Clipboard.SetText ZTB
'将LISTVIEW内容输出到HTML
Dim f%
Dim i%
Dim j As Long
Dim fa As String
f = FreeFileOpen HtmlFile For Output As #fPrint #f, "<html>"
Print #f, "<table border=""1"">"Print #f, "<tr>" '写表头
For i = 1 To ll.ColumnHeaders.Count
Print #f, "<td width=""" & CInt(ll.ColumnHeaders(i).Width / 10) & """ bgcolor=""" & GetTableColor(&HFF8080) & """ nowrap>" & "<p align=""" & GetAlign(ll.ColumnHeaders(i).Alignment) & """><font color=""#" & GetTableColor(&HFF0000) & """>" & ll.ColumnHeaders(i).Text & "</font></p></td>"
Next
Print #f, "</tr>"For j = 1 To ll.ListItems.Count '写数据
Print #f, "<tr>"
For i = 1 To ll.ColumnHeaders.Count
If i = 1 Then
Print #f, "<td width=""" & CInt(ll.ColumnHeaders(i).Width / 10) & """ bgcolor=""" & GetTableColor(ll.BackColor) & """ nowrap>" & "<p align=""" & GetAlign(ll.ColumnHeaders(i).Alignment) & """><font color=""#" & GetTableColor(ll.ListItems(j).ForeColor) & """> " & ll.ListItems(j).Text & "</font></p></td>"
Else
Print #f, "<td width=""" & CInt(ll.ColumnHeaders(i).Width / 10) & """ bgcolor=""" & GetTableColor(ll.BackColor) & """ nowrap >" & "<p align=""" & GetAlign(ll.ColumnHeaders(i).Alignment) & """><font color=""#" & GetTableColor(ll.ListItems(j).ListSubItems(i - 1).ForeColor) & """> " & ll.ListItems(j).SubItems(i - 1) & "</font></p></td>"
End If
Next
Print #f, "</tr>"
Next
Print #f, "</table>"
Print #f, "</html>"
Close #f
End Sub
Public Function GetAlign(i As Integer)
Select Case i
Case 0
GetAlign = "left"
Case 1
GetAlign = "right"
Case 2
GetAlign = "center"
End Select
End Function
Public Function GetTableColor(c As Long)
Dim b$
b = Format(Hex(c), "00000000")
If Len(b) >= 8 Then
If left(b, 2) = "80" Then '为系统颜色
b = "000000"
End If
Else
If Len(b) < 6 Then '为调色板颜色
b = String(6 - Len(b), "0") & b '不足6位的加零
Else
b = right(b, 6) '超过6位的取后6位
End If
End If
b = right(b, 2) & Mid(b, 3, 2) & left(b, 2) '把RBB中的蓝色分量与红色分量调换,(VB中的RGB对应IE中的BGR,VB中的不对)
GetTableColor = b
End Function
Dim i As Integer
Dim t As Integer
Dim ZTB
Clipboard.Clear
ZTB = ""
For i = 1 To ListView2.ListItems.Count
ZTB = ZTB & Replace(ListView2.ListItems(i).Text, vbCrLf, "") & Chr(9)
For t = 1 To ListView2.ColumnHeaders.Count - 1
ZTB = ZTB & Replace(ListView2.ListItems(i).SubItems(t), vbCrLf, "") & Chr(9)
Next
ZTB = ZTB & vbCrLf
Next
Clipboard.SetText ZTB