通过坐标获取单元格 [英] Getting cells by coordinate

查看:127
本文介绍了通过坐标获取单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {

    foreach ($worksheet->getRowIterator() as $row) {
        $cellIterator = $row->getCellIterator();
        $cellIterator->setIterateOnlyExistingCells(false);
            // I wish
            echo $cellIterator->getCell("A3"); // row: $row, cell: A3
    }
}

我正在寻找一种类似的方法,该方法在上面名为getCell或写得很好的PHPExcel文档中.

I'm looking for a similar method which named getCell above or well-writed PHPExcel documentation.

谢谢.

推荐答案

如果您从RowIterator获得了$row信息,则可以轻松调用:

If you have the $row information from RowIterator, you can just easily call:

$rowIndex = $row->getRowIndex ();
$cell = $sheet->getCell('A' . $rowIndex);
echo $cell->getCalculatedValue();

完整的代码将是:

foreach($worksheet->getRowIterator() as $row){
    $rowIndex = $row->getRowIndex();

    $cell = $worksheet->getCell('A' . $rowIndex);
    echo $cell->getCalculatedValue();
    $cell = $worksheet->getCell('B' . $rowIndex);
    echo $cell->getCalculatedValue();
}

这篇关于通过坐标获取单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆