| 
									
										
										
										
											2010-10-13 19:37:19 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-20 11:30:09 +00:00
										 |  |  | error_reporting(E_ALL); | 
					
						
							|  |  |  | set_time_limit(0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | date_default_timezone_set('Europe/London'); | 
					
						
							| 
									
										
										
										
											2010-10-13 19:37:19 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | ?>
 | 
					
						
							|  |  |  | <html> | 
					
						
							|  |  |  | <head> | 
					
						
							|  |  |  | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <title>PHPExcel Reader Example #12</title>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | </head> | 
					
						
							|  |  |  | <body> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <h1>PHPExcel Reader Example #12</h1>
 | 
					
						
							| 
									
										
										
										
											2010-10-20 11:30:09 +00:00
										 |  |  | <h2>Reading a Workbook in "Chunks" Using a Configurable Read Filter (Version 2)</h2> | 
					
						
							| 
									
										
										
										
											2010-10-13 19:37:19 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-20 11:30:09 +00:00
										 |  |  | /**  Set Include path to point at the PHPExcel Classes folder  **/ | 
					
						
							| 
									
										
										
										
											2010-10-20 12:57:51 +00:00
										 |  |  | set_include_path(get_include_path() . PATH_SEPARATOR . '../../../Classes/'); | 
					
						
							| 
									
										
										
										
											2010-10-13 19:37:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-20 11:30:09 +00:00
										 |  |  | /**  Include PHPExcel_IOFactory  **/ | 
					
						
							| 
									
										
										
										
											2010-10-13 19:37:19 +00:00
										 |  |  | include 'PHPExcel/IOFactory.php'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-20 11:30:09 +00:00
										 |  |  | $inputFileType = 'Excel5'; | 
					
						
							| 
									
										
										
										
											2010-10-20 12:57:51 +00:00
										 |  |  | //	$inputFileType = 'Excel2007';
 | 
					
						
							|  |  |  | //	$inputFileType = 'Excel2003XML';
 | 
					
						
							|  |  |  | //	$inputFileType = 'OOCalc';
 | 
					
						
							|  |  |  | //	$inputFileType = 'Gnumeric';
 | 
					
						
							| 
									
										
										
										
											2010-10-20 11:30:09 +00:00
										 |  |  | $inputFileName = './sampleData/example2.xls'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**  Define a Read Filter class implementing PHPExcel_Reader_IReadFilter  */ | 
					
						
							|  |  |  | class chunkReadFilter implements PHPExcel_Reader_IReadFilter | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	private $_startRow = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	private $_endRow = 0; | 
					
						
							| 
									
										
										
										
											2010-10-13 19:37:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-20 11:30:09 +00:00
										 |  |  | 	/**  Set the list of rows that we want to read  */ | 
					
						
							|  |  |  | 	public function setRows($startRow, $chunkSize) { | 
					
						
							|  |  |  | 		$this->_startRow	= $startRow; | 
					
						
							|  |  |  | 		$this->_endRow		= $startRow + $chunkSize; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	public function readCell($column, $row, $worksheetName = '') { | 
					
						
							|  |  |  | 		//  Only read the heading row, and the rows that are configured in $this->_startRow and $this->_endRow
 | 
					
						
							|  |  |  | 		if (($row == 1) || ($row >= $this->_startRow && $row < $this->_endRow)) { | 
					
						
							|  |  |  | 			return true; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2010-10-13 19:37:19 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-20 11:30:09 +00:00
										 |  |  | echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />'; | 
					
						
							|  |  |  | /**  Create a new Reader of the type defined in $inputFileType  **/ | 
					
						
							| 
									
										
										
										
											2010-10-13 19:37:19 +00:00
										 |  |  | $objReader = PHPExcel_IOFactory::createReader($inputFileType); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | echo '<hr />'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-20 11:30:09 +00:00
										 |  |  | /**  Define how many rows we want to read for each "chunk"  **/ | 
					
						
							|  |  |  | $chunkSize = 20; | 
					
						
							|  |  |  | /**  Create a new Instance of our Read Filter  **/ | 
					
						
							|  |  |  | $chunkFilter = new chunkReadFilter(); | 
					
						
							| 
									
										
										
										
											2010-10-13 19:37:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-20 11:30:09 +00:00
										 |  |  | /**  Tell the Reader that we want to use the Read Filter that we've Instantiated  **/ | 
					
						
							|  |  |  | $objReader->setReadFilter($chunkFilter); | 
					
						
							| 
									
										
										
										
											2010-10-13 19:37:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-20 11:30:09 +00:00
										 |  |  | /**  Loop to read our worksheet in "chunk size" blocks  **/ | 
					
						
							|  |  |  | for ($startRow = 2; $startRow <= 240; $startRow += $chunkSize) { | 
					
						
							|  |  |  | 	echo 'Loading WorkSheet using configurable filter for headings row 1 and for rows ',$startRow,' to ',($startRow+$chunkSize-1),'<br />'; | 
					
						
							|  |  |  | 	/**  Tell the Read Filter, the limits on which rows we want to read this iteration  **/ | 
					
						
							|  |  |  | 	$chunkFilter->setRows($startRow,$chunkSize); | 
					
						
							|  |  |  | 	/**  Load only the rows that match our filter from $inputFileName to a PHPExcel Object  **/ | 
					
						
							|  |  |  | 	$objPHPExcel = $objReader->load($inputFileName); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	//	Do some processing here
 | 
					
						
							| 
									
										
										
										
											2010-10-13 19:37:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-20 11:30:09 +00:00
										 |  |  | 	$sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true); | 
					
						
							| 
									
										
										
										
											2010-10-13 19:37:19 +00:00
										 |  |  | 	var_dump($sheetData); | 
					
						
							| 
									
										
										
										
											2010-10-20 11:30:09 +00:00
										 |  |  | 	echo '<br /><br />'; | 
					
						
							| 
									
										
										
										
											2010-10-13 19:37:19 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-20 11:30:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-13 19:37:19 +00:00
										 |  |  | ?>
 | 
					
						
							|  |  |  | <body> | 
					
						
							|  |  |  | </html> |