2

I'm trying to use this component, I've updated it from 2.1 to 3.1 and my exports now are broken the method create doesnt exist in this new version or there's something that I'm missing in the documentation.

 Excel::create()

Call to undefined method Maatwebsite\Excel\Excel::create()
Christian
  • 481
  • 1
  • 7
  • 24
  • You're [not missing anything](https://docs.laravel-excel.com/3.1/getting-started/upgrade.html). Upgrade guide says that these methods are removed. Exportables are now the preferred method. The library is vastly different now. I encourage you to go through the documentation about it. – Ohgodwhy Dec 22 '19 at 04:16
  • I've reading it but i dont see a part that talks about cells manipulation https://docs.laravel-excel.com/2.1/export/cells.html, something like `$sheet->row` we used to use – Christian Dec 22 '19 at 13:41

2 Answers2

0

Here the docs https://docs.laravel-excel.com/3.1/exports/
You have to create a export class inside de folder:

app/Exports/

with this command:

php artisan make:export UsersExport --model=User

Will be create the file UsersExport.php

namespace App\Exports;

use App\User;
use Maatwebsite\Excel\Concerns\FromCollection;

class UsersExport implements FromCollection
{
  public function collection()
  {
    return User::all();
  }
}

In your controller

namespace App\Http\Controllers;

use App\Exports\UsersExport;
use Maatwebsite\Excel\Facades\Excel;

class UsersController extends Controller 
{
    public function export() 
    {
        return Excel::download(new UsersExport, 'users.xlsx');
    }
}

In your route

Route::get('users/export/', 'UsersController@export');
Itamar Garcia
  • 882
  • 10
  • 17
  • How can i manipulate the cells in this new version? https://docs.laravel-excel.com/2.1/export/cells.html – Christian Dec 22 '19 at 13:40
  • 1
    @Christian You would now be using [Concerns](https://docs.laravel-excel.com/3.1/exports/concerns.html). Such as, [adding a heading row](https://docs.laravel-excel.com/3.1/exports/mapping.html#adding-a-heading-row) – Ohgodwhy Dec 22 '19 at 19:15
-2

export data in excel using laravel plugin

Excel::create('filename', function($excel) use ($data){

    $excel->sheet('filename', function($sheet) use ($data){
    $sheet->fromArray($data, null, 'A1', false, false);
    $sheet->cell('A1:Z1', function ($cells) {
            $cells->setFontWeight('bold');
        });
    $sheet->setWidth('A', 5);
    $sheet->cell('A1:A', function($cells) {
            $cells->setAlignment('center');
        });
    });
})->download('xlsx');  
lentern
  • 11
  • 3