| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 | <?phpnamespace App\Exports;use Illuminate\Support\Collection;use Maatwebsite\Excel\Concerns\FromCollection;use Maatwebsite\Excel\Concerns\WithCustomValueBinder;use Maatwebsite\Excel\Concerns\WithHeadings;use Maatwebsite\Excel\Concerns\WithStrictNullComparison;    // 导出 0 原样显示,不为 nulluse PhpOffice\PhpSpreadsheet\Cell\DefaultValueBinder;class TableHeadExport extends DefaultValueBinder implements WithCustomValueBinder , FromCollection, WithStrictNullComparison,withHeadings{    /**     * @return \Illuminate\Support\Collection     */    public function __construct($data,$headers)    {        $this->data = $data;        $this->headers = $headers;    }    //数组转集合    public function collection()    {        return new Collection($this->createData());    }    //业务代码    public function createData()    {        $data = $this->export();        return $data;    }    // 自定义表头,需实现withHeadings接口    public function headings(): array    {        return $this->headers;    }    private function export(){        $list = [];//        dump($this->data);die;        foreach ($this->data as $v){            $list[] = $v;        }        return $list;    }}
 |