简体   繁体   English

获取除字段 Laravel 之外的所有行:Excel

[英]Get all the rows except for the fields Laravel: Excel

So I have an excel file with a format like this所以我有一个格式像这样的 excel 文件

在此处输入图像描述

在此处输入图像描述

I'm trying to get all the rows below the row1我正在尝试获取row1下面的所有行

This would be the records of John Doe and Mc Doe这将是John DoeMc Doe的记录

Currently I have this code from controller目前我有来自controller的代码

    $dateTime = date('Ymd_His');
    $file = $request->file('file');
    $fileName = $dateTime . '-' . $file->getClientOriginalName();
    $savePath = public_path('/upload/projectlist/');
    $file->move($savePath, $fileName);

    $excel = Importer::make('Excel');
    $excel->load($savePath.$fileName);
    $collection = $excel->getCollection();

    if(sizeof($collection[1]) == 5){

        for($row=1; $row<sizeof($collection); $row++){
            try{
                dd($collection[$row]);
            }
            catch(\Exception $e){
                return redirect()
                ->back()
                ->with(['errors'=>$e->getMessage()])
                ->with('modal',$modal);
            }
        }
    }else{
        return redirect()
        ->back()
        ->with(['errors'=> [0=> 'Please provide date in file according to your format.']])
        ->with('modal',$modal);
    }

And this gives me an output like this这给了我一个像这样的 output

在此处输入图像描述

Which the record of John Doe only.只有John Doe的记录。 How can I get all the rows except for row1 ?如何获取除row1之外的所有行?

here you get all the value if remove dd & it save every row in a array & dd that array outside the for loop then you get all results在这里,如果删除 dd 并且将每一行保存在数组中并在 for 循环之外 dd 该数组,则您将获得所有值,然后您将获得所有结果

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM