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
你可以在EXEL中把这个过程录制成宏,然后把代码复制到.net中,一般情况稍加修改就可以了
新建一个控件测试窗体工程,添加一个DataGridView控件,添加前面我们做的扩展控件DataGridViewExt的引用,并在Form1.Designer.vb文件中中将
Friend WithEvents DataGridView1 As System.Windows.Forms.DataGridView
Me.DataGridView1 = New System.Windows.Forms.DataGridView
分别改为:
Friend WithEvents DataGridView1 As DataGridViewExt.DataGridViewExt
Me.DataGridView1 = New DataGridViewExt.DataGridViewExt
然后就可以从Excel,记事本等程序往DataGridView粘贴数据了.
例如,把文件"E:\新建文件夹\a.txt"复制到剪贴板
CreateObject("Shell.Application").NameSpace("E:\新建文件夹").ParseName("a.txt").InvokeVerb "复制(C)"
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Clipboard.SetDataObject(TextBox1.Text)
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
TextBox1.Text = Clipboard.GetDataObject().GetData(DataFormats.Text, False)
End Sub