Call to Undefined Method Maatwebsite\Excel\Excel::Load()

Call to undefined method Maatwebsite\Excel\Excel::load()

Version 3.0 of that package doesn't handle imports yet. Release date for this feature is unknown. See this post for more details: https://medium.com/@maatwebsite/laravel-excel-lessons-learned-7fee2812551

I suggest you switch to version 2.*.

Else you want to continue further
ALL Laravel Excel 2.* methods are deprecated and will not be able to use in 3.0 .

   Excel::load() is removed and replaced by Excel::import($yourImport)
Excel::create() is removed and replaced by Excel::download/Excel::store($yourExport)
Excel::create()->string('xlsx') is removed an replaced by Excel::raw($yourExport, Excel::XLSX)

3.0 provides no convenience methods for styling, you are encouraged to use PhpSpreadsheets native methods.

Call to undefined method Maatwebsite\\Excel\\Excel::selectSheetsByIndex()

After debugging a lot I finally found out the answer.

I will be putting the solution to the problem below:-

public function getValidatedRows($uploadedFile, $corporate)
{
$validationRules = $this->getValidationRules();

$employeeImport = new EmployeeImport;
$sheet = Excel::import($employeeImport, $uploadedFile);
$rows = $employeeImport->data;

if (!count($rows)) {
throw new Exception('Invalid data.');
}

$parsedRows = [];

foreach ($rows as $key => $row) {

$rowNumber = $key + 2; // Added + 2 since key is zero-indexed and first row is for Headers.

$columns = $row;

$columns = array_slice($columns, 0, count($validationRules));

if (count($columns) != count($validationRules)) {
throw new Exception('Invalid data.');
}

$columnValues = array_values($columns);

$columnKeys = array_keys($validationRules);

$columnsWithValidKeys = array_combine($columnKeys ,$columnValues);

$attributes = [
'name' => 'name',
'email' => 'email',
'mobile' => 'mobile',
];

$validationRowSuffix = "(row #{$rowNumber})";
array_walk($attributes, function (&$item1, $key, $suffix) {
$item1 = "$item1 $suffix";
}, $validationRowSuffix);

$attributes = array_filter($attributes);

Validator::make($columnsWithValidKeys, $validationRules, [], $attributes)->validate();

$parsedRows[] = $columnsWithValidKeys;
}

return $parsedRows;
}

Generic Export File will be used for the export purpose not for the import purpose. For import, you need to make an import file.

<?php

namespace App\Imports;

use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\ToCollection;
use Maatwebsite\Excel\Concerns\WithHeadingRow;

class EmployeeImport implements ToCollection, WithHeadingRow {

public $data;

public function collection(Collection $rows) {

$xyz = $rows->toArray();

$this->data = $xyz;
return $xyz;
}

public function headingRow(): int
{
return 1;
}
}

If you return anything in the collection function it will not be sent back to the controller. So, if you want to send the data to the controller you need to make a public variable and then call it in the controller.

Call to undefined method Maatwebsite\Excel\Excel::downlood() in laravel 8

Looks like you typed the wrong word, it should be a download, not a downlood.

return Excel::downlood(new UserExport , 'All-User.csv');

Please change it to...

return Excel::download(new UserExport , 'All-User.csv');

Maatwebsite Excel load function not working

The load method has been removed in version 3.0 (may be re-added in 3.1). Please refer the upgrade guide

ALL Laravel Excel 2.* methods are deprecated and will not be able to
use in 3.0 .

  1. Excel::load() is removed and will not be re-added until 3.1
  2. Excel::create() is removed and replaced by Excel::download/Excel::store($yourExport)
  3. v3.0 provides no convenience methods for styling, you are encouraged to use PhpSpreadsheets native methods.

Call to undefined method Maatwebsite\Excel\Excel::create() - laravel 5.6

Try to decrease the version using :

composer require "maatwebsite/excel=2.1.0"

Call to undefined method Maatwebsite\Excel\Excel::create() in Laravel 5.8

The create method has been removed. You have to use one of the following:

Excel::download($yourExport);
Excel::store($yourExport);

As stated in the upgrade guide:

Excel::create() is removed and replaced by Excel::download/Excel::store($yourExport)

Source: https://docs.laravel-excel.com/3.1/getting-started/upgrade.html#upgrading-to-3-from-2-1

How to fix Call to undefined method Maatwebsite\Excel\Excel::create()?

According to this docs (Officinal document Here):

You may do this by using the make:export command.

php artisan make:export UsersExport --model=User

If you prefer to create the export manually, you can create the following in App/Exports:

<?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 you can call this export now:

use App\Exports\UsersExport;
use Maatwebsite\Excel\Facades\Excel;
use App\Http\Controllers\Controller;

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

Find your users.xlsx in your downloads folder!



Related Topics



Leave a reply



Submit