How to Set Font Color in Laravel Maatwebsite Excel ?

Share Me
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Today now in this post i will show you How to Set Font Color in Laravel Maatwebsite Excel ? Now here, i will give you an example of laravel maatwebsite excel how to set font color. Here i would like to share with you about laravel excel font color. if you want to know about example of laravel maatwebsite function getColor() then i hope you are a right place. So now we will see this step by step also with explain how to add font color in laravel excel maatwebsite.

We will use here getColor() for set the font color in our laravel maatwesite composer package. Now we can also use this example with laravel 5.*,laravel 6, laravel 7 and laravel 8 any version.

Just you need to follow the bellow steps for your solutions. In bellow i will show you the solution of How to Set Font Color in Laravel Maatwebsite Excel ?:

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');
   
            },
        ];
    }
}

Read Also :Laravel Join with Subquery in Query Builder Example

Thanks for read. I hope it help you. For more you can follow us on facebook.

About Shahriar Sagor

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Shahriar Sagor →