VB.Net 复制Excel数据到剪贴板,然后粘贴到Listview1,最好提供代码,多谢!
下面数据为Excel中选取的数据,已复制到剪贴板...应该如何写入Listview中去呢?需要自动填充标题。谢谢...
下面数据为Excel中选取的数据,已复制到剪贴板...应该如何写入Listview中去呢?需要自动填充标题。谢谢
展开
1个回答
展开全部
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim Str As String = Clipboard.GetText '获取剪切板数据。
ListView1.View = View.Details
Dim Tit As Boolean = True
Dim Index As Integer = 0 '标题行的列数。
Try
For Each i In Str.Replace(vbLf, "").Split(vbCr)
Dim Str2() As String = i.Split(" ")
If Tit Then '标题行
Tit = False
For Each k In Str2
ListView1.Columns.Add(k)
Next
Index = Str2.Length - 1
Else '非标题行。
Dim lv As New ListViewItem(Str2(0))
For k = 1 To Index
lv.SubItems.Add(Str2(k))
Next
ListView1.Items.Add(lv)
End If
Next
Catch ex As Exception
End Try
End Sub
Dim Str As String = Clipboard.GetText '获取剪切板数据。
ListView1.View = View.Details
Dim Tit As Boolean = True
Dim Index As Integer = 0 '标题行的列数。
Try
For Each i In Str.Replace(vbLf, "").Split(vbCr)
Dim Str2() As String = i.Split(" ")
If Tit Then '标题行
Tit = False
For Each k In Str2
ListView1.Columns.Add(k)
Next
Index = Str2.Length - 1
Else '非标题行。
Dim lv As New ListViewItem(Str2(0))
For k = 1 To Index
lv.SubItems.Add(Str2(k))
Next
ListView1.Items.Add(lv)
End If
Next
Catch ex As Exception
End Try
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |