Win32::Clipboard() and Excel

M

Mike Flannigan

I'm trying to use Win32::Clipboard() to get data from the
clipboard. The text I am copying to the clipboard is in
an Excel file. Here is the code I use:

$clip = Win32::Clipboard();
$text = $clip->Get();

It works fine if I swipe the formula bar in Excel, hit
ctrl C, and then run the program. But if I just highlight
the cell I want and hit ctrl C, and then run the Perl
script I get a bunch of garbage like this:

 6 ( ²      ø à 
ÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆ

Apparently this is some kind of metacharacters or something
that contains cell formatting (and other things?) along with the
text I want. Does anybody know how to extract the root
text from this gobley gook?


Mike Flannigan
 
B

Brian Helterline

Mike Flannigan said:
I'm trying to use Win32::Clipboard() to get data from the
clipboard. The text I am copying to the clipboard is in
an Excel file. Here is the code I use:

$clip = Win32::Clipboard();
$text = $clip->Get();

It works fine if I swipe the formula bar in Excel, hit
ctrl C, and then run the program. But if I just highlight
the cell I want and hit ctrl C, and then run the Perl
script I get a bunch of garbage like this:

 6 ( ²      ø à 
ÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆÆ

If you want text, specify it:
$text = $clip->GetText();

according to the docs,

Get()

Returns the clipboard content; note that the result depends on the nature of
clipboard data; to ensure that you get only the desired format, you should
use GetText(), GetBitmap() or GetFiles() instead. Get() is in fact
implemented as:
if( IsBitmap() ) { return GetBitmap(); }
elsif( IsFiles() ) { return GetFiles(); }
else { return GetText(); }


and if you had tried $clip->IsBitmap(), you would have seen that it returned
true
so it treated the Excel cell information as a bitmap.

-brian
 
M

Mike Flannigan

Brian said:
If you want text, specify it:
$text = $clip->GetText();

according to the docs,

Get()

Returns the clipboard content; note that the result depends on the nature of
clipboard data; to ensure that you get only the desired format, you should
use GetText(), GetBitmap() or GetFiles() instead. Get() is in fact
implemented as:
if( IsBitmap() ) { return GetBitmap(); }
elsif( IsFiles() ) { return GetFiles(); }
else { return GetText(); }

and if you had tried $clip->IsBitmap(), you would have seen that it returned
true
so it treated the Excel cell information as a bitmap.

-brian

Thank you very much. I really appreciate the response.
Your suggestion works perfectly.

I did do some research on this and didn't come up with
any of that. Unfortunately, I went to:
http://secu.zzu.edu.cn/book/Perl/Perl Bookshelf [3rd Ed]/perlnut/ch22_01.htm#perlnut2-CHP-22-SECT-1

and
http://www.cpan.org/modules/by-authors/id/ACALPINI/Win32-Clipboard-0.50.readme
via a Google search.

I have now repaired my link to CPAN, and will . . .

Well, now I can't even find the module on CPAN. I used to go to
"all modules" and find everything I needed, but that was on a
site mirror that no longer exists (404). The "all modules" I see
now is at:
http://www.perl.com/CPAN/modules/01modules.index.html
and it has no clipboard module I can see.

Sometimes I think Perl is just trying to make me look stupid :)


Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,140
Latest member
SweetcalmCBDreview
Top