What's the best library for laravel to use when it comes to exporting data to an excel file ? something that uses a template would be much better.
2 Answers
Laravel Excel if you need to add dropdown in your excel sheet PhpSpreadsheet would a good choice over Laravel Excel
For Laravel Excel you can simply
Excel::loadView('folder.file', $data)
->setTitle('FileName')
->sheet('SheetName')
->mergeCells('A2:B2')
->export('xls');
8 Comments
Lucentyr
Would I be able to use a template ? Because my data contains headers that require merged cells. So, maybe I'm thinking of something that uses a library, or something that can manually merge cells
Lucentyr
Call to undefined method Maatwebsite\Excel\Excel::loadView() Already added service providers and aliases
Rahman Qaiser
depends on what you have set in your config, please read laravel-excel.maatwebsite.nl/docs/2.1/blade/load-view#docs
Lucentyr
What's the purpose of the view btw ? Is it something like, the $data variable will be loaded in the folder.file view, then the output will be the same with the exported excel file ?
Rahman Qaiser
if you want to use template, for reports etc... you can make the view, and pass the data to that view
|
Use maatwebsite to Create and import Excel, CSV and PDF files
Add this lines to your composer.json:
"require": {
"maatwebsite/excel": "~2.1.0"
}
After updating composer, add the ServiceProvider to the providers array in config/app.php
Maatwebsite\Excel\ExcelServiceProvider::class,
You can use the facade for shorter code. Add this to your aliasses:
'Excel' => Maatwebsite\Excel\Facades\Excel::class,
To publish the config settings in Laravel 5 use:
php artisan vendor:publish --provider="Maatwebsite\Excel\ExcelServiceProvider"