How to set RowIterator current to X

Topics: Developer Forum, User Forum
Jul 1, 2010 at 9:48 AM
Edited Jul 5, 2010 at 1:45 PM

How can you change the current row iterator so "foreach ($worksheet->getRowIterator() as $row) " can start from row X (e.a. starting from the 10th row) ?
Thanks in advance

Jul 5, 2010 at 1:20 PM
Can someone please answer my question. Thnx
Jul 6, 2010 at 5:03 AM
Edited Jul 6, 2010 at 5:10 AM

Hi, 

Actually, I have no idea about how to set the RowIterator current. However, if you are OK with accessing the cell by their indexes following code will definitely work for you.

row indexes starts from 0.

column indexes starts from 0.

<?php

$objReader = PHPExcel_IOFactory::createReader('Excel2007'); // you can replace with any other type of readers such as excel 5 and so on.

$objReader->setReadDataOnly(true);

$objPHPExcel = $objReader->load("test.xlsx");

$objWorksheet = $objPHPExcel->getActiveSheet();

$highestRow = $objWorksheet->getHighestRow(); // e.g. 10

$highestColumn = $objWorksheet->getHighestColumn(); // e.g 'F'

$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn); // e.g. 5

echo '<table>' . "\n";

for ($row = 1; $row <= $highestRow; ++$row) {

  echo '<tr>' . "\n";

  for ($col = 0; $col <= $highestColumnIndex; ++$col) {

    echo '<td>' . $objWorksheet->getCellByColumnAndRow($col, $row)->getValue() . '</td>' . "\n";

  }

  echo '</tr>' . "\n";

}

echo '</table>' . "\n";

?>

 

FYI, you can browse more features of PHPExcel from link below; with examples too. 

http://typo3.org/documentation/document-library/extension-manuals/phpexcel_library/1.7.0/view/

Above code snippet is derived from :

http://typo3.org/documentation/document-library/extension-manuals/phpexcel_library/1.7.0/view/5/3/ (Looping cell indexes section)

All the best.