Skip to content
This repository has been archived by the owner on Jan 2, 2019. It is now read-only.

Html Reader can get data from HTML String #204

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 24 additions & 15 deletions Classes/PHPExcel/Reader/HTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,19 @@ protected function _isValidFormat()
}

/**
* Loads PHPExcel from file
* Loads PHPExcel from file or from HTML Data
*
* @param string $pFilename
* @param string $pHtmlData
* @return PHPExcel
* @throws PHPExcel_Reader_Exception
*/
public function load($pFilename)
public function load($pHtmlData)
{
// Create new PHPExcel
$objPHPExcel = new PHPExcel();

// Load into this instance
return $this->loadIntoExisting($pFilename, $objPHPExcel);
return $this->loadIntoExisting($pHtmlData, $objPHPExcel);
}

/**
Expand Down Expand Up @@ -397,23 +397,28 @@ private function _processDomElement(DOMNode $element, $sheet, &$row, &$column, &
}

/**
* Loads PHPExcel from file into PHPExcel instance
* Loads PHPExcel from file or from HTML data into PHPExcel instance
*
* @param string $pFilename
* @param PHPExcel $objPHPExcel
* @return PHPExcel
* @throws PHPExcel_Reader_Exception
*/
public function loadIntoExisting($pFilename, PHPExcel $objPHPExcel)
public function loadIntoExisting($pHtmlData, PHPExcel $objPHPExcel)
{
// Open file to validate
$this->_openFile($pFilename);
if (!$this->_isValidFormat()) {
$isHtmlFile = FALSE;
if(is_file($pHtmlData)){
$isHtmlFile = TRUE;
// Open file to validate
$this->_openFile($pHtmlData);
if (!$this->_isValidFormat()) {
fclose ($this->_fileHandle);
throw new PHPExcel_Reader_Exception($pHtmlData . " is an Invalid HTML file.");
}
// Close after validating
fclose ($this->_fileHandle);
throw new PHPExcel_Reader_Exception($pFilename . " is an Invalid HTML file.");
}
// Close after validating
fclose ($this->_fileHandle);


// Create new PHPExcel
while ($objPHPExcel->getSheetCount() <= $this->_sheetIndex) {
Expand All @@ -424,15 +429,19 @@ public function loadIntoExisting($pFilename, PHPExcel $objPHPExcel)
// Create a new DOM object
$dom = new domDocument;
// Reload the HTML file into the DOM object
$loaded = $dom->loadHTMLFile($pFilename);
if($isHtmlFile){
$loaded = $dom->loadHTMLFile($pHtmlData);
}else{
$loaded = $dom->loadHTML($pHtmlData);
}

if ($loaded === FALSE) {
throw new PHPExcel_Reader_Exception('Failed to load ',$pFilename,' as a DOM Document');
throw new PHPExcel_Reader_Exception('Failed to load ',$pHtmlData,' as a DOM Document');
}

// Discard white space
$dom->preserveWhiteSpace = false;


$row = 0;
$column = 'A';
$content = '';
Expand Down