I am using the following code to read an excel sheet in php. It works fine, however I am confused how to loop through it the right way. In the following code, $val outputs all the data in the sheet, but I wanna see one row at a time, not sure how to make that happen. I am not sure how to access elements within $val
[php]
require_once (ABSPATH . ‘PHPExcel_1.8.0_doc/Classes/PHPExcel.php’);
$objPHPExcel = PHPExcel_IOFactory::load(ABSPATH . “test.xlsx”);
foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
$worksheetTitle = $worksheet->getTitle();
$highestRow = $worksheet->getHighestRow(); // e.g. 10
$highestColumn = $worksheet->getHighestColumn(); // e.g ‘F’
$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
$nrColumns = ord($highestColumn) - 64;
for ($row = 1; $row <= $highestRow; ++ $row) {
for ($col = 0; $col < $highestColumnIndex; ++ $col) {
$cell = $worksheet->getCellByColumnAndRow($col, $row);
$val = $cell->getValue();
echo '<td>' . $val . '<br></td>';
}
}
}
[/php]