Guest User

Untitled

a guest
Aug 18th, 2019
76
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class CustomersExportStyling implements FromCollection, WithEvents
  2. {
  3. public function collection()
  4. {
  5. return User::all();
  6. }
  7.  
  8. public function registerEvents(): array
  9. {
  10. return [
  11. AfterSheet::class => function(AfterSheet $event) {
  12. // All headers - set font size to 14
  13. $cellRange = 'A1:W1';
  14. $event->sheet->getDelegate()->getStyle($cellRange)->getFont()->setSize(14);
  15.  
  16. // Apply array of styles to B2:G8 cell range
  17. $styleArray = [
  18. 'bord ers' => [
  19. 'outline' => [
  20. 'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THICK,
  21. 'color' => ['argb' => 'FFFF0000'],
  22. ]
  23. ]
  24. ];
  25. $event->sheet->getDelegate()->getStyle('B2:G8')->applyFromArray($styleArray);
  26.  
  27. // Set first row to height 20
  28. $event->sheet->getDelegate()->getRowDimension(1)->setRowHeight(20);
  29.  
  30. // Set A1:D4 range to wrap text in cells
  31. $event->sheet->getDelegate()->getStyle('A1:D4')
  32. ->getAlignment()->setWrapText(true);
  33. },
  34. ];
  35. }
  36. }
RAW Paste Data