title: PHPExcel - .xlsx file downloads unreadable content
body: <p>I was trying export my data to spread sheet and it was working fine in my localhost , but when I uploaded that to server , it always downloads files with unreadable content . Writing the code  here.</p>
  
  <p>There is php_xml, php_zip and gd already installed in my server. The file downloaded is readonly.</p>
  
  <pre><code>    error_reporting(E_ALL);
      ini_set('display_errors', TRUE);
      ini_set('display_startup_errors', TRUE);
      date_default_timezone_set('Europe/London');
  
      if (PHP_SAPI == 'cli')
          die('This example should only be run from a Web Browser');
  
      /** Include PHPExcel */
      require_once dirname(__FILE__) . '/lib/PHPExcel.php';
  
  
      // Create new PHPExcel object
      $objPHPExcel = new PHPExcel();
  
      // Set document properties
      $objPHPExcel-&gt;getProperties()-&gt;setCreator("test")
                           -&gt;setLastModifiedBy("test")
                           -&gt;setTitle("test Report")
                           -&gt;setSubject("test Report")
                           -&gt;setDescription("test Report")
                           -&gt;setKeywords("test Report")
                           -&gt;setCategory("test Report");
  
      //Title
      $objPHPExcel-&gt;getActiveSheet()-&gt;mergeCells('A1:J1');
      $objPHPExcel-&gt;getActiveSheet()-&gt;getStyle('A1:J1')-&gt;getAlignment()-&gt;setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
      $objPHPExcel-&gt;getActiveSheet()-&gt;getStyle("A1:J1")-&gt;getFont()-&gt;setSize(20);
      $styleArray = array(
          'font' =&gt; array(
              'bold' =&gt; true
          )
      );
      $objPHPExcel-&gt;getActiveSheet()-&gt;getStyle('A1:J1')-&gt;applyFromArray($styleArray);
      $objPHPExcel-&gt;setActiveSheetIndex(0)
          -&gt;setCellValue('A1', 'test Report');
      $objPHPExcel-&gt;getActiveSheet()-&gt;getRowDimension(1)-&gt;setRowHeight(30);
      // //Set Column headlines
      $objPHPExcel-&gt;setActiveSheetIndex(0)
          -&gt;setCellValue('A2', 'First Name')
          -&gt;setCellValue('B2', 'Last name')
          -&gt;setCellValue('C2', 'State')
          -&gt;setCellValue('D2', 'Email')
          -&gt;setCellValue('E2', 'Mob')
          -&gt;setCellValue('F2', 'address')
          -&gt;setCellValue('G2', 'PIN')
          -&gt;setCellValue('H2', 'status')
          -&gt;setCellValue('I2', 'condition')
          -&gt;setCellValue('J2', 'log');
  
    $objPHPExcel-&gt;getActiveSheet()-&gt;getStyle("A2:J2")-&gt;getFont()-&gt;setSize(10);
    $objPHPExcel-&gt;getActiveSheet()-&gt;getStyle('A2:J2')-&gt;applyFromArray($styleArray);
    $objPHPExcel-&gt;getActiveSheet()-&gt;getColumnDimension('A')-&gt;setWidth(15);
    $objPHPExcel-&gt;getActiveSheet()-&gt;getColumnDimension('B')-&gt;setWidth(15);
    $objPHPExcel-&gt;getActiveSheet()-&gt;getColumnDimension('C')-&gt;setWidth(15);
    $objPHPExcel-&gt;getActiveSheet()-&gt;getColumnDimension('D')-&gt;setWidth(18);
    $objPHPExcel-&gt;getActiveSheet()-&gt;getColumnDimension('E')-&gt;setWidth(5);
    $objPHPExcel-&gt;getActiveSheet()-&gt;getColumnDimension('F')-&gt;setWidth(7);
    $objPHPExcel-&gt;getActiveSheet()-&gt;getColumnDimension('G')-&gt;setWidth(15);
    $objPHPExcel-&gt;getActiveSheet()-&gt;getColumnDimension('H')-&gt;setWidth(15);
    $objPHPExcel-&gt;getActiveSheet()-&gt;getColumnDimension('I')-&gt;setWidth(18);
    $objPHPExcel-&gt;getActiveSheet()-&gt;getColumnDimension('J')-&gt;setWidth(15);
  
  $colArray=array("A","B","C","D","E","F","G","H","I","J");
   $rowNumber = 3; 
      while ($row = mysqli_fetch_row($result)) { 
      $col = 0; 
      foreach($row as $cell) { 
          $objPHPExcel-&gt;getActiveSheet()-&gt;setCellValue($colArray[$col].$rowNumber,$cell); 
          $objPHPExcel-&gt;getActiveSheet()-&gt;getStyle($colArray[$col].$rowNumber)-&gt;getFont()-&gt;setSize(10);
          $col++; 
      } 
      $rowNumber++; 
  
      } 
  // Rename worksheet
  $objPHPExcel-&gt;getActiveSheet()-&gt;setTitle('test Report');
  
  // Set active sheet index to the first sheet, so Excel opens this as the first sheet
  $objPHPExcel-&gt;setActiveSheetIndex(0);
  // Redirect output to a client’s web browser (Excel2007)
  header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  header('Content-Disposition: attachment;filename="testreport.xlsx"');
  header('Cache-Control: max-age=0');
  // If you're serving to IE 9, then the following may be needed
  header('Cache-Control: max-age=1');
  
  // If you're serving to IE over SSL, then the following may be needed
  header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
  header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
  header ('Pragma: public'); // HTTP/1.0
  
  $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
  $objWriter-&gt;save('php://output');
  exit;
  </code></pre>