Posts Tagged ‘excel reader’

PHP read excel file

Posted: August 14, 2012 in PHP
Tags: , ,

I have used PHPExcel Download latest library and use below code.


<?php error_reporting(E_ALL);

require_once '../Classes/PHPExcel/IOFactory.php';

$objPHPExcel = PHPExcel_IOFactory::load("demo.xlsx");
$objWorksheet = $objPHPExcel->setActiveSheetIndex(0);
$rowCount = $objWorksheet->getHighestRow();
$columnCount = $objWorksheet->getHighestColumn();


$excelTitle = $objWorksheet->rangeToArray('A1:'.$columnCount.'1',null, true, true, true);
$excelTitle = $excelTitle[1];


$excelData = array();
$count = 0;
for ($row = 2; $row<=$rowCount; $row++)
{
$dataRow = $objWorksheet->rangeToArray('A'.$row.':'.$columnCount.$row,null, true, true, true);
if((isset($dataRow[$row]['A'])) && (trim($dataRow[$row]['A']) != ''))
{
foreach($excelTitle as $columnKey => $columnHeading)
{
$excelData[$count][$columnHeading] = $dataRow[$row][$columnKey];
}
$count++;
}
}
echo '<pre>';
print_r($excelData);
echo '</pre>';
exit;
?>