Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A question about method set_column() in Excel::Writer::XLSX module 1

Status
Not open for further replies.

whn

Programmer
Oct 14, 2007
265
US
I am trying to understand Excel::Writer::XLSX module by study the samples at CPAN site.

One of the sample code is at this link:
The implementation I am trying to understand listed below (my comments are in blue):

Code:
my $worksheet = $workbook->add_worksheet( 'Fonts' );

$worksheet->set_column( 0, 0, 30 ); [COLOR=blue]# First row, First column, width is 30[/color]
[COLOR=red]$worksheet->set_column( 1, 1, 10 );[/color] [COLOR=blue]# Second row, Second column, width is 10[/color]

If I modified the code above in red like below:
Code:
[b]$worksheet->set_column( 0, 1, 10 );[/b]
then the width of the first column will be overwritten.

Is this the way supposed to be?

In general, please take a look at a block of codes below:
Code:
for(my $i = 0, $i < 10; $i++) {
    my $width = 20 + $i;
    [COLOR=red]$worksheet->set_column( 0, $i, $width ); # This line does not work. All columns will have the same width! [/color]
    [b]#$worksheet->set_column( $i, $i, $width ); # This is the correct implementation.[/b]
}

I feel a bit odd. To me, both implementations should work.
Could someone explain it to me? Many thanks.
 
Hi

set_column() said:
[tt]set_column( $first_col, $last_col, $width, $format, $hidden, $level, $collapsed )[/tt]
[tt]Excel::Writer::XLSX[/tt] | [tt]set_column()[/tt] )

Perl:
[navy]$worksheet[/navy][teal]->[/teal][COLOR=darkgoldenrod]set_column[/color][teal]([/teal] [purple]0[/purple][teal],[/teal] [navy]$i[/navy][teal],[/teal] [navy]$width[/navy] [teal]);[/teal]  [gray]# sets columns in range 0..$i[/gray]
[navy]$worksheet[/navy][teal]->[/teal][COLOR=darkgoldenrod]set_column[/color][teal]([/teal] [navy]$i[/navy][teal],[/teal] [navy]$i[/navy][teal],[/teal] [navy]$width[/navy] [teal]);[/teal] [gray]# sets column $i[/gray]

Feherke.
[link feherke.github.com/][/url]
 
Thanks for the explanation. I have not thought about whether there should be a way to set column's width in a range, yet.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top