programing

정의되지 않은 메서드 Maatwebsite 호출\Excel\Excel::load()

easyjava 2023. 4. 14. 22:18
반응형

정의되지 않은 메서드 Maatwebsite 호출\Excel\Excel::load()

maatwebsite 3.0을 사용하여 Excel 파일(.xlsx)을 Import하려고 합니다.이 오류를 수정하는 방법

정의되지 않은 메서드 Maatwebsite 호출\Excel\Excel::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은 아직 Import를 처리하지 않습니다.이 기능의 릴리스 날짜를 알 수 없습니다.상세한 것에 대하여는, https://medium.com/@maatwebsite/laravel-website-http-http-7wp-2812551 을 참조해 주세요.

버전 2.*로 전환할 을 권장합니다.

그렇지 않으면 모든 Larabel 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은 스타일링을 위한 편리한 방법을 제공하지 않습니다.PhpSpreadsheets 네이티브 방식을 사용하는 것이 좋습니다.

안녕하세요, 버전 3에서는 로드 방식이 삭제되었으므로 버전 2로 다시 전환합니다.이 명령어를 사용해 보십시오.

composer require "maatwebsite/excel:~2.1.0"

모든 Larabel 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은 스타일링을 위한 편리한 방법을 제공하지 않습니다.PhpSpreadsheets 네이티브 방식을 사용하는 것이 좋습니다.

^3.0버전maatwebsite/excel는 부하를 지원하지 않습니다.
삭제하다config/excel.php파일을 먼저 제출합니다.

다운그레이드하다maatwebsite/excel버전 변경으로composer.json에서 줄서다."maatwebsite/excel": "^3.1",로."maatwebsite/excel": "~2.1.0"및 '업데이트'를 수행합니다.

에러가 발생했을 경우는, 다음과 같이 됩니다.

2.1 버전에서 정의되지 않은 클래스 상수 'XLSX'

이게 네가 해야 할 일이야
설정/excel을 삭제합니다.php를 다운그레이드하기 전에 Composer 업데이트를 수행합니다.

당황하지 마세요 :)이렇게 하면 됩니다.

Excel::toArray([],$filePath);

빈 배열을 첫 번째 매개 변수로 전달합니다.

Laravel Excel 버전 3.0은 Import를 지원하지 않습니다.

또한 다음과 같은 가져오기와 함께 작동하는 대체 패키지를 사용할 수도 있습니다.

  • https://github.com/Cyber-Duck/laravel-excel (Laravel Excel Fork)
  • https://github.com/rap2hpoutre/fast-excel (Laravel Excel을 대체하는 고속 서비스)

양쪽 핸들 Import

버전 2로 전환할 수도 있지만 이전 버전의 lib를 사용해야 합니다.

언급URL : https://stackoverflow.com/questions/49473098/call-to-undefined-method-maatwebsite-excel-excelload

반응형