fileName = '新生回访统计数据-' . date('Y-m-d') . '.xlsx'; //拼接下载文件名称 $this->titles = ['学院基础信息', '', '总录取', '', '', '未联系', '', '']; foreach (UserFollowStatus::query()->orderBy('id', 'asc')->get('name')->toArray() as $key => $item) { $this->titles[] = $item['name']; $this->titles[] = ''; $this->titles[] = ''; } parent::__construct(); } public function export() { // TODO: Implement export() method. $this->download($this->fileName)->prepare(request())->send(); exit; } public function collection() { $data = $this->buildData(); $newData[2] = ['二级学院', '专业', '总人数', '男生', '女生', '总人数', '男生', '女生']; foreach (UserFollowStatus::query()->get('id')->toArray() as $key => $item) { $newData[2][] = '总人数'; $newData[2][] = '男生'; $newData[2][] = '女生'; } foreach ($data as $key => $item) { $newData[] = $item; } // TODO: Implement collection() method. return collect($newData); } public function headings(): array { // TODO: Implement headings() method. return $this->titles; } public function map($row): array { // 直接返回row 导出全部字段 dd($row); // return $row; foreach ($row as $k => $v) { $row[$k] = (string)$v; } // TODO: Implement map() method. return $row; } }