Skip to content

Commit

Permalink
Better fallback for loading HTML (when using loadView() never check i…
Browse files Browse the repository at this point in the history
…f it's a file)
  • Loading branch information
Patrick Brouwers committed Feb 27, 2014
1 parent 9cc5f67 commit ee51853
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
@@ -1,4 +1,4 @@
## Laravel 4 Wrapper for PHPExcel v0.2.5
## Laravel 4 Wrapper for PHPExcel v0.2.6

#Installation

Expand Down
2 changes: 1 addition & 1 deletion src/Maatwebsite/Excel/Excel.php
Expand Up @@ -185,7 +185,7 @@ public function loadHTML($string){
include_once('Readers/HTML_reader.php');

$this->reader = new HTML_reader;
$this->excel = $this->reader->load($string);
$this->excel = $this->reader->load($string, true);

return $this;

Expand Down
33 changes: 20 additions & 13 deletions src/Maatwebsite/Excel/Readers/HTML_reader.php
Expand Up @@ -128,13 +128,13 @@ class HTML_reader extends \PHPExcel_Reader_HTML
* @return PHPExcel
* @throws PHPExcel_Reader_Exception
*/
public function load($pFilename)
public function load($pFilename, $isString = false)
{
// Create new PHPExcel
$objPHPExcel = new \PHPExcel();

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

/**
Expand All @@ -145,20 +145,27 @@ public function load($pFilename)
* @return PHPExcel
* @throws PHPExcel_Reader_Exception
*/
public function loadIntoExisting($pFilename, PHPExcel $objPHPExcel)
public function loadIntoExisting($pFilename, PHPExcel $objPHPExcel, $isString = false)
{
$isHtmlFile = FALSE;
if(is_file($pFilename)){
$isHtmlFile = TRUE;
// Open file to validate
$this->_openFile($pFilename);

if (!$this->_isValidFormat()) {
fclose ($this->_fileHandle);
throw new PHPExcel_Reader_Exception($pFilename . " is an Invalid HTML file.");
}
$isHtmlFile = FALSE;

fclose ($this->_fileHandle);
// Check if it's a string or file
if(!$isString)
{
// Double check if it's a file
if(is_file($pFilename)){
$isHtmlFile = TRUE;
// Open file to validate
$this->_openFile($pFilename);

if (!$this->_isValidFormat()) {
fclose ($this->_fileHandle);
throw new PHPExcel_Reader_Exception($pFilename . " is an Invalid HTML file.");
}

fclose ($this->_fileHandle);
}
}

// Create new PHPExcel
Expand Down

0 comments on commit ee51853

Please sign in to comment.