2

_KeyDown在我的 Windows 窗体中使用了该功能:

if ((e.KeyCode == Keys.V) && (e.Modifiers == Keys.Control))
{
    // do stuff
}

然后用于获取复制的数据:

 string[] clipboardRows = Clipboard.GetText(TextDataFormat.UnicodeText).Split(new string[] {"\r\n"},
                                                                                                 StringSplitOptions.None);

这很好用,但是当您从电子表格中选择说选定的单元格时,它最终会复制其间的所有单元格,例如:

1.Test
2.Test2
3.Test3
4.Test4

如果我同时选择testtest 4使用ctrl然后按复制C,当按ctrl+v并单步执行时,它会在 sotest2test3.

我该如何解决这个问题?

4

1 回答 1

1

我会告诉你为什么你不能这样做。我在Excel中记录了一个宏,输入了四行数据。我选择了单元格 A1 和 A4,按 Ctrl + C

Range("A1").Select
ActiveCell.FormulaR1C1 = "abc"
Range("A2").Select
ActiveCell.FormulaR1C1 = "def"
Range("A3").Select
ActiveCell.FormulaR1C1 = "hij"
Range("A4").Select
ActiveCell.FormulaR1C1 = "klm"
Range("A4,A1").Select    'It actually concatenates the cells you've selected, that info isn't in the clipboard, if I selected three cells in the column it would be Range("A4,A1,A2").Select
Range("A1").Activate
Selection.Copy  

'Range("B1").Select
'ActiveSheet.Paste   'when I paste onto new cells, only two rows are taken up

您可以在 VSTO 中执行此操作,例如Copy & Paste VSTO - Excel Power Tools,但这是另一个问题。

于 2012-07-31T04:07:57.133 回答