title: Taking too long to export excel using spout library with php & mysqli?
body: <p>I am facing a problem at the time of generating excel using spout library. It is taking forever to complete. I have a large amount of data to export. This is going to generate at least 600 rows and 98 columns in excel.</p>
  
  <pre><code>require(APPPATH .'libraries/spout/src/Spout/Autoloader/autoload.php');  
  $this-&gt;load-&gt;model('Report_model','report');
  $pay_ele = $this-&gt;report-&gt;pay_elements_data();// iT has 70+ codes like 
  hra,Da etc.
  $pay_code = '';
  $array = [];
  array_push($array,'E- 
  ID','Name','Month','Year','Department','Grade','Accno','Bank 
  Name','IFSC','Aadhar','PFNo','ESI','PAN','Working 
  Days','Holidays','Weekoffs','Presents','Leaves','Absents');
  foreach( $pay_ele as $pay) {
  array_push($array,$pay-&gt;code);
  }
  array_push($array, 'Gross Pay');
  array_push($array, 'Net Pay');
  $writer-&gt;addRowWithStyle($array, $style);
  if(empty($employee_id)) {
  $employees  = $this-&gt;report-&gt;find_all_employee_ids();
  }
  foreach ( $employees as $emp) {
  $employee_id    = $emp-&gt;employee_id;
  $name           = $emp-&gt;full_name;
  $department     = $emp-&gt;company_department;
  $grades         = $emp-&gt;category_code;
  $bank_details       = $this-&gt;report-&gt;find_bank_details($employee_id);
  $p_det              = $this-&gt;report-&gt;personal_detail($employee_id);
  $mon_dat  = $this-&gt;report-&gt;find_all_monhtlydata($employee_id,$month,$year);
  if(!empty($mon_dat)) {
  foreach ( $mon_dat as $mondata) {
  $absent_days    = $mondata-&gt;absent_days; 
  $present_days       = $mondata-&gt;present_days;
  $working_days   = $mondata-&gt;working_days;
  $holidays       = $mondata-&gt;holidays;
  $week_off       = $mondata-&gt;week_off;
  $leave_days     = $mondata-&gt;leave_days;
  }
  }
  foreach( $bank_details as $bank) {
  $acc_number = $bank-&gt;account_number;
  $bank_name = $bank-&gt;bank_name;
  $ifsc_code = $bank-&gt;ifsc_code;
  }
  $data1 = [$employee_id,$name,$month,$year,$department,$grades,$acc_number,
            $bank_name,$ifsc_code,$addhar,$pf,$esi,$pan,$working_days];
  $gtotAmt = 0;
  $totAmt = 0;
  foreach( $pay_ele as $pay) {
  $n_data = $this-&gt;report-&gt;find_pay_ledger_data_withparametrs
            ($employee_id,$month,$year,$department,$pay-&gt;code);
  $amt = 0;
  foreach( $n_data as $dat) {
  $amt = round($dat-&gt;amount,2);
  $totAmt += round($dat-&gt;amount,2);
  if($pay-&gt;type == 'ADDITION') {
  $gtotAmt += round($dat-&gt;amount,2);
  } }
  array_push($data1,$amt); 
  }
  array_push($data1,$gtotAmt);
  array_push($data1,$totAmt);
  $writer-&gt;addRow($data1);
  }
  $writer-&gt;close();
  if (file_exists($filePath)
  header('Content-Description: File Transfer');
  header('Content-Type: application/octet-stream');
  header('Content-Disposition: attachment; 
  filename="'.basename($filePath).'"');
  header('Expires: 0');
  header('Cache-Control: must-revalidate');
  header('Pragma: public');
  header('Content-Length: ' . filesize($filePath));
  readfile($filePath);
  exit;
  }
  </code></pre>
  
  <p>I want to export excel in very fast mode but actually it is taking more than 2 hours. For few employees it is generating excel very fast but not for 500+ employees.</p>