Export large Excel/CSV (10-20K records) I need to export Excel (CSV is ok) where will be about 10-20K records. I tried to export the package Maatwebsite/Laravel-Excel ( https://github.com/Maatwebsite/Laravel-Excel ). it works perfectly for small amount of records but does not work for this large files.
what could be the way around of this situation?
Maybe try spout - it's a lot lighter than the php excel. It doesn't do everything that php excel does, but for straight xls it's pretty fast.
Make chunks of the files. I have been using this to export over 100k rows from database into excel files
const MAX_CHUNK_ROWS = 2500;
...
$backupRowsCount = count($this->exportData)
$current = 0;
while ($current < $backupRowsCount) {
$next = $current + self::MAX_CHUNK_ROWS;
if (is_array($this->exportData)) {
$chunk = array_slice($this->exportData, $current, self::MAX_CHUNK_ROWS, true);
}
else {
$chunk = $this->exportData->slice($current,self::MAX_CHUNK_ROWS, true);
}
$command->exportName .= "{$current}_{$next}";
$command->exportData = $chunk;
$command->exportFile();
$current += self::MAX_CHUNK_ROWS;
$percent = ($next / $backupRowsCount) * 100;
$this->comment("{$next} rows exported to {$command->exportName} [{$percent}%]");
$command->exportName = $oldExportName;
}
Just use https://csv.thephpleague.com/ , its extremely faster, exported 75k in less than 1 min, and less than 3mins using background queue worker
Please sign in or create an account to participate in this conversation.