PHP read excel file example code

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

PHP read excel file example code.

Code:  

<?php

/**

* PHP read the excel file

* by www.jbxue.com

*/

$this->loadexcel();//Contain any phpexcel file

$_ReadExcel = new PHPExcel_Reader_Excel2007();

if(!$_ReadExcel->canRead('link.xls')){

$_ReadExcel = new PHPExcel_Reader_Excel5();

 }

$_phpExcel = $_ReadExcel->load('link.xls');

$sheetCount = $_phpExcel->getSheetCount();

$newExcel = array();

$excelData = array();

for($s = 0;$s<$sheetCount;$s++) {

 $currentSheet = $_phpExcel->getSheet($s);

$allColumn = $currentSheet->getHighestColumn();

  $allRow = $currentSheet->getHighestRow();

  for($r = 1;$r<=$allRow;$r++){

for($currentColumn='A';$currentColumn<=$allColumn;$currentColumn++){

  $address = $currentColumn.$r;

  $newExcel[] = $currentSheet->getCell($address)->getValue();

  }

 }

 }

The back is on an array of operations -- but the first to download phpexcel, and included.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Jason at November 17, 2013 - 3:28 PM