why dont you use this package https://laravel-excel.com/
Apr 3, 2023
5
Level 8
Impossible to export large amount of data using: Spatie\SimpleExcel
Hello
I try to export a Sql query to excel file , but when the number of rows is bigger than 200k I get no results :
This page isn’t workinglocalhost didn’t send any data.
ERR_EMPTY_RESPONSE
This is my code :
$writer = SimpleExcelWriter::streamDownload('your-export.xlsx');
$starttimer = microtime(true);
$i = 0;
$this->sqlQuery('2022-05-01', '2022-12-15')->lazy() // a function returning the collection result
->each(function ($row) use (&$i, $writer) {
$i++;
$writer->addRow([
'date' => $row->date,
'user_name' => $row->user_name,
]);
if ($i % 100 === 0) {
flush(); // Flush the buffer every 1000 rows
}
});
$writer->toBrowser();
So as I said it works for low amount of data but if it's more than 200K!
any idea ?
Please or to participate in this conversation.