data = $data; $this->headers = $headers; } public function array(): array { return $this->data; } public function registerEvents(): array { return [ AfterSheet::class => function (AfterSheet $event) { $sheet = $event->sheet->getDelegate(); // Freeze first row $sheet->freezePane('A2'); // Auto filter for all header columns $columnCount = count($this->headers); $lastColumnLetter = \PhpOffice\PhpSpreadsheet\Cell\Coordinate::stringFromColumnIndex($columnCount); $sheet->setAutoFilter("A1:{$lastColumnLetter}1"); // Style each header with individual colors foreach ($this->headers as $index => $header) { $cell = \PhpOffice\PhpSpreadsheet\Cell\Coordinate::stringFromColumnIndex($index + 1) . '1'; $sheet->getStyle($cell)->applyFromArray([ 'font' => ['bold' => true, 'color'=> ['rgb' => isset($header['fontcolor']) ? $header['fontcolor'] : 'FFFFFF']], 'fill' => [ 'fillType' => Fill::FILL_SOLID, 'startColor' => ['rgb' => $header['color']], ], ]); } }, ]; } }