title: Perl - Spreadsheet::WriteExcel function explanation
body: <p>I'd like to use the function "autofit_columns" as found here:<a href="http://search.cpan.org/~jmcnamara/Spreadsheet-WriteExcel/lib/Spreadsheet/WriteExcel/Examples.pm#Example%3a_autofilter.pl" rel="nofollow">CPAN</a></p>
  
  <p>Here's my program so far(I skipped the DB connect and query part)</p>
  
  <pre><code>my $workbook = Spreadsheet::WriteExcel-&gt;new("TEST.xls");
  
  my $bold = $workbook-&gt;add_format();
  $bold-&gt;set_bold();
  my $number = $workbook-&gt;add_format();
  $number-&gt;set_num_format(0x01);
  $worksheet = $workbook-&gt;add_worksheet('Sheet1');
  
  my @headings = ('Blabla...');
  
  foreach $i (@headings){
  $worksheet-&gt;write(0, $col++, $i, $bold);
  };
  
  $col=0;
  $lrow=1;
  while (@row = $sth-&gt;fetchrow_array()) {
          $worksheet-&gt;write($lrow,$col,\@row);
          $lrow++;
  
  };
  $sth-&gt;finish;
  $dbh-&gt;disconnect;
  
  autofit_columns($worksheet);
  $workbook-&gt;close();
  
  sub autofit_columns {
  
          my $worksheet = shift;
          my $col       = 0;
  
          for my $width (@{$worksheet-&gt;{__col_widths}}) {
  
              $worksheet-&gt;set_column($col, $col, $width) if $width;
              $col++;
          }
      }
  </code></pre>
  
  <p>PROBLEM: My columns are not autofitted in the xls file... Any idea why? </p>
  
  <p>I don't get the peice of code:</p>
  
  <pre><code>for my $width (@{$worksheet-&gt;{__col_widths}}) {
  
                  $worksheet-&gt;set_column($col, $col, $width) if $width;
                  $col++;
              } 
  </code></pre>