Reputation: 95
I have made use of the _KeyDown
function in my windows form:
if ((e.KeyCode == Keys.V) && (e.Modifiers == Keys.Control))
{
// do stuff
}
and then have used to get the copied data:
string[] clipboardRows = Clipboard.GetText(TextDataFormat.UnicodeText).Split(new string[] {"\r\n"},
StringSplitOptions.None);
This works fine, however when you select say selected cells from a spreadsheet it ends up copying all cells in between for example:
1.Test
2.Test2
3.Test3
4.Test4
If i select both test
and test 4
using ctrl and then copying by pressing C, when pressing ctrl + v and stepping through it gets all in between so test2
and test3
.
How do i resolve this?
Upvotes: 2
Views: 2219
Reputation: 65712
I'll show you why you cant do it. I recorded a Macro in Excel, entered four rows of data. I selected cell A1 and A4, press 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
You can do this in VSTO eg Copy & Paste VSTO - Excel Power Tools, but thats another question.
Upvotes: 1