title: PHPExcel download not working properly
body: <p>I am trying to create a page that allows a user to download the contents of an SQL table, into an excel file.</p>
  
  <p>Problem : When I open the excel file, it only contains random gibberish. An example -</p>
  
  <pre><code>PKQ=DG’D²Xð[Content_Types].xml­”MNÃ0…÷œ"ò%nY „švAa
  •(0ö¤±êØ–gúw{&amp;i‰@ÕnbEö{ßøyìÑdÛ¸l
  mð¥‘×ÁX¿(ÅÛü)¿’òF¹à¡;@1_æ»˜±Øc)j¢x/%ê…Eˆày¦
  </code></pre>
  
  <p>This is my code -</p>
  
  <pre><code>&lt;?php
  error_reporting(E_ALL);
  ini_set('display_errors', TRUE);
  ini_set('display_startup_errors', TRUE);
  
  $download="";
  if (isset($_GET['surveyid'])) {
  //Survey ID
  $download = $_GET['surveyid'];
  require_once('../Classes/PHPExcel.php');
  
  $query="SELECT b.question_id as qid,
                  a.question as ques,
                  b.response as response,
                  count(b.response) as cnt
            FROM v3_sai.survey_responses b 
            INNER JOIN v3_sai.survey_questions a 
               ON a.id = b.question_id 
                  AND a.survey_id=".intval($download)."
            group by b.response, a.question
            order by b.question_id";
            var_dump($query);
  $resultdl= mysql_query($query) or die(mysql_error());
  $objPHPExcel = new PHPExcel();
  $objPHPExcel-&gt;setActiveSheetIndex(0);
  $rowcount=1;
  while($row = mysql_fetch_array($resultdl)){
  $objPHPExcel-&gt;getActiveSheet()-&gt;SetCellValue('A'.$rowcount, $row['qid']);
  $objPHPExcel-&gt;getActiveSheet()-&gt;SetCellValue('B'.$rowcount, $row['ques']); 
  $objPHPExcel-&gt;getActiveSheet()-&gt;SetCellValue('C'.$rowcount, $row['response']);
  $objPHPExcel-&gt;getActiveSheet()-&gt;SetCellValue('D'.$rowcount, $row['cnt']); 
  $rowCount++; 
  } 
  $objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel); 
  header('Content-type: application/vnd.ms-excel');
  header('Content-Disposition: attachment; filename="file.xls"');
  $objWriter-&gt;save('php://output');
  die();
  }
  </code></pre>