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

gretschduojet's avatar

Laravel Excel adding extra empty rows

I'm trying to use Laravel Excel to export an array into an excel file. However, if there are 10 elements in the array Laravel Excel exports the excel file with the 10 items, but an empty row in between each one. I can't seem to figure out what I'm doing wrong.

Here is my code for exporting the excel file:

Excel::create($filename, function($excel) use ($codeArray){
            $excel->sheet('Sheetname', function($sheet) use ($codeArray){
                foreach($codeArray as $key => $code)
                {
                    $sheet->fromArray(array(
                        array($code)
                    ));
                }
            });
        })->download('xls');

Thank you in advance for the help.

0 likes
2 replies
graham's avatar
graham
Best Answer
Level 12

What's in $codeArray prior to creating the excel doc?

gretschduojet's avatar

Thank you for your reply - it was an issue with the array that I completely missed.

Please or to participate in this conversation.