data = $data; $this->startDate = $startDate; $this->endDate = $endDate; } public function array(): array { return $this->data; } public function startCell(): string { // Headings start on row 2 return 'A2'; } public function headings(): array { $headings = [ 'Plant Name', 'Line Name', 'Item Code', 'Category', 'Non Planned Production', ]; return $headings; } public function map($row): array { $mapped = [ $row['plant_name'] ?? '', $row['line_name'] ?? '', $row['item_code'] ?? '', $row['item_category'] ?? '', $row['total_qty'] ?? '', ]; return $mapped; } public function registerEvents(): array { return [ AfterSheet::class => function (AfterSheet $event) { $sheet = $event->sheet->getDelegate(); $start = Carbon::parse($this->startDate) ->format('d-m-Y h:i:s A'); $end = Carbon::parse($this->endDate) ->format('d-m-Y h:i:s A'); // First row: merge five columns $sheet->mergeCells('A1:E1'); $sheet->setCellValue( 'A1', "Report date from {$start} to {$end}" ); // Style report title $sheet->getStyle('A1:E1')->applyFromArray([ 'font' => [ 'bold' => true, 'size' => 12, ], 'alignment' => [ 'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER, 'vertical' => \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER, ], ]); $sheet->getRowDimension(1)->setRowHeight(25); // Style headings $sheet->getStyle('A2:E2')->getFont()->setBold(true); }, ]; } }