2015-11-02 92 views

回答

8

SO,我問了一個問題,別人誰也答不上來,但懦弱授予-1。不過,我想它是如何手動完成的。發佈代碼,這樣可以幫助像我這樣的未來初學者。

public function downloadSummary(){ 

     Excel::create('records', function($excel) { 

      $excel->sheet('Sheet1', function($sheet) { 
       $employees = Employee::all(); 

       $arr =array(); 
       foreach($employees as $employee) { 
        foreach($employee->sims as $sim){ 
         $data = array($employee->id, $employee->name, $employee->nic, $employee->address, $employee->title, 
          $sim->id, $sim->msisdn, $sim->imei, $sim->issued_to); 
         array_push($arr, $data); 
        } 
       } 

       //set the titles 
       $sheet->fromArray($arr,null,'A1',false,false)->prependRow(array(
         'Employee Id', 'Employee Name', 'Employee NIC', 'Employee Address', 'Employee Title', 
         'Sim Id', 'Sim MSISDN', 'IMEI', 'Issued To' 
        ) 

       ); 

      }); 

     })->export('xls'); 
    }