title: Setting autosize column phpExcel
body: <p>How do I make PHPExcel create the column width automatically I don't like having to go in by hand and stretch the columns witdth. I have looked at other examples but none work for me. Here is my code:</p>
  
  <pre><code>$objPHPExcel-&gt;setActiveSheetIndex(0);
  $objPHPExcel-&gt;getActiveSheet()-&gt;setCellValue('A1', "Company Name");
  $objPHPExcel-&gt;getActiveSheet()-&gt;setCellValue('B1', "Company Type");
  $objPHPExcel-&gt;getActiveSheet()-&gt;setCellValue('C1', "First Name");
  $objPHPExcel-&gt;getActiveSheet()-&gt;setCellValue('D1', "Last Name");
  $objPHPExcel-&gt;getActiveSheet()-&gt;setCellValue('E1', "Position");
  $objPHPExcel-&gt;getActiveSheet()-&gt;setCellValue('F1', "Email");
  
  // Set outline levels
  
  $objPHPExcel-&gt;getActiveSheet()-&gt;getColumnDimension('E')-&gt;setOutlineLevel(1)
                                                         -&gt;setVisible(false)
                                                         -&gt;setCollapsed(true);
  
  // Freeze panes
  
  $objPHPExcel-&gt;getActiveSheet()-&gt;freezePane('A2');
  
  
  // Rows to repeat at top
  
  $objPHPExcel-&gt;getActiveSheet()-&gt;getPageSetup()-&gt;setRowsToRepeatAtTopByStartAndEnd(1, 1);
  
  
  
  
  try {
  
      $stmt3 = $DB-&gt;prepare('SELECT * FROM companies C INNER JOIN personalInfo PI ON C.CompanyName = PI.Company_id');
      $stmt3-&gt;execute();
  
  
  } catch(PDOException $e) {  
      echo $e-&gt;getMessage();  
  }
  
  $info3 = $stmt3-&gt;fetchAll();
  
  
  $i = 2;
  foreach($info3 as $info) {
      $objPHPExcel-&gt;getActiveSheet()-&gt;setCellValue('A' . $i, $info['CompanyName'])
                                    -&gt;setCellValue('B' . $i, $info['CompanyType'])
                                    -&gt;setCellValue('C' . $i, $info['firstName'])
                                    -&gt;setCellValue('D' . $i, $info['lastName'])
                                    -&gt;setCellValue('E' . $i, $info['position'])
                                    -&gt;setCellValue('F' . $i, $info['email']);
      $i++;
  }
  
  
  // Set active sheet index to the first sheet, so Excel opens this as the first sheet
  $objPHPExcel-&gt;setActiveSheetIndex(0);
  
  
  // Save Excel 2007 file
  
  $callStartTime = microtime(true);
  
  $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
  $objWriter-&gt;save(str_replace('.php', '.xlsx', __FILE__));
  $callEndTime = microtime(true);
  $callTime = $callEndTime - $callStartTime;
  
  echo "Excel file has been created click &lt;a href='Excel.xlsx'&gt;HERE&lt;/a&gt; to view it.";
  </code></pre>