表格上面做了一个按钮,利用syscmd.Edit.copy()复制表格选中区域的数据,再用Clipboard.GetText()获取复制的内容到变量str,但是老实获取不到值!!!
Dim tb As Table = e.Form.Controls("Table1").Table
tb.DataTable.AllowCopyHeader =True
tb.Select
ClipBoard.Clear
syscmd.Edit.copy()
System.Threading.Thread.Sleep(1000)
If Clipboard.ContainsText() Then
Dim str As String = Clipboard.GetText()
MsgBox("剪贴板包含文本: " & str)
Else
MsgBox("剪贴板不包含文本")
End If
[此贴子已经被作者于2024/10/19 8:06:19编辑过]
不要使用syscmd.Edit.copy。要使用表格提供的复制方法:http://www.foxtable.com/webhelp/topics/2212.htm
Dim tb As Table = e.Form.Controls("Table1").Table
tb.DataTable.AllowCopyHeader =True
tb.Select
tb.EditCopy
If Clipboard.ContainsText() Then
Dim str As String = Clipboard.GetText()
MsgBox("剪贴板包含文本: " & str)
……
[此贴子已经被作者于2024/10/19 9:44:08编辑过]
谢谢蓝总!十分感谢!大师果然是大师!但是CurrentTable.EditCopy()和syscmd.Edit.copy()只能复制表头的字段名(英文),不能复制标题(中文),
后面自己想了个土办法,遍历所选区域的表头和数据,组装到str这个字符串变量,再装进ClipBoard,
土办法比较麻烦,请问蓝老师,想要复制表头的标题行,请问有没有什么自带的简单方法呢:
Dim S As String
If CurrentTable.LeftCol >=0 And CurrentTable.RightCol >=0 Then
For i As Integer = CurrentTable.LeftCol To CurrentTable.RightCol
Dim c As Col=CurrentTable.Cols(i)
If i=CurrentTable.RightCol Then
s=s & c.Caption & chr(13)
Else
s=s & c.Caption & chr(9)
End If
Next
End If
If CurrentTable.TopPosition >=0 And CurrentTable.BottomPosition>=0 Then
For i As Integer =CurrentTable.TopPosition To CurrentTable.BottomPosition
Dim R As Row =CurrentTable.Rows(i)
If CurrentTable.LeftCol >=0 And CurrentTable.RightCol >=0 Then
For j As Integer = CurrentTable.LeftCol To CurrentTable.RightCol
Dim a As String
a=CurrentTable.Rows(i)(j)
If j=CurrentTable.RightCol Then
s=s & a & chr(13)
Else
s=s & a & chr(9)
End If
Next
End If
Next
End If
ClipBoard.SetText(s)
[此贴子已经被作者于2024/10/19 14:50:35编辑过]