Retrieve column and row?

Sep 29, 2010 at 8:38 PM

Hi there,

I'm just trying to read an XLS file, but I want to be able to return the column and row of a particular cell for reference purposes. 

 

$objReader = PHPExcel_IOFactory::createReader('Excel5');
					$objReader->setReadDataOnly(true);
					$objPHPExcel = $objReader->load($target);
					$objWorksheet = $objPHPExcel->getActiveSheet();
					$i = 1;
					foreach ($objWorksheet->getRowIterator() as $row) {
						$j = 1;
						$cellIterator = $row->getCellIterator();
  						$cellIterator->setIterateOnlyExistingCells(false);
						foreach ($cellIterator as $cell_raw) {
							$cell = $cell_raw->getValue();

I want to be able to reference $cell and find the the column and row of that particular cell (i.e. "A5" or simply the column and row #'s)

Thanks!

Sep 29, 2010 at 9:40 PM

$row = $cell_raw->getRow(); // get row of a particular cell (i.e. "1", "2", "3")

$column = $cell_raw->getColumn(); // get column of a particular cell (i.e. "A", "B", "C")

$coordinates = $cell_raw->getCoordinates(); // get row and column (i.e. "A5", "C5", "E5")