2010-08-26 19:14:53 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* PHPExcel
|
|
|
|
*
|
2013-12-31 18:36:33 +00:00
|
|
|
* Copyright (c) 2006 - 2014 PHPExcel
|
2010-08-26 19:14:53 +00:00
|
|
|
*
|
|
|
|
* 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
|
2013-12-31 18:36:33 +00:00
|
|
|
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
|
2010-08-26 19:14:53 +00:00
|
|
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
|
|
|
* @version ##VERSION##, ##DATE##
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PHPExcel_CachedObjectStorage_CacheBase
|
|
|
|
*
|
|
|
|
* @category PHPExcel
|
|
|
|
* @package PHPExcel_CachedObjectStorage
|
2013-12-31 18:36:33 +00:00
|
|
|
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
|
2010-08-26 19:14:53 +00:00
|
|
|
*/
|
2012-09-06 21:56:56 +00:00
|
|
|
abstract class PHPExcel_CachedObjectStorage_CacheBase {
|
2010-08-26 19:14:53 +00:00
|
|
|
|
|
|
|
/**
|
2012-03-11 17:58:38 +00:00
|
|
|
* Parent worksheet
|
2010-08-26 19:14:53 +00:00
|
|
|
*
|
2012-03-11 17:58:38 +00:00
|
|
|
* @var PHPExcel_Worksheet
|
2010-08-26 19:14:53 +00:00
|
|
|
*/
|
|
|
|
protected $_parent;
|
|
|
|
|
|
|
|
/**
|
2012-03-11 17:58:38 +00:00
|
|
|
* The currently active Cell
|
2010-08-26 19:14:53 +00:00
|
|
|
*
|
2012-03-11 17:58:38 +00:00
|
|
|
* @var PHPExcel_Cell
|
2010-08-26 19:14:53 +00:00
|
|
|
*/
|
|
|
|
protected $_currentObject = null;
|
|
|
|
|
|
|
|
/**
|
2012-03-11 17:58:38 +00:00
|
|
|
* Coordinate address of the currently active Cell
|
2010-08-26 19:14:53 +00:00
|
|
|
*
|
2012-03-11 17:58:38 +00:00
|
|
|
* @var string
|
2010-08-26 19:14:53 +00:00
|
|
|
*/
|
|
|
|
protected $_currentObjectID = null;
|
|
|
|
|
|
|
|
|
2011-04-25 14:25:53 +00:00
|
|
|
/**
|
2012-03-11 17:58:38 +00:00
|
|
|
* Flag indicating whether the currently active Cell requires saving
|
2011-04-25 14:25:53 +00:00
|
|
|
*
|
2012-03-11 17:58:38 +00:00
|
|
|
* @var boolean
|
2011-04-25 14:25:53 +00:00
|
|
|
*/
|
|
|
|
protected $_currentCellIsDirty = true;
|
|
|
|
|
2010-08-26 19:14:53 +00:00
|
|
|
/**
|
2012-03-11 17:58:38 +00:00
|
|
|
* An array of cells or cell pointers for the worksheet cells held in this cache,
|
2010-08-26 19:14:53 +00:00
|
|
|
* and indexed by their coordinate address within the worksheet
|
|
|
|
*
|
2012-03-11 17:58:38 +00:00
|
|
|
* @var array of mixed
|
2010-08-26 19:14:53 +00:00
|
|
|
*/
|
|
|
|
protected $_cellCache = array();
|
|
|
|
|
|
|
|
|
2012-03-21 23:55:54 +00:00
|
|
|
/**
|
|
|
|
* Initialise this new cell collection
|
|
|
|
*
|
|
|
|
* @param PHPExcel_Worksheet $parent The worksheet for this cell collection
|
|
|
|
*/
|
2010-08-26 19:14:53 +00:00
|
|
|
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()
|
|
|
|
|
|
|
|
|
2013-04-27 13:49:08 +00:00
|
|
|
/**
|
|
|
|
* Return the parent worksheet for this cell collection
|
|
|
|
*
|
|
|
|
* @return PHPExcel_Worksheet
|
|
|
|
*/
|
2013-02-15 15:42:06 +00:00
|
|
|
public function getParent()
|
|
|
|
{
|
|
|
|
return $this->_parent;
|
|
|
|
}
|
|
|
|
|
2010-08-26 19:14:53 +00:00
|
|
|
/**
|
2012-03-11 17:58:38 +00:00
|
|
|
* Is a value set in the current PHPExcel_CachedObjectStorage_ICache for an indexed cell?
|
2010-08-26 19:14:53 +00:00
|
|
|
*
|
2012-03-11 17:58:38 +00:00
|
|
|
* @param string $pCoord Coordinate address of the cell to check
|
|
|
|
* @return boolean
|
2010-08-26 19:14:53 +00:00
|
|
|
*/
|
|
|
|
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()
|
|
|
|
|
|
|
|
|
2013-02-27 17:54:45 +00:00
|
|
|
/**
|
|
|
|
* Move a cell object from one address to another
|
|
|
|
*
|
|
|
|
* @param string $fromAddress Current address of the cell to move
|
|
|
|
* @param string $toAddress Destination address of the cell to move
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function moveCell($fromAddress, $toAddress) {
|
|
|
|
if ($fromAddress === $this->_currentObjectID) {
|
|
|
|
$this->_currentObjectID = $toAddress;
|
|
|
|
}
|
2013-02-27 23:13:49 +00:00
|
|
|
$this->_currentCellIsDirty = true;
|
2013-02-27 17:54:45 +00:00
|
|
|
if (isset($this->_cellCache[$fromAddress])) {
|
|
|
|
$this->_cellCache[$toAddress] = &$this->_cellCache[$fromAddress];
|
|
|
|
unset($this->_cellCache[$fromAddress]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2013-02-27 23:13:49 +00:00
|
|
|
} // function moveCell()
|
2013-02-27 17:54:45 +00:00
|
|
|
|
|
|
|
|
2010-08-26 19:14:53 +00:00
|
|
|
/**
|
2012-03-11 17:58:38 +00:00
|
|
|
* Add or Update a cell in cache
|
2010-08-26 19:14:53 +00:00
|
|
|
*
|
2012-03-11 17:58:38 +00:00
|
|
|
* @param PHPExcel_Cell $cell Cell to update
|
|
|
|
* @return void
|
2013-01-15 21:42:28 +00:00
|
|
|
* @throws PHPExcel_Exception
|
2010-08-26 19:14:53 +00:00
|
|
|
*/
|
|
|
|
public function updateCacheData(PHPExcel_Cell $cell) {
|
2010-11-05 22:13:41 +00:00
|
|
|
return $this->addCacheData($cell->getCoordinate(),$cell);
|
2010-08-26 19:14:53 +00:00
|
|
|
} // function updateCacheData()
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2012-03-11 17:58:38 +00:00
|
|
|
* Delete a cell in cache identified by coordinate address
|
2010-08-26 19:14:53 +00:00
|
|
|
*
|
2012-03-11 17:58:38 +00:00
|
|
|
* @param string $pCoord Coordinate address of the cell to delete
|
2013-01-15 21:42:28 +00:00
|
|
|
* @throws PHPExcel_Exception
|
2010-08-26 19:14:53 +00:00
|
|
|
*/
|
|
|
|
public function deleteCacheData($pCoord) {
|
|
|
|
if ($pCoord === $this->_currentObjectID) {
|
|
|
|
$this->_currentObject->detach();
|
|
|
|
$this->_currentObjectID = $this->_currentObject = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_object($this->_cellCache[$pCoord])) {
|
|
|
|
$this->_cellCache[$pCoord]->detach();
|
|
|
|
unset($this->_cellCache[$pCoord]);
|
|
|
|
}
|
2011-04-25 14:25:53 +00:00
|
|
|
$this->_currentCellIsDirty = false;
|
2010-08-26 19:14:53 +00:00
|
|
|
} // function deleteCacheData()
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2012-03-11 17:58:38 +00:00
|
|
|
* Get a list of all cell addresses currently held in cache
|
2010-08-26 19:14:53 +00:00
|
|
|
*
|
2012-03-11 17:58:38 +00:00
|
|
|
* @return array of string
|
2010-08-26 19:14:53 +00:00
|
|
|
*/
|
|
|
|
public function getCellList() {
|
|
|
|
return array_keys($this->_cellCache);
|
|
|
|
} // function getCellList()
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2012-03-11 17:58:38 +00:00
|
|
|
* Sort the list of all cell addresses currently held in cache by row and column
|
2010-08-26 19:14:53 +00:00
|
|
|
*
|
2012-03-11 17:58:38 +00:00
|
|
|
* @return void
|
2010-08-26 19:14:53 +00:00
|
|
|
*/
|
|
|
|
public function getSortedCellList() {
|
|
|
|
$sortKeys = array();
|
2011-12-03 00:24:44 +00:00
|
|
|
foreach ($this->getCellList() as $coord) {
|
2013-04-26 11:44:47 +00:00
|
|
|
sscanf($coord,'%[A-Z]%d', $column, $row);
|
2010-10-27 10:39:53 +00:00
|
|
|
$sortKeys[sprintf('%09d%3s',$row,$column)] = $coord;
|
2010-08-26 19:14:53 +00:00
|
|
|
}
|
|
|
|
ksort($sortKeys);
|
|
|
|
|
|
|
|
return array_values($sortKeys);
|
|
|
|
} // function sortCellList()
|
|
|
|
|
|
|
|
|
2011-12-16 16:01:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get highest worksheet column and highest row that have cell records
|
|
|
|
*
|
|
|
|
* @return array Highest column name and highest row number
|
|
|
|
*/
|
|
|
|
public function getHighestRowAndColumn()
|
|
|
|
{
|
|
|
|
// Lookup highest column and highest row
|
|
|
|
$col = array('A' => '1A');
|
|
|
|
$row = array(1);
|
|
|
|
foreach ($this->getCellList() as $coord) {
|
2013-04-26 11:44:47 +00:00
|
|
|
sscanf($coord,'%[A-Z]%d', $c, $r);
|
2011-12-16 16:01:21 +00:00
|
|
|
$row[$r] = $r;
|
|
|
|
$col[$c] = strlen($c).$c;
|
|
|
|
}
|
2012-01-16 12:34:22 +00:00
|
|
|
if (!empty($row)) {
|
2011-12-16 16:01:21 +00:00
|
|
|
// Determine highest column and row
|
|
|
|
$highestRow = max($row);
|
|
|
|
$highestColumn = substr(max($col),1);
|
|
|
|
}
|
2012-09-05 13:12:00 +00:00
|
|
|
|
2011-12-16 16:01:21 +00:00
|
|
|
return array( 'row' => $highestRow,
|
|
|
|
'column' => $highestColumn
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-27 13:49:08 +00:00
|
|
|
/**
|
|
|
|
* Return the cell address of the currently active cell object
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2013-02-15 15:42:06 +00:00
|
|
|
public function getCurrentAddress()
|
|
|
|
{
|
|
|
|
return $this->_currentObjectID;
|
|
|
|
}
|
|
|
|
|
2013-04-27 13:49:08 +00:00
|
|
|
/**
|
|
|
|
* Return the column address of the currently active cell object
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2013-02-15 15:42:06 +00:00
|
|
|
public function getCurrentColumn()
|
|
|
|
{
|
2013-04-26 11:44:47 +00:00
|
|
|
sscanf($this->_currentObjectID, '%[A-Z]%d', $column, $row);
|
2013-02-15 15:42:06 +00:00
|
|
|
return $column;
|
|
|
|
}
|
|
|
|
|
2013-04-27 13:49:08 +00:00
|
|
|
/**
|
|
|
|
* Return the row address of the currently active cell object
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2013-02-15 15:42:06 +00:00
|
|
|
public function getCurrentRow()
|
|
|
|
{
|
2013-04-26 11:44:47 +00:00
|
|
|
sscanf($this->_currentObjectID, '%[A-Z]%d', $column, $row);
|
2013-02-15 15:42:06 +00:00
|
|
|
return $row;
|
|
|
|
}
|
|
|
|
|
2011-12-16 16:01:21 +00:00
|
|
|
/**
|
|
|
|
* Get highest worksheet column
|
|
|
|
*
|
2013-11-09 00:40:59 +00:00
|
|
|
* @param string $row Return the highest column for the specified row,
|
|
|
|
* or the highest column of any row if no row number is passed
|
|
|
|
* @return string Highest column name
|
2011-12-16 16:01:21 +00:00
|
|
|
*/
|
2013-11-09 00:40:59 +00:00
|
|
|
public function getHighestColumn($row = null)
|
2011-12-16 16:01:21 +00:00
|
|
|
{
|
2013-11-09 00:40:59 +00:00
|
|
|
if ($row == null) {
|
|
|
|
$colRow = $this->getHighestRowAndColumn();
|
|
|
|
return $colRow['column'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$columnList = array(1);
|
|
|
|
foreach ($this->getCellList() as $coord) {
|
|
|
|
sscanf($coord,'%[A-Z]%d', $c, $r);
|
|
|
|
if ($r != $row) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$columnList[] = PHPExcel_Cell::columnIndexFromString($c);
|
|
|
|
}
|
|
|
|
return PHPExcel_Cell::stringFromColumnIndex(max($columnList) - 1);
|
|
|
|
}
|
2011-12-16 16:01:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get highest worksheet row
|
|
|
|
*
|
2013-11-09 00:40:59 +00:00
|
|
|
* @param string $column Return the highest row for the specified column,
|
|
|
|
* or the highest row of any column if no column letter is passed
|
|
|
|
* @return int Highest row number
|
2011-12-16 16:01:21 +00:00
|
|
|
*/
|
2013-11-09 00:40:59 +00:00
|
|
|
public function getHighestRow($column = null)
|
2011-12-16 16:01:21 +00:00
|
|
|
{
|
2013-11-09 00:40:59 +00:00
|
|
|
if ($column == null) {
|
|
|
|
$colRow = $this->getHighestRowAndColumn();
|
|
|
|
return $colRow['row'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$rowList = array(0);
|
|
|
|
foreach ($this->getCellList() as $coord) {
|
|
|
|
sscanf($coord,'%[A-Z]%d', $c, $r);
|
|
|
|
if ($c != $column) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$rowList[] = $r;
|
|
|
|
}
|
|
|
|
|
|
|
|
return max($rowList);
|
2011-12-16 16:01:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-21 23:55:54 +00:00
|
|
|
/**
|
|
|
|
* Generate a unique ID for cache referencing
|
|
|
|
*
|
|
|
|
* @return string Unique Reference
|
|
|
|
*/
|
2010-08-26 19:14:53 +00:00
|
|
|
protected function _getUniqueID() {
|
|
|
|
if (function_exists('posix_getpid')) {
|
|
|
|
$baseUnique = posix_getpid();
|
|
|
|
} else {
|
|
|
|
$baseUnique = mt_rand();
|
|
|
|
}
|
|
|
|
return uniqid($baseUnique,true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-03-11 17:58:38 +00:00
|
|
|
* Clone the cell collection
|
2010-08-26 19:14:53 +00:00
|
|
|
*
|
2012-03-21 23:55:54 +00:00
|
|
|
* @param PHPExcel_Worksheet $parent The new worksheet
|
2012-03-11 17:58:38 +00:00
|
|
|
* @return void
|
2010-08-26 19:14:53 +00:00
|
|
|
*/
|
|
|
|
public function copyCellCollection(PHPExcel_Worksheet $parent) {
|
2012-11-29 23:57:12 +00:00
|
|
|
$this->_currentCellIsDirty;
|
|
|
|
$this->_storeData();
|
|
|
|
|
2010-08-26 19:14:53 +00:00
|
|
|
$this->_parent = $parent;
|
2012-01-25 23:07:22 +00:00
|
|
|
if (($this->_currentObject !== NULL) && (is_object($this->_currentObject))) {
|
2013-02-21 11:44:33 +00:00
|
|
|
$this->_currentObject->attach($this);
|
2010-08-26 19:14:53 +00:00
|
|
|
}
|
|
|
|
} // function copyCellCollection()
|
|
|
|
|
2011-12-09 12:10:46 +00:00
|
|
|
|
|
|
|
/**
|
2012-03-11 17:58:38 +00:00
|
|
|
* Identify whether the caching method is currently available
|
|
|
|
* Some methods are dependent on the availability of certain extensions being enabled in the PHP build
|
2011-12-09 12:10:46 +00:00
|
|
|
*
|
2012-03-11 17:58:38 +00:00
|
|
|
* @return boolean
|
2011-12-09 12:10:46 +00:00
|
|
|
*/
|
|
|
|
public static function cacheMethodIsAvailable() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-08-26 19:14:53 +00:00
|
|
|
}
|