目前我用phpspeadsheet導出excel文件,是存為文件然后再respon的。
有沒有方法直接輸出而不用輸出實體文件?
找到一個方法,共享一下:
$writer = new Xlsx($spreadsheet);
$response = response();
ob_start();
$writer->save('php://output');
$c = ob_get_contents();
ob_flush();
flush();
$response->withHeaders([
'Content-Type' => 'application/vnd.ms-excel',
'Content-Disposition' => 'attachment;filename="xxx.xlsx"',
'Cache-Control' => 'max-age=0',
])->withBody($c);
return $response;