pasting clipboard from Excel

Jim Ault jimaultwins at yahoo.com
Tue Sep 13 11:25:56 EDT 2011


>
> On Tue, Sep 13, 2011 at 10:30 AM, Colin Holgate <coiin at verizon.net>  
> wrote:
>
>> I'm trying to copy some cells from Excel (Mac, 2008 Office version)  
>> and
>> paste it into a field in LiveCode. If I do that with Numbers all is  
>> good.
>> From Excel I get nothing.
>>
>> 'the clipboard' tells me that it contains 'text, but that 'the
>> clipboarddata' is apparently empty.
>>
>> If I take a moment to paste the clipboard into another program, I  
>> can then
>> go on to paste in LiveCode ok.
>>
>> Is there a way for LiveCode to see the text from Excel without first
pasting it into another program?

I think the answer is yes, depending on the design of your spreadsheet.
It is always an adventure in data format conversion when using the  
clipboard between apps.

When I have done this using Applescript and other programs (LC, etc.)  
exchanging with Excel...

I write the spreadsheet formulas to 'gather' all the values into one  
cell using a series of formulas, then copy that single cell.

As a better practice, I name the cell, and access it by name rather  
than cell address.
Using the formulated value allows you to choose your delimiters
(such as char 160 = CR, and char 161 = tab )
and avoid the variations with tab, return cross platform.
This means the same Excel formula and the same LC handler will work on  
all versions of Win, Mac, and incarnations of Excel.

I have used this approach for very large text runs, in particular,  
merging (html + values) to create complete web pages in a single cell.

Also, when switching between apps using the clipboard, be aware that  
you should do an Applescript line such as

tell app "Microsoft Excel"
   -- copy named cell
end tell
delay 1   -- wait 1 second
tell app "Livecode" to activate  --
delay 0.5
put the clipboarddata into tTextBlock
--now parse delims ( 161, 160 )
--etc

This gives each app time to convert the clipboard, especially if it is  
very large.


>>

Jim Ault
Las Vegas






More information about the Use-livecode mailing list