Laravel Maatwebsite Excel Set Cell Height and Width Example

By Hardik Savani April 16, 2024 Category : Laravel

This article will give you example of laravel maatwebsite excel column height and width. This post will give you simple example of how to set row height and column width in excel laravel php. This post will give you simple example of laravel excel cell height. you will learn laravel excel row height maatwebsite.

We will use setRowHeight() and setWidth() for set height and width 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()->getRowDimension('1')->setRowHeight(40);

$event->sheet->getDelegate()->getColumnDimension('A')->setWidth(50);

},

];

}

}

Output:

I hope it can help you...

Tags :
Shares