title: exporting data to excel in codeigniter usingt php excel library error
body: <p>i am trying to export data from my table to excel file using php excel library, my controller is like below:</p>
  <pre><code>public function exportexcel() {
      $this-&gt;load-&gt;model(&quot;excel_import_model&quot;);
  
      $var = $this-&gt;excel_import_model-&gt;excelexport();
      $this-&gt;load-&gt;library('excel');
  
      $object = new PHPExcel();
      $object-&gt;setActiveSheetIndex(0);
  
      $table_columns = array(&quot;Name&quot;, &quot;Address&quot;, &quot;Gender&quot;, &quot;Designation&quot;, &quot;Age&quot;);
  
      $column = 0;
  
      foreach($table_columns as $field) {
          $object-&gt;getActiveSheet()-&gt;setCellValueByColumnAndRow($column, 1, $field);
          $column++;
      }
  
      $employee_data = $this-&gt;excel_import_model-&gt;excelexport();
  
      $excel_row = 2;
  
      foreach($employee_data as $row) {
          $object-&gt;getActiveSheet()-&gt;setCellValueByColumnAndRow(0, $excel_row, $row-&gt;sendername);
          $object-&gt;getActiveSheet()-&gt;setCellValueByColumnAndRow(1, $excel_row, $row-&gt;sendercity);
          $object-&gt;getActiveSheet()-&gt;setCellValueByColumnAndRow(2, $excel_row, $row-&gt;senderphone);
          $object-&gt;getActiveSheet()-&gt;setCellValueByColumnAndRow(3, $excel_row, $row-&gt;awb);
          $object-&gt;getActiveSheet()-&gt;setCellValueByColumnAndRow(4, $excel_row, $row-&gt;sendermobile);
          $excel_row++;
      }
      date_default_timezone_set(&quot;Asia/Jakarta&quot;);
      $this_date = date(&quot;Y-m-d&quot;);
      $filename='pb_turnamen_data-'.$this_date.'.xls'; //save our workbook as this file name
      header('Content-Type: application/vnd.ms-excel; charset=UTF-8'); //mime type
      header('Content-Disposition: attachment;filename=&quot;'.$filename.'&quot;'); //tell browser what's the file name
      header('Cache-Control: max-age=0'); //no cache
  
      $objWriter = PHPExcel_IOFactory::createWriter($this-&gt;excel, 'Excel5');
      ob_end_clean();
      $objWriter-&gt;save('php://output');
  }
  </code></pre>
  <p>and my model is like beloww:</p>
  <pre><code>function excelexport()
  {
     $this-&gt;db-&gt;order_by(&quot;id&quot;, &quot;DESC&quot;);
     $query = $this-&gt;db-&gt;get(&quot;consignments&quot;);
     return $query-&gt;result();
  }
  </code></pre>
  <p>while clicking the button, the excel file is being downloaded but the file is being displayed like in the below image:
  <a href="https://i.stack.imgur.com/8whOc.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8whOc.jpg" alt="enter image description here" /></a>
  <a href="https://i.stack.imgur.com/LkwQl.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LkwQl.jpg" alt="enter image description here" /></a></p>
  <p>can anyone please tell me what is wrong in here, thanks in advance</p>