![]() In your controler function, import an excel file. $collection = Exporter::make('Excel')->load($yourCollection)->setSerialiser(new ExampleSerialiser)->stream($yourFileName) Then set the serialiser before saving the file the collection. Use Cyberduck\LaravelExcel\Contract\SerialiserInterface Ĭlass ExampleSerialiser implements SerialiserInterface GetData(Model $data) must return an array of string, and every elements is a cell. To not print the header row, simply return a void array. GetHeaderRow() must return an array of string where every element is a cell of the first row. To change this behaviour, create a class extending Cyberduck\LaravelExcel\Contract\SerialiserInterface, implement the methods getHeaderRow() and getData(Model $data) and set this class on the excel object usint setSerialiser(). return $excel->save($yourFileNameWithPath) īy default, every element of the Collection becomes a row and every unprotected field of the Model becomes a cell. To save the excel file on the server, use the save method. If you deal with big tables, you can set the chunk size to minimise the memory usage $query = DB:table('table')->select('col1','col2') The exporter class supports Query builder objects as well $query = DB:table('table')->select('col1','col2') The exporter class is fluent, so you can also write return Exporter::make('Excel')->load($yourCollection)->stream($yourFileName) In your controler function, create a new excel file from an Eloquent collection. Export Excel Generate and download an excel file No need to register anything, since it used package auto discovery feature in Laravel 5.5. 'providers' => [Ĭyberduck\ LaravelExcel\ ExcelLegacyServiceProvider::class,Ĭyberduck\ LaravelExcel\ ExcelServiceProvider::class, Register the service provider in config/app.php by adding this line to providers array. Use composer to download the package: composer require cyber-duck/laravel-excel Exporting and importing Excel, CSV and OpenOffice stylesheets using Eloquent Collections and Query Builders in Laravel (5.* and 4.*).
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |