Documentation says the following:
// ...
use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Events\AfterSheet;
class UsersExport implements FromCollection, WithHeadings, ShouldAutoSize, WithEvents
{
// ...
/**
* @return array
*/
public function registerEvents(): array
{
return [
AfterSheet::class => function(AfterSheet $event) {
$cellRange = 'A1:W1'; // All headers
$event->sheet->getDelegate()->getStyle($cellRange)->getFont()->setSize(14);
},
];
}
}
Where $cellRange = 'A1:W1';
is range what I want to change.
I use collections method to get all data from db:
class VisitorsExport implements FromCollection, WithHeadings, WithEvents
{
public function collection()
{
return $visitors = Visitor::all();
}
}
Could I iterate result $visitors
and assign color for concrete row?
I mean like this:
$visitors->map(function($item) {
if($item->id == 1) {
$item->cell()->style()->backgroundcolor('#ccc');
}
});
I tried this code:
Excel::store($sheet, $path.$filename, function($excel) {
$excel->sheet('Sheetshit', function($sheet) use($main_arr) {
dd($main_arr);
});
});