Update library PHPExcel to version 1.7.6

This commit is contained in:
Dieter Adriaenssens
2011-03-02 20:56:37 +01:00
parent f07a0842f0
commit e0a70f4c6b
149 changed files with 26496 additions and 21168 deletions

View File

@@ -145,6 +145,7 @@
- rfe #1640812 [auth] Add example for OpenID authentication using signon method.
- rfe #1312657 [dbi] Default to mysqli extension.
- rfe #1168350 [interface] Add clear button to SQL edit box.
- [core] Update library PHPExcel to version 1.7.6
3.3.10.0 (not yet released)
- patch #3147400 [structure] Aria table size printed as unknown,

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
@@ -30,12 +30,6 @@
if (!defined('PHPEXCEL_ROOT')) {
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/');
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
PHPExcel_Autoloader::Register();
PHPExcel_Shared_ZipStreamWrapper::register();
// check mbstring.func_overload
if (ini_get('mbstring.func_overload') & 2) {
throw new Exception('Multibyte function overloading in PHP must be disabled for string functions (2).');
}
}
@@ -44,7 +38,7 @@ if (!defined('PHPEXCEL_ROOT')) {
*
* @category PHPExcel
* @package PHPExcel
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel
{
@@ -628,7 +622,7 @@ class PHPExcel
// then update cellXf indexes for cells
foreach ($this->_workSheetCollection as $worksheet) {
foreach ($worksheet->getCellCollection(false) as $cellID) {
$cell = $sheet->getCell($cellID);
$cell = $worksheet->getCell($cellID);
$xfIndex = $cell->getXfIndex();
if ($xfIndex > $pIndex ) {
// decrease xf index by 1

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -20,11 +20,20 @@
*
* @category PHPExcel
* @package PHPExcel
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
PHPExcel_Autoloader::Register();
PHPExcel_Shared_ZipStreamWrapper::register();
// check mbstring.func_overload
if (ini_get('mbstring.func_overload') & 2) {
throw new Exception('Multibyte function overloading in PHP must be disabled for string functions (2).');
}
PHPExcel_Shared_String::buildCharacterSets();
class PHPExcel_Autoloader
{
public static function Register() {

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
@@ -31,7 +31,7 @@
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_CachedObjectStorage_APC extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
@@ -31,7 +31,7 @@
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_CachedObjectStorage_CacheBase {
@@ -98,9 +98,7 @@ class PHPExcel_CachedObjectStorage_CacheBase {
* @throws Exception
*/
public function updateCacheData(PHPExcel_Cell $cell) {
$pCoord = $cell->getCoordinate();
return $this->addCacheData($pCoord,$cell);
return $this->addCacheData($cell->getCoordinate(),$cell);
} // function updateCacheData()
@@ -140,9 +138,9 @@ class PHPExcel_CachedObjectStorage_CacheBase {
*/
public function getSortedCellList() {
$sortKeys = array();
foreach ($this->_cellCache as $coord => $value) {
list($colNum,$rowNum) = sscanf($coord,'%[A-Z]%d');
$sortKeys[sprintf('%09d%3s',$rowNum,$colNum)] = $coord;
foreach (array_keys($this->_cellCache) as $coord) {
list($column,$row) = sscanf($coord,'%[A-Z]%d');
$sortKeys[sprintf('%09d%3s',$row,$column)] = $coord;
}
ksort($sortKeys);

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
@@ -31,7 +31,7 @@
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_CachedObjectStorage_DiscISAM extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {
@@ -112,7 +112,7 @@ class PHPExcel_CachedObjectStorage_DiscISAM extends PHPExcel_CachedObjectStorage
parent::copyCellCollection($parent);
// Get a new id for the new file name
$baseUnique = $this->_getUniqueID();
$newFileName = sys_get_temp_dir().'/PHPExcel.'.$baseUnique.'.cache';
$newFileName = PHPExcel_Shared_File::sys_get_temp_dir().'/PHPExcel.'.$baseUnique.'.cache';
// Copy the existing cell cache file
copy ($this->_fileName,$newFileName);
$this->_fileName = $newFileName;
@@ -140,7 +140,7 @@ class PHPExcel_CachedObjectStorage_DiscISAM extends PHPExcel_CachedObjectStorage
parent::__construct($parent);
if (is_null($this->_fileHandle)) {
$baseUnique = $this->_getUniqueID();
$this->_fileName = sys_get_temp_dir().'/PHPExcel.'.$baseUnique.'.cache';
$this->_fileName = PHPExcel_Shared_File::sys_get_temp_dir().'/PHPExcel.'.$baseUnique.'.cache';
$this->_fileHandle = fopen($this->_fileName,'a+');
}
} // function __construct()

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
@@ -31,7 +31,7 @@
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
interface PHPExcel_CachedObjectStorage_ICache
{

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
@@ -31,7 +31,7 @@
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_CachedObjectStorage_Memcache extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {
@@ -234,6 +234,3 @@ class PHPExcel_CachedObjectStorage_Memcache extends PHPExcel_CachedObjectStorage
} // function __destruct()
}
?>

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
@@ -31,7 +31,7 @@
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_CachedObjectStorage_Memory extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {
@@ -68,6 +68,19 @@ class PHPExcel_CachedObjectStorage_Memory extends PHPExcel_CachedObjectStorage_C
} // function getCacheData()
public function copyCellCollection(PHPExcel_Worksheet $parent) {
parent::copyCellCollection($parent);
$newCollection = array();
foreach($this->_cellCache as $k => &$cell) {
$newCollection[$k] = clone $cell;
$newCollection[$k]->attach($parent);
}
$this->_cellCache = $newCollection;
}
public function unsetWorksheetCells() {
// Because cells are all stored as intact objects in memory, we need to detach each one from the parent
foreach($this->_cellCache as $k => &$cell) {

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
@@ -31,7 +31,7 @@
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_CachedObjectStorage_MemoryGZip extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
@@ -31,7 +31,7 @@
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_CachedObjectStorage_MemorySerialized extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
@@ -31,7 +31,7 @@
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_CachedObjectStorage_PHPTemp extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
@@ -31,7 +31,7 @@
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_CachedObjectStorage_Wincache extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {
@@ -228,6 +228,3 @@ class PHPExcel_CachedObjectStorage_Wincache extends PHPExcel_CachedObjectStorage
} // function __destruct()
}
?>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,384 @@
<?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_Calculation
* @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 1.7.6, 2011-02-27
*/
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
}
/**
* PHPExcel_Calculation_Database
*
* @category PHPExcel
* @package PHPExcel_Calculation
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Calculation_Database {
private static function __fieldExtract($database,$field) {
$field = strtoupper(PHPExcel_Calculation_Functions::flattenSingleValue($field));
$fieldNames = array_map('strtoupper',array_shift($database));
if (is_numeric($field)) {
$keys = array_keys($fieldNames);
return $keys[$field-1];
}
$key = array_search($field,$fieldNames);
return ($key) ? $key : null;
}
private static function __filter($database,$criteria) {
$fieldNames = array_shift($database);
$criteriaNames = array_shift($criteria);
// Convert the criteria into a set of AND/OR conditions with [:placeholders]
$testConditions = $testValues = array();
$testConditionsCount = 0;
foreach($criteriaNames as $key => $criteriaName) {
$testCondition = array();
$testConditionCount = 0;
foreach($criteria as $row => $criterion) {
if ($criterion[$key] > '') {
$testCondition[] = '[:'.$criteriaName.']'.PHPExcel_Calculation_Functions::_ifCondition($criterion[$key]);
$testConditionCount++;
}
}
if ($testConditionCount > 1) {
$testConditions[] = 'OR('.implode(',',$testCondition).')';
$testConditionsCount++;
} elseif($testConditionCount == 1) {
$testConditions[] = $testCondition[0];
$testConditionsCount++;
}
}
if ($testConditionsCount > 1) {
$testConditionSet = 'AND('.implode(',',$testConditions).')';
} elseif($testConditionsCount == 1) {
$testConditionSet = $testConditions[0];
}
// Loop through each row of the database
foreach($database as $dataRow => $dataValues) {
// Substitute actual values from the database row for our [:placeholders]
$testConditionList = $testConditionSet;
foreach($criteriaNames as $key => $criteriaName) {
$k = array_search($criteriaName,$fieldNames);
if (isset($dataValues[$k])) {
$dataValue = $dataValues[$k];
$dataValue = (is_string($dataValue)) ? PHPExcel_Calculation::_wrapResult(strtoupper($dataValue)) : $dataValue;
$testConditionList = str_replace('[:'.$criteriaName.']',$dataValue,$testConditionList);
}
}
// evaluate the criteria against the row data
$result = PHPExcel_Calculation::getInstance()->_calculateFormulaValue('='.$testConditionList);
// If the row failed to meet the criteria, remove it from the database
if (!$result) {
unset($database[$dataRow]);
}
}
return $database;
}
/**
* DAVERAGE
*
*/
public static function DAVERAGE($database,$field,$criteria) {
$field = self::__fieldExtract($database,$field);
if (is_null($field)) {
return NULL;
}
// reduce the database to a set of rows that match all the criteria
$database = self::__filter($database,$criteria);
// extract an array of values for the requested column
$colData = array();
foreach($database as $row) {
$colData[] = $row[$field];
}
// Return
return PHPExcel_Calculation_Statistical::AVERAGE($colData);
} // function DAVERAGE()
/**
* DCOUNT
*
*/
public static function DCOUNT($database,$field,$criteria) {
$field = self::__fieldExtract($database,$field);
if (is_null($field)) {
return NULL;
}
// reduce the database to a set of rows that match all the criteria
$database = self::__filter($database,$criteria);
// extract an array of values for the requested column
$colData = array();
foreach($database as $row) {
$colData[] = $row[$field];
}
// Return
return PHPExcel_Calculation_Statistical::COUNT($colData);
} // function DCOUNT()
/**
* DCOUNTA
*
*/
public static function DCOUNTA($database,$field,$criteria) {
$field = self::__fieldExtract($database,$field);
if (is_null($field)) {
return NULL;
}
// reduce the database to a set of rows that match all the criteria
$database = self::__filter($database,$criteria);
// extract an array of values for the requested column
$colData = array();
foreach($database as $row) {
$colData[] = $row[$field];
}
// Return
return PHPExcel_Calculation_Statistical::COUNTA($colData);
} // function DCOUNTA()
/**
* DGET
*
*/
public static function DGET($database,$field,$criteria) {
$field = self::__fieldExtract($database,$field);
if (is_null($field)) {
return NULL;
}
// reduce the database to a set of rows that match all the criteria
$database = self::__filter($database,$criteria);
// extract an array of values for the requested column
$colData = array();
foreach($database as $row) {
$colData[] = $row[$field];
}
// Return
if (count($colData) > 1) {
return PHPExcel_Calculation_Functions::NaN();
}
return $colData[0];
} // function DGET()
/**
* DMAX
*
*/
public static function DMAX($database,$field,$criteria) {
$field = self::__fieldExtract($database,$field);
if (is_null($field)) {
return NULL;
}
// reduce the database to a set of rows that match all the criteria
$database = self::__filter($database,$criteria);
// extract an array of values for the requested column
$colData = array();
foreach($database as $row) {
$colData[] = $row[$field];
}
// Return
return PHPExcel_Calculation_Statistical::MAX($colData);
} // function DMAX()
/**
* DMIN
*
*/
public static function DMIN($database,$field,$criteria) {
$field = self::__fieldExtract($database,$field);
if (is_null($field)) {
return NULL;
}
// reduce the database to a set of rows that match all the criteria
$database = self::__filter($database,$criteria);
// extract an array of values for the requested column
$colData = array();
foreach($database as $row) {
$colData[] = $row[$field];
}
// Return
return PHPExcel_Calculation_Statistical::MIN($colData);
} // function DMIN()
/**
* DPRODUCT
*
*/
public static function DPRODUCT($database,$field,$criteria) {
$field = self::__fieldExtract($database,$field);
if (is_null($field)) {
return NULL;
}
// reduce the database to a set of rows that match all the criteria
$database = self::__filter($database,$criteria);
// extract an array of values for the requested column
$colData = array();
foreach($database as $row) {
$colData[] = $row[$field];
}
// Return
return PHPExcel_Calculation_MathTrig::PRODUCT($colData);
} // function DPRODUCT()
/**
* DSTDEV
*
*/
public static function DSTDEV($database,$field,$criteria) {
$field = self::__fieldExtract($database,$field);
if (is_null($field)) {
return NULL;
}
// reduce the database to a set of rows that match all the criteria
$database = self::__filter($database,$criteria);
// extract an array of values for the requested column
$colData = array();
foreach($database as $row) {
$colData[] = $row[$field];
}
// Return
return PHPExcel_Calculation_Statistical::STDEV($colData);
} // function DSTDEV()
/**
* DSTDEVP
*
*/
public static function DSTDEVP($database,$field,$criteria) {
$field = self::__fieldExtract($database,$field);
if (is_null($field)) {
return NULL;
}
// reduce the database to a set of rows that match all the criteria
$database = self::__filter($database,$criteria);
// extract an array of values for the requested column
$colData = array();
foreach($database as $row) {
$colData[] = $row[$field];
}
// Return
return PHPExcel_Calculation_Statistical::STDEVP($colData);
} // function DSTDEVP()
/**
* DSUM
*
*/
public static function DSUM($database,$field,$criteria) {
$field = self::__fieldExtract($database,$field);
if (is_null($field)) {
return NULL;
}
// reduce the database to a set of rows that match all the criteria
$database = self::__filter($database,$criteria);
// extract an array of values for the requested column
$colData = array();
foreach($database as $row) {
$colData[] = $row[$field];
}
// Return
return PHPExcel_Calculation_MathTrig::SUM($colData);
} // function DSUM()
/**
* DVAR
*
*/
public static function DVAR($database,$field,$criteria) {
$field = self::__fieldExtract($database,$field);
if (is_null($field)) {
return NULL;
}
// reduce the database to a set of rows that match all the criteria
$database = self::__filter($database,$criteria);
// extract an array of values for the requested column
$colData = array();
foreach($database as $row) {
$colData[] = $row[$field];
}
// Return
return PHPExcel_Calculation_Statistical::VARFunc($colData);
} // function DVAR()
/**
* DVARP
*
*/
public static function DVARP($database,$field,$criteria) {
$field = self::__fieldExtract($database,$field);
if (is_null($field)) {
return NULL;
}
// reduce the database to a set of rows that match all the criteria
$database = self::__filter($database,$criteria);
// extract an array of values for the requested column
$colData = array();
foreach($database as $row) {
$colData[] = $row[$field];
}
// Return
return PHPExcel_Calculation_Statistical::VARP($colData);
} // function DVARP()
} // class PHPExcel_Calculation_Database

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Calculation
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
@@ -31,7 +31,7 @@
*
* @category PHPExcel
* @package PHPExcel_Calculation
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Calculation_Exception extends Exception {
/**

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Calculation
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
/**
@@ -30,7 +30,7 @@
*
* @category PHPExcel
* @package PHPExcel_Calculation
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Calculation_ExceptionHandler {
/**

File diff suppressed because it is too large Load Diff

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Calculation
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
@@ -54,7 +54,7 @@ PARTLY BASED ON:
*
* @category PHPExcel
* @package PHPExcel_Calculation
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Calculation_FormulaParser {
/* Character constants */

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Calculation
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
@@ -55,7 +55,7 @@ PARTLY BASED ON:
*
* @category PHPExcel
* @package PHPExcel_Calculation
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Calculation_FormulaToken {
/* Token types */

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Calculation
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
@@ -31,7 +31,7 @@
*
* @category PHPExcel
* @package PHPExcel_Calculation
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Calculation_Function {
/* Function categories */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,290 @@
<?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_Calculation
* @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 1.7.6, 2011-02-27
*/
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
}
/**
* PHPExcel_Calculation_Logical
*
* @category PHPExcel
* @package PHPExcel_Calculation
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Calculation_Logical {
/**
* TRUE
*
* Returns the boolean TRUE.
*
* Excel Function:
* =TRUE()
*
* @access public
* @category Logical Functions
* @return boolean True
*/
public static function TRUE() {
return true;
} // function TRUE()
/**
* FALSE
*
* Returns the boolean FALSE.
*
* Excel Function:
* =FALSE()
*
* @access public
* @category Logical Functions
* @return boolean False
*/
public static function FALSE() {
return false;
} // function FALSE()
/**
* LOGICAL_AND
*
* Returns boolean TRUE if all its arguments are TRUE; returns FALSE if one or more argument is FALSE.
*
* Excel Function:
* =AND(logical1[,logical2[, ...]])
*
* The arguments must evaluate to logical values such as TRUE or FALSE, or the arguments must be arrays
* or references that contain logical values.
*
* Boolean arguments are treated as True or False as appropriate
* Integer or floating point arguments are treated as True, except for 0 or 0.0 which are False
* If any argument value is a string, or a Null, the function returns a #VALUE! error, unless the string holds
* the value TRUE or FALSE, in which case it is evaluated as the corresponding boolean value
*
* @access public
* @category Logical Functions
* @param mixed $arg,... Data values
* @return boolean The logical AND of the arguments.
*/
public static function LOGICAL_AND() {
// Return value
$returnValue = True;
// Loop through the arguments
$aArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args());
$argCount = 0;
foreach ($aArgs as $arg) {
// Is it a boolean value?
if (is_bool($arg)) {
$returnValue = $returnValue && $arg;
} elseif ((is_numeric($arg)) && (!is_string($arg))) {
$returnValue = $returnValue && ($arg != 0);
} elseif (is_string($arg)) {
$arg = strtoupper($arg);
if (($arg == 'TRUE') || ($arg == PHPExcel_Calculation::getTRUE())) {
$arg = true;
} elseif (($arg == 'FALSE') || ($arg == PHPExcel_Calculation::getFALSE())) {
$arg = false;
} else {
return PHPExcel_Calculation_Functions::VALUE();
}
$returnValue = $returnValue && ($arg != 0);
}
++$argCount;
}
// Return
if ($argCount == 0) {
return PHPExcel_Calculation_Functions::VALUE();
}
return $returnValue;
} // function LOGICAL_AND()
/**
* LOGICAL_OR
*
* Returns boolean TRUE if any argument is TRUE; returns FALSE if all arguments are FALSE.
*
* Excel Function:
* =OR(logical1[,logical2[, ...]])
*
* The arguments must evaluate to logical values such as TRUE or FALSE, or the arguments must be arrays
* or references that contain logical values.
*
* Boolean arguments are treated as True or False as appropriate
* Integer or floating point arguments are treated as True, except for 0 or 0.0 which are False
* If any argument value is a string, or a Null, the function returns a #VALUE! error, unless the string holds
* the value TRUE or FALSE, in which case it is evaluated as the corresponding boolean value
*
* @access public
* @category Logical Functions
* @param mixed $arg,... Data values
* @return boolean The logical OR of the arguments.
*/
public static function LOGICAL_OR() {
// Return value
$returnValue = False;
// Loop through the arguments
$aArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args());
$argCount = 0;
foreach ($aArgs as $arg) {
// Is it a boolean value?
if (is_bool($arg)) {
$returnValue = $returnValue || $arg;
} elseif ((is_numeric($arg)) && (!is_string($arg))) {
$returnValue = $returnValue || ($arg != 0);
} elseif (is_string($arg)) {
$arg = strtoupper($arg);
if (($arg == 'TRUE') || ($arg == PHPExcel_Calculation::getTRUE())) {
$arg = true;
} elseif (($arg == 'FALSE') || ($arg == PHPExcel_Calculation::getFALSE())) {
$arg = false;
} else {
return PHPExcel_Calculation_Functions::VALUE();
}
$returnValue = $returnValue || ($arg != 0);
}
++$argCount;
}
// Return
if ($argCount == 0) {
return PHPExcel_Calculation_Functions::VALUE();
}
return $returnValue;
} // function LOGICAL_OR()
/**
* NOT
*
* Returns the boolean inverse of the argument.
*
* Excel Function:
* =NOT(logical)
*
* The argument must evaluate to a logical value such as TRUE or FALSE
*
* Boolean arguments are treated as True or False as appropriate
* Integer or floating point arguments are treated as True, except for 0 or 0.0 which are False
* If any argument value is a string, or a Null, the function returns a #VALUE! error, unless the string holds
* the value TRUE or FALSE, in which case it is evaluated as the corresponding boolean value
*
* @access public
* @category Logical Functions
* @param mixed $logical A value or expression that can be evaluated to TRUE or FALSE
* @return boolean The boolean inverse of the argument.
*/
public static function NOT($logical) {
$logical = PHPExcel_Calculation_Functions::flattenSingleValue($logical);
if (is_string($logical)) {
$logical = strtoupper($logical);
if (($logical == 'TRUE') || ($logical == PHPExcel_Calculation::getTRUE())) {
return false;
} elseif (($logical == 'FALSE') || ($logical == PHPExcel_Calculation::getFALSE())) {
return true;
} else {
return PHPExcel_Calculation_Functions::VALUE();
}
}
return !$logical;
} // function NOT()
/**
* STATEMENT_IF
*
* Returns one value if a condition you specify evaluates to TRUE and another value if it evaluates to FALSE.
*
* Excel Function:
* =IF(condition[,returnIfTrue[,returnIfFalse]])
*
* Condition is any value or expression that can be evaluated to TRUE or FALSE.
* For example, A10=100 is a logical expression; if the value in cell A10 is equal to 100,
* the expression evaluates to TRUE. Otherwise, the expression evaluates to FALSE.
* This argument can use any comparison calculation operator.
* ReturnIfTrue is the value that is returned if condition evaluates to TRUE.
* For example, if this argument is the text string "Within budget" and the condition argument evaluates to TRUE,
* then the IF function returns the text "Within budget"
* If condition is TRUE and ReturnIfTrue is blank, this argument returns 0 (zero). To display the word TRUE, use
* the logical value TRUE for this argument.
* ReturnIfTrue can be another formula.
* ReturnIfFalse is the value that is returned if condition evaluates to FALSE.
* For example, if this argument is the text string "Over budget" and the condition argument evaluates to FALSE,
* then the IF function returns the text "Over budget".
* If condition is FALSE and ReturnIfFalse is omitted, then the logical value FALSE is returned.
* If condition is FALSE and ReturnIfFalse is blank, then the value 0 (zero) is returned.
* ReturnIfFalse can be another formula.
*
* @access public
* @category Logical Functions
* @param mixed $condition Condition to evaluate
* @param mixed $returnIfTrue Value to return when condition is true
* @param mixed $returnIfFalse Optional value to return when condition is false
* @return mixed The value of returnIfTrue or returnIfFalse determined by condition
*/
public static function STATEMENT_IF($condition = true, $returnIfTrue = 0, $returnIfFalse = False) {
$condition = (is_null($condition)) ? True : (boolean) PHPExcel_Calculation_Functions::flattenSingleValue($condition);
$returnIfTrue = (is_null($returnIfTrue)) ? 0 : PHPExcel_Calculation_Functions::flattenSingleValue($returnIfTrue);
$returnIfFalse = (is_null($returnIfFalse)) ? False : PHPExcel_Calculation_Functions::flattenSingleValue($returnIfFalse);
return ($condition ? $returnIfTrue : $returnIfFalse);
} // function STATEMENT_IF()
/**
* IFERROR
*
* Excel Function:
* =IFERROR(testValue,errorpart)
*
* @access public
* @category Logical Functions
* @param mixed $testValue Value to check, is also the value returned when no error
* @param mixed $errorpart Value to return when testValue is an error condition
* @return mixed The value of errorpart or testValue determined by error condition
*/
public static function IFERROR($testValue = '', $errorpart = '') {
$testValue = (is_null($testValue)) ? '' : PHPExcel_Calculation_Functions::flattenSingleValue($testValue);
$errorpart = (is_null($errorpart)) ? '' : PHPExcel_Calculation_Functions::flattenSingleValue($errorpart);
return self::STATEMENT_IF(PHPExcel_Calculation_Functions::IS_ERROR($testValue), $errorpart, $testValue);
} // function IFERROR()
} // class PHPExcel_Calculation_Logical

View File

@@ -0,0 +1,746 @@
<?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_Calculation
* @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 1.7.6, 2011-02-27
*/
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
}
/**
* PHPExcel_Calculation_LookupRef
*
* @category PHPExcel
* @package PHPExcel_Calculation
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Calculation_LookupRef {
/**
* CELL_ADDRESS
*
* Creates a cell address as text, given specified row and column numbers.
*
* @param row Row number to use in the cell reference
* @param column Column number to use in the cell reference
* @param relativity Flag indicating the type of reference to return
* 1 or omitted Absolute
* 2 Absolute row; relative column
* 3 Relative row; absolute column
* 4 Relative
* @param referenceStyle A logical value that specifies the A1 or R1C1 reference style.
* TRUE or omitted CELL_ADDRESS returns an A1-style reference
* FALSE CELL_ADDRESS returns an R1C1-style reference
* @param sheetText Optional Name of worksheet to use
* @return string
*/
public static function CELL_ADDRESS($row, $column, $relativity=1, $referenceStyle=True, $sheetText='') {
$row = PHPExcel_Calculation_Functions::flattenSingleValue($row);
$column = PHPExcel_Calculation_Functions::flattenSingleValue($column);
$relativity = PHPExcel_Calculation_Functions::flattenSingleValue($relativity);
$sheetText = PHPExcel_Calculation_Functions::flattenSingleValue($sheetText);
if (($row < 1) || ($column < 1)) {
return PHPExcel_Calculation_Functions::VALUE();
}
if ($sheetText > '') {
if (strpos($sheetText,' ') !== False) { $sheetText = "'".$sheetText."'"; }
$sheetText .='!';
}
if ((!is_bool($referenceStyle)) || $referenceStyle) {
$rowRelative = $columnRelative = '$';
$column = PHPExcel_Cell::stringFromColumnIndex($column-1);
if (($relativity == 2) || ($relativity == 4)) { $columnRelative = ''; }
if (($relativity == 3) || ($relativity == 4)) { $rowRelative = ''; }
return $sheetText.$columnRelative.$column.$rowRelative.$row;
} else {
if (($relativity == 2) || ($relativity == 4)) { $column = '['.$column.']'; }
if (($relativity == 3) || ($relativity == 4)) { $row = '['.$row.']'; }
return $sheetText.'R'.$row.'C'.$column;
}
} // function CELL_ADDRESS()
/**
* COLUMN
*
* Returns the column number of the given cell reference
* If the cell reference is a range of cells, COLUMN returns the column numbers of each column in the reference as a horizontal array.
* If cell reference is omitted, and the function is being called through the calculation engine, then it is assumed to be the
* reference of the cell in which the COLUMN function appears; otherwise this function returns 0.
*
* @param cellAddress A reference to a range of cells for which you want the column numbers
* @return integer or array of integer
*/
public static function COLUMN($cellAddress=Null) {
if (is_null($cellAddress) || trim($cellAddress) === '') { return 0; }
if (is_array($cellAddress)) {
foreach($cellAddress as $columnKey => $value) {
$columnKey = preg_replace('/[^a-z]/i','',$columnKey);
return (integer) PHPExcel_Cell::columnIndexFromString($columnKey);
}
} else {
if (strpos($cellAddress,'!') !== false) {
list($sheet,$cellAddress) = explode('!',$cellAddress);
}
if (strpos($cellAddress,':') !== false) {
list($startAddress,$endAddress) = explode(':',$cellAddress);
$startAddress = preg_replace('/[^a-z]/i','',$startAddress);
$endAddress = preg_replace('/[^a-z]/i','',$endAddress);
$returnValue = array();
do {
$returnValue[] = (integer) PHPExcel_Cell::columnIndexFromString($startAddress);
} while ($startAddress++ != $endAddress);
return $returnValue;
} else {
$cellAddress = preg_replace('/[^a-z]/i','',$cellAddress);
return (integer) PHPExcel_Cell::columnIndexFromString($cellAddress);
}
}
} // function COLUMN()
/**
* COLUMNS
*
* Returns the number of columns in an array or reference.
*
* @param cellAddress An array or array formula, or a reference to a range of cells for which you want the number of columns
* @return integer
*/
public static function COLUMNS($cellAddress=Null) {
if (is_null($cellAddress) || $cellAddress === '') {
return 1;
} elseif (!is_array($cellAddress)) {
return PHPExcel_Calculation_Functions::VALUE();
}
$x = array_keys($cellAddress);
$x = array_shift($x);
$isMatrix = (is_numeric($x));
list($columns,$rows) = PHPExcel_Calculation::_getMatrixDimensions($cellAddress);
if ($isMatrix) {
return $rows;
} else {
return $columns;
}
} // function COLUMNS()
/**
* ROW
*
* Returns the row number of the given cell reference
* If the cell reference is a range of cells, ROW returns the row numbers of each row in the reference as a vertical array.
* If cell reference is omitted, and the function is being called through the calculation engine, then it is assumed to be the
* reference of the cell in which the ROW function appears; otherwise this function returns 0.
*
* @param cellAddress A reference to a range of cells for which you want the row numbers
* @return integer or array of integer
*/
public static function ROW($cellAddress=Null) {
if (is_null($cellAddress) || trim($cellAddress) === '') { return 0; }
if (is_array($cellAddress)) {
foreach($cellAddress as $columnKey => $rowValue) {
foreach($rowValue as $rowKey => $cellValue) {
return (integer) preg_replace('/[^0-9]/i','',$rowKey);
}
}
} else {
if (strpos($cellAddress,'!') !== false) {
list($sheet,$cellAddress) = explode('!',$cellAddress);
}
if (strpos($cellAddress,':') !== false) {
list($startAddress,$endAddress) = explode(':',$cellAddress);
$startAddress = preg_replace('/[^0-9]/','',$startAddress);
$endAddress = preg_replace('/[^0-9]/','',$endAddress);
$returnValue = array();
do {
$returnValue[][] = (integer) $startAddress;
} while ($startAddress++ != $endAddress);
return $returnValue;
} else {
list($cellAddress) = explode(':',$cellAddress);
return (integer) preg_replace('/[^0-9]/','',$cellAddress);
}
}
} // function ROW()
/**
* ROWS
*
* Returns the number of rows in an array or reference.
*
* @param cellAddress An array or array formula, or a reference to a range of cells for which you want the number of rows
* @return integer
*/
public static function ROWS($cellAddress=Null) {
if (is_null($cellAddress) || $cellAddress === '') {
return 1;
} elseif (!is_array($cellAddress)) {
return PHPExcel_Calculation_Functions::VALUE();
}
$i = array_keys($cellAddress);
$isMatrix = (is_numeric(array_shift($i)));
list($columns,$rows) = PHPExcel_Calculation::_getMatrixDimensions($cellAddress);
if ($isMatrix) {
return $columns;
} else {
return $rows;
}
} // function ROWS()
/**
* HYPERLINK
*
* Excel Function:
* =HYPERLINK(linkURL,displayName)
*
* @access public
* @category Logical Functions
* @param string $linkURL Value to check, is also the value returned when no error
* @param string $displayName Value to return when testValue is an error condition
* @return mixed The value of errorpart or testValue determined by error condition
*/
public static function HYPERLINK($linkURL = '', $displayName = null, PHPExcel_Cell $pCell = null) {
$args = func_get_args();
$pCell = array_pop($args);
$linkURL = (is_null($linkURL)) ? '' : PHPExcel_Calculation_Functions::flattenSingleValue($linkURL);
$displayName = (is_null($displayName)) ? '' : PHPExcel_Calculation_Functions::flattenSingleValue($displayName);
if ((!is_object($pCell)) || (trim($linkURL) == '')) {
return PHPExcel_Calculation_Functions::REF();
}
if ((is_object($displayName)) || trim($displayName) == '') {
$displayName = $linkURL;
}
$pCell->getHyperlink()->setUrl($linkURL);
return $displayName;
} // function HYPERLINK()
/**
* INDIRECT
*
* Returns the number of rows in an array or reference.
*
* @param cellAddress An array or array formula, or a reference to a range of cells for which you want the number of rows
* @return integer
*/
public static function INDIRECT($cellAddress=Null, PHPExcel_Cell $pCell = null) {
$cellAddress = PHPExcel_Calculation_Functions::flattenSingleValue($cellAddress);
if (is_null($cellAddress) || $cellAddress === '') {
return PHPExcel_Calculation_Functions::REF();
}
$cellAddress1 = $cellAddress;
$cellAddress2 = NULL;
if (strpos($cellAddress,':') !== false) {
list($cellAddress1,$cellAddress2) = explode(':',$cellAddress);
}
if ((!preg_match('/^'.PHPExcel_Calculation::CALCULATION_REGEXP_CELLREF.'$/i', $cellAddress1, $matches)) ||
((!is_null($cellAddress2)) && (!preg_match('/^'.PHPExcel_Calculation::CALCULATION_REGEXP_CELLREF.'$/i', $cellAddress2, $matches)))) {
return PHPExcel_Calculation_Functions::REF();
}
if (strpos($cellAddress,'!') !== false) {
list($sheetName,$cellAddress) = explode('!',$cellAddress);
$pSheet = $pCell->getParent()->getParent()->getSheetByName($sheetName);
} else {
$pSheet = $pCell->getParent();
}
return PHPExcel_Calculation::getInstance()->extractCellRange($cellAddress, $pSheet, False);
} // function INDIRECT()
/**
* OFFSET
*
* Returns a reference to a range that is a specified number of rows and columns from a cell or range of cells.
* The reference that is returned can be a single cell or a range of cells. You can specify the number of rows and
* the number of columns to be returned.
*
* @param cellAddress The reference from which you want to base the offset. Reference must refer to a cell or
* range of adjacent cells; otherwise, OFFSET returns the #VALUE! error value.
* @param rows The number of rows, up or down, that you want the upper-left cell to refer to.
* Using 5 as the rows argument specifies that the upper-left cell in the reference is
* five rows below reference. Rows can be positive (which means below the starting reference)
* or negative (which means above the starting reference).
* @param cols The number of columns, to the left or right, that you want the upper-left cell of the result
* to refer to. Using 5 as the cols argument specifies that the upper-left cell in the
* reference is five columns to the right of reference. Cols can be positive (which means
* to the right of the starting reference) or negative (which means to the left of the
* starting reference).
* @param height The height, in number of rows, that you want the returned reference to be. Height must be a positive number.
* @param width The width, in number of columns, that you want the returned reference to be. Width must be a positive number.
* @return string A reference to a cell or range of cells
*/
public static function OFFSET($cellAddress=Null,$rows=0,$columns=0,$height=null,$width=null) {
$rows = PHPExcel_Calculation_Functions::flattenSingleValue($rows);
$columns = PHPExcel_Calculation_Functions::flattenSingleValue($columns);
$height = PHPExcel_Calculation_Functions::flattenSingleValue($height);
$width = PHPExcel_Calculation_Functions::flattenSingleValue($width);
if ($cellAddress == Null) {
return 0;
}
$args = func_get_args();
$pCell = array_pop($args);
if (!is_object($pCell)) {
return PHPExcel_Calculation_Functions::REF();
}
$sheetName = null;
if (strpos($cellAddress,"!")) {
list($sheetName,$cellAddress) = explode("!",$cellAddress);
}
if (strpos($cellAddress,":")) {
list($startCell,$endCell) = explode(":",$cellAddress);
} else {
$startCell = $endCell = $cellAddress;
}
list($startCellColumn,$startCellRow) = PHPExcel_Cell::coordinateFromString($startCell);
list($endCellColumn,$endCellRow) = PHPExcel_Cell::coordinateFromString($endCell);
$startCellRow += $rows;
$startCellColumn = PHPExcel_Cell::columnIndexFromString($startCellColumn) - 1;
$startCellColumn += $columns;
if (($startCellRow <= 0) || ($startCellColumn < 0)) {
return PHPExcel_Calculation_Functions::REF();
}
$endCellColumn = PHPExcel_Cell::columnIndexFromString($endCellColumn) - 1;
if (($width != null) && (!is_object($width))) {
$endCellColumn = $startCellColumn + $width - 1;
} else {
$endCellColumn += $columns;
}
$startCellColumn = PHPExcel_Cell::stringFromColumnIndex($startCellColumn);
if (($height != null) && (!is_object($height))) {
$endCellRow = $startCellRow + $height - 1;
} else {
$endCellRow += $rows;
}
if (($endCellRow <= 0) || ($endCellColumn < 0)) {
return PHPExcel_Calculation_Functions::REF();
}
$endCellColumn = PHPExcel_Cell::stringFromColumnIndex($endCellColumn);
$cellAddress = $startCellColumn.$startCellRow;
if (($startCellColumn != $endCellColumn) || ($startCellRow != $endCellRow)) {
$cellAddress .= ':'.$endCellColumn.$endCellRow;
}
if ($sheetName !== null) {
$pSheet = $pCell->getParent()->getParent()->getSheetByName($sheetName);
} else {
$pSheet = $pCell->getParent();
}
return PHPExcel_Calculation::getInstance()->extractCellRange($cellAddress, $pSheet, False);
} // function OFFSET()
public static function CHOOSE() {
$chooseArgs = func_get_args();
$chosenEntry = PHPExcel_Calculation_Functions::flattenArray(array_shift($chooseArgs));
$entryCount = count($chooseArgs) - 1;
if(is_array($chosenEntry)) {
$chosenEntry = array_shift($chosenEntry);
}
if ((is_numeric($chosenEntry)) && (!is_bool($chosenEntry))) {
--$chosenEntry;
} else {
return PHPExcel_Calculation_Functions::VALUE();
}
$chosenEntry = floor($chosenEntry);
if (($chosenEntry <= 0) || ($chosenEntry > $entryCount)) {
return PHPExcel_Calculation_Functions::VALUE();
}
if (is_array($chooseArgs[$chosenEntry])) {
return PHPExcel_Calculation_Functions::flattenArray($chooseArgs[$chosenEntry]);
} else {
return $chooseArgs[$chosenEntry];
}
} // function CHOOSE()
/**
* MATCH
*
* The MATCH function searches for a specified item in a range of cells
*
* @param lookup_value The value that you want to match in lookup_array
* @param lookup_array The range of cells being searched
* @param match_type The number -1, 0, or 1. -1 means above, 0 means exact match, 1 means below. If match_type is 1 or -1, the list has to be ordered.
* @return integer The relative position of the found item
*/
public static function MATCH($lookup_value, $lookup_array, $match_type=1) {
$lookup_array = PHPExcel_Calculation_Functions::flattenArray($lookup_array);
$lookup_value = PHPExcel_Calculation_Functions::flattenSingleValue($lookup_value);
$match_type = (is_null($match_type)) ? 1 : (int) PHPExcel_Calculation_Functions::flattenSingleValue($match_type);
// MATCH is not case sensitive
$lookup_value = strtolower($lookup_value);
// lookup_value type has to be number, text, or logical values
if ((!is_numeric($lookup_value)) && (!is_string($lookup_value)) && (!is_bool($lookup_value))) {
return PHPExcel_Calculation_Functions::NA();
}
// match_type is 0, 1 or -1
if (($match_type !== 0) && ($match_type !== -1) && ($match_type !== 1)) {
return PHPExcel_Calculation_Functions::NA();
}
// lookup_array should not be empty
$lookupArraySize = count($lookup_array);
if ($lookupArraySize <= 0) {
return PHPExcel_Calculation_Functions::NA();
}
// lookup_array should contain only number, text, or logical values, or empty (null) cells
foreach($lookup_array as $i => $lookupArrayValue) {
// check the type of the value
if ((!is_numeric($lookupArrayValue)) && (!is_string($lookupArrayValue)) &&
(!is_bool($lookupArrayValue)) && (!is_null($lookupArrayValue))) {
return PHPExcel_Calculation_Functions::NA();
}
// convert strings to lowercase for case-insensitive testing
if (is_string($lookupArrayValue)) {
$lookup_array[$i] = strtolower($lookupArrayValue);
}
if ((is_null($lookupArrayValue)) && (($match_type == 1) || ($match_type == -1))) {
$lookup_array = array_slice($lookup_array,0,$i-1);
}
}
// if match_type is 1 or -1, the list has to be ordered
if ($match_type == 1) {
asort($lookup_array);
$keySet = array_keys($lookup_array);
} elseif($match_type == -1) {
arsort($lookup_array);
$keySet = array_keys($lookup_array);
}
// **
// find the match
// **
// loop on the cells
// var_dump($lookup_array);
// echo '<br />';
foreach($lookup_array as $i => $lookupArrayValue) {
if (($match_type == 0) && ($lookupArrayValue == $lookup_value)) {
// exact match
return ++$i;
} elseif (($match_type == -1) && ($lookupArrayValue <= $lookup_value)) {
// echo '$i = '.$i.' => ';
// var_dump($lookupArrayValue);
// echo '<br />';
// echo 'Keyset = ';
// var_dump($keySet);
// echo '<br />';
$i = array_search($i,$keySet);
// echo '$i='.$i.'<br />';
// if match_type is -1 <=> find the smallest value that is greater than or equal to lookup_value
if ($i < 1){
// 1st cell was allready smaller than the lookup_value
break;
} else {
// the previous cell was the match
return $keySet[$i-1]+1;
}
} elseif (($match_type == 1) && ($lookupArrayValue >= $lookup_value)) {
// echo '$i = '.$i.' => ';
// var_dump($lookupArrayValue);
// echo '<br />';
// echo 'Keyset = ';
// var_dump($keySet);
// echo '<br />';
$i = array_search($i,$keySet);
// echo '$i='.$i.'<br />';
// if match_type is 1 <=> find the largest value that is less than or equal to lookup_value
if ($i < 1){
// 1st cell was allready bigger than the lookup_value
break;
} else {
// the previous cell was the match
return $keySet[$i-1]+1;
}
}
}
// unsuccessful in finding a match, return #N/A error value
return PHPExcel_Calculation_Functions::NA();
} // function MATCH()
/**
* INDEX
*
* Uses an index to choose a value from a reference or array
* implemented: Return the value of a specified cell or array of cells Array form
* not implemented: Return a reference to specified cells Reference form
*
* @param range_array a range of cells or an array constant
* @param row_num selects the row in array from which to return a value. If row_num is omitted, column_num is required.
* @param column_num selects the column in array from which to return a value. If column_num is omitted, row_num is required.
*/
public static function INDEX($arrayValues,$rowNum = 0,$columnNum = 0) {
if (($rowNum < 0) || ($columnNum < 0)) {
return PHPExcel_Calculation_Functions::VALUE();
}
if (!is_array($arrayValues)) {
return PHPExcel_Calculation_Functions::REF();
}
$rowKeys = array_keys($arrayValues);
$columnKeys = @array_keys($arrayValues[$rowKeys[0]]);
if ($columnNum > count($columnKeys)) {
return PHPExcel_Calculation_Functions::VALUE();
} elseif ($columnNum == 0) {
if ($rowNum == 0) {
return $arrayValues;
}
$rowNum = $rowKeys[--$rowNum];
$returnArray = array();
foreach($arrayValues as $arrayColumn) {
if (is_array($arrayColumn)) {
if (isset($arrayColumn[$rowNum])) {
$returnArray[] = $arrayColumn[$rowNum];
} else {
return $arrayValues[$rowNum];
}
} else {
return $arrayValues[$rowNum];
}
}
return $returnArray;
}
$columnNum = $columnKeys[--$columnNum];
if ($rowNum > count($rowKeys)) {
return PHPExcel_Calculation_Functions::VALUE();
} elseif ($rowNum == 0) {
return $arrayValues[$columnNum];
}
$rowNum = $rowKeys[--$rowNum];
return $arrayValues[$rowNum][$columnNum];
} // function INDEX()
/**
* TRANSPOSE
*
* @param array $matrixData A matrix of values
* @return array
*
* Unlike the Excel TRANSPOSE function, which will only work on a single row or column, this function will transpose a full matrix.
*/
public static function TRANSPOSE($matrixData) {
$returnMatrix = array();
if (!is_array($matrixData)) { $matrixData = array(array($matrixData)); }
$column = 0;
foreach($matrixData as $matrixRow) {
$row = 0;
foreach($matrixRow as $matrixCell) {
$returnMatrix[$row][$column] = $matrixCell;
++$row;
}
++$column;
}
return $returnMatrix;
} // function TRANSPOSE()
private static function _vlookupSort($a,$b) {
$f = array_keys($a);
$firstColumn = array_shift($f);
if (strtolower($a[$firstColumn]) == strtolower($b[$firstColumn])) {
return 0;
}
return (strtolower($a[$firstColumn]) < strtolower($b[$firstColumn])) ? -1 : 1;
} // function _vlookupSort()
/**
* VLOOKUP
* The VLOOKUP function searches for value in the left-most column of lookup_array and returns the value in the same row based on the index_number.
* @param lookup_value The value that you want to match in lookup_array
* @param lookup_array The range of cells being searched
* @param index_number The column number in table_array from which the matching value must be returned. The first column is 1.
* @param not_exact_match Determines if you are looking for an exact match based on lookup_value.
* @return mixed The value of the found cell
*/
public static function VLOOKUP($lookup_value, $lookup_array, $index_number, $not_exact_match=true) {
$lookup_value = PHPExcel_Calculation_Functions::flattenSingleValue($lookup_value);
$index_number = PHPExcel_Calculation_Functions::flattenSingleValue($index_number);
$not_exact_match = PHPExcel_Calculation_Functions::flattenSingleValue($not_exact_match);
// index_number must be greater than or equal to 1
if ($index_number < 1) {
return PHPExcel_Calculation_Functions::VALUE();
}
// index_number must be less than or equal to the number of columns in lookup_array
if ((!is_array($lookup_array)) || (count($lookup_array) < 1)) {
return PHPExcel_Calculation_Functions::REF();
} else {
$f = array_keys($lookup_array);
$firstRow = array_pop($f);
if ((!is_array($lookup_array[$firstRow])) || ($index_number > count($lookup_array[$firstRow]))) {
return PHPExcel_Calculation_Functions::REF();
} else {
$columnKeys = array_keys($lookup_array[$firstRow]);
$returnColumn = $columnKeys[--$index_number];
$firstColumn = array_shift($columnKeys);
}
}
if (!$not_exact_match) {
uasort($lookup_array,array('self','_vlookupSort'));
}
$rowNumber = $rowValue = False;
foreach($lookup_array as $rowKey => $rowData) {
if (strtolower($rowData[$firstColumn]) > strtolower($lookup_value)) {
break;
}
$rowNumber = $rowKey;
$rowValue = $rowData[$firstColumn];
}
if ($rowNumber !== false) {
if ((!$not_exact_match) && ($rowValue != $lookup_value)) {
// if an exact match is required, we have what we need to return an appropriate response
return PHPExcel_Calculation_Functions::NA();
} else {
// otherwise return the appropriate value
return $lookup_array[$rowNumber][$returnColumn];
}
}
return PHPExcel_Calculation_Functions::NA();
} // function VLOOKUP()
/**
* LOOKUP
* The LOOKUP function searches for value either from a one-row or one-column range or from an array.
* @param lookup_value The value that you want to match in lookup_array
* @param lookup_vector The range of cells being searched
* @param result_vector The column from which the matching value must be returned
* @return mixed The value of the found cell
*/
public static function LOOKUP($lookup_value, $lookup_vector, $result_vector=null) {
$lookup_value = PHPExcel_Calculation_Functions::flattenSingleValue($lookup_value);
if (!is_array($lookup_vector)) {
return PHPExcel_Calculation_Functions::NA();
}
$lookupRows = count($lookup_vector);
$l = array_keys($lookup_vector);
$l = array_shift($l);
$lookupColumns = count($lookup_vector[$l]);
if ((($lookupRows == 1) && ($lookupColumns > 1)) || (($lookupRows == 2) && ($lookupColumns != 2))) {
$lookup_vector = self::TRANSPOSE($lookup_vector);
$lookupRows = count($lookup_vector);
$l = array_keys($lookup_vector);
$lookupColumns = count($lookup_vector[array_shift($l)]);
}
if (is_null($result_vector)) {
$result_vector = $lookup_vector;
}
$resultRows = count($result_vector);
$l = array_keys($result_vector);
$l = array_shift($l);
$resultColumns = count($result_vector[$l]);
if ((($resultRows == 1) && ($resultColumns > 1)) || (($resultRows == 2) && ($resultColumns != 2))) {
$result_vector = self::TRANSPOSE($result_vector);
$resultRows = count($result_vector);
$r = array_keys($result_vector);
$resultColumns = count($result_vector[array_shift($r)]);
}
if ($lookupRows == 2) {
$result_vector = array_pop($lookup_vector);
$lookup_vector = array_shift($lookup_vector);
}
if ($lookupColumns != 2) {
foreach($lookup_vector as &$value) {
if (is_array($value)) {
$k = array_keys($value);
$key1 = $key2 = array_shift($k);
$key2++;
$dataValue1 = $value[$key1];
} else {
$key1 = 0;
$key2 = 1;
$dataValue1 = $value;
}
$dataValue2 = array_shift($result_vector);
if (is_array($dataValue2)) {
$dataValue2 = array_shift($dataValue2);
}
$value = array($key1 => $dataValue1, $key2 => $dataValue2);
}
unset($value);
}
return self::VLOOKUP($lookup_value,$lookup_vector,2);
} // function LOOKUP()
} // class PHPExcel_Calculation_LookupRef

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,588 @@
<?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_Calculation
* @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 1.7.6, 2011-02-27
*/
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
}
/**
* PHPExcel_Calculation_TextData
*
* @category PHPExcel
* @package PHPExcel_Calculation
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Calculation_TextData {
private static $_invalidChars = Null;
private static function _uniord($c) {
if (ord($c{0}) >=0 && ord($c{0}) <= 127)
return ord($c{0});
if (ord($c{0}) >= 192 && ord($c{0}) <= 223)
return (ord($c{0})-192)*64 + (ord($c{1})-128);
if (ord($c{0}) >= 224 && ord($c{0}) <= 239)
return (ord($c{0})-224)*4096 + (ord($c{1})-128)*64 + (ord($c{2})-128);
if (ord($c{0}) >= 240 && ord($c{0}) <= 247)
return (ord($c{0})-240)*262144 + (ord($c{1})-128)*4096 + (ord($c{2})-128)*64 + (ord($c{3})-128);
if (ord($c{0}) >= 248 && ord($c{0}) <= 251)
return (ord($c{0})-248)*16777216 + (ord($c{1})-128)*262144 + (ord($c{2})-128)*4096 + (ord($c{3})-128)*64 + (ord($c{4})-128);
if (ord($c{0}) >= 252 && ord($c{0}) <= 253)
return (ord($c{0})-252)*1073741824 + (ord($c{1})-128)*16777216 + (ord($c{2})-128)*262144 + (ord($c{3})-128)*4096 + (ord($c{4})-128)*64 + (ord($c{5})-128);
if (ord($c{0}) >= 254 && ord($c{0}) <= 255) //error
return PHPExcel_Calculation_Functions::VALUE();
return 0;
} // function _uniord()
/**
* CHARACTER
*
* @param string $character Value
* @return int
*/
public static function CHARACTER($character) {
$character = PHPExcel_Calculation_Functions::flattenSingleValue($character);
if ((!is_numeric($character)) || ($character < 0)) {
return PHPExcel_Calculation_Functions::VALUE();
}
if (function_exists('mb_convert_encoding')) {
return mb_convert_encoding('&#'.intval($character).';', 'UTF-8', 'HTML-ENTITIES');
} else {
return chr(intval($character));
}
}
/**
* TRIMNONPRINTABLE
*
* @param mixed $value Value to check
* @return string
*/
public static function TRIMNONPRINTABLE($stringValue = '') {
$stringValue = PHPExcel_Calculation_Functions::flattenSingleValue($stringValue);
if (is_bool($stringValue)) {
$stringValue = ($stringValue) ? 'TRUE' : 'FALSE';
}
if (self::$_invalidChars == Null) {
self::$_invalidChars = range(chr(0),chr(31));
}
if (is_string($stringValue) || is_numeric($stringValue)) {
return str_replace(self::$_invalidChars,'',trim($stringValue,"\x00..\x1F"));
}
return Null;
} // function TRIMNONPRINTABLE()
/**
* TRIMSPACES
*
* @param mixed $value Value to check
* @return string
*/
public static function TRIMSPACES($stringValue = '') {
$stringValue = PHPExcel_Calculation_Functions::flattenSingleValue($stringValue);
if (is_string($stringValue) || is_numeric($stringValue)) {
return trim(preg_replace('/ +/',' ',$stringValue));
}
return Null;
} // function TRIMSPACES()
/**
* ASCIICODE
*
* @param string $character Value
* @return int
*/
public static function ASCIICODE($characters) {
$characters = PHPExcel_Calculation_Functions::flattenSingleValue($characters);
if (is_bool($characters)) {
if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) {
$characters = (int) $characters;
} else {
if ($characters) {
$characters = 'True';
} else {
$characters = 'False';
}
}
}
$character = $characters;
if ((function_exists('mb_strlen')) && (function_exists('mb_substr'))) {
if (mb_strlen($characters, 'UTF-8') > 1) { $character = mb_substr($characters, 0, 1, 'UTF-8'); }
return self::_uniord($character);
} else {
if (strlen($characters) > 0) { $character = substr($characters, 0, 1); }
return ord($character);
}
} // function ASCIICODE()
/**
* CONCATENATE
*
* @return string
*/
public static function CONCATENATE() {
// Return value
$returnValue = '';
// Loop through arguments
$aArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args());
foreach ($aArgs as $arg) {
if (is_bool($arg)) {
if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) {
$arg = (int) $arg;
} else {
if ($arg) {
$arg = 'TRUE';
} else {
$arg = 'FALSE';
}
}
}
$returnValue .= $arg;
}
// Return
return $returnValue;
} // function CONCATENATE()
/**
* DOLLAR
*
* This function converts a number to text using currency format, with the decimals rounded to the specified place.
* The format used is $#,##0.00_);($#,##0.00)..
*
* @param float $value The value to format
* @param int $decimals The number of digits to display to the right of the decimal point.
* If decimals is negative, number is rounded to the left of the decimal point.
* If you omit decimals, it is assumed to be 2
* @return string
*/
public static function DOLLAR($value = 0, $decimals = 2) {
$value = PHPExcel_Calculation_Functions::flattenSingleValue($value);
$decimals = is_null($decimals) ? 0 : PHPExcel_Calculation_Functions::flattenSingleValue($decimals);
// Validate parameters
if (!is_numeric($value) || !is_numeric($decimals)) {
return PHPExcel_Calculation_Functions::NaN();
}
$decimals = floor($decimals);
if ($decimals > 0) {
return money_format('%.'.$decimals.'n',$value);
} else {
$round = pow(10,abs($decimals));
if ($value < 0) { $round = 0-$round; }
$value = PHPExcel_Calculation_MathTrig::MROUND($value,$round);
// The implementation of money_format used if the standard PHP function is not available can't handle decimal places of 0,
// so we display to 1 dp and chop off that character and the decimal separator using substr
return substr(money_format('%.1n',$value),0,-2);
}
} // function DOLLAR()
/**
* SEARCHSENSITIVE
*
* @param string $needle The string to look for
* @param string $haystack The string in which to look
* @param int $offset Offset within $haystack
* @return string
*/
public static function SEARCHSENSITIVE($needle,$haystack,$offset=1) {
$needle = PHPExcel_Calculation_Functions::flattenSingleValue($needle);
$haystack = PHPExcel_Calculation_Functions::flattenSingleValue($haystack);
$offset = PHPExcel_Calculation_Functions::flattenSingleValue($offset);
if (!is_bool($needle)) {
if (is_bool($haystack)) {
$haystack = ($haystack) ? 'TRUE' : 'FALSE';
}
if (($offset > 0) && (strlen($haystack) > $offset)) {
if (function_exists('mb_strpos')) {
$pos = mb_strpos($haystack, $needle, --$offset,'UTF-8');
} else {
$pos = strpos($haystack, $needle, --$offset);
}
if ($pos !== false) {
return ++$pos;
}
}
}
return PHPExcel_Calculation_Functions::VALUE();
} // function SEARCHSENSITIVE()
/**
* SEARCHINSENSITIVE
*
* @param string $needle The string to look for
* @param string $haystack The string in which to look
* @param int $offset Offset within $haystack
* @return string
*/
public static function SEARCHINSENSITIVE($needle,$haystack,$offset=1) {
$needle = PHPExcel_Calculation_Functions::flattenSingleValue($needle);
$haystack = PHPExcel_Calculation_Functions::flattenSingleValue($haystack);
$offset = PHPExcel_Calculation_Functions::flattenSingleValue($offset);
if (!is_bool($needle)) {
if (is_bool($haystack)) {
$haystack = ($haystack) ? 'TRUE' : 'FALSE';
}
if (($offset > 0) && (strlen($haystack) > $offset)) {
if (function_exists('mb_stripos')) {
$pos = mb_stripos($haystack, $needle, --$offset,'UTF-8');
} else {
$pos = stripos($haystack, $needle, --$offset);
}
if ($pos !== false) {
return ++$pos;
}
}
}
return PHPExcel_Calculation_Functions::VALUE();
} // function SEARCHINSENSITIVE()
/**
* FIXEDFORMAT
*
* @param mixed $value Value to check
* @return boolean
*/
public static function FIXEDFORMAT($value,$decimals=2,$no_commas=false) {
$value = PHPExcel_Calculation_Functions::flattenSingleValue($value);
$decimals = PHPExcel_Calculation_Functions::flattenSingleValue($decimals);
$no_commas = PHPExcel_Calculation_Functions::flattenSingleValue($no_commas);
$valueResult = round($value,$decimals);
if ($decimals < 0) { $decimals = 0; }
if (!$no_commas) {
$valueResult = number_format($valueResult,$decimals);
}
return (string) $valueResult;
} // function FIXEDFORMAT()
/**
* LEFT
*
* @param string $value Value
* @param int $chars Number of characters
* @return string
*/
public static function LEFT($value = '', $chars = 1) {
$value = PHPExcel_Calculation_Functions::flattenSingleValue($value);
$chars = PHPExcel_Calculation_Functions::flattenSingleValue($chars);
if ($chars < 0) {
return PHPExcel_Calculation_Functions::VALUE();
}
if (is_bool($value)) {
$value = ($value) ? 'TRUE' : 'FALSE';
}
if (function_exists('mb_substr')) {
return mb_substr($value, 0, $chars, 'UTF-8');
} else {
return substr($value, 0, $chars);
}
} // function LEFT()
/**
* MID
*
* @param string $value Value
* @param int $start Start character
* @param int $chars Number of characters
* @return string
*/
public static function MID($value = '', $start = 1, $chars = null) {
$value = PHPExcel_Calculation_Functions::flattenSingleValue($value);
$start = PHPExcel_Calculation_Functions::flattenSingleValue($start);
$chars = PHPExcel_Calculation_Functions::flattenSingleValue($chars);
if (($start < 1) || ($chars < 0)) {
return PHPExcel_Calculation_Functions::VALUE();
}
if (is_bool($value)) {
$value = ($value) ? 'TRUE' : 'FALSE';
}
if (function_exists('mb_substr')) {
return mb_substr($value, --$start, $chars, 'UTF-8');
} else {
return substr($value, --$start, $chars);
}
} // function MID()
/**
* RIGHT
*
* @param string $value Value
* @param int $chars Number of characters
* @return string
*/
public static function RIGHT($value = '', $chars = 1) {
$value = PHPExcel_Calculation_Functions::flattenSingleValue($value);
$chars = PHPExcel_Calculation_Functions::flattenSingleValue($chars);
if ($chars < 0) {
return PHPExcel_Calculation_Functions::VALUE();
}
if (is_bool($value)) {
$value = ($value) ? 'TRUE' : 'FALSE';
}
if ((function_exists('mb_substr')) && (function_exists('mb_strlen'))) {
return mb_substr($value, mb_strlen($value, 'UTF-8') - $chars, $chars, 'UTF-8');
} else {
return substr($value, strlen($value) - $chars);
}
} // function RIGHT()
/**
* STRINGLENGTH
*
* @param string $value Value
* @param int $chars Number of characters
* @return string
*/
public static function STRINGLENGTH($value = '') {
$value = PHPExcel_Calculation_Functions::flattenSingleValue($value);
if (is_bool($value)) {
$value = ($value) ? 'TRUE' : 'FALSE';
}
if (function_exists('mb_strlen')) {
return mb_strlen($value, 'UTF-8');
} else {
return strlen($value);
}
} // function STRINGLENGTH()
/**
* LOWERCASE
*
* Converts a string value to upper case.
*
* @param string $mixedCaseString
* @return string
*/
public static function LOWERCASE($mixedCaseString) {
$mixedCaseString = PHPExcel_Calculation_Functions::flattenSingleValue($mixedCaseString);
if (is_bool($mixedCaseString)) {
$mixedCaseString = ($mixedCaseString) ? 'TRUE' : 'FALSE';
}
if (function_exists('mb_convert_case')) {
return mb_convert_case($mixedCaseString, MB_CASE_LOWER, 'UTF-8');
} else {
return strtoupper($mixedCaseString);
}
} // function LOWERCASE()
/**
* UPPERCASE
*
* Converts a string value to upper case.
*
* @param string $mixedCaseString
* @return string
*/
public static function UPPERCASE($mixedCaseString) {
$mixedCaseString = PHPExcel_Calculation_Functions::flattenSingleValue($mixedCaseString);
if (is_bool($mixedCaseString)) {
$mixedCaseString = ($mixedCaseString) ? 'TRUE' : 'FALSE';
}
if (function_exists('mb_convert_case')) {
return mb_convert_case($mixedCaseString, MB_CASE_UPPER, 'UTF-8');
} else {
return strtoupper($mixedCaseString);
}
} // function UPPERCASE()
/**
* PROPERCASE
*
* Converts a string value to upper case.
*
* @param string $mixedCaseString
* @return string
*/
public static function PROPERCASE($mixedCaseString) {
$mixedCaseString = PHPExcel_Calculation_Functions::flattenSingleValue($mixedCaseString);
if (is_bool($mixedCaseString)) {
$mixedCaseString = ($mixedCaseString) ? 'TRUE' : 'FALSE';
}
if (function_exists('mb_convert_case')) {
return mb_convert_case($mixedCaseString, MB_CASE_TITLE, 'UTF-8');
} else {
return ucwords($mixedCaseString);
}
} // function PROPERCASE()
/**
* REPLACE
*
* @param string $value Value
* @param int $start Start character
* @param int $chars Number of characters
* @return string
*/
public static function REPLACE($oldText = '', $start = 1, $chars = null, $newText) {
$oldText = PHPExcel_Calculation_Functions::flattenSingleValue($oldText);
$start = PHPExcel_Calculation_Functions::flattenSingleValue($start);
$chars = PHPExcel_Calculation_Functions::flattenSingleValue($chars);
$newText = PHPExcel_Calculation_Functions::flattenSingleValue($newText);
$left = self::LEFT($oldText,$start-1);
$right = self::RIGHT($oldText,self::STRINGLENGTH($oldText)-($start+$chars)+1);
return $left.$newText.$right;
} // function REPLACE()
/**
* SUBSTITUTE
*
* @param string $text Value
* @param string $fromText From Value
* @param string $toText To Value
* @param integer $instance Instance Number
* @return string
*/
public static function SUBSTITUTE($text = '', $fromText = '', $toText = '', $instance = 0) {
$text = PHPExcel_Calculation_Functions::flattenSingleValue($text);
$fromText = PHPExcel_Calculation_Functions::flattenSingleValue($fromText);
$toText = PHPExcel_Calculation_Functions::flattenSingleValue($toText);
$instance = floor(PHPExcel_Calculation_Functions::flattenSingleValue($instance));
if ($instance == 0) {
if(function_exists('mb_str_replace')) {
return mb_str_replace($fromText,$toText,$text);
} else {
return str_replace($fromText,$toText,$text);
}
} else {
$pos = -1;
while($instance > 0) {
if (function_exists('mb_strpos')) {
$pos = mb_strpos($text, $fromText, $pos+1, 'UTF-8');
} else {
$pos = strpos($text, $fromText, $pos+1);
}
if ($pos === false) {
break;
}
--$instance;
}
if ($pos !== false) {
if (function_exists('mb_strlen')) {
return self::REPLACE($text,++$pos,mb_strlen($fromText, 'UTF-8'),$toText);
} else {
return self::REPLACE($text,++$pos,strlen($fromText),$toText);
}
}
}
return $left.$newText.$right;
} // function SUBSTITUTE()
/**
* RETURNSTRING
*
* @param mixed $value Value to check
* @return boolean
*/
public static function RETURNSTRING($testValue = '') {
$testValue = PHPExcel_Calculation_Functions::flattenSingleValue($testValue);
if (is_string($testValue)) {
return $testValue;
}
return Null;
} // function RETURNSTRING()
/**
* TEXTFORMAT
*
* @param mixed $value Value to check
* @return boolean
*/
public static function TEXTFORMAT($value,$format) {
$value = PHPExcel_Calculation_Functions::flattenSingleValue($value);
$format = PHPExcel_Calculation_Functions::flattenSingleValue($format);
if ((is_string($value)) && (!is_numeric($value)) && PHPExcel_Shared_Date::isDateTimeFormatCode($format)) {
$value = PHPExcel_Calculation_DateTime::DATEVALUE($value);
}
return (string) PHPExcel_Style_NumberFormat::toFormattedString($value,$format);
} // function TEXTFORMAT()
} // class PHPExcel_Calculation_TextData

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Cell
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
@@ -31,7 +31,7 @@
*
* @category PHPExcel
* @package PHPExcel_Cell
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Cell
{
@@ -140,7 +140,9 @@ class PHPExcel_Cell
$this->_parent = $pSheet;
// Set datatype?
if (!is_null($pDataType)) {
if ($pDataType !== null) {
if ($pDataType == PHPExcel_Cell_DataType::TYPE_STRING2)
$pDataType = PHPExcel_Cell_DataType::TYPE_STRING;
$this->_dataType = $pDataType;
} else {
if (!self::getValueBinder()->bindValue($this, $pValue)) {
@@ -192,6 +194,18 @@ class PHPExcel_Cell
return $this->_value;
}
/**
* Get cell value with formatting
*
* @return string
*/
public function getFormattedValue()
{
return PHPExcel_Style_NumberFormat::toFormattedString( $this->getCalculatedValue(),
$this->_parent->getParent()->getCellXfByIndex($this->getXfIndex())->getNumberFormat()->getFormatCode()
);
}
/**
* Set cell value
*
@@ -220,6 +234,8 @@ class PHPExcel_Cell
{
// set the value according to data type
switch ($pDataType) {
case PHPExcel_Cell_DataType::TYPE_STRING2:
$pDataType = PHPExcel_Cell_DataType::TYPE_STRING;
case PHPExcel_Cell_DataType::TYPE_STRING:
case PHPExcel_Cell_DataType::TYPE_NULL:
case PHPExcel_Cell_DataType::TYPE_INLINE:
@@ -280,10 +296,10 @@ class PHPExcel_Cell
return $result;
}
if (is_null($this->_value)) {
// if (is_null($this->_value)) {
// echo 'Cell '.$this->getCoordinate().' has no value, formula or otherwise<br />';
return null;
}
// return null;
// }
// echo 'Cell value for '.$this->getCoordinate().' is not a formula: Returning data value of '.$this->_value.'<br />';
return $this->_value;
}
@@ -331,6 +347,9 @@ class PHPExcel_Cell
*/
public function setDataType($pDataType = PHPExcel_Cell_DataType::TYPE_STRING)
{
if ($pDataType == PHPExcel_Cell_DataType::TYPE_STRING2)
$pDataType = PHPExcel_Cell_DataType::TYPE_STRING;
$this->_dataType = $pDataType;
return $this->notifyCacheController();
@@ -461,7 +480,7 @@ class PHPExcel_Cell
list($rangeStart,$rangeEnd) = PHPExcel_Cell::rangeBoundaries($pRange);
// Translate properties
$myColumn = PHPExcel_Cell::columnIndexFromString($this->getColumn()) - 1;
$myColumn = PHPExcel_Cell::columnIndexFromString($this->getColumn());
$myRow = $this->getRow();
// Verify if cell is in range
@@ -479,23 +498,44 @@ class PHPExcel_Cell
*/
public static function coordinateFromString($pCoordinateString = 'A1')
{
if (strpos($pCoordinateString,':') !== false) {
if (preg_match("/^([$]?[A-Z]{1,3})([$]?\d{1,7})$/", $pCoordinateString, $matches)) {
return array($matches[1],$matches[2]);
} elseif ((strpos($pCoordinateString,':') !== false) || (strpos($pCoordinateString,',') !== false)) {
throw new Exception('Cell coordinate string can not be a range of cells.');
} else if ($pCoordinateString == '') {
} elseif ($pCoordinateString == '') {
throw new Exception('Cell coordinate can not be zero-length string.');
} else if (preg_match("/([$]?[A-Z]+)([$]?\d+)/", $pCoordinateString, $matches)) {
list(, $column, $row) = $matches;
return array($column, $row);
} else {
throw new Exception('Invalid cell coordinate.');
throw new Exception('Invalid cell coordinate '.$pCoordinateString);
}
}
/**
* Make string row, column or cell coordinate absolute
*
* @param string $pCoordinateString e.g. 'A' or '1' or 'A1'
* @return string Absolute coordinate e.g. '$A' or '$1' or '$A$1'
* @throws Exception
*/
public static function absoluteReference($pCoordinateString = 'A1')
{
if (strpos($pCoordinateString,':') === false && strpos($pCoordinateString,',') === false) {
// Create absolute coordinate
if (ctype_digit($pCoordinateString)) {
return '$'.$pCoordinateString;
} elseif (ctype_alpha($pCoordinateString)) {
return '$'.strtoupper($pCoordinateString);
}
return self::absoluteCoordinate($pCoordinateString);
} else {
throw new Exception("Coordinate string should not be a cell range.");
}
}
/**
* Make string coordinate absolute
*
* @param string $pCoordinateString
* @return string Absolute coordinate
* @param string $pCoordinateString e.g. 'A1'
* @return string Absolute coordinate e.g. '$A$1'
* @throws Exception
*/
public static function absoluteCoordinate($pCoordinateString = 'A1')
@@ -503,6 +543,8 @@ class PHPExcel_Cell
if (strpos($pCoordinateString,':') === false && strpos($pCoordinateString,',') === false) {
// Create absolute coordinate
list($column, $row) = PHPExcel_Cell::coordinateFromString($pCoordinateString);
if ($column[0] == '$') $column = substr($column,1);
if ($row[0] == '$') $row = substr($row,1);
return '$' . $column . '$' . $row;
} else {
throw new Exception("Coordinate string should not be a cell range.");
@@ -518,7 +560,8 @@ class PHPExcel_Cell
public static function splitRange($pRange = 'A1:A1')
{
$exploded = explode(',', $pRange);
for ($i = 0; $i < count($exploded); ++$i) {
$counter = count($exploded);
for ($i = 0; $i < $counter; ++$i) {
$exploded[$i] = explode(':', $exploded[$i]);
}
return $exploded;
@@ -540,7 +583,8 @@ class PHPExcel_Cell
// Build range
$imploded = array();
for ($i = 0; $i < count($pRange); ++$i) {
$counter = count($pRange);
for ($i = 0; $i < $counter; ++$i) {
$pRange[$i] = implode(':', $pRange[$i]);
}
$imploded = implode(',', $pRange);
@@ -604,8 +648,7 @@ class PHPExcel_Cell
// Extract range
if (strpos($pRange, ':') === false) {
$rangeA = $pRange;
$rangeB = $pRange;
$rangeA = $rangeB = $pRange;
} else {
list($rangeA, $rangeB) = explode(':', $pRange);
}
@@ -622,28 +665,28 @@ class PHPExcel_Cell
*/
public static function columnIndexFromString($pString = 'A')
{
static $lookup = array(
// It's surprising how costly the strtoupper() and ord() calls actually are, so we use a lookup array rather than use ord()
// and make it case insensitive to get rid of the strtoupper() as well. Because it's a static, there's no significant
// memory overhead either
static $_columnLookup = array(
'A' => 1, 'B' => 2, 'C' => 3, 'D' => 4, 'E' => 5, 'F' => 6, 'G' => 7, 'H' => 8, 'I' => 9, 'J' => 10, 'K' => 11, 'L' => 12, 'M' => 13,
'N' => 14, 'O' => 15, 'P' => 16, 'Q' => 17, 'R' => 18, 'S' => 19, 'T' => 20, 'U' => 21, 'V' => 22, 'W' => 23, 'X' => 24, 'Y' => 25, 'Z' => 26
'N' => 14, 'O' => 15, 'P' => 16, 'Q' => 17, 'R' => 18, 'S' => 19, 'T' => 20, 'U' => 21, 'V' => 22, 'W' => 23, 'X' => 24, 'Y' => 25, 'Z' => 26,
'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5, 'f' => 6, 'g' => 7, 'h' => 8, 'i' => 9, 'j' => 10, 'k' => 11, 'l' => 12, 'm' => 13,
'n' => 14, 'o' => 15, 'p' => 16, 'q' => 17, 'r' => 18, 's' => 19, 't' => 20, 'u' => 21, 'v' => 22, 'w' => 23, 'x' => 24, 'y' => 25, 'z' => 26
);
if (isset($lookup[$pString]))
return $lookup[$pString];
// Convert to uppercase
$pString = strtoupper($pString);
$strLen = strlen($pString);
// Convert column to integer
if ($strLen == 1) {
return (ord($pString{0}) - 64);
} elseif ($strLen == 2) {
return $result = ((1 + (ord($pString{0}) - 65)) * 26) + (ord($pString{1}) - 64);
} elseif ($strLen == 3) {
return ((1 + (ord($pString{0}) - 65)) * 676) + ((1 + (ord($pString{1}) - 65)) * 26) + (ord($pString{2}) - 64);
} else {
throw new Exception("Column string index can not be " . ($strLen != 0 ? "longer than 3 characters" : "empty") . ".");
// We also use the language construct isset() rather than the more costly strlen() function to match the length of $pString
// for improved performance
if (isset($pString{0})) {
if (!isset($pString{1})) {
return $_columnLookup[$pString];
} elseif(!isset($pString{2})) {
return $_columnLookup[$pString{0}] * 26 + $_columnLookup[$pString{1}];
} elseif(!isset($pString{3})) {
return $_columnLookup[$pString{0}] * 676 + $_columnLookup[$pString{1}] * 26 + $_columnLookup[$pString{2}];
}
}
throw new Exception("Column string index can not be " . ((isset($pString{0})) ? "longer than 3 characters" : "empty") . ".");
}
/**
@@ -657,8 +700,10 @@ class PHPExcel_Cell
// Determine column string
if ($pColumnIndex < 26) {
return chr(65 + $pColumnIndex);
} elseif ($pColumnIndex < 702) {
return chr(64 + ($pColumnIndex / 26)).chr(65 + $pColumnIndex % 26);
}
return PHPExcel_Cell::stringFromColumnIndex((int)($pColumnIndex / 26) -1).chr(65 + $pColumnIndex%26) ;
return chr(64 + (($pColumnIndex - 26) / 676)).chr(65 + ((($pColumnIndex - 26) % 676) / 26)).chr(65 + $pColumnIndex % 26);
}
/**
@@ -672,60 +717,41 @@ class PHPExcel_Cell
$returnValue = array();
// Explode spaces
$aExplodeSpaces = explode(' ', str_replace('$', '', strtoupper($pRange)));
foreach ($aExplodeSpaces as $explodedSpaces) {
$cellBlocks = explode(' ', str_replace('$', '', strtoupper($pRange)));
foreach ($cellBlocks as $cellBlock) {
// Single cell?
if (strpos($explodedSpaces,':') === false && strpos($explodedSpaces,',') === false) {
$col = 'A';
$row = 1;
list($col, $row) = PHPExcel_Cell::coordinateFromString($explodedSpaces);
if (strlen($col) <= 2) {
$returnValue[] = $explodedSpaces;
}
if (strpos($cellBlock,':') === false && strpos($cellBlock,',') === false) {
$returnValue[] = $cellBlock;
continue;
}
// Range...
$range = PHPExcel_Cell::splitRange($explodedSpaces);
for ($i = 0; $i < count($range); ++$i) {
$ranges = PHPExcel_Cell::splitRange($cellBlock);
foreach($ranges as $range) {
// Single cell?
if (count($range[$i]) == 1) {
$col = 'A';
$row = 1;
list($col, $row) = PHPExcel_Cell::coordinateFromString($range[$i]);
if (strlen($col) <= 2) {
$returnValue[] = $explodedSpaces;
}
if (!isset($range[1])) {
$returnValue[] = $range[0];
continue;
}
// Range...
$rangeStart = $rangeEnd = '';
$startingCol = $startingRow = $endingCol = $endingRow = 0;
list($rangeStart, $rangeEnd) = $range[$i];
list($startingCol, $startingRow) = PHPExcel_Cell::coordinateFromString($rangeStart);
list($endingCol, $endingRow) = PHPExcel_Cell::coordinateFromString($rangeEnd);
// Conversions...
$startingCol = PHPExcel_Cell::columnIndexFromString($startingCol);
$endingCol = PHPExcel_Cell::columnIndexFromString($endingCol);
list($rangeStart, $rangeEnd) = $range;
list($startCol, $startRow) = sscanf($rangeStart,'%[A-Z]%d');
list($endCol, $endRow) = sscanf($rangeEnd,'%[A-Z]%d');
$endCol++;
// Current data
$currentCol = --$startingCol;
$currentRow = $startingRow;
$currentCol = $startCol;
$currentRow = $startRow;
// Loop cells
while ($currentCol < $endingCol) {
$loopColumn = PHPExcel_Cell::stringFromColumnIndex($currentCol);
while ($currentRow <= $endingRow) {
$returnValue[] = $loopColumn.$currentRow;
while ($currentCol != $endCol) {
while ($currentRow <= $endRow) {
$returnValue[] = $currentCol.$currentRow;
++$currentRow;
}
++$currentCol;
$currentRow = $startingRow;
$currentRow = $startRow;
}
}
}

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -20,18 +20,28 @@
*
* @category PHPExcel
* @package PHPExcel_Cell
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
}
/**
* PHPExcel_Cell_AdvancedValueBinder
*
* @category PHPExcel
* @package PHPExcel_Cell
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Cell_AdvancedValueBinder extends PHPExcel_Cell_DefaultValueBinder implements PHPExcel_Cell_IValueBinder
{
@@ -54,14 +64,27 @@ class PHPExcel_Cell_AdvancedValueBinder extends PHPExcel_Cell_DefaultValueBinder
// Style logic - strings
if ($dataType === PHPExcel_Cell_DataType::TYPE_STRING && !$value instanceof PHPExcel_RichText) {
// Test for booleans using locale-setting
if ($value == PHPExcel_Calculation::getTRUE()) {
$cell->setValueExplicit( True, PHPExcel_Cell_DataType::TYPE_BOOL);
return true;
} elseif($value == PHPExcel_Calculation::getFALSE()) {
$cell->setValueExplicit( False, PHPExcel_Cell_DataType::TYPE_BOOL);
return true;
}
// Check for number in scientific format
if (preg_match('/^'.PHPExcel_Calculation::CALCULATION_REGEXP_NUMBER.'$/', $value)) {
$cell->setValueExplicit( (float) $value, PHPExcel_Cell_DataType::TYPE_NUMERIC);
return true;
}
// Check for percentage
if (preg_match('/^\-?[0-9]*\.?[0-9]*\s?\%$/', $value)) {
// Convert value to number
$cell->setValueExplicit( (float)str_replace('%', '', $value) / 100, PHPExcel_Cell_DataType::TYPE_NUMERIC);
// Set style
$cell->getParent()->getStyle( $cell->getCoordinate() )->getNumberFormat()->setFormatCode( PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE );
return true;
}
@@ -69,13 +92,10 @@ class PHPExcel_Cell_AdvancedValueBinder extends PHPExcel_Cell_DefaultValueBinder
if (preg_match('/^(\d|[0-1]\d|2[0-3]):[0-5]\d$/', $value)) {
list($h, $m) = explode(':', $value);
$days = $h / 24 + $m / 1440;
// Convert value to number
$cell->setValueExplicit($days, PHPExcel_Cell_DataType::TYPE_NUMERIC);
// Set style
$cell->getParent()->getStyle( $cell->getCoordinate() )->getNumberFormat()->setFormatCode( PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME3 );
return true;
}
@@ -83,29 +103,24 @@ class PHPExcel_Cell_AdvancedValueBinder extends PHPExcel_Cell_DefaultValueBinder
if (preg_match('/^(\d|[0-1]\d|2[0-3]):[0-5]\d:[0-5]\d$/', $value)) {
list($h, $m, $s) = explode(':', $value);
$days = $h / 24 + $m / 1440 + $s / 86400;
// Convert value to number
$cell->setValueExplicit($days, PHPExcel_Cell_DataType::TYPE_NUMERIC);
// Set style
$cell->getParent()->getStyle( $cell->getCoordinate() )->getNumberFormat()->setFormatCode( PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME4 );
return true;
}
// Check for datetime, e.g. '2008-12-31', '2008-12-31 15:59', '2008-12-31 15:59:10'
if (($v = PHPExcel_Shared_Date::stringToExcel($value)) !== false) {
// Convert value to Excel date
$cell->setValueExplicit($v, PHPExcel_Cell_DataType::TYPE_NUMERIC);
// Set style. Either there is a time part or not. Look for ':'
if (($d = PHPExcel_Shared_Date::stringToExcel($value)) !== false) {
// Convert value to number
$cell->setValueExplicit($d, PHPExcel_Cell_DataType::TYPE_NUMERIC);
// Determine style. Either there is a time part or not. Look for ':'
if (strpos($value, ':') !== false) {
$formatCode = 'yyyy-mm-dd h:mm';
} else {
$formatCode = 'yyyy-mm-dd';
}
$cell->getParent()->getStyle( $cell->getCoordinate() )->getNumberFormat()->setFormatCode($formatCode);
return true;
}
@@ -113,10 +128,8 @@ class PHPExcel_Cell_AdvancedValueBinder extends PHPExcel_Cell_DefaultValueBinder
if (strpos($value, "\n") !== false) {
$value = PHPExcel_Shared_String::SanitizeUTF8($value);
$cell->setValueExplicit($value, PHPExcel_Cell_DataType::TYPE_STRING);
// Set style
$cell->getParent()->getStyle( $cell->getCoordinate() )->getAlignment()->setWrapText(true);
return true;
}
}

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Cell
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
@@ -31,11 +31,12 @@
*
* @category PHPExcel
* @package PHPExcel_Cell
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Cell_DataType
{
/* Data types */
const TYPE_STRING2 = 'str';
const TYPE_STRING = 's';
const TYPE_FORMULA = 'f';
const TYPE_NUMERIC = 'n';

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Cell
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
@@ -31,7 +31,7 @@
*
* @category PHPExcel
* @package PHPExcel_Cell
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Cell_DataValidation
{

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -20,18 +20,28 @@
*
* @category PHPExcel
* @package PHPExcel_Cell
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
}
/**
* PHPExcel_Cell_DefaultValueBinder
*
* @category PHPExcel
* @package PHPExcel_Cell
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Cell_DefaultValueBinder implements PHPExcel_Cell_IValueBinder
{

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Cell
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
@@ -31,7 +31,7 @@
*
* @category PHPExcel
* @package PHPExcel_Cell
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Cell_Hyperlink
{

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Cell
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
@@ -31,7 +31,7 @@
*
* @category PHPExcel
* @package PHPExcel_Cell
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
interface PHPExcel_Cell_IValueBinder
{

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
@@ -31,7 +31,7 @@
*
* @category PHPExcel
* @package PHPExcel
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Comment implements PHPExcel_IComparable
{
@@ -91,6 +91,13 @@ class PHPExcel_Comment implements PHPExcel_IComparable
*/
private $_fillColor;
/**
* Alignment
*
* @var string
*/
private $_alignment;
/**
* Create a new PHPExcel_Comment
*
@@ -99,9 +106,10 @@ class PHPExcel_Comment implements PHPExcel_IComparable
public function __construct()
{
// Initialise variables
$this->_author = 'Author';
$this->_text = new PHPExcel_RichText();
$this->_fillColor = new PHPExcel_Style_Color('FFFFFFE1');
$this->_author = 'Author';
$this->_text = new PHPExcel_RichText();
$this->_fillColor = new PHPExcel_Style_Color('FFFFFFE1');
$this->_alignment = PHPExcel_Style_Alignment::HORIZONTAL_GENERAL;
}
/**
@@ -253,6 +261,26 @@ class PHPExcel_Comment implements PHPExcel_IComparable
return $this->_fillColor;
}
/**
* Set Alignment
*
* @param string $pValue
* @return PHPExcel_Comment
*/
public function setAlignment($pValue = PHPExcel_Style_Alignment::HORIZONTAL_GENERAL) {
$this->_alignment = $pValue;
return $this;
}
/**
* Get Alignment
*
* @return string
*/
public function getAlignment() {
return $this->_alignment;
}
/**
* Get hash code
*
@@ -268,6 +296,7 @@ class PHPExcel_Comment implements PHPExcel_IComparable
. $this->_marginTop
. ($this->_visible ? 1 : 0)
. $this->_fillColor->getHashCode()
. $this->_alignment
. __CLASS__
);
}

View File

@@ -1,354 +1,465 @@
<?php
/**
* PHPExcel
* PHPExcel
*
* Copyright (c) 2006 - 2010 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 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.
* 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
* 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 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.4, 2010-08-26
* @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 1.7.6, 2011-02-27
*/
/**
* PHPExcel_DocumentProperties
*
* @category PHPExcel
* @package PHPExcel
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @category PHPExcel
* @package PHPExcel
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_DocumentProperties
{
/** constants */
const PROPERTY_TYPE_BOOLEAN = 'b';
const PROPERTY_TYPE_INTEGER = 'i';
const PROPERTY_TYPE_FLOAT = 'f';
const PROPERTY_TYPE_DATE = 'd';
const PROPERTY_TYPE_STRING = 's';
const PROPERTY_TYPE_UNKNOWN = 'u';
/**
* Creator
*
* @var string
* @var string
*/
private $_creator;
private $_creator = 'Unknown Creator';
/**
* LastModifiedBy
*
* @var string
* @var string
*/
private $_lastModifiedBy;
/**
* Created
*
* @var datetime
* @var datetime
*/
private $_created;
/**
* Modified
*
* @var datetime
* @var datetime
*/
private $_modified;
/**
* Title
*
* @var string
* @var string
*/
private $_title;
private $_title = 'Untitled Spreadsheet';
/**
* Description
*
* @var string
* @var string
*/
private $_description;
private $_description = '';
/**
* Subject
*
* @var string
* @var string
*/
private $_subject;
private $_subject = '';
/**
* Keywords
*
* @var string
* @var string
*/
private $_keywords;
private $_keywords = '';
/**
* Category
*
* @var string
* @var string
*/
private $_category;
private $_category = '';
/**
* Manager
*
* @var string
*/
private $_manager = '';
/**
* Company
*
* @var string
* @var string
*/
private $_company;
private $_company = 'Microsoft Corporation';
/**
* Create a new PHPExcel_DocumentProperties
*/
public function __construct()
{
// Initialise values
$this->_creator = 'Unknown Creator';
$this->_lastModifiedBy = $this->_creator;
$this->_created = time();
$this->_modified = time();
$this->_title = "Untitled Spreadsheet";
$this->_subject = '';
$this->_description = '';
$this->_keywords = '';
$this->_category = '';
$this->_manager = '';
$this->_company = 'Microsoft Corporation';
}
/**
* Custom Properties
*
* @var string
*/
private $_customProperties = array();
/**
* Get Creator
*
* @return string
*/
public function getCreator() {
return $this->_creator;
}
/**
* Set Creator
*
* @param string $pValue
* @return PHPExcel_DocumentProperties
*/
public function setCreator($pValue = '') {
$this->_creator = $pValue;
return $this;
}
/**
* Create a new PHPExcel_DocumentProperties
*/
public function __construct()
{
// Initialise values
$this->_lastModifiedBy = $this->_creator;
$this->_created = time();
$this->_modified = time();
}
/**
* Get Last Modified By
*
* @return string
*/
public function getLastModifiedBy() {
return $this->_lastModifiedBy;
}
/**
* Get Creator
*
* @return string
*/
public function getCreator() {
return $this->_creator;
}
/**
* Set Last Modified By
*
* @param string $pValue
* @return PHPExcel_DocumentProperties
*/
public function setLastModifiedBy($pValue = '') {
$this->_lastModifiedBy = $pValue;
return $this;
}
/**
* Set Creator
*
* @param string $pValue
* @return PHPExcel_DocumentProperties
*/
public function setCreator($pValue = '') {
$this->_creator = $pValue;
return $this;
}
/**
* Get Created
*
* @return datetime
*/
public function getCreated() {
return $this->_created;
}
/**
* Get Last Modified By
*
* @return string
*/
public function getLastModifiedBy() {
return $this->_lastModifiedBy;
}
/**
* Set Created
*
* @param datetime $pValue
* @return PHPExcel_DocumentProperties
*/
public function setCreated($pValue = null) {
if (is_null($pValue)) {
$pValue = time();
}
$this->_created = $pValue;
return $this;
}
/**
* Set Last Modified By
*
* @param string $pValue
* @return PHPExcel_DocumentProperties
*/
public function setLastModifiedBy($pValue = '') {
$this->_lastModifiedBy = $pValue;
return $this;
}
/**
* Get Modified
*
* @return datetime
*/
public function getModified() {
return $this->_modified;
}
/**
* Get Created
*
* @return datetime
*/
public function getCreated() {
return $this->_created;
}
/**
* Set Modified
*
* @param datetime $pValue
* @return PHPExcel_DocumentProperties
*/
public function setModified($pValue = null) {
if (is_null($pValue)) {
$pValue = time();
}
$this->_modified = $pValue;
return $this;
}
/**
* Set Created
*
* @param datetime $pValue
* @return PHPExcel_DocumentProperties
*/
public function setCreated($pValue = null) {
if (is_null($pValue)) {
$pValue = time();
} elseif (is_string($pValue)) {
if (is_numeric($pValue)) {
$pValue = intval($pValue);
} else {
$pValue = strtotime($pValue);
}
}
/**
* Get Title
*
* @return string
*/
public function getTitle() {
return $this->_title;
}
$this->_created = $pValue;
return $this;
}
/**
* Set Title
*
* @param string $pValue
* @return PHPExcel_DocumentProperties
*/
public function setTitle($pValue = '') {
$this->_title = $pValue;
return $this;
}
/**
* Get Modified
*
* @return datetime
*/
public function getModified() {
return $this->_modified;
}
/**
* Get Description
*
* @return string
*/
public function getDescription() {
return $this->_description;
}
/**
* Set Modified
*
* @param datetime $pValue
* @return PHPExcel_DocumentProperties
*/
public function setModified($pValue = null) {
if (is_null($pValue)) {
$pValue = time();
} elseif (is_string($pValue)) {
if (is_numeric($pValue)) {
$pValue = intval($pValue);
} else {
$pValue = strtotime($pValue);
}
}
/**
* Set Description
*
* @param string $pValue
* @return PHPExcel_DocumentProperties
*/
public function setDescription($pValue = '') {
$this->_description = $pValue;
return $this;
}
$this->_modified = $pValue;
return $this;
}
/**
* Get Subject
*
* @return string
*/
public function getSubject() {
return $this->_subject;
}
/**
* Get Title
*
* @return string
*/
public function getTitle() {
return $this->_title;
}
/**
* Set Subject
*
* @param string $pValue
* @return PHPExcel_DocumentProperties
*/
public function setSubject($pValue = '') {
$this->_subject = $pValue;
return $this;
}
/**
* Set Title
*
* @param string $pValue
* @return PHPExcel_DocumentProperties
*/
public function setTitle($pValue = '') {
$this->_title = $pValue;
return $this;
}
/**
* Get Keywords
*
* @return string
*/
public function getKeywords() {
return $this->_keywords;
}
/**
* Get Description
*
* @return string
*/
public function getDescription() {
return $this->_description;
}
/**
* Set Keywords
*
* @param string $pValue
* @return PHPExcel_DocumentProperties
*/
public function setKeywords($pValue = '') {
$this->_keywords = $pValue;
return $this;
}
/**
* Set Description
*
* @param string $pValue
* @return PHPExcel_DocumentProperties
*/
public function setDescription($pValue = '') {
$this->_description = $pValue;
return $this;
}
/**
* Get Category
*
* @return string
*/
public function getCategory() {
return $this->_category;
}
/**
* Get Subject
*
* @return string
*/
public function getSubject() {
return $this->_subject;
}
/**
* Set Category
*
* @param string $pValue
* @return PHPExcel_DocumentProperties
*/
public function setCategory($pValue = '') {
$this->_category = $pValue;
return $this;
}
/**
* Set Subject
*
* @param string $pValue
* @return PHPExcel_DocumentProperties
*/
public function setSubject($pValue = '') {
$this->_subject = $pValue;
return $this;
}
/**
* Get Company
*
* @return string
*/
public function getCompany() {
return $this->_company;
}
/**
* Get Keywords
*
* @return string
*/
public function getKeywords() {
return $this->_keywords;
}
/**
* Set Company
*
* @param string $pValue
* @return PHPExcel_DocumentProperties
*/
public function setCompany($pValue = '') {
$this->_company = $pValue;
return $this;
}
/**
* Set Keywords
*
* @param string $pValue
* @return PHPExcel_DocumentProperties
*/
public function setKeywords($pValue = '') {
$this->_keywords = $pValue;
return $this;
}
/**
* Get Manager
*
* @return string
*/
public function getManager() {
return $this->_manager;
}
/**
* Get Category
*
* @return string
*/
public function getCategory() {
return $this->_category;
}
/**
* Set Manager
*
* @param string $pValue
* @return PHPExcel_DocumentProperties
*/
public function setManager($pValue = '') {
$this->_manager = $pValue;
return $this;
}
/**
* Set Category
*
* @param string $pValue
* @return PHPExcel_DocumentProperties
*/
public function setCategory($pValue = '') {
$this->_category = $pValue;
return $this;
}
/**
* Get Company
*
* @return string
*/
public function getCompany() {
return $this->_company;
}
/**
* Set Company
*
* @param string $pValue
* @return PHPExcel_DocumentProperties
*/
public function setCompany($pValue = '') {
$this->_company = $pValue;
return $this;
}
/**
* Get Manager
*
* @return string
*/
public function getManager() {
return $this->_manager;
}
/**
* Set Manager
*
* @param string $pValue
* @return PHPExcel_DocumentProperties
*/
public function setManager($pValue = '') {
$this->_manager = $pValue;
return $this;
}
/**
* Get a List of Custom Property Names
*
* @return array of string
*/
public function getCustomProperties() {
return array_keys($this->_customProperties);
}
/**
* Check if a Custom Property is defined
*
* @param string $propertyName
* @return boolean
*/
public function isCustomPropertySet($propertyName) {
return isset($this->_customProperties[$propertyName]);
}
/**
* Get a Custom Property Value
*
* @param string $propertyName
* @return string
*/
public function getCustomPropertyValue($propertyName) {
if (isset($this->_customProperties[$propertyName])) {
return $this->_customProperties[$propertyName]['value'];
}
}
/**
* Get a Custom Property Type
*
* @param string $propertyName
* @return string
*/
public function getCustomPropertyType($propertyName) {
if (isset($this->_customProperties[$propertyName])) {
return $this->_customProperties[$propertyName]['type'];
}
}
/**
* Set a Custom Property
*
* @param string $propertyName
* @param mixed $propertyValue
* @param string $propertyType
* 'i' : Integer
* 'f' : Floating Point
* 's' : String
* 'd' : Date/Time
* 'b' : Boolean
* @return PHPExcel_DocumentProperties
*/
public function setCustomProperty($propertyName,$propertyValue='',$propertyType=NULL) {
if ((is_null($propertyType)) || (!in_array($propertyType,array(self::PROPERTY_TYPE_INTEGER,
self::PROPERTY_TYPE_FLOAT,
self::PROPERTY_TYPE_STRING,
self::PROPERTY_TYPE_DATE,
self::PROPERTY_TYPE_BOOLEAN)))) {
if (is_null($propertyValue)) {
$propertyType = self::PROPERTY_TYPE_STRING;
} elseif (is_float($propertyValue)) {
$propertyType = self::PROPERTY_TYPE_FLOAT;
} elseif(is_int($propertyValue)) {
$propertyType = self::PROPERTY_TYPE_INTEGER;
} elseif (is_bool($propertyValue)) {
$propertyType = self::PROPERTY_TYPE_BOOLEAN;
} else {
$propertyType = self::PROPERTY_TYPE_STRING;
}
}
$this->_customProperties[$propertyName] = array('value' => $propertyValue, 'type' => $propertyType);
return $this;
}
/**
* Implement PHP __clone to create a deep clone, not just a shallow copy.
@@ -363,4 +474,115 @@ class PHPExcel_DocumentProperties
}
}
}
public static function convertProperty($propertyValue,$propertyType) {
switch ($propertyType) {
case 'empty' : // Empty
return '';
break;
case 'null' : // Null
return NULL;
break;
case 'i1' : // 1-Byte Signed Integer
case 'i2' : // 2-Byte Signed Integer
case 'i4' : // 4-Byte Signed Integer
case 'i8' : // 8-Byte Signed Integer
case 'int' : // Integer
return (int) $propertyValue;
break;
case 'ui1' : // 1-Byte Unsigned Integer
case 'ui2' : // 2-Byte Unsigned Integer
case 'ui4' : // 4-Byte Unsigned Integer
case 'ui8' : // 8-Byte Unsigned Integer
case 'uint' : // Unsigned Integer
return abs((int) $propertyValue);
break;
case 'r4' : // 4-Byte Real Number
case 'r8' : // 8-Byte Real Number
case 'decimal' : // Decimal
return (float) $propertyValue;
break;
case 'lpstr' : // LPSTR
case 'lpwstr' : // LPWSTR
case 'bstr' : // Basic String
return $propertyValue;
break;
case 'date' : // Date and Time
case 'filetime' : // File Time
return strtotime($propertyValue);
break;
case 'bool' : // Boolean
return ($propertyValue == 'true') ? True : False;
break;
case 'cy' : // Currency
case 'error' : // Error Status Code
case 'vector' : // Vector
case 'array' : // Array
case 'blob' : // Binary Blob
case 'oblob' : // Binary Blob Object
case 'stream' : // Binary Stream
case 'ostream' : // Binary Stream Object
case 'storage' : // Binary Storage
case 'ostorage' : // Binary Storage Object
case 'vstream' : // Binary Versioned Stream
case 'clsid' : // Class ID
case 'cf' : // Clipboard Data
return $propertyValue;
break;
}
return $propertyValue;
}
public static function convertPropertyType($propertyType) {
switch ($propertyType) {
case 'i1' : // 1-Byte Signed Integer
case 'i2' : // 2-Byte Signed Integer
case 'i4' : // 4-Byte Signed Integer
case 'i8' : // 8-Byte Signed Integer
case 'int' : // Integer
case 'ui1' : // 1-Byte Unsigned Integer
case 'ui2' : // 2-Byte Unsigned Integer
case 'ui4' : // 4-Byte Unsigned Integer
case 'ui8' : // 8-Byte Unsigned Integer
case 'uint' : // Unsigned Integer
return self::PROPERTY_TYPE_INTEGER;
break;
case 'r4' : // 4-Byte Real Number
case 'r8' : // 8-Byte Real Number
case 'decimal' : // Decimal
return self::PROPERTY_TYPE_FLOAT;
break;
case 'empty' : // Empty
case 'null' : // Null
case 'lpstr' : // LPSTR
case 'lpwstr' : // LPWSTR
case 'bstr' : // Basic String
return self::PROPERTY_TYPE_STRING;
break;
case 'date' : // Date and Time
case 'filetime' : // File Time
return self::PROPERTY_TYPE_DATE;
break;
case 'bool' : // Boolean
return self::PROPERTY_TYPE_BOOLEAN;
break;
case 'cy' : // Currency
case 'error' : // Error Status Code
case 'vector' : // Vector
case 'array' : // Array
case 'blob' : // Binary Blob
case 'oblob' : // Binary Blob Object
case 'stream' : // Binary Stream
case 'ostream' : // Binary Stream Object
case 'storage' : // Binary Storage
case 'ostorage' : // Binary Storage Object
case 'vstream' : // Binary Versioned Stream
case 'clsid' : // Class ID
case 'cf' : // Clipboard Data
return self::PROPERTY_TYPE_UNKNOWN;
break;
}
return self::PROPERTY_TYPE_UNKNOWN;
}
}

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
@@ -31,7 +31,7 @@
*
* @category PHPExcel
* @package PHPExcel
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_DocumentSecurity
{

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -19,10 +19,10 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.4, 2010-08-26
* @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 1.7.6, 2011-02-27
*/
@@ -30,161 +30,163 @@
* PHPExcel_HashTable
*
* @category PHPExcel
* @package PHPExcel
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @package PHPExcel
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_HashTable
{
/**
* HashTable elements
*
* @var array
*/
public $_items = array();
/**
* HashTable elements
*
* @var array
*/
public $_items = array();
/**
* HashTable key map
*
* @var array
*/
public $_keyMap = array();
/**
* HashTable key map
*
* @var array
*/
public $_keyMap = array();
/**
* Create a new PHPExcel_HashTable
*
* @param PHPExcel_IComparable[] $pSource Optional source array to create HashTable from
* @throws Exception
*/
public function __construct($pSource = null)
{
if (!is_null($pSource)) {
// Create HashTable
$this->addFromSource($pSource);
}
}
/**
* Create a new PHPExcel_HashTable
*
* @param PHPExcel_IComparable[] $pSource Optional source array to create HashTable from
* @throws Exception
*/
public function __construct($pSource = null)
{
if (!is_null($pSource)) {
// Create HashTable
$this->addFromSource($pSource);
}
}
/**
* Add HashTable items from source
*
* @param PHPExcel_IComparable[] $pSource Source array to create HashTable from
* @throws Exception
*/
public function addFromSource($pSource = null) {
// Check if an array was passed
if ($pSource == null) {
return;
} else if (!is_array($pSource)) {
throw new Exception('Invalid array parameter passed.');
}
/**
* Add HashTable items from source
*
* @param PHPExcel_IComparable[] $pSource Source array to create HashTable from
* @throws Exception
*/
public function addFromSource($pSource = null) {
// Check if an array was passed
if ($pSource == null) {
return;
} else if (!is_array($pSource)) {
throw new Exception('Invalid array parameter passed.');
}
foreach ($pSource as $item) {
$this->add($item);
}
}
foreach ($pSource as $item) {
$this->add($item);
}
}
/**
* Add HashTable item
*
* @param PHPExcel_IComparable $pSource Item to add
* @throws Exception
*/
public function add(PHPExcel_IComparable $pSource = null) {
if (!isset($this->_items[ $pSource->getHashCode() ])) {
$this->_items[ $pSource->getHashCode() ] = $pSource;
$this->_keyMap[ count($this->_items) - 1 ] = $pSource->getHashCode();
}
}
/**
* Add HashTable item
*
* @param PHPExcel_IComparable $pSource Item to add
* @throws Exception
*/
public function add(PHPExcel_IComparable $pSource = null) {
$hash = $pSource->getHashCode();
if (!isset($this->_items[$hash])) {
$this->_items[$hash] = $pSource;
$this->_keyMap[count($this->_items) - 1] = $hash;
}
}
/**
* Remove HashTable item
*
* @param PHPExcel_IComparable $pSource Item to remove
* @throws Exception
*/
public function remove(PHPExcel_IComparable $pSource = null) {
if (isset($this->_items[ $pSource->getHashCode() ])) {
unset($this->_items[ $pSource->getHashCode() ]);
/**
* Remove HashTable item
*
* @param PHPExcel_IComparable $pSource Item to remove
* @throws Exception
*/
public function remove(PHPExcel_IComparable $pSource = null) {
$hash = $pSource->getHashCode();
if (isset($this->_items[$hash])) {
unset($this->_items[$hash]);
$deleteKey = -1;
foreach ($this->_keyMap as $key => $value) {
if ($deleteKey >= 0) {
$this->_keyMap[$key - 1] = $value;
}
$deleteKey = -1;
foreach ($this->_keyMap as $key => $value) {
if ($deleteKey >= 0) {
$this->_keyMap[$key - 1] = $value;
}
if ($value == $pSource->getHashCode()) {
$deleteKey = $key;
}
}
unset($this->_keyMap[ count($this->_keyMap) - 1 ]);
}
}
if ($value == $hash) {
$deleteKey = $key;
}
}
unset($this->_keyMap[count($this->_keyMap) - 1]);
}
}
/**
* Clear HashTable
*
*/
public function clear() {
$this->_items = array();
$this->_keyMap = array();
}
/**
* Clear HashTable
*
*/
public function clear() {
$this->_items = array();
$this->_keyMap = array();
}
/**
* Count
*
* @return int
*/
public function count() {
return count($this->_items);
}
/**
* Count
*
* @return int
*/
public function count() {
return count($this->_items);
}
/**
* Get index for hash code
*
* @param string $pHashCode
* @return int Index
*/
public function getIndexForHashCode($pHashCode = '') {
return array_search($pHashCode, $this->_keyMap);
}
/**
* Get index for hash code
*
* @param string $pHashCode
* @return int Index
*/
public function getIndexForHashCode($pHashCode = '') {
return array_search($pHashCode, $this->_keyMap);
}
/**
* Get by index
*
* @param int $pIndex
* @return PHPExcel_IComparable
*
*/
public function getByIndex($pIndex = 0) {
if (isset($this->_keyMap[$pIndex])) {
return $this->getByHashCode( $this->_keyMap[$pIndex] );
}
/**
* Get by index
*
* @param int $pIndex
* @return PHPExcel_IComparable
*
*/
public function getByIndex($pIndex = 0) {
if (isset($this->_keyMap[$pIndex])) {
return $this->getByHashCode( $this->_keyMap[$pIndex] );
}
return null;
}
return null;
}
/**
* Get by hashcode
*
* @param string $pHashCode
* @return PHPExcel_IComparable
*
*/
public function getByHashCode($pHashCode = '') {
if (isset($this->_items[$pHashCode])) {
return $this->_items[$pHashCode];
}
/**
* Get by hashcode
*
* @param string $pHashCode
* @return PHPExcel_IComparable
*
*/
public function getByHashCode($pHashCode = '') {
if (isset($this->_items[$pHashCode])) {
return $this->_items[$pHashCode];
}
return null;
}
return null;
}
/**
* HashTable to array
*
* @return PHPExcel_IComparable[]
*/
public function toArray() {
return $this->_items;
}
/**
* HashTable to array
*
* @return PHPExcel_IComparable[]
*/
public function toArray() {
return $this->_items;
}
/**
* Implement PHP __clone to create a deep clone, not just a shallow copy.

View File

@@ -18,9 +18,9 @@
*
* @category PHPExcel
* @package PHPExcel
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
@@ -29,7 +29,7 @@
*
* @category PHPExcel
* @package PHPExcel
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
interface PHPExcel_IComparable
{

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
@@ -33,12 +33,6 @@ if (!defined('PHPEXCEL_ROOT')) {
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../');
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
PHPExcel_Autoloader::Register();
PHPExcel_Shared_ZipStreamWrapper::register();
// check mbstring.func_overload
if (ini_get('mbstring.func_overload') & 2) {
throw new Exception('Multibyte function overloading in PHP must be disabled for string functions (2).');
}
}
/**
@@ -46,7 +40,7 @@ if (!defined('PHPEXCEL_ROOT')) {
*
* @category PHPExcel
* @package PHPExcel
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_IOFactory
{
@@ -75,7 +69,7 @@ class PHPExcel_IOFactory
'Excel2003XML',
'OOCalc',
'SYLK',
'Serialized',
'Gnumeric',
'CSV',
);
@@ -247,6 +241,9 @@ class PHPExcel_IOFactory
case 'xml':
$reader = self::createReader('Excel2003XML');
break;
case 'gnumeric':
$reader = self::createReader('Gnumeric');
break;
case 'csv':
// Do nothing
// We must not try to use CSV reader since it loads

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
@@ -31,7 +31,7 @@
*
* @category PHPExcel
* @package PHPExcel
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_NamedRange
{

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
@@ -33,12 +33,6 @@ if (!defined('PHPEXCEL_ROOT')) {
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
PHPExcel_Autoloader::Register();
PHPExcel_Shared_ZipStreamWrapper::register();
// check mbstring.func_overload
if (ini_get('mbstring.func_overload') & 2) {
throw new Exception('Multibyte function overloading in PHP must be disabled for string functions (2).');
}
}
/**
@@ -46,7 +40,7 @@ if (!defined('PHPEXCEL_ROOT')) {
*
* @category PHPExcel
* @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Reader_CSV implements PHPExcel_Reader_IReader
{
@@ -56,7 +50,7 @@ class PHPExcel_Reader_CSV implements PHPExcel_Reader_IReader
* @access private
* @var string
*/
private $_inputEncoding;
private $_inputEncoding = 'UTF-8';
/**
* Delimiter
@@ -64,7 +58,7 @@ class PHPExcel_Reader_CSV implements PHPExcel_Reader_IReader
* @access private
* @var string
*/
private $_delimiter;
private $_delimiter = ',';
/**
* Enclosure
@@ -72,7 +66,7 @@ class PHPExcel_Reader_CSV implements PHPExcel_Reader_IReader
* @access private
* @var string
*/
private $_enclosure;
private $_enclosure = '"';
/**
* Line ending
@@ -80,7 +74,7 @@ class PHPExcel_Reader_CSV implements PHPExcel_Reader_IReader
* @access private
* @var string
*/
private $_lineEnding;
private $_lineEnding = PHP_EOL;
/**
* Sheet index to read
@@ -88,7 +82,24 @@ class PHPExcel_Reader_CSV implements PHPExcel_Reader_IReader
* @access private
* @var int
*/
private $_sheetIndex;
private $_sheetIndex = 0;
/**
* Load rows contiguously
*
* @access private
* @var int
*/
private $_contiguous = false;
/**
* Row counter for loading rows contiguously
*
* @access private
* @var int
*/
private $_contiguousRow = -1;
/**
* PHPExcel_Reader_IReadFilter instance
@@ -102,12 +113,7 @@ class PHPExcel_Reader_CSV implements PHPExcel_Reader_IReader
* Create a new PHPExcel_Reader_CSV
*/
public function __construct() {
$this->_inputEncoding = 'UTF-8';
$this->_delimiter = ',';
$this->_enclosure = '"';
$this->_lineEnding = PHP_EOL;
$this->_sheetIndex = 0;
$this->_readFilter = new PHPExcel_Reader_DefaultReadFilter();
$this->_readFilter = new PHPExcel_Reader_DefaultReadFilter();
} // function __construct()
/**
@@ -223,37 +229,64 @@ class PHPExcel_Reader_CSV implements PHPExcel_Reader_IReader
fgets($fileHandle, 4) == "\xEF\xBB\xBF" ?
fseek($fileHandle, 3) : fseek($fileHandle, 0);
break;
case 'UTF-16LE':
fgets($fileHandle, 3) == "\xFF\xFE" ?
fseek($fileHandle, 2) : fseek($fileHandle, 0);
break;
case 'UTF-16BE':
fgets($fileHandle, 3) == "\xFE\xFF" ?
fseek($fileHandle, 2) : fseek($fileHandle, 0);
break;
case 'UTF-32LE':
fgets($fileHandle, 5) == "\xFF\xFE\x00\x00" ?
fseek($fileHandle, 4) : fseek($fileHandle, 0);
break;
case 'UTF-32BE':
fgets($fileHandle, 5) == "\x00\x00\xFE\xFF" ?
fseek($fileHandle, 4) : fseek($fileHandle, 0);
break;
default:
break;
}
// Loop through file
$currentRow = 0;
$rowData = array();
$escapeEnclosures = array( "\\" . $this->_enclosure,
$this->_enclosure . $this->_enclosure
);
// Set our starting row based on whether we're in contiguous mode or not
$currentRow = 1;
if ($this->_contiguous) {
$currentRow = ($this->_contiguousRow == -1) ? $objPHPExcel->getActiveSheet()->getHighestRow(): $this->_contiguousRow;
}
// Loop through each line of the file in turn
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)) {
$columnLetter = 'A';
foreach($rowData as $rowDatum) {
if ($rowDatum != '' && $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]);
$rowDatum = str_replace($escapeEnclosures, $this->_enclosure, $rowDatum);
// Convert encoding if necessary
if ($this->_inputEncoding !== 'UTF-8') {
$rowData[$i] = PHPExcel_Shared_String::ConvertEncoding($rowData[$i], 'UTF-8', $this->_inputEncoding);
$rowDatum = PHPExcel_Shared_String::ConvertEncoding($rowDatum, 'UTF-8', $this->_inputEncoding);
}
// Set cell value
$objPHPExcel->getActiveSheet()->getCell($columnLetter . $currentRow)->setValue($rowData[$i]);
$objPHPExcel->getActiveSheet()->getCell($columnLetter . $currentRow)->setValue($rowDatum);
}
++$columnLetter;
}
++$currentRow;
}
// Close file
fclose($fileHandle);
if ($this->_contiguous) {
$this->_contiguousRow = $currentRow;
}
// Return
return $objPHPExcel;
} // function loadIntoExisting()
@@ -348,4 +381,31 @@ class PHPExcel_Reader_CSV implements PHPExcel_Reader_IReader
$this->_sheetIndex = $pValue;
return $this;
} // function setSheetIndex()
/**
* Set Contiguous
*
* @access public
* @param string $pValue Input encoding
*/
public function setContiguous($contiguous = false)
{
$this->_contiguous = (bool)$contiguous;
if (!$contiguous) {
$this->_contiguousRow = -1;
}
return $this;
} // function setInputEncoding()
/**
* Get Contiguous
*
* @access public
* @return boolean
*/
public function getContiguous() {
return $this->_contiguous;
} // function getSheetIndex()
}

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
@@ -33,12 +33,6 @@ if (!defined('PHPEXCEL_ROOT')) {
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
PHPExcel_Autoloader::Register();
PHPExcel_Shared_ZipStreamWrapper::register();
// check mbstring.func_overload
if (ini_get('mbstring.func_overload') & 2) {
throw new Exception('Multibyte function overloading in PHP must be disabled for string functions (2).');
}
}
/**
@@ -46,7 +40,7 @@ if (!defined('PHPEXCEL_ROOT')) {
*
* @category PHPExcel
* @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Reader_DefaultReadFilter implements PHPExcel_Reader_IReadFilter
{

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
@@ -33,12 +33,6 @@ if (!defined('PHPEXCEL_ROOT')) {
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
PHPExcel_Autoloader::Register();
PHPExcel_Shared_ZipStreamWrapper::register();
// check mbstring.func_overload
if (ini_get('mbstring.func_overload') & 2) {
throw new Exception('Multibyte function overloading in PHP must be disabled for string functions (2).');
}
}
/**
@@ -46,7 +40,7 @@ if (!defined('PHPEXCEL_ROOT')) {
*
* @category PHPExcel
* @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Reader_Excel2003XML implements PHPExcel_Reader_IReader
{
@@ -64,13 +58,6 @@ class PHPExcel_Reader_Excel2003XML implements PHPExcel_Reader_IReader
*/
private $_loadSheetsOnly = null;
/**
* Sheet index to read
*
* @var int
*/
private $_sheetIndex;
/**
* Formats
*
@@ -99,7 +86,7 @@ class PHPExcel_Reader_Excel2003XML implements PHPExcel_Reader_IReader
* Set read data only
*
* @param boolean $pValue
* @return PHPExcel_Reader_Excel2007
* @return PHPExcel_Reader_Excel2003XML
*/
public function setReadDataOnly($pValue = false) {
$this->_readDataOnly = $pValue;
@@ -120,7 +107,7 @@ class PHPExcel_Reader_Excel2003XML implements PHPExcel_Reader_IReader
* Set which sheets to load
*
* @param mixed $value
* @return PHPExcel_Reader_Excel2007
* @return PHPExcel_Reader_Excel2003XML
*/
public function setLoadSheetsOnly($value = null)
{
@@ -132,7 +119,7 @@ class PHPExcel_Reader_Excel2003XML implements PHPExcel_Reader_IReader
/**
* Set all sheets to load
*
* @return PHPExcel_Reader_Excel2007
* @return PHPExcel_Reader_Excel2003XML
*/
public function setLoadAllSheets()
{
@@ -153,7 +140,7 @@ class PHPExcel_Reader_Excel2003XML implements PHPExcel_Reader_IReader
* Set read filter
*
* @param PHPExcel_Reader_IReadFilter $pValue
* @return PHPExcel_Reader_Excel2007
* @return PHPExcel_Reader_Excel2003XML
*/
public function setReadFilter(PHPExcel_Reader_IReadFilter $pValue) {
$this->_readFilter = $pValue;
@@ -164,7 +151,6 @@ class PHPExcel_Reader_Excel2003XML implements PHPExcel_Reader_IReader
* Create a new PHPExcel_Reader_Excel2003XML
*/
public function __construct() {
$this->_sheetIndex = 0;
$this->_readFilter = new PHPExcel_Reader_DefaultReadFilter();
}
@@ -188,7 +174,7 @@ class PHPExcel_Reader_Excel2003XML implements PHPExcel_Reader_IReader
//
$signature = array(
'<?xml version="1.0"?>',
'<?xml version="1.0"',
'<?mso-application progid="Excel.Sheet"?>'
);
@@ -202,16 +188,10 @@ class PHPExcel_Reader_Excel2003XML implements PHPExcel_Reader_IReader
$data = fread($fh, 2048);
fclose($fh);
$headers = explode("\n",$data);
$valid = true;
foreach($signature as $key => $match) {
if (isset($headers[$key])) {
$line = trim(rtrim($headers[$key], "\r\n"));
if ($line != $match) {
$valid = false;
break;
}
} else {
foreach($signature as $match) {
// every part of the signature must be present
if (strpos($data, $match) === false) {
$valid = false;
break;
}
@@ -220,6 +200,34 @@ class PHPExcel_Reader_Excel2003XML implements PHPExcel_Reader_IReader
return $valid;
}
/**
* Reads names of the worksheets from a file, without parsing the whole file to a PHPExcel object
*
* @param string $pFilename
* @throws Exception
*/
public function listWorksheetNames($pFilename)
{
// Check if file exists
if (!file_exists($pFilename)) {
throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
}
$worksheetNames = array();
$xml = simplexml_load_file($pFilename);
$namespaces = $xml->getNamespaces(true);
$xml_ss = $xml->children($namespaces['ss']);
foreach($xml_ss->Worksheet as $worksheet) {
$worksheet_ss = $worksheet->attributes($namespaces['ss']);
$worksheetNames[] = $worksheet_ss['Name'];
}
return $worksheetNames;
}
/**
* Loads PHPExcel from file
*
@@ -272,6 +280,11 @@ class PHPExcel_Reader_Excel2003XML implements PHPExcel_Reader_IReader
return $pixels;
}
private static function _hex2str($hex) {
return chr(hexdec($hex[1]));
}
/**
* Loads PHPExcel from file into PHPExcel instance
*
@@ -307,6 +320,9 @@ class PHPExcel_Reader_Excel2003XML implements PHPExcel_Reader_IReader
PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY
);
$timezoneObj = new DateTimeZone('Europe/London');
$GMT = new DateTimeZone('UTC');
// Check if file exists
if (!file_exists($pFilename)) {
@@ -315,48 +331,79 @@ class PHPExcel_Reader_Excel2003XML implements PHPExcel_Reader_IReader
$xml = simplexml_load_file($pFilename);
$namespaces = $xml->getNamespaces(true);
// echo '<pre>';
// print_r($namespaces);
// echo '</pre><hr />';
//
// echo '<pre>';
// print_r($xml);
// echo '</pre><hr />';
//
$docProps = $objPHPExcel->getProperties();
foreach($xml->DocumentProperties[0] as $propertyName => $propertyValue) {
switch ($propertyName) {
case 'Title' :
$docProps->setTitle($propertyValue);
break;
case 'Subject' :
$docProps->setSubject($propertyValue);
break;
case 'Author' :
$docProps->setCreator($propertyValue);
break;
case 'Created' :
$creationDate = strtotime($propertyValue);
$docProps->setCreated($creationDate);
break;
case 'LastAuthor' :
$docProps->setLastModifiedBy($propertyValue);
break;
case 'Company' :
$docProps->setCompany($propertyValue);
break;
case 'Category' :
$docProps->setCategory($propertyValue);
break;
case 'Keywords' :
$docProps->setKeywords($propertyValue);
break;
case 'Description' :
$docProps->setDescription($propertyValue);
break;
if (isset($xml->DocumentProperties[0])) {
foreach($xml->DocumentProperties[0] as $propertyName => $propertyValue) {
switch ($propertyName) {
case 'Title' :
$docProps->setTitle($propertyValue);
break;
case 'Subject' :
$docProps->setSubject($propertyValue);
break;
case 'Author' :
$docProps->setCreator($propertyValue);
break;
case 'Created' :
$creationDate = strtotime($propertyValue);
$docProps->setCreated($creationDate);
break;
case 'LastAuthor' :
$docProps->setLastModifiedBy($propertyValue);
break;
case 'LastSaved' :
$lastSaveDate = strtotime($propertyValue);
$docProps->setModified($lastSaveDate);
break;
case 'Company' :
$docProps->setCompany($propertyValue);
break;
case 'Category' :
$docProps->setCategory($propertyValue);
break;
case 'Manager' :
$docProps->setManager($propertyValue);
break;
case 'Keywords' :
$docProps->setKeywords($propertyValue);
break;
case 'Description' :
$docProps->setDescription($propertyValue);
break;
}
}
}
if (isset($xml->CustomDocumentProperties)) {
foreach($xml->CustomDocumentProperties[0] as $propertyName => $propertyValue) {
$propertyAttributes = $propertyValue->attributes($namespaces['dt']);
$propertyName = preg_replace_callback('/_x([0-9a-z]{4})_/','PHPExcel_Reader_Excel2003XML::_hex2str',$propertyName);
$propertyType = PHPExcel_DocumentProperties::PROPERTY_TYPE_UNKNOWN;
switch((string) $propertyAttributes) {
case 'string' :
$propertyType = PHPExcel_DocumentProperties::PROPERTY_TYPE_STRING;
$propertyValue = trim($propertyValue);
break;
case 'boolean' :
$propertyType = PHPExcel_DocumentProperties::PROPERTY_TYPE_BOOLEAN;
$propertyValue = (bool) $propertyValue;
break;
case 'integer' :
$propertyType = PHPExcel_DocumentProperties::PROPERTY_TYPE_INTEGER;
$propertyValue = intval($propertyValue);
break;
case 'float' :
$propertyType = PHPExcel_DocumentProperties::PROPERTY_TYPE_FLOAT;
$propertyValue = floatval($propertyValue);
break;
case 'dateTime.tz' :
$propertyType = PHPExcel_DocumentProperties::PROPERTY_TYPE_DATE;
$propertyValue = strtotime(trim($propertyValue));
break;
}
$docProps->setCustomProperty($propertyName,$propertyValue,$propertyType);
}
}
foreach($xml->Styles[0] as $style) {
$style_ss = $style->attributes($namespaces['ss']);
@@ -487,13 +534,17 @@ class PHPExcel_Reader_Excel2003XML implements PHPExcel_Reader_IReader
// echo '<hr />';
$worksheetID = 0;
foreach($xml->Worksheet as $worksheet) {
$xml_ss = $xml->children($namespaces['ss']);
foreach($xml_ss->Worksheet as $worksheet) {
$worksheet_ss = $worksheet->attributes($namespaces['ss']);
if ((isset($this->_loadSheetsOnly)) && (isset($worksheet_ss['Name'])) &&
(!in_array($worksheet_ss['Name'], $this->_loadSheetsOnly))) {
continue;
}
// echo '<h3>Worksheet: ',$worksheet_ss['Name'],'<h3>';
//
// Create new Worksheet
$objPHPExcel->createSheet();
$objPHPExcel->setActiveSheetIndex($worksheetID);
@@ -503,166 +554,220 @@ class PHPExcel_Reader_Excel2003XML implements PHPExcel_Reader_IReader
}
$columnID = 'A';
foreach($worksheet->Table->Column as $columnData) {
$columnData_ss = $columnData->attributes($namespaces['ss']);
if (isset($columnData_ss['Index'])) {
$columnID = PHPExcel_Cell::stringFromColumnIndex($columnData_ss['Index']-1);
}
if (isset($columnData_ss['Width'])) {
$columnWidth = $columnData_ss['Width'];
// echo '<b>Setting column width for '.$columnID.' to '.$columnWidth.'</b><br />';
$objPHPExcel->getActiveSheet()->getColumnDimension($columnID)->setWidth($columnWidth / 5.4);
}
++$columnID;
}
$rowID = 1;
foreach($worksheet->Table->Row as $rowData) {
$row_ss = $rowData->attributes($namespaces['ss']);
if (isset($row_ss['Index'])) {
$rowID = (integer) $row_ss['Index'];
}
// echo '<b>Row '.$rowID.'</b><br />';
if (isset($row_ss['StyleID'])) {
$rowStyle = $row_ss['StyleID'];
}
if (isset($row_ss['Height'])) {
$rowHeight = $row_ss['Height'];
// echo '<b>Setting row height to '.$rowHeight.'</b><br />';
$objPHPExcel->getActiveSheet()->getRowDimension($rowID)->setRowHeight($rowHeight);
}
$columnID = 'A';
foreach($rowData->Cell as $cell) {
$cell_ss = $cell->attributes($namespaces['ss']);
if (isset($cell_ss['Index'])) {
$columnID = PHPExcel_Cell::stringFromColumnIndex($cell_ss['Index']-1);
if (isset($worksheet->Table->Column)) {
foreach($worksheet->Table->Column as $columnData) {
$columnData_ss = $columnData->attributes($namespaces['ss']);
if (isset($columnData_ss['Index'])) {
$columnID = PHPExcel_Cell::stringFromColumnIndex($columnData_ss['Index']-1);
}
$cellRange = $columnID.$rowID;
if ((isset($cell_ss['MergeAcross'])) || (isset($cell_ss['MergeDown']))) {
$columnTo = $columnID;
if (isset($cell_ss['MergeAcross'])) {
$columnTo = PHPExcel_Cell::stringFromColumnIndex(PHPExcel_Cell::columnIndexFromString($columnID) + $cell_ss['MergeAcross'] -1);
}
$rowTo = $rowID;
if (isset($cell_ss['MergeDown'])) {
$rowTo = $rowTo + $cell_ss['MergeDown'];
}
$cellRange .= ':'.$columnTo.$rowTo;
$objPHPExcel->getActiveSheet()->mergeCells($cellRange);
}
$hasCalculatedValue = false;
$cellDataFormula = '';
if (isset($cell_ss['Formula'])) {
$cellDataFormula = $cell_ss['Formula'];
// added this as a check for array formulas
if (isset($cell_ss['ArrayRange'])) {
$cellDataCSEFormula = $cell_ss['ArrayRange'];
// echo "found an array formula at ".$columnID.$rowID."<br />";
}
$hasCalculatedValue = true;
}
if (isset($cell->Data)) {
$cellValue = $cellData = $cell->Data;
$type = PHPExcel_Cell_DataType::TYPE_NULL;
$cellData_ss = $cellData->attributes($namespaces['ss']);
if (isset($cellData_ss['Type'])) {
$cellDataType = $cellData_ss['Type'];
switch ($cellDataType) {
/*
const TYPE_STRING = 's';
const TYPE_FORMULA = 'f';
const TYPE_NUMERIC = 'n';
const TYPE_BOOL = 'b';
const TYPE_NULL = 's';
const TYPE_INLINE = 'inlineStr';
const TYPE_ERROR = 'e';
*/
case 'String' :
$type = PHPExcel_Cell_DataType::TYPE_STRING;
break;
case 'Number' :
$type = PHPExcel_Cell_DataType::TYPE_NUMERIC;
$cellValue = (float) $cellValue;
if (floor($cellValue) == $cellValue) {
$cellValue = (integer) $cellValue;
}
break;
case 'Boolean' :
$type = PHPExcel_Cell_DataType::TYPE_BOOL;
$cellValue = ($cellValue != 0);
break;
case 'DateTime' :
$type = PHPExcel_Cell_DataType::TYPE_NUMERIC;
$cellValue = PHPExcel_Shared_Date::PHPToExcel(strtotime($cellValue));
break;
case 'Error' :
$type = PHPExcel_Cell_DataType::TYPE_ERROR;
break;
}
}
if ($hasCalculatedValue) {
$type = PHPExcel_Cell_DataType::TYPE_FORMULA;
$columnNumber = PHPExcel_Cell::columnIndexFromString($columnID);
// Convert R1C1 style references to A1 style references (but only when not quoted)
$temp = explode('"',$cellDataFormula);
foreach($temp as $key => &$value) {
// Only replace in alternate array entries (i.e. non-quoted blocks)
if (($key % 2) == 0) {
preg_match_all('/(R(\[?-?\d*\]?))(C(\[?-?\d*\]?))/',$value, $cellReferences,PREG_SET_ORDER+PREG_OFFSET_CAPTURE);
// Reverse the matches array, otherwise all our offsets will become incorrect if we modify our way
// through the formula from left to right. Reversing means that we work right to left.through
// the formula
$cellReferences = array_reverse($cellReferences);
// Loop through each R1C1 style reference in turn, converting it to its A1 style equivalent,
// then modify the formula to use that new reference
foreach($cellReferences as $cellReference) {
$rowReference = $cellReference[2][0];
// Empty R reference is the current row
if ($rowReference == '') $rowReference = $rowID;
// Bracketed R references are relative to the current row
if ($rowReference{0} == '[') $rowReference = $rowID + trim($rowReference,'[]');
$columnReference = $cellReference[4][0];
// Empty C reference is the current column
if ($columnReference == '') $columnReference = $columnNumber;
// Bracketed C references are relative to the current column
if ($columnReference{0} == '[') $columnReference = $columnNumber + trim($columnReference,'[]');
$A1CellReference = PHPExcel_Cell::stringFromColumnIndex($columnReference-1).$rowReference;
$value = substr_replace($value,$A1CellReference,$cellReference[0][1],strlen($cellReference[0][0]));
}
}
}
unset($value);
// Then rebuild the formula string
$cellDataFormula = implode('"',$temp);
}
// echo 'Cell '.$columnID.$rowID.' is a '.$type.' with a value of '.(($hasCalculatedValue) ? $cellDataFormula : $cellValue).'<br />';
//
$objPHPExcel->getActiveSheet()->getCell($columnID.$rowID)->setValueExplicit((($hasCalculatedValue) ? $cellDataFormula : $cellValue),$type);
if ($hasCalculatedValue) {
// echo 'Forumla result is '.$cellValue.'<br />';
$objPHPExcel->getActiveSheet()->getCell($columnID.$rowID)->setCalculatedValue($cellValue);
}
}
if (isset($cell_ss['StyleID'])) {
$style = (string) $cell_ss['StyleID'];
// echo 'Cell style for '.$columnID.$rowID.' is '.$style.'<br />';
if ((isset($this->_styles[$style])) && (count($this->_styles[$style]) > 0)) {
// echo 'Cell '.$columnID.$rowID.'<br />';
// print_r($this->_styles[$style]);
// echo '<br />';
if (!$objPHPExcel->getActiveSheet()->cellExists($columnID.$rowID)) {
$objPHPExcel->getActiveSheet()->getCell($columnID.$rowID)->setValue(NULL);
}
$objPHPExcel->getActiveSheet()->getStyle($cellRange)->applyFromArray($this->_styles[$style]);
}
if (isset($columnData_ss['Width'])) {
$columnWidth = $columnData_ss['Width'];
// echo '<b>Setting column width for '.$columnID.' to '.$columnWidth.'</b><br />';
$objPHPExcel->getActiveSheet()->getColumnDimension($columnID)->setWidth($columnWidth / 5.4);
}
++$columnID;
}
++$rowID;
}
$rowID = 1;
if (isset($worksheet->Table->Row)) {
foreach($worksheet->Table->Row as $rowData) {
$rowHasData = false;
$row_ss = $rowData->attributes($namespaces['ss']);
if (isset($row_ss['Index'])) {
$rowID = (integer) $row_ss['Index'];
}
// echo '<b>Row '.$rowID.'</b><br />';
$columnID = 'A';
foreach($rowData->Cell as $cell) {
$cell_ss = $cell->attributes($namespaces['ss']);
if (isset($cell_ss['Index'])) {
$columnID = PHPExcel_Cell::stringFromColumnIndex($cell_ss['Index']-1);
}
$cellRange = $columnID.$rowID;
if (!is_null($this->getReadFilter())) {
if (!$this->getReadFilter()->readCell($columnID, $rowID, $worksheetName)) {
continue;
}
}
if ((isset($cell_ss['MergeAcross'])) || (isset($cell_ss['MergeDown']))) {
$columnTo = $columnID;
if (isset($cell_ss['MergeAcross'])) {
$columnTo = PHPExcel_Cell::stringFromColumnIndex(PHPExcel_Cell::columnIndexFromString($columnID) + $cell_ss['MergeAcross'] -1);
}
$rowTo = $rowID;
if (isset($cell_ss['MergeDown'])) {
$rowTo = $rowTo + $cell_ss['MergeDown'];
}
$cellRange .= ':'.$columnTo.$rowTo;
$objPHPExcel->getActiveSheet()->mergeCells($cellRange);
}
$cellIsSet = $hasCalculatedValue = false;
$cellDataFormula = '';
if (isset($cell_ss['Formula'])) {
$cellDataFormula = $cell_ss['Formula'];
// added this as a check for array formulas
if (isset($cell_ss['ArrayRange'])) {
$cellDataCSEFormula = $cell_ss['ArrayRange'];
// echo "found an array formula at ".$columnID.$rowID."<br />";
}
$hasCalculatedValue = true;
}
if (isset($cell->Data)) {
$cellValue = $cellData = $cell->Data;
$type = PHPExcel_Cell_DataType::TYPE_NULL;
$cellData_ss = $cellData->attributes($namespaces['ss']);
if (isset($cellData_ss['Type'])) {
$cellDataType = $cellData_ss['Type'];
switch ($cellDataType) {
/*
const TYPE_STRING = 's';
const TYPE_FORMULA = 'f';
const TYPE_NUMERIC = 'n';
const TYPE_BOOL = 'b';
const TYPE_NULL = 's';
const TYPE_INLINE = 'inlineStr';
const TYPE_ERROR = 'e';
*/
case 'String' :
$type = PHPExcel_Cell_DataType::TYPE_STRING;
break;
case 'Number' :
$type = PHPExcel_Cell_DataType::TYPE_NUMERIC;
$cellValue = (float) $cellValue;
if (floor($cellValue) == $cellValue) {
$cellValue = (integer) $cellValue;
}
break;
case 'Boolean' :
$type = PHPExcel_Cell_DataType::TYPE_BOOL;
$cellValue = ($cellValue != 0);
break;
case 'DateTime' :
$type = PHPExcel_Cell_DataType::TYPE_NUMERIC;
$cellValue = PHPExcel_Shared_Date::PHPToExcel(strtotime($cellValue));
break;
case 'Error' :
$type = PHPExcel_Cell_DataType::TYPE_ERROR;
break;
}
}
if ($hasCalculatedValue) {
// echo 'FORMULA<br />';
$type = PHPExcel_Cell_DataType::TYPE_FORMULA;
$columnNumber = PHPExcel_Cell::columnIndexFromString($columnID);
if (substr($cellDataFormula,0,3) == 'of:') {
$cellDataFormula = substr($cellDataFormula,3);
// echo 'Before: ',$cellDataFormula,'<br />';
$temp = explode('"',$cellDataFormula);
$key = false;
foreach($temp as &$value) {
// Only replace in alternate array entries (i.e. non-quoted blocks)
if ($key = !$key) {
$value = str_replace(array('[.','.',']'),'',$value);
}
}
} else {
// Convert R1C1 style references to A1 style references (but only when not quoted)
// echo 'Before: ',$cellDataFormula,'<br />';
$temp = explode('"',$cellDataFormula);
$key = false;
foreach($temp as &$value) {
// Only replace in alternate array entries (i.e. non-quoted blocks)
if ($key = !$key) {
preg_match_all('/(R(\[?-?\d*\]?))(C(\[?-?\d*\]?))/',$value, $cellReferences,PREG_SET_ORDER+PREG_OFFSET_CAPTURE);
// Reverse the matches array, otherwise all our offsets will become incorrect if we modify our way
// through the formula from left to right. Reversing means that we work right to left.through
// the formula
$cellReferences = array_reverse($cellReferences);
// Loop through each R1C1 style reference in turn, converting it to its A1 style equivalent,
// then modify the formula to use that new reference
foreach($cellReferences as $cellReference) {
$rowReference = $cellReference[2][0];
// Empty R reference is the current row
if ($rowReference == '') $rowReference = $rowID;
// Bracketed R references are relative to the current row
if ($rowReference{0} == '[') $rowReference = $rowID + trim($rowReference,'[]');
$columnReference = $cellReference[4][0];
// Empty C reference is the current column
if ($columnReference == '') $columnReference = $columnNumber;
// Bracketed C references are relative to the current column
if ($columnReference{0} == '[') $columnReference = $columnNumber + trim($columnReference,'[]');
$A1CellReference = PHPExcel_Cell::stringFromColumnIndex($columnReference-1).$rowReference;
$value = substr_replace($value,$A1CellReference,$cellReference[0][1],strlen($cellReference[0][0]));
}
}
}
}
unset($value);
// Then rebuild the formula string
$cellDataFormula = implode('"',$temp);
// echo 'After: ',$cellDataFormula,'<br />';
}
// echo 'Cell '.$columnID.$rowID.' is a '.$type.' with a value of '.(($hasCalculatedValue) ? $cellDataFormula : $cellValue).'<br />';
//
$objPHPExcel->getActiveSheet()->getCell($columnID.$rowID)->setValueExplicit((($hasCalculatedValue) ? $cellDataFormula : $cellValue),$type);
if ($hasCalculatedValue) {
// echo 'Formula result is '.$cellValue.'<br />';
$objPHPExcel->getActiveSheet()->getCell($columnID.$rowID)->setCalculatedValue($cellValue);
}
$cellIsSet = $rowHasData = true;
}
if (isset($cell->Comment)) {
// echo '<b>comment found</b><br />';
$commentAttributes = $cell->Comment->attributes($namespaces['ss']);
$author = 'unknown';
if (isset($commentAttributes->Author)) {
$author = (string)$commentAttributes->Author;
// echo 'Author: ',$author,'<br />';
}
$node = $cell->Comment->Data->asXML();
// $annotation = str_replace('html:','',substr($node,49,-10));
// echo $annotation,'<br />';
$annotation = strip_tags($node);
// echo 'Annotation: ',$annotation,'<br />';
$objPHPExcel->getActiveSheet()->getComment( $columnID.$rowID )
->setAuthor( $author )
->setText($this->_parseRichText($annotation) );
}
if (($cellIsSet) && (isset($cell_ss['StyleID']))) {
$style = (string) $cell_ss['StyleID'];
// echo 'Cell style for '.$columnID.$rowID.' is '.$style.'<br />';
if ((isset($this->_styles[$style])) && (count($this->_styles[$style]) > 0)) {
// echo 'Cell '.$columnID.$rowID.'<br />';
// print_r($this->_styles[$style]);
// echo '<br />';
if (!$objPHPExcel->getActiveSheet()->cellExists($columnID.$rowID)) {
$objPHPExcel->getActiveSheet()->getCell($columnID.$rowID)->setValue(NULL);
}
$objPHPExcel->getActiveSheet()->getStyle($cellRange)->applyFromArray($this->_styles[$style]);
}
}
++$columnID;
}
if ($rowHasData) {
if (isset($row_ss['StyleID'])) {
$rowStyle = $row_ss['StyleID'];
}
if (isset($row_ss['Height'])) {
$rowHeight = $row_ss['Height'];
// echo '<b>Setting row height to '.$rowHeight.'</b><br />';
$objPHPExcel->getActiveSheet()->getRowDimension($rowID)->setRowHeight($rowHeight);
}
}
++$rowID;
}
}
++$worksheetID;
}
@@ -671,23 +776,12 @@ class PHPExcel_Reader_Excel2003XML implements PHPExcel_Reader_IReader
return $objPHPExcel;
}
/**
* Get sheet index
*
* @return int
*/
public function getSheetIndex() {
return $this->_sheetIndex;
private function _parseRichText($is = '') {
$value = new PHPExcel_RichText();
$value->createText($is);
return $value;
}
/**
* Set sheet index
*
* @param int $pValue Sheet index
* @return PHPExcel_Reader_Excel2003XML
*/
public function setSheetIndex($pValue = 0) {
$this->_sheetIndex = $pValue;
return $this;
}
}

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
@@ -33,34 +33,31 @@ if (!defined('PHPEXCEL_ROOT')) {
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
PHPExcel_Autoloader::Register();
PHPExcel_Shared_ZipStreamWrapper::register();
// check mbstring.func_overload
if (ini_get('mbstring.func_overload') & 2) {
throw new Exception('Multibyte function overloading in PHP must be disabled for string functions (2).');
}
}
/**
* PHPExcel_Reader_Excel2007
* PHPExcel_Reader_Excel2007
*
* @category PHPExcel
* @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @category PHPExcel
* @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
{
/**
* Read data only?
* Read data only?
* Identifies whether the Reader should only read data values for cells, and ignore any formatting information;
* or whether it should read both data and formatting
*
* @var boolean
* @var boolean
*/
private $_readDataOnly = false;
/**
* Restict which sheets should be loaded?
* Restrict which sheets should be loaded?
* This property holds an array of worksheet names to be loaded. If null, then all worksheets will be loaded.
*
* @var array
* @var array of string
*/
private $_loadSheetsOnly = null;
@@ -71,23 +68,40 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
*/
private $_readFilter = null;
/**
* PHPExcel_ReferenceHelper instance
*
* @var PHPExcel_ReferenceHelper
*/
private $_referenceHelper = null;
/**
* Read data only?
* PHPExcel_Reader_Excel2007_Theme instance
*
* @return boolean
* @var PHPExcel_Reader_Excel2007_Theme
*/
private static $_theme = null;
/**
* Read data only?
* If this is true, then the Reader will only read data values for cells, it will not read any formatting information.
* If false (the default) it will read data and formatting.
*
* @return boolean
*/
public function getReadDataOnly() {
return $this->_readDataOnly;
}
/**
* Set read data only
* Set read data only
* Set to true, to advise the Reader only to read data values for cells, and to ignore any formatting information.
* Set to false (the default) to advise the Reader to read both data and formatting for cells.
*
* @param boolean $pValue
* @return PHPExcel_Reader_Excel2007
* @param boolean $pValue
*
* @return PHPExcel_Reader_Excel2007
*/
public function setReadDataOnly($pValue = false) {
$this->_readDataOnly = $pValue;
@@ -95,9 +109,11 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
}
/**
* Get which sheets to load
* Get which sheets to load
* Returns either an array of worksheet names (the list of worksheets that should be loaded), or a null
* indicating that all worksheets in the workbook should be loaded.
*
* @return mixed
* @return mixed
*/
public function getLoadSheetsOnly()
{
@@ -105,10 +121,13 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
}
/**
* Set which sheets to load
* Set which sheets to load
*
* @param mixed $value
* @return PHPExcel_Reader_Excel2007
* @param mixed $value
* This should be either an array of worksheet names to be loaded, or a string containing a single worksheet name.
* If NULL, then it tells the Reader to read all worksheets in the workbook
*
* @return PHPExcel_Reader_Excel2007
*/
public function setLoadSheetsOnly($value = null)
{
@@ -118,9 +137,10 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
}
/**
* Set all sheets to load
* Set all sheets to load
* Tells the Reader to load all worksheets from the workbook.
*
* @return PHPExcel_Reader_Excel2007
* @return PHPExcel_Reader_Excel2007
*/
public function setLoadAllSheets()
{
@@ -174,39 +194,47 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
}
$xl = false;
// Load file
$zip = new ZipArchive;
if ($zip->open($pFilename) === true) {
// check if it is an OOXML archive
$rels = simplexml_load_string($this->_getFromZipArchive($zip, "_rels/.rels"));
foreach ($rels->Relationship as $rel) {
switch ($rel["Type"]) {
case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument":
if (basename($rel["Target"]) == 'workbook.xml') {
$xl = true;
}
break;
}
}
$zip->close();
return ($rels !== false);
}
return false;
return $xl;
}
private function _castToBool($c) {
private static function _castToBool($c) {
// echo 'Initial Cast to Boolean<br />';
$value = isset($c->v) ? (string) $c->v : null;
if ($value == '0') {
$value = false;
return false;
} elseif ($value == '1') {
$value = true;
return true;
} else {
$value = (bool)$c->v;
return (bool)$c->v;
}
return $value;
} // function _castToBool()
private function _castToError($c) {
private static function _castToError($c) {
// echo 'Initial Cast to Error<br />';
return isset($c->v) ? (string) $c->v : null;;
} // function _castToError()
private function _castToString($c) {
private static function _castToString($c) {
// echo 'Initial Cast to String<br />';
return isset($c->v) ? (string) $c->v : null;;
} // function _castToString()
@@ -216,7 +244,7 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
// echo '$c->f is '.$c->f.'<br />';
$cellDataType = 'f';
$value = "={$c->f}";
$calculatedValue = $this->$castBaseType($c);
$calculatedValue = self::$castBaseType($c);
// Shared formula?
if (isset($c->f['t']) && strtolower((string)$c->f['t']) == 'shared') {
@@ -275,17 +303,48 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
$contents = $archive->getFromName(substr($fileName, 1));
}
/*
if (strpos($contents, '<?xml') !== false && strpos($contents, '<?xml') !== 0)
{
$contents = substr($contents, strpos($contents, '<?xml'));
}
var_dump($fileName);
var_dump($contents);
*/
return $contents;
}
/**
* Reads names of the worksheets from a file, without parsing the whole file to a PHPExcel object
*
* @param string $pFilename
* @throws Exception
*/
public function listWorksheetNames($pFilename)
{
// Check if file exists
if (!file_exists($pFilename)) {
throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
}
$worksheetNames = array();
$zip = new ZipArchive;
$zip->open($pFilename);
$rels = simplexml_load_string($this->_getFromZipArchive($zip, "_rels/.rels")); //~ http://schemas.openxmlformats.org/package/2006/relationships");
foreach ($rels->Relationship as $rel) {
switch ($rel["Type"]) {
case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument":
$xmlWorkbook = simplexml_load_string($this->_getFromZipArchive($zip, "{$rel['Target']}")); //~ http://schemas.openxmlformats.org/spreadsheetml/2006/main");
if ($xmlWorkbook->sheets) {
foreach ($xmlWorkbook->sheets->sheet as $eleSheet) {
// Check if sheet should be skipped
$worksheetNames[] = (string) $eleSheet["name"];
}
}
}
}
$zip->close();
return $worksheetNames;
}
/**
* Loads PHPExcel from file
*
@@ -309,6 +368,44 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
$zip = new ZipArchive;
$zip->open($pFilename);
// Read the theme first, because we need the colour scheme when reading the styles
$wbRels = simplexml_load_string($this->_getFromZipArchive($zip, "xl/_rels/workbook.xml.rels")); //~ http://schemas.openxmlformats.org/package/2006/relationships");
foreach ($wbRels->Relationship as $rel) {
switch ($rel["Type"]) {
case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme":
$themeOrderArray = array('lt1','dk1','lt2','dk2');
$themeOrderAdditional = count($themeOrderArray);
$xmlTheme = simplexml_load_string($this->_getFromZipArchive($zip, "xl/{$rel['Target']}"));
if (is_object($xmlTheme)) {
$xmlThemeName = $xmlTheme->attributes();
$xmlTheme = $xmlTheme->children("http://schemas.openxmlformats.org/drawingml/2006/main");
$themeName = (string)$xmlThemeName['name'];
$colourScheme = $xmlTheme->themeElements->clrScheme->attributes();
$colourSchemeName = (string)$colourScheme['name'];
$colourScheme = $xmlTheme->themeElements->clrScheme->children("http://schemas.openxmlformats.org/drawingml/2006/main");
$themeColours = array();
foreach ($colourScheme as $k => $xmlColour) {
$themePos = array_search($k,$themeOrderArray);
if ($themePos === false) {
$themePos = $themeOrderAdditional++;
}
if (isset($xmlColour->sysClr)) {
$xmlColourData = $xmlColour->sysClr->attributes();
$themeColours[$themePos] = $xmlColourData['lastClr'];
} elseif (isset($xmlColour->srgbClr)) {
$xmlColourData = $xmlColour->srgbClr->attributes();
$themeColours[$themePos] = $xmlColourData['val'];
}
}
self::$_theme = new PHPExcel_Reader_Excel2007_Theme($themeName,$colourSchemeName,$themeColours);
}
break;
}
}
$rels = simplexml_load_string($this->_getFromZipArchive($zip, "_rels/.rels")); //~ http://schemas.openxmlformats.org/package/2006/relationships");
foreach ($rels->Relationship as $rel) {
switch ($rel["Type"]) {
@@ -345,8 +442,19 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties":
$xmlCore = simplexml_load_string($this->_getFromZipArchive($zip, "{$rel['Target']}"));
if (is_object($xmlCore)) {
$xmlCore->registerXPathNamespace("vt", "http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes");
$docProps = $excel->getProperties();
foreach ($xmlCore as $xmlProperty) {
$cellDataOfficeAttributes = $xmlProperty->attributes();
if (isset($cellDataOfficeAttributes['name'])) {
$propertyName = (string) $cellDataOfficeAttributes['name'];
$cellDataOfficeChildren = $xmlProperty->children('http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes');
$attributeType = $cellDataOfficeChildren->getName();
$attributeValue = (string) $cellDataOfficeChildren->{$attributeType};
$attributeValue = PHPExcel_DocumentProperties::convertProperty($attributeValue,$attributeType);
$attributeType = PHPExcel_DocumentProperties::convertPropertyType($attributeType);
$docProps->setCustomProperty($propertyName,$attributeValue,$attributeType);
}
}
}
break;
@@ -418,7 +526,7 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
// add style to cellXf collection
$objStyle = new PHPExcel_Style;
$this->_readStyle($objStyle, $style);
self::_readStyle($objStyle, $style);
$excel->addCellXf($objStyle);
}
@@ -445,7 +553,7 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
// add style to cellStyleXf collection
$objStyle = new PHPExcel_Style;
$this->_readStyle($objStyle, $cellStyle);
self::_readStyle($objStyle, $cellStyle);
$excel->addCellStyleXf($objStyle);
}
}
@@ -455,7 +563,7 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
if ($xmlStyles->dxfs) {
foreach ($xmlStyles->dxfs->dxf as $dxf) {
$style = new PHPExcel_Style;
$this->_readStyle($style, $dxf);
self::_readStyle($style, $dxf);
$dxfs[] = $style;
}
}
@@ -467,7 +575,7 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
if (isset($cellStyles[intval($cellStyle['xfId'])])) {
// Set default style
$style = new PHPExcel_Style;
$this->_readStyle($style, $cellStyles[intval($cellStyle['xfId'])]);
self::_readStyle($style, $cellStyles[intval($cellStyle['xfId'])]);
// normal style, currently not using it for anything
}
@@ -710,7 +818,7 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
case "b":
// echo 'Boolean<br />';
if (!isset($c->f)) {
$value = $this->_castToBool($c);
$value = self::_castToBool($c);
} else {
// Formula
$this->_castToFormula($c,$r,$cellDataType,$value,$calculatedValue,$sharedFormulas,'_castToBool');
@@ -730,7 +838,7 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
case "e":
// echo 'Error<br />';
if (!isset($c->f)) {
$value = $this->_castToError($c);
$value = self::_castToError($c);
} else {
// Formula
$this->_castToFormula($c,$r,$cellDataType,$value,$calculatedValue,$sharedFormulas,'_castToError');
@@ -743,7 +851,7 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
// echo 'Default<br />';
if (!isset($c->f)) {
// echo 'Not a Formula<br />';
$value = $this->_castToString($c);
$value = self::_castToString($c);
} else {
// echo 'Treat as Formula<br />';
// Formula
@@ -1267,7 +1375,11 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
// Extract range
$extractedRange = (string)$definedName;
$extractedRange = preg_replace('/\'(\w+)\'\!/', '', $extractedRange);
$extractedRange = str_replace('$', '', $extractedRange);
if (($spos = strpos($extractedRange,'!')) !== false) {
$extractedRange = substr($extractedRange,0,$spos).str_replace('$', '', substr($extractedRange,$spos));
} else {
$extractedRange = str_replace('$', '', $extractedRange);
}
// Valid range?
if (stripos((string)$definedName, '#REF!') !== false || $extractedRange == '') {
@@ -1330,7 +1442,11 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
// Extract range
$extractedRange = (string)$definedName;
$extractedRange = preg_replace('/\'(\w+)\'\!/', '', $extractedRange);
$extractedRange = str_replace('$', '', $extractedRange);
if (($spos = strpos($extractedRange,'!')) !== false) {
$extractedRange = substr($extractedRange,0,$spos).str_replace('$', '', substr($extractedRange,$spos));
} else {
$extractedRange = str_replace('$', '', $extractedRange);
}
// Valid range?
if (stripos((string)$definedName, '#REF!') !== false || $extractedRange == '') {
@@ -1407,18 +1523,34 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
}
$zip->close();
return $excel;
}
private function _readColor($color) {
private static function _readColor($color, $background=false) {
if (isset($color["rgb"])) {
return (string)$color["rgb"];
} else if (isset($color["indexed"])) {
return PHPExcel_Style_Color::indexedColor($color["indexed"])->getARGB();
return PHPExcel_Style_Color::indexedColor($color["indexed"],$background)->getARGB();
} else if (isset($color["theme"])) {
if (!is_null(self::$_theme)) {
$returnColour = self::$_theme->getColourByIndex((int)$color["theme"]);
if (isset($color["tint"])) {
$tintAdjust = (float) $color["tint"];
$returnColour = PHPExcel_Style_Color::changeBrightness($returnColour, $tintAdjust);
}
return 'FF'.$returnColour;
}
}
if ($background) {
return 'FFFFFFFF';
}
return 'FF000000';
}
private function _readStyle($docStyle, $style) {
private static function _readStyle($docStyle, $style) {
// format code
if (isset($style->numFmt)) {
$docStyle->getNumberFormat()->setFormatCode($style->numFmt);
@@ -1437,7 +1569,7 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
if (isset($style->font->strike)) {
$docStyle->getFont()->setStrikethrough(!isset($style->font->strike["val"]) || $style->font->strike["val"] == 'true' || $style->font->strike["val"] == '1');
}
$docStyle->getFont()->getColor()->setARGB($this->_readColor($style->font->color));
$docStyle->getFont()->getColor()->setARGB(self::_readColor($style->font->color));
if (isset($style->font->u) && !isset($style->font->u["val"])) {
$docStyle->getFont()->setUnderline(PHPExcel_Style_Font::UNDERLINE_SINGLE);
@@ -1460,21 +1592,23 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
if (isset($style->fill)) {
if ($style->fill->gradientFill) {
$gradientFill = $style->fill->gradientFill[0];
$docStyle->getFill()->setFillType((string) $gradientFill["type"]);
if(!empty($gradientFill["type"])) {
$docStyle->getFill()->setFillType((string) $gradientFill["type"]);
}
$docStyle->getFill()->setRotation(floatval($gradientFill["degree"]));
$gradientFill->registerXPathNamespace("sml", "http://schemas.openxmlformats.org/spreadsheetml/2006/main");
$docStyle->getFill()->getStartColor()->setARGB($this->_readColor( self::array_item($gradientFill->xpath("sml:stop[@position=0]"))->color) );
$docStyle->getFill()->getEndColor()->setARGB($this->_readColor( self::array_item($gradientFill->xpath("sml:stop[@position=1]"))->color) );
$docStyle->getFill()->getStartColor()->setARGB(self::_readColor( self::array_item($gradientFill->xpath("sml:stop[@position=0]"))->color) );
$docStyle->getFill()->getEndColor()->setARGB(self::_readColor( self::array_item($gradientFill->xpath("sml:stop[@position=1]"))->color) );
} elseif ($style->fill->patternFill) {
$patternType = (string)$style->fill->patternFill["patternType"] != '' ? (string)$style->fill->patternFill["patternType"] : 'solid';
$docStyle->getFill()->setFillType($patternType);
if ($style->fill->patternFill->fgColor) {
$docStyle->getFill()->getStartColor()->setARGB($this->_readColor($style->fill->patternFill->fgColor));
$docStyle->getFill()->getStartColor()->setARGB(self::_readColor($style->fill->patternFill->fgColor,true));
} else {
$docStyle->getFill()->getStartColor()->setARGB('FF000000');
}
if ($style->fill->patternFill->bgColor) {
$docStyle->getFill()->getEndColor()->setARGB($this->_readColor($style->fill->patternFill->bgColor));
$docStyle->getFill()->getEndColor()->setARGB(self::_readColor($style->fill->patternFill->bgColor,true));
}
}
}
@@ -1498,11 +1632,11 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
} elseif ($diagonalUp == true && $diagonalDown == true) {
$docStyle->getBorders()->setDiagonalDirection(PHPExcel_Style_Borders::DIAGONAL_BOTH);
}
$this->_readBorder($docStyle->getBorders()->getLeft(), $style->border->left);
$this->_readBorder($docStyle->getBorders()->getRight(), $style->border->right);
$this->_readBorder($docStyle->getBorders()->getTop(), $style->border->top);
$this->_readBorder($docStyle->getBorders()->getBottom(), $style->border->bottom);
$this->_readBorder($docStyle->getBorders()->getDiagonal(), $style->border->diagonal);
self::_readBorder($docStyle->getBorders()->getLeft(), $style->border->left);
self::_readBorder($docStyle->getBorders()->getRight(), $style->border->right);
self::_readBorder($docStyle->getBorders()->getTop(), $style->border->top);
self::_readBorder($docStyle->getBorders()->getBottom(), $style->border->bottom);
self::_readBorder($docStyle->getBorders()->getDiagonal(), $style->border->diagonal);
}
// alignment
@@ -1543,12 +1677,12 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
}
}
private function _readBorder($docBorder, $eleBorder) {
private static function _readBorder($docBorder, $eleBorder) {
if (isset($eleBorder["style"])) {
$docBorder->setBorderStyle((string) $eleBorder["style"]);
}
if (isset($eleBorder->color)) {
$docBorder->getColor()->setARGB($this->_readColor($eleBorder->color));
$docBorder->getColor()->setARGB(self::_readColor($eleBorder->color));
}
}
@@ -1574,7 +1708,7 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
}
if (isset($run->rPr->color)) {
$objText->getFont()->setColor( new PHPExcel_Style_Color( $this->_readColor($run->rPr->color) ) );
$objText->getFont()->setColor( new PHPExcel_Style_Color( self::_readColor($run->rPr->color) ) );
}
if ( (isset($run->rPr->b["val"]) && ((string) $run->rPr->b["val"] == 'true' || (string) $run->rPr->b["val"] == '1'))
@@ -1623,11 +1757,9 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
}
private static function toCSSArray($style) {
$style = str_replace("\r", "", $style);
$style = str_replace("\n", "", $style);
$style = str_replace(array("\r","\n"), "", $style);
$temp = explode(';', $style);
$style = array();
foreach ($temp as $item) {
$item = explode(':', $item);

View File

@@ -0,0 +1,124 @@
<?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_Excel2007
* @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 1.7.6, 2011-02-27
*/
/**
* PHPExcel_Reader_Excel2007_Theme
*
* @category PHPExcel
* @package PHPExcel_Reader_Excel2007
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Reader_Excel2007_Theme
{
/**
* Theme Name
*
* @var string
*/
private $_themeName;
/**
* Colour Scheme Name
*
* @var string
*/
private $_colourSchemeName;
/**
* Colour Map indexed by position
*
* @var array of string
*/
private $_colourMapValues;
/**
* Colour Map
*
* @var array of string
*/
private $_colourMap;
/**
* Create a new PHPExcel_Theme
*
*/
public function __construct($themeName,$colourSchemeName,$colourMap)
{
// Initialise values
$this->_themeName = $themeName;
$this->_colourSchemeName = $colourSchemeName;
$this->_colourMap = $colourMap;
}
/**
* Get Theme Name
*
* @return string
*/
public function getThemeName()
{
return $this->_themeName;
}
/**
* Get colour Scheme Name
*
* @return string
*/
public function getColourSchemeName() {
return $this->_colourSchemeName;
}
/**
* Get colour Map Value by Position
*
* @return string
*/
public function getColourByIndex($index=0) {
if (isset($this->_colourMap[$index])) {
return $this->_colourMap[$index];
}
return null;
}
/**
* Implement PHP __clone to create a deep clone, not just a shallow copy.
*/
public function __clone() {
$vars = get_object_vars($this);
foreach ($vars as $key => $value) {
if ((is_object($value)) && ($key != '_parent')) {
$this->$key = clone $value;
} else {
$this->$key = $value;
}
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Reader_Excel5
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
/**
@@ -30,7 +30,7 @@
*
* @category PHPExcel
* @package PHPExcel_Reader_Excel5
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Reader_Excel5_Escher
{
@@ -108,9 +108,8 @@ class PHPExcel_Reader_Excel5_Escher
// Parse Escher stream
while ($this->_pos < $this->_dataSize) {
// offset: 2; size: 2: Record Type
$fbt = $this->_GetInt2d($this->_data, $this->_pos + 2);
$fbt = PHPExcel_Reader_Excel5::_GetInt2d($this->_data, $this->_pos + 2);
switch ($fbt) {
case self::DGGCONTAINER: $this->_readDggContainer(); break;
@@ -144,15 +143,15 @@ class PHPExcel_Reader_Excel5_Escher
private function _readDefault()
{
// offset 0; size: 2; recVer and recInstance
$verInstance = $this->_GetInt2d($this->_data, $this->_pos);
$verInstance = PHPExcel_Reader_Excel5::_GetInt2d($this->_data, $this->_pos);
// offset: 2; size: 2: Record Type
$fbt = $this->_GetInt2d($this->_data, $this->_pos + 2);
$fbt = PHPExcel_Reader_Excel5::_GetInt2d($this->_data, $this->_pos + 2);
// bit: 0-3; mask: 0x000F; recVer
$recVer = (0x000F & $verInstance) >> 0;
$length = $this->_GetInt4d($this->_data, $this->_pos + 4);
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4);
$recordData = substr($this->_data, $this->_pos + 8, $length);
// move stream pointer to next record
@@ -164,7 +163,7 @@ class PHPExcel_Reader_Excel5_Escher
*/
private function _readDggContainer()
{
$length = $this->_GetInt4d($this->_data, $this->_pos + 4);
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4);
$recordData = substr($this->_data, $this->_pos + 8, $length);
// move stream pointer to next record
@@ -182,7 +181,7 @@ class PHPExcel_Reader_Excel5_Escher
*/
private function _readDgg()
{
$length = $this->_GetInt4d($this->_data, $this->_pos + 4);
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4);
$recordData = substr($this->_data, $this->_pos + 8, $length);
// move stream pointer to next record
@@ -194,7 +193,7 @@ class PHPExcel_Reader_Excel5_Escher
*/
private function _readBstoreContainer()
{
$length = $this->_GetInt4d($this->_data, $this->_pos + 4);
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4);
$recordData = substr($this->_data, $this->_pos + 8, $length);
// move stream pointer to next record
@@ -215,9 +214,9 @@ class PHPExcel_Reader_Excel5_Escher
// offset: 0; size: 2; recVer and recInstance
// bit: 4-15; mask: 0xFFF0; recInstance
$recInstance = (0xFFF0 & $this->_GetInt2d($this->_data, $this->_pos)) >> 4;
$recInstance = (0xFFF0 & PHPExcel_Reader_Excel5::_GetInt2d($this->_data, $this->_pos)) >> 4;
$length = $this->_GetInt4d($this->_data, $this->_pos + 4);
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4);
$recordData = substr($this->_data, $this->_pos + 8, $length);
// move stream pointer to next record
@@ -239,16 +238,16 @@ class PHPExcel_Reader_Excel5_Escher
$rgbUid = substr($recordData, 2, 16);
// offset: 18; size: 2; tag
$tag = $this->_GetInt2d($recordData, 18);
$tag = PHPExcel_Reader_Excel5::_GetInt2d($recordData, 18);
// offset: 20; size: 4; size of BLIP in bytes
$size = $this->_GetInt4d($recordData, 20);
$size = PHPExcel_Reader_Excel5::_GetInt4d($recordData, 20);
// offset: 24; size: 4; number of references to this BLIP
$cRef = $this->_GetInt4d($recordData, 24);
$cRef = PHPExcel_Reader_Excel5::_GetInt4d($recordData, 24);
// offset: 28; size: 4; MSOFO file offset
$foDelay = $this->_GetInt4d($recordData, 28);
$foDelay = PHPExcel_Reader_Excel5::_GetInt4d($recordData, 28);
// offset: 32; size: 1; unused1
$unused1 = ord($recordData{32});
@@ -281,9 +280,9 @@ class PHPExcel_Reader_Excel5_Escher
// offset: 0; size: 2; recVer and recInstance
// bit: 4-15; mask: 0xFFF0; recInstance
$recInstance = (0xFFF0 & $this->_GetInt2d($this->_data, $this->_pos)) >> 4;
$recInstance = (0xFFF0 & PHPExcel_Reader_Excel5::_GetInt2d($this->_data, $this->_pos)) >> 4;
$length = $this->_GetInt4d($this->_data, $this->_pos + 4);
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4);
$recordData = substr($this->_data, $this->_pos + 8, $length);
// move stream pointer to next record
@@ -322,9 +321,9 @@ class PHPExcel_Reader_Excel5_Escher
// offset: 0; size: 2; recVer and recInstance
// bit: 4-15; mask: 0xFFF0; recInstance
$recInstance = (0xFFF0 & $this->_GetInt2d($this->_data, $this->_pos)) >> 4;
$recInstance = (0xFFF0 & PHPExcel_Reader_Excel5::_GetInt2d($this->_data, $this->_pos)) >> 4;
$length = $this->_GetInt4d($this->_data, $this->_pos + 4);
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4);
$recordData = substr($this->_data, $this->_pos + 8, $length);
// move stream pointer to next record
@@ -363,9 +362,9 @@ class PHPExcel_Reader_Excel5_Escher
// offset: 0; size: 2; recVer and recInstance
// bit: 4-15; mask: 0xFFF0; recInstance
$recInstance = (0xFFF0 & $this->_GetInt2d($this->_data, $this->_pos)) >> 4;
$recInstance = (0xFFF0 & PHPExcel_Reader_Excel5::_GetInt2d($this->_data, $this->_pos)) >> 4;
$length = $this->_GetInt4d($this->_data, $this->_pos + 4);
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4);
$recordData = substr($this->_data, $this->_pos + 8, $length);
// move stream pointer to next record
@@ -382,9 +381,9 @@ class PHPExcel_Reader_Excel5_Escher
// offset: 0; size: 2; recVer and recInstance
// bit: 4-15; mask: 0xFFF0; recInstance
$recInstance = (0xFFF0 & $this->_GetInt2d($this->_data, $this->_pos)) >> 4;
$recInstance = (0xFFF0 & PHPExcel_Reader_Excel5::_GetInt2d($this->_data, $this->_pos)) >> 4;
$length = $this->_GetInt4d($this->_data, $this->_pos + 4);
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4);
$recordData = substr($this->_data, $this->_pos + 8, $length);
// move stream pointer to next record
@@ -396,7 +395,7 @@ class PHPExcel_Reader_Excel5_Escher
*/
private function _readSplitMenuColors()
{
$length = $this->_GetInt4d($this->_data, $this->_pos + 4);
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4);
$recordData = substr($this->_data, $this->_pos + 8, $length);
// move stream pointer to next record
@@ -408,7 +407,7 @@ class PHPExcel_Reader_Excel5_Escher
*/
private function _readDgContainer()
{
$length = $this->_GetInt4d($this->_data, $this->_pos + 4);
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4);
$recordData = substr($this->_data, $this->_pos + 8, $length);
// move stream pointer to next record
@@ -426,7 +425,7 @@ class PHPExcel_Reader_Excel5_Escher
*/
private function _readDg()
{
$length = $this->_GetInt4d($this->_data, $this->_pos + 4);
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4);
$recordData = substr($this->_data, $this->_pos + 8, $length);
// move stream pointer to next record
@@ -440,7 +439,7 @@ class PHPExcel_Reader_Excel5_Escher
{
// context is either context DgContainer or SpgrContainer
$length = $this->_GetInt4d($this->_data, $this->_pos + 4);
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4);
$recordData = substr($this->_data, $this->_pos + 8, $length);
// move stream pointer to next record
@@ -466,7 +465,7 @@ class PHPExcel_Reader_Excel5_Escher
*/
private function _readSpContainer()
{
$length = $this->_GetInt4d($this->_data, $this->_pos + 4);
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4);
$recordData = substr($this->_data, $this->_pos + 8, $length);
// add spContainer to spgrContainer
@@ -486,7 +485,7 @@ class PHPExcel_Reader_Excel5_Escher
*/
private function _readSpgr()
{
$length = $this->_GetInt4d($this->_data, $this->_pos + 4);
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4);
$recordData = substr($this->_data, $this->_pos + 8, $length);
// move stream pointer to next record
@@ -501,9 +500,9 @@ class PHPExcel_Reader_Excel5_Escher
// offset: 0; size: 2; recVer and recInstance
// bit: 4-15; mask: 0xFFF0; recInstance
$recInstance = (0xFFF0 & $this->_GetInt2d($this->_data, $this->_pos)) >> 4;
$recInstance = (0xFFF0 & PHPExcel_Reader_Excel5::_GetInt2d($this->_data, $this->_pos)) >> 4;
$length = $this->_GetInt4d($this->_data, $this->_pos + 4);
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4);
$recordData = substr($this->_data, $this->_pos + 8, $length);
// move stream pointer to next record
@@ -518,9 +517,9 @@ class PHPExcel_Reader_Excel5_Escher
// offset: 0; size: 2; recVer and recInstance
// bit: 4-15; mask: 0xFFF0; recInstance
$recInstance = (0xFFF0 & $this->_GetInt2d($this->_data, $this->_pos)) >> 4;
$recInstance = (0xFFF0 & PHPExcel_Reader_Excel5::_GetInt2d($this->_data, $this->_pos)) >> 4;
$length = $this->_GetInt4d($this->_data, $this->_pos + 4);
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4);
$recordData = substr($this->_data, $this->_pos + 8, $length);
// move stream pointer to next record
@@ -532,35 +531,35 @@ class PHPExcel_Reader_Excel5_Escher
*/
private function _readClientAnchor()
{
$length = $this->_GetInt4d($this->_data, $this->_pos + 4);
$length = PHPExcel_Reader_Excel5::_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);
$c1 = PHPExcel_Reader_Excel5::_GetInt2d($recordData, 2);
// offset: 4; size: 2; upper-left corner horizontal offset in 1/1024 of column width
$startOffsetX = $this->_GetInt2d($recordData, 4);
$startOffsetX = PHPExcel_Reader_Excel5::_GetInt2d($recordData, 4);
// offset: 6; size: 2; upper-left corner row index (0-based)
$r1 = $this->_GetInt2d($recordData, 6);
$r1 = PHPExcel_Reader_Excel5::_GetInt2d($recordData, 6);
// offset: 8; size: 2; upper-left corner vertical offset in 1/256 of row height
$startOffsetY = $this->_GetInt2d($recordData, 8);
$startOffsetY = PHPExcel_Reader_Excel5::_GetInt2d($recordData, 8);
// offset: 10; size: 2; bottom-right corner column index (0-based)
$c2 = $this->_GetInt2d($recordData, 10);
$c2 = PHPExcel_Reader_Excel5::_GetInt2d($recordData, 10);
// offset: 12; size: 2; bottom-right corner horizontal offset in 1/1024 of column width
$endOffsetX = $this->_GetInt2d($recordData, 12);
$endOffsetX = PHPExcel_Reader_Excel5::_GetInt2d($recordData, 12);
// offset: 14; size: 2; bottom-right corner row index (0-based)
$r2 = $this->_GetInt2d($recordData, 14);
$r2 = PHPExcel_Reader_Excel5::_GetInt2d($recordData, 14);
// offset: 16; size: 2; bottom-right corner vertical offset in 1/256 of row height
$endOffsetY = $this->_GetInt2d($recordData, 16);
$endOffsetY = PHPExcel_Reader_Excel5::_GetInt2d($recordData, 16);
// set the start coordinates
$this->_object->setStartCoordinates(PHPExcel_Cell::stringFromColumnIndex($c1) . ($r1 + 1));
@@ -586,7 +585,7 @@ class PHPExcel_Reader_Excel5_Escher
*/
private function _readClientData()
{
$length = $this->_GetInt4d($this->_data, $this->_pos + 4);
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4);
$recordData = substr($this->_data, $this->_pos + 8, $length);
// move stream pointer to next record
@@ -609,7 +608,7 @@ class PHPExcel_Reader_Excel5_Escher
$fopte = substr($data, 6 * $i, 6);
// offset: 0; size: 2; opid
$opid = $this->_GetInt2d($fopte, 0);
$opid = PHPExcel_Reader_Excel5::_GetInt2d($fopte, 0);
// bit: 0-13; mask: 0x3FFF; opid.opid
$opidOpid = (0x3FFF & $opid) >> 0;
@@ -621,7 +620,7 @@ class PHPExcel_Reader_Excel5_Escher
$opidFComplex = (0x8000 & $opid) >> 15;
// offset: 2; size: 4; the value for this property
$op = $this->_GetInt4d($fopte, 2);
$op = PHPExcel_Reader_Excel5::_GetInt4d($fopte, 2);
if ($opidFComplex) {
$complexData = substr($splicedComplexData, 0, $op);
@@ -638,40 +637,4 @@ class PHPExcel_Reader_Excel5_Escher
}
}
/**
* 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;
}
}

View File

@@ -0,0 +1,914 @@
<?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 1.7.6, 2011-02-27
*/
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
}
/**
* PHPExcel_Reader_Gnumeric
*
* @category PHPExcel
* @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Reader_Gnumeric implements PHPExcel_Reader_IReader
{
/**
* Read data only?
* Identifies whether the Reader should only read data values for cells, and ignore any formatting information;
* or whether it should read both data and formatting
*
* @var boolean
*/
private $_readDataOnly = false;
/**
* Restrict which sheets should be loaded?
* This property holds an array of worksheet names to be loaded. If null, then all worksheets will be loaded.
*
* @var array of string
*/
private $_loadSheetsOnly = null;
/**
* Formats
*
* @var array
*/
private $_styles = array();
/**
* Shared Expressions
*
* @var array
*/
private $_expressions = array();
private $_referenceHelper = null;
/**
* PHPExcel_Reader_IReadFilter instance
*
* @var PHPExcel_Reader_IReadFilter
*/
private $_readFilter = null;
/**
* Read data only?
* If this is true, then the Reader will only read data values for cells, it will not read any formatting information.
* If false (the default) it will read data and formatting.
*
* @return boolean
*/
public function getReadDataOnly() {
return $this->_readDataOnly;
}
/**
* Set read data only
* Set to true, to advise the Reader only to read data values for cells, and to ignore any formatting information.
* Set to false (the default) to advise the Reader to read both data and formatting for cells.
*
* @param boolean $pValue
*
* @return PHPExcel_Reader_Gnumeric
*/
public function setReadDataOnly($pValue = false) {
$this->_readDataOnly = $pValue;
return $this;
}
/**
* Get which sheets to load
* Returns either an array of worksheet names (the list of worksheets that should be loaded), or a null
* indicating that all worksheets in the workbook should be loaded.
*
* @return mixed
*/
public function getLoadSheetsOnly()
{
return $this->_loadSheetsOnly;
}
/**
* Set which sheets to load
*
* @param mixed $value
* This should be either an array of worksheet names to be loaded, or a string containing a single worksheet name.
* If NULL, then it tells the Reader to read all worksheets in the workbook
*
* @return PHPExcel_Reader_Gnumeric
*/
public function setLoadSheetsOnly($value = null)
{
$this->_loadSheetsOnly = is_array($value) ?
$value : array($value);
return $this;
}
/**
* Set all sheets to load
* Tells the Reader to load all worksheets from the workbook.
*
* @return PHPExcel_Reader_Gnumeric
*/
public function setLoadAllSheets()
{
$this->_loadSheetsOnly = null;
return $this;
}
/**
* Read filter
*
* @return PHPExcel_Reader_IReadFilter
*/
public function getReadFilter() {
return $this->_readFilter;
}
/**
* Set read filter
*
* @param PHPExcel_Reader_IReadFilter $pValue
* @return PHPExcel_Reader_Gnumeric
*/
public function setReadFilter(PHPExcel_Reader_IReadFilter $pValue) {
$this->_readFilter = $pValue;
return $this;
}
/**
* Create a new PHPExcel_Reader_Gnumeric
*/
public function __construct() {
$this->_readFilter = new PHPExcel_Reader_DefaultReadFilter();
$this->_referenceHelper = PHPExcel_ReferenceHelper::getInstance();
}
/**
* Can the current PHPExcel_Reader_IReader read the file?
*
* @param string $pFileName
* @return boolean
*/
public function canRead($pFilename)
{
// Check if gzlib functions are available
if (!function_exists('gzread')) {
return false;
}
// Check if file exists
if (!file_exists($pFilename)) {
throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
}
// Read signature data (first 3 bytes)
$fh = fopen($pFilename, 'r');
$data = fread($fh, 2);
fclose($fh);
if ($data != chr(0x1F).chr(0x8B)) {
return false;
}
return true;
}
/**
* Loads PHPExcel from file
*
* @param string $pFilename
* @return PHPExcel
* @throws Exception
*/
public function load($pFilename)
{
// Create new PHPExcel
$objPHPExcel = new PHPExcel();
// Load into this instance
return $this->loadIntoExisting($pFilename, $objPHPExcel);
}
private function _gzfileGetContents($filename) {
$file = @gzopen($filename, 'rb');
if ($file !== false) {
$data = '';
while (!gzeof($file)) {
$data .= gzread($file, 1024);
}
gzclose($file);
}
return $data;
}
/**
* Reads names of the worksheets from a file, without parsing the whole file to a PHPExcel object
*
* @param string $pFilename
* @throws Exception
*/
public function listWorksheetNames($pFilename)
{
// Check if file exists
if (!file_exists($pFilename)) {
throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
}
$gFileData = $this->_gzfileGetContents($pFilename);
$xml = simplexml_load_string($gFileData);
$namespacesMeta = $xml->getNamespaces(true);
$gnmXML = $xml->children($namespacesMeta['gnm']);
$worksheetNames = array();
foreach($gnmXML->Sheets->Sheet as $sheet) {
$worksheetNames[] = (string) $sheet->Name;
}
return $worksheetNames;
}
/**
* Loads PHPExcel from file into PHPExcel instance
*
* @param string $pFilename
* @param PHPExcel $objPHPExcel
* @return PHPExcel
* @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.");
}
$timezoneObj = new DateTimeZone('Europe/London');
$GMT = new DateTimeZone('UTC');
$gFileData = $this->_gzfileGetContents($pFilename);
// echo '<pre>';
// echo htmlentities($gFileData,ENT_QUOTES,'UTF-8');
// echo '</pre><hr />';
//
$xml = simplexml_load_string($gFileData);
$namespacesMeta = $xml->getNamespaces(true);
// var_dump($namespacesMeta);
//
$gnmXML = $xml->children($namespacesMeta['gnm']);
$docProps = $objPHPExcel->getProperties();
// Document Properties are held differently, depending on the version of Gnumeric
if (isset($namespacesMeta['office'])) {
$officeXML = $xml->children($namespacesMeta['office']);
$officeDocXML = $officeXML->{'document-meta'};
$officeDocMetaXML = $officeDocXML->meta;
foreach($officeDocMetaXML as $officePropertyData) {
$officePropertyDC = array();
if (isset($namespacesMeta['dc'])) {
$officePropertyDC = $officePropertyData->children($namespacesMeta['dc']);
}
foreach($officePropertyDC as $propertyName => $propertyValue) {
$propertyValue = (string) $propertyValue;
switch ($propertyName) {
case 'title' :
$docProps->setTitle(trim($propertyValue));
break;
case 'subject' :
$docProps->setSubject(trim($propertyValue));
break;
case 'creator' :
$docProps->setCreator(trim($propertyValue));
$docProps->setLastModifiedBy(trim($propertyValue));
break;
case 'date' :
$creationDate = strtotime(trim($propertyValue));
$docProps->setCreated($creationDate);
$docProps->setModified($creationDate);
break;
case 'description' :
$docProps->setDescription(trim($propertyValue));
break;
}
}
$officePropertyMeta = array();
if (isset($namespacesMeta['meta'])) {
$officePropertyMeta = $officePropertyData->children($namespacesMeta['meta']);
}
foreach($officePropertyMeta as $propertyName => $propertyValue) {
$attributes = $propertyValue->attributes($namespacesMeta['meta']);
$propertyValue = (string) $propertyValue;
switch ($propertyName) {
case 'keyword' :
$docProps->setKeywords(trim($propertyValue));
break;
case 'initial-creator' :
$docProps->setCreator(trim($propertyValue));
$docProps->setLastModifiedBy(trim($propertyValue));
break;
case 'creation-date' :
$creationDate = strtotime(trim($propertyValue));
$docProps->setCreated($creationDate);
$docProps->setModified($creationDate);
break;
case 'user-defined' :
list(,$attrName) = explode(':',$attributes['name']);
switch ($attrName) {
case 'publisher' :
$docProps->setCompany(trim($propertyValue));
break;
case 'category' :
$docProps->setCategory(trim($propertyValue));
break;
case 'manager' :
$docProps->setManager(trim($propertyValue));
break;
}
break;
}
}
}
} elseif (isset($gnmXML->Summary)) {
foreach($gnmXML->Summary->Item as $summaryItem) {
$propertyName = $summaryItem->name;
$propertyValue = $summaryItem->{'val-string'};
switch ($propertyName) {
case 'title' :
$docProps->setTitle(trim($propertyValue));
break;
case 'comments' :
$docProps->setDescription(trim($propertyValue));
break;
case 'keywords' :
$docProps->setKeywords(trim($propertyValue));
break;
case 'category' :
$docProps->setCategory(trim($propertyValue));
break;
case 'manager' :
$docProps->setManager(trim($propertyValue));
break;
case 'author' :
$docProps->setCreator(trim($propertyValue));
$docProps->setLastModifiedBy(trim($propertyValue));
break;
case 'company' :
$docProps->setCompany(trim($propertyValue));
break;
}
}
}
$worksheetID = 0;
foreach($gnmXML->Sheets->Sheet as $sheet) {
$worksheetName = (string) $sheet->Name;
// echo '<b>Worksheet: ',$worksheetName,'</b><br />';
if ((isset($this->_loadSheetsOnly)) && (!in_array($worksheetName, $this->_loadSheetsOnly))) {
continue;
}
$maxRow = $maxCol = 0;
// Create new Worksheet
$objPHPExcel->createSheet();
$objPHPExcel->setActiveSheetIndex($worksheetID);
$objPHPExcel->getActiveSheet()->setTitle($worksheetName);
if ((!$this->_readDataOnly) && (isset($sheet->PrintInformation))) {
if (isset($sheet->PrintInformation->Margins)) {
foreach($sheet->PrintInformation->Margins->children('gnm',TRUE) as $key => $margin) {
$marginAttributes = $margin->attributes();
$marginSize = 72 / 100; // Default
switch($marginAttributes['PrefUnit']) {
case 'mm' :
$marginSize = intval($marginAttributes['Points']) / 100;
break;
}
switch($key) {
case 'top' :
$objPHPExcel->getActiveSheet()->getPageMargins()->setTop($marginSize);
break;
case 'bottom' :
$objPHPExcel->getActiveSheet()->getPageMargins()->setBottom($marginSize);
break;
case 'left' :
$objPHPExcel->getActiveSheet()->getPageMargins()->setLeft($marginSize);
break;
case 'right' :
$objPHPExcel->getActiveSheet()->getPageMargins()->setRight($marginSize);
break;
case 'header' :
$objPHPExcel->getActiveSheet()->getPageMargins()->setHeader($marginSize);
break;
case 'footer' :
$objPHPExcel->getActiveSheet()->getPageMargins()->setFooter($marginSize);
break;
}
}
}
}
foreach($sheet->Cells->Cell as $cell) {
$cellAttributes = $cell->attributes();
$row = (int) $cellAttributes->Row + 1;
$column = (int) $cellAttributes->Col;
if ($row > $maxRow) $maxRow = $row;
if ($column > $maxCol) $maxCol = $column;
$column = PHPExcel_Cell::stringFromColumnIndex($column);
// Read cell?
if (!is_null($this->getReadFilter())) {
if (!$this->getReadFilter()->readCell($column, $row, $worksheetName)) {
continue;
}
}
$ValueType = $cellAttributes->ValueType;
$ExprID = (string) $cellAttributes->ExprID;
// echo 'Cell ',$column,$row,'<br />';
// echo 'Type is ',$ValueType,'<br />';
// echo 'Value is ',$cell,'<br />';
$type = PHPExcel_Cell_DataType::TYPE_FORMULA;
if ($ExprID > '') {
if (((string) $cell) > '') {
$this->_expressions[$ExprID] = array( 'column' => $cellAttributes->Col,
'row' => $cellAttributes->Row,
'formula' => (string) $cell
);
// echo 'NEW EXPRESSION ',$ExprID,'<br />';
} else {
$expression = $this->_expressions[$ExprID];
$cell = $this->_referenceHelper->updateFormulaReferences( $expression['formula'],
'A1',
$cellAttributes->Col - $expression['column'],
$cellAttributes->Row - $expression['row'],
$worksheetName
);
// echo 'SHARED EXPRESSION ',$ExprID,'<br />';
// echo 'New Value is ',$cell,'<br />';
}
$type = PHPExcel_Cell_DataType::TYPE_FORMULA;
} else {
switch($ValueType) {
case '10' : // NULL
$type = PHPExcel_Cell_DataType::TYPE_NULL;
break;
case '20' : // Boolean
$type = PHPExcel_Cell_DataType::TYPE_BOOL;
$cell = ($cell == 'TRUE') ? True : False;
break;
case '30' : // Integer
$cell = intval($cell);
case '40' : // Float
$type = PHPExcel_Cell_DataType::TYPE_NUMERIC;
break;
case '50' : // Error
$type = PHPExcel_Cell_DataType::TYPE_ERROR;
break;
case '60' : // String
$type = PHPExcel_Cell_DataType::TYPE_STRING;
break;
case '70' : // Cell Range
case '80' : // Array
}
}
$objPHPExcel->getActiveSheet()->getCell($column.$row)->setValueExplicit($cell,$type);
}
if ((!$this->_readDataOnly) && (isset($sheet->Objects))) {
foreach($sheet->Objects->children('gnm',TRUE) as $key => $comment) {
$commentAttributes = $comment->attributes();
// Only comment objects are handled at the moment
if ($commentAttributes->Text) {
$objPHPExcel->getActiveSheet()->getComment( (string)$commentAttributes->ObjectBound )
->setAuthor( (string)$commentAttributes->Author )
->setText($this->_parseRichText((string)$commentAttributes->Text) );
}
}
}
// echo '$maxCol=',$maxCol,'; $maxRow=',$maxRow,'<br />';
//
foreach($sheet->Styles->StyleRegion as $styleRegion) {
$styleAttributes = $styleRegion->attributes();
// var_dump($styleAttributes);
// echo '<br />';
if (($styleAttributes['startRow'] <= $maxRow) &&
($styleAttributes['startCol'] <= $maxCol)) {
$startColumn = PHPExcel_Cell::stringFromColumnIndex($styleAttributes['startCol']);
$startRow = $styleAttributes['startRow'] + 1;
$endColumn = ($styleAttributes['endCol'] > $maxCol) ? $maxCol : $styleAttributes['endCol'];
$endColumn = PHPExcel_Cell::stringFromColumnIndex($endColumn);
$endRow = ($styleAttributes['endRow'] > $maxRow) ? $maxRow : $styleAttributes['endRow'];
$endRow += 1;
$cellRange = $startColumn.$startRow.':'.$endColumn.$endRow;
// echo $cellRange,'<br />';
$styleAttributes = $styleRegion->Style->attributes();
// var_dump($styleAttributes);
// echo '<br />';
// We still set the number format mask for date/time values, even if _readDataOnly is true
if ((!$this->_readDataOnly) ||
(PHPExcel_Shared_Date::isDateTimeFormatCode($styleArray['numberformat']['code']))) {
$styleArray = array();
$styleArray['numberformat']['code'] = (string) $styleAttributes['Format'];
// If _readDataOnly is false, we set all formatting information
if (!$this->_readDataOnly) {
switch($styleAttributes['HAlign']) {
case '1' :
$styleArray['alignment']['horizontal'] = PHPExcel_Style_Alignment::HORIZONTAL_GENERAL;
break;
case '2' :
$styleArray['alignment']['horizontal'] = PHPExcel_Style_Alignment::HORIZONTAL_LEFT;
break;
case '4' :
$styleArray['alignment']['horizontal'] = PHPExcel_Style_Alignment::HORIZONTAL_RIGHT;
break;
case '8' :
$styleArray['alignment']['horizontal'] = PHPExcel_Style_Alignment::HORIZONTAL_CENTER;
break;
case '16' :
case '64' :
$styleArray['alignment']['horizontal'] = PHPExcel_Style_Alignment::HORIZONTAL_CENTER_CONTINUOUS;
break;
case '32' :
$styleArray['alignment']['horizontal'] = PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY;
break;
}
switch($styleAttributes['VAlign']) {
case '1' :
$styleArray['alignment']['vertical'] = PHPExcel_Style_Alignment::VERTICAL_TOP;
break;
case '2' :
$styleArray['alignment']['vertical'] = PHPExcel_Style_Alignment::VERTICAL_BOTTOM;
break;
case '4' :
$styleArray['alignment']['vertical'] = PHPExcel_Style_Alignment::VERTICAL_CENTER;
break;
case '8' :
$styleArray['alignment']['vertical'] = PHPExcel_Style_Alignment::VERTICAL_JUSTIFY;
break;
}
$styleArray['alignment']['wrap'] = ($styleAttributes['WrapText'] == '1') ? True : False;
$styleArray['alignment']['shrinkToFit'] = ($styleAttributes['ShrinkToFit'] == '1') ? True : False;
$styleArray['alignment']['indent'] = (intval($styleAttributes["Indent"]) > 0) ? $styleAttributes["indent"] : 0;
$RGB = self::_parseGnumericColour($styleAttributes["Fore"]);
$styleArray['font']['color']['rgb'] = $RGB;
$RGB = self::_parseGnumericColour($styleAttributes["Back"]);
$shade = $styleAttributes["Shade"];
if (($RGB != '000000') || ($shade != '0')) {
$styleArray['fill']['color']['rgb'] = $styleArray['fill']['startcolor']['rgb'] = $RGB;
$RGB2 = self::_parseGnumericColour($styleAttributes["PatternColor"]);
$styleArray['fill']['endcolor']['rgb'] = $RGB2;
switch($shade) {
case '1' :
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_SOLID;
break;
case '2' :
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_GRADIENT_LINEAR;
break;
case '3' :
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_GRADIENT_PATH;
break;
case '4' :
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_PATTERN_DARKDOWN;
break;
case '5' :
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_PATTERN_DARKGRAY;
break;
case '6' :
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_PATTERN_DARKGRID;
break;
case '7' :
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_PATTERN_DARKHORIZONTAL;
break;
case '8' :
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_PATTERN_DARKTRELLIS;
break;
case '9' :
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_PATTERN_DARKUP;
break;
case '10' :
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_PATTERN_DARKVERTICAL;
break;
case '11' :
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_PATTERN_GRAY0625;
break;
case '12' :
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_PATTERN_GRAY125;
break;
case '13' :
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_PATTERN_LIGHTDOWN;
break;
case '14' :
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_PATTERN_LIGHTGRAY;
break;
case '15' :
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_PATTERN_LIGHTGRID;
break;
case '16' :
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_PATTERN_LIGHTHORIZONTAL;
break;
case '17' :
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_PATTERN_LIGHTTRELLIS;
break;
case '18' :
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_PATTERN_LIGHTUP;
break;
case '19' :
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_PATTERN_LIGHTVERTICAL;
break;
case '20' :
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_PATTERN_MEDIUMGRAY;
break;
}
}
$fontAttributes = $styleRegion->Style->Font->attributes();
// var_dump($fontAttributes);
// echo '<br />';
$styleArray['font']['name'] = (string) $styleRegion->Style->Font;
$styleArray['font']['size'] = intval($fontAttributes['Unit']);
$styleArray['font']['bold'] = ($fontAttributes['Bold'] == '1') ? True : False;
$styleArray['font']['italic'] = ($fontAttributes['Italic'] == '1') ? True : False;
$styleArray['font']['strike'] = ($fontAttributes['StrikeThrough'] == '1') ? True : False;
switch($fontAttributes['Underline']) {
case '1' :
$styleArray['font']['underline'] = PHPExcel_Style_Font::UNDERLINE_SINGLE;
break;
case '2' :
$styleArray['font']['underline'] = PHPExcel_Style_Font::UNDERLINE_DOUBLE;
break;
case '3' :
$styleArray['font']['underline'] = PHPExcel_Style_Font::UNDERLINE_SINGLEACCOUNTING;
break;
case '4' :
$styleArray['font']['underline'] = PHPExcel_Style_Font::UNDERLINE_DOUBLEACCOUNTING;
break;
default :
$styleArray['font']['underline'] = PHPExcel_Style_Font::UNDERLINE_NONE;
break;
}
switch($fontAttributes['Script']) {
case '1' :
$styleArray['font']['superScript'] = True;
break;
case '-1' :
$styleArray['font']['subScript'] = True;
break;
}
if (isset($styleRegion->Style->StyleBorder)) {
if (isset($styleRegion->Style->StyleBorder->Top)) {
$styleArray['borders']['top'] = self::_parseBorderAttributes($styleRegion->Style->StyleBorder->Top->attributes());
}
if (isset($styleRegion->Style->StyleBorder->Bottom)) {
$styleArray['borders']['bottom'] = self::_parseBorderAttributes($styleRegion->Style->StyleBorder->Bottom->attributes());
}
if (isset($styleRegion->Style->StyleBorder->Left)) {
$styleArray['borders']['left'] = self::_parseBorderAttributes($styleRegion->Style->StyleBorder->Left->attributes());
}
if (isset($styleRegion->Style->StyleBorder->Right)) {
$styleArray['borders']['right'] = self::_parseBorderAttributes($styleRegion->Style->StyleBorder->Right->attributes());
}
if ((isset($styleRegion->Style->StyleBorder->Diagonal)) && (isset($styleRegion->Style->StyleBorder->{'Rev-Diagonal'}))) {
$styleArray['borders']['diagonal'] = self::_parseBorderAttributes($styleRegion->Style->StyleBorder->Diagonal->attributes());
$styleArray['borders']['diagonaldirection'] = PHPExcel_Style_Borders::DIAGONAL_BOTH;
} elseif (isset($styleRegion->Style->StyleBorder->Diagonal)) {
$styleArray['borders']['diagonal'] = self::_parseBorderAttributes($styleRegion->Style->StyleBorder->Diagonal->attributes());
$styleArray['borders']['diagonaldirection'] = PHPExcel_Style_Borders::DIAGONAL_UP;
} elseif (isset($styleRegion->Style->StyleBorder->{'Rev-Diagonal'})) {
$styleArray['borders']['diagonal'] = self::_parseBorderAttributes($styleRegion->Style->StyleBorder->{'Rev-Diagonal'}->attributes());
$styleArray['borders']['diagonaldirection'] = PHPExcel_Style_Borders::DIAGONAL_DOWN;
}
}
if (isset($styleRegion->Style->HyperLink)) {
// TO DO
$hyperlink = $styleRegion->Style->HyperLink->attributes();
}
}
// var_dump($styleArray);
// echo '<br />';
$objPHPExcel->getActiveSheet()->getStyle($cellRange)->applyFromArray($styleArray);
}
}
}
if ((!$this->_readDataOnly) && (isset($sheet->Cols))) {
// Column Widths
$columnAttributes = $sheet->Cols->attributes();
$defaultWidth = $columnAttributes['DefaultSizePts'] / 5.4;
$c = 0;
foreach($sheet->Cols->ColInfo as $columnOverride) {
$columnAttributes = $columnOverride->attributes();
$column = $columnAttributes['No'];
$columnWidth = $columnAttributes['Unit'] / 5.4;
$hidden = ((isset($columnAttributes['Hidden'])) && ($columnAttributes['Hidden'] == '1')) ? true : false;
$columnCount = (isset($columnAttributes['Count'])) ? $columnAttributes['Count'] : 1;
while ($c < $column) {
$objPHPExcel->getActiveSheet()->getColumnDimension(PHPExcel_Cell::stringFromColumnIndex($c))->setWidth($defaultWidth);
++$c;
}
while (($c < ($column+$columnCount)) && ($c <= $maxCol)) {
$objPHPExcel->getActiveSheet()->getColumnDimension(PHPExcel_Cell::stringFromColumnIndex($c))->setWidth($columnWidth);
if ($hidden) {
$objPHPExcel->getActiveSheet()->getColumnDimension(PHPExcel_Cell::stringFromColumnIndex($c))->setVisible(false);
}
++$c;
}
}
while ($c <= $maxCol) {
$objPHPExcel->getActiveSheet()->getColumnDimension(PHPExcel_Cell::stringFromColumnIndex($c))->setWidth($defaultWidth);
++$c;
}
}
if ((!$this->_readDataOnly) && (isset($sheet->Rows))) {
// Row Heights
$rowAttributes = $sheet->Rows->attributes();
$defaultHeight = $rowAttributes['DefaultSizePts'];
$r = 0;
foreach($sheet->Rows->RowInfo as $rowOverride) {
$rowAttributes = $rowOverride->attributes();
$row = $rowAttributes['No'];
$rowHeight = $rowAttributes['Unit'];
$hidden = ((isset($rowAttributes['Hidden'])) && ($rowAttributes['Hidden'] == '1')) ? true : false;
$rowCount = (isset($rowAttributes['Count'])) ? $rowAttributes['Count'] : 1;
while ($r < $row) {
++$r;
$objPHPExcel->getActiveSheet()->getRowDimension($r)->setRowHeight($defaultHeight);
}
while (($r < ($row+$rowCount)) && ($r < $maxRow)) {
++$r;
$objPHPExcel->getActiveSheet()->getRowDimension($r)->setRowHeight($rowHeight);
if ($hidden) {
$objPHPExcel->getActiveSheet()->getRowDimension($r)->setVisible(false);
}
}
}
while ($r < $maxRow) {
++$r;
$objPHPExcel->getActiveSheet()->getRowDimension($r)->setRowHeight($defaultHeight);
}
}
// Handle Merged Cells in this worksheet
if (isset($sheet->MergedRegions)) {
foreach($sheet->MergedRegions->Merge as $mergeCells) {
$objPHPExcel->getActiveSheet()->mergeCells($mergeCells);
}
}
$worksheetID++;
}
// Loop through definedNames (global named ranges)
if (isset($gnmXML->Names)) {
foreach($gnmXML->Names->Name as $namedRange) {
$name = (string) $namedRange->name;
$range = (string) $namedRange->value;
if (stripos($range, '#REF!') !== false) {
continue;
}
$range = explode('!',$range);
$range[0] = trim($range[0],"'");;
if ($worksheet = $objPHPExcel->getSheetByName($range[0])) {
$extractedRange = str_replace('$', '', $range[1]);
$objPHPExcel->addNamedRange( new PHPExcel_NamedRange($name, $worksheet, $extractedRange) );
}
}
}
// Return
return $objPHPExcel;
}
private static function _parseBorderAttributes($borderAttributes) {
$styleArray = array();
if (isset($borderAttributes["Color"])) {
$RGB = self::_parseGnumericColour($borderAttributes["Color"]);
$styleArray['color']['rgb'] = $RGB;
}
switch ($borderAttributes["Style"]) {
case '0' :
$styleArray['style'] = PHPExcel_Style_Border::BORDER_NONE;
break;
case '1' :
$styleArray['style'] = PHPExcel_Style_Border::BORDER_THIN;
break;
case '2' :
$styleArray['style'] = PHPExcel_Style_Border::BORDER_MEDIUM;
break;
case '4' :
$styleArray['style'] = PHPExcel_Style_Border::BORDER_DASHED;
break;
case '5' :
$styleArray['style'] = PHPExcel_Style_Border::BORDER_THICK;
break;
case '6' :
$styleArray['style'] = PHPExcel_Style_Border::BORDER_DOUBLE;
break;
case '7' :
$styleArray['style'] = PHPExcel_Style_Border::BORDER_DOTTED;
break;
case '9' :
$styleArray['style'] = PHPExcel_Style_Border::BORDER_DASHDOT;
break;
case '10' :
$styleArray['style'] = PHPExcel_Style_Border::BORDER_MEDIUMDASHDOT;
break;
case '11' :
$styleArray['style'] = PHPExcel_Style_Border::BORDER_DASHDOTDOT;
break;
case '12' :
$styleArray['style'] = PHPExcel_Style_Border::BORDER_MEDIUMDASHDOTDOT;
break;
case '13' :
$styleArray['style'] = PHPExcel_Style_Border::BORDER_MEDIUMDASHDOTDOT;
break;
case '3' :
$styleArray['style'] = PHPExcel_Style_Border::BORDER_SLANTDASHDOT;
break;
case '8' :
$styleArray['style'] = PHPExcel_Style_Border::BORDER_MEDIUMDASHED;
break;
}
return $styleArray;
}
private function _parseRichText($is = '') {
$value = new PHPExcel_RichText();
$value->createText($is);
return $value;
}
private static function _parseGnumericColour($gnmColour) {
list($gnmR,$gnmG,$gnmB) = explode(':',$gnmColour);
$gnmR = substr(str_pad($gnmR,4,'0',STR_PAD_RIGHT),0,2);
$gnmG = substr(str_pad($gnmG,4,'0',STR_PAD_RIGHT),0,2);
$gnmB = substr(str_pad($gnmB,4,'0',STR_PAD_RIGHT),0,2);
$RGB = $gnmR.$gnmG.$gnmB;
// echo 'Excel Colour: ',$RGB,'<br />';
return $RGB;
}
}

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
@@ -31,7 +31,7 @@
*
* @category PHPExcel
* @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
interface PHPExcel_Reader_IReadFilter
{

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
@@ -31,7 +31,7 @@
*
* @category PHPExcel
* @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
interface PHPExcel_Reader_IReader
{

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
@@ -33,44 +33,34 @@ if (!defined('PHPEXCEL_ROOT')) {
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
PHPExcel_Autoloader::Register();
PHPExcel_Shared_ZipStreamWrapper::register();
// check mbstring.func_overload
if (ini_get('mbstring.func_overload') & 2) {
throw new Exception('Multibyte function overloading in PHP must be disabled for string functions (2).');
}
}
/**
* PHPExcel_Reader_OOCalc
* PHPExcel_Reader_OOCalc
*
* @category PHPExcel
* @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @category PHPExcel
* @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Reader_OOCalc implements PHPExcel_Reader_IReader
{
/**
* Read data only?
* Read data only?
* Identifies whether the Reader should only read data values for cells, and ignore any formatting information;
* or whether it should read both data and formatting
*
* @var boolean
* @var boolean
*/
private $_readDataOnly = false;
/**
* Restict which sheets should be loaded?
* Restrict which sheets should be loaded?
* This property holds an array of worksheet names to be loaded. If null, then all worksheets will be loaded.
*
* @var array
* @var array of string
*/
private $_loadSheetsOnly = null;
/**
* Sheet index to read
*
* @var int
*/
private $_sheetIndex;
/**
* Formats
*
@@ -87,19 +77,24 @@ class PHPExcel_Reader_OOCalc implements PHPExcel_Reader_IReader
/**
* Read data only?
* Read data only?
* If this is true, then the Reader will only read data values for cells, it will not read any formatting information.
* If false (the default) it will read data and formatting.
*
* @return boolean
* @return boolean
*/
public function getReadDataOnly() {
return $this->_readDataOnly;
}
/**
* Set read data only
* Set read data only
* Set to true, to advise the Reader only to read data values for cells, and to ignore any formatting information.
* Set to false (the default) to advise the Reader to read both data and formatting for cells.
*
* @param boolean $pValue
* @return PHPExcel_Reader_Excel2007
* @param boolean $pValue
*
* @return PHPExcel_Reader_OOCalc
*/
public function setReadDataOnly($pValue = false) {
$this->_readDataOnly = $pValue;
@@ -107,9 +102,11 @@ class PHPExcel_Reader_OOCalc implements PHPExcel_Reader_IReader
}
/**
* Get which sheets to load
* Get which sheets to load
* Returns either an array of worksheet names (the list of worksheets that should be loaded), or a null
* indicating that all worksheets in the workbook should be loaded.
*
* @return mixed
* @return mixed
*/
public function getLoadSheetsOnly()
{
@@ -117,10 +114,13 @@ class PHPExcel_Reader_OOCalc implements PHPExcel_Reader_IReader
}
/**
* Set which sheets to load
* Set which sheets to load
*
* @param mixed $value
* @return PHPExcel_Reader_Excel2007
* @param mixed $value
* This should be either an array of worksheet names to be loaded, or a string containing a single worksheet name.
* If NULL, then it tells the Reader to read all worksheets in the workbook
*
* @return PHPExcel_Reader_OOCalc
*/
public function setLoadSheetsOnly($value = null)
{
@@ -130,9 +130,10 @@ class PHPExcel_Reader_OOCalc implements PHPExcel_Reader_IReader
}
/**
* Set all sheets to load
* Set all sheets to load
* Tells the Reader to load all worksheets from the workbook.
*
* @return PHPExcel_Reader_Excel2007
* @return PHPExcel_Reader_OOCalc
*/
public function setLoadAllSheets()
{
@@ -153,7 +154,7 @@ class PHPExcel_Reader_OOCalc implements PHPExcel_Reader_IReader
* Set read filter
*
* @param PHPExcel_Reader_IReadFilter $pValue
* @return PHPExcel_Reader_Excel2007
* @return PHPExcel_Reader_OOCalc
*/
public function setReadFilter(PHPExcel_Reader_IReadFilter $pValue) {
$this->_readFilter = $pValue;
@@ -164,7 +165,6 @@ class PHPExcel_Reader_OOCalc implements PHPExcel_Reader_IReader
* Create a new PHPExcel_Reader_OOCalc
*/
public function __construct() {
$this->_sheetIndex = 0;
$this->_readFilter = new PHPExcel_Reader_DefaultReadFilter();
}
@@ -200,6 +200,42 @@ class PHPExcel_Reader_OOCalc implements PHPExcel_Reader_IReader
return false;
}
/**
* Reads names of the worksheets from a file, without parsing the whole file to a PHPExcel object
*
* @param string $pFilename
* @throws Exception
*/
public function listWorksheetNames($pFilename)
{
// Check if file exists
if (!file_exists($pFilename)) {
throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
}
$worksheetNames = array();
$zip = new ZipArchive;
if ($zip->open($pFilename) === true) {
$xml = simplexml_load_string($zip->getFromName("content.xml"));
$namespacesContent = $xml->getNamespaces(true);
$workbook = $xml->children($namespacesContent['office']);
foreach($workbook->body->spreadsheet as $workbookData) {
$workbookData = $workbookData->children($namespacesContent['table']);
foreach($workbookData->table as $worksheetDataSet) {
$worksheetDataAttributes = $worksheetDataSet->attributes($namespacesContent['table']);
$worksheetNames[] = $worksheetDataAttributes['name'];
}
}
}
return $worksheetNames;
}
/**
* Loads PHPExcel from file
*
@@ -262,8 +298,6 @@ class PHPExcel_Reader_OOCalc implements PHPExcel_Reader_IReader
$officePropertyDC = $officePropertyData->children($namespacesMeta['dc']);
}
foreach($officePropertyDC as $propertyName => $propertyValue) {
// echo $propertyName.' = '.$propertyValue.'<hr />';
switch ($propertyName) {
case 'title' :
$docProps->setTitle($propertyValue);
@@ -273,10 +307,12 @@ class PHPExcel_Reader_OOCalc implements PHPExcel_Reader_IReader
break;
case 'creator' :
$docProps->setCreator($propertyValue);
$docProps->setLastModifiedBy($propertyValue);
break;
case 'date' :
$creationDate = strtotime($propertyValue);
$docProps->setCreated($creationDate);
$docProps->setModified($creationDate);
break;
case 'description' :
$docProps->setDescription($propertyValue);
@@ -289,17 +325,43 @@ class PHPExcel_Reader_OOCalc implements PHPExcel_Reader_IReader
}
foreach($officePropertyMeta as $propertyName => $propertyValue) {
$propertyValueAttributes = $propertyValue->attributes($namespacesMeta['meta']);
// echo $propertyName.' = '.$propertyValue.'<br />';
// foreach ($propertyValueAttributes as $key => $value) {
// echo $key.' = '.$value.'<br />';
// }
// echo '<hr />';
//
switch ($propertyName) {
case 'initial-creator' :
$docProps->setCreator($propertyValue);
break;
case 'keyword' :
$docProps->setKeywords($propertyValue);
break;
case 'creation-date' :
$creationDate = strtotime($propertyValue);
$docProps->setCreated($creationDate);
break;
case 'user-defined' :
$propertyValueType = PHPExcel_DocumentProperties::PROPERTY_TYPE_STRING;
foreach ($propertyValueAttributes as $key => $value) {
if ($key == 'name') {
$propertyValueName = (string) $value;
} elseif($key == 'value-type') {
switch ($value) {
case 'date' :
$propertyValue = PHPExcel_DocumentProperties::convertProperty($propertyValue,'date');
$propertyValueType = PHPExcel_DocumentProperties::PROPERTY_TYPE_DATE;
break;
case 'boolean' :
$propertyValue = PHPExcel_DocumentProperties::convertProperty($propertyValue,'bool');
$propertyValueType = PHPExcel_DocumentProperties::PROPERTY_TYPE_BOOLEAN;
break;
case 'float' :
$propertyValue = PHPExcel_DocumentProperties::convertProperty($propertyValue,'r4');
$propertyValueType = PHPExcel_DocumentProperties::PROPERTY_TYPE_FLOAT;
break;
default :
$propertyValueType = PHPExcel_DocumentProperties::PROPERTY_TYPE_STRING;
}
}
}
$docProps->setCustomProperty($propertyValueName,$propertyValue,$propertyValueType);
break;
}
}
}
@@ -349,8 +411,15 @@ class PHPExcel_Reader_OOCalc implements PHPExcel_Reader_IReader
case 'table-row' :
$columnID = 'A';
foreach($rowData as $key => $cellData) {
if (!is_null($this->getReadFilter())) {
if (!$this->getReadFilter()->readCell($columnID, $rowID, $worksheetName)) {
continue;
}
}
// echo '<b>'.$columnID.$rowID.'</b><br />';
$cellDataText = $cellData->children($namespacesContent['text']);
$cellDataOffice = $cellData->children($namespacesContent['office']);
$cellDataOfficeAttributes = $cellData->attributes($namespacesContent['office']);
$cellDataTableAttributes = $cellData->attributes($namespacesContent['table']);
@@ -370,6 +439,22 @@ class PHPExcel_Reader_OOCalc implements PHPExcel_Reader_IReader
$hasCalculatedValue = true;
}
if (isset($cellDataOffice->annotation)) {
// echo 'Cell has comment<br />';
$annotationText = $cellDataOffice->annotation->children($namespacesContent['text']);
$textArray = array();
foreach($annotationText as $t) {
foreach($t->span as $text) {
$textArray[] = (string)$text;
}
}
$text = implode("\n",$textArray);
// echo $text,'<br />';
$objPHPExcel->getActiveSheet()->getComment( $columnID.$rowID )
// ->setAuthor( $author )
->setText($this->_parseRichText($text) );
}
if (isset($cellDataText->p)) {
// echo 'Value Type is '.$cellDataOfficeAttributes['value-type'].'<br />';
switch ($cellDataOfficeAttributes['value-type']) {
@@ -422,9 +507,10 @@ class PHPExcel_Reader_OOCalc implements PHPExcel_Reader_IReader
// echo 'Formula: '.$cellDataFormula.'<br />';
$cellDataFormula = substr($cellDataFormula,strpos($cellDataFormula,':=')+1);
$temp = explode('"',$cellDataFormula);
foreach($temp as $key => &$value) {
$tKey = false;
foreach($temp as &$value) {
// Only replace in alternate array entries (i.e. non-quoted blocks)
if (($key % 2) == 0) {
if ($tKey = !$tKey) {
$value = preg_replace('/\[\.(.*):\.(.*)\]/Ui','$1:$2',$value);
$value = preg_replace('/\[\.(.*)\]/Ui','$1',$value);
$value = PHPExcel_Calculation::_translateSeparator(';',',',$value,$inBraces);
@@ -485,23 +571,12 @@ class PHPExcel_Reader_OOCalc implements PHPExcel_Reader_IReader
return $objPHPExcel;
}
/**
* Get sheet index
*
* @return int
*/
public function getSheetIndex() {
return $this->_sheetIndex;
private function _parseRichText($is = '') {
$value = new PHPExcel_RichText();
$value->createText($is);
return $value;
}
/**
* Set sheet index
*
* @param int $pValue Sheet index
* @return PHPExcel_Reader_OOCalc
*/
public function setSheetIndex($pValue = 0) {
$this->_sheetIndex = $pValue;
return $this;
}
}

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
@@ -33,12 +33,6 @@ if (!defined('PHPEXCEL_ROOT')) {
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
PHPExcel_Autoloader::Register();
PHPExcel_Shared_ZipStreamWrapper::register();
// check mbstring.func_overload
if (ini_get('mbstring.func_overload') & 2) {
throw new Exception('Multibyte function overloading in PHP must be disabled for string functions (2).');
}
}
/**
@@ -46,7 +40,7 @@ if (!defined('PHPEXCEL_ROOT')) {
*
* @category PHPExcel
* @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Reader_SYLK implements PHPExcel_Reader_IReader
{
@@ -55,35 +49,14 @@ class PHPExcel_Reader_SYLK implements PHPExcel_Reader_IReader
*
* @var string
*/
private $_inputEncoding;
/**
* Delimiter
*
* @var string
*/
private $_delimiter;
/**
* Enclosure
*
* @var string
*/
private $_enclosure;
/**
* Line ending
*
* @var string
*/
private $_lineEnding;
private $_inputEncoding = 'ANSI';
/**
* Sheet index to read
*
* @var int
*/
private $_sheetIndex;
private $_sheetIndex = 0;
/**
* Formats
@@ -110,11 +83,6 @@ class PHPExcel_Reader_SYLK implements PHPExcel_Reader_IReader
* Create a new PHPExcel_Reader_SYLK
*/
public function __construct() {
$this->_inputEncoding = 'ANSI';
$this->_delimiter = ';';
$this->_enclosure = '"';
$this->_lineEnding = PHP_EOL;
$this->_sheetIndex = 0;
$this->_readFilter = new PHPExcel_Reader_DefaultReadFilter();
}
@@ -302,9 +270,10 @@ class PHPExcel_Reader_SYLK implements PHPExcel_Reader_IReader
case 'E' : $cellDataFormula = '='.substr($rowDatum,1);
// Convert R1C1 style references to A1 style references (but only when not quoted)
$temp = explode('"',$cellDataFormula);
foreach($temp as $key => &$value) {
$key = false;
foreach($temp as &$value) {
// Only count/replace in alternate array entries
if (($key % 2) == 0) {
if ($key = !$key) {
preg_match_all('/(R(\[?-?\d*\]?))(C(\[?-?\d*\]?))/',$value, $cellReferences,PREG_SET_ORDER+PREG_OFFSET_CAPTURE);
// Reverse the matches array, otherwise all our offsets will become incorrect if we modify our way
// through the formula from left to right. Reversing means that we work right to left.through
@@ -423,69 +392,6 @@ class PHPExcel_Reader_SYLK implements PHPExcel_Reader_IReader
return $objPHPExcel;
}
/**
* Get delimiter
*
* @return string
*/
public function getDelimiter() {
return $this->_delimiter;
}
/**
* Set delimiter
*
* @param string $pValue Delimiter, defaults to ,
* @return PHPExcel_Reader_SYLK
*/
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_SYLK
*/
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_SYLK
*/
public function setLineEnding($pValue = PHP_EOL) {
$this->_lineEnding = $pValue;
return $this;
}
/**
* Get sheet index
*

View File

@@ -1,130 +0,0 @@
<?php
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.4, 2010-08-26
*/
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
PHPExcel_Autoloader::Register();
PHPExcel_Shared_ZipStreamWrapper::register();
// check mbstring.func_overload
if (ini_get('mbstring.func_overload') & 2) {
throw new Exception('Multibyte function overloading in PHP must be disabled for string functions (2).');
}
}
/**
* PHPExcel_Reader_Serialized
*
* @category PHPExcel
* @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2010 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

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
@@ -31,7 +31,7 @@
*
* @category PHPExcel
* @package PHPExcel
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_ReferenceHelper
{
@@ -137,7 +137,8 @@ class PHPExcel_ReferenceHelper
if ($cell->getDataType() == PHPExcel_Cell_DataType::TYPE_FORMULA) {
// Formula should be adjusted
$pSheet->getCell($newCoordinates)
->setValue($this->updateFormulaReferences($cell->getValue(), $pBefore, $pNumCols, $pNumRows, $pSheet->getTitle()));
->setValue($this->updateFormulaReferences($cell->getValue(),
$pBefore, $pNumCols, $pNumRows, $pSheet->getTitle()));
} else {
// Formula should not be adjusted
$pSheet->getCell($newCoordinates)->setValue($cell->getValue());
@@ -145,6 +146,16 @@ class PHPExcel_ReferenceHelper
// Clear the original cell
$pSheet->getCell($cell->getCoordinate())->setValue('');
} else {
/* We don't need to update styles for rows/columns before our insertion position,
but we do still need to adjust any formulae in those cells */
if ($cell->getDataType() == PHPExcel_Cell_DataType::TYPE_FORMULA) {
// Formula should be adjusted
$cell->setValue($this->updateFormulaReferences($cell->getValue(),
$pBefore, $pNumCols, $pNumRows, $pSheet->getTitle()));
}
}
}
@@ -248,6 +259,14 @@ class PHPExcel_ReferenceHelper
}
}
// Update worksheet: comments
$aComments = $pSheet->getComments();
$aNewComments = array(); // the new array of all comments
foreach ($aComments as $key => &$value) {
$newReference = $this->updateCellReference($key, $pBefore, $pNumCols, $pNumRows);
$aNewComments[$newReference] = $value;
}
$pSheet->setComments($aNewComments); // replace the comments array
// Update worksheet: hyperlinks
$aHyperlinkCollection = array_reverse($pSheet->getHyperlinkCollection(), true);
@@ -348,9 +367,10 @@ class PHPExcel_ReferenceHelper
public function updateFormulaReferences($pFormula = '', $pBefore = 'A1', $pNumCols = 0, $pNumRows = 0, $sheetName = '') {
// Update cell references in the formula
$formulaBlocks = explode('"',$pFormula);
foreach($formulaBlocks as $i => &$formulaBlock) {
// Ignore blocks that were enclosed in quotes (even entries in the $formulaBlocks array after the explode)
if (($i % 2) == 0) {
$i = false;
foreach($formulaBlocks as &$formulaBlock) {
// Ignore blocks that were enclosed in quotes (alternating entries in the $formulaBlocks array after the explode)
if ($i = !$i) {
$adjustCount = 0;
$newCellTokens = $cellTokens = array();
// Search for row ranges (e.g. 'Sheet1'!3:5 or 3:5) with or without $ absolutes (e.g. $3:5)
@@ -525,7 +545,7 @@ class PHPExcel_ReferenceHelper
/**
* Update cell range
*
* @param string $pCellRange Cell range
* @param string $pCellRange Cell range (e.g. 'B2:D4', 'B:C' or '2:3')
* @param int $pBefore Insert before this one
* @param int $pNumCols Number of columns to increment
* @param int $pNumRows Number of rows to increment
@@ -536,9 +556,19 @@ class PHPExcel_ReferenceHelper
if (strpos($pCellRange,':') !== false || strpos($pCellRange, ',') !== false) {
// Update range
$range = PHPExcel_Cell::splitRange($pCellRange);
for ($i = 0; $i < count($range); ++$i) {
for ($j = 0; $j < count($range[$i]); ++$j) {
$range[$i][$j] = $this->_updateSingleCellReference($range[$i][$j], $pBefore, $pNumCols, $pNumRows);
$ic = count($range);
for ($i = 0; $i < $ic; ++$i) {
$jc = count($range[$i]);
for ($j = 0; $j < $jc; ++$j) {
if (ctype_alpha($range[$i][$j])) {
$r = PHPExcel_Cell::coordinateFromString($this->_updateSingleCellReference($range[$i][$j].'1', $pBefore, $pNumCols, $pNumRows));
$range[$i][$j] = $r[0];
} elseif(ctype_digit($range[$i][$j])) {
$r = PHPExcel_Cell::coordinateFromString($this->_updateSingleCellReference('A'.$range[$i][$j], $pBefore, $pNumCols, $pNumRows));
$range[$i][$j] = $r[1];
} else {
$range[$i][$j] = $this->_updateSingleCellReference($range[$i][$j], $pBefore, $pNumCols, $pNumRows);
}
}
}
@@ -562,29 +592,17 @@ class PHPExcel_ReferenceHelper
private function _updateSingleCellReference($pCellReference = 'A1', $pBefore = 'A1', $pNumCols = 0, $pNumRows = 0) {
if (strpos($pCellReference, ':') === false && strpos($pCellReference, ',') === false) {
// Get coordinates of $pBefore
$beforeColumn = 'A';
$beforeRow = 1;
list($beforeColumn, $beforeRow) = PHPExcel_Cell::coordinateFromString( $pBefore );
// Get coordinates
$newColumn = 'A';
$newRow = 1;
// Get coordinates of $pCellReference
list($newColumn, $newRow) = PHPExcel_Cell::coordinateFromString( $pCellReference );
// Make sure the reference can be used
if ($newColumn == '' && $newRow == '')
{
return $pCellReference;
}
// Verify which parts should be updated
$updateColumn = (PHPExcel_Cell::columnIndexFromString($newColumn) >= PHPExcel_Cell::columnIndexFromString($beforeColumn))
&& (strpos($newColumn, '$') === false)
&& (strpos($beforeColumn, '$') === false);
$updateColumn = (($newColumn{0} != '$') && ($beforeColumn{0} != '$') &&
PHPExcel_Cell::columnIndexFromString($newColumn) >= PHPExcel_Cell::columnIndexFromString($beforeColumn));
$updateRow = ($newRow >= $beforeRow)
&& (strpos($newRow, '$') === false)
&& (strpos($beforeRow, '$') === false);
$updateRow = (($newRow{0} != '$') && ($beforeRow{0} != '$') &&
$newRow >= $beforeRow);
// Create new column reference
if ($updateColumn) {

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_RichText
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
@@ -31,7 +31,7 @@
*
* @category PHPExcel
* @package PHPExcel_RichText
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_RichText implements PHPExcel_IComparable
{

View File

@@ -18,9 +18,9 @@
*
* @category PHPExcel
* @package PHPExcel_RichText
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
@@ -29,7 +29,7 @@
*
* @category PHPExcel
* @package PHPExcel_RichText
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
interface PHPExcel_RichText_ITextElement
{

View File

@@ -18,9 +18,9 @@
*
* @category PHPExcel
* @package PHPExcel_RichText
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
@@ -29,7 +29,7 @@
*
* @category PHPExcel
* @package PHPExcel_RichText
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_RichText_Run extends PHPExcel_RichText_TextElement implements PHPExcel_RichText_ITextElement
{

View File

@@ -18,9 +18,9 @@
*
* @category PHPExcel
* @package PHPExcel_RichText
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
@@ -29,7 +29,7 @@
*
* @category PHPExcel
* @package PHPExcel_RichText
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_RichText_TextElement implements PHPExcel_RichText_ITextElement
{

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Settings
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
/** PHPExcel root directory */
@@ -32,17 +32,45 @@ if (!defined('PHPEXCEL_ROOT')) {
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../');
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
PHPExcel_Autoloader::Register();
PHPExcel_Shared_ZipStreamWrapper::register();
// check mbstring.func_overload
if (ini_get('mbstring.func_overload') & 2) {
throw new Exception('Multibyte function overloading in PHP must be disabled for string functions (2).');
}
}
class PHPExcel_Settings
{
/** constants */
const PCLZIP = 'PHPExcel_Shared_ZipArchive';
const ZIPARCHIVE = 'ZipArchive';
private static $_zipClass = self::ZIPARCHIVE;
/**
* Set the Zip Class to use (PCLZip or ZipArchive)
*
* @param string $zipClass PHPExcel_Settings::PCLZip or PHPExcel_Settings::ZipArchive
* @return boolean Success or failure
*/
public static function setZipClass($zipClass) {
if (($zipClass == self::PCLZIP) ||
($zipClass == self::ZIPARCHIVE)) {
self::$_zipClass = $zipClass;
return True;
}
return False;
} // function setZipClass()
/**
* Return the Zip Class to use (PCLZip or ZipArchive)
*
* @return string Zip Class to use - PHPExcel_Settings::PCLZip or PHPExcel_Settings::ZipArchive
*/
public static function getZipClass() {
return self::$_zipClass;
} // function getZipClass()
public static function getCacheStorageMethod() {
return PHPExcel_CachedObjectStorageFactory::$_cacheStorageMethod;
} // function getCacheStorageMethod()

View File

@@ -1,94 +0,0 @@
<?php
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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_Shared
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.4, 2010-08-26
*/
/**
* PHPExcel_Shared_CodePage
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_CodePage
{
/**
* Convert Microsoft Code Page Identifier to Code Page Name which iconv
* and mbstring understands
*
* @param int $number Microsoft Code Page Indentifier
* @return string Code Page Name
* @throws Exception
*/
public static function NumberToName($codePage = '1252')
{
switch ($codePage) {
case 367: return 'ASCII'; break; // ASCII
case 437: return 'CP437'; break; //OEM US
case 720: throw new Exception('Code page 720 not supported.');
break; //OEM Arabic
case 737: return 'CP737'; break; //OEM Greek
case 775: return 'CP775'; break; //OEM Baltic
case 850: return 'CP850'; break; //OEM Latin I
case 852: return 'CP852'; break; //OEM Latin II (Central European)
case 855: return 'CP855'; break; //OEM Cyrillic
case 857: return 'CP857'; break; //OEM Turkish
case 858: return 'CP858'; break; //OEM Multilingual Latin I with Euro
case 860: return 'CP860'; break; //OEM Portugese
case 861: return 'CP861'; break; //OEM Icelandic
case 862: return 'CP862'; break; //OEM Hebrew
case 863: return 'CP863'; break; //OEM Canadian (French)
case 864: return 'CP864'; break; //OEM Arabic
case 865: return 'CP865'; break; //OEM Nordic
case 866: return 'CP866'; break; //OEM Cyrillic (Russian)
case 869: return 'CP869'; break; //OEM Greek (Modern)
case 874: return 'CP874'; break; //ANSI Thai
case 932: return 'CP932'; break; //ANSI Japanese Shift-JIS
case 936: return 'CP936'; break; //ANSI Chinese Simplified GBK
case 949: return 'CP949'; break; //ANSI Korean (Wansung)
case 950: return 'CP950'; break; //ANSI Chinese Traditional BIG5
case 1200: return 'UTF-16LE'; break; //UTF-16 (BIFF8)
case 1250: return 'CP1250'; break; // ANSI Latin II (Central European)
case 1251: return 'CP1251'; break; //ANSI Cyrillic
case 1252: return 'CP1252'; break; //ANSI Latin I (BIFF4-BIFF7)
case 1253: return 'CP1253'; break; //ANSI Greek
case 1254: return 'CP1254'; break; //ANSI Turkish
case 1255: return 'CP1255'; break; //ANSI Hebrew
case 1256: return 'CP1256'; break; //ANSI Arabic
case 1257: return 'CP1257'; break; //ANSI Baltic
case 1258: return 'CP1258'; break; //ANSI Vietnamese
case 1361: return 'CP1361'; break; //ANSI Korean (Johab)
case 10000: return 'MAC'; break; //Apple Roman
case 32768: return 'MAC'; break; //Apple Roman
case 32769: throw new Exception('Code page 32769 not supported.');
break; //ANSI Latin I (BIFF2-BIFF3)
case 65001: return 'UTF-8'; break; //Unicode (UTF-8)
}
throw new Exception('Unknown codepage: ' . $codePage);
}
}

View File

@@ -1,303 +0,0 @@
<?php
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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_Shared
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.4, 2010-08-26
*/
/**
* PHPExcel_Shared_Date
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_Date
{
/** constants */
const CALENDAR_WINDOWS_1900 = 1900; // Base date of 1st Jan 1900 = 1.0
const CALENDAR_MAC_1904 = 1904; // Base date of 2nd Jan 1904 = 1.0
private static $ExcelBaseDate = self::CALENDAR_WINDOWS_1900;
public static $dateTimeObjectType = 'DateTime';
/**
* Set the Excel calendar (Windows 1900 or Mac 1904)
*
* @param integer $baseDate Excel base date
* @return boolean Success or failure
*/
public static function setExcelCalendar($baseDate) {
if (($baseDate == self::CALENDAR_WINDOWS_1900) ||
($baseDate == self::CALENDAR_MAC_1904)) {
self::$ExcelBaseDate = $baseDate;
return True;
}
return False;
} // function setExcelCalendar()
/**
* Return the Excel calendar (Windows 1900 or Mac 1904)
*
* @return integer $baseDate Excel base date
*/
public static function getExcelCalendar() {
return self::$ExcelBaseDate;
} // function getExcelCalendar()
/**
* Convert a date from Excel to PHP
*
* @param long $dateValue Excel date/time value
* @return long PHP serialized date/time
*/
public static function ExcelToPHP($dateValue = 0) {
if (self::$ExcelBaseDate == self::CALENDAR_WINDOWS_1900) {
$myExcelBaseDate = 25569;
// Adjust for the spurious 29-Feb-1900 (Day 60)
if ($dateValue < 60) {
--$myExcelBaseDate;
}
} else {
$myExcelBaseDate = 24107;
}
// Perform conversion
if ($dateValue >= 1) {
$utcDays = $dateValue - $myExcelBaseDate;
$returnValue = round($utcDays * 24 * 60 * 60);
if (($returnValue <= PHP_INT_MAX) && ($returnValue >= -PHP_INT_MAX)) {
$returnValue = (integer) $returnValue;
}
} else {
$hours = round($dateValue * 24);
$mins = round($dateValue * 24 * 60) - round($hours * 60);
$secs = round($dateValue * 24 * 60 * 60) - round($hours * 60 * 60) - round($mins * 60);
$returnValue = (integer) gmmktime($hours, $mins, $secs);
}
// Return
return $returnValue;
} // function ExcelToPHP()
/**
* Convert a date from Excel to a PHP Date/Time object
*
* @param long $dateValue Excel date/time value
* @return long PHP date/time object
*/
public static function ExcelToPHPObject($dateValue = 0) {
$dateTime = self::ExcelToPHP($dateValue);
$days = floor($dateTime / 86400);
$time = round((($dateTime / 86400) - $days) * 86400);
$hours = round($time / 3600);
$minutes = round($time / 60) - ($hours * 60);
$seconds = round($time) - ($hours * 3600) - ($minutes * 60);
$dateObj = date_create('1-Jan-1970+'.$days.' days');
$dateObj->setTime($hours,$minutes,$seconds);
return $dateObj;
} // function ExcelToPHPObject()
/**
* Convert a date from PHP to Excel
*
* @param mixed $dateValue PHP serialized date/time or date object
* @return mixed Excel date/time value
* or boolean False on failure
*/
public static function PHPToExcel($dateValue = 0) {
$saveTimeZone = date_default_timezone_get();
date_default_timezone_set('UTC');
$retValue = False;
if ((is_object($dateValue)) && ($dateValue instanceof self::$dateTimeObjectType)) {
$retValue = self::FormattedPHPToExcel( $dateValue->format('Y'), $dateValue->format('m'), $dateValue->format('d'),
$dateValue->format('H'), $dateValue->format('i'), $dateValue->format('s')
);
} elseif (is_numeric($dateValue)) {
$retValue = self::FormattedPHPToExcel( date('Y',$dateValue), date('m',$dateValue), date('d',$dateValue),
date('H',$dateValue), date('i',$dateValue), date('s',$dateValue)
);
}
date_default_timezone_set($saveTimeZone);
return $retValue;
} // function PHPToExcel()
/**
* FormattedPHPToExcel
*
* @param long $year
* @param long $month
* @param long $day
* @param long $hours
* @param long $minutes
* @param long $seconds
* @return long Excel date/time value
*/
public static function FormattedPHPToExcel($year, $month, $day, $hours=0, $minutes=0, $seconds=0) {
if (self::$ExcelBaseDate == self::CALENDAR_WINDOWS_1900) {
//
// Fudge factor for the erroneous fact that the year 1900 is treated as a Leap Year in MS Excel
// This affects every date following 28th February 1900
//
$excel1900isLeapYear = True;
if (($year == 1900) && ($month <= 2)) { $excel1900isLeapYear = False; }
$myExcelBaseDate = 2415020;
} else {
$myExcelBaseDate = 2416481;
$excel1900isLeapYear = False;
}
// Julian base date Adjustment
if ($month > 2) {
$month = $month - 3;
} else {
$month = $month + 9;
--$year;
}
// Calculate the Julian Date, then subtract the Excel base date (JD 2415020 = 31-Dec-1899 Giving Excel Date of 0)
$century = substr($year,0,2);
$decade = substr($year,2,2);
$excelDate = floor((146097 * $century) / 4) + floor((1461 * $decade) / 4) + floor((153 * $month + 2) / 5) + $day + 1721119 - $myExcelBaseDate + $excel1900isLeapYear;
$excelTime = (($hours * 3600) + ($minutes * 60) + $seconds) / 86400;
return (float) $excelDate + $excelTime;
} // function FormattedPHPToExcel()
/**
* Is a given cell a date/time?
*
* @param PHPExcel_Cell $pCell
* @return boolean
*/
public static function isDateTime(PHPExcel_Cell $pCell) {
return self::isDateTimeFormat($pCell->getParent()->getStyle($pCell->getCoordinate())->getNumberFormat());
} // function isDateTime()
/**
* Is a given number format a date/time?
*
* @param PHPExcel_Style_NumberFormat $pFormat
* @return boolean
*/
public static function isDateTimeFormat(PHPExcel_Style_NumberFormat $pFormat) {
return self::isDateTimeFormatCode($pFormat->getFormatCode());
} // function isDateTimeFormat()
private static $possibleDateFormatCharacters = 'ymdHis';
/**
* Is a given number format code a date/time?
*
* @param string $pFormatCode
* @return boolean
*/
public static function isDateTimeFormatCode($pFormatCode = '') {
// Switch on formatcode
switch ($pFormatCode) {
case PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDD:
case PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDD2:
case PHPExcel_Style_NumberFormat::FORMAT_DATE_DDMMYYYY:
case PHPExcel_Style_NumberFormat::FORMAT_DATE_DMYSLASH:
case PHPExcel_Style_NumberFormat::FORMAT_DATE_DMYMINUS:
case PHPExcel_Style_NumberFormat::FORMAT_DATE_DMMINUS:
case PHPExcel_Style_NumberFormat::FORMAT_DATE_MYMINUS:
case PHPExcel_Style_NumberFormat::FORMAT_DATE_DATETIME:
case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME1:
case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME2:
case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME3:
case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME4:
case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME5:
case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME6:
case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME7:
case PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME8:
case PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDDSLASH:
case PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX14:
case PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX15:
case PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX16:
case PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX17:
case PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX22:
return true;
}
// Try checking for any of the date formatting characters that don't appear within square braces
if (preg_match('/(^|\])[^\[]*['.self::$possibleDateFormatCharacters.']/i',$pFormatCode)) {
return true;
}
// No date...
return false;
} // function isDateTimeFormatCode()
/**
* Convert a date/time string to Excel time
*
* @param string $dateValue Examples: '2009-12-31', '2009-12-31 15:59', '2009-12-31 15:59:10'
* @return float|false Excel date/time serial value
*/
public static function stringToExcel($dateValue = '') {
// restrict to dates and times like these because date_parse accepts too many strings
// '2009-12-31'
// '2009-12-31 15:59'
// '2009-12-31 15:59:10'
if (!preg_match('/^\d{4}\-\d{1,2}\-\d{1,2}( \d{1,2}:\d{1,2}(:\d{1,2})?)?$/', $dateValue)) {
return false;
}
// now try with date_parse
$PHPDateArray = date_parse($dateValue);
if ($PHPDateArray['error_count'] == 0) {
$year = $PHPDateArray['year'] !== false ? $PHPDateArray['year'] : self::getExcelCalendar();
$month = $PHPDateArray['month'] !== false ? $PHPDateArray['month'] : 1;
$day = $PHPDateArray['day'] !== false ? $PHPDateArray['day'] : 0;
$hour = $PHPDateArray['hour'] !== false ? $PHPDateArray['hour'] : 0;
$minute = $PHPDateArray['minute'] !== false ? $PHPDateArray['minute'] : 0;
$second = $PHPDateArray['second'] !== false ? $PHPDateArray['second'] : 0;
$excelDateValue = PHPExcel_Shared_Date::FormattedPHPToExcel($year, $month, $day, $hour, $minute, $second);
return $excelDateValue;
}
return false;
}
}

View File

@@ -1,272 +0,0 @@
<?php
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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_Shared
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.4, 2010-08-26
*/
/**
* PHPExcel_Shared_Drawing
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_Drawing
{
/**
* Convert pixels to EMU
*
* @param int $pValue Value in pixels
* @return int Value in EMU
*/
public static function pixelsToEMU($pValue = 0) {
return round($pValue * 9525);
}
/**
* Convert EMU to pixels
*
* @param int $pValue Value in EMU
* @return int Value in pixels
*/
public static function EMUToPixels($pValue = 0) {
if ($pValue != 0) {
return round($pValue / 9525);
} else {
return 0;
}
}
/**
* Convert pixels to column width. Exact algorithm not known.
* By inspection of a real Excel file using Calibri 11, one finds 1000px ~ 142.85546875
* This gives a conversion factor of 7. Also, we assume that pixels and font size are proportional.
*
* @param int $pValue Value in pixels
* @param PHPExcel_Style_Font $pDefaultFont Default font of the workbook
* @return int Value in cell dimension
*/
public static function pixelsToCellDimension($pValue = 0, PHPExcel_Style_Font $pDefaultFont) {
// Font name and size
$name = $pDefaultFont->getName();
$size = $pDefaultFont->getSize();
if (isset(PHPExcel_Shared_Font::$defaultColumnWidths[$name][$size])) {
// Exact width can be determined
$colWidth = $pValue
* PHPExcel_Shared_Font::$defaultColumnWidths[$name][$size]['width']
/ PHPExcel_Shared_Font::$defaultColumnWidths[$name][$size]['px'];
} else {
// We don't have data for this particular font and size, use approximation by
// extrapolating from Calibri 11
$colWidth = $pValue * 11
* PHPExcel_Shared_Font::$defaultColumnWidths['Calibri'][11]['width']
/ PHPExcel_Shared_Font::$defaultColumnWidths['Calibri'][11]['px'] / $size;
}
return $colWidth;
}
/**
* Convert column width from (intrinsic) Excel units to pixels
*
* @param float $pValue Value in cell dimension
* @param PHPExcel_Style_Font $pDefaultFont Default font of the workbook
* @return int Value in pixels
*/
public static function cellDimensionToPixels($pValue = 0, PHPExcel_Style_Font $pDefaultFont) {
// Font name and size
$name = $pDefaultFont->getName();
$size = $pDefaultFont->getSize();
if (isset(PHPExcel_Shared_Font::$defaultColumnWidths[$name][$size])) {
// Exact width can be determined
$colWidth = $pValue
* PHPExcel_Shared_Font::$defaultColumnWidths[$name][$size]['px']
/ PHPExcel_Shared_Font::$defaultColumnWidths[$name][$size]['width'];
} else {
// We don't have data for this particular font and size, use approximation by
// extrapolating from Calibri 11
$colWidth = $pValue * $size
* PHPExcel_Shared_Font::$defaultColumnWidths['Calibri'][11]['px']
/ PHPExcel_Shared_Font::$defaultColumnWidths['Calibri'][11]['width'] / 11;
}
// Round pixels to closest integer
$colWidth = (int) round($colWidth);
return $colWidth;
}
/**
* Convert pixels to points
*
* @param int $pValue Value in pixels
* @return int Value in points
*/
public static function pixelsToPoints($pValue = 0) {
return $pValue * 0.67777777;
}
/**
* Convert points to pixels
*
* @param int $pValue Value in points
* @return int Value in pixels
*/
public static function pointsToPixels($pValue = 0) {
if ($pValue != 0) {
return (int) ceil($pValue * 1.333333333);
} else {
return 0;
}
}
/**
* Convert degrees to angle
*
* @param int $pValue Degrees
* @return int Angle
*/
public static function degreesToAngle($pValue = 0) {
return (int)round($pValue * 60000);
}
/**
* Convert angle to degrees
*
* @param int $pValue Angle
* @return int Degrees
*/
public static function angleToDegrees($pValue = 0) {
if ($pValue != 0) {
return round($pValue / 60000);
} else {
return 0;
}
}
/**
* Create a new image from file. By alexander at alexauto dot nl
*
* @link http://www.php.net/manual/en/function.imagecreatefromwbmp.php#86214
* @param string $filename Path to Windows DIB (BMP) image
* @return resource
*/
public static function imagecreatefrombmp($p_sFile)
{
// Load the image into a string
$file = fopen($p_sFile,"rb");
$read = fread($file,10);
while(!feof($file)&&($read<>""))
$read .= fread($file,1024);
$temp = unpack("H*",$read);
$hex = $temp[1];
$header = substr($hex,0,108);
// Process the header
// Structure: http://www.fastgraph.com/help/bmp_header_format.html
if (substr($header,0,4)=="424d")
{
// Cut it in parts of 2 bytes
$header_parts = str_split($header,2);
// Get the width 4 bytes
$width = hexdec($header_parts[19].$header_parts[18]);
// Get the height 4 bytes
$height = hexdec($header_parts[23].$header_parts[22]);
// Unset the header params
unset($header_parts);
}
// Define starting X and Y
$x = 0;
$y = 1;
// Create newimage
$image = imagecreatetruecolor($width,$height);
// Grab the body from the image
$body = substr($hex,108);
// Calculate if padding at the end-line is needed
// Divided by two to keep overview.
// 1 byte = 2 HEX-chars
$body_size = (strlen($body)/2);
$header_size = ($width*$height);
// Use end-line padding? Only when needed
$usePadding = ($body_size>($header_size*3)+4);
// Using a for-loop with index-calculation instaid of str_split to avoid large memory consumption
// Calculate the next DWORD-position in the body
for ($i=0;$i<$body_size;$i+=3)
{
// Calculate line-ending and padding
if ($x>=$width)
{
// If padding needed, ignore image-padding
// Shift i to the ending of the current 32-bit-block
if ($usePadding)
$i += $width%4;
// Reset horizontal position
$x = 0;
// Raise the height-position (bottom-up)
$y++;
// Reached the image-height? Break the for-loop
if ($y>$height)
break;
}
// Calculation of the RGB-pixel (defined as BGR in image-data)
// Define $i_pos as absolute position in the body
$i_pos = $i*2;
$r = hexdec($body[$i_pos+4].$body[$i_pos+5]);
$g = hexdec($body[$i_pos+2].$body[$i_pos+3]);
$b = hexdec($body[$i_pos].$body[$i_pos+1]);
// Calculate and draw the pixel
$color = imagecolorallocate($image,$r,$g,$b);
imagesetpixel($image,$x,$height-$y,$color);
// Raise the horizontal position
$x++;
}
// Unset the body / free the memory
unset($body);
// Return image-object
return $image;
}
}

View File

@@ -1,91 +0,0 @@
<?php
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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_Shared_Escher
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.4, 2010-08-26
*/
/**
* PHPExcel_Shared_Escher
*
* @category PHPExcel
* @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_Escher
{
/**
* Drawing Group Container
*
* @var PHPExcel_Shared_Escher_DggContainer
*/
private $_dggContainer;
/**
* Drawing Container
*
* @var PHPExcel_Shared_Escher_DgContainer
*/
private $_dgContainer;
/**
* Get Drawing Group Container
*
* @return PHPExcel_Shared_Escher_DgContainer
*/
public function getDggContainer()
{
return $this->_dggContainer;
}
/**
* Set Drawing Group Container
*
* @param PHPExcel_Shared_Escher_DggContainer $dggContainer
*/
public function setDggContainer($dggContainer)
{
return $this->_dggContainer = $dggContainer;
}
/**
* Get Drawing Container
*
* @return PHPExcel_Shared_Escher_DgContainer
*/
public function getDgContainer()
{
return $this->_dgContainer;
}
/**
* Set Drawing Container
*
* @param PHPExcel_Shared_Escher_DgContainer $dgContainer
*/
public function setDgContainer($dgContainer)
{
return $this->_dgContainer = $dgContainer;
}
}

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
/**
@@ -30,7 +30,7 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_Escher_DgContainer
{

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
/**
@@ -30,7 +30,7 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_Escher_DgContainer_SpgrContainer
{

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
/**
@@ -30,7 +30,7 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_Escher_DgContainer_SpgrContainer_SpContainer
{

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
/**
@@ -30,7 +30,7 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_Escher_DggContainer
{

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
/**
@@ -30,7 +30,7 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_Escher_DggContainer_BstoreContainer
{

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
/**
@@ -30,7 +30,7 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE
{

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
/**
@@ -30,7 +30,7 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE_Blip
{

View File

@@ -1,317 +0,0 @@
<?php
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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_Shared
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.4, 2010-08-26
*/
/**
* PHPExcel_Shared_Excel5
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_Excel5
{
/**
* Get the width of a column in pixels. We use the relationship y = ceil(7x) where
* x is the width in intrinsic Excel units (measuring width in number of normal characters)
* This holds for Arial 10
*
* @param PHPExcel_Worksheet $sheet The sheet
* @param integer $col The column
* @return integer The width in pixels
*/
public static function sizeCol($sheet, $col = 'A')
{
// default font of the workbook
$font = $sheet->getParent()->getDefaultStyle()->getFont();
$columnDimensions = $sheet->getColumnDimensions();
// first find the true column width in pixels (uncollapsed and unhidden)
if ( isset($columnDimensions[$col]) and $columnDimensions[$col]->getWidth() != -1 ) {
// then we have column dimension with explicit width
$columnDimension = $columnDimensions[$col];
$width = $columnDimension->getWidth();
$pixelWidth = PHPExcel_Shared_Drawing::cellDimensionToPixels($width, $font);
} else if ($sheet->getDefaultColumnDimension()->getWidth() != -1) {
// then we have default column dimension with explicit width
$defaultColumnDimension = $sheet->getDefaultColumnDimension();
$width = $defaultColumnDimension->getWidth();
$pixelWidth = PHPExcel_Shared_Drawing::cellDimensionToPixels($width, $font);
} else {
// we don't even have any default column dimension. Width depends on default font
$pixelWidth = PHPExcel_Shared_Font::getDefaultColumnWidthByFont($font, true);
}
// now find the effective column width in pixels
if (isset($columnDimensions[$col]) and !$columnDimensions[$col]->getVisible()) {
$effectivePixelWidth = 0;
} else {
$effectivePixelWidth = $pixelWidth;
}
return $effectivePixelWidth;
}
/**
* Convert the height of a cell from user's units to pixels. By interpolation
* the relationship is: y = 4/3x. If the height hasn't been set by the user we
* use the default value. If the row is hidden we use a value of zero.
*
* @param PHPExcel_Worksheet $sheet The sheet
* @param integer $row The row index (1-based)
* @return integer The width in pixels
*/
public static function sizeRow($sheet, $row = 1)
{
// default font of the workbook
$font = $sheet->getParent()->getDefaultStyle()->getFont();
$rowDimensions = $sheet->getRowDimensions();
// first find the true row height in pixels (uncollapsed and unhidden)
if ( isset($rowDimensions[$row]) and $rowDimensions[$row]->getRowHeight() != -1) {
// then we have a row dimension
$rowDimension = $rowDimensions[$row];
$rowHeight = $rowDimension->getRowHeight();
$pixelRowHeight = (int) ceil(4 * $rowHeight / 3); // here we assume Arial 10
} else if ($sheet->getDefaultRowDimension()->getRowHeight() != -1) {
// then we have a default row dimension with explicit height
$defaultRowDimension = $sheet->getDefaultRowDimension();
$rowHeight = $defaultRowDimension->getRowHeight();
$pixelRowHeight = PHPExcel_Shared_Drawing::pointsToPixels($rowHeight);
} else {
// we don't even have any default row dimension. Height depends on default font
$pointRowHeight = PHPExcel_Shared_Font::getDefaultRowHeightByFont($font);
$pixelRowHeight = PHPExcel_Shared_Font::fontSizeToPixels($pointRowHeight);
}
// now find the effective row height in pixels
if ( isset($rowDimensions[$row]) and !$rowDimensions[$row]->getVisible() ) {
$effectivePixelRowHeight = 0;
} else {
$effectivePixelRowHeight = $pixelRowHeight;
}
return $effectivePixelRowHeight;
}
/**
* Get the horizontal distance in pixels between two anchors
* The distanceX is found as sum of all the spanning columns widths minus correction for the two offsets
*
* @param PHPExcel_Worksheet $sheet
* @param string $startColumn
* @param integer $startOffset Offset within start cell measured in 1/1024 of the cell width
* @param string $endColumn
* @param integer $endOffset Offset within end cell measured in 1/1024 of the cell width
* @return integer Horizontal measured in pixels
*/
public static function getDistanceX(PHPExcel_Worksheet $sheet, $startColumn = 'A', $startOffsetX = 0, $endColumn = 'A', $endOffsetX = 0)
{
$distanceX = 0;
// add the widths of the spanning columns
$startColumnIndex = PHPExcel_Cell::columnIndexFromString($startColumn) - 1; // 1-based
$endColumnIndex = PHPExcel_Cell::columnIndexFromString($endColumn) - 1; // 1-based
for ($i = $startColumnIndex; $i <= $endColumnIndex; ++$i) {
$distanceX += self::sizeCol($sheet, PHPExcel_Cell::stringFromColumnIndex($i));
}
// correct for offsetX in startcell
$distanceX -= (int) floor(self::sizeCol($sheet, $startColumn) * $startOffsetX / 1024);
// correct for offsetX in endcell
$distanceX -= (int) floor(self::sizeCol($sheet, $endColumn) * (1 - $endOffsetX / 1024));
return $distanceX;
}
/**
* Get the vertical distance in pixels between two anchors
* The distanceY is found as sum of all the spanning rows minus two offsets
*
* @param PHPExcel_Worksheet $sheet
* @param string $startRow (1-based)
* @param integer $startOffset Offset within start cell measured in 1/256 of the cell height
* @param string $endRow (1-based)
* @param integer $endOffset Offset within end cell measured in 1/256 of the cell height
* @return integer Vertical distance measured in pixels
*/
public static function getDistanceY(PHPExcel_Worksheet $sheet, $startRow = 1, $startOffsetY = 0, $endRow = 1, $endOffsetY = 0)
{
$distanceY = 0;
// add the widths of the spanning rows
for ($row = $startRow; $row <= $endRow; ++$row) {
$distanceY += self::sizeRow($sheet, $row);
}
// correct for offsetX in startcell
$distanceY -= (int) floor(self::sizeRow($sheet, $startRow) * $startOffsetY / 256);
// correct for offsetX in endcell
$distanceY -= (int) floor(self::sizeRow($sheet, $endRow) * (1 - $endOffsetY / 256));
return $distanceY;
}
/**
* Convert 1-cell anchor coordinates to 2-cell anchor coordinates
* This function is ported from PEAR Spreadsheet_Writer_Excel with small modifications
*
* Calculate the vertices that define the position of the image as required by
* the OBJ record.
*
* +------------+------------+
* | A | B |
* +-----+------------+------------+
* | |(x1,y1) | |
* | 1 |(A1)._______|______ |
* | | | | |
* | | | | |
* +-----+----| BITMAP |-----+
* | | | | |
* | 2 | |______________. |
* | | | (B2)|
* | | | (x2,y2)|
* +---- +------------+------------+
*
* Example of a bitmap that covers some of the area from cell A1 to cell B2.
*
* Based on the width and height of the bitmap we need to calculate 8 vars:
* $col_start, $row_start, $col_end, $row_end, $x1, $y1, $x2, $y2.
* The width and height of the cells are also variable and have to be taken into
* account.
* The values of $col_start and $row_start are passed in from the calling
* function. The values of $col_end and $row_end are calculated by subtracting
* the width and height of the bitmap from the width and height of the
* underlying cells.
* The vertices are expressed as a percentage of the underlying cell width as
* follows (rhs values are in pixels):
*
* x1 = X / W *1024
* y1 = Y / H *256
* x2 = (X-1) / W *1024
* y2 = (Y-1) / H *256
*
* Where: X is distance from the left side of the underlying cell
* Y is distance from the top of the underlying cell
* W is the width of the cell
* H is the height of the cell
*
* @param PHPExcel_Worksheet $sheet
* @param string $coordinates E.g. 'A1'
* @param integer $offsetX Horizontal offset in pixels
* @param integer $offsetY Vertical offset in pixels
* @param integer $width Width in pixels
* @param integer $height Height in pixels
* @return array
*/
public static function oneAnchor2twoAnchor($sheet, $coordinates, $offsetX, $offsetY, $width, $height)
{
list($column, $row) = PHPExcel_Cell::coordinateFromString($coordinates);
$col_start = PHPExcel_Cell::columnIndexFromString($column) - 1;
$row_start = $row - 1;
$x1 = $offsetX;
$y1 = $offsetY;
// Initialise end cell to the same as the start cell
$col_end = $col_start; // Col containing lower right corner of object
$row_end = $row_start; // Row containing bottom right corner of object
// Zero the specified offset if greater than the cell dimensions
if ($x1 >= self::sizeCol($sheet, PHPExcel_Cell::stringFromColumnIndex($col_start))) {
$x1 = 0;
}
if ($y1 >= self::sizeRow($sheet, $row_start + 1)) {
$y1 = 0;
}
$width = $width + $x1 -1;
$height = $height + $y1 -1;
// Subtract the underlying cell widths to find the end cell of the image
while ($width >= self::sizeCol($sheet, PHPExcel_Cell::stringFromColumnIndex($col_end))) {
$width -= self::sizeCol($sheet, PHPExcel_Cell::stringFromColumnIndex($col_end));
++$col_end;
}
// Subtract the underlying cell heights to find the end cell of the image
while ($height >= self::sizeRow($sheet, $row_end + 1)) {
$height -= self::sizeRow($sheet, $row_end + 1);
++$row_end;
}
// Bitmap isn't allowed to start or finish in a hidden cell, i.e. a cell
// with zero height or width.
if (self::sizeCol($sheet, PHPExcel_Cell::stringFromColumnIndex($col_start)) == 0) {
return;
}
if (self::sizeCol($sheet, PHPExcel_Cell::stringFromColumnIndex($col_end)) == 0) {
return;
}
if (self::sizeRow($sheet, $row_start + 1) == 0) {
return;
}
if (self::sizeRow($sheet, $row_end + 1) == 0) {
return;
}
// Convert the pixel values to the percentage value expected by Excel
$x1 = $x1 / self::sizeCol($sheet, PHPExcel_Cell::stringFromColumnIndex($col_start)) * 1024;
$y1 = $y1 / self::sizeRow($sheet, $row_start + 1) * 256;
$x2 = ($width + 1) / self::sizeCol($sheet, PHPExcel_Cell::stringFromColumnIndex($col_end)) * 1024; // Distance to right side of object
$y2 = ($height + 1) / self::sizeRow($sheet, $row_end + 1) * 256; // Distance to bottom of object
$startCoordinates = PHPExcel_Cell::stringFromColumnIndex($col_start) . ($row_start + 1);
$endCoordinates = PHPExcel_Cell::stringFromColumnIndex($col_end) . ($row_end + 1);
$twoAnchor = array(
'startCoordinates' => $startCoordinates,
'startOffsetX' => $x1,
'startOffsetY' => $y1,
'endCoordinates' => $endCoordinates,
'endOffsetX' => $x2,
'endOffsetY' => $y2,
);
return $twoAnchor;
}
}

View File

@@ -1,139 +0,0 @@
<?php
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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_Shared
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.4, 2010-08-26
*/
/**
* PHPExcel_Shared_File
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_File
{
/**
* Verify if a file exists
*
* @param string $pFilename Filename
* @return bool
*/
public static function file_exists($pFilename) {
// Sick construction, but it seems that
// file_exists returns strange values when
// doing the original file_exists on ZIP archives...
if ( strtolower(substr($pFilename, 0, 3)) == 'zip' ) {
// Open ZIP file and verify if the file exists
$zipFile = substr($pFilename, 6, strpos($pFilename, '#') - 6);
$archiveFile = substr($pFilename, strpos($pFilename, '#') + 1);
$zip = new ZipArchive();
if ($zip->open($zipFile) === true) {
$returnValue = ($zip->getFromName($archiveFile) !== false);
$zip->close();
return $returnValue;
} else {
return false;
}
} else {
// Regular file_exists
return file_exists($pFilename);
}
}
/**
* Returns canonicalized absolute pathname, also for ZIP archives
*
* @param string $pFilename
* @return string
*/
public static function realpath($pFilename) {
// Returnvalue
$returnValue = '';
// Try using realpath()
if (file_exists($pFilename)) {
$returnValue = realpath($pFilename);
}
// Found something?
if ($returnValue == '' || is_null($returnValue)) {
$pathArray = explode('/' , $pFilename);
while(in_array('..', $pathArray) && $pathArray[0] != '..') {
for ($i = 0; $i < count($pathArray); ++$i) {
if ($pathArray[$i] == '..' && $i > 0) {
unset($pathArray[$i]);
unset($pathArray[$i - 1]);
break;
}
}
}
$returnValue = implode('/', $pathArray);
}
// Return
return $returnValue;
}
/**
* Get the systems temporary directory.
*
* @return string
*/
public static function sys_get_temp_dir()
{
// sys_get_temp_dir is only available since PHP 5.2.1
// http://php.net/manual/en/function.sys-get-temp-dir.php#94119
if ( !function_exists('sys_get_temp_dir')) {
if ($temp = getenv('TMP') ) {
if (file_exists($temp)) { return realpath($temp); }
}
if ($temp = getenv('TEMP') ) {
if (file_exists($temp)) { return realpath($temp); }
}
if ($temp = getenv('TMPDIR') ) {
if (file_exists($temp)) { return realpath($temp); }
}
// trick for creating a file in system's temporary dir
// without knowing the path of the system's temporary dir
$temp = tempnam(__FILE__, '');
if (file_exists($temp)) {
unlink($temp);
return realpath(dirname($temp));
}
return null;
}
// use ordinary built-in PHP function
// There should be no problem with the 5.2.4 Suhosin realpath() bug, because this line should only
// be called if we're running 5.2.1 or earlier
return realpath(sys_get_temp_dir());
}
}

View File

@@ -1,763 +0,0 @@
<?php
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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_Shared
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.4, 2010-08-26
*/
/**
* PHPExcel_Shared_Font
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_Font
{
/* Methods for resolving autosize value */
const AUTOSIZE_METHOD_APPROX = 'approx';
const AUTOSIZE_METHOD_EXACT = 'exact';
/** Character set codes used by BIFF5-8 in Font records */
const CHARSET_ANSI_LATIN = 0x00;
const CHARSET_SYSTEM_DEFAULT = 0x01;
const CHARSET_SYMBOL = 0x02;
const CHARSET_APPLE_ROMAN = 0x4D;
const CHARSET_ANSI_JAPANESE_SHIFTJIS = 0x80;
const CHARSET_ANSI_KOREAN_HANGUL = 0x81;
const CHARSET_ANSI_KOREAN_JOHAB = 0x82;
const CHARSET_ANSI_CHINESE_SIMIPLIFIED = 0x86;
const CHARSET_ANSI_CHINESE_TRADITIONAL = 0x88;
const CHARSET_ANSI_GREEK = 0xA1;
const CHARSET_ANSI_TURKISH = 0xA2;
const CHARSET_ANSI_VIETNAMESE = 0xA3;
const CHARSET_ANSI_HEBREW = 0xB1;
const CHARSET_ANSI_ARABIC = 0xB2;
const CHARSET_ANSI_BALTIC = 0xBA;
const CHARSET_ANSI_CYRILLIC = 0xCC;
const CHARSET_ANSI_THAI = 0xDE;
const CHARSET_ANSI_LATIN_II = 0xEE;
const CHARSET_OEM_LATIN_I = 0xFF;
// XXX: Constants created!
/** Font filenames */
const ARIAL = 'arial.ttf';
const ARIAL_BOLD = 'arialbd.ttf';
const ARIAL_ITALIC = 'ariali.ttf';
const ARIAL_BOLD_ITALIC = 'arialbi.ttf';
const CALIBRI = 'CALIBRI.TTF';
const CALIBRI_BOLD = 'CALIBRIB.TTF';
const CALIBRI_ITALIC = 'CALIBRII.TTF';
const CALIBRI_BOLD_ITALIC = 'CALIBRIZ.TTF';
const COMIC_SANS_MS = 'comic.ttf';
const COMIC_SANS_MS_BOLD = 'comicbd.ttf';
const COURIER_NEW = 'cour.ttf';
const COURIER_NEW_BOLD = 'courbd.ttf';
const COURIER_NEW_ITALIC = 'couri.ttf';
const COURIER_NEW_BOLD_ITALIC = 'courbi.ttf';
const GEORGIA = 'georgia.ttf';
const GEORGIA_BOLD = 'georgiab.ttf';
const GEORGIA_ITALIC = 'georgiai.ttf';
const GEORGIA_BOLD_ITALIC = 'georgiaz.ttf';
const IMPACT = 'impact.ttf';
const LIBERATION_SANS = 'LiberationSans-Regular.ttf';
const LIBERATION_SANS_BOLD = 'LiberationSans-Bold.ttf';
const LIBERATION_SANS_ITALIC = 'LiberationSans-Italic.ttf';
const LIBERATION_SANS_BOLD_ITALIC = 'LiberationSans-BoldItalic.ttf';
const LUCIDA_CONSOLE = 'lucon.ttf';
const LUCIDA_SANS_UNICODE = 'l_10646.ttf';
const MICROSOFT_SANS_SERIF = 'micross.ttf';
const PALATINO_LINOTYPE = 'pala.ttf';
const PALATINO_LINOTYPE_BOLD = 'palab.ttf';
const PALATINO_LINOTYPE_ITALIC = 'palai.ttf';
const PALATINO_LINOTYPE_BOLD_ITALIC = 'palabi.ttf';
const SYMBOL = 'symbol.ttf';
const TAHOMA = 'tahoma.ttf';
const TAHOMA_BOLD = 'tahomabd.ttf';
const TIMES_NEW_ROMAN = 'times.ttf';
const TIMES_NEW_ROMAN_BOLD = 'timesbd.ttf';
const TIMES_NEW_ROMAN_ITALIC = 'timesi.ttf';
const TIMES_NEW_ROMAN_BOLD_ITALIC = 'timesbi.ttf';
const TREBUCHET_MS = 'trebuc.ttf';
const TREBUCHET_MS_BOLD = 'trebucbd.ttf';
const TREBUCHET_MS_ITALIC = 'trebucit.ttf';
const TREBUCHET_MS_BOLD_ITALIC = 'trebucbi.ttf';
const VERDANA = 'verdana.ttf';
const VERDANA_BOLD = 'verdanab.ttf';
const VERDANA_ITALIC = 'verdanai.ttf';
const VERDANA_BOLD_ITALIC = 'verdanaz.ttf';
/**
* AutoSize method
*
* @var string
*/
private static $autoSizeMethod = self::AUTOSIZE_METHOD_APPROX;
/**
* Path to folder containing TrueType font .ttf files
*
* @var string
*/
private static $trueTypeFontPath = null;
/**
* How wide is a default column for a given default font and size?
* Empirical data found by inspecting real Excel files and reading off the pixel width
* in Microsoft Office Excel 2007.
*
* @var array
*/
public static $defaultColumnWidths = array(
'Arial' => array(
1 => array('px' => 24, 'width' => 12.00000000),
2 => array('px' => 24, 'width' => 12.00000000),
3 => array('px' => 32, 'width' => 10.66406250),
4 => array('px' => 32, 'width' => 10.66406250),
5 => array('px' => 40, 'width' => 10.00000000),
6 => array('px' => 48, 'width' => 9.59765625),
7 => array('px' => 48, 'width' => 9.59765625),
8 => array('px' => 56, 'width' => 9.33203125),
9 => array('px' => 64, 'width' => 9.14062500),
10 => array('px' => 64, 'width' => 9.14062500),
),
'Calibri' => array(
1 => array('px' => 24, 'width' => 12.00000000),
2 => array('px' => 24, 'width' => 12.00000000),
3 => array('px' => 32, 'width' => 10.66406250),
4 => array('px' => 32, 'width' => 10.66406250),
5 => array('px' => 40, 'width' => 10.00000000),
6 => array('px' => 48, 'width' => 9.59765625),
7 => array('px' => 48, 'width' => 9.59765625),
8 => array('px' => 56, 'width' => 9.33203125),
9 => array('px' => 56, 'width' => 9.33203125),
10 => array('px' => 64, 'width' => 9.14062500),
11 => array('px' => 64, 'width' => 9.14062500),
),
'Verdana' => array(
1 => array('px' => 24, 'width' => 12.00000000),
2 => array('px' => 24, 'width' => 12.00000000),
3 => array('px' => 32, 'width' => 10.66406250),
4 => array('px' => 32, 'width' => 10.66406250),
5 => array('px' => 40, 'width' => 10.00000000),
6 => array('px' => 48, 'width' => 9.59765625),
7 => array('px' => 48, 'width' => 9.59765625),
8 => array('px' => 64, 'width' => 9.14062500),
9 => array('px' => 72, 'width' => 9.00000000),
10 => array('px' => 72, 'width' => 9.00000000),
),
);
/**
* Set autoSize method
*
* @param string $pValue
*/
public static function setAutoSizeMethod($pValue = 'approx')
{
self::$autoSizeMethod = $pValue;
}
/**
* Get autoSize method
*
* @return string
*/
public static function getAutoSizeMethod()
{
return self::$autoSizeMethod;
}
/**
* Set the path to the folder containing .ttf files. There should be a trailing slash.
* Typical locations on variout some platforms:
* <ul>
* <li>C:/Windows/Fonts/</li>
* <li>/usr/share/fonts/truetype/</li>
* <li>~/.fonts/</li>
* </ul>
*
* @param string $pValue
*/
public static function setTrueTypeFontPath($pValue = '')
{
self::$trueTypeFontPath = $pValue;
}
/**
* Get the path to the folder containing .ttf files.
*
* @return string
*/
public static function getTrueTypeFontPath()
{
return self::$trueTypeFontPath;
}
/**
* Calculate an (approximate) OpenXML column width, based on font size and text contained
*
* @param int $fontSize Font size (in pixels or points)
* @param bool $fontSizeInPixels Is the font size specified in pixels (true) or in points (false) ?
* @param string $cellText Text to calculate width
* @param int $rotation Rotation angle
* @return int Column width
*/
public static function calculateColumnWidth(PHPExcel_Style_Font $font, $cellText = '', $rotation = 0, PHPExcel_Style_Font $defaultFont = null) {
// If it is rich text, use plain text
if ($cellText instanceof PHPExcel_RichText) {
$cellText = $cellText->getPlainText();
}
// Special case if there are one or more newline characters ("\n")
if (strpos($cellText, "\n") !== false) {
$lineTexts = explode("\n", $cellText);
$lineWitdhs = array();
foreach ($lineTexts as $lineText) {
$lineWidths[] = self::calculateColumnWidth($font, $lineText, $rotation = 0, $defaultFont);
}
return max($lineWidths); // width of longest line in cell
}
// Try to get the exact text width in pixels
try {
// If autosize method is set to 'approx', use approximation
if (self::$autoSizeMethod == self::AUTOSIZE_METHOD_APPROX) {
throw new Exception('AutoSize method is set to approx');
}
// Width of text in pixels excl. padding
$columnWidth = self::getTextWidthPixelsExact($cellText, $font, $rotation);
// Excel adds some padding, use 1.07 of the width of an 'n' glyph
$columnWidth += ceil(self::getTextWidthPixelsExact('0', $font, 0) * 1.07); // pixels incl. padding
} catch (Exception $e) {
// Width of text in pixels excl. padding, approximation
$columnWidth = self::getTextWidthPixelsApprox($cellText, $font, $rotation);
// Excel adds some padding, just use approx width of 'n' glyph
$columnWidth += self::getTextWidthPixelsApprox('n', $font, 0);
}
// Convert from pixel width to column width
$columnWidth = PHPExcel_Shared_Drawing::pixelsToCellDimension($columnWidth, $defaultFont);
// Return
return round($columnWidth, 6);
}
/**
* Get GD text width in pixels for a string of text in a certain font at a certain rotation angle
*
* @param string $text
* @param PHPExcel_Style_Font
* @param int $rotation
* @return int
* @throws Exception
*/
public static function getTextWidthPixelsExact($text, PHPExcel_Style_Font $font, $rotation = 0) {
if (!function_exists('imagettfbbox')) {
throw new Exception('GD library needs to be enabled');
}
// font size should really be supplied in pixels in GD2,
// but since GD2 seems to assume 72dpi, pixels and points are the same
$fontFile = self::getTrueTypeFontFileFromFont($font);
$textBox = imagettfbbox($font->getSize(), $rotation, $fontFile, $text);
// Get corners positions
$lowerLeftCornerX = $textBox[0];
$lowerLeftCornerY = $textBox[1];
$lowerRightCornerX = $textBox[2];
$lowerRightCornerY = $textBox[3];
$upperRightCornerX = $textBox[4];
$upperRightCornerY = $textBox[5];
$upperLeftCornerX = $textBox[6];
$upperLeftCornerY = $textBox[7];
// Consider the rotation when calculating the width
$textWidth = max($lowerRightCornerX - $upperLeftCornerX, $upperRightCornerX - $lowerLeftCornerX);
return $textWidth;
}
/**
* Get approximate width in pixels for a string of text in a certain font at a certain rotation angle
*
* @param string $columnText
* @param PHPExcel_Style_Font $font
* @param int $rotation
* @return int Text width in pixels (no padding added)
*/
public static function getTextWidthPixelsApprox($columnText, PHPExcel_Style_Font $font = null, $rotation = 0)
{
$fontName = $font->getName();
$fontSize = $font->getSize();
// Calculate column width in pixels. We assume fixed glyph width. Result varies with font name and size.
switch ($fontName) {
case 'Calibri':
// value 8.26 was found via interpolation by inspecting real Excel files with Calibri 11 font.
$columnWidth = (int) (8.26 * PHPExcel_Shared_String::CountCharacters($columnText));
$columnWidth = $columnWidth * $fontSize / 11; // extrapolate from font size
break;
case 'Arial':
// value 7 was found via interpolation by inspecting real Excel files with Arial 10 font.
$columnWidth = (int) (7 * PHPExcel_Shared_String::CountCharacters($columnText));
$columnWidth = $columnWidth * $fontSize / 10; // extrapolate from font size
break;
case 'Verdana':
// value 8 was found via interpolation by inspecting real Excel files with Verdana 10 font.
$columnWidth = (int) (8 * PHPExcel_Shared_String::CountCharacters($columnText));
$columnWidth = $columnWidth * $fontSize / 10; // extrapolate from font size
break;
default:
// just assume Calibri
$columnWidth = (int) (8.26 * PHPExcel_Shared_String::CountCharacters($columnText));
$columnWidth = $columnWidth * $fontSize / 11; // extrapolate from font size
break;
}
// Calculate approximate rotated column width
if ($rotation !== 0) {
if ($rotation == -165) {
// stacked text
$columnWidth = 4; // approximation
} else {
// rotated text
$columnWidth = $columnWidth * cos(deg2rad($rotation))
+ $fontSize * abs(sin(deg2rad($rotation))) / 5; // approximation
}
}
// pixel width is an integer
$columnWidth = (int) $columnWidth;
return $columnWidth;
}
/**
* Calculate an (approximate) pixel size, based on a font points size
*
* @param int $fontSizeInPoints Font size (in points)
* @return int Font size (in pixels)
*/
public static function fontSizeToPixels($fontSizeInPoints = 11) {
return (int) ((4 / 3) * $fontSizeInPoints);
}
/**
* Calculate an (approximate) pixel size, based on inch size
*
* @param int $sizeInInch Font size (in inch)
* @return int Size (in pixels)
*/
public static function inchSizeToPixels($sizeInInch = 1) {
return ($sizeInInch * 96);
}
/**
* Calculate an (approximate) pixel size, based on centimeter size
*
* @param int $sizeInCm Font size (in centimeters)
* @return int Size (in pixels)
*/
public static function centimeterSizeToPixels($sizeInCm = 1) {
return ($sizeInCm * 37.795275591);
}
/**
* Returns the font path given the font
*
* @param PHPExcel_Style_Font
* @return string Path to TrueType font file
*/
public static function getTrueTypeFontFileFromFont($font) {
if (!file_exists(self::$trueTypeFontPath) || !is_dir(self::$trueTypeFontPath)) {
throw new Exception('Valid directory to TrueType Font files not specified');
}
$name = $font->getName();
$bold = $font->getBold();
$italic = $font->getItalic();
// Check if we can map font to true type font file
switch ($name) {
case 'Arial':
$fontFile = (
$bold ? ($italic ? self::ARIAL_BOLD_ITALIC : self::ARIAL_BOLD)
: ($italic ? self::ARIAL_ITALIC : self::ARIAL)
);
break;
case 'Calibri':
$fontFile = (
$bold ? ($italic ? self::CALIBRI_BOLD_ITALIC : self::CALIBRI_BOLD)
: ($italic ? self::CALIBRI_ITALIC : self::CALIBRI)
);
break;
case 'Courier New':
$fontFile = (
$bold ? ($italic ? self::COURIER_NEW_BOLD_ITALIC : self::COURIER_NEW_BOLD)
: ($italic ? self::COURIER_NEW_ITALIC : self::COURIER_NEW)
);
break;
case 'Comic Sans MS':
$fontFile = (
$bold ? self::COMIC_SANS_MS_BOLD : self::COMIC_SANS_MS
);
break;
case 'Georgia':
$fontFile = (
$bold ? ($italic ? self::GEORGIA_BOLD_ITALIC : self::GEORGIA_BOLD)
: ($italic ? self::GEORGIA_ITALIC : self::GEORGIA)
);
break;
case 'Impact':
$fontFile = self::IMPACT;
break;
case 'Liberation Sans':
$fontFile = (
$bold ? ($italic ? self::LIBERATION_SANS_BOLD_ITALIC : self::LIBERATION_SANS_BOLD)
: ($italic ? self::LIBERATION_SANS_ITALIC : self::LIBERATION_SANS)
);
break;
case 'Lucida Console':
$fontFile = self::LUCIDA_CONSOLE;
break;
case 'Lucida Sans Unicode':
$fontFile = self::LUCIDA_SANS_UNICODE;
break;
case 'Microsoft Sans Serif':
$fontFile = self::MICROSOFT_SANS_SERIF;
break;
case 'Palatino Linotype':
$fontFile = (
$bold ? ($italic ? self::PALATINO_LINOTYPE_BOLD_ITALIC : self::PALATINO_LINOTYPE_BOLD)
: ($italic ? self::PALATINO_LINOTYPE_ITALIC : self::PALATINO_LINOTYPE)
);
break;
case 'Symbol':
$fontFile = self::SYMBOL;
break;
case 'Tahoma':
$fontFile = (
$bold ? self::TAHOMA_BOLD : self::TAHOMA
);
break;
case 'Times New Roman':
$fontFile = (
$bold ? ($italic ? self::TIMES_NEW_ROMAN_BOLD_ITALIC : self::TIMES_NEW_ROMAN_BOLD)
: ($italic ? self::TIMES_NEW_ROMAN_ITALIC : self::TIMES_NEW_ROMAN)
);
break;
case 'Trebuchet MS':
$fontFile = (
$bold ? ($italic ? self::TREBUCHET_MS_BOLD_ITALIC : self::TREBUCHET_MS_BOLD)
: ($italic ? self::TREBUCHET_MS_ITALIC : self::TREBUCHET_MS)
);
break;
case 'Verdana':
$fontFile = (
$bold ? ($italic ? self::VERDANA_BOLD_ITALIC : self::VERDANA_BOLD)
: ($italic ? self::VERDANA_ITALIC : self::VERDANA)
);
break;
default:
throw new Exception('Unknown font name "'. $name .'". Cannot map to TrueType font file');
break;
}
$fontFile = self::$trueTypeFontPath . $fontFile;
// Check if file actually exists
if (!file_exists($fontFile)) {
throw New Exception('TrueType Font file not found');
}
return $fontFile;
}
/**
* Returns the associated charset for the font name.
*
* @param string $name Font name
* @return int Character set code
*/
public static function getCharsetFromFontName($name)
{
switch ($name) {
// Add more cases. Check FONT records in real Excel files.
case 'EucrosiaUPC': return self::CHARSET_ANSI_THAI;
case 'Wingdings': return self::CHARSET_SYMBOL;
case 'Wingdings 2': return self::CHARSET_SYMBOL;
case 'Wingdings 3': return self::CHARSET_SYMBOL;
default: return self::CHARSET_ANSI_LATIN;
}
}
/**
* Get the effective column width for columns without a column dimension or column with width -1
* For example, for Calibri 11 this is 9.140625 (64 px)
*
* @param PHPExcel_Style_Font $font The workbooks default font
* @param boolean $pPixels true = return column width in pixels, false = return in OOXML units
* @return mixed Column width
*/
public static function getDefaultColumnWidthByFont(PHPExcel_Style_Font $font, $pPixels = false)
{
if (isset(self::$defaultColumnWidths[$font->getName()][$font->getSize()])) {
// Exact width can be determined
$columnWidth = $pPixels ?
self::$defaultColumnWidths[$font->getName()][$font->getSize()]['px']
: self::$defaultColumnWidths[$font->getName()][$font->getSize()]['width'];
} else {
// We don't have data for this particular font and size, use approximation by
// extrapolating from Calibri 11
$columnWidth = $pPixels ?
self::$defaultColumnWidths['Calibri'][11]['px']
: self::$defaultColumnWidths['Calibri'][11]['width'];
$columnWidth = $columnWidth * $font->getSize() / 11;
// Round pixels to closest integer
if ($pPixels) {
$columnWidth = (int) round($columnWidth);
}
}
return $columnWidth;
}
/**
* Get the effective row height for rows without a row dimension or rows with height -1
* For example, for Calibri 11 this is 15 points
*
* @param PHPExcel_Style_Font $font The workbooks default font
* @return float Row height in points
*/
public static function getDefaultRowHeightByFont(PHPExcel_Style_Font $font)
{
switch ($font->getName()) {
case 'Arial':
switch ($font->getSize()) {
case 10:
// inspection of Arial 10 workbook says 12.75pt ~17px
$rowHeight = 12.75;
break;
case 9:
// inspection of Arial 9 workbook says 12.00pt ~16px
$rowHeight = 12;
break;
case 8:
// inspection of Arial 8 workbook says 11.25pt ~15px
$rowHeight = 11.25;
break;
case 7:
// inspection of Arial 7 workbook says 9.00pt ~12px
$rowHeight = 9;
break;
case 6:
case 5:
// inspection of Arial 5,6 workbook says 8.25pt ~11px
$rowHeight = 8.25;
break;
case 4:
// inspection of Arial 4 workbook says 6.75pt ~9px
$rowHeight = 6.75;
break;
case 3:
// inspection of Arial 3 workbook says 6.00pt ~8px
$rowHeight = 6;
break;
case 2:
case 1:
// inspection of Arial 1,2 workbook says 5.25pt ~7px
$rowHeight = 5.25;
break;
default:
// use Arial 10 workbook as an approximation, extrapolation
$rowHeight = 12.75 * $font->getSize() / 10;
break;
}
break;
case 'Calibri':
switch ($font->getSize()) {
case 11:
// inspection of Calibri 11 workbook says 15.00pt ~20px
$rowHeight = 15;
break;
case 10:
// inspection of Calibri 10 workbook says 12.75pt ~17px
$rowHeight = 12.75;
break;
case 9:
// inspection of Calibri 9 workbook says 12.00pt ~16px
$rowHeight = 12;
break;
case 8:
// inspection of Calibri 8 workbook says 11.25pt ~15px
$rowHeight = 11.25;
break;
case 7:
// inspection of Calibri 7 workbook says 9.00pt ~12px
$rowHeight = 9;
break;
case 6:
case 5:
// inspection of Calibri 5,6 workbook says 8.25pt ~11px
$rowHeight = 8.25;
break;
case 4:
// inspection of Calibri 4 workbook says 6.75pt ~9px
$rowHeight = 6.75;
break;
case 3:
// inspection of Calibri 3 workbook says 6.00pt ~8px
$rowHeight = 6.00;
break;
case 2:
case 1:
// inspection of Calibri 1,2 workbook says 5.25pt ~7px
$rowHeight = 5.25;
break;
default:
// use Calibri 11 workbook as an approximation, extrapolation
$rowHeight = 15 * $font->getSize() / 11;
break;
}
break;
case 'Verdana':
switch ($font->getSize()) {
case 10:
// inspection of Verdana 10 workbook says 12.75pt ~17px
$rowHeight = 12.75;
break;
case 9:
// inspection of Verdana 9 workbook says 11.25pt ~15px
$rowHeight = 11.25;
break;
case 8:
// inspection of Verdana 8 workbook says 10.50pt ~14px
$rowHeight = 10.50;
break;
case 7:
// inspection of Verdana 7 workbook says 9.00pt ~12px
$rowHeight = 9.00;
break;
case 6:
case 5:
// inspection of Verdana 5,6 workbook says 8.25pt ~11px
$rowHeight = 8.25;
break;
case 4:
// inspection of Verdana 4 workbook says 6.75pt ~9px
$rowHeight = 6.75;
break;
case 3:
// inspection of Verdana 3 workbook says 6.00pt ~8px
$rowHeight = 6;
break;
case 2:
case 1:
// inspection of Verdana 1,2 workbook says 5.25pt ~7px
$rowHeight = 5.25;
break;
default:
// use Verdana 10 workbook as an approximation, extrapolation
$rowHeight = 12.75 * $font->getSize() / 10;
break;
}
break;
default:
// just use Calibri as an approximation
$rowHeight = 15 * $font->getSize() / 11;
break;
}
return $rowHeight;
}
}

View File

@@ -18,7 +18,10 @@
* @version 1.1
* @license PHP v3.0
*/
class LUDecomposition {
class PHPExcel_Shared_JAMA_LUDecomposition {
const MatrixSingularException = "Can only perform operation on singular matrix.";
const MatrixSquareException = "Mismatched Row dimension";
/**
* Decomposition storage
@@ -58,9 +61,9 @@ class LUDecomposition {
* @return Structure to access L, U and piv.
*/
public function __construct($A) {
if ($A instanceof Matrix) {
if ($A instanceof PHPExcel_Shared_JAMA_Matrix) {
// Use a "left-looking", dot-product, Crout/Doolittle algorithm.
$this->LU = $A->getArrayCopy();
$this->LU = $A->getArray();
$this->m = $A->getRowDimension();
$this->n = $A->getColumnDimension();
for ($i = 0; $i < $this->m; ++$i) {
@@ -112,7 +115,7 @@ class LUDecomposition {
}
}
} else {
throw new Exception(JAMAError(ArgumentTypeException));
throw new Exception(PHPExcel_Shared_JAMA_Matrix::ArgumentTypeException);
}
} // function __construct()
@@ -134,7 +137,7 @@ class LUDecomposition {
}
}
}
return new Matrix($L);
return new PHPExcel_Shared_JAMA_Matrix($L);
} // function getL()
@@ -153,7 +156,7 @@ class LUDecomposition {
}
}
}
return new Matrix($U);
return new PHPExcel_Shared_JAMA_Matrix($U);
} // function getU()
@@ -205,7 +208,7 @@ class LUDecomposition {
}
return $d;
} else {
throw new Exception(JAMAError(MatrixDimensionException));
throw new Exception(PHPExcel_Shared_JAMA_Matrix::MatrixDimensionException);
}
} // function det()
@@ -245,11 +248,11 @@ class LUDecomposition {
}
return $X;
} else {
throw new Exception(JAMAError(MatrixSingularException));
throw new Exception(self::MatrixSingularException);
}
} else {
throw new Exception(JAMAError(MatrixSquareException));
throw new Exception(self::MatrixSquareException);
}
} // function solve()
} // class LUDecomposition
} // class PHPExcel_Shared_JAMA_LUDecomposition

File diff suppressed because it is too large Load Diff

View File

@@ -16,7 +16,9 @@
* @license PHP v3.0
* @version 1.1
*/
class QRDecomposition {
class PHPExcel_Shared_JAMA_QRDecomposition {
const MatrixRankException = "Can only perform operation on full-rank matrix.";
/**
* Array for internal storage of decomposition.
@@ -50,7 +52,7 @@ class QRDecomposition {
* @return Structure to access R and the Householder vectors and compute Q.
*/
public function __construct($A) {
if($A instanceof Matrix) {
if($A instanceof PHPExcel_Shared_JAMA_Matrix) {
// Initialize.
$this->QR = $A->getArrayCopy();
$this->m = $A->getRowDimension();
@@ -86,7 +88,7 @@ class QRDecomposition {
$this->Rdiag[$k] = -$nrm;
}
} else {
throw new Exception(JAMAError(ArgumentTypeException));
throw new Exception(PHPExcel_Shared_JAMA_Matrix::ArgumentTypeException);
}
} // function __construct()
@@ -121,7 +123,7 @@ class QRDecomposition {
}
}
}
return new Matrix($H);
return new PHPExcel_Shared_JAMA_Matrix($H);
} // function getH()
@@ -142,7 +144,7 @@ class QRDecomposition {
}
}
}
return new Matrix($R);
return new PHPExcel_Shared_JAMA_Matrix($R);
} // function getR()
@@ -179,7 +181,7 @@ class QRDecomposition {
}
}
*/
return new Matrix($Q);
return new PHPExcel_Shared_JAMA_Matrix($Q);
} // function getQ()
@@ -219,14 +221,14 @@ class QRDecomposition {
}
}
}
$X = new Matrix($X);
$X = new PHPExcel_Shared_JAMA_Matrix($X);
return ($X->getMatrix(0, $this->n-1, 0, $nx));
} else {
throw new Exception(JAMAError(MatrixRankException));
throw new Exception(self::MatrixRankException);
}
} else {
throw new Exception(JAMAError(MatrixDimensionException));
throw new Exception(PHPExcel_Shared_JAMA_Matrix::MatrixDimensionException);
}
} // function solve()
} // class QRDecomposition
} // PHPExcel_Shared_JAMA_class QRDecomposition

View File

@@ -1,531 +0,0 @@
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | PHP Version 4 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2002 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Author: Xavier Noguer <xnoguer@php.net> |
// | Based on OLE::Storage_Lite by Kawai, Takanori |
// +----------------------------------------------------------------------+
//
// $Id: OLE.php,v 1.13 2007/03/07 14:38:25 schmidt Exp $
/**
* Array for storing OLE instances that are accessed from
* OLE_ChainedBlockStream::stream_open().
* @var array
*/
$GLOBALS['_OLE_INSTANCES'] = array();
/**
* OLE package base class.
*
* @author Xavier Noguer <xnoguer@php.net>
* @author Christian Schmidt <schmidt@php.net>
* @category PHPExcel
* @package PHPExcel_Shared_OLE
*/
class PHPExcel_Shared_OLE
{
const OLE_PPS_TYPE_ROOT = 5;
const OLE_PPS_TYPE_DIR = 1;
const OLE_PPS_TYPE_FILE = 2;
const OLE_DATA_SIZE_SMALL = 0x1000;
const OLE_LONG_INT_SIZE = 4;
const OLE_PPS_SIZE = 0x80;
/**
* The file handle for reading an OLE container
* @var resource
*/
public $_file_handle;
/**
* Array of PPS's found on the OLE container
* @var array
*/
public $_list = array();
/**
* Root directory of OLE container
* @var OLE_PPS_Root
*/
public $root;
/**
* Big Block Allocation Table
* @var array (blockId => nextBlockId)
*/
public $bbat;
/**
* Short Block Allocation Table
* @var array (blockId => nextBlockId)
*/
public $sbat;
/**
* Size of big blocks. This is usually 512.
* @var int number of octets per block.
*/
public $bigBlockSize;
/**
* Size of small blocks. This is usually 64.
* @var int number of octets per block
*/
public $smallBlockSize;
/**
* Reads an OLE container from the contents of the file given.
*
* @acces public
* @param string $file
* @return mixed true on success, PEAR_Error on failure
*/
public function read($file)
{
$fh = fopen($file, "r");
if (!$fh) {
throw new Exception("Can't open file $file");
}
$this->_file_handle = $fh;
$signature = fread($fh, 8);
if ("\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1" != $signature) {
throw new Exception("File doesn't seem to be an OLE container.");
}
fseek($fh, 28);
if (fread($fh, 2) != "\xFE\xFF") {
// This shouldn't be a problem in practice
throw new Exception("Only Little-Endian encoding is supported.");
}
// Size of blocks and short blocks in bytes
$this->bigBlockSize = pow(2, $this->_readInt2($fh));
$this->smallBlockSize = pow(2, $this->_readInt2($fh));
// Skip UID, revision number and version number
fseek($fh, 44);
// Number of blocks in Big Block Allocation Table
$bbatBlockCount = $this->_readInt4($fh);
// Root chain 1st block
$directoryFirstBlockId = $this->_readInt4($fh);
// Skip unused bytes
fseek($fh, 56);
// Streams shorter than this are stored using small blocks
$this->bigBlockThreshold = $this->_readInt4($fh);
// Block id of first sector in Short Block Allocation Table
$sbatFirstBlockId = $this->_readInt4($fh);
// Number of blocks in Short Block Allocation Table
$sbbatBlockCount = $this->_readInt4($fh);
// Block id of first sector in Master Block Allocation Table
$mbatFirstBlockId = $this->_readInt4($fh);
// Number of blocks in Master Block Allocation Table
$mbbatBlockCount = $this->_readInt4($fh);
$this->bbat = array();
// Remaining 4 * 109 bytes of current block is beginning of Master
// Block Allocation Table
$mbatBlocks = array();
for ($i = 0; $i < 109; ++$i) {
$mbatBlocks[] = $this->_readInt4($fh);
}
// Read rest of Master Block Allocation Table (if any is left)
$pos = $this->_getBlockOffset($mbatFirstBlockId);
for ($i = 0; $i < $mbbatBlockCount; ++$i) {
fseek($fh, $pos);
for ($j = 0; $j < $this->bigBlockSize / 4 - 1; ++$j) {
$mbatBlocks[] = $this->_readInt4($fh);
}
// Last block id in each block points to next block
$pos = $this->_getBlockOffset($this->_readInt4($fh));
}
// Read Big Block Allocation Table according to chain specified by
// $mbatBlocks
for ($i = 0; $i < $bbatBlockCount; ++$i) {
$pos = $this->_getBlockOffset($mbatBlocks[$i]);
fseek($fh, $pos);
for ($j = 0 ; $j < $this->bigBlockSize / 4; ++$j) {
$this->bbat[] = $this->_readInt4($fh);
}
}
// Read short block allocation table (SBAT)
$this->sbat = array();
$shortBlockCount = $sbbatBlockCount * $this->bigBlockSize / 4;
$sbatFh = $this->getStream($sbatFirstBlockId);
for ($blockId = 0; $blockId < $shortBlockCount; ++$blockId) {
$this->sbat[$blockId] = $this->_readInt4($sbatFh);
}
fclose($sbatFh);
$this->_readPpsWks($directoryFirstBlockId);
return true;
}
/**
* @param int block id
* @param int byte offset from beginning of file
* @access public
*/
public function _getBlockOffset($blockId)
{
return 512 + $blockId * $this->bigBlockSize;
}
/**
* Returns a stream for use with fread() etc. External callers should
* use PHPExcel_Shared_OLE_PPS_File::getStream().
* @param int|PPS block id or PPS
* @return resource read-only stream
*/
public function getStream($blockIdOrPps)
{
static $isRegistered = false;
if (!$isRegistered) {
stream_wrapper_register('ole-chainedblockstream',
'PHPExcel_Shared_OLE_ChainedBlockStream');
$isRegistered = true;
}
// Store current instance in global array, so that it can be accessed
// in OLE_ChainedBlockStream::stream_open().
// Object is removed from self::$instances in OLE_Stream::close().
$GLOBALS['_OLE_INSTANCES'][] = $this;
$instanceId = end(array_keys($GLOBALS['_OLE_INSTANCES']));
$path = 'ole-chainedblockstream://oleInstanceId=' . $instanceId;
if ($blockIdOrPps instanceof PHPExcel_Shared_OLE_PPS) {
$path .= '&blockId=' . $blockIdOrPps->_StartBlock;
$path .= '&size=' . $blockIdOrPps->Size;
} else {
$path .= '&blockId=' . $blockIdOrPps;
}
return fopen($path, 'r');
}
/**
* Reads a signed char.
* @param resource file handle
* @return int
* @access public
*/
public function _readInt1($fh)
{
list(, $tmp) = unpack("c", fread($fh, 1));
return $tmp;
}
/**
* Reads an unsigned short (2 octets).
* @param resource file handle
* @return int
* @access public
*/
public function _readInt2($fh)
{
list(, $tmp) = unpack("v", fread($fh, 2));
return $tmp;
}
/**
* Reads an unsigned long (4 octets).
* @param resource file handle
* @return int
* @access public
*/
public function _readInt4($fh)
{
list(, $tmp) = unpack("V", fread($fh, 4));
return $tmp;
}
/**
* Gets information about all PPS's on the OLE container from the PPS WK's
* creates an OLE_PPS object for each one.
*
* @access public
* @param integer the block id of the first block
* @return mixed true on success, PEAR_Error on failure
*/
public function _readPpsWks($blockId)
{
$fh = $this->getStream($blockId);
for ($pos = 0; ; $pos += 128) {
fseek($fh, $pos, SEEK_SET);
$nameUtf16 = fread($fh, 64);
$nameLength = $this->_readInt2($fh);
$nameUtf16 = substr($nameUtf16, 0, $nameLength - 2);
// Simple conversion from UTF-16LE to ISO-8859-1
$name = str_replace("\x00", "", $nameUtf16);
$type = $this->_readInt1($fh);
switch ($type) {
case self::OLE_PPS_TYPE_ROOT:
$pps = new PHPExcel_Shared_OLE_PPS_Root(null, null, array());
$this->root = $pps;
break;
case self::OLE_PPS_TYPE_DIR:
$pps = new PHPExcel_Shared_OLE_PPS(null, null, null, null, null,
null, null, null, null, array());
break;
case self::OLE_PPS_TYPE_FILE:
$pps = new PHPExcel_Shared_OLE_PPS_File($name);
break;
default:
continue;
}
fseek($fh, 1, SEEK_CUR);
$pps->Type = $type;
$pps->Name = $name;
$pps->PrevPps = $this->_readInt4($fh);
$pps->NextPps = $this->_readInt4($fh);
$pps->DirPps = $this->_readInt4($fh);
fseek($fh, 20, SEEK_CUR);
$pps->Time1st = self::OLE2LocalDate(fread($fh, 8));
$pps->Time2nd = self::OLE2LocalDate(fread($fh, 8));
$pps->_StartBlock = $this->_readInt4($fh);
$pps->Size = $this->_readInt4($fh);
$pps->No = count($this->_list);
$this->_list[] = $pps;
// check if the PPS tree (starting from root) is complete
if (isset($this->root) &&
$this->_ppsTreeComplete($this->root->No)) {
break;
}
}
fclose($fh);
// Initialize $pps->children on directories
foreach ($this->_list as $pps) {
if ($pps->Type == self::OLE_PPS_TYPE_DIR || $pps->Type == self::OLE_PPS_TYPE_ROOT) {
$nos = array($pps->DirPps);
$pps->children = array();
while ($nos) {
$no = array_pop($nos);
if ($no != -1) {
$childPps = $this->_list[$no];
$nos[] = $childPps->PrevPps;
$nos[] = $childPps->NextPps;
$pps->children[] = $childPps;
}
}
}
}
return true;
}
/**
* It checks whether the PPS tree is complete (all PPS's read)
* starting with the given PPS (not necessarily root)
*
* @access public
* @param integer $index The index of the PPS from which we are checking
* @return boolean Whether the PPS tree for the given PPS is complete
*/
public function _ppsTreeComplete($index)
{
return isset($this->_list[$index]) &&
($pps = $this->_list[$index]) &&
($pps->PrevPps == -1 ||
$this->_ppsTreeComplete($pps->PrevPps)) &&
($pps->NextPps == -1 ||
$this->_ppsTreeComplete($pps->NextPps)) &&
($pps->DirPps == -1 ||
$this->_ppsTreeComplete($pps->DirPps));
}
/**
* Checks whether a PPS is a File PPS or not.
* If there is no PPS for the index given, it will return false.
*
* @access public
* @param integer $index The index for the PPS
* @return bool true if it's a File PPS, false otherwise
*/
public function isFile($index)
{
if (isset($this->_list[$index])) {
return ($this->_list[$index]->Type == self::OLE_PPS_TYPE_FILE);
}
return false;
}
/**
* Checks whether a PPS is a Root PPS or not.
* If there is no PPS for the index given, it will return false.
*
* @access public
* @param integer $index The index for the PPS.
* @return bool true if it's a Root PPS, false otherwise
*/
public function isRoot($index)
{
if (isset($this->_list[$index])) {
return ($this->_list[$index]->Type == self::OLE_PPS_TYPE_ROOT);
}
return false;
}
/**
* Gives the total number of PPS's found in the OLE container.
*
* @access public
* @return integer The total number of PPS's found in the OLE container
*/
public function ppsTotal()
{
return count($this->_list);
}
/**
* Gets data from a PPS
* If there is no PPS for the index given, it will return an empty string.
*
* @access public
* @param integer $index The index for the PPS
* @param integer $position The position from which to start reading
* (relative to the PPS)
* @param integer $length The amount of bytes to read (at most)
* @return string The binary string containing the data requested
* @see OLE_PPS_File::getStream()
*/
public function getData($index, $position, $length)
{
// if position is not valid return empty string
if (!isset($this->_list[$index]) || ($position >= $this->_list[$index]->Size) || ($position < 0)) {
return '';
}
$fh = $this->getStream($this->_list[$index]);
$data = stream_get_contents($fh, $length, $position);
fclose($fh);
return $data;
}
/**
* Gets the data length from a PPS
* If there is no PPS for the index given, it will return 0.
*
* @access public
* @param integer $index The index for the PPS
* @return integer The amount of bytes in data the PPS has
*/
public function getDataLength($index)
{
if (isset($this->_list[$index])) {
return $this->_list[$index]->Size;
}
return 0;
}
/**
* Utility function to transform ASCII text to Unicode
*
* @access public
* @static
* @param string $ascii The ASCII string to transform
* @return string The string in Unicode
*/
public static function Asc2Ucs($ascii)
{
$rawname = '';
for ($i = 0; $i < strlen($ascii); ++$i) {
$rawname .= $ascii{$i} . "\x00";
}
return $rawname;
}
/**
* Utility function
* Returns a string for the OLE container with the date given
*
* @access public
* @static
* @param integer $date A timestamp
* @return string The string for the OLE container
*/
public static function LocalDate2OLE($date = null)
{
if (!isset($date)) {
return "\x00\x00\x00\x00\x00\x00\x00\x00";
}
// factor used for separating numbers into 4 bytes parts
$factor = pow(2, 32);
// days from 1-1-1601 until the beggining of UNIX era
$days = 134774;
// calculate seconds
$big_date = $days*24*3600 + gmmktime(date("H",$date),date("i",$date),date("s",$date),
date("m",$date),date("d",$date),date("Y",$date));
// multiply just to make MS happy
$big_date *= 10000000;
$high_part = floor($big_date / $factor);
// lower 4 bytes
$low_part = floor((($big_date / $factor) - $high_part) * $factor);
// Make HEX string
$res = '';
for ($i = 0; $i < 4; ++$i) {
$hex = $low_part % 0x100;
$res .= pack('c', $hex);
$low_part /= 0x100;
}
for ($i = 0; $i < 4; ++$i) {
$hex = $high_part % 0x100;
$res .= pack('c', $hex);
$high_part /= 0x100;
}
return $res;
}
/**
* Returns a timestamp from an OLE container's date
*
* @access public
* @static
* @param integer $string A binary string with the encoded date
* @return string The timestamp corresponding to the string
*/
public static function OLE2LocalDate($string)
{
if (strlen($string) != 8) {
return new PEAR_Error("Expecting 8 byte string");
}
// factor used for separating numbers into 4 bytes parts
$factor = pow(2,32);
list(, $high_part) = unpack('V', substr($string, 4, 4));
list(, $low_part) = unpack('V', substr($string, 0, 4));
$big_date = ($high_part * $factor) + $low_part;
// translate to seconds
$big_date /= 10000000;
// days from 1-1-1601 until the beggining of UNIX era
$days = 134774;
// translate to seconds from beggining of UNIX era
$big_date -= $days * 24 * 3600;
return floor($big_date);
}
}

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (C) 2006 - 2010 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
@@ -22,7 +22,7 @@
* @package PHPExcel_Shared_OLE
* @copyright Copyright (c) 2006 - 2007 Christian Schmidt
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
/**

View File

@@ -169,10 +169,8 @@ class PHPExcel_Shared_OLE_PPS
*/
public function _getPpsWk()
{
$ret = $this->Name;
for ($i = 0; $i < (64 - strlen($this->Name)); ++$i) {
$ret .= "\x00";
}
$ret = str_pad($this->Name,64,"\x00");
$ret .= pack("v", strlen($this->Name) + 2) // 66
. pack("c", $this->Type) // 67
. pack("c", 0x00) //UK // 68
@@ -215,4 +213,4 @@ class PHPExcel_Shared_OLE_PPS
}
return $this->No;
}
}
}

View File

@@ -29,12 +29,21 @@
*/
class PHPExcel_Shared_OLE_PPS_Root extends PHPExcel_Shared_OLE_PPS
{
/**
* Directory for temporary files
* @var string
*/
protected $_tmp_dir = '';
/**
* @param integer $time_1st A timestamp
* @param integer $time_2nd A timestamp
*/
public function __construct($time_1st, $time_2nd, $raChild)
{
$this->_tempDir = PHPExcel_Shared_File::sys_get_temp_dir();
parent::__construct(
null,
PHPExcel_Shared_OLE::Asc2Ucs('Root Entry'),
@@ -63,9 +72,9 @@ class PHPExcel_Shared_OLE_PPS_Root extends PHPExcel_Shared_OLE_PPS
{
// Initial Setting for saving
$this->_BIG_BLOCK_SIZE = pow(2,
((isset($this->_BIG_BLOCK_SIZE))? $this->_adjust2($this->_BIG_BLOCK_SIZE) : 9));
((isset($this->_BIG_BLOCK_SIZE))? self::_adjust2($this->_BIG_BLOCK_SIZE) : 9));
$this->_SMALL_BLOCK_SIZE= pow(2,
((isset($this->_SMALL_BLOCK_SIZE))? $this->_adjust2($this->_SMALL_BLOCK_SIZE): 6));
((isset($this->_SMALL_BLOCK_SIZE))? self::_adjust2($this->_SMALL_BLOCK_SIZE): 6));
if (is_resource($filename)) {
$this->_FILEH_ = $filename;
@@ -119,7 +128,8 @@ class PHPExcel_Shared_OLE_PPS_Root extends PHPExcel_Shared_OLE_PPS
list($iSBDcnt, $iBBcnt, $iPPScnt) = array(0,0,0);
$iSmallLen = 0;
$iSBcnt = 0;
for ($i = 0; $i < count($raList); ++$i) {
$iCount = count($raList);
for ($i = 0; $i < $iCount; ++$i) {
if ($raList[$i]->Type == PHPExcel_Shared_OLE::OLE_PPS_TYPE_FILE) {
$raList[$i]->Size = $raList[$i]->_DataLen();
if ($raList[$i]->Size < PHPExcel_Shared_OLE::OLE_DATA_SIZE_SMALL) {
@@ -151,7 +161,7 @@ class PHPExcel_Shared_OLE_PPS_Root extends PHPExcel_Shared_OLE_PPS
* @see save()
* @return integer
*/
public function _adjust2($i2)
private static function _adjust2($i2)
{
$iWk = log($i2)/log(2);
return ($iWk > floor($iWk))? floor($iWk)+1:$iWk;
@@ -229,7 +239,8 @@ class PHPExcel_Shared_OLE_PPS_Root extends PHPExcel_Shared_OLE_PPS
fwrite($FILE, pack("V", $iAll+$i));
}
if ($i < $i1stBdL) {
for ($j = 0; $j < ($i1stBdL-$i); ++$j) {
$jB = $i1stBdL - $i;
for ($j = 0; $j < $jB; ++$j) {
fwrite($FILE, (pack("V", -1)));
}
}
@@ -247,7 +258,8 @@ class PHPExcel_Shared_OLE_PPS_Root extends PHPExcel_Shared_OLE_PPS
$FILE = $this->_FILEH_;
// cycle through PPS's
for ($i = 0; $i < count($raList); ++$i) {
$iCount = count($raList);
for ($i = 0; $i < $iCount; ++$i) {
if ($raList[$i]->Type != PHPExcel_Shared_OLE::OLE_PPS_TYPE_DIR) {
$raList[$i]->Size = $raList[$i]->_DataLen();
if (($raList[$i]->Size >= PHPExcel_Shared_OLE::OLE_DATA_SIZE_SMALL) ||
@@ -266,9 +278,7 @@ class PHPExcel_Shared_OLE_PPS_Root extends PHPExcel_Shared_OLE_PPS
//}
if ($raList[$i]->Size % $this->_BIG_BLOCK_SIZE) {
for ($j = 0; $j < ($this->_BIG_BLOCK_SIZE - ($raList[$i]->Size % $this->_BIG_BLOCK_SIZE)); ++$j) {
fwrite($FILE, "\x00");
}
fwrite($FILE, str_repeat("\x00", $this->_BIG_BLOCK_SIZE - ($raList[$i]->Size % $this->_BIG_BLOCK_SIZE)));
}
// Set For PPS
$raList[$i]->_StartBlock = $iStBlk;
@@ -298,7 +308,8 @@ class PHPExcel_Shared_OLE_PPS_Root extends PHPExcel_Shared_OLE_PPS
$FILE = $this->_FILEH_;
$iSmBlk = 0;
for ($i = 0; $i < count($raList); ++$i) {
$iCount = count($raList);
for ($i = 0; $i < $iCount; ++$i) {
// Make SBD, small data string
if ($raList[$i]->Type == PHPExcel_Shared_OLE::OLE_PPS_TYPE_FILE) {
if ($raList[$i]->Size <= 0) {
@@ -308,7 +319,8 @@ class PHPExcel_Shared_OLE_PPS_Root extends PHPExcel_Shared_OLE_PPS
$iSmbCnt = floor($raList[$i]->Size / $this->_SMALL_BLOCK_SIZE)
+ (($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE)? 1: 0);
// Add to SBD
for ($j = 0; $j < ($iSmbCnt-1); ++$j) {
$jB = $iSmbCnt - 1;
for ($j = 0; $j < $jB; ++$j) {
fwrite($FILE, pack("V", $j+$iSmBlk+1));
}
fwrite($FILE, pack("V", -2));
@@ -323,9 +335,7 @@ class PHPExcel_Shared_OLE_PPS_Root extends PHPExcel_Shared_OLE_PPS
$sRes .= $raList[$i]->_data;
//}
if ($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE) {
for ($j = 0; $j < ($this->_SMALL_BLOCK_SIZE - ($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE)); ++$j) {
$sRes .= "\x00";
}
$sRes .= str_repeat("\x00",$this->_SMALL_BLOCK_SIZE - ($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE));
}
// Set for PPS
$raList[$i]->_StartBlock = $iSmBlk;
@@ -335,7 +345,8 @@ class PHPExcel_Shared_OLE_PPS_Root extends PHPExcel_Shared_OLE_PPS
}
$iSbCnt = floor($this->_BIG_BLOCK_SIZE / PHPExcel_Shared_OLE::OLE_LONG_INT_SIZE);
if ($iSmBlk % $iSbCnt) {
for ($i = 0; $i < ($iSbCnt - ($iSmBlk % $iSbCnt)); ++$i) {
$iB = $iSbCnt - ($iSmBlk % $iSbCnt);
for ($i = 0; $i < $iB; ++$i) {
fwrite($FILE, pack("V", -1));
}
}
@@ -351,16 +362,15 @@ class PHPExcel_Shared_OLE_PPS_Root extends PHPExcel_Shared_OLE_PPS
public function _savePps(&$raList)
{
// Save each PPS WK
for ($i = 0; $i < count($raList); ++$i) {
$iC = count($raList);
for ($i = 0; $i < $iC; ++$i) {
fwrite($this->_FILEH_, $raList[$i]->_getPpsWk());
}
// Adjust for Block
$iCnt = count($raList);
$iBCnt = $this->_BIG_BLOCK_SIZE / PHPExcel_Shared_OLE::OLE_PPS_SIZE;
if ($iCnt % $iBCnt) {
for ($i = 0; $i < (($iBCnt - ($iCnt % $iBCnt)) * PHPExcel_Shared_OLE::OLE_PPS_SIZE); ++$i) {
fwrite($this->_FILEH_, "\x00");
}
fwrite($this->_FILEH_, str_repeat("\x00",($iBCnt - ($iCnt % $iBCnt)) * PHPExcel_Shared_OLE::OLE_PPS_SIZE));
}
}
@@ -426,7 +436,8 @@ class PHPExcel_Shared_OLE_PPS_Root extends PHPExcel_Shared_OLE_PPS
}
// Adjust for Block
if (($iAllW + $iBdCnt) % $iBbCnt) {
for ($i = 0; $i < ($iBbCnt - (($iAllW + $iBdCnt) % $iBbCnt)); ++$i) {
$iBlock = ($iBbCnt - (($iAllW + $iBdCnt) % $iBbCnt));
for ($i = 0; $i < $iBlock; ++$i) {
fwrite($FILE, pack("V", -1));
}
}
@@ -443,11 +454,12 @@ class PHPExcel_Shared_OLE_PPS_Root extends PHPExcel_Shared_OLE_PPS
fwrite($FILE, pack("V", $iBsize+$iSbdSize+$iPpsCnt+$i));
}
if (($iBdCnt-$i1stBdL) % ($iBbCnt-1)) {
for ($i = 0; $i < (($iBbCnt - 1) - (($iBdCnt - $i1stBdL) % ($iBbCnt - 1))); ++$i) {
$iB = ($iBbCnt - 1) - (($iBdCnt - $i1stBdL) % ($iBbCnt - 1));
for ($i = 0; $i < $iB; ++$i) {
fwrite($FILE, pack("V", -1));
}
}
fwrite($FILE, pack("V", -2));
}
}
}
}

View File

@@ -1,361 +0,0 @@
<?php
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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_Shared
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.4, 2010-08-26
*/
define('IDENTIFIER_OLE', pack('CCCCCCCC', 0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1));
class PHPExcel_Shared_OLERead {
private $data = '';
// OLE identifier
const IDENTIFIER_OLE = IDENTIFIER_OLE;
// Size of a sector = 512 bytes
const BIG_BLOCK_SIZE = 0x200;
// Size of a short sector = 64 bytes
const SMALL_BLOCK_SIZE = 0x40;
// Size of a directory entry always = 128 bytes
const PROPERTY_STORAGE_BLOCK_SIZE = 0x80;
// Minimum size of a standard stream = 4096 bytes, streams smaller than this are stored as short streams
const SMALL_BLOCK_THRESHOLD = 0x1000;
// header offsets
const NUM_BIG_BLOCK_DEPOT_BLOCKS_POS = 0x2c;
const ROOT_START_BLOCK_POS = 0x30;
const SMALL_BLOCK_DEPOT_BLOCK_POS = 0x3c;
const EXTENSION_BLOCK_POS = 0x44;
const NUM_EXTENSION_BLOCK_POS = 0x48;
const BIG_BLOCK_DEPOT_BLOCKS_POS = 0x4c;
// property storage offsets (directory offsets)
const SIZE_OF_NAME_POS = 0x40;
const TYPE_POS = 0x42;
const START_BLOCK_POS = 0x74;
const SIZE_POS = 0x78;
/**
* Read the file
*
* @param $sFileName string Filename
* @throws Exception
*/
public function read($sFileName)
{
// Check if file exists and is readable
if(!is_readable($sFileName)) {
throw new Exception("Could not open " . $sFileName . " for reading! File does not exist, or it is not readable.");
}
// Get the file data
$this->data = file_get_contents($sFileName);
// Check OLE identifier
if (substr($this->data, 0, 8) != self::IDENTIFIER_OLE) {
throw new Exception('The filename ' . $sFileName . ' is not recognised as an OLE file');
}
// Total number of sectors used for the SAT
$this->numBigBlockDepotBlocks = $this->_GetInt4d($this->data, self::NUM_BIG_BLOCK_DEPOT_BLOCKS_POS);
// SecID of the first sector of the directory stream
$this->rootStartBlock = $this->_GetInt4d($this->data, self::ROOT_START_BLOCK_POS);
// SecID of the first sector of the SSAT (or -2 if not extant)
$this->sbdStartBlock = $this->_GetInt4d($this->data, self::SMALL_BLOCK_DEPOT_BLOCK_POS);
// SecID of the first sector of the MSAT (or -2 if no additional sectors are used)
$this->extensionBlock = $this->_GetInt4d($this->data, self::EXTENSION_BLOCK_POS);
// Total number of sectors used by MSAT
$this->numExtensionBlocks = $this->_GetInt4d($this->data, self::NUM_EXTENSION_BLOCK_POS);
$bigBlockDepotBlocks = array();
$pos = self::BIG_BLOCK_DEPOT_BLOCKS_POS;
$bbdBlocks = $this->numBigBlockDepotBlocks;
if ($this->numExtensionBlocks != 0) {
$bbdBlocks = (self::BIG_BLOCK_SIZE - self::BIG_BLOCK_DEPOT_BLOCKS_POS)/4;
}
for ($i = 0; $i < $bbdBlocks; ++$i) {
$bigBlockDepotBlocks[$i] = $this->_GetInt4d($this->data, $pos);
$pos += 4;
}
for ($j = 0; $j < $this->numExtensionBlocks; ++$j) {
$pos = ($this->extensionBlock + 1) * self::BIG_BLOCK_SIZE;
$blocksToRead = min($this->numBigBlockDepotBlocks - $bbdBlocks, self::BIG_BLOCK_SIZE / 4 - 1);
for ($i = $bbdBlocks; $i < $bbdBlocks + $blocksToRead; ++$i) {
$bigBlockDepotBlocks[$i] = $this->_GetInt4d($this->data, $pos);
$pos += 4;
}
$bbdBlocks += $blocksToRead;
if ($bbdBlocks < $this->numBigBlockDepotBlocks) {
$this->extensionBlock = $this->_GetInt4d($this->data, $pos);
}
}
$pos = 0;
$index = 0;
$this->bigBlockChain = array();
for ($i = 0; $i < $this->numBigBlockDepotBlocks; ++$i) {
$pos = ($bigBlockDepotBlocks[$i] + 1) * self::BIG_BLOCK_SIZE;
for ($j = 0 ; $j < self::BIG_BLOCK_SIZE / 4; ++$j) {
$this->bigBlockChain[$index] = $this->_GetInt4d($this->data, $pos);
$pos += 4 ;
++$index;
}
}
$pos = 0;
$index = 0;
$sbdBlock = $this->sbdStartBlock;
$this->smallBlockChain = array();
while ($sbdBlock != -2) {
$pos = ($sbdBlock + 1) * self::BIG_BLOCK_SIZE;
for ($j = 0; $j < self::BIG_BLOCK_SIZE / 4; ++$j) {
$this->smallBlockChain[$index] = $this->_GetInt4d($this->data, $pos);
$pos += 4;
++$index;
}
$sbdBlock = $this->bigBlockChain[$sbdBlock];
}
$block = $this->rootStartBlock;
$pos = 0;
// read the directory stream
$this->entry = $this->_readData($block);
$this->_readPropertySets();
}
/**
* Extract binary stream data, workbook stream + sheet streams
*
* @return string
*/
public function getWorkBook()
{
if ($this->props[$this->wrkbook]['size'] < self::SMALL_BLOCK_THRESHOLD){
$rootdata = $this->_readData($this->props[$this->rootentry]['startBlock']);
$streamData = '';
$block = $this->props[$this->wrkbook]['startBlock'];
$pos = 0;
while ($block != -2) {
$pos = $block * self::SMALL_BLOCK_SIZE;
$streamData .= substr($rootdata, $pos, self::SMALL_BLOCK_SIZE);
$block = $this->smallBlockChain[$block];
}
return $streamData;
} else {
$numBlocks = $this->props[$this->wrkbook]['size'] / self::BIG_BLOCK_SIZE;
if ($this->props[$this->wrkbook]['size'] % self::BIG_BLOCK_SIZE != 0) {
++$numBlocks;
}
if ($numBlocks == 0) return '';
$streamData = '';
$block = $this->props[$this->wrkbook]['startBlock'];
$pos = 0;
while ($block != -2) {
$pos = ($block + 1) * self::BIG_BLOCK_SIZE;
$streamData .= substr($this->data, $pos, self::BIG_BLOCK_SIZE);
$block = $this->bigBlockChain[$block];
}
return $streamData;
}
}
/**
* Extract binary stream data, summary information
*
* @return string|null
*/
public function getSummaryInformation()
{
if (!isset($this->summaryInformation)) {
return null;
}
if ($this->props[$this->summaryInformation]['size'] < self::SMALL_BLOCK_THRESHOLD){
$rootdata = $this->_readData($this->props[$this->rootentry]['startBlock']);
$streamData = '';
$block = $this->props[$this->summaryInformation]['startBlock'];
$pos = 0;
while ($block != -2) {
$pos = $block * self::SMALL_BLOCK_SIZE;
$streamData .= substr($rootdata, $pos, self::SMALL_BLOCK_SIZE);
$block = $this->smallBlockChain[$block];
}
return $streamData;
} else {
$numBlocks = $this->props[$this->summaryInformation]['size'] / self::BIG_BLOCK_SIZE;
if ($this->props[$this->summaryInformation]['size'] % self::BIG_BLOCK_SIZE != 0) {
++$numBlocks;
}
if ($numBlocks == 0) return '';
$streamData = '';
$block = $this->props[$this->summaryInformation]['startBlock'];
$pos = 0;
while ($block != -2) {
$pos = ($block + 1) * self::BIG_BLOCK_SIZE;
$streamData .= substr($this->data, $pos, self::BIG_BLOCK_SIZE);
$block = $this->bigBlockChain[$block];
}
return $streamData;
}
}
/**
* Read a standard stream (by joining sectors using information from SAT)
*
* @param int $bl Sector ID where the stream starts
* @return string Data for standard stream
*/
private function _readData($bl)
{
$block = $bl;
$pos = 0;
$data = '';
while ($block != -2) {
$pos = ($block + 1) * self::BIG_BLOCK_SIZE;
$data = $data . substr($this->data, $pos, self::BIG_BLOCK_SIZE);
$block = $this->bigBlockChain[$block];
}
return $data;
}
/**
* Read entries in the directory stream.
*/
private function _readPropertySets()
{
$offset = 0;
// loop through entires, each entry is 128 bytes
while ($offset < strlen($this->entry)) {
// entry data (128 bytes)
$d = substr($this->entry, $offset, self::PROPERTY_STORAGE_BLOCK_SIZE);
// size in bytes of name
$nameSize = ord($d[self::SIZE_OF_NAME_POS]) | (ord($d[self::SIZE_OF_NAME_POS+1]) << 8);
// type of entry
$type = ord($d[self::TYPE_POS]);
// sectorID of first sector or short sector, if this entry refers to a stream (the case with workbook)
// sectorID of first sector of the short-stream container stream, if this entry is root entry
$startBlock = $this->_GetInt4d($d, self::START_BLOCK_POS);
$size = $this->_GetInt4d($d, self::SIZE_POS);
$name = '';
for ($i = 0; $i < $nameSize ; ++$i) {
$name .= $d[$i];
}
$name = str_replace("\x00", "", $name);
$this->props[] = array (
'name' => $name,
'type' => $type,
'startBlock' => $startBlock,
'size' => $size);
// Workbook directory entry (BIFF5 uses Book, BIFF8 uses Workbook)
if (($name == 'Workbook') || ($name == 'Book') || ($name == 'WORKBOOK') || ($name == 'BOOK')) {
$this->wrkbook = count($this->props) - 1;
}
// Root entry
if ($name == 'Root Entry' || $name == 'ROOT ENTRY' || $name == 'R') {
$this->rootentry = count($this->props) - 1;
}
// Summary information
if ($name == chr(5) . 'SummaryInformation') {
$this->summaryInformation = count($this->props) - 1;
}
$offset += self::PROPERTY_STORAGE_BLOCK_SIZE;
}
}
/**
* Read 4 bytes of data at specified position
*
* @param string $data
* @param int $pos
* @return int
*/
private function _GetInt4d($data, $pos)
{
// Hacked by Andreas Rehm 2006 to ensure correct result of the <<24 block on 32 and 64bit systems
$_or_24 = ord($data[$pos+3]);
if ($_or_24>=128) $_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;
}
}

View File

@@ -0,0 +1,504 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 2.1, February 1999
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
[This is the first released version of the Lesser GPL. It also counts
as the successor of the GNU Library Public License, version 2, hence
the version number 2.1.]
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
Licenses are intended to guarantee your freedom to share and change
free software--to make sure the software is free for all its users.
This license, the Lesser General Public License, applies to some
specially designated software packages--typically libraries--of the
Free Software Foundation and other authors who decide to use it. You
can use it too, but we suggest you first think carefully about whether
this license or the ordinary General Public License is the better
strategy to use in any particular case, based on the explanations below.
When we speak of free software, we are referring to freedom of use,
not price. Our General Public Licenses are designed to make sure that
you have the freedom to distribute copies of free software (and charge
for this service if you wish); that you receive source code or can get
it if you want it; that you can change the software and use pieces of
it in new free programs; and that you are informed that you can do
these things.
To protect your rights, we need to make restrictions that forbid
distributors to deny you these rights or to ask you to surrender these
rights. These restrictions translate to certain responsibilities for
you if you distribute copies of the library or if you modify it.
For example, if you distribute copies of the library, whether gratis
or for a fee, you must give the recipients all the rights that we gave
you. You must make sure that they, too, receive or can get the source
code. If you link other code with the library, you must provide
complete object files to the recipients, so that they can relink them
with the library after making changes to the library and recompiling
it. And you must show them these terms so they know their rights.
We protect your rights with a two-step method: (1) we copyright the
library, and (2) we offer you this license, which gives you legal
permission to copy, distribute and/or modify the library.
To protect each distributor, we want to make it very clear that
there is no warranty for the free library. Also, if the library is
modified by someone else and passed on, the recipients should know
that what they have is not the original version, so that the original
author's reputation will not be affected by problems that might be
introduced by others.
Finally, software patents pose a constant threat to the existence of
any free program. We wish to make sure that a company cannot
effectively restrict the users of a free program by obtaining a
restrictive license from a patent holder. Therefore, we insist that
any patent license obtained for a version of the library must be
consistent with the full freedom of use specified in this license.
Most GNU software, including some libraries, is covered by the
ordinary GNU General Public License. This license, the GNU Lesser
General Public License, applies to certain designated libraries, and
is quite different from the ordinary General Public License. We use
this license for certain libraries in order to permit linking those
libraries into non-free programs.
When a program is linked with a library, whether statically or using
a shared library, the combination of the two is legally speaking a
combined work, a derivative of the original library. The ordinary
General Public License therefore permits such linking only if the
entire combination fits its criteria of freedom. The Lesser General
Public License permits more lax criteria for linking other code with
the library.
We call this license the "Lesser" General Public License because it
does Less to protect the user's freedom than the ordinary General
Public License. It also provides other free software developers Less
of an advantage over competing non-free programs. These disadvantages
are the reason we use the ordinary General Public License for many
libraries. However, the Lesser license provides advantages in certain
special circumstances.
For example, on rare occasions, there may be a special need to
encourage the widest possible use of a certain library, so that it becomes
a de-facto standard. To achieve this, non-free programs must be
allowed to use the library. A more frequent case is that a free
library does the same job as widely used non-free libraries. In this
case, there is little to gain by limiting the free library to free
software only, so we use the Lesser General Public License.
In other cases, permission to use a particular library in non-free
programs enables a greater number of people to use a large body of
free software. For example, permission to use the GNU C Library in
non-free programs enables many more people to use the whole GNU
operating system, as well as its variant, the GNU/Linux operating
system.
Although the Lesser General Public License is Less protective of the
users' freedom, it does ensure that the user of a program that is
linked with the Library has the freedom and the wherewithal to run
that program using a modified version of the Library.
The precise terms and conditions for copying, distribution and
modification follow. Pay close attention to the difference between a
"work based on the library" and a "work that uses the library". The
former contains code derived from the library, whereas the latter must
be combined with the library in order to run.
GNU LESSER GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License Agreement applies to any software library or other
program which contains a notice placed by the copyright holder or
other authorized party saying it may be distributed under the terms of
this Lesser General Public License (also called "this License").
Each licensee is addressed as "you".
A "library" means a collection of software functions and/or data
prepared so as to be conveniently linked with application programs
(which use some of those functions and data) to form executables.
The "Library", below, refers to any such software library or work
which has been distributed under these terms. A "work based on the
Library" means either the Library or any derivative work under
copyright law: that is to say, a work containing the Library or a
portion of it, either verbatim or with modifications and/or translated
straightforwardly into another language. (Hereinafter, translation is
included without limitation in the term "modification".)
"Source code" for a work means the preferred form of the work for
making modifications to it. For a library, complete source code means
all the source code for all modules it contains, plus any associated
interface definition files, plus the scripts used to control compilation
and installation of the library.
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running a program using the Library is not restricted, and output from
such a program is covered only if its contents constitute a work based
on the Library (independent of the use of the Library in a tool for
writing it). Whether that is true depends on what the Library does
and what the program that uses the Library does.
1. You may copy and distribute verbatim copies of the Library's
complete source code as you receive it, in any medium, provided that
you conspicuously and appropriately publish on each copy an
appropriate copyright notice and disclaimer of warranty; keep intact
all the notices that refer to this License and to the absence of any
warranty; and distribute a copy of this License along with the
Library.
You may charge a fee for the physical act of transferring a copy,
and you may at your option offer warranty protection in exchange for a
fee.
2. You may modify your copy or copies of the Library or any portion
of it, thus forming a work based on the Library, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) The modified work must itself be a software library.
b) You must cause the files modified to carry prominent notices
stating that you changed the files and the date of any change.
c) You must cause the whole of the work to be licensed at no
charge to all third parties under the terms of this License.
d) If a facility in the modified Library refers to a function or a
table of data to be supplied by an application program that uses
the facility, other than as an argument passed when the facility
is invoked, then you must make a good faith effort to ensure that,
in the event an application does not supply such function or
table, the facility still operates, and performs whatever part of
its purpose remains meaningful.
(For example, a function in a library to compute square roots has
a purpose that is entirely well-defined independent of the
application. Therefore, Subsection 2d requires that any
application-supplied function or table used by this function must
be optional: if the application does not supply it, the square
root function must still compute square roots.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Library,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Library, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote
it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Library.
In addition, mere aggregation of another work not based on the Library
with the Library (or with a work based on the Library) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may opt to apply the terms of the ordinary GNU General Public
License instead of this License to a given copy of the Library. To do
this, you must alter all the notices that refer to this License, so
that they refer to the ordinary GNU General Public License, version 2,
instead of to this License. (If a newer version than version 2 of the
ordinary GNU General Public License has appeared, then you can specify
that version instead if you wish.) Do not make any other change in
these notices.
Once this change is made in a given copy, it is irreversible for
that copy, so the ordinary GNU General Public License applies to all
subsequent copies and derivative works made from that copy.
This option is useful when you wish to copy part of the code of
the Library into a program that is not a library.
4. You may copy and distribute the Library (or a portion or
derivative of it, under Section 2) in object code or executable form
under the terms of Sections 1 and 2 above provided that you accompany
it with the complete corresponding machine-readable source code, which
must be distributed under the terms of Sections 1 and 2 above on a
medium customarily used for software interchange.
If distribution of object code is made by offering access to copy
from a designated place, then offering equivalent access to copy the
source code from the same place satisfies the requirement to
distribute the source code, even though third parties are not
compelled to copy the source along with the object code.
5. A program that contains no derivative of any portion of the
Library, but is designed to work with the Library by being compiled or
linked with it, is called a "work that uses the Library". Such a
work, in isolation, is not a derivative work of the Library, and
therefore falls outside the scope of this License.
However, linking a "work that uses the Library" with the Library
creates an executable that is a derivative of the Library (because it
contains portions of the Library), rather than a "work that uses the
library". The executable is therefore covered by this License.
Section 6 states terms for distribution of such executables.
When a "work that uses the Library" uses material from a header file
that is part of the Library, the object code for the work may be a
derivative work of the Library even though the source code is not.
Whether this is true is especially significant if the work can be
linked without the Library, or if the work is itself a library. The
threshold for this to be true is not precisely defined by law.
If such an object file uses only numerical parameters, data
structure layouts and accessors, and small macros and small inline
functions (ten lines or less in length), then the use of the object
file is unrestricted, regardless of whether it is legally a derivative
work. (Executables containing this object code plus portions of the
Library will still fall under Section 6.)
Otherwise, if the work is a derivative of the Library, you may
distribute the object code for the work under the terms of Section 6.
Any executables containing that work also fall under Section 6,
whether or not they are linked directly with the Library itself.
6. As an exception to the Sections above, you may also combine or
link a "work that uses the Library" with the Library to produce a
work containing portions of the Library, and distribute that work
under terms of your choice, provided that the terms permit
modification of the work for the customer's own use and reverse
engineering for debugging such modifications.
You must give prominent notice with each copy of the work that the
Library is used in it and that the Library and its use are covered by
this License. You must supply a copy of this License. If the work
during execution displays copyright notices, you must include the
copyright notice for the Library among them, as well as a reference
directing the user to the copy of this License. Also, you must do one
of these things:
a) Accompany the work with the complete corresponding
machine-readable source code for the Library including whatever
changes were used in the work (which must be distributed under
Sections 1 and 2 above); and, if the work is an executable linked
with the Library, with the complete machine-readable "work that
uses the Library", as object code and/or source code, so that the
user can modify the Library and then relink to produce a modified
executable containing the modified Library. (It is understood
that the user who changes the contents of definitions files in the
Library will not necessarily be able to recompile the application
to use the modified definitions.)
b) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (1) uses at run time a
copy of the library already present on the user's computer system,
rather than copying library functions into the executable, and (2)
will operate properly with a modified version of the library, if
the user installs one, as long as the modified version is
interface-compatible with the version that the work was made with.
c) Accompany the work with a written offer, valid for at
least three years, to give the same user the materials
specified in Subsection 6a, above, for a charge no more
than the cost of performing this distribution.
d) If distribution of the work is made by offering access to copy
from a designated place, offer equivalent access to copy the above
specified materials from the same place.
e) Verify that the user has already received a copy of these
materials or that you have already sent this user a copy.
For an executable, the required form of the "work that uses the
Library" must include any data and utility programs needed for
reproducing the executable from it. However, as a special exception,
the materials to be distributed need not include anything that is
normally distributed (in either source or binary form) with the major
components (compiler, kernel, and so on) of the operating system on
which the executable runs, unless that component itself accompanies
the executable.
It may happen that this requirement contradicts the license
restrictions of other proprietary libraries that do not normally
accompany the operating system. Such a contradiction means you cannot
use both them and the Library together in an executable that you
distribute.
7. You may place library facilities that are a work based on the
Library side-by-side in a single library together with other library
facilities not covered by this License, and distribute such a combined
library, provided that the separate distribution of the work based on
the Library and of the other library facilities is otherwise
permitted, and provided that you do these two things:
a) Accompany the combined library with a copy of the same work
based on the Library, uncombined with any other library
facilities. This must be distributed under the terms of the
Sections above.
b) Give prominent notice with the combined library of the fact
that part of it is a work based on the Library, and explaining
where to find the accompanying uncombined form of the same work.
8. You may not copy, modify, sublicense, link with, or distribute
the Library except as expressly provided under this License. Any
attempt otherwise to copy, modify, sublicense, link with, or
distribute the Library is void, and will automatically terminate your
rights under this License. However, parties who have received copies,
or rights, from you under this License will not have their licenses
terminated so long as such parties remain in full compliance.
9. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Library or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Library (or any work based on the
Library), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Library or works based on it.
10. Each time you redistribute the Library (or any work based on the
Library), the recipient automatically receives a license from the
original licensor to copy, distribute, link with or modify the Library
subject to these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties with
this License.
11. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Library at all. For example, if a patent
license would not permit royalty-free redistribution of the Library by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Library.
If any portion of this section is held invalid or unenforceable under any
particular circumstance, the balance of the section is intended to apply,
and the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
12. If the distribution and/or use of the Library is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Library under this License may add
an explicit geographical distribution limitation excluding those countries,
so that distribution is permitted only in or among countries not thus
excluded. In such case, this License incorporates the limitation as if
written in the body of this License.
13. The Free Software Foundation may publish revised and/or new
versions of the Lesser General Public License from time to time.
Such new versions will be similar in spirit to the present version,
but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Library
specifies a version number of this License which applies to it and
"any later version", you have the option of following the terms and
conditions either of that version or of any later version published by
the Free Software Foundation. If the Library does not specify a
license version number, you may choose any version ever published by
the Free Software Foundation.
14. If you wish to incorporate parts of the Library into other free
programs whose distribution conditions are incompatible with these,
write to the author to ask for permission. For software which is
copyrighted by the Free Software Foundation, write to the Free
Software Foundation; we sometimes make exceptions for this. Our
decision will be guided by the two goals of preserving the free status
of all derivatives of our free software and of promoting the sharing
and reuse of software generally.
NO WARRANTY
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Libraries
If you develop a new library, and you want it to be of the greatest
possible use to the public, we recommend making it free software that
everyone can redistribute and change. You can do so by permitting
redistribution under these terms (or, alternatively, under the terms of the
ordinary General Public License).
To apply these terms, attach the following notices to the library. It is
safest to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.
<one line to give the library's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Also add information on how to contact you by electronic and paper mail.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the library, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
<signature of Ty Coon>, 1 April 1990
Ty Coon, President of Vice
That's all there is to it!

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,421 @@
// --------------------------------------------------------------------------------
// PclZip 2.8.2 - readme.txt
// --------------------------------------------------------------------------------
// License GNU/LGPL - August 2009
// Vincent Blavet - vincent@phpconcept.net
// http://www.phpconcept.net
// --------------------------------------------------------------------------------
// $Id: readme.txt,v 1.60 2009/09/30 20:35:21 vblavet Exp $
// --------------------------------------------------------------------------------
0 - Sommaire
============
1 - Introduction
2 - What's new
3 - Corrected bugs
4 - Known bugs or limitations
5 - License
6 - Warning
7 - Documentation
8 - Author
9 - Contribute
1 - Introduction
================
PclZip is a library that allow you to manage a Zip archive.
Full documentation about PclZip can be found here : http://www.phpconcept.net/pclzip
2 - What's new
==============
Version 2.8.2 :
- PCLZIP_CB_PRE_EXTRACT and PCLZIP_CB_POST_EXTRACT are now supported with
extraction as a string (PCLZIP_OPT_EXTRACT_AS_STRING). The string
can also be modified in the post-extract call back.
**Bugs correction :
- PCLZIP_OPT_REMOVE_ALL_PATH was not working correctly
- Remove use of eval() and do direct call to callback functions
- Correct support of 64bits systems (Thanks to WordPress team)
Version 2.8.1 :
- Move option PCLZIP_OPT_BY_EREG to PCLZIP_OPT_BY_PREG because ereg() is
deprecated in PHP 5.3. When using option PCLZIP_OPT_BY_EREG, PclZip will
automatically replace it by PCLZIP_OPT_BY_PREG.
Version 2.8 :
- Improve extraction of zip archive for large files by using temporary files
This feature is working like the one defined in r2.7.
Options are renamed : PCLZIP_OPT_TEMP_FILE_ON, PCLZIP_OPT_TEMP_FILE_OFF,
PCLZIP_OPT_TEMP_FILE_THRESHOLD
- Add a ratio constant PCLZIP_TEMPORARY_FILE_RATIO to configure the auto
sense of temporary file use.
- Bug correction : Reduce filepath in returned file list to remove ennoying
'.//' preambule in file path.
Version 2.7 :
- Improve creation of zip archive for large files :
PclZip will now autosense the configured memory and use temporary files
when large file is suspected.
This feature can also ne triggered by manual options in create() and add()
methods. 'PCLZIP_OPT_ADD_TEMP_FILE_ON' force the use of temporary files,
'PCLZIP_OPT_ADD_TEMP_FILE_OFF' disable the autosense technic,
'PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD' allow for configuration of a size
threshold to use temporary files.
Using "temporary files" rather than "memory" might take more time, but
might give the ability to zip very large files :
Tested on my win laptop with a 88Mo file :
Zip "in-memory" : 18sec (max_execution_time=30, memory_limit=180Mo)
Zip "tmporary-files" : 23sec (max_execution_time=30, memory_limit=30Mo)
- Replace use of mktime() by time() to limit the E_STRICT error messages.
- Bug correction : When adding files with full windows path (drive letter)
PclZip is now working. Before, if the drive letter is not the default
path, PclZip was not able to add the file.
Version 2.6 :
- Code optimisation
- New attributes PCLZIP_ATT_FILE_COMMENT gives the ability to
add a comment for a specific file. (Don't really know if this is usefull)
- New attribute PCLZIP_ATT_FILE_CONTENT gives the ability to add a string
as a file.
- New attribute PCLZIP_ATT_FILE_MTIME modify the timestamp associated with
a file.
- Correct a bug. Files archived with a timestamp with 0h0m0s were extracted
with current time
- Add CRC value in the informations returned back for each file after an
action.
- Add missing closedir() statement.
- When adding a folder, and removing the path of this folder, files were
incorrectly added with a '/' at the beginning. Which means files are
related to root in unix systems. Corrected.
- Add conditional if before constant definition. This will allow users
to redefine constants without changing the file, and then improve
upgrade of pclzip code for new versions.
Version 2.5 :
- Introduce the ability to add file/folder with individual properties (file descriptor).
This gives for example the ability to change the filename of a zipped file.
. Able to add files individually
. Able to change full name
. Able to change short name
. Compatible with global options
- New attributes : PCLZIP_ATT_FILE_NAME, PCLZIP_ATT_FILE_NEW_SHORT_NAME, PCLZIP_ATT_FILE_NEW_FULL_NAME
- New error code : PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE
- Add a security control feature. PclZip can extract any file in any folder
of a system. People may use this to upload a zip file and try to override
a system file. The PCLZIP_OPT_EXTRACT_DIR_RESTRICTION will give the
ability to forgive any directory transversal behavior.
- New PCLZIP_OPT_EXTRACT_DIR_RESTRICTION : check extraction path
- New error code : PCLZIP_ERR_DIRECTORY_RESTRICTION
- Modification in PclZipUtilPathInclusion() : dir and path beginning with ./ will be prepend
by current path (getcwd())
Version 2.4 :
- Code improvment : try to speed up the code by removing unusefull call to pack()
- Correct bug in delete() : delete() should be called with no argument. This was not
the case in 2.3. This is corrected in 2.4.
- Correct a bug in path_inclusion function. When the path has several '../../', the
result was bad.
- Add a check for magic_quotes_runtime configuration. If enabled, PclZip will
disable it while working and det it back to its original value.
This resolve a lots of bad formated archive errors.
- Bug correction : PclZip now correctly unzip file in some specific situation,
when compressed content has same size as uncompressed content.
- Bug correction : When selecting option 'PCLZIP_OPT_REMOVE_ALL_PATH',
directories are not any more created.
- Code improvment : correct unclosed opendir(), better handling of . and .. in
loops.
Version 2.3 :
- Correct a bug with PHP5 : affecting the value 0xFE49FFE0 to a variable does not
give the same result in PHP4 and PHP5 ....
Version 2.2 :
- Try development of PCLZIP_OPT_CRYPT .....
However this becomes to a stop. To crypt/decrypt I need to multiply 2 long integers,
the result (greater than a long) is not supported by PHP. Even the use of bcmath
functions does not help. I did not find yet a solution ...;
- Add missing '/' at end of directory entries
- Check is a file is encrypted or not. Returns status 'unsupported_encryption' and/or
error code PCLZIP_ERR_UNSUPPORTED_ENCRYPTION.
- Corrected : Bad "version need to extract" field in local file header
- Add private method privCheckFileHeaders() in order to check local and central
file headers. PclZip is now supporting purpose bit flag bit 3. Purpose bit flag bit 3 gives
the ability to have a local file header without size, compressed size and crc filled.
- Add a generic status 'error' for file status
- Add control of compression type. PclZip only support deflate compression method.
Before v2.2, PclZip does not check the compression method used in an archive while
extracting. With v2.2 PclZip returns a new error status for a file using an unsupported
compression method. New status is "unsupported_compression". New error code is
PCLZIP_ERR_UNSUPPORTED_COMPRESSION.
- Add optional attribute PCLZIP_OPT_STOP_ON_ERROR. This will stop the extract of files
when errors like 'a folder with same name exists' or 'a newer file exists' or
'a write protected file' exists, rather than set a status for the concerning file
and resume the extract of the zip.
- Add optional attribute PCLZIP_OPT_REPLACE_NEWER. This will force, during an extract' the
replacement of the file, even if a newer version of the file exists.
Note that today if a file with the same name already exists but is older it will be
replaced by the extracted one.
- Improve PclZipUtilOption()
- Support of zip archive with trailing bytes. Before 2.2, PclZip checks that the central
directory structure is the last data in the archive. Crypt encryption/decryption of
zip archive put trailing 0 bytes after decryption. PclZip is now supporting this.
Version 2.1 :
- Add the ability to abort the extraction by using a user callback function.
The user can now return the value '2' in its callback which indicates to stop the
extraction. For a pre call-back extract is stopped before the extration of the current
file. For a post call back, the extraction is stopped after.
- Add the ability to extract a file (or several files) directly in the standard output.
This is done by the new parameter PCLZIP_OPT_EXTRACT_IN_OUTPUT with method extract().
- Add support for parameters PCLZIP_OPT_COMMENT, PCLZIP_OPT_ADD_COMMENT,
PCLZIP_OPT_PREPEND_COMMENT. This will create, replace, add, or prepend comments
in the zip archive.
- When merging two archives, the comments are not any more lost, but merged, with a
blank space separator.
- Corrected bug : Files are not deleted when all files are asked to be deleted.
- Corrected bug : Folders with name '0' made PclZip to abort the create or add feature.
Version 2.0 :
***** Warning : Some new features may break the backward compatibility for your scripts.
Please carefully read the readme file.
- Add the ability to delete by Index, name and regular expression. This feature is
performed by the method delete(), which uses the optional parameters
PCLZIP_OPT_BY_INDEX, PCLZIP_OPT_BY_NAME, PCLZIP_OPT_BY_EREG or PCLZIP_OPT_BY_PREG.
- Add the ability to extract by regular expression. To extract by regexp you must use the method
extract(), with the option PCLZIP_OPT_BY_EREG or PCLZIP_OPT_BY_PREG
(depending if you want to use ereg() or preg_match() syntax) followed by the
regular expression pattern.
- Add the ability to extract by index, directly with the extract() method. This is a
code improvment of the extractByIndex() method.
- Add the ability to extract by name. To extract by name you must use the method
extract(), with the option PCLZIP_OPT_BY_NAME followed by the filename to
extract or an array of filenames to extract. To extract all a folder, use the folder
name rather than the filename with a '/' at the end.
- Add the ability to add files without compression. This is done with a new attribute
which is PCLZIP_OPT_NO_COMPRESSION.
- Add the attribute PCLZIP_OPT_EXTRACT_AS_STRING, which allow to extract a file directly
in a string without using any file (or temporary file).
- Add constant PCLZIP_SEPARATOR for static configuration of filename separators in a single string.
The default separator is now a comma (,) and not any more a blank space.
THIS BREAK THE BACKWARD COMPATIBILITY : Please check if this may have an impact with
your script.
- Improve algorythm performance by removing the use of temporary files when adding or
extracting files in an archive.
- Add (correct) detection of empty filename zipping. This can occurs when the removed
path is the same
as a zipped dir. The dir is not zipped (['status'] = filtered), only its content.
- Add better support for windows paths (thanks for help from manus@manusfreedom.com).
- Corrected bug : When the archive file already exists with size=0, the add() method
fails. Corrected in 2.0.
- Remove the use of OS_WINDOWS constant. Use php_uname() function rather.
- Control the order of index ranges in extract by index feature.
- Change the internal management of folders (better handling of internal flag).
Version 1.3 :
- Removing the double include check. This is now done by include_once() and require_once()
PHP directives.
- Changing the error handling mecanism : Remove the use of an external error library.
The former PclError...() functions are replaced by internal equivalent methods.
By changing the environment variable PCLZIP_ERROR_EXTERNAL you can still use the former library.
Introducing the use of constants for error codes rather than integer values. This will help
in futur improvment.
Introduction of error handling functions like errorCode(), errorName() and errorInfo().
- Remove the deprecated use of calling function with arguments passed by reference.
- Add the calling of extract(), extractByIndex(), create() and add() functions
with variable options rather than fixed arguments.
- Add the ability to remove all the file path while extracting or adding,
without any need to specify the path to remove.
This is available for extract(), extractByIndex(), create() and add() functionS by using
the new variable options parameters :
- PCLZIP_OPT_REMOVE_ALL_PATH : by indicating this option while calling the fct.
- Ability to change the mode of a file after the extraction (chmod()).
This is available for extract() and extractByIndex() functionS by using
the new variable options parameters.
- PCLZIP_OPT_SET_CHMOD : by setting the value of this option.
- Ability to definition call-back options. These call-back will be called during the adding,
or the extracting of file (extract(), extractByIndex(), create() and add() functions) :
- PCLZIP_CB_PRE_EXTRACT : will be called before each extraction of a file. The user
can trigerred the change the filename of the extracted file. The user can triggered the
skip of the extraction. This is adding a 'skipped' status in the file list result value.
- PCLZIP_CB_POST_EXTRACT : will be called after each extraction of a file.
Nothing can be triggered from that point.
- PCLZIP_CB_PRE_ADD : will be called before each add of a file. The user
can trigerred the change the stored filename of the added file. The user can triggered the
skip of the add. This is adding a 'skipped' status in the file list result value.
- PCLZIP_CB_POST_ADD : will be called after each add of a file.
Nothing can be triggered from that point.
- Two status are added in the file list returned as function result : skipped & filename_too_long
'skipped' is used when a call-back function ask for skipping the file.
'filename_too_long' is used while adding a file with a too long filename to archive (the file is
not added)
- Adding the function PclZipUtilPathInclusion(), that check the inclusion of a path into
a directory.
- Add a check of the presence of the archive file before some actions (like list, ...)
- Add the initialisation of field "index" in header array. This means that by
default index will be -1 when not explicitly set by the methods.
Version 1.2 :
- Adding a duplicate function.
- Adding a merge function. The merge function is a "quick merge" function,
it just append the content of an archive at the end of the first one. There
is no check for duplicate files or more recent files.
- Improve the search of the central directory end.
Version 1.1.2 :
- Changing the license of PclZip. PclZip is now released under the GNU / LGPL license
(see License section).
- Adding the optional support of a static temporary directory. You will need to configure
the constant PCLZIP_TEMPORARY_DIR if you want to use this feature.
- Improving the rename() function. In some cases rename() does not work (different
Filesystems), so it will be replaced by a copy() + unlink() functions.
Version 1.1.1 :
- Maintenance release, no new feature.
Version 1.1 :
- New method Add() : adding files in the archive
- New method ExtractByIndex() : partial extract of the archive, files are identified by
their index in the archive
- New method DeleteByIndex() : delete some files/folder entries from the archive,
files are identified by their index in the archive.
- Adding a test of the zlib extension presence. If not present abort the script.
Version 1.0.1 :
- No new feature
3 - Corrected bugs
==================
Corrected in Version 2.0 :
- Corrected : During an extraction, if a call-back fucntion is used and try to skip
a file, all the extraction process is stopped.
Corrected in Version 1.3 :
- Corrected : Support of static synopsis for method extract() is broken.
- Corrected : invalid size of archive content field (0xFF) should be (0xFFFF).
- Corrected : When an extract is done with a remove_path parameter, the entry for
the directory with exactly the same path is not skipped/filtered.
- Corrected : extractByIndex() and deleteByIndex() were not managing index in the
right way. For example indexes '1,3-5,11' will only extract files 1 and 11. This
is due to a sort of the index resulting table that puts 11 before 3-5 (sort on
string and not interger). The sort is temporarilly removed, this means that
you must provide a sorted list of index ranges.
Corrected in Version 1.2 :
- Nothing.
Corrected in Version 1.1.2 :
- Corrected : Winzip is unable to delete or add new files in a PclZip created archives.
Corrected in Version 1.1.1 :
- Corrected : When archived file is not compressed (0% compression), the
extract method fails.
Corrected in Version 1.1 :
- Corrected : Adding a complete tree of folder may result in a bad archive
creation.
Corrected in Version 1.0.1 :
- Corrected : Error while compressing files greater than PCLZIP_READ_BLOCK_SIZE (default=1024).
4 - Known bugs or limitations
=============================
Please publish bugs reports in SourceForge :
http://sourceforge.net/tracker/?group_id=40254&atid=427564
In Version 2.x :
- PclZip does only support file uncompressed or compressed with deflate (compression method 8)
- PclZip does not support password protected zip archive
- Some concern were seen when changing mtime of a file while archiving.
Seems to be linked to Daylight Saving Time (PclTest_changing_mtime).
In Version 1.2 :
- merge() methods does not check for duplicate files or last date of modifications.
In Version 1.1 :
- Limitation : Using 'extract' fields in the file header in the zip archive is not supported.
- WinZip is unable to delete a single file in a PclZip created archive. It is also unable to
add a file in a PclZip created archive. (Corrected in v.1.2)
In Version 1.0.1 :
- Adding a complete tree of folder may result in a bad archive
creation. (Corrected in V.1.1).
- Path given to methods must be in the unix format (/) and not the Windows format (\).
Workaround : Use only / directory separators.
- PclZip is using temporary files that are sometime the name of the file with a .tmp or .gz
added suffix. Files with these names may already exist and may be overwritten.
Workaround : none.
- PclZip does not check if the zlib extension is present. If it is absent, the zip
file is not created and the lib abort without warning.
Workaround : enable the zlib extension on the php install
In Version 1.0 :
- Error while compressing files greater than PCLZIP_READ_BLOCK_SIZE (default=1024).
(Corrected in v.1.0.1)
- Limitation : Multi-disk zip archive are not supported.
5 - License
===========
Since version 1.1.2, PclZip Library is released under GNU/LGPL license.
This library is free, so you can use it at no cost.
HOWEVER, if you release a script, an application, a library or any kind of
code using PclZip library (or a part of it), YOU MUST :
- Indicate in the documentation (or a readme file), that your work
uses PclZip Library, and make a reference to the author and the web site
http://www.phpconcept.net
- Gives the ability to the final user to update the PclZip libary.
I will also appreciate that you send me a mail (vincent@phpconcept.net), just to
be aware that someone is using PclZip.
For more information about GNU/LGPL license : http://www.gnu.org
6 - Warning
=================
This library and the associated files are non commercial, non professional work.
It should not have unexpected results. However if any damage is caused by this software
the author can not be responsible.
The use of this software is at the risk of the user.
7 - Documentation
=================
PclZip User Manuel is available in English on PhpConcept : http://www.phpconcept.net/pclzip/man/en/index.php
A Russian translation was done by Feskov Kuzma : http://php.russofile.ru/ru/authors/unsort/zip/
8 - Author
==========
This software was written by Vincent Blavet (vincent@phpconcept.net) on its leasure time.
9 - Contribute
==============
If you want to contribute to the development of PclZip, please contact vincent@phpconcept.net.
If you can help in financing PhpConcept hosting service, please go to
http://www.phpconcept.net/soutien.php

View File

@@ -1,67 +0,0 @@
<?php
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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_Shared
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.4, 2010-08-26
*/
/**
* PHPExcel_Shared_PasswordHasher
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_PasswordHasher
{
/**
* Create a password hash from a given string.
*
* This method is based on the algorithm provided by
* Daniel Rentz of OpenOffice and the PEAR package
* Spreadsheet_Excel_Writer by Xavier Noguer <xnoguer@rezebra.com>.
*
* @param string $pPassword Password to hash
* @return string Hashed password
*/
public static function hashPassword($pPassword = '') {
$password = 0x0000;
$i = 1; // char position
// split the plain text password in its component characters
$chars = preg_split('//', $pPassword, -1, PREG_SPLIT_NO_EMPTY);
foreach ($chars as $char) {
$value = ord($char) << $i; // shifted ASCII value
$rotated_bits = $value >> 15; // rotated bits beyond bit 15
$value &= 0x7fff; // first 15 bits
$password ^= ($value | $rotated_bits);
++$i;
}
$password ^= strlen($pPassword);
$password ^= 0xCE4B;
return(strtoupper(dechex($password)));
}
}

View File

@@ -1,677 +0,0 @@
<?php
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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_Shared
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.4, 2010-08-26
*/
/**
* PHPExcel_Shared_String
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_String
{
/** Constants */
/** Regular Expressions */
// Fraction
const STRING_REGEXP_FRACTION = '(-?)(\d+)\s+(\d+\/\d+)';
/**
* Control characters array
*
* @var string[]
*/
private static $_controlCharacters = array();
/**
* SYLK Characters array
*
* $var array
*/
private static $_SYLKCharacters = array();
/**
* Decimal separator
*
* @var string
*/
private static $_decimalSeparator;
/**
* Thousands separator
*
* @var string
*/
private static $_thousandsSeparator;
/**
* Is mbstring extension avalable?
*
* @var boolean
*/
private static $_isMbstringEnabled;
/**
* Is iconv extension avalable?
*
* @var boolean
*/
private static $_isIconvEnabled;
/**
* Build control characters array
*/
private static function _buildControlCharacters() {
for ($i = 0; $i <= 31; ++$i) {
if ($i != 9 && $i != 10 && $i != 13) {
$find = '_x' . sprintf('%04s' , strtoupper(dechex($i))) . '_';
$replace = chr($i);
self::$_controlCharacters[$find] = $replace;
}
}
}
/**
* Build SYLK characters array
*/
private static function _buildSYLKCharacters()
{
self::$_SYLKCharacters = array(
"\x1B 0" => chr(0),
"\x1B 1" => chr(1),
"\x1B 2" => chr(2),
"\x1B 3" => chr(3),
"\x1B 4" => chr(4),
"\x1B 5" => chr(5),
"\x1B 6" => chr(6),
"\x1B 7" => chr(7),
"\x1B 8" => chr(8),
"\x1B 9" => chr(9),
"\x1B :" => chr(10),
"\x1B ;" => chr(11),
"\x1B <" => chr(12),
"\x1B :" => chr(13),
"\x1B >" => chr(14),
"\x1B ?" => chr(15),
"\x1B!0" => chr(16),
"\x1B!1" => chr(17),
"\x1B!2" => chr(18),
"\x1B!3" => chr(19),
"\x1B!4" => chr(20),
"\x1B!5" => chr(21),
"\x1B!6" => chr(22),
"\x1B!7" => chr(23),
"\x1B!8" => chr(24),
"\x1B!9" => chr(25),
"\x1B!:" => chr(26),
"\x1B!;" => chr(27),
"\x1B!<" => chr(28),
"\x1B!=" => chr(29),
"\x1B!>" => chr(30),
"\x1B!?" => chr(31),
"\x1B'?" => chr(127),
"\x1B(0" => '€', // 128 in CP1252
"\x1B(2" => '', // 130 in CP1252
"\x1B(3" => 'ƒ', // 131 in CP1252
"\x1B(4" => '„', // 132 in CP1252
"\x1B(5" => '…', // 133 in CP1252
"\x1B(6" => '†', // 134 in CP1252
"\x1B(7" => '‡', // 135 in CP1252
"\x1B(8" => 'ˆ', // 136 in CP1252
"\x1B(9" => '‰', // 137 in CP1252
"\x1B(:" => 'Š', // 138 in CP1252
"\x1B(;" => '', // 139 in CP1252
"\x1BNj" => 'Œ', // 140 in CP1252
"\x1B(>" => 'Ž', // 142 in CP1252
"\x1B)1" => '', // 145 in CP1252
"\x1B)2" => '', // 146 in CP1252
"\x1B)3" => '“', // 147 in CP1252
"\x1B)4" => '”', // 148 in CP1252
"\x1B)5" => '•', // 149 in CP1252
"\x1B)6" => '', // 150 in CP1252
"\x1B)7" => '—', // 151 in CP1252
"\x1B)8" => '˜', // 152 in CP1252
"\x1B)9" => '™', // 153 in CP1252
"\x1B):" => 'š', // 154 in CP1252
"\x1B);" => '', // 155 in CP1252
"\x1BNz" => 'œ', // 156 in CP1252
"\x1B)>" => 'ž', // 158 in CP1252
"\x1B)?" => 'Ÿ', // 159 in CP1252
"\x1B*0" => ' ', // 160 in CP1252
"\x1BN!" => '¡', // 161 in CP1252
"\x1BN\"" => '¢', // 162 in CP1252
"\x1BN#" => '£', // 163 in CP1252
"\x1BN(" => '¤', // 164 in CP1252
"\x1BN%" => '¥', // 165 in CP1252
"\x1B*6" => '¦', // 166 in CP1252
"\x1BN'" => '§', // 167 in CP1252
"\x1BNH " => '¨', // 168 in CP1252
"\x1BNS" => '©', // 169 in CP1252
"\x1BNc" => 'ª', // 170 in CP1252
"\x1BN+" => '«', // 171 in CP1252
"\x1B*<" => '¬', // 172 in CP1252
"\x1B*=" => '­', // 173 in CP1252
"\x1BNR" => '®', // 174 in CP1252
"\x1B*?" => '¯', // 175 in CP1252
"\x1BN0" => '°', // 176 in CP1252
"\x1BN1" => '±', // 177 in CP1252
"\x1BN2" => '²', // 178 in CP1252
"\x1BN3" => '³', // 179 in CP1252
"\x1BNB " => '´', // 180 in CP1252
"\x1BN5" => 'µ', // 181 in CP1252
"\x1BN6" => '¶', // 182 in CP1252
"\x1BN7" => '·', // 183 in CP1252
"\x1B+8" => '¸', // 184 in CP1252
"\x1BNQ" => '¹', // 185 in CP1252
"\x1BNk" => 'º', // 186 in CP1252
"\x1BN;" => '»', // 187 in CP1252
"\x1BN<" => '¼', // 188 in CP1252
"\x1BN=" => '½', // 189 in CP1252
"\x1BN>" => '¾', // 190 in CP1252
"\x1BN?" => '¿', // 191 in CP1252
"\x1BNAA" => 'À', // 192 in CP1252
"\x1BNBA" => 'Á', // 193 in CP1252
"\x1BNCA" => 'Â', // 194 in CP1252
"\x1BNDA" => 'Ã', // 195 in CP1252
"\x1BNHA" => 'Ä', // 196 in CP1252
"\x1BNJA" => 'Å', // 197 in CP1252
"\x1BNa" => 'Æ', // 198 in CP1252
"\x1BNKC" => 'Ç', // 199 in CP1252
"\x1BNAE" => 'È', // 200 in CP1252
"\x1BNBE" => 'É', // 201 in CP1252
"\x1BNCE" => 'Ê', // 202 in CP1252
"\x1BNHE" => 'Ë', // 203 in CP1252
"\x1BNAI" => 'Ì', // 204 in CP1252
"\x1BNBI" => 'Í', // 205 in CP1252
"\x1BNCI" => 'Î', // 206 in CP1252
"\x1BNHI" => 'Ï', // 207 in CP1252
"\x1BNb" => 'Ð', // 208 in CP1252
"\x1BNDN" => 'Ñ', // 209 in CP1252
"\x1BNAO" => 'Ò', // 210 in CP1252
"\x1BNBO" => 'Ó', // 211 in CP1252
"\x1BNCO" => 'Ô', // 212 in CP1252
"\x1BNDO" => 'Õ', // 213 in CP1252
"\x1BNHO" => 'Ö', // 214 in CP1252
"\x1B-7" => '×', // 215 in CP1252
"\x1BNi" => 'Ø', // 216 in CP1252
"\x1BNAU" => 'Ù', // 217 in CP1252
"\x1BNBU" => 'Ú', // 218 in CP1252
"\x1BNCU" => 'Û', // 219 in CP1252
"\x1BNHU" => 'Ü', // 220 in CP1252
"\x1B-=" => 'Ý', // 221 in CP1252
"\x1BNl" => 'Þ', // 222 in CP1252
"\x1BN{" => 'ß', // 223 in CP1252
"\x1BNAa" => 'à', // 224 in CP1252
"\x1BNBa" => 'á', // 225 in CP1252
"\x1BNCa" => 'â', // 226 in CP1252
"\x1BNDa" => 'ã', // 227 in CP1252
"\x1BNHa" => 'ä', // 228 in CP1252
"\x1BNJa" => 'å', // 229 in CP1252
"\x1BNq" => 'æ', // 230 in CP1252
"\x1BNKc" => 'ç', // 231 in CP1252
"\x1BNAe" => 'è', // 232 in CP1252
"\x1BNBe" => 'é', // 233 in CP1252
"\x1BNCe" => 'ê', // 234 in CP1252
"\x1BNHe" => 'ë', // 235 in CP1252
"\x1BNAi" => 'ì', // 236 in CP1252
"\x1BNBi" => 'í', // 237 in CP1252
"\x1BNCi" => 'î', // 238 in CP1252
"\x1BNHi" => 'ï', // 239 in CP1252
"\x1BNs" => 'ð', // 240 in CP1252
"\x1BNDn" => 'ñ', // 241 in CP1252
"\x1BNAo" => 'ò', // 242 in CP1252
"\x1BNBo" => 'ó', // 243 in CP1252
"\x1BNCo" => 'ô', // 244 in CP1252
"\x1BNDo" => 'õ', // 245 in CP1252
"\x1BNHo" => 'ö', // 246 in CP1252
"\x1B/7" => '÷', // 247 in CP1252
"\x1BNy" => 'ø', // 248 in CP1252
"\x1BNAu" => 'ù', // 249 in CP1252
"\x1BNBu" => 'ú', // 250 in CP1252
"\x1BNCu" => 'û', // 251 in CP1252
"\x1BNHu" => 'ü', // 252 in CP1252
"\x1B/=" => 'ý', // 253 in CP1252
"\x1BN|" => 'þ', // 254 in CP1252
"\x1BNHy" => 'ÿ', // 255 in CP1252
);
}
/**
* Get whether mbstring extension is available
*
* @return boolean
*/
public static function getIsMbstringEnabled()
{
if (isset(self::$_isMbstringEnabled)) {
return self::$_isMbstringEnabled;
}
self::$_isMbstringEnabled = function_exists('mb_convert_encoding') ?
true : false;
return self::$_isMbstringEnabled;
}
/**
* Get whether iconv extension is available
*
* @return boolean
*/
public static function getIsIconvEnabled()
{
if (isset(self::$_isIconvEnabled)) {
return self::$_isIconvEnabled;
}
// Fail if iconv doesn't exist
if (!function_exists('iconv')) {
self::$_isIconvEnabled = false;
return false;
}
// Sometimes iconv is not working, and e.g. iconv('UTF-8', 'UTF-16LE', 'x') just returns false,
if (!@iconv('UTF-8', 'UTF-16LE', 'x')) {
self::$_isIconvEnabled = false;
return false;
}
// Sometimes iconv_substr('A', 0, 1, 'UTF-8') just returns false in PHP 5.2.0
// we cannot use iconv in that case either (http://bugs.php.net/bug.php?id=37773)
if (!@iconv('UTF-8', 'UTF-16LE', 'x')) {
self::$_isIconvEnabled = false;
return false;
}
// CUSTOM: IBM AIX iconv() does not work
if ( defined('PHP_OS') && @stristr(PHP_OS, 'AIX')
&& defined('ICONV_IMPL') && (@strcasecmp(ICONV_IMPL, 'unknown') == 0)
&& defined('ICONV_VERSION') && (@strcasecmp(ICONV_VERSION, 'unknown') == 0) )
{
self::$_isIconvEnabled = false;
return false;
}
// If we reach here no problems were detected with iconv
self::$_isIconvEnabled = true;
return true;
}
/**
* Convert from OpenXML escaped control character to PHP control character
*
* Excel 2007 team:
* ----------------
* That's correct, control characters are stored directly in the shared-strings table.
* We do encode characters that cannot be represented in XML using the following escape sequence:
* _xHHHH_ where H represents a hexadecimal character in the character's value...
* So you could end up with something like _x0008_ in a string (either in a cell value (<v>)
* element or in the shared string <t> element.
*
* @param string $value Value to unescape
* @return string
*/
public static function ControlCharacterOOXML2PHP($value = '') {
if(empty(self::$_controlCharacters)) {
self::_buildControlCharacters();
}
return str_replace( array_keys(self::$_controlCharacters), array_values(self::$_controlCharacters), $value );
}
/**
* Convert from PHP control character to OpenXML escaped control character
*
* Excel 2007 team:
* ----------------
* That's correct, control characters are stored directly in the shared-strings table.
* We do encode characters that cannot be represented in XML using the following escape sequence:
* _xHHHH_ where H represents a hexadecimal character in the character's value...
* So you could end up with something like _x0008_ in a string (either in a cell value (<v>)
* element or in the shared string <t> element.
*
* @param string $value Value to escape
* @return string
*/
public static function ControlCharacterPHP2OOXML($value = '') {
if(empty(self::$_controlCharacters)) {
self::_buildControlCharacters();
}
return str_replace( array_values(self::$_controlCharacters), array_keys(self::$_controlCharacters), $value );
}
/**
* Try to sanitize UTF8, stripping invalid byte sequences. Not perfect. Does not surrogate characters.
*
* @param string $value
* @return string
*/
public static function SanitizeUTF8($value)
{
if (self::getIsIconvEnabled()) {
$value = @iconv('UTF-8', 'UTF-8', $value);
return $value;
}
if (self::getIsMbstringEnabled()) {
$value = mb_convert_encoding($value, 'UTF-8', 'UTF-8');
return $value;
}
// else, no conversion
return $value;
}
/**
* Check if a string contains UTF8 data
*
* @param string $value
* @return boolean
*/
public static function IsUTF8($value = '') {
return utf8_encode(utf8_decode($value)) === $value;
}
/**
* Formats a numeric value as a string for output in various output writers forcing
* point as decimal separator in case locale is other than English.
*
* @param mixed $value
* @return string
*/
public static function FormatNumber($value) {
if (is_float($value)) {
return str_replace(',', '.', $value);
}
return (string) $value;
}
/**
* Converts a UTF-8 string into BIFF8 Unicode string data (8-bit string length)
* Writes the string using uncompressed notation, no rich text, no Asian phonetics
* If mbstring extension is not available, ASCII is assumed, and compressed notation is used
* although this will give wrong results for non-ASCII strings
* see OpenOffice.org's Documentation of the Microsoft Excel File Format, sect. 2.5.3
*
* @param string $value UTF-8 encoded string
* @return string
*/
public static function UTF8toBIFF8UnicodeShort($value)
{
// character count
$ln = self::CountCharacters($value, 'UTF-8');
// option flags
$opt = (self::getIsIconvEnabled() || self::getIsMbstringEnabled()) ?
0x0001 : 0x0000;
// characters
$chars = self::ConvertEncoding($value, 'UTF-16LE', 'UTF-8');
$data = pack('CC', $ln, $opt) . $chars;
return $data;
}
/**
* Converts a UTF-8 string into BIFF8 Unicode string data (16-bit string length)
* Writes the string using uncompressed notation, no rich text, no Asian phonetics
* If mbstring extension is not available, ASCII is assumed, and compressed notation is used
* although this will give wrong results for non-ASCII strings
* see OpenOffice.org's Documentation of the Microsoft Excel File Format, sect. 2.5.3
*
* @param string $value UTF-8 encoded string
* @return string
*/
public static function UTF8toBIFF8UnicodeLong($value)
{
// character count
$ln = self::CountCharacters($value, 'UTF-8');
// option flags
$opt = (self::getIsIconvEnabled() || self::getIsMbstringEnabled()) ?
0x0001 : 0x0000;
// characters
$chars = self::ConvertEncoding($value, 'UTF-16LE', 'UTF-8');
$data = pack('vC', $ln, $opt) . $chars;
return $data;
}
/**
* Convert string from one encoding to another. First try iconv, then mbstring, or no convertion
*
* @param string $value
* @param string $to Encoding to convert to, e.g. 'UTF-8'
* @param string $from Encoding to convert from, e.g. 'UTF-16LE'
* @return string
*/
public static function ConvertEncoding($value, $to, $from)
{
if (self::getIsIconvEnabled()) {
$value = iconv($from, $to, $value);
return $value;
}
if (self::getIsMbstringEnabled()) {
$value = mb_convert_encoding($value, $to, $from);
return $value;
}
if($from == 'UTF-16LE'){
return self::utf16_decode($value, false);
}else if($from == 'UTF-16BE'){
return self::utf16_decode($value);
}
// else, no conversion
return $value;
}
/**
* Decode UTF-16 encoded strings.
*
* Can handle both BOM'ed data and un-BOM'ed data.
* Assumes Big-Endian byte order if no BOM is available.
* This function was taken from http://php.net/manual/en/function.utf8-decode.php
* and $bom_be parameter added.
*
* @param string $str UTF-16 encoded data to decode.
* @return string UTF-8 / ISO encoded data.
* @access public
* @version 0.2 / 2010-05-13
* @author Rasmus Andersson {@link http://rasmusandersson.se/}
* @author vadik56
*/
public static function utf16_decode( $str, $bom_be=true ) {
if( strlen($str) < 2 ) return $str;
$c0 = ord($str{0});
$c1 = ord($str{1});
if( $c0 == 0xfe && $c1 == 0xff ) { $str = substr($str,2); }
elseif( $c0 == 0xff && $c1 == 0xfe ) { $str = substr($str,2); $bom_be = false; }
$len = strlen($str);
$newstr = '';
for($i=0;$i<$len;$i+=2) {
if( $bom_be ) { $val = ord($str{$i}) << 4; $val += ord($str{$i+1}); }
else { $val = ord($str{$i+1}) << 4; $val += ord($str{$i}); }
$newstr .= ($val == 0x228) ? "\n" : chr($val);
}
return $newstr;
}
/**
* Get character count. First try mbstring, then iconv, finally strlen
*
* @param string $value
* @param string $enc Encoding
* @return int Character count
*/
public static function CountCharacters($value, $enc = 'UTF-8')
{
if (self::getIsIconvEnabled()) {
$count = iconv_strlen($value, $enc);
return $count;
}
if (self::getIsMbstringEnabled()) {
$count = mb_strlen($value, $enc);
return $count;
}
// else strlen
$count = strlen($value);
return $count;
}
/**
* Get a substring of a UTF-8 encoded string
*
* @param string $pValue UTF-8 encoded string
* @param int $start Start offset
* @param int $length Maximum number of characters in substring
* @return string
*/
public static function Substring($pValue = '', $pStart = 0, $pLength = 0)
{
if (self::getIsIconvEnabled()) {
$string = iconv_substr($pValue, $pStart, $pLength, 'UTF-8');
return $string;
}
if (self::getIsMbstringEnabled()) {
$string = mb_substr($pValue, $pStart, $pLength, 'UTF-8');
return $string;
}
// else substr
$string = substr($pValue, $pStart, $pLength);
return $string;
}
/**
* Identify whether a string contains a fractional numeric value,
* and convert it to a numeric if it is
*
* @param string &$operand string value to test
* @return boolean
*/
public static function convertToNumberIfFraction(&$operand) {
if (preg_match('/^'.self::STRING_REGEXP_FRACTION.'$/i', $operand, $match)) {
$sign = ($match[1] == '-') ? '-' : '+';
$fractionFormula = '='.$sign.$match[2].$sign.$match[3];
$operand = PHPExcel_Calculation::getInstance()->_calculateFormulaValue($fractionFormula);
return true;
}
return false;
} // function convertToNumberIfFraction()
/**
* Get the decimal separator. If it has not yet been set explicitly, try to obtain number
* formatting information from locale.
*
* @return string
*/
public static function getDecimalSeparator()
{
if (!isset(self::$_decimalSeparator)) {
$localeconv = localeconv();
self::$_decimalSeparator = $localeconv['decimal_point'] != ''
? $localeconv['decimal_point'] : $localeconv['mon_decimal_point'];
if (self::$_decimalSeparator == '')
{
// Default to .
self::$_decimalSeparator = '.';
}
}
return self::$_decimalSeparator;
}
/**
* Set the decimal separator. Only used by PHPExcel_Style_NumberFormat::toFormattedString()
* to format output by PHPExcel_Writer_HTML and PHPExcel_Writer_PDF
*
* @param string $pValue Character for decimal separator
*/
public static function setDecimalSeparator($pValue = '.')
{
self::$_decimalSeparator = $pValue;
}
/**
* Get the thousands separator. If it has not yet been set explicitly, try to obtain number
* formatting information from locale.
*
* @return string
*/
public static function getThousandsSeparator()
{
if (!isset(self::$_thousandsSeparator)) {
$localeconv = localeconv();
self::$_thousandsSeparator = $localeconv['thousands_sep'] != ''
? $localeconv['thousands_sep'] : $localeconv['mon_thousands_sep'];
}
return self::$_thousandsSeparator;
}
/**
* Set the thousands separator. Only used by PHPExcel_Style_NumberFormat::toFormattedString()
* to format output by PHPExcel_Writer_HTML and PHPExcel_Writer_PDF
*
* @param string $pValue Character for thousands separator
*/
public static function setThousandsSeparator($pValue = ',')
{
self::$_thousandsSeparator = $pValue;
}
/**
* Convert SYLK encoded string to UTF-8
*
* @param string $pValue
* @return string UTF-8 encoded string
*/
public static function SYLKtoUTF8($pValue = '')
{
// If there is no escape character in the string there is nothing to do
if (strpos($pValue, '') === false) {
return $pValue;
}
if(empty(self::$_SYLKCharacters)) {
self::_buildSYLKCharacters();
}
foreach (self::$_SYLKCharacters as $k => $v) {
$pValue = str_replace($k, $v, $pValue);
}
return $pValue;
}
}

View File

@@ -1,148 +0,0 @@
<?php
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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_Shared
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.4, 2010-08-26
*/
if (!defined('DATE_W3C')) {
define('DATE_W3C', 'Y-m-d\TH:i:sP');
}
if (!defined('DEBUGMODE_ENABLED')) {
define('DEBUGMODE_ENABLED', false);
}
/**
* PHPExcel_Shared_XMLWriter
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_XMLWriter {
/** Temporary storage method */
const STORAGE_MEMORY = 1;
const STORAGE_DISK = 2;
/**
* Internal XMLWriter
*
* @var XMLWriter
*/
private $_xmlWriter;
/**
* Temporary filename
*
* @var string
*/
private $_tempFileName = '';
/**
* Create a new PHPExcel_Shared_XMLWriter instance
*
* @param int $pTemporaryStorage Temporary storage location
* @param string $pTemporaryStorageFolder Temporary storage folder
*/
public function __construct($pTemporaryStorage = self::STORAGE_MEMORY, $pTemporaryStorageFolder = './') {
// Create internal XMLWriter
$this->_xmlWriter = new XMLWriter();
// Open temporary storage
if ($pTemporaryStorage == self::STORAGE_MEMORY) {
$this->_xmlWriter->openMemory();
} else {
// Create temporary filename
$this->_tempFileName = @tempnam($pTemporaryStorageFolder, 'xml');
// Open storage
if ($this->_xmlWriter->openUri($this->_tempFileName) === false) {
// Fallback to memory...
$this->_xmlWriter->openMemory();
}
}
// Set default values
if (DEBUGMODE_ENABLED) {
$this->_xmlWriter->setIndent(true);
}
}
/**
* Destructor
*/
public function __destruct() {
// Desctruct XMLWriter
unset($this->_xmlWriter);
// Unlink temporary files
if ($this->_tempFileName != '') {
@unlink($this->_tempFileName);
}
}
/**
* Get written data
*
* @return $data
*/
public function getData() {
if ($this->_tempFileName == '') {
return $this->_xmlWriter->outputMemory(true);
} else {
$this->_xmlWriter->flush();
return file_get_contents($this->_tempFileName);
}
}
/**
* Catch function calls (and pass them to internal XMLWriter)
*
* @param unknown_type $function
* @param unknown_type $args
*/
public function __call($function, $args) {
try {
@call_user_func_array(array($this->_xmlWriter, $function), $args);
} catch (Exception $ex) {
// Do nothing!
}
}
/**
* Fallback method for writeRaw, introduced in PHP 5.2
*
* @param string $text
* @return string
*/
public function writeRaw($text)
{
if (isset($this->_xmlWriter) && is_object($this->_xmlWriter) && (method_exists($this->_xmlWriter, 'writeRaw'))) {
return $this->_xmlWriter->writeRaw(htmlspecialchars($text));
}
return $this->text($text);
}
}

View File

@@ -1,163 +0,0 @@
<?php
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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_Shared
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.4, 2010-08-26
*/
/**
* PHPExcel_Shared_ZipStreamWrapper
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_ZipStreamWrapper {
/**
* Internal ZipAcrhive
*
* @var ZipAcrhive
*/
private $_archive;
/**
* Filename in ZipAcrhive
*
* @var string
*/
private $_fileNameInArchive = '';
/**
* Position in file
*
* @var int
*/
private $_position = 0;
/**
* Data
*
* @var mixed
*/
private $_data = '';
/**
* Register wrapper
*/
public static function register() {
@stream_wrapper_unregister("zip");
@stream_wrapper_register("zip", __CLASS__);
}
/**
* Open stream
*/
public function stream_open($path, $mode, $options, &$opened_path) {
// Check for mode
if ($mode{0} != 'r') {
throw new Exception('Mode ' . $mode . ' is not supported. Only read mode is supported.');
}
$pos = strrpos($path, '#');
$url['host'] = substr($path, 6, $pos - 6); // 6: strlen('zip://')
$url['fragment'] = substr($path, $pos + 1);
// Open archive
$this->_archive = new ZipArchive();
$this->_archive->open($url['host']);
$this->_fileNameInArchive = $url['fragment'];
$this->_position = 0;
$this->_data = $this->_archive->getFromName( $this->_fileNameInArchive );
return true;
}
/**
* Stat stream
*/
public function stream_stat() {
return $this->_archive->statName( $this->_fileNameInArchive );
}
/**
* Read stream
*/
function stream_read($count) {
$ret = substr($this->_data, $this->_position, $count);
$this->_position += strlen($ret);
return $ret;
}
/**
* Tell stream
*/
public function stream_tell() {
return $this->_position;
}
/**
* EOF stream
*/
public function stream_eof() {
return $this->_position >= strlen($this->_data);
}
/**
* Seek stream
*/
public function stream_seek($offset, $whence) {
switch ($whence) {
case SEEK_SET:
if ($offset < strlen($this->_data) && $offset >= 0) {
$this->_position = $offset;
return true;
} else {
return false;
}
break;
case SEEK_CUR:
if ($offset >= 0) {
$this->_position += $offset;
return true;
} else {
return false;
}
break;
case SEEK_END:
if (strlen($this->_data) + $offset >= 0) {
$this->_position = strlen($this->_data) + $offset;
return true;
} else {
return false;
}
break;
default:
return false;
}
}
}

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Best_Fit
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
@@ -31,7 +31,7 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Best_Fit
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Best_Fit
{

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Best_Fit
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
@@ -34,7 +34,7 @@ require_once(PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php');
*
* @category PHPExcel
* @package PHPExcel_Shared_Best_Fit
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Exponential_Best_Fit extends PHPExcel_Best_Fit
{

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Best_Fit
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
@@ -34,7 +34,7 @@ require_once(PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php');
*
* @category PHPExcel
* @package PHPExcel_Shared_Best_Fit
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Linear_Best_Fit extends PHPExcel_Best_Fit
{

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Best_Fit
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
@@ -34,7 +34,7 @@ require_once(PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php');
*
* @category PHPExcel
* @package PHPExcel_Shared_Best_Fit
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Logarithmic_Best_Fit extends PHPExcel_Best_Fit
{

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Best_Fit
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
@@ -35,7 +35,7 @@ require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/JAMA/Matrix.php';
*
* @category PHPExcel
* @package PHPExcel_Shared_Best_Fit
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Polynomial_Best_Fit extends PHPExcel_Best_Fit
{

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Shared_Best_Fit
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
@@ -34,7 +34,7 @@ require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php';
*
* @category PHPExcel
* @package PHPExcel_Shared_Best_Fit
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Power_Best_Fit extends PHPExcel_Best_Fit
{

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Style
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/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 1.7.4, 2010-08-26
* @version 1.7.6, 2011-02-27
*/
@@ -31,7 +31,7 @@
*
* @category PHPExcel
* @package PHPExcel_Style
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Style implements PHPExcel_IComparable
{
@@ -169,14 +169,12 @@ class PHPExcel_Style implements PHPExcel_IComparable
$selectedCell = $this->getActiveCell(); // e.g. 'A1'
if ($activeSheet->cellExists($selectedCell)) {
$cell = $activeSheet->getCell($selectedCell);
$xfIndex = $cell->getXfIndex();
$xfIndex = $activeSheet->getCell($selectedCell)->getXfIndex();
} else {
$xfIndex = 0;
}
$activeStyle = $this->_parent->getCellXfByIndex($xfIndex);
return $activeStyle;
return $this->_parent->getCellXfByIndex($xfIndex);
}
/**
@@ -270,8 +268,6 @@ class PHPExcel_Style implements PHPExcel_IComparable
$pRange = strtoupper($pRange);
// Is it a cell range or a single cell?
$rangeA = '';
$rangeB = '';
if (strpos($pRange, ':') === false) {
$rangeA = $pRange;
$rangeB = $pRange;
@@ -610,9 +606,7 @@ class PHPExcel_Style implements PHPExcel_IComparable
*/
public function setConditionalStyles($pValue = null) {
if (is_array($pValue)) {
foreach (PHPExcel_Cell::extractAllCellReferencesInRange($this->getSelectedCells()) as $cellReference) {
$this->getActiveSheet()->setConditionalStyles($cellReference, $pValue);
}
$this->getActiveSheet()->setConditionalStyles($this->getSelectedCells(), $pValue);
}
return $this;
}
@@ -638,13 +632,13 @@ class PHPExcel_Style implements PHPExcel_IComparable
}
return md5(
$this->getFill()->getHashCode()
. $this->getFont()->getHashCode()
. $this->getBorders()->getHashCode()
. $this->getAlignment()->getHashCode()
. $this->getNumberFormat()->getHashCode()
$this->_fill->getHashCode()
. $this->_font->getHashCode()
. $this->_borders->getHashCode()
. $this->_alignment->getHashCode()
. $this->_numberFormat->getHashCode()
. $hashConditionals
. $this->getProtection()->getHashCode()
. $this->_protection->getHashCode()
. __CLASS__
);
}

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -19,10 +19,10 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel_Style
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.4, 2010-08-26
* @package PHPExcel_Style
* @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 1.7.6, 2011-02-27
*/
@@ -30,8 +30,8 @@
* PHPExcel_Style_Alignment
*
* @category PHPExcel
* @package PHPExcel_Style
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @package PHPExcel_Style
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Style_Alignment implements PHPExcel_IComparable
{
@@ -54,42 +54,42 @@ class PHPExcel_Style_Alignment implements PHPExcel_IComparable
*
* @var string
*/
private $_horizontal;
private $_horizontal = PHPExcel_Style_Alignment::HORIZONTAL_GENERAL;
/**
* Vertical
*
* @var string
*/
private $_vertical;
private $_vertical = PHPExcel_Style_Alignment::VERTICAL_BOTTOM;
/**
* Text rotation
*
* @var int
*/
private $_textRotation;
private $_textRotation = 0;
/**
* Wrap text
*
* @var boolean
*/
private $_wrapText;
private $_wrapText = false;
/**
* Shrink to fit
*
* @var boolean
*/
private $_shrinkToFit;
private $_shrinkToFit = false;
/**
* Indent - only possible with horizontal alignment left and right
*
* @var int
*/
private $_indent;
private $_indent = 0;
/**
* Parent Borders
@@ -112,22 +112,14 @@ class PHPExcel_Style_Alignment implements PHPExcel_IComparable
*/
private $_parent;
/**
* Create a new PHPExcel_Style_Alignment
*/
public function __construct($isSupervisor = false)
{
// Supervisor?
/**
* Create a new PHPExcel_Style_Alignment
*/
public function __construct($isSupervisor = false)
{
// Supervisor?
$this->_isSupervisor = $isSupervisor;
// Initialise values
$this->_horizontal = PHPExcel_Style_Alignment::HORIZONTAL_GENERAL;
$this->_vertical = PHPExcel_Style_Alignment::VERTICAL_BOTTOM;
$this->_textRotation = 0;
$this->_wrapText = false;
$this->_shrinkToFit = false;
$this->_indent = 0;
}
}
/**
* Bind parent. Only used for supervisor
@@ -205,24 +197,24 @@ class PHPExcel_Style_Alignment implements PHPExcel_IComparable
return array('alignment' => $array);
}
/**
* Apply styles from array
*
* <code>
* $objPHPExcel->getActiveSheet()->getStyle('B2')->getAlignment()->applyFromArray(
* array(
* 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
* 'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
* 'rotation' => 0,
* 'wrap' => true
* )
* );
* </code>
*
* @param array $pStyles Array containing style information
* @throws Exception
* @return PHPExcel_Style_Alignment
*/
/**
* Apply styles from array
*
* <code>
* $objPHPExcel->getActiveSheet()->getStyle('B2')->getAlignment()->applyFromArray(
* array(
* 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
* 'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
* 'rotation' => 0,
* 'wrap' => true
* )
* );
* </code>
*
* @param array $pStyles Array containing style information
* @throws Exception
* @return PHPExcel_Style_Alignment
*/
public function applyFromArray($pStyles = null) {
if (is_array($pStyles)) {
if ($this->_isSupervisor) {
@@ -253,28 +245,28 @@ class PHPExcel_Style_Alignment implements PHPExcel_IComparable
return $this;
}
/**
* Get Horizontal
*
* @return string
*/
public function getHorizontal() {
/**
* Get Horizontal
*
* @return string
*/
public function getHorizontal() {
if ($this->_isSupervisor) {
return $this->getSharedComponent()->getHorizontal();
}
return $this->_horizontal;
}
return $this->_horizontal;
}
/**
* Set Horizontal
*
* @param string $pValue
* @return PHPExcel_Style_Alignment
*/
public function setHorizontal($pValue = PHPExcel_Style_Alignment::HORIZONTAL_GENERAL) {
if ($pValue == '') {
$pValue = PHPExcel_Style_Alignment::HORIZONTAL_GENERAL;
}
/**
* Set Horizontal
*
* @param string $pValue
* @return PHPExcel_Style_Alignment
*/
public function setHorizontal($pValue = PHPExcel_Style_Alignment::HORIZONTAL_GENERAL) {
if ($pValue == '') {
$pValue = PHPExcel_Style_Alignment::HORIZONTAL_GENERAL;
}
if ($this->_isSupervisor) {
$styleArray = $this->getStyleArray(array('horizontal' => $pValue));
@@ -284,30 +276,30 @@ class PHPExcel_Style_Alignment implements PHPExcel_IComparable
$this->_horizontal = $pValue;
}
return $this;
}
}
/**
* Get Vertical
*
* @return string
*/
public function getVertical() {
/**
* Get Vertical
*
* @return string
*/
public function getVertical() {
if ($this->_isSupervisor) {
return $this->getSharedComponent()->getVertical();
}
return $this->_vertical;
}
return $this->_vertical;
}
/**
* Set Vertical
*
* @param string $pValue
* @return PHPExcel_Style_Alignment
*/
public function setVertical($pValue = PHPExcel_Style_Alignment::VERTICAL_BOTTOM) {
if ($pValue == '') {
$pValue = PHPExcel_Style_Alignment::VERTICAL_BOTTOM;
}
/**
* Set Vertical
*
* @param string $pValue
* @return PHPExcel_Style_Alignment
*/
public function setVertical($pValue = PHPExcel_Style_Alignment::VERTICAL_BOTTOM) {
if ($pValue == '') {
$pValue = PHPExcel_Style_Alignment::VERTICAL_BOTTOM;
}
if ($this->_isSupervisor) {
$styleArray = $this->getStyleArray(array('vertical' => $pValue));
@@ -316,70 +308,70 @@ class PHPExcel_Style_Alignment implements PHPExcel_IComparable
$this->_vertical = $pValue;
}
return $this;
}
}
/**
* Get TextRotation
*
* @return int
*/
public function getTextRotation() {
/**
* Get TextRotation
*
* @return int
*/
public function getTextRotation() {
if ($this->_isSupervisor) {
return $this->getSharedComponent()->getTextRotation();
}
return $this->_textRotation;
}
return $this->_textRotation;
}
/**
* Set TextRotation
*
* @param int $pValue
* @throws Exception
* @return PHPExcel_Style_Alignment
*/
public function setTextRotation($pValue = 0) {
/**
* Set TextRotation
*
* @param int $pValue
* @throws Exception
* @return PHPExcel_Style_Alignment
*/
public function setTextRotation($pValue = 0) {
// Excel2007 value 255 => PHPExcel value -165
if ($pValue == 255) {
$pValue = -165;
}
if ($pValue == 255) {
$pValue = -165;
}
// Set rotation
if ( ($pValue >= -90 && $pValue <= 90) || $pValue == -165 ) {
if ( ($pValue >= -90 && $pValue <= 90) || $pValue == -165 ) {
if ($this->_isSupervisor) {
$styleArray = $this->getStyleArray(array('rotation' => $pValue));
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
} else {
$this->_textRotation = $pValue;
}
} else {
throw new Exception("Text rotation should be a value between -90 and 90.");
}
} else {
throw new Exception("Text rotation should be a value between -90 and 90.");
}
return $this;
}
return $this;
}
/**
* Get Wrap Text
*
* @return boolean
*/
public function getWrapText() {
/**
* Get Wrap Text
*
* @return boolean
*/
public function getWrapText() {
if ($this->_isSupervisor) {
return $this->getSharedComponent()->getWrapText();
}
return $this->_wrapText;
}
return $this->_wrapText;
}
/**
* Set Wrap Text
*
* @param boolean $pValue
* @return PHPExcel_Style_Alignment
*/
public function setWrapText($pValue = false) {
if ($pValue == '') {
$pValue = false;
}
/**
* Set Wrap Text
*
* @param boolean $pValue
* @return PHPExcel_Style_Alignment
*/
public function setWrapText($pValue = false) {
if ($pValue == '') {
$pValue = false;
}
if ($this->_isSupervisor) {
$styleArray = $this->getStyleArray(array('wrap' => $pValue));
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
@@ -387,30 +379,30 @@ class PHPExcel_Style_Alignment implements PHPExcel_IComparable
$this->_wrapText = $pValue;
}
return $this;
}
}
/**
* Get Shrink to fit
*
* @return boolean
*/
public function getShrinkToFit() {
/**
* Get Shrink to fit
*
* @return boolean
*/
public function getShrinkToFit() {
if ($this->_isSupervisor) {
return $this->getSharedComponent()->getShrinkToFit();
}
return $this->_shrinkToFit;
}
return $this->_shrinkToFit;
}
/**
* Set Shrink to fit
*
* @param boolean $pValue
* @return PHPExcel_Style_Alignment
*/
public function setShrinkToFit($pValue = false) {
if ($pValue == '') {
$pValue = false;
}
/**
* Set Shrink to fit
*
* @param boolean $pValue
* @return PHPExcel_Style_Alignment
*/
public function setShrinkToFit($pValue = false) {
if ($pValue == '') {
$pValue = false;
}
if ($this->_isSupervisor) {
$styleArray = $this->getStyleArray(array('shrinkToFit' => $pValue));
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
@@ -418,27 +410,27 @@ class PHPExcel_Style_Alignment implements PHPExcel_IComparable
$this->_shrinkToFit = $pValue;
}
return $this;
}
}
/**
* Get indent
*
* @return int
*/
public function getIndent() {
/**
* Get indent
*
* @return int
*/
public function getIndent() {
if ($this->_isSupervisor) {
return $this->getSharedComponent()->getIndent();
}
return $this->_indent;
}
return $this->_indent;
}
/**
* Set indent
*
* @param int $pValue
* @return PHPExcel_Style_Alignment
*/
public function setIndent($pValue = 0) {
/**
* Set indent
*
* @param int $pValue
* @return PHPExcel_Style_Alignment
*/
public function setIndent($pValue = 0) {
if ($pValue > 0) {
if ($this->getHorizontal() != self::HORIZONTAL_GENERAL && $this->getHorizontal() != self::HORIZONTAL_LEFT && $this->getHorizontal() != self::HORIZONTAL_RIGHT) {
$pValue = 0; // indent not supported
@@ -451,7 +443,7 @@ class PHPExcel_Style_Alignment implements PHPExcel_IComparable
$this->_indent = $pValue;
}
return $this;
}
}
/**
* Get hash code
@@ -462,16 +454,16 @@ class PHPExcel_Style_Alignment implements PHPExcel_IComparable
if ($this->_isSupervisor) {
return $this->getSharedComponent()->getHashCode();
}
return md5(
$this->_horizontal
. $this->_vertical
. $this->_textRotation
. ($this->_wrapText ? 't' : 'f')
. ($this->_shrinkToFit ? 't' : 'f')
return md5(
$this->_horizontal
. $this->_vertical
. $this->_textRotation
. ($this->_wrapText ? 't' : 'f')
. ($this->_shrinkToFit ? 't' : 'f')
. $this->_indent
. __CLASS__
);
}
. __CLASS__
);
}
/**
* Implement PHP __clone to create a deep clone, not just a shallow copy.

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2010 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
@@ -19,10 +19,10 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel_Style
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.4, 2010-08-26
* @package PHPExcel_Style
* @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 1.7.6, 2011-02-27
*/
@@ -30,8 +30,8 @@
* PHPExcel_Style_Border
*
* @category PHPExcel
* @package PHPExcel_Style
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
* @package PHPExcel_Style
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Style_Border implements PHPExcel_IComparable
{
@@ -56,7 +56,7 @@ class PHPExcel_Style_Border implements PHPExcel_IComparable
*
* @var string
*/
private $_borderStyle;
private $_borderStyle = PHPExcel_Style_Border::BORDER_NONE;
/**
* Border color
@@ -86,23 +86,22 @@ class PHPExcel_Style_Border implements PHPExcel_IComparable
*/
private $_parentPropertyName;
/**
* Create a new PHPExcel_Style_Border
*/
public function __construct($isSupervisor = false)
{
// Supervisor?
/**
* Create a new PHPExcel_Style_Border
*/
public function __construct($isSupervisor = false)
{
// Supervisor?
$this->_isSupervisor = $isSupervisor;
// Initialise values
$this->_borderStyle = PHPExcel_Style_Border::BORDER_NONE;
// Initialise values
$this->_color = new PHPExcel_Style_Color(PHPExcel_Style_Color::COLOR_BLACK, $isSupervisor);
// bind parent if we are a supervisor
if ($isSupervisor) {
$this->_color->bindParent($this, '_color');
}
}
}
/**
* Bind parent. Only used for supervisor
@@ -253,24 +252,24 @@ class PHPExcel_Style_Border implements PHPExcel_IComparable
return $this->_parent->getStyleArray(array($key => $array));
}
/**
* Apply styles from array
*
* <code>
* $objPHPExcel->getActiveSheet()->getStyle('B2')->getBorders()->getTop()->applyFromArray(
* array(
* 'style' => PHPExcel_Style_Border::BORDER_DASHDOT,
* 'color' => array(
* 'rgb' => '808080'
* )
* )
* );
* </code>
*
* @param array $pStyles Array containing style information
* @throws Exception
* @return PHPExcel_Style_Border
*/
/**
* Apply styles from array
*
* <code>
* $objPHPExcel->getActiveSheet()->getStyle('B2')->getBorders()->getTop()->applyFromArray(
* array(
* 'style' => PHPExcel_Style_Border::BORDER_DASHDOT,
* 'color' => array(
* 'rgb' => '808080'
* )
* )
* );
* </code>
*
* @param array $pStyles Array containing style information
* @throws Exception
* @return PHPExcel_Style_Border
*/
public function applyFromArray($pStyles = null) {
if (is_array($pStyles)) {
if ($this->_isSupervisor) {
@@ -289,29 +288,29 @@ class PHPExcel_Style_Border implements PHPExcel_IComparable
return $this;
}
/**
* Get Border style
*
* @return string
*/
public function getBorderStyle() {
/**
* Get Border style
*
* @return string
*/
public function getBorderStyle() {
if ($this->_isSupervisor) {
return $this->getSharedComponent()->getBorderStyle();
}
return $this->_borderStyle;
}
return $this->_borderStyle;
}
/**
* Set Border style
*
* @param string $pValue
* @return PHPExcel_Style_Border
*/
public function setBorderStyle($pValue = PHPExcel_Style_Border::BORDER_NONE) {
/**
* Set Border style
*
* @param string $pValue
* @return PHPExcel_Style_Border
*/
public function setBorderStyle($pValue = PHPExcel_Style_Border::BORDER_NONE) {
if ($pValue == '') {
$pValue = PHPExcel_Style_Border::BORDER_NONE;
}
if ($pValue == '') {
$pValue = PHPExcel_Style_Border::BORDER_NONE;
}
if ($this->_isSupervisor) {
$styleArray = $this->getStyleArray(array('style' => $pValue));
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
@@ -319,25 +318,25 @@ class PHPExcel_Style_Border implements PHPExcel_IComparable
$this->_borderStyle = $pValue;
}
return $this;
}
}
/**
* Get Border Color
*
* @return PHPExcel_Style_Color
*/
public function getColor() {
return $this->_color;
}
/**
* Get Border Color
*
* @return PHPExcel_Style_Color
*/
public function getColor() {
return $this->_color;
}
/**
* Set Border Color
*
* @param PHPExcel_Style_Color $pValue
* @throws Exception
* @return PHPExcel_Style_Border
*/
public function setColor(PHPExcel_Style_Color $pValue = null) {
/**
* Set Border Color
*
* @param PHPExcel_Style_Color $pValue
* @throws Exception
* @return PHPExcel_Style_Border
*/
public function setColor(PHPExcel_Style_Color $pValue = null) {
// make sure parameter is a real color and not a supervisor
$color = $pValue->getIsSupervisor() ? $pValue->getSharedComponent() : $pValue;
@@ -348,7 +347,7 @@ class PHPExcel_Style_Border implements PHPExcel_IComparable
$this->_color = $color;
}
return $this;
}
}
/**
* Get hash code
@@ -359,12 +358,12 @@ class PHPExcel_Style_Border implements PHPExcel_IComparable
if ($this->_isSupervisor) {
return $this->getSharedComponent()->getHashCode();
}
return md5(
$this->_borderStyle
. $this->_color->getHashCode()
. __CLASS__
);
}
return md5(
$this->_borderStyle
. $this->_color->getHashCode()
. __CLASS__
);
}
/**
* Implement PHP __clone to create a deep clone, not just a shallow copy.

Some files were not shown because too many files have changed in this diff Show More