Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Magalliu's avatar

Maatwebsite\Excel returning complex table `FromView` takes too long

I have a complex excel which I managed to build using FromView interface. I had to use FromView because I have to manage different rowspans but the problem is that it goes on Maximum execution time of 60 seconds exceeded error for more then 500+ rows and it needs like 15 sec for just 100 rows.

Link with how I implemented the export: https://ibb.co/9VcZKDj

The data of the model I'm returning has 5 related tables (hasOne) which are being mapped on the final excel also.

Inside the view I make different foreach in order to map data as required. Link with image of the view: https://ibb.co/k8WG2jm

Link with image of a part of the excel I have generated for 100 rows: https://ibb.co/NpzC9yq

Any idea on how to achieve this. Thank you!

P.S. I'm not considering using a queue job because the rows at their max will be 2000.

0 likes
2 replies
Nakov's avatar

And what is the reason for not considering queue? You want the user whoever that is to wait for the excel to be exported, even though it takes more than a minute in your case?

If you are happy with that, then maybe increasing the timeout will work for you:

If it takes 15 seconds for 100 rows, then it will take at least 5 minutes for 2000 rows.

ini_set('max_execution_time', 300); // 5 minutes
Magalliu's avatar
Magalliu
OP
Best Answer
Level 2

@Nakov Thank you for your answer but I really want to avoid the queues. I can't stay in peace just queuing it knowing that it is only about 2000 rows.

Anyway I did managed without using FromView but using WithMapping and WithEvents in which I did hard coded the customization of the cells with PhpSpreadsheet helpers and it takes like 1.7-1.8 sec for 2000 rows.

What I do is merging the cells and setting the value like this:

$sheet->mergeCells('B'.$startingKey.':B'.$endingKey);
$sheet->setCellValue('B'.$startingKey, $participant->agency->corporation);

Please or to participate in this conversation.