Reputation: 838
I'm trying out Box\Spout and rewriting some code which was formerly using PHPExcel. Iterating through rows is clear but in a few cases I need to address directly one specific row. I cannot find this in the documentation.
Something like:
$row = $sheet->getRow(8);
Upvotes: 3
Views: 2983
Reputation: 1947
You can't access rows directly. If you need the 8th row, you'll need to read the first 8 rows... This is because Spout does not load the entire spreadsheet in memory so it reads the data row by row.
However, you can do something like this:
foreach ($reader->getSheetIterator() as $sheet) {
foreach ($sheet->getRowIterator() as $rowIndex => $row) {
if ($rowIndex !== 8) {
continue;
}
// do something with row 8
}
}
Upvotes: 4
Reputation: 12384
Try using the iterator's key()
method:
$it = $sheet->getRowIterator();
$row = $it->key(8);
Upvotes: 1