laravel excel只获取当前数据

我刚开始使用这个excel pakage maatwebsite / excel,我设法下载了excel。 但是,在创buildexcel时遇到一些困难

  1. 如何更改Excel中打印的date格式? 我看到有人用这样的东西,但为什么不能开展工作?

$ sheet-> setColumnFormat(array('E'=>'d / m / y'));

  1. 如何从今天获取数据? 例如,我input了一些数据并保存到数据库中,当我下载excel时,它只显示数据而不显示过去的数据。 我怎么做?

  2. 有没有可能改变Excel的标题? 例如created_at更改为date

目前这里是我的代码:

public function downloadExcel($type) { $data = personal_info::join('qualifications', 'qualifications.user_id', '=', 'personal_infos.id') ->select( 'personal_infos.id', 'personal_infos.name', 'personal_infos.email', 'qualifications.qualification', 'personal_infos.created_at') ->get() ->sortByDesc('created_at'); return Excel::create('test', function($excel) use ($data) { $excel->sheet('mySheet', function($sheet) use ($data) { $sheet->fromArray($data); $sheet->setColumnFormat(array('E' => 'd/m/y')); }); })->download($type); } 

如果你想要今天的数据,然后在你的查询条件添加如下: –

 $todaydate = date('Ym-d'); $data = personal_info::join('qualifications', 'qualifications.user_id', '=', 'personal_infos.id') ->select( 'personal_infos.id', 'personal_infos.name', 'personal_infos.email', 'qualifications.qualification', 'personal_infos.created_at') ->where('personal_infos.created_at',$todaydate) // or you can use whereDate() of laravel like :- whereDate('personal_infos.created_at', '=', date('Ym-d')); ->get(); 

是的,可以更改created_atDate你需要给别名: –

 enter code here $data = personal_info::join('qualifications', 'qualifications.user_id', '=', 'personal_infos.id') ->select( 'personal_infos.id', 'personal_infos.name', 'personal_infos.email', 'qualifications.qualification', 'personal_infos.created_at as Date') //here you can change the name ->where('Date',$todaydate) // then you need to change in where condition also ->get(); 

希望它可以帮助你!