Call to undefined method MaatwebsiteExcelExcel::load()(调用未定义的方法 MaatwebsiteExcelExcel::load())
问题描述
我正在尝试使用 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()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:调用未定义的方法 MaatwebsiteExcelExcel::load()


基础教程推荐
- HTTP 与 FTP 上传 2021-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- PHP 守护进程/worker 环境 2022-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- 使用 PDO 转义列名 2021-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01