Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Link excel worksheets using perl

I am trying to write a perl script which links a cell value in say 1st worksheet to a value in 2nd worksheet using perl. I tried using the following modules which were available in perl :-

  1. Excel::Writer::XLSX

  2. Spreadsheet::WriteExcel

Can anyone help me with a simple perl script that does this.

Example :-

Worksheet1

enter image description here


Worksheet2

enter image description here

So, In the above example the Rules Column Items R1, R2, R3 in Worksheet1 should be hyperlinks that takes us to Rules Column Items R1, R2, R3 respectively when clicked.

Can someone show me how it can be done using perl or atleast push me into the right direction on how to use the module Spreadsheet::WriteExcel or Excel::Writer::XLSX for this problem.

Please help me out..!!

like image 654
Vivek Sharma Avatar asked Feb 20 '26 13:02

Vivek Sharma


1 Answers

Using Excel::Writer::XLSX you would use the write_url followed by write_formula method. Here is an example:

#!/usr/bin/perl
use strict;
use Excel::Writer::XLSX;
my $workbook = Excel::Writer::XLSX->new( 'test.xlsx' );
my $worksheet1 = $workbook->add_worksheet('Worksheet1');
my $worksheet2 = $workbook->add_worksheet('Worksheet2');

$worksheet2->write_string(0,0, 'Rules'); 
$worksheet2->write_string(1,0, 'R1');
$worksheet2->write_string(2,0, 'R2');
$worksheet2->write_string(3,0, 'R3');

my $format = $workbook->add_format( color => 'blue', underline => 1 );
$worksheet1->write_url( 1,1,  'internal:Worksheet2!A2', $format);
$worksheet1->write_formula( 1, 1, '=Worksheet2!A2' );
like image 69
Patrick Collins Avatar answered Feb 23 '26 12:02

Patrick Collins



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!