Rss & SiteMap
Foxtable(狐表) http://www.foxtable.com
CZY楼主,麻烦你写一个“从剪贴板导入数据(即,粘贴时区分列标题)”的按钮功能。能够自动匹配列标题进行粘贴。
下载信息 [文件大小: 下载次数: ] | |
![]() |
如咐件:
(1)打开销售明细.xls,全选,复制
(2)打开管理项目1.Table,选择表A,粘贴(求助:此粘贴按钮的代码)。
这样试试
Dim s As String = ClipBoard.GetText()
Dim Lines() As String = s.split(chr(13))
Dim Title() As String = Lines(0).Trim(chr(10)).Split(chr(9))
Dim dtb As New DataTableBuilder("test")
For n As Integer = 0 To Title.Length -1
dtb.AddDef(Title(n), Gettype(String),250)
Next
dtb.TableVisible = False
dtb.Build()
Dim t As Table = Tables("test")
For n As Integer = 1 To Lines.Length -2
Dim Line() As String = Lines(n).Trim(chr(10)).Split(chr(9))
Dim r As Row = t.AddNew()
For c As Integer = 0 To t.Cols.Count - 1
r(c) = Line(c)
Next
Next
For Each dr1 As DataRow In DataTables("test").DataRows
Dim dr2 As DataRow = DataTables("表A").AddNew()
For Each dc As DataCol In DataTables("test").DataCols
If DataTables("表A").DataCols.Contains(dc.name) Then
dr2(dc.name) = dr1(dc.name)
End If
Next
Next
搞定
If ClipBoard.ContainsText Then '如果剪贴板中有数据
Dim x As Integer
Dim s As String = ClipBoard.GetText()
Dim Lines() As String = s.split(chr(13))
Dim Title() As String = Lines(0).Trim(chr(10)).Split(chr(9))
Dim dtb As New DataTableBuilder("Temp") '创建临时表
For n As Integer = 0 To Title.Length -1
dtb.AddDef(Title(n),Gettype(String),250)
Next
dtb.TableVisible = False
dtb.Build()
Dim t As Table = Tables("Temp")
'将剪贴板中的数据写入临时表
For n As Integer = 1 To Lines.Length -2
Dim Line() As String = Lines(n).Trim(chr(10)).Split(chr(9))
Dim r As Row = t.AddNew()
For c As Integer = 0 To t.Cols.Count - 1
r(c) = Line(c)
Next
Next
ClipBoard.Clear
s = ""
For i As Integer = 0 To Tables("表A").Cols.Count -1
s = s & Tables("表A").Cols(i).Name & "|" & Tables("表A").Cols(i).Width & "|"
Next '隐藏临时表在表A中不存在的列
t.SetColVisibleWidth(s)
For c As Integer = 0 To t.Cols.Count -1
If t.Cols(c).Visible Then
x = x + 1
End If
Next
If x > 0 Then '如果临时表有符合的列,则向表A填充数据
Dim f As New Filler
f.SourceTable = DataTables("Temp")
f.datatable = DataTables("表A")
f.Distinct = False
f.Fill()
End If
End If
CZY楼主,谢谢。你太谦虚了,是我辈学习谐模。以后麻烦多多指教。