| 
									
										
										
										
											2012-06-07 19:43:19 +00:00
										 |  |  | <?php | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-16 23:16:41 +00:00
										 |  |  | if (!defined('PHPEXCEL_ROOT')) { | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @ignore | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../'); | 
					
						
							|  |  |  |     require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php'); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-07 19:43:19 +00:00
										 |  |  | /** | 
					
						
							| 
									
										
										
										
											2015-05-16 23:16:41 +00:00
										 |  |  |  * PHPExcel_Reader_HTML | 
					
						
							| 
									
										
										
										
											2012-06-07 19:43:19 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2015-05-02 22:50:37 +00:00
										 |  |  |  * Copyright (c) 2006 - 2015 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 | 
					
						
							| 
									
										
										
										
											2015-05-02 22:50:37 +00:00
										 |  |  |  * @copyright  Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel) | 
					
						
							| 
									
										
										
										
											2015-05-11 21:38:52 +00:00
										 |  |  |  * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL | 
					
						
							| 
									
										
										
										
											2012-06-07 19:43:19 +00:00
										 |  |  |  * @version    ##VERSION##, ##DATE##
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | /** PHPExcel root directory */ | 
					
						
							| 
									
										
										
										
											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
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Input encoding | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @var string | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     protected $_inputEncoding = 'ANSI'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Sheet index to read | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @var int | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     protected $_sheetIndex = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Formats | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @var array | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     protected $_formats = array( | 
					
						
							|  |  |  |         'h1' => array('font' => array('bold' => true, | 
					
						
							|  |  |  |                 'size' => 24, | 
					
						
							|  |  |  |             ), | 
					
						
							| 
									
										
										
										
											2015-05-11 21:38:52 +00:00
										 |  |  |         ), //    Bold, 24pt
 | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |         'h2' => array('font' => array('bold' => true, | 
					
						
							|  |  |  |                 'size' => 18, | 
					
						
							|  |  |  |             ), | 
					
						
							| 
									
										
										
										
											2015-05-11 21:38:52 +00:00
										 |  |  |         ), //    Bold, 18pt
 | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |         'h3' => array('font' => array('bold' => true, | 
					
						
							|  |  |  |                 'size' => 13.5, | 
					
						
							|  |  |  |             ), | 
					
						
							| 
									
										
										
										
											2015-05-11 21:38:52 +00:00
										 |  |  |         ), //    Bold, 13.5pt
 | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |         'h4' => array('font' => array('bold' => true, | 
					
						
							|  |  |  |                 'size' => 12, | 
					
						
							|  |  |  |             ), | 
					
						
							| 
									
										
										
										
											2015-05-11 21:38:52 +00:00
										 |  |  |         ), //    Bold, 12pt
 | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |         'h5' => array('font' => array('bold' => true, | 
					
						
							|  |  |  |                 'size' => 10, | 
					
						
							|  |  |  |             ), | 
					
						
							| 
									
										
										
										
											2015-05-11 21:38:52 +00:00
										 |  |  |         ), //    Bold, 10pt
 | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |         'h6' => array('font' => array('bold' => true, | 
					
						
							|  |  |  |                 'size' => 7.5, | 
					
						
							|  |  |  |             ), | 
					
						
							| 
									
										
										
										
											2015-05-11 21:38:52 +00:00
										 |  |  |         ), //    Bold, 7.5pt
 | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |         'a' => array('font' => array('underline' => true, | 
					
						
							|  |  |  |                 'color' => array('argb' => PHPExcel_Style_Color::COLOR_BLUE, | 
					
						
							|  |  |  |                 ), | 
					
						
							|  |  |  |             ), | 
					
						
							| 
									
										
										
										
											2015-05-11 21:38:52 +00:00
										 |  |  |         ), //    Blue underlined
 | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |         'hr' => array('borders' => array('bottom' => array('style' => PHPExcel_Style_Border::BORDER_THIN, | 
					
						
							|  |  |  |                     'color' => array(\PHPExcel_Style_Color::COLOR_BLACK, | 
					
						
							|  |  |  |                     ), | 
					
						
							|  |  |  |                 ), | 
					
						
							|  |  |  |             ), | 
					
						
							| 
									
										
										
										
											2015-05-11 21:38:52 +00:00
										 |  |  |         ), //    Bottom border
 | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |     ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     protected $rowspan = array(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Create a new PHPExcel_Reader_HTML | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function __construct() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $this->_readFilter = new PHPExcel_Reader_DefaultReadFilter(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Validate that the current file is an HTML file | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return boolean | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     protected function _isValidFormat() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-05-11 21:38:52 +00:00
										 |  |  |         //    Reading 2048 bytes should be enough to validate that the format is HTML
 | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |         $data = fread($this->_fileHandle, 2048); | 
					
						
							| 
									
										
										
										
											2015-05-16 23:16:41 +00:00
										 |  |  |         if ((strpos($data, '<') !== false) && | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |                 (strlen($data) !== strlen(strip_tags($data)))) { | 
					
						
							| 
									
										
										
										
											2015-05-16 23:16:41 +00:00
										 |  |  |             return true; | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-16 23:16:41 +00:00
										 |  |  |         return false; | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Loads PHPExcel from file | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param  string                    $pFilename | 
					
						
							|  |  |  |      * @return PHPExcel | 
					
						
							|  |  |  |      * @throws PHPExcel_Reader_Exception | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     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; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-11 21:38:52 +00:00
										 |  |  |     //    Data Array used for testing only, should write to PHPExcel object on completion of tests
 | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |     protected $_dataArray = array(); | 
					
						
							|  |  |  |     protected $_tableLevel = 0; | 
					
						
							|  |  |  |     protected $_nestedColumn = array('A'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     protected function _setTableStartColumn($column) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-05-16 23:16:41 +00:00
										 |  |  |         if ($this->_tableLevel == 0) { | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |             $column = 'A'; | 
					
						
							| 
									
										
										
										
											2015-05-16 23:16:41 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |         ++$this->_tableLevel; | 
					
						
							|  |  |  |         $this->_nestedColumn[$this->_tableLevel] = $column; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $this->_nestedColumn[$this->_tableLevel]; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     protected function _getTableStartColumn() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return $this->_nestedColumn[$this->_tableLevel]; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     protected function _releaseTableStartColumn() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         --$this->_tableLevel; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return array_pop($this->_nestedColumn); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     protected function _flushCell($sheet, $column, $row, &$cellContent) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         if (is_string($cellContent)) { | 
					
						
							| 
									
										
										
										
											2015-05-11 21:38:52 +00:00
										 |  |  |             //    Simple String content
 | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |             if (trim($cellContent) > '') { | 
					
						
							| 
									
										
										
										
											2015-05-11 21:38:52 +00:00
										 |  |  |                 //    Only actually write it if there's content in the string
 | 
					
						
							|  |  |  | //                echo 'FLUSH CELL: ' , $column , $row , ' => ' , $cellContent , '<br />';
 | 
					
						
							|  |  |  |                 //    Write to worksheet to be done here...
 | 
					
						
							|  |  |  |                 //    ... we return the cell so we can mess about with styles more easily
 | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |                 $sheet->setCellValue($column . $row, $cellContent, true); | 
					
						
							|  |  |  |                 $this->_dataArray[$row][$column] = $cellContent; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2015-05-11 21:38:52 +00:00
										 |  |  |             //    We have a Rich Text run
 | 
					
						
							|  |  |  |             //    TODO
 | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |             $this->_dataArray[$row][$column] = 'RICH TEXT: ' . $cellContent; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         $cellContent = (string) ''; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     protected function _processDomElement(DOMNode $element, $sheet, &$row, &$column, &$cellContent, $format = null) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         foreach ($element->childNodes as $child) { | 
					
						
							|  |  |  |             if ($child instanceof DOMText) { | 
					
						
							| 
									
										
										
										
											2015-02-14 23:52:57 +00:00
										 |  |  |                 $domText = preg_replace('/\s+/u', ' ', trim($child->nodeValue)); | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |                 if (is_string($cellContent)) { | 
					
						
							| 
									
										
										
										
											2015-05-11 21:38:52 +00:00
										 |  |  |                     //    simply append the text if the cell content is a plain text string
 | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |                     $cellContent .= $domText; | 
					
						
							|  |  |  |                 } else { | 
					
						
							| 
									
										
										
										
											2015-05-11 21:38:52 +00:00
										 |  |  |                     //    but if we have a rich text run instead, we need to append it correctly
 | 
					
						
							|  |  |  |                     //    TODO
 | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |                 } | 
					
						
							|  |  |  |             } elseif ($child instanceof DOMElement) { | 
					
						
							| 
									
										
										
										
											2015-05-11 21:38:52 +00:00
										 |  |  | //                echo '<b>DOM ELEMENT: </b>' , strtoupper($child->nodeName) , '<br />';
 | 
					
						
							| 
									
										
										
										
											2012-06-07 19:43:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |                 $attributeArray = array(); | 
					
						
							|  |  |  |                 foreach ($child->attributes as $attribute) { | 
					
						
							| 
									
										
										
										
											2015-05-11 21:38:52 +00:00
										 |  |  | //                    echo '<b>ATTRIBUTE: </b>' , $attribute->name , ' => ' , $attribute->value , '<br />';
 | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |                     $attributeArray[$attribute->name] = $attribute->value; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 switch ($child->nodeName) { | 
					
						
							| 
									
										
										
										
											2015-05-16 23:16:41 +00:00
										 |  |  |                     case 'meta': | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |                         foreach ($attributeArray as $attributeName => $attributeValue) { | 
					
						
							|  |  |  |                             switch ($attributeName) { | 
					
						
							|  |  |  |                                 case 'content': | 
					
						
							| 
									
										
										
										
											2015-05-11 21:38:52 +00:00
										 |  |  |                                     //    TODO
 | 
					
						
							|  |  |  |                                     //    Extract character set, so we can convert to UTF-8 if required
 | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |                                     break; | 
					
						
							|  |  |  |                             } | 
					
						
							|  |  |  |                         } | 
					
						
							|  |  |  |                         $this->_processDomElement($child, $sheet, $row, $column, $cellContent); | 
					
						
							|  |  |  |                         break; | 
					
						
							| 
									
										
										
										
											2015-05-16 23:16:41 +00:00
										 |  |  |                     case 'title': | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |                         $this->_processDomElement($child, $sheet, $row, $column, $cellContent); | 
					
						
							|  |  |  |                         $sheet->setTitle($cellContent); | 
					
						
							|  |  |  |                         $cellContent = ''; | 
					
						
							|  |  |  |                         break; | 
					
						
							| 
									
										
										
										
											2015-05-16 23:16:41 +00:00
										 |  |  |                     case 'span': | 
					
						
							|  |  |  |                     case 'div': | 
					
						
							|  |  |  |                     case 'font': | 
					
						
							|  |  |  |                     case 'i': | 
					
						
							|  |  |  |                     case 'em': | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |                     case 'strong': | 
					
						
							| 
									
										
										
										
											2015-05-16 23:16:41 +00:00
										 |  |  |                     case 'b': | 
					
						
							| 
									
										
										
										
											2015-05-11 21:38:52 +00:00
										 |  |  | //                        echo 'STYLING, SPAN OR DIV<br />';
 | 
					
						
							| 
									
										
										
										
											2015-05-16 23:16:41 +00:00
										 |  |  |                         if ($cellContent > '') { | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |                             $cellContent .= ' '; | 
					
						
							| 
									
										
										
										
											2015-05-16 23:16:41 +00:00
										 |  |  |                         } | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |                         $this->_processDomElement($child, $sheet, $row, $column, $cellContent); | 
					
						
							| 
									
										
										
										
											2015-05-16 23:16:41 +00:00
										 |  |  |                         if ($cellContent > '') { | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |                             $cellContent .= ' '; | 
					
						
							| 
									
										
										
										
											2015-05-16 23:16:41 +00:00
										 |  |  |                         } | 
					
						
							| 
									
										
										
										
											2015-05-11 21:38:52 +00:00
										 |  |  | //                        echo 'END OF STYLING, SPAN OR DIV<br />';
 | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |                         break; | 
					
						
							| 
									
										
										
										
											2015-05-16 23:16:41 +00:00
										 |  |  |                     case 'hr': | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |                         $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; | 
					
						
							| 
									
										
										
										
											2015-05-16 23:16:41 +00:00
										 |  |  |                     case 'br': | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |                         if ($this->_tableLevel > 0) { | 
					
						
							| 
									
										
										
										
											2015-05-11 21:38:52 +00:00
										 |  |  |                             //    If we're inside a table, replace with a \n
 | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |                             $cellContent .= "\n"; | 
					
						
							|  |  |  |                         } else { | 
					
						
							| 
									
										
										
										
											2015-05-11 21:38:52 +00:00
										 |  |  |                             //    Otherwise flush our existing content and move the row cursor on
 | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |                             $this->_flushCell($sheet, $column, $row, $cellContent); | 
					
						
							|  |  |  |                             ++$row; | 
					
						
							|  |  |  |                         } | 
					
						
							| 
									
										
										
										
											2015-05-11 21:38:52 +00:00
										 |  |  | //                        echo 'HARD LINE BREAK: ' , '<br />';
 | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |                         break; | 
					
						
							| 
									
										
										
										
											2015-05-16 23:16:41 +00:00
										 |  |  |                     case 'a': | 
					
						
							| 
									
										
										
										
											2015-05-11 21:38:52 +00:00
										 |  |  | //                        echo 'START OF HYPERLINK: ' , '<br />';
 | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |                         foreach ($attributeArray as $attributeName => $attributeValue) { | 
					
						
							|  |  |  |                             switch ($attributeName) { | 
					
						
							|  |  |  |                                 case 'href': | 
					
						
							| 
									
										
										
										
											2015-05-11 21:38:52 +00:00
										 |  |  | //                                    echo 'Link to ' , $attributeValue , '<br />';
 | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +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); | 
					
						
							| 
									
										
										
										
											2015-05-11 21:38:52 +00:00
										 |  |  | //                        echo 'END OF HYPERLINK:' , '<br />';
 | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |                         break; | 
					
						
							| 
									
										
										
										
											2015-05-16 23:16:41 +00:00
										 |  |  |                     case 'h1': | 
					
						
							|  |  |  |                     case 'h2': | 
					
						
							|  |  |  |                     case 'h3': | 
					
						
							|  |  |  |                     case 'h4': | 
					
						
							|  |  |  |                     case 'h5': | 
					
						
							|  |  |  |                     case 'h6': | 
					
						
							|  |  |  |                     case 'ol': | 
					
						
							|  |  |  |                     case 'ul': | 
					
						
							|  |  |  |                     case 'p': | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |                         if ($this->_tableLevel > 0) { | 
					
						
							| 
									
										
										
										
											2015-05-11 21:38:52 +00:00
										 |  |  |                             //    If we're inside a table, replace with a \n
 | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |                             $cellContent .= "\n"; | 
					
						
							| 
									
										
										
										
											2015-05-11 21:38:52 +00:00
										 |  |  | //                            echo 'LIST ENTRY: ' , '<br />';
 | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |                             $this->_processDomElement($child, $sheet, $row, $column, $cellContent); | 
					
						
							| 
									
										
										
										
											2015-05-11 21:38:52 +00:00
										 |  |  | //                            echo 'END OF LIST ENTRY:' , '<br />';
 | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |                         } else { | 
					
						
							|  |  |  |                             if ($cellContent > '') { | 
					
						
							|  |  |  |                                 $this->_flushCell($sheet, $column, $row, $cellContent); | 
					
						
							|  |  |  |                                 $row++; | 
					
						
							|  |  |  |                             } | 
					
						
							| 
									
										
										
										
											2015-05-11 21:38:52 +00:00
										 |  |  | //                            echo 'START OF PARAGRAPH: ' , '<br />';
 | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |                             $this->_processDomElement($child, $sheet, $row, $column, $cellContent); | 
					
						
							| 
									
										
										
										
											2015-05-11 21:38:52 +00:00
										 |  |  | //                            echo 'END OF PARAGRAPH:' , '<br />';
 | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |                             $this->_flushCell($sheet, $column, $row, $cellContent); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                             if (isset($this->_formats[$child->nodeName])) { | 
					
						
							|  |  |  |                                 $sheet->getStyle($column . $row)->applyFromArray($this->_formats[$child->nodeName]); | 
					
						
							|  |  |  |                             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                             $row++; | 
					
						
							|  |  |  |                             $column = 'A'; | 
					
						
							|  |  |  |                         } | 
					
						
							|  |  |  |                         break; | 
					
						
							| 
									
										
										
										
											2015-05-16 23:16:41 +00:00
										 |  |  |                     case 'li': | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |                         if ($this->_tableLevel > 0) { | 
					
						
							| 
									
										
										
										
											2015-05-11 21:38:52 +00:00
										 |  |  |                             //    If we're inside a table, replace with a \n
 | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |                             $cellContent .= "\n"; | 
					
						
							| 
									
										
										
										
											2015-05-11 21:38:52 +00:00
										 |  |  | //                            echo 'LIST ENTRY: ' , '<br />';
 | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |                             $this->_processDomElement($child, $sheet, $row, $column, $cellContent); | 
					
						
							| 
									
										
										
										
											2015-05-11 21:38:52 +00:00
										 |  |  | //                            echo 'END OF LIST ENTRY:' , '<br />';
 | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |                         } else { | 
					
						
							|  |  |  |                             if ($cellContent > '') { | 
					
						
							|  |  |  |                                 $this->_flushCell($sheet, $column, $row, $cellContent); | 
					
						
							|  |  |  |                             } | 
					
						
							|  |  |  |                             ++$row; | 
					
						
							| 
									
										
										
										
											2015-05-11 21:38:52 +00:00
										 |  |  | //                            echo 'LIST ENTRY: ' , '<br />';
 | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |                             $this->_processDomElement($child, $sheet, $row, $column, $cellContent); | 
					
						
							| 
									
										
										
										
											2015-05-11 21:38:52 +00:00
										 |  |  | //                            echo 'END OF LIST ENTRY:' , '<br />';
 | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |                             $this->_flushCell($sheet, $column, $row, $cellContent); | 
					
						
							|  |  |  |                             $column = 'A'; | 
					
						
							|  |  |  |                         } | 
					
						
							|  |  |  |                         break; | 
					
						
							| 
									
										
										
										
											2015-05-16 23:16:41 +00:00
										 |  |  |                     case 'table': | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |                         $this->_flushCell($sheet, $column, $row, $cellContent); | 
					
						
							|  |  |  |                         $column = $this->_setTableStartColumn($column); | 
					
						
							| 
									
										
										
										
											2015-05-11 21:38:52 +00:00
										 |  |  | //                        echo 'START OF TABLE LEVEL ' , $this->_tableLevel , '<br />';
 | 
					
						
							| 
									
										
										
										
											2015-05-16 23:16:41 +00:00
										 |  |  |                         if ($this->_tableLevel > 1) { | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |                             --$row; | 
					
						
							| 
									
										
										
										
											2015-05-16 23:16:41 +00:00
										 |  |  |                         } | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |                         $this->_processDomElement($child, $sheet, $row, $column, $cellContent); | 
					
						
							| 
									
										
										
										
											2015-05-11 21:38:52 +00:00
										 |  |  | //                        echo 'END OF TABLE LEVEL ' , $this->_tableLevel , '<br />';
 | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |                         $column = $this->_releaseTableStartColumn(); | 
					
						
							|  |  |  |                         if ($this->_tableLevel > 1) { | 
					
						
							|  |  |  |                             ++$column; | 
					
						
							|  |  |  |                         } else { | 
					
						
							|  |  |  |                             ++$row; | 
					
						
							|  |  |  |                         } | 
					
						
							|  |  |  |                         break; | 
					
						
							| 
									
										
										
										
											2015-05-16 23:16:41 +00:00
										 |  |  |                     case 'thead': | 
					
						
							|  |  |  |                     case 'tbody': | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |                         $this->_processDomElement($child, $sheet, $row, $column, $cellContent); | 
					
						
							|  |  |  |                         break; | 
					
						
							| 
									
										
										
										
											2015-05-16 23:16:41 +00:00
										 |  |  |                     case 'tr': | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |                         $column = $this->_getTableStartColumn(); | 
					
						
							|  |  |  |                         $cellContent = ''; | 
					
						
							| 
									
										
										
										
											2015-05-11 21:38:52 +00:00
										 |  |  | //                        echo 'START OF TABLE ' , $this->_tableLevel , ' ROW<br />';
 | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |                         $this->_processDomElement($child, $sheet, $row, $column, $cellContent); | 
					
						
							|  |  |  |                         ++$row; | 
					
						
							| 
									
										
										
										
											2015-05-11 21:38:52 +00:00
										 |  |  | //                        echo 'END OF TABLE ' , $this->_tableLevel , ' ROW<br />';
 | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |                         break; | 
					
						
							| 
									
										
										
										
											2015-05-16 23:16:41 +00:00
										 |  |  |                     case 'th': | 
					
						
							|  |  |  |                     case 'td': | 
					
						
							| 
									
										
										
										
											2015-05-11 21:38:52 +00:00
										 |  |  | //                        echo 'START OF TABLE ' , $this->_tableLevel , ' CELL<br />';
 | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |                         $this->_processDomElement($child, $sheet, $row, $column, $cellContent); | 
					
						
							| 
									
										
										
										
											2015-05-11 21:38:52 +00:00
										 |  |  | //                        echo 'END OF TABLE ' , $this->_tableLevel , ' CELL<br />';
 | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |                         while (isset($this->rowspan[$column . $row])) { | 
					
						
							|  |  |  |                             ++$column; | 
					
						
							|  |  |  |                         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                         $this->_flushCell($sheet, $column, $row, $cellContent); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-12 23:18:46 +00:00
										 |  |  | //                        if (isset($attributeArray['style']) && !empty($attributeArray['style'])) {
 | 
					
						
							|  |  |  | //                            $styleAry = $this->getPhpExcelStyleArray($attributeArray['style']);
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //                            if (!empty($styleAry)) {
 | 
					
						
							|  |  |  | //                                $sheet->getStyle($column . $row)->applyFromArray($styleAry);
 | 
					
						
							|  |  |  | //                            }
 | 
					
						
							|  |  |  | //                        }
 | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |                         if (isset($attributeArray['rowspan']) && isset($attributeArray['colspan'])) { | 
					
						
							| 
									
										
										
										
											2014-12-07 23:45:15 +00:00
										 |  |  |                             //create merging rowspan and colspan
 | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |                             $columnTo = $column; | 
					
						
							|  |  |  |                             for ($i = 0; $i < $attributeArray['colspan'] - 1; $i++) { | 
					
						
							|  |  |  |                                 ++$columnTo; | 
					
						
							|  |  |  |                             } | 
					
						
							|  |  |  |                             $range = $column . $row . ':' . $columnTo . ($row + $attributeArray['rowspan'] - 1); | 
					
						
							|  |  |  |                             foreach (\PHPExcel_Cell::extractAllCellReferencesInRange($range) as $value) { | 
					
						
							|  |  |  |                                 $this->rowspan[$value] = true; | 
					
						
							|  |  |  |                             } | 
					
						
							|  |  |  |                             $sheet->mergeCells($range); | 
					
						
							| 
									
										
										
										
											2014-12-07 23:45:15 +00:00
										 |  |  |                             $column = $columnTo; | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |                         } elseif (isset($attributeArray['rowspan'])) { | 
					
						
							| 
									
										
										
										
											2014-12-07 23:45:15 +00:00
										 |  |  |                             //create merging rowspan
 | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |                             $range = $column . $row . ':' . $column . ($row + $attributeArray['rowspan'] - 1); | 
					
						
							|  |  |  |                             foreach (\PHPExcel_Cell::extractAllCellReferencesInRange($range) as $value) { | 
					
						
							|  |  |  |                                 $this->rowspan[$value] = true; | 
					
						
							|  |  |  |                             } | 
					
						
							|  |  |  |                             $sheet->mergeCells($range); | 
					
						
							|  |  |  |                         } elseif (isset($attributeArray['colspan'])) { | 
					
						
							| 
									
										
										
										
											2014-12-07 23:45:15 +00:00
										 |  |  |                             //create merging colspan
 | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |                             $columnTo = $column; | 
					
						
							|  |  |  |                             for ($i = 0; $i < $attributeArray['colspan'] - 1; $i++) { | 
					
						
							|  |  |  |                                 ++$columnTo; | 
					
						
							|  |  |  |                             } | 
					
						
							|  |  |  |                             $sheet->mergeCells($column . $row . ':' . $columnTo . $row); | 
					
						
							|  |  |  |                             $column = $columnTo; | 
					
						
							|  |  |  |                         } | 
					
						
							|  |  |  |                         ++$column; | 
					
						
							|  |  |  |                         break; | 
					
						
							| 
									
										
										
										
											2015-05-16 23:16:41 +00:00
										 |  |  |                     case 'body': | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |                         $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 | 
					
						
							|  |  |  |      * @throws PHPExcel_Reader_Exception | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function loadIntoExisting($pFilename, PHPExcel $objPHPExcel) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         // Open file to validate
 | 
					
						
							|  |  |  |         $this->_openFile($pFilename); | 
					
						
							|  |  |  |         if (!$this->_isValidFormat()) { | 
					
						
							|  |  |  |             fclose($this->_fileHandle); | 
					
						
							|  |  |  |             throw new PHPExcel_Reader_Exception($pFilename . " is an Invalid HTML file."); | 
					
						
							| 
									
										
										
										
											2014-08-23 12:54:21 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-05-11 21:38:52 +00:00
										 |  |  |         //    Close after validating
 | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |         fclose($this->_fileHandle); | 
					
						
							| 
									
										
										
										
											2012-06-07 19:43:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |         // Create new PHPExcel
 | 
					
						
							|  |  |  |         while ($objPHPExcel->getSheetCount() <= $this->_sheetIndex) { | 
					
						
							|  |  |  |             $objPHPExcel->createSheet(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         $objPHPExcel->setActiveSheetIndex($this->_sheetIndex); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-11 21:38:52 +00:00
										 |  |  |         //    Create a new DOM object
 | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |         $dom = new domDocument; | 
					
						
							| 
									
										
										
										
											2015-05-11 21:38:52 +00:00
										 |  |  |         //    Reload the HTML file into the DOM object
 | 
					
						
							| 
									
										
										
										
											2015-04-28 23:43:04 +00:00
										 |  |  |         $loaded = $dom->loadHTML($this->securityScanFile($pFilename)); | 
					
						
							| 
									
										
										
										
											2015-05-16 23:16:41 +00:00
										 |  |  |         if ($loaded === false) { | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |             throw new PHPExcel_Reader_Exception('Failed to load ', $pFilename, ' as a DOM Document'); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2012-06-07 19:43:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-11 21:38:52 +00:00
										 |  |  |         //    Discard white space
 | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |         $dom->preserveWhiteSpace = false; | 
					
						
							| 
									
										
										
										
											2012-06-07 19:43:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |         $row = 0; | 
					
						
							|  |  |  |         $column = 'A'; | 
					
						
							|  |  |  |         $content = ''; | 
					
						
							|  |  |  |         $this->_processDomElement($dom, $objPHPExcel->getActiveSheet(), $row, $column, $content); | 
					
						
							| 
									
										
										
										
											2012-06-07 19:43:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-11 21:38:52 +00:00
										 |  |  |         // Return
 | 
					
						
							| 
									
										
										
										
											2014-12-07 14:45:55 +00:00
										 |  |  |         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; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-06-07 19:43:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-11 21:38:52 +00:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Scan theXML for use of <!ENTITY to prevent XXE/XEE attacks | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param     string         $xml | 
					
						
							|  |  |  |      * @throws PHPExcel_Reader_Exception | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function securityScan($xml) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-04-29 21:41:54 +00:00
										 |  |  |         $pattern = '/\\0?' . implode('\\0?', str_split('<!ENTITY')) . '\\0?/'; | 
					
						
							| 
									
										
										
										
											2015-05-16 23:16:41 +00:00
										 |  |  |         if (preg_match($pattern, $xml)) { | 
					
						
							| 
									
										
										
										
											2015-04-29 21:41:54 +00:00
										 |  |  |             throw new PHPExcel_Reader_Exception('Detected use of ENTITY in XML, spreadsheet file load() aborted to prevent XXE/XEE attacks'); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return $xml; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-06-07 19:43:19 +00:00
										 |  |  | } |