Php Excel::download()返回空/空白页,即使在返回后也是如此
这是我的环境Php Excel::download()返回空/空白页,即使在返回后也是如此,php,laravel,laravel-6,maatwebsite-excel,php-7.4,Php,Laravel,Laravel 6,Maatwebsite Excel,Php 7.4,这是我的环境 php : 7.4.2 laravel : 6.14.0 maatwbsite-excel : 3.1.18 这是导出文件 namespace App\Exports; use Illuminate\Support\Collection; use Maatwebsite\Excel\Concerns\Exportable; use Maatwebsite\Excel\Concerns\FromArray; class UserReportsExport implements
php : 7.4.2
laravel : 6.14.0
maatwbsite-excel : 3.1.18
这是导出文件
namespace App\Exports;
use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\FromArray;
class UserReportsExport implements FromArray
{
use Exportable;
protected $export_columns;
function __construct($export_columns)
{
$this->export_columns = $export_columns;
}
public function array(): array
{
return [
$this->export_columns
];
}
}
这是控制器
return Excel::download(new UserReportsExport($export_columns), 'Users_Report_' . $todayDate . '.xlsx');
以下是接近问题的答案。根据建议的解决方案,我在控制器中使用return
,但页面仍然是空的,但在我的/tmp
文件夹中,会生成一个.zip
像laravel excel-***
(它包含的都是.xml文件)
不知道我错过了什么。请建议。谢谢。查看它,您需要删除返回[$this->exports\u columns]
中的括号,这样它就变成了返回$this->exports\u columns
如果它仍然不起作用,那么您可能需要调用ob_end_clean()返回下载链接之前的代码>。在关闭?>
后可能会有一个尾随空格,或者在某个地方有一个var_转储或一个回音,这会扰乱程序流和正在设置的头。如果它开始处理这个问题,请检查您的代码,通过发送早期输出,您已经把您的头弄乱了
ob_end_clean();
return Excel::download(new UserReportsExport($export_columns), 'Users_Report_' . $todayDate . '.xlsx');
此外,如果您还没有,请为所有内容启用错误报告。它可能会给你一些有意义的回报。如果您得到一个空白页面,听起来像是关闭了错误报告的错误500。检查您的php日志
我能想到的最常见的错误是在这种情况下:无法修改头,头已经发送。请阅读查看它,您需要删除return[$this->exports\u columns]
中的括号,使其成为return$this->exports\u columns
如果它仍然不起作用,那么您可能需要调用ob_end_clean()返回下载链接之前的代码>。在关闭?>
后可能会有一个尾随空格,或者在某个地方有一个var_转储或一个回音,这会扰乱程序流和正在设置的头。如果它开始处理这个问题,请检查您的代码,通过发送早期输出,您已经把您的头弄乱了
ob_end_clean();
return Excel::download(new UserReportsExport($export_columns), 'Users_Report_' . $todayDate . '.xlsx');
此外,如果您还没有,请为所有内容启用错误报告。它可能会给你一些有意义的回报。如果您得到一个空白页面,听起来像是关闭了错误报告的错误500。检查您的php日志
我能想到的最常见的错误是在这种情况下:无法修改头,头已经发送。请阅读