现在我试图找到如何在laravel excel中获取当前行号或单元格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
}
});注意:我不想要单元格的值,但想要单元格的索引
发布于 2017-06-01 16:37:59
在我的情况下,我希望用户在上传excel文件时指定包含电话号码的列号。因此,我需要通过用户输入的索引号来查找列。
在您和我的情况下,我们都需要行和列索引。下面是我是如何破解它的。

//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; https://stackoverflow.com/questions/42250467
复制相似问题