所以基本上得到了laravel项目并在excel中导出表。我正在使用this进行导出。到目前为止,我只从数组或在我的情况下导出。
public function exportGames()
{
$export = Games::all();
Excel::create('Games Data', function($excel) use($export){
$excel->sheet('Games', function($sheet) use($export){
$sheet->fromArray($export);
});
})->export('xlsx');
}然而,这将返回完整的表数据,其中包括一些要消失的字段i(时间戳等)。此外,关系表也不能显示(仅在页面上的实际表中)。花了几个小时在文档中仍然不知道该怎么做。想把我的头发扯下来。如何修改要导出的列。谢谢你的建议。
发布于 2016-08-12 15:15:28
看起来很简单:
$export = Games::select(['client_game_id', 'client_game_name', 'gameid', 'description', 'game_type', 'db_name', 'short_name'])->get();您只能在导出的XLS文件中看到这些列。
发布于 2020-09-26 02:21:17
你可以这样做
$export = Games::all();
Excel::create('Games Data', function($excel) use($export){
$excel->sheet('Games', function($sheet) use($export){
foreach ($export as $key => $value) {
$exports[] = array('email' => $value['email'], 'name' =>$value['name']);
}
$sheet->fromArray($exports);
});
})->export('xlsx');https://stackoverflow.com/questions/38910973
复制相似问题