我已经找到了下载csv的方法。
\Response::macro('attachment', function ($content) {
$headers = [
'Content-type' => 'text/csv',
'Content-Disposition' => 'attachment; filename="download.csv"',
];
return \Response::make($content, 200, $headers);
});
return response()->attachment($content);
但是,如何与PhpSpreadsheet一起使用它,以便我可以不保存而下载它?有办法实现吗?
$header = array("Customer Number", "Customer Name", "Address", "City", "State", "Zip");
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->fromArray([$header], NULL, 'A1');
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
$writer->save(storage_path('app/' . "abc.xlsx"));
return response()->attachment($writer);