Maatwebsite Excel 加载功能不工作

Maatwebsite Excel load function not working

$file = $request->file('excel');
$reader = Excel::load($file->getRealPath())->get();

出现以下错误:

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

我在 laravel 5.7

中使用 Maatwebsite 3

load 方法已在 3.0 版本中删除(可能会在 3.1 中重新添加)。请参考upgrade guide

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

  1. Excel::load() 已删除,直到 3.1
  2. 才会重新添加
  3. Excel::create() 被删除并替换为 Excel::download/Excel::store($yourExport)
  4. v3.0 不提供方便的样式设置方法,建议您使用 PhpSpreadsheets 本机方法。

在 las post 中引用的 load 方法已被删除,但它已在 3.1 版本中实现。

Excel::load() 被删除并替换为 Excel::import($yourImport)

检查这个 link

不过就我个人而言,我最终还是使用了 Excel::toColletion($file)。

^3.0版本的maatwebsite/excel不支持加载。 先删除config/excel.php文件。

通过更改 composer.json 来降级 maatwebsite/excel 版本 "maatwebsite/excel": "^3.1",至 "maatwebsite/excel": "~2.1.0" 执行 composer update.

如果你得到一个错误“Undefined class constant 'XLSX' in 2.1 version”,这就是你必须做的。

降级前删除config/excel.php

然后执行composer update.