Reputation: 1821
I am using Spreadsheet::WriteExcel
to create an excel and write some data into it.
I am using the merge_range
to merger some cells.
But the problem is my below code does merge cells but dont show the data in it ($str
contents).
I am not able to figure out why????.
Please help me, where did i going wrong?
Below is the part of my code:
#!/usr/bin/perl
use Spreadsheet::WriteExcel;
use strict;
my $wb = Spreadsheet::WriteExcel->new('excel_test.xls');
my $custom_ws = $wb->add_worksheet('Custom Parameters');
my $wb_format_merge = $wb->add_format();
$wb_format_merge->set_bold();
$wb_format_merge->set_text_wrap();
$wb_format_merge->set_border(1);
$wb_format_merge->set_align('left');
$wb_format_merge->set_valign('vcenter');
my($row, $coll) = 0;
my $merge_coll_len = 8;
###### write data ###
my $str = "Please select the follwong metrics to generate custom report in Details sheet";
$custom_ws->merge_range($row, $coll, $row, $coll + $merge_coll_len, $str,$merge_format);
$row += 2;
$custom_ws->write($row, $coll, 'select the data type for the reference');
Upvotes: 2
Views: 1359
Reputation: 573
my($row, $coll) = 0;
$coll
is undefined
use
my($row, $coll)=(0,0);
Using 4 row,coll,row,coll for the merge_range
is perfectly valid (provided they have values ;) )
Upvotes: 3
Reputation: 37146
From what I can see in the Spreadsheet::WriteExcel
documentation example, the cell ranges are supposed to be passed as a single string argument, although as John points out, separate arguments are valid also:
For the single argument form, it would look like this:
$custom_ws->merge_range('A1:H1', $str, $merge_format);
One idea could be to roll a couple of helper subroutines to allow for the use of this form:
sub range {
my ( $from_row, $from_col ) = @{ $_[0] };
my ( $to_row, $to_col ) = @{ $_[1] };
die "Expecting to go from top-left to bottom-right"
if $from_row > $to_row || $from_col > $to_col;
return join '', alpha( $from_row ), $from_col, ':', alpha( $to_row ), $to_col;
}
sub alpha {
my $row = 'A';
$row++ for 1 .. +shift;
return $row;
}
And then call range
:
$custom_ws->merge_range( range( [ $row, $col ],
[ $row, $col + $length ] ),
$str,
$merge_format );
Upvotes: 2