2016-04-07 57 views
1

http://imgur.com/fypWZgy更改標題excel導出php laravel

下面是我試圖導出它時所具有的功能。它默認使用屬性鍵。我想把它改成我自己的標題。例如payStatus支付。

這裏是我的代碼:

public function exportReferral($sourceRef){ 
    ob_end_clean(); 
    ob_start(); //At the very top of your program (first line) 
    \Excel::create('ViecBonus ' . 'referal report', function($excel) use ($sourceRef) { 
      $excel->sheet('ViecBonus Data', function($sheet) use ($sourceRef) { 
       $sheet->fromModel($sourceRef); 
      }); 
    })->export('xlsx'); 
} 

回答

0

怎麼是這樣的:

\Excel::create('ViecBonus ' . 'referal report', function($excel) use ($sourceRef) { 
    $excel->sheet('ViecBonus Data', function($sheet) use ($sourceRef) { 
     $sheet->appendRow(['some', 'custom', 'headers', 'here']); 
     foreach ($sourceRef as $source) { 
      $sheet->appendRow((array)$source); 
     } 
    }); 
})->export('xlsx'); 

```

0

傳遞到Excel之前,我會去轉換數據:YourModel::select(['real_column as heading_name']),然後您的最終文件標題將不是real_column,而是heading_name