From 0d8a5d1f0b73b4a45eee4c455898ff6836104ae7 Mon Sep 17 00:00:00 2001 From: Mark Baker Date: Sun, 17 Nov 2013 17:33:56 +0000 Subject: [PATCH] General: (adamriyadi) Work Item GH-247 - Modify PHPExcel_Reader_Excel2007 to use zipClass from PHPExcel_Settings::getZipClass() This allows the use of PCLZip when reading for people that don't have access to ZipArchive --- Classes/PHPExcel/Reader/Excel2007.php | 27 +++++++++++++++++--------- Classes/PHPExcel/Shared/ZipArchive.php | 13 ++++++------- changelog.txt | 2 ++ 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/Classes/PHPExcel/Reader/Excel2007.php b/Classes/PHPExcel/Reader/Excel2007.php index 8f58279b..74322a18 100644 --- a/Classes/PHPExcel/Reader/Excel2007.php +++ b/Classes/PHPExcel/Reader/Excel2007.php @@ -82,14 +82,16 @@ class PHPExcel_Reader_Excel2007 extends PHPExcel_Reader_Abstract implements PHPE throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist."); } + $zipClass = PHPExcel_Settings::getZipClass(); + // Check if zip class exists - if (!class_exists('ZipArchive',FALSE)) { - throw new PHPExcel_Reader_Exception("ZipArchive library is not enabled"); - } +// if (!class_exists($zipClass, FALSE)) { +// throw new PHPExcel_Reader_Exception($zipClass . " library is not enabled"); +// } $xl = false; // Load file - $zip = new ZipArchive; + $zip = new $zipClass; if ($zip->open($pFilename) === true) { // check if it is an OOXML archive $rels = simplexml_load_string($this->_getFromZipArchive($zip, "_rels/.rels")); @@ -127,7 +129,9 @@ class PHPExcel_Reader_Excel2007 extends PHPExcel_Reader_Abstract implements PHPE $worksheetNames = array(); - $zip = new ZipArchive; + $zipClass = PHPExcel_Settings::getZipClass(); + + $zip = new $zipClass; $zip->open($pFilename); // The files we're looking at here are small enough that simpleXML is more efficient than XMLReader @@ -171,7 +175,9 @@ class PHPExcel_Reader_Excel2007 extends PHPExcel_Reader_Abstract implements PHPE $worksheetInfo = array(); - $zip = new ZipArchive; + $zipClass = PHPExcel_Settings::getZipClass(); + + $zip = new $zipClass; $zip->open($pFilename); $rels = simplexml_load_string($this->_getFromZipArchive($zip, "_rels/.rels")); //~ http://schemas.openxmlformats.org/package/2006/relationships"); @@ -308,7 +314,7 @@ class PHPExcel_Reader_Excel2007 extends PHPExcel_Reader_Abstract implements PHPE } - public function _getFromZipArchive(ZipArchive $archive, $fileName = '') + public function _getFromZipArchive($archive, $fileName = '') { // Root-relative paths if (strpos($fileName, '//') !== false) @@ -348,7 +354,10 @@ class PHPExcel_Reader_Excel2007 extends PHPExcel_Reader_Abstract implements PHPE $excel->removeCellStyleXfByIndex(0); // remove the default style $excel->removeCellXfByIndex(0); // remove the default style } - $zip = new ZipArchive; + + $zipClass = PHPExcel_Settings::getZipClass(); + + $zip = new $zipClass; $zip->open($pFilename); // Read the theme first, because we need the colour scheme when reading the styles @@ -1409,7 +1418,7 @@ class PHPExcel_Reader_Excel2007 extends PHPExcel_Reader_Abstract implements PHPE } -// TODO: Autoshapes from twoCellAnchors! + // TODO: Autoshapes from twoCellAnchors! if ($zip->locateName(dirname("$dir/$fileWorksheet") . "/_rels/" . basename($fileWorksheet) . ".rels")) { $relsWorksheet = simplexml_load_string($this->_getFromZipArchive($zip, dirname("$dir/$fileWorksheet") . "/_rels/" . basename($fileWorksheet) . ".rels") ); //~ http://schemas.openxmlformats.org/package/2006/relationships"); $drawings = array(); diff --git a/Classes/PHPExcel/Shared/ZipArchive.php b/Classes/PHPExcel/Shared/ZipArchive.php index e70ad28a..a0a954c8 100644 --- a/Classes/PHPExcel/Shared/ZipArchive.php +++ b/Classes/PHPExcel/Shared/ZipArchive.php @@ -113,7 +113,6 @@ class PHPExcel_Shared_ZipArchive /** * Find if given fileName exist in archive (Emulate ZipArchive locateName()) - * author Adam (adam.riyadi@gmail.com) * * @param string $fileName Filename for the file in zip archive * @return boolean @@ -123,7 +122,7 @@ class PHPExcel_Shared_ZipArchive $list = $this->_zip->listContent(); $listCount = count($list); $list_index = -1; - for ($i = 0; $i < $listCount; $i++) { + for ($i = 0; $i < $listCount; ++$i) { if (strtolower($list[$i]["filename"]) == strtolower($fileName) || strtolower($list[$i]["stored_filename"]) == strtolower($fileName)) { $list_index = $i; @@ -135,7 +134,6 @@ class PHPExcel_Shared_ZipArchive /** * Extract file from archive by given fileName (Emulate ZipArchive getFromName()) - * author Adam (adam.riyadi@gmail.com) * * @param string $fileName Filename for the file in zip archive * @return string $contents File string contents @@ -145,22 +143,23 @@ class PHPExcel_Shared_ZipArchive $list = $this->_zip->listContent(); $listCount = count($list); $list_index = -1; - for ($i = 0; $i < $listCount; $i++) { + for ($i = 0; $i < $listCount; ++$i) { if (strtolower($list[$i]["filename"]) == strtolower($fileName) || strtolower($list[$i]["stored_filename"]) == strtolower($fileName)) { $list_index = $i; break; } } - + $extracted = ""; if ($list_index != -1) { $extracted = $this->_zip->extractByIndex($list_index, PCLZIP_OPT_EXTRACT_AS_STRING); } else { $filename = substr($fileName, 1); $list_index = -1; - for ($i = 0; $i < $listCount; $i++) { - if (strtolower($list[$i]["filename"]) == strtolower($fileName) || strtolower($list[$i]["stored_filename"]) == strtolower($fileName)) { + for ($i = 0; $i < $listCount; ++$i) { + if (strtolower($list[$i]["filename"]) == strtolower($fileName) || + strtolower($list[$i]["stored_filename"]) == strtolower($fileName)) { $list_index = $i; break; } diff --git a/changelog.txt b/changelog.txt index deeb03b3..6340623e 100644 --- a/changelog.txt +++ b/changelog.txt @@ -45,6 +45,8 @@ Fixed in develop branch for release v1.8.0: - General: (MBaker) - Modified Excel2007 Writer to default preCalculateFormulas to false Note that autosize columns will still recalculate affected formulae internally - General: (dresenhista) Work Item GH-242 - Functionality to getHighestRow() for a specified column, and getHighestColumn() for a specified row +- General: (adamriyadi) Work Item GH-247 - Modify PHPExcel_Reader_Excel2007 to use zipClass from PHPExcel_Settings::getZipClass() + This allows the use of PCLZip when reading for people that don't have access to ZipArchive Fixed in develop branch for release v1.7.9: