Troubleshoot downloads

Most libraries like PHPSpreadSheet seems to use PHP buffer. And depending on your PHP configuration some warnings or errors could interfer with the output.

Let’s examine the output before the Excel-file is written:


ob_end_clean(); 
ob_start(); 

$writer = new Xlsx($spreadsheet);
$writer->save('hello-world.xlsx');

// hello-world.xlsx no longer corrupt

If this works, you have something in your output buffer already. Let’s find it.


dd(ob_get_contents());

// "\n"

A blank line, let’s find and remove it. Somewhere the is probably a php-file that starts with a blank line.