ItSolutionStuff.com

Laravel Maatwebsite Excel Set Background Color Example

By Hardik Savani • April 16, 2024
Laravel

Here, i will show you laravel maatwebsite excel set background color. if you have question about laravel excel sheet set background color then i will give simple example with solution. This article goes in detailed on how to set background color in excel cell heading laravel php. step by step explain phpexcel set background color laravel. Let's get started with laravel maatwebsite background color.

We will use WithEvents and AfterSheet for set background color of column in laravel maatwesite composer package. you can use this example with laravel 6, laravel 7, laravel 8, laravel 9, laravel 10 and laravel 11 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')

->getFill()

->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)

->getStartColor()

->setARGB('DD4B39');

},

];

}

}

Output:

I hope it can help you...

Tags: Laravel
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

How to Validate Excel Sheet Data in Laravel?

Read Now →

Laravel 8 Stripe Payment Gateway Integration Example

Read Now →

Laravel 8 Get Current Logged in User Data Example

Read Now →

Laravel 8 Inertia JS CRUD with Jetstream & Tailwind CSS

Read Now →

Laravel 8 Yajra Datatables Example Tutorial

Read Now →

Laravel 8 Import Export Excel and CSV File Tutorial

Read Now →

Laravel 8 Authentication using Jetstream Example

Read Now →

Laravel Yajra Datatables Export to Excel CSV Button Example

Read Now →

How to add header row in export excel file with maatwebsite in Laravel 5.8?

Read Now →

PHP Import Excel File into MySQL Database Tutorial

Read Now →

Laravel Export to PDF using Maatwebsite Example

Read Now →