Php 如何在laravel excel maatwebsite中获取当前行数或单元格索引

Php 如何在laravel excel maatwebsite中获取当前行数或单元格索引,php,laravel,laravel-excel,Php,Laravel,Laravel Excel,现在我试图找到如何获取当前的行号或单元格id,但我找不到它,我需要获取当前的行号或单元格id,因为我需要生成一些错误消息,其中提到了当前的行号或单元格id , 请打开excel图像链接以查看图像 好的,例如,根据图像,我想知道当前活动单元格,例如活动单元格位于B列和第2行,我如何获得该单元格索引或行号 $sheet = 'public/site.xls'; // load excel content $excel = Excel::load($sheet, fu

现在我试图找到如何获取当前的行号或单元格id,但我找不到它,我需要获取当前的行号或单元格id,因为我需要生成一些错误消息,其中提到了当前的行号或单元格id

,

请打开excel图像链接以查看图像 好的,例如,根据图像,我想知道当前活动单元格,例如活动单元格位于B列和第2行,我如何获得该单元格索引或行号

$sheet = 'public/site.xls';

        // load excel content
        $excel = Excel::load($sheet, function ($reader)
        {
            $results = $reader->toObject();

            foreach($results as $result)
            {

               // i want to know how to retrieve active cell index here

            }

        });

注意:我不想要单元格的值,但我想要单元格的索引在我的情况下,我希望用户在上传excel文件时指定包含电话号码的列号。 因此,我需要按用户输入的索引号查找列

在你我的情况下,我们都需要行和列索引。 这是我如何破解的。


在视图中:
@foreach($index=>$item){{{$index}}@endforeach
这有什么不对?请发布一些代码示例,让我们了解您是如何做到这一点的。@devk检查一下,我已经更新了描述的更多细节
//Array to hold the phone numbers
$phone_numbers = array();

//Load Excel file as array
$rows = Excel::load($contacts_file)->toArray();

//Loop through each row
foreach($rows as $row_index=>$row){ //$row_index is the row index
    $col_headers = array_keys($row); //Gives you an array, in my case ["serial","contact_name","contact_phone"]
    //Getting Cell Value i.e phone number
    array_push($phone_numbers,$row[$col_headers[2]]); //$col_headers[2] is the column index for phone
}
return $phone_numbers;