首页 > 解决方案 > laravel 7.15 Undefined offset: 38 Maatwebsite Excel 导入导出

问题描述

我正在使用 Maatwebsite excel 导入和导出 xlsx 文件。我以前在其他应用程序中使用过它并且它正在工作。在我的第二个应用程序中,我遇到了一个错误。

未定义的偏移量:3

我不明白,我做错了什么。一切都和我的其他应用程序一样。

这是我的控制器:

$products = Excel::toArray(new ProductsImport(), $request->file('file'));

    //  dd($products);

    foreach($products[0] as $row) {
        
        $arr[] = [
            'coil_id' => $row[1],
            'category' => $row[2],
            'product_family' => $row[3],
        ];
    }

if(!empty($arr)){
        DB::table('products')->insert($arr);
    }
      
    return back()->with('toast_success', 'Excel file uploaded to database successfully');

即使出口也不起作用。它只是将我带到一个空白页面 localhost/products/export

标签: phplaravelmaatwebsite-excel

解决方案


推荐阅读