1 year ago

Formatting exported excel file

Posted 1 year ago by konrms

Hello guys!

I use the maatwebsite/excel package to produce excel files from database tables. The export is successful, but I need some help with formatting it.

In fact I want the excel to have bigger font size for headings, highlighted headings and borders.

So far I have succeeded only in creating bigger size header fonts using setSize() as you can see in my code excerpt.

My exports file (C:\xampp\htdocs\laravel\app\Exports\MembersExport.php) is the following:


namespace App\Exports;

use App\Member;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings; 
use Maatwebsite\Excel\Concerns\ShouldAutoSize;

use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Events\AfterSheet;

class MembersExport implements FromCollection, WithHeadings, ShouldAutoSize, WithEvents
    public function collection()
        return Member::all();
    public function headings(): array
     public function registerEvents(): array
        return [
            AfterSheet::class    => function(AfterSheet $event) 

                       $cellRange = 'A1:G1'; // All headers


For example I have found the following code in a guide. How can I integrate it in the excerpt above?

$styleArray = [
    'borders' => [
        'outline' => [
            'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THICK,
            'color' => ['argb' => 'FFFF0000'],


Thanks a lot!

Please sign in or create an account to participate in this conversation.