【问题标题】:get the value of dynamic column on Laravel 4.2 Excel在 Laravel 4.2 Excel 上获取动态列的值
【发布时间】:2016-11-11 07:13:29
【问题描述】:

我导入了一个 csv 文件并在 Laravel 4.2 中使用 Maatwebsite Excel 读取该文件 如果我知道列名,我可以简单地通过以下方式获取行值:

Excel::load($file->getRealPath(), function($reader)) { $data = $reader->get(); foreach ($data as $key => $row) { echo $row->I_know_this; });

但是如果 csv 文件包含动态列并且您不知道它们是什么?

【问题讨论】:

    标签: php laravel maatwebsite-excel


    【解决方案1】:

    试试这个。

    $excel = [];

            Excel::load($destinationPath . $filename, function($reader) use (&$excel) {
                $objExcel = $reader->getExcel();
                $sheet = $objExcel->getSheet(0);
                $highestRow = $sheet->getHighestRow();
                $highestColumn = $sheet->getHighestColumn();
    
                //  Loop through each row of the worksheet in turn
                for ($row = 1; $row <= $highestRow; $row++)
                {
                    //  Read a row of data into an array
                    $rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row,
                        NULL, TRUE, FALSE);
    
                    $excel[] = $rowData[0];
                }
            });
    

    【讨论】:

      猜你喜欢
      • 2017-06-18
      • 1970-01-01
      • 2015-06-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-05
      • 1970-01-01
      • 2016-01-15
      相关资源
      最近更新 更多