title: PHPExcel : CodeIgniter error on output
body: <p>I have this controller which renders my data from database to the PHPExcel library.</p>
  
  <blockquote>
    <p><a href="https://arjunphp.com/how-to-use-phpexcel-with-codeigniter/" rel="nofollow noreferrer">https://arjunphp.com/how-to-use-phpexcel-with-codeigniter/</a></p>
  </blockquote>
  
  <p>this is my controller :</p>
  
  <pre><code>public function downloadTournamentData() {
      $this-&gt;load-&gt;model("Tournament");
  
      $var_data = array();
  
      $var_data['tournament'] = $this-&gt;Tournament-&gt;getTournamentData();
  
      $this-&gt;load-&gt;library('excel');
  
      $this-&gt;excel-&gt;setActiveSheetIndex(0);
  
      $this-&gt;excel-&gt;getActiveSheet()-&gt;setTitle('test');
  
      $this-&gt;excel-&gt;getActiveSheet()-&gt;setCellValue('A1', 'member_username');
      $this-&gt;excel-&gt;getActiveSheet()-&gt;setCellValue('B1', 'member_name');
      $this-&gt;excel-&gt;getActiveSheet()-&gt;setCellValue('C1', 'member_phone');
      $this-&gt;excel-&gt;getActiveSheet()-&gt;setCellValue('D1', 'member_email');
      $this-&gt;excel-&gt;getActiveSheet()-&gt;setCellValue('E1', 'member_idcard');
      $this-&gt;excel-&gt;getActiveSheet()-&gt;setCellValue('F1', 'Date_created');
      $this-&gt;excel-&gt;getActiveSheet()-&gt;setCellValue('G1', 'team_name');
      $this-&gt;excel-&gt;getActiveSheet()-&gt;setCellValue('H1', 'warnet_name');
      $this-&gt;excel-&gt;getActiveSheet()-&gt;setCellValue('I1', 'warnet_cp');
      $this-&gt;excel-&gt;getActiveSheet()-&gt;setCellValue('J1', 'warnet_phone');
      $this-&gt;excel-&gt;getActiveSheet()-&gt;setCellValue('K1', 'region_name');
      $this-&gt;excel-&gt;getActiveSheet()-&gt;setCellValue('L1', 'City');
  
  
      $cell_inc = 2;
      foreach($var_data['tournament'] as $k =&gt; $v) {
          $this-&gt;excel-&gt;getActiveSheet()-&gt;setCellValue('A'.$cell_inc, $v['member_username']);
          $this-&gt;excel-&gt;getActiveSheet()-&gt;setCellValue('B'.$cell_inc, $v['member_name']);
          $this-&gt;excel-&gt;getActiveSheet()-&gt;setCellValue('C'.$cell_inc, $v['member_phone']);
          $this-&gt;excel-&gt;getActiveSheet()-&gt;setCellValue('D'.$cell_inc, $v['member_email']);
          $this-&gt;excel-&gt;getActiveSheet()-&gt;setCellValue('E'.$cell_inc, $v['member_idcard']);
          $this-&gt;excel-&gt;getActiveSheet()-&gt;setCellValue('F'.$cell_inc, $v['Date_created']);
          $this-&gt;excel-&gt;getActiveSheet()-&gt;setCellValue('G'.$cell_inc, $v['team_name']);
          $this-&gt;excel-&gt;getActiveSheet()-&gt;setCellValue('H'.$cell_inc, $v['warnet_name']);
          $this-&gt;excel-&gt;getActiveSheet()-&gt;setCellValue('I'.$cell_inc, $v['warnet_cp']);
          $this-&gt;excel-&gt;getActiveSheet()-&gt;setCellValue('J'.$cell_inc, $v['warnet_phone']);
          $this-&gt;excel-&gt;getActiveSheet()-&gt;setCellValue('K'.$cell_inc, $v['region_name']);
          $this-&gt;excel-&gt;getActiveSheet()-&gt;setCellValue('L'.$cell_inc, $v['City']);
  
          $cell_inc++;
      }
  
      date_default_timezone_set("Asia/Jakarta");
  
      $this_date = date("Y-m-d");
  
      $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="'.$filename.'"'); //tell browser what's the file name
      header('Cache-Control: max-age=0'); //no cache
  
      //save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
      //if you want to save it as .XLSX Excel 2007 format
      $objWriter = PHPExcel_IOFactory::createWriter($this-&gt;excel, 'Excel5');  
      //force user to download the Excel file without writing it to server's HD
      $objWriter-&gt;save('php://output');
  }
  </code></pre>
  
  <p>It does download the excel file. Only problem is that the data is mixed up and it's all wrong.</p>
  
  <p><img src="https://i300.photobucket.com/albums/nn19/GODHEAPER_dionpasc1809/data-error_zpsydgt0sik.jpg" alt="Screenshot of downloaded excel file"></p>
  
  <p>Why is this happening? Is there something wrong with my controller?</p>
  
  <p><strong>Please provide solution...</strong></p>