Call to undefined method Maatwebsite\Excel\Excel::load()

半腔热情 提交于 2019-11-27 06:55:20

问题


I'm trying to import excel file (.xlsx) using maatwebsite 3.0. How to fix This error

Call to undefined method 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);
                }
            }
        }
    }
}

回答1:


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

I suggest you switch to version 2.*.




回答2:


Hi there in version 3 the load method was remove so switch back to version two like so try using this command,

composer require "maatwebsite/excel:~2.1.0"




回答3:


Version 3.0 of Laravel Excel doesn't handle imports.

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)

Both handles import.

You could also switch to version 2, but it means use an old version of a lib.




回答4:


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 provides no convenience methods for styling, you are encouraged to use PhpSpreadsheets native methods.



来源:https://stackoverflow.com/questions/49473098/call-to-undefined-method-maatwebsite-excel-excelload

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!