First, Excel has a hard line limit, a large one, but a bit more than 1 million lines.
Second, Laravel Excel uses PhpSpreadsheet under the hood, and don't take me wrong, they are my go to tool to export excel files as they make adding format and other features very easy, but as you already noticed, they are very memory intensive, so even for datasets large enough but not close to 1 million records you would need to give PHP lots of memory and execution time, which is hard to predict how much.
Third, these are my suggestions:
- If CSV is ok, take a look at
league/csv- I use it for large datasets as you can stream the contents to a file, it is very lightweight on memory
- If you need Excel, there is a Spatie package for that:
spatie/simple-excel- It is a wrapper around
box/spout, which can export native Excel using generators (you don't need to write those yourself) to be memory lightweight - It provides some formatting features, but not as easy, nor as extensive as Laravel Excel
- It is a wrapper around
Good Luck!