Php 从列中的某一行获取值

Php 从列中的某一行获取值,php,phpexcel,Php,Phpexcel,我目前有下面的代码,它将在excel文件中循环并返回丢失数据的行。输出如下: - Row number: 37 - Missing : in cell B37 - Missing : in cell D37 我想返回的内容如下 - Row number: 37 - Missing nameFirst : in cell B37 - Missing nameLast : in cell D37 其中,nameFirst是单元格B1的值,nameLast是D1的值

我目前有下面的代码,它将在excel文件中循环并返回丢失数据的行。输出如下:

- Row number: 37
    - Missing : in cell B37
    - Missing : in cell D37
我想返回的内容如下

- Row number: 37
    - Missing nameFirst : in cell B37
    - Missing nameLast : in cell D37
其中,nameFirst是单元格B1的值,nameLast是D1的值

<?PHP
require_once 'Excel/PHPExcel.php';
require_once 'Excel/PHPExcel/Reader/Excel2007.php';
class MyReadFilter implements PHPExcel_Reader_IReadFilter
{
    public function readCell($column, $row, $worksheetName = '') {
        $Retour=false;
        $column=PHPExcel_Cell::columnIndexFromString($column);// Warning ! A=1, not zero as usual
        if($row<1 || $column>4)
            $Retour=false;
        else
            $Retour=true;
        return $Retour;
    }
}
echo '<pre>';
$objReader = PHPExcel_IOFactory::createReader('Excel2007');
$objReader->setReadDataOnly(true);
$objReader->setReadFilter( new MyReadFilter() );
$objPHPExcel = $objReader->load('test.xlsx');
$worksheet=$objPHPExcel->getSheet(0);
foreach ($worksheet->getRowIterator() as $row) {
        if($row->getRowIndex()>1){
            echo '    - Row number: ' . $row->getRowIndex() . "\r\n";

            $cellIterator = $row->getCellIterator();
            $cellIterator->setIterateOnlyExistingCells(false); // Loop all cells, even if it is not set
            foreach ($cellIterator as $cell) {
                 $colIndex = PHPExcel_Cell::columnIndexFromString($cell->getColumn());



                if($cell->getCalculatedValue() == "")
                echo '        - Missing <THIS IS WHERE I WANT THE INDEX CELL FOR THE COLUMN> :' . 'in cell ' . $cell->getCoordinate() . "\r\n";

        }
        }
    }
echo '</pre>';

?>
但这会导致返回一行、一个正确的单元格和一大堆空白变量

echo '        - Missing ' .
     $worksheet->getCell($cell->getColumn(). '1')->getValue() . 
     ' :' . 'in cell ' . 
     $cell->getCoordinate() . "\r\n";

因此,您需要在当前单元格的($cell)列中获取行1的单元格值

应该可以很好地工作

- Row number: 2
    - Missing nameFirst. :B1
    - Missing . :E1
    - Missing . :F1
    - Missing . :G1
    - Missing . :H1
echo '        - Missing ' .
     $worksheet->getCell($cell->getColumn(). '1')->getValue() . 
     ' :' . 'in cell ' . 
     $cell->getCoordinate() . "\r\n";