Loop through several sheets to find values

Topics: User Forum
Jun 9, 2010 at 7:21 PM

I'm trying to use phpexcel to loop through a directory of excel sheets and I can go through and find the fields I want in one sheet but on the second sheet I receive the error

"Cannot redeclare class PHPExcel_IOFactory"

 

I'm using the following function

function findValue($file,$value)
{
	echo $file.' '.$value.'<br>';
	/** Error reporting */
	error_reporting(E_ALL);
	/** Include path **/
	ini_set('include_path', ini_get('include_path').';../Classes/'); //Classes dir
	/** PHPExcel_IOFactory */
	include 'PHPExcel/IOFactory.php';
	$objReader = PHPExcel_IOFactory::createReader('Excel5');//excel2007
	$objPHPExcel = $objReader->load($file); //ARCHIVE excel2007 dir
	$val = ($objPHPExcel->getActiveSheet()->getCell('AB31')); //CELL
	$temp = $val->getvalue();//returns the value in the cell
	$objWorksheet = $objPHPExcel->getActiveSheet();
	foreach ($objWorksheet->getRowIterator() as $row) {
	  $cellIterator = $row->getCellIterator();
	  $cellIterator->setIterateOnlyExistingCells(false); // This loops all cells,                                                     // even if it is not set.                                                     // By default, only cells                                                     // that are set will be                                                     // iterated.
	  foreach ($cellIterator as $cell) {
		$searchedvalue = $cell->getValue();
		echo $searchedvalue;
		if ($searchedvalue=$value)
		{
			return "FOUND: ".$searchedvalue;
		}
	  }
	}
}
Any help on how to do this would be appreciated.
Jun 9, 2010 at 7:27 PM

Looks like I needed

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

 

Found it in another post, sorry I had tried it earlier but left off the once.  Reread the post.