fileSupportsUnserializePHPExcel($pFilename); } /** * Loads PHPExcel Serialized file * * @param string $pFilename * @return PHPExcel * @throws Exception */ public function load($pFilename) { // Check if file exists if (!file_exists($pFilename)) { throw new Exception("Could not open " . $pFilename . " for reading! File does not exist."); } // Unserialize... First make sure the file supports it! if (!$this->fileSupportsUnserializePHPExcel($pFilename)) { throw new Exception("Invalid file format for PHPExcel_Reader_Serialized: " . $pFilename . "."); } return $this->_loadSerialized($pFilename); } /** * Load PHPExcel Serialized file * * @param string $pFilename * @return PHPExcel */ private function _loadSerialized($pFilename) { $xmlData = simplexml_load_string(file_get_contents("zip://$pFilename#phpexcel.xml")); $excel = unserialize(base64_decode((string)$xmlData->data)); // Update media links for ($i = 0; $i < $excel->getSheetCount(); ++$i) { for ($j = 0; $j < $excel->getSheet($i)->getDrawingCollection()->count(); ++$j) { if ($excel->getSheet($i)->getDrawingCollection()->offsetGet($j) instanceof PHPExcl_Worksheet_BaseDrawing) { $imgTemp =& $excel->getSheet($i)->getDrawingCollection()->offsetGet($j); $imgTemp->setPath('zip://' . $pFilename . '#media/' . $imgTemp->getFilename(), false); } } } return $excel; } /** * Does a file support UnserializePHPExcel ? * * @param string $pFilename * @throws Exception * @return boolean */ public function fileSupportsUnserializePHPExcel($pFilename = '') { // Check if file exists if (!file_exists($pFilename)) { throw new Exception("Could not open " . $pFilename . " for reading! File does not exist."); } // File exists, does it contain phpexcel.xml? return PHPExcel_Shared_File::file_exists("zip://$pFilename#phpexcel.xml"); } }