Paste column into grid

Using (or providing) components based on the "Win32" framework
Post Reply
Hannu
Posts: 5
Joined: Tue Jan 25, 2011 1:21 pm

Paste column into grid

Post by Hannu »

I'd like to copy a column from Excel to clipboad and paste it into a column in Dyalog grid starting from a selected cell. But it is transposed to a row. Only when the target region in the grid is preselected it goes to the wrigth place. Is it possible to change this default Excel -> Dyalog grid pasting method? Thanks in advance!
User avatar
kai
Posts: 141
Joined: Thu Jun 18, 2009 5:10 pm
Location: Hillesheim / Germany

Re: Paste column into grid

Post by kai »

Presumably it's not. When you inspect the clipboard after the copy you will find that there is no way to tell whether the data is a column or a row. Nothing you can do about this. Well, you could start pestering Bill...
uwejanza
Posts: 19
Joined: Tue Mar 09, 2010 2:01 pm
Location: Nürnberg, Germany

Re: Paste column into grid

Post by uwejanza »

When an application copies data into the clipboard it may provide the data in several formats simultaneously. Every application is allowed to add data to the clipboard in it's own proprietary format, or even in several formats, containing more or less information. At least the application's programmers have the choice to do so.

So data you find in the clipboard may or may not contain shape information. The only clipboard format common to (almost) all applications is plain text. This format does not know about columns.

Of course, in Excel an additional proprietary clipboard data format is provided, so a user of Excel can copy data from one instance of Excel to the next instance of Excel in a way that preserves shape. For this purpose, Excel simply has to first check the clipboard for data in it's own proprietary format.

The challenge for an application that wants to paste data from the clipboard is to guess which of the data formats provided in the clipboard at the moment is most appropriate.
User avatar
kai
Posts: 141
Joined: Thu Jun 18, 2009 5:10 pm
Location: Hillesheim / Germany

Re: Paste column into grid

Post by kai »

Although Uwe is correct in what he's saying it might be misleading:

The information in which formats data is available on the clipboard is provided by the "Formats" property. Naturally, Dyalog only supports standard formats. So any proprietary formats left behind by any other application is not available to an APL programmer, at least not without []NA calls.

It's understandable that the text format does not provide any information regarding shape, but what it less understandable is why the array property doesn't come with it when only a single row or a single column got copied.

For example:

      'cl' ⎕wc'Clipboard'
⍝ after copying 3 rows and 2 columns
⍴cl.Array
3 2
⍝ after copying 3 rows and ONE column
⍴cl.Array
3


That is simply rubbish.
User avatar
Phil Last
Posts: 628
Joined: Thu Jun 18, 2009 6:29 pm
Location: Wessex

Re: Paste column into grid

Post by Phil Last »

I don't have msexcel but I do have open-office calc.

copy 3 rows by 1 column.

Then in APL:
   ⍴CL.Array
3

copy 1 row by 3 columns.

   ⍴CL.Array
1 3

if ooo is the same as excel then I guess you need:

   ⍴⍪CL.Array
uwejanza
Posts: 19
Joined: Tue Mar 09, 2010 2:01 pm
Location: Nürnberg, Germany

Re: Paste column into grid

Post by uwejanza »

I just repeated Phil's extension to Kai's example with Excel:

'cl' ⎕wc'Clipboard'
⍝ Copy 1 row and 3 columns into the clipboard
⍴cl.Array
1 3
⍝ Copy 3 rows and 1 column into the clipboard
⍴cl.Array
3

Same result as with ooo. Seem like for once in my life Bill is not the one to be pestered.
User avatar
Phil Last
Posts: 628
Joined: Thu Jun 18, 2009 6:29 pm
Location: Wessex

Re: Paste column into grid

Post by Phil Last »

The fact that there is a difference between a column vector and a single row means that there is no ambiguity. Inserting monadic comma-bar (⍪) forces a vector to be a 1 column matrix. This is the solution the original poster requires.
Post Reply