title: How to PHPExcel set auto-columns width
body: <p>I'm working with PHPExcel to export data for download. When open downloaded files, with cells have big number, it show "#######" instead of value number. I'm tried <code>setAutoSize()</code> for every columns then call <code>$sheet-&gt;calculateColumnWidths()</code> but it still not changes. I see calculateColumnWidths() <a href="https://stackoverflow.com/questions/9965476/phpexcel-column-size-issues">at here</a>, @Mark Baker says "calculateColumnWidths() increase the value by perhaps 5% to try and ensure that the entire column fits". If number length in cell exceed 5%, it seems doen's resolved the problem</p>
  
  <p><strong>UPDATE</strong>
  This is my function to auto size columns:</p>
  
  <pre><code>   function autoFitColumnWidthToContent($sheet, $fromCol, $toCol) {
          if (empty($toCol) ) {//not defined the last column, set it the max one
              $toCol = $sheet-&gt;getColumnDimension($sheet-&gt;getHighestColumn())-&gt;getColumnIndex();
          }
          for($i = $fromCol; $i &lt;= $toCol; $i++) {
              $sheet-&gt;getColumnDimension($i)-&gt;setAutoSize(true);
          }
          $sheet-&gt;calculateColumnWidths();
      }
  </code></pre>