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?
Yes!
$row = $this->objPHPExcel->getActiveSheet()->getRowIterator($rownumber)->current();
$cellIterator = $row->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(false);
foreach ($cellIterator as $cell) {
echo $cell->getValue();
}
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()
.
$myRow = 123;
$this->objPHPExcel->getActiveSheet()
->rangeToArray(
'A' . $myRow .
':' .
$this->objPHPExcel->getActiveSheet()->getHighestColumn() . $myRow
);
will return the specified row as an array of cells
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With