只需从PHPExcel获得一行 [英] Just get one row from PHPExcel

查看:382
本文介绍了只需从PHPExcel获得一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到一种方法来仅使用PHPExcel获得一行.在互联网上进行了无数次搜索之后,我只发现了一种对它们进行迭代的方法,并带有一个可选的开始行.这导致以下解决方案:

I tried to find a way to just get a row using PHPExcel. After numerous searches on the internet, I only found a way to iterate over them, with an optional start row. This lead to the following solution:

foreach ($this->objPHPExcel->getActiveSheet()->getRowIterator($rownumber) as $row) {
    $cellIterator = $row->getCellIterator();
    $cellIterator->setIterateOnlyExistingCells(false);

    foreach ($cellIterator as $cell) {
        echo $cell->getValue();
    }

    break;
}

但是感觉有点难看.还有另一种方法吗?

but this feels a little ugly. Is there another way to do it?

推荐答案

是!

$row = $this->objPHPExcel->getActiveSheet()->getRowIterator($rownumber)->current();

$cellIterator = $row->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(false);

foreach ($cellIterator as $cell) {
    echo $cell->getValue();
}

我不记得您应该使用next还是current.如果您输入的行错误,请使用current()而不是next().

I don't remember if you are supposed to use next or current. If you are getting the wrong row, use current() instead of next().

这篇关于只需从PHPExcel获得一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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