How to add header row in export excel file with maatwebsite in Laravel 5.8?
In this post we will give you information about How to add header row in export excel file with maatwebsite in Laravel 5.8?. Hear we will give you detail about How to add header row in export excel file with maatwebsite in Laravel 5.8?And how to use it also give you demo for it if it is necessary.
Laravel maatwebsite/excel introduce new version 3 with new feature and code structure. If you see on quick example of maatwebsite then it will very easy to export excel or csv. but if you want add headings row with export excel file then you can do it using WithHeadings Class. So you can add export csv with headers cell maatwebsite in laravel 5.8.
I will simple show you how you can set specific header on your export excel file using maatwebsite/excel composer package. If you want to import export from scratch then you can follow this tutorial: Import Export CSV File in Laravel 5.8.
So, let’s see bellow example how it is done. just follow bellow file:
app/Exports/ServiceExport.php
<?php
namespace AppExports;
use AppService;
use MaatwebsiteExcelConcernsFromCollection;
use MaatwebsiteExcelConcernsWithHeadings;
class ServiceExport implements FromCollection, WithHeadings
{
/**
* @return IlluminateSupportCollection
*/
public function collection()
{
return Service::all();
}
public function headings(): array
{
return [
'Code',
'Description',
'Pos',
'Mod A',
'Mod B',
'Charge',
];
}
}
I hope it can help you…
Hope this code and post will helped you for implement How to add header row in export excel file with maatwebsite in Laravel 5.8?. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs