PHPexcel, read and print data from specific column?

Topics: Developer Forum, User Forum
Oct 4, 2012 at 7:42 PM

hm, cannot understand how to read a specific colum and print the data from it, this is the one i use for now, but it print everything in  that .xls file... suggestion?

 

<?php
error_reporting(E_ALL);
require_once 'Classes/PHPExcel/IOFactory.php';
$objPHPExcel = PHPExcel_IOFactory::load("test.xls");
$objWorksheet = $objPHPExcel->getActiveSheet();
echo '<table>' . "\n";
foreach ($objWorksheet->getRowIterator() as $row) {
echo '<tr>' . "\n";

$cellIterator = $row->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(false);
foreach ($cellIterator as $cell) {
echo '<td>' . $cell->getValue() . '</td>' . "\n";
}

echo '</tr>' . "\n";
}
echo '</table>' . "\n";
?>

Coordinator
Oct 4, 2012 at 10:05 PM
$column = 'D';
$lastRow = $objWorksheet->getHighestRow();
echo '<table>';
for ($row = 1; $row <= $lastRow; $row++) {
    echo '<tr><td>' . 
         $objWorksheet->getCell($column . $row)->getValue() . 
         '</td></tr>';
}
echo '</table>';