问题描述
我正在尝试使用 maatwebsite 3.0 导入 excel 文件 (.xlsx).如何修复此错误
I'm trying to import excel file (.xlsx) using maatwebsite 3.0. How to fix This error
调用未定义的方法 MaatwebsiteExcelExcel::load()
Call to undefined method MaatwebsiteExcelExcel::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 版本的包尚不处理导入.此功能的发布日期未知.有关更多详细信息,请参阅此帖子:https://medium.com/@maatwebsite/laravel-excel-lessons-learned-7fee2812551
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
我建议您切换到版本 2.*.
否则你想继续所有 Laravel Excel 2.* 方法均已弃用,无法在 3.0 中使用.
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 没有提供方便的样式方法,鼓励您使用 PhpSpreadsheets 原生方法.
3.0 provides no convenience methods for styling, you are encouraged to use PhpSpreadsheets native methods.
这篇关于调用未定义的方法 MaatwebsiteExcelExcel::load()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!