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()
基础教程推荐
- 在PHP中根据W3C规范Unicode 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 如何替换eregi() 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
