Laravel-excel: Chunking Export

Created on 16 Apr 2016  路  10Comments  路  Source: Maatwebsite/Laravel-Excel

Is it possible to chunk export (with PDF::loadView)?

I have about 70,000 rows to export and I am hitting a timeout.

Most helpful comment

An example of how to do this:

Excel::create('ExcelFile', function($excel) {
    $excel->sheet('Sheet1', function($sheet) {
        ExampleModel::chunk(500, function($modelInstance) use($sheet) {

            $modelAsArray = $modelInstance->toArray();
            $sheet->appendRow($modelAsArray);
        });
    });
})->export('xls');

All 10 comments

I'm wondering the same thing. When I try to export a dataset which contains 100K+ records I have timeout problems. But when I try to chunk the results, I only have the first chunk in de export:

$getData->contacts()->chunk(5000, function($chunkContacts) use ($row, $sheet)
    {

        foreach( $chunkContacts as $contact )
        {

            # Add contact to file
            $sheet->row( $row, [ $contact->email,
                                 $contact->firstname,
                                 $contact->lastname,
            ] );

            $row++;

        }
    });

It appears that the chunk method generated some kind of output which causes the Excel file to be created immediately.

I have a similar issue, would appreciate if someone has figured it out.

Same issue here, can't export 20,000 rows and it takes a long time.

Any new info on this?

Same problem, is there any update of this problem? When i export 33.000 rows with 10 colums i had no problem. When i export the 33.000 rows with the 11the colum than i have the problem.

Is there other solution for exporting thousands of row that is fast enough?

An example of how to do this:

Excel::create('ExcelFile', function($excel) {
    $excel->sheet('Sheet1', function($sheet) {
        ExampleModel::chunk(500, function($modelInstance) use($sheet) {

            $modelAsArray = $modelInstance->toArray();
            $sheet->appendRow($modelAsArray);
        });
    });
})->export('xls');

Interesting solution to just 'invert' the logic! I'm curious if it helps other people who experienced the same problem.

How is this task performed with v3.0?

Was this page helpful?
0 / 5 - 0 ratings