Ads Inside Post

Search in This Blog

Read excel file in PHP

Problem:

How to read Excel 2003 or 2007 or 2010 format microsoft excel file in PHP

Solution:

Use  PHPExcel library to read Excel 2003 or 2007 or 2010 format microsoft excel file in PHP.
Download it from it's website

Example:

Below the code that will read excel file.
<?php
require_once './PHPExcel/IOFactory.php';
$objReader = PHPExcel_IOFactory::createReader('excel2007');//excel2007 or Excel5
$objPHPExcel = $objReader->load("Test.xlsx");

$worksheet=$objPHPExcel->getActiveSheet();
$lastRow = $worksheet->getHighestRow();
$lastCol = $worksheet->getHighestColumn();

for ($row = 2; $row <= $lastRow; $row++){
   echo $worksheet->getCell("A".$row)->getValue()."======";
   echo $worksheet->getCell("B".$row)->getValue()."<br/>"; 
 /// so on.......
}
?>