Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 如何处理此类数据_Excel_Laravel_Laravel 5.4_Maatwebsite Excel - Fatal编程技术网

Excel 如何处理此类数据

Excel 如何处理此类数据,excel,laravel,laravel-5.4,maatwebsite-excel,Excel,Laravel,Laravel 5.4,Maatwebsite Excel,我在这个项目中使用了laravel-5.4 使用“maatwebsite/excel” 我计划为我的网站创建一个功能,我可以上传一个excel文件,然后在我的视图中显示该文件的数据 我用来上传数据并将数据发送到后端的表单 public function bundleaddstudent(Request $request) { if($request->hasFile('excelstudent')){ $File = $request->file('ex

我在这个项目中使用了laravel-5.4 使用“maatwebsite/excel”

我计划为我的网站创建一个功能,我可以上传一个excel文件,然后在我的视图中显示该文件的数据

我用来上传数据并将数据发送到后端的表单

public function bundleaddstudent(Request $request)
{

   if($request->hasFile('excelstudent')){

          $File = $request->file('excelstudent');
              $path = $File->getRealPath();

      $data = Excel::load($path, function($reader) {

        })->toObject();


          return view('User.content.tobe_added_students')
          ->with('selection', $this->selection())
          ->with('Students', $data);

    }
  else
  {
    return view('User.content.Add_student')
        ->with('selection', $this->selection())
        ->with('Students', 'No Data')
        ->with('request', $request);
  }
}
现在,已上载并在我的控制器中处理的文件已转换为数据对象,并且已与新视图一起传递

我现在需要在我的视图中处理传递的数据我就是这样做的

 @isset($Students)
    @foreach ($Students as $key => $value)
      <tr>
          <td> {{$value}}</td>
      </tr>
    @endforeach
 @endisset
你明白了吗

我还尝试了
{{$value->studentId}
,但没有显示任何结果

基于@LrdArc的评论,我应该尝试

@isset( $Students )
      {{  dd( $Students )  }}
@endisset
输出:

LaravelExcelReader {#353 ▼
  +excel: PHPExcel {#361 ▶}
  +reader: PHPExcel_Reader_Excel2007 {#354 ▶}
  +file: "/tmp/phpu3zVBH"
  +columns: []
  +title: "phpu3zVBH"
  +ext: ""
  +encoding: false
  +format: "Excel2007"
  +parsed: RowCollection {#430 ▼
     #title: "Sheet1"
     #items: array:5 [▼
       0 => CellCollection {#495 ▼
          #title: null
          #items: array:9 [▼
             "studentid" => "15-2000332"
             "firstname" => "Dummy1"
             "lastname" => "Dummy1"
             "middlename" => "Dummy1"
             "course" => "Dummy1"
             "ay" => "Dummy1"
             "gender" => "Dummy1"
             "address" => "Dummy1"
             "contact" => "Dummy1"
        ]
      }
      1 => CellCollection {#496 ▼
          #title: null
          #items: array:9 [▼
           "studentid" => "15-2000333"
           "firstname" => "Dummy2"
           "lastname" => "Dummy2"
           "middlename" => "Dummy2"
           "course" => "Dummy2"
           "ay" => "Dummy2"
           "gender" => "Dummy2"
           "address" => "Dummy2"
           "contact" => "Dummy2"
        ]
       }
         2 => CellCollection {#515 ▶}
         3 => CellCollection {#514 ▶}
         4 => CellCollection {#513 ▶}
     ]
     }
编辑: 好的,我刚测试过。在控制器中将toObject()更改为get()

它是一个物体。在您的视图中尝试以下操作:

@isset( $Students )
  @foreach ( $Students as $student )
  <tr>
      <td>{{ $student->studentID }}</td>
      <td>{{ $student->firstname }}</td>
      <td>{{ $student->lastname }}</td>
      <td>{{ $student->middlename }}</td>
  </tr>
  @endforeach
@endisset
@isset($Students)
@foreach($student作为$student)
{{$student->studentID}
{{$student->firstname}
{{$student->lastname}
{{$student->middlename}
@endforeach
@尾端集

try
dd($Students)输出是什么?@LrdArd我已经编辑它,将
{{dd($Students)}
@GroverReyes change
toObject
的输出添加到
get()
相同的结果中<代码>获取()
@isset( $Students )
  @foreach ( $Students as $student )
  <tr>
      <td>{{ $student->studentID }}</td>
      <td>{{ $student->firstname }}</td>
      <td>{{ $student->lastname }}</td>
      <td>{{ $student->middlename }}</td>
  </tr>
  @endforeach
@endisset