如何解决Laravel Excel导出队列和MultipleSheet
我尝试将Laravel excel与多个工作表和shouldQueue
一起使用,但是该文件返回了一个空工作表,尽管所有工作表都已成功创建。
解决方法
我设法限制每个文件的记录
这是代码
<?php
namespace App\Exports;
use App\Exports\Sheets\AnswersPerSchoolSheet;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\DB;
use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
class AnswersExport implements WithMultipleSheets,ShouldQueue
{
use Exportable;
public function __construct($start,$end)
{
$this->start = $start;
$this->end = $end;
}
public function sheets(): array
{
$sheets = [];
$schools = DB::table('schools')
->join('answers','schools.id','=','answers.school_id')
->select('schools.id')
->distinct('schools.id')
->whereBetween('schools.id',[$this->start,$this->end])
->get();
foreach ($schools as $school) {
$sheets[] = new AnswersPerSchoolSheet($school->id);
}
return $sheets;
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。