【问题标题】:How to design excel sheet using maatwebsite in laravel如何在 laravel 中使用 maatwebsite 设计 excel 表格
【发布时间】:2018-06-23 07:39:41
【问题描述】:

我已经使用laravel 中的maatwebsite 包导出了excel CSV 文件。但是当我导出它时,它会显示原始数据,我该如何设计这个excel来分别显示每个数据和它的标题。

这里是我导出的数据图片链接。 http://prntscr.com/i08up8 这是excel导出代码。

 public function export()
{
  $items = DB::table('userinformations')
        ->join('users', 'userinformations.user_id', '=', 'users.id')
        ->select('userinformations.fname','userinformations.lname','users.email')
        ->where('userinformations.payment_status',1)
        ->get();
    $items=array($items);
  Excel::create('items', function($excel) use($items) {
      $excel->sheet('ExportFile', function($sheet) use($items) {
          $sheet->fromArray($items);
      });
  })->export('csv');
}

【问题讨论】:

    标签: php laravel maatwebsite-excel


    【解决方案1】:

    问题出在下面一行:

     $items=array($items);
    

    Laravel 返回一个集合。所以这意味着你将整个集合放在一个(一个)数组中。

    试试这个:

    $items = $items->toArray(); 
    

    这会将您的收藏转换为一个数组,应该可以解决您的问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-30
      • 2018-02-28
      • 1970-01-01
      • 2017-11-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多