3.3
This commit is contained in:
294
libraries/PHPExcel/PHPExcel/Reader/CSV.php
Normal file
294
libraries/PHPExcel/PHPExcel/Reader/CSV.php
Normal file
@@ -0,0 +1,294 @@
|
||||
<?php
|
||||
/**
|
||||
* PHPExcel
|
||||
*
|
||||
* Copyright (c) 2006 - 2009 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 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version 1.7.0, 2009-08-10
|
||||
*/
|
||||
|
||||
|
||||
/** PHPExcel root directory */
|
||||
if (!defined('PHPEXCEL_ROOT')) {
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
|
||||
}
|
||||
|
||||
/** PHPExcel */
|
||||
require_once PHPEXCEL_ROOT . 'PHPExcel.php';
|
||||
|
||||
/** PHPExcel_Reader_IReader */
|
||||
require_once PHPEXCEL_ROOT . 'PHPExcel/Reader/IReader.php';
|
||||
|
||||
/** PHPExcel_Worksheet */
|
||||
require_once PHPEXCEL_ROOT . 'PHPExcel/Worksheet.php';
|
||||
|
||||
/** PHPExcel_Cell */
|
||||
require_once PHPEXCEL_ROOT . 'PHPExcel/Cell.php';
|
||||
|
||||
/** PHPExcel_Reader_DefaultReadFilter */
|
||||
require_once PHPEXCEL_ROOT . 'PHPExcel/Reader/DefaultReadFilter.php';
|
||||
|
||||
|
||||
/**
|
||||
* PHPExcel_Reader_CSV
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel_Reader
|
||||
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
class PHPExcel_Reader_CSV implements PHPExcel_Reader_IReader
|
||||
{
|
||||
/**
|
||||
* Delimiter
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_delimiter;
|
||||
|
||||
/**
|
||||
* Enclosure
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_enclosure;
|
||||
|
||||
/**
|
||||
* Line ending
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_lineEnding;
|
||||
|
||||
/**
|
||||
* Sheet index to read
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $_sheetIndex;
|
||||
|
||||
/**
|
||||
* PHPExcel_Reader_IReadFilter instance
|
||||
*
|
||||
* @var PHPExcel_Reader_IReadFilter
|
||||
*/
|
||||
private $_readFilter = null;
|
||||
|
||||
/**
|
||||
* Create a new PHPExcel_Reader_CSV
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->_delimiter = ',';
|
||||
$this->_enclosure = '"';
|
||||
$this->_lineEnding = PHP_EOL;
|
||||
$this->_sheetIndex = 0;
|
||||
$this->_readFilter = new PHPExcel_Reader_DefaultReadFilter();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.");
|
||||
}
|
||||
|
||||
// Check if it is a CSV file (using file name)
|
||||
return (substr(strtolower($pFilename), -3) == 'csv');
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads PHPExcel from file
|
||||
*
|
||||
* @param string $pFilename
|
||||
* @throws Exception
|
||||
*/
|
||||
public function load($pFilename)
|
||||
{
|
||||
// Create new PHPExcel
|
||||
$objPHPExcel = new PHPExcel();
|
||||
|
||||
// Load into this instance
|
||||
return $this->loadIntoExisting($pFilename, $objPHPExcel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read filter
|
||||
*
|
||||
* @return PHPExcel_Reader_IReadFilter
|
||||
*/
|
||||
public function getReadFilter() {
|
||||
return $this->_readFilter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set read filter
|
||||
*
|
||||
* @param PHPExcel_Reader_IReadFilter $pValue
|
||||
*/
|
||||
public function setReadFilter(PHPExcel_Reader_IReadFilter $pValue) {
|
||||
$this->_readFilter = $pValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads PHPExcel from file into PHPExcel instance
|
||||
*
|
||||
* @param string $pFilename
|
||||
* @param PHPExcel $objPHPExcel
|
||||
* @throws Exception
|
||||
*/
|
||||
public function loadIntoExisting($pFilename, PHPExcel $objPHPExcel)
|
||||
{
|
||||
// Check if file exists
|
||||
if (!file_exists($pFilename)) {
|
||||
throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
|
||||
}
|
||||
|
||||
// Create new PHPExcel
|
||||
while ($objPHPExcel->getSheetCount() <= $this->_sheetIndex) {
|
||||
$objPHPExcel->createSheet();
|
||||
}
|
||||
$objPHPExcel->setActiveSheetIndex( $this->_sheetIndex );
|
||||
|
||||
// Open file
|
||||
$fileHandle = fopen($pFilename, 'r');
|
||||
if ($fileHandle === false) {
|
||||
throw new Exception("Could not open file $pFilename for reading.");
|
||||
}
|
||||
|
||||
// Loop trough file
|
||||
$currentRow = 0;
|
||||
$rowData = array();
|
||||
while (($rowData = fgetcsv($fileHandle, 0, $this->_delimiter, $this->_enclosure)) !== FALSE) {
|
||||
++$currentRow;
|
||||
$rowDataCount = count($rowData);
|
||||
for ($i = 0; $i < $rowDataCount; ++$i) {
|
||||
$columnLetter = PHPExcel_Cell::stringFromColumnIndex($i);
|
||||
if ($rowData[$i] != '' && $this->_readFilter->readCell($columnLetter, $currentRow)) {
|
||||
// Unescape enclosures
|
||||
$rowData[$i] = str_replace("\\" . $this->_enclosure, $this->_enclosure, $rowData[$i]);
|
||||
$rowData[$i] = str_replace($this->_enclosure . $this->_enclosure, $this->_enclosure, $rowData[$i]);
|
||||
|
||||
// Set cell value
|
||||
$objPHPExcel->getActiveSheet()->setCellValue(
|
||||
$columnLetter . $currentRow, $rowData[$i]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Close file
|
||||
fclose($fileHandle);
|
||||
|
||||
// Return
|
||||
return $objPHPExcel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get delimiter
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDelimiter() {
|
||||
return $this->_delimiter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set delimiter
|
||||
*
|
||||
* @param string $pValue Delimiter, defaults to ,
|
||||
* @return PHPExcel_Reader_CSV
|
||||
*/
|
||||
public function setDelimiter($pValue = ',') {
|
||||
$this->_delimiter = $pValue;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get enclosure
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getEnclosure() {
|
||||
return $this->_enclosure;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set enclosure
|
||||
*
|
||||
* @param string $pValue Enclosure, defaults to "
|
||||
* @return PHPExcel_Reader_CSV
|
||||
*/
|
||||
public function setEnclosure($pValue = '"') {
|
||||
if ($pValue == '') {
|
||||
$pValue = '"';
|
||||
}
|
||||
$this->_enclosure = $pValue;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get line ending
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLineEnding() {
|
||||
return $this->_lineEnding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set line ending
|
||||
*
|
||||
* @param string $pValue Line ending, defaults to OS line ending (PHP_EOL)
|
||||
* @return PHPExcel_Reader_CSV
|
||||
*/
|
||||
public function setLineEnding($pValue = PHP_EOL) {
|
||||
$this->_lineEnding = $pValue;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sheet index
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getSheetIndex() {
|
||||
return $this->_sheetIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set sheet index
|
||||
*
|
||||
* @param int $pValue Sheet index
|
||||
* @return PHPExcel_Reader_CSV
|
||||
*/
|
||||
public function setSheetIndex($pValue = 0) {
|
||||
$this->_sheetIndex = $pValue;
|
||||
return $this;
|
||||
}
|
||||
}
|
61
libraries/PHPExcel/PHPExcel/Reader/DefaultReadFilter.php
Normal file
61
libraries/PHPExcel/PHPExcel/Reader/DefaultReadFilter.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/**
|
||||
* PHPExcel
|
||||
*
|
||||
* Copyright (c) 2006 - 2009 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 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version 1.7.0, 2009-08-10
|
||||
*/
|
||||
|
||||
|
||||
/** PHPExcel root directory */
|
||||
if (!defined('PHPEXCEL_ROOT')) {
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
|
||||
}
|
||||
|
||||
/** PHPExcel_Reader_IReadFilter */
|
||||
require_once PHPEXCEL_ROOT . 'PHPExcel/Reader/IReadFilter.php';
|
||||
|
||||
|
||||
/**
|
||||
* PHPExcel_Reader_DefaultReadFilter
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel_Reader
|
||||
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
class PHPExcel_Reader_DefaultReadFilter implements PHPExcel_Reader_IReadFilter
|
||||
{
|
||||
/**
|
||||
* Should this cell be read?
|
||||
*
|
||||
* @param $column String column index
|
||||
* @param $row Row index
|
||||
* @param $worksheetName Optional worksheet name
|
||||
* @return boolean
|
||||
*/
|
||||
public function readCell($column, $row, $worksheetName = '') {
|
||||
return true;
|
||||
}
|
||||
}
|
1565
libraries/PHPExcel/PHPExcel/Reader/Excel2007.php
Normal file
1565
libraries/PHPExcel/PHPExcel/Reader/Excel2007.php
Normal file
File diff suppressed because it is too large
Load Diff
5246
libraries/PHPExcel/PHPExcel/Reader/Excel5.php
Normal file
5246
libraries/PHPExcel/PHPExcel/Reader/Excel5.php
Normal file
File diff suppressed because it is too large
Load Diff
709
libraries/PHPExcel/PHPExcel/Reader/Excel5/Escher.php
Normal file
709
libraries/PHPExcel/PHPExcel/Reader/Excel5/Escher.php
Normal file
@@ -0,0 +1,709 @@
|
||||
<?php
|
||||
/**
|
||||
* PHPExcel
|
||||
*
|
||||
* Copyright (c) 2006 - 2009 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_Excel5
|
||||
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version 1.7.0, 2009-08-10
|
||||
*/
|
||||
|
||||
/** PHPExcel root directory */
|
||||
if (!defined('PHPEXCEL_ROOT')) {
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../../');
|
||||
}
|
||||
|
||||
/** PHPExcel_Cell */
|
||||
require_once PHPEXCEL_ROOT . 'PHPExcel/Cell.php';
|
||||
|
||||
/** PHPExcel_Shared_Escher_DggContainer */
|
||||
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/Escher/DggContainer.php';
|
||||
|
||||
/** PHPExcel_Shared_Escher_DggContainer_BstoreContainer */
|
||||
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/Escher/DggContainer/BstoreContainer.php';
|
||||
|
||||
/** PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE */
|
||||
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/Escher/DggContainer/BstoreContainer/BSE.php';
|
||||
|
||||
/** PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE_Blip */
|
||||
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/Escher/DggContainer/BstoreContainer/BSE/Blip.php';
|
||||
|
||||
/** PHPExcel_Shared_Escher_DgContainer */
|
||||
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/Escher/DgContainer.php';
|
||||
|
||||
/** PHPExcel_Shared_Escher_DgContainer_SpgrContainer */
|
||||
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/Escher/DgContainer/SpgrContainer.php';
|
||||
|
||||
/** PHPExcel_Shared_Escher_DgContainer_SpgrContainer_SpContainer */
|
||||
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/Escher/DgContainer/SpgrContainer/SpContainer.php';
|
||||
|
||||
/**
|
||||
* PHPExcel_Reader_Excel5_Escher
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel_Reader_Excel5
|
||||
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
class PHPExcel_Reader_Excel5_Escher
|
||||
{
|
||||
const DGGCONTAINER = 0xF000;
|
||||
const BSTORECONTAINER = 0xF001;
|
||||
const DGCONTAINER = 0xF002;
|
||||
const SPGRCONTAINER = 0xF003;
|
||||
const SPCONTAINER = 0xF004;
|
||||
const DGG = 0xF006;
|
||||
const BSE = 0xF007;
|
||||
const DG = 0xF008;
|
||||
const SPGR = 0xF009;
|
||||
const SP = 0xF00A;
|
||||
const OPT = 0xF00B;
|
||||
const CLIENTTEXTBOX = 0xF00D;
|
||||
const CLIENTANCHOR = 0xF010;
|
||||
const CLIENTDATA = 0xF011;
|
||||
const BLIPJPEG = 0xF01D;
|
||||
const BLIPPNG = 0xF01E;
|
||||
const SPLITMENUCOLORS = 0xF11E;
|
||||
const TERTIARYOPT = 0xF122;
|
||||
|
||||
/**
|
||||
* Escher stream data (binary)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_data;
|
||||
|
||||
/**
|
||||
* Size in bytes of the Escher stream data
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $_dataSize;
|
||||
|
||||
/**
|
||||
* Current position of stream pointer in Escher stream data
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $_pos;
|
||||
|
||||
/**
|
||||
* The object to be returned by the reader. Modified during load.
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
private $_object;
|
||||
|
||||
/**
|
||||
* Create a new PHPExcel_Reader_Excel5_Escher instance
|
||||
*
|
||||
* @param mixed $object
|
||||
*/
|
||||
public function __construct($object)
|
||||
{
|
||||
$this->_object = $object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Escher stream data. May be a partial Escher stream.
|
||||
*
|
||||
* @param string $data
|
||||
*/
|
||||
public function load($data)
|
||||
{
|
||||
$this->_data = $data;
|
||||
|
||||
// total byte size of Excel data (workbook global substream + sheet substreams)
|
||||
$this->_dataSize = strlen($this->_data);
|
||||
|
||||
$this->_pos = 0;
|
||||
|
||||
// Parse Escher stream
|
||||
while ($this->_pos < $this->_dataSize) {
|
||||
|
||||
|
||||
// offset: 2; size: 2: Record Type
|
||||
$fbt = $this->_GetInt2d($this->_data, $this->_pos + 2);
|
||||
|
||||
switch ($fbt) {
|
||||
case self::DGGCONTAINER: $this->_readDggContainer(); break;
|
||||
case self::DGG: $this->_readDgg(); break;
|
||||
case self::BSTORECONTAINER: $this->_readBstoreContainer(); break;
|
||||
case self::BSE: $this->_readBSE(); break;
|
||||
case self::BLIPJPEG: $this->_readBlipJPEG(); break;
|
||||
case self::BLIPPNG: $this->_readBlipPNG(); break;
|
||||
case self::OPT: $this->_readOPT(); break;
|
||||
case self::TERTIARYOPT: $this->_readTertiaryOPT(); break;
|
||||
case self::SPLITMENUCOLORS: $this->_readSplitMenuColors(); break;
|
||||
case self::DGCONTAINER: $this->_readDgContainer(); break;
|
||||
case self::DG: $this->_readDg(); break;
|
||||
case self::SPGRCONTAINER: $this->_readSpgrContainer(); break;
|
||||
case self::SPCONTAINER: $this->_readSpContainer(); break;
|
||||
case self::SPGR: $this->_readSpgr(); break;
|
||||
case self::SP: $this->_readSp(); break;
|
||||
case self::CLIENTTEXTBOX: $this->_readClientTextbox(); break;
|
||||
case self::CLIENTANCHOR: $this->_readClientAnchor(); break;
|
||||
case self::CLIENTDATA: $this->_readClientData(); break;
|
||||
default: $this->_readDefault(); break;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a generic record
|
||||
*/
|
||||
private function _readDefault()
|
||||
{
|
||||
// offset 0; size: 2; recVer and recInstance
|
||||
$verInstance = $this->_GetInt2d($this->_data, $this->_pos);
|
||||
|
||||
// offset: 2; size: 2: Record Type
|
||||
$fbt = $this->_GetInt2d($this->_data, $this->_pos + 2);
|
||||
|
||||
// bit: 0-3; mask: 0x000F; recVer
|
||||
$recVer = (0x000F & $verInstance) >> 0;
|
||||
|
||||
$length = $this->_GetInt4d($this->_data, $this->_pos + 4);
|
||||
$recordData = substr($this->_data, $this->_pos + 8, $length);
|
||||
|
||||
// move stream pointer to next record
|
||||
$this->_pos += 8 + $length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read DggContainer record (Drawing Group Container)
|
||||
*/
|
||||
private function _readDggContainer()
|
||||
{
|
||||
$length = $this->_GetInt4d($this->_data, $this->_pos + 4);
|
||||
$recordData = substr($this->_data, $this->_pos + 8, $length);
|
||||
|
||||
// move stream pointer to next record
|
||||
$this->_pos += 8 + $length;
|
||||
|
||||
// record is a container, read contents
|
||||
$dggContainer = new PHPExcel_Shared_Escher_DggContainer();
|
||||
$this->_object->setDggContainer($dggContainer);
|
||||
$reader = new PHPExcel_Reader_Excel5_Escher($dggContainer);
|
||||
$reader->load($recordData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read Dgg record (Drawing Group)
|
||||
*/
|
||||
private function _readDgg()
|
||||
{
|
||||
$length = $this->_GetInt4d($this->_data, $this->_pos + 4);
|
||||
$recordData = substr($this->_data, $this->_pos + 8, $length);
|
||||
|
||||
// move stream pointer to next record
|
||||
$this->_pos += 8 + $length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read BstoreContainer record (Blip Store Container)
|
||||
*/
|
||||
private function _readBstoreContainer()
|
||||
{
|
||||
$length = $this->_GetInt4d($this->_data, $this->_pos + 4);
|
||||
$recordData = substr($this->_data, $this->_pos + 8, $length);
|
||||
|
||||
// move stream pointer to next record
|
||||
$this->_pos += 8 + $length;
|
||||
|
||||
// record is a container, read contents
|
||||
$bstoreContainer = new PHPExcel_Shared_Escher_DggContainer_BstoreContainer();
|
||||
$this->_object->setBstoreContainer($bstoreContainer);
|
||||
$reader = new PHPExcel_Reader_Excel5_Escher($bstoreContainer);
|
||||
$reader->load($recordData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read BSE record
|
||||
*/
|
||||
private function _readBSE()
|
||||
{
|
||||
// offset: 0; size: 2; recVer and recInstance
|
||||
|
||||
// bit: 4-15; mask: 0xFFF0; recInstance
|
||||
$recInstance = (0xFFF0 & $this->_GetInt2d($this->_data, $this->_pos)) >> 4;
|
||||
|
||||
$length = $this->_GetInt4d($this->_data, $this->_pos + 4);
|
||||
$recordData = substr($this->_data, $this->_pos + 8, $length);
|
||||
|
||||
// move stream pointer to next record
|
||||
$this->_pos += 8 + $length;
|
||||
|
||||
// add BSE to BstoreContainer
|
||||
$BSE = new PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE();
|
||||
$this->_object->addBSE($BSE);
|
||||
|
||||
$BSE->setBLIPType($recInstance);
|
||||
|
||||
// offset: 0; size: 1; btWin32 (MSOBLIPTYPE)
|
||||
$btWin32 = ord($recordData[0]);
|
||||
|
||||
// offset: 1; size: 1; btWin32 (MSOBLIPTYPE)
|
||||
$btMacOS = ord($recordData[1]);
|
||||
|
||||
// offset: 2; size: 16; MD4 digest
|
||||
$rgbUid = substr($recordData, 2, 16);
|
||||
|
||||
// offset: 18; size: 2; tag
|
||||
$tag = $this->_GetInt2d($recordData, 18);
|
||||
|
||||
// offset: 20; size: 4; size of BLIP in bytes
|
||||
$size = $this->_GetInt4d($recordData, 20);
|
||||
|
||||
// offset: 24; size: 4; number of references to this BLIP
|
||||
$cRef = $this->_GetInt4d($recordData, 24);
|
||||
|
||||
// offset: 28; size: 4; MSOFO file offset
|
||||
$foDelay = $this->_GetInt4d($recordData, 28);
|
||||
|
||||
// offset: 32; size: 1; unused1
|
||||
$unused1 = ord($recordData{32});
|
||||
|
||||
// offset: 33; size: 1; size of nameData in bytes (including null terminator)
|
||||
$cbName = ord($recordData{33});
|
||||
|
||||
// offset: 34; size: 1; unused2
|
||||
$unused2 = ord($recordData{34});
|
||||
|
||||
// offset: 35; size: 1; unused3
|
||||
$unused3 = ord($recordData{35});
|
||||
|
||||
// offset: 36; size: $cbName; nameData
|
||||
$nameData = substr($recordData, 36, $cbName);
|
||||
|
||||
// offset: 36 + $cbName, size: var; the BLIP data
|
||||
$blipData = substr($recordData, 36 + $cbName);
|
||||
|
||||
// record is a container, read contents
|
||||
$reader = new PHPExcel_Reader_Excel5_Escher($BSE);
|
||||
$reader->load($blipData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read BlipJPEG record. Holds raw JPEG image data
|
||||
*/
|
||||
private function _readBlipJPEG()
|
||||
{
|
||||
// offset: 0; size: 2; recVer and recInstance
|
||||
|
||||
// bit: 4-15; mask: 0xFFF0; recInstance
|
||||
$recInstance = (0xFFF0 & $this->_GetInt2d($this->_data, $this->_pos)) >> 4;
|
||||
|
||||
$length = $this->_GetInt4d($this->_data, $this->_pos + 4);
|
||||
$recordData = substr($this->_data, $this->_pos + 8, $length);
|
||||
|
||||
// move stream pointer to next record
|
||||
$this->_pos += 8 + $length;
|
||||
|
||||
$pos = 0;
|
||||
|
||||
// offset: 0; size: 16; rgbUid1 (MD4 digest of)
|
||||
$rgbUid1 = substr($recordData, 0, 16);
|
||||
$pos += 16;
|
||||
|
||||
// offset: 16; size: 16; rgbUid2 (MD4 digest), only if $recInstance = 0x46B or 0x6E3
|
||||
if (in_array($recInstance, array(0x046B, 0x06E3))) {
|
||||
$rgbUid2 = substr($recordData, 16, 16);
|
||||
$pos += 16;
|
||||
}
|
||||
|
||||
// offset: var; size: 1; tag
|
||||
$tag = ord($recordData{$pos});
|
||||
$pos += 1;
|
||||
|
||||
// offset: var; size: var; the raw image data
|
||||
$data = substr($recordData, $pos);
|
||||
|
||||
$blip = new PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE_Blip();
|
||||
$blip->setData($data);
|
||||
|
||||
$this->_object->setBlip($blip);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read BlipPNG record. Holds raw PNG image data
|
||||
*/
|
||||
private function _readBlipPNG()
|
||||
{
|
||||
// offset: 0; size: 2; recVer and recInstance
|
||||
|
||||
// bit: 4-15; mask: 0xFFF0; recInstance
|
||||
$recInstance = (0xFFF0 & $this->_GetInt2d($this->_data, $this->_pos)) >> 4;
|
||||
|
||||
$length = $this->_GetInt4d($this->_data, $this->_pos + 4);
|
||||
$recordData = substr($this->_data, $this->_pos + 8, $length);
|
||||
|
||||
// move stream pointer to next record
|
||||
$this->_pos += 8 + $length;
|
||||
|
||||
$pos = 0;
|
||||
|
||||
// offset: 0; size: 16; rgbUid1 (MD4 digest of)
|
||||
$rgbUid1 = substr($recordData, 0, 16);
|
||||
$pos += 16;
|
||||
|
||||
// offset: 16; size: 16; rgbUid2 (MD4 digest), only if $recInstance = 0x46B or 0x6E3
|
||||
if ($recInstance == 0x06E1) {
|
||||
$rgbUid2 = substr($recordData, 16, 16);
|
||||
$pos += 16;
|
||||
}
|
||||
|
||||
// offset: var; size: 1; tag
|
||||
$tag = ord($recordData{$pos});
|
||||
$pos += 1;
|
||||
|
||||
// offset: var; size: var; the raw image data
|
||||
$data = substr($recordData, $pos);
|
||||
|
||||
$blip = new PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE_Blip();
|
||||
$blip->setData($data);
|
||||
|
||||
$this->_object->setBlip($blip);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read OPT record. This record may occur within DggContainer record or SpContainer
|
||||
*/
|
||||
private function _readOPT()
|
||||
{
|
||||
// offset: 0; size: 2; recVer and recInstance
|
||||
|
||||
// bit: 4-15; mask: 0xFFF0; recInstance
|
||||
$recInstance = (0xFFF0 & $this->_GetInt2d($this->_data, $this->_pos)) >> 4;
|
||||
|
||||
$length = $this->_GetInt4d($this->_data, $this->_pos + 4);
|
||||
$recordData = substr($this->_data, $this->_pos + 8, $length);
|
||||
|
||||
// move stream pointer to next record
|
||||
$this->_pos += 8 + $length;
|
||||
|
||||
$this->_readOfficeArtRGFOPTE($recordData, $recInstance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read TertiaryOPT record
|
||||
*/
|
||||
private function _readTertiaryOPT()
|
||||
{
|
||||
// offset: 0; size: 2; recVer and recInstance
|
||||
|
||||
// bit: 4-15; mask: 0xFFF0; recInstance
|
||||
$recInstance = (0xFFF0 & $this->_GetInt2d($this->_data, $this->_pos)) >> 4;
|
||||
|
||||
$length = $this->_GetInt4d($this->_data, $this->_pos + 4);
|
||||
$recordData = substr($this->_data, $this->_pos + 8, $length);
|
||||
|
||||
// move stream pointer to next record
|
||||
$this->_pos += 8 + $length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read SplitMenuColors record
|
||||
*/
|
||||
private function _readSplitMenuColors()
|
||||
{
|
||||
$length = $this->_GetInt4d($this->_data, $this->_pos + 4);
|
||||
$recordData = substr($this->_data, $this->_pos + 8, $length);
|
||||
|
||||
// move stream pointer to next record
|
||||
$this->_pos += 8 + $length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read DgContainer record (Drawing Container)
|
||||
*/
|
||||
private function _readDgContainer()
|
||||
{
|
||||
$length = $this->_GetInt4d($this->_data, $this->_pos + 4);
|
||||
$recordData = substr($this->_data, $this->_pos + 8, $length);
|
||||
|
||||
// move stream pointer to next record
|
||||
$this->_pos += 8 + $length;
|
||||
|
||||
// record is a container, read contents
|
||||
$dgContainer = new PHPExcel_Shared_Escher_DgContainer();
|
||||
$this->_object->setDgContainer($dgContainer);
|
||||
$reader = new PHPExcel_Reader_Excel5_Escher($dgContainer);
|
||||
$escher = $reader->load($recordData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read Dg record (Drawing)
|
||||
*/
|
||||
private function _readDg()
|
||||
{
|
||||
$length = $this->_GetInt4d($this->_data, $this->_pos + 4);
|
||||
$recordData = substr($this->_data, $this->_pos + 8, $length);
|
||||
|
||||
// move stream pointer to next record
|
||||
$this->_pos += 8 + $length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read SpgrContainer record (Shape Group Container)
|
||||
*/
|
||||
private function _readSpgrContainer()
|
||||
{
|
||||
// context is either context DgContainer or SpgrContainer
|
||||
|
||||
$length = $this->_GetInt4d($this->_data, $this->_pos + 4);
|
||||
$recordData = substr($this->_data, $this->_pos + 8, $length);
|
||||
|
||||
// move stream pointer to next record
|
||||
$this->_pos += 8 + $length;
|
||||
|
||||
// record is a container, read contents
|
||||
$spgrContainer = new PHPExcel_Shared_Escher_DgContainer_SpgrContainer();
|
||||
|
||||
if ($this->_object instanceof PHPExcel_Shared_Escher_DgContainer) {
|
||||
// DgContainer
|
||||
$this->_object->setSpgrContainer($spgrContainer);
|
||||
} else {
|
||||
// SpgrContainer
|
||||
$this->_object->addChild($spgrContainer);
|
||||
}
|
||||
|
||||
$reader = new PHPExcel_Reader_Excel5_Escher($spgrContainer);
|
||||
$escher = $reader->load($recordData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read SpContainer record (Shape Container)
|
||||
*/
|
||||
private function _readSpContainer()
|
||||
{
|
||||
$length = $this->_GetInt4d($this->_data, $this->_pos + 4);
|
||||
$recordData = substr($this->_data, $this->_pos + 8, $length);
|
||||
|
||||
// add spContainer to spgrContainer
|
||||
$spContainer = new PHPExcel_Shared_Escher_DgContainer_SpgrContainer_SpContainer();
|
||||
$this->_object->addChild($spContainer);
|
||||
|
||||
// move stream pointer to next record
|
||||
$this->_pos += 8 + $length;
|
||||
|
||||
// record is a container, read contents
|
||||
$reader = new PHPExcel_Reader_Excel5_Escher($spContainer);
|
||||
$escher = $reader->load($recordData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read Spgr record (Shape Group)
|
||||
*/
|
||||
private function _readSpgr()
|
||||
{
|
||||
$length = $this->_GetInt4d($this->_data, $this->_pos + 4);
|
||||
$recordData = substr($this->_data, $this->_pos + 8, $length);
|
||||
|
||||
// move stream pointer to next record
|
||||
$this->_pos += 8 + $length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read Sp record (Shape)
|
||||
*/
|
||||
private function _readSp()
|
||||
{
|
||||
// offset: 0; size: 2; recVer and recInstance
|
||||
|
||||
// bit: 4-15; mask: 0xFFF0; recInstance
|
||||
$recInstance = (0xFFF0 & $this->_GetInt2d($this->_data, $this->_pos)) >> 4;
|
||||
|
||||
$length = $this->_GetInt4d($this->_data, $this->_pos + 4);
|
||||
$recordData = substr($this->_data, $this->_pos + 8, $length);
|
||||
|
||||
// move stream pointer to next record
|
||||
$this->_pos += 8 + $length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read ClientTextbox record
|
||||
*/
|
||||
private function _readClientTextbox()
|
||||
{
|
||||
// offset: 0; size: 2; recVer and recInstance
|
||||
|
||||
// bit: 4-15; mask: 0xFFF0; recInstance
|
||||
$recInstance = (0xFFF0 & $this->_GetInt2d($this->_data, $this->_pos)) >> 4;
|
||||
|
||||
$length = $this->_GetInt4d($this->_data, $this->_pos + 4);
|
||||
$recordData = substr($this->_data, $this->_pos + 8, $length);
|
||||
|
||||
// move stream pointer to next record
|
||||
$this->_pos += 8 + $length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read ClientAnchor record. This record holds information about where the shape is anchored in worksheet
|
||||
*/
|
||||
private function _readClientAnchor()
|
||||
{
|
||||
$length = $this->_GetInt4d($this->_data, $this->_pos + 4);
|
||||
$recordData = substr($this->_data, $this->_pos + 8, $length);
|
||||
|
||||
// move stream pointer to next record
|
||||
$this->_pos += 8 + $length;
|
||||
|
||||
// offset: 2; size: 2; upper-left corner column index (0-based)
|
||||
$c1 = $this->_GetInt2d($recordData, 2);
|
||||
|
||||
// offset: 4; size: 2; upper-left corner horizontal offset in 1/1024 of column width
|
||||
$startOffsetX = $this->_GetInt2d($recordData, 4);
|
||||
|
||||
// offset: 6; size: 2; upper-left corner row index (0-based)
|
||||
$r1 = $this->_GetInt2d($recordData, 6);
|
||||
|
||||
// offset: 8; size: 2; upper-left corner vertical offset in 1/256 of row height
|
||||
$startOffsetY = $this->_GetInt2d($recordData, 8);
|
||||
|
||||
// offset: 10; size: 2; bottom-right corner column index (0-based)
|
||||
$c2 = $this->_GetInt2d($recordData, 10);
|
||||
|
||||
// offset: 12; size: 2; bottom-right corner horizontal offset in 1/1024 of column width
|
||||
$endOffsetX = $this->_GetInt2d($recordData, 12);
|
||||
|
||||
// offset: 14; size: 2; bottom-right corner row index (0-based)
|
||||
$r2 = $this->_GetInt2d($recordData, 14);
|
||||
|
||||
// offset: 16; size: 2; bottom-right corner vertical offset in 1/256 of row height
|
||||
$endOffsetY = $this->_GetInt2d($recordData, 16);
|
||||
|
||||
// set the start coordinates
|
||||
$this->_object->setStartCoordinates(PHPExcel_Cell::stringFromColumnIndex($c1) . ($r1 + 1));
|
||||
|
||||
// set the start offsetX
|
||||
$this->_object->setStartOffsetX($startOffsetX);
|
||||
|
||||
// set the start offsetY
|
||||
$this->_object->setStartOffsetY($startOffsetY);
|
||||
|
||||
// set the end coordinates
|
||||
$this->_object->setEndCoordinates(PHPExcel_Cell::stringFromColumnIndex($c2) . ($r2 + 1));
|
||||
|
||||
// set the end offsetX
|
||||
$this->_object->setEndOffsetX($endOffsetX);
|
||||
|
||||
// set the end offsetY
|
||||
$this->_object->setEndOffsetY($endOffsetY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read ClientData record
|
||||
*/
|
||||
private function _readClientData()
|
||||
{
|
||||
$length = $this->_GetInt4d($this->_data, $this->_pos + 4);
|
||||
$recordData = substr($this->_data, $this->_pos + 8, $length);
|
||||
|
||||
// move stream pointer to next record
|
||||
$this->_pos += 8 + $length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read OfficeArtRGFOPTE table of property-value pairs
|
||||
*
|
||||
* @param string $data Binary data
|
||||
* @param int $n Number of properties
|
||||
*/
|
||||
private function _readOfficeArtRGFOPTE($data, $n) {
|
||||
|
||||
$splicedComplexData = substr($data, 6 * $n);
|
||||
|
||||
// loop through property-value pairs
|
||||
for ($i = 0; $i < $n; ++$i) {
|
||||
// read 6 bytes at a time
|
||||
$fopte = substr($data, 6 * $i, 6);
|
||||
|
||||
// offset: 0; size: 2; opid
|
||||
$opid = $this->_GetInt2d($fopte, 0);
|
||||
|
||||
// bit: 0-13; mask: 0x3FFF; opid.opid
|
||||
$opidOpid = (0x3FFF & $opid) >> 0;
|
||||
|
||||
// bit: 14; mask 0x4000; 1 = value in op field is BLIP identifier
|
||||
$opidFBid = (0x4000 & $opid) >> 14;
|
||||
|
||||
// bit: 15; mask 0x8000; 1 = this is a complex property, op field specifies size of complex data
|
||||
$opidFComplex = (0x8000 & $opid) >> 15;
|
||||
|
||||
// offset: 2; size: 4; the value for this property
|
||||
$op = $this->_GetInt4d($fopte, 2);
|
||||
|
||||
if ($opidFComplex) {
|
||||
$complexData = substr($splicedComplexData, 0, $op);
|
||||
$splicedComplexData = substr($splicedComplexData, $op);
|
||||
|
||||
// we store string value with complex data
|
||||
$value = $complexData;
|
||||
} else {
|
||||
// we store integer value
|
||||
$value = $op;
|
||||
}
|
||||
|
||||
$this->_object->setOPT($opidOpid, $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read 16-bit unsigned integer
|
||||
*
|
||||
* @param string $data
|
||||
* @param int $pos
|
||||
* @return int
|
||||
*/
|
||||
private function _GetInt2d($data, $pos)
|
||||
{
|
||||
return ord($data[$pos]) | (ord($data[$pos + 1]) << 8);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read 32-bit signed integer
|
||||
*
|
||||
* @param string $data
|
||||
* @param int $pos
|
||||
* @return int
|
||||
*/
|
||||
private function _GetInt4d($data, $pos)
|
||||
{
|
||||
//return ord($data[$pos]) | (ord($data[$pos + 1]) << 8) |
|
||||
// (ord($data[$pos + 2]) << 16) | (ord($data[$pos + 3]) << 24);
|
||||
|
||||
// FIX: represent numbers correctly on 64-bit system
|
||||
// http://sourceforge.net/tracker/index.php?func=detail&aid=1487372&group_id=99160&atid=623334
|
||||
$_or_24 = ord($data[$pos + 3]);
|
||||
if ($_or_24 >= 128) {
|
||||
// negative number
|
||||
$_ord_24 = -abs((256 - $_or_24) << 24);
|
||||
} else {
|
||||
$_ord_24 = ($_or_24 & 127) << 24;
|
||||
}
|
||||
return ord($data[$pos]) | (ord($data[$pos + 1]) << 8) | (ord($data[$pos + 2]) << 16) | $_ord_24;
|
||||
}
|
||||
|
||||
}
|
47
libraries/PHPExcel/PHPExcel/Reader/IReadFilter.php
Normal file
47
libraries/PHPExcel/PHPExcel/Reader/IReadFilter.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
* PHPExcel
|
||||
*
|
||||
* Copyright (c) 2006 - 2009 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 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version 1.7.0, 2009-08-10
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* PHPExcel_Reader_IReadFilter
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel_Reader
|
||||
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
interface PHPExcel_Reader_IReadFilter
|
||||
{
|
||||
/**
|
||||
* Should this cell be read?
|
||||
*
|
||||
* @param $column String column index
|
||||
* @param $row Row index
|
||||
* @param $worksheetName Optional worksheet name
|
||||
* @return boolean
|
||||
*/
|
||||
public function readCell($column, $row, $worksheetName = '');
|
||||
}
|
53
libraries/PHPExcel/PHPExcel/Reader/IReader.php
Normal file
53
libraries/PHPExcel/PHPExcel/Reader/IReader.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* PHPExcel
|
||||
*
|
||||
* Copyright (c) 2006 - 2009 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 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version 1.7.0, 2009-08-10
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* PHPExcel_Reader_IReader
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel_Reader
|
||||
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
interface PHPExcel_Reader_IReader
|
||||
{
|
||||
/**
|
||||
* Can the current PHPExcel_Reader_IReader read the file?
|
||||
*
|
||||
* @param string $pFileName
|
||||
* @return boolean
|
||||
*/
|
||||
public function canRead($pFilename);
|
||||
|
||||
/**
|
||||
* Loads PHPExcel from file
|
||||
*
|
||||
* @param string $pFileName
|
||||
* @throws Exception
|
||||
*/
|
||||
public function load($pFilename);
|
||||
}
|
133
libraries/PHPExcel/PHPExcel/Reader/Serialized.php
Normal file
133
libraries/PHPExcel/PHPExcel/Reader/Serialized.php
Normal file
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
/**
|
||||
* PHPExcel
|
||||
*
|
||||
* Copyright (c) 2006 - 2009 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 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version 1.7.0, 2009-08-10
|
||||
*/
|
||||
|
||||
|
||||
/** PHPExcel root directory */
|
||||
if (!defined('PHPEXCEL_ROOT')) {
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
|
||||
}
|
||||
|
||||
/** PHPExcel */
|
||||
require_once PHPEXCEL_ROOT . 'PHPExcel.php';
|
||||
|
||||
/** PHPExcel_Reader_IReader */
|
||||
require_once PHPEXCEL_ROOT . 'PHPExcel/Reader/IReader.php';
|
||||
|
||||
/** PHPExcel_Shared_File */
|
||||
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/File.php';
|
||||
|
||||
|
||||
/**
|
||||
* PHPExcel_Reader_Serialized
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel_Reader
|
||||
* @copyright Copyright (c) 2006 - 2009 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");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user