gpt4 book ai didi

Laravel - 下载 PhpSpreadsheet 之前不保存

转载 作者:行者123 更新时间:2023-12-05 07:32:11 25 4
gpt4 key购买 nike

我找到了这种下载 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);

最佳答案

$writer = new Xlsx($spreadsheet);
$writer->save($path = storage_path('hello world.xlsx'));

return response()->download($path)->deleteFileAfterSend();

关于Laravel - 下载 PhpSpreadsheet 之前不保存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51430698/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com