merge with master

This commit is contained in:
Dieter Adriaenssens
2010-06-03 21:21:34 +02:00
143 changed files with 19046 additions and 11703 deletions

View File

@@ -83,6 +83,7 @@ $Id$
+ [core] Include Content Security Policy HTTP headers. + [core] Include Content Security Policy HTTP headers.
- bug #3004216 [CSS] Field attributes use inline CSS - bug #3004216 [CSS] Field attributes use inline CSS
- patch #2999595, rfe #2998130 [interface] Cleanup navigation frame. - patch #2999595, rfe #2998130 [interface] Cleanup navigation frame.
- [core] Update library PHPExcel to version 1.7.3c
3.3.4.0 (not yet released) 3.3.4.0 (not yet released)
- bug #2996161 [import] properly escape import value - bug #2996161 [import] properly escape import value

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,37 +20,23 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel * @package PHPExcel
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
/** PHPExcel root directory */ /** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) { if (!defined('PHPEXCEL_ROOT')) {
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/'); 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_Cell */
require_once PHPEXCEL_ROOT . 'PHPExcel/Cell.php';
/** PHPExcel_DocumentProperties */
require_once PHPEXCEL_ROOT . 'PHPExcel/DocumentProperties.php';
/** PHPExcel_DocumentSecurity */
require_once PHPEXCEL_ROOT . 'PHPExcel/DocumentSecurity.php';
/** PHPExcel_Worksheet */
require_once PHPEXCEL_ROOT . 'PHPExcel/Worksheet.php';
/** PHPExcel_Shared_ZipStreamWrapper */
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/ZipStreamWrapper.php';
/** PHPExcel_NamedRange */
require_once PHPEXCEL_ROOT . 'PHPExcel/NamedRange.php';
/** PHPExcel_WorksheetIterator */
require_once PHPEXCEL_ROOT . 'PHPExcel/WorksheetIterator.php';
/** /**
@@ -58,7 +44,7 @@ require_once PHPEXCEL_ROOT . 'PHPExcel/WorksheetIterator.php';
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel * @package PHPExcel
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel class PHPExcel
{ {
@@ -146,6 +132,16 @@ class PHPExcel
$this->addCellStyleXf(new PHPExcel_Style); $this->addCellStyleXf(new PHPExcel_Style);
} }
public function disconnectWorksheets() {
foreach($this->_workSheetCollection as $k => &$worksheet) {
$worksheet->disconnectCells();
$this->_workSheetCollection[$k] = null;
}
unset($worksheet);
$this->_workSheetCollection = array();
}
/** /**
* Get properties * Get properties
* *
@@ -212,6 +208,8 @@ class PHPExcel
* Add sheet * Add sheet
* *
* @param PHPExcel_Worksheet $pSheet * @param PHPExcel_Worksheet $pSheet
* @param int|null $iSheetIndex Index where sheet should go (0,1,..., or null for last)
* @return PHPExcel_Worksheet
* @throws Exception * @throws Exception
*/ */
public function addSheet(PHPExcel_Worksheet $pSheet = null, $iSheetIndex = null) public function addSheet(PHPExcel_Worksheet $pSheet = null, $iSheetIndex = null)
@@ -229,7 +227,14 @@ class PHPExcel
0, 0,
array($pSheet) array($pSheet)
); );
// Adjust active sheet index if necessary
if ($this->_activeSheetIndex >= $iSheetIndex) {
++$this->_activeSheetIndex;
} }
}
return $pSheet;
} }
/** /**
@@ -370,6 +375,23 @@ class PHPExcel
return $this->getActiveSheet(); return $this->getActiveSheet();
} }
/**
* Set active sheet index by name
*
* @param string $pValue Sheet title
* @return PHPExcel_Worksheet
* @throws Exception
*/
public function setActiveSheetIndexByName($pValue = '')
{
if (($worksheet = $this->getSheetByName($pValue)) instanceof PHPExcel_Worksheet) {
$this->setActiveSheetIndex($worksheet->getParent()->getIndex($worksheet));
return $worksheet;
}
throw new Exception('Workbook does not contain sheet:' . $pValue);
}
/** /**
* Get sheet names * Get sheet names
* *
@@ -390,10 +412,11 @@ class PHPExcel
* Add external sheet * Add external sheet
* *
* @param PHPExcel_Worksheet $pSheet External sheet to add * @param PHPExcel_Worksheet $pSheet External sheet to add
* @param int|null $iSheetIndex Index where sheet should go (0,1,..., or null for last)
* @throws Exception * @throws Exception
* @return PHPExcel_Worksheet * @return PHPExcel_Worksheet
*/ */
public function addExternalSheet(PHPExcel_Worksheet $pSheet) { public function addExternalSheet(PHPExcel_Worksheet $pSheet, $iSheetIndex = null) {
if (!is_null($this->getSheetByName($pSheet->getTitle()))) { if (!is_null($this->getSheetByName($pSheet->getTitle()))) {
throw new Exception("Workbook already contains a worksheet named '{$pSheet->getTitle()}'. Rename the external sheet first."); throw new Exception("Workbook already contains a worksheet named '{$pSheet->getTitle()}'. Rename the external sheet first.");
} }
@@ -410,11 +433,12 @@ class PHPExcel
$pSheet->rebindParent($this); $pSheet->rebindParent($this);
// update the cellXfs // update the cellXfs
foreach ($pSheet->getCellCollection(false) as $cell) { foreach ($pSheet->getCellCollection(false) as $cellID) {
$cell = $sheet->getCell($cellID);
$cell->setXfIndex( $cell->getXfIndex() + $countCellXfs ); $cell->setXfIndex( $cell->getXfIndex() + $countCellXfs );
} }
return $this->addSheet($pSheet); return $this->addSheet($pSheet, $iSheetIndex);
} }
/** /**
@@ -433,7 +457,13 @@ class PHPExcel
* @return PHPExcel * @return PHPExcel
*/ */
public function addNamedRange(PHPExcel_NamedRange $namedRange) { public function addNamedRange(PHPExcel_NamedRange $namedRange) {
$this->_namedRanges[$namedRange->getWorksheet()->getTitle().'!'.$namedRange->getName()] = $namedRange; if ($namedRange->getScope() == null) {
// global scope
$this->_namedRanges[$namedRange->getName()] = $namedRange;
} else {
// local scope
$this->_namedRanges[$namedRange->getScope()->getTitle().'!'.$namedRange->getName()] = $namedRange;
}
return true; return true;
} }
@@ -441,57 +471,42 @@ class PHPExcel
* Get named range * Get named range
* *
* @param string $namedRange * @param string $namedRange
* @param PHPExcel_Worksheet|null $pSheet Scope. Use null for global scope
* @return PHPExcel_NamedRange|null
*/ */
public function getNamedRange($namedRange, PHPExcel_Worksheet $pSheet = null) { public function getNamedRange($namedRange, PHPExcel_Worksheet $pSheet = null) {
$returnValue = null;
if ($namedRange != '' && !is_null($namedRange)) { if ($namedRange != '' && !is_null($namedRange)) {
if (!is_null($pSheet)) { // first look for global defined name
$key = $pSheet->getTitle().'!'.$namedRange; if (isset($this->_namedRanges[$namedRange])) {
if (isset($this->_namedRanges[$key])) { $returnValue = $this->_namedRanges[$namedRange];
return $this->_namedRanges[$key];
} }
}
$returnCount = 0; // then look for local defined name (has priority over global defined name if both names exist)
foreach($this->_namedRanges as $_namedRange) { if (!is_null($pSheet) && isset($this->_namedRanges[$pSheet->getTitle() . '!' . $namedRange])) {
if ($_namedRange->getName() == $namedRange) { $returnValue = $this->_namedRanges[$pSheet->getTitle() . '!' . $namedRange];
if ((!is_null($pSheet)) && ($_namedRange->getWorksheet()->getTitle() == $pSheet->getTitle())) {
return $_namedRange;
} else {
$returnCount++;
$returnValue = $_namedRange;
}
}
}
if ($returnCount == 1) {
return $returnValue;
} }
} }
return null; return $returnValue;
} }
/** /**
* Remove named range * Remove named range
* *
* @param string $namedRange * @param string $namedRange
* @param PHPExcel_Worksheet|null $pSheet. Scope. Use null for global scope.
* @return PHPExcel * @return PHPExcel
*/ */
public function removeNamedRange($namedRange, PHPExcel_Worksheet $pSheet = null) { public function removeNamedRange($namedRange, PHPExcel_Worksheet $pSheet = null) {
if ($namedRange != '' && !is_null($namedRange)) { if (is_null($pSheet)) {
if (!is_null($pSheet)) { if (isset($this->_namedRanges[$namedRange])) {
$key = $pSheet->getTitle().'!'.$namedRange; unset($this->_namedRanges[$namedRange]);
if (isset($this->_namedRanges[$key])) {
unset($this->_namedRanges[$key]);
}
}
foreach($this->_namedRanges as $_namedRange) {
if ($_namedRange->getName() == $namedRange) {
if ((!is_null($pSheet)) && ($_namedRange->getWorksheet()->getTitle() == $pSheet->getTitle())) {
$key = $pSheet->getTitle().'!'.$namedRange;
if (isset($this->_namedRanges[$key])) {
unset($this->_namedRanges[$key]);
}
}
} }
} else {
if (isset($this->_namedRanges[$pSheet->getTitle() . '!' . $namedRange])) {
unset($this->_namedRanges[$pSheet->getTitle() . '!' . $namedRange]);
} }
} }
return $this; return $this;
@@ -612,7 +627,8 @@ class PHPExcel
// then update cellXf indexes for cells // then update cellXf indexes for cells
foreach ($this->_workSheetCollection as $worksheet) { foreach ($this->_workSheetCollection as $worksheet) {
foreach ($worksheet->getCellCollection(false) as $cell) { foreach ($worksheet->getCellCollection(false) as $cellID) {
$cell = $sheet->getCell($cellID);
$xfIndex = $cell->getXfIndex(); $xfIndex = $cell->getXfIndex();
if ($xfIndex > $pIndex ) { if ($xfIndex > $pIndex ) {
// decrease xf index by 1 // decrease xf index by 1
@@ -700,7 +716,8 @@ class PHPExcel
} }
/** /**
* Eliminate all unneeded cellXf and afterwards update the xfIndex for all cells in the workbook * Eliminate all unneeded cellXf and afterwards update the xfIndex for all cells
* and columns in the workbook
*/ */
public function garbageCollect() public function garbageCollect()
{ {
@@ -711,12 +728,28 @@ class PHPExcel
} }
foreach ($this->getWorksheetIterator() as $sheet) { foreach ($this->getWorksheetIterator() as $sheet) {
foreach ($sheet->getCellCollection(false) as $cell) {
// from cells
foreach ($sheet->getCellCollection(false) as $cellID) {
$cell = $sheet->getCell($cellID);
++$countReferencesCellXf[$cell->getXfIndex()]; ++$countReferencesCellXf[$cell->getXfIndex()];
} }
// from row dimensions
foreach ($sheet->getRowDimensions() as $rowDimension) {
if ($rowDimension->getXfIndex() !== null) {
++$countReferencesCellXf[$rowDimension->getXfIndex()];
}
} }
// remove those cellXfs that have zero references and create mapping so we can update xfIndex for all cells // from column dimensions
foreach ($sheet->getColumnDimensions() as $columnDimension) {
++$countReferencesCellXf[$columnDimension->getXfIndex()];
}
}
// remove cellXfs without references and create mapping so we can update xfIndex
// for all cells and columns
$countNeededCellXfs = 0; $countNeededCellXfs = 0;
foreach ($this->_cellXfCollection as $index => $cellXf) { foreach ($this->_cellXfCollection as $index => $cellXf) {
if ($countReferencesCellXf[$index] > 0 || $index == 0) { // we must never remove the first cellXf if ($countReferencesCellXf[$index] > 0 || $index == 0) { // we must never remove the first cellXf
@@ -728,16 +761,36 @@ class PHPExcel
} }
$this->_cellXfCollection = array_values($this->_cellXfCollection); $this->_cellXfCollection = array_values($this->_cellXfCollection);
// if we removed the first style by accident, recreate it // update the index for all cellXfs
foreach ($this->_cellXfCollection as $i => $cellXf) {
$cellXf->setIndex($i);
}
// make sure there is always at least one cellXf (there should be)
if (count($this->_cellXfCollection) == 0) { if (count($this->_cellXfCollection) == 0) {
$this->_cellXfCollection[] = new PHPExcel_Style(); $this->_cellXfCollection[] = new PHPExcel_Style();
} }
// update the xfIndex for all cells // update the xfIndex for all cells, row dimensions, column dimensions
foreach ($this->getWorksheetIterator() as $sheet) { foreach ($this->getWorksheetIterator() as $sheet) {
foreach ($sheet->getCellCollection(false) as $cell) {
// for all cells
foreach ($sheet->getCellCollection(false) as $cellID) {
$cell = $sheet->getCell($cellID);
$cell->setXfIndex( $map[$cell->getXfIndex()] ); $cell->setXfIndex( $map[$cell->getXfIndex()] );
} }
// for all row dimensions
foreach ($sheet->getRowDimensions() as $rowDimension) {
if ($rowDimension->getXfIndex() !== null) {
$rowDimension->setXfIndex( $map[$rowDimension->getXfIndex()] );
}
}
// for all column dimensions
foreach ($sheet->getColumnDimensions() as $columnDimension) {
$columnDimension->setXfIndex( $map[$columnDimension->getXfIndex()] );
}
} }
// also do garbage collection for all the sheets // also do garbage collection for all the sheets

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -19,21 +19,33 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared * @package PHPExcel
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
class PHPExcel_Autoloader
{
public static function Register() {
return spl_autoload_register(array('PHPExcel_Autoloader', 'Load'));
} // function Register()
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) { public static function Load($pObjectName){
/** if ((class_exists($pObjectName)) || (strpos($pObjectName, 'PHPExcel') === False)) {
* @ignore return false;
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
} }
/** Require FPDF library */ $pObjectFilePath = PHPEXCEL_ROOT.
$k_path_url = dirname(__FILE__) . '/PDF'; str_replace('_',DIRECTORY_SEPARATOR,$pObjectName).
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/PDF/tcpdf.php'; '.php';
if ((file_exists($pObjectFilePath) === false) || (is_readable($pObjectFilePath) === false)) {
return false;
}
require($pObjectFilePath);
} // function Load()
}

View File

@@ -0,0 +1,193 @@
<?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_CachedObjectStorage
* @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.3c, 2010-06-01
*/
/**
* PHPExcel_CachedObjectStorage_APC
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_CachedObjectStorage_APC extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {
private $_cachePrefix = null;
private $_cacheTime = 600;
private function _storeData() {
$this->_currentObject->detach();
if (!apc_store($this->_cachePrefix.$this->_currentObjectID.'.cache',serialize($this->_currentObject),$this->_cacheTime)) {
$this->__destruct();
throw new Exception('Failed to store cell in APC');
}
$this->_currentObjectID = $this->_currentObject = null;
} // function _storeData()
/**
* Add or Update a cell in cache identified by coordinate address
*
* @param string $pCoord Coordinate address of the cell to update
* @param PHPExcel_Cell $cell Cell to update
* @return void
* @throws Exception
*/
public function addCacheData($pCoord, PHPExcel_Cell $cell) {
if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) {
$this->_storeData();
}
$this->_cellCache[$pCoord] = true;
$this->_currentObjectID = $pCoord;
$this->_currentObject = $cell;
return $cell;
} // function addCacheData()
/**
* Is a value set in the current PHPExcel_CachedObjectStorage_ICache for an indexed cell?
*
* @param string $pCoord Coordinate address of the cell to check
* @return void
* @return boolean
*/
public function isDataSet($pCoord) {
// Check if the requested entry is the current object, or exists in the cache
if (parent::isDataSet($pCoord)) {
if ($this->_currentObjectID == $pCoord) {
return true;
}
// Check if the requested entry still exists in apc
$success = apc_fetch($this->_cachePrefix.$pCoord.'.cache');
if ($success === false) {
// Entry no longer exists in APC, so clear it from the cache array
parent::deleteCacheData($pCoord);
throw new Exception('Cell entry no longer exists in APC');
}
return true;
}
return false;
} // function isDataSet()
/**
* Get cell at a specific coordinate
*
* @param string $pCoord Coordinate of the cell
* @throws Exception
* @return PHPExcel_Cell Cell that was found, or null if not found
*/
public function getCacheData($pCoord) {
if ($pCoord === $this->_currentObjectID) {
return $this->_currentObject;
}
$this->_storeData();
// Check if the entry that has been requested actually exists
if (parent::isDataSet($pCoord)) {
$obj = apc_fetch($this->_cachePrefix.$pCoord.'.cache');
if ($obj === false) {
// Entry no longer exists in APC, so clear it from the cache array
parent::deleteCacheData($pCoord);
throw new Exception('Cell entry no longer exists in APC');
}
} else {
// Return null if requested entry doesn't exist in cache
return null;
}
// Set current entry to the requested entry
$this->_currentObjectID = $pCoord;
$this->_currentObject = unserialize($obj);
// Re-attach the parent worksheet
$this->_currentObject->attach($this->_parent);
// Return requested entry
return $this->_currentObject;
} // function getCacheData()
/**
* Delete a cell in cache identified by coordinate address
*
* @param string $pCoord Coordinate address of the cell to delete
* @throws Exception
*/
public function deleteCacheData($pCoord) {
// Delete the entry from APC
apc_delete($this->_cachePrefix.$pCoord.'.cache');
// Delete the entry from our cell address array
parent::deleteCacheData($pCoord);
} // function deleteCacheData()
public function unsetWorksheetCells() {
if(!is_null($this->_currentObject)) {
$this->_currentObject->detach();
$this->_currentObject = $this->_currentObjectID = null;
}
// Flush the APC cache
$this->__destruct();
$this->_cellCache = array();
// detach ourself from the worksheet, so that it can then delete this object successfully
$this->_parent = null;
} // function unsetWorksheetCells()
public function __construct(PHPExcel_Worksheet $parent, $arguments) {
$cacheTime = (isset($arguments['cacheTime'])) ? $arguments['cacheTime'] : 600;
if (is_null($this->_cachePrefix)) {
if (function_exists('posix_getpid')) {
$baseUnique = posix_getpid();
} else {
$baseUnique = mt_rand();
}
$this->_cachePrefix = substr(md5(uniqid($baseUnique,true)),0,8).'.';
$this->_cacheTime = $cacheTime;
parent::__construct($parent);
}
} // function __construct()
public function __destruct() {
$cacheList = $this->getCellList();
foreach($cacheList as $cellID) {
apc_delete($this->_cachePrefix.$cellID.'.cache');
}
} // function __destruct()
}

View File

@@ -0,0 +1,153 @@
<?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_CachedObjectStorage
* @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.3c, 2010-06-01
*/
/**
* PHPExcel_CachedObjectStorage_CacheBase
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_CachedObjectStorage_CacheBase {
/**
* Parent worksheet
*
* @var PHPExcel_Worksheet
*/
protected $_parent;
/**
* The currently active Cell
*
* @var PHPExcel_Cell
*/
protected $_currentObject = null;
/**
* Coordinate address of the currently active Cell
*
* @var string
*/
protected $_currentObjectID = null;
/**
* An array of cells or cell pointers for the worksheet cells held in this cache,
* and indexed by their coordinate address within the worksheet
*
* @var array of mixed
*/
protected $_cellCache = array();
public function __construct(PHPExcel_Worksheet $parent) {
// Set our parent worksheet.
// This is maintained within the cache controller to facilitate re-attaching it to PHPExcel_Cell objects when
// they are woken from a serialized state
$this->_parent = $parent;
} // function __construct()
/**
* Is a value set in the current PHPExcel_CachedObjectStorage_ICache for an indexed cell?
*
* @param string $pCoord Coordinate address of the cell to check
* @return void
* @return boolean
*/
public function isDataSet($pCoord) {
if ($pCoord === $this->_currentObjectID) {
return true;
}
// Check if the requested entry exists in the cache
return isset($this->_cellCache[$pCoord]);
} // function isDataSet()
/**
* Add or Update a cell in cache
*
* @param PHPExcel_Cell $cell Cell to update
* @return void
* @throws Exception
*/
public function updateCacheData(PHPExcel_Cell $cell) {
$pCoord = $cell->getCoordinate();
return $this->addCacheData($pCoord,$cell);
} // function updateCacheData()
/**
* Delete a cell in cache identified by coordinate address
*
* @param string $pCoord Coordinate address of the cell to delete
* @throws Exception
*/
public function deleteCacheData($pCoord) {
if ($pCoord === $this->_currentObjectID) {
$this->_currentObject->detach();
$this->_currentObjectID = $this->_currentObject = null;
}
if (isset($this->_cellCache[$pCoord])) {
$this->_cellCache[$pCoord]->detach();
unset($this->_cellCache[$pCoord]);
}
} // function deleteCacheData()
/**
* Get a list of all cell addresses currently held in cache
*
* @return array of string
*/
public function getCellList() {
return array_keys($this->_cellCache);
} // function getCellList()
/**
* Sort the list of all cell addresses currently held in cache by row and column
*
* @return void
*/
public function getSortedCellList() {
$sortKeys = array();
foreach ($this->_cellCache as $coord => $value) {
preg_match('/^(\w+)(\d+)$/U',$coord,$matches);
list(,$colNum,$rowNum) = $matches;
$sortKeys[$coord] = str_pad($rowNum . str_pad($colNum,3,'@',STR_PAD_LEFT),12,'0',STR_PAD_LEFT);
}
asort($sortKeys);
return array_keys($sortKeys);
} // function sortCellList()
}

View File

@@ -0,0 +1,143 @@
<?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_CachedObjectStorage
* @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.3c, 2010-06-01
*/
/**
* PHPExcel_CachedObjectStorage_DiscISAM
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_CachedObjectStorage_DiscISAM extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {
private $_fileName = null;
private $_fileHandle = null;
private function _storeData() {
$this->_currentObject->detach();
fseek($this->_fileHandle,0,SEEK_END);
$offset = ftell($this->_fileHandle);
fwrite($this->_fileHandle, serialize($this->_currentObject));
$this->_cellCache[$this->_currentObjectID] = array('ptr' => $offset,
'sz' => ftell($this->_fileHandle) - $offset
);
$this->_currentObjectID = $this->_currentObject = null;
} // function _storeData()
/**
* Add or Update a cell in cache identified by coordinate address
*
* @param string $pCoord Coordinate address of the cell to update
* @param PHPExcel_Cell $cell Cell to update
* @return void
* @throws Exception
*/
public function addCacheData($pCoord, PHPExcel_Cell $cell) {
if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) {
$this->_storeData();
}
$this->_currentObjectID = $pCoord;
$this->_currentObject = $cell;
return $cell;
} // function addCacheData()
/**
* Get cell at a specific coordinate
*
* @param string $pCoord Coordinate of the cell
* @throws Exception
* @return PHPExcel_Cell Cell that was found, or null if not found
*/
public function getCacheData($pCoord) {
if ($pCoord === $this->_currentObjectID) {
return $this->_currentObject;
}
$this->_storeData();
// Check if the entry that has been requested actually exists
if (!isset($this->_cellCache[$pCoord])) {
// Return null if requested entry doesn't exist in cache
return null;
}
// Set current entry to the requested entry
$this->_currentObjectID = $pCoord;
fseek($this->_fileHandle,$this->_cellCache[$pCoord]['ptr']);
$this->_currentObject = unserialize(fread($this->_fileHandle,$this->_cellCache[$pCoord]['sz']));
// Re-attach the parent worksheet
$this->_currentObject->attach($this->_parent);
// Return requested entry
return $this->_currentObject;
} // function getCacheData()
public function unsetWorksheetCells() {
if(!is_null($this->_currentObject)) {
$this->_currentObject->detach();
$this->_currentObject = $this->_currentObjectID = null;
}
$this->_cellCache = array();
// detach ourself from the worksheet, so that it can then delete this object successfully
$this->_parent = null;
// Close down the temporary cache file
$this->__destruct();
} // function unsetWorksheetCells()
public function __construct(PHPExcel_Worksheet $parent) {
parent::__construct($parent);
if (is_null($this->_fileHandle)) {
if (function_exists('posix_getpid')) {
$baseUnique = posix_getpid();
} else {
$baseUnique = mt_rand();
}
$this->_fileName = sys_get_temp_dir().'/PHPExcel.'.uniqid($baseUnique,true).'.cache';
$this->_fileHandle = fopen($this->_fileName,'a+');
}
} // function __construct()
public function __destruct() {
if (!is_null($this->_fileHandle)) {
fclose($this->_fileHandle);
unlink($this->_fileName);
}
$this->_fileHandle = null;
} // function __destruct()
}

View File

@@ -0,0 +1,97 @@
<?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_CachedObjectStorage
* @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.3c, 2010-06-01
*/
/**
* PHPExcel_CachedObjectStorage_ICache
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
interface PHPExcel_CachedObjectStorage_ICache
{
/**
* Add or Update a cell in cache identified by coordinate address
*
* @param string $pCoord Coordinate address of the cell to update
* @param PHPExcel_Cell $cell Cell to update
* @return void
* @throws Exception
*/
public function addCacheData($pCoord, PHPExcel_Cell $cell);
/**
* Add or Update a cell in cache
*
* @param PHPExcel_Cell $cell Cell to update
* @return void
* @throws Exception
*/
public function updateCacheData(PHPExcel_Cell $cell);
/**
* Fetch a cell from cache identified by coordinate address
*
* @param string $pCoord Coordinate address of the cell to retrieve
* @return PHPExcel_Cell Cell that was found, or null if not found
* @throws Exception
*/
public function getCacheData($pCoord);
/**
* Delete a cell in cache identified by coordinate address
*
* @param string $pCoord Coordinate address of the cell to delete
* @throws Exception
*/
public function deleteCacheData($pCoord);
/**
* Is a value set in the current PHPExcel_CachedObjectStorage_ICache for an indexed cell?
*
* @param string $pCoord Coordinate address of the cell to check
* @return void
* @return boolean
*/
public function isDataSet($pCoord);
/**
* Get a list of all cell addresses currently held in cache
*
* @return array of string
*/
public function getCellList();
/**
* Get the list of all cell addresses currently held in cache sorted by column and row
*
* @return void
*/
public function getSortedCellList();
}

View File

@@ -0,0 +1,214 @@
<?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_CachedObjectStorage
* @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.3c, 2010-06-01
*/
/**
* PHPExcel_CachedObjectStorage_Memcache
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_CachedObjectStorage_Memcache extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {
private $_cachePrefix = null;
private $_cacheTime = 600;
private $_memcache = null;
private function _storeData() {
$this->_currentObject->detach();
$obj = serialize($this->_currentObject);
if (!$this->_memcache->replace($this->_cachePrefix.$this->_currentObjectID.'.cache',$obj,NULL,$this->_cacheTime)) {
if (!$this->_memcache->add($this->_cachePrefix.$this->_currentObjectID.'.cache',$obj,NULL,$this->_cacheTime)) {
$this->__destruct();
throw new Exception('Failed to store cell in Memcache');
}
}
$this->_currentObjectID = $this->_currentObject = null;
} // function _storeData()
/**
* Add or Update a cell in cache identified by coordinate address
*
* @param string $pCoord Coordinate address of the cell to update
* @param PHPExcel_Cell $cell Cell to update
* @return void
* @throws Exception
*/
public function addCacheData($pCoord, PHPExcel_Cell $cell) {
if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) {
$this->_storeData();
}
$this->_cellCache[$pCoord] = true;
$this->_currentObjectID = $pCoord;
$this->_currentObject = $cell;
return $cell;
} // function addCacheData()
/**
* Is a value set in the current PHPExcel_CachedObjectStorage_ICache for an indexed cell?
*
* @param string $pCoord Coordinate address of the cell to check
* @return void
* @return boolean
*/
public function isDataSet($pCoord) {
// Check if the requested entry is the current object, or exists in the cache
if (parent::isDataSet($pCoord)) {
if ($this->_currentObjectID == $pCoord) {
return true;
}
// Check if the requested entry still exists in apc
$success = $this->_memcache->get($this->_cachePrefix.$pCoord.'.cache');
if ($success === false) {
// Entry no longer exists in Memcache, so clear it from the cache array
parent::deleteCacheData($pCoord);
throw new Exception('Cell entry no longer exists in Memcache');
}
return true;
}
return false;
} // function isDataSet()
/**
* Get cell at a specific coordinate
*
* @param string $pCoord Coordinate of the cell
* @throws Exception
* @return PHPExcel_Cell Cell that was found, or null if not found
*/
public function getCacheData($pCoord) {
if ($pCoord === $this->_currentObjectID) {
return $this->_currentObject;
}
$this->_storeData();
// Check if the entry that has been requested actually exists
if (parent::isDataSet($pCoord)) {
$obj = $this->_memcache->get($this->_cachePrefix.$pCoord.'.cache');
if ($obj === false) {
// Entry no longer exists in Memcache, so clear it from the cache array
parent::deleteCacheData($pCoord);
throw new Exception('Cell entry no longer exists in Memcache');
}
} else {
// Return null if requested entry doesn't exist in cache
return null;
}
// Set current entry to the requested entry
$this->_currentObjectID = $pCoord;
$this->_currentObject = unserialize($obj);
// Re-attach the parent worksheet
$this->_currentObject->attach($this->_parent);
// Return requested entry
return $this->_currentObject;
} // function getCacheData()
/**
* Delete a cell in cache identified by coordinate address
*
* @param string $pCoord Coordinate address of the cell to delete
* @throws Exception
*/
public function deleteCacheData($pCoord) {
// Delete the entry from Memcache
$this->_memcache->delete($this->_cachePrefix.$pCoord.'.cache');
// Delete the entry from our cell address array
parent::deleteCacheData($pCoord);
} // function deleteCacheData()
public function unsetWorksheetCells() {
if(!is_null($this->_currentObject)) {
$this->_currentObject->detach();
$this->_currentObject = $this->_currentObjectID = null;
}
// Flush the Memcache cache
$this->__destruct();
$this->_cellCache = array();
// detach ourself from the worksheet, so that it can then delete this object successfully
$this->_parent = null;
} // function unsetWorksheetCells()
public function __construct(PHPExcel_Worksheet $parent, $arguments) {
$memcacheServer = (isset($arguments['memcacheServer'])) ? $arguments['memcacheServer'] : 'localhost';
$memcachePort = (isset($arguments['memcachePort'])) ? $arguments['memcachePort'] : 11211;
$cacheTime = (isset($arguments['cacheTime'])) ? $arguments['cacheTime'] : 600;
if (is_null($this->_cachePrefix)) {
if (function_exists('posix_getpid')) {
$baseUnique = posix_getpid();
} else {
$baseUnique = mt_rand();
}
$this->_cachePrefix = substr(md5(uniqid($baseUnique,true)),0,8).'.';
// Set a new Memcache object and connect to the Memcache server
$this->_memcache = new Memcache();
if (!$this->_memcache->addServer($memcacheServer, $memcachePort, false, 50, 5, 5, true, array($this, 'failureCallback')) {
throw new Exception('Could not connect to Memcache server at '.$memcacheServer.':'.$memcachePort);
}
$this->_cacheTime = $cacheTime;
parent::__construct($parent);
}
} // function __construct()
public function failureCallback($host, $port) {
throw new Exception('memcache '.$host.':'.$port' failed');
}
public function __destruct() {
$cacheList = $this->getCellList();
foreach($cacheList as $cellID) {
$this->_memcache->delete($this->_cachePrefix.$cellID.'.cache');
}
} // function __destruct()
}
?>

View File

@@ -0,0 +1,85 @@
<?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_CachedObjectStorage
* @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.3c, 2010-06-01
*/
/**
* PHPExcel_CachedObjectStorage_Memory
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_CachedObjectStorage_Memory extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {
/**
* Add or Update a cell in cache identified by coordinate address
*
* @param string $pCoord Coordinate address of the cell to update
* @param PHPExcel_Cell $cell Cell to update
* @return void
* @throws Exception
*/
public function addCacheData($pCoord, PHPExcel_Cell $cell) {
$this->_cellCache[$pCoord] = $cell;
return $cell;
} // function addCacheData()
/**
* Get cell at a specific coordinate
*
* @param string $pCoord Coordinate of the cell
* @throws Exception
* @return PHPExcel_Cell Cell that was found, or null if not found
*/
public function getCacheData($pCoord) {
// Check if the entry that has been requested actually exists
if (!isset($this->_cellCache[$pCoord])) {
// Return null if requested entry doesn't exist in cache
return null;
}
// Return requested entry
return $this->_cellCache[$pCoord];
} // function getCacheData()
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) {
$cell->detach();
$this->_cellCache[$k] = null;
}
unset($cell);
$this->_cellCache = array();
// detach ourself from the worksheet, so that it can then delete this object successfully
$this->_parent = null;
} // function unsetWorksheetCells()
}

View File

@@ -0,0 +1,107 @@
<?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_CachedObjectStorage
* @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.3c, 2010-06-01
*/
/**
* PHPExcel_CachedObjectStorage_MemoryGZip
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_CachedObjectStorage_MemoryGZip extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {
private function _storeData() {
$this->_currentObject->detach();
$this->_cellCache[$this->_currentObjectID] = gzdeflate(serialize($this->_currentObject));
$this->_currentObjectID = $this->_currentObject = null;
} // function _storeData()
/**
* Add or Update a cell in cache identified by coordinate address
*
* @param string $pCoord Coordinate address of the cell to update
* @param PHPExcel_Cell $cell Cell to update
* @return void
* @throws Exception
*/
public function addCacheData($pCoord, PHPExcel_Cell $cell) {
if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) {
$this->_storeData();
}
$this->_currentObjectID = $pCoord;
$this->_currentObject = $cell;
return $cell;
} // function addCacheData()
/**
* Get cell at a specific coordinate
*
* @param string $pCoord Coordinate of the cell
* @throws Exception
* @return PHPExcel_Cell Cell that was found, or null if not found
*/
public function getCacheData($pCoord) {
if ($pCoord === $this->_currentObjectID) {
return $this->_currentObject;
}
$this->_storeData();
// Check if the entry that has been requested actually exists
if (!isset($this->_cellCache[$pCoord])) {
// Return null if requested entry doesn't exist in cache
return null;
}
// Set current entry to the requested entry
$this->_currentObjectID = $pCoord;
$this->_currentObject = unserialize(gzinflate($this->_cellCache[$pCoord]));
// Re-attach the parent worksheet
$this->_currentObject->attach($this->_parent);
// Return requested entry
return $this->_currentObject;
} // function getCacheData()
public function unsetWorksheetCells() {
if(!is_null($this->_currentObject)) {
$this->_currentObject->detach();
$this->_currentObject = $this->_currentObjectID = null;
}
$this->_cellCache = array();
// detach ourself from the worksheet, so that it can then delete this object successfully
$this->_parent = null;
} // function unsetWorksheetCells()
}

View File

@@ -0,0 +1,107 @@
<?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_CachedObjectStorage
* @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.3c, 2010-06-01
*/
/**
* PHPExcel_CachedObjectStorage_MemorySerialized
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_CachedObjectStorage_MemorySerialized extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {
private function _storeData() {
$this->_currentObject->detach();
$this->_cellCache[$this->_currentObjectID] = serialize($this->_currentObject);
$this->_currentObjectID = $this->_currentObject = null;
} // function _storeData()
/**
* Add or Update a cell in cache identified by coordinate address
*
* @param string $pCoord Coordinate address of the cell to update
* @param PHPExcel_Cell $cell Cell to update
* @return void
* @throws Exception
*/
public function addCacheData($pCoord, PHPExcel_Cell $cell) {
if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) {
$this->_storeData();
}
$this->_currentObjectID = $pCoord;
$this->_currentObject = $cell;
return $cell;
} // function addCacheData()
/**
* Get cell at a specific coordinate
*
* @param string $pCoord Coordinate of the cell
* @throws Exception
* @return PHPExcel_Cell Cell that was found, or null if not found
*/
public function getCacheData($pCoord) {
if ($pCoord === $this->_currentObjectID) {
return $this->_currentObject;
}
$this->_storeData();
// Check if the entry that has been requested actually exists
if (!isset($this->_cellCache[$pCoord])) {
// Return null if requested entry doesn't exist in cache
return null;
}
// Set current entry to the requested entry
$this->_currentObjectID = $pCoord;
$this->_currentObject = unserialize($this->_cellCache[$pCoord]);
// Re-attach the parent worksheet
$this->_currentObject->attach($this->_parent);
// Return requested entry
return $this->_currentObject;
} // function getCacheData()
public function unsetWorksheetCells() {
if(!is_null($this->_currentObject)) {
$this->_currentObject->detach();
$this->_currentObject = $this->_currentObjectID = null;
}
$this->_cellCache = array();
// detach ourself from the worksheet, so that it can then delete this object successfully
$this->_parent = null;
} // function unsetWorksheetCells()
}

View File

@@ -0,0 +1,137 @@
<?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_CachedObjectStorage
* @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.3c, 2010-06-01
*/
/**
* PHPExcel_CachedObjectStorage_PHPTemp
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_CachedObjectStorage_PHPTemp extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {
private $_fileHandle = null;
private function _storeData() {
$this->_currentObject->detach();
fseek($this->_fileHandle,0,SEEK_END);
$offset = ftell($this->_fileHandle);
fwrite($this->_fileHandle, serialize($this->_currentObject));
$this->_cellCache[$this->_currentObjectID] = array('ptr' => $offset,
'sz' => ftell($this->_fileHandle) - $offset
);
$this->_currentObjectID = $this->_currentObject = null;
} // function _storeData()
/**
* Add or Update a cell in cache identified by coordinate address
*
* @param string $pCoord Coordinate address of the cell to update
* @param PHPExcel_Cell $cell Cell to update
* @return void
* @throws Exception
*/
public function addCacheData($pCoord, PHPExcel_Cell $cell) {
if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) {
$this->_storeData();
}
$this->_currentObjectID = $pCoord;
$this->_currentObject = $cell;
return $cell;
} // function addCacheData()
/**
* Get cell at a specific coordinate
*
* @param string $pCoord Coordinate of the cell
* @throws Exception
* @return PHPExcel_Cell Cell that was found, or null if not found
*/
public function getCacheData($pCoord) {
if ($pCoord === $this->_currentObjectID) {
return $this->_currentObject;
}
$this->_storeData();
// Check if the entry that has been requested actually exists
if (!isset($this->_cellCache[$pCoord])) {
// Return null if requested entry doesn't exist in cache
return null;
}
// Set current entry to the requested entry
$this->_currentObjectID = $pCoord;
fseek($this->_fileHandle,$this->_cellCache[$pCoord]['ptr']);
$this->_currentObject = unserialize(fread($this->_fileHandle,$this->_cellCache[$pCoord]['sz']));
// Re-attach the parent worksheet
$this->_currentObject->attach($this->_parent);
// Return requested entry
return $this->_currentObject;
} // function getCacheData()
public function unsetWorksheetCells() {
if(!is_null($this->_currentObject)) {
$this->_currentObject->detach();
$this->_currentObject = $this->_currentObjectID = null;
}
$this->_cellCache = array();
// detach ourself from the worksheet, so that it can then delete this object successfully
$this->_parent = null;
// Close down the php://temp file
$this->__destruct();
} // function unsetWorksheetCells()
public function __construct(PHPExcel_Worksheet $parent, $memoryCacheSize = '1MB') {
$memoryCacheSize = (isset($arguments['memoryCacheSize'])) ? $arguments['memoryCacheSize'] : '1MB';
parent::__construct($parent);
if (is_null($this->_fileHandle)) {
$this->_fileHandle = fopen('php://temp/maxmemory:'.$memoryCacheSize,'a+');
}
} // function __construct()
public function __destruct() {
if (!is_null($this->_fileHandle)) {
fclose($this->_fileHandle);
}
$this->_fileHandle = null;
} // function __destruct()
}

View File

@@ -0,0 +1,201 @@
<?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_CachedObjectStorage
* @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.3c, 2010-06-01
*/
/**
* PHPExcel_CachedObjectStorage_Wincache
*
* @category PHPExcel
* @package PHPExcel_CachedObjectStorage
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_CachedObjectStorage_Wincache extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {
private $_cachePrefix = null;
private $_cacheTime = 600;
private function _storeData() {
$this->_currentObject->detach();
$obj = serialize($this->_currentObject);
if (wincache_ucache_exists($this->_cachePrefix.$this->_currentObjectID.'.cache')) {
wincache_ucache_set($this->_cachePrefix.$this->_currentObjectID.'.cache', $obj, $this->_cacheTime);
} else {
wincache_ucache_add($this->_cachePrefix.$this->_currentObjectID.'.cache', $obj, $this->_cacheTime);
}
$this->_currentObjectID = $this->_currentObject = null;
} // function _storeData()
/**
* Add or Update a cell in cache identified by coordinate address
*
* @param string $pCoord Coordinate address of the cell to update
* @param PHPExcel_Cell $cell Cell to update
* @return void
* @throws Exception
*/
public function addCacheData($pCoord, PHPExcel_Cell $cell) {
if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) {
$this->_storeData();
}
$this->_cellCache[$pCoord] = true;
$this->_currentObjectID = $pCoord;
$this->_currentObject = $cell;
return $cell;
} // function addCacheData()
/**
* Is a value set in the current PHPExcel_CachedObjectStorage_ICache for an indexed cell?
*
* @param string $pCoord Coordinate address of the cell to check
* @return void
* @return boolean
*/
public function isDataSet($pCoord) {
// Check if the requested entry is the current object, or exists in the cache
if (parent::isDataSet($pCoord)) {
if ($this->_currentObjectID == $pCoord) {
return true;
}
// Check if the requested entry still exists in cache
$success = wincache_ucache_exists($this->_cachePrefix.$pCoord.'.cache');
if ($success === false) {
// Entry no longer exists in Wincache, so clear it from the cache array
parent::deleteCacheData($pCoord);
throw new Exception('Cell entry no longer exists in Wincache');
}
return true;
}
return false;
} // function isDataSet()
/**
* Get cell at a specific coordinate
*
* @param string $pCoord Coordinate of the cell
* @throws Exception
* @return PHPExcel_Cell Cell that was found, or null if not found
*/
public function getCacheData($pCoord) {
if ($pCoord === $this->_currentObjectID) {
return $this->_currentObject;
}
$this->_storeData();
// Check if the entry that has been requested actually exists
$obj = null;
if (parent::isDataSet($pCoord)) {
$success = false;
$obj = wincache_ucache_get($this->_cachePrefix.$pCoord.'.cache', $success);
if ($success === false) {
// Entry no longer exists in Wincache, so clear it from the cache array
parent::deleteCacheData($pCoord);
throw new Exception('Cell entry no longer exists in Wincache');
}
} else {
// Return null if requested entry doesn't exist in cache
return null;
}
// Set current entry to the requested entry
$this->_currentObjectID = $pCoord;
$this->_currentObject = unserialize($obj);
// Re-attach the parent worksheet
$this->_currentObject->attach($this->_parent);
// Return requested entry
return $this->_currentObject;
} // function getCacheData()
/**
* Delete a cell in cache identified by coordinate address
*
* @param string $pCoord Coordinate address of the cell to delete
* @throws Exception
*/
public function deleteCacheData($pCoord) {
// Delete the entry from Wincache
wincache_ucache_delete($this->_cachePrefix.$pCoord.'.cache');
// Delete the entry from our cell address array
parent::deleteCacheData($pCoord);
} // function deleteCacheData()
public function unsetWorksheetCells() {
if(!is_null($this->_currentObject)) {
$this->_currentObject->detach();
$this->_currentObject = $this->_currentObjectID = null;
}
// Flush the Wincache cache
$this->__destruct();
$this->_cellCache = array();
// detach ourself from the worksheet, so that it can then delete this object successfully
$this->_parent = null;
} // function unsetWorksheetCells()
public function __construct(PHPExcel_Worksheet $parent, $arguments) {
$cacheTime = (isset($arguments['cacheTime'])) ? $arguments['cacheTime'] : 600;
if (is_null($this->_cachePrefix)) {
if (function_exists('posix_getpid')) {
$baseUnique = posix_getpid();
} else {
$baseUnique = mt_rand();
}
$this->_cachePrefix = substr(md5(uniqid($baseUnique,true)),0,8).'.';
$this->_cacheTime = $cacheTime;
parent::__construct($parent);
}
} // function __construct()
public function __destruct() {
$cacheList = $this->getCellList();
foreach($cacheList as $cellID) {
wincache_ucache_delete($this->_cachePrefix.$cellID.'.cache');
}
} // function __destruct()
}
?>

View File

@@ -0,0 +1,131 @@
<?php
class PHPExcel_CachedObjectStorageFactory {
const cache_in_memory = 'Memory';
const cache_in_memory_gzip = 'MemoryGZip';
const cache_in_memory_serialized = 'MemorySerialized';
const cache_to_discISAM = 'DiscISAM';
const cache_to_apc = 'APC';
const cache_to_memcache = 'Memcache';
const cache_to_phpTemp = 'PHPTemp';
const cache_to_wincache = 'Wincache';
private static $_cacheStorageMethod = null;
private static $_cacheStorageClass = null;
private static $_storageMethods = array(
self::cache_in_memory,
self::cache_in_memory_gzip,
self::cache_in_memory_serialized,
self::cache_to_phpTemp,
self::cache_to_discISAM,
self::cache_to_apc,
self::cache_to_memcache,
self::cache_to_wincache,
);
private static $_storageMethodDefaultParameters = array(
self::cache_in_memory => array(
),
self::cache_in_memory_gzip => array(
),
self::cache_in_memory_serialized => array(
),
self::cache_to_phpTemp => array( 'memoryCacheSize' => '1MB'
),
self::cache_to_discISAM => array(
),
self::cache_to_apc => array( 'cacheTime' => 600
),
self::cache_to_memcache => array( 'memcacheServer' => 'localhost',
'memcachePort' => 11211,
'cacheTime' => 600
),
self::cache_to_wincache => array( 'cacheTime' => 600
)
);
private static $_storageMethodParameters = array();
public static function getCacheStorageMethod() {
if (!is_null(self::$_cacheStorageMethod)) {
return self::$_cacheStorageMethod;
}
return null;
} // function getCacheStorageMethod()
public static function getCacheStorageClass() {
if (!is_null(self::$_cacheStorageClass)) {
return self::$_cacheStorageClass;
}
return null;
} // function getCacheStorageClass()
public static function getCacheStorageMethods() {
return self::$_storageMethods;
} // function getCacheStorageMethods()
public static function initialize($method = self::cache_in_memory, $arguments = array()) {
if (!in_array($method,self::$_storageMethods)) {
return false;
}
switch($method) {
case self::cache_to_apc :
if (!function_exists('apc_store')) {
return false;
}
if (apc_sma_info() === false) {
return false;
}
break;
case self::cache_to_memcache :
if (!function_exists('memcache_add')) {
return false;
}
break;
case self::cache_to_wincache :
if (!function_exists('wincache_ucache_add')) {
return false;
}
break;
}
self::$_storageMethodParameters[$method] = self::$_storageMethodDefaultParameters[$method];
foreach($arguments as $k => $v) {
if (isset(self::$_storageMethodParameters[$method][$k])) {
self::$_storageMethodParameters[$method][$k] = $v;
}
}
if (is_null(self::$_cacheStorageMethod)) {
self::$_cacheStorageClass = 'PHPExcel_CachedObjectStorage_'.$method;
self::$_cacheStorageMethod = $method;
}
return true;
} // function initialize()
public static function getInstance(PHPExcel_Worksheet $parent) {
if (is_null(self::$_cacheStorageMethod)) {
self::initialize();
}
$instance = new self::$_cacheStorageClass($parent,self::$_storageMethodParameters[self::$_cacheStorageMethod]);
if (!is_null($instance)) {
return $instance;
}
return false;
} // function getInstance()
}

File diff suppressed because it is too large Load Diff

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Calculation * @package PHPExcel_Calculation
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
@@ -31,7 +31,7 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Calculation * @package PHPExcel_Calculation
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_Calculation_Exception extends Exception { class PHPExcel_Calculation_Exception extends Exception {
/** /**

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,28 +20,17 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Calculation * @package PHPExcel_Calculation
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
}
/** PHPExcel_Calculation_Exception */
require_once PHPEXCEL_ROOT . 'PHPExcel/Calculation/Exception.php';
/** /**
* PHPExcel_Calculation_ExceptionHandler * PHPExcel_Calculation_ExceptionHandler
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Calculation * @package PHPExcel_Calculation
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_Calculation_ExceptionHandler { class PHPExcel_Calculation_ExceptionHandler {
/** /**

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Calculation * @package PHPExcel_Calculation
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
@@ -49,23 +49,12 @@ PARTLY BASED ON:
http://ewbi.blogs.com/develops/2004/12/excel_formula_p.html http://ewbi.blogs.com/develops/2004/12/excel_formula_p.html
*/ */
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
}
/** PHPExcel_Calculation_FormulaToken */
require_once PHPEXCEL_ROOT . 'PHPExcel/Calculation/FormulaToken.php';
/** /**
* PHPExcel_Calculation_FormulaParser * PHPExcel_Calculation_FormulaParser
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Calculation * @package PHPExcel_Calculation
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_Calculation_FormulaParser { class PHPExcel_Calculation_FormulaParser {
/* Character constants */ /* Character constants */

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Calculation * @package PHPExcel_Calculation
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
@@ -55,7 +55,7 @@ PARTLY BASED ON:
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Calculation * @package PHPExcel_Calculation
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_Calculation_FormulaToken { class PHPExcel_Calculation_FormulaToken {
/* Token types */ /* Token types */

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Calculation * @package PHPExcel_Calculation
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
@@ -31,7 +31,7 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Calculation * @package PHPExcel_Calculation
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_Calculation_Function { class PHPExcel_Calculation_Function {
/* Function categories */ /* Function categories */

File diff suppressed because it is too large Load Diff

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,51 +20,18 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Cell * @package PHPExcel_Cell
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../');
}
/** PHPExcel_Cell_DataType */
require_once PHPEXCEL_ROOT . 'PHPExcel/Cell/DataType.php';
/** PHPExcel_Cell_DataValidation */
require_once PHPEXCEL_ROOT . 'PHPExcel/Cell/DataValidation.php';
/** PHPExcel_Cell_Hyperlink */
require_once PHPEXCEL_ROOT . 'PHPExcel/Cell/Hyperlink.php';
/** PHPExcel_Worksheet */
require_once PHPEXCEL_ROOT . 'PHPExcel/Worksheet.php';
/** PHPExcel_Calculation */
require_once PHPEXCEL_ROOT . 'PHPExcel/Calculation.php';
/** PHPExcel_Cell_IValueBinder */
require_once PHPEXCEL_ROOT . 'PHPExcel/Cell/IValueBinder.php';
/** PHPExcel_Cell_DefaultValueBinder */
require_once PHPEXCEL_ROOT . 'PHPExcel/Cell/DefaultValueBinder.php';
/** PHPExcel_Shared_String */
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/String.php';
/** /**
* PHPExcel_Cell * PHPExcel_Cell
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Cell * @package PHPExcel_Cell
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_Cell class PHPExcel_Cell
{ {
@@ -124,6 +91,24 @@ class PHPExcel_Cell
*/ */
private $_xfIndex; private $_xfIndex;
/**
* Send notification to the cache controller
* @return void
**/
public function notifyCacheController() {
$this->_parent->getCellCacheController()->updateCacheData($this);
}
public function detach() {
$this->_parent = null;
}
public function attach($parent) {
$this->_parent = $parent;
}
/** /**
* Create a new Cell * Create a new Cell
* *
@@ -136,11 +121,6 @@ class PHPExcel_Cell
*/ */
public function __construct($pColumn = 'A', $pRow = 1, $pValue = null, $pDataType = null, PHPExcel_Worksheet $pSheet = null) public function __construct($pColumn = 'A', $pRow = 1, $pValue = null, $pDataType = null, PHPExcel_Worksheet $pSheet = null)
{ {
// Set value binder?
if (is_null(self::$_valueBinder)) {
self::$_valueBinder = new PHPExcel_Cell_DefaultValueBinder();
}
// Initialise cell coordinate // Initialise cell coordinate
$this->_column = strtoupper($pColumn); $this->_column = strtoupper($pColumn);
$this->_row = $pRow; $this->_row = $pRow;
@@ -171,7 +151,7 @@ class PHPExcel_Cell
*/ */
public function getColumn() public function getColumn()
{ {
return strtoupper($this->_column); return $this->_column;
} }
/** /**
@@ -226,26 +206,48 @@ class PHPExcel_Cell
* @param mixed $pValue Value * @param mixed $pValue Value
* @param string $pDataType Explicit data type * @param string $pDataType Explicit data type
* @return PHPExcel_Cell * @return PHPExcel_Cell
* @throws Exception
*/ */
public function setValueExplicit($pValue = null, $pDataType = PHPExcel_Cell_DataType::TYPE_STRING) public function setValueExplicit($pValue = null, $pDataType = PHPExcel_Cell_DataType::TYPE_STRING)
{ {
// check strings that they are ok // set the value according to data type
// TODO: fix also for RichText switch ($pDataType) {
if ($pDataType == PHPExcel_Cell_DataType::TYPE_STRING && !($pValue instanceof PHPExcel_RichText)) { case PHPExcel_Cell_DataType::TYPE_STRING:
// string must never be longer than 32,767 characters, truncate if necessary case PHPExcel_Cell_DataType::TYPE_NULL:
$pValue = PHPExcel_Shared_String::Substring($pValue, 0, 32767); case PHPExcel_Cell_DataType::TYPE_INLINE:
$this->_value = PHPExcel_Cell_DataType::checkString($pValue);
break;
// we require that newline is represented as "\n" in core, not as "\r\n" or "\r" case PHPExcel_Cell_DataType::TYPE_NUMERIC:
$pValue = str_replace(array("\r\n", "\r"), "\n", $pValue); $this->_value = (float)$pValue;
break;
case PHPExcel_Cell_DataType::TYPE_FORMULA:
$this->_value = (string)$pValue;
break;
case PHPExcel_Cell_DataType::TYPE_BOOL:
$this->_value = (bool)$pValue;
break;
case PHPExcel_Cell_DataType::TYPE_ERROR:
$this->_value = PHPExcel_Cell_DataType::checkErrorCode($pValue);
break;
default:
throw new Exception('Invalid datatype: ' . $pDataType);
break;
} }
$this->_value = $pValue; // set the datatype
$this->_dataType = $pDataType; $this->_dataType = $pDataType;
$this->notifyCacheController();
return $this; return $this;
} }
/** /**
* Get caluclated cell value * Get calculated cell value
* *
* @return mixed * @return mixed
*/ */
@@ -256,9 +258,11 @@ class PHPExcel_Cell
try { try {
// echo 'Cell value for '.$this->getCoordinate().' is a formula: Calculating value<br />'; // echo 'Cell value for '.$this->getCoordinate().' is a formula: Calculating value<br />';
$result = PHPExcel_Calculation::getInstance()->calculateCellValue($this,$resetLog); $result = PHPExcel_Calculation::getInstance()->calculateCellValue($this,$resetLog);
// echo $this->getCoordinate().' calculation result is '.$result.'<br />';
} catch ( Exception $ex ) { } catch ( Exception $ex ) {
// echo 'Calculation Exception: '.$ex->getMessage().'<br />'; // echo 'Calculation Exception: '.$ex->getMessage().'<br />';
$result = '#N/A'; $result = '#N/A';
throw(new Exception($ex->getMessage()));
} }
if ((is_string($result)) && ($result == '#Not Yet Implemented')) { if ((is_string($result)) && ($result == '#Not Yet Implemented')) {
@@ -293,6 +297,8 @@ class PHPExcel_Cell
if (!is_null($pValue)) { if (!is_null($pValue)) {
$this->_calculatedValue = $pValue; $this->_calculatedValue = $pValue;
} }
$this->notifyCacheController();
return $this; return $this;
} }
@@ -325,6 +331,8 @@ class PHPExcel_Cell
public function setDataType($pDataType = PHPExcel_Cell_DataType::TYPE_STRING) public function setDataType($pDataType = PHPExcel_Cell_DataType::TYPE_STRING)
{ {
$this->_dataType = $pDataType; $this->_dataType = $pDataType;
$this->notifyCacheController();
return $this; return $this;
} }
@@ -371,6 +379,8 @@ class PHPExcel_Cell
} }
$this->_parent->setDataValidation($this->getCoordinate(), $pDataValidation); $this->_parent->setDataValidation($this->getCoordinate(), $pDataValidation);
$this->notifyCacheController();
return $this; return $this;
} }
@@ -418,6 +428,8 @@ class PHPExcel_Cell
} }
$this->_parent->setHyperlink($this->getCoordinate(), $pHyperlink); $this->_parent->setHyperlink($this->getCoordinate(), $pHyperlink);
$this->notifyCacheController();
return $this; return $this;
} }
@@ -438,6 +450,8 @@ class PHPExcel_Cell
*/ */
public function rebindParent(PHPExcel_Worksheet $parent) { public function rebindParent(PHPExcel_Worksheet $parent) {
$this->_parent = $parent; $this->_parent = $parent;
$this->notifyCacheController();
return $this; return $this;
} }
@@ -492,22 +506,17 @@ class PHPExcel_Cell
{ {
if (strpos($pCoordinateString,':') !== false) { if (strpos($pCoordinateString,':') !== false) {
throw new Exception('Cell coordinate string can not be a range of cells.'); throw new Exception('Cell coordinate string can not be a range of cells.');
} else if ($pCoordinateString == '') { } else if ($pCoordinateString == '') {
throw new Exception('Cell coordinate can not be zero-length string.'); throw new Exception('Cell coordinate can not be zero-length string.');
} else {
// Column
$column = '';
// Row } else if (preg_match("/([$]?[A-Z]+)([$]?\d+)/", $pCoordinateString, $matches)) {
$row = '';
// Convert a cell reference
if (preg_match("/([$]?[A-Z]+)([$]?\d+)/", $pCoordinateString, $matches)) {
list(, $column, $row) = $matches; list(, $column, $row) = $matches;
}
// Return array
return array($column, $row); return array($column, $row);
} else {
throw new Exception('Invalid cell coordinate.');
} }
} }
@@ -606,6 +615,30 @@ class PHPExcel_Cell
return array( ($rangeEnd[0] - $rangeStart[0] + 1), ($rangeEnd[1] - $rangeStart[1] + 1) ); return array( ($rangeEnd[0] - $rangeStart[0] + 1), ($rangeEnd[1] - $rangeStart[1] + 1) );
} }
/**
* Calculate range boundaries
*
* @param string $pRange Cell range (e.g. A1:A1)
* @return array Range boundaries (staring Column, starting Row, Final Column, Final Row)
*/
public static function getRangeBoundaries($pRange = 'A1:A1')
{
// Uppercase coordinate
$pRange = strtoupper($pRange);
// Extract range
$rangeA = '';
$rangeB = '';
if (strpos($pRange, ':') === false) {
$rangeA = $pRange;
$rangeB = $pRange;
} else {
list($rangeA, $rangeB) = explode(':', $pRange);
}
return array( self::coordinateFromString($rangeA), self::coordinateFromString($rangeB));
}
/** /**
* Column index from string * Column index from string
* *
@@ -615,6 +648,14 @@ class PHPExcel_Cell
*/ */
public static function columnIndexFromString($pString = 'A') public static function columnIndexFromString($pString = 'A')
{ {
static $lookup = 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
);
if (isset($lookup[$pString]))
return $lookup[$pString];
// Convert to uppercase // Convert to uppercase
$pString = strtoupper($pString); $pString = strtoupper($pString);
@@ -745,6 +786,10 @@ class PHPExcel_Cell
* @return PHPExcel_Cell_IValueBinder * @return PHPExcel_Cell_IValueBinder
*/ */
public static function getValueBinder() { public static function getValueBinder() {
if (is_null(self::$_valueBinder)) {
self::$_valueBinder = new PHPExcel_Cell_DefaultValueBinder();
}
return self::$_valueBinder; return self::$_valueBinder;
} }
@@ -795,6 +840,8 @@ class PHPExcel_Cell
public function setXfIndex($pValue = 0) public function setXfIndex($pValue = 0)
{ {
$this->_xfIndex = $pValue; $this->_xfIndex = $pValue;
$this->notifyCacheController();
return $this; return $this;
} }

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,45 +20,18 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Cell * @package PHPExcel_Cell
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
}
/** PHPExcel_Cell */
require_once PHPEXCEL_ROOT . 'PHPExcel/Cell.php';
/** PHPExcel_Cell_IValueBinder */
require_once PHPEXCEL_ROOT . 'PHPExcel/Cell/IValueBinder.php';
/** PHPExcel_Cell_DefaultValueBinder */
require_once PHPEXCEL_ROOT . 'PHPExcel/Cell/DefaultValueBinder.php';
/** PHPExcel_Style_NumberFormat */
require_once PHPEXCEL_ROOT . 'PHPExcel/Style/NumberFormat.php';
/** PHPExcel_Shared_Date */
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/Date.php';
/** PHPExcel_Shared_String */
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/String.php';
/** /**
* PHPExcel_Cell_AdvancedValueBinder * PHPExcel_Cell_AdvancedValueBinder
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Cell * @package PHPExcel_Cell
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_Cell_AdvancedValueBinder extends PHPExcel_Cell_DefaultValueBinder implements PHPExcel_Cell_IValueBinder class PHPExcel_Cell_AdvancedValueBinder extends PHPExcel_Cell_DefaultValueBinder implements PHPExcel_Cell_IValueBinder
{ {
@@ -92,7 +65,7 @@ class PHPExcel_Cell_AdvancedValueBinder extends PHPExcel_Cell_DefaultValueBinder
return true; return true;
} }
// Check for time e.g. '9:45', '09:45' // Check for time without seconds e.g. '9:45', '09:45'
if (preg_match('/^(\d|[0-1]\d|2[0-3]):[0-5]\d$/', $value)) { if (preg_match('/^(\d|[0-1]\d|2[0-3]):[0-5]\d$/', $value)) {
list($h, $m) = explode(':', $value); list($h, $m) = explode(':', $value);
$days = $h / 24 + $m / 1440; $days = $h / 24 + $m / 1440;
@@ -106,34 +79,43 @@ class PHPExcel_Cell_AdvancedValueBinder extends PHPExcel_Cell_DefaultValueBinder
return true; return true;
} }
// Check for date // Check for time with seconds '9:45:59', '09:45:59'
if (strtotime($value) !== false) { if (preg_match('/^(\d|[0-1]\d|2[0-3]):[0-5]\d:[0-5]\d$/', $value)) {
// make sure we have UTC for the sake of strtotime list($h, $m, $s) = explode(':', $value);
$saveTimeZone = date_default_timezone_get(); $days = $h / 24 + $m / 1440 + $s / 86400;
date_default_timezone_set('UTC');
// Convert value to Excel date // Convert value to number
$cell->setValueExplicit( PHPExcel_Shared_Date::PHPToExcel(strtotime($value)), PHPExcel_Cell_DataType::TYPE_NUMERIC); $cell->setValueExplicit($days, PHPExcel_Cell_DataType::TYPE_NUMERIC);
// Set style // Set style
$cell->getParent()->getStyle( $cell->getCoordinate() )->getNumberFormat()->setFormatCode( PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDD2 ); $cell->getParent()->getStyle( $cell->getCoordinate() )->getNumberFormat()->setFormatCode( PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME4 );
// restore original value for timezone
date_default_timezone_set($saveTimeZone);
return true; 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 (strpos($value, ':') !== false) {
$formatCode = 'yyyy-mm-dd h:mm';
} else {
$formatCode = 'yyyy-mm-dd';
}
$cell->getParent()->getStyle( $cell->getCoordinate() )->getNumberFormat()->setFormatCode($formatCode);
return true;
} }
// Style logic - Numbers // Check for newline character "\n"
if ($dataType === PHPExcel_Cell_DataType::TYPE_NUMERIC) { if (strpos($value, "\n") !== false) {
// Leading zeroes? $value = PHPExcel_Shared_String::SanitizeUTF8($value);
if (preg_match('/^\-?[0]+[0-9]*\.?[0-9]*$/', $value)) {
// Convert value to string
$cell->setValueExplicit($value, PHPExcel_Cell_DataType::TYPE_STRING); $cell->setValueExplicit($value, PHPExcel_Cell_DataType::TYPE_STRING);
// Set style // Set style
$cell->getParent()->getStyle( $cell->getCoordinate() )->getNumberFormat()->setFormatCode( PHPExcel_Style_NumberFormat::FORMAT_TEXT ); $cell->getParent()->getStyle( $cell->getCoordinate() )->getAlignment()->setWrapText(true);
return true; return true;
} }

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,30 +20,18 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Cell * @package PHPExcel_Cell
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
}
/** PHPExcel_Cell_DefaultValueBinder */
require_once PHPEXCEL_ROOT . 'PHPExcel/Cell/DefaultValueBinder.php';
/** /**
* PHPExcel_Cell_DataType * PHPExcel_Cell_DataType
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Cell * @package PHPExcel_Cell
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_Cell_DataType class PHPExcel_Cell_DataType
{ {
@@ -82,4 +70,44 @@ class PHPExcel_Cell_DataType
public static function dataTypeForValue($pValue = null) { public static function dataTypeForValue($pValue = null) {
return PHPExcel_Cell_DefaultValueBinder::dataTypeForValue($pValue); return PHPExcel_Cell_DefaultValueBinder::dataTypeForValue($pValue);
} }
/**
* Check a string that it satisfies Excel requirements
*
* @param mixed Value to sanitize to an Excel string
* @return mixed Sanitized value
*/
public static function checkString($pValue = null)
{
if ($pValue instanceof PHPExcel_RichText) {
// TODO: Sanitize Rich-Text string (max. character count is 32,767)
return $pValue;
}
// string must never be longer than 32,767 characters, truncate if necessary
$pValue = PHPExcel_Shared_String::Substring($pValue, 0, 32767);
// we require that newline is represented as "\n" in core, not as "\r\n" or "\r"
$pValue = str_replace(array("\r\n", "\r"), "\n", $pValue);
return $pValue;
}
/**
* Check a value that it is a valid error code
*
* @param mixed Value to sanitize to an Excel error code
* @return string Sanitized value
*/
public static function checkErrorCode($pValue = null)
{
$pValue = (string)$pValue;
if ( !array_key_exists($pValue, self::$_errorCodes) ) {
$pValue = '#NULL!';
}
return $pValue;
}
} }

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Cell * @package PHPExcel_Cell
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
@@ -31,7 +31,7 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Cell * @package PHPExcel_Cell
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_Cell_DataValidation class PHPExcel_Cell_DataValidation
{ {
@@ -151,20 +151,12 @@ class PHPExcel_Cell_DataValidation
*/ */
private $_prompt; private $_prompt;
/**
* Parent cell
*
* @var PHPExcel_Cell
*/
private $_parent;
/** /**
* Create a new PHPExcel_Cell_DataValidation * Create a new PHPExcel_Cell_DataValidation
* *
* @param PHPExcel_Cell $pCell Parent cell
* @throws Exception * @throws Exception
*/ */
public function __construct(PHPExcel_Cell $pCell = null) public function __construct()
{ {
// Initialise member variables // Initialise member variables
$this->_formula1 = ''; $this->_formula1 = '';
@@ -180,9 +172,6 @@ class PHPExcel_Cell_DataValidation
$this->_error = ''; $this->_error = '';
$this->_promptTitle = ''; $this->_promptTitle = '';
$this->_prompt = ''; $this->_prompt = '';
// Set cell
$this->_parent = $pCell;
} }
/** /**
@@ -445,26 +434,6 @@ class PHPExcel_Cell_DataValidation
return $this; return $this;
} }
/**
* Get parent
*
* @return PHPExcel_Cell
*/
public function getParent() {
return $this->_parent;
}
/**
* Set Parent
*
* @param PHPExcel_Cell $value
* @return PHPExcel_Cell_DataValidation
*/
public function setParent($value = null) {
$this->_parent = $value;
return $this;
}
/** /**
* Get hash code * Get hash code
* *
@@ -485,7 +454,6 @@ class PHPExcel_Cell_DataValidation
. $this->_error . $this->_error
. $this->_promptTitle . $this->_promptTitle
. $this->_prompt . $this->_prompt
. $this->_parent->getCoordinate()
. __CLASS__ . __CLASS__
); );
} }
@@ -494,12 +462,9 @@ class PHPExcel_Cell_DataValidation
* Implement PHP __clone to create a deep clone, not just a shallow copy. * Implement PHP __clone to create a deep clone, not just a shallow copy.
*/ */
public function __clone() { public function __clone() {
// unbind parent
$this->setParent(null);
$vars = get_object_vars($this); $vars = get_object_vars($this);
foreach ($vars as $key => $value) { foreach ($vars as $key => $value) {
if (is_object($value) && $key != '_parent') { if (is_object($value)) {
$this->$key = clone $value; $this->$key = clone $value;
} else { } else {
$this->$key = $value; $this->$key = $value;

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,39 +20,18 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Cell * @package PHPExcel_Cell
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
}
/** PHPExcel_Cell */
require_once PHPEXCEL_ROOT . 'PHPExcel/Cell.php';
/** PHPExcel_Cell_IValueBinder */
require_once PHPEXCEL_ROOT . 'PHPExcel/Cell/IValueBinder.php';
/** PHPExcel_Cell_DataType */
require_once PHPEXCEL_ROOT . 'PHPExcel/Cell/DataType.php';
/** PHPExcel_Shared_String */
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/String.php';
/** /**
* PHPExcel_Cell_DefaultValueBinder * PHPExcel_Cell_DefaultValueBinder
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Cell * @package PHPExcel_Cell
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_Cell_DefaultValueBinder implements PHPExcel_Cell_IValueBinder class PHPExcel_Cell_DefaultValueBinder implements PHPExcel_Cell_IValueBinder
{ {
@@ -87,22 +66,31 @@ class PHPExcel_Cell_DefaultValueBinder implements PHPExcel_Cell_IValueBinder
// Match the value against a few data types // Match the value against a few data types
if (is_null($pValue)) { if (is_null($pValue)) {
return PHPExcel_Cell_DataType::TYPE_NULL; return PHPExcel_Cell_DataType::TYPE_NULL;
} elseif ($pValue === '') { } elseif ($pValue === '') {
return PHPExcel_Cell_DataType::TYPE_STRING; return PHPExcel_Cell_DataType::TYPE_STRING;
} elseif ($pValue instanceof PHPExcel_RichText) { } elseif ($pValue instanceof PHPExcel_RichText) {
return PHPExcel_Cell_DataType::TYPE_STRING; return PHPExcel_Cell_DataType::TYPE_STRING;
} elseif ($pValue{0} === '=') {
} elseif ($pValue{0} === '=' && strlen($pValue) > 1) {
return PHPExcel_Cell_DataType::TYPE_FORMULA; return PHPExcel_Cell_DataType::TYPE_FORMULA;
} elseif (is_bool($pValue)) { } elseif (is_bool($pValue)) {
return PHPExcel_Cell_DataType::TYPE_BOOL; return PHPExcel_Cell_DataType::TYPE_BOOL;
} elseif (is_float($pValue) || is_int($pValue)) { } elseif (is_float($pValue) || is_int($pValue)) {
return PHPExcel_Cell_DataType::TYPE_NUMERIC; return PHPExcel_Cell_DataType::TYPE_NUMERIC;
} elseif (preg_match('/^\-?[0-9]*\\.?[0-9]*$/', $pValue)) {
} elseif (preg_match('/^\-?([0-9]+\\.?[0-9]*|[0-9]*\\.?[0-9]+)$/', $pValue)) {
return PHPExcel_Cell_DataType::TYPE_NUMERIC; return PHPExcel_Cell_DataType::TYPE_NUMERIC;
} elseif (is_string($pValue) && array_key_exists($pValue, PHPExcel_Cell_DataType::getErrorCodes())) { } elseif (is_string($pValue) && array_key_exists($pValue, PHPExcel_Cell_DataType::getErrorCodes())) {
return PHPExcel_Cell_DataType::TYPE_ERROR; return PHPExcel_Cell_DataType::TYPE_ERROR;
} else { } else {
return PHPExcel_Cell_DataType::TYPE_STRING; return PHPExcel_Cell_DataType::TYPE_STRING;
} }
} }
} }

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Cell * @package PHPExcel_Cell
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
@@ -31,17 +31,10 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Cell * @package PHPExcel_Cell
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_Cell_Hyperlink class PHPExcel_Cell_Hyperlink
{ {
/**
* Cell representing the hyperlink
*
* @var PHPExcel_Cell
*/
private $_cell;
/** /**
* URL to link the cell to * URL to link the cell to
* *
@@ -59,19 +52,15 @@ class PHPExcel_Cell_Hyperlink
/** /**
* Create a new PHPExcel_Cell_Hyperlink * Create a new PHPExcel_Cell_Hyperlink
* *
* @param PHPExcel_Cell $pCell Parent cell
* @param string $pUrl Url to link the cell to * @param string $pUrl Url to link the cell to
* @param string $pTooltip Tooltip to display on the hyperlink * @param string $pTooltip Tooltip to display on the hyperlink
* @throws Exception * @throws Exception
*/ */
public function __construct(PHPExcel_Cell $pCell = null, $pUrl = '', $pTooltip = '') public function __construct($pUrl = '', $pTooltip = '')
{ {
// Initialise member variables // Initialise member variables
$this->_url = $pUrl; $this->_url = $pUrl;
$this->_tooltip = $pTooltip; $this->_tooltip = $pTooltip;
// Set cell
$this->_parent = $pCell;
} }
/** /**
@@ -123,26 +112,6 @@ class PHPExcel_Cell_Hyperlink
return strpos($this->_url, 'sheet://') !== false; return strpos($this->_url, 'sheet://') !== false;
} }
/**
* Get parent
*
* @return PHPExcel_Cell
*/
public function getParent() {
return $this->_parent;
}
/**
* Set Parent
*
* @param PHPExcel_Cell $value
* @return PHPExcel_Cell_Hyperlink
*/
public function setParent($value = null) {
$this->_parent = $value;
return $this;
}
/** /**
* Get hash code * Get hash code
* *
@@ -152,7 +121,6 @@ class PHPExcel_Cell_Hyperlink
return md5( return md5(
$this->_url $this->_url
. $this->_tooltip . $this->_tooltip
. $this->_parent->getCoordinate()
. __CLASS__ . __CLASS__
); );
} }

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,30 +20,18 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Cell * @package PHPExcel_Cell
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
}
/** PHPExcel_Cell */
require_once PHPEXCEL_ROOT . 'PHPExcel/Cell.php';
/** /**
* PHPExcel_Cell_IValueBinder * PHPExcel_Cell_IValueBinder
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Cell * @package PHPExcel_Cell
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
interface PHPExcel_Cell_IValueBinder interface PHPExcel_Cell_IValueBinder
{ {

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,36 +20,18 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel * @package PHPExcel
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../');
}
/** PHPExcel_RichText */
require_once PHPEXCEL_ROOT . 'PHPExcel/RichText.php';
/** PHPExcel_Style_Color */
require_once PHPEXCEL_ROOT . 'PHPExcel/Style/Color.php';
/** PHPExcel_IComparable */
require_once PHPEXCEL_ROOT . 'PHPExcel/IComparable.php';
/** /**
* PHPExcel_Comment * PHPExcel_Comment
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel * @package PHPExcel
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_Comment implements PHPExcel_IComparable class PHPExcel_Comment implements PHPExcel_IComparable
{ {
@@ -290,37 +272,6 @@ class PHPExcel_Comment implements PHPExcel_IComparable
); );
} }
/**
* Hash index
*
* @var string
*/
private $_hashIndex;
/**
* Get hash index
*
* Note that this index may vary during script execution! Only reliable moment is
* while doing a write of a workbook and when changes are not allowed.
*
* @return string Hash index
*/
public function getHashIndex() {
return $this->_hashIndex;
}
/**
* Set hash index
*
* Note that this index may vary during script execution! Only reliable moment is
* while doing a write of a workbook and when changes are not allowed.
*
* @param string $value Hash index
*/
public function setHashIndex($value) {
$this->_hashIndex = $value;
}
/** /**
* Implement PHP __clone to create a deep clone, not just a shallow copy. * Implement PHP __clone to create a deep clone, not just a shallow copy.
*/ */

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel * @package PHPExcel
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
@@ -31,7 +31,7 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel * @package PHPExcel
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_DocumentProperties class PHPExcel_DocumentProperties
{ {

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,30 +20,18 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel * @package PHPExcel
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../');
}
/** PHPExcel_Shared_PasswordHasher */
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/PasswordHasher.php';
/** /**
* PHPExcel_DocumentSecurity * PHPExcel_DocumentSecurity
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel * @package PHPExcel
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_DocumentSecurity class PHPExcel_DocumentSecurity
{ {

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,30 +20,18 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel * @package PHPExcel
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../');
}
/** PHPExcel_IComparable */
require_once PHPEXCEL_ROOT . 'PHPExcel/IComparable.php';
/** /**
* PHPExcel_HashTable * PHPExcel_HashTable
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel * @package PHPExcel
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_HashTable class PHPExcel_HashTable
{ {
@@ -101,25 +89,9 @@ class PHPExcel_HashTable
* @throws Exception * @throws Exception
*/ */
public function add(PHPExcel_IComparable $pSource = null) { public function add(PHPExcel_IComparable $pSource = null) {
// Determine hashcode if (!isset($this->_items[ $pSource->getHashCode() ])) {
$hashCode = null; $this->_items[ $pSource->getHashCode() ] = $pSource;
$hashIndex = $pSource->getHashIndex(); $this->_keyMap[ count($this->_items) - 1 ] = $pSource->getHashCode();
if ( is_null ( $hashIndex ) ) {
$hashCode = $pSource->getHashCode();
} else if ( isset ( $this->_keyMap[$hashIndex] ) ) {
$hashCode = $this->_keyMap[$hashIndex];
} else {
$hashCode = $pSource->getHashCode();
}
// Add value
if (!isset($this->_items[ $hashCode ])) {
$this->_items[ $hashCode ] = $pSource;
$index = count($this->_items) - 1;
$this->_keyMap[ $index ] = $hashCode;
$pSource->setHashIndex( $index );
} else {
$pSource->setHashIndex( $this->_items[ $hashCode ]->getHashIndex() );
} }
} }

View File

@@ -18,9 +18,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel * @package PHPExcel
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
@@ -29,7 +29,7 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel * @package PHPExcel
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
interface PHPExcel_IComparable interface PHPExcel_IComparable
{ {
@@ -40,23 +40,4 @@ interface PHPExcel_IComparable
*/ */
public function getHashCode(); public function getHashCode();
/**
* Get hash index
*
* Note that this index may vary during script execution! Only reliable moment is
* while doing a write of a workbook and when changes are not allowed.
*
* @return string Hash index
*/
public function getHashIndex();
/**
* Set hash index
*
* Note that this index may vary during script execution! Only reliable moment is
* while doing a write of a workbook and when changes are not allowed.
*
* @param string $value Hash index
*/
public function setHashIndex($value);
} }

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel * @package PHPExcel
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
@@ -32,24 +32,21 @@ if (!defined('PHPEXCEL_ROOT')) {
* @ignore * @ignore
*/ */
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../'); 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 */
require_once PHPEXCEL_ROOT . 'PHPExcel.php';
/** PHPExcel_IWriter */
require_once PHPEXCEL_ROOT . 'PHPExcel/Writer/IWriter.php';
/** PHPExcel_IReader */
require_once PHPEXCEL_ROOT . 'PHPExcel/Reader/IReader.php';
/** /**
* PHPExcel_IOFactory * PHPExcel_IOFactory
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel * @package PHPExcel
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_IOFactory class PHPExcel_IOFactory
{ {
@@ -57,6 +54,8 @@ class PHPExcel_IOFactory
* Search locations * Search locations
* *
* @var array * @var array
* @access private
* @static
*/ */
private static $_searchLocations = array( private static $_searchLocations = array(
array( 'type' => 'IWriter', 'path' => 'PHPExcel/Writer/{0}.php', 'class' => 'PHPExcel_Writer_{0}' ), array( 'type' => 'IWriter', 'path' => 'PHPExcel/Writer/{0}.php', 'class' => 'PHPExcel_Writer_{0}' ),
@@ -67,12 +66,17 @@ class PHPExcel_IOFactory
* Autoresolve classes * Autoresolve classes
* *
* @var array * @var array
* @access private
* @static
*/ */
private static $_autoResolveClasses = array( private static $_autoResolveClasses = array(
'Excel2007', 'Excel2007',
'Excel5', 'Excel5',
'Excel2003XML',
'OOCalc',
'SYLK',
'Serialized', 'Serialized',
'CSV' 'CSV',
); );
/** /**
@@ -83,15 +87,19 @@ class PHPExcel_IOFactory
/** /**
* Get search locations * Get search locations
* *
* @static
* @access public
* @return array * @return array
*/ */
public static function getSearchLocations() { public static function getSearchLocations() {
return self::$_searchLocations; return self::$_searchLocations;
} } // function getSearchLocations()
/** /**
* Set search locations * Set search locations
* *
* @static
* @access public
* @param array $value * @param array $value
* @throws Exception * @throws Exception
*/ */
@@ -101,25 +109,30 @@ class PHPExcel_IOFactory
} else { } else {
throw new Exception('Invalid parameter passed.'); throw new Exception('Invalid parameter passed.');
} }
} } // function setSearchLocations()
/** /**
* Add search location * Add search location
* *
* @static
* @access public
* @param string $type Example: IWriter * @param string $type Example: IWriter
* @param string $location Example: PHPExcel/Writer/{0}.php * @param string $location Example: PHPExcel/Writer/{0}.php
* @param string $classname Example: PHPExcel_Writer_{0} * @param string $classname Example: PHPExcel_Writer_{0}
*/ */
public static function addSearchLocation($type = '', $location = '', $classname = '') { public static function addSearchLocation($type = '', $location = '', $classname = '') {
self::$_searchLocations[] = array( 'type' => $type, 'path' => $location, 'class' => $classname ); self::$_searchLocations[] = array( 'type' => $type, 'path' => $location, 'class' => $classname );
} } // function addSearchLocation()
/** /**
* Create PHPExcel_Writer_IWriter * Create PHPExcel_Writer_IWriter
* *
* @static
* @access public
* @param PHPExcel $phpExcel * @param PHPExcel $phpExcel
* @param string $writerType Example: Excel2007 * @param string $writerType Example: Excel2007
* @return PHPExcel_Writer_IWriter * @return PHPExcel_Writer_IWriter
* @throws Exception
*/ */
public static function createWriter(PHPExcel $phpExcel, $writerType = '') { public static function createWriter(PHPExcel $phpExcel, $writerType = '') {
// Search type // Search type
@@ -131,10 +144,6 @@ class PHPExcel_IOFactory
$className = str_replace('{0}', $writerType, $searchLocation['class']); $className = str_replace('{0}', $writerType, $searchLocation['class']);
$classFile = str_replace('{0}', $writerType, $searchLocation['path']); $classFile = str_replace('{0}', $writerType, $searchLocation['path']);
if (!class_exists($className)) {
require_once PHPEXCEL_ROOT . $classFile;
}
$instance = new $className($phpExcel); $instance = new $className($phpExcel);
if (!is_null($instance)) { if (!is_null($instance)) {
return $instance; return $instance;
@@ -144,13 +153,16 @@ class PHPExcel_IOFactory
// Nothing found... // Nothing found...
throw new Exception("No $searchType found for type $writerType"); throw new Exception("No $searchType found for type $writerType");
} } // function createWriter()
/** /**
* Create PHPExcel_Reader_IReader * Create PHPExcel_Reader_IReader
* *
* @static
* @access public
* @param string $readerType Example: Excel2007 * @param string $readerType Example: Excel2007
* @return PHPExcel_Reader_IReader * @return PHPExcel_Reader_IReader
* @throws Exception
*/ */
public static function createReader($readerType = '') { public static function createReader($readerType = '') {
// Search type // Search type
@@ -162,10 +174,6 @@ class PHPExcel_IOFactory
$className = str_replace('{0}', $readerType, $searchLocation['class']); $className = str_replace('{0}', $readerType, $searchLocation['class']);
$classFile = str_replace('{0}', $readerType, $searchLocation['path']); $classFile = str_replace('{0}', $readerType, $searchLocation['path']);
if (!class_exists($className)) {
require_once PHPEXCEL_ROOT . $classFile;
}
$instance = new $className(); $instance = new $className();
if (!is_null($instance)) { if (!is_null($instance)) {
return $instance; return $instance;
@@ -175,27 +183,88 @@ class PHPExcel_IOFactory
// Nothing found... // Nothing found...
throw new Exception("No $searchType found for type $readerType"); throw new Exception("No $searchType found for type $readerType");
} } // function createReader()
/** /**
* Loads PHPExcel from file using automatic PHPExcel_Reader_IReader resolution * Loads PHPExcel from file using automatic PHPExcel_Reader_IReader resolution
* *
* @static
* @access public
* @param string $pFileName * @param string $pFileName
* @return PHPExcel * @return PHPExcel
* @throws Exception
*/ */
public static function load($pFilename) { public static function load($pFilename) {
$reader = self::createReaderForFile($pFilename); $reader = self::createReaderForFile($pFilename);
return $reader->load($pFilename); return $reader->load($pFilename);
} } // function load()
/**
* Identify file type using automatic PHPExcel_Reader_IReader resolution
*
* @static
* @access public
* @param string $pFileName
* @return string
* @throws Exception
*/
public static function identify($pFilename) {
$reader = self::createReaderForFile($pFilename);
$className = get_class($reader);
$classType = explode('_',$className);
unset($reader);
return array_pop($classType);
} // function identify()
/** /**
* Create PHPExcel_Reader_IReader for file using automatic PHPExcel_Reader_IReader resolution * Create PHPExcel_Reader_IReader for file using automatic PHPExcel_Reader_IReader resolution
* *
* @static
* @access public
* @param string $pFileName * @param string $pFileName
* @return PHPExcel_Reader_IReader * @return PHPExcel_Reader_IReader
* @throws Exception * @throws Exception
*/ */
public static function createReaderForFile($pFilename) { public static function createReaderForFile($pFilename) {
// First, lucky guess by inspecting file extension
$pathinfo = pathinfo($pFilename);
if (isset($pathinfo['extension'])) {
switch (strtolower($pathinfo['extension'])) {
case 'xlsx':
$reader = self::createReader('Excel2007');
break;
case 'xls':
$reader = self::createReader('Excel5');
break;
case 'ods':
$reader = self::createReader('OOCalc');
break;
case 'slk':
$reader = self::createReader('SYLK');
break;
case 'xml':
$reader = self::createReader('Excel2003XML');
break;
case 'csv':
// Do nothing
// We must not try to use CSV reader since it loads
// all files including Excel files etc.
break;
default:
break;
}
// Let's see if we are lucky
if (isset($reader) && $reader->canRead($pFilename)) {
return $reader;
}
}
// If we reach here then "lucky guess" didn't give any result
// Try loading using self::$_autoResolveClasses // Try loading using self::$_autoResolveClasses
foreach (self::$_autoResolveClasses as $autoResolveClass) { foreach (self::$_autoResolveClasses as $autoResolveClass) {
$reader = self::createReader($autoResolveClass); $reader = self::createReader($autoResolveClass);
@@ -204,6 +273,5 @@ class PHPExcel_IOFactory
} }
} }
throw new Exception("Could not automatically determine PHPExcel_Reader_IReader for file."); } // function createReaderForFile()
}
} }

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,36 +20,18 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel * @package PHPExcel
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../');
}
/** PHPExcel */
require_once PHPEXCEL_ROOT . 'PHPExcel.php';
/** PHPExcel_Worksheet */
require_once PHPEXCEL_ROOT . 'PHPExcel/Worksheet.php';
/** PHPExcel_ReferenceHelper */
require_once PHPEXCEL_ROOT . 'PHPExcel/ReferenceHelper.php';
/** /**
* PHPExcel_NamedRange * PHPExcel_NamedRange
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel * @package PHPExcel
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_NamedRange class PHPExcel_NamedRange
{ {
@@ -81,6 +63,13 @@ class PHPExcel_NamedRange
*/ */
private $_localOnly; private $_localOnly;
/**
* Scope
*
* @var PHPExcel_Worksheet
*/
private $_scope;
/** /**
* Create a new NamedRange * Create a new NamedRange
* *
@@ -88,8 +77,9 @@ class PHPExcel_NamedRange
* @param PHPExcel_Worksheet $pWorksheet * @param PHPExcel_Worksheet $pWorksheet
* @param string $pRange * @param string $pRange
* @param bool $pLocalOnly * @param bool $pLocalOnly
* @param PHPExcel_Worksheet|null $pScope Scope. Only applies when $pLocalOnly = true. Null for global scope.
*/ */
public function __construct($pName = null, PHPExcel_Worksheet $pWorksheet, $pRange = 'A1', $pLocalOnly = false) public function __construct($pName = null, PHPExcel_Worksheet $pWorksheet, $pRange = 'A1', $pLocalOnly = false, $pScope = null)
{ {
// Validate data // Validate data
if (is_null($pName) || is_null($pWorksheet)|| is_null($pRange)) { if (is_null($pName) || is_null($pWorksheet)|| is_null($pRange)) {
@@ -101,6 +91,8 @@ class PHPExcel_NamedRange
$this->_worksheet = $pWorksheet; $this->_worksheet = $pWorksheet;
$this->_range = $pRange; $this->_range = $pRange;
$this->_localOnly = $pLocalOnly; $this->_localOnly = $pLocalOnly;
$this->_scope = ($pLocalOnly == true) ?
(($pScope == null) ? $pWorksheet : $pScope) : null;
} }
/** /**
@@ -201,6 +193,28 @@ class PHPExcel_NamedRange
*/ */
public function setLocalOnly($value = false) { public function setLocalOnly($value = false) {
$this->_localOnly = $value; $this->_localOnly = $value;
$this->_scope = $value ? $this->_worksheet : null;
return $this;
}
/**
* Get scope
*
* @return PHPExcel_Worksheet|null
*/
public function getScope() {
return $this->_scope;
}
/**
* Set scope
*
* @param PHPExcel_Worksheet|null $value
* @return PHPExcel_NamedRange
*/
public function setScope(PHPExcel_Worksheet $value = null) {
$this->_scope = $value;
$this->_localOnly = ($value == null) ? false : true;
return $this; return $this;
} }
@@ -208,7 +222,7 @@ class PHPExcel_NamedRange
* Resolve a named range to a regular cell range * Resolve a named range to a regular cell range
* *
* @param string $pNamedRange Named range * @param string $pNamedRange Named range
* @param PHPExcel_Worksheet $pSheet Worksheet * @param PHPExcel_Worksheet|null $pSheet Scope. Use null for global scope
* @return PHPExcel_NamedRange * @return PHPExcel_NamedRange
*/ */
public static function resolveRange($pNamedRange = '', PHPExcel_Worksheet $pSheet) { public static function resolveRange($pNamedRange = '', PHPExcel_Worksheet $pSheet) {

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Reader * @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
@@ -32,36 +32,36 @@ if (!defined('PHPEXCEL_ROOT')) {
* @ignore * @ignore
*/ */
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../'); 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 */
require_once PHPEXCEL_ROOT . 'PHPExcel.php';
/** PHPExcel_Reader_IReader */
require_once PHPEXCEL_ROOT . 'PHPExcel/Reader/IReader.php';
/** PHPExcel_Worksheet */
require_once PHPEXCEL_ROOT . 'PHPExcel/Worksheet.php';
/** PHPExcel_Cell */
require_once PHPEXCEL_ROOT . 'PHPExcel/Cell.php';
/** PHPExcel_Reader_DefaultReadFilter */
require_once PHPEXCEL_ROOT . 'PHPExcel/Reader/DefaultReadFilter.php';
/** /**
* PHPExcel_Reader_CSV * PHPExcel_Reader_CSV
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Reader * @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_Reader_CSV implements PHPExcel_Reader_IReader class PHPExcel_Reader_CSV implements PHPExcel_Reader_IReader
{ {
/**
* Input encoding
*
* @access private
* @var string
*/
private $_inputEncoding;
/** /**
* Delimiter * Delimiter
* *
* @access private
* @var string * @var string
*/ */
private $_delimiter; private $_delimiter;
@@ -69,6 +69,7 @@ class PHPExcel_Reader_CSV implements PHPExcel_Reader_IReader
/** /**
* Enclosure * Enclosure
* *
* @access private
* @var string * @var string
*/ */
private $_enclosure; private $_enclosure;
@@ -76,6 +77,7 @@ class PHPExcel_Reader_CSV implements PHPExcel_Reader_IReader
/** /**
* Line ending * Line ending
* *
* @access private
* @var string * @var string
*/ */
private $_lineEnding; private $_lineEnding;
@@ -83,6 +85,7 @@ class PHPExcel_Reader_CSV implements PHPExcel_Reader_IReader
/** /**
* Sheet index to read * Sheet index to read
* *
* @access private
* @var int * @var int
*/ */
private $_sheetIndex; private $_sheetIndex;
@@ -90,6 +93,7 @@ class PHPExcel_Reader_CSV implements PHPExcel_Reader_IReader
/** /**
* PHPExcel_Reader_IReadFilter instance * PHPExcel_Reader_IReadFilter instance
* *
* @access private
* @var PHPExcel_Reader_IReadFilter * @var PHPExcel_Reader_IReadFilter
*/ */
private $_readFilter = null; private $_readFilter = null;
@@ -98,18 +102,21 @@ class PHPExcel_Reader_CSV implements PHPExcel_Reader_IReader
* Create a new PHPExcel_Reader_CSV * Create a new PHPExcel_Reader_CSV
*/ */
public function __construct() { public function __construct() {
$this->_inputEncoding = 'UTF-8';
$this->_delimiter = ','; $this->_delimiter = ',';
$this->_enclosure = '"'; $this->_enclosure = '"';
$this->_lineEnding = PHP_EOL; $this->_lineEnding = PHP_EOL;
$this->_sheetIndex = 0; $this->_sheetIndex = 0;
$this->_readFilter = new PHPExcel_Reader_DefaultReadFilter(); $this->_readFilter = new PHPExcel_Reader_DefaultReadFilter();
} } // function __construct()
/** /**
* Can the current PHPExcel_Reader_IReader read the file? * Can the current PHPExcel_Reader_IReader read the file?
* *
* @access public
* @param string $pFileName * @param string $pFileName
* @return boolean * @return boolean
* @throws Exception
*/ */
public function canRead($pFilename) public function canRead($pFilename)
{ {
@@ -118,14 +125,15 @@ class PHPExcel_Reader_CSV implements PHPExcel_Reader_IReader
throw new Exception("Could not open " . $pFilename . " for reading! File does not exist."); throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
} }
// Check if it is a CSV file (using file name) return true;
return (substr(strtolower($pFilename), -3) == 'csv'); } // function canRead()
}
/** /**
* Loads PHPExcel from file * Loads PHPExcel from file
* *
* @access public
* @param string $pFilename * @param string $pFilename
* @return PHPExcel
* @throws Exception * @throws Exception
*/ */
public function load($pFilename) public function load($pFilename)
@@ -135,31 +143,59 @@ class PHPExcel_Reader_CSV implements PHPExcel_Reader_IReader
// Load into this instance // Load into this instance
return $this->loadIntoExisting($pFilename, $objPHPExcel); return $this->loadIntoExisting($pFilename, $objPHPExcel);
} } // function load()
/** /**
* Read filter * Read filter
* *
* @access public
* @return PHPExcel_Reader_IReadFilter * @return PHPExcel_Reader_IReadFilter
*/ */
public function getReadFilter() { public function getReadFilter() {
return $this->_readFilter; return $this->_readFilter;
} } // function getReadFilter()
/** /**
* Set read filter * Set read filter
* *
* @access public
* @param PHPExcel_Reader_IReadFilter $pValue * @param PHPExcel_Reader_IReadFilter $pValue
*/ */
public function setReadFilter(PHPExcel_Reader_IReadFilter $pValue) { public function setReadFilter(PHPExcel_Reader_IReadFilter $pValue) {
$this->_readFilter = $pValue; $this->_readFilter = $pValue;
} return $this;
} // function setReadFilter()
/**
* Set input encoding
*
* @access public
* @param string $pValue Input encoding
*/
public function setInputEncoding($pValue = 'UTF-8')
{
$this->_inputEncoding = $pValue;
return $this;
} // function setInputEncoding()
/**
* Get input encoding
*
* @access public
* @return string
*/
public function getInputEncoding()
{
return $this->_inputEncoding;
} // function getInputEncoding()
/** /**
* Loads PHPExcel from file into PHPExcel instance * Loads PHPExcel from file into PHPExcel instance
* *
* @access public
* @param string $pFilename * @param string $pFilename
* @param PHPExcel $objPHPExcel * @param PHPExcel $objPHPExcel
* @return PHPExcel
* @throws Exception * @throws Exception
*/ */
public function loadIntoExisting($pFilename, PHPExcel $objPHPExcel) public function loadIntoExisting($pFilename, PHPExcel $objPHPExcel)
@@ -181,7 +217,17 @@ class PHPExcel_Reader_CSV implements PHPExcel_Reader_IReader
throw new Exception("Could not open file $pFilename for reading."); throw new Exception("Could not open file $pFilename for reading.");
} }
// Loop trough file // Skip BOM, if any
switch ($this->_inputEncoding) {
case 'UTF-8':
fgets($fileHandle, 4) == "\xEF\xBB\xBF" ?
fseek($fileHandle, 3) : fseek($fileHandle, 0);
break;
default:
break;
}
// Loop through file
$currentRow = 0; $currentRow = 0;
$rowData = array(); $rowData = array();
while (($rowData = fgetcsv($fileHandle, 0, $this->_delimiter, $this->_enclosure)) !== FALSE) { while (($rowData = fgetcsv($fileHandle, 0, $this->_delimiter, $this->_enclosure)) !== FALSE) {
@@ -194,10 +240,13 @@ class PHPExcel_Reader_CSV implements PHPExcel_Reader_IReader
$rowData[$i] = str_replace("\\" . $this->_enclosure, $this->_enclosure, $rowData[$i]); $rowData[$i] = str_replace("\\" . $this->_enclosure, $this->_enclosure, $rowData[$i]);
$rowData[$i] = str_replace($this->_enclosure . $this->_enclosure, $this->_enclosure, $rowData[$i]); $rowData[$i] = str_replace($this->_enclosure . $this->_enclosure, $this->_enclosure, $rowData[$i]);
// Convert encoding if necessary
if ($this->_inputEncoding !== 'UTF-8') {
$rowData[$i] = PHPExcel_Shared_String::ConvertEncoding($rowData[$i], 'UTF-8', $this->_inputEncoding);
}
// Set cell value // Set cell value
$objPHPExcel->getActiveSheet()->setCellValue( $objPHPExcel->getActiveSheet()->getCell($columnLetter . $currentRow)->setValue($rowData[$i]);
$columnLetter . $currentRow, $rowData[$i]
);
} }
} }
} }
@@ -207,40 +256,44 @@ class PHPExcel_Reader_CSV implements PHPExcel_Reader_IReader
// Return // Return
return $objPHPExcel; return $objPHPExcel;
} } // function loadIntoExisting()
/** /**
* Get delimiter * Get delimiter
* *
* @access public
* @return string * @return string
*/ */
public function getDelimiter() { public function getDelimiter() {
return $this->_delimiter; return $this->_delimiter;
} } // function getDelimiter()
/** /**
* Set delimiter * Set delimiter
* *
* @access public
* @param string $pValue Delimiter, defaults to , * @param string $pValue Delimiter, defaults to ,
* @return PHPExcel_Reader_CSV * @return PHPExcel_Reader_CSV
*/ */
public function setDelimiter($pValue = ',') { public function setDelimiter($pValue = ',') {
$this->_delimiter = $pValue; $this->_delimiter = $pValue;
return $this; return $this;
} } // function setDelimiter()
/** /**
* Get enclosure * Get enclosure
* *
* @access public
* @return string * @return string
*/ */
public function getEnclosure() { public function getEnclosure() {
return $this->_enclosure; return $this->_enclosure;
} } // function getEnclosure()
/** /**
* Set enclosure * Set enclosure
* *
* @access public
* @param string $pValue Enclosure, defaults to " * @param string $pValue Enclosure, defaults to "
* @return PHPExcel_Reader_CSV * @return PHPExcel_Reader_CSV
*/ */
@@ -250,45 +303,49 @@ class PHPExcel_Reader_CSV implements PHPExcel_Reader_IReader
} }
$this->_enclosure = $pValue; $this->_enclosure = $pValue;
return $this; return $this;
} } // function setEnclosure()
/** /**
* Get line ending * Get line ending
* *
* @access public
* @return string * @return string
*/ */
public function getLineEnding() { public function getLineEnding() {
return $this->_lineEnding; return $this->_lineEnding;
} } // function getLineEnding()
/** /**
* Set line ending * Set line ending
* *
* @access public
* @param string $pValue Line ending, defaults to OS line ending (PHP_EOL) * @param string $pValue Line ending, defaults to OS line ending (PHP_EOL)
* @return PHPExcel_Reader_CSV * @return PHPExcel_Reader_CSV
*/ */
public function setLineEnding($pValue = PHP_EOL) { public function setLineEnding($pValue = PHP_EOL) {
$this->_lineEnding = $pValue; $this->_lineEnding = $pValue;
return $this; return $this;
} } // function setLineEnding()
/** /**
* Get sheet index * Get sheet index
* *
* @access public
* @return int * @return int
*/ */
public function getSheetIndex() { public function getSheetIndex() {
return $this->_sheetIndex; return $this->_sheetIndex;
} } // function getSheetIndex()
/** /**
* Set sheet index * Set sheet index
* *
* @access public
* @param int $pValue Sheet index * @param int $pValue Sheet index
* @return PHPExcel_Reader_CSV * @return PHPExcel_Reader_CSV
*/ */
public function setSheetIndex($pValue = 0) { public function setSheetIndex($pValue = 0) {
$this->_sheetIndex = $pValue; $this->_sheetIndex = $pValue;
return $this; return $this;
} } // function setSheetIndex()
} }

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Reader * @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
@@ -32,18 +32,21 @@ if (!defined('PHPEXCEL_ROOT')) {
* @ignore * @ignore
*/ */
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../'); 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_IReadFilter */
require_once PHPEXCEL_ROOT . 'PHPExcel/Reader/IReadFilter.php';
/** /**
* PHPExcel_Reader_DefaultReadFilter * PHPExcel_Reader_DefaultReadFilter
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Reader * @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_Reader_DefaultReadFilter implements PHPExcel_Reader_IReadFilter class PHPExcel_Reader_DefaultReadFilter implements PHPExcel_Reader_IReadFilter
{ {

View File

@@ -0,0 +1,688 @@
<?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.3c, 2010-06-01
*/
/** 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_Excel2003XML
*
* @category PHPExcel
* @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Reader_Excel2003XML implements PHPExcel_Reader_IReader
{
/**
* Read data only?
*
* @var boolean
*/
private $_readDataOnly = false;
/**
* Restict which sheets should be loaded?
*
* @var array
*/
private $_loadSheetsOnly = null;
/**
* Sheet index to read
*
* @var int
*/
private $_sheetIndex;
/**
* Formats
*
* @var array
*/
private $_styles = array();
/**
* PHPExcel_Reader_IReadFilter instance
*
* @var PHPExcel_Reader_IReadFilter
*/
private $_readFilter = null;
/**
* Read data only?
*
* @return boolean
*/
public function getReadDataOnly() {
return $this->_readDataOnly;
}
/**
* Set read data only
*
* @param boolean $pValue
* @return PHPExcel_Reader_Excel2007
*/
public function setReadDataOnly($pValue = false) {
$this->_readDataOnly = $pValue;
return $this;
}
/**
* Get which sheets to load
*
* @return mixed
*/
public function getLoadSheetsOnly()
{
return $this->_loadSheetsOnly;
}
/**
* Set which sheets to load
*
* @param mixed $value
* @return PHPExcel_Reader_Excel2007
*/
public function setLoadSheetsOnly($value = null)
{
$this->_loadSheetsOnly = is_array($value) ?
$value : array($value);
return $this;
}
/**
* Set all sheets to load
*
* @return PHPExcel_Reader_Excel2007
*/
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_Excel2007
*/
public function setReadFilter(PHPExcel_Reader_IReadFilter $pValue) {
$this->_readFilter = $pValue;
return $this;
}
/**
* Create a new PHPExcel_Reader_Excel2003XML
*/
public function __construct() {
$this->_sheetIndex = 0;
$this->_readFilter = new PHPExcel_Reader_DefaultReadFilter();
}
/**
* Can the current PHPExcel_Reader_IReader read the file?
*
* @param string $pFileName
* @return boolean
*/
public function canRead($pFilename)
{
// Office xmlns:o="urn:schemas-microsoft-com:office:office"
// Excel xmlns:x="urn:schemas-microsoft-com:office:excel"
// XML Spreadsheet xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
// Spreadsheet component xmlns:c="urn:schemas-microsoft-com:office:component:spreadsheet"
// XML schema xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882"
// XML data type xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"
// MS-persist recordset xmlns:rs="urn:schemas-microsoft-com:rowset"
// Rowset xmlns:z="#RowsetSchema"
//
$signature = array(
'<?xml version="1.0"?>',
'<?mso-application progid="Excel.Sheet"?>'
);
// Check if file exists
if (!file_exists($pFilename)) {
throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
}
// Read sample data (first 2 KB will do)
$fh = fopen($pFilename, 'r');
$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 {
$valid = false;
break;
}
}
return $valid;
}
/**
* 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 static function identifyFixedStyleValue($styleList,&$styleAttributeValue) {
$styleAttributeValue = strtolower($styleAttributeValue);
foreach($styleList as $style) {
if ($styleAttributeValue == strtolower($style)) {
$styleAttributeValue = $style;
return true;
}
}
return false;
}
/**
* pixel units to excel width units(units of 1/256th of a character width)
* @param pxs
* @return
*/
private static function _pixel2WidthUnits($pxs) {
$UNIT_OFFSET_MAP = array(0, 36, 73, 109, 146, 182, 219);
$widthUnits = 256 * ($pxs / 7);
$widthUnits += $UNIT_OFFSET_MAP[($pxs % 7)];
return $widthUnits;
}
/**
* excel width units(units of 1/256th of a character width) to pixel units
* @param widthUnits
* @return
*/
private static function _widthUnits2Pixel($widthUnits) {
$pixels = ($widthUnits / 256) * 7;
$offsetWidthUnits = $widthUnits % 256;
$pixels += round($offsetWidthUnits / (256 / 7));
return $pixels;
}
/**
* Loads PHPExcel from file into PHPExcel instance
*
* @param string $pFilename
* @param PHPExcel $objPHPExcel
* @return PHPExcel
* @throws Exception
*/
public function loadIntoExisting($pFilename, PHPExcel $objPHPExcel)
{
$fromFormats = array('\-', '\ ');
$toFormats = array('-', ' ');
$underlineStyles = array (
PHPExcel_Style_Font::UNDERLINE_NONE,
PHPExcel_Style_Font::UNDERLINE_DOUBLE,
PHPExcel_Style_Font::UNDERLINE_DOUBLEACCOUNTING,
PHPExcel_Style_Font::UNDERLINE_SINGLE,
PHPExcel_Style_Font::UNDERLINE_SINGLEACCOUNTING
);
$verticalAlignmentStyles = array (
PHPExcel_Style_Alignment::VERTICAL_BOTTOM,
PHPExcel_Style_Alignment::VERTICAL_TOP,
PHPExcel_Style_Alignment::VERTICAL_CENTER,
PHPExcel_Style_Alignment::VERTICAL_JUSTIFY
);
$horizontalAlignmentStyles = array (
PHPExcel_Style_Alignment::HORIZONTAL_GENERAL,
PHPExcel_Style_Alignment::HORIZONTAL_LEFT,
PHPExcel_Style_Alignment::HORIZONTAL_RIGHT,
PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
PHPExcel_Style_Alignment::HORIZONTAL_CENTER_CONTINUOUS,
PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY
);
// Check if file exists
if (!file_exists($pFilename)) {
throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
}
$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;
}
}
foreach($xml->Styles[0] as $style) {
$style_ss = $style->attributes($namespaces['ss']);
$styleID = (string) $style_ss['ID'];
// echo 'Style ID = '.$styleID.'<br />';
if ($styleID == 'Default') {
$this->_styles['Default'] = array();
} else {
$this->_styles[$styleID] = $this->_styles['Default'];
}
foreach ($style as $styleType => $styleData) {
$styleAttributes = $styleData->attributes($namespaces['ss']);
// echo $styleType.'<br />';
switch ($styleType) {
case 'Alignment' :
foreach($styleAttributes as $styleAttributeKey => $styleAttributeValue) {
// echo $styleAttributeKey.' = '.$styleAttributeValue.'<br />';
$styleAttributeValue = (string) $styleAttributeValue;
switch ($styleAttributeKey) {
case 'Vertical' :
if (self::identifyFixedStyleValue($verticalAlignmentStyles,$styleAttributeValue)) {
$this->_styles[$styleID]['alignment']['vertical'] = $styleAttributeValue;
}
break;
case 'Horizontal' :
if (self::identifyFixedStyleValue($horizontalAlignmentStyles,$styleAttributeValue)) {
$this->_styles[$styleID]['alignment']['horizontal'] = $styleAttributeValue;
}
break;
case 'WrapText' :
$this->_styles[$styleID]['alignment']['wrap'] = true;
break;
}
}
break;
case 'Borders' :
foreach($styleData->Border as $borderStyle) {
$borderAttributes = $borderStyle->attributes($namespaces['ss']);
$thisBorder = array();
foreach($borderAttributes as $borderStyleKey => $borderStyleValue) {
// echo $borderStyleKey.' = '.$borderStyleValue.'<br />';
switch ($borderStyleKey) {
case 'LineStyle' :
$thisBorder['style'] = PHPExcel_Style_Border::BORDER_MEDIUM;
// $thisBorder['style'] = $borderStyleValue;
break;
case 'Weight' :
// $thisBorder['style'] = $borderStyleValue;
break;
case 'Position' :
$borderPosition = strtolower($borderStyleValue);
break;
case 'Color' :
$borderColour = substr($borderStyleValue,1);
$thisBorder['color']['rgb'] = $borderColour;
break;
}
}
if (count($thisBorder) > 0) {
if (($borderPosition == 'left') || ($borderPosition == 'right') || ($borderPosition == 'top') || ($borderPosition == 'bottom')) {
$this->_styles[$styleID]['borders'][$borderPosition] = $thisBorder;
}
}
}
break;
case 'Font' :
foreach($styleAttributes as $styleAttributeKey => $styleAttributeValue) {
// echo $styleAttributeKey.' = '.$styleAttributeValue.'<br />';
$styleAttributeValue = (string) $styleAttributeValue;
switch ($styleAttributeKey) {
case 'FontName' :
$this->_styles[$styleID]['font']['name'] = $styleAttributeValue;
break;
case 'Size' :
$this->_styles[$styleID]['font']['size'] = $styleAttributeValue;
break;
case 'Color' :
$this->_styles[$styleID]['font']['color']['rgb'] = substr($styleAttributeValue,1);
break;
case 'Bold' :
$this->_styles[$styleID]['font']['bold'] = true;
break;
case 'Italic' :
$this->_styles[$styleID]['font']['italic'] = true;
break;
case 'Underline' :
if (self::identifyFixedStyleValue($underlineStyles,$styleAttributeValue)) {
$this->_styles[$styleID]['font']['underline'] = $styleAttributeValue;
}
break;
}
}
break;
case 'Interior' :
foreach($styleAttributes as $styleAttributeKey => $styleAttributeValue) {
// echo $styleAttributeKey.' = '.$styleAttributeValue.'<br />';
switch ($styleAttributeKey) {
case 'Color' :
$this->_styles[$styleID]['fill']['color']['rgb'] = substr($styleAttributeValue,1);
break;
}
}
break;
case 'NumberFormat' :
foreach($styleAttributes as $styleAttributeKey => $styleAttributeValue) {
// echo $styleAttributeKey.' = '.$styleAttributeValue.'<br />';
$styleAttributeValue = str_replace($fromFormats,$toFormats,$styleAttributeValue);
switch ($styleAttributeValue) {
case 'Short Date' :
$styleAttributeValue = 'dd/mm/yyyy';
break;
}
if ($styleAttributeValue > '') {
$this->_styles[$styleID]['numberformat']['code'] = $styleAttributeValue;
}
}
break;
case 'Protection' :
foreach($styleAttributes as $styleAttributeKey => $styleAttributeValue) {
// echo $styleAttributeKey.' = '.$styleAttributeValue.'<br />';
}
break;
}
}
// print_r($this->_styles[$styleID]);
// echo '<hr />';
}
// echo '<hr />';
$worksheetID = 0;
foreach($xml->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;
}
// Create new Worksheet
$objPHPExcel->createSheet();
$objPHPExcel->setActiveSheetIndex($worksheetID);
if (isset($worksheet_ss['Name'])) {
$worksheetName = (string) $worksheet_ss['Name'];
$objPHPExcel->getActiveSheet()->setTitle($worksheetName);
}
$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);
}
$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'];
$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]);
}
}
++$columnID;
}
++$rowID;
}
++$worksheetID;
}
// Return
return $objPHPExcel;
}
/**
* Get sheet index
*
* @return int
*/
public function getSheetIndex() {
return $this->_sheetIndex;
}
/**
* 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 * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Reader * @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
@@ -32,69 +32,21 @@ if (!defined('PHPEXCEL_ROOT')) {
* @ignore * @ignore
*/ */
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../'); 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 */
require_once PHPEXCEL_ROOT . 'PHPExcel.php';
/** PHPExcel_Reader_IReader */
require_once PHPEXCEL_ROOT . 'PHPExcel/Reader/IReader.php';
/** PHPExcel_Worksheet */
require_once PHPEXCEL_ROOT . 'PHPExcel/Worksheet.php';
/** PHPExcel_Cell */
require_once PHPEXCEL_ROOT . 'PHPExcel/Cell.php';
/** PHPExcel_Style */
require_once PHPEXCEL_ROOT . 'PHPExcel/Style.php';
/** PHPExcel_Style_Borders */
require_once PHPEXCEL_ROOT . 'PHPExcel/Style/Borders.php';
/** PHPExcel_Style_Conditional */
require_once PHPEXCEL_ROOT . 'PHPExcel/Style/Conditional.php';
/** PHPExcel_Style_Protection */
require_once PHPEXCEL_ROOT . 'PHPExcel/Style/Protection.php';
/** PHPExcel_Style_NumberFormat */
require_once PHPEXCEL_ROOT . 'PHPExcel/Style/NumberFormat.php';
/** PHPExcel_Worksheet_BaseDrawing */
require_once PHPEXCEL_ROOT . 'PHPExcel/Worksheet/BaseDrawing.php';
/** PHPExcel_Worksheet_Drawing */
require_once PHPEXCEL_ROOT . 'PHPExcel/Worksheet/Drawing.php';
/** PHPExcel_Shared_Drawing */
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/Drawing.php';
/** PHPExcel_Shared_Date */
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/Date.php';
/** PHPExcel_Shared_File */
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/File.php';
/** PHPExcel_Shared_String */
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/String.php';
/** PHPExcel_ReferenceHelper */
require_once PHPEXCEL_ROOT . 'PHPExcel/ReferenceHelper.php';
/** PHPExcel_Reader_IReadFilter */
require_once PHPEXCEL_ROOT . 'PHPExcel/Reader/IReadFilter.php';
/** PHPExcel_Reader_DefaultReadFilter */
require_once PHPEXCEL_ROOT . 'PHPExcel/Reader/DefaultReadFilter.php';
/** /**
* PHPExcel_Reader_Excel2007 * PHPExcel_Reader_Excel2007
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Reader * @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
{ {
@@ -208,6 +160,11 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
*/ */
public function canRead($pFilename) public function canRead($pFilename)
{ {
// Check if zip class exists
if (!class_exists('ZipArchive')) {
return false;
}
// Check if file exists // Check if file exists
if (!file_exists($pFilename)) { if (!file_exists($pFilename)) {
throw new Exception("Could not open " . $pFilename . " for reading! File does not exist."); throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
@@ -217,7 +174,7 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
$zip = new ZipArchive; $zip = new ZipArchive;
if ($zip->open($pFilename) === true) { if ($zip->open($pFilename) === true) {
// check if it is an OOXML archive // check if it is an OOXML archive
$rels = simplexml_load_string($zip->getFromName("_rels/.rels")); $rels = simplexml_load_string($this->_getFromZipArchive($zip, "_rels/.rels"));
$zip->close(); $zip->close();
@@ -227,7 +184,6 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
return false; return false;
} }
private function _castToBool($c) { private function _castToBool($c) {
// echo 'Initial Cast to Boolean<br />'; // echo 'Initial Cast to Boolean<br />';
$value = isset($c->v) ? (string) $c->v : null; $value = isset($c->v) ? (string) $c->v : null;
@@ -300,6 +256,32 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
} }
} }
public function _getFromZipArchive(ZipArchive $archive, $fileName = '')
{
// Root-relative paths
if (strpos($fileName, '//') !== false)
{
$fileName = substr($fileName, strpos($fileName, '//') + 1);
}
$fileName = PHPExcel_Shared_File::realpath($fileName);
// Apache POI fixes
$contents = $archive->getFromName($fileName);
if ($contents === false)
{
$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;
}
/** /**
* Loads PHPExcel from file * Loads PHPExcel from file
@@ -324,14 +306,11 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
$zip = new ZipArchive; $zip = new ZipArchive;
$zip->open($pFilename); $zip->open($pFilename);
$rels = simplexml_load_string($zip->getFromName("_rels/.rels")); //~ http://schemas.openxmlformats.org/package/2006/relationships"); $rels = simplexml_load_string($this->_getFromZipArchive($zip, "_rels/.rels")); //~ http://schemas.openxmlformats.org/package/2006/relationships");
foreach ($rels->Relationship as $rel) { foreach ($rels->Relationship as $rel) {
switch ($rel["Type"]) { switch ($rel["Type"]) {
case "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties": case "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties":
$xmlCore = simplexml_load_string($zip->getFromName("{$rel['Target']}")); $xmlCore = simplexml_load_string($this->_getFromZipArchive($zip, "{$rel['Target']}"));
if ($xmlCore === false) { // Apache POI hack
$xmlCore = simplexml_load_string($zip->getFromName(substr("{$rel['Target']}", 1)));
}
if ($xmlCore) { if ($xmlCore) {
$xmlCore->registerXPathNamespace("dc", "http://purl.org/dc/elements/1.1/"); $xmlCore->registerXPathNamespace("dc", "http://purl.org/dc/elements/1.1/");
$xmlCore->registerXPathNamespace("dcterms", "http://purl.org/dc/terms/"); $xmlCore->registerXPathNamespace("dcterms", "http://purl.org/dc/terms/");
@@ -351,15 +330,12 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument": case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument":
$dir = dirname($rel["Target"]); $dir = dirname($rel["Target"]);
$relsWorkbook = simplexml_load_string($zip->getFromName("$dir/_rels/" . basename($rel["Target"]) . ".rels")); //~ http://schemas.openxmlformats.org/package/2006/relationships"); $relsWorkbook = simplexml_load_string($this->_getFromZipArchive($zip, "$dir/_rels/" . basename($rel["Target"]) . ".rels")); //~ http://schemas.openxmlformats.org/package/2006/relationships");
if ($relsWorkbook === false) { // Apache POI hack
$relsWorkbook = simplexml_load_string($zip->getFromName(substr("$dir/_rels/" . basename($rel["Target"]) . ".rels", 1))); //~ http://schemas.openxmlformats.org/package/2006/relationships");
}
$relsWorkbook->registerXPathNamespace("rel", "http://schemas.openxmlformats.org/package/2006/relationships"); $relsWorkbook->registerXPathNamespace("rel", "http://schemas.openxmlformats.org/package/2006/relationships");
$sharedStrings = array(); $sharedStrings = array();
$xpath = self::array_item($relsWorkbook->xpath("rel:Relationship[@Type='http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings']")); $xpath = self::array_item($relsWorkbook->xpath("rel:Relationship[@Type='http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings']"));
$xmlStrings = simplexml_load_string($zip->getFromName("$dir/$xpath[Target]")); //~ http://schemas.openxmlformats.org/spreadsheetml/2006/main"); $xmlStrings = simplexml_load_string($this->_getFromZipArchive($zip, "$dir/$xpath[Target]")); //~ http://schemas.openxmlformats.org/spreadsheetml/2006/main");
if (isset($xmlStrings) && isset($xmlStrings->si)) { if (isset($xmlStrings) && isset($xmlStrings->si)) {
foreach ($xmlStrings->si as $val) { foreach ($xmlStrings->si as $val) {
if (isset($val->t)) { if (isset($val->t)) {
@@ -380,7 +356,7 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
$styles = array(); $styles = array();
$cellStyles = array(); $cellStyles = array();
$xpath = self::array_item($relsWorkbook->xpath("rel:Relationship[@Type='http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles']")); $xpath = self::array_item($relsWorkbook->xpath("rel:Relationship[@Type='http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles']"));
$xmlStyles = simplexml_load_string($zip->getFromName("$dir/$xpath[Target]")); //~ http://schemas.openxmlformats.org/spreadsheetml/2006/main"); $xmlStyles = simplexml_load_string($this->_getFromZipArchive($zip, "$dir/$xpath[Target]")); //~ http://schemas.openxmlformats.org/spreadsheetml/2006/main");
$numFmts = null; $numFmts = null;
if ($xmlStyles && $xmlStyles->numFmts[0]) { if ($xmlStyles && $xmlStyles->numFmts[0]) {
$numFmts = $xmlStyles->numFmts[0]; $numFmts = $xmlStyles->numFmts[0];
@@ -415,12 +391,6 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
"border" => $xmlStyles->borders->border[intval($xf["borderId"])], "border" => $xmlStyles->borders->border[intval($xf["borderId"])],
"alignment" => $xf->alignment, "alignment" => $xf->alignment,
"protection" => $xf->protection, "protection" => $xf->protection,
"applyAlignment" => (isset($xf["applyAlignment"]) && ((string)$xf["applyAlignment"] == 'true' || (string)$xf["applyAlignment"] == '1')),
"applyBorder" => (isset($xf["applyBorder"]) && ((string)$xf["applyBorder"] == 'true' || (string)$xf["applyBorder"] == '1')),
"applyFill" => (isset($xf["applyFill"]) && ((string)$xf["applyFill"] == 'true' || (string)$xf["applyFill"] == '1')),
"applyFont" => (isset($xf["applyFont"]) && ((string)$xf["applyFont"] == 'true' || (string)$xf["applyFont"] == '1')),
"applyNumberFormat" => (isset($xf["applyNumberFormat"]) && ((string)$xf["applyNumberFormat"] == 'true' || (string)$xf["applyNumberFormat"] == '1')),
"applyProtection" => (isset($xf["applyProtection"]) && ((string)$xf["applyProtection"] == 'true' || (string)$xf["applyProtection"] == '1'))
); );
$styles[] = $style; $styles[] = $style;
@@ -448,12 +418,6 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
"border" => $xmlStyles->borders->border[intval($xf["borderId"])], "border" => $xmlStyles->borders->border[intval($xf["borderId"])],
"alignment" => $xf->alignment, "alignment" => $xf->alignment,
"protection" => $xf->protection, "protection" => $xf->protection,
"applyAlignment" => true,
"applyBorder" => true,
"applyFill" => true,
"applyFont" => true,
"applyNumberFormat" => true,
"applyProtection" => true
); );
$cellStyles[] = $cellStyle; $cellStyles[] = $cellStyle;
@@ -466,12 +430,16 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
$dxfs = array(); $dxfs = array();
if (!$this->_readDataOnly && $xmlStyles) { if (!$this->_readDataOnly && $xmlStyles) {
if ($xmlStyles->dxfs) {
foreach ($xmlStyles->dxfs->dxf as $dxf) { foreach ($xmlStyles->dxfs->dxf as $dxf) {
$style = new PHPExcel_Style; $style = new PHPExcel_Style;
$this->_readStyle($style, $dxf); $this->_readStyle($style, $dxf);
$dxfs[] = $style; $dxfs[] = $style;
} }
}
if ($xmlStyles->cellStyles)
{
foreach ($xmlStyles->cellStyles->cellStyle as $cellStyle) { foreach ($xmlStyles->cellStyles->cellStyle as $cellStyle) {
if (intval($cellStyle['builtinId']) == 0) { if (intval($cellStyle['builtinId']) == 0) {
if (isset($cellStyles[intval($cellStyle['xfId'])])) { if (isset($cellStyles[intval($cellStyle['xfId'])])) {
@@ -484,11 +452,10 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
} }
} }
} }
$xmlWorkbook = simplexml_load_string($zip->getFromName("{$rel['Target']}")); //~ http://schemas.openxmlformats.org/spreadsheetml/2006/main");
if ($xmlWorkbook === false) { // Apache POI hack
$xmlWorkbook = simplexml_load_string($zip->getFromName(substr("{$rel['Target']}", 1))); //~ http://schemas.openxmlformats.org/spreadsheetml/2006/main");
} }
$xmlWorkbook = simplexml_load_string($this->_getFromZipArchive($zip, "{$rel['Target']}")); //~ http://schemas.openxmlformats.org/spreadsheetml/2006/main");
// Set base date // Set base date
if ($xmlWorkbook->workbookPr) { if ($xmlWorkbook->workbookPr) {
PHPExcel_Shared_Date::setExcelCalendar(PHPExcel_Shared_Date::CALENDAR_WINDOWS_1900); PHPExcel_Shared_Date::setExcelCalendar(PHPExcel_Shared_Date::CALENDAR_WINDOWS_1900);
@@ -505,6 +472,8 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
$countSkippedSheets = 0; // keep track of number of skipped sheets $countSkippedSheets = 0; // keep track of number of skipped sheets
$mapSheetId = array(); // mapping of sheet ids from old to new $mapSheetId = array(); // mapping of sheet ids from old to new
if ($xmlWorkbook->sheets)
{
foreach ($xmlWorkbook->sheets->sheet as $eleSheet) { foreach ($xmlWorkbook->sheets->sheet as $eleSheet) {
++$oldSheetId; ++$oldSheetId;
@@ -523,10 +492,14 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
$docSheet = $excel->createSheet(); $docSheet = $excel->createSheet();
$docSheet->setTitle((string) $eleSheet["name"]); $docSheet->setTitle((string) $eleSheet["name"]);
$fileWorksheet = $worksheets[(string) self::array_item($eleSheet->attributes("http://schemas.openxmlformats.org/officeDocument/2006/relationships"), "id")]; $fileWorksheet = $worksheets[(string) self::array_item($eleSheet->attributes("http://schemas.openxmlformats.org/officeDocument/2006/relationships"), "id")];
$xmlSheet = simplexml_load_string($zip->getFromName("$dir/$fileWorksheet")); //~ http://schemas.openxmlformats.org/spreadsheetml/2006/main"); $xmlSheet = simplexml_load_string($this->_getFromZipArchive($zip, "$dir/$fileWorksheet")); //~ http://schemas.openxmlformats.org/spreadsheetml/2006/main");
$sharedFormulas = array(); $sharedFormulas = array();
if (isset($eleSheet["state"]) && (string) $eleSheet["state"] != '') {
$docSheet->setSheetState( (string) $eleSheet["state"] );
}
if (isset($xmlSheet->sheetViews) && isset($xmlSheet->sheetViews->sheetView)) { if (isset($xmlSheet->sheetViews) && isset($xmlSheet->sheetViews->sheetView)) {
if (isset($xmlSheet->sheetViews->sheetView['zoomScale'])) { if (isset($xmlSheet->sheetViews->sheetView['zoomScale'])) {
$docSheet->getSheetView()->setZoomScale( intval($xmlSheet->sheetViews->sheetView['zoomScale']) ); $docSheet->getSheetView()->setZoomScale( intval($xmlSheet->sheetViews->sheetView['zoomScale']) );
@@ -540,6 +513,10 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
$docSheet->setShowGridLines((string)$xmlSheet->sheetViews->sheetView['showGridLines'] ? true : false); $docSheet->setShowGridLines((string)$xmlSheet->sheetViews->sheetView['showGridLines'] ? true : false);
} }
if (isset($xmlSheet->sheetViews->sheetView['showRowColHeaders'])) {
$docSheet->setShowRowColHeaders((string)$xmlSheet->sheetViews->sheetView['showRowColHeaders'] ? true : false);
}
if (isset($xmlSheet->sheetViews->sheetView['rightToLeft'])) { if (isset($xmlSheet->sheetViews->sheetView['rightToLeft'])) {
$docSheet->setRightToLeft((string)$xmlSheet->sheetViews->sheetView['rightToLeft'] ? true : false); $docSheet->setRightToLeft((string)$xmlSheet->sheetViews->sheetView['rightToLeft'] ? true : false);
} }
@@ -562,6 +539,22 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
$docSheet->freezePaneByColumnAndRow($xSplit, $ySplit); $docSheet->freezePaneByColumnAndRow($xSplit, $ySplit);
} }
} }
if (isset($xmlSheet->sheetViews->sheetView->selection)) {
if (isset($xmlSheet->sheetViews->sheetView->selection['sqref'])) {
$sqref = (string)$xmlSheet->sheetViews->sheetView->selection['sqref'];
$sqref = explode(' ', $sqref);
$sqref = $sqref[0];
$docSheet->setSelectedCells($sqref);
}
}
}
if (isset($xmlSheet->sheetPr) && isset($xmlSheet->sheetPr->tabColor)) {
if (isset($xmlSheet->sheetPr->tabColor['rgb'])) {
$docSheet->getTabColor()->setARGB( (string)$xmlSheet->sheetPr->tabColor['rgb'] );
}
} }
if (isset($xmlSheet->sheetPr) && isset($xmlSheet->sheetPr->outlinePr)) { if (isset($xmlSheet->sheetPr) && isset($xmlSheet->sheetPr->outlinePr)) {
@@ -578,6 +571,14 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
} }
} }
if (isset($xmlSheet->sheetPr) && isset($xmlSheet->sheetPr->pageSetUpPr)) {
if (isset($xmlSheet->sheetPr->pageSetUpPr['fitToPage']) && $xmlSheet->sheetPr->pageSetUpPr['fitToPage'] == false) {
$docSheet->getPageSetup()->setFitToPage(false);
} else {
$docSheet->getPageSetup()->setFitToPage(true);
}
}
if (isset($xmlSheet->sheetFormatPr)) { if (isset($xmlSheet->sheetFormatPr)) {
if (isset($xmlSheet->sheetFormatPr['customHeight']) && ((string)$xmlSheet->sheetFormatPr['customHeight'] == '1' || strtolower((string)$xmlSheet->sheetFormatPr['customHeight']) == 'true') && isset($xmlSheet->sheetFormatPr['defaultRowHeight'])) { if (isset($xmlSheet->sheetFormatPr['customHeight']) && ((string)$xmlSheet->sheetFormatPr['customHeight'] == '1' || strtolower((string)$xmlSheet->sheetFormatPr['customHeight']) == 'true') && isset($xmlSheet->sheetFormatPr['defaultRowHeight'])) {
$docSheet->getDefaultRowDimension()->setRowHeight( (float)$xmlSheet->sheetFormatPr['defaultRowHeight'] ); $docSheet->getDefaultRowDimension()->setRowHeight( (float)$xmlSheet->sheetFormatPr['defaultRowHeight'] );
@@ -590,8 +591,11 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
if (isset($xmlSheet->cols) && !$this->_readDataOnly) { if (isset($xmlSheet->cols) && !$this->_readDataOnly) {
foreach ($xmlSheet->cols->col as $col) { foreach ($xmlSheet->cols->col as $col) {
for ($i = intval($col["min"]) - 1; $i < intval($col["max"]); ++$i) { for ($i = intval($col["min"]) - 1; $i < intval($col["max"]); ++$i) {
if ($col["style"] && !$this->_readDataOnly) {
$docSheet->getColumnDimension(PHPExcel_Cell::stringFromColumnIndex($i))->setXfIndex(intval($col["style"]));
}
if ($col["bestFit"]) { if ($col["bestFit"]) {
$docSheet->getColumnDimension(PHPExcel_Cell::stringFromColumnIndex($i))->setAutoSize(true); //$docSheet->getColumnDimension(PHPExcel_Cell::stringFromColumnIndex($i))->setAutoSize(true);
} }
if ($col["hidden"]) { if ($col["hidden"]) {
$docSheet->getColumnDimension(PHPExcel_Cell::stringFromColumnIndex($i))->setVisible(false); $docSheet->getColumnDimension(PHPExcel_Cell::stringFromColumnIndex($i))->setVisible(false);
@@ -642,6 +646,9 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
if ($row["outlineLevel"] > 0) { if ($row["outlineLevel"] > 0) {
$docSheet->getRowDimension(intval($row["r"]))->setOutlineLevel(intval($row["outlineLevel"])); $docSheet->getRowDimension(intval($row["r"]))->setOutlineLevel(intval($row["outlineLevel"]));
} }
if ($row["s"] && !$this->_readDataOnly) {
$docSheet->getRowDimension(intval($row["r"]))->setXfIndex(intval($row["s"]));
}
foreach ($row->c as $c) { foreach ($row->c as $c) {
$r = (string) $c["r"]; $r = (string) $c["r"];
@@ -654,7 +661,7 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
$coordinates = PHPExcel_Cell::coordinateFromString($r); $coordinates = PHPExcel_Cell::coordinateFromString($r);
if (!$this->getReadFilter()->readCell($coordinates[0], $coordinates[1], $docSheet->getTitle())) { if (!$this->getReadFilter()->readCell($coordinates[0], $coordinates[1], $docSheet->getTitle())) {
break; continue;
} }
} }
@@ -733,27 +740,23 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
$value = $value->getPlainText(); $value = $value->getPlainText();
} }
$cell = $docSheet->getCell($r);
// Assign value // Assign value
if ($cellDataType != '') { if ($cellDataType != '') {
$docSheet->setCellValueExplicit($r, $value, $cellDataType); $cell->setValueExplicit($value, $cellDataType);
} else { } else {
$docSheet->setCellValue($r, $value); $cell->setValue($value);
} }
if (!is_null($calculatedValue)) { if (!is_null($calculatedValue)) {
$docSheet->getCell($r)->setCalculatedValue($calculatedValue); $cell->setCalculatedValue($calculatedValue);
} }
// Style information? // Style information?
if ($c["s"] && !$this->_readDataOnly) { if ($c["s"] && !$this->_readDataOnly) {
// no style index means 0, it seems // no style index means 0, it seems
$docSheet->getCell($r)->setXfIndex(isset($styles[intval($c["s"])]) ? $cell->setXfIndex(isset($styles[intval($c["s"])]) ?
intval($c["s"]) : 0); intval($c["s"]) : 0);
} }
// Set rich text parent
if ($value instanceof PHPExcel_RichText && !$this->_readDataOnly) {
$value->setParent($docSheet->getCell($r));
}
} }
} }
} }
@@ -766,7 +769,8 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
( (
(string)$cfRule["type"] == PHPExcel_Style_Conditional::CONDITION_NONE || (string)$cfRule["type"] == PHPExcel_Style_Conditional::CONDITION_NONE ||
(string)$cfRule["type"] == PHPExcel_Style_Conditional::CONDITION_CELLIS || (string)$cfRule["type"] == PHPExcel_Style_Conditional::CONDITION_CELLIS ||
(string)$cfRule["type"] == PHPExcel_Style_Conditional::CONDITION_CONTAINSTEXT (string)$cfRule["type"] == PHPExcel_Style_Conditional::CONDITION_CONTAINSTEXT ||
(string)$cfRule["type"] == PHPExcel_Style_Conditional::CONDITION_EXPRESSION
) && isset($dxfs[intval($cfRule["dxfId"])]) ) && isset($dxfs[intval($cfRule["dxfId"])])
) { ) {
$conditionals[(string) $conditional["sqref"]][intval($cfRule["priority"])] = $cfRule; $conditionals[(string) $conditional["sqref"]][intval($cfRule["priority"])] = $cfRule;
@@ -852,13 +856,17 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
$docPageSetup->setPaperSize(intval($xmlSheet->pageSetup["paperSize"])); $docPageSetup->setPaperSize(intval($xmlSheet->pageSetup["paperSize"]));
} }
if (isset($xmlSheet->pageSetup["scale"])) { if (isset($xmlSheet->pageSetup["scale"])) {
$docPageSetup->setScale(intval($xmlSheet->pageSetup["scale"])); $docPageSetup->setScale(intval($xmlSheet->pageSetup["scale"]), false);
} }
if (isset($xmlSheet->pageSetup["fitToHeight"]) && intval($xmlSheet->pageSetup["fitToHeight"]) > 0) { if (isset($xmlSheet->pageSetup["fitToHeight"]) && intval($xmlSheet->pageSetup["fitToHeight"]) >= 0) {
$docPageSetup->setFitToHeight(intval($xmlSheet->pageSetup["fitToHeight"])); $docPageSetup->setFitToHeight(intval($xmlSheet->pageSetup["fitToHeight"]), false);
} }
if (isset($xmlSheet->pageSetup["fitToWidth"]) && intval($xmlSheet->pageSetup["fitToWidth"]) > 0) { if (isset($xmlSheet->pageSetup["fitToWidth"]) && intval($xmlSheet->pageSetup["fitToWidth"]) >= 0) {
$docPageSetup->setFitToWidth(intval($xmlSheet->pageSetup["fitToWidth"])); $docPageSetup->setFitToWidth(intval($xmlSheet->pageSetup["fitToWidth"]), false);
}
if (isset($xmlSheet->pageSetup["firstPageNumber"]) && isset($xmlSheet->pageSetup["useFirstPageNumber"]) &&
((string)$xmlSheet->pageSetup["useFirstPageNumber"] == 'true' || (string)$xmlSheet->pageSetup["useFirstPageNumber"] == '1')) {
$docPageSetup->setFirstPageNumber(intval($xmlSheet->pageSetup["firstPageNumber"]));
} }
} }
@@ -917,9 +925,12 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
foreach ($xmlSheet->dataValidations->dataValidation as $dataValidation) { foreach ($xmlSheet->dataValidations->dataValidation as $dataValidation) {
// Uppercase coordinate // Uppercase coordinate
$range = strtoupper($dataValidation["sqref"]); $range = strtoupper($dataValidation["sqref"]);
$rangeSet = explode(' ',$range);
foreach($rangeSet as $range) {
$stRange = $docSheet->shrinkRangeToFit($range);
// Extract all cell references in $range // Extract all cell references in $range
$aReferences = PHPExcel_Cell::extractAllCellReferencesInRange($range); $aReferences = PHPExcel_Cell::extractAllCellReferencesInRange($stRange);
foreach ($aReferences as $reference) { foreach ($aReferences as $reference) {
// Create validation // Create validation
$docValidation = $docSheet->getCell($reference)->getDataValidation(); $docValidation = $docSheet->getCell($reference)->getDataValidation();
@@ -939,13 +950,14 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
} }
} }
} }
}
// Add hyperlinks // Add hyperlinks
$hyperlinks = array(); $hyperlinks = array();
if (!$this->_readDataOnly) { if (!$this->_readDataOnly) {
// Locate hyperlink relations // Locate hyperlink relations
if ($zip->locateName(dirname("$dir/$fileWorksheet") . "/_rels/" . basename($fileWorksheet) . ".rels")) { if ($zip->locateName(dirname("$dir/$fileWorksheet") . "/_rels/" . basename($fileWorksheet) . ".rels")) {
$relsWorksheet = simplexml_load_string($zip->getFromName( dirname("$dir/$fileWorksheet") . "/_rels/" . basename($fileWorksheet) . ".rels") ); //~ http://schemas.openxmlformats.org/package/2006/relationships"); $relsWorksheet = simplexml_load_string($this->_getFromZipArchive($zip, dirname("$dir/$fileWorksheet") . "/_rels/" . basename($fileWorksheet) . ".rels") ); //~ http://schemas.openxmlformats.org/package/2006/relationships");
foreach ($relsWorksheet->Relationship as $ele) { foreach ($relsWorksheet->Relationship as $ele) {
if ($ele["Type"] == "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink") { if ($ele["Type"] == "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink") {
$hyperlinks[(string)$ele["Id"]] = (string)$ele["Target"]; $hyperlinks[(string)$ele["Id"]] = (string)$ele["Target"];
@@ -953,23 +965,24 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
} }
} }
// Loop trough hyperlinks // Loop through hyperlinks
if ($xmlSheet && $xmlSheet->hyperlinks) { if ($xmlSheet && $xmlSheet->hyperlinks) {
foreach ($xmlSheet->hyperlinks->hyperlink as $hyperlink) { foreach ($xmlSheet->hyperlinks->hyperlink as $hyperlink) {
// Link url // Link url
$linkRel = $hyperlink->attributes('http://schemas.openxmlformats.org/officeDocument/2006/relationships'); $linkRel = $hyperlink->attributes('http://schemas.openxmlformats.org/officeDocument/2006/relationships');
foreach (PHPExcel_Cell::extractAllCellReferencesInRange($hyperlink['ref']) as $cellReference) { foreach (PHPExcel_Cell::extractAllCellReferencesInRange($hyperlink['ref']) as $cellReference) {
$cell = $docSheet->getCell( $cellReference );
if (isset($linkRel['id'])) { if (isset($linkRel['id'])) {
$docSheet->getCell( $cellReference )->getHyperlink()->setUrl( $hyperlinks[ (string)$linkRel['id'] ] ); $cell->getHyperlink()->setUrl( $hyperlinks[ (string)$linkRel['id'] ] );
} }
if (isset($hyperlink['location'])) { if (isset($hyperlink['location'])) {
$docSheet->getCell( $cellReference )->getHyperlink()->setUrl( 'sheet://' . (string)$hyperlink['location'] ); $cell->getHyperlink()->setUrl( 'sheet://' . (string)$hyperlink['location'] );
} }
// Tooltip // Tooltip
if (isset($hyperlink['tooltip'])) { if (isset($hyperlink['tooltip'])) {
$docSheet->getCell( $cellReference )->getHyperlink()->setTooltip( (string)$hyperlink['tooltip'] ); $cell->getHyperlink()->setTooltip( (string)$hyperlink['tooltip'] );
} }
} }
} }
@@ -982,7 +995,7 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
if (!$this->_readDataOnly) { if (!$this->_readDataOnly) {
// Locate comment relations // Locate comment relations
if ($zip->locateName(dirname("$dir/$fileWorksheet") . "/_rels/" . basename($fileWorksheet) . ".rels")) { if ($zip->locateName(dirname("$dir/$fileWorksheet") . "/_rels/" . basename($fileWorksheet) . ".rels")) {
$relsWorksheet = simplexml_load_string($zip->getFromName( dirname("$dir/$fileWorksheet") . "/_rels/" . basename($fileWorksheet) . ".rels") ); //~ http://schemas.openxmlformats.org/package/2006/relationships"); $relsWorksheet = simplexml_load_string($this->_getFromZipArchive($zip, dirname("$dir/$fileWorksheet") . "/_rels/" . basename($fileWorksheet) . ".rels") ); //~ http://schemas.openxmlformats.org/package/2006/relationships");
foreach ($relsWorksheet->Relationship as $ele) { foreach ($relsWorksheet->Relationship as $ele) {
if ($ele["Type"] == "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments") { if ($ele["Type"] == "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments") {
$comments[(string)$ele["Id"]] = (string)$ele["Target"]; $comments[(string)$ele["Id"]] = (string)$ele["Target"];
@@ -993,32 +1006,32 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
} }
} }
// Loop trough comments // Loop through comments
foreach ($comments as $relName => $relPath) { foreach ($comments as $relName => $relPath) {
// Load comments file // Load comments file
$relPath = PHPExcel_Shared_File::realpath(dirname("$dir/$fileWorksheet") . "/" . $relPath); $relPath = PHPExcel_Shared_File::realpath(dirname("$dir/$fileWorksheet") . "/" . $relPath);
$commentsFile = simplexml_load_string($zip->getFromName($relPath) ); $commentsFile = simplexml_load_string($this->_getFromZipArchive($zip, $relPath) );
// Utility variables // Utility variables
$authors = array(); $authors = array();
// Loop trough authors // Loop through authors
foreach ($commentsFile->authors->author as $author) { foreach ($commentsFile->authors->author as $author) {
$authors[] = (string)$author; $authors[] = (string)$author;
} }
// Loop trough contents // Loop through contents
foreach ($commentsFile->commentList->comment as $comment) { foreach ($commentsFile->commentList->comment as $comment) {
$docSheet->getComment( (string)$comment['ref'] )->setAuthor( $authors[(string)$comment['authorId']] ); $docSheet->getComment( (string)$comment['ref'] )->setAuthor( $authors[(string)$comment['authorId']] );
$docSheet->getComment( (string)$comment['ref'] )->setText( $this->_parseRichText($comment->text) ); $docSheet->getComment( (string)$comment['ref'] )->setText( $this->_parseRichText($comment->text) );
} }
} }
// Loop trough VML comments // Loop through VML comments
foreach ($vmlComments as $relName => $relPath) { foreach ($vmlComments as $relName => $relPath) {
// Load VML comments file // Load VML comments file
$relPath = PHPExcel_Shared_File::realpath(dirname("$dir/$fileWorksheet") . "/" . $relPath); $relPath = PHPExcel_Shared_File::realpath(dirname("$dir/$fileWorksheet") . "/" . $relPath);
$vmlCommentsFile = simplexml_load_string( $zip->getFromName($relPath) ); $vmlCommentsFile = simplexml_load_string( $this->_getFromZipArchive($zip, $relPath) );
$vmlCommentsFile->registerXPathNamespace('v', 'urn:schemas-microsoft-com:vml'); $vmlCommentsFile->registerXPathNamespace('v', 'urn:schemas-microsoft-com:vml');
$shapes = $vmlCommentsFile->xpath('//v:shape'); $shapes = $vmlCommentsFile->xpath('//v:shape');
@@ -1032,7 +1045,7 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
$row = null; $row = null;
$clientData = $shape->xpath('.//x:ClientData'); $clientData = $shape->xpath('.//x:ClientData');
if (is_array($clientData)) { if (is_array($clientData) && count($clientData) > 0) {
$clientData = $clientData[0]; $clientData = $clientData[0];
if ( isset($clientData['ObjectType']) && (string)$clientData['ObjectType'] == 'Note' ) { if ( isset($clientData['ObjectType']) && (string)$clientData['ObjectType'] == 'Note' ) {
@@ -1069,7 +1082,7 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
// Header/footer images // Header/footer images
if ($xmlSheet && $xmlSheet->legacyDrawingHF && !$this->_readDataOnly) { if ($xmlSheet && $xmlSheet->legacyDrawingHF && !$this->_readDataOnly) {
if ($zip->locateName(dirname("$dir/$fileWorksheet") . "/_rels/" . basename($fileWorksheet) . ".rels")) { if ($zip->locateName(dirname("$dir/$fileWorksheet") . "/_rels/" . basename($fileWorksheet) . ".rels")) {
$relsWorksheet = simplexml_load_string($zip->getFromName( dirname("$dir/$fileWorksheet") . "/_rels/" . basename($fileWorksheet) . ".rels") ); //~ http://schemas.openxmlformats.org/package/2006/relationships"); $relsWorksheet = simplexml_load_string($this->_getFromZipArchive($zip, dirname("$dir/$fileWorksheet") . "/_rels/" . basename($fileWorksheet) . ".rels") ); //~ http://schemas.openxmlformats.org/package/2006/relationships");
$vmlRelationship = ''; $vmlRelationship = '';
foreach ($relsWorksheet->Relationship as $ele) { foreach ($relsWorksheet->Relationship as $ele) {
@@ -1080,7 +1093,7 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
if ($vmlRelationship != '') { if ($vmlRelationship != '') {
// Fetch linked images // Fetch linked images
$relsVML = simplexml_load_string($zip->getFromName( dirname($vmlRelationship) . '/_rels/' . basename($vmlRelationship) . '.rels' )); //~ http://schemas.openxmlformats.org/package/2006/relationships"); $relsVML = simplexml_load_string($this->_getFromZipArchive($zip, dirname($vmlRelationship) . '/_rels/' . basename($vmlRelationship) . '.rels' )); //~ http://schemas.openxmlformats.org/package/2006/relationships");
$drawings = array(); $drawings = array();
foreach ($relsVML->Relationship as $ele) { foreach ($relsVML->Relationship as $ele) {
if ($ele["Type"] == "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image") { if ($ele["Type"] == "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image") {
@@ -1089,7 +1102,7 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
} }
// Fetch VML document // Fetch VML document
$vmlDrawing = simplexml_load_string($zip->getFromName($vmlRelationship)); $vmlDrawing = simplexml_load_string($this->_getFromZipArchive($zip, $vmlRelationship));
$vmlDrawing->registerXPathNamespace('v', 'urn:schemas-microsoft-com:vml'); $vmlDrawing->registerXPathNamespace('v', 'urn:schemas-microsoft-com:vml');
$hfImages = array(); $hfImages = array();
@@ -1126,7 +1139,7 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
// TODO: Make sure drawings and graph are loaded differently! // TODO: Make sure drawings and graph are loaded differently!
if ($zip->locateName(dirname("$dir/$fileWorksheet") . "/_rels/" . basename($fileWorksheet) . ".rels")) { if ($zip->locateName(dirname("$dir/$fileWorksheet") . "/_rels/" . basename($fileWorksheet) . ".rels")) {
$relsWorksheet = simplexml_load_string($zip->getFromName( dirname("$dir/$fileWorksheet") . "/_rels/" . basename($fileWorksheet) . ".rels") ); //~ http://schemas.openxmlformats.org/package/2006/relationships"); $relsWorksheet = simplexml_load_string($this->_getFromZipArchive($zip, dirname("$dir/$fileWorksheet") . "/_rels/" . basename($fileWorksheet) . ".rels") ); //~ http://schemas.openxmlformats.org/package/2006/relationships");
$drawings = array(); $drawings = array();
foreach ($relsWorksheet->Relationship as $ele) { foreach ($relsWorksheet->Relationship as $ele) {
if ($ele["Type"] == "http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing") { if ($ele["Type"] == "http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing") {
@@ -1136,7 +1149,7 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
if ($xmlSheet->drawing && !$this->_readDataOnly) { if ($xmlSheet->drawing && !$this->_readDataOnly) {
foreach ($xmlSheet->drawing as $drawing) { foreach ($xmlSheet->drawing as $drawing) {
$fileDrawing = $drawings[(string) self::array_item($drawing->attributes("http://schemas.openxmlformats.org/officeDocument/2006/relationships"), "id")]; $fileDrawing = $drawings[(string) self::array_item($drawing->attributes("http://schemas.openxmlformats.org/officeDocument/2006/relationships"), "id")];
$relsDrawing = simplexml_load_string($zip->getFromName( dirname($fileDrawing) . "/_rels/" . basename($fileDrawing) . ".rels") ); //~ http://schemas.openxmlformats.org/package/2006/relationships"); $relsDrawing = simplexml_load_string($this->_getFromZipArchive($zip, dirname($fileDrawing) . "/_rels/" . basename($fileDrawing) . ".rels") ); //~ http://schemas.openxmlformats.org/package/2006/relationships");
$images = array(); $images = array();
if ($relsDrawing && $relsDrawing->Relationship) { if ($relsDrawing && $relsDrawing->Relationship) {
@@ -1146,7 +1159,7 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
} }
} }
} }
$xmlDrawing = simplexml_load_string($zip->getFromName($fileDrawing))->children("http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing"); $xmlDrawing = simplexml_load_string($this->_getFromZipArchive($zip, $fileDrawing))->children("http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing");
if ($xmlDrawing->oneCellAnchor) { if ($xmlDrawing->oneCellAnchor) {
foreach ($xmlDrawing->oneCellAnchor as $oneCellAnchor) { foreach ($xmlDrawing->oneCellAnchor as $oneCellAnchor) {
@@ -1221,7 +1234,7 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
} }
} }
// Loop trough definedNames // Loop through definedNames
if ($xmlWorkbook->definedNames) { if ($xmlWorkbook->definedNames) {
foreach ($xmlWorkbook->definedNames->definedName as $definedName) { foreach ($xmlWorkbook->definedNames->definedName as $definedName) {
// Extract range // Extract range
@@ -1248,31 +1261,18 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
$extractedRange = explode(',', $extractedRange); $extractedRange = explode(',', $extractedRange);
// Set print titles // Set print titles
if (isset($extractedRange[0])) { foreach ($extractedRange as $range) {
$range = explode(':', $extractedRange[0]); $matches = array();
if (PHPExcel_Worksheet::extractSheetTitle($range[0]) != '') // check for repeating columns, e g. 'A:A' or 'A:D'
$range[0] = PHPExcel_Worksheet::extractSheetTitle($range[0]); if (preg_match('/^([A-Z]+)\:([A-Z]+)$/', $range, $matches)) {
$range[0] = str_replace('$', '', $range[0]); $docSheet->getPageSetup()->setColumnsToRepeatAtLeft(array($matches[1], $matches[2]));
if (PHPExcel_Worksheet::extractSheetTitle($range[1]) != '') }
$range[1] = PHPExcel_Worksheet::extractSheetTitle($range[1]); // check for repeating rows, e.g. '1:1' or '1:5'
$range[1] = str_replace('$', '', $range[1]); elseif (preg_match('/^(\d+)\:(\d+)$/', $range, $matches)) {
$docSheet->getPageSetup()->setRowsToRepeatAtTop(array($matches[1], $matches[2]));
$docSheet->getPageSetup()->setColumnsToRepeatAtLeft( $range );
} }
if (isset($extractedRange[1])) {
$range = explode(':', $extractedRange[1]);
if (PHPExcel_Worksheet::extractSheetTitle($range[0]) != '')
$range[0] = PHPExcel_Worksheet::extractSheetTitle($range[0]);
$range[0] = str_replace('$', '', $range[0]);
if (PHPExcel_Worksheet::extractSheetTitle($range[1]) != '')
$range[1] = PHPExcel_Worksheet::extractSheetTitle($range[1]);
$range[1] = str_replace('$', '', $range[1]);
$docSheet->getPageSetup()->setRowsToRepeatAtTop( $range );
} }
break; break;
case '_xlnm.Print_Area': case '_xlnm.Print_Area':
@@ -1283,13 +1283,55 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
break; break;
default: default:
$range = explode('!', $extractedRange);
$extractedRange = isset($range[1]) ? $range[1] : $range[0];
$excel->addNamedRange( new PHPExcel_NamedRange((string)$definedName['name'], $docSheet, $extractedRange, true) );
break; break;
} }
} else { }
}
}
// Next sheet id
++$sheetId;
}
// Loop through definedNames
if ($xmlWorkbook->definedNames) {
foreach ($xmlWorkbook->definedNames->definedName as $definedName) {
// Extract range
$extractedRange = (string)$definedName;
$extractedRange = preg_replace('/\'(\w+)\'\!/', '', $extractedRange);
$extractedRange = str_replace('$', '', $extractedRange);
// Valid range?
if (stripos((string)$definedName, '#REF!') !== false || $extractedRange == '') {
continue;
}
// Some definedNames are only applicable if we are on the same sheet...
if ((string)$definedName['localSheetId'] != '') {
// Local defined name
// Switch on type
switch ((string)$definedName['name']) {
case '_xlnm._FilterDatabase':
case '_xlnm.Print_Titles':
case '_xlnm.Print_Area':
break;
default:
$range = explode('!', (string)$definedName);
if (count($range) == 2) {
$range[0] = str_replace("''", "'", $range[0]);
$range[0] = str_replace("'", "", $range[0]);
if ($worksheet = $docSheet->getParent()->getSheetByName($range[0])) {
$extractedRange = str_replace('$', '', $range[1]);
$scope = $docSheet->getParent()->getSheet((string)$definedName['localSheetId']);
$excel->addNamedRange( new PHPExcel_NamedRange((string)$definedName['name'], $worksheet, $extractedRange, true, $scope) );
}
}
break;
}
} else if (!isset($definedName['localSheetId'])) {
// "Global" definedNames // "Global" definedNames
$locatedSheet = null; $locatedSheet = null;
$extractedSheetName = ''; $extractedSheetName = '';
@@ -1312,9 +1354,6 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
} }
} }
} }
// Next sheet id
++$sheetId;
} }
if (!$this->_readDataOnly) { if (!$this->_readDataOnly) {
@@ -1322,9 +1361,13 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
$activeTab = intval($xmlWorkbook->bookViews->workbookView["activeTab"]); // refers to old sheet index $activeTab = intval($xmlWorkbook->bookViews->workbookView["activeTab"]); // refers to old sheet index
// keep active sheet index if sheet is still loaded, else first sheet is set as the active // keep active sheet index if sheet is still loaded, else first sheet is set as the active
if ($mapSheetId[$activeTab] !== null) { if (isset($mapSheetId[$activeTab]) && $mapSheetId[$activeTab] !== null) {
$excel->setActiveSheetIndex($mapSheetId[$activeTab]); $excel->setActiveSheetIndex($mapSheetId[$activeTab]);
} else { } else {
if ($excel->getSheetCount() == 0)
{
$excel->createSheet();
}
$excel->setActiveSheetIndex(0); $excel->setActiveSheetIndex(0);
} }
} }
@@ -1346,20 +1389,22 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
private function _readStyle($docStyle, $style) { private function _readStyle($docStyle, $style) {
// format code // format code
if ($style->applyNumberFormat) $docStyle->getNumberFormat()->setFormatCode($style->numFmt); if (isset($style->numFmt)) {
$docStyle->getNumberFormat()->setFormatCode($style->numFmt);
}
// font // font
if (isset($style->font)) { if (isset($style->font)) {
$docStyle->getFont()->setName((string) $style->font->name["val"]); $docStyle->getFont()->setName((string) $style->font->name["val"]);
$docStyle->getFont()->setSize((string) $style->font->sz["val"]); $docStyle->getFont()->setSize((string) $style->font->sz["val"]);
if (isset($style->font->b)) { if (isset($style->font->b)) {
$docStyle->getFont()->setBold(!isset($style->font->b["val"]) || $style->font->b["val"] == 'true'); $docStyle->getFont()->setBold(!isset($style->font->b["val"]) || $style->font->b["val"] == 'true' || $style->font->b["val"] == '1');
} }
if (isset($style->font->i)) { if (isset($style->font->i)) {
$docStyle->getFont()->setItalic(!isset($style->font->i["val"]) || $style->font->i["val"] == 'true'); $docStyle->getFont()->setItalic(!isset($style->font->i["val"]) || $style->font->i["val"] == 'true' || $style->font->i["val"] == '1');
} }
if (isset($style->font->strike)) { if (isset($style->font->strike)) {
$docStyle->getFont()->setStrikethrough(!isset($style->font->strike["val"]) || $style->font->strike["val"] == 'true'); $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($this->_readColor($style->font->color));
@@ -1381,7 +1426,7 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
} }
// fill // fill
if (isset($style->fill) && ($style->applyFill || $style instanceof SimpleXMLElement)) { if (isset($style->fill)) {
if ($style->fill->gradientFill) { if ($style->fill->gradientFill) {
$gradientFill = $style->fill->gradientFill[0]; $gradientFill = $style->fill->gradientFill[0];
$docStyle->getFill()->setFillType((string) $gradientFill["type"]); $docStyle->getFill()->setFillType((string) $gradientFill["type"]);
@@ -1404,11 +1449,23 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
} }
// border // border
if (isset($style->border) && ($style->applyBorder || $style instanceof SimpleXMLElement)) { if (isset($style->border)) {
if ($style->border["diagonalUp"] == 'true') { $diagonalUp = false;
$diagonalDown = false;
if ($style->border["diagonalUp"] == 'true' || $style->border["diagonalUp"] == 1) {
$diagonalUp = true;
}
if ($style->border["diagonalDown"] == 'true' || $style->border["diagonalDown"] == 1) {
$diagonalDown = true;
}
if ($diagonalUp == false && $diagonalDown == false) {
$docStyle->getBorders()->setDiagonalDirection(PHPExcel_Style_Borders::DIAGONAL_NONE);
} elseif ($diagonalUp == true && $diagonalDown == false) {
$docStyle->getBorders()->setDiagonalDirection(PHPExcel_Style_Borders::DIAGONAL_UP); $docStyle->getBorders()->setDiagonalDirection(PHPExcel_Style_Borders::DIAGONAL_UP);
} elseif ($style->border["diagonalDown"] == 'true') { } elseif ($diagonalUp == false && $diagonalDown == true) {
$docStyle->getBorders()->setDiagonalDirection(PHPExcel_Style_Borders::DIAGONAL_DOWN); $docStyle->getBorders()->setDiagonalDirection(PHPExcel_Style_Borders::DIAGONAL_DOWN);
} 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()->getLeft(), $style->border->left);
$this->_readBorder($docStyle->getBorders()->getRight(), $style->border->right); $this->_readBorder($docStyle->getBorders()->getRight(), $style->border->right);
@@ -1418,7 +1475,7 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
} }
// alignment // alignment
if (isset($style->alignment) && ($style->applyAlignment || $style instanceof SimpleXMLElement)) { if (isset($style->alignment)) {
$docStyle->getAlignment()->setHorizontal((string) $style->alignment["horizontal"]); $docStyle->getAlignment()->setHorizontal((string) $style->alignment["horizontal"]);
$docStyle->getAlignment()->setVertical((string) $style->alignment["vertical"]); $docStyle->getAlignment()->setVertical((string) $style->alignment["vertical"]);
@@ -1436,7 +1493,7 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
} }
// protection // protection
if (isset($style->protection) && $style->applyProtection) { if (isset($style->protection)) {
if (isset($style->protection['locked'])) { if (isset($style->protection['locked'])) {
if ((string)$style->protection['locked'] == 'true') { if ((string)$style->protection['locked'] == 'true') {
$docStyle->getProtection()->setLocked(PHPExcel_Style_Protection::PROTECTION_PROTECTED); $docStyle->getProtection()->setLocked(PHPExcel_Style_Protection::PROTECTION_PROTECTED);
@@ -1471,9 +1528,12 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
$value->createText( PHPExcel_Shared_String::ControlCharacterOOXML2PHP( (string) $is->t ) ); $value->createText( PHPExcel_Shared_String::ControlCharacterOOXML2PHP( (string) $is->t ) );
} else { } else {
foreach ($is->r as $run) { foreach ($is->r as $run) {
if (!isset($run->rPr)) {
$objText = $value->createText( PHPExcel_Shared_String::ControlCharacterOOXML2PHP( (string) $run->t ) );
} else {
$objText = $value->createTextRun( PHPExcel_Shared_String::ControlCharacterOOXML2PHP( (string) $run->t ) ); $objText = $value->createTextRun( PHPExcel_Shared_String::ControlCharacterOOXML2PHP( (string) $run->t ) );
if (isset($run->rPr)) {
if (isset($run->rPr->rFont["val"])) { if (isset($run->rPr->rFont["val"])) {
$objText->getFont()->setName((string) $run->rPr->rFont["val"]); $objText->getFont()->setName((string) $run->rPr->rFont["val"]);
} }

File diff suppressed because it is too large Load Diff

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,49 +20,17 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Reader_Excel5 * @package PHPExcel_Reader_Excel5
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../../');
}
/** PHPExcel_Cell */
require_once PHPEXCEL_ROOT . 'PHPExcel/Cell.php';
/** PHPExcel_Shared_Escher_DggContainer */
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/Escher/DggContainer.php';
/** PHPExcel_Shared_Escher_DggContainer_BstoreContainer */
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/Escher/DggContainer/BstoreContainer.php';
/** PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE */
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/Escher/DggContainer/BstoreContainer/BSE.php';
/** PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE_Blip */
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/Escher/DggContainer/BstoreContainer/BSE/Blip.php';
/** PHPExcel_Shared_Escher_DgContainer */
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/Escher/DgContainer.php';
/** PHPExcel_Shared_Escher_DgContainer_SpgrContainer */
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/Escher/DgContainer/SpgrContainer.php';
/** PHPExcel_Shared_Escher_DgContainer_SpgrContainer_SpContainer */
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/Escher/DgContainer/SpgrContainer/SpContainer.php';
/** /**
* PHPExcel_Reader_Excel5_Escher * PHPExcel_Reader_Excel5_Escher
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Reader_Excel5 * @package PHPExcel_Reader_Excel5
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_Reader_Excel5_Escher class PHPExcel_Reader_Excel5_Escher
{ {

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Reader * @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
@@ -31,7 +31,7 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Reader * @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
interface PHPExcel_Reader_IReadFilter interface PHPExcel_Reader_IReadFilter
{ {

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Reader * @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
@@ -31,7 +31,7 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Reader * @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
interface PHPExcel_Reader_IReader interface PHPExcel_Reader_IReader
{ {

View File

@@ -0,0 +1,498 @@
<?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.3c, 2010-06-01
*/
/** 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_OOCalc
*
* @category PHPExcel
* @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Reader_OOCalc implements PHPExcel_Reader_IReader
{
/**
* Read data only?
*
* @var boolean
*/
private $_readDataOnly = false;
/**
* Restict which sheets should be loaded?
*
* @var array
*/
private $_loadSheetsOnly = null;
/**
* Sheet index to read
*
* @var int
*/
private $_sheetIndex;
/**
* Formats
*
* @var array
*/
private $_styles = array();
/**
* PHPExcel_Reader_IReadFilter instance
*
* @var PHPExcel_Reader_IReadFilter
*/
private $_readFilter = null;
/**
* Read data only?
*
* @return boolean
*/
public function getReadDataOnly() {
return $this->_readDataOnly;
}
/**
* Set read data only
*
* @param boolean $pValue
* @return PHPExcel_Reader_Excel2007
*/
public function setReadDataOnly($pValue = false) {
$this->_readDataOnly = $pValue;
return $this;
}
/**
* Get which sheets to load
*
* @return mixed
*/
public function getLoadSheetsOnly()
{
return $this->_loadSheetsOnly;
}
/**
* Set which sheets to load
*
* @param mixed $value
* @return PHPExcel_Reader_Excel2007
*/
public function setLoadSheetsOnly($value = null)
{
$this->_loadSheetsOnly = is_array($value) ?
$value : array($value);
return $this;
}
/**
* Set all sheets to load
*
* @return PHPExcel_Reader_Excel2007
*/
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_Excel2007
*/
public function setReadFilter(PHPExcel_Reader_IReadFilter $pValue) {
$this->_readFilter = $pValue;
return $this;
}
/**
* Create a new PHPExcel_Reader_OOCalc
*/
public function __construct() {
$this->_sheetIndex = 0;
$this->_readFilter = new PHPExcel_Reader_DefaultReadFilter();
}
/**
* Can the current PHPExcel_Reader_IReader read the file?
*
* @param string $pFileName
* @return boolean
*/
public function canRead($pFilename)
{
// Check if zip class exists
if (!class_exists('ZipArchive')) {
return false;
}
// Check if file exists
if (!file_exists($pFilename)) {
throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
}
// Load file
$zip = new ZipArchive;
if ($zip->open($pFilename) === true) {
// check if it is an OOXML archive
$mimeType = $zip->getFromName("mimetype");
$zip->close();
return ($mimeType === 'application/vnd.oasis.opendocument.spreadsheet');
}
return false;
}
/**
* 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 static function identifyFixedStyleValue($styleList,&$styleAttributeValue) {
$styleAttributeValue = strtolower($styleAttributeValue);
foreach($styleList as $style) {
if ($styleAttributeValue == strtolower($style)) {
$styleAttributeValue = $style;
return true;
}
}
return false;
}
/**
* 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.");
}
$zip = new ZipArchive;
if ($zip->open($pFilename) === true) {
// echo '<h1>Meta Information</h1>';
$xml = simplexml_load_string($zip->getFromName("meta.xml"));
$namespacesMeta = $xml->getNamespaces(true);
// echo '<pre>';
// print_r($namespacesMeta);
// echo '</pre><hr />';
$docProps = $objPHPExcel->getProperties();
$officeProperty = $xml->children($namespacesMeta['office']);
foreach($officeProperty as $officePropertyData) {
$officePropertyDC = array();
if (isset($namespacesMeta['dc'])) {
$officePropertyDC = $officePropertyData->children($namespacesMeta['dc']);
}
foreach($officePropertyDC as $propertyName => $propertyValue) {
// echo $propertyName.' = '.$propertyValue.'<hr />';
switch ($propertyName) {
case 'title' :
$docProps->setTitle($propertyValue);
break;
case 'subject' :
$docProps->setSubject($propertyValue);
break;
case 'creator' :
$docProps->setCreator($propertyValue);
break;
case 'date' :
$creationDate = strtotime($propertyValue);
$docProps->setCreated($creationDate);
break;
case 'description' :
$docProps->setDescription($propertyValue);
break;
}
}
$officePropertyMeta = array();
if (isset($namespacesMeta['dc'])) {
$officePropertyMeta = $officePropertyData->children($namespacesMeta['meta']);
}
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 'keyword' :
$docProps->setKeywords($propertyValue);
break;
}
}
}
// echo '<h1>Workbook Content</h1>';
$xml = simplexml_load_string($zip->getFromName("content.xml"));
$namespacesContent = $xml->getNamespaces(true);
// echo '<pre>';
// print_r($namespacesContent);
// echo '</pre><hr />';
$workbook = $xml->children($namespacesContent['office']);
foreach($workbook->body->spreadsheet as $workbookData) {
$workbookData = $workbookData->children($namespacesContent['table']);
$worksheetID = 0;
foreach($workbookData->table as $worksheetDataSet) {
$worksheetData = $worksheetDataSet->children($namespacesContent['table']);
// print_r($worksheetData);
// echo '<br />';
$worksheetDataAttributes = $worksheetDataSet->attributes($namespacesContent['table']);
// print_r($worksheetDataAttributes);
// echo '<br />';
if ((isset($this->_loadSheetsOnly)) && (isset($worksheetDataAttributes['name'])) &&
(!in_array($worksheetDataAttributes['name'], $this->_loadSheetsOnly))) {
continue;
}
// echo '<h2>Worksheet '.$worksheetDataAttributes['name'].'</h2>';
// Create new Worksheet
$objPHPExcel->createSheet();
$objPHPExcel->setActiveSheetIndex($worksheetID);
if (isset($worksheetDataAttributes['name'])) {
$worksheetName = (string) $worksheetDataAttributes['name'];
$objPHPExcel->getActiveSheet()->setTitle($worksheetName);
}
$rowID = 1;
foreach($worksheetData as $key => $rowData) {
// echo '<b>'.$key.'</b><br />';
switch ($key) {
case 'table-row' :
$columnID = 'A';
foreach($rowData as $key => $cellData) {
// echo '<b>'.$columnID.$rowID.'</b><br />';
$cellDataText = $cellData->children($namespacesContent['text']);
$cellDataOfficeAttributes = $cellData->attributes($namespacesContent['office']);
$cellDataTableAttributes = $cellData->attributes($namespacesContent['table']);
// echo 'Office Attributes: ';
// print_r($cellDataOfficeAttributes);
// echo '<br />Table Attributes: ';
// print_r($cellDataTableAttributes);
// echo '<br />Cell Data Text';
// print_r($cellDataText);
// echo '<br />';
//
$type = $formatting = $hyperlink = null;
$hasCalculatedValue = false;
$cellDataFormula = '';
if (isset($cellDataTableAttributes['formula'])) {
$cellDataFormula = $cellDataTableAttributes['formula'];
$hasCalculatedValue = true;
}
if (isset($cellDataText->p)) {
// echo 'Value Type is '.$cellDataOfficeAttributes['value-type'].'<br />';
switch ($cellDataOfficeAttributes['value-type']) {
case 'string' :
$type = PHPExcel_Cell_DataType::TYPE_STRING;
$dataValue = $cellDataText->p;
if (isset($dataValue->a)) {
$dataValue = $dataValue->a;
$cellXLinkAttributes = $dataValue->attributes($namespacesContent['xlink']);
$hyperlink = $cellXLinkAttributes['href'];
}
break;
case 'boolean' :
$type = PHPExcel_Cell_DataType::TYPE_BOOL;
$dataValue = ($cellDataText->p == 'TRUE') ? True : False;
break;
case 'float' :
$type = PHPExcel_Cell_DataType::TYPE_NUMERIC;
$dataValue = (float) $cellDataOfficeAttributes['value'];
if (floor($dataValue) == $dataValue) {
$dataValue = (integer) $dataValue;
}
break;
case 'date' :
$type = PHPExcel_Cell_DataType::TYPE_NUMERIC;
$dateObj = date_create($cellDataOfficeAttributes['date-value']);
list($year,$month,$day,$hour,$minute,$second) = explode(' ',$dateObj->format('Y m d H i s'));
$dataValue = PHPExcel_Shared_Date::FormattedPHPToExcel($year,$month,$day,$hour,$minute,$second);
if ($dataValue != floor($dataValue)) {
$formatting = PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX15.' '.PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME4;
} else {
$formatting = PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX15;
}
break;
case 'time' :
$type = PHPExcel_Cell_DataType::TYPE_NUMERIC;
$dataValue = PHPExcel_Shared_Date::PHPToExcel(strtotime('01-01-1970 '.implode(':',sscanf($cellDataOfficeAttributes['time-value'],'PT%dH%dM%dS'))));
$formatting = PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME4;
break;
}
// echo 'Data value is '.$dataValue.'<br />';
// if (!is_null($hyperlink)) {
// echo 'Hyperlink is '.$hyperlink.'<br />';
// }
}
if ($hasCalculatedValue) {
$type = PHPExcel_Cell_DataType::TYPE_FORMULA;
// echo 'Formula: '.$cellDataFormula.'<br />';
$cellDataFormula = substr($cellDataFormula,strpos($cellDataFormula,':=')+1);
$temp = explode('"',$cellDataFormula);
foreach($temp as $key => &$value) {
// Only replace in alternate array entries (i.e. non-quoted blocks)
if (($key % 2) == 0) {
$value = preg_replace('/\[\.(.*):\.(.*)\]/Ui','$1:$2',$value);
$value = preg_replace('/\[\.(.*)\]/Ui','$1',$value);
$value = PHPExcel_Calculation::_translateSeparator(';',',',$value);
}
}
unset($value);
// Then rebuild the formula string
$cellDataFormula = implode('"',$temp);
// echo 'Adjusted Formula: '.$cellDataFormula.'<br />';
}
if (!is_null($type)) {
$objPHPExcel->getActiveSheet()->getCell($columnID.$rowID)->setValueExplicit((($hasCalculatedValue) ? $cellDataFormula : $dataValue),$type);
if ($hasCalculatedValue) {
// echo 'Forumla result is '.$dataValue.'<br />';
$objPHPExcel->getActiveSheet()->getCell($columnID.$rowID)->setCalculatedValue($dataValue);
}
if (($cellDataOfficeAttributes['value-type'] == 'date') ||
($cellDataOfficeAttributes['value-type'] == 'time')) {
$objPHPExcel->getActiveSheet()->getStyle($columnID.$rowID)->getNumberFormat()->setFormatCode($formatting);
}
if (!is_null($hyperlink)) {
$objPHPExcel->getActiveSheet()->getCell($columnID.$rowID)->getHyperlink()->setUrl($hyperlink);
}
}
// Merged cells
if ((isset($cellDataTableAttributes['number-columns-spanned'])) || (isset($cellDataTableAttributes['number-rows-spanned']))) {
$columnTo = $columnID;
if (isset($cellDataTableAttributes['number-columns-spanned'])) {
$columnTo = PHPExcel_Cell::stringFromColumnIndex(PHPExcel_Cell::columnIndexFromString($columnID) + $cellDataTableAttributes['number-columns-spanned'] -2);
}
$rowTo = $rowID;
if (isset($cellDataTableAttributes['number-rows-spanned'])) {
$rowTo = $rowTo + $cellDataTableAttributes['number-rows-spanned'] - 1;
}
$cellRange = $columnID.$rowID.':'.$columnTo.$rowTo;
$objPHPExcel->getActiveSheet()->mergeCells($cellRange);
}
if (isset($cellDataTableAttributes['number-columns-repeated'])) {
// echo 'Repeated '.$cellDataTableAttributes['number-columns-repeated'].' times<br />';
$columnID = PHPExcel_Cell::stringFromColumnIndex(PHPExcel_Cell::columnIndexFromString($columnID) + $cellDataTableAttributes['number-columns-repeated'] - 2);
}
++$columnID;
}
++$rowID;
break;
}
}
++$worksheetID;
}
}
}
// Return
return $objPHPExcel;
}
/**
* Get sheet index
*
* @return int
*/
public function getSheetIndex() {
return $this->_sheetIndex;
}
/**
* Set sheet index
*
* @param int $pValue Sheet index
* @return PHPExcel_Reader_OOCalc
*/
public function setSheetIndex($pValue = 0) {
$this->_sheetIndex = $pValue;
return $this;
}
}

View File

@@ -0,0 +1,509 @@
<?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.3c, 2010-06-01
*/
/** 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_SYLK
*
* @category PHPExcel
* @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Reader_SYLK implements PHPExcel_Reader_IReader
{
/**
* Input encoding
*
* @var string
*/
private $_inputEncoding;
/**
* Delimiter
*
* @var string
*/
private $_delimiter;
/**
* Enclosure
*
* @var string
*/
private $_enclosure;
/**
* Line ending
*
* @var string
*/
private $_lineEnding;
/**
* Sheet index to read
*
* @var int
*/
private $_sheetIndex;
/**
* Formats
*
* @var array
*/
private $_formats = array();
/**
* Format Count
*
* @var int
*/
private $_format = 0;
/**
* PHPExcel_Reader_IReadFilter instance
*
* @var PHPExcel_Reader_IReadFilter
*/
private $_readFilter = null;
/**
* 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();
}
/**
* 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.");
}
// Read sample data (first 2 KB will do)
$fh = fopen($pFilename, 'r');
$data = fread($fh, 2048);
fclose($fh);
// Count delimiters in file
$delimiterCount = substr_count($data, ';');
if ($delimiterCount < 1) {
return false;
}
// Analyze first line looking for ID; signature
$lines = explode("\n", $data);
if (substr($lines[0],0,4) != 'ID;P') {
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);
}
/**
* Read filter
*
* @return PHPExcel_Reader_IReadFilter
*/
public function getReadFilter() {
return $this->_readFilter;
}
/**
* Set read filter
*
* @param PHPExcel_Reader_IReadFilter $pValue
*/
public function setReadFilter(PHPExcel_Reader_IReadFilter $pValue) {
$this->_readFilter = $pValue;
return $this;
}
/**
* Set input encoding
*
* @param string $pValue Input encoding
*/
public function setInputEncoding($pValue = 'ANSI')
{
$this->_inputEncoding = $pValue;
return $this;
}
/**
* Get input encoding
*
* @return string
*/
public function getInputEncoding()
{
return $this->_inputEncoding;
}
/**
* 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.");
}
// Create new PHPExcel
while ($objPHPExcel->getSheetCount() <= $this->_sheetIndex) {
$objPHPExcel->createSheet();
}
$objPHPExcel->setActiveSheetIndex( $this->_sheetIndex );
$fromFormats = array('\-', '\ ');
$toFormats = array('-', ' ');
// Open file
$fileHandle = fopen($pFilename, 'r');
if ($fileHandle === false) {
throw new Exception("Could not open file $pFilename for reading.");
}
// Loop through file
$rowData = array();
$column = $row = '';
// loop through one row (line) at a time in the file
while (($rowData = fgets($fileHandle)) !== FALSE) {
// convert SYLK encoded $rowData to UTF-8
$rowData = PHPExcel_Shared_String::SYLKtoUTF8($rowData);
// explode each row at semicolons while taking into account that literal semicolon (;)
// is escaped like this (;;)
$rowData = explode("\t",str_replace('¤',';',str_replace(';',"\t",str_replace(';;','¤',rtrim($rowData)))));
$dataType = array_shift($rowData);
// Read shared styles
if ($dataType == 'P') {
$formatArray = array();
foreach($rowData as $rowDatum) {
switch($rowDatum{0}) {
case 'P' : $formatArray['numberformat']['code'] = str_replace($fromFormats,$toFormats,substr($rowDatum,1));
break;
case 'E' :
case 'F' : $formatArray['font']['name'] = substr($rowDatum,1);
break;
case 'L' : $formatArray['font']['size'] = substr($rowDatum,1);
break;
case 'S' : $styleSettings = substr($rowDatum,1);
for ($i=0;$i<strlen($styleSettings);++$i) {
switch ($styleSettings{$i}) {
case 'I' : $formatArray['font']['italic'] = true;
break;
case 'D' : $formatArray['font']['bold'] = true;
break;
case 'T' : $formatArray['borders']['top']['style'] = PHPExcel_Style_Border::BORDER_THIN;
break;
case 'B' : $formatArray['borders']['bottom']['style'] = PHPExcel_Style_Border::BORDER_THIN;
break;
case 'L' : $formatArray['borders']['left']['style'] = PHPExcel_Style_Border::BORDER_THIN;
break;
case 'R' : $formatArray['borders']['right']['style'] = PHPExcel_Style_Border::BORDER_THIN;
break;
}
}
break;
}
}
$this->_formats['P'.$this->_format++] = $formatArray;
// Read cell value data
} elseif ($dataType == 'C') {
$hasCalculatedValue = false;
$cellData = $cellDataFormula = '';
foreach($rowData as $rowDatum) {
switch($rowDatum{0}) {
case 'C' :
case 'X' : $column = substr($rowDatum,1);
break;
case 'R' :
case 'Y' : $row = substr($rowDatum,1);
break;
case 'K' : $cellData = substr($rowDatum,1);
break;
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) {
// Only count/replace in alternate array entries
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 = $row;
// Bracketed R references are relative to the current row
if ($rowReference{0} == '[') $rowReference = $row + trim($rowReference,'[]');
$columnReference = $cellReference[4][0];
// Empty C reference is the current column
if ($columnReference == '') $columnReference = $column;
// Bracketed C references are relative to the current column
if ($columnReference{0} == '[') $columnReference = $column + 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);
$hasCalculatedValue = true;
break;
}
}
$columnLetter = PHPExcel_Cell::stringFromColumnIndex($column-1);
$cellData = PHPExcel_Calculation::_unwrapResult($cellData);
// Set cell value
$objPHPExcel->getActiveSheet()->getCell($columnLetter.$row)->setValue(($hasCalculatedValue) ? $cellDataFormula : $cellData);
if ($hasCalculatedValue) {
$cellData = PHPExcel_Calculation::_unwrapResult($cellData);
$objPHPExcel->getActiveSheet()->getCell($columnLetter.$row)->setCalculatedValue($cellData);
}
// Read cell formatting
} elseif ($dataType == 'F') {
$formatStyle = $columnWidth = $styleSettings = '';
$styleData = array();
foreach($rowData as $rowDatum) {
switch($rowDatum{0}) {
case 'C' :
case 'X' : $column = substr($rowDatum,1);
break;
case 'R' :
case 'Y' : $row = substr($rowDatum,1);
break;
case 'P' : $formatStyle = $rowDatum;
break;
case 'W' : list($startCol,$endCol,$columnWidth) = explode(' ',substr($rowDatum,1));
break;
case 'S' : $styleSettings = substr($rowDatum,1);
for ($i=0;$i<strlen($styleSettings);++$i) {
switch ($styleSettings{$i}) {
case 'I' : $styleData['font']['italic'] = true;
break;
case 'D' : $styleData['font']['bold'] = true;
break;
case 'T' : $styleData['borders']['top']['style'] = PHPExcel_Style_Border::BORDER_THIN;
break;
case 'B' : $styleData['borders']['bottom']['style'] = PHPExcel_Style_Border::BORDER_THIN;
break;
case 'L' : $styleData['borders']['left']['style'] = PHPExcel_Style_Border::BORDER_THIN;
break;
case 'R' : $styleData['borders']['right']['style'] = PHPExcel_Style_Border::BORDER_THIN;
break;
}
}
break;
}
}
if (($formatStyle > '') && ($column > '') && ($row > '')) {
$columnLetter = PHPExcel_Cell::stringFromColumnIndex($column-1);
$objPHPExcel->getActiveSheet()->getStyle($columnLetter.$row)->applyFromArray($this->_formats[$formatStyle]);
}
if ((count($styleData) > 0) && ($column > '') && ($row > '')) {
$columnLetter = PHPExcel_Cell::stringFromColumnIndex($column-1);
$objPHPExcel->getActiveSheet()->getStyle($columnLetter.$row)->applyFromArray($styleData);
}
if ($columnWidth > '') {
if ($startCol == $endCol) {
$startCol = PHPExcel_Cell::stringFromColumnIndex($startCol-1);
$objPHPExcel->getActiveSheet()->getColumnDimension($startCol)->setWidth($columnWidth);
} else {
$startCol = PHPExcel_Cell::stringFromColumnIndex($startCol-1);
$endCol = PHPExcel_Cell::stringFromColumnIndex($endCol-1);
$objPHPExcel->getActiveSheet()->getColumnDimension($startCol)->setWidth($columnWidth);
do {
$objPHPExcel->getActiveSheet()->getColumnDimension(++$startCol)->setWidth($columnWidth);
} while ($startCol != $endCol);
}
}
} else {
foreach($rowData as $rowDatum) {
switch($rowDatum{0}) {
case 'C' :
case 'X' : $column = substr($rowDatum,1);
break;
case 'R' :
case 'Y' : $row = substr($rowDatum,1);
break;
}
}
}
}
// Close file
fclose($fileHandle);
// Return
return $objPHPExcel;
}
/**
* Get delimiter
*
* @return string
*/
public function getDelimiter() {
return $this->_delimiter;
}
/**
* Set delimiter
*
* @param string $pValue Delimiter, defaults to ,
* @return PHPExcel_Reader_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
*
* @return int
*/
public function getSheetIndex() {
return $this->_sheetIndex;
}
/**
* Set sheet index
*
* @param int $pValue Sheet index
* @return PHPExcel_Reader_SYLK
*/
public function setSheetIndex($pValue = 0) {
$this->_sheetIndex = $pValue;
return $this;
}
}

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Reader * @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
@@ -32,24 +32,21 @@ if (!defined('PHPEXCEL_ROOT')) {
* @ignore * @ignore
*/ */
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../'); 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 */
require_once PHPEXCEL_ROOT . 'PHPExcel.php';
/** PHPExcel_Reader_IReader */
require_once PHPEXCEL_ROOT . 'PHPExcel/Reader/IReader.php';
/** PHPExcel_Shared_File */
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/File.php';
/** /**
* PHPExcel_Reader_Serialized * PHPExcel_Reader_Serialized
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Reader * @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_Reader_Serialized implements PHPExcel_Reader_IReader class PHPExcel_Reader_Serialized implements PHPExcel_Reader_IReader
{ {

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,48 +20,18 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel * @package PHPExcel
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../');
}
/** PHPExcel_Worksheet */
require_once PHPEXCEL_ROOT . 'PHPExcel/Worksheet.php';
/** PHPExcel_Cell */
require_once PHPEXCEL_ROOT . 'PHPExcel/Cell.php';
/** PHPExcel_Cell_DataType */
require_once PHPEXCEL_ROOT . 'PHPExcel/Cell/DataType.php';
/** PHPExcel_Style */
require_once PHPEXCEL_ROOT . 'PHPExcel/Style.php';
/** PHPExcel_Worksheet_Drawing */
require_once PHPEXCEL_ROOT . 'PHPExcel/Worksheet/Drawing.php';
/** PHPExcel_Calculation_FormulaParser */
require_once PHPEXCEL_ROOT . 'PHPExcel/Calculation/FormulaParser.php';
/** PHPExcel_Calculation_FormulaToken */
require_once PHPEXCEL_ROOT . 'PHPExcel/Calculation/FormulaToken.php';
/** /**
* PHPExcel_ReferenceHelper (Singleton) * PHPExcel_ReferenceHelper (Singleton)
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel * @package PHPExcel
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_ReferenceHelper class PHPExcel_ReferenceHelper
{ {
@@ -86,7 +56,7 @@ class PHPExcel_ReferenceHelper
} }
/** /**
* Create a new PHPExcel_Calculation * Create a new PHPExcel_ReferenceHelper
*/ */
protected function __construct() { protected function __construct() {
} }
@@ -100,12 +70,6 @@ class PHPExcel_ReferenceHelper
* @throws Exception * @throws Exception
*/ */
public function insertNewBefore($pBefore = 'A1', $pNumCols = 0, $pNumRows = 0, PHPExcel_Worksheet $pSheet = null) { public function insertNewBefore($pBefore = 'A1', $pNumCols = 0, $pNumRows = 0, PHPExcel_Worksheet $pSheet = null) {
// Get a copy of the cell collection
/*$aTemp = $pSheet->getCellCollection();
$aCellCollection = array();
foreach ($aTemp as $key => $value) {
$aCellCollection[$key] = clone $value;
}*/
$aCellCollection = $pSheet->getCellCollection(); $aCellCollection = $pSheet->getCellCollection();
// Get coordinates of $pBefore // Get coordinates of $pBefore
@@ -148,7 +112,9 @@ class PHPExcel_ReferenceHelper
// Loop through cells, bottom-up, and change cell coordinates // Loop through cells, bottom-up, and change cell coordinates
while ( ($cell = ($pNumCols < 0 || $pNumRows < 0) ? array_shift($aCellCollection) : array_pop($aCellCollection)) ) { while (($cellID = ($pNumCols < 0 || $pNumRows < 0) ? array_shift($aCellCollection) : array_pop($aCellCollection))) {
$cell = $pSheet->getCell($cellID);
// New coordinates // New coordinates
$newCoordinates = PHPExcel_Cell::stringFromColumnIndex( PHPExcel_Cell::columnIndexFromString($cell->getColumn()) - 1 + $pNumCols ) . ($cell->getRow() + $pNumRows); $newCoordinates = PHPExcel_Cell::stringFromColumnIndex( PHPExcel_Cell::columnIndexFromString($cell->getColumn()) - 1 + $pNumCols ) . ($cell->getRow() + $pNumRows);
@@ -165,17 +131,15 @@ class PHPExcel_ReferenceHelper
// Insert this cell at its new location // Insert this cell at its new location
if ($cell->getDataType() == PHPExcel_Cell_DataType::TYPE_FORMULA) { if ($cell->getDataType() == PHPExcel_Cell_DataType::TYPE_FORMULA) {
// Formula should be adjusted // Formula should be adjusted
$pSheet->setCellValue( $pSheet->getCell($newCoordinates)
$newCoordinates ->setValue($this->updateFormulaReferences($cell->getValue(), $pBefore, $pNumCols, $pNumRows));
, $this->updateFormulaReferences($cell->getValue(), $pBefore, $pNumCols, $pNumRows)
);
} else { } else {
// Formula should not be adjusted // Formula should not be adjusted
$pSheet->setCellValue($newCoordinates, $cell->getValue()); $pSheet->getCell($newCoordinates)->setValue($cell->getValue());
} }
// Clear the original cell // Clear the original cell
$pSheet->setCellValue($cell->getCoordinate(), ''); $pSheet->getCell($cell->getCoordinate())->setValue('');
} }
} }
@@ -303,14 +267,13 @@ class PHPExcel_ReferenceHelper
// Update worksheet: merge cells // Update worksheet: merge cells
$aMergeCells = array_reverse($pSheet->getMergeCells(), true); $aMergeCells = $pSheet->getMergeCells();
foreach ($aMergeCells as $key => $value) { $aNewMergeCells = array(); // the new array of all merge cells
foreach ($aMergeCells as $key => &$value) {
$newReference = $this->updateCellReference($key, $pBefore, $pNumCols, $pNumRows); $newReference = $this->updateCellReference($key, $pBefore, $pNumCols, $pNumRows);
if ($key != $newReference) { $aNewMergeCells[$newReference] = $newReference;
$pSheet->mergeCells( $newReference );
$pSheet->unmergeCells( $key );
}
} }
$pSheet->setMergeCells($aNewMergeCells); // replace the merge cells array
// Update worksheet: protected cells // Update worksheet: protected cells
@@ -378,29 +341,46 @@ class PHPExcel_ReferenceHelper
* @throws Exception * @throws Exception
*/ */
public function updateFormulaReferences($pFormula = '', $pBefore = 'A1', $pNumCols = 0, $pNumRows = 0) { public function updateFormulaReferences($pFormula = '', $pBefore = 'A1', $pNumCols = 0, $pNumRows = 0) {
// Formula stack
$executableFormulaArray = array();
// Parse formula into a tree of tokens // Parse formula into a tree of tokens
$tokenisedFormula = PHPExcel_Calculation::getInstance()->parseFormula($pFormula); $tokenisedFormula = PHPExcel_Calculation::getInstance()->parseFormula($pFormula);
$newCellTokens = $cellTokens = array(); $newCellTokens = $cellTokens = array();
$adjustCount = 0;
// Build the translation table of cell tokens // Build the translation table of cell tokens
foreach($tokenisedFormula as $token) { foreach($tokenisedFormula as $token) {
$token = $token['value'];
if (preg_match('/^'.PHPExcel_Calculation::CALCULATION_REGEXP_CELLREF.'$/i', $token, $matches)) { if (preg_match('/^'.PHPExcel_Calculation::CALCULATION_REGEXP_CELLREF.'$/i', $token, $matches)) {
$newCellTokens[] = $this->updateCellReference($token, $pBefore, $pNumCols, $pNumRows); list($column,$row) = PHPExcel_Cell::coordinateFromString($token);
$cellTokens[] = '/'.$token.'/'; // Max worksheet size is 1,048,576 rows by 16,384 columns in Excel 2007, so our adjustments need to be at least one digit more
$column = PHPExcel_Cell::columnIndexFromString($column) + 100000;
$row += 10000000;
$cellIndex = $column.$row;
if (!isset($cellTokens[$cellIndex])) {
$newReference = $this->updateCellReference($token, $pBefore, $pNumCols, $pNumRows);
if ($newReference !== $token) {
$newCellTokens[$cellIndex] = preg_quote($newReference);
$cellTokens[$cellIndex] = '/(?<![A-Z])'.preg_quote($token).'(?!\d)/i';
++$adjustCount;
} }
} }
}
}
if ($adjustCount == 0) {
return $pFormula;
}
krsort($cellTokens);
krsort($newCellTokens);
// Update cell references in the formula // Update cell references in the formula
$formulaBlocks = explode('"',$pFormula); $formulaBlocks = explode('"',$pFormula);
$i = 0; foreach($formulaBlocks as $i => &$formulaBlock) {
foreach($formulaBlocks as $formulaBlockKey => $formulaBlock) {
// Only count/replace in alternate array entries // Only count/replace in alternate array entries
if (($i++ % 2) == 0) { if (($i % 2) == 0) {
$formulaBlocks[$formulaBlockKey] = preg_replace($cellTokens,$newCellTokens,$formulaBlock); $formulaBlock = preg_replace($cellTokens,$newCellTokens,$formulaBlock);
} }
} }
unset($formulaBlock);
// Then rebuild the formula string // Then rebuild the formula string
return implode('"',$formulaBlocks); return implode('"',$formulaBlocks);
} }
@@ -440,8 +420,13 @@ class PHPExcel_ReferenceHelper
* @param string $newName New name * @param string $newName New name
*/ */
public function updateNamedFormulas(PHPExcel $pPhpExcel, $oldName = '', $newName = '') { public function updateNamedFormulas(PHPExcel $pPhpExcel, $oldName = '', $newName = '') {
if ($oldName == '') {
return;
}
foreach ($pPhpExcel->getWorksheetIterator() as $sheet) { foreach ($pPhpExcel->getWorksheetIterator() as $sheet) {
foreach ($sheet->getCellCollection(false) as $cell) { foreach ($sheet->getCellCollection(false) as $cellID) {
$cell = $sheet->getCell($cellID);
if (!is_null($cell) && $cell->getDataType() == PHPExcel_Cell_DataType::TYPE_FORMULA) { if (!is_null($cell) && $cell->getDataType() == PHPExcel_Cell_DataType::TYPE_FORMULA) {
$formula = $cell->getValue(); $formula = $cell->getValue();
if (strpos($formula, $oldName) !== false) { if (strpos($formula, $oldName) !== false) {
@@ -468,8 +453,8 @@ class PHPExcel_ReferenceHelper
if (strpos($pCellRange,':') !== false || strpos($pCellRange, ',') !== false) { if (strpos($pCellRange,':') !== false || strpos($pCellRange, ',') !== false) {
// Update range // Update range
$range = PHPExcel_Cell::splitRange($pCellRange); $range = PHPExcel_Cell::splitRange($pCellRange);
for ($i = 0; $i < count($range); $i++) { for ($i = 0; $i < count($range); ++$i) {
for ($j = 0; $j < count($range[$i]); $j++) { for ($j = 0; $j < count($range[$i]); ++$j) {
$range[$i][$j] = $this->_updateSingleCellReference($range[$i][$j], $pBefore, $pNumCols, $pNumRows); $range[$i][$j] = $this->_updateSingleCellReference($range[$i][$j], $pBefore, $pNumCols, $pNumRows);
} }
} }

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,47 +20,18 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_RichText * @package PHPExcel_RichText
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../');
}
/** PHPExcel_IComparable */
require_once PHPEXCEL_ROOT . 'PHPExcel/IComparable.php';
/** PHPExcel_Cell */
require_once PHPEXCEL_ROOT . 'PHPExcel/Cell.php';
/** PHPExcel_Cell_DataType */
require_once PHPEXCEL_ROOT . 'PHPExcel/Cell/DataType.php';
/** PHPExcel_RichText_ITextElement */
require_once PHPEXCEL_ROOT . 'PHPExcel/RichText/ITextElement.php';
/** PHPExcel_RichText_TextElement */
require_once PHPEXCEL_ROOT . 'PHPExcel/RichText/TextElement.php';
/** PHPExcel_RichText_Run */
require_once PHPEXCEL_ROOT . 'PHPExcel/RichText/Run.php';
/** PHPExcel_Style_Font */
require_once PHPEXCEL_ROOT . 'PHPExcel/Style/Font.php';
/** /**
* PHPExcel_RichText * PHPExcel_RichText
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_RichText * @package PHPExcel_RichText
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_RichText implements PHPExcel_IComparable class PHPExcel_RichText implements PHPExcel_IComparable
{ {
@@ -71,13 +42,6 @@ class PHPExcel_RichText implements PHPExcel_IComparable
*/ */
private $_richTextElements; private $_richTextElements;
/**
* Parent cell
*
* @var PHPExcel_Cell
*/
private $_parent;
/** /**
* Create a new PHPExcel_RichText instance * Create a new PHPExcel_RichText instance
* *
@@ -89,20 +53,17 @@ class PHPExcel_RichText implements PHPExcel_IComparable
// Initialise variables // Initialise variables
$this->_richTextElements = array(); $this->_richTextElements = array();
// Set parent? // Rich-Text string attached to cell?
if (!is_null($pCell)) { if (!is_null($pCell)) {
// Set parent cell
$this->_parent = $pCell;
// Add cell text and style // Add cell text and style
if ($this->_parent->getValue() != "") { if ($pCell->getValue() != "") {
$objRun = new PHPExcel_RichText_Run($this->_parent->getValue()); $objRun = new PHPExcel_RichText_Run($pCell->getValue());
$objRun->setFont(clone $this->_parent->getParent()->getStyle($this->_parent->getCoordinate())->getFont()); $objRun->setFont(clone $pCell->getParent()->getStyle($pCell->getCoordinate())->getFont());
$this->addText($objRun); $this->addText($objRun);
} }
// Set parent value // Set parent value
$this->_parent->setValueExplicit($this, PHPExcel_Cell_DataType::TYPE_STRING); $pCell->setValueExplicit($this, PHPExcel_Cell_DataType::TYPE_STRING);
} }
} }
@@ -157,7 +118,7 @@ class PHPExcel_RichText implements PHPExcel_IComparable
// Return value // Return value
$returnValue = ''; $returnValue = '';
// Loop trough all PHPExcel_RichText_ITextElement // Loop through all PHPExcel_RichText_ITextElement
foreach ($this->_richTextElements as $text) { foreach ($this->_richTextElements as $text) {
$returnValue .= $text->getText(); $returnValue .= $text->getText();
} }
@@ -202,44 +163,6 @@ class PHPExcel_RichText implements PHPExcel_IComparable
return $this; return $this;
} }
/**
* Get parent
*
* @return PHPExcel_Cell
*/
public function getParent() {
return $this->_parent;
}
/**
* Set parent
*
* @param PHPExcel_Cell $value
* @return PHPExcel_RichText
*/
public function setParent(PHPExcel_Cell $value) {
// Set parent
$this->_parent = $value;
// Set parent value
$this->_parent->setValueExplicit($this, PHPExcel_Cell_DataType::TYPE_STRING);
// Verify style information
$sheet = $this->_parent->getParent();
$cellFont = $sheet->getStyle($this->_parent->getCoordinate())->getFont()->getSharedComponent();
foreach ($this->getRichTextElements() as $element) {
if (!($element instanceof PHPExcel_RichText_Run)) continue;
if ($element->getFont()->getHashCode() == $sheet->getDefaultStyle()->getFont()->getHashCode()) {
if ($element->getFont()->getHashCode() != $cellFont->getHashCode()) {
$element->setFont(clone $cellFont);
}
}
}
return $this;
}
/** /**
* Get hash code * Get hash code
* *
@@ -257,45 +180,12 @@ class PHPExcel_RichText implements PHPExcel_IComparable
); );
} }
/**
* Hash index
*
* @var string
*/
private $_hashIndex;
/**
* Get hash index
*
* Note that this index may vary during script execution! Only reliable moment is
* while doing a write of a workbook and when changes are not allowed.
*
* @return string Hash index
*/
public function getHashIndex() {
return $this->_hashIndex;
}
/**
* Set hash index
*
* Note that this index may vary during script execution! Only reliable moment is
* while doing a write of a workbook and when changes are not allowed.
*
* @param string $value Hash index
*/
public function setHashIndex($value) {
$this->_hashIndex = $value;
}
/** /**
* Implement PHP __clone to create a deep clone, not just a shallow copy. * Implement PHP __clone to create a deep clone, not just a shallow copy.
*/ */
public function __clone() { public function __clone() {
$vars = get_object_vars($this); $vars = get_object_vars($this);
foreach ($vars as $key => $value) { foreach ($vars as $key => $value) {
if ($key == '_parent') continue;
if (is_object($value)) { if (is_object($value)) {
$this->$key = clone $value; $this->$key = clone $value;
} else { } else {

View File

@@ -18,30 +18,18 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_RichText * @package PHPExcel_RichText
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
}
/** PHPExcel_Style_Font */
require_once PHPEXCEL_ROOT . 'PHPExcel/Style/Font.php';
/** /**
* PHPExcel_RichText_ITextElement * PHPExcel_RichText_ITextElement
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_RichText * @package PHPExcel_RichText
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
interface PHPExcel_RichText_ITextElement interface PHPExcel_RichText_ITextElement
{ {

View File

@@ -18,36 +18,18 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_RichText * @package PHPExcel_RichText
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
}
/** PHPExcel_RichText_ITextElement */
require_once PHPEXCEL_ROOT . 'PHPExcel/RichText/ITextElement.php';
/** PHPExcel_RichText_TextElement */
require_once PHPEXCEL_ROOT . 'PHPExcel/RichText/TextElement.php';
/** PHPExcel_Style_Font */
require_once PHPEXCEL_ROOT . 'PHPExcel/Style/Font.php';
/** /**
* PHPExcel_RichText_Run * PHPExcel_RichText_Run
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_RichText * @package PHPExcel_RichText
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_RichText_Run extends PHPExcel_RichText_TextElement implements PHPExcel_RichText_ITextElement class PHPExcel_RichText_Run extends PHPExcel_RichText_TextElement implements PHPExcel_RichText_ITextElement
{ {

View File

@@ -18,33 +18,18 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_RichText * @package PHPExcel_RichText
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
}
/** PHPExcel_RichText_ITextElement */
require_once PHPEXCEL_ROOT . 'PHPExcel/RichText/ITextElement.php';
/** PHPExcel_Style_Font */
require_once PHPEXCEL_ROOT . 'PHPExcel/Style/Font.php';
/** /**
* PHPExcel_RichText_TextElement * PHPExcel_RichText_TextElement
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_RichText * @package PHPExcel_RichText
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_RichText_TextElement implements PHPExcel_RichText_ITextElement class PHPExcel_RichText_TextElement implements PHPExcel_RichText_ITextElement
{ {

View File

@@ -0,0 +1,65 @@
<?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_Settings
* @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.3c, 2010-06-01
*/
/** 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).');
}
}
class PHPExcel_Settings
{
public static function getCacheStorageMethod() {
return PHPExcel_CachedObjectStorageFactory::$_cacheStorageMethod;
} // function getCacheStorageMethod()
public static function getCacheStorageClass() {
return PHPExcel_CachedObjectStorageFactory::$_cacheStorageClass;
} // function getCacheStorageClass()
public static function setCacheStorageMethod($method = PHPExcel_CachedObjectStorageFactory::cache_in_memory, $arguments = array()) {
return PHPExcel_CachedObjectStorageFactory::initialize($method,$arguments);
} // function setCacheStorageMethod()
public static function setLocale($locale){
return PHPExcel_Calculation::getInstance()->setLocale($locale);
} // function setLocale()
}

View File

@@ -0,0 +1,94 @@
<?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.3c, 2010-06-01
*/
/**
* 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

@@ -3,7 +3,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -21,33 +21,18 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared * @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
}
/** PHPExcel_Cell */
require_once PHPEXCEL_ROOT . 'PHPExcel/Cell.php';
/** PHPExcel_Style_NumberFormat */
require_once PHPEXCEL_ROOT . 'PHPExcel/Style/NumberFormat.php';
/** /**
* PHPExcel_Shared_Date * PHPExcel_Shared_Date
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared * @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_Shared_Date class PHPExcel_Shared_Date
{ {
@@ -106,12 +91,15 @@ class PHPExcel_Shared_Date
// Perform conversion // Perform conversion
if ($dateValue >= 1) { if ($dateValue >= 1) {
$utcDays = $dateValue - $myExcelBaseDate; $utcDays = $dateValue - $myExcelBaseDate;
$returnValue = (integer) round($utcDays * 24 * 60 * 60); $returnValue = round($utcDays * 24 * 60 * 60);
if (($returnValue <= PHP_INT_MAX) && ($returnValue >= -PHP_INT_MAX)) {
$returnValue = (integer) $returnValue;
}
} else { } else {
$hours = round($dateValue * 24); $hours = round($dateValue * 24);
$mins = round($dateValue * 24 * 60) - round($hours * 60); $mins = round($dateValue * 24 * 60) - round($hours * 60);
$secs = round($dateValue * 24 * 60 * 60) - round($hours * 60 * 60) - round($mins * 60); $secs = round($dateValue * 24 * 60 * 60) - round($hours * 60 * 60) - round($mins * 60);
$returnValue = (integer) mktime($hours, $mins, $secs); $returnValue = (integer) gmmktime($hours, $mins, $secs);
} }
// Return // Return
@@ -132,8 +120,10 @@ class PHPExcel_Shared_Date
$hours = round($time / 3600); $hours = round($time / 3600);
$minutes = round($time / 60) - ($hours * 60); $minutes = round($time / 60) - ($hours * 60);
$seconds = round($time) - ($hours * 3600) - ($minutes * 60); $seconds = round($time) - ($hours * 3600) - ($minutes * 60);
$dateObj = date_create('1-Jan-1970+'.$days.' days'); $dateObj = date_create('1-Jan-1970+'.$days.' days');
$dateObj->setTime($hours,$minutes,$seconds); $dateObj->setTime($hours,$minutes,$seconds);
return $dateObj; return $dateObj;
} // function ExcelToPHPObject() } // function ExcelToPHPObject()
@@ -274,4 +264,40 @@ class PHPExcel_Shared_Date
// No date... // No date...
return false; return false;
} // function isDateTimeFormatCode() } // 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

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared * @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
@@ -31,7 +31,7 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared * @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_Shared_Drawing class PHPExcel_Shared_Drawing
{ {
@@ -60,31 +60,65 @@ class PHPExcel_Shared_Drawing
} }
/** /**
* Convert pixels to cell dimension. Exact algorithm not known. * Convert pixels to column width. Exact algorithm not known.
* By inspection of a real Excel file using Calibri 11, one finds 1000px ~ 142.85546875 * 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. * This gives a conversion factor of 7. Also, we assume that pixels and font size are proportional.
* *
* @param int $pValue Value in pixels * @param int $pValue Value in pixels
* @param int $pFontSize Default font size of workbook * @param PHPExcel_Style_Font $pDefaultFont Default font of the workbook
* @return int Value in cell dimension * @return int Value in cell dimension
*/ */
public static function pixelsToCellDimension($pValue = 0, $pFontSize = 11) { public static function pixelsToCellDimension($pValue = 0, PHPExcel_Style_Font $pDefaultFont) {
return $pValue * $pFontSize / 11 / 7; // 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 cell width to pixels * Convert column width from (intrinsic) Excel units to pixels
* *
* @param int $pValue Value in cell dimension * @param float $pValue Value in cell dimension
* @param int $pFontSize Default font size of workbook * @param PHPExcel_Style_Font $pDefaultFont Default font of the workbook
* @return int Value in pixels * @return int Value in pixels
*/ */
public static function cellDimensionToPixels($pValue = 0, $pFontSize = 11) { public static function cellDimensionToPixels($pValue = 0, PHPExcel_Style_Font $pDefaultFont) {
if ($pValue != 0) { // Font name and size
return $pValue * 7 * $pFontSize / 11; $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 { } else {
return 0; // 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;
} }
/** /**
@@ -134,4 +168,105 @@ class PHPExcel_Shared_Drawing
return 0; 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

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared_Escher * @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
/** /**
@@ -30,7 +30,7 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared_Escher * @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_Shared_Escher class PHPExcel_Shared_Escher
{ {

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared_Escher * @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.6.7, 2009-04-22 * @version 1.7.3c, 2010-06-01
*/ */
/** /**
@@ -30,7 +30,7 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared_Escher * @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_Shared_Escher_DgContainer class PHPExcel_Shared_Escher_DgContainer
{ {

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared_Escher * @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.6.7, 2009-04-22 * @version 1.7.3c, 2010-06-01
*/ */
/** /**
@@ -30,7 +30,7 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared_Escher * @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_Shared_Escher_DgContainer_SpgrContainer class PHPExcel_Shared_Escher_DgContainer_SpgrContainer
{ {

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared_Escher * @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.6.7, 2009-04-22 * @version 1.7.3c, 2010-06-01
*/ */
/** /**
@@ -30,7 +30,7 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared_Escher * @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_Shared_Escher_DgContainer_SpgrContainer_SpContainer class PHPExcel_Shared_Escher_DgContainer_SpgrContainer_SpContainer
{ {

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared_Escher * @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.6.7, 2009-04-22 * @version 1.7.3c, 2010-06-01
*/ */
/** /**
@@ -30,7 +30,7 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared_Escher * @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_Shared_Escher_DggContainer class PHPExcel_Shared_Escher_DggContainer
{ {

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared_Escher * @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.6.7, 2009-04-22 * @version 1.7.3c, 2010-06-01
*/ */
/** /**
@@ -30,7 +30,7 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared_Escher * @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_Shared_Escher_DggContainer_BstoreContainer class PHPExcel_Shared_Escher_DggContainer_BstoreContainer
{ {

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared_Escher * @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.6.7, 2009-04-22 * @version 1.7.3c, 2010-06-01
*/ */
/** /**
@@ -30,7 +30,7 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared_Escher * @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE class PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE
{ {

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared_Escher * @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.6.7, 2009-04-22 * @version 1.7.3c, 2010-06-01
*/ */
/** /**
@@ -30,7 +30,7 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared_Escher * @package PHPExcel_Shared_Escher
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE_Blip class PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE_Blip
{ {

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,31 +20,17 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared * @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
}
/** PHPExcel_Cell */
require_once PHPEXCEL_ROOT . 'PHPExcel/Cell.php';
/** PHPExcel_Shared_Drawing */
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/Drawing.php';
/** /**
* PHPExcel_Shared_Excel5 * PHPExcel_Shared_Excel5
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared * @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_Shared_Excel5 class PHPExcel_Shared_Excel5
{ {
@@ -59,8 +45,8 @@ class PHPExcel_Shared_Excel5
*/ */
public static function sizeCol($sheet, $col = 'A') public static function sizeCol($sheet, $col = 'A')
{ {
// default font size of workbook // default font of the workbook
$fontSize = $sheet->getParent()->getDefaultStyle()->getFont()->getSize(); $font = $sheet->getParent()->getDefaultStyle()->getFont();
$columnDimensions = $sheet->getColumnDimensions(); $columnDimensions = $sheet->getColumnDimensions();
@@ -70,17 +56,19 @@ class PHPExcel_Shared_Excel5
// then we have column dimension with explicit width // then we have column dimension with explicit width
$columnDimension = $columnDimensions[$col]; $columnDimension = $columnDimensions[$col];
$width = $columnDimension->getWidth(); $width = $columnDimension->getWidth();
$pixelWidth = PHPExcel_Shared_Drawing::cellDimensionToPixels($width, $fontSize); $pixelWidth = PHPExcel_Shared_Drawing::cellDimensionToPixels($width, $font);
} else if ($sheet->getDefaultColumnDimension()->getWidth() != -1) { } else if ($sheet->getDefaultColumnDimension()->getWidth() != -1) {
// then we have default column dimension with explicit width // then we have default column dimension with explicit width
$defaultColumnDimension = $sheet->getDefaultColumnDimension(); $defaultColumnDimension = $sheet->getDefaultColumnDimension();
$width = $defaultColumnDimension->getWidth(); $width = $defaultColumnDimension->getWidth();
$pixelWidth = PHPExcel_Shared_Drawing::cellDimensionToPixels($width, $fontSize); $pixelWidth = PHPExcel_Shared_Drawing::cellDimensionToPixels($width, $font);
} else { } else {
$pixelWidth = (int) 64 * $fontSize / 11; // here we interpolate from Calibri 11
// 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 // now find the effective column width in pixels
@@ -104,6 +92,9 @@ class PHPExcel_Shared_Excel5
*/ */
public static function sizeRow($sheet, $row = 1) public static function sizeRow($sheet, $row = 1)
{ {
// default font of the workbook
$font = $sheet->getParent()->getDefaultStyle()->getFont();
$rowDimensions = $sheet->getRowDimensions(); $rowDimensions = $sheet->getRowDimensions();
// first find the true row height in pixels (uncollapsed and unhidden) // first find the true row height in pixels (uncollapsed and unhidden)
@@ -122,7 +113,11 @@ class PHPExcel_Shared_Excel5
$pixelRowHeight = PHPExcel_Shared_Drawing::pointsToPixels($rowHeight); $pixelRowHeight = PHPExcel_Shared_Drawing::pointsToPixels($rowHeight);
} else { } else {
$pixelRowHeight = 20; // here we assume Calibri 11
// 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 // now find the effective row height in pixels
@@ -301,8 +296,8 @@ class PHPExcel_Shared_Excel5
// Convert the pixel values to the percentage value expected by Excel // Convert the pixel values to the percentage value expected by Excel
$x1 = $x1 / self::sizeCol($sheet, PHPExcel_Cell::stringFromColumnIndex($col_start)) * 1024; $x1 = $x1 / self::sizeCol($sheet, PHPExcel_Cell::stringFromColumnIndex($col_start)) * 1024;
$y1 = $y1 / self::sizeRow($sheet, $row_start + 1) * 256; $y1 = $y1 / self::sizeRow($sheet, $row_start + 1) * 256;
$x2 = $width / self::sizeCol($sheet, PHPExcel_Cell::stringFromColumnIndex($col_end)) * 1024; // Distance to right side of object $x2 = ($width + 1) / self::sizeCol($sheet, PHPExcel_Cell::stringFromColumnIndex($col_end)) * 1024; // Distance to right side of object
$y2 = $height / self::sizeRow($sheet, $row_end + 1) * 256; // Distance to bottom 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); $startCoordinates = PHPExcel_Cell::stringFromColumnIndex($col_start) . ($row_start + 1);
$endCoordinates = PHPExcel_Cell::stringFromColumnIndex($col_end) . ($row_end + 1); $endCoordinates = PHPExcel_Cell::stringFromColumnIndex($col_end) . ($row_end + 1);

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared * @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
@@ -31,7 +31,7 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared * @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_Shared_File class PHPExcel_Shared_File
{ {
@@ -79,7 +79,7 @@ class PHPExcel_Shared_File
// Found something? // Found something?
if ($returnValue == '' || is_null($returnValue)) { if ($returnValue == '' || is_null($returnValue)) {
$pathArray = split('/' , $pFilename); $pathArray = explode('/' , $pFilename);
while(in_array('..', $pathArray) && $pathArray[0] != '..') { while(in_array('..', $pathArray) && $pathArray[0] != '..') {
for ($i = 0; $i < count($pathArray); ++$i) { for ($i = 0; $i < count($pathArray); ++$i) {
if ($pathArray[$i] == '..' && $i > 0) { if ($pathArray[$i] == '..' && $i > 0) {
@@ -95,4 +95,42 @@ class PHPExcel_Shared_File
// Return // Return
return $returnValue; 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') ) {
return realpath($temp);
}
if( $temp = getenv('TEMP') ) {
return realpath($temp);
}
if( $temp = getenv('TMPDIR') ) {
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
return realpath(sys_get_temp_dir());
}
} }

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared * @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
@@ -31,10 +31,14 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared * @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_Shared_Font 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 */ /** Character set codes used by BIFF5-8 in Font records */
const CHARSET_ANSI_LATIN = 0x00; const CHARSET_ANSI_LATIN = 0x00;
const CHARSET_SYSTEM_DEFAULT = 0x01; const CHARSET_SYSTEM_DEFAULT = 0x01;
@@ -56,38 +60,303 @@ class PHPExcel_Shared_Font
const CHARSET_ANSI_LATIN_II = 0xEE; const CHARSET_ANSI_LATIN_II = 0xEE;
const CHARSET_OEM_LATIN_I = 0xFF; 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 * Calculate an (approximate) OpenXML column width, based on font size and text contained
* *
* @param int $fontSize Font size (in pixels or points) * @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 bool $fontSizeInPixels Is the font size specified in pixels (true) or in points (false) ?
* @param string $columnText Text to calculate width * @param string $cellText Text to calculate width
* @param int $rotation Rotation angle * @param int $rotation Rotation angle
* @return int Column width * @return int Column width
*/ */
public static function calculateColumnWidth($fontSize = 9, $fontSizeInPixels = false, $columnText = '', $rotation = 0) { public static function calculateColumnWidth(PHPExcel_Style_Font $font, $cellText = '', $rotation = 0, PHPExcel_Style_Font $defaultFont = null) {
if (!$fontSizeInPixels) {
// Translate points size to pixel size // If it is rich text, use plain text
$fontSize = PHPExcel_Shared_Font::fontSizeToPixels($fontSize); if ($cellText instanceof PHPExcel_RichText) {
$cellText = $cellText->getPlainText();
} }
// If it is rich text, use rich text... // Special case if there are one or more newline characters ("\n")
if ($columnText instanceof PHPExcel_RichText) { if (strpos($cellText, "\n") !== false) {
$columnText = $columnText->getPlainText(); $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
} }
// Only measure the part before the first newline character // Try to get the exact text width in pixels
if (strpos($columnText, "\r") !== false) { try {
$columnText = substr($columnText, 0, strpos($columnText, "\r")); // If autosize method is set to 'approx', use approximation
} if (self::$autoSizeMethod == self::AUTOSIZE_METHOD_APPROX) {
if (strpos($columnText, "\n") !== false) { throw new Exception('AutoSize method is set to approx');
$columnText = substr($columnText, 0, strpos($columnText, "\n"));
} }
// Calculate column width // Width of text in pixels excl. padding
// values 1.025 and 0.584 found via interpolation by inspecting real Excel files with $columnWidth = self::getTextWidthPixelsExact($cellText, $font, $rotation);
// Calibri font. May need further adjustment
$columnWidth = 1.025 * strlen($columnText) + 0.584; // Excel adds some padding // 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 // Calculate approximate rotated column width
if ($rotation !== 0) { if ($rotation !== 0) {
@@ -101,8 +370,9 @@ class PHPExcel_Shared_Font
} }
} }
// Return // pixel width is an integer
return round($columnWidth, 6); $columnWidth = (int) $columnWidth;
return $columnWidth;
} }
/** /**
@@ -111,8 +381,8 @@ class PHPExcel_Shared_Font
* @param int $fontSizeInPoints Font size (in points) * @param int $fontSizeInPoints Font size (in points)
* @return int Font size (in pixels) * @return int Font size (in pixels)
*/ */
public static function fontSizeToPixels($fontSizeInPoints = 12) { public static function fontSizeToPixels($fontSizeInPoints = 11) {
return ((16 / 12) * $fontSizeInPoints); return (int) ((4 / 3) * $fontSizeInPoints);
} }
/** /**
@@ -135,6 +405,133 @@ class PHPExcel_Shared_Font
return ($sizeInCm * 37.795275591); 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. * Returns the associated charset for the font name.
* *
@@ -145,6 +542,7 @@ class PHPExcel_Shared_Font
{ {
switch ($name) { switch ($name) {
// Add more cases. Check FONT records in real Excel files. // 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': return self::CHARSET_SYMBOL;
case 'Wingdings 2': return self::CHARSET_SYMBOL; case 'Wingdings 2': return self::CHARSET_SYMBOL;
case 'Wingdings 3': return self::CHARSET_SYMBOL; case 'Wingdings 3': return self::CHARSET_SYMBOL;
@@ -152,4 +550,214 @@ class PHPExcel_Shared_Font
} }
} }
/**
* 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

@@ -16,42 +16,45 @@
* @version 1.2 * @version 1.2
*/ */
class CholeskyDecomposition { class CholeskyDecomposition {
/** /**
* Decomposition storage * Decomposition storage
* @var array * @var array
* @access private * @access private
*/ */
var $L = array(); private $L = array();
/** /**
* Matrix row and column dimension * Matrix row and column dimension
* @var int * @var int
* @access private * @access private
*/ */
var $m; private $m;
/** /**
* Symmetric positive definite flag * Symmetric positive definite flag
* @var boolean * @var boolean
* @access private * @access private
*/ */
var $isspd = true; private $isspd = true;
/** /**
* CholeskyDecomposition * CholeskyDecomposition
*
* Class constructor - decomposes symmetric positive definite matrix * Class constructor - decomposes symmetric positive definite matrix
* @param mixed Matrix square symmetric positive definite matrix * @param mixed Matrix square symmetric positive definite matrix
*/ */
function CholeskyDecomposition( $A = null ) { public function __construct($A = null) {
if( is_a($A, 'Matrix') ) { if ($A instanceof Matrix) {
$this->L = $A->getArray(); $this->L = $A->getArray();
$this->m = $A->getRowDimension(); $this->m = $A->getRowDimension();
for( $i = 0; $i < $this->m; $i++ ) { for($i = 0; $i < $this->m; ++$i) {
for( $j = $i; $j < $this->m; $j++ ) { for($j = $i; $j < $this->m; ++$j) {
for( $sum = $this->L[$i][$j], $k = $i - 1; $k >= 0; $k-- ) for($sum = $this->L[$i][$j], $k = $i - 1; $k >= 0; --$k) {
$sum -= $this->L[$i][$k] * $this->L[$j][$k]; $sum -= $this->L[$i][$k] * $this->L[$j][$k];
}
if ($i == $j) { if ($i == $j) {
if ($sum >= 0) { if ($sum >= 0) {
$this->L[$i][$i] = sqrt($sum); $this->L[$i][$i] = sqrt($sum);
@@ -59,75 +62,88 @@ class CholeskyDecomposition {
$this->isspd = false; $this->isspd = false;
} }
} else { } else {
if( $this->L[$i][$i] != 0 ) if ($this->L[$i][$i] != 0) {
$this->L[$j][$i] = $sum / $this->L[$i][$i]; $this->L[$j][$i] = $sum / $this->L[$i][$i];
} }
} }
}
for ($k = $i+1; $k < $this->m; $k++) for ($k = $i+1; $k < $this->m; ++$k) {
$this->L[$i][$k] = 0.0; $this->L[$i][$k] = 0.0;
} }
}
} else { } else {
trigger_error(ArgumentTypeException, ERROR); throw new Exception(JAMAError(ArgumentTypeException));
}
} }
} // function __construct()
/** /**
* Is the matrix symmetric and positive definite? * Is the matrix symmetric and positive definite?
*
* @return boolean * @return boolean
*/ */
function isSPD () { public function isSPD() {
return $this->isspd; return $this->isspd;
} } // function isSPD()
/** /**
* getL * getL
*
* Return triangular factor. * Return triangular factor.
* @return Matrix Lower triangular matrix * @return Matrix Lower triangular matrix
*/ */
function getL () { public function getL() {
return new Matrix($this->L); return new Matrix($this->L);
} } // function getL()
/** /**
* Solve A*X = B * Solve A*X = B
*
* @param $B Row-equal matrix * @param $B Row-equal matrix
* @return Matrix L * L' * X = B * @return Matrix L * L' * X = B
*/ */
function solve ( $B = null ) { public function solve($B = null) {
if( is_a($B, 'Matrix') ) { if ($B instanceof Matrix) {
if ($B->getRowDimension() == $this->m) { if ($B->getRowDimension() == $this->m) {
if ($this->isspd) { if ($this->isspd) {
$X = $B->getArrayCopy(); $X = $B->getArrayCopy();
$nx = $B->getColumnDimension(); $nx = $B->getColumnDimension();
for ($k = 0; $k < $this->m; $k++) { for ($k = 0; $k < $this->m; ++$k) {
for ($i = $k + 1; $i < $this->m; $i++) for ($i = $k + 1; $i < $this->m; ++$i) {
for ($j = 0; $j < $nx; $j++) for ($j = 0; $j < $nx; ++$j) {
$X[$i][$j] -= $X[$k][$j] * $this->L[$i][$k]; $X[$i][$j] -= $X[$k][$j] * $this->L[$i][$k];
}
for ($j = 0; $j < $nx; $j++) }
for ($j = 0; $j < $nx; ++$j) {
$X[$k][$j] /= $this->L[$k][$k]; $X[$k][$j] /= $this->L[$k][$k];
} }
}
for ($k = $this->m - 1; $k >= 0; $k--) { for ($k = $this->m - 1; $k >= 0; --$k) {
for ($j = 0; $j < $nx; $j++) for ($j = 0; $j < $nx; ++$j) {
$X[$k][$j] /= $this->L[$k][$k]; $X[$k][$j] /= $this->L[$k][$k];
}
for ($i = 0; $i < $k; $i++) for ($i = 0; $i < $k; ++$i) {
for ($j = 0; $j < $nx; $j++) for ($j = 0; $j < $nx; ++$j) {
$X[$i][$j] -= $X[$k][$j] * $this->L[$k][$i]; $X[$i][$j] -= $X[$k][$j] * $this->L[$k][$i];
} }
}
}
return new Matrix($X, $this->m, $nx); return new Matrix($X, $this->m, $nx);
} else { } else {
trigger_error(MatrixSPDException, ERROR); throw new Exception(JAMAError(MatrixSPDException));
} }
} else { } else {
trigger_error(MatrixDimensionException, ERROR); throw new Exception(JAMAError(MatrixDimensionException));
} }
} else { } else {
trigger_error(ArgumentTypeException, ERROR); throw new Exception(JAMAError(ArgumentTypeException));
}
}
} }
} // function solve()
} // class CholeskyDecomposition

View File

@@ -27,59 +27,60 @@ class EigenvalueDecomposition {
* Row and column dimension (square matrix). * Row and column dimension (square matrix).
* @var int * @var int
*/ */
var $n; private $n;
/** /**
* Internal symmetry flag. * Internal symmetry flag.
* @var int * @var int
*/ */
var $issymmetric; private $issymmetric;
/** /**
* Arrays for internal storage of eigenvalues. * Arrays for internal storage of eigenvalues.
* @var array * @var array
*/ */
var $d = array(); private $d = array();
var $e = array(); private $e = array();
/** /**
* Array for internal storage of eigenvectors. * Array for internal storage of eigenvectors.
* @var array * @var array
*/ */
var $V = array(); private $V = array();
/** /**
* Array for internal storage of nonsymmetric Hessenberg form. * Array for internal storage of nonsymmetric Hessenberg form.
* @var array * @var array
*/ */
var $H = array(); private $H = array();
/** /**
* Working storage for nonsymmetric algorithm. * Working storage for nonsymmetric algorithm.
* @var array * @var array
*/ */
var $ort; private $ort;
/** /**
* Used for complex scalar division. * Used for complex scalar division.
* @var float * @var float
*/ */
var $cdivr; private $cdivr;
var $cdivi; private $cdivi;
/** /**
* Symmetric Householder reduction to tridiagonal form. * Symmetric Householder reduction to tridiagonal form.
*
* @access private * @access private
*/ */
function tred2 () { private function tred2 () {
// This is derived from the Algol procedures tred2 by // This is derived from the Algol procedures tred2 by
// Bowdler, Martin, Reinsch, and Wilkinson, Handbook for // Bowdler, Martin, Reinsch, and Wilkinson, Handbook for
// Auto. Comp., Vol.ii-Linear Algebra, and the corresponding // Auto. Comp., Vol.ii-Linear Algebra, and the corresponding
// Fortran subroutine in EISPACK. // Fortran subroutine in EISPACK.
$this->d = $this->V[$this->n-1]; $this->d = $this->V[$this->n-1];
// Householder reduction to tridiagonal form. // Householder reduction to tridiagonal form.
for ($i = $this->n-1; $i > 0; $i--) { for ($i = $this->n-1; $i > 0; --$i) {
$i_ = $i -1; $i_ = $i -1;
// Scale to avoid under/overflow. // Scale to avoid under/overflow.
$h = $scale = 0.0; $h = $scale = 0.0;
@@ -87,73 +88,82 @@ class EigenvalueDecomposition {
if ($scale == 0.0) { if ($scale == 0.0) {
$this->e[$i] = $this->d[$i_]; $this->e[$i] = $this->d[$i_];
$this->d = array_slice($this->V[$i_], 0, $i_); $this->d = array_slice($this->V[$i_], 0, $i_);
for ($j = 0; $j < $i; $j++) { for ($j = 0; $j < $i; ++$j) {
$this->V[$j][$i] = $this->V[$i][$j] = 0.0; $this->V[$j][$i] = $this->V[$i][$j] = 0.0;
} }
} else { } else {
// Generate Householder vector. // Generate Householder vector.
for ($k = 0; $k < $i; $k++) { for ($k = 0; $k < $i; ++$k) {
$this->d[$k] /= $scale; $this->d[$k] /= $scale;
$h += pow($this->d[$k], 2); $h += pow($this->d[$k], 2);
} }
$f = $this->d[$i_]; $f = $this->d[$i_];
$g = sqrt($h); $g = sqrt($h);
if ($f > 0) if ($f > 0) {
$g = -$g; $g = -$g;
}
$this->e[$i] = $scale * $g; $this->e[$i] = $scale * $g;
$h = $h - $f * $g; $h = $h - $f * $g;
$this->d[$i_] = $f - $g; $this->d[$i_] = $f - $g;
for ($j = 0; $j < $i; $j++) for ($j = 0; $j < $i; ++$j) {
$this->e[$j] = 0.0; $this->e[$j] = 0.0;
}
// Apply similarity transformation to remaining columns. // Apply similarity transformation to remaining columns.
for ($j = 0; $j < $i; $j++) { for ($j = 0; $j < $i; ++$j) {
$f = $this->d[$j]; $f = $this->d[$j];
$this->V[$j][$i] = $f; $this->V[$j][$i] = $f;
$g = $this->e[$j] + $this->V[$j][$j] * $f; $g = $this->e[$j] + $this->V[$j][$j] * $f;
for ($k = $j+1; $k <= $i_; $k++) { for ($k = $j+1; $k <= $i_; ++$k) {
$g += $this->V[$k][$j] * $this->d[$k]; $g += $this->V[$k][$j] * $this->d[$k];
$this->e[$k] += $this->V[$k][$j] * $f; $this->e[$k] += $this->V[$k][$j] * $f;
} }
$this->e[$j] = $g; $this->e[$j] = $g;
} }
$f = 0.0; $f = 0.0;
for ($j = 0; $j < $i; $j++) { for ($j = 0; $j < $i; ++$j) {
$this->e[$j] /= $h; $this->e[$j] /= $h;
$f += $this->e[$j] * $this->d[$j]; $f += $this->e[$j] * $this->d[$j];
} }
$hh = $f / (2 * $h); $hh = $f / (2 * $h);
for ($j=0; $j < $i; $j++) for ($j=0; $j < $i; ++$j) {
$this->e[$j] -= $hh * $this->d[$j]; $this->e[$j] -= $hh * $this->d[$j];
for ($j = 0; $j < $i; $j++) { }
for ($j = 0; $j < $i; ++$j) {
$f = $this->d[$j]; $f = $this->d[$j];
$g = $this->e[$j]; $g = $this->e[$j];
for ($k = $j; $k <= $i_; $k++) for ($k = $j; $k <= $i_; ++$k) {
$this->V[$k][$j] -= ($f * $this->e[$k] + $g * $this->d[$k]); $this->V[$k][$j] -= ($f * $this->e[$k] + $g * $this->d[$k]);
}
$this->d[$j] = $this->V[$i-1][$j]; $this->d[$j] = $this->V[$i-1][$j];
$this->V[$i][$j] = 0.0; $this->V[$i][$j] = 0.0;
} }
} }
$this->d[$i] = $h; $this->d[$i] = $h;
} }
// Accumulate transformations. // Accumulate transformations.
for ($i = 0; $i < $this->n-1; $i++) { for ($i = 0; $i < $this->n-1; ++$i) {
$this->V[$this->n-1][$i] = $this->V[$i][$i]; $this->V[$this->n-1][$i] = $this->V[$i][$i];
$this->V[$i][$i] = 1.0; $this->V[$i][$i] = 1.0;
$h = $this->d[$i+1]; $h = $this->d[$i+1];
if ($h != 0.0) { if ($h != 0.0) {
for ($k = 0; $k <= $i; $k++) for ($k = 0; $k <= $i; ++$k) {
$this->d[$k] = $this->V[$k][$i+1] / $h; $this->d[$k] = $this->V[$k][$i+1] / $h;
for ($j = 0; $j <= $i; $j++) { }
for ($j = 0; $j <= $i; ++$j) {
$g = 0.0; $g = 0.0;
for ($k = 0; $k <= $i; $k++) for ($k = 0; $k <= $i; ++$k) {
$g += $this->V[$k][$i+1] * $this->V[$k][$j]; $g += $this->V[$k][$i+1] * $this->V[$k][$j];
for ($k = 0; $k <= $i; $k++) }
for ($k = 0; $k <= $i; ++$k) {
$this->V[$k][$j] -= $g * $this->d[$k]; $this->V[$k][$j] -= $g * $this->d[$k];
} }
} }
for ($k = 0; $k <= $i; $k++) }
for ($k = 0; $k <= $i; ++$k) {
$this->V[$k][$i+1] = 0.0; $this->V[$k][$i+1] = 0.0;
} }
}
$this->d = $this->V[$this->n-1]; $this->d = $this->V[$this->n-1];
$this->V[$this->n-1] = array_fill(0, $j, 0.0); $this->V[$this->n-1] = array_fill(0, $j, 0.0);
@@ -161,6 +171,7 @@ class EigenvalueDecomposition {
$this->e[0] = 0.0; $this->e[0] = 0.0;
} }
/** /**
* Symmetric tridiagonal QL algorithm. * Symmetric tridiagonal QL algorithm.
* *
@@ -171,21 +182,23 @@ class EigenvalueDecomposition {
* *
* @access private * @access private
*/ */
function tql2 () { private function tql2() {
for ($i = 1; $i < $this->n; $i++) for ($i = 1; $i < $this->n; ++$i) {
$this->e[$i-1] = $this->e[$i]; $this->e[$i-1] = $this->e[$i];
}
$this->e[$this->n-1] = 0.0; $this->e[$this->n-1] = 0.0;
$f = 0.0; $f = 0.0;
$tst1 = 0.0; $tst1 = 0.0;
$eps = pow(2.0,-52.0); $eps = pow(2.0,-52.0);
for ($l = 0; $l < $this->n; $l++) {
for ($l = 0; $l < $this->n; ++$l) {
// Find small subdiagonal element // Find small subdiagonal element
$tst1 = max($tst1, abs($this->d[$l]) + abs($this->e[$l])); $tst1 = max($tst1, abs($this->d[$l]) + abs($this->e[$l]));
$m = $l; $m = $l;
while ($m < $this->n) { while ($m < $this->n) {
if (abs($this->e[$m]) <= $eps * $tst1) if (abs($this->e[$m]) <= $eps * $tst1)
break; break;
$m++; ++$m;
} }
// If m == l, $this->d[l] is an eigenvalue, // If m == l, $this->d[l] is an eigenvalue,
// otherwise, iterate. // otherwise, iterate.
@@ -204,7 +217,7 @@ class EigenvalueDecomposition {
$this->d[$l+1] = $this->e[$l] * ($p + $r); $this->d[$l+1] = $this->e[$l] * ($p + $r);
$dl1 = $this->d[$l+1]; $dl1 = $this->d[$l+1];
$h = $g - $this->d[$l]; $h = $g - $this->d[$l];
for ($i = $l + 2; $i < $this->n; $i++) for ($i = $l + 2; $i < $this->n; ++$i)
$this->d[$i] -= $h; $this->d[$i] -= $h;
$f += $h; $f += $h;
// Implicit QL transformation. // Implicit QL transformation.
@@ -213,7 +226,7 @@ class EigenvalueDecomposition {
$c2 = $c3 = $c; $c2 = $c3 = $c;
$el1 = $this->e[$l + 1]; $el1 = $this->e[$l + 1];
$s = $s2 = 0.0; $s = $s2 = 0.0;
for ($i = $m-1; $i >= $l; $i--) { for ($i = $m-1; $i >= $l; --$i) {
$c3 = $c2; $c3 = $c2;
$c2 = $c; $c2 = $c;
$s2 = $s; $s2 = $s;
@@ -226,7 +239,7 @@ class EigenvalueDecomposition {
$p = $c * $this->d[$i] - $s * $g; $p = $c * $this->d[$i] - $s * $g;
$this->d[$i+1] = $h + $s * ($c * $g + $s * $this->d[$i]); $this->d[$i+1] = $h + $s * ($c * $g + $s * $this->d[$i]);
// Accumulate transformation. // Accumulate transformation.
for ($k = 0; $k < $this->n; $k++) { for ($k = 0; $k < $this->n; ++$k) {
$h = $this->V[$k][$i+1]; $h = $this->V[$k][$i+1];
$this->V[$k][$i+1] = $s * $this->V[$k][$i] + $c * $h; $this->V[$k][$i+1] = $s * $this->V[$k][$i] + $c * $h;
$this->V[$k][$i] = $c * $this->V[$k][$i] - $s * $h; $this->V[$k][$i] = $c * $this->V[$k][$i] - $s * $h;
@@ -241,11 +254,12 @@ class EigenvalueDecomposition {
$this->d[$l] = $this->d[$l] + $f; $this->d[$l] = $this->d[$l] + $f;
$this->e[$l] = 0.0; $this->e[$l] = 0.0;
} }
// Sort eigenvalues and corresponding vectors. // Sort eigenvalues and corresponding vectors.
for ($i = 0; $i < $this->n - 1; $i++) { for ($i = 0; $i < $this->n - 1; ++$i) {
$k = $i; $k = $i;
$p = $this->d[$i]; $p = $this->d[$i];
for ($j = $i+1; $j < $this->n; $j++) { for ($j = $i+1; $j < $this->n; ++$j) {
if ($this->d[$j] < $p) { if ($this->d[$j] < $p) {
$k = $j; $k = $j;
$p = $this->d[$j]; $p = $this->d[$j];
@@ -254,7 +268,7 @@ class EigenvalueDecomposition {
if ($k != $i) { if ($k != $i) {
$this->d[$k] = $this->d[$i]; $this->d[$k] = $this->d[$i];
$this->d[$i] = $p; $this->d[$i] = $p;
for ($j = 0; $j < $this->n; $j++) { for ($j = 0; $j < $this->n; ++$j) {
$p = $this->V[$j][$i]; $p = $this->V[$j][$i];
$this->V[$j][$i] = $this->V[$j][$k]; $this->V[$j][$i] = $this->V[$j][$k];
$this->V[$j][$k] = $p; $this->V[$j][$k] = $p;
@@ -263,6 +277,7 @@ class EigenvalueDecomposition {
} }
} }
/** /**
* Nonsymmetric reduction to Hessenberg form. * Nonsymmetric reduction to Hessenberg form.
* *
@@ -273,74 +288,89 @@ class EigenvalueDecomposition {
* *
* @access private * @access private
*/ */
function orthes () { private function orthes () {
$low = 0; $low = 0;
$high = $this->n-1; $high = $this->n-1;
for ($m = $low+1; $m <= $high-1; $m++) {
for ($m = $low+1; $m <= $high-1; ++$m) {
// Scale column. // Scale column.
$scale = 0.0; $scale = 0.0;
for ($i = $m; $i <= $high; $i++) for ($i = $m; $i <= $high; ++$i) {
$scale = $scale + abs($this->H[$i][$m-1]); $scale = $scale + abs($this->H[$i][$m-1]);
}
if ($scale != 0.0) { if ($scale != 0.0) {
// Compute Householder transformation. // Compute Householder transformation.
$h = 0.0; $h = 0.0;
for ($i = $high; $i >= $m; $i--) { for ($i = $high; $i >= $m; --$i) {
$this->ort[$i] = $this->H[$i][$m-1] / $scale; $this->ort[$i] = $this->H[$i][$m-1] / $scale;
$h += $this->ort[$i] * $this->ort[$i]; $h += $this->ort[$i] * $this->ort[$i];
} }
$g = sqrt($h); $g = sqrt($h);
if ($this->ort[$m] > 0) if ($this->ort[$m] > 0) {
$g *= -1; $g *= -1;
}
$h -= $this->ort[$m] * $g; $h -= $this->ort[$m] * $g;
$this->ort[$m] -= $g; $this->ort[$m] -= $g;
// Apply Householder similarity transformation // Apply Householder similarity transformation
// H = (I -u * u' / h) * H * (I -u * u') / h) // H = (I -u * u' / h) * H * (I -u * u') / h)
for ($j = $m; $j < $this->n; $j++) { for ($j = $m; $j < $this->n; ++$j) {
$f = 0.0; $f = 0.0;
for ($i = $high; $i >= $m; $i--) for ($i = $high; $i >= $m; --$i) {
$f += $this->ort[$i] * $this->H[$i][$j]; $f += $this->ort[$i] * $this->H[$i][$j];
}
$f /= $h; $f /= $h;
for ($i = $m; $i <= $high; $i++) for ($i = $m; $i <= $high; ++$i) {
$this->H[$i][$j] -= $f * $this->ort[$i]; $this->H[$i][$j] -= $f * $this->ort[$i];
} }
for ($i = 0; $i <= $high; $i++) { }
for ($i = 0; $i <= $high; ++$i) {
$f = 0.0; $f = 0.0;
for ($j = $high; $j >= $m; $j--) for ($j = $high; $j >= $m; --$j) {
$f += $this->ort[$j] * $this->H[$i][$j]; $f += $this->ort[$j] * $this->H[$i][$j];
}
$f = $f / $h; $f = $f / $h;
for ($j = $m; $j <= $high; $j++) for ($j = $m; $j <= $high; ++$j) {
$this->H[$i][$j] -= $f * $this->ort[$j]; $this->H[$i][$j] -= $f * $this->ort[$j];
} }
}
$this->ort[$m] = $scale * $this->ort[$m]; $this->ort[$m] = $scale * $this->ort[$m];
$this->H[$m][$m-1] = $scale * $g; $this->H[$m][$m-1] = $scale * $g;
} }
} }
// Accumulate transformations (Algol's ortran). // Accumulate transformations (Algol's ortran).
for ($i = 0; $i < $this->n; $i++) for ($i = 0; $i < $this->n; ++$i) {
for ($j = 0; $j < $this->n; $j++) for ($j = 0; $j < $this->n; ++$j) {
$this->V[$i][$j] = ($i == $j ? 1.0 : 0.0); $this->V[$i][$j] = ($i == $j ? 1.0 : 0.0);
for ($m = $high-1; $m >= $low+1; $m--) { }
}
for ($m = $high-1; $m >= $low+1; --$m) {
if ($this->H[$m][$m-1] != 0.0) { if ($this->H[$m][$m-1] != 0.0) {
for ($i = $m+1; $i <= $high; $i++) for ($i = $m+1; $i <= $high; ++$i) {
$this->ort[$i] = $this->H[$i][$m-1]; $this->ort[$i] = $this->H[$i][$m-1];
for ($j = $m; $j <= $high; $j++) { }
for ($j = $m; $j <= $high; ++$j) {
$g = 0.0; $g = 0.0;
for ($i = $m; $i <= $high; $i++) for ($i = $m; $i <= $high; ++$i) {
$g += $this->ort[$i] * $this->V[$i][$j]; $g += $this->ort[$i] * $this->V[$i][$j];
}
// Double division avoids possible underflow // Double division avoids possible underflow
$g = ($g / $this->ort[$m]) / $this->H[$m][$m-1]; $g = ($g / $this->ort[$m]) / $this->H[$m][$m-1];
for ($i = $m; $i <= $high; $i++) for ($i = $m; $i <= $high; ++$i) {
$this->V[$i][$j] += $g * $this->ort[$i]; $this->V[$i][$j] += $g * $this->ort[$i];
} }
} }
} }
} }
}
/** /**
* Performs complex division. * Performs complex division.
*
* @access private * @access private
*/ */
function cdiv($xr, $xi, $yr, $yi) { private function cdiv($xr, $xi, $yr, $yi) {
if (abs($yr) > abs($yi)) { if (abs($yr) > abs($yi)) {
$r = $yi / $yr; $r = $yi / $yr;
$d = $yr + $r * $yi; $d = $yr + $r * $yi;
@@ -354,6 +384,7 @@ class EigenvalueDecomposition {
} }
} }
/** /**
* Nonsymmetric reduction from Hessenberg to real Schur form. * Nonsymmetric reduction from Hessenberg to real Schur form.
* *
@@ -364,7 +395,7 @@ class EigenvalueDecomposition {
* *
* @access private * @access private
*/ */
function hqr2 () { private function hqr2 () {
// Initialize // Initialize
$nn = $this->n; $nn = $this->n;
$n = $nn - 1; $n = $nn - 1;
@@ -375,14 +406,17 @@ class EigenvalueDecomposition {
$p = $q = $r = $s = $z = 0; $p = $q = $r = $s = $z = 0;
// Store roots isolated by balanc and compute matrix norm // Store roots isolated by balanc and compute matrix norm
$norm = 0.0; $norm = 0.0;
for ($i = 0; $i < $nn; $i++) {
for ($i = 0; $i < $nn; ++$i) {
if (($i < $low) OR ($i > $high)) { if (($i < $low) OR ($i > $high)) {
$this->d[$i] = $this->H[$i][$i]; $this->d[$i] = $this->H[$i][$i];
$this->e[$i] = 0.0; $this->e[$i] = 0.0;
} }
for ($j = max($i-1, 0); $j < $nn; $j++) for ($j = max($i-1, 0); $j < $nn; ++$j) {
$norm = $norm + abs($this->H[$i][$j]); $norm = $norm + abs($this->H[$i][$j]);
} }
}
// Outer loop over eigenvalue index // Outer loop over eigenvalue index
$iter = 0; $iter = 0;
while ($n >= $low) { while ($n >= $low) {
@@ -390,11 +424,13 @@ class EigenvalueDecomposition {
$l = $n; $l = $n;
while ($l > $low) { while ($l > $low) {
$s = abs($this->H[$l-1][$l-1]) + abs($this->H[$l][$l]); $s = abs($this->H[$l-1][$l-1]) + abs($this->H[$l][$l]);
if ($s == 0.0) if ($s == 0.0) {
$s = $norm; $s = $norm;
if (abs($this->H[$l][$l-1]) < $eps * $s) }
if (abs($this->H[$l][$l-1]) < $eps * $s) {
break; break;
$l--; }
--$l;
} }
// Check for convergence // Check for convergence
// One root found // One root found
@@ -402,7 +438,7 @@ class EigenvalueDecomposition {
$this->H[$n][$n] = $this->H[$n][$n] + $exshift; $this->H[$n][$n] = $this->H[$n][$n] + $exshift;
$this->d[$n] = $this->H[$n][$n]; $this->d[$n] = $this->H[$n][$n];
$this->e[$n] = 0.0; $this->e[$n] = 0.0;
$n--; --$n;
$iter = 0; $iter = 0;
// Two roots found // Two roots found
} else if ($l == $n-1) { } else if ($l == $n-1) {
@@ -415,14 +451,16 @@ class EigenvalueDecomposition {
$x = $this->H[$n][$n]; $x = $this->H[$n][$n];
// Real pair // Real pair
if ($q >= 0) { if ($q >= 0) {
if ($p >= 0) if ($p >= 0) {
$z = $p + $z; $z = $p + $z;
else } else {
$z = $p - $z; $z = $p - $z;
}
$this->d[$n-1] = $x + $z; $this->d[$n-1] = $x + $z;
$this->d[$n] = $this->d[$n-1]; $this->d[$n] = $this->d[$n-1];
if ($z != 0.0) if ($z != 0.0) {
$this->d[$n] = $x - $w / $z; $this->d[$n] = $x - $w / $z;
}
$this->e[$n-1] = 0.0; $this->e[$n-1] = 0.0;
$this->e[$n] = 0.0; $this->e[$n] = 0.0;
$x = $this->H[$n][$n-1]; $x = $this->H[$n][$n-1];
@@ -433,19 +471,19 @@ class EigenvalueDecomposition {
$p = $p / $r; $p = $p / $r;
$q = $q / $r; $q = $q / $r;
// Row modification // Row modification
for ($j = $n-1; $j < $nn; $j++) { for ($j = $n-1; $j < $nn; ++$j) {
$z = $this->H[$n-1][$j]; $z = $this->H[$n-1][$j];
$this->H[$n-1][$j] = $q * $z + $p * $this->H[$n][$j]; $this->H[$n-1][$j] = $q * $z + $p * $this->H[$n][$j];
$this->H[$n][$j] = $q * $this->H[$n][$j] - $p * $z; $this->H[$n][$j] = $q * $this->H[$n][$j] - $p * $z;
} }
// Column modification // Column modification
for ($i = 0; $i <= n; $i++) { for ($i = 0; $i <= n; ++$i) {
$z = $this->H[$i][$n-1]; $z = $this->H[$i][$n-1];
$this->H[$i][$n-1] = $q * $z + $p * $this->H[$i][$n]; $this->H[$i][$n-1] = $q * $z + $p * $this->H[$i][$n];
$this->H[$i][$n] = $q * $this->H[$i][$n] - $p * $z; $this->H[$i][$n] = $q * $this->H[$i][$n] - $p * $z;
} }
// Accumulate transformations // Accumulate transformations
for ($i = $low; $i <= $high; $i++) { for ($i = $low; $i <= $high; ++$i) {
$z = $this->V[$i][$n-1]; $z = $this->V[$i][$n-1];
$this->V[$i][$n-1] = $q * $z + $p * $this->V[$i][$n]; $this->V[$i][$n-1] = $q * $z + $p * $this->V[$i][$n];
$this->V[$i][$n] = $q * $this->V[$i][$n] - $p * $z; $this->V[$i][$n] = $q * $this->V[$i][$n] - $p * $z;
@@ -472,8 +510,9 @@ class EigenvalueDecomposition {
// Wilkinson's original ad hoc shift // Wilkinson's original ad hoc shift
if ($iter == 10) { if ($iter == 10) {
$exshift += $x; $exshift += $x;
for ($i = $low; $i <= $n; $i++) for ($i = $low; $i <= $n; ++$i) {
$this->H[$i][$i] -= $x; $this->H[$i][$i] -= $x;
}
$s = abs($this->H[$n][$n-1]) + abs($this->H[$n-1][$n-2]); $s = abs($this->H[$n][$n-1]) + abs($this->H[$n-1][$n-2]);
$x = $y = 0.75 * $s; $x = $y = 0.75 * $s;
$w = -0.4375 * $s * $s; $w = -0.4375 * $s * $s;
@@ -484,11 +523,13 @@ class EigenvalueDecomposition {
$s = $s * $s + $w; $s = $s * $s + $w;
if ($s > 0) { if ($s > 0) {
$s = sqrt($s); $s = sqrt($s);
if ($y < $x) if ($y < $x) {
$s = -$s; $s = -$s;
}
$s = $x - $w / (($y - $x) / 2.0 + $s); $s = $x - $w / (($y - $x) / 2.0 + $s);
for ($i = $low; $i <= $n; $i++) for ($i = $low; $i <= $n; ++$i) {
$this->H[$i][$i] -= $s; $this->H[$i][$i] -= $s;
}
$exshift += $s; $exshift += $s;
$x = $y = $w = 0.964; $x = $y = $w = 0.964;
} }
@@ -508,19 +549,23 @@ class EigenvalueDecomposition {
$p = $p / $s; $p = $p / $s;
$q = $q / $s; $q = $q / $s;
$r = $r / $s; $r = $r / $s;
if ($m == $l) if ($m == $l) {
break; break;
if (abs($this->H[$m][$m-1]) * (abs($q) + abs($r)) < $eps * (abs($p) * (abs($this->H[$m-1][$m-1]) + abs($z) + abs($this->H[$m+1][$m+1]))))
break;
$m--;
} }
for ($i = $m + 2; $i <= $n; $i++) { if (abs($this->H[$m][$m-1]) * (abs($q) + abs($r)) <
$eps * (abs($p) * (abs($this->H[$m-1][$m-1]) + abs($z) + abs($this->H[$m+1][$m+1])))) {
break;
}
--$m;
}
for ($i = $m + 2; $i <= $n; ++$i) {
$this->H[$i][$i-2] = 0.0; $this->H[$i][$i-2] = 0.0;
if ($i > $m+2) if ($i > $m+2) {
$this->H[$i][$i-3] = 0.0; $this->H[$i][$i-3] = 0.0;
} }
}
// Double QR step involving rows l:n and columns m:n // Double QR step involving rows l:n and columns m:n
for ($k = $m; $k <= $n-1; $k++) { for ($k = $m; $k <= $n-1; ++$k) {
$notlast = ($k != $n-1); $notlast = ($k != $n-1);
if ($k != $m) { if ($k != $m) {
$p = $this->H[$k][$k-1]; $p = $this->H[$k][$k-1];
@@ -533,16 +578,19 @@ class EigenvalueDecomposition {
$r = $r / $x; $r = $r / $x;
} }
} }
if ($x == 0.0) if ($x == 0.0) {
break; break;
}
$s = sqrt($p * $p + $q * $q + $r * $r); $s = sqrt($p * $p + $q * $q + $r * $r);
if ($p < 0) if ($p < 0) {
$s = -$s; $s = -$s;
}
if ($s != 0) { if ($s != 0) {
if ($k != $m) if ($k != $m) {
$this->H[$k][$k-1] = -$s * $x; $this->H[$k][$k-1] = -$s * $x;
else if ($l != $m) } elseif ($l != $m) {
$this->H[$k][$k-1] = -$this->H[$k][$k-1]; $this->H[$k][$k-1] = -$this->H[$k][$k-1];
}
$p = $p + $s; $p = $p + $s;
$x = $p / $s; $x = $p / $s;
$y = $q / $s; $y = $q / $s;
@@ -550,7 +598,7 @@ class EigenvalueDecomposition {
$q = $q / $p; $q = $q / $p;
$r = $r / $p; $r = $r / $p;
// Row modification // Row modification
for ($j = $k; $j < $nn; $j++) { for ($j = $k; $j < $nn; ++$j) {
$p = $this->H[$k][$j] + $q * $this->H[$k+1][$j]; $p = $this->H[$k][$j] + $q * $this->H[$k+1][$j];
if ($notlast) { if ($notlast) {
$p = $p + $r * $this->H[$k+2][$j]; $p = $p + $r * $this->H[$k+2][$j];
@@ -560,7 +608,7 @@ class EigenvalueDecomposition {
$this->H[$k+1][$j] = $this->H[$k+1][$j] - $p * $y; $this->H[$k+1][$j] = $this->H[$k+1][$j] - $p * $y;
} }
// Column modification // Column modification
for ($i = 0; $i <= min($n, $k+3); $i++) { for ($i = 0; $i <= min($n, $k+3); ++$i) {
$p = $x * $this->H[$i][$k] + $y * $this->H[$i][$k+1]; $p = $x * $this->H[$i][$k] + $y * $this->H[$i][$k+1];
if ($notlast) { if ($notlast) {
$p = $p + $z * $this->H[$i][$k+2]; $p = $p + $z * $this->H[$i][$k+2];
@@ -570,7 +618,7 @@ class EigenvalueDecomposition {
$this->H[$i][$k+1] = $this->H[$i][$k+1] - $p * $q; $this->H[$i][$k+1] = $this->H[$i][$k+1] - $p * $q;
} }
// Accumulate transformations // Accumulate transformations
for ($i = $low; $i <= $high; $i++) { for ($i = $low; $i <= $high; ++$i) {
$p = $x * $this->V[$i][$k] + $y * $this->V[$i][$k+1]; $p = $x * $this->V[$i][$k] + $y * $this->V[$i][$k+1];
if ($notlast) { if ($notlast) {
$p = $p + $z * $this->V[$i][$k+2]; $p = $p + $z * $this->V[$i][$k+2];
@@ -583,31 +631,36 @@ class EigenvalueDecomposition {
} // k loop } // k loop
} // check convergence } // check convergence
} // while ($n >= $low) } // while ($n >= $low)
// Backsubstitute to find vectors of upper triangular form // Backsubstitute to find vectors of upper triangular form
if ($norm == 0.0) if ($norm == 0.0) {
return; return;
for ($n = $nn-1; $n >= 0; $n--) { }
for ($n = $nn-1; $n >= 0; --$n) {
$p = $this->d[$n]; $p = $this->d[$n];
$q = $this->e[$n]; $q = $this->e[$n];
// Real vector // Real vector
if ($q == 0) { if ($q == 0) {
$l = $n; $l = $n;
$this->H[$n][$n] = 1.0; $this->H[$n][$n] = 1.0;
for ($i = $n-1; $i >= 0; $i--) { for ($i = $n-1; $i >= 0; --$i) {
$w = $this->H[$i][$i] - $p; $w = $this->H[$i][$i] - $p;
$r = 0.0; $r = 0.0;
for ($j = $l; $j <= $n; $j++) for ($j = $l; $j <= $n; ++$j) {
$r = $r + $this->H[$i][$j] * $this->H[$j][$n]; $r = $r + $this->H[$i][$j] * $this->H[$j][$n];
}
if ($this->e[$i] < 0.0) { if ($this->e[$i] < 0.0) {
$z = $w; $z = $w;
$s = $r; $s = $r;
} else { } else {
$l = $i; $l = $i;
if ($this->e[$i] == 0.0) { if ($this->e[$i] == 0.0) {
if ($w != 0.0) if ($w != 0.0) {
$this->H[$i][$n] = -$r / $w; $this->H[$i][$n] = -$r / $w;
else } else {
$this->H[$i][$n] = -$r / ($eps * $norm); $this->H[$i][$n] = -$r / ($eps * $norm);
}
// Solve real equations // Solve real equations
} else { } else {
$x = $this->H[$i][$i+1]; $x = $this->H[$i][$i+1];
@@ -615,19 +668,21 @@ class EigenvalueDecomposition {
$q = ($this->d[$i] - $p) * ($this->d[$i] - $p) + $this->e[$i] * $this->e[$i]; $q = ($this->d[$i] - $p) * ($this->d[$i] - $p) + $this->e[$i] * $this->e[$i];
$t = ($x * $s - $z * $r) / $q; $t = ($x * $s - $z * $r) / $q;
$this->H[$i][$n] = $t; $this->H[$i][$n] = $t;
if (abs($x) > abs($z)) if (abs($x) > abs($z)) {
$this->H[$i+1][$n] = (-$r - $w * $t) / $x; $this->H[$i+1][$n] = (-$r - $w * $t) / $x;
else } else {
$this->H[$i+1][$n] = (-$s - $y * $t) / $z; $this->H[$i+1][$n] = (-$s - $y * $t) / $z;
} }
}
// Overflow control // Overflow control
$t = abs($this->H[$i][$n]); $t = abs($this->H[$i][$n]);
if (($eps * $t) * $t > 1) { if (($eps * $t) * $t > 1) {
for ($j = $i; $j <= $n; $j++) for ($j = $i; $j <= $n; ++$j) {
$this->H[$j][$n] = $this->H[$j][$n] / $t; $this->H[$j][$n] = $this->H[$j][$n] / $t;
} }
} }
} }
}
// Complex vector // Complex vector
} else if ($q < 0) { } else if ($q < 0) {
$l = $n-1; $l = $n-1;
@@ -642,11 +697,11 @@ class EigenvalueDecomposition {
} }
$this->H[$n][$n-1] = 0.0; $this->H[$n][$n-1] = 0.0;
$this->H[$n][$n] = 1.0; $this->H[$n][$n] = 1.0;
for ($i = $n-2; $i >= 0; $i--) { for ($i = $n-2; $i >= 0; --$i) {
// double ra,sa,vr,vi; // double ra,sa,vr,vi;
$ra = 0.0; $ra = 0.0;
$sa = 0.0; $sa = 0.0;
for ($j = $l; $j <= $n; $j++) { for ($j = $l; $j <= $n; ++$j) {
$ra = $ra + $this->H[$i][$j] * $this->H[$j][$n-1]; $ra = $ra + $this->H[$i][$j] * $this->H[$j][$n-1];
$sa = $sa + $this->H[$i][$j] * $this->H[$j][$n]; $sa = $sa + $this->H[$i][$j] * $this->H[$j][$n];
} }
@@ -667,8 +722,9 @@ class EigenvalueDecomposition {
$y = $this->H[$i+1][$i]; $y = $this->H[$i+1][$i];
$vr = ($this->d[$i] - $p) * ($this->d[$i] - $p) + $this->e[$i] * $this->e[$i] - $q * $q; $vr = ($this->d[$i] - $p) * ($this->d[$i] - $p) + $this->e[$i] * $this->e[$i] - $q * $q;
$vi = ($this->d[$i] - $p) * 2.0 * $q; $vi = ($this->d[$i] - $p) * 2.0 * $q;
if ($vr == 0.0 & $vi == 0.0) if ($vr == 0.0 & $vi == 0.0) {
$vr = $eps * $norm * (abs($w) + abs($q) + abs($x) + abs($y) + abs($z)); $vr = $eps * $norm * (abs($w) + abs($q) + abs($x) + abs($y) + abs($z));
}
$this->cdiv($x * $r - $z * $ra + $q * $sa, $x * $s - $z * $sa - $q * $ra, $vr, $vi); $this->cdiv($x * $r - $z * $ra + $q * $sa, $x * $s - $z * $sa - $q * $ra, $vr, $vi);
$this->H[$i][$n-1] = $this->cdivr; $this->H[$i][$n-1] = $this->cdivr;
$this->H[$i][$n] = $this->cdivi; $this->H[$i][$n] = $this->cdivi;
@@ -684,7 +740,7 @@ class EigenvalueDecomposition {
// Overflow control // Overflow control
$t = max(abs($this->H[$i][$n-1]),abs($this->H[$i][$n])); $t = max(abs($this->H[$i][$n-1]),abs($this->H[$i][$n]));
if (($eps * $t) * $t > 1) { if (($eps * $t) * $t > 1) {
for ($j = $i; $j <= $n; $j++) { for ($j = $i; $j <= $n; ++$j) {
$this->H[$j][$n-1] = $this->H[$j][$n-1] / $t; $this->H[$j][$n-1] = $this->H[$j][$n-1] / $t;
$this->H[$j][$n] = $this->H[$j][$n] / $t; $this->H[$j][$n] = $this->H[$j][$n] / $t;
} }
@@ -693,40 +749,47 @@ class EigenvalueDecomposition {
} // end for } // end for
} // end else for complex case } // end else for complex case
} // end for } // end for
// Vectors of isolated roots // Vectors of isolated roots
for ($i = 0; $i < $nn; $i++) { for ($i = 0; $i < $nn; ++$i) {
if ($i < $low | $i > $high) { if ($i < $low | $i > $high) {
for ($j = $i; $j < $nn; $j++) for ($j = $i; $j < $nn; ++$j) {
$this->V[$i][$j] = $this->H[$i][$j]; $this->V[$i][$j] = $this->H[$i][$j];
} }
} }
}
// Back transformation to get eigenvectors of original matrix // Back transformation to get eigenvectors of original matrix
for ($j = $nn-1; $j >= $low; $j--) { for ($j = $nn-1; $j >= $low; --$j) {
for ($i = $low; $i <= $high; $i++) { for ($i = $low; $i <= $high; ++$i) {
$z = 0.0; $z = 0.0;
for ($k = $low; $k <= min($j,$high); $k++) for ($k = $low; $k <= min($j,$high); ++$k) {
$z = $z + $this->V[$i][$k] * $this->H[$k][$j]; $z = $z + $this->V[$i][$k] * $this->H[$k][$j];
}
$this->V[$i][$j] = $z; $this->V[$i][$j] = $z;
} }
} }
} // end hqr2 } // end hqr2
/** /**
* Constructor: Check for symmetry, then construct the eigenvalue decomposition * Constructor: Check for symmetry, then construct the eigenvalue decomposition
*
* @access public * @access public
* @param A Square matrix * @param A Square matrix
* @return Structure to access D and V. * @return Structure to access D and V.
*/ */
function EigenvalueDecomposition($Arg) { public function __construct($Arg) {
$this->A = $Arg->getArray(); $this->A = $Arg->getArray();
$this->n = $Arg->getColumnDimension(); $this->n = $Arg->getColumnDimension();
$this->V = array();
$this->d = array();
$this->e = array();
$issymmetric = true; $issymmetric = true;
for ($j = 0; ($j < $this->n) & $issymmetric; $j++) for ($j = 0; ($j < $this->n) & $issymmetric; ++$j) {
for ($i = 0; ($i < $this->n) & $issymmetric; $i++) for ($i = 0; ($i < $this->n) & $issymmetric; ++$i) {
$issymmetric = ($this->A[$i][$j] == $this->A[$j][$i]); $issymmetric = ($this->A[$i][$j] == $this->A[$j][$i]);
}
}
if ($issymmetric) { if ($issymmetric) {
$this->V = $this->A; $this->V = $this->A;
// Tridiagonalize. // Tridiagonalize.
@@ -743,47 +806,57 @@ class EigenvalueDecomposition {
} }
} }
/** /**
* Return the eigenvector matrix * Return the eigenvector matrix
*
* @access public * @access public
* @return V * @return V
*/ */
function getV() { public function getV() {
return new Matrix($this->V, $this->n, $this->n); return new Matrix($this->V, $this->n, $this->n);
} }
/** /**
* Return the real parts of the eigenvalues * Return the real parts of the eigenvalues
*
* @access public * @access public
* @return real(diag(D)) * @return real(diag(D))
*/ */
function getRealEigenvalues() { public function getRealEigenvalues() {
return $this->d; return $this->d;
} }
/** /**
* Return the imaginary parts of the eigenvalues * Return the imaginary parts of the eigenvalues
*
* @access public * @access public
* @return imag(diag(D)) * @return imag(diag(D))
*/ */
function getImagEigenvalues() { public function getImagEigenvalues() {
return $this->e; return $this->e;
} }
/** /**
* Return the block diagonal eigenvalue matrix * Return the block diagonal eigenvalue matrix
*
* @access public * @access public
* @return D * @return D
*/ */
function getD() { public function getD() {
for ($i = 0; $i < $this->n; $i++) { for ($i = 0; $i < $this->n; ++$i) {
$D[$i] = array_fill(0, $this->n, 0.0); $D[$i] = array_fill(0, $this->n, 0.0);
$D[$i][$i] = $this->d[$i]; $D[$i][$i] = $this->d[$i];
if ($this->e[$i] == 0) if ($this->e[$i] == 0) {
continue; continue;
}
$o = ($this->e[$i] > 0) ? $i + 1 : $i - 1; $o = ($this->e[$i] > 0) ? $i + 1 : $i - 1;
$D[$i][$o] = $this->e[$i]; $D[$i][$o] = $this->e[$i];
} }
return new Matrix($D); return new Matrix($D);
} }
}
} // class EigenvalueDecomposition

View File

@@ -19,75 +19,82 @@
* @license PHP v3.0 * @license PHP v3.0
*/ */
class LUDecomposition { class LUDecomposition {
/** /**
* Decomposition storage * Decomposition storage
* @var array * @var array
*/ */
var $LU = array(); private $LU = array();
/** /**
* Row dimension. * Row dimension.
* @var int * @var int
*/ */
var $m; private $m;
/** /**
* Column dimension. * Column dimension.
* @var int * @var int
*/ */
var $n; private $n;
/** /**
* Pivot sign. * Pivot sign.
* @var int * @var int
*/ */
var $pivsign; private $pivsign;
/** /**
* Internal storage of pivot vector. * Internal storage of pivot vector.
* @var array * @var array
*/ */
var $piv = array(); private $piv = array();
/** /**
* LU Decomposition constructor. * LU Decomposition constructor.
*
* @param $A Rectangular matrix * @param $A Rectangular matrix
* @return Structure to access L, U and piv. * @return Structure to access L, U and piv.
*/ */
function LUDecomposition ($A) { public function __construct($A) {
if( is_a($A, 'Matrix') ) { if ($A instanceof Matrix) {
// Use a "left-looking", dot-product, Crout/Doolittle algorithm. // Use a "left-looking", dot-product, Crout/Doolittle algorithm.
$this->LU = $A->getArrayCopy(); $this->LU = $A->getArrayCopy();
$this->m = $A->getRowDimension(); $this->m = $A->getRowDimension();
$this->n = $A->getColumnDimension(); $this->n = $A->getColumnDimension();
for ($i = 0; $i < $this->m; $i++) for ($i = 0; $i < $this->m; ++$i) {
$this->piv[$i] = $i; $this->piv[$i] = $i;
}
$this->pivsign = 1; $this->pivsign = 1;
$LUrowi = array(); $LUrowi = $LUcolj = array();
$LUcolj = array();
// Outer loop. // Outer loop.
for ($j = 0; $j < $this->n; $j++) { for ($j = 0; $j < $this->n; ++$j) {
// Make a copy of the j-th column to localize references. // Make a copy of the j-th column to localize references.
for ($i = 0; $i < $this->m; $i++) for ($i = 0; $i < $this->m; ++$i) {
$LUcolj[$i] = &$this->LU[$i][$j]; $LUcolj[$i] = &$this->LU[$i][$j];
}
// Apply previous transformations. // Apply previous transformations.
for ($i = 0; $i < $this->m; $i++) { for ($i = 0; $i < $this->m; ++$i) {
$LUrowi = $this->LU[$i]; $LUrowi = $this->LU[$i];
// Most of the time is spent in the following dot product. // Most of the time is spent in the following dot product.
$kmax = min($i,$j); $kmax = min($i,$j);
$s = 0.0; $s = 0.0;
for ($k = 0; $k < $kmax; $k++) for ($k = 0; $k < $kmax; ++$k) {
$s += $LUrowi[$k] * $LUcolj[$k]; $s += $LUrowi[$k] * $LUcolj[$k];
}
$LUrowi[$j] = $LUcolj[$i] -= $s; $LUrowi[$j] = $LUcolj[$i] -= $s;
} }
// Find pivot and exchange if necessary. // Find pivot and exchange if necessary.
$p = $j; $p = $j;
for ($i = $j+1; $i < $this->m; $i++) { for ($i = $j+1; $i < $this->m; ++$i) {
if (abs($LUcolj[$i]) > abs($LUcolj[$p])) if (abs($LUcolj[$i]) > abs($LUcolj[$p])) {
$p = $i; $p = $i;
} }
}
if ($p != $j) { if ($p != $j) {
for ($k = 0; $k < $this->n; $k++) { for ($k = 0; $k < $this->n; ++$k) {
$t = $this->LU[$p][$k]; $t = $this->LU[$p][$k];
$this->LU[$p][$k] = $this->LU[$j][$k]; $this->LU[$p][$k] = $this->LU[$j][$k];
$this->LU[$j][$k] = $t; $this->LU[$j][$k] = $t;
@@ -98,125 +105,151 @@ class LUDecomposition {
$this->pivsign = $this->pivsign * -1; $this->pivsign = $this->pivsign * -1;
} }
// Compute multipliers. // Compute multipliers.
if ( ($j < $this->m) AND ($this->LU[$j][$j] != 0.0) ) { if (($j < $this->m) && ($this->LU[$j][$j] != 0.0)) {
for ($i = $j+1; $i < $this->m; $i++) for ($i = $j+1; $i < $this->m; ++$i) {
$this->LU[$i][$j] /= $this->LU[$j][$j]; $this->LU[$i][$j] /= $this->LU[$j][$j];
} }
} }
}
} else { } else {
trigger_error(ArgumentTypeException, ERROR); throw new Exception(JAMAError(ArgumentTypeException));
}
} }
} // function __construct()
/** /**
* Get lower triangular factor. * Get lower triangular factor.
*
* @return array Lower triangular factor * @return array Lower triangular factor
*/ */
function getL () { public function getL() {
for ($i = 0; $i < $this->m; $i++) { for ($i = 0; $i < $this->m; ++$i) {
for ($j = 0; $j < $this->n; $j++) { for ($j = 0; $j < $this->n; ++$j) {
if ($i > $j) if ($i > $j) {
$L[$i][$j] = $this->LU[$i][$j]; $L[$i][$j] = $this->LU[$i][$j];
else if($i == $j) } elseif ($i == $j) {
$L[$i][$j] = 1.0; $L[$i][$j] = 1.0;
else } else {
$L[$i][$j] = 0.0; $L[$i][$j] = 0.0;
} }
} }
return new Matrix($L);
} }
return new Matrix($L);
} // function getL()
/** /**
* Get upper triangular factor. * Get upper triangular factor.
*
* @return array Upper triangular factor * @return array Upper triangular factor
*/ */
function getU () { public function getU() {
for ($i = 0; $i < $this->n; $i++) { for ($i = 0; $i < $this->n; ++$i) {
for ($j = 0; $j < $this->n; $j++) { for ($j = 0; $j < $this->n; ++$j) {
if ($i <= $j) if ($i <= $j) {
$U[$i][$j] = $this->LU[$i][$j]; $U[$i][$j] = $this->LU[$i][$j];
else } else {
$U[$i][$j] = 0.0; $U[$i][$j] = 0.0;
} }
} }
return new Matrix($U);
} }
return new Matrix($U);
} // function getU()
/** /**
* Return pivot permutation vector. * Return pivot permutation vector.
*
* @return array Pivot vector * @return array Pivot vector
*/ */
function getPivot () { public function getPivot() {
return $this->piv; return $this->piv;
} } // function getPivot()
/** /**
* Alias for getPivot * Alias for getPivot
*
* @see getPivot * @see getPivot
*/ */
function getDoublePivot () { public function getDoublePivot() {
return $this->getPivot(); return $this->getPivot();
} } // function getDoublePivot()
/** /**
* Is the matrix nonsingular? * Is the matrix nonsingular?
*
* @return true if U, and hence A, is nonsingular. * @return true if U, and hence A, is nonsingular.
*/ */
function isNonsingular () { public function isNonsingular() {
for ($j = 0; $j < $this->n; $j++) { for ($j = 0; $j < $this->n; ++$j) {
if ($this->LU[$j][$j] == 0) if ($this->LU[$j][$j] == 0) {
return false; return false;
} }
return true;
} }
return true;
} // function isNonsingular()
/** /**
* Count determinants * Count determinants
*
* @return array d matrix deterninat * @return array d matrix deterninat
*/ */
function det() { public function det() {
if ($this->m == $this->n) { if ($this->m == $this->n) {
$d = $this->pivsign; $d = $this->pivsign;
for ($j = 0; $j < $this->n; $j++) for ($j = 0; $j < $this->n; ++$j) {
$d *= $this->LU[$j][$j]; $d *= $this->LU[$j][$j];
}
return $d; return $d;
} else { } else {
trigger_error(MatrixDimensionException, ERROR); throw new Exception(JAMAError(MatrixDimensionException));
}
} }
} // function det()
/** /**
* Solve A*X = B * Solve A*X = B
*
* @param $B A Matrix with as many rows as A and any number of columns. * @param $B A Matrix with as many rows as A and any number of columns.
* @return X so that L*U*X = B(piv,:) * @return X so that L*U*X = B(piv,:)
* @exception IllegalArgumentException Matrix row dimensions must agree. * @exception IllegalArgumentException Matrix row dimensions must agree.
* @exception RuntimeException Matrix is singular. * @exception RuntimeException Matrix is singular.
*/ */
function solve($B) { public function solve($B) {
if ($B->getRowDimension() == $this->m) { if ($B->getRowDimension() == $this->m) {
if ($this->isNonsingular()) { if ($this->isNonsingular()) {
// Copy right hand side with pivoting // Copy right hand side with pivoting
$nx = $B->getColumnDimension(); $nx = $B->getColumnDimension();
$X = $B->getMatrix($this->piv, 0, $nx-1); $X = $B->getMatrix($this->piv, 0, $nx-1);
// Solve L*Y = B(piv,:) // Solve L*Y = B(piv,:)
for ($k = 0; $k < $this->n; $k++) for ($k = 0; $k < $this->n; ++$k) {
for ($i = $k+1; $i < $this->n; $i++) for ($i = $k+1; $i < $this->n; ++$i) {
for ($j = 0; $j < $nx; $j++) for ($j = 0; $j < $nx; ++$j) {
$X->A[$i][$j] -= $X->A[$k][$j] * $this->LU[$i][$k]; $X->A[$i][$j] -= $X->A[$k][$j] * $this->LU[$i][$k];
}
}
}
// Solve U*X = Y; // Solve U*X = Y;
for ($k = $this->n-1; $k >= 0; $k--) { for ($k = $this->n-1; $k >= 0; --$k) {
for ($j = 0; $j < $nx; $j++) for ($j = 0; $j < $nx; ++$j) {
$X->A[$k][$j] /= $this->LU[$k][$k]; $X->A[$k][$j] /= $this->LU[$k][$k];
for ($i = 0; $i < $k; $i++) }
for ($j = 0; $j < $nx; $j++) for ($i = 0; $i < $k; ++$i) {
for ($j = 0; $j < $nx; ++$j) {
$X->A[$i][$j] -= $X->A[$k][$j] * $this->LU[$i][$k]; $X->A[$i][$j] -= $X->A[$k][$j] * $this->LU[$i][$k];
} }
}
}
return $X; return $X;
} else { } else {
trigger_error(MatrixSingularException, ERROR); throw new Exception(JAMAError(MatrixSingularException));
} }
} else { } else {
trigger_error(MatrixSquareException, ERROR); throw new Exception(JAMAError(MatrixSquareException));
}
}
} }
} // function solve()
} // class LUDecomposition

File diff suppressed because it is too large Load Diff

View File

@@ -17,179 +17,216 @@
* @version 1.1 * @version 1.1
*/ */
class QRDecomposition { class QRDecomposition {
/** /**
* Array for internal storage of decomposition. * Array for internal storage of decomposition.
* @var array * @var array
*/ */
var $QR = array(); private $QR = array();
/** /**
* Row dimension. * Row dimension.
* @var integer * @var integer
*/ */
var $m; private $m;
/** /**
* Column dimension. * Column dimension.
* @var integer * @var integer
*/ */
var $n; private $n;
/** /**
* Array for internal storage of diagonal of R. * Array for internal storage of diagonal of R.
* @var array * @var array
*/ */
var $Rdiag = array(); private $Rdiag = array();
/** /**
* QR Decomposition computed by Householder reflections. * QR Decomposition computed by Householder reflections.
*
* @param matrix $A Rectangular matrix * @param matrix $A Rectangular matrix
* @return Structure to access R and the Householder vectors and compute Q. * @return Structure to access R and the Householder vectors and compute Q.
*/ */
function QRDecomposition($A) { public function __construct($A) {
if( is_a($A, 'Matrix') ) { if($A instanceof Matrix) {
// Initialize. // Initialize.
$this->QR = $A->getArrayCopy(); $this->QR = $A->getArrayCopy();
$this->m = $A->getRowDimension(); $this->m = $A->getRowDimension();
$this->n = $A->getColumnDimension(); $this->n = $A->getColumnDimension();
// Main loop. // Main loop.
for ($k = 0; $k < $this->n; $k++) { for ($k = 0; $k < $this->n; ++$k) {
// Compute 2-norm of k-th column without under/overflow. // Compute 2-norm of k-th column without under/overflow.
$nrm = 0.0; $nrm = 0.0;
for ($i = $k; $i < $this->m; $i++) for ($i = $k; $i < $this->m; ++$i) {
$nrm = hypo($nrm, $this->QR[$i][$k]); $nrm = hypo($nrm, $this->QR[$i][$k]);
}
if ($nrm != 0.0) { if ($nrm != 0.0) {
// Form k-th Householder vector. // Form k-th Householder vector.
if ($this->QR[$k][$k] < 0) if ($this->QR[$k][$k] < 0) {
$nrm = -$nrm; $nrm = -$nrm;
for ($i = $k; $i < $this->m; $i++) }
for ($i = $k; $i < $this->m; ++$i) {
$this->QR[$i][$k] /= $nrm; $this->QR[$i][$k] /= $nrm;
}
$this->QR[$k][$k] += 1.0; $this->QR[$k][$k] += 1.0;
// Apply transformation to remaining columns. // Apply transformation to remaining columns.
for ($j = $k+1; $j < $this->n; $j++) { for ($j = $k+1; $j < $this->n; ++$j) {
$s = 0.0; $s = 0.0;
for ($i = $k; $i < $this->m; $i++) for ($i = $k; $i < $this->m; ++$i) {
$s += $this->QR[$i][$k] * $this->QR[$i][$j]; $s += $this->QR[$i][$k] * $this->QR[$i][$j];
}
$s = -$s/$this->QR[$k][$k]; $s = -$s/$this->QR[$k][$k];
for ($i = $k; $i < $this->m; $i++) for ($i = $k; $i < $this->m; ++$i) {
$this->QR[$i][$j] += $s * $this->QR[$i][$k]; $this->QR[$i][$j] += $s * $this->QR[$i][$k];
} }
} }
}
$this->Rdiag[$k] = -$nrm; $this->Rdiag[$k] = -$nrm;
} }
} else } else {
trigger_error(ArgumentTypeException, ERROR); throw new Exception(JAMAError(ArgumentTypeException));
} }
} // function __construct()
/** /**
* Is the matrix full rank? * Is the matrix full rank?
*
* @return boolean true if R, and hence A, has full rank, else false. * @return boolean true if R, and hence A, has full rank, else false.
*/ */
function isFullRank() { public function isFullRank() {
for ($j = 0; $j < $this->n; $j++) for ($j = 0; $j < $this->n; ++$j) {
if ($this->Rdiag[$j] == 0) if ($this->Rdiag[$j] == 0) {
return false; return false;
return true;
} }
}
return true;
} // function isFullRank()
/** /**
* Return the Householder vectors * Return the Householder vectors
*
* @return Matrix Lower trapezoidal matrix whose columns define the reflections * @return Matrix Lower trapezoidal matrix whose columns define the reflections
*/ */
function getH() { public function getH() {
for ($i = 0; $i < $this->m; $i++) { for ($i = 0; $i < $this->m; ++$i) {
for ($j = 0; $j < $this->n; $j++) { for ($j = 0; $j < $this->n; ++$j) {
if ($i >= $j) if ($i >= $j) {
$H[$i][$j] = $this->QR[$i][$j]; $H[$i][$j] = $this->QR[$i][$j];
else } else {
$H[$i][$j] = 0.0; $H[$i][$j] = 0.0;
} }
} }
return new Matrix($H);
} }
return new Matrix($H);
} // function getH()
/** /**
* Return the upper triangular factor * Return the upper triangular factor
*
* @return Matrix upper triangular factor * @return Matrix upper triangular factor
*/ */
function getR() { public function getR() {
for ($i = 0; $i < $this->n; $i++) { for ($i = 0; $i < $this->n; ++$i) {
for ($j = 0; $j < $this->n; $j++) { for ($j = 0; $j < $this->n; ++$j) {
if ($i < $j) if ($i < $j) {
$R[$i][$j] = $this->QR[$i][$j]; $R[$i][$j] = $this->QR[$i][$j];
else if ($i == $j) } elseif ($i == $j) {
$R[$i][$j] = $this->Rdiag[$i]; $R[$i][$j] = $this->Rdiag[$i];
else } else {
$R[$i][$j] = 0.0; $R[$i][$j] = 0.0;
} }
} }
return new Matrix($R);
} }
return new Matrix($R);
} // function getR()
/** /**
* Generate and return the (economy-sized) orthogonal factor * Generate and return the (economy-sized) orthogonal factor
*
* @return Matrix orthogonal factor * @return Matrix orthogonal factor
*/ */
function getQ() { public function getQ() {
for ($k = $this->n-1; $k >= 0; $k--) { for ($k = $this->n-1; $k >= 0; --$k) {
for ($i = 0; $i < $this->m; $i++) for ($i = 0; $i < $this->m; ++$i) {
$Q[$i][$k] = 0.0; $Q[$i][$k] = 0.0;
}
$Q[$k][$k] = 1.0; $Q[$k][$k] = 1.0;
for ($j = $k; $j < $this->n; $j++) { for ($j = $k; $j < $this->n; ++$j) {
if ($this->QR[$k][$k] != 0) { if ($this->QR[$k][$k] != 0) {
$s = 0.0; $s = 0.0;
for ($i = $k; $i < $this->m; $i++) for ($i = $k; $i < $this->m; ++$i) {
$s += $this->QR[$i][$k] * $Q[$i][$j]; $s += $this->QR[$i][$k] * $Q[$i][$j];
}
$s = -$s/$this->QR[$k][$k]; $s = -$s/$this->QR[$k][$k];
for ($i = $k; $i < $this->m; $i++) for ($i = $k; $i < $this->m; ++$i) {
$Q[$i][$j] += $s * $this->QR[$i][$k]; $Q[$i][$j] += $s * $this->QR[$i][$k];
} }
} }
} }
}
/* /*
for( $i = 0; $i < count($Q); $i++ ) for($i = 0; $i < count($Q); ++$i) {
for( $j = 0; $j < count($Q); $j++ ) for($j = 0; $j < count($Q); ++$j) {
if(! isset($Q[$i][$j]) ) if(! isset($Q[$i][$j]) ) {
$Q[$i][$j] = 0; $Q[$i][$j] = 0;
}
}
}
*/ */
return new Matrix($Q); return new Matrix($Q);
} } // function getQ()
/** /**
* Least squares solution of A*X = B * Least squares solution of A*X = B
*
* @param Matrix $B A Matrix with as many rows as A and any number of columns. * @param Matrix $B A Matrix with as many rows as A and any number of columns.
* @return Matrix Matrix that minimizes the two norm of Q*R*X-B. * @return Matrix Matrix that minimizes the two norm of Q*R*X-B.
*/ */
function solve($B) { public function solve($B) {
if ($B->getRowDimension() == $this->m) { if ($B->getRowDimension() == $this->m) {
if ($this->isFullRank()) { if ($this->isFullRank()) {
// Copy right hand side // Copy right hand side
$nx = $B->getColumnDimension(); $nx = $B->getColumnDimension();
$X = $B->getArrayCopy(); $X = $B->getArrayCopy();
// Compute Y = transpose(Q)*B // Compute Y = transpose(Q)*B
for ($k = 0; $k < $this->n; $k++) { for ($k = 0; $k < $this->n; ++$k) {
for ($j = 0; $j < $nx; $j++) { for ($j = 0; $j < $nx; ++$j) {
$s = 0.0; $s = 0.0;
for ($i = $k; $i < $this->m; $i++) for ($i = $k; $i < $this->m; ++$i) {
$s += $this->QR[$i][$k] * $X[$i][$j]; $s += $this->QR[$i][$k] * $X[$i][$j];
}
$s = -$s/$this->QR[$k][$k]; $s = -$s/$this->QR[$k][$k];
for ($i = $k; $i < $this->m; $i++) for ($i = $k; $i < $this->m; ++$i) {
$X[$i][$j] += $s * $this->QR[$i][$k]; $X[$i][$j] += $s * $this->QR[$i][$k];
} }
} }
}
// Solve R*X = Y; // Solve R*X = Y;
for ($k = $this->n-1; $k >= 0; $k--) { for ($k = $this->n-1; $k >= 0; --$k) {
for ($j = 0; $j < $nx; $j++) for ($j = 0; $j < $nx; ++$j) {
$X[$k][$j] /= $this->Rdiag[$k]; $X[$k][$j] /= $this->Rdiag[$k];
for ($i = 0; $i < $k; $i++) }
for ($j = 0; $j < $nx; $j++) for ($i = 0; $i < $k; ++$i) {
for ($j = 0; $j < $nx; ++$j) {
$X[$i][$j] -= $X[$k][$j]* $this->QR[$i][$k]; $X[$i][$j] -= $X[$k][$j]* $this->QR[$i][$k];
} }
}
}
$X = new Matrix($X); $X = new Matrix($X);
return ($X->getMatrix(0, $this->n-1, 0, $nx)); return ($X->getMatrix(0, $this->n-1, 0, $nx));
} else } else {
trigger_error(MatrixRankException, ERROR); throw new Exception(JAMAError(MatrixRankException));
} else
trigger_error(MatrixDimensionException, ERROR);
} }
} else {
throw new Exception(JAMAError(MatrixDimensionException));
} }
} // function solve()
} // class QRDecomposition

View File

@@ -23,31 +23,32 @@ class SingularValueDecomposition {
* Internal storage of U. * Internal storage of U.
* @var array * @var array
*/ */
var $U = array(); private $U = array();
/** /**
* Internal storage of V. * Internal storage of V.
* @var array * @var array
*/ */
var $V = array(); private $V = array();
/** /**
* Internal storage of singular values. * Internal storage of singular values.
* @var array * @var array
*/ */
var $s = array(); private $s = array();
/** /**
* Row dimension. * Row dimension.
* @var int * @var int
*/ */
var $m; private $m;
/** /**
* Column dimension. * Column dimension.
* @var int * @var int
*/ */
var $n; private $n;
/** /**
* Construct the singular value decomposition * Construct the singular value decomposition
@@ -57,10 +58,9 @@ class SingularValueDecomposition {
* @param $A Rectangular matrix * @param $A Rectangular matrix
* @return Structure to access U, S and V. * @return Structure to access U, S and V.
*/ */
function SingularValueDecomposition ($Arg) { public function __construct($Arg) {
// Initialize. // Initialize.
$A = $Arg->getArrayCopy(); $A = $Arg->getArrayCopy();
$this->m = $Arg->getRowDimension(); $this->m = $Arg->getRowDimension();
$this->n = $Arg->getColumnDimension(); $this->n = $Arg->getColumnDimension();
@@ -74,35 +74,39 @@ class SingularValueDecomposition {
// Reduce A to bidiagonal form, storing the diagonal elements // Reduce A to bidiagonal form, storing the diagonal elements
// in s and the super-diagonal elements in e. // in s and the super-diagonal elements in e.
for ($k = 0; $k < max($nct,$nrt); ++$k) {
for ($k = 0; $k < max($nct,$nrt); $k++) {
if ($k < $nct) { if ($k < $nct) {
// Compute the transformation for the k-th column and // Compute the transformation for the k-th column and
// place the k-th diagonal in s[$k]. // place the k-th diagonal in s[$k].
// Compute 2-norm of k-th column without under/overflow. // Compute 2-norm of k-th column without under/overflow.
$this->s[$k] = 0; $this->s[$k] = 0;
for ($i = $k; $i < $this->m; $i++) for ($i = $k; $i < $this->m; ++$i) {
$this->s[$k] = hypo($this->s[$k], $A[$i][$k]); $this->s[$k] = hypo($this->s[$k], $A[$i][$k]);
}
if ($this->s[$k] != 0.0) { if ($this->s[$k] != 0.0) {
if ($A[$k][$k] < 0.0) if ($A[$k][$k] < 0.0) {
$this->s[$k] = -$this->s[$k]; $this->s[$k] = -$this->s[$k];
for ($i = $k; $i < $this->m; $i++) }
for ($i = $k; $i < $this->m; ++$i) {
$A[$i][$k] /= $this->s[$k]; $A[$i][$k] /= $this->s[$k];
}
$A[$k][$k] += 1.0; $A[$k][$k] += 1.0;
} }
$this->s[$k] = -$this->s[$k]; $this->s[$k] = -$this->s[$k];
} }
for ($j = $k + 1; $j < $this->n; $j++) { for ($j = $k + 1; $j < $this->n; ++$j) {
if (($k < $nct) & ($this->s[$k] != 0.0)) { if (($k < $nct) & ($this->s[$k] != 0.0)) {
// Apply the transformation. // Apply the transformation.
$t = 0; $t = 0;
for ($i = $k; $i < $this->m; $i++) for ($i = $k; $i < $this->m; ++$i) {
$t += $A[$i][$k] * $A[$i][$j]; $t += $A[$i][$k] * $A[$i][$j];
}
$t = -$t / $A[$k][$k]; $t = -$t / $A[$k][$k];
for ($i = $k; $i < $this->m; $i++) for ($i = $k; $i < $this->m; ++$i) {
$A[$i][$j] += $t * $A[$i][$k]; $A[$i][$j] += $t * $A[$i][$k];
}
// Place the k-th row of A into e for the // Place the k-th row of A into e for the
// subsequent calculation of the row transformation. // subsequent calculation of the row transformation.
$e[$j] = $A[$k][$j]; $e[$j] = $A[$k][$j];
@@ -112,81 +116,99 @@ class SingularValueDecomposition {
if ($wantu AND ($k < $nct)) { if ($wantu AND ($k < $nct)) {
// Place the transformation in U for subsequent back // Place the transformation in U for subsequent back
// multiplication. // multiplication.
for ($i = $k; $i < $this->m; $i++) for ($i = $k; $i < $this->m; ++$i) {
$this->U[$i][$k] = $A[$i][$k]; $this->U[$i][$k] = $A[$i][$k];
} }
}
if ($k < $nrt) { if ($k < $nrt) {
// Compute the k-th row transformation and place the // Compute the k-th row transformation and place the
// k-th super-diagonal in e[$k]. // k-th super-diagonal in e[$k].
// Compute 2-norm without under/overflow. // Compute 2-norm without under/overflow.
$e[$k] = 0; $e[$k] = 0;
for ($i = $k + 1; $i < $this->n; $i++) for ($i = $k + 1; $i < $this->n; ++$i) {
$e[$k] = hypo($e[$k], $e[$i]); $e[$k] = hypo($e[$k], $e[$i]);
}
if ($e[$k] != 0.0) { if ($e[$k] != 0.0) {
if ($e[$k+1] < 0.0) if ($e[$k+1] < 0.0) {
$e[$k] = -$e[$k]; $e[$k] = -$e[$k];
for ($i = $k + 1; $i < $this->n; $i++) }
for ($i = $k + 1; $i < $this->n; ++$i) {
$e[$i] /= $e[$k]; $e[$i] /= $e[$k];
}
$e[$k+1] += 1.0; $e[$k+1] += 1.0;
} }
$e[$k] = -$e[$k]; $e[$k] = -$e[$k];
if (($k+1 < $this->m) AND ($e[$k] != 0.0)) { if (($k+1 < $this->m) AND ($e[$k] != 0.0)) {
// Apply the transformation. // Apply the transformation.
for ($i = $k+1; $i < $this->m; $i++) for ($i = $k+1; $i < $this->m; ++$i) {
$work[$i] = 0.0; $work[$i] = 0.0;
for ($j = $k+1; $j < $this->n; $j++) }
for ($i = $k+1; $i < $this->m; $i++) for ($j = $k+1; $j < $this->n; ++$j) {
for ($i = $k+1; $i < $this->m; ++$i) {
$work[$i] += $e[$j] * $A[$i][$j]; $work[$i] += $e[$j] * $A[$i][$j];
for ($j = $k + 1; $j < $this->n; $j++) { }
}
for ($j = $k + 1; $j < $this->n; ++$j) {
$t = -$e[$j] / $e[$k+1]; $t = -$e[$j] / $e[$k+1];
for ($i = $k + 1; $i < $this->m; $i++) for ($i = $k + 1; $i < $this->m; ++$i) {
$A[$i][$j] += $t * $work[$i]; $A[$i][$j] += $t * $work[$i];
} }
} }
}
if ($wantv) { if ($wantv) {
// Place the transformation in V for subsequent // Place the transformation in V for subsequent
// back multiplication. // back multiplication.
for ($i = $k + 1; $i < $this->n; $i++) for ($i = $k + 1; $i < $this->n; ++$i) {
$this->V[$i][$k] = $e[$i]; $this->V[$i][$k] = $e[$i];
} }
} }
} }
}
// Set up the final bidiagonal matrix or order p. // Set up the final bidiagonal matrix or order p.
$p = min($this->n, $this->m + 1); $p = min($this->n, $this->m + 1);
if ($nct < $this->n) if ($nct < $this->n) {
$this->s[$nct] = $A[$nct][$nct]; $this->s[$nct] = $A[$nct][$nct];
if ($this->m < $p) }
if ($this->m < $p) {
$this->s[$p-1] = 0.0; $this->s[$p-1] = 0.0;
if ($nrt + 1 < $p) }
if ($nrt + 1 < $p) {
$e[$nrt] = $A[$nrt][$p-1]; $e[$nrt] = $A[$nrt][$p-1];
}
$e[$p-1] = 0.0; $e[$p-1] = 0.0;
// If required, generate U. // If required, generate U.
if ($wantu) { if ($wantu) {
for ($j = $nct; $j < $nu; $j++) { for ($j = $nct; $j < $nu; ++$j) {
for ($i = 0; $i < $this->m; $i++) for ($i = 0; $i < $this->m; ++$i) {
$this->U[$i][$j] = 0.0; $this->U[$i][$j] = 0.0;
}
$this->U[$j][$j] = 1.0; $this->U[$j][$j] = 1.0;
} }
for ($k = $nct - 1; $k >= 0; $k--) { for ($k = $nct - 1; $k >= 0; --$k) {
if ($this->s[$k] != 0.0) { if ($this->s[$k] != 0.0) {
for ($j = $k + 1; $j < $nu; $j++) { for ($j = $k + 1; $j < $nu; ++$j) {
$t = 0; $t = 0;
for ($i = $k; $i < $this->m; $i++) for ($i = $k; $i < $this->m; ++$i) {
$t += $this->U[$i][$k] * $this->U[$i][$j]; $t += $this->U[$i][$k] * $this->U[$i][$j];
}
$t = -$t / $this->U[$k][$k]; $t = -$t / $this->U[$k][$k];
for ($i = $k; $i < $this->m; $i++) for ($i = $k; $i < $this->m; ++$i) {
$this->U[$i][$j] += $t * $this->U[$i][$k]; $this->U[$i][$j] += $t * $this->U[$i][$k];
} }
for ($i = $k; $i < $this->m; $i++ ) }
for ($i = $k; $i < $this->m; ++$i ) {
$this->U[$i][$k] = -$this->U[$i][$k]; $this->U[$i][$k] = -$this->U[$i][$k];
}
$this->U[$k][$k] = 1.0 + $this->U[$k][$k]; $this->U[$k][$k] = 1.0 + $this->U[$k][$k];
for ($i = 0; $i < $k - 1; $i++) for ($i = 0; $i < $k - 1; ++$i) {
$this->U[$i][$k] = 0.0; $this->U[$i][$k] = 0.0;
}
} else { } else {
for ($i = 0; $i < $this->m; $i++) for ($i = 0; $i < $this->m; ++$i) {
$this->U[$i][$k] = 0.0; $this->U[$i][$k] = 0.0;
}
$this->U[$k][$k] = 1.0; $this->U[$k][$k] = 1.0;
} }
} }
@@ -194,19 +216,22 @@ class SingularValueDecomposition {
// If required, generate V. // If required, generate V.
if ($wantv) { if ($wantv) {
for ($k = $this->n - 1; $k >= 0; $k--) { for ($k = $this->n - 1; $k >= 0; --$k) {
if (($k < $nrt) AND ($e[$k] != 0.0)) { if (($k < $nrt) AND ($e[$k] != 0.0)) {
for ($j = $k + 1; $j < $nu; $j++) { for ($j = $k + 1; $j < $nu; ++$j) {
$t = 0; $t = 0;
for ($i = $k + 1; $i < $this->n; $i++) for ($i = $k + 1; $i < $this->n; ++$i) {
$t += $this->V[$i][$k]* $this->V[$i][$j]; $t += $this->V[$i][$k]* $this->V[$i][$j];
}
$t = -$t / $this->V[$k+1][$k]; $t = -$t / $this->V[$k+1][$k];
for ($i = $k + 1; $i < $this->n; $i++) for ($i = $k + 1; $i < $this->n; ++$i) {
$this->V[$i][$j] += $t * $this->V[$i][$k]; $this->V[$i][$j] += $t * $this->V[$i][$k];
} }
} }
for ($i = 0; $i < $this->n; $i++) }
for ($i = 0; $i < $this->n; ++$i) {
$this->V[$i][$k] = 0.0; $this->V[$i][$k] = 0.0;
}
$this->V[$k][$k] = 1.0; $this->V[$k][$k] = 1.0;
} }
} }
@@ -215,8 +240,8 @@ class SingularValueDecomposition {
$pp = $p - 1; $pp = $p - 1;
$iter = 0; $iter = 0;
$eps = pow(2.0, -52.0); $eps = pow(2.0, -52.0);
while ($p > 0) {
while ($p > 0) {
// Here is where a test for too many iterations would go. // Here is where a test for too many iterations would go.
// This section of the program inspects for negligible // This section of the program inspects for negligible
// elements in the s and e arrays. On completion the // elements in the s and e arrays. On completion the
@@ -226,37 +251,38 @@ class SingularValueDecomposition {
// kase = 3 if e[k-1] is negligible, k<p, and // kase = 3 if e[k-1] is negligible, k<p, and
// s(k), ..., s(p) are not negligible (qr step). // s(k), ..., s(p) are not negligible (qr step).
// kase = 4 if e(p-1) is negligible (convergence). // kase = 4 if e(p-1) is negligible (convergence).
for ($k = $p - 2; $k >= -1; --$k) {
for ($k = $p - 2; $k >= -1; $k--) { if ($k == -1) {
if ($k == -1)
break; break;
}
if (abs($e[$k]) <= $eps * (abs($this->s[$k]) + abs($this->s[$k+1]))) { if (abs($e[$k]) <= $eps * (abs($this->s[$k]) + abs($this->s[$k+1]))) {
$e[$k] = 0.0; $e[$k] = 0.0;
break; break;
} }
} }
if ($k == $p - 2) if ($k == $p - 2) {
$kase = 4; $kase = 4;
else { } else {
for ($ks = $p - 1; $ks >= $k; $ks--) { for ($ks = $p - 1; $ks >= $k; --$ks) {
if ($ks == $k) if ($ks == $k) {
break; break;
}
$t = ($ks != $p ? abs($e[$ks]) : 0.) + ($ks != $k + 1 ? abs($e[$ks-1]) : 0.); $t = ($ks != $p ? abs($e[$ks]) : 0.) + ($ks != $k + 1 ? abs($e[$ks-1]) : 0.);
if (abs($this->s[$ks]) <= $eps * $t) { if (abs($this->s[$ks]) <= $eps * $t) {
$this->s[$ks] = 0.0; $this->s[$ks] = 0.0;
break; break;
} }
} }
if ($ks == $k) if ($ks == $k) {
$kase = 3; $kase = 3;
else if ($ks == $p-1) } else if ($ks == $p-1) {
$kase = 1; $kase = 1;
else { } else {
$kase = 2; $kase = 2;
$k = $ks; $k = $ks;
} }
} }
$k++; ++$k;
// Perform the task indicated by kase. // Perform the task indicated by kase.
switch ($kase) { switch ($kase) {
@@ -264,7 +290,7 @@ class SingularValueDecomposition {
case 1: case 1:
$f = $e[$p-2]; $f = $e[$p-2];
$e[$p-2] = 0.0; $e[$p-2] = 0.0;
for ($j = $p - 2; $j >= $k; $j--) { for ($j = $p - 2; $j >= $k; --$j) {
$t = hypo($this->s[$j],$f); $t = hypo($this->s[$j],$f);
$cs = $this->s[$j] / $t; $cs = $this->s[$j] / $t;
$sn = $f / $t; $sn = $f / $t;
@@ -274,7 +300,7 @@ class SingularValueDecomposition {
$e[$j-1] = $cs * $e[$j-1]; $e[$j-1] = $cs * $e[$j-1];
} }
if ($wantv) { if ($wantv) {
for ($i = 0; $i < $this->n; $i++) { for ($i = 0; $i < $this->n; ++$i) {
$t = $cs * $this->V[$i][$j] + $sn * $this->V[$i][$p-1]; $t = $cs * $this->V[$i][$j] + $sn * $this->V[$i][$p-1];
$this->V[$i][$p-1] = -$sn * $this->V[$i][$j] + $cs * $this->V[$i][$p-1]; $this->V[$i][$p-1] = -$sn * $this->V[$i][$j] + $cs * $this->V[$i][$p-1];
$this->V[$i][$j] = $t; $this->V[$i][$j] = $t;
@@ -286,7 +312,7 @@ class SingularValueDecomposition {
case 2: case 2:
$f = $e[$k-1]; $f = $e[$k-1];
$e[$k-1] = 0.0; $e[$k-1] = 0.0;
for ($j = $k; $j < $p; $j++) { for ($j = $k; $j < $p; ++$j) {
$t = hypo($this->s[$j], $f); $t = hypo($this->s[$j], $f);
$cs = $this->s[$j] / $t; $cs = $this->s[$j] / $t;
$sn = $f / $t; $sn = $f / $t;
@@ -294,7 +320,7 @@ class SingularValueDecomposition {
$f = -$sn * $e[$j]; $f = -$sn * $e[$j];
$e[$j] = $cs * $e[$j]; $e[$j] = $cs * $e[$j];
if ($wantu) { if ($wantu) {
for ($i = 0; $i < $this->m; $i++) { for ($i = 0; $i < $this->m; ++$i) {
$t = $cs * $this->U[$i][$j] + $sn * $this->U[$i][$k-1]; $t = $cs * $this->U[$i][$j] + $sn * $this->U[$i][$k-1];
$this->U[$i][$k-1] = -$sn * $this->U[$i][$j] + $cs * $this->U[$i][$k-1]; $this->U[$i][$k-1] = -$sn * $this->U[$i][$j] + $cs * $this->U[$i][$k-1];
$this->U[$i][$j] = $t; $this->U[$i][$j] = $t;
@@ -318,25 +344,27 @@ class SingularValueDecomposition {
$shift = 0.0; $shift = 0.0;
if (($b != 0.0) || ($c != 0.0)) { if (($b != 0.0) || ($c != 0.0)) {
$shift = sqrt($b * $b + $c); $shift = sqrt($b * $b + $c);
if ($b < 0.0) if ($b < 0.0) {
$shift = -$shift; $shift = -$shift;
}
$shift = $c / ($b + $shift); $shift = $c / ($b + $shift);
} }
$f = ($sk + $sp) * ($sk - $sp) + $shift; $f = ($sk + $sp) * ($sk - $sp) + $shift;
$g = $sk * $ek; $g = $sk * $ek;
// Chase zeros. // Chase zeros.
for ($j = $k; $j < $p-1; $j++) { for ($j = $k; $j < $p-1; ++$j) {
$t = hypo($f,$g); $t = hypo($f,$g);
$cs = $f/$t; $cs = $f/$t;
$sn = $g/$t; $sn = $g/$t;
if ($j != $k) if ($j != $k) {
$e[$j-1] = $t; $e[$j-1] = $t;
}
$f = $cs * $this->s[$j] + $sn * $e[$j]; $f = $cs * $this->s[$j] + $sn * $e[$j];
$e[$j] = $cs * $e[$j] - $sn * $this->s[$j]; $e[$j] = $cs * $e[$j] - $sn * $this->s[$j];
$g = $sn * $this->s[$j+1]; $g = $sn * $this->s[$j+1];
$this->s[$j+1] = $cs * $this->s[$j+1]; $this->s[$j+1] = $cs * $this->s[$j+1];
if ($wantv) { if ($wantv) {
for ($i = 0; $i < $this->n; $i++) { for ($i = 0; $i < $this->n; ++$i) {
$t = $cs * $this->V[$i][$j] + $sn * $this->V[$i][$j+1]; $t = $cs * $this->V[$i][$j] + $sn * $this->V[$i][$j+1];
$this->V[$i][$j+1] = -$sn * $this->V[$i][$j] + $cs * $this->V[$i][$j+1]; $this->V[$i][$j+1] = -$sn * $this->V[$i][$j] + $cs * $this->V[$i][$j+1];
$this->V[$i][$j] = $t; $this->V[$i][$j] = $t;
@@ -351,7 +379,7 @@ class SingularValueDecomposition {
$g = $sn * $e[$j+1]; $g = $sn * $e[$j+1];
$e[$j+1] = $cs * $e[$j+1]; $e[$j+1] = $cs * $e[$j+1];
if ($wantu && ($j < $this->m - 1)) { if ($wantu && ($j < $this->m - 1)) {
for ($i = 0; $i < $this->m; $i++) { for ($i = 0; $i < $this->m; ++$i) {
$t = $cs * $this->U[$i][$j] + $sn * $this->U[$i][$j+1]; $t = $cs * $this->U[$i][$j] + $sn * $this->U[$i][$j+1];
$this->U[$i][$j+1] = -$sn * $this->U[$i][$j] + $cs * $this->U[$i][$j+1]; $this->U[$i][$j+1] = -$sn * $this->U[$i][$j] + $cs * $this->U[$i][$j+1];
$this->U[$i][$j] = $t; $this->U[$i][$j] = $t;
@@ -367,135 +395,132 @@ class SingularValueDecomposition {
if ($this->s[$k] <= 0.0) { if ($this->s[$k] <= 0.0) {
$this->s[$k] = ($this->s[$k] < 0.0 ? -$this->s[$k] : 0.0); $this->s[$k] = ($this->s[$k] < 0.0 ? -$this->s[$k] : 0.0);
if ($wantv) { if ($wantv) {
for ($i = 0; $i <= $pp; $i++) for ($i = 0; $i <= $pp; ++$i) {
$this->V[$i][$k] = -$this->V[$i][$k]; $this->V[$i][$k] = -$this->V[$i][$k];
} }
} }
}
// Order the singular values. // Order the singular values.
while ($k < $pp) { while ($k < $pp) {
if ($this->s[$k] >= $this->s[$k+1]) if ($this->s[$k] >= $this->s[$k+1]) {
break; break;
}
$t = $this->s[$k]; $t = $this->s[$k];
$this->s[$k] = $this->s[$k+1]; $this->s[$k] = $this->s[$k+1];
$this->s[$k+1] = $t; $this->s[$k+1] = $t;
if ($wantv AND ($k < $this->n - 1)) { if ($wantv AND ($k < $this->n - 1)) {
for ($i = 0; $i < $this->n; $i++) { for ($i = 0; $i < $this->n; ++$i) {
$t = $this->V[$i][$k+1]; $t = $this->V[$i][$k+1];
$this->V[$i][$k+1] = $this->V[$i][$k]; $this->V[$i][$k+1] = $this->V[$i][$k];
$this->V[$i][$k] = $t; $this->V[$i][$k] = $t;
} }
} }
if ($wantu AND ($k < $this->m-1)) { if ($wantu AND ($k < $this->m-1)) {
for ($i = 0; $i < $this->m; $i++) { for ($i = 0; $i < $this->m; ++$i) {
$t = $this->U[$i][$k+1]; $t = $this->U[$i][$k+1];
$this->U[$i][$k+1] = $this->U[$i][$k]; $this->U[$i][$k+1] = $this->U[$i][$k];
$this->U[$i][$k] = $t; $this->U[$i][$k] = $t;
} }
} }
$k++; ++$k;
} }
$iter = 0; $iter = 0;
$p--; --$p;
break; break;
} // end switch } // end switch
} // end while } // end while
/*
echo "<p>Output A</p>";
$A = new Matrix($A);
$A->toHTML();
echo "<p>Matrix U</p>";
echo "<pre>";
print_r($this->U);
echo "</pre>";
echo "<p>Matrix V</p>";
echo "<pre>";
print_r($this->V);
echo "</pre>";
echo "<p>Vector S</p>";
echo "<pre>";
print_r($this->s);
echo "</pre>";
exit;
*/
} // end constructor } // end constructor
/** /**
* Return the left singular vectors * Return the left singular vectors
*
* @access public * @access public
* @return U * @return U
*/ */
function getU() { public function getU() {
return new Matrix($this->U, $this->m, min($this->m + 1, $this->n)); return new Matrix($this->U, $this->m, min($this->m + 1, $this->n));
} }
/** /**
* Return the right singular vectors * Return the right singular vectors
*
* @access public * @access public
* @return V * @return V
*/ */
function getV() { public function getV() {
return new Matrix($this->V); return new Matrix($this->V);
} }
/** /**
* Return the one-dimensional array of singular values * Return the one-dimensional array of singular values
*
* @access public * @access public
* @return diagonal of S. * @return diagonal of S.
*/ */
function getSingularValues() { public function getSingularValues() {
return $this->s; return $this->s;
} }
/** /**
* Return the diagonal matrix of singular values * Return the diagonal matrix of singular values
*
* @access public * @access public
* @return S * @return S
*/ */
function getS() { public function getS() {
for ($i = 0; $i < $this->n; $i++) { for ($i = 0; $i < $this->n; ++$i) {
for ($j = 0; $j < $this->n; $j++) for ($j = 0; $j < $this->n; ++$j) {
$S[$i][$j] = 0.0; $S[$i][$j] = 0.0;
}
$S[$i][$i] = $this->s[$i]; $S[$i][$i] = $this->s[$i];
} }
return new Matrix($S); return new Matrix($S);
} }
/** /**
* Two norm * Two norm
*
* @access public * @access public
* @return max(S) * @return max(S)
*/ */
function norm2() { public function norm2() {
return $this->s[0]; return $this->s[0];
} }
/** /**
* Two norm condition number * Two norm condition number
*
* @access public * @access public
* @return max(S)/min(S) * @return max(S)/min(S)
*/ */
function cond() { public function cond() {
return $this->s[0] / $this->s[min($this->m, $this->n) - 1]; return $this->s[0] / $this->s[min($this->m, $this->n) - 1];
} }
/** /**
* Effective numerical matrix rank * Effective numerical matrix rank
*
* @access public * @access public
* @return Number of nonnegligible singular values. * @return Number of nonnegligible singular values.
*/ */
function rank() { public function rank() {
$eps = pow(2.0, -52.0); $eps = pow(2.0, -52.0);
$tol = max($this->m, $this->n) * $this->s[0] * $eps; $tol = max($this->m, $this->n) * $this->s[0] * $eps;
$r = 0; $r = 0;
for ($i = 0; $i < count($this->s); $i++) { for ($i = 0; $i < count($this->s); ++$i) {
if ($this->s[$i] > $tol) if ($this->s[$i] > $tol) {
$r++; ++$r;
}
} }
return $r; return $r;
} }
}
} // class SingularValueDecomposition

View File

@@ -8,113 +8,75 @@
*/ */
//Language constant //Language constant
define('LANG', 'EN'); define('JAMALANG', 'EN');
//Error type constants
define('ERROR', E_USER_ERROR);
define('WARNING', E_USER_WARNING);
define('NOTICE', E_USER_NOTICE);
//All errors may be defined by the following format: //All errors may be defined by the following format:
//define('ExceptionName', N); //define('ExceptionName', N);
//$error['lang'][N] = 'Error message'; //$error['lang'][ExceptionName] = 'Error message';
$error = array(); $error = array();
/* /*
I've used Babelfish and a little poor knowledge of Romance/Germanic languages for the translations I've used Babelfish and a little poor knowledge of Romance/Germanic languages for the translations here.
here. Feel free to correct anything that looks amiss to you. Feel free to correct anything that looks amiss to you.
*/ */
define('PolymorphicArgumentException', -1); define('PolymorphicArgumentException', -1);
$error['EN'][-1] = "Invalid argument pattern for polymorphic function."; $error['EN'][PolymorphicArgumentException] = "Invalid argument pattern for polymorphic function.";
$error['FR'][-1] = "Modèle inadmissible d'argument pour la fonction polymorphe.". $error['FR'][PolymorphicArgumentException] = "Modèle inadmissible d'argument pour la fonction polymorphe.".
$error['DE'][-1] = "Unzulässiges Argumentmuster für polymorphe Funktion."; $error['DE'][PolymorphicArgumentException] = "Unzulässiges Argumentmuster für polymorphe Funktion.";
define('ArgumentTypeException', -2); define('ArgumentTypeException', -2);
$error['EN'][-2] = "Invalid argument type."; $error['EN'][ArgumentTypeException] = "Invalid argument type.";
$error['FR'][-2] = "Type inadmissible d'argument."; $error['FR'][ArgumentTypeException] = "Type inadmissible d'argument.";
$error['DE'][-2] = "Unzulässige Argumentart."; $error['DE'][ArgumentTypeException] = "Unzulässige Argumentart.";
define('ArgumentBoundsException', -3); define('ArgumentBoundsException', -3);
$error['EN'][-3] = "Invalid argument range."; $error['EN'][ArgumentBoundsException] = "Invalid argument range.";
$error['FR'][-3] = "Gamme inadmissible d'argument."; $error['FR'][ArgumentBoundsException] = "Gamme inadmissible d'argument.";
$error['DE'][-3] = "Unzulässige Argumentstrecke."; $error['DE'][ArgumentBoundsException] = "Unzulässige Argumentstrecke.";
define('MatrixDimensionException', -4); define('MatrixDimensionException', -4);
$error['EN'][-4] = "Matrix dimensions are not equal."; $error['EN'][MatrixDimensionException] = "Matrix dimensions are not equal.";
$error['FR'][-4] = "Les dimensions de Matrix ne sont pas égales."; $error['FR'][MatrixDimensionException] = "Les dimensions de Matrix ne sont pas égales.";
$error['DE'][-4] = "Matrixmaße sind nicht gleich."; $error['DE'][MatrixDimensionException] = "Matrixmaße sind nicht gleich.";
define('PrecisionLossException', -5); define('PrecisionLossException', -5);
$error['EN'][-5] = "Significant precision loss detected."; $error['EN'][PrecisionLossException] = "Significant precision loss detected.";
$error['FR'][-5] = "Perte significative de précision détectée."; $error['FR'][PrecisionLossException] = "Perte significative de précision détectée.";
$error['DE'][-5] = "Bedeutender Präzision Verlust ermittelte."; $error['DE'][PrecisionLossException] = "Bedeutender Präzision Verlust ermittelte.";
define('MatrixSPDException', -6); define('MatrixSPDException', -6);
$error['EN'][-6] = "Can only perform operation on symmetric positive definite matrix."; $error['EN'][MatrixSPDException] = "Can only perform operation on symmetric positive definite matrix.";
$error['FR'][-6] = "Perte significative de précision détectée."; $error['FR'][MatrixSPDException] = "Perte significative de précision détectée.";
$error['DE'][-6] = "Bedeutender Präzision Verlust ermittelte."; $error['DE'][MatrixSPDException] = "Bedeutender Präzision Verlust ermittelte.";
define('MatrixSingularException', -7); define('MatrixSingularException', -7);
$error['EN'][-7] = "Can only perform operation on singular matrix."; $error['EN'][MatrixSingularException] = "Can only perform operation on singular matrix.";
define('MatrixRankException', -8); define('MatrixRankException', -8);
$error['EN'][-8] = "Can only perform operation on full-rank matrix."; $error['EN'][MatrixRankException] = "Can only perform operation on full-rank matrix.";
define('ArrayLengthException', -9); define('ArrayLengthException', -9);
$error['EN'][-9] = "Array length must be a multiple of m."; $error['EN'][ArrayLengthException] = "Array length must be a multiple of m.";
define('RowLengthException', -10); define('RowLengthException', -10);
$error['EN'][-10] = "All rows must have the same length."; $error['EN'][RowLengthException] = "All rows must have the same length.";
/** /**
* Custom error handler * Custom error handler
* @param int $type Error type: {ERROR, WARNING, NOTICE}
* @param int $num Error number * @param int $num Error number
* @param string $file File in which the error occured
* @param int $line Line on which the error occured
*/ */
function JAMAError( $type = null, $num = null, $file = null, $line = null, $context = null ) { function JAMAError($errorNumber = null) {
global $error; global $error;
$lang = LANG; if (isset($errorNumber)) {
if( isset($type) && isset($num) && isset($file) && isset($line) ) { if (isset($error[JAMALANG][$errorNumber])) {
switch( $type ) { return $error[JAMALANG][$errorNumber];
case ERROR: } else {
echo '<div class="errror"><b>Error:</b> ' . $error[$lang][$num] . '<br />' . $file . ' @ L' . $line . '</div>'; return $error['EN'][$errorNumber];
die();
break;
case WARNING:
echo '<div class="warning"><b>Warning:</b> ' . $error[$lang][$num] . '<br />' . $file . ' @ L' . $line . '</div>';
break;
case NOTICE:
//echo '<div class="notice"><b>Notice:</b> ' . $error[$lang][$num] . '<br />' . $file . ' @ L' . $line . '</div>';
break;
case E_NOTICE:
//echo '<div class="errror"><b>Notice:</b> ' . $error[$lang][$num] . '<br />' . $file . ' @ L' . $line . '</div>';
break;
case E_STRICT:
break;
case E_WARNING:
break;
default:
echo "<div class=\"error\"><b>Unknown Error Type:</b> $type - $file @ L{$line}</div>";
die();
break;
} }
} else { } else {
die( "Invalid arguments to JAMAError()" ); return ("Invalid argument to JAMAError()");
} }
} }
// TODO MarkBaker
//set_error_handler('JAMAError');
//error_reporting(ERROR | WARNING);

View File

@@ -18,10 +18,12 @@ function hypo($a, $b) {
} elseif ($b != 0) { } elseif ($b != 0) {
$r = $a / $b; $r = $a / $b;
$r = abs($b) * sqrt(1 + $r * $r); $r = abs($b) * sqrt(1 + $r * $r);
} else } else {
$r = 0.0; $r = 0.0;
return $r;
} }
return $r;
} // function hypo()
/** /**
* Mike Bommarito's version. * Mike Bommarito's version.
@@ -30,10 +32,11 @@ function hypo($a, $b) {
function hypot() { function hypot() {
$s = 0; $s = 0;
foreach (func_get_args() as $d) { foreach (func_get_args() as $d) {
if (is_numeric($d)) if (is_numeric($d)) {
$s += pow($d, 2); $s += pow($d, 2);
else } else {
trigger_error(ArgumentTypeException, ERROR); throw new Exception(JAMAError(ArgumentTypeException));
}
} }
return sqrt($s); return sqrt($s);
} }

View File

@@ -19,19 +19,6 @@
// //
// $Id: OLE.php,v 1.13 2007/03/07 14:38:25 schmidt Exp $ // $Id: OLE.php,v 1.13 2007/03/07 14:38:25 schmidt Exp $
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
}
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/OLE.php';
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/OLE/OLE_PPS.php';
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/OLE/OLE_File.php';
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/OLE/OLE_Root.php';
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/OLE/ChainedBlockStream.php';
/** /**
* Array for storing OLE instances that are accessed from * Array for storing OLE instances that are accessed from
@@ -527,20 +514,9 @@ class PHPExcel_Shared_OLE
// factor used for separating numbers into 4 bytes parts // factor used for separating numbers into 4 bytes parts
$factor = pow(2,32); $factor = pow(2,32);
$high_part = 0; list(, $high_part) = unpack('V', substr($string, 4, 4));
for ($i = 0; $i < 4; ++$i) { list(, $low_part) = unpack('V', substr($string, 0, 4));
list(, $high_part) = unpack('C', $string{(7 - $i)});
if ($i < 3) {
$high_part *= 0x100;
}
}
$low_part = 0;
for ($i = 4; $i < 8; ++$i) {
list(, $low_part) = unpack('C', $string{(7 - $i)});
if ($i < 7) {
$low_part *= 0x100;
}
}
$big_date = ($high_part * $factor) + $low_part; $big_date = ($high_part * $factor) + $low_part;
// translate to seconds // translate to seconds
$big_date /= 10000000; $big_date /= 10000000;

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (C) 2006 - 2009 PHPExcel * Copyright (C) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -22,19 +22,9 @@
* @package PHPExcel_Shared_OLE * @package PHPExcel_Shared_OLE
* @copyright Copyright (c) 2006 - 2007 Christian Schmidt * @copyright Copyright (c) 2006 - 2007 Christian Schmidt
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../../');
}
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/OLE.php';
/** /**
* PHPExcel_Shared_OLE_ChainedBlockStream * PHPExcel_Shared_OLE_ChainedBlockStream
* *

View File

@@ -20,16 +20,6 @@
// $Id: PPS.php,v 1.7 2007/02/13 21:00:42 schmidt Exp $ // $Id: PPS.php,v 1.7 2007/02/13 21:00:42 schmidt Exp $
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../../');
}
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/OLE.php';
/** /**
* Class for creating PPS's for OLE containers * Class for creating PPS's for OLE containers
* *
@@ -162,13 +152,13 @@ class PHPExcel_Shared_OLE_PPS
if (!isset($this->_data)) { if (!isset($this->_data)) {
return 0; return 0;
} }
if (isset($this->_PPS_FILE)) { //if (isset($this->_PPS_FILE)) {
fseek($this->_PPS_FILE, 0); // fseek($this->_PPS_FILE, 0);
$stats = fstat($this->_PPS_FILE); // $stats = fstat($this->_PPS_FILE);
return $stats[7]; // return $stats[7];
} else { //} else {
return strlen($this->_data); return strlen($this->_data);
} //}
} }
/** /**

View File

@@ -20,16 +20,6 @@
// $Id: File.php,v 1.11 2007/02/13 21:00:42 schmidt Exp $ // $Id: File.php,v 1.11 2007/02/13 21:00:42 schmidt Exp $
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../../');
}
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/OLE/OLE_PPS.php';
/** /**
* Class for creating File PPS's for OLE containers * Class for creating File PPS's for OLE containers
* *
@@ -39,12 +29,6 @@ require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/OLE/OLE_PPS.php';
*/ */
class PHPExcel_Shared_OLE_PPS_File extends PHPExcel_Shared_OLE_PPS class PHPExcel_Shared_OLE_PPS_File extends PHPExcel_Shared_OLE_PPS
{ {
/**
* The temporary dir for storing the OLE file
* @var string
*/
public $_tmp_dir;
/** /**
* The constructor * The constructor
* *
@@ -54,7 +38,6 @@ class PHPExcel_Shared_OLE_PPS_File extends PHPExcel_Shared_OLE_PPS
*/ */
public function __construct($name) public function __construct($name)
{ {
$this->_tmp_dir = '';
parent::__construct( parent::__construct(
null, null,
$name, $name,
@@ -68,22 +51,6 @@ class PHPExcel_Shared_OLE_PPS_File extends PHPExcel_Shared_OLE_PPS
array()); array());
} }
/**
* Sets the temp dir used for storing the OLE file
*
* @access public
* @param string $dir The dir to be used as temp dir
* @return true if given dir is valid, false otherwise
*/
public function setTempDir($dir)
{
if (is_dir($dir)) {
$this->_tmp_dir = $dir;
return true;
}
return false;
}
/** /**
* Initialization method. Has to be called right after OLE_PPS_File(). * Initialization method. Has to be called right after OLE_PPS_File().
* *
@@ -92,15 +59,6 @@ class PHPExcel_Shared_OLE_PPS_File extends PHPExcel_Shared_OLE_PPS
*/ */
public function init() public function init()
{ {
$this->_tmp_filename = tempnam($this->_tmp_dir, "OLE_PPS_File");
$fh = fopen($this->_tmp_filename, "w+b");
if ($fh === false) {
throw new Exception("Can't create temporary file");
}
$this->_PPS_FILE = $fh;
if ($this->_PPS_FILE) {
fseek($this->_PPS_FILE, 0);
}
return true; return true;
} }
@@ -112,12 +70,8 @@ class PHPExcel_Shared_OLE_PPS_File extends PHPExcel_Shared_OLE_PPS
*/ */
public function append($data) public function append($data)
{ {
if ($this->_PPS_FILE) {
fwrite($this->_PPS_FILE, $data);
} else {
$this->_data .= $data; $this->_data .= $data;
} }
}
/** /**
* Returns a stream for reading this file using fread() etc. * Returns a stream for reading this file using fread() etc.

View File

@@ -20,16 +20,6 @@
// $Id: Root.php,v 1.9 2005/04/23 21:53:49 dufuz Exp $ // $Id: Root.php,v 1.9 2005/04/23 21:53:49 dufuz Exp $
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../../');
}
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/OLE/OLE_PPS.php';
/** /**
* Class for creating Root PPS's for OLE containers * Class for creating Root PPS's for OLE containers
* *
@@ -39,19 +29,12 @@ require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/OLE/OLE_PPS.php';
*/ */
class PHPExcel_Shared_OLE_PPS_Root extends PHPExcel_Shared_OLE_PPS class PHPExcel_Shared_OLE_PPS_Root extends PHPExcel_Shared_OLE_PPS
{ {
/**
* The temporary dir for storing the OLE file
* @var string
*/
public $_tmp_dir;
/** /**
* @param integer $time_1st A timestamp * @param integer $time_1st A timestamp
* @param integer $time_2nd A timestamp * @param integer $time_2nd A timestamp
*/ */
public function __construct($time_1st, $time_2nd, $raChild) public function __construct($time_1st, $time_2nd, $raChild)
{ {
$this->_tmp_dir = '';
parent::__construct( parent::__construct(
null, null,
PHPExcel_Shared_OLE::Asc2Ucs('Root Entry'), PHPExcel_Shared_OLE::Asc2Ucs('Root Entry'),
@@ -65,28 +48,14 @@ class PHPExcel_Shared_OLE_PPS_Root extends PHPExcel_Shared_OLE_PPS
$raChild); $raChild);
} }
/**
* Sets the temp dir used for storing the OLE file
*
* @access public
* @param string $dir The dir to be used as temp dir
* @return true if given dir is valid, false otherwise
*/
public function setTempDir($dir)
{
if (is_dir($dir)) {
$this->_tmp_dir = $dir;
return true;
}
return false;
}
/** /**
* Method for saving the whole OLE container (including files). * Method for saving the whole OLE container (including files).
* In fact, if called with an empty argument (or '-'), it saves to a * In fact, if called with an empty argument (or '-'), it saves to a
* temporary file and then outputs it's contents to stdout. * temporary file and then outputs it's contents to stdout.
* If a resource pointer to a stream created by fopen() is passed
* it will be used, but you have to close such stream by yourself.
* *
* @param string $filename The name of the file where to save the OLE container * @param string|resource $filename The name of the file or stream where to save the OLE container.
* @access public * @access public
* @return mixed true on success * @return mixed true on success
*/ */
@@ -98,8 +67,9 @@ class PHPExcel_Shared_OLE_PPS_Root extends PHPExcel_Shared_OLE_PPS
$this->_SMALL_BLOCK_SIZE= pow(2, $this->_SMALL_BLOCK_SIZE= pow(2,
((isset($this->_SMALL_BLOCK_SIZE))? $this->_adjust2($this->_SMALL_BLOCK_SIZE): 6)); ((isset($this->_SMALL_BLOCK_SIZE))? $this->_adjust2($this->_SMALL_BLOCK_SIZE): 6));
// Open temp file if we are sending output to stdout if (is_resource($filename)) {
if ($filename == '-' || $filename == '') { $this->_FILEH_ = $filename;
} else if ($filename == '-' || $filename == '') {
$this->_tmp_filename = tempnam($this->_tmp_dir, "OLE_PPS_Root"); $this->_tmp_filename = tempnam($this->_tmp_dir, "OLE_PPS_Root");
$this->_FILEH_ = fopen($this->_tmp_filename,"w+b"); $this->_FILEH_ = fopen($this->_tmp_filename,"w+b");
if ($this->_FILEH_ == false) { if ($this->_FILEH_ == false) {
@@ -107,10 +77,10 @@ class PHPExcel_Shared_OLE_PPS_Root extends PHPExcel_Shared_OLE_PPS
} }
} else { } else {
$this->_FILEH_ = fopen($filename, "wb"); $this->_FILEH_ = fopen($filename, "wb");
}
if ($this->_FILEH_ == false) { if ($this->_FILEH_ == false) {
throw new Exception("Can't open $filename. It may be in use or protected."); throw new Exception("Can't open $filename. It may be in use or protected.");
} }
}
// Make an array of PPS's (for Save) // Make an array of PPS's (for Save)
$aList = array(); $aList = array();
$this->_savePpsSetPnt($aList); $this->_savePpsSetPnt($aList);
@@ -128,14 +98,8 @@ class PHPExcel_Shared_OLE_PPS_Root extends PHPExcel_Shared_OLE_PPS
$this->_savePps($aList); $this->_savePps($aList);
// Write Big Block Depot and BDList and Adding Header informations // Write Big Block Depot and BDList and Adding Header informations
$this->_saveBbd($iSBDcnt, $iBBcnt, $iPPScnt); $this->_saveBbd($iSBDcnt, $iBBcnt, $iPPScnt);
// Close File, send it to stdout if necessary
if (($filename == '-') || ($filename == '')) { if (!is_resource($filename)) {
fseek($this->_FILEH_, 0);
fpassthru($this->_FILEH_);
fclose($this->_FILEH_);
// Delete the temporary file.
unlink($this->_tmp_filename);
} else {
fclose($this->_FILEH_); fclose($this->_FILEH_);
} }
@@ -248,7 +212,7 @@ class PHPExcel_Shared_OLE_PPS_Root extends PHPExcel_Shared_OLE_PPS
. pack("V", 0) . pack("V", 0)
. pack("V", 0x1000) . pack("V", 0x1000)
. pack("V", $iSBDcnt ? 0 : -2) //Small Block Depot . pack("V", $iSBDcnt ? 0 : -2) //Small Block Depot
. pack("V", 1) . pack("V", $iSBDcnt)
); );
// Extra BDList Start, Count // Extra BDList Start, Count
if ($iBdCnt < $i1stBdL) { if ($iBdCnt < $i1stBdL) {
@@ -290,16 +254,16 @@ class PHPExcel_Shared_OLE_PPS_Root extends PHPExcel_Shared_OLE_PPS
(($raList[$i]->Type == PHPExcel_Shared_OLE::OLE_PPS_TYPE_ROOT) && isset($raList[$i]->_data))) (($raList[$i]->Type == PHPExcel_Shared_OLE::OLE_PPS_TYPE_ROOT) && isset($raList[$i]->_data)))
{ {
// Write Data // Write Data
if (isset($raList[$i]->_PPS_FILE)) { //if (isset($raList[$i]->_PPS_FILE)) {
$iLen = 0; // $iLen = 0;
fseek($raList[$i]->_PPS_FILE, 0); // To The Top // fseek($raList[$i]->_PPS_FILE, 0); // To The Top
while($sBuff = fread($raList[$i]->_PPS_FILE, 4096)) { // while($sBuff = fread($raList[$i]->_PPS_FILE, 4096)) {
$iLen += strlen($sBuff); // $iLen += strlen($sBuff);
fwrite($FILE, $sBuff); // fwrite($FILE, $sBuff);
} // }
} else { //} else {
fwrite($FILE, $raList[$i]->_data); fwrite($FILE, $raList[$i]->_data);
} //}
if ($raList[$i]->Size % $this->_BIG_BLOCK_SIZE) { if ($raList[$i]->Size % $this->_BIG_BLOCK_SIZE) {
for ($j = 0; $j < ($this->_BIG_BLOCK_SIZE - ($raList[$i]->Size % $this->_BIG_BLOCK_SIZE)); ++$j) { for ($j = 0; $j < ($this->_BIG_BLOCK_SIZE - ($raList[$i]->Size % $this->_BIG_BLOCK_SIZE)); ++$j) {
@@ -313,11 +277,11 @@ class PHPExcel_Shared_OLE_PPS_Root extends PHPExcel_Shared_OLE_PPS
(($raList[$i]->Size % $this->_BIG_BLOCK_SIZE)? 1: 0)); (($raList[$i]->Size % $this->_BIG_BLOCK_SIZE)? 1: 0));
} }
// Close file for each PPS, and unlink it // Close file for each PPS, and unlink it
if (isset($raList[$i]->_PPS_FILE)) { //if (isset($raList[$i]->_PPS_FILE)) {
fclose($raList[$i]->_PPS_FILE); // fclose($raList[$i]->_PPS_FILE);
$raList[$i]->_PPS_FILE = null; // $raList[$i]->_PPS_FILE = null;
unlink($raList[$i]->_tmp_filename); // unlink($raList[$i]->_tmp_filename);
} //}
} }
} }
} }
@@ -349,15 +313,15 @@ class PHPExcel_Shared_OLE_PPS_Root extends PHPExcel_Shared_OLE_PPS
} }
fwrite($FILE, pack("V", -2)); fwrite($FILE, pack("V", -2));
// Add to Data String(this will be written for RootEntry) //// Add to Data String(this will be written for RootEntry)
if ($raList[$i]->_PPS_FILE) { //if ($raList[$i]->_PPS_FILE) {
fseek($raList[$i]->_PPS_FILE, 0); // To The Top // fseek($raList[$i]->_PPS_FILE, 0); // To The Top
while ($sBuff = fread($raList[$i]->_PPS_FILE, 4096)) { // while ($sBuff = fread($raList[$i]->_PPS_FILE, 4096)) {
$sRes .= $sBuff; // $sRes .= $sBuff;
} // }
} else { //} else {
$sRes .= $raList[$i]->_data; $sRes .= $raList[$i]->_data;
} //}
if ($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE) { if ($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE) {
for ($j = 0; $j < ($this->_SMALL_BLOCK_SIZE - ($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE)); ++$j) { for ($j = 0; $j < ($this->_SMALL_BLOCK_SIZE - ($raList[$i]->Size % $this->_SMALL_BLOCK_SIZE)); ++$j) {
$sRes .= "\x00"; $sRes .= "\x00";

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared * @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
define('IDENTIFIER_OLE', pack('CCCCCCCC', 0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1)); define('IDENTIFIER_OLE', pack('CCCCCCCC', 0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1));
@@ -162,7 +162,6 @@ class PHPExcel_Shared_OLERead {
$this->entry = $this->_readData($block); $this->entry = $this->_readData($block);
$this->_readPropertySets(); $this->_readPropertySets();
} }
/** /**
@@ -213,6 +212,58 @@ class PHPExcel_Shared_OLERead {
} }
} }
/**
* 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) * Read a standard stream (by joining sectors using information from SAT)
* *
@@ -271,7 +322,7 @@ class PHPExcel_Shared_OLERead {
'size' => $size); 'size' => $size);
// Workbook directory entry (BIFF5 uses Book, BIFF8 uses Workbook) // Workbook directory entry (BIFF5 uses Book, BIFF8 uses Workbook)
if (($name == 'Workbook') || ($name == 'Book') || ($name == 'WORKBOOK')) { if (($name == 'Workbook') || ($name == 'Book') || ($name == 'WORKBOOK') || ($name == 'BOOK')) {
$this->wrkbook = count($this->props) - 1; $this->wrkbook = count($this->props) - 1;
} }
@@ -280,6 +331,11 @@ class PHPExcel_Shared_OLERead {
$this->rootentry = count($this->props) - 1; $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; $offset += self::PROPERTY_STORAGE_BLOCK_SIZE;
} }

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared * @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
@@ -31,7 +31,7 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared * @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_Shared_PasswordHasher class PHPExcel_Shared_PasswordHasher
{ {

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared * @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
@@ -31,10 +31,16 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared * @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_Shared_String class PHPExcel_Shared_String
{ {
/** Constants */
/** Regular Expressions */
// Fraction
const STRING_REGEXP_FRACTION = '(-?)(\d+)\s+(\d+\/\d+)';
/** /**
* Control characters array * Control characters array
* *
@@ -42,6 +48,27 @@ class PHPExcel_Shared_String
*/ */
private static $_controlCharacters = array(); 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? * Is mbstring extension avalable?
* *
@@ -60,7 +87,7 @@ class PHPExcel_Shared_String
* Build control characters array * Build control characters array
*/ */
private static function _buildControlCharacters() { private static function _buildControlCharacters() {
for ($i = 0; $i <= 19; ++$i) { for ($i = 0; $i <= 31; ++$i) {
if ($i != 9 && $i != 10 && $i != 13) { if ($i != 9 && $i != 10 && $i != 13) {
$find = '_x' . sprintf('%04s' , strtoupper(dechex($i))) . '_'; $find = '_x' . sprintf('%04s' , strtoupper(dechex($i))) . '_';
$replace = chr($i); $replace = chr($i);
@@ -69,6 +96,171 @@ class PHPExcel_Shared_String
} }
} }
/**
* 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 * Get whether mbstring extension is available
* *
@@ -97,14 +289,37 @@ class PHPExcel_Shared_String
return self::$_isIconvEnabled; return self::$_isIconvEnabled;
} }
// IBM AIX iconv() does not work // Fail if iconv doesn't exist
self::$_isIconvEnabled = function_exists('iconv') && if (!function_exists('iconv')) {
!(defined('PHP_OS') && @stristr(PHP_OS, 'AIX') && defined('ICONV_IMPL') self::$_isIconvEnabled = false;
&& (@strcasecmp(ICONV_IMPL, 'unknown') == 0) && defined('ICONV_VERSION') return false;
&& (@strcasecmp(ICONV_VERSION, 'unknown') == 0)) ? }
true : false;
return self::$_isIconvEnabled; // 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;
} }
/** /**
@@ -250,7 +465,7 @@ class PHPExcel_Shared_String
} }
/** /**
* Convert string from one encoding to another. First try mbstring, then iconv, or no convertion * Convert string from one encoding to another. First try iconv, then mbstring, or no convertion
* *
* @param string $value * @param string $value
* @param string $to Encoding to convert to, e.g. 'UTF-8' * @param string $to Encoding to convert to, e.g. 'UTF-8'
@@ -268,11 +483,46 @@ class PHPExcel_Shared_String
$value = mb_convert_encoding($value, $to, $from); $value = mb_convert_encoding($value, $to, $from);
return $value; 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 // else, no conversion
return $value; 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
*/
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 * Get character count. First try mbstring, then iconv, finally strlen
* *
@@ -322,4 +572,106 @@ class PHPExcel_Shared_String
return $string; 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

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared * @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
if (!defined('DATE_W3C')) { if (!defined('DATE_W3C')) {
@@ -34,7 +34,7 @@ if (!defined('DATE_W3C')) {
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared * @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_Shared_XMLWriter { class PHPExcel_Shared_XMLWriter {
/** Temporary storage method */ /** Temporary storage method */

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,22 +20,18 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared * @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
/** Register new zip wrapper */
PHPExcel_Shared_ZipStreamWrapper::register();
/** /**
* PHPExcel_Shared_ZipStreamWrapper * PHPExcel_Shared_ZipStreamWrapper
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared * @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_Shared_ZipStreamWrapper { class PHPExcel_Shared_ZipStreamWrapper {
/** /**
@@ -83,24 +79,9 @@ class PHPExcel_Shared_ZipStreamWrapper {
throw new Exception('Mode ' . $mode . ' is not supported. Only read mode is supported.'); throw new Exception('Mode ' . $mode . ' is not supported. Only read mode is supported.');
} }
// Parse URL $pos = strrpos($path, '#');
$url = @parse_url($path); $url['host'] = substr($path, 6, $pos - 6); // 6: strlen('zip://')
$url['fragment'] = substr($path, $pos + 1);
// Fix URL
if (!is_array($url)) {
$url['host'] = substr($path, strlen('zip://'));
$url['path'] = '';
}
if (strpos($url['host'], '#') !== false) {
if (!isset($url['fragment'])) {
$url['fragment'] = substr($url['host'], strpos($url['host'], '#') + 1) . $url['path'];
$url['host'] = substr($url['host'], 0, strpos($url['host'], '#'));
unset($url['path']);
}
} else {
$url['host'] = $url['host'] . $url['path'];
unset($url['path']);
}
// Open archive // Open archive
$this->_archive = new ZipArchive(); $this->_archive = new ZipArchive();

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared_Best_Fit * @package PHPExcel_Shared_Best_Fit
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
@@ -31,7 +31,7 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared_Best_Fit * @package PHPExcel_Shared_Best_Fit
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_Best_Fit class PHPExcel_Best_Fit
{ {
@@ -239,7 +239,11 @@ class PHPExcel_Best_Fit
$this->_SSResiduals = $SSres; $this->_SSResiduals = $SSres;
$this->_DFResiduals = $this->_valueCount - 1 - $const; $this->_DFResiduals = $this->_valueCount - 1 - $const;
if ($this->_DFResiduals == 0.0) {
$this->_stdevOfResiduals = 0.0;
} else {
$this->_stdevOfResiduals = sqrt($SSres / $this->_DFResiduals); $this->_stdevOfResiduals = sqrt($SSres / $this->_DFResiduals);
}
if (($SStot == 0.0) || ($SSres == $SStot)) { if (($SStot == 0.0) || ($SSres == $SStot)) {
$this->_goodnessOfFit = 1; $this->_goodnessOfFit = 1;
} else { } else {
@@ -252,10 +256,18 @@ class PHPExcel_Best_Fit
$this->_slopeSE = $this->_stdevOfResiduals / sqrt($SSsex); $this->_slopeSE = $this->_stdevOfResiduals / sqrt($SSsex);
$this->_intersectSE = $this->_stdevOfResiduals * sqrt(1 / ($this->_valueCount - ($sumX * $sumX) / $sumX2)); $this->_intersectSE = $this->_stdevOfResiduals * sqrt(1 / ($this->_valueCount - ($sumX * $sumX) / $sumX2));
if ($this->_SSResiduals != 0.0) { if ($this->_SSResiduals != 0.0) {
if ($this->_DFResiduals == 0.0) {
$this->_F = 0.0;
} else {
$this->_F = $this->_SSRegression / ($this->_SSResiduals / $this->_DFResiduals); $this->_F = $this->_SSRegression / ($this->_SSResiduals / $this->_DFResiduals);
}
} else {
if ($this->_DFResiduals == 0.0) {
$this->_F = 0.0;
} else { } else {
$this->_F = $this->_SSRegression / $this->_DFResiduals; $this->_F = $this->_SSRegression / $this->_DFResiduals;
} }
}
} // function _calculateGoodnessOfFit() } // function _calculateGoodnessOfFit()

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,20 +20,12 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared_Best_Fit * @package PHPExcel_Shared_Best_Fit
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../../');
}
require_once(PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php'); require_once(PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php');
@@ -42,7 +34,7 @@ require_once(PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php');
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared_Best_Fit * @package PHPExcel_Shared_Best_Fit
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_Exponential_Best_Fit extends PHPExcel_Best_Fit class PHPExcel_Exponential_Best_Fit extends PHPExcel_Best_Fit
{ {
@@ -84,8 +76,14 @@ class PHPExcel_Exponential_Best_Fit extends PHPExcel_Best_Fit
private function _exponential_regression($yValues, $xValues, $const) { private function _exponential_regression($yValues, $xValues, $const) {
$mArray = $xValues; foreach($yValues as &$value) {
$yValues = array_map('log',$yValues); if ($value < 0.0) {
$value = 0 - log(abs($value));
} elseif ($value > 0.0) {
$value = log($value);
}
}
unset($value);
$this->_leastSquareFit($yValues, $xValues, $const); $this->_leastSquareFit($yValues, $xValues, $const);
} // function _exponential_regression() } // function _exponential_regression()

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,20 +20,12 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared_Best_Fit * @package PHPExcel_Shared_Best_Fit
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../../');
}
require_once(PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php'); require_once(PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php');
@@ -42,7 +34,7 @@ require_once(PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php');
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared_Best_Fit * @package PHPExcel_Shared_Best_Fit
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_Linear_Best_Fit extends PHPExcel_Best_Fit class PHPExcel_Linear_Best_Fit extends PHPExcel_Best_Fit
{ {

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,20 +20,12 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared_Best_Fit * @package PHPExcel_Shared_Best_Fit
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../../');
}
require_once(PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php'); require_once(PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php');
@@ -42,7 +34,7 @@ require_once(PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php');
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared_Best_Fit * @package PHPExcel_Shared_Best_Fit
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_Logarithmic_Best_Fit extends PHPExcel_Best_Fit class PHPExcel_Logarithmic_Best_Fit extends PHPExcel_Best_Fit
{ {
@@ -68,8 +60,14 @@ class PHPExcel_Logarithmic_Best_Fit extends PHPExcel_Best_Fit
private function _logarithmic_regression($yValues, $xValues, $const) { private function _logarithmic_regression($yValues, $xValues, $const) {
$mArray = $xValues; foreach($xValues as &$value) {
$xValues = array_map('log',$xValues); if ($value < 0.0) {
$value = 0 - log(abs($value));
} elseif ($value > 0.0) {
$value = log($value);
}
}
unset($value);
$this->_leastSquareFit($yValues, $xValues, $const); $this->_leastSquareFit($yValues, $xValues, $const);
} // function _logarithmic_regression() } // function _logarithmic_regression()

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,20 +20,12 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared_Best_Fit * @package PHPExcel_Shared_Best_Fit
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../../');
}
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php'; require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php';
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/JAMA/Matrix.php'; require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/JAMA/Matrix.php';
@@ -43,7 +35,7 @@ require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/JAMA/Matrix.php';
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared_Best_Fit * @package PHPExcel_Shared_Best_Fit
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_Polynomial_Best_Fit extends PHPExcel_Best_Fit class PHPExcel_Polynomial_Best_Fit extends PHPExcel_Best_Fit
{ {

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,20 +20,12 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared_Best_Fit * @package PHPExcel_Shared_Best_Fit
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../../');
}
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php'; require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php';
@@ -42,7 +34,7 @@ require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/bestFitClass.php';
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Shared_Best_Fit * @package PHPExcel_Shared_Best_Fit
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_Power_Best_Fit extends PHPExcel_Best_Fit class PHPExcel_Power_Best_Fit extends PHPExcel_Best_Fit
{ {
@@ -76,10 +68,22 @@ class PHPExcel_Power_Best_Fit extends PHPExcel_Best_Fit
private function _power_regression($yValues, $xValues, $const) { private function _power_regression($yValues, $xValues, $const) {
$mArray = $xValues; foreach($xValues as &$value) {
sort($mArray,SORT_NUMERIC); if ($value < 0.0) {
$xValues = array_map('log',$xValues); $value = 0 - log(abs($value));
$yValues = array_map('log',$yValues); } elseif ($value > 0.0) {
$value = log($value);
}
}
unset($value);
foreach($yValues as &$value) {
if ($value < 0.0) {
$value = 0 - log(abs($value));
} elseif ($value > 0.0) {
$value = log($value);
}
}
unset($value);
$this->_leastSquareFit($yValues, $xValues, $const); $this->_leastSquareFit($yValues, $xValues, $const);
} // function _power_regression() } // function _power_regression()

View File

@@ -1,13 +1,5 @@
<?php <?php
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../../');
}
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/linearBestFitClass.php'; require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/linearBestFitClass.php';
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/logarithmicBestFitClass.php'; require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/logarithmicBestFitClass.php';
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/exponentialBestFitClass.php'; require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/trend/exponentialBestFitClass.php';

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,53 +20,18 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Style * @package PHPExcel_Style
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../');
}
/** PHPExcel_Style_Color */
require_once PHPEXCEL_ROOT . 'PHPExcel/Style/Color.php';
/** PHPExcel_Style_Font */
require_once PHPEXCEL_ROOT . 'PHPExcel/Style/Font.php';
/** PHPExcel_Style_Fill */
require_once PHPEXCEL_ROOT . 'PHPExcel/Style/Fill.php';
/** PHPExcel_Style_Borders */
require_once PHPEXCEL_ROOT . 'PHPExcel/Style/Borders.php';
/** PHPExcel_Style_Alignment */
require_once PHPEXCEL_ROOT . 'PHPExcel/Style/Alignment.php';
/** PHPExcel_Style_NumberFormat */
require_once PHPEXCEL_ROOT . 'PHPExcel/Style/NumberFormat.php';
/** PHPExcel_Style_Conditional */
require_once PHPEXCEL_ROOT . 'PHPExcel/Style/Conditional.php';
/** PHPExcel_Style_Protection */
require_once PHPEXCEL_ROOT . 'PHPExcel/Style/Protection.php';
/** PHPExcel_IComparable */
require_once PHPEXCEL_ROOT . 'PHPExcel/IComparable.php';
/** /**
* PHPExcel_Style * PHPExcel_Style
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Style * @package PHPExcel_Style
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_Style implements PHPExcel_IComparable class PHPExcel_Style implements PHPExcel_IComparable
{ {
@@ -201,7 +166,7 @@ class PHPExcel_Style implements PHPExcel_IComparable
public function getSharedComponent() public function getSharedComponent()
{ {
$activeSheet = $this->getActiveSheet(); $activeSheet = $this->getActiveSheet();
$selectedCell = $this->getXActiveCell(); // e.g. 'A1' $selectedCell = $this->getActiveCell(); // e.g. 'A1'
if ($activeSheet->cellExists($selectedCell)) { if ($activeSheet->cellExists($selectedCell)) {
$cell = $activeSheet->getCell($selectedCell); $cell = $activeSheet->getCell($selectedCell);
@@ -230,9 +195,9 @@ class PHPExcel_Style implements PHPExcel_IComparable
* *
* @return string E.g. 'A1' * @return string E.g. 'A1'
*/ */
public function getXSelectedCells() public function getSelectedCells()
{ {
return $this->_parent->getActiveSheet()->getXSelectedCells(); return $this->_parent->getActiveSheet()->getSelectedCells();
} }
/** /**
@@ -241,9 +206,9 @@ class PHPExcel_Style implements PHPExcel_IComparable
* *
* @return string E.g. 'A1' * @return string E.g. 'A1'
*/ */
public function getXActiveCell() public function getActiveCell()
{ {
return $this->_parent->getActiveSheet()->getXActiveCell(); return $this->_parent->getActiveSheet()->getActiveCell();
} }
/** /**
@@ -299,9 +264,8 @@ class PHPExcel_Style implements PHPExcel_IComparable
if (is_array($pStyles)) { if (is_array($pStyles)) {
if ($this->_isSupervisor) { if ($this->_isSupervisor) {
$pRange = $this->getXSelectedCells(); $pRange = $this->getSelectedCells();
if (is_array($pStyles)) {
// Uppercase coordinate // Uppercase coordinate
$pRange = strtoupper($pRange); $pRange = strtoupper($pRange);
@@ -330,7 +294,8 @@ class PHPExcel_Style implements PHPExcel_IComparable
$rangeEnd = $tmp; $rangeEnd = $tmp;
} }
// Advanced mode // ADVANCED MODE:
if ($pAdvanced && isset($pStyles['borders'])) { if ($pAdvanced && isset($pStyles['borders'])) {
// 'allborders' is a shorthand property for 'outline' and 'inside' and // 'allborders' is a shorthand property for 'outline' and 'inside' and
@@ -456,15 +421,46 @@ class PHPExcel_Style implements PHPExcel_IComparable
return; return;
} }
// Simple mode // SIMPLE MODE:
// First loop through cells to find out which styles are affected by this operation // Selection type, inspect
if (preg_match('/^[A-Z]+1:[A-Z]+1048576$/', $pRange)) {
$selectionType = 'COLUMN';
} else if (preg_match('/^A[0-9]+:XFD[0-9]+$/', $pRange)) {
$selectionType = 'ROW';
} else {
$selectionType = 'CELL';
}
// First loop through columns, rows, or cells to find out which styles are affected by this operation
switch ($selectionType) {
case 'COLUMN':
$oldXfIndexes = array();
for ($col = $rangeStart[0]; $col <= $rangeEnd[0]; ++$col) {
$oldXfIndexes[$this->getActiveSheet()->getColumnDimensionByColumn($col)->getXfIndex()] = true;
}
break;
case 'ROW':
$oldXfIndexes = array();
for ($row = $rangeStart[1]; $row <= $rangeEnd[1]; ++$row) {
if ($this->getActiveSheet()->getRowDimension($row)->getXfIndex() == null) {
$oldXfIndexes[0] = true; // row without explicit style should be formatted based on default style
} else {
$oldXfIndexes[$this->getActiveSheet()->getRowDimension($row)->getXfIndex()] = true;
}
}
break;
case 'CELL':
$oldXfIndexes = array(); $oldXfIndexes = array();
for ($col = $rangeStart[0]; $col <= $rangeEnd[0]; ++$col) { for ($col = $rangeStart[0]; $col <= $rangeEnd[0]; ++$col) {
for ($row = $rangeStart[1]; $row <= $rangeEnd[1]; ++$row) { for ($row = $rangeStart[1]; $row <= $rangeEnd[1]; ++$row) {
$oldXfIndexes[$this->getActiveSheet()->getCellByColumnAndRow($col, $row)->getXfIndex()] = true; $oldXfIndexes[$this->getActiveSheet()->getCellByColumnAndRow($col, $row)->getXfIndex()] = true;
} }
} }
break;
}
// clone each of the affected styles, apply the style arrray, and add the new styles to the workbook // clone each of the affected styles, apply the style arrray, and add the new styles to the workbook
$workbook = $this->getActiveSheet()->getParent(); $workbook = $this->getActiveSheet()->getParent();
@@ -483,7 +479,26 @@ class PHPExcel_Style implements PHPExcel_IComparable
} }
} }
// Loop through cells again and update the XF index // Loop through columns, rows, or cells again and update the XF index
switch ($selectionType) {
case 'COLUMN':
for ($col = $rangeStart[0]; $col <= $rangeEnd[0]; ++$col) {
$columnDimension = $this->getActiveSheet()->getColumnDimensionByColumn($col);
$oldXfIndex = $columnDimension->getXfIndex();
$columnDimension->setXfIndex($newXfIndexes[$oldXfIndex]);
}
break;
case 'ROW':
for ($row = $rangeStart[1]; $row <= $rangeEnd[1]; ++$row) {
$rowDimension = $this->getActiveSheet()->getRowDimension($row);
$oldXfIndex = $rowDimension->getXfIndex() === null ?
0 : $rowDimension->getXfIndex(); // row without explicit style should be formatted based on default style
$rowDimension->setXfIndex($newXfIndexes[$oldXfIndex]);
}
break;
case 'CELL':
for ($col = $rangeStart[0]; $col <= $rangeEnd[0]; ++$col) { for ($col = $rangeStart[0]; $col <= $rangeEnd[0]; ++$col) {
for ($row = $rangeStart[1]; $row <= $rangeEnd[1]; ++$row) { for ($row = $rangeStart[1]; $row <= $rangeEnd[1]; ++$row) {
$cell = $this->getActiveSheet()->getCellByColumnAndRow($col, $row); $cell = $this->getActiveSheet()->getCellByColumnAndRow($col, $row);
@@ -491,12 +506,11 @@ class PHPExcel_Style implements PHPExcel_IComparable
$cell->setXfIndex($newXfIndexes[$oldXfIndex]); $cell->setXfIndex($newXfIndexes[$oldXfIndex]);
} }
} }
break;
} else {
throw new Exception("Invalid style array passed.");
} }
} else { } else {
// not a supervisor, just apply the style array directly on style object
if (array_key_exists('fill', $pStyles)) { if (array_key_exists('fill', $pStyles)) {
$this->getFill()->applyFromArray($pStyles['fill']); $this->getFill()->applyFromArray($pStyles['fill']);
} }
@@ -585,7 +599,7 @@ class PHPExcel_Style implements PHPExcel_IComparable
* @return PHPExcel_Style_Conditional[] * @return PHPExcel_Style_Conditional[]
*/ */
public function getConditionalStyles() { public function getConditionalStyles() {
return $this->getActiveSheet()->getConditionalStyles($this->getXActiveCell()); return $this->getActiveSheet()->getConditionalStyles($this->getActiveCell());
} }
/** /**
@@ -596,7 +610,7 @@ class PHPExcel_Style implements PHPExcel_IComparable
*/ */
public function setConditionalStyles($pValue = null) { public function setConditionalStyles($pValue = null) {
if (is_array($pValue)) { if (is_array($pValue)) {
foreach (PHPExcel_Cell::extractAllCellReferencesInRange($this->getXSelectedCells()) as $cellReference) { foreach (PHPExcel_Cell::extractAllCellReferencesInRange($this->getSelectedCells()) as $cellReference) {
$this->getActiveSheet()->setConditionalStyles($cellReference, $pValue); $this->getActiveSheet()->setConditionalStyles($cellReference, $pValue);
} }
} }
@@ -635,37 +649,6 @@ class PHPExcel_Style implements PHPExcel_IComparable
); );
} }
/**
* Hash index
*
* @var string
*/
private $_hashIndex;
/**
* Get hash index
*
* Note that this index may vary during script execution! Only reliable moment is
* while doing a write of a workbook and when changes are not allowed.
*
* @return string Hash index
*/
public function getHashIndex() {
return $this->_hashIndex;
}
/**
* Set hash index
*
* Note that this index may vary during script execution! Only reliable moment is
* while doing a write of a workbook and when changes are not allowed.
*
* @param string $value Hash index
*/
public function setHashIndex($value) {
$this->_hashIndex = $value;
}
/** /**
* Get own index in style collection * Get own index in style collection
* *

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,30 +20,18 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Style * @package PHPExcel_Style
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
}
/** PHPExcel_IComparable */
require_once PHPEXCEL_ROOT . 'PHPExcel/IComparable.php';
/** /**
* PHPExcel_Style_Alignment * PHPExcel_Style_Alignment
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Style * @package PHPExcel_Style
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_Style_Alignment implements PHPExcel_IComparable class PHPExcel_Style_Alignment implements PHPExcel_IComparable
{ {
@@ -190,9 +178,9 @@ class PHPExcel_Style_Alignment implements PHPExcel_IComparable
* *
* @return string E.g. 'A1' * @return string E.g. 'A1'
*/ */
public function getXSelectedCells() public function getSelectedCells()
{ {
return $this->getActiveSheet()->getXSelectedCells(); return $this->getActiveSheet()->getSelectedCells();
} }
/** /**
@@ -201,9 +189,9 @@ class PHPExcel_Style_Alignment implements PHPExcel_IComparable
* *
* @return string E.g. 'A1' * @return string E.g. 'A1'
*/ */
public function getXActiveCell() public function getActiveCell()
{ {
return $this->getActiveSheet()->getXActiveCell(); return $this->getActiveSheet()->getActiveCell();
} }
/** /**
@@ -238,7 +226,7 @@ class PHPExcel_Style_Alignment implements PHPExcel_IComparable
public function applyFromArray($pStyles = null) { public function applyFromArray($pStyles = null) {
if (is_array($pStyles)) { if (is_array($pStyles)) {
if ($this->_isSupervisor) { if ($this->_isSupervisor) {
$this->getActiveSheet()->getStyle($this->getXSelectedCells())->applyFromArray($this->getStyleArray($pStyles)); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($pStyles));
} else { } else {
if (array_key_exists('horizontal', $pStyles)) { if (array_key_exists('horizontal', $pStyles)) {
$this->setHorizontal($pStyles['horizontal']); $this->setHorizontal($pStyles['horizontal']);
@@ -290,7 +278,7 @@ class PHPExcel_Style_Alignment implements PHPExcel_IComparable
if ($this->_isSupervisor) { if ($this->_isSupervisor) {
$styleArray = $this->getStyleArray(array('horizontal' => $pValue)); $styleArray = $this->getStyleArray(array('horizontal' => $pValue));
$this->getActiveSheet()->getStyle($this->getXSelectedCells())->applyFromArray($styleArray); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
} }
else { else {
$this->_horizontal = $pValue; $this->_horizontal = $pValue;
@@ -323,7 +311,7 @@ class PHPExcel_Style_Alignment implements PHPExcel_IComparable
if ($this->_isSupervisor) { if ($this->_isSupervisor) {
$styleArray = $this->getStyleArray(array('vertical' => $pValue)); $styleArray = $this->getStyleArray(array('vertical' => $pValue));
$this->getActiveSheet()->getStyle($this->getXSelectedCells())->applyFromArray($styleArray); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
} else { } else {
$this->_vertical = $pValue; $this->_vertical = $pValue;
} }
@@ -359,7 +347,7 @@ class PHPExcel_Style_Alignment implements PHPExcel_IComparable
if ( ($pValue >= -90 && $pValue <= 90) || $pValue == -165 ) { if ( ($pValue >= -90 && $pValue <= 90) || $pValue == -165 ) {
if ($this->_isSupervisor) { if ($this->_isSupervisor) {
$styleArray = $this->getStyleArray(array('rotation' => $pValue)); $styleArray = $this->getStyleArray(array('rotation' => $pValue));
$this->getActiveSheet()->getStyle($this->getXSelectedCells())->applyFromArray($styleArray); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
} else { } else {
$this->_textRotation = $pValue; $this->_textRotation = $pValue;
} }
@@ -394,7 +382,7 @@ class PHPExcel_Style_Alignment implements PHPExcel_IComparable
} }
if ($this->_isSupervisor) { if ($this->_isSupervisor) {
$styleArray = $this->getStyleArray(array('wrap' => $pValue)); $styleArray = $this->getStyleArray(array('wrap' => $pValue));
$this->getActiveSheet()->getStyle($this->getXSelectedCells())->applyFromArray($styleArray); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
} else { } else {
$this->_wrapText = $pValue; $this->_wrapText = $pValue;
} }
@@ -425,7 +413,7 @@ class PHPExcel_Style_Alignment implements PHPExcel_IComparable
} }
if ($this->_isSupervisor) { if ($this->_isSupervisor) {
$styleArray = $this->getStyleArray(array('shrinkToFit' => $pValue)); $styleArray = $this->getStyleArray(array('shrinkToFit' => $pValue));
$this->getActiveSheet()->getStyle($this->getXSelectedCells())->applyFromArray($styleArray); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
} else { } else {
$this->_shrinkToFit = $pValue; $this->_shrinkToFit = $pValue;
} }
@@ -458,7 +446,7 @@ class PHPExcel_Style_Alignment implements PHPExcel_IComparable
} }
if ($this->_isSupervisor) { if ($this->_isSupervisor) {
$styleArray = $this->getStyleArray(array('indent' => $pValue)); $styleArray = $this->getStyleArray(array('indent' => $pValue));
$this->getActiveSheet()->getStyle($this->getXSelectedCells())->applyFromArray($styleArray); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
} else { } else {
$this->_indent = $pValue; $this->_indent = $pValue;
} }
@@ -485,37 +473,6 @@ class PHPExcel_Style_Alignment implements PHPExcel_IComparable
); );
} }
/**
* Hash index
*
* @var string
*/
private $_hashIndex;
/**
* Get hash index
*
* Note that this index may vary during script execution! Only reliable moment is
* while doing a write of a workbook and when changes are not allowed.
*
* @return string Hash index
*/
public function getHashIndex() {
return $this->_hashIndex;
}
/**
* Set hash index
*
* Note that this index may vary during script execution! Only reliable moment is
* while doing a write of a workbook and when changes are not allowed.
*
* @param string $value Hash index
*/
public function setHashIndex($value) {
$this->_hashIndex = $value;
}
/** /**
* Implement PHP __clone to create a deep clone, not just a shallow copy. * Implement PHP __clone to create a deep clone, not just a shallow copy.
*/ */

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,33 +20,18 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Style * @package PHPExcel_Style
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
}
/** PHPExcel_Style_Color */
require_once PHPEXCEL_ROOT . 'PHPExcel/Style/Color.php';
/** PHPExcel_IComparable */
require_once PHPEXCEL_ROOT . 'PHPExcel/IComparable.php';
/** /**
* PHPExcel_Style_Border * PHPExcel_Style_Border
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Style * @package PHPExcel_Style
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_Style_Border implements PHPExcel_IComparable class PHPExcel_Style_Border implements PHPExcel_IComparable
{ {
@@ -200,9 +185,9 @@ class PHPExcel_Style_Border implements PHPExcel_IComparable
* *
* @return string E.g. 'A1' * @return string E.g. 'A1'
*/ */
public function getXSelectedCells() public function getSelectedCells()
{ {
return $this->getActiveSheet()->getXSelectedCells(); return $this->getActiveSheet()->getSelectedCells();
} }
/** /**
@@ -211,9 +196,9 @@ class PHPExcel_Style_Border implements PHPExcel_IComparable
* *
* @return string E.g. 'A1' * @return string E.g. 'A1'
*/ */
public function getXActiveCell() public function getActiveCell()
{ {
return $this->getActiveSheet()->getXActiveCell(); return $this->getActiveSheet()->getActiveCell();
} }
/** /**
@@ -289,7 +274,7 @@ class PHPExcel_Style_Border implements PHPExcel_IComparable
public function applyFromArray($pStyles = null) { public function applyFromArray($pStyles = null) {
if (is_array($pStyles)) { if (is_array($pStyles)) {
if ($this->_isSupervisor) { if ($this->_isSupervisor) {
$this->getActiveSheet()->getStyle($this->getXSelectedCells())->applyFromArray($this->getStyleArray($pStyles)); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($pStyles));
} else { } else {
if (array_key_exists('style', $pStyles)) { if (array_key_exists('style', $pStyles)) {
$this->setBorderStyle($pStyles['style']); $this->setBorderStyle($pStyles['style']);
@@ -329,7 +314,7 @@ class PHPExcel_Style_Border implements PHPExcel_IComparable
} }
if ($this->_isSupervisor) { if ($this->_isSupervisor) {
$styleArray = $this->getStyleArray(array('style' => $pValue)); $styleArray = $this->getStyleArray(array('style' => $pValue));
$this->getActiveSheet()->getStyle($this->getXSelectedCells())->applyFromArray($styleArray); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
} else { } else {
$this->_borderStyle = $pValue; $this->_borderStyle = $pValue;
} }
@@ -358,7 +343,7 @@ class PHPExcel_Style_Border implements PHPExcel_IComparable
if ($this->_isSupervisor) { if ($this->_isSupervisor) {
$styleArray = $this->getColor()->getStyleArray(array('argb' => $color->getARGB())); $styleArray = $this->getColor()->getStyleArray(array('argb' => $color->getARGB()));
$this->getActiveSheet()->getStyle($this->getXSelectedCells())->applyFromArray($styleArray); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
} else { } else {
$this->_color = $color; $this->_color = $color;
} }
@@ -381,37 +366,6 @@ class PHPExcel_Style_Border implements PHPExcel_IComparable
); );
} }
/**
* Hash index
*
* @var string
*/
private $_hashIndex;
/**
* Get hash index
*
* Note that this index may vary during script execution! Only reliable moment is
* while doing a write of a workbook and when changes are not allowed.
*
* @return string Hash index
*/
public function getHashIndex() {
return $this->_hashIndex;
}
/**
* Set hash index
*
* Note that this index may vary during script execution! Only reliable moment is
* while doing a write of a workbook and when changes are not allowed.
*
* @param string $value Hash index
*/
public function setHashIndex($value) {
$this->_hashIndex = $value;
}
/** /**
* Implement PHP __clone to create a deep clone, not just a shallow copy. * Implement PHP __clone to create a deep clone, not just a shallow copy.
*/ */

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,33 +20,18 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Style * @package PHPExcel_Style
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
}
/** PHPExcel_Style_Border */
require_once PHPEXCEL_ROOT . 'PHPExcel/Style/Border.php';
/** PHPExcel_IComparable */
require_once PHPEXCEL_ROOT . 'PHPExcel/IComparable.php';
/** /**
* PHPExcel_Style_Borders * PHPExcel_Style_Borders
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Style * @package PHPExcel_Style
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_Style_Borders implements PHPExcel_IComparable class PHPExcel_Style_Borders implements PHPExcel_IComparable
{ {
@@ -54,6 +39,7 @@ class PHPExcel_Style_Borders implements PHPExcel_IComparable
const DIAGONAL_NONE = 0; const DIAGONAL_NONE = 0;
const DIAGONAL_UP = 1; const DIAGONAL_UP = 1;
const DIAGONAL_DOWN = 2; const DIAGONAL_DOWN = 2;
const DIAGONAL_BOTH = 3;
/** /**
* Left * Left
@@ -241,9 +227,9 @@ class PHPExcel_Style_Borders implements PHPExcel_IComparable
* *
* @return string E.g. 'A1' * @return string E.g. 'A1'
*/ */
public function getXSelectedCells() public function getSelectedCells()
{ {
return $this->getActiveSheet()->getXSelectedCells(); return $this->getActiveSheet()->getSelectedCells();
} }
/** /**
@@ -252,9 +238,9 @@ class PHPExcel_Style_Borders implements PHPExcel_IComparable
* *
* @return string E.g. 'A1' * @return string E.g. 'A1'
*/ */
public function getXActiveCell() public function getActiveCell()
{ {
return $this->getActiveSheet()->getXActiveCell(); return $this->getActiveSheet()->getActiveCell();
} }
/** /**
@@ -309,7 +295,7 @@ class PHPExcel_Style_Borders implements PHPExcel_IComparable
public function applyFromArray($pStyles = null) { public function applyFromArray($pStyles = null) {
if (is_array($pStyles)) { if (is_array($pStyles)) {
if ($this->_isSupervisor) { if ($this->_isSupervisor) {
$this->getActiveSheet()->getStyle($this->getXSelectedCells())->applyFromArray($this->getStyleArray($pStyles)); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($pStyles));
} else { } else {
if (array_key_exists('left', $pStyles)) { if (array_key_exists('left', $pStyles)) {
$this->getLeft()->applyFromArray($pStyles['left']); $this->getLeft()->applyFromArray($pStyles['left']);
@@ -470,7 +456,7 @@ class PHPExcel_Style_Borders implements PHPExcel_IComparable
} }
if ($this->_isSupervisor) { if ($this->_isSupervisor) {
$styleArray = $this->getStyleArray(array('diagonaldirection' => $pValue)); $styleArray = $this->getStyleArray(array('diagonaldirection' => $pValue));
$this->getActiveSheet()->getStyle($this->getXSelectedCells())->applyFromArray($styleArray); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
} else { } else {
$this->_diagonalDirection = $pValue; $this->_diagonalDirection = $pValue;
} }
@@ -497,37 +483,6 @@ class PHPExcel_Style_Borders implements PHPExcel_IComparable
); );
} }
/**
* Hash index
*
* @var string
*/
private $_hashIndex;
/**
* Get hash index
*
* Note that this index may vary during script execution! Only reliable moment is
* while doing a write of a workbook and when changes are not allowed.
*
* @return string Hash index
*/
public function getHashIndex() {
return $this->_hashIndex;
}
/**
* Set hash index
*
* Note that this index may vary during script execution! Only reliable moment is
* while doing a write of a workbook and when changes are not allowed.
*
* @param string $value Hash index
*/
public function setHashIndex($value) {
$this->_hashIndex = $value;
}
/** /**
* Implement PHP __clone to create a deep clone, not just a shallow copy. * Implement PHP __clone to create a deep clone, not just a shallow copy.
*/ */

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,30 +20,18 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Style * @package PHPExcel_Style
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
}
/** PHPExcel_IComparable */
require_once PHPEXCEL_ROOT . 'PHPExcel/IComparable.php';
/** /**
* PHPExcel_Style_Color * PHPExcel_Style_Color
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Style * @package PHPExcel_Style
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_Style_Color implements PHPExcel_IComparable class PHPExcel_Style_Color implements PHPExcel_IComparable
{ {
@@ -171,9 +159,9 @@ class PHPExcel_Style_Color implements PHPExcel_IComparable
* *
* @return string E.g. 'A1' * @return string E.g. 'A1'
*/ */
public function getXSelectedCells() public function getSelectedCells()
{ {
return $this->getActiveSheet()->getXSelectedCells(); return $this->getActiveSheet()->getSelectedCells();
} }
/** /**
@@ -182,9 +170,9 @@ class PHPExcel_Style_Color implements PHPExcel_IComparable
* *
* @return string E.g. 'A1' * @return string E.g. 'A1'
*/ */
public function getXActiveCell() public function getActiveCell()
{ {
return $this->getActiveSheet()->getXActiveCell(); return $this->getActiveSheet()->getActiveCell();
} }
/** /**
@@ -226,7 +214,7 @@ class PHPExcel_Style_Color implements PHPExcel_IComparable
public function applyFromArray($pStyles = null) { public function applyFromArray($pStyles = null) {
if (is_array($pStyles)) { if (is_array($pStyles)) {
if ($this->_isSupervisor) { if ($this->_isSupervisor) {
$this->getActiveSheet()->getStyle($this->getXSelectedCells())->applyFromArray($this->getStyleArray($pStyles)); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($pStyles));
} else { } else {
if (array_key_exists('rgb', $pStyles)) { if (array_key_exists('rgb', $pStyles)) {
$this->setRGB($pStyles['rgb']); $this->setRGB($pStyles['rgb']);
@@ -265,7 +253,7 @@ class PHPExcel_Style_Color implements PHPExcel_IComparable
} }
if ($this->_isSupervisor) { if ($this->_isSupervisor) {
$styleArray = $this->getStyleArray(array('argb' => $pValue)); $styleArray = $this->getStyleArray(array('argb' => $pValue));
$this->getActiveSheet()->getStyle($this->getXSelectedCells())->applyFromArray($styleArray); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
} else { } else {
$this->_argb = $pValue; $this->_argb = $pValue;
} }
@@ -296,7 +284,7 @@ class PHPExcel_Style_Color implements PHPExcel_IComparable
} }
if ($this->_isSupervisor) { if ($this->_isSupervisor) {
$styleArray = $this->getStyleArray(array('argb' => 'FF' . $pValue)); $styleArray = $this->getStyleArray(array('argb' => 'FF' . $pValue));
$this->getActiveSheet()->getStyle($this->getXSelectedCells())->applyFromArray($styleArray); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
} else { } else {
$this->_argb = 'FF' . $pValue; $this->_argb = 'FF' . $pValue;
} }
@@ -404,37 +392,6 @@ class PHPExcel_Style_Color implements PHPExcel_IComparable
); );
} }
/**
* Hash index
*
* @var string
*/
private $_hashIndex;
/**
* Get hash index
*
* Note that this index may vary during script execution! Only reliable moment is
* while doing a write of a workbook and when changes are not allowed.
*
* @return string Hash index
*/
public function getHashIndex() {
return $this->_hashIndex;
}
/**
* Set hash index
*
* Note that this index may vary during script execution! Only reliable moment is
* while doing a write of a workbook and when changes are not allowed.
*
* @param string $value Hash index
*/
public function setHashIndex($value) {
$this->_hashIndex = $value;
}
/** /**
* Implement PHP __clone to create a deep clone, not just a shallow copy. * Implement PHP __clone to create a deep clone, not just a shallow copy.
*/ */

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,33 +20,18 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Style * @package PHPExcel_Style
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
}
/** PHPExcel_Style */
require_once PHPEXCEL_ROOT . 'PHPExcel/Style.php';
/** PHPExcel_IComparable */
require_once PHPEXCEL_ROOT . 'PHPExcel/IComparable.php';
/** /**
* PHPExcel_Style_Conditional * PHPExcel_Style_Conditional
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Style * @package PHPExcel_Style
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_Style_Conditional implements PHPExcel_IComparable class PHPExcel_Style_Conditional implements PHPExcel_IComparable
{ {
@@ -276,37 +261,6 @@ class PHPExcel_Style_Conditional implements PHPExcel_IComparable
); );
} }
/**
* Hash index
*
* @var string
*/
private $_hashIndex;
/**
* Get hash index
*
* Note that this index may vary during script execution! Only reliable moment is
* while doing a write of a workbook and when changes are not allowed.
*
* @return string Hash index
*/
public function getHashIndex() {
return $this->_hashIndex;
}
/**
* Set hash index
*
* Note that this index may vary during script execution! Only reliable moment is
* while doing a write of a workbook and when changes are not allowed.
*
* @param string $value Hash index
*/
public function setHashIndex($value) {
$this->_hashIndex = $value;
}
/** /**
* Implement PHP __clone to create a deep clone, not just a shallow copy. * Implement PHP __clone to create a deep clone, not just a shallow copy.
*/ */

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,33 +20,18 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Style * @package PHPExcel_Style
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
}
/** PHPExcel_Style_Color */
require_once PHPEXCEL_ROOT . 'PHPExcel/Style/Color.php';
/** PHPExcel_IComparable */
require_once PHPEXCEL_ROOT . 'PHPExcel/IComparable.php';
/** /**
* PHPExcel_Style_Fill * PHPExcel_Style_Fill
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Style * @package PHPExcel_Style
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_Style_Fill implements PHPExcel_IComparable class PHPExcel_Style_Fill implements PHPExcel_IComparable
{ {
@@ -192,9 +177,9 @@ class PHPExcel_Style_Fill implements PHPExcel_IComparable
* *
* @return string E.g. 'A1' * @return string E.g. 'A1'
*/ */
public function getXSelectedCells() public function getSelectedCells()
{ {
return $this->getActiveSheet()->getXSelectedCells(); return $this->getActiveSheet()->getSelectedCells();
} }
/** /**
@@ -203,9 +188,9 @@ class PHPExcel_Style_Fill implements PHPExcel_IComparable
* *
* @return string E.g. 'A1' * @return string E.g. 'A1'
*/ */
public function getXActiveCell() public function getActiveCell()
{ {
return $this->getActiveSheet()->getXActiveCell(); return $this->getActiveSheet()->getActiveCell();
} }
/** /**
@@ -244,7 +229,7 @@ class PHPExcel_Style_Fill implements PHPExcel_IComparable
public function applyFromArray($pStyles = null) { public function applyFromArray($pStyles = null) {
if (is_array($pStyles)) { if (is_array($pStyles)) {
if ($this->_isSupervisor) { if ($this->_isSupervisor) {
$this->getActiveSheet()->getStyle($this->getXSelectedCells())->applyFromArray($this->getStyleArray($pStyles)); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($pStyles));
} else { } else {
if (array_key_exists('type', $pStyles)) { if (array_key_exists('type', $pStyles)) {
$this->setFillType($pStyles['type']); $this->setFillType($pStyles['type']);
@@ -289,7 +274,7 @@ class PHPExcel_Style_Fill implements PHPExcel_IComparable
public function setFillType($pValue = PHPExcel_Style_Fill::FILL_NONE) { public function setFillType($pValue = PHPExcel_Style_Fill::FILL_NONE) {
if ($this->_isSupervisor) { if ($this->_isSupervisor) {
$styleArray = $this->getStyleArray(array('type' => $pValue)); $styleArray = $this->getStyleArray(array('type' => $pValue));
$this->getActiveSheet()->getStyle($this->getXSelectedCells())->applyFromArray($styleArray); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
} else { } else {
$this->_fillType = $pValue; $this->_fillType = $pValue;
} }
@@ -317,7 +302,7 @@ class PHPExcel_Style_Fill implements PHPExcel_IComparable
public function setRotation($pValue = 0) { public function setRotation($pValue = 0) {
if ($this->_isSupervisor) { if ($this->_isSupervisor) {
$styleArray = $this->getStyleArray(array('rotation' => $pValue)); $styleArray = $this->getStyleArray(array('rotation' => $pValue));
$this->getActiveSheet()->getStyle($this->getXSelectedCells())->applyFromArray($styleArray); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
} else { } else {
$this->_rotation = $pValue; $this->_rotation = $pValue;
} }
@@ -346,7 +331,7 @@ class PHPExcel_Style_Fill implements PHPExcel_IComparable
if ($this->_isSupervisor) { if ($this->_isSupervisor) {
$styleArray = $this->getStartColor()->getStyleArray(array('argb' => $color->getARGB())); $styleArray = $this->getStartColor()->getStyleArray(array('argb' => $color->getARGB()));
$this->getActiveSheet()->getStyle($this->getXSelectedCells())->applyFromArray($styleArray); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
} else { } else {
$this->_startColor = $color; $this->_startColor = $color;
} }
@@ -375,7 +360,7 @@ class PHPExcel_Style_Fill implements PHPExcel_IComparable
if ($this->_isSupervisor) { if ($this->_isSupervisor) {
$styleArray = $this->getEndColor()->getStyleArray(array('argb' => $color->getARGB())); $styleArray = $this->getEndColor()->getStyleArray(array('argb' => $color->getARGB()));
$this->getActiveSheet()->getStyle($this->getXSelectedCells())->applyFromArray($styleArray); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
} else { } else {
$this->_endColor = $color; $this->_endColor = $color;
} }
@@ -400,37 +385,6 @@ class PHPExcel_Style_Fill implements PHPExcel_IComparable
); );
} }
/**
* Hash index
*
* @var string
*/
private $_hashIndex;
/**
* Get hash index
*
* Note that this index may vary during script execution! Only reliable moment is
* while doing a write of a workbook and when changes are not allowed.
*
* @return string Hash index
*/
public function getHashIndex() {
return $this->_hashIndex;
}
/**
* Set hash index
*
* Note that this index may vary during script execution! Only reliable moment is
* while doing a write of a workbook and when changes are not allowed.
*
* @param string $value Hash index
*/
public function setHashIndex($value) {
$this->_hashIndex = $value;
}
/** /**
* Implement PHP __clone to create a deep clone, not just a shallow copy. * Implement PHP __clone to create a deep clone, not just a shallow copy.
*/ */

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,33 +20,18 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Style * @package PHPExcel_Style
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
}
/** PHPExcel_Style_Color */
require_once PHPEXCEL_ROOT . 'PHPExcel/Style/Color.php';
/** PHPExcel_IComparable */
require_once PHPEXCEL_ROOT . 'PHPExcel/IComparable.php';
/** /**
* PHPExcel_Style_Font * PHPExcel_Style_Font
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Style * @package PHPExcel_Style
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_Style_Font implements PHPExcel_IComparable class PHPExcel_Style_Font implements PHPExcel_IComparable
{ {
@@ -207,9 +192,9 @@ class PHPExcel_Style_Font implements PHPExcel_IComparable
* *
* @return string E.g. 'A1' * @return string E.g. 'A1'
*/ */
public function getXSelectedCells() public function getSelectedCells()
{ {
return $this->getActiveSheet()->getXSelectedCells(); return $this->getActiveSheet()->getSelectedCells();
} }
/** /**
@@ -218,9 +203,9 @@ class PHPExcel_Style_Font implements PHPExcel_IComparable
* *
* @return string E.g. 'A1' * @return string E.g. 'A1'
*/ */
public function getXActiveCell() public function getActiveCell()
{ {
return $this->getActiveSheet()->getXActiveCell(); return $this->getActiveSheet()->getActiveCell();
} }
/** /**
@@ -259,7 +244,7 @@ class PHPExcel_Style_Font implements PHPExcel_IComparable
public function applyFromArray($pStyles = null) { public function applyFromArray($pStyles = null) {
if (is_array($pStyles)) { if (is_array($pStyles)) {
if ($this->_isSupervisor) { if ($this->_isSupervisor) {
$this->getActiveSheet()->getStyle($this->getXSelectedCells())->applyFromArray($this->getStyleArray($pStyles)); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($pStyles));
} else { } else {
if (array_key_exists('name', $pStyles)) { if (array_key_exists('name', $pStyles)) {
$this->setName($pStyles['name']); $this->setName($pStyles['name']);
@@ -319,7 +304,7 @@ class PHPExcel_Style_Font implements PHPExcel_IComparable
} }
if ($this->_isSupervisor) { if ($this->_isSupervisor) {
$styleArray = $this->getStyleArray(array('name' => $pValue)); $styleArray = $this->getStyleArray(array('name' => $pValue));
$this->getActiveSheet()->getStyle($this->getXSelectedCells())->applyFromArray($styleArray); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
} else { } else {
$this->_name = $pValue; $this->_name = $pValue;
} }
@@ -350,7 +335,7 @@ class PHPExcel_Style_Font implements PHPExcel_IComparable
} }
if ($this->_isSupervisor) { if ($this->_isSupervisor) {
$styleArray = $this->getStyleArray(array('size' => $pValue)); $styleArray = $this->getStyleArray(array('size' => $pValue));
$this->getActiveSheet()->getStyle($this->getXSelectedCells())->applyFromArray($styleArray); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
} else { } else {
$this->_size = $pValue; $this->_size = $pValue;
} }
@@ -381,7 +366,7 @@ class PHPExcel_Style_Font implements PHPExcel_IComparable
} }
if ($this->_isSupervisor) { if ($this->_isSupervisor) {
$styleArray = $this->getStyleArray(array('bold' => $pValue)); $styleArray = $this->getStyleArray(array('bold' => $pValue));
$this->getActiveSheet()->getStyle($this->getXSelectedCells())->applyFromArray($styleArray); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
} else { } else {
$this->_bold = $pValue; $this->_bold = $pValue;
} }
@@ -412,7 +397,7 @@ class PHPExcel_Style_Font implements PHPExcel_IComparable
} }
if ($this->_isSupervisor) { if ($this->_isSupervisor) {
$styleArray = $this->getStyleArray(array('italic' => $pValue)); $styleArray = $this->getStyleArray(array('italic' => $pValue));
$this->getActiveSheet()->getStyle($this->getXSelectedCells())->applyFromArray($styleArray); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
} else { } else {
$this->_italic = $pValue; $this->_italic = $pValue;
} }
@@ -443,7 +428,7 @@ class PHPExcel_Style_Font implements PHPExcel_IComparable
} }
if ($this->_isSupervisor) { if ($this->_isSupervisor) {
$styleArray = $this->getStyleArray(array('superScript' => $pValue)); $styleArray = $this->getStyleArray(array('superScript' => $pValue));
$this->getActiveSheet()->getStyle($this->getXSelectedCells())->applyFromArray($styleArray); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
} else { } else {
$this->_superScript = $pValue; $this->_superScript = $pValue;
$this->_subScript = !$pValue; $this->_subScript = !$pValue;
@@ -475,7 +460,7 @@ class PHPExcel_Style_Font implements PHPExcel_IComparable
} }
if ($this->_isSupervisor) { if ($this->_isSupervisor) {
$styleArray = $this->getStyleArray(array('subScript' => $pValue)); $styleArray = $this->getStyleArray(array('subScript' => $pValue));
$this->getActiveSheet()->getStyle($this->getXSelectedCells())->applyFromArray($styleArray); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
} else { } else {
$this->_subScript = $pValue; $this->_subScript = $pValue;
$this->_superScript = !$pValue; $this->_superScript = !$pValue;
@@ -507,7 +492,7 @@ class PHPExcel_Style_Font implements PHPExcel_IComparable
} }
if ($this->_isSupervisor) { if ($this->_isSupervisor) {
$styleArray = $this->getStyleArray(array('underline' => $pValue)); $styleArray = $this->getStyleArray(array('underline' => $pValue));
$this->getActiveSheet()->getStyle($this->getXSelectedCells())->applyFromArray($styleArray); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
} else { } else {
$this->_underline = $pValue; $this->_underline = $pValue;
} }
@@ -559,7 +544,7 @@ class PHPExcel_Style_Font implements PHPExcel_IComparable
} }
if ($this->_isSupervisor) { if ($this->_isSupervisor) {
$styleArray = $this->getStyleArray(array('strike' => $pValue)); $styleArray = $this->getStyleArray(array('strike' => $pValue));
$this->getActiveSheet()->getStyle($this->getXSelectedCells())->applyFromArray($styleArray); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
} else { } else {
$this->_strikethrough = $pValue; $this->_strikethrough = $pValue;
} }
@@ -588,7 +573,7 @@ class PHPExcel_Style_Font implements PHPExcel_IComparable
if ($this->_isSupervisor) { if ($this->_isSupervisor) {
$styleArray = $this->getColor()->getStyleArray(array('argb' => $color->getARGB())); $styleArray = $this->getColor()->getStyleArray(array('argb' => $color->getARGB()));
$this->getActiveSheet()->getStyle($this->getXSelectedCells())->applyFromArray($styleArray); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
} else { } else {
$this->_color = $color; $this->_color = $color;
} }
@@ -618,37 +603,6 @@ class PHPExcel_Style_Font implements PHPExcel_IComparable
); );
} }
/**
* Hash index
*
* @var string
*/
private $_hashIndex;
/**
* Get hash index
*
* Note that this index may vary during script execution! Only reliable moment is
* while doing a write of a workbook and when changes are not allowed.
*
* @return string Hash index
*/
public function getHashIndex() {
return $this->_hashIndex;
}
/**
* Set hash index
*
* Note that this index may vary during script execution! Only reliable moment is
* while doing a write of a workbook and when changes are not allowed.
*
* @param string $value Hash index
*/
public function setHashIndex($value) {
$this->_hashIndex = $value;
}
/** /**
* Implement PHP __clone to create a deep clone, not just a shallow copy. * Implement PHP __clone to create a deep clone, not just a shallow copy.
*/ */

View File

@@ -2,7 +2,7 @@
/** /**
* PHPExcel * PHPExcel
* *
* Copyright (c) 2006 - 2009 PHPExcel * Copyright (c) 2006 - 2010 PHPExcel
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@@ -20,36 +20,18 @@
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Style * @package PHPExcel_Style
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/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 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.0, 2009-08-10 * @version 1.7.3c, 2010-06-01
*/ */
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
/**
* @ignore
*/
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
}
/** PHPExcel_IComparable */
require_once PHPEXCEL_ROOT . 'PHPExcel/IComparable.php';
/** PHPExcel_Shared_Date */
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/Date.php';
/** PHPExcel_Calculation_Functions */
require_once PHPEXCEL_ROOT . 'PHPExcel/Calculation/Functions.php';
/** /**
* PHPExcel_Style_NumberFormat * PHPExcel_Style_NumberFormat
* *
* @category PHPExcel * @category PHPExcel
* @package PHPExcel_Style * @package PHPExcel_Style
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel) * @copyright Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
*/ */
class PHPExcel_Style_NumberFormat implements PHPExcel_IComparable class PHPExcel_Style_NumberFormat implements PHPExcel_IComparable
{ {
@@ -203,9 +185,9 @@ class PHPExcel_Style_NumberFormat implements PHPExcel_IComparable
* *
* @return string E.g. 'A1' * @return string E.g. 'A1'
*/ */
public function getXSelectedCells() public function getSelectedCells()
{ {
return $this->getActiveSheet()->getXSelectedCells(); return $this->getActiveSheet()->getSelectedCells();
} }
/** /**
@@ -214,9 +196,9 @@ class PHPExcel_Style_NumberFormat implements PHPExcel_IComparable
* *
* @return string E.g. 'A1' * @return string E.g. 'A1'
*/ */
public function getXActiveCell() public function getActiveCell()
{ {
return $this->getActiveSheet()->getXActiveCell(); return $this->getActiveSheet()->getActiveCell();
} }
/** /**
@@ -245,10 +227,11 @@ class PHPExcel_Style_NumberFormat implements PHPExcel_IComparable
* @throws Exception * @throws Exception
* @return PHPExcel_Style_NumberFormat * @return PHPExcel_Style_NumberFormat
*/ */
public function applyFromArray($pStyles = null) { public function applyFromArray($pStyles = null)
{
if (is_array($pStyles)) { if (is_array($pStyles)) {
if ($this->_isSupervisor) { if ($this->_isSupervisor) {
$this->getActiveSheet()->getStyle($this->getXSelectedCells())->applyFromArray($this->getStyleArray($pStyles)); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($pStyles));
} else { } else {
if (array_key_exists('code', $pStyles)) { if (array_key_exists('code', $pStyles)) {
$this->setFormatCode($pStyles['code']); $this->setFormatCode($pStyles['code']);
@@ -265,7 +248,8 @@ class PHPExcel_Style_NumberFormat implements PHPExcel_IComparable
* *
* @return string * @return string
*/ */
public function getFormatCode() { public function getFormatCode()
{
if ($this->_isSupervisor) { if ($this->_isSupervisor) {
return $this->getSharedComponent()->getFormatCode(); return $this->getSharedComponent()->getFormatCode();
} }
@@ -282,13 +266,14 @@ class PHPExcel_Style_NumberFormat implements PHPExcel_IComparable
* @param string $pValue * @param string $pValue
* @return PHPExcel_Style_NumberFormat * @return PHPExcel_Style_NumberFormat
*/ */
public function setFormatCode($pValue = PHPExcel_Style_NumberFormat::FORMAT_GENERAL) { public function setFormatCode($pValue = PHPExcel_Style_NumberFormat::FORMAT_GENERAL)
{
if ($pValue == '') { if ($pValue == '') {
$pValue = PHPExcel_Style_NumberFormat::FORMAT_GENERAL; $pValue = PHPExcel_Style_NumberFormat::FORMAT_GENERAL;
} }
if ($this->_isSupervisor) { if ($this->_isSupervisor) {
$styleArray = $this->getStyleArray(array('code' => $pValue)); $styleArray = $this->getStyleArray(array('code' => $pValue));
$this->getActiveSheet()->getStyle($this->getXSelectedCells())->applyFromArray($styleArray); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
} else { } else {
$this->_formatCode = $pValue; $this->_formatCode = $pValue;
$this->_builtInFormatCode = self::builtInFormatCodeIndex($pValue); $this->_builtInFormatCode = self::builtInFormatCodeIndex($pValue);
@@ -301,7 +286,8 @@ class PHPExcel_Style_NumberFormat implements PHPExcel_IComparable
* *
* @return int * @return int
*/ */
public function getBuiltInFormatCode() { public function getBuiltInFormatCode()
{
if ($this->_isSupervisor) { if ($this->_isSupervisor) {
return $this->getSharedComponent()->getBuiltInFormatCode(); return $this->getSharedComponent()->getBuiltInFormatCode();
} }
@@ -314,11 +300,12 @@ class PHPExcel_Style_NumberFormat implements PHPExcel_IComparable
* @param int $pValue * @param int $pValue
* @return PHPExcel_Style_NumberFormat * @return PHPExcel_Style_NumberFormat
*/ */
public function setBuiltInFormatCode($pValue = 0) { public function setBuiltInFormatCode($pValue = 0)
{
if ($this->_isSupervisor) { if ($this->_isSupervisor) {
$styleArray = $this->getStyleArray(array('code' => self::builtInFormatCode($pValue))); $styleArray = $this->getStyleArray(array('code' => self::builtInFormatCode($pValue)));
$this->getActiveSheet()->getStyle($this->getXSelectedCells())->applyFromArray($styleArray); $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
} else { } else {
$this->_builtInFormatCode = $pValue; $this->_builtInFormatCode = $pValue;
$this->_formatCode = self::builtInFormatCode($pValue); $this->_formatCode = self::builtInFormatCode($pValue);
@@ -397,7 +384,8 @@ class PHPExcel_Style_NumberFormat implements PHPExcel_IComparable
* @param int $pIndex * @param int $pIndex
* @return string * @return string
*/ */
public static function builtInFormatCode($pIndex) { public static function builtInFormatCode($pIndex)
{
// Clean parameter // Clean parameter
$pIndex = intval($pIndex); $pIndex = intval($pIndex);
@@ -418,7 +406,8 @@ class PHPExcel_Style_NumberFormat implements PHPExcel_IComparable
* @param string $formatCode * @param string $formatCode
* @return int|boolean * @return int|boolean
*/ */
public static function builtInFormatCodeIndex($formatCode) { public static function builtInFormatCodeIndex($formatCode)
{
// Ensure built-in format codes are available // Ensure built-in format codes are available
self::fillBuiltInFormatCodes(); self::fillBuiltInFormatCodes();
@@ -435,7 +424,8 @@ class PHPExcel_Style_NumberFormat implements PHPExcel_IComparable
* *
* @return string Hash code * @return string Hash code
*/ */
public function getHashCode() { public function getHashCode()
{
if ($this->_isSupervisor) { if ($this->_isSupervisor) {
return $this->getSharedComponent()->getHashCode(); return $this->getSharedComponent()->getHashCode();
} }
@@ -446,41 +436,11 @@ class PHPExcel_Style_NumberFormat implements PHPExcel_IComparable
); );
} }
/**
* Hash index
*
* @var string
*/
private $_hashIndex;
/**
* Get hash index
*
* Note that this index may vary during script execution! Only reliable moment is
* while doing a write of a workbook and when changes are not allowed.
*
* @return string Hash index
*/
public function getHashIndex() {
return $this->_hashIndex;
}
/**
* Set hash index
*
* Note that this index may vary during script execution! Only reliable moment is
* while doing a write of a workbook and when changes are not allowed.
*
* @param string $value Hash index
*/
public function setHashIndex($value) {
$this->_hashIndex = $value;
}
/** /**
* Implement PHP __clone to create a deep clone, not just a shallow copy. * Implement PHP __clone to create a deep clone, not just a shallow copy.
*/ */
public function __clone() { public function __clone()
{
$vars = get_object_vars($this); $vars = get_object_vars($this);
foreach ($vars as $key => $value) { foreach ($vars as $key => $value) {
if (is_object($value)) { if (is_object($value)) {
@@ -491,15 +451,60 @@ class PHPExcel_Style_NumberFormat implements PHPExcel_IComparable
} }
} }
private static $_dateFormatReplacements = array(
// first remove escapes related to non-format characters
'\\' => '',
// 12-hour suffix
'am/pm' => 'A',
// 4-digit year
'yyyy' => 'Y',
// 2-digit year
'yy' => 'y',
// first letter of month - no php equivalent
'mmmmm' => 'M',
// full month name
'mmmm' => 'F',
// short month name
'mmm' => 'M',
// mm is minutes if time or month w/leading zero
':mm' => ':i',
// month leading zero
'mm' => 'm',
// month no leading zero
'm' => 'n',
// full day of week name
'dddd' => 'l',
// short day of week name
'ddd' => 'D',
// days leading zero
'dd' => 'd',
// days no leading zero
'd' => 'j',
// seconds
'ss' => 's',
// fractional seconds - no php equivalent
'.s' => ''
);
private static $_dateFormatReplacements24 = array(
'hh' => 'H',
'h' => 'G'
);
private static $_dateFormatReplacements12 = array(
'hh' => 'h',
'h' => 'g'
);
/** /**
* Convert a value in a pre-defined format to a PHP string * Convert a value in a pre-defined format to a PHP string
* *
* @param mixed $value Value to format * @param mixed $value Value to format
* @param string $format Format code * @param string $format Format code
* @param array $callBack Callback function for additional formatting of string
* @return string Formatted string * @return string Formatted string
*/ */
public static function toFormattedString($value = '', $format = '') { public static function toFormattedString($value = '', $format = '', $callBack = null)
// For now we do not treat strings although part 4 of a format code affects strings {
// For now we do not treat strings although section 4 of a format code affects strings
if (!is_numeric($value)) return $value; if (!is_numeric($value)) return $value;
// For 'General' format code, we just pass the value although this is not entirely the way Excel does it, // For 'General' format code, we just pass the value although this is not entirely the way Excel does it,
@@ -508,67 +513,79 @@ class PHPExcel_Style_NumberFormat implements PHPExcel_IComparable
return $value; return $value;
} }
// Get the parts, there can be up to four parts // Get the sections, there can be up to four sections
$parts = explode(';', $format); $sections = explode(';', $format);
// We should really fetch the relevant part depending on whether we have a positive number, // Fetch the relevant section depending on whether number is positive, negative, or zero?
// negative number, zero, or text. But for now we just use first part // Text not supported yet.
$format = $parts[0]; // Here is how the sections apply to various values in Excel:
// 1 section: [POSITIVE/NEGATIVE/ZERO/TEXT]
// 2 sections: [POSITIVE/ZERO/TEXT] [NEGATIVE]
// 3 sections: [POSITIVE/TEXT] [NEGATIVE] [ZERO]
// 4 sections: [POSITIVE] [NEGATIVE] [ZERO] [TEXT]
switch (count($sections)) {
case 1:
$format = $sections[0];
break;
if (preg_match("/^[hmsdy]/i", $format)) { // custom datetime format case 2:
$format = ($value >= 0) ? $sections[0] : $sections[1];
$value = abs($value); // Use the absolute value
break;
case 3:
$format = ($value > 0) ?
$sections[0] : ( ($value < 0) ?
$sections[1] : $sections[2]);
$value = abs($value); // Use the absolute value
break;
case 4:
$format = ($value > 0) ?
$sections[0] : ( ($value < 0) ?
$sections[1] : $sections[2]);
$value = abs($value); // Use the absolute value
break;
default:
// something is wrong, just use first section
$format = $sections[0];
break;
}
// Save format with color information for later use below
$formatColor = $format;
// Strip color information
$color_regex = '/^\\[[a-zA-Z]+\\]/';
$format = preg_replace($color_regex, '', $format);
// Let's begin inspecting the format and converting the value to a formatted string
if (preg_match('/^(\[\$[A-Z]*-[0-9A-F]*\])*[hmsdy]/i', $format)) { // datetime format
// dvc: convert Excel formats to PHP date formats // dvc: convert Excel formats to PHP date formats
// first remove escapes related to non-format characters
// strip off first part containing e.g. [$-F800] or [$USD-409]
// general syntax: [$<Currency string>-<language info>]
// language info is in hexadecimal
$format = preg_replace('/^(\[\$[A-Z]*-[0-9A-F]*\])/i', '', $format);
// OpenOffice.org uses upper-case number formats, e.g. 'YYYY', convert to lower-case // OpenOffice.org uses upper-case number formats, e.g. 'YYYY', convert to lower-case
$format = strtolower($format); $format = strtolower($format);
$format = str_replace('\\', '', $format); $format = strtr($format,self::$_dateFormatReplacements);
if (!strpos($format,'A')) { // 24-hour time format
// 4-digit year $format = strtr($format,self::$_dateFormatReplacements24);
$format = str_replace('yyyy', 'Y', $format); } else { // 12-hour time format
// 2-digit year $format = strtr($format,self::$_dateFormatReplacements12);
$format = str_replace('yy', 'y', $format);
// first letter of month - no php equivalent
$format = str_replace('mmmmm', 'M', $format);
// full month name
$format = str_replace('mmmm', 'F', $format);
// short month name
$format = str_replace('mmm', 'M', $format);
// mm is minutes if time or month w/leading zero
$format = str_replace(':mm', ':i', $format);
// tmp place holder
$format = str_replace('mm', 'x', $format);
// month no leading zero
$format = str_replace('m', 'n', $format);
// month leading zero
$format = str_replace('x', 'm', $format);
// 12-hour suffix
$format = str_replace('am/pm', 'A', $format);
// full day of week name
$format = str_replace('dddd', 'l', $format);
// short day of week name
$format = str_replace('ddd', 'D', $format);
// tmp place holder
$format = str_replace('dd', 'x', $format);
// days no leading zero
$format = str_replace('d', 'j', $format);
// days leading zero
$format = str_replace('x', 'd', $format);
// seconds
$format = str_replace('ss', 's', $format);
// fractional seconds - no php equivalent
$format = str_replace('.s', '', $format);
if (!strpos($format,'A')) { // 24-hour format
$format = str_replace('h', 'H', $format);
} }
return gmdate($format, PHPExcel_Shared_Date::ExcelToPHP($value)); $dateObj = PHPExcel_Shared_Date::ExcelToPHPObject($value);
$value = $dateObj->format($format);
} else if (preg_match('/%$/', $format)) { // % number format } else if (preg_match('/%$/', $format)) { // % number format
if ($format === self::FORMAT_PERCENTAGE) { if ($format === self::FORMAT_PERCENTAGE) {
return round( (100 * $value), 0) . '%'; $value = round( (100 * $value), 0) . '%';
} } else {
if (preg_match('/\.[#0]+/i', $format, $m)) { if (preg_match('/\.[#0]+/i', $format, $m)) {
$s = substr($m[0], 0, 1) . (strlen($m[0]) - 1); $s = substr($m[0], 0, 1) . (strlen($m[0]) - 1);
$format = str_replace($m[0], $s, $format); $format = str_replace($m[0], $s, $format);
@@ -578,12 +595,12 @@ class PHPExcel_Style_NumberFormat implements PHPExcel_IComparable
} }
$format = '%' . str_replace('%', 'f%%', $format); $format = '%' . str_replace('%', 'f%%', $format);
return sprintf($format, 100 * $value); $value = sprintf($format, 100 * $value);
}
} else { } else {
if (preg_match ("/^([0-9.,-]+)$/", $value)) {
if ($format === self::FORMAT_CURRENCY_EUR_SIMPLE) { if ($format === self::FORMAT_CURRENCY_EUR_SIMPLE) {
return 'EUR ' . sprintf('%1.2f', $value); $value = 'EUR ' . sprintf('%1.2f', $value);
} else { } else {
// In Excel formats, "_" is used to add spacing, which we can't do in HTML // In Excel formats, "_" is used to add spacing, which we can't do in HTML
@@ -595,17 +612,31 @@ class PHPExcel_Style_NumberFormat implements PHPExcel_IComparable
// Some non-number strings are quoted, so we'll get rid of the quotes // Some non-number strings are quoted, so we'll get rid of the quotes
$format = preg_replace('/"/', '', $format); $format = preg_replace('/"/', '', $format);
// TEMPORARY - Convert # to 0
$format = preg_replace('/\\#/', '0', $format);
// Find out if we need thousands separator // Find out if we need thousands separator
$useThousands = preg_match('/,/', $format); // This is indicated by a comma enclosed by a digit placeholder:
// #,# or 0,0
$useThousands = preg_match('/(#,#|0,0)/', $format);
if ($useThousands) { if ($useThousands) {
$format = preg_replace('/,/', '', $format); $format = preg_replace('/0,0/', '00', $format);
$format = preg_replace('/#,#/', '##', $format);
} }
if (preg_match('/0?.*\?\/\?/', $format, $m)) { // Scale thousands, millions,...
// This is indicated by a number of commas after a digit placeholder:
// #, or 0.0,,
$scale = 1; // same as no scale
$matches = array();
if (preg_match('/(#|0)(,+)/', $format, $matches)) {
$scale = pow(1000, strlen($matches[2]));
// strip the commas
$format = preg_replace('/0,+/', '0', $format);
$format = preg_replace('/#,+/', '#', $format);
}
if (preg_match('/#?.*\?\/\?/', $format, $m)) {
//echo 'Format mask is fractional '.$format.' <br />'; //echo 'Format mask is fractional '.$format.' <br />';
if ($value != (int)$value) {
$sign = ($value < 0) ? '-' : ''; $sign = ($value < 0) ? '-' : '';
$integerPart = floor(abs($value)); $integerPart = floor(abs($value));
@@ -618,41 +649,60 @@ class PHPExcel_Style_NumberFormat implements PHPExcel_IComparable
$adjustedDecimalPart = $decimalPart/$GCD; $adjustedDecimalPart = $decimalPart/$GCD;
$adjustedDecimalDivisor = $decimalDivisor/$GCD; $adjustedDecimalDivisor = $decimalDivisor/$GCD;
if (strpos($format,'0') !== false) { if ((strpos($format,'0') !== false) || (substr($format,0,3) == '? ?')) {
if ($integerPart == 0) { $integerPart = ''; }
$value = "$sign$integerPart $adjustedDecimalPart/$adjustedDecimalDivisor"; $value = "$sign$integerPart $adjustedDecimalPart/$adjustedDecimalDivisor";
} else { } else {
$adjustedDecimalPart += $integerPart * $adjustedDecimalDivisor; $adjustedDecimalPart += $integerPart * $adjustedDecimalDivisor;
$value = "$sign$adjustedDecimalPart/$adjustedDecimalDivisor"; $value = "$sign$adjustedDecimalPart/$adjustedDecimalDivisor";
} }
}
} else { } else {
// Handle the number itself // Handle the number itself
$number_regex = "/(\d+)(\.?)(\d*)/";
// scale number
$value = $value / $scale;
// Strip #
$format = preg_replace('/\\#/', '', $format);
$number_regex = "/(0+)(\.?)(0*)/";
$matches = array();
if (preg_match($number_regex, $format, $matches)) { if (preg_match($number_regex, $format, $matches)) {
$left = $matches[1]; $left = $matches[1];
$dec = $matches[2]; $dec = $matches[2];
$right = $matches[3]; $right = $matches[3];
// minimun width of formatted number (including dot)
$minWidth = strlen($left) + strlen($dec) + strlen($right);
if ($useThousands) { if ($useThousands) {
$localeconv = localeconv(); $value = number_format(
if (($localeconv['thousands_sep'] == '') || ($localeconv['decimal_point'] == '')) { $value
$value = number_format($value, strlen($right), $localeconv['mon_decimal_point'], $localeconv['mon_thousands_sep']); , strlen($right)
, PHPExcel_Shared_String::getDecimalSeparator()
, PHPExcel_Shared_String::getThousandsSeparator()
);
} else { } else {
$value = number_format($value, strlen($right), $localeconv['decimal_point'], $localeconv['thousands_sep']); $sprintf_pattern = "%0$minWidth." . strlen($right) . "f";
}
} else {
$sprintf_pattern = "%1." . strlen($right) . "f";
$value = sprintf($sprintf_pattern, $value); $value = sprintf($sprintf_pattern, $value);
} }
$value = preg_replace($number_regex, $value, $format); $value = preg_replace($number_regex, $value, $format);
} }
} }
return $value;
} }
} }
// Additional formatting provided by callback function
if ($callBack !== null) {
list($writerInstance, $function) = $callBack;
$value = $writerInstance->$function($value, $formatColor);
}
return $value; return $value;
} }
}
} }

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