I'd like to use the function "autofit_columns" as found here:CPAN
Here's my program so far(I skipped the DB connect and query part)
my $workbook = Spreadsheet::WriteExcel->new("TEST.xls");
my $bold = $workbook->add_format();
$bold->set_bold();
my $number = $workbook->add_format();
$number->set_num_format(0x01);
$worksheet = $workbook->add_worksheet('Sheet1');
my @headings = ('Blabla...');
foreach $i (@headings){
$worksheet->write(0, $col++, $i, $bold);
};
$col=0;
$lrow=1;
while (@row = $sth->fetchrow_array()) {
$worksheet->write($lrow,$col,\@row);
$lrow++;
};
$sth->finish;
$dbh->disconnect;
autofit_columns($worksheet);
$workbook->close();
sub autofit_columns {
my $worksheet = shift;
my $col = 0;
for my $width (@{$worksheet->{__col_widths}}) {
$worksheet->set_column($col, $col, $width) if $width;
$col++;
}
}
PROBLEM: My columns are not autofitted in the xls file... Any idea why?
I don't get the peice of code:
for my $width (@{$worksheet->{__col_widths}}) {
$worksheet->set_column($col, $col, $width) if $width;
$col++;
}