General: Removed Serialized Reader/Writer as these no longer work.

git-svn-id: https://phpexcel.svn.codeplex.com/svn/trunk@69147 2327b42d-5241-43d6-9e2a-de5ac946f064
This commit is contained in:
Mark Baker 2011-02-22 10:21:38 +00:00
parent a8517724dc
commit 46e1c4eaff
6 changed files with 1 additions and 366 deletions

View File

@ -70,7 +70,6 @@ class PHPExcel_IOFactory
'OOCalc',
'SYLK',
'Gnumeric',
'Serialized',
'CSV',
);

View File

@ -1,124 +0,0 @@
<?php
/**
* PHPExcel
*
* Copyright (c) 2006 - 2011 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE##
*/
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
}
/**
* PHPExcel_Reader_Serialized
*
* @category PHPExcel
* @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Reader_Serialized implements PHPExcel_Reader_IReader
{
/**
* Can the current PHPExcel_Reader_IReader read the file?
*
* @param string $pFileName
* @return boolean
*/
public function canRead($pFilename)
{
// Check if file exists
if (!file_exists($pFilename)) {
throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
}
return $this->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");
}
}

View File

@ -1,181 +0,0 @@
<?php
/**
* PHPExcel
*
* Copyright (c) 2006 - 2011 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel_Writer
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE##
*/
/**
* PHPExcel_Writer_Serialized
*
* @category PHPExcel
* @package PHPExcel_Writer
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Writer_Serialized implements PHPExcel_Writer_IWriter
{
/**
* Private PHPExcel
*
* @var PHPExcel
*/
private $_spreadSheet;
/**
* Create a new PHPExcel_Writer_Serialized
*
* @param PHPExcel $pPHPExcel
*/
public function __construct(PHPExcel $pPHPExcel = null)
{
// Assign PHPExcel
$this->setPHPExcel($pPHPExcel);
}
/**
* Save PHPExcel to file
*
* @param string $pFileName
* @throws Exception
*/
public function save($pFilename = null)
{
if (!is_null($this->_spreadSheet)) {
// Garbage collect
$this->_spreadSheet->garbageCollect();
// Garbage collect...
foreach ($this->_spreadSheet->getAllSheets() as $sheet) {
$sheet->garbageCollect();
}
// Create new ZIP file and open it for writing
$objZip = new ZipArchive();
// Try opening the ZIP file
if ($objZip->open($pFilename, ZIPARCHIVE::OVERWRITE) !== true) {
if ($objZip->open($pFilename, ZIPARCHIVE::CREATE) !== true) {
throw new Exception("Could not open " . $pFilename . " for writing.");
}
}
// Add media
$sheetCount = $this->_spreadSheet->getSheetCount();
for ($i = 0; $i < $sheetCount; ++$i) {
for ($j = 0; $j < $this->_spreadSheet->getSheet($i)->getDrawingCollection()->count(); ++$j) {
if ($this->_spreadSheet->getSheet($i)->getDrawingCollection()->offsetGet($j) instanceof PHPExcel_Worksheet_BaseDrawing) {
$imgTemp = $this->_spreadSheet->getSheet($i)->getDrawingCollection()->offsetGet($j);
$objZip->addFromString('media/' . $imgTemp->getFilename(), file_get_contents($imgTemp->getPath()));
}
}
}
// Add phpexcel.xml to the document, which represents a PHP serialized PHPExcel object
$objZip->addFromString('phpexcel.xml', $this->_writeSerialized($this->_spreadSheet, $pFilename));
// Close file
if ($objZip->close() === false) {
throw new Exception("Could not close zip file $pFilename.");
}
} else {
throw new Exception("PHPExcel object unassigned.");
}
}
/**
* Get PHPExcel object
*
* @return PHPExcel
* @throws Exception
*/
public function getPHPExcel() {
if (!is_null($this->_spreadSheet)) {
return $this->_spreadSheet;
} else {
throw new Exception("No PHPExcel assigned.");
}
}
/**
* Get PHPExcel object
*
* @param PHPExcel $pPHPExcel PHPExcel object
* @throws Exception
* @return PHPExcel_Writer_Serialized
*/
public function setPHPExcel(PHPExcel $pPHPExcel = null) {
$this->_spreadSheet = $pPHPExcel;
return $this;
}
/**
* Serialize PHPExcel object to XML
*
* @param PHPExcel $pPHPExcel
* @param string $pFilename
* @return string XML Output
* @throws Exception
*/
private function _writeSerialized(PHPExcel $pPHPExcel = null, $pFilename = '')
{
// Clone $pPHPExcel
$pPHPExcel = clone $pPHPExcel;
// Update media links
$sheetCount = $pPHPExcel->getSheetCount();
for ($i = 0; $i < $sheetCount; ++$i) {
for ($j = 0; $j < $pPHPExcel->getSheet($i)->getDrawingCollection()->count(); ++$j) {
if ($pPHPExcel->getSheet($i)->getDrawingCollection()->offsetGet($j) instanceof PHPExcel_Worksheet_BaseDrawing) {
$imgTemp =& $pPHPExcel->getSheet($i)->getDrawingCollection()->offsetGet($j);
$imgTemp->setPath('zip://' . $pFilename . '#media/' . $imgTemp->getFilename(), false);
}
}
}
// Create XML writer
$objWriter = new xmlWriter();
$objWriter->openMemory();
$objWriter->setIndent(true);
// XML header
$objWriter->startDocument('1.0','UTF-8','yes');
// PHPExcel
$objWriter->startElement('PHPExcel');
$objWriter->writeAttribute('version', '##VERSION##');
// Comment
$objWriter->writeComment('This file has been generated using PHPExcel v##VERSION## (http://www.codeplex.com/PHPExcel). It contains a base64 encoded serialized version of the PHPExcel internal object.');
// Data
$objWriter->startElement('data');
$objWriter->writeCData( base64_encode(serialize($pPHPExcel)) );
$objWriter->endElement();
$objWriter->endElement();
// Return
return $objWriter->outputMemory(true);
}
}

View File

@ -1,60 +0,0 @@
<?php
/**
* PHPExcel
*
* Copyright (C) 2006 - 2011 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE##
*/
/** Error reporting */
error_reporting(E_ALL);
date_default_timezone_set('Europe/London');
include "05featuredemo.inc.php";
/** PHPExcel_IOFactory */
require_once '../Classes/PHPExcel/IOFactory.php';
// Save PHPExcel Serialized file
echo date('H:i:s') . " Write to PHPExcel Serialized format\n";
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Serialized');
$objWriter->save(str_replace('.php', '.phpxl', __FILE__));
// Read PHPExcel Serialized file
echo date('H:i:s') . " Read from PHPExcel Serialized format\n";
$objPHPExcel = PHPExcel_IOFactory::load(str_replace('.php', '.phpxl', __FILE__));
// Save Excel 2007 file
echo date('H:i:s') . " Write to Excel2007 format\n";
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save(str_replace('.php', '.xlsx', __FILE__));
// Echo memory peak usage
echo date('H:i:s') . " Peak memory usage: " . (memory_get_peak_usage(true) / 1024 / 1024) . " MB\r\n";
// Echo done
echo date('H:i:s') . " Done writing file.\r\n";

View File

@ -70,6 +70,7 @@ Fixed in SVN:
- General: (MBaker) Improved performance (speed), for building the Shared Strings table in the Excel2007 Writer.
- General: (MBaker) Improved performance (speed), for PHP to Excel date conversions
- General: (MBaker) Enhanced SheetViews element structures in the Excel2007 Writer for frozen panes.
- General: (MBaker) Removed Serialized Reader/Writer as these no longer work.