| 
									
										
										
										
											2012-06-07 19:43:19 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * PHPExcel | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2013-05-14 11:20:28 +00:00
										 |  |  |  * Copyright (c) 2006 - 2013 PHPExcel | 
					
						
							| 
									
										
										
										
											2012-06-07 19:43:19 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * This library is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU Lesser General Public | 
					
						
							|  |  |  |  * License as published by the Free Software Foundation; either | 
					
						
							|  |  |  |  * version 2.1 of the License, or (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This library is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
					
						
							|  |  |  |  * Lesser General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU Lesser General Public | 
					
						
							|  |  |  |  * License along with this library; if not, write to the Free Software | 
					
						
							|  |  |  |  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @category   PHPExcel | 
					
						
							|  |  |  |  * @package    PHPExcel_Reader | 
					
						
							| 
									
										
										
										
											2013-05-14 11:20:28 +00:00
										 |  |  |  * @copyright  Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) | 
					
						
							| 
									
										
										
										
											2012-06-07 19:43:19 +00:00
										 |  |  |  * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt	LGPL | 
					
						
							|  |  |  |  * @version    ##VERSION##, ##DATE##
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** PHPExcel root directory */ | 
					
						
							|  |  |  | if (!defined('PHPEXCEL_ROOT')) { | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @ignore | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../'); | 
					
						
							|  |  |  | 	require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php'); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * PHPExcel_Reader_HTML | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @category   PHPExcel | 
					
						
							|  |  |  |  * @package    PHPExcel_Reader | 
					
						
							| 
									
										
										
										
											2013-05-14 11:20:28 +00:00
										 |  |  |  * @copyright  Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel) | 
					
						
							| 
									
										
										
										
											2012-06-07 19:43:19 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2012-11-05 21:23:38 +00:00
										 |  |  | class PHPExcel_Reader_HTML extends PHPExcel_Reader_Abstract implements PHPExcel_Reader_IReader | 
					
						
							| 
									
										
										
										
											2012-06-07 19:43:19 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Input encoding | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @var string | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	private $_inputEncoding	= 'ANSI'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Sheet index to read | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @var int | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	private $_sheetIndex 	= 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Formats | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @var array | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	private $_formats = array( 'h1' => array( 'font' => array( 'bold' => true, | 
					
						
							|  |  |  | 															   'size' => 24, | 
					
						
							|  |  |  | 															 ), | 
					
						
							|  |  |  | 											),	//	Bold, 24pt
 | 
					
						
							|  |  |  | 							   'h2' => array( 'font' => array( 'bold' => true, | 
					
						
							|  |  |  | 															   'size' => 18, | 
					
						
							|  |  |  | 															 ), | 
					
						
							|  |  |  | 											),	//	Bold, 18pt
 | 
					
						
							|  |  |  | 							   'h3' => array( 'font' => array( 'bold' => true, | 
					
						
							|  |  |  | 															   'size' => 13.5, | 
					
						
							|  |  |  | 															 ), | 
					
						
							|  |  |  | 											),	//	Bold, 13.5pt
 | 
					
						
							|  |  |  | 							   'h4' => array( 'font' => array( 'bold' => true, | 
					
						
							|  |  |  | 															   'size' => 12, | 
					
						
							|  |  |  | 															 ), | 
					
						
							|  |  |  | 											),	//	Bold, 12pt
 | 
					
						
							|  |  |  | 							   'h5' => array( 'font' => array( 'bold' => true, | 
					
						
							|  |  |  | 															   'size' => 10, | 
					
						
							|  |  |  | 															 ), | 
					
						
							|  |  |  | 											),	//	Bold, 10pt
 | 
					
						
							|  |  |  | 							   'h6' => array( 'font' => array( 'bold' => true, | 
					
						
							|  |  |  | 															   'size' => 7.5, | 
					
						
							|  |  |  | 															 ), | 
					
						
							|  |  |  | 											),	//	Bold, 7.5pt
 | 
					
						
							|  |  |  | 							   'a'  => array( 'font' => array( 'underline' => true, | 
					
						
							|  |  |  | 															   'color' => array( 'argb' => PHPExcel_Style_Color::COLOR_BLUE, | 
					
						
							|  |  |  | 															                   ), | 
					
						
							|  |  |  | 															 ), | 
					
						
							|  |  |  | 											),	//	Blue underlined
 | 
					
						
							|  |  |  | 							   'hr' => array( 'borders' => array( 'bottom' => array( 'style' => PHPExcel_Style_Border::BORDER_THIN, | 
					
						
							|  |  |  | 																					 'color' => array( PHPExcel_Style_Color::COLOR_BLACK, | 
					
						
							|  |  |  | 																					                 ), | 
					
						
							|  |  |  | 																				   ), | 
					
						
							|  |  |  | 																), | 
					
						
							|  |  |  | 											),	//	Bottom border
 | 
					
						
							|  |  |  | 							 ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Create a new PHPExcel_Reader_HTML | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public function __construct() { | 
					
						
							|  |  |  | 		$this->_readFilter 	= new PHPExcel_Reader_DefaultReadFilter(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2013-05-06 22:39:49 +00:00
										 |  |  | 	 * Validate that the current file is an HTML file | 
					
						
							| 
									
										
										
										
											2012-06-07 19:43:19 +00:00
										 |  |  | 	 * | 
					
						
							| 
									
										
										
										
											2013-05-06 22:39:49 +00:00
										 |  |  | 	 * @return boolean | 
					
						
							| 
									
										
										
										
											2012-06-07 19:43:19 +00:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2013-05-06 22:39:49 +00:00
										 |  |  | 	protected function _isValidFormat() | 
					
						
							| 
									
										
										
										
											2012-06-07 19:43:19 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2013-05-06 22:39:49 +00:00
										 |  |  | 		//	Reading 2048 bytes should be enough to validate that the format is HTML
 | 
					
						
							|  |  |  | 		$data = fread($this->_fileHandle, 2048); | 
					
						
							| 
									
										
										
										
											2013-06-21 21:52:29 +00:00
										 |  |  | 		if ((strpos($data, '<') !== FALSE) && | 
					
						
							| 
									
										
										
										
											2012-10-16 12:39:59 +00:00
										 |  |  | 			(strlen($data) !== strlen(strip_tags($data)))) { | 
					
						
							|  |  |  | 			return TRUE; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return FALSE; | 
					
						
							| 
									
										
										
										
											2012-06-07 19:43:19 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Loads PHPExcel from file | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @param 	string 		$pFilename | 
					
						
							|  |  |  | 	 * @return 	PHPExcel | 
					
						
							| 
									
										
										
										
											2012-10-29 23:48:29 +00:00
										 |  |  | 	 * @throws 	PHPExcel_Reader_Exception | 
					
						
							| 
									
										
										
										
											2012-06-07 19:43:19 +00:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	public function load($pFilename) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		// Create new PHPExcel
 | 
					
						
							|  |  |  | 		$objPHPExcel = new PHPExcel(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Load into this instance
 | 
					
						
							|  |  |  | 		return $this->loadIntoExisting($pFilename, $objPHPExcel); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Set input encoding | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @param string $pValue Input encoding | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public function setInputEncoding($pValue = 'ANSI') | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		$this->_inputEncoding = $pValue; | 
					
						
							|  |  |  | 		return $this; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Get input encoding | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @return string | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public function getInputEncoding() | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return $this->_inputEncoding; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	//	Data Array used for testing only, should write to PHPExcel object on completion of tests
 | 
					
						
							|  |  |  | 	private $_dataArray = array(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	private $_tableLevel = 0; | 
					
						
							|  |  |  | 	private $_nestedColumn = array('A'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	private function _setTableStartColumn($column) { | 
					
						
							|  |  |  | 		if ($this->_tableLevel == 0) | 
					
						
							|  |  |  | 			$column = 'A'; | 
					
						
							|  |  |  | 		++$this->_tableLevel; | 
					
						
							|  |  |  | 		$this->_nestedColumn[$this->_tableLevel] = $column; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return $this->_nestedColumn[$this->_tableLevel]; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	private function _getTableStartColumn() { | 
					
						
							|  |  |  | 		return $this->_nestedColumn[$this->_tableLevel]; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	private function _releaseTableStartColumn() { | 
					
						
							|  |  |  | 		--$this->_tableLevel; | 
					
						
							|  |  |  | 		return array_pop($this->_nestedColumn); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	private function _flushCell($sheet,$column,$row,&$cellContent) { | 
					
						
							|  |  |  | 		if (is_string($cellContent)) { | 
					
						
							|  |  |  | 			//	Simple String content
 | 
					
						
							|  |  |  | 			if (trim($cellContent) > '') { | 
					
						
							|  |  |  | 				//	Only actually write it if there's content in the string
 | 
					
						
							| 
									
										
										
										
											2012-12-11 21:55:46 +00:00
										 |  |  | //				echo 'FLUSH CELL: ' , $column , $row , ' => ' , $cellContent , '<br />';
 | 
					
						
							| 
									
										
										
										
											2012-06-07 19:43:19 +00:00
										 |  |  | 				//	Write to worksheet to be done here...
 | 
					
						
							|  |  |  | 				//	... we return the cell so we can mess about with styles more easily
 | 
					
						
							|  |  |  | 				$cell = $sheet->setCellValue($column.$row,$cellContent,true); | 
					
						
							|  |  |  | 				$this->_dataArray[$row][$column] = $cellContent; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			//	We have a Rich Text run
 | 
					
						
							|  |  |  | 			//	TODO
 | 
					
						
							|  |  |  | 			$this->_dataArray[$row][$column] = 'RICH TEXT: ' . $cellContent; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		$cellContent = (string) ''; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	private function _processDomElement(DOMNode $element, $sheet, &$row, &$column, &$cellContent){ | 
					
						
							|  |  |  | 		foreach($element->childNodes as $child){ | 
					
						
							| 
									
										
										
										
											2012-10-29 23:48:29 +00:00
										 |  |  | 			if ($child instanceof DOMText) { | 
					
						
							| 
									
										
										
										
											2012-06-07 19:43:19 +00:00
										 |  |  | 				$domText = preg_replace('/\s+/',' ',trim($child->nodeValue)); | 
					
						
							|  |  |  | 				if (is_string($cellContent)) { | 
					
						
							|  |  |  | 					//	simply append the text if the cell content is a plain text string
 | 
					
						
							|  |  |  | 					$cellContent .= $domText; | 
					
						
							|  |  |  | 				} else { | 
					
						
							|  |  |  | 					//	but if we have a rich text run instead, we need to append it correctly
 | 
					
						
							|  |  |  | 					//	TODO
 | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2012-10-29 23:48:29 +00:00
										 |  |  | 			} elseif($child instanceof DOMElement) { | 
					
						
							| 
									
										
										
										
											2012-12-11 21:55:46 +00:00
										 |  |  | //				echo '<b>DOM ELEMENT: </b>' , strtoupper($child->nodeName) , '<br />';
 | 
					
						
							| 
									
										
										
										
											2012-06-07 19:43:19 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				$attributeArray = array(); | 
					
						
							|  |  |  | 				foreach($child->attributes as $attribute) { | 
					
						
							| 
									
										
										
										
											2012-12-11 21:55:46 +00:00
										 |  |  | //					echo '<b>ATTRIBUTE: </b>' , $attribute->name , ' => ' , $attribute->value , '<br />';
 | 
					
						
							| 
									
										
										
										
											2012-06-07 19:43:19 +00:00
										 |  |  | 					$attributeArray[$attribute->name] = $attribute->value; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				switch($child->nodeName) { | 
					
						
							|  |  |  | 					case 'meta' : | 
					
						
							|  |  |  | 						foreach($attributeArray as $attributeName => $attributeValue) { | 
					
						
							|  |  |  | 							switch($attributeName) { | 
					
						
							|  |  |  | 								case 'content': | 
					
						
							|  |  |  | 									//	TODO
 | 
					
						
							|  |  |  | 									//	Extract character set, so we can convert to UTF-8 if required
 | 
					
						
							|  |  |  | 									break; | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 						$this->_processDomElement($child,$sheet,$row,$column,$cellContent); | 
					
						
							|  |  |  | 						break; | 
					
						
							|  |  |  | 					case 'title' : | 
					
						
							|  |  |  | 						$this->_processDomElement($child,$sheet,$row,$column,$cellContent); | 
					
						
							|  |  |  | 						$sheet->setTitle($cellContent); | 
					
						
							|  |  |  | 						$cellContent = ''; | 
					
						
							|  |  |  | 						break; | 
					
						
							|  |  |  | 					case 'span'  : | 
					
						
							|  |  |  | 					case 'div'   : | 
					
						
							|  |  |  | 					case 'font'  : | 
					
						
							|  |  |  | 					case 'i'     : | 
					
						
							|  |  |  | 					case 'em'    : | 
					
						
							|  |  |  | 					case 'strong': | 
					
						
							|  |  |  | 					case 'b'     : | 
					
						
							| 
									
										
										
										
											2012-12-11 21:55:46 +00:00
										 |  |  | //						echo 'STYLING, SPAN OR DIV<br />';
 | 
					
						
							| 
									
										
										
										
											2012-06-07 19:43:19 +00:00
										 |  |  | 						if ($cellContent > '') | 
					
						
							|  |  |  | 							$cellContent .= ' '; | 
					
						
							|  |  |  | 						$this->_processDomElement($child,$sheet,$row,$column,$cellContent); | 
					
						
							|  |  |  | 						if ($cellContent > '') | 
					
						
							|  |  |  | 							$cellContent .= ' '; | 
					
						
							| 
									
										
										
										
											2012-12-11 21:55:46 +00:00
										 |  |  | //						echo 'END OF STYLING, SPAN OR DIV<br />';
 | 
					
						
							| 
									
										
										
										
											2012-06-07 19:43:19 +00:00
										 |  |  | 						break; | 
					
						
							|  |  |  | 					case 'hr' : | 
					
						
							|  |  |  | 						$this->_flushCell($sheet,$column,$row,$cellContent); | 
					
						
							|  |  |  | 						++$row; | 
					
						
							|  |  |  | 						if (isset($this->_formats[$child->nodeName])) { | 
					
						
							|  |  |  | 							$sheet->getStyle($column.$row)->applyFromArray($this->_formats[$child->nodeName]); | 
					
						
							|  |  |  | 						} else { | 
					
						
							|  |  |  | 							$cellContent = '----------'; | 
					
						
							|  |  |  | 							$this->_flushCell($sheet,$column,$row,$cellContent); | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 						++$row; | 
					
						
							|  |  |  | 					case 'br' : | 
					
						
							|  |  |  | 						if ($this->_tableLevel > 0) { | 
					
						
							|  |  |  | 							//	If we're inside a table, replace with a \n
 | 
					
						
							|  |  |  | 							$cellContent .= "\n"; | 
					
						
							|  |  |  | 						} else { | 
					
						
							|  |  |  | 							//	Otherwise flush our existing content and move the row cursor on
 | 
					
						
							|  |  |  | 							$this->_flushCell($sheet,$column,$row,$cellContent); | 
					
						
							|  |  |  | 							++$row; | 
					
						
							|  |  |  | 						} | 
					
						
							| 
									
										
										
										
											2012-12-11 21:55:46 +00:00
										 |  |  | //						echo 'HARD LINE BREAK: ' , '<br />';
 | 
					
						
							| 
									
										
										
										
											2012-06-07 19:43:19 +00:00
										 |  |  | 						break; | 
					
						
							|  |  |  | 					case 'a'  : | 
					
						
							| 
									
										
										
										
											2012-12-11 21:55:46 +00:00
										 |  |  | //						echo 'START OF HYPERLINK: ' , '<br />';
 | 
					
						
							| 
									
										
										
										
											2012-06-07 19:43:19 +00:00
										 |  |  | 						foreach($attributeArray as $attributeName => $attributeValue) { | 
					
						
							|  |  |  | 							switch($attributeName) { | 
					
						
							|  |  |  | 								case 'href': | 
					
						
							| 
									
										
										
										
											2012-12-11 21:55:46 +00:00
										 |  |  | //									echo 'Link to ' , $attributeValue , '<br />';
 | 
					
						
							| 
									
										
										
										
											2012-06-07 19:43:19 +00:00
										 |  |  | 									$sheet->getCell($column.$row)->getHyperlink()->setUrl($attributeValue); | 
					
						
							|  |  |  | 									if (isset($this->_formats[$child->nodeName])) { | 
					
						
							|  |  |  | 										$sheet->getStyle($column.$row)->applyFromArray($this->_formats[$child->nodeName]); | 
					
						
							|  |  |  | 									} | 
					
						
							|  |  |  | 									break; | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 						$cellContent .= ' '; | 
					
						
							|  |  |  | 						$this->_processDomElement($child,$sheet,$row,$column,$cellContent); | 
					
						
							| 
									
										
										
										
											2012-12-11 21:55:46 +00:00
										 |  |  | //						echo 'END OF HYPERLINK:' , '<br />';
 | 
					
						
							| 
									
										
										
										
											2012-06-07 19:43:19 +00:00
										 |  |  | 						break; | 
					
						
							|  |  |  | 					case 'h1' : | 
					
						
							|  |  |  | 					case 'h2' : | 
					
						
							|  |  |  | 					case 'h3' : | 
					
						
							|  |  |  | 					case 'h4' : | 
					
						
							|  |  |  | 					case 'h5' : | 
					
						
							|  |  |  | 					case 'h6' : | 
					
						
							|  |  |  | 					case 'ol' : | 
					
						
							|  |  |  | 					case 'ul' : | 
					
						
							|  |  |  | 					case 'p'  : | 
					
						
							|  |  |  | 						if ($this->_tableLevel > 0) { | 
					
						
							|  |  |  | 							//	If we're inside a table, replace with a \n
 | 
					
						
							|  |  |  | 							$cellContent .= "\n"; | 
					
						
							| 
									
										
										
										
											2012-12-11 21:55:46 +00:00
										 |  |  | //							echo 'LIST ENTRY: ' , '<br />';
 | 
					
						
							| 
									
										
										
										
											2012-06-07 19:43:19 +00:00
										 |  |  | 							$this->_processDomElement($child,$sheet,$row,$column,$cellContent); | 
					
						
							| 
									
										
										
										
											2012-12-11 21:55:46 +00:00
										 |  |  | //							echo 'END OF LIST ENTRY:' , '<br />';
 | 
					
						
							| 
									
										
										
										
											2012-06-07 19:43:19 +00:00
										 |  |  | 						} else { | 
					
						
							|  |  |  | 							if ($cellContent > '') { | 
					
						
							|  |  |  | 								$this->_flushCell($sheet,$column,$row,$cellContent); | 
					
						
							|  |  |  | 								$row += 2; | 
					
						
							|  |  |  | 							} | 
					
						
							| 
									
										
										
										
											2012-12-11 21:55:46 +00:00
										 |  |  | //							echo 'START OF PARAGRAPH: ' , '<br />';
 | 
					
						
							| 
									
										
										
										
											2012-06-07 19:43:19 +00:00
										 |  |  | 							$this->_processDomElement($child,$sheet,$row,$column,$cellContent); | 
					
						
							| 
									
										
										
										
											2012-12-11 21:55:46 +00:00
										 |  |  | //							echo 'END OF PARAGRAPH:' , '<br />';
 | 
					
						
							| 
									
										
										
										
											2012-06-07 19:43:19 +00:00
										 |  |  | 							$this->_flushCell($sheet,$column,$row,$cellContent); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 							if (isset($this->_formats[$child->nodeName])) { | 
					
						
							|  |  |  | 								$sheet->getStyle($column.$row)->applyFromArray($this->_formats[$child->nodeName]); | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 							$row += 2; | 
					
						
							|  |  |  | 							$column = 'A'; | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 						break; | 
					
						
							|  |  |  | 					case 'li'  : | 
					
						
							|  |  |  | 						if ($this->_tableLevel > 0) { | 
					
						
							|  |  |  | 							//	If we're inside a table, replace with a \n
 | 
					
						
							|  |  |  | 							$cellContent .= "\n"; | 
					
						
							| 
									
										
										
										
											2012-12-11 21:55:46 +00:00
										 |  |  | //							echo 'LIST ENTRY: ' , '<br />';
 | 
					
						
							| 
									
										
										
										
											2012-06-07 19:43:19 +00:00
										 |  |  | 							$this->_processDomElement($child,$sheet,$row,$column,$cellContent); | 
					
						
							| 
									
										
										
										
											2012-12-11 21:55:46 +00:00
										 |  |  | //							echo 'END OF LIST ENTRY:' , '<br />';
 | 
					
						
							| 
									
										
										
										
											2012-06-07 19:43:19 +00:00
										 |  |  | 						} else { | 
					
						
							|  |  |  | 							if ($cellContent > '') { | 
					
						
							|  |  |  | 								$this->_flushCell($sheet,$column,$row,$cellContent); | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 							++$row; | 
					
						
							| 
									
										
										
										
											2012-12-11 21:55:46 +00:00
										 |  |  | //							echo 'LIST ENTRY: ' , '<br />';
 | 
					
						
							| 
									
										
										
										
											2012-06-07 19:43:19 +00:00
										 |  |  | 							$this->_processDomElement($child,$sheet,$row,$column,$cellContent); | 
					
						
							| 
									
										
										
										
											2012-12-11 21:55:46 +00:00
										 |  |  | //							echo 'END OF LIST ENTRY:' , '<br />';
 | 
					
						
							| 
									
										
										
										
											2012-06-07 19:43:19 +00:00
										 |  |  | 							$this->_flushCell($sheet,$column,$row,$cellContent); | 
					
						
							|  |  |  | 							$column = 'A'; | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 						break; | 
					
						
							|  |  |  | 					case 'table' : | 
					
						
							|  |  |  | 						$this->_flushCell($sheet,$column,$row,$cellContent); | 
					
						
							|  |  |  | 						$column = $this->_setTableStartColumn($column); | 
					
						
							| 
									
										
										
										
											2012-12-11 21:55:46 +00:00
										 |  |  | //						echo 'START OF TABLE LEVEL ' , $this->_tableLevel , '<br />';
 | 
					
						
							| 
									
										
										
										
											2012-06-07 19:43:19 +00:00
										 |  |  | 						if ($this->_tableLevel > 1) | 
					
						
							|  |  |  | 							--$row; | 
					
						
							|  |  |  | 						$this->_processDomElement($child,$sheet,$row,$column,$cellContent); | 
					
						
							| 
									
										
										
										
											2012-12-11 21:55:46 +00:00
										 |  |  | //						echo 'END OF TABLE LEVEL ' , $this->_tableLevel , '<br />';
 | 
					
						
							| 
									
										
										
										
											2012-06-07 19:43:19 +00:00
										 |  |  | 						$column = $this->_releaseTableStartColumn(); | 
					
						
							|  |  |  | 						if ($this->_tableLevel > 1) { | 
					
						
							|  |  |  | 							++$column; | 
					
						
							|  |  |  | 						} else { | 
					
						
							|  |  |  | 							++$row; | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 						break; | 
					
						
							|  |  |  | 					case 'thead' : | 
					
						
							|  |  |  | 					case 'tbody' : | 
					
						
							|  |  |  | 						$this->_processDomElement($child,$sheet,$row,$column,$cellContent); | 
					
						
							|  |  |  | 						break; | 
					
						
							|  |  |  | 					case 'tr' : | 
					
						
							|  |  |  | 						++$row; | 
					
						
							|  |  |  | 						$column = $this->_getTableStartColumn(); | 
					
						
							|  |  |  | 						$cellContent = ''; | 
					
						
							| 
									
										
										
										
											2012-12-11 21:55:46 +00:00
										 |  |  | //						echo 'START OF TABLE ' , $this->_tableLevel , ' ROW<br />';
 | 
					
						
							| 
									
										
										
										
											2012-06-07 19:43:19 +00:00
										 |  |  | 						$this->_processDomElement($child,$sheet,$row,$column,$cellContent); | 
					
						
							| 
									
										
										
										
											2012-12-11 21:55:46 +00:00
										 |  |  | //						echo 'END OF TABLE ' , $this->_tableLevel , ' ROW<br />';
 | 
					
						
							| 
									
										
										
										
											2012-06-07 19:43:19 +00:00
										 |  |  | 						break; | 
					
						
							|  |  |  | 					case 'th' : | 
					
						
							|  |  |  | 					case 'td' : | 
					
						
							| 
									
										
										
										
											2012-12-11 21:55:46 +00:00
										 |  |  | //						echo 'START OF TABLE ' , $this->_tableLevel , ' CELL<br />';
 | 
					
						
							| 
									
										
										
										
											2012-06-07 19:43:19 +00:00
										 |  |  | 						$this->_processDomElement($child,$sheet,$row,$column,$cellContent); | 
					
						
							| 
									
										
										
										
											2012-12-11 21:55:46 +00:00
										 |  |  | //						echo 'END OF TABLE ' , $this->_tableLevel , ' CELL<br />';
 | 
					
						
							| 
									
										
										
										
											2012-06-07 19:43:19 +00:00
										 |  |  | 						$this->_flushCell($sheet,$column,$row,$cellContent); | 
					
						
							|  |  |  | 						++$column; | 
					
						
							|  |  |  | 						break; | 
					
						
							|  |  |  | 					case 'body' : | 
					
						
							|  |  |  | 						$row = 1; | 
					
						
							|  |  |  | 						$column = 'A'; | 
					
						
							|  |  |  | 						$content = ''; | 
					
						
							|  |  |  | 						$this->_tableLevel = 0; | 
					
						
							|  |  |  | 						$this->_processDomElement($child,$sheet,$row,$column,$cellContent); | 
					
						
							|  |  |  | 						break; | 
					
						
							|  |  |  | 					default: | 
					
						
							|  |  |  | 						$this->_processDomElement($child,$sheet,$row,$column,$cellContent); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Loads PHPExcel from file into PHPExcel instance | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @param 	string 		$pFilename | 
					
						
							|  |  |  | 	 * @param	PHPExcel	$objPHPExcel | 
					
						
							|  |  |  | 	 * @return 	PHPExcel | 
					
						
							| 
									
										
										
										
											2012-10-29 23:48:29 +00:00
										 |  |  | 	 * @throws 	PHPExcel_Reader_Exception | 
					
						
							| 
									
										
										
										
											2012-06-07 19:43:19 +00:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	public function loadIntoExisting($pFilename, PHPExcel $objPHPExcel) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2013-05-06 22:39:49 +00:00
										 |  |  | 		// Open file to validate
 | 
					
						
							|  |  |  | 		$this->_openFile($pFilename); | 
					
						
							|  |  |  | 		if (!$this->_isValidFormat()) { | 
					
						
							|  |  |  | 			fclose ($this->_fileHandle); | 
					
						
							|  |  |  | 			throw new PHPExcel_Reader_Exception($pFilename . " is an Invalid HTML file."); | 
					
						
							| 
									
										
										
										
											2012-09-05 11:12:51 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-05-06 22:39:49 +00:00
										 |  |  | 		//	Close after validating
 | 
					
						
							|  |  |  | 		fclose ($this->_fileHandle); | 
					
						
							| 
									
										
										
										
											2012-09-05 11:12:51 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-07 19:43:19 +00:00
										 |  |  | 		// Create new PHPExcel
 | 
					
						
							|  |  |  | 		while ($objPHPExcel->getSheetCount() <= $this->_sheetIndex) { | 
					
						
							|  |  |  | 			$objPHPExcel->createSheet(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		$objPHPExcel->setActiveSheetIndex( $this->_sheetIndex ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		//	Create a new DOM object
 | 
					
						
							|  |  |  | 		$dom = new domDocument; | 
					
						
							| 
									
										
										
										
											2013-05-06 22:39:49 +00:00
										 |  |  | 		//	Reload the HTML file into the DOM object
 | 
					
						
							| 
									
										
										
										
											2012-06-07 19:43:19 +00:00
										 |  |  | 		$loaded = $dom->loadHTMLFile($pFilename); | 
					
						
							| 
									
										
										
										
											2013-05-06 22:39:49 +00:00
										 |  |  | 		if ($loaded === FALSE) { | 
					
						
							| 
									
										
										
										
											2012-10-29 23:48:29 +00:00
										 |  |  | 			throw new PHPExcel_Reader_Exception('Failed to load ',$pFilename,' as a DOM Document'); | 
					
						
							| 
									
										
										
										
											2012-06-07 19:43:19 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		//	Discard white space
 | 
					
						
							|  |  |  | 		$dom->preserveWhiteSpace = false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		$row = 0; | 
					
						
							|  |  |  | 		$column = 'A'; | 
					
						
							|  |  |  | 		$content = ''; | 
					
						
							|  |  |  | 		$this->_processDomElement($dom,$objPHPExcel->getActiveSheet(),$row,$column,$content); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-11 21:55:46 +00:00
										 |  |  | //		echo '<hr />';
 | 
					
						
							|  |  |  | //		var_dump($this->_dataArray);
 | 
					
						
							| 
									
										
										
										
											2012-06-07 19:43:19 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// Return
 | 
					
						
							|  |  |  | 		return $objPHPExcel; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Get sheet index | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @return int | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public function getSheetIndex() { | 
					
						
							|  |  |  | 		return $this->_sheetIndex; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Set sheet index | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @param	int		$pValue		Sheet index | 
					
						
							|  |  |  | 	 * @return PHPExcel_Reader_HTML | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public function setSheetIndex($pValue = 0) { | 
					
						
							|  |  |  | 		$this->_sheetIndex = $pValue; | 
					
						
							|  |  |  | 		return $this; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |