调用未定义的方法 Maatwebsite\Excel\Excel::load()
Call to undefined method Maatwebsite\Excel\Excel::load()
我正在尝试使用 maatwebsite 3.0 导入 excel 文件 (.xlsx)。如何修复此错误
Call to undefined method Maatwebsite\Excel\Excel::load()
我的控制器
public function importsave(Request $request)
{
if($request->hasFile('excel'))
{
$path = $request->file('excel')->getRealPath();
$data= Excel::load($path, function($reader) {})->get();
if(!empty($data) && $data->count())
{
foreach($data->toArray() as $key=>$value)
{
if(!empty($value))
{
Employee::insert($value);
}
}
}
}
}
该软件包的 3.0 版本 尚不处理导入 。此功能的发布日期未知。有关详细信息,请参阅此 post:https://medium.com/@maatwebsite/laravel-excel-lessons-learned-7fee2812551
我建议你切换到版本 2。*。
否则你想继续
ALL Laravel Excel 2.* 方法已弃用,将无法在 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 不提供方便的样式设置方法,建议您使用 PhpSpreadsheets 本机方法。
您好,在第 3 版中删除了加载方法,因此请切换回第 2 版,尝试使用此命令,
composer require "maatwebsite/excel:~2.1.0"
LaravelExcel 的 3.0 版不处理导入。
您还可以使用与导入一起使用的替代包,例如:
- https://github.com/Cyber-Duck/laravel-excel (Laravel Excel 分叉)
- https://github.com/rap2hpoutre/fast-excel(Laravel Excel 的更快替代方法)
两者都处理导入。
您也可以切换到版本 2,但这意味着使用旧版本的库。
ALL Laravel Excel 2.* 方法已弃用,将无法在 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 不提供方便的样式设置方法,建议您使用 PhpSpreadsheets 本机方法。
^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 然后执行作曲家更新。
不要惊慌 :) 就这样做
Excel::toArray([],$filePath);
只传递一个空数组作为第一个参数
我正在尝试使用 maatwebsite 3.0 导入 excel 文件 (.xlsx)。如何修复此错误
Call to undefined method Maatwebsite\Excel\Excel::load()
我的控制器
public function importsave(Request $request)
{
if($request->hasFile('excel'))
{
$path = $request->file('excel')->getRealPath();
$data= Excel::load($path, function($reader) {})->get();
if(!empty($data) && $data->count())
{
foreach($data->toArray() as $key=>$value)
{
if(!empty($value))
{
Employee::insert($value);
}
}
}
}
}
该软件包的 3.0 版本 尚不处理导入 。此功能的发布日期未知。有关详细信息,请参阅此 post:https://medium.com/@maatwebsite/laravel-excel-lessons-learned-7fee2812551
我建议你切换到版本 2。*。
否则你想继续 ALL Laravel Excel 2.* 方法已弃用,将无法在 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 不提供方便的样式设置方法,建议您使用 PhpSpreadsheets 本机方法。
您好,在第 3 版中删除了加载方法,因此请切换回第 2 版,尝试使用此命令,
composer require "maatwebsite/excel:~2.1.0"
LaravelExcel 的 3.0 版不处理导入。
您还可以使用与导入一起使用的替代包,例如:
- https://github.com/Cyber-Duck/laravel-excel (Laravel Excel 分叉)
- https://github.com/rap2hpoutre/fast-excel(Laravel Excel 的更快替代方法)
两者都处理导入。
您也可以切换到版本 2,但这意味着使用旧版本的库。
ALL Laravel Excel 2.* 方法已弃用,将无法在 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 不提供方便的样式设置方法,建议您使用 PhpSpreadsheets 本机方法。
^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 然后执行作曲家更新。
不要惊慌 :) 就这样做
Excel::toArray([],$filePath);
只传递一个空数组作为第一个参数