php 调用未定义的方法 Maatwebsite\Excel\Excel::load()
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/49473098/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Call to undefined method Maatwebsite\Excel\Excel::load()
提问by Rio Aditya
I'm trying to import excel file (.xlsx) using maatwebsite 3.0. How to fix This error
我正在尝试使用 maatwebsite 3.0 导入 excel 文件 (.xlsx)。如何修复此错误
Call to undefined method Maatwebsite\Excel\Excel::load()
调用未定义的方法 Maatwebsite\Excel\Excel::load()
My controller
我的控制器
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);
}
}
}
}
}
回答by jedrzej.kurylo
Version 3.0of 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
该软件包的3.0版尚未处理导入。此功能的发布日期未知。有关更多详细信息,请参阅此帖子:https: //medium.com/@maatwebsite/laravel-excel-lessons-learned-7fee2812551
I suggest you switch to version 2.*.
我建议您切换到版本 2.*。
回答by Dawood Iddris
Hi there in version 3 the load method was remove so switch back to version two like so try using this command,
嗨,在第 3 版中,加载方法已删除,因此请切换回第 2 版,尝试使用此命令,
composer require "maatwebsite/excel:~2.1.0"
composer require "maatwebsite/excel:~2.1.0"
回答by Aravind
^3.0
versions of maatwebsite/excel
does not support loads.
Delete the config/excel.php
file first .
^3.0
的版本maatwebsite/excel
不支持负载。
先删除config/excel.php
文件。
Downgrade the maatwebsite/excel
version by changing your composer.json
file from
"maatwebsite/excel": "^3.1"
, to "maatwebsite/excel": "~2.1.0"
, and performing 'composer update'.
maatwebsite/excel
通过将composer.json
文件从
"maatwebsite/excel": "^3.1"
、更改为"maatwebsite/excel": "~2.1.0"
并执行“作曲家更新”来 降级版本。
And if you get an error:
如果出现错误:
Undefined class constant 'XLSX' in 2.1 version
2.1 版本中未定义的类常量“XLSX”
this is what you have to do.
Delete the config/excel.php before downgrading then perform the composer update.
这是你必须做的。
在降级之前删除 config/excel.php 然后执行 Composer 更新。
回答by Engr Syed Rowshan Ali
ALL Laravel Excel 2.* methods are deprecated and will not be able to use in 3.0 .
所有 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 provides no convenience methods for styling, you are encouraged to use PhpSpreadsheets native methods.
3.0 没有提供方便的样式方法,鼓励您使用 PhpSpreadsheets 本地方法。
回答by rap-2-h
Version 3.0 of Laravel Excel doesn't handle imports.
Laravel Excel 3.0 版不处理导入。
You could also use an alternative package that works with import such as:
您还可以使用与导入一起使用的替代包,例如:
- https://github.com/Cyber-Duck/laravel-excel(Laravel Excel Fork)
- https://github.com/rap2hpoutre/fast-excel(Faster alternative to Laravel Excel)
- https://github.com/Cyber-Duck/laravel-excel(Laravel Excel Fork)
- https://github.com/rap2hpoutre/fast-excel(LaravelExcel 的快速替代品)
Both handles import.
两者都处理导入。
You could also switch to version 2, but it means use an old version of a lib.
您也可以切换到版本 2,但这意味着使用旧版本的 lib。