我在 Windows 窗体中使用了 _KeyDown
函数:
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
如果我使用 ctrl 选择 test
和 test 4
然后按 C 进行复制,当按下ctrl + v 并单步执行它,所有内容都介于 test2
和 test3
之间。
我该如何解决?
最佳答案
我会告诉你为什么你做不到。我在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 ,但那是另一个问题。
关于c# - 从 Excel 复制并粘贴到 Windows 窗体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11722721/