PHPExcel Column Loop

To loop through columns in PHPExcel, you can use the following code snippet as an example:

<?php

require_once 'PHPExcel/IOFactory.php';

$inputFileName = 'example.xlsx';
$objPHPExcel = PHPExcel_IOFactory::load($inputFileName);

$worksheet = $objPHPExcel->getActiveSheet();

foreach ($worksheet->getRowIterator() as $row) {
  $cellIterator = $row->getCellIterator();
  $cellIterator->setIterateOnlyExistingCells(false);
  foreach ($cellIterator as $cell) {
    echo $cell->getValue() . "\n";
  }
}

Watch a course Learn object oriented PHP

This code uses the getRowIterator() method to loop through each row in the worksheet, and the getCellIterator() method to loop through each cell in the row. The setIterateOnlyExistingCells(false) method is used to ensure that the loop includes all cells, even if they are empty. The getValue() method is then used to access the value of each cell.