title: php excel download a file
body: <p>Developers<br>I am using Yii1 and I want to generate a report using PHPExcel extension but my file is not ready to download, instead it appears in console. I also set headers but still file is not ready for download. I can't find exact answer. please resolve my problem</p>
  
  <pre><code>public function GenerateReport($dataProvider)
  {
  
      $phpExcelPath = Yii::getPathOfAlias('ext.phpexcel.Classes');
      include($phpExcelPath . DIRECTORY_SEPARATOR . 'PHPExcel.php');
  
      $objPHPExcel = new PHPExcel();
      $fileName = 'report-'.uniqid().'.xlsx';
      $objPHPExcel-&gt;getProperties()-&gt;setCreator("Palash Gupta");
      $objPHPExcel-&gt;getProperties()-&gt;setTitle($fileName);
      $objPHPExcel-&gt;getProperties()-&gt;setSubject("Placement Student List");
      $objPHPExcel-&gt;getProperties()-&gt;setDescription("Placement Student List");
      $objPHPExcel-&gt;setActiveSheetIndex(0);
  
      $rowCount = 1;
      $objPHPExcel-&gt;getActiveSheet()-&gt;SetCellValue('A' . $rowCount, 'Name');
      $objPHPExcel-&gt;getActiveSheet()-&gt;SetCellValue('B' . $rowCount, 'Course');
  
      $rowCount = 2;
      foreach ($dataProvider-&gt;getData() as $data)
      {
          $objPHPExcel-&gt;getActiveSheet()-&gt;SetCellValue('A' . $rowCount, $data['sd_fname']);
          $objPHPExcel-&gt;getActiveSheet()-&gt;SetCellValue('B' . $rowCount, $data['fk_mc_id']);
          $rowCount++;
      }
  
      header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
      header('Content-Disposition: attachment;filename="'.$fileName.'"');
  
      $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
      $objWriter-&gt;save('php://output');
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/QIsDg.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QIsDg.jpg" alt="enter image description here"></a>    }</p>