Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Modifying Excel hyperlink using PERL and OLE.pm

by SplashCD (Initiate)
on Jul 23, 2004 at 17:39 UTC ( [id://376940]=perlquestion: print w/replies, xml ) Need Help??

SplashCD has asked for the wisdom of the Perl Monks concerning the following question:

I've looked far and wide, even so much as going to Microsoft's Excel hyperlinks reference page.

What is the structure/syntax one would use to edit an Excel cell's hyperlink value, using only Perl and Win32::OLE.pm?

I can read cell values and hyperlinks, and change cell values, but cant figure out how to modify the hyperlink.



Here are some of the things I've tried in vain:

• $worksheet->Range("D39")->Hyperlinks->{Address}="C:\\temp";
• $worksheet->Range("D39")->Hyperlinks->Add({Address => "C:\\temp"});
• $worksheet->Hyperlinks->Add({Address=>'C:\\temp'});
• $worksheet->Hyperlinks->Add({Anchor=>('D39'), Address=>'C:\\temp'});
• $cellObject->Hyperlinks->Add(Range('A2'), 'C:\\temp');


... and my personal favorite ...


$worksheet->Hyperlinks()->Add({ Address => "C:\\temp", Anchor => Selected, TextToDisplay => "AutoLink", });

I'd just like to know what structure will work.

Thanks,
-SplashCD

  • Comment on Modifying Excel hyperlink using PERL and OLE.pm

Replies are listed 'Best First'.
Re: Modifying Excel hyperlink using PERL and OLE.pm
by guha (Priest) on Jul 23, 2004 at 18:13 UTC

    On my way out the door ....

    $worksheet->Hyperlinks->Add({ Anchor => $range1, Address => $adr, TextToDisplay => $txt, ScreenTip => $tip1, });
      Thank you guha!

      Your solution brings a very welcomed end to my days long search.

      I am indebted. Would you suggest any book or reference that I should look to for future OLE.pm quandaries?

      Regards, -SplashCD
Re: Modifying Excel hyperlink using PERL and OLE.pm
by jmcnamara (Monsignor) on Jul 23, 2004 at 23:10 UTC

    Here is one way:
    #!/usr/bin/perl -w use strict; use Cwd; use Win32::OLE; use Win32::OLE::Const 'Microsoft Excel'; my $application = Win32::OLE->new("Excel.Application"); my $workbook = $application->Workbooks->Add; my $worksheet = $workbook->Worksheets(1); # Write a hyperlink my $range = $worksheet->Range("B2:B2"); $worksheet->Hyperlinks->Add({Anchor => $range, Address => "http://www.perl.com/"}); # Get current directory using Cwd.pm $workbook->SaveAs({FileName => cwd() . '/win32ole.xls'}); $workbook->Close; __END__

    P.S. I answered this earlier as well.

    --
    John.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://376940]
Approved by Old_Gray_Bear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2024-04-19 13:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found