PHPExcel_Reader
[ class tree: PHPExcel_Reader ] [ index: PHPExcel_Reader ] [ all elements ]

Source for file Serialized.php

Documentation is available at Serialized.php

  1. <?php
  2. /**
  3.  * PHPExcel
  4.  *
  5.  * Copyright (c) 2006 - 2009 PHPExcel
  6.  *
  7.  * This library is free software; you can redistribute it and/or
  8.  * modify it under the terms of the GNU Lesser General Public
  9.  * License as published by the Free Software Foundation; either
  10.  * version 2.1 of the License, or (at your option) any later version.
  11.  *
  12.  * This library is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.  * Lesser General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU Lesser General Public
  18.  * License along with this library; if not, write to the Free Software
  19.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  20.  *
  21.  * @category   PHPExcel
  22.  * @package    PHPExcel_Reader
  23.  * @copyright  Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
  24.  * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
  25.  * @version    1.6.5, 2009-01-05
  26.  */
  27.  
  28.  
  29. /** PHPExcel */
  30. require_once 'PHPExcel.php';
  31.  
  32. /** PHPExcel_Reader_IReader */
  33. require_once 'PHPExcel/Reader/IReader.php';
  34.  
  35. /** PHPExcel_Shared_File */
  36. require_once 'PHPExcel/Shared/File.php';
  37.  
  38.  
  39. /**
  40.  * PHPExcel_Reader_Serialized
  41.  *
  42.  * @category   PHPExcel
  43.  * @package    PHPExcel_Reader
  44.  * @copyright  Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
  45.  */
  46. class PHPExcel_Reader_Serialized implements PHPExcel_Reader_IReader
  47. {
  48.     /**
  49.      * Loads PHPExcel Serialized file
  50.      *
  51.      * @param     string         $pFilename 
  52.      * @return     PHPExcel 
  53.      * @throws     Exception
  54.      */
  55.     public function load($pFilename)
  56.     {
  57.         // Check if file exists
  58.         if (!file_exists($pFilename)) {
  59.             throw new Exception("Could not open " $pFilename " for reading! File does not exist.");
  60.         }
  61.  
  62.         // Unserialize... First make sure the file supports it!
  63.         if (!$this->fileSupportsUnserializePHPExcel($pFilename)) {
  64.             throw new Exception("Invalid file format for PHPExcel_Reader_Serialized: " $pFilename ".");
  65.         }
  66.  
  67.         return $this->_loadSerialized($pFilename);
  68.     }
  69.  
  70.     /**
  71.      * Load PHPExcel Serialized file
  72.      *
  73.      * @param     string         $pFilename 
  74.      * @return     PHPExcel 
  75.      */
  76.     private function _loadSerialized($pFilename{
  77.         $xmlData simplexml_load_string(file_get_contents("zip://$pFilename#phpexcel.xml"));
  78.         $excel unserialize(base64_decode((string)$xmlData->data));
  79.  
  80.         // Update media links
  81.         for ($i 0$i $excel->getSheetCount()++$i{
  82.             for ($j 0$j $excel->getSheet($i)->getDrawingCollection()->count()++$j{
  83.                 if ($excel->getSheet($i)->getDrawingCollection()->offsetGet($jinstanceof PHPExcl_Worksheet_BaseDrawing{
  84.                     $imgTemp =$excel->getSheet($i)->getDrawingCollection()->offsetGet($j);
  85.                     $imgTemp->setPath('zip://' $pFilename '#media/' $imgTemp->getFilename()false);
  86.                 }
  87.             }
  88.         }
  89.  
  90.         return $excel;
  91.     }
  92.  
  93.     /**
  94.      * Does a file support UnserializePHPExcel ?
  95.      *
  96.      * @param     string         $pFilename 
  97.      * @throws     Exception
  98.      * @return     boolean 
  99.      */
  100.     public function fileSupportsUnserializePHPExcel($pFilename ''{
  101.         // Check if file exists
  102.         if (!file_exists($pFilename)) {
  103.             throw new Exception("Could not open " $pFilename " for reading! File does not exist.");
  104.         }
  105.  
  106.         // File exists, does it contain phpexcel.xml?
  107.         return PHPExcel_Shared_File::file_exists("zip://$pFilename#phpexcel.xml");
  108.     }
  109. }

Documentation generated on Mon, 05 Jan 2009 20:38:28 +0100 by phpDocumentor 1.4.1