用MR实现Excel功能
因为原有的Paste不能实现我所要得功能,所以自定义了一个。我还想要追加多行的粘贴,该怎么办
比如
复制了三行DATA,在粘贴时,我选择的行数是三的倍数时,DATA会被复制三遍,可以实现吗 改正:我选择的行数是三的三倍时,DATA会被复制三遍 不好意思 MultiRow 控件没有这个功能。 我知道会比较麻烦,你们最近也很忙,
有时间可以帮我看看吗,日语版的帮助给出了下面的方法,
可是会出现错误,怎样改正呀
Public Sub Execute(ByVal target As GrapeCity.Win.MultiRow.GcMultiRow) Implements GrapeCity.Win.MultiRow.IAction.Execute
Dim temp As String = Clipboard.GetText()
' 取得DATA貼り付け
If Not String.IsNullOrEmpty(temp) Then
' 取得したデータの配列変数への設定
Dim rows As String() = temp.Split(CChar(vbCrLf))
Dim rCount As Integer = rows.Length
Dim cCount As Integer = rows(0).Split(CChar(vbTab)).Length
Dim data As String()() = New String(rCount - 1)() {}
For i As Integer = 0 To rCount - 1
data(i) = rows(i).Split(CChar(vbTab))
Next
' 選択領域がCopy元領域の整数倍的判別
Dim row1 As Integer = target.SelectedCells.Min(Function(c) c.RowIndex)
Dim row2 As Integer = target.SelectedCells.Max(Function(c) c.RowIndex)
Dim col1 As Integer = target.SelectedCells.Min(Function(c) c.CellIndex)
Dim col2 As Integer = target.SelectedCells.Max(Function(c) c.CellIndex)
Dim isRowMatch As Boolean = (row2 - row1 + 1) Mod rCount = 0
Dim isColMatch As Boolean = (col2 - col1 + 1) Mod cCount = 0
If isRowMatch And isColMatch Then
' 整数倍になっている場合:ブロック単位の複数回コピーの実行
For i As Integer = row1 To row2
For j As Integer = col1 To col2
target.SetValue(i, j, data((i - row1) Mod rCount)((j - col1) Mod cCount))
Next
Next
Else
' 整数倍になっていない場合:通常のペースト操作の実行
EditingActions.Paste.Execute(target)
End If
End If
End Sub 问题解决了 出现了什么错误,我试验了下这个代码貌似没有问题。你发的代码是通过自定义Action来解决这个问题。以下是完整的代码,希望对你有所帮助。
Imports GrapeCity.Win.MultiRow
Public Class Form1
Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Me.GcMultiRow1.Template = Template.CreateGridTemplate(10)
Me.GcMultiRow1.RowCount = 10
Me.GcMultiRow1.ShortcutKeyManager.Unregister(Keys.V Or Keys.Control)
Me.GcMultiRow1.ShortcutKeyManager.Register(New MyAction(), Keys.V Or Keys.Control)
End Sub
End Class
Public Class MyAction
Implements IAction
Public Function CanExecute(target As GrapeCity.Win.MultiRow.GcMultiRow) As Boolean Implements GrapeCity.Win.MultiRow.IAction.CanExecute
Return EditingActions.Paste.CanExecute(target)
End Function
Public ReadOnly Property DisplayName As String Implements GrapeCity.Win.MultiRow.IAction.DisplayName
Get
Return "CustomPaste"
End Get
End Property
Public Sub Execute(target As GrapeCity.Win.MultiRow.GcMultiRow) Implements GrapeCity.Win.MultiRow.IAction.Execute
Dim temp As String = Clipboard.GetText()
' 取得DATA貼り付け
If Not String.IsNullOrEmpty(temp) Then
' 取得したデータの配列変数への設定
Dim rows As String() = temp.Split(CChar(vbCrLf))
Dim rCount As Integer = rows.Length
Dim cCount As Integer = rows(0).Split(CChar(vbTab)).Length
Dim data As String()() = New String(rCount - 1)() {}
For i As Integer = 0 To rCount - 1
data(i) = rows(i).Split(CChar(vbTab))
Next
' 選択領域がCopy元領域の整数倍的判別
Dim row1 As Integer = target.SelectedCells.Min(Function(c) c.RowIndex)
Dim row2 As Integer = target.SelectedCells.Max(Function(c) c.RowIndex)
Dim col1 As Integer = target.SelectedCells.Min(Function(c) c.CellIndex)
Dim col2 As Integer = target.SelectedCells.Max(Function(c) c.CellIndex)
Dim isRowMatch As Boolean = (row2 - row1 + 1) Mod rCount = 0
Dim isColMatch As Boolean = (col2 - col1 + 1) Mod cCount = 0
If isRowMatch And isColMatch Then
' 整数倍になっている場合:ブロック単位の複数回コピーの実行
For i As Integer = row1 To row2
For j As Integer = col1 To col2
target.SetValue(i, j, data((i - row1) Mod rCount)((j - col1) Mod cCount))
Next
Next
Else
' 整数倍になっていない場合:通常のペースト操作の実行
EditingActions.Paste.Execute(target)
End If
End If
End Sub
End Class
代码没有问题,不过
Dim row1 As Integer = target.SelectedCells.Min(Function(c) c.RowIndex)
好像是NET Framework 3.5以降才有的Linq机能,所以我的用不了
:~ 顺便问一下,我想把这个自定义Action追加到ContextMenu的粘贴里可以吗
也就是说按下ContextMenu的粘贴时
不用既定的Paste用自定义Action
可以吗 可以。在ContextMenu的Item_Click里调用new MyAction().Execute(Me.GcMultiRow1) 就可以了。 谢谢,
可是怎么调用,可以写一下
页:
[1]
2