title: Using PHPExcel to export to xlsx
body: <p>I am using PHPEXxcel to export an HTML Table generated using MYSQL and its like this.</p>
  
  <pre><code>&lt;?php $query = "SELECT `Firstname`,`Lastname`,`Branch`,`Gender`,`Mobileno`, `Email`  
        FROM `student_details` WHERE Branch IN ('$branch') and `Year`='$year' 
           and Tenthresult &gt; '$tenth' and 
        Twelthresult &gt; '$twelth' and (CGPA &gt; '$cgpa' || CGPA = '$cgpa')";  
  
  $result = mysql_query($query);
  confirm_query($result);
  $objPHPExcel = new PHPExcel(); 
  $objPHPExcel-&gt;setActiveSheetIndex(0); 
  
  $rowCount = 1; 
  $objPHPExcel-&gt;getActiveSheet()-&gt;SetCellValue('A'.$rowCount,'Firstname');
  $objPHPExcel-&gt;getActiveSheet()-&gt;SetCellValue('B'.$rowCount,'Lastname');
  $objPHPExcel-&gt;getActiveSheet()-&gt;SetCellValue('C'.$rowCount,'Branch');
  $objPHPExcel-&gt;getActiveSheet()-&gt;SetCellValue('D'.$rowCount,'Gender');
  $objPHPExcel-&gt;getActiveSheet()-&gt;SetCellValue('E'.$rowCount,'Mobileno');
  $objPHPExcel-&gt;getActiveSheet()-&gt;SetCellValue('F'.$rowCount,'Email');
  
  while($row = mysql_fetch_array($result)){ 
      $rowCount++;
      $objPHPExcel-&gt;getActiveSheet()-&gt;SetCellValue('A'.$rowCount, $row['0']);
      $objPHPExcel-&gt;getActiveSheet()-&gt;SetCellValue('B'.$rowCount, $row['1']);
      $objPHPExcel-&gt;getActiveSheet()-&gt;SetCellValue('C'.$rowCount, $row['2']);
      $objPHPExcel-&gt;getActiveSheet()-&gt;SetCellValue('D'.$rowCount, $row['3']);
      $objPHPExcel-&gt;getActiveSheet()-&gt;SetCellValue('E'.$rowCount, $row['4']);
      $objPHPExcel-&gt;getActiveSheet()-&gt;SetCellValue('F'.$rowCount, $row['5']);
  } 
  
  $objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel); 
  $objWriter-&gt;save('some_excel_file.xlsx'); 
  ?&gt;
  </code></pre>
  
  <p>Its working but it saves the xlsx file in the root folder without showing to user any signs that its being downloaded.
  This code rund when i click a button.now, can i make it to be downloaded like we download a mail attachment and showing the user in the front end that its being downloaded along with the location.</p>
  
  <p>I tried using </p>
  
  <pre><code>header('Content-Type: application/vnd.ms-excel');
  header('Content-Disposition: attachment;filename="01simple.xls"');
  header('Cache-Control: max-age=0'); 
  </code></pre>
  
  <p>With this, i am getting what i wanted above but the xls file downloaded when opened shows 
  the message 
  'The File you are trying to open 'filename' is in a different format than the specified extension.....etc.Do you want to open now?</p>
  
  <p>On opening it contains either the entire HTML Page or its simply blank...
  Can anybody help me..?</p>