Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/247.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
将数组的数组从phpexcel传递到blade laravel_Php_Laravel_Phpexcel - Fatal编程技术网

将数组的数组从phpexcel传递到blade laravel

将数组的数组从phpexcel传递到blade laravel,php,laravel,phpexcel,Php,Laravel,Phpexcel,我想把数组的数组传递给blade laravel,我使用laravel 5.5和PHP7 mycontroller: public function openexcel(Request $request, $directory) { $data = Exceluploads::get(); $path = 'excel/'.$directory; $objPHPExcel = PHPExcel_IOFactory::load($pat

我想把数组的数组传递给blade laravel,我使用laravel 5.5和PHP7

mycontroller:

  public function openexcel(Request  $request, $directory)
    {
        $data = Exceluploads::get();
        $path = 'excel/'.$directory;
        $objPHPExcel = PHPExcel_IOFactory::load($path);
        $sheet = $objPHPExcel->getSheetByName('mySheet1');

        $a = $sheet->rangeToArray('A1:D9');
    return view('excel.index_openexcel', compact('objPHPExcel,a'));
}
例如,数据excel:

返回$a

如何在blade laravel中显示它

您可以试试这个

<table>
    <thead>
        <tr>
            <th>{{ $objPHPExcel[0][0] }}</th>
            <th>{{ $objPHPExcel[0][1] }}</th>
            <th>{{ $objPHPExcel[0][2] }}</th>
            <th>{{ $objPHPExcel[0][3] }}</th>
        </tr>
    </thead>
    <tbody>
        @for($i=1; $i<count($objPHPExcel); $i++) 
            <tr>
                <td>{{ $objPHPExcel[$i][0] }}</td>
                <td>{{ $objPHPExcel[$i][1] }}</td>
                <td>{{ $objPHPExcel[$i][2] }}</td>
                <td>{{ $objPHPExcel[$i][3] }}</td>
            </tr>
        @endfor
    </tbody>
</table>

{{$objPHPExcel[0][0]}
{{$objPHPExcel[0][1]}
{{$objPHPExcel[0][2]}
{{$objPHPExcel[0][3]}

@对于($i=1;$i),可以在刀片文件中这样循环数组

<table>
  <thead>
    <tr>
      {{-- loop the column names --}}
      @foreach ($a[0] as  $columnName)
        <td>{{$columnName}}</td>
      @endforeach
    </tr>
  </thead>
  <tbody>
    {{-- loop all the arrays except the first on --}}
    @for ($i = 1; $i < count($a); $i++)
      <tr>
        {{-- get the data of that array --}}
        @foreach ($a[$i] as $data)
           <td>{{ $data }}</td>
        @endforeach
      </tr>
    @endfor
  </tbody>
</table>

{{--循环列名--}
@foreach($columnName形式的[0]a)
{{$columnName}
@endforeach
{{--loop除了--}上的第一个数组之外的所有数组
@对于($i=1;$i

希望这有帮助!

您可以使用foreach
<table>
  <thead>
    <tr>
      {{-- loop the column names --}}
      @foreach ($a[0] as  $columnName)
        <td>{{$columnName}}</td>
      @endforeach
    </tr>
  </thead>
  <tbody>
    {{-- loop all the arrays except the first on --}}
    @for ($i = 1; $i < count($a); $i++)
      <tr>
        {{-- get the data of that array --}}
        @foreach ($a[$i] as $data)
           <td>{{ $data }}</td>
        @endforeach
      </tr>
    @endfor
  </tbody>
</table>