title: PHPexcel Library Error when exporting from database
body: <p>I am using the PHPexcel Library for my reporting. It functions well when I'm using static values but, when I try to export my data in MySQL database to PHPexcel, </p>
  
  <p>it always gives me this error</p>
  
  <pre><code>Warning: Cannot modify header information - headers already sent 
  </code></pre>
  
  <p>I've tried <code>ob_start()</code> function but the moment i opened my downloaded excel, it is empty</p>
  
  <p>this is my PHPexcel code:</p>
  
  <pre><code>&lt;?php
  
  include("conn.php");
  
  $query ="Select * from info";
  $result = mysql_query($query);
  
  
  
  /** Error reporting */
  error_reporting(E_ALL);
  
  /** Include path **/
  ini_set('include_path', ini_get('include_path').';../Classes/');
  
  /** PHPExcel */
  include 'PHPExcel.php';
  
  /** PHPExcel_Writer_Excel2007 */
  include 'PHPExcel/Writer/Excel2007.php';
  
  // Create new PHPExcel object
  echo date('H:i:s') . " Create new PHPExcel object\n";
  $objPHPExcel = new PHPExcel();
  
  
  
  
  // Add some data
  $row1=1;
  $row2=1;
  $row3=1;
  
  echo date('H:i:s') . " Add some data\n";
  $objPHPExcel-&gt;setActiveSheetIndex(0);
  
  
  while($row = mysql_fetch_array($result))
  {
  $let1 = "A".$row1."";
  $let2 = "B".$row2."";
  $let3 = "C".$row3."";
  
  $objPHPExcel-&gt;getActiveSheet()-&gt;SetCellValue($let1, $row['id']);
  $objPHPExcel-&gt;getActiveSheet()-&gt;SetCellValue($let2, $row['name']);
  $objPHPExcel-&gt;getActiveSheet()-&gt;SetCellValue($let3, $row['age']);
  
  $row1++;
  $row2++;
  $row3++;
  }
  
  $objPHPExcel-&gt;getActiveSheet()-&gt;getStyle("A1:C1")-&gt;getFont()-&gt;setBold(true);
  $objPHPExcel-&gt;getActiveSheet()-&gt;getStyle("A1:C1")-&gt;getFont()-&gt;setSize(20);
  $objPHPExcel-&gt;setActiveSheetIndex(0)-&gt;mergeCells('A1:C1');
  
  $objPHPExcel-&gt;getActiveSheet()-&gt;getStyle('A1')-&gt;applyFromArray(
      array(
          'fill' =&gt; array(
              'type' =&gt; PHPExcel_Style_Fill::FILL_SOLID,
              'color' =&gt; array('rgb' =&gt; 'FF0000')
          )
      )
  );
  
  
  header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
  header("Content-Disposition: attachment;filename=\"filename.xlsx\"");
  header("Cache-Control: max-age=0");
  
  exit();
  
  ?&gt;
  </code></pre>
  
  <p>It works perfect dealing with static values but when I tried to dynamically add values, it messes up. Please help, thank u in advance</p>