Laravel导出到excel并将文件保存到文件夹

时间:2018-08-12 03:17:07

标签: php excel laravel export maatwebsite-excel

我想将数据导出到excel并将其保存到folder_project / storage / excel / exports

但文件未保存到文件夹中。

我使用laravel和maatwebsite-excel。请帮我

$file = Excel::create('Export Data',function($excel) use($user){
    $excel->sheet('Sheet 1',function($sheet) use($user){
        $sheet->fromArray($user);
    });
})->save('xlsx', storage_path('excel/exports'), true);

1 个答案:

答案 0 :(得分:0)

尝试一下

Excel::create($sheetname, function($excel) use ($user) {
// Set the spreadsheet title, creator, and description
$excel->setTitle('Payments');
$excel->setCreator('Laravel')->setCompany('WJ Gilmore, LLC');
$excel->setDescription('payments file');

// Build the spreadsheet, passing in the payments array
$excel->sheet('sheet1', function($sheet) use ($user) {
$sheet->fromArray($user, null, 'A1', false, false);
});
})->download('xlsx');