Laravel Maatwebsite Excel Set Font Color Example

By Hardik Savani August 27, 2021 Category : Laravel

Here, i will show you laravel maatwebsite excel set font color. i would like to share with you laravel excel font color. if you want to see example of laravel maatwebsite getColor() then you are a right place. step by step explain how to add font color in laravel excel maatwebsite.

We will use getColor() for set font color in laravel maatwesite composer package. you can use this example with laravel 6, laravel 7 and laravel 8 version.

You can follow bellow url for checking full example of Import and Export Excel File with laravel. Here i will give you solution with export class:

Laravel Import Export Excel and CSV File Tutorial

Solution:

app/Exports/UsersExport.php

<?php

namespace App\Exports;

use App\Models\User;

use Maatwebsite\Excel\Concerns\FromCollection;

use Maatwebsite\Excel\Concerns\WithHeadings;

use Maatwebsite\Excel\Concerns\WithEvents;

use Maatwebsite\Excel\Events\AfterSheet;

class UsersExport implements FromCollection, WithHeadings, WithEvents

{

/**

* Write code on Method

*

* @return response()

*/

public function collection()

{

return User::select("id", "name", "email")->get();

}

/**

* Write code on Method

*

* @return response()

*/

public function headings() :array

{

return [

'ID',

'Name',

'Email',

];

}

/**

* Write code on Method

*

* @return response()

*/

public function registerEvents(): array

{

return [

AfterSheet::class => function(AfterSheet $event) {

$event->sheet->getDelegate()->getStyle('A1:C1')

->getFont()

->getColor()

->setARGB('DD4B39');

},

];

}

}

Output:

I hope it can help you...

Tags :