diff --git a/htdocs/includes/phpexcel/PHPExcel/CachedObjectStorage/APC.php b/htdocs/includes/phpexcel/PHPExcel/CachedObjectStorage/APC.php
index cda4d3bb79e..9dab5581480 100644
--- a/htdocs/includes/phpexcel/PHPExcel/CachedObjectStorage/APC.php
+++ b/htdocs/includes/phpexcel/PHPExcel/CachedObjectStorage/APC.php
@@ -1,280 +1,280 @@
-_currentCellIsDirty) {
- $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 '.$this->_currentObjectID.' in APC');
- }
- $this->_currentCellIsDirty = false;
- }
- $this->_currentObjectID = $this->_currentObject = null;
- } // function _storeData()
-
-
- /**
- * Add or Update a cell in cache identified by coordinate address
- *
- * @access public
- * @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;
- $this->_currentCellIsDirty = true;
-
- return $cell;
- } // function addCacheData()
-
-
- /**
- * Is a value set in the current PHPExcel_CachedObjectStorage_ICache for an indexed cell?
- *
- * @access public
- * @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 '.$pCoord.' no longer exists in APC');
- }
- return true;
- }
- return false;
- } // function isDataSet()
-
-
- /**
- * Get cell at a specific coordinate
- *
- * @access public
- * @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 '.$pCoord.' 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
- *
- * @access public
- * @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()
-
-
- /**
- * Clone the cell collection
- *
- * @access public
- * @param PHPExcel_Worksheet $parent The new worksheet
- * @return void
- */
- public function copyCellCollection(PHPExcel_Worksheet $parent) {
- parent::copyCellCollection($parent);
- // Get a new id for the new file name
- $baseUnique = $this->_getUniqueID();
- $newCachePrefix = substr(md5($baseUnique),0,8).'.';
- $cacheList = $this->getCellList();
- foreach($cacheList as $cellID) {
- if ($cellID != $this->_currentObjectID) {
- $obj = apc_fetch($this->_cachePrefix.$cellID.'.cache');
- if ($obj === false) {
- // Entry no longer exists in APC, so clear it from the cache array
- parent::deleteCacheData($cellID);
- throw new Exception('Cell entry '.$cellID.' no longer exists in APC');
- }
- if (!apc_store($newCachePrefix.$cellID.'.cache',$obj,$this->_cacheTime)) {
- $this->__destruct();
- throw new Exception('Failed to store cell '.$cellID.' in APC');
- }
- }
- }
- $this->_cachePrefix = $newCachePrefix;
- } // function copyCellCollection()
-
-
- /**
- * Clear the cell collection and disconnect from our parent
- *
- * @return void
- */
- public function unsetWorksheetCells() {
- if ($this->_currentObject !== NULL) {
- $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()
-
-
- /**
- * Initialise this new cell collection
- *
- * @param PHPExcel_Worksheet $parent The worksheet for this cell collection
- * @param array of mixed $arguments Additional initialisation arguments
- */
- public function __construct(PHPExcel_Worksheet $parent, $arguments) {
- $cacheTime = (isset($arguments['cacheTime'])) ? $arguments['cacheTime'] : 600;
-
- if ($this->_cachePrefix === NULL) {
- $baseUnique = $this->_getUniqueID();
- $this->_cachePrefix = substr(md5($baseUnique),0,8).'.';
- $this->_cacheTime = $cacheTime;
-
- parent::__construct($parent);
- }
- } // function __construct()
-
-
- /**
- * Destroy this cell collection
- */
- public function __destruct() {
- $cacheList = $this->getCellList();
- foreach($cacheList as $cellID) {
- apc_delete($this->_cachePrefix.$cellID.'.cache');
- }
- } // function __destruct()
-
-
- /**
- * Identify whether the caching method is currently available
- * Some methods are dependent on the availability of certain extensions being enabled in the PHP build
- *
- * @return boolean
- */
- public static function cacheMethodIsAvailable() {
- if (!function_exists('apc_store')) {
- return false;
- }
- if (apc_sma_info() === false) {
- return false;
- }
-
- return true;
- }
-
-}
+_currentCellIsDirty) {
+ $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 '.$this->_currentObjectID.' in APC');
+ }
+ $this->_currentCellIsDirty = false;
+ }
+ $this->_currentObjectID = $this->_currentObject = null;
+ } // function _storeData()
+
+
+ /**
+ * Add or Update a cell in cache identified by coordinate address
+ *
+ * @access public
+ * @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;
+ $this->_currentCellIsDirty = true;
+
+ return $cell;
+ } // function addCacheData()
+
+
+ /**
+ * Is a value set in the current PHPExcel_CachedObjectStorage_ICache for an indexed cell?
+ *
+ * @access public
+ * @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 '.$pCoord.' no longer exists in APC');
+ }
+ return true;
+ }
+ return false;
+ } // function isDataSet()
+
+
+ /**
+ * Get cell at a specific coordinate
+ *
+ * @access public
+ * @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 '.$pCoord.' 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
+ *
+ * @access public
+ * @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()
+
+
+ /**
+ * Clone the cell collection
+ *
+ * @access public
+ * @param PHPExcel_Worksheet $parent The new worksheet
+ * @return void
+ */
+ public function copyCellCollection(PHPExcel_Worksheet $parent) {
+ parent::copyCellCollection($parent);
+ // Get a new id for the new file name
+ $baseUnique = $this->_getUniqueID();
+ $newCachePrefix = substr(md5($baseUnique),0,8).'.';
+ $cacheList = $this->getCellList();
+ foreach($cacheList as $cellID) {
+ if ($cellID != $this->_currentObjectID) {
+ $obj = apc_fetch($this->_cachePrefix.$cellID.'.cache');
+ if ($obj === false) {
+ // Entry no longer exists in APC, so clear it from the cache array
+ parent::deleteCacheData($cellID);
+ throw new Exception('Cell entry '.$cellID.' no longer exists in APC');
+ }
+ if (!apc_store($newCachePrefix.$cellID.'.cache',$obj,$this->_cacheTime)) {
+ $this->__destruct();
+ throw new Exception('Failed to store cell '.$cellID.' in APC');
+ }
+ }
+ }
+ $this->_cachePrefix = $newCachePrefix;
+ } // function copyCellCollection()
+
+
+ /**
+ * Clear the cell collection and disconnect from our parent
+ *
+ * @return void
+ */
+ public function unsetWorksheetCells() {
+ if ($this->_currentObject !== NULL) {
+ $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()
+
+
+ /**
+ * Initialise this new cell collection
+ *
+ * @param PHPExcel_Worksheet $parent The worksheet for this cell collection
+ * @param array of mixed $arguments Additional initialisation arguments
+ */
+ public function __construct(PHPExcel_Worksheet $parent, $arguments) {
+ $cacheTime = (isset($arguments['cacheTime'])) ? $arguments['cacheTime'] : 600;
+
+ if ($this->_cachePrefix === NULL) {
+ $baseUnique = $this->_getUniqueID();
+ $this->_cachePrefix = substr(md5($baseUnique),0,8).'.';
+ $this->_cacheTime = $cacheTime;
+
+ parent::__construct($parent);
+ }
+ } // function __construct()
+
+
+ /**
+ * Destroy this cell collection
+ */
+ public function __destruct() {
+ $cacheList = $this->getCellList();
+ foreach($cacheList as $cellID) {
+ apc_delete($this->_cachePrefix.$cellID.'.cache');
+ }
+ } // function __destruct()
+
+
+ /**
+ * Identify whether the caching method is currently available
+ * Some methods are dependent on the availability of certain extensions being enabled in the PHP build
+ *
+ * @return boolean
+ */
+ public static function cacheMethodIsAvailable() {
+ if (!function_exists('apc_store')) {
+ return false;
+ }
+ if (apc_sma_info() === false) {
+ return false;
+ }
+
+ return true;
+ }
+
+}
diff --git a/htdocs/includes/phpexcel/PHPExcel/CachedObjectStorage/CacheBase.php b/htdocs/includes/phpexcel/PHPExcel/CachedObjectStorage/CacheBase.php
index deaae4ca19c..d2eea08bb97 100644
--- a/htdocs/includes/phpexcel/PHPExcel/CachedObjectStorage/CacheBase.php
+++ b/htdocs/includes/phpexcel/PHPExcel/CachedObjectStorage/CacheBase.php
@@ -1,252 +1,252 @@
-_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 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) {
- return $this->addCacheData($cell->getCoordinate(),$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 (is_object($this->_cellCache[$pCoord])) {
- $this->_cellCache[$pCoord]->detach();
- unset($this->_cellCache[$pCoord]);
- }
- $this->_currentCellIsDirty = false;
- } // 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->getCellList() as $coord) {
- list($column,$row) = sscanf($coord,'%[A-Z]%d');
- $sortKeys[sprintf('%09d%3s',$row,$column)] = $coord;
- }
- ksort($sortKeys);
-
- return array_values($sortKeys);
- } // function sortCellList()
-
-
-
- /**
- * 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) {
- list($c,$r) = sscanf($coord,'%[A-Z]%d');
- $row[$r] = $r;
- $col[$c] = strlen($c).$c;
- }
- if (!empty($row)) {
- // Determine highest column and row
- $highestRow = max($row);
- $highestColumn = substr(max($col),1);
- }
-
- return array( 'row' => $highestRow,
- 'column' => $highestColumn
- );
- }
-
-
- /**
- * Get highest worksheet column
- *
- * @return string Highest column name
- */
- public function getHighestColumn()
- {
- $colRow = $this->getHighestRowAndColumn();
- return $colRow['column'];
- }
-
- /**
- * Get highest worksheet row
- *
- * @return int Highest row number
- */
- public function getHighestRow()
- {
- $colRow = $this->getHighestRowAndColumn();
- return $colRow['row'];
- }
-
-
- /**
- * Generate a unique ID for cache referencing
- *
- * @return string Unique Reference
- */
- protected function _getUniqueID() {
- if (function_exists('posix_getpid')) {
- $baseUnique = posix_getpid();
- } else {
- $baseUnique = mt_rand();
- }
- return uniqid($baseUnique,true);
- }
-
- /**
- * Clone the cell collection
- *
- * @param PHPExcel_Worksheet $parent The new worksheet
- * @return void
- */
- public function copyCellCollection(PHPExcel_Worksheet $parent) {
- $this->_parent = $parent;
- if (($this->_currentObject !== NULL) && (is_object($this->_currentObject))) {
- $this->_currentObject->attach($parent);
- }
- } // function copyCellCollection()
-
-
- /**
- * Identify whether the caching method is currently available
- * Some methods are dependent on the availability of certain extensions being enabled in the PHP build
- *
- * @return boolean
- */
- public static function cacheMethodIsAvailable() {
- return true;
- }
-
-}
+_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 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) {
+ return $this->addCacheData($cell->getCoordinate(),$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 (is_object($this->_cellCache[$pCoord])) {
+ $this->_cellCache[$pCoord]->detach();
+ unset($this->_cellCache[$pCoord]);
+ }
+ $this->_currentCellIsDirty = false;
+ } // 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->getCellList() as $coord) {
+ list($column,$row) = sscanf($coord,'%[A-Z]%d');
+ $sortKeys[sprintf('%09d%3s',$row,$column)] = $coord;
+ }
+ ksort($sortKeys);
+
+ return array_values($sortKeys);
+ } // function sortCellList()
+
+
+
+ /**
+ * 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) {
+ list($c,$r) = sscanf($coord,'%[A-Z]%d');
+ $row[$r] = $r;
+ $col[$c] = strlen($c).$c;
+ }
+ if (!empty($row)) {
+ // Determine highest column and row
+ $highestRow = max($row);
+ $highestColumn = substr(max($col),1);
+ }
+
+ return array( 'row' => $highestRow,
+ 'column' => $highestColumn
+ );
+ }
+
+
+ /**
+ * Get highest worksheet column
+ *
+ * @return string Highest column name
+ */
+ public function getHighestColumn()
+ {
+ $colRow = $this->getHighestRowAndColumn();
+ return $colRow['column'];
+ }
+
+ /**
+ * Get highest worksheet row
+ *
+ * @return int Highest row number
+ */
+ public function getHighestRow()
+ {
+ $colRow = $this->getHighestRowAndColumn();
+ return $colRow['row'];
+ }
+
+
+ /**
+ * Generate a unique ID for cache referencing
+ *
+ * @return string Unique Reference
+ */
+ protected function _getUniqueID() {
+ if (function_exists('posix_getpid')) {
+ $baseUnique = posix_getpid();
+ } else {
+ $baseUnique = mt_rand();
+ }
+ return uniqid($baseUnique,true);
+ }
+
+ /**
+ * Clone the cell collection
+ *
+ * @param PHPExcel_Worksheet $parent The new worksheet
+ * @return void
+ */
+ public function copyCellCollection(PHPExcel_Worksheet $parent) {
+ $this->_parent = $parent;
+ if (($this->_currentObject !== NULL) && (is_object($this->_currentObject))) {
+ $this->_currentObject->attach($parent);
+ }
+ } // function copyCellCollection()
+
+
+ /**
+ * Identify whether the caching method is currently available
+ * Some methods are dependent on the availability of certain extensions being enabled in the PHP build
+ *
+ * @return boolean
+ */
+ public static function cacheMethodIsAvailable() {
+ return true;
+ }
+
+}
diff --git a/htdocs/includes/phpexcel/PHPExcel/CachedObjectStorage/DiscISAM.php b/htdocs/includes/phpexcel/PHPExcel/CachedObjectStorage/DiscISAM.php
index d93ab05e569..805dc063ace 100644
--- a/htdocs/includes/phpexcel/PHPExcel/CachedObjectStorage/DiscISAM.php
+++ b/htdocs/includes/phpexcel/PHPExcel/CachedObjectStorage/DiscISAM.php
@@ -1,205 +1,205 @@
-_currentCellIsDirty) {
- $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->_currentCellIsDirty = false;
- }
- $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;
- $this->_currentCellIsDirty = true;
-
- 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()
-
-
- /**
- * Clone the cell collection
- *
- * @param PHPExcel_Worksheet $parent The new worksheet
- * @return void
- */
- public function copyCellCollection(PHPExcel_Worksheet $parent) {
- parent::copyCellCollection($parent);
- // Get a new id for the new file name
- $baseUnique = $this->_getUniqueID();
- $newFileName = $this->_cacheDirectory.'/PHPExcel.'.$baseUnique.'.cache';
- // Copy the existing cell cache file
- copy ($this->_fileName,$newFileName);
- $this->_fileName = $newFileName;
- // Open the copied cell cache file
- $this->_fileHandle = fopen($this->_fileName,'a+');
- } // function copyCellCollection()
-
-
- /**
- * Clear the cell collection and disconnect from our parent
- *
- * @return void
- */
- 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()
-
-
- /**
- * Initialise this new cell collection
- *
- * @param PHPExcel_Worksheet $parent The worksheet for this cell collection
- * @param array of mixed $arguments Additional initialisation arguments
- */
- public function __construct(PHPExcel_Worksheet $parent, $arguments) {
- $this->_cacheDirectory = ((isset($arguments['dir'])) && ($arguments['dir'] !== NULL))
- ? $arguments['dir']
- : PHPExcel_Shared_File::sys_get_temp_dir();
-
- parent::__construct($parent);
- if (is_null($this->_fileHandle)) {
- $baseUnique = $this->_getUniqueID();
- $this->_fileName = $this->_cacheDirectory.'/PHPExcel.'.$baseUnique.'.cache';
- $this->_fileHandle = fopen($this->_fileName,'a+');
- }
- } // function __construct()
-
-
- /**
- * Destroy this cell collection
- */
- public function __destruct() {
- if (!is_null($this->_fileHandle)) {
- fclose($this->_fileHandle);
- unlink($this->_fileName);
- }
- $this->_fileHandle = null;
- } // function __destruct()
-
-}
+_currentCellIsDirty) {
+ $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->_currentCellIsDirty = false;
+ }
+ $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;
+ $this->_currentCellIsDirty = true;
+
+ 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()
+
+
+ /**
+ * Clone the cell collection
+ *
+ * @param PHPExcel_Worksheet $parent The new worksheet
+ * @return void
+ */
+ public function copyCellCollection(PHPExcel_Worksheet $parent) {
+ parent::copyCellCollection($parent);
+ // Get a new id for the new file name
+ $baseUnique = $this->_getUniqueID();
+ $newFileName = $this->_cacheDirectory.'/PHPExcel.'.$baseUnique.'.cache';
+ // Copy the existing cell cache file
+ copy ($this->_fileName,$newFileName);
+ $this->_fileName = $newFileName;
+ // Open the copied cell cache file
+ $this->_fileHandle = fopen($this->_fileName,'a+');
+ } // function copyCellCollection()
+
+
+ /**
+ * Clear the cell collection and disconnect from our parent
+ *
+ * @return void
+ */
+ 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()
+
+
+ /**
+ * Initialise this new cell collection
+ *
+ * @param PHPExcel_Worksheet $parent The worksheet for this cell collection
+ * @param array of mixed $arguments Additional initialisation arguments
+ */
+ public function __construct(PHPExcel_Worksheet $parent, $arguments) {
+ $this->_cacheDirectory = ((isset($arguments['dir'])) && ($arguments['dir'] !== NULL))
+ ? $arguments['dir']
+ : PHPExcel_Shared_File::sys_get_temp_dir();
+
+ parent::__construct($parent);
+ if (is_null($this->_fileHandle)) {
+ $baseUnique = $this->_getUniqueID();
+ $this->_fileName = $this->_cacheDirectory.'/PHPExcel.'.$baseUnique.'.cache';
+ $this->_fileHandle = fopen($this->_fileName,'a+');
+ }
+ } // function __construct()
+
+
+ /**
+ * Destroy this cell collection
+ */
+ public function __destruct() {
+ if (!is_null($this->_fileHandle)) {
+ fclose($this->_fileHandle);
+ unlink($this->_fileName);
+ }
+ $this->_fileHandle = null;
+ } // function __destruct()
+
+}
diff --git a/htdocs/includes/phpexcel/PHPExcel/CachedObjectStorage/Igbinary.php b/htdocs/includes/phpexcel/PHPExcel/CachedObjectStorage/Igbinary.php
index 5d5daf4bf57..fc2f1129917 100644
--- a/htdocs/includes/phpexcel/PHPExcel/CachedObjectStorage/Igbinary.php
+++ b/htdocs/includes/phpexcel/PHPExcel/CachedObjectStorage/Igbinary.php
@@ -1,138 +1,138 @@
-_currentCellIsDirty) {
- $this->_currentObject->detach();
-
- $this->_cellCache[$this->_currentObjectID] = igbinary_serialize($this->_currentObject);
- $this->_currentCellIsDirty = false;
- }
- $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;
- $this->_currentCellIsDirty = true;
-
- 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 = igbinary_unserialize($this->_cellCache[$pCoord]);
- // Re-attach the parent worksheet
- $this->_currentObject->attach($this->_parent);
-
- // Return requested entry
- return $this->_currentObject;
- } // function getCacheData()
-
-
- /**
- * Clear the cell collection and disconnect from our parent
- *
- * @return void
- */
- 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()
-
-
- /**
- * Identify whether the caching method is currently available
- * Some methods are dependent on the availability of certain extensions being enabled in the PHP build
- *
- * @return boolean
- */
- public static function cacheMethodIsAvailable() {
- if (!function_exists('igbinary_serialize')) {
- return false;
- }
-
- return true;
- }
-
-}
+_currentCellIsDirty) {
+ $this->_currentObject->detach();
+
+ $this->_cellCache[$this->_currentObjectID] = igbinary_serialize($this->_currentObject);
+ $this->_currentCellIsDirty = false;
+ }
+ $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;
+ $this->_currentCellIsDirty = true;
+
+ 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 = igbinary_unserialize($this->_cellCache[$pCoord]);
+ // Re-attach the parent worksheet
+ $this->_currentObject->attach($this->_parent);
+
+ // Return requested entry
+ return $this->_currentObject;
+ } // function getCacheData()
+
+
+ /**
+ * Clear the cell collection and disconnect from our parent
+ *
+ * @return void
+ */
+ 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()
+
+
+ /**
+ * Identify whether the caching method is currently available
+ * Some methods are dependent on the availability of certain extensions being enabled in the PHP build
+ *
+ * @return boolean
+ */
+ public static function cacheMethodIsAvailable() {
+ if (!function_exists('igbinary_serialize')) {
+ return false;
+ }
+
+ return true;
+ }
+
+}
diff --git a/htdocs/includes/phpexcel/PHPExcel/CachedObjectStorage/Memcache.php b/htdocs/includes/phpexcel/PHPExcel/CachedObjectStorage/Memcache.php
index 3e5fcb4ada7..23d6957281f 100644
--- a/htdocs/includes/phpexcel/PHPExcel/CachedObjectStorage/Memcache.php
+++ b/htdocs/includes/phpexcel/PHPExcel/CachedObjectStorage/Memcache.php
@@ -1,298 +1,298 @@
-_currentCellIsDirty) {
- $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 '.$this->_currentObjectID.' in MemCache');
- }
- }
- $this->_currentCellIsDirty = false;
- }
- $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;
- $this->_currentCellIsDirty = true;
-
- 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 Memcache
- $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 '.$pCoord.' 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 '.$pCoord.' 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()
-
-
- /**
- * Clone the cell collection
- *
- * @param PHPExcel_Worksheet $parent The new worksheet
- * @return void
- */
- public function copyCellCollection(PHPExcel_Worksheet $parent) {
- parent::copyCellCollection($parent);
- // Get a new id for the new file name
- $baseUnique = $this->_getUniqueID();
- $newCachePrefix = substr(md5($baseUnique),0,8).'.';
- $cacheList = $this->getCellList();
- foreach($cacheList as $cellID) {
- if ($cellID != $this->_currentObjectID) {
- $obj = $this->_memcache->get($this->_cachePrefix.$cellID.'.cache');
- if ($obj === false) {
- // Entry no longer exists in Memcache, so clear it from the cache array
- parent::deleteCacheData($cellID);
- throw new Exception('Cell entry '.$cellID.' no longer exists in MemCache');
- }
- if (!$this->_memcache->add($newCachePrefix.$cellID.'.cache',$obj,NULL,$this->_cacheTime)) {
- $this->__destruct();
- throw new Exception('Failed to store cell '.$cellID.' in MemCache');
- }
- }
- }
- $this->_cachePrefix = $newCachePrefix;
- } // function copyCellCollection()
-
-
- /**
- * Clear the cell collection and disconnect from our parent
- *
- * @return void
- */
- 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()
-
-
- /**
- * Initialise this new cell collection
- *
- * @param PHPExcel_Worksheet $parent The worksheet for this cell collection
- * @param array of mixed $arguments Additional initialisation arguments
- */
- 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)) {
- $baseUnique = $this->_getUniqueID();
- $this->_cachePrefix = substr(md5($baseUnique),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()
-
-
- /**
- * Memcache error handler
- *
- * @param string $host Memcache server
- * @param integer $port Memcache port
- * @throws Exception
- */
- public function failureCallback($host, $port) {
- throw new Exception('memcache '.$host.':'.$port.' failed');
- }
-
-
- /**
- * Destroy this cell collection
- */
- public function __destruct() {
- $cacheList = $this->getCellList();
- foreach($cacheList as $cellID) {
- $this->_memcache->delete($this->_cachePrefix.$cellID.'.cache');
- }
- } // function __destruct()
-
- /**
- * Identify whether the caching method is currently available
- * Some methods are dependent on the availability of certain extensions being enabled in the PHP build
- *
- * @return boolean
- */
- public static function cacheMethodIsAvailable() {
- if (!function_exists('memcache_add')) {
- return false;
- }
-
- return true;
- }
-
-}
+_currentCellIsDirty) {
+ $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 '.$this->_currentObjectID.' in MemCache');
+ }
+ }
+ $this->_currentCellIsDirty = false;
+ }
+ $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;
+ $this->_currentCellIsDirty = true;
+
+ 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 Memcache
+ $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 '.$pCoord.' 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 '.$pCoord.' 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()
+
+
+ /**
+ * Clone the cell collection
+ *
+ * @param PHPExcel_Worksheet $parent The new worksheet
+ * @return void
+ */
+ public function copyCellCollection(PHPExcel_Worksheet $parent) {
+ parent::copyCellCollection($parent);
+ // Get a new id for the new file name
+ $baseUnique = $this->_getUniqueID();
+ $newCachePrefix = substr(md5($baseUnique),0,8).'.';
+ $cacheList = $this->getCellList();
+ foreach($cacheList as $cellID) {
+ if ($cellID != $this->_currentObjectID) {
+ $obj = $this->_memcache->get($this->_cachePrefix.$cellID.'.cache');
+ if ($obj === false) {
+ // Entry no longer exists in Memcache, so clear it from the cache array
+ parent::deleteCacheData($cellID);
+ throw new Exception('Cell entry '.$cellID.' no longer exists in MemCache');
+ }
+ if (!$this->_memcache->add($newCachePrefix.$cellID.'.cache',$obj,NULL,$this->_cacheTime)) {
+ $this->__destruct();
+ throw new Exception('Failed to store cell '.$cellID.' in MemCache');
+ }
+ }
+ }
+ $this->_cachePrefix = $newCachePrefix;
+ } // function copyCellCollection()
+
+
+ /**
+ * Clear the cell collection and disconnect from our parent
+ *
+ * @return void
+ */
+ 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()
+
+
+ /**
+ * Initialise this new cell collection
+ *
+ * @param PHPExcel_Worksheet $parent The worksheet for this cell collection
+ * @param array of mixed $arguments Additional initialisation arguments
+ */
+ 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)) {
+ $baseUnique = $this->_getUniqueID();
+ $this->_cachePrefix = substr(md5($baseUnique),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()
+
+
+ /**
+ * Memcache error handler
+ *
+ * @param string $host Memcache server
+ * @param integer $port Memcache port
+ * @throws Exception
+ */
+ public function failureCallback($host, $port) {
+ throw new Exception('memcache '.$host.':'.$port.' failed');
+ }
+
+
+ /**
+ * Destroy this cell collection
+ */
+ public function __destruct() {
+ $cacheList = $this->getCellList();
+ foreach($cacheList as $cellID) {
+ $this->_memcache->delete($this->_cachePrefix.$cellID.'.cache');
+ }
+ } // function __destruct()
+
+ /**
+ * Identify whether the caching method is currently available
+ * Some methods are dependent on the availability of certain extensions being enabled in the PHP build
+ *
+ * @return boolean
+ */
+ public static function cacheMethodIsAvailable() {
+ if (!function_exists('memcache_add')) {
+ return false;
+ }
+
+ return true;
+ }
+
+}
diff --git a/htdocs/includes/phpexcel/PHPExcel/CachedObjectStorage/Memory.php b/htdocs/includes/phpexcel/PHPExcel/CachedObjectStorage/Memory.php
index f368e397735..36f42fb6ccf 100644
--- a/htdocs/includes/phpexcel/PHPExcel/CachedObjectStorage/Memory.php
+++ b/htdocs/includes/phpexcel/PHPExcel/CachedObjectStorage/Memory.php
@@ -1,109 +1,109 @@
-_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()
-
-
- /**
- * Clone the cell collection
- *
- * @param PHPExcel_Worksheet $parent The new worksheet
- * @return void
- */
- public function copyCellCollection(PHPExcel_Worksheet $parent) {
- parent::copyCellCollection($parent);
-
- $newCollection = array();
- foreach($this->_cellCache as $k => &$cell) {
- $newCollection[$k] = clone $cell;
- $newCollection[$k]->attach($parent);
- }
-
- $this->_cellCache = $newCollection;
- }
-
-
- /**
- * Clear the cell collection and disconnect from our parent
- *
- * @return void
- */
- 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()
-
-}
+_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()
+
+
+ /**
+ * Clone the cell collection
+ *
+ * @param PHPExcel_Worksheet $parent The new worksheet
+ * @return void
+ */
+ public function copyCellCollection(PHPExcel_Worksheet $parent) {
+ parent::copyCellCollection($parent);
+
+ $newCollection = array();
+ foreach($this->_cellCache as $k => &$cell) {
+ $newCollection[$k] = clone $cell;
+ $newCollection[$k]->attach($parent);
+ }
+
+ $this->_cellCache = $newCollection;
+ }
+
+
+ /**
+ * Clear the cell collection and disconnect from our parent
+ *
+ * @return void
+ */
+ 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()
+
+}
diff --git a/htdocs/includes/phpexcel/PHPExcel/CachedObjectStorage/MemoryGZip.php b/htdocs/includes/phpexcel/PHPExcel/CachedObjectStorage/MemoryGZip.php
index 6941231261f..ee8e95eb2b5 100644
--- a/htdocs/includes/phpexcel/PHPExcel/CachedObjectStorage/MemoryGZip.php
+++ b/htdocs/includes/phpexcel/PHPExcel/CachedObjectStorage/MemoryGZip.php
@@ -1,123 +1,123 @@
-_currentCellIsDirty) {
- $this->_currentObject->detach();
-
- $this->_cellCache[$this->_currentObjectID] = gzdeflate(serialize($this->_currentObject));
- $this->_currentCellIsDirty = false;
- }
- $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;
- $this->_currentCellIsDirty = true;
-
- 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()
-
-
- /**
- * Clear the cell collection and disconnect from our parent
- *
- * @return void
- */
- 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()
-
-}
+_currentCellIsDirty) {
+ $this->_currentObject->detach();
+
+ $this->_cellCache[$this->_currentObjectID] = gzdeflate(serialize($this->_currentObject));
+ $this->_currentCellIsDirty = false;
+ }
+ $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;
+ $this->_currentCellIsDirty = true;
+
+ 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()
+
+
+ /**
+ * Clear the cell collection and disconnect from our parent
+ *
+ * @return void
+ */
+ 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()
+
+}
diff --git a/htdocs/includes/phpexcel/PHPExcel/CachedObjectStorage/MemorySerialized.php b/htdocs/includes/phpexcel/PHPExcel/CachedObjectStorage/MemorySerialized.php
index 09f3b665818..d6b09b530e8 100644
--- a/htdocs/includes/phpexcel/PHPExcel/CachedObjectStorage/MemorySerialized.php
+++ b/htdocs/includes/phpexcel/PHPExcel/CachedObjectStorage/MemorySerialized.php
@@ -1,123 +1,123 @@
-_currentCellIsDirty) {
- $this->_currentObject->detach();
-
- $this->_cellCache[$this->_currentObjectID] = serialize($this->_currentObject);
- $this->_currentCellIsDirty = false;
- }
- $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;
- $this->_currentCellIsDirty = true;
-
- 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()
-
-
- /**
- * Clear the cell collection and disconnect from our parent
- *
- * @return void
- */
- 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()
-
-}
+_currentCellIsDirty) {
+ $this->_currentObject->detach();
+
+ $this->_cellCache[$this->_currentObjectID] = serialize($this->_currentObject);
+ $this->_currentCellIsDirty = false;
+ }
+ $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;
+ $this->_currentCellIsDirty = true;
+
+ 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()
+
+
+ /**
+ * Clear the cell collection and disconnect from our parent
+ *
+ * @return void
+ */
+ 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()
+
+}
diff --git a/htdocs/includes/phpexcel/PHPExcel/CachedObjectStorage/PHPTemp.php b/htdocs/includes/phpexcel/PHPExcel/CachedObjectStorage/PHPTemp.php
index c3f2bd95bea..8dbbe92e8c2 100644
--- a/htdocs/includes/phpexcel/PHPExcel/CachedObjectStorage/PHPTemp.php
+++ b/htdocs/includes/phpexcel/PHPExcel/CachedObjectStorage/PHPTemp.php
@@ -1,192 +1,192 @@
-_currentCellIsDirty) {
- $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->_currentCellIsDirty = false;
- }
- $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;
- $this->_currentCellIsDirty = true;
-
- 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()
-
-
- /**
- * Clone the cell collection
- *
- * @param PHPExcel_Worksheet $parent The new worksheet
- * @return void
- */
- public function copyCellCollection(PHPExcel_Worksheet $parent) {
- parent::copyCellCollection($parent);
- // Open a new stream for the cell cache data
- $newFileHandle = fopen('php://temp/maxmemory:'.$this->_memoryCacheSize,'a+');
- // Copy the existing cell cache data to the new stream
- fseek($this->_fileHandle,0);
- while (!feof($this->_fileHandle)) {
- fwrite($newFileHandle,fread($this->_fileHandle, 1024));
- }
- $this->_fileHandle = $newFileHandle;
- } // function copyCellCollection()
-
-
- /**
- * Clear the cell collection and disconnect from our parent
- *
- * @return void
- */
- 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()
-
-
- /**
- * Initialise this new cell collection
- *
- * @param PHPExcel_Worksheet $parent The worksheet for this cell collection
- * @param array of mixed $arguments Additional initialisation arguments
- */
- public function __construct(PHPExcel_Worksheet $parent, $arguments) {
- $this->_memoryCacheSize = (isset($arguments['memoryCacheSize'])) ? $arguments['memoryCacheSize'] : '1MB';
-
- parent::__construct($parent);
- if (is_null($this->_fileHandle)) {
- $this->_fileHandle = fopen('php://temp/maxmemory:'.$this->_memoryCacheSize,'a+');
- }
- } // function __construct()
-
-
- /**
- * Destroy this cell collection
- */
- public function __destruct() {
- if (!is_null($this->_fileHandle)) {
- fclose($this->_fileHandle);
- }
- $this->_fileHandle = null;
- } // function __destruct()
-
-}
+_currentCellIsDirty) {
+ $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->_currentCellIsDirty = false;
+ }
+ $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;
+ $this->_currentCellIsDirty = true;
+
+ 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()
+
+
+ /**
+ * Clone the cell collection
+ *
+ * @param PHPExcel_Worksheet $parent The new worksheet
+ * @return void
+ */
+ public function copyCellCollection(PHPExcel_Worksheet $parent) {
+ parent::copyCellCollection($parent);
+ // Open a new stream for the cell cache data
+ $newFileHandle = fopen('php://temp/maxmemory:'.$this->_memoryCacheSize,'a+');
+ // Copy the existing cell cache data to the new stream
+ fseek($this->_fileHandle,0);
+ while (!feof($this->_fileHandle)) {
+ fwrite($newFileHandle,fread($this->_fileHandle, 1024));
+ }
+ $this->_fileHandle = $newFileHandle;
+ } // function copyCellCollection()
+
+
+ /**
+ * Clear the cell collection and disconnect from our parent
+ *
+ * @return void
+ */
+ 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()
+
+
+ /**
+ * Initialise this new cell collection
+ *
+ * @param PHPExcel_Worksheet $parent The worksheet for this cell collection
+ * @param array of mixed $arguments Additional initialisation arguments
+ */
+ public function __construct(PHPExcel_Worksheet $parent, $arguments) {
+ $this->_memoryCacheSize = (isset($arguments['memoryCacheSize'])) ? $arguments['memoryCacheSize'] : '1MB';
+
+ parent::__construct($parent);
+ if (is_null($this->_fileHandle)) {
+ $this->_fileHandle = fopen('php://temp/maxmemory:'.$this->_memoryCacheSize,'a+');
+ }
+ } // function __construct()
+
+
+ /**
+ * Destroy this cell collection
+ */
+ public function __destruct() {
+ if (!is_null($this->_fileHandle)) {
+ fclose($this->_fileHandle);
+ }
+ $this->_fileHandle = null;
+ } // function __destruct()
+
+}
diff --git a/htdocs/includes/phpexcel/PHPExcel/CachedObjectStorage/SQLite.php b/htdocs/includes/phpexcel/PHPExcel/CachedObjectStorage/SQLite.php
index 515573dc9df..e4bf469e0fc 100644
--- a/htdocs/includes/phpexcel/PHPExcel/CachedObjectStorage/SQLite.php
+++ b/htdocs/includes/phpexcel/PHPExcel/CachedObjectStorage/SQLite.php
@@ -1,270 +1,270 @@
-_currentCellIsDirty) {
- $this->_currentObject->detach();
-
- if (!$this->_DBHandle->queryExec("INSERT OR REPLACE INTO kvp_".$this->_TableName." VALUES('".$this->_currentObjectID."','".sqlite_escape_string(serialize($this->_currentObject))."')"))
- throw new Exception(sqlite_error_string($this->_DBHandle->lastError()));
- $this->_currentCellIsDirty = false;
- }
- $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;
- $this->_currentCellIsDirty = true;
-
- 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();
-
- $query = "SELECT value FROM kvp_".$this->_TableName." WHERE id='".$pCoord."'";
- $cellResultSet = $this->_DBHandle->query($query,SQLITE_ASSOC);
- if ($cellResultSet === false) {
- throw new Exception(sqlite_error_string($this->_DBHandle->lastError()));
- } elseif ($cellResultSet->numRows() == 0) {
- // Return null if requested entry doesn't exist in cache
- return null;
- }
-
- // Set current entry to the requested entry
- $this->_currentObjectID = $pCoord;
-
- $cellResult = $cellResultSet->fetchSingle();
- $this->_currentObject = unserialize($cellResult);
- // Re-attach the parent worksheet
- $this->_currentObject->attach($this->_parent);
-
- // Return requested entry
- return $this->_currentObject;
- } // function getCacheData()
-
-
- /**
- * Is a value set for an indexed cell?
- *
- * @param string $pCoord Coordinate address of the cell to check
- * @return boolean
- */
- public function isDataSet($pCoord) {
- if ($pCoord === $this->_currentObjectID) {
- return true;
- }
-
- // Check if the requested entry exists in the cache
- $query = "SELECT id FROM kvp_".$this->_TableName." WHERE id='".$pCoord."'";
- $cellResultSet = $this->_DBHandle->query($query,SQLITE_ASSOC);
- if ($cellResultSet === false) {
- throw new Exception(sqlite_error_string($this->_DBHandle->lastError()));
- } elseif ($cellResultSet->numRows() == 0) {
- // Return null if requested entry doesn't exist in cache
- return false;
- }
- return true;
- } // function isDataSet()
-
-
- /**
- * 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;
- }
-
- // Check if the requested entry exists in the cache
- $query = "DELETE FROM kvp_".$this->_TableName." WHERE id='".$pCoord."'";
- if (!$this->_DBHandle->queryExec($query))
- throw new Exception(sqlite_error_string($this->_DBHandle->lastError()));
-
- $this->_currentCellIsDirty = false;
- } // function deleteCacheData()
-
-
- /**
- * Get a list of all cell addresses currently held in cache
- *
- * @return array of string
- */
- public function getCellList() {
- $query = "SELECT id FROM kvp_".$this->_TableName;
- $cellIdsResult = $this->_DBHandle->unbufferedQuery($query,SQLITE_ASSOC);
- if ($cellIdsResult === false)
- throw new Exception(sqlite_error_string($this->_DBHandle->lastError()));
-
- $cellKeys = array();
- foreach($cellIdsResult as $row) {
- $cellKeys[] = $row['id'];
- }
-
- return $cellKeys;
- } // function getCellList()
-
-
- /**
- * Clone the cell collection
- *
- * @param PHPExcel_Worksheet $parent The new worksheet
- * @return void
- */
- public function copyCellCollection(PHPExcel_Worksheet $parent) {
- // Get a new id for the new table name
- $tableName = str_replace('.','_',$this->_getUniqueID());
- if (!$this->_DBHandle->queryExec('CREATE TABLE kvp_'.$tableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB)
- AS SELECT * FROM kvp_'.$this->_TableName))
- throw new Exception(sqlite_error_string($this->_DBHandle->lastError()));
-
- // Copy the existing cell cache file
- $this->_TableName = $tableName;
- } // function copyCellCollection()
-
-
- /**
- * Clear the cell collection and disconnect from our parent
- *
- * @return void
- */
- public function unsetWorksheetCells() {
- if(!is_null($this->_currentObject)) {
- $this->_currentObject->detach();
- $this->_currentObject = $this->_currentObjectID = null;
- }
- // 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()
-
-
- /**
- * Initialise this new cell collection
- *
- * @param PHPExcel_Worksheet $parent The worksheet for this cell collection
- */
- public function __construct(PHPExcel_Worksheet $parent) {
- parent::__construct($parent);
- if (is_null($this->_DBHandle)) {
- $this->_TableName = str_replace('.','_',$this->_getUniqueID());
- $_DBName = ':memory:';
-
- $this->_DBHandle = new SQLiteDatabase($_DBName);
- if ($this->_DBHandle === false)
- throw new Exception(sqlite_error_string($this->_DBHandle->lastError()));
- if (!$this->_DBHandle->queryExec('CREATE TABLE kvp_'.$this->_TableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB)'))
- throw new Exception(sqlite_error_string($this->_DBHandle->lastError()));
- }
- } // function __construct()
-
-
- /**
- * Destroy this cell collection
- */
- public function __destruct() {
- $this->_DBHandle = null;
- } // function __destruct()
-
-
- /**
- * Identify whether the caching method is currently available
- * Some methods are dependent on the availability of certain extensions being enabled in the PHP build
- *
- * @return boolean
- */
- public static function cacheMethodIsAvailable() {
- if (!function_exists('sqlite_open')) {
- return false;
- }
-
- return true;
- }
-
-}
+_currentCellIsDirty) {
+ $this->_currentObject->detach();
+
+ if (!$this->_DBHandle->queryExec("INSERT OR REPLACE INTO kvp_".$this->_TableName." VALUES('".$this->_currentObjectID."','".sqlite_escape_string(serialize($this->_currentObject))."')"))
+ throw new Exception(sqlite_error_string($this->_DBHandle->lastError()));
+ $this->_currentCellIsDirty = false;
+ }
+ $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;
+ $this->_currentCellIsDirty = true;
+
+ 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();
+
+ $query = "SELECT value FROM kvp_".$this->_TableName." WHERE id='".$pCoord."'";
+ $cellResultSet = $this->_DBHandle->query($query,SQLITE_ASSOC);
+ if ($cellResultSet === false) {
+ throw new Exception(sqlite_error_string($this->_DBHandle->lastError()));
+ } elseif ($cellResultSet->numRows() == 0) {
+ // Return null if requested entry doesn't exist in cache
+ return null;
+ }
+
+ // Set current entry to the requested entry
+ $this->_currentObjectID = $pCoord;
+
+ $cellResult = $cellResultSet->fetchSingle();
+ $this->_currentObject = unserialize($cellResult);
+ // Re-attach the parent worksheet
+ $this->_currentObject->attach($this->_parent);
+
+ // Return requested entry
+ return $this->_currentObject;
+ } // function getCacheData()
+
+
+ /**
+ * Is a value set for an indexed cell?
+ *
+ * @param string $pCoord Coordinate address of the cell to check
+ * @return boolean
+ */
+ public function isDataSet($pCoord) {
+ if ($pCoord === $this->_currentObjectID) {
+ return true;
+ }
+
+ // Check if the requested entry exists in the cache
+ $query = "SELECT id FROM kvp_".$this->_TableName." WHERE id='".$pCoord."'";
+ $cellResultSet = $this->_DBHandle->query($query,SQLITE_ASSOC);
+ if ($cellResultSet === false) {
+ throw new Exception(sqlite_error_string($this->_DBHandle->lastError()));
+ } elseif ($cellResultSet->numRows() == 0) {
+ // Return null if requested entry doesn't exist in cache
+ return false;
+ }
+ return true;
+ } // function isDataSet()
+
+
+ /**
+ * 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;
+ }
+
+ // Check if the requested entry exists in the cache
+ $query = "DELETE FROM kvp_".$this->_TableName." WHERE id='".$pCoord."'";
+ if (!$this->_DBHandle->queryExec($query))
+ throw new Exception(sqlite_error_string($this->_DBHandle->lastError()));
+
+ $this->_currentCellIsDirty = false;
+ } // function deleteCacheData()
+
+
+ /**
+ * Get a list of all cell addresses currently held in cache
+ *
+ * @return array of string
+ */
+ public function getCellList() {
+ $query = "SELECT id FROM kvp_".$this->_TableName;
+ $cellIdsResult = $this->_DBHandle->unbufferedQuery($query,SQLITE_ASSOC);
+ if ($cellIdsResult === false)
+ throw new Exception(sqlite_error_string($this->_DBHandle->lastError()));
+
+ $cellKeys = array();
+ foreach($cellIdsResult as $row) {
+ $cellKeys[] = $row['id'];
+ }
+
+ return $cellKeys;
+ } // function getCellList()
+
+
+ /**
+ * Clone the cell collection
+ *
+ * @param PHPExcel_Worksheet $parent The new worksheet
+ * @return void
+ */
+ public function copyCellCollection(PHPExcel_Worksheet $parent) {
+ // Get a new id for the new table name
+ $tableName = str_replace('.','_',$this->_getUniqueID());
+ if (!$this->_DBHandle->queryExec('CREATE TABLE kvp_'.$tableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB)
+ AS SELECT * FROM kvp_'.$this->_TableName))
+ throw new Exception(sqlite_error_string($this->_DBHandle->lastError()));
+
+ // Copy the existing cell cache file
+ $this->_TableName = $tableName;
+ } // function copyCellCollection()
+
+
+ /**
+ * Clear the cell collection and disconnect from our parent
+ *
+ * @return void
+ */
+ public function unsetWorksheetCells() {
+ if(!is_null($this->_currentObject)) {
+ $this->_currentObject->detach();
+ $this->_currentObject = $this->_currentObjectID = null;
+ }
+ // 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()
+
+
+ /**
+ * Initialise this new cell collection
+ *
+ * @param PHPExcel_Worksheet $parent The worksheet for this cell collection
+ */
+ public function __construct(PHPExcel_Worksheet $parent) {
+ parent::__construct($parent);
+ if (is_null($this->_DBHandle)) {
+ $this->_TableName = str_replace('.','_',$this->_getUniqueID());
+ $_DBName = ':memory:';
+
+ $this->_DBHandle = new SQLiteDatabase($_DBName);
+ if ($this->_DBHandle === false)
+ throw new Exception(sqlite_error_string($this->_DBHandle->lastError()));
+ if (!$this->_DBHandle->queryExec('CREATE TABLE kvp_'.$this->_TableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB)'))
+ throw new Exception(sqlite_error_string($this->_DBHandle->lastError()));
+ }
+ } // function __construct()
+
+
+ /**
+ * Destroy this cell collection
+ */
+ public function __destruct() {
+ $this->_DBHandle = null;
+ } // function __destruct()
+
+
+ /**
+ * Identify whether the caching method is currently available
+ * Some methods are dependent on the availability of certain extensions being enabled in the PHP build
+ *
+ * @return boolean
+ */
+ public static function cacheMethodIsAvailable() {
+ if (!function_exists('sqlite_open')) {
+ return false;
+ }
+
+ return true;
+ }
+
+}
diff --git a/htdocs/includes/phpexcel/PHPExcel/CachedObjectStorage/SQLite3.php b/htdocs/includes/phpexcel/PHPExcel/CachedObjectStorage/SQLite3.php
index b867b4dd0cd..ead6e91f87f 100644
--- a/htdocs/includes/phpexcel/PHPExcel/CachedObjectStorage/SQLite3.php
+++ b/htdocs/includes/phpexcel/PHPExcel/CachedObjectStorage/SQLite3.php
@@ -1,277 +1,277 @@
-_currentCellIsDirty) {
- $this->_currentObject->detach();
-
- $query = $this->_DBHandle->prepare("INSERT OR REPLACE INTO kvp_".$this->_TableName." VALUES(:id,:data)");
- $query->bindValue('id',$this->_currentObjectID,SQLITE3_TEXT);
- $query->bindValue('data',serialize($this->_currentObject),SQLITE3_BLOB);
- $result = $query->execute();
- if ($result === false)
- throw new Exception($this->_DBHandle->lastErrorMsg());
- $this->_currentCellIsDirty = false;
- }
- $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;
- $this->_currentCellIsDirty = true;
-
- 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();
-
- $query = "SELECT value FROM kvp_".$this->_TableName." WHERE id='".$pCoord."'";
- $cellResult = $this->_DBHandle->querySingle($query);
- if ($cellResult === false) {
- throw new Exception($this->_DBHandle->lastErrorMsg());
- } elseif (is_null($cellResult)) {
- // 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($cellResult);
- // Re-attach the parent worksheet
- $this->_currentObject->attach($this->_parent);
-
- // Return requested entry
- return $this->_currentObject;
- } // function getCacheData()
-
-
- /**
- * Is a value set for an indexed cell?
- *
- * @param string $pCoord Coordinate address of the cell to check
- * @return boolean
- */
- public function isDataSet($pCoord) {
- if ($pCoord === $this->_currentObjectID) {
- return true;
- }
-
- // Check if the requested entry exists in the cache
- $query = "SELECT id FROM kvp_".$this->_TableName." WHERE id='".$pCoord."'";
- $cellResult = $this->_DBHandle->querySingle($query);
- if ($cellResult === false) {
- throw new Exception($this->_DBHandle->lastErrorMsg());
- } elseif (is_null($cellResult)) {
- // Return null if requested entry doesn't exist in cache
- return false;
- }
- return true;
- } // function isDataSet()
-
-
- /**
- * 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;
- }
-
- // Check if the requested entry exists in the cache
- $query = "DELETE FROM kvp_".$this->_TableName." WHERE id='".$pCoord."'";
- $result = $this->_DBHandle->exec($query);
- if ($result === false)
- throw new Exception($this->_DBHandle->lastErrorMsg());
-
- $this->_currentCellIsDirty = false;
- } // function deleteCacheData()
-
-
- /**
- * Get a list of all cell addresses currently held in cache
- *
- * @return array of string
- */
- public function getCellList() {
- $query = "SELECT id FROM kvp_".$this->_TableName;
- $cellIdsResult = $this->_DBHandle->query($query);
- if ($cellIdsResult === false)
- throw new Exception($this->_DBHandle->lastErrorMsg());
-
- $cellKeys = array();
- while ($row = $cellIdsResult->fetchArray(SQLITE3_ASSOC)) {
- $cellKeys[] = $row['id'];
- }
-
- return $cellKeys;
- } // function getCellList()
-
-
- /**
- * Clone the cell collection
- *
- * @param PHPExcel_Worksheet $parent The new worksheet
- * @return void
- */
- public function copyCellCollection(PHPExcel_Worksheet $parent) {
- // Get a new id for the new table name
- $tableName = str_replace('.','_',$this->_getUniqueID());
- if (!$this->_DBHandle->exec('CREATE TABLE kvp_'.$tableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB)
- AS SELECT * FROM kvp_'.$this->_TableName))
- throw new Exception($this->_DBHandle->lastErrorMsg());
-
- // Copy the existing cell cache file
- $this->_TableName = $tableName;
- } // function copyCellCollection()
-
-
- /**
- * Clear the cell collection and disconnect from our parent
- *
- * @return void
- */
- public function unsetWorksheetCells() {
- if(!is_null($this->_currentObject)) {
- $this->_currentObject->detach();
- $this->_currentObject = $this->_currentObjectID = null;
- }
- // 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()
-
-
- /**
- * Initialise this new cell collection
- *
- * @param PHPExcel_Worksheet $parent The worksheet for this cell collection
- */
- public function __construct(PHPExcel_Worksheet $parent) {
- parent::__construct($parent);
- if (is_null($this->_DBHandle)) {
- $this->_TableName = str_replace('.','_',$this->_getUniqueID());
- $_DBName = ':memory:';
-
- $this->_DBHandle = new SQLite3($_DBName);
- if ($this->_DBHandle === false)
- throw new Exception($this->_DBHandle->lastErrorMsg());
- if (!$this->_DBHandle->exec('CREATE TABLE kvp_'.$this->_TableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB)'))
- throw new Exception($this->_DBHandle->lastErrorMsg());
- }
- } // function __construct()
-
-
- /**
- * Destroy this cell collection
- */
- public function __destruct() {
- if (!is_null($this->_DBHandle)) {
- $this->_DBHandle->close();
- }
- $this->_DBHandle = null;
- } // function __destruct()
-
-
- /**
- * Identify whether the caching method is currently available
- * Some methods are dependent on the availability of certain extensions being enabled in the PHP build
- *
- * @return boolean
- */
- public static function cacheMethodIsAvailable() {
- if (!class_exists('SQLite3',FALSE)) {
- return false;
- }
-
- return true;
- }
-
-}
+_currentCellIsDirty) {
+ $this->_currentObject->detach();
+
+ $query = $this->_DBHandle->prepare("INSERT OR REPLACE INTO kvp_".$this->_TableName." VALUES(:id,:data)");
+ $query->bindValue('id',$this->_currentObjectID,SQLITE3_TEXT);
+ $query->bindValue('data',serialize($this->_currentObject),SQLITE3_BLOB);
+ $result = $query->execute();
+ if ($result === false)
+ throw new Exception($this->_DBHandle->lastErrorMsg());
+ $this->_currentCellIsDirty = false;
+ }
+ $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;
+ $this->_currentCellIsDirty = true;
+
+ 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();
+
+ $query = "SELECT value FROM kvp_".$this->_TableName." WHERE id='".$pCoord."'";
+ $cellResult = $this->_DBHandle->querySingle($query);
+ if ($cellResult === false) {
+ throw new Exception($this->_DBHandle->lastErrorMsg());
+ } elseif (is_null($cellResult)) {
+ // 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($cellResult);
+ // Re-attach the parent worksheet
+ $this->_currentObject->attach($this->_parent);
+
+ // Return requested entry
+ return $this->_currentObject;
+ } // function getCacheData()
+
+
+ /**
+ * Is a value set for an indexed cell?
+ *
+ * @param string $pCoord Coordinate address of the cell to check
+ * @return boolean
+ */
+ public function isDataSet($pCoord) {
+ if ($pCoord === $this->_currentObjectID) {
+ return true;
+ }
+
+ // Check if the requested entry exists in the cache
+ $query = "SELECT id FROM kvp_".$this->_TableName." WHERE id='".$pCoord."'";
+ $cellResult = $this->_DBHandle->querySingle($query);
+ if ($cellResult === false) {
+ throw new Exception($this->_DBHandle->lastErrorMsg());
+ } elseif (is_null($cellResult)) {
+ // Return null if requested entry doesn't exist in cache
+ return false;
+ }
+ return true;
+ } // function isDataSet()
+
+
+ /**
+ * 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;
+ }
+
+ // Check if the requested entry exists in the cache
+ $query = "DELETE FROM kvp_".$this->_TableName." WHERE id='".$pCoord."'";
+ $result = $this->_DBHandle->exec($query);
+ if ($result === false)
+ throw new Exception($this->_DBHandle->lastErrorMsg());
+
+ $this->_currentCellIsDirty = false;
+ } // function deleteCacheData()
+
+
+ /**
+ * Get a list of all cell addresses currently held in cache
+ *
+ * @return array of string
+ */
+ public function getCellList() {
+ $query = "SELECT id FROM kvp_".$this->_TableName;
+ $cellIdsResult = $this->_DBHandle->query($query);
+ if ($cellIdsResult === false)
+ throw new Exception($this->_DBHandle->lastErrorMsg());
+
+ $cellKeys = array();
+ while ($row = $cellIdsResult->fetchArray(SQLITE3_ASSOC)) {
+ $cellKeys[] = $row['id'];
+ }
+
+ return $cellKeys;
+ } // function getCellList()
+
+
+ /**
+ * Clone the cell collection
+ *
+ * @param PHPExcel_Worksheet $parent The new worksheet
+ * @return void
+ */
+ public function copyCellCollection(PHPExcel_Worksheet $parent) {
+ // Get a new id for the new table name
+ $tableName = str_replace('.','_',$this->_getUniqueID());
+ if (!$this->_DBHandle->exec('CREATE TABLE kvp_'.$tableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB)
+ AS SELECT * FROM kvp_'.$this->_TableName))
+ throw new Exception($this->_DBHandle->lastErrorMsg());
+
+ // Copy the existing cell cache file
+ $this->_TableName = $tableName;
+ } // function copyCellCollection()
+
+
+ /**
+ * Clear the cell collection and disconnect from our parent
+ *
+ * @return void
+ */
+ public function unsetWorksheetCells() {
+ if(!is_null($this->_currentObject)) {
+ $this->_currentObject->detach();
+ $this->_currentObject = $this->_currentObjectID = null;
+ }
+ // 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()
+
+
+ /**
+ * Initialise this new cell collection
+ *
+ * @param PHPExcel_Worksheet $parent The worksheet for this cell collection
+ */
+ public function __construct(PHPExcel_Worksheet $parent) {
+ parent::__construct($parent);
+ if (is_null($this->_DBHandle)) {
+ $this->_TableName = str_replace('.','_',$this->_getUniqueID());
+ $_DBName = ':memory:';
+
+ $this->_DBHandle = new SQLite3($_DBName);
+ if ($this->_DBHandle === false)
+ throw new Exception($this->_DBHandle->lastErrorMsg());
+ if (!$this->_DBHandle->exec('CREATE TABLE kvp_'.$this->_TableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB)'))
+ throw new Exception($this->_DBHandle->lastErrorMsg());
+ }
+ } // function __construct()
+
+
+ /**
+ * Destroy this cell collection
+ */
+ public function __destruct() {
+ if (!is_null($this->_DBHandle)) {
+ $this->_DBHandle->close();
+ }
+ $this->_DBHandle = null;
+ } // function __destruct()
+
+
+ /**
+ * Identify whether the caching method is currently available
+ * Some methods are dependent on the availability of certain extensions being enabled in the PHP build
+ *
+ * @return boolean
+ */
+ public static function cacheMethodIsAvailable() {
+ if (!class_exists('SQLite3',FALSE)) {
+ return false;
+ }
+
+ return true;
+ }
+
+}
diff --git a/htdocs/includes/phpexcel/PHPExcel/CachedObjectStorage/Wincache.php b/htdocs/includes/phpexcel/PHPExcel/CachedObjectStorage/Wincache.php
index 15344488496..ba8b0458062 100644
--- a/htdocs/includes/phpexcel/PHPExcel/CachedObjectStorage/Wincache.php
+++ b/htdocs/includes/phpexcel/PHPExcel/CachedObjectStorage/Wincache.php
@@ -1,280 +1,280 @@
-_currentCellIsDirty) {
- $this->_currentObject->detach();
-
- $obj = serialize($this->_currentObject);
- if (wincache_ucache_exists($this->_cachePrefix.$this->_currentObjectID.'.cache')) {
- if (!wincache_ucache_set($this->_cachePrefix.$this->_currentObjectID.'.cache', $obj, $this->_cacheTime)) {
- $this->__destruct();
- throw new Exception('Failed to store cell '.$this->_currentObjectID.' in WinCache');
- }
- } else {
- if (!wincache_ucache_add($this->_cachePrefix.$this->_currentObjectID.'.cache', $obj, $this->_cacheTime)) {
- $this->__destruct();
- throw new Exception('Failed to store cell '.$this->_currentObjectID.' in WinCache');
- }
- }
- $this->_currentCellIsDirty = false;
- }
-
- $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;
- $this->_currentCellIsDirty = true;
-
- 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 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 '.$pCoord.' 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 '.$pCoord.' 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()
-
-
- /**
- * Clone the cell collection
- *
- * @param PHPExcel_Worksheet $parent The new worksheet
- * @return void
- */
- public function copyCellCollection(PHPExcel_Worksheet $parent) {
- parent::copyCellCollection($parent);
- // Get a new id for the new file name
- $baseUnique = $this->_getUniqueID();
- $newCachePrefix = substr(md5($baseUnique),0,8).'.';
- $cacheList = $this->getCellList();
- foreach($cacheList as $cellID) {
- if ($cellID != $this->_currentObjectID) {
- $success = false;
- $obj = wincache_ucache_get($this->_cachePrefix.$cellID.'.cache', $success);
- if ($success === false) {
- // Entry no longer exists in WinCache, so clear it from the cache array
- parent::deleteCacheData($cellID);
- throw new Exception('Cell entry '.$cellID.' no longer exists in Wincache');
- }
- if (!wincache_ucache_add($newCachePrefix.$cellID.'.cache', $obj, $this->_cacheTime)) {
- $this->__destruct();
- throw new Exception('Failed to store cell '.$cellID.' in Wincache');
- }
- }
- }
- $this->_cachePrefix = $newCachePrefix;
- } // function copyCellCollection()
-
-
- /**
- * Clear the cell collection and disconnect from our parent
- *
- * @return void
- */
- 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()
-
-
- /**
- * Initialise this new cell collection
- *
- * @param PHPExcel_Worksheet $parent The worksheet for this cell collection
- * @param array of mixed $arguments Additional initialisation arguments
- */
- public function __construct(PHPExcel_Worksheet $parent, $arguments) {
- $cacheTime = (isset($arguments['cacheTime'])) ? $arguments['cacheTime'] : 600;
-
- if (is_null($this->_cachePrefix)) {
- $baseUnique = $this->_getUniqueID();
- $this->_cachePrefix = substr(md5($baseUnique),0,8).'.';
- $this->_cacheTime = $cacheTime;
-
- parent::__construct($parent);
- }
- } // function __construct()
-
-
- /**
- * Destroy this cell collection
- */
- public function __destruct() {
- $cacheList = $this->getCellList();
- foreach($cacheList as $cellID) {
- wincache_ucache_delete($this->_cachePrefix.$cellID.'.cache');
- }
- } // function __destruct()
-
-
- /**
- * Identify whether the caching method is currently available
- * Some methods are dependent on the availability of certain extensions being enabled in the PHP build
- *
- * @return boolean
- */
- public static function cacheMethodIsAvailable() {
- if (!function_exists('wincache_ucache_add')) {
- return false;
- }
-
- return true;
- }
-
-}
+_currentCellIsDirty) {
+ $this->_currentObject->detach();
+
+ $obj = serialize($this->_currentObject);
+ if (wincache_ucache_exists($this->_cachePrefix.$this->_currentObjectID.'.cache')) {
+ if (!wincache_ucache_set($this->_cachePrefix.$this->_currentObjectID.'.cache', $obj, $this->_cacheTime)) {
+ $this->__destruct();
+ throw new Exception('Failed to store cell '.$this->_currentObjectID.' in WinCache');
+ }
+ } else {
+ if (!wincache_ucache_add($this->_cachePrefix.$this->_currentObjectID.'.cache', $obj, $this->_cacheTime)) {
+ $this->__destruct();
+ throw new Exception('Failed to store cell '.$this->_currentObjectID.' in WinCache');
+ }
+ }
+ $this->_currentCellIsDirty = false;
+ }
+
+ $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;
+ $this->_currentCellIsDirty = true;
+
+ 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 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 '.$pCoord.' 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 '.$pCoord.' 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()
+
+
+ /**
+ * Clone the cell collection
+ *
+ * @param PHPExcel_Worksheet $parent The new worksheet
+ * @return void
+ */
+ public function copyCellCollection(PHPExcel_Worksheet $parent) {
+ parent::copyCellCollection($parent);
+ // Get a new id for the new file name
+ $baseUnique = $this->_getUniqueID();
+ $newCachePrefix = substr(md5($baseUnique),0,8).'.';
+ $cacheList = $this->getCellList();
+ foreach($cacheList as $cellID) {
+ if ($cellID != $this->_currentObjectID) {
+ $success = false;
+ $obj = wincache_ucache_get($this->_cachePrefix.$cellID.'.cache', $success);
+ if ($success === false) {
+ // Entry no longer exists in WinCache, so clear it from the cache array
+ parent::deleteCacheData($cellID);
+ throw new Exception('Cell entry '.$cellID.' no longer exists in Wincache');
+ }
+ if (!wincache_ucache_add($newCachePrefix.$cellID.'.cache', $obj, $this->_cacheTime)) {
+ $this->__destruct();
+ throw new Exception('Failed to store cell '.$cellID.' in Wincache');
+ }
+ }
+ }
+ $this->_cachePrefix = $newCachePrefix;
+ } // function copyCellCollection()
+
+
+ /**
+ * Clear the cell collection and disconnect from our parent
+ *
+ * @return void
+ */
+ 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()
+
+
+ /**
+ * Initialise this new cell collection
+ *
+ * @param PHPExcel_Worksheet $parent The worksheet for this cell collection
+ * @param array of mixed $arguments Additional initialisation arguments
+ */
+ public function __construct(PHPExcel_Worksheet $parent, $arguments) {
+ $cacheTime = (isset($arguments['cacheTime'])) ? $arguments['cacheTime'] : 600;
+
+ if (is_null($this->_cachePrefix)) {
+ $baseUnique = $this->_getUniqueID();
+ $this->_cachePrefix = substr(md5($baseUnique),0,8).'.';
+ $this->_cacheTime = $cacheTime;
+
+ parent::__construct($parent);
+ }
+ } // function __construct()
+
+
+ /**
+ * Destroy this cell collection
+ */
+ public function __destruct() {
+ $cacheList = $this->getCellList();
+ foreach($cacheList as $cellID) {
+ wincache_ucache_delete($this->_cachePrefix.$cellID.'.cache');
+ }
+ } // function __destruct()
+
+
+ /**
+ * Identify whether the caching method is currently available
+ * Some methods are dependent on the availability of certain extensions being enabled in the PHP build
+ *
+ * @return boolean
+ */
+ public static function cacheMethodIsAvailable() {
+ if (!function_exists('wincache_ucache_add')) {
+ return false;
+ }
+
+ return true;
+ }
+
+}
diff --git a/htdocs/includes/phpexcel/PHPExcel/CachedObjectStorageFactory.php b/htdocs/includes/phpexcel/PHPExcel/CachedObjectStorageFactory.php
index d523a20686a..51019f7bdc5 100644
--- a/htdocs/includes/phpexcel/PHPExcel/CachedObjectStorageFactory.php
+++ b/htdocs/includes/phpexcel/PHPExcel/CachedObjectStorageFactory.php
@@ -1,239 +1,239 @@
- array(
- ),
- self::cache_in_memory_gzip => array(
- ),
- self::cache_in_memory_serialized => array(
- ),
- self::cache_igbinary => array(
- ),
- self::cache_to_phpTemp => array( 'memoryCacheSize' => '1MB'
- ),
- self::cache_to_discISAM => array( 'dir' => NULL
- ),
- 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
- ),
- self::cache_to_sqlite => array(
- ),
- self::cache_to_sqlite3 => array(
- ),
- );
-
-
- /**
- * Arguments for the active cache storage method
- *
- * @var array of mixed array
- */
- private static $_storageMethodParameters = array();
-
-
- /**
- * Return the current cache storage method
- *
- * @return string|NULL
- **/
- public static function getCacheStorageMethod()
- {
- return self::$_cacheStorageMethod;
- } // function getCacheStorageMethod()
-
-
- /**
- * Return the current cache storage class
- *
- * @return PHPExcel_CachedObjectStorage_ICache|NULL
- **/
- public static function getCacheStorageClass()
- {
- return self::$_cacheStorageClass;
- } // function getCacheStorageClass()
-
-
- /**
- * Return the list of all possible cache storage methods
- *
- * @return string[]
- **/
- public static function getAllCacheStorageMethods()
- {
- return self::$_storageMethods;
- } // function getCacheStorageMethods()
-
-
- /**
- * Return the list of all available cache storage methods
- *
- * @return string[]
- **/
- public static function getCacheStorageMethods()
- {
- $activeMethods = array();
- foreach(self::$_storageMethods as $storageMethod) {
- $cacheStorageClass = 'PHPExcel_CachedObjectStorage_' . $storageMethod;
- if (call_user_func(array($cacheStorageClass, 'cacheMethodIsAvailable'))) {
- $activeMethods[] = $storageMethod;
- }
- }
- return $activeMethods;
- } // function getCacheStorageMethods()
-
-
- /**
- * Identify the cache storage method to use
- *
- * @param string $method Name of the method to use for cell cacheing
- * @param array of mixed $arguments Additional arguments to pass to the cell caching class
- * when instantiating
- * @return boolean
- **/
- public static function initialize($method = self::cache_in_memory, $arguments = array())
- {
- if (!in_array($method,self::$_storageMethods)) {
- return FALSE;
- }
-
- $cacheStorageClass = 'PHPExcel_CachedObjectStorage_'.$method;
- if (!call_user_func(array( $cacheStorageClass,
- 'cacheMethodIsAvailable'))) {
- return FALSE;
- }
-
- self::$_storageMethodParameters[$method] = self::$_storageMethodDefaultParameters[$method];
- foreach($arguments as $k => $v) {
- if (isset(self::$_storageMethodParameters[$method][$k])) {
- self::$_storageMethodParameters[$method][$k] = $v;
- }
- }
-
- if (self::$_cacheStorageMethod === NULL) {
- self::$_cacheStorageClass = 'PHPExcel_CachedObjectStorage_' . $method;
- self::$_cacheStorageMethod = $method;
- }
- return TRUE;
- } // function initialize()
-
-
- /**
- * Initialise the cache storage
- *
- * @param PHPExcel_Worksheet $parent Enable cell caching for this worksheet
- * @return PHPExcel_CachedObjectStorage_ICache
- **/
- public static function getInstance(PHPExcel_Worksheet $parent)
- {
- $cacheMethodIsAvailable = TRUE;
- if (self::$_cacheStorageMethod === NULL) {
- $cacheMethodIsAvailable = self::initialize();
- }
-
- if ($cacheMethodIsAvailable) {
- $instance = new self::$_cacheStorageClass( $parent,
- self::$_storageMethodParameters[self::$_cacheStorageMethod]
- );
- if ($instance !== NULL) {
- return $instance;
- }
- }
-
- return FALSE;
- } // function getInstance()
-
+ array(
+ ),
+ self::cache_in_memory_gzip => array(
+ ),
+ self::cache_in_memory_serialized => array(
+ ),
+ self::cache_igbinary => array(
+ ),
+ self::cache_to_phpTemp => array( 'memoryCacheSize' => '1MB'
+ ),
+ self::cache_to_discISAM => array( 'dir' => NULL
+ ),
+ 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
+ ),
+ self::cache_to_sqlite => array(
+ ),
+ self::cache_to_sqlite3 => array(
+ ),
+ );
+
+
+ /**
+ * Arguments for the active cache storage method
+ *
+ * @var array of mixed array
+ */
+ private static $_storageMethodParameters = array();
+
+
+ /**
+ * Return the current cache storage method
+ *
+ * @return string|NULL
+ **/
+ public static function getCacheStorageMethod()
+ {
+ return self::$_cacheStorageMethod;
+ } // function getCacheStorageMethod()
+
+
+ /**
+ * Return the current cache storage class
+ *
+ * @return PHPExcel_CachedObjectStorage_ICache|NULL
+ **/
+ public static function getCacheStorageClass()
+ {
+ return self::$_cacheStorageClass;
+ } // function getCacheStorageClass()
+
+
+ /**
+ * Return the list of all possible cache storage methods
+ *
+ * @return string[]
+ **/
+ public static function getAllCacheStorageMethods()
+ {
+ return self::$_storageMethods;
+ } // function getCacheStorageMethods()
+
+
+ /**
+ * Return the list of all available cache storage methods
+ *
+ * @return string[]
+ **/
+ public static function getCacheStorageMethods()
+ {
+ $activeMethods = array();
+ foreach(self::$_storageMethods as $storageMethod) {
+ $cacheStorageClass = 'PHPExcel_CachedObjectStorage_' . $storageMethod;
+ if (call_user_func(array($cacheStorageClass, 'cacheMethodIsAvailable'))) {
+ $activeMethods[] = $storageMethod;
+ }
+ }
+ return $activeMethods;
+ } // function getCacheStorageMethods()
+
+
+ /**
+ * Identify the cache storage method to use
+ *
+ * @param string $method Name of the method to use for cell cacheing
+ * @param array of mixed $arguments Additional arguments to pass to the cell caching class
+ * when instantiating
+ * @return boolean
+ **/
+ public static function initialize($method = self::cache_in_memory, $arguments = array())
+ {
+ if (!in_array($method,self::$_storageMethods)) {
+ return FALSE;
+ }
+
+ $cacheStorageClass = 'PHPExcel_CachedObjectStorage_'.$method;
+ if (!call_user_func(array( $cacheStorageClass,
+ 'cacheMethodIsAvailable'))) {
+ return FALSE;
+ }
+
+ self::$_storageMethodParameters[$method] = self::$_storageMethodDefaultParameters[$method];
+ foreach($arguments as $k => $v) {
+ if (isset(self::$_storageMethodParameters[$method][$k])) {
+ self::$_storageMethodParameters[$method][$k] = $v;
+ }
+ }
+
+ if (self::$_cacheStorageMethod === NULL) {
+ self::$_cacheStorageClass = 'PHPExcel_CachedObjectStorage_' . $method;
+ self::$_cacheStorageMethod = $method;
+ }
+ return TRUE;
+ } // function initialize()
+
+
+ /**
+ * Initialise the cache storage
+ *
+ * @param PHPExcel_Worksheet $parent Enable cell caching for this worksheet
+ * @return PHPExcel_CachedObjectStorage_ICache
+ **/
+ public static function getInstance(PHPExcel_Worksheet $parent)
+ {
+ $cacheMethodIsAvailable = TRUE;
+ if (self::$_cacheStorageMethod === NULL) {
+ $cacheMethodIsAvailable = self::initialize();
+ }
+
+ if ($cacheMethodIsAvailable) {
+ $instance = new self::$_cacheStorageClass( $parent,
+ self::$_storageMethodParameters[self::$_cacheStorageMethod]
+ );
+ if ($instance !== NULL) {
+ return $instance;
+ }
+ }
+
+ return FALSE;
+ } // function getInstance()
+
}
\ No newline at end of file
diff --git a/htdocs/includes/phpexcel/PHPExcel/Chart/Renderer/PHP Charting Libraries.txt b/htdocs/includes/phpexcel/PHPExcel/Chart/Renderer/PHP Charting Libraries.txt
index 20a8258850d..faaa61d153b 100644
--- a/htdocs/includes/phpexcel/PHPExcel/Chart/Renderer/PHP Charting Libraries.txt
+++ b/htdocs/includes/phpexcel/PHPExcel/Chart/Renderer/PHP Charting Libraries.txt
@@ -1,17 +1,17 @@
-ChartDirector
- http://www.advsofteng.com/cdphp.html
-
-GraPHPite
- http://graphpite.sourceforge.net/
-
-JpGraph
- http://www.aditus.nu/jpgraph/
-
-LibChart
- http://naku.dohcrew.com/libchart/pages/introduction/
-
-pChart
- http://pchart.sourceforge.net/
-
-TeeChart
- http://www.steema.com/products/teechart/overview.html
+ChartDirector
+ http://www.advsofteng.com/cdphp.html
+
+GraPHPite
+ http://graphpite.sourceforge.net/
+
+JpGraph
+ http://www.aditus.nu/jpgraph/
+
+LibChart
+ http://naku.dohcrew.com/libchart/pages/introduction/
+
+pChart
+ http://pchart.sourceforge.net/
+
+TeeChart
+ http://www.steema.com/products/teechart/overview.html
diff --git a/htdocs/includes/phpexcel/PHPExcel/Chart/Renderer/jpgraph.php b/htdocs/includes/phpexcel/PHPExcel/Chart/Renderer/jpgraph.php
index 6fb3aadc133..889fd9fce08 100644
--- a/htdocs/includes/phpexcel/PHPExcel/Chart/Renderer/jpgraph.php
+++ b/htdocs/includes/phpexcel/PHPExcel/Chart/Renderer/jpgraph.php
@@ -1,839 +1,839 @@
- MARK_DIAMOND,
- 'square' => MARK_SQUARE,
- 'triangle' => MARK_UTRIANGLE,
- 'x' => MARK_X,
- 'star' => MARK_STAR,
- 'dot' => MARK_FILLEDCIRCLE,
- 'dash' => MARK_DTRIANGLE,
- 'circle' => MARK_CIRCLE,
- 'plus' => MARK_CROSS
- );
-
-
- private $_chart = null;
-
- private $_graph = null;
-
- private static $_plotColour = 0;
-
- private static $_plotMark = 0;
-
-
- private function _formatPointMarker($seriesPlot,$markerID) {
- $plotMarkKeys = array_keys(self::$_markSet);
- if (is_null($markerID)) {
- // Use default plot marker (next marker in the series)
- self::$_plotMark %= count(self::$_markSet);
- $seriesPlot->mark->SetType(self::$_markSet[$plotMarkKeys[self::$_plotMark++]]);
- } elseif ($markerID !== 'none') {
- // Use specified plot marker (if it exists)
- if (isset(self::$_markSet[$markerID])) {
- $seriesPlot->mark->SetType(self::$_markSet[$markerID]);
- } else {
- // If the specified plot marker doesn't exist, use default plot marker (next marker in the series)
- self::$_plotMark %= count(self::$_markSet);
- $seriesPlot->mark->SetType(self::$_markSet[$plotMarkKeys[self::$_plotMark++]]);
- }
- } else {
- // Hide plot marker
- $seriesPlot->mark->Hide();
- }
- $seriesPlot->mark->SetColor(self::$_colourSet[self::$_plotColour]);
- $seriesPlot->mark->SetFillColor(self::$_colourSet[self::$_plotColour]);
- $seriesPlot->SetColor(self::$_colourSet[self::$_plotColour++]);
-
- return $seriesPlot;
- } // function _formatPointMarker()
-
-
- private function _formatDataSetLabels($groupID, $datasetLabels, $labelCount, $rotation = '') {
- $datasetLabelFormatCode = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex(0)->getFormatCode();
- if (!is_null($datasetLabelFormatCode)) {
- // Retrieve any label formatting code
- $datasetLabelFormatCode = stripslashes($datasetLabelFormatCode);
- }
-
- $testCurrentIndex = 0;
- foreach($datasetLabels as $i => $datasetLabel) {
- array_reverse($datasetLabel);
-
- if (is_array($datasetLabel)) {
- if ($rotation == 'bar') {
- $datasetLabel = array_reverse($datasetLabel);
- $datasetLabels[$i] = implode(" ",$datasetLabel);
- } else {
- $datasetLabels[$i] = implode("\n",$datasetLabel);
- }
- } else {
- // Format labels according to any formatting code
- if (!is_null($datasetLabelFormatCode)) {
- $datasetLabels[$i] = PHPExcel_Style_NumberFormat::toFormattedString($datasetLabel,$datasetLabelFormatCode);
- }
- }
- ++$testCurrentIndex;
- }
-
- return $datasetLabels;
- } // function _formatDataSetLabels()
-
-
- private function _percentageSumCalculation($groupID,$seriesCount) {
- // Adjust our values to a percentage value across all series in the group
- for($i = 0; $i < $seriesCount; ++$i) {
- if ($i == 0) {
- $sumValues = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($i)->getDataValues();
- } else {
- $nextValues = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($i)->getDataValues();
- foreach($nextValues as $k => $value) {
- if (isset($sumValues[$k])) {
- $sumValues[$k] += $value;
- } else {
- $sumValues[$k] = $value;
- }
- }
- }
- }
-
- return $sumValues;
- } // function _percentageSumCalculation()
-
-
- private function _percentageAdjustValues($dataValues,$sumValues) {
- foreach($dataValues as $k => $dataValue) {
- $dataValues[$k] = $dataValue / $sumValues[$k] * 100;
- }
-
- return $dataValues;
- } // function _percentageAdjustValues()
-
-
- private function _getCaption($captionElement) {
- // Read any caption
- $caption = (!is_null($captionElement)) ? $captionElement->getCaption() : NULL;
- // Test if we have a title caption to display
- if (!is_null($caption)) {
- // If we do, it could be a plain string or an array
- if (is_array($caption)) {
- // Implode an array to a plain string
- $caption = implode('',$caption);
- }
- }
- return $caption;
- } // function _getCaption()
-
-
- private function _renderTitle() {
- $title = $this->_getCaption($this->_chart->getTitle());
- if (!is_null($title)) {
- $this->_graph->title->Set($title);
- }
- } // function _renderTitle()
-
-
- private function _renderLegend() {
- $legend = $this->_chart->getLegend();
- if (!is_null($legend)) {
- $legendPosition = $legend->getPosition();
- $legendOverlay = $legend->getOverlay();
- switch ($legendPosition) {
- case 'r' :
- $this->_graph->legend->SetPos(0.01,0.5,'right','center'); // right
- $this->_graph->legend->SetColumns(1);
- break;
- case 'l' :
- $this->_graph->legend->SetPos(0.01,0.5,'left','center'); // left
- $this->_graph->legend->SetColumns(1);
- break;
- case 't' :
- $this->_graph->legend->SetPos(0.5,0.01,'center','top'); // top
- break;
- case 'b' :
- $this->_graph->legend->SetPos(0.5,0.99,'center','bottom'); // bottom
- break;
- default :
- $this->_graph->legend->SetPos(0.01,0.01,'right','top'); // top-right
- $this->_graph->legend->SetColumns(1);
- break;
- }
- } else {
- $this->_graph->legend->Hide();
- }
- } // function _renderLegend()
-
-
- private function _renderCartesianPlotArea($type='textlin') {
- $this->_graph = new Graph(self::$_width,self::$_height);
- $this->_graph->SetScale($type);
-
- $this->_renderTitle();
-
- // Rotate for bar rather than column chart
- $rotation = $this->_chart->getPlotArea()->getPlotGroupByIndex(0)->getPlotDirection();
- $reverse = ($rotation == 'bar') ? true : false;
-
- $xAxisLabel = $this->_chart->getXAxisLabel();
- if (!is_null($xAxisLabel)) {
- $title = $this->_getCaption($xAxisLabel);
- if (!is_null($title)) {
- $this->_graph->xaxis->SetTitle($title,'center');
- $this->_graph->xaxis->title->SetMargin(35);
- if ($reverse) {
- $this->_graph->xaxis->title->SetAngle(90);
- $this->_graph->xaxis->title->SetMargin(90);
- }
- }
- }
-
- $yAxisLabel = $this->_chart->getYAxisLabel();
- if (!is_null($yAxisLabel)) {
- $title = $this->_getCaption($yAxisLabel);
- if (!is_null($title)) {
- $this->_graph->yaxis->SetTitle($title,'center');
- if ($reverse) {
- $this->_graph->yaxis->title->SetAngle(0);
- $this->_graph->yaxis->title->SetMargin(-55);
- }
- }
- }
- } // function _renderCartesianPlotArea()
-
-
- private function _renderPiePlotArea($doughnut = False) {
- $this->_graph = new PieGraph(self::$_width,self::$_height);
-
- $this->_renderTitle();
- } // function _renderPiePlotArea()
-
-
- private function _renderRadarPlotArea() {
- $this->_graph = new RadarGraph(self::$_width,self::$_height);
- $this->_graph->SetScale('lin');
-
- $this->_renderTitle();
- } // function _renderRadarPlotArea()
-
-
- private function _renderPlotLine($groupID, $filled = false, $combination = false, $dimensions = '2d') {
- $grouping = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotGrouping();
-
- $labelCount = count($this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex(0)->getPointCount());
- if ($labelCount > 0) {
- $datasetLabels = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex(0)->getDataValues();
- $datasetLabels = $this->_formatDataSetLabels($groupID, $datasetLabels, $labelCount);
- $this->_graph->xaxis->SetTickLabels($datasetLabels);
- }
-
- $seriesCount = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotSeriesCount();
- $seriesPlots = array();
- if ($grouping == 'percentStacked') {
- $sumValues = $this->_percentageSumCalculation($groupID,$seriesCount);
- }
-
- // Loop through each data series in turn
- for($i = 0; $i < $seriesCount; ++$i) {
- $dataValues = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($i)->getDataValues();
- $marker = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($i)->getPointMarker();
-
- if ($grouping == 'percentStacked') {
- $dataValues = $this->_percentageAdjustValues($dataValues,$sumValues);
- }
-
- // Fill in any missing values in the $dataValues array
- $testCurrentIndex = 0;
- foreach($dataValues as $k => $dataValue) {
- while($k != $testCurrentIndex) {
- $dataValues[$testCurrentIndex] = null;
- ++$testCurrentIndex;
- }
- ++$testCurrentIndex;
- }
-
- $seriesPlot = new LinePlot($dataValues);
- if ($combination) {
- $seriesPlot->SetBarCenter();
- }
-
- if ($filled) {
- $seriesPlot->SetFilled(true);
- $seriesPlot->SetColor('black');
- $seriesPlot->SetFillColor(self::$_colourSet[self::$_plotColour++]);
- } else {
- // Set the appropriate plot marker
- $this->_formatPointMarker($seriesPlot,$marker);
- }
- $dataLabel = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotLabelByIndex($i)->getDataValue();
- $seriesPlot->SetLegend($dataLabel);
-
- $seriesPlots[] = $seriesPlot;
- }
-
- if ($grouping == 'standard') {
- $groupPlot = $seriesPlots;
- } else {
- $groupPlot = new AccLinePlot($seriesPlots);
- }
- $this->_graph->Add($groupPlot);
- } // function _renderPlotLine()
-
-
- private function _renderPlotBar($groupID, $dimensions = '2d') {
- $rotation = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotDirection();
- // Rotate for bar rather than column chart
- if (($groupID == 0) && ($rotation == 'bar')) {
- $this->_graph->Set90AndMargin();
- }
- $grouping = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotGrouping();
-
- $labelCount = count($this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex(0)->getPointCount());
- if ($labelCount > 0) {
- $datasetLabels = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex(0)->getDataValues();
- $datasetLabels = $this->_formatDataSetLabels($groupID, $datasetLabels, $labelCount, $rotation);
- // Rotate for bar rather than column chart
- if ($rotation == 'bar') {
- $datasetLabels = array_reverse($datasetLabels);
- $this->_graph->yaxis->SetPos('max');
- $this->_graph->yaxis->SetLabelAlign('center','top');
- $this->_graph->yaxis->SetLabelSide(SIDE_RIGHT);
- }
- $this->_graph->xaxis->SetTickLabels($datasetLabels);
- }
-
-
- $seriesCount = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotSeriesCount();
- $seriesPlots = array();
- if ($grouping == 'percentStacked') {
- $sumValues = $this->_percentageSumCalculation($groupID,$seriesCount);
- }
-
- // Loop through each data series in turn
- for($j = 0; $j < $seriesCount; ++$j) {
- $dataValues = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($j)->getDataValues();
- if ($grouping == 'percentStacked') {
- $dataValues = $this->_percentageAdjustValues($dataValues,$sumValues);
- }
-
- // Fill in any missing values in the $dataValues array
- $testCurrentIndex = 0;
- foreach($dataValues as $k => $dataValue) {
- while($k != $testCurrentIndex) {
- $dataValues[$testCurrentIndex] = null;
- ++$testCurrentIndex;
- }
- ++$testCurrentIndex;
- }
-
- // Reverse the $dataValues order for bar rather than column chart
- if ($rotation == 'bar') {
- $dataValues = array_reverse($dataValues);
- }
- $seriesPlot = new BarPlot($dataValues);
- $seriesPlot->SetColor('black');
- $seriesPlot->SetFillColor(self::$_colourSet[self::$_plotColour++]);
- if ($dimensions == '3d') {
- $seriesPlot->SetShadow();
- }
- if (!$this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotLabelByIndex($j)) {
- $dataLabel = '';
- } else {
- $dataLabel = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotLabelByIndex($j)->getDataValue();
- }
- $seriesPlot->SetLegend($dataLabel);
-
- $seriesPlots[] = $seriesPlot;
- }
- // Reverse the plot order for bar rather than column chart
- if (($rotation == 'bar') && (!($grouping == 'percentStacked'))) {
- $seriesPlots = array_reverse($seriesPlots);
- }
-
- if ($grouping == 'clustered') {
- $groupPlot = new GroupBarPlot($seriesPlots);
- } elseif ($grouping == 'standard') {
- $groupPlot = new GroupBarPlot($seriesPlots);
- } else {
- $groupPlot = new AccBarPlot($seriesPlots);
- if ($dimensions == '3d') {
- $groupPlot->SetShadow();
- }
- }
-
- $this->_graph->Add($groupPlot);
- } // function _renderPlotBar()
-
-
- private function _renderPlotScatter($groupID,$bubble) {
- $grouping = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotGrouping();
- $scatterStyle = $bubbleSize = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotStyle();
-
- $seriesCount = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotSeriesCount();
- $seriesPlots = array();
-
- // Loop through each data series in turn
- for($i = 0; $i < $seriesCount; ++$i) {
- $dataValuesY = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex($i)->getDataValues();
- $dataValuesX = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($i)->getDataValues();
-
- foreach($dataValuesY as $k => $dataValueY) {
- $dataValuesY[$k] = $k;
- }
-
- $seriesPlot = new ScatterPlot($dataValuesX,$dataValuesY);
- if ($scatterStyle == 'lineMarker') {
- $seriesPlot->SetLinkPoints();
- $seriesPlot->link->SetColor(self::$_colourSet[self::$_plotColour]);
- } elseif ($scatterStyle == 'smoothMarker') {
- $spline = new Spline($dataValuesY,$dataValuesX);
- list($splineDataY,$splineDataX) = $spline->Get(count($dataValuesX) * self::$_width / 20);
- $lplot = new LinePlot($splineDataX,$splineDataY);
- $lplot->SetColor(self::$_colourSet[self::$_plotColour]);
-
- $this->_graph->Add($lplot);
- }
-
- if ($bubble) {
- $this->_formatPointMarker($seriesPlot,'dot');
- $seriesPlot->mark->SetColor('black');
- $seriesPlot->mark->SetSize($bubbleSize);
- } else {
- $marker = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($i)->getPointMarker();
- $this->_formatPointMarker($seriesPlot,$marker);
- }
- $dataLabel = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotLabelByIndex($i)->getDataValue();
- $seriesPlot->SetLegend($dataLabel);
-
- $this->_graph->Add($seriesPlot);
- }
- } // function _renderPlotScatter()
-
-
- private function _renderPlotRadar($groupID) {
- $radarStyle = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotStyle();
-
- $seriesCount = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotSeriesCount();
- $seriesPlots = array();
-
- // Loop through each data series in turn
- for($i = 0; $i < $seriesCount; ++$i) {
- $dataValuesY = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex($i)->getDataValues();
- $dataValuesX = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($i)->getDataValues();
- $marker = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($i)->getPointMarker();
-
- $dataValues = array();
- foreach($dataValuesY as $k => $dataValueY) {
- $dataValues[$k] = implode(' ',array_reverse($dataValueY));
- }
- $tmp = array_shift($dataValues);
- $dataValues[] = $tmp;
- $tmp = array_shift($dataValuesX);
- $dataValuesX[] = $tmp;
-
- $this->_graph->SetTitles(array_reverse($dataValues));
-
- $seriesPlot = new RadarPlot(array_reverse($dataValuesX));
-
- $dataLabel = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotLabelByIndex($i)->getDataValue();
- $seriesPlot->SetColor(self::$_colourSet[self::$_plotColour++]);
- if ($radarStyle == 'filled') {
- $seriesPlot->SetFillColor(self::$_colourSet[self::$_plotColour]);
- }
- $this->_formatPointMarker($seriesPlot,$marker);
- $seriesPlot->SetLegend($dataLabel);
-
- $this->_graph->Add($seriesPlot);
- }
- } // function _renderPlotRadar()
-
-
- private function _renderPlotContour($groupID) {
- $contourStyle = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotStyle();
-
- $seriesCount = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotSeriesCount();
- $seriesPlots = array();
-
- $dataValues = array();
- // Loop through each data series in turn
- for($i = 0; $i < $seriesCount; ++$i) {
- $dataValuesY = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex($i)->getDataValues();
- $dataValuesX = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($i)->getDataValues();
-
- $dataValues[$i] = $dataValuesX;
- }
- $seriesPlot = new ContourPlot($dataValues);
-
- $this->_graph->Add($seriesPlot);
- } // function _renderPlotContour()
-
-
- private function _renderPlotStock($groupID) {
- $seriesCount = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotSeriesCount();
- $plotOrder = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotOrder();
- $seriesPlots = array();
-
- $dataValues = array();
- // Loop through each data series in turn
- for($i = 0; $i < $seriesCount; ++$i) {
- $dataValuesY = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex($i)->getDataValues();
- $dataValuesX = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($i)->getDataValues();
-
- foreach($dataValuesX as $j => $dataValueX)
- $dataValues[$j][$plotOrder[$i]] = $dataValueX;
- }
-
- $seriesPlot = new StockPlot($dataValues);
-
- $this->_graph->Add($seriesPlot);
- } // function _renderPlotStock()
-
-
- private function _renderAreaChart($groupCount, $dimensions = '2d') {
- require_once('jpgraph_line.php');
-
- $this->_renderCartesianPlotArea();
-
- for($i = 0; $i < $groupCount; ++$i) {
- $this->_renderPlotLine($i,True,False,$dimensions);
- }
- } // function _renderAreaChart()
-
-
- private function _renderLineChart($groupCount, $dimensions = '2d') {
- require_once('jpgraph_line.php');
-
- $this->_renderCartesianPlotArea();
-
- for($i = 0; $i < $groupCount; ++$i) {
- $this->_renderPlotLine($i,False,False,$dimensions);
- }
- } // function _renderLineChart()
-
-
- private function _renderBarChart($groupCount, $dimensions = '2d') {
- require_once('jpgraph_bar.php');
-
- $this->_renderCartesianPlotArea();
-
- for($i = 0; $i < $groupCount; ++$i) {
- $this->_renderPlotBar($i,$dimensions);
- }
- } // function _renderBarChart()
-
-
- private function _renderScatterChart($groupCount) {
- require_once('jpgraph_scatter.php');
- require_once('jpgraph_regstat.php');
- require_once('jpgraph_line.php');
-
- $this->_renderCartesianPlotArea('linlin');
-
- for($i = 0; $i < $groupCount; ++$i) {
- $this->_renderPlotScatter($i,false);
- }
- } // function _renderScatterChart()
-
-
- private function _renderBubbleChart($groupCount) {
- require_once('jpgraph_scatter.php');
-
- $this->_renderCartesianPlotArea('linlin');
-
- for($i = 0; $i < $groupCount; ++$i) {
- $this->_renderPlotScatter($i,true);
- }
- } // function _renderBubbleChart()
-
-
- private function _renderPieChart($groupCount, $dimensions = '2d', $doughnut = False, $multiplePlots = False) {
- require_once('jpgraph_pie.php');
- if ($dimensions == '3d') {
- require_once('jpgraph_pie3d.php');
- }
-
- $this->_renderPiePlotArea($doughnut);
-
- $iLimit = ($multiplePlots) ? $groupCount : 1;
- for($groupID = 0; $groupID < $iLimit; ++$groupID) {
- $grouping = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotGrouping();
- $exploded = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotStyle();
- if ($groupID == 0) {
- $labelCount = count($this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex(0)->getPointCount());
- if ($labelCount > 0) {
- $datasetLabels = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex(0)->getDataValues();
- $datasetLabels = $this->_formatDataSetLabels($groupID, $datasetLabels, $labelCount);
- }
- }
-
- $seriesCount = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotSeriesCount();
- $seriesPlots = array();
- // For pie charts, we only display the first series: doughnut charts generally display all series
- $jLimit = ($multiplePlots) ? $seriesCount : 1;
- // Loop through each data series in turn
- for($j = 0; $j < $jLimit; ++$j) {
- $dataValues = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($j)->getDataValues();
-
- // Fill in any missing values in the $dataValues array
- $testCurrentIndex = 0;
- foreach($dataValues as $k => $dataValue) {
- while($k != $testCurrentIndex) {
- $dataValues[$testCurrentIndex] = null;
- ++$testCurrentIndex;
- }
- ++$testCurrentIndex;
- }
-
- if ($dimensions == '3d') {
- $seriesPlot = new PiePlot3D($dataValues);
- } else {
- if ($doughnut) {
- $seriesPlot = new PiePlotC($dataValues);
- } else {
- $seriesPlot = new PiePlot($dataValues);
- }
- }
-
- if ($multiplePlots) {
- $seriesPlot->SetSize(($jLimit-$j) / ($jLimit * 4));
- }
-
- if ($doughnut) {
- $seriesPlot->SetMidColor('white');
- }
-
- $seriesPlot->SetColor(self::$_colourSet[self::$_plotColour++]);
- if (count($datasetLabels) > 0)
- $seriesPlot->SetLabels(array_fill(0,count($datasetLabels),''));
- if ($dimensions != '3d') {
- $seriesPlot->SetGuideLines(false);
- }
- if ($j == 0) {
- if ($exploded) {
- $seriesPlot->ExplodeAll();
- }
- $seriesPlot->SetLegends($datasetLabels);
- }
-
- $this->_graph->Add($seriesPlot);
- }
- }
- } // function _renderPieChart()
-
-
- private function _renderRadarChart($groupCount) {
- require_once('jpgraph_radar.php');
-
- $this->_renderRadarPlotArea();
-
- for($groupID = 0; $groupID < $groupCount; ++$groupID) {
- $this->_renderPlotRadar($groupID);
- }
- } // function _renderRadarChart()
-
-
- private function _renderStockChart($groupCount) {
- require_once('jpgraph_stock.php');
-
- $this->_renderCartesianPlotArea();
-
- for($groupID = 0; $groupID < $groupCount; ++$i) {
- $this->_renderPlotStock($groupID);
- }
- } // function _renderStockChart()
-
-
- private function _renderContourChart($groupCount,$dimensions) {
- require_once('jpgraph_contour.php');
-
- $this->_renderCartesianPlotArea('intint');
-
- for($i = 0; $i < $groupCount; ++$i) {
- $this->_renderPlotContour($i);
- }
- } // function _renderContourChart()
-
-
- private function _renderCombinationChart($groupCount,$dimensions,$outputDestination) {
- require_once('jpgraph_line.php');
- require_once('jpgraph_bar.php');
- require_once('jpgraph_scatter.php');
- require_once('jpgraph_regstat.php');
- require_once('jpgraph_line.php');
-
- $this->_renderCartesianPlotArea();
-
- for($i = 0; $i < $groupCount; ++$i) {
- $dimensions = null;
- $chartType = $this->_chart->getPlotArea()->getPlotGroupByIndex($i)->getPlotType();
- switch ($chartType) {
- case 'area3DChart' :
- $dimensions = '3d';
- case 'areaChart' :
- $this->_renderPlotLine($i,True,True,$dimensions);
- break;
- case 'bar3DChart' :
- $dimensions = '3d';
- case 'barChart' :
- $this->_renderPlotBar($i,$dimensions);
- break;
- case 'line3DChart' :
- $dimensions = '3d';
- case 'lineChart' :
- $this->_renderPlotLine($i,False,True,$dimensions);
- break;
- case 'scatterChart' :
- $this->_renderPlotScatter($i,false);
- break;
- case 'bubbleChart' :
- $this->_renderPlotScatter($i,true);
- break;
- default :
- $this->_graph = null;
- return false;
- }
- }
-
- $this->_renderLegend();
-
- $this->_graph->Stroke($outputDestination);
- return true;
- } // function _renderCombinationChart()
-
-
- public function render($outputDestination) {
- self::$_plotColour = 0;
-
- $groupCount = $this->_chart->getPlotArea()->getPlotGroupCount();
-
- $dimensions = null;
- if ($groupCount == 1) {
- $chartType = $this->_chart->getPlotArea()->getPlotGroupByIndex(0)->getPlotType();
- } else {
- $chartTypes = array();
- for($i = 0; $i < $groupCount; ++$i) {
- $chartTypes[] = $this->_chart->getPlotArea()->getPlotGroupByIndex($i)->getPlotType();
- }
- $chartTypes = array_unique($chartTypes);
- if (count($chartTypes) == 1) {
- $chartType = array_pop($chartTypes);
- } elseif (count($chartTypes) == 0) {
- echo 'Chart is not yet implemented
';
- return false;
- } else {
- return $this->_renderCombinationChart($groupCount,$dimensions,$outputDestination);
- }
- }
-
- switch ($chartType) {
- case 'area3DChart' :
- $dimensions = '3d';
- case 'areaChart' :
- $this->_renderAreaChart($groupCount,$dimensions);
- break;
- case 'bar3DChart' :
- $dimensions = '3d';
- case 'barChart' :
- $this->_renderBarChart($groupCount,$dimensions);
- break;
- case 'line3DChart' :
- $dimensions = '3d';
- case 'lineChart' :
- $this->_renderLineChart($groupCount,$dimensions);
- break;
- case 'pie3DChart' :
- $dimensions = '3d';
- case 'pieChart' :
- $this->_renderPieChart($groupCount,$dimensions,False,False);
- break;
- case 'doughnut3DChart' :
- $dimensions = '3d';
- case 'doughnutChart' :
- $this->_renderPieChart($groupCount,$dimensions,True,True);
- break;
- case 'scatterChart' :
- $this->_renderScatterChart($groupCount);
- break;
- case 'bubbleChart' :
- $this->_renderBubbleChart($groupCount);
- break;
- case 'radarChart' :
- $this->_renderRadarChart($groupCount);
- break;
- case 'surface3DChart' :
- $dimensions = '3d';
- case 'surfaceChart' :
- $this->_renderContourChart($groupCount,$dimensions);
- break;
- case 'stockChart' :
- $this->_renderStockChart($groupCount,$dimensions);
- break;
- default :
- echo $chartType.' is not yet implemented
';
- return false;
- }
- $this->_renderLegend();
-
- $this->_graph->Stroke($outputDestination);
- return true;
- } // function render()
-
-
- /**
- * Create a new PHPExcel_Chart_Renderer_jpgraph
- */
- public function __construct(PHPExcel_Chart $chart)
- {
- $this->_graph = null;
- $this->_chart = $chart;
- } // function __construct()
-
-} // PHPExcel_Chart_Renderer_jpgraph
+ MARK_DIAMOND,
+ 'square' => MARK_SQUARE,
+ 'triangle' => MARK_UTRIANGLE,
+ 'x' => MARK_X,
+ 'star' => MARK_STAR,
+ 'dot' => MARK_FILLEDCIRCLE,
+ 'dash' => MARK_DTRIANGLE,
+ 'circle' => MARK_CIRCLE,
+ 'plus' => MARK_CROSS
+ );
+
+
+ private $_chart = null;
+
+ private $_graph = null;
+
+ private static $_plotColour = 0;
+
+ private static $_plotMark = 0;
+
+
+ private function _formatPointMarker($seriesPlot,$markerID) {
+ $plotMarkKeys = array_keys(self::$_markSet);
+ if (is_null($markerID)) {
+ // Use default plot marker (next marker in the series)
+ self::$_plotMark %= count(self::$_markSet);
+ $seriesPlot->mark->SetType(self::$_markSet[$plotMarkKeys[self::$_plotMark++]]);
+ } elseif ($markerID !== 'none') {
+ // Use specified plot marker (if it exists)
+ if (isset(self::$_markSet[$markerID])) {
+ $seriesPlot->mark->SetType(self::$_markSet[$markerID]);
+ } else {
+ // If the specified plot marker doesn't exist, use default plot marker (next marker in the series)
+ self::$_plotMark %= count(self::$_markSet);
+ $seriesPlot->mark->SetType(self::$_markSet[$plotMarkKeys[self::$_plotMark++]]);
+ }
+ } else {
+ // Hide plot marker
+ $seriesPlot->mark->Hide();
+ }
+ $seriesPlot->mark->SetColor(self::$_colourSet[self::$_plotColour]);
+ $seriesPlot->mark->SetFillColor(self::$_colourSet[self::$_plotColour]);
+ $seriesPlot->SetColor(self::$_colourSet[self::$_plotColour++]);
+
+ return $seriesPlot;
+ } // function _formatPointMarker()
+
+
+ private function _formatDataSetLabels($groupID, $datasetLabels, $labelCount, $rotation = '') {
+ $datasetLabelFormatCode = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex(0)->getFormatCode();
+ if (!is_null($datasetLabelFormatCode)) {
+ // Retrieve any label formatting code
+ $datasetLabelFormatCode = stripslashes($datasetLabelFormatCode);
+ }
+
+ $testCurrentIndex = 0;
+ foreach($datasetLabels as $i => $datasetLabel) {
+ array_reverse($datasetLabel);
+
+ if (is_array($datasetLabel)) {
+ if ($rotation == 'bar') {
+ $datasetLabel = array_reverse($datasetLabel);
+ $datasetLabels[$i] = implode(" ",$datasetLabel);
+ } else {
+ $datasetLabels[$i] = implode("\n",$datasetLabel);
+ }
+ } else {
+ // Format labels according to any formatting code
+ if (!is_null($datasetLabelFormatCode)) {
+ $datasetLabels[$i] = PHPExcel_Style_NumberFormat::toFormattedString($datasetLabel,$datasetLabelFormatCode);
+ }
+ }
+ ++$testCurrentIndex;
+ }
+
+ return $datasetLabels;
+ } // function _formatDataSetLabels()
+
+
+ private function _percentageSumCalculation($groupID,$seriesCount) {
+ // Adjust our values to a percentage value across all series in the group
+ for($i = 0; $i < $seriesCount; ++$i) {
+ if ($i == 0) {
+ $sumValues = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($i)->getDataValues();
+ } else {
+ $nextValues = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($i)->getDataValues();
+ foreach($nextValues as $k => $value) {
+ if (isset($sumValues[$k])) {
+ $sumValues[$k] += $value;
+ } else {
+ $sumValues[$k] = $value;
+ }
+ }
+ }
+ }
+
+ return $sumValues;
+ } // function _percentageSumCalculation()
+
+
+ private function _percentageAdjustValues($dataValues,$sumValues) {
+ foreach($dataValues as $k => $dataValue) {
+ $dataValues[$k] = $dataValue / $sumValues[$k] * 100;
+ }
+
+ return $dataValues;
+ } // function _percentageAdjustValues()
+
+
+ private function _getCaption($captionElement) {
+ // Read any caption
+ $caption = (!is_null($captionElement)) ? $captionElement->getCaption() : NULL;
+ // Test if we have a title caption to display
+ if (!is_null($caption)) {
+ // If we do, it could be a plain string or an array
+ if (is_array($caption)) {
+ // Implode an array to a plain string
+ $caption = implode('',$caption);
+ }
+ }
+ return $caption;
+ } // function _getCaption()
+
+
+ private function _renderTitle() {
+ $title = $this->_getCaption($this->_chart->getTitle());
+ if (!is_null($title)) {
+ $this->_graph->title->Set($title);
+ }
+ } // function _renderTitle()
+
+
+ private function _renderLegend() {
+ $legend = $this->_chart->getLegend();
+ if (!is_null($legend)) {
+ $legendPosition = $legend->getPosition();
+ $legendOverlay = $legend->getOverlay();
+ switch ($legendPosition) {
+ case 'r' :
+ $this->_graph->legend->SetPos(0.01,0.5,'right','center'); // right
+ $this->_graph->legend->SetColumns(1);
+ break;
+ case 'l' :
+ $this->_graph->legend->SetPos(0.01,0.5,'left','center'); // left
+ $this->_graph->legend->SetColumns(1);
+ break;
+ case 't' :
+ $this->_graph->legend->SetPos(0.5,0.01,'center','top'); // top
+ break;
+ case 'b' :
+ $this->_graph->legend->SetPos(0.5,0.99,'center','bottom'); // bottom
+ break;
+ default :
+ $this->_graph->legend->SetPos(0.01,0.01,'right','top'); // top-right
+ $this->_graph->legend->SetColumns(1);
+ break;
+ }
+ } else {
+ $this->_graph->legend->Hide();
+ }
+ } // function _renderLegend()
+
+
+ private function _renderCartesianPlotArea($type='textlin') {
+ $this->_graph = new Graph(self::$_width,self::$_height);
+ $this->_graph->SetScale($type);
+
+ $this->_renderTitle();
+
+ // Rotate for bar rather than column chart
+ $rotation = $this->_chart->getPlotArea()->getPlotGroupByIndex(0)->getPlotDirection();
+ $reverse = ($rotation == 'bar') ? true : false;
+
+ $xAxisLabel = $this->_chart->getXAxisLabel();
+ if (!is_null($xAxisLabel)) {
+ $title = $this->_getCaption($xAxisLabel);
+ if (!is_null($title)) {
+ $this->_graph->xaxis->SetTitle($title,'center');
+ $this->_graph->xaxis->title->SetMargin(35);
+ if ($reverse) {
+ $this->_graph->xaxis->title->SetAngle(90);
+ $this->_graph->xaxis->title->SetMargin(90);
+ }
+ }
+ }
+
+ $yAxisLabel = $this->_chart->getYAxisLabel();
+ if (!is_null($yAxisLabel)) {
+ $title = $this->_getCaption($yAxisLabel);
+ if (!is_null($title)) {
+ $this->_graph->yaxis->SetTitle($title,'center');
+ if ($reverse) {
+ $this->_graph->yaxis->title->SetAngle(0);
+ $this->_graph->yaxis->title->SetMargin(-55);
+ }
+ }
+ }
+ } // function _renderCartesianPlotArea()
+
+
+ private function _renderPiePlotArea($doughnut = False) {
+ $this->_graph = new PieGraph(self::$_width,self::$_height);
+
+ $this->_renderTitle();
+ } // function _renderPiePlotArea()
+
+
+ private function _renderRadarPlotArea() {
+ $this->_graph = new RadarGraph(self::$_width,self::$_height);
+ $this->_graph->SetScale('lin');
+
+ $this->_renderTitle();
+ } // function _renderRadarPlotArea()
+
+
+ private function _renderPlotLine($groupID, $filled = false, $combination = false, $dimensions = '2d') {
+ $grouping = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotGrouping();
+
+ $labelCount = count($this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex(0)->getPointCount());
+ if ($labelCount > 0) {
+ $datasetLabels = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex(0)->getDataValues();
+ $datasetLabels = $this->_formatDataSetLabels($groupID, $datasetLabels, $labelCount);
+ $this->_graph->xaxis->SetTickLabels($datasetLabels);
+ }
+
+ $seriesCount = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotSeriesCount();
+ $seriesPlots = array();
+ if ($grouping == 'percentStacked') {
+ $sumValues = $this->_percentageSumCalculation($groupID,$seriesCount);
+ }
+
+ // Loop through each data series in turn
+ for($i = 0; $i < $seriesCount; ++$i) {
+ $dataValues = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($i)->getDataValues();
+ $marker = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($i)->getPointMarker();
+
+ if ($grouping == 'percentStacked') {
+ $dataValues = $this->_percentageAdjustValues($dataValues,$sumValues);
+ }
+
+ // Fill in any missing values in the $dataValues array
+ $testCurrentIndex = 0;
+ foreach($dataValues as $k => $dataValue) {
+ while($k != $testCurrentIndex) {
+ $dataValues[$testCurrentIndex] = null;
+ ++$testCurrentIndex;
+ }
+ ++$testCurrentIndex;
+ }
+
+ $seriesPlot = new LinePlot($dataValues);
+ if ($combination) {
+ $seriesPlot->SetBarCenter();
+ }
+
+ if ($filled) {
+ $seriesPlot->SetFilled(true);
+ $seriesPlot->SetColor('black');
+ $seriesPlot->SetFillColor(self::$_colourSet[self::$_plotColour++]);
+ } else {
+ // Set the appropriate plot marker
+ $this->_formatPointMarker($seriesPlot,$marker);
+ }
+ $dataLabel = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotLabelByIndex($i)->getDataValue();
+ $seriesPlot->SetLegend($dataLabel);
+
+ $seriesPlots[] = $seriesPlot;
+ }
+
+ if ($grouping == 'standard') {
+ $groupPlot = $seriesPlots;
+ } else {
+ $groupPlot = new AccLinePlot($seriesPlots);
+ }
+ $this->_graph->Add($groupPlot);
+ } // function _renderPlotLine()
+
+
+ private function _renderPlotBar($groupID, $dimensions = '2d') {
+ $rotation = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotDirection();
+ // Rotate for bar rather than column chart
+ if (($groupID == 0) && ($rotation == 'bar')) {
+ $this->_graph->Set90AndMargin();
+ }
+ $grouping = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotGrouping();
+
+ $labelCount = count($this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex(0)->getPointCount());
+ if ($labelCount > 0) {
+ $datasetLabels = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex(0)->getDataValues();
+ $datasetLabels = $this->_formatDataSetLabels($groupID, $datasetLabels, $labelCount, $rotation);
+ // Rotate for bar rather than column chart
+ if ($rotation == 'bar') {
+ $datasetLabels = array_reverse($datasetLabels);
+ $this->_graph->yaxis->SetPos('max');
+ $this->_graph->yaxis->SetLabelAlign('center','top');
+ $this->_graph->yaxis->SetLabelSide(SIDE_RIGHT);
+ }
+ $this->_graph->xaxis->SetTickLabels($datasetLabels);
+ }
+
+
+ $seriesCount = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotSeriesCount();
+ $seriesPlots = array();
+ if ($grouping == 'percentStacked') {
+ $sumValues = $this->_percentageSumCalculation($groupID,$seriesCount);
+ }
+
+ // Loop through each data series in turn
+ for($j = 0; $j < $seriesCount; ++$j) {
+ $dataValues = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($j)->getDataValues();
+ if ($grouping == 'percentStacked') {
+ $dataValues = $this->_percentageAdjustValues($dataValues,$sumValues);
+ }
+
+ // Fill in any missing values in the $dataValues array
+ $testCurrentIndex = 0;
+ foreach($dataValues as $k => $dataValue) {
+ while($k != $testCurrentIndex) {
+ $dataValues[$testCurrentIndex] = null;
+ ++$testCurrentIndex;
+ }
+ ++$testCurrentIndex;
+ }
+
+ // Reverse the $dataValues order for bar rather than column chart
+ if ($rotation == 'bar') {
+ $dataValues = array_reverse($dataValues);
+ }
+ $seriesPlot = new BarPlot($dataValues);
+ $seriesPlot->SetColor('black');
+ $seriesPlot->SetFillColor(self::$_colourSet[self::$_plotColour++]);
+ if ($dimensions == '3d') {
+ $seriesPlot->SetShadow();
+ }
+ if (!$this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotLabelByIndex($j)) {
+ $dataLabel = '';
+ } else {
+ $dataLabel = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotLabelByIndex($j)->getDataValue();
+ }
+ $seriesPlot->SetLegend($dataLabel);
+
+ $seriesPlots[] = $seriesPlot;
+ }
+ // Reverse the plot order for bar rather than column chart
+ if (($rotation == 'bar') && (!($grouping == 'percentStacked'))) {
+ $seriesPlots = array_reverse($seriesPlots);
+ }
+
+ if ($grouping == 'clustered') {
+ $groupPlot = new GroupBarPlot($seriesPlots);
+ } elseif ($grouping == 'standard') {
+ $groupPlot = new GroupBarPlot($seriesPlots);
+ } else {
+ $groupPlot = new AccBarPlot($seriesPlots);
+ if ($dimensions == '3d') {
+ $groupPlot->SetShadow();
+ }
+ }
+
+ $this->_graph->Add($groupPlot);
+ } // function _renderPlotBar()
+
+
+ private function _renderPlotScatter($groupID,$bubble) {
+ $grouping = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotGrouping();
+ $scatterStyle = $bubbleSize = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotStyle();
+
+ $seriesCount = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotSeriesCount();
+ $seriesPlots = array();
+
+ // Loop through each data series in turn
+ for($i = 0; $i < $seriesCount; ++$i) {
+ $dataValuesY = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex($i)->getDataValues();
+ $dataValuesX = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($i)->getDataValues();
+
+ foreach($dataValuesY as $k => $dataValueY) {
+ $dataValuesY[$k] = $k;
+ }
+
+ $seriesPlot = new ScatterPlot($dataValuesX,$dataValuesY);
+ if ($scatterStyle == 'lineMarker') {
+ $seriesPlot->SetLinkPoints();
+ $seriesPlot->link->SetColor(self::$_colourSet[self::$_plotColour]);
+ } elseif ($scatterStyle == 'smoothMarker') {
+ $spline = new Spline($dataValuesY,$dataValuesX);
+ list($splineDataY,$splineDataX) = $spline->Get(count($dataValuesX) * self::$_width / 20);
+ $lplot = new LinePlot($splineDataX,$splineDataY);
+ $lplot->SetColor(self::$_colourSet[self::$_plotColour]);
+
+ $this->_graph->Add($lplot);
+ }
+
+ if ($bubble) {
+ $this->_formatPointMarker($seriesPlot,'dot');
+ $seriesPlot->mark->SetColor('black');
+ $seriesPlot->mark->SetSize($bubbleSize);
+ } else {
+ $marker = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($i)->getPointMarker();
+ $this->_formatPointMarker($seriesPlot,$marker);
+ }
+ $dataLabel = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotLabelByIndex($i)->getDataValue();
+ $seriesPlot->SetLegend($dataLabel);
+
+ $this->_graph->Add($seriesPlot);
+ }
+ } // function _renderPlotScatter()
+
+
+ private function _renderPlotRadar($groupID) {
+ $radarStyle = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotStyle();
+
+ $seriesCount = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotSeriesCount();
+ $seriesPlots = array();
+
+ // Loop through each data series in turn
+ for($i = 0; $i < $seriesCount; ++$i) {
+ $dataValuesY = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex($i)->getDataValues();
+ $dataValuesX = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($i)->getDataValues();
+ $marker = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($i)->getPointMarker();
+
+ $dataValues = array();
+ foreach($dataValuesY as $k => $dataValueY) {
+ $dataValues[$k] = implode(' ',array_reverse($dataValueY));
+ }
+ $tmp = array_shift($dataValues);
+ $dataValues[] = $tmp;
+ $tmp = array_shift($dataValuesX);
+ $dataValuesX[] = $tmp;
+
+ $this->_graph->SetTitles(array_reverse($dataValues));
+
+ $seriesPlot = new RadarPlot(array_reverse($dataValuesX));
+
+ $dataLabel = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotLabelByIndex($i)->getDataValue();
+ $seriesPlot->SetColor(self::$_colourSet[self::$_plotColour++]);
+ if ($radarStyle == 'filled') {
+ $seriesPlot->SetFillColor(self::$_colourSet[self::$_plotColour]);
+ }
+ $this->_formatPointMarker($seriesPlot,$marker);
+ $seriesPlot->SetLegend($dataLabel);
+
+ $this->_graph->Add($seriesPlot);
+ }
+ } // function _renderPlotRadar()
+
+
+ private function _renderPlotContour($groupID) {
+ $contourStyle = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotStyle();
+
+ $seriesCount = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotSeriesCount();
+ $seriesPlots = array();
+
+ $dataValues = array();
+ // Loop through each data series in turn
+ for($i = 0; $i < $seriesCount; ++$i) {
+ $dataValuesY = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex($i)->getDataValues();
+ $dataValuesX = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($i)->getDataValues();
+
+ $dataValues[$i] = $dataValuesX;
+ }
+ $seriesPlot = new ContourPlot($dataValues);
+
+ $this->_graph->Add($seriesPlot);
+ } // function _renderPlotContour()
+
+
+ private function _renderPlotStock($groupID) {
+ $seriesCount = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotSeriesCount();
+ $plotOrder = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotOrder();
+ $seriesPlots = array();
+
+ $dataValues = array();
+ // Loop through each data series in turn
+ for($i = 0; $i < $seriesCount; ++$i) {
+ $dataValuesY = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex($i)->getDataValues();
+ $dataValuesX = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($i)->getDataValues();
+
+ foreach($dataValuesX as $j => $dataValueX)
+ $dataValues[$j][$plotOrder[$i]] = $dataValueX;
+ }
+
+ $seriesPlot = new StockPlot($dataValues);
+
+ $this->_graph->Add($seriesPlot);
+ } // function _renderPlotStock()
+
+
+ private function _renderAreaChart($groupCount, $dimensions = '2d') {
+ require_once('jpgraph_line.php');
+
+ $this->_renderCartesianPlotArea();
+
+ for($i = 0; $i < $groupCount; ++$i) {
+ $this->_renderPlotLine($i,True,False,$dimensions);
+ }
+ } // function _renderAreaChart()
+
+
+ private function _renderLineChart($groupCount, $dimensions = '2d') {
+ require_once('jpgraph_line.php');
+
+ $this->_renderCartesianPlotArea();
+
+ for($i = 0; $i < $groupCount; ++$i) {
+ $this->_renderPlotLine($i,False,False,$dimensions);
+ }
+ } // function _renderLineChart()
+
+
+ private function _renderBarChart($groupCount, $dimensions = '2d') {
+ require_once('jpgraph_bar.php');
+
+ $this->_renderCartesianPlotArea();
+
+ for($i = 0; $i < $groupCount; ++$i) {
+ $this->_renderPlotBar($i,$dimensions);
+ }
+ } // function _renderBarChart()
+
+
+ private function _renderScatterChart($groupCount) {
+ require_once('jpgraph_scatter.php');
+ require_once('jpgraph_regstat.php');
+ require_once('jpgraph_line.php');
+
+ $this->_renderCartesianPlotArea('linlin');
+
+ for($i = 0; $i < $groupCount; ++$i) {
+ $this->_renderPlotScatter($i,false);
+ }
+ } // function _renderScatterChart()
+
+
+ private function _renderBubbleChart($groupCount) {
+ require_once('jpgraph_scatter.php');
+
+ $this->_renderCartesianPlotArea('linlin');
+
+ for($i = 0; $i < $groupCount; ++$i) {
+ $this->_renderPlotScatter($i,true);
+ }
+ } // function _renderBubbleChart()
+
+
+ private function _renderPieChart($groupCount, $dimensions = '2d', $doughnut = False, $multiplePlots = False) {
+ require_once('jpgraph_pie.php');
+ if ($dimensions == '3d') {
+ require_once('jpgraph_pie3d.php');
+ }
+
+ $this->_renderPiePlotArea($doughnut);
+
+ $iLimit = ($multiplePlots) ? $groupCount : 1;
+ for($groupID = 0; $groupID < $iLimit; ++$groupID) {
+ $grouping = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotGrouping();
+ $exploded = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotStyle();
+ if ($groupID == 0) {
+ $labelCount = count($this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex(0)->getPointCount());
+ if ($labelCount > 0) {
+ $datasetLabels = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex(0)->getDataValues();
+ $datasetLabels = $this->_formatDataSetLabels($groupID, $datasetLabels, $labelCount);
+ }
+ }
+
+ $seriesCount = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotSeriesCount();
+ $seriesPlots = array();
+ // For pie charts, we only display the first series: doughnut charts generally display all series
+ $jLimit = ($multiplePlots) ? $seriesCount : 1;
+ // Loop through each data series in turn
+ for($j = 0; $j < $jLimit; ++$j) {
+ $dataValues = $this->_chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($j)->getDataValues();
+
+ // Fill in any missing values in the $dataValues array
+ $testCurrentIndex = 0;
+ foreach($dataValues as $k => $dataValue) {
+ while($k != $testCurrentIndex) {
+ $dataValues[$testCurrentIndex] = null;
+ ++$testCurrentIndex;
+ }
+ ++$testCurrentIndex;
+ }
+
+ if ($dimensions == '3d') {
+ $seriesPlot = new PiePlot3D($dataValues);
+ } else {
+ if ($doughnut) {
+ $seriesPlot = new PiePlotC($dataValues);
+ } else {
+ $seriesPlot = new PiePlot($dataValues);
+ }
+ }
+
+ if ($multiplePlots) {
+ $seriesPlot->SetSize(($jLimit-$j) / ($jLimit * 4));
+ }
+
+ if ($doughnut) {
+ $seriesPlot->SetMidColor('white');
+ }
+
+ $seriesPlot->SetColor(self::$_colourSet[self::$_plotColour++]);
+ if (count($datasetLabels) > 0)
+ $seriesPlot->SetLabels(array_fill(0,count($datasetLabels),''));
+ if ($dimensions != '3d') {
+ $seriesPlot->SetGuideLines(false);
+ }
+ if ($j == 0) {
+ if ($exploded) {
+ $seriesPlot->ExplodeAll();
+ }
+ $seriesPlot->SetLegends($datasetLabels);
+ }
+
+ $this->_graph->Add($seriesPlot);
+ }
+ }
+ } // function _renderPieChart()
+
+
+ private function _renderRadarChart($groupCount) {
+ require_once('jpgraph_radar.php');
+
+ $this->_renderRadarPlotArea();
+
+ for($groupID = 0; $groupID < $groupCount; ++$groupID) {
+ $this->_renderPlotRadar($groupID);
+ }
+ } // function _renderRadarChart()
+
+
+ private function _renderStockChart($groupCount) {
+ require_once('jpgraph_stock.php');
+
+ $this->_renderCartesianPlotArea();
+
+ for($groupID = 0; $groupID < $groupCount; ++$i) {
+ $this->_renderPlotStock($groupID);
+ }
+ } // function _renderStockChart()
+
+
+ private function _renderContourChart($groupCount,$dimensions) {
+ require_once('jpgraph_contour.php');
+
+ $this->_renderCartesianPlotArea('intint');
+
+ for($i = 0; $i < $groupCount; ++$i) {
+ $this->_renderPlotContour($i);
+ }
+ } // function _renderContourChart()
+
+
+ private function _renderCombinationChart($groupCount,$dimensions,$outputDestination) {
+ require_once('jpgraph_line.php');
+ require_once('jpgraph_bar.php');
+ require_once('jpgraph_scatter.php');
+ require_once('jpgraph_regstat.php');
+ require_once('jpgraph_line.php');
+
+ $this->_renderCartesianPlotArea();
+
+ for($i = 0; $i < $groupCount; ++$i) {
+ $dimensions = null;
+ $chartType = $this->_chart->getPlotArea()->getPlotGroupByIndex($i)->getPlotType();
+ switch ($chartType) {
+ case 'area3DChart' :
+ $dimensions = '3d';
+ case 'areaChart' :
+ $this->_renderPlotLine($i,True,True,$dimensions);
+ break;
+ case 'bar3DChart' :
+ $dimensions = '3d';
+ case 'barChart' :
+ $this->_renderPlotBar($i,$dimensions);
+ break;
+ case 'line3DChart' :
+ $dimensions = '3d';
+ case 'lineChart' :
+ $this->_renderPlotLine($i,False,True,$dimensions);
+ break;
+ case 'scatterChart' :
+ $this->_renderPlotScatter($i,false);
+ break;
+ case 'bubbleChart' :
+ $this->_renderPlotScatter($i,true);
+ break;
+ default :
+ $this->_graph = null;
+ return false;
+ }
+ }
+
+ $this->_renderLegend();
+
+ $this->_graph->Stroke($outputDestination);
+ return true;
+ } // function _renderCombinationChart()
+
+
+ public function render($outputDestination) {
+ self::$_plotColour = 0;
+
+ $groupCount = $this->_chart->getPlotArea()->getPlotGroupCount();
+
+ $dimensions = null;
+ if ($groupCount == 1) {
+ $chartType = $this->_chart->getPlotArea()->getPlotGroupByIndex(0)->getPlotType();
+ } else {
+ $chartTypes = array();
+ for($i = 0; $i < $groupCount; ++$i) {
+ $chartTypes[] = $this->_chart->getPlotArea()->getPlotGroupByIndex($i)->getPlotType();
+ }
+ $chartTypes = array_unique($chartTypes);
+ if (count($chartTypes) == 1) {
+ $chartType = array_pop($chartTypes);
+ } elseif (count($chartTypes) == 0) {
+ echo 'Chart is not yet implemented
';
+ return false;
+ } else {
+ return $this->_renderCombinationChart($groupCount,$dimensions,$outputDestination);
+ }
+ }
+
+ switch ($chartType) {
+ case 'area3DChart' :
+ $dimensions = '3d';
+ case 'areaChart' :
+ $this->_renderAreaChart($groupCount,$dimensions);
+ break;
+ case 'bar3DChart' :
+ $dimensions = '3d';
+ case 'barChart' :
+ $this->_renderBarChart($groupCount,$dimensions);
+ break;
+ case 'line3DChart' :
+ $dimensions = '3d';
+ case 'lineChart' :
+ $this->_renderLineChart($groupCount,$dimensions);
+ break;
+ case 'pie3DChart' :
+ $dimensions = '3d';
+ case 'pieChart' :
+ $this->_renderPieChart($groupCount,$dimensions,False,False);
+ break;
+ case 'doughnut3DChart' :
+ $dimensions = '3d';
+ case 'doughnutChart' :
+ $this->_renderPieChart($groupCount,$dimensions,True,True);
+ break;
+ case 'scatterChart' :
+ $this->_renderScatterChart($groupCount);
+ break;
+ case 'bubbleChart' :
+ $this->_renderBubbleChart($groupCount);
+ break;
+ case 'radarChart' :
+ $this->_renderRadarChart($groupCount);
+ break;
+ case 'surface3DChart' :
+ $dimensions = '3d';
+ case 'surfaceChart' :
+ $this->_renderContourChart($groupCount,$dimensions);
+ break;
+ case 'stockChart' :
+ $this->_renderStockChart($groupCount,$dimensions);
+ break;
+ default :
+ echo $chartType.' is not yet implemented
';
+ return false;
+ }
+ $this->_renderLegend();
+
+ $this->_graph->Stroke($outputDestination);
+ return true;
+ } // function render()
+
+
+ /**
+ * Create a new PHPExcel_Chart_Renderer_jpgraph
+ */
+ public function __construct(PHPExcel_Chart $chart)
+ {
+ $this->_graph = null;
+ $this->_chart = $chart;
+ } // function __construct()
+
+} // PHPExcel_Chart_Renderer_jpgraph
diff --git a/htdocs/includes/phpexcel/PHPExcel/Reader/Excel2007.php b/htdocs/includes/phpexcel/PHPExcel/Reader/Excel2007.php
index 0a0ae35eec5..fbb9158ebd3 100644
--- a/htdocs/includes/phpexcel/PHPExcel/Reader/Excel2007.php
+++ b/htdocs/includes/phpexcel/PHPExcel/Reader/Excel2007.php
@@ -53,14 +53,14 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
*/
private $_readDataOnly = FALSE;
- /**
- * Read charts that are defined in the workbook?
- * Identifies whether the Reader should read the definitions for any charts that exist in the workbook;
- *
- * @var boolean
- */
- private $_includeCharts = FALSE;
-
+ /**
+ * Read charts that are defined in the workbook?
+ * Identifies whether the Reader should read the definitions for any charts that exist in the workbook;
+ *
+ * @var boolean
+ */
+ private $_includeCharts = FALSE;
+
/**
* Restrict which sheets should be loaded?
* This property holds an array of worksheet names to be loaded. If null, then all worksheets will be loaded.
@@ -91,15 +91,15 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
private static $_theme = NULL;
- /**
- * Create a new PHPExcel_Reader_Excel2007 instance
- */
- public function __construct() {
- $this->_readFilter = new PHPExcel_Reader_DefaultReadFilter();
- $this->_referenceHelper = PHPExcel_ReferenceHelper::getInstance();
- }
-
-
+ /**
+ * Create a new PHPExcel_Reader_Excel2007 instance
+ */
+ public function __construct() {
+ $this->_readFilter = new PHPExcel_Reader_DefaultReadFilter();
+ $this->_referenceHelper = PHPExcel_ReferenceHelper::getInstance();
+ }
+
+
/**
* Read data only?
* If this is true, then the Reader will only read data values for cells, it will not read any formatting information.
@@ -111,7 +111,7 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
return $this->_readDataOnly;
}
-
+
/**
* Set read data only
* Set to true, to advise the Reader only to read data values for cells, and to ignore any formatting information.
@@ -125,37 +125,37 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
$this->_readDataOnly = $pValue;
return $this;
}
-
- /**
- * Read charts in workbook?
- * If this is true, then the Reader will include any charts that exist in the workbook.
- * Note that a ReadDataOnly value of false overrides, and charts won't be read regardless of the IncludeCharts value.
- * If false (the default) it will ignore any charts defined in the workbook file.
- *
- * @return boolean
- */
- public function getIncludeCharts() {
- return $this->_includeCharts;
- }
-
-
- /**
- * Set read charts in workbook
- * Set to true, to advise the Reader to include any charts that exist in the workbook.
- * Note that a ReadDataOnly value of false overrides, and charts won't be read regardless of the IncludeCharts value.
- * Set to false (the default) to discard charts.
- *
- * @param boolean $pValue
- *
- * @return PHPExcel_Reader_Excel2007
- */
- public function setIncludeCharts($pValue = FALSE) {
- $this->_includeCharts = (boolean) $pValue;
- return $this;
- }
-
-
+
+ /**
+ * Read charts in workbook?
+ * If this is true, then the Reader will include any charts that exist in the workbook.
+ * Note that a ReadDataOnly value of false overrides, and charts won't be read regardless of the IncludeCharts value.
+ * If false (the default) it will ignore any charts defined in the workbook file.
+ *
+ * @return boolean
+ */
+ public function getIncludeCharts() {
+ return $this->_includeCharts;
+ }
+
+
+ /**
+ * Set read charts in workbook
+ * Set to true, to advise the Reader to include any charts that exist in the workbook.
+ * Note that a ReadDataOnly value of false overrides, and charts won't be read regardless of the IncludeCharts value.
+ * Set to false (the default) to discard charts.
+ *
+ * @param boolean $pValue
+ *
+ * @return PHPExcel_Reader_Excel2007
+ */
+ public function setIncludeCharts($pValue = FALSE) {
+ $this->_includeCharts = (boolean) $pValue;
+ return $this;
+ }
+
+
/**
* Get which sheets to load
* Returns either an array of worksheet names (the list of worksheets that should be loaded), or a null
@@ -168,7 +168,7 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
return $this->_loadSheetsOnly;
}
-
+
/**
* Set which sheets to load
*
@@ -185,7 +185,7 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
return $this;
}
-
+
/**
* Set all sheets to load
* Tells the Reader to load all worksheets from the workbook.
@@ -198,7 +198,7 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
return $this;
}
-
+
/**
* Read filter
*
@@ -208,7 +208,7 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
return $this->_readFilter;
}
-
+
/**
* Set read filter
*
@@ -264,82 +264,82 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
return $xl;
}
-
- /**
- * Return worksheet info (Name, Last Column Letter, Last Column Index, Total Rows, Total Columns)
- *
- * @param string $pFilename
- * @throws Exception
- */
- public function listWorksheetInfo($pFilename)
- {
- // Check if file exists
- if (!file_exists($pFilename)) {
- throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
- }
-
- $worksheetInfo = array();
-
- $zip = new ZipArchive;
- $zip->open($pFilename);
-
- $rels = simplexml_load_string($this->_getFromZipArchive($zip, "_rels/.rels")); //~ http://schemas.openxmlformats.org/package/2006/relationships");
- foreach ($rels->Relationship as $rel) {
- if ($rel["Type"] == "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument") {
- $dir = dirname($rel["Target"]);
- $relsWorkbook = simplexml_load_string($this->_getFromZipArchive($zip, "$dir/_rels/" . basename($rel["Target"]) . ".rels")); //~ http://schemas.openxmlformats.org/package/2006/relationships");
- $relsWorkbook->registerXPathNamespace("rel", "http://schemas.openxmlformats.org/package/2006/relationships");
-
- $worksheets = array();
- foreach ($relsWorkbook->Relationship as $ele) {
- if ($ele["Type"] == "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet") {
- $worksheets[(string) $ele["Id"]] = $ele["Target"];
- }
- }
-
- $xmlWorkbook = simplexml_load_string($this->_getFromZipArchive($zip, "{$rel['Target']}")); //~ http://schemas.openxmlformats.org/spreadsheetml/2006/main");
- if ($xmlWorkbook->sheets) {
- $dir = dirname($rel["Target"]);
- foreach ($xmlWorkbook->sheets->sheet as $eleSheet) {
- $tmpInfo = array();
- $tmpInfo['worksheetName'] = (string) $eleSheet["name"];
- $tmpInfo['lastColumnLetter'] = 'A';
- $tmpInfo['lastColumnIndex'] = 0;
- $tmpInfo['totalRows'] = 0;
- $tmpInfo['totalColumns'] = 0;
-
- $fileWorksheet = $worksheets[(string) self::array_item($eleSheet->attributes("http://schemas.openxmlformats.org/officeDocument/2006/relationships"), "id")];
- $xmlSheet = simplexml_load_string($this->_getFromZipArchive($zip, "$dir/$fileWorksheet")); //~ http://schemas.openxmlformats.org/spreadsheetml/2006/main");
- if ($xmlSheet && $xmlSheet->sheetData && $xmlSheet->sheetData->row) {
- foreach ($xmlSheet->sheetData->row as $row) {
- foreach ($row->c as $c) {
- $r = (string) $c["r"];
- $coordinates = PHPExcel_Cell::coordinateFromString($r);
-
- $rowIndex = $coordinates[1];
- $columnIndex = PHPExcel_Cell::columnIndexFromString($coordinates[0]) - 1;
-
- $tmpInfo['totalRows'] = max($tmpInfo['totalRows'], $rowIndex);
- $tmpInfo['lastColumnIndex'] = max($tmpInfo['lastColumnIndex'], $columnIndex);
- }
- }
- }
-
- $tmpInfo['lastColumnLetter'] = PHPExcel_Cell::stringFromColumnIndex($tmpInfo['lastColumnIndex']);
- $tmpInfo['totalColumns'] = $tmpInfo['lastColumnIndex'] + 1;
-
- $worksheetInfo[] = $tmpInfo;
- }
- }
- }
- }
-
- $zip->close();
-
- return $worksheetInfo;
- }
-
-
+
+ /**
+ * Return worksheet info (Name, Last Column Letter, Last Column Index, Total Rows, Total Columns)
+ *
+ * @param string $pFilename
+ * @throws Exception
+ */
+ public function listWorksheetInfo($pFilename)
+ {
+ // Check if file exists
+ if (!file_exists($pFilename)) {
+ throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
+ }
+
+ $worksheetInfo = array();
+
+ $zip = new ZipArchive;
+ $zip->open($pFilename);
+
+ $rels = simplexml_load_string($this->_getFromZipArchive($zip, "_rels/.rels")); //~ http://schemas.openxmlformats.org/package/2006/relationships");
+ foreach ($rels->Relationship as $rel) {
+ if ($rel["Type"] == "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument") {
+ $dir = dirname($rel["Target"]);
+ $relsWorkbook = simplexml_load_string($this->_getFromZipArchive($zip, "$dir/_rels/" . basename($rel["Target"]) . ".rels")); //~ http://schemas.openxmlformats.org/package/2006/relationships");
+ $relsWorkbook->registerXPathNamespace("rel", "http://schemas.openxmlformats.org/package/2006/relationships");
+
+ $worksheets = array();
+ foreach ($relsWorkbook->Relationship as $ele) {
+ if ($ele["Type"] == "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet") {
+ $worksheets[(string) $ele["Id"]] = $ele["Target"];
+ }
+ }
+
+ $xmlWorkbook = simplexml_load_string($this->_getFromZipArchive($zip, "{$rel['Target']}")); //~ http://schemas.openxmlformats.org/spreadsheetml/2006/main");
+ if ($xmlWorkbook->sheets) {
+ $dir = dirname($rel["Target"]);
+ foreach ($xmlWorkbook->sheets->sheet as $eleSheet) {
+ $tmpInfo = array();
+ $tmpInfo['worksheetName'] = (string) $eleSheet["name"];
+ $tmpInfo['lastColumnLetter'] = 'A';
+ $tmpInfo['lastColumnIndex'] = 0;
+ $tmpInfo['totalRows'] = 0;
+ $tmpInfo['totalColumns'] = 0;
+
+ $fileWorksheet = $worksheets[(string) self::array_item($eleSheet->attributes("http://schemas.openxmlformats.org/officeDocument/2006/relationships"), "id")];
+ $xmlSheet = simplexml_load_string($this->_getFromZipArchive($zip, "$dir/$fileWorksheet")); //~ http://schemas.openxmlformats.org/spreadsheetml/2006/main");
+ if ($xmlSheet && $xmlSheet->sheetData && $xmlSheet->sheetData->row) {
+ foreach ($xmlSheet->sheetData->row as $row) {
+ foreach ($row->c as $c) {
+ $r = (string) $c["r"];
+ $coordinates = PHPExcel_Cell::coordinateFromString($r);
+
+ $rowIndex = $coordinates[1];
+ $columnIndex = PHPExcel_Cell::columnIndexFromString($coordinates[0]) - 1;
+
+ $tmpInfo['totalRows'] = max($tmpInfo['totalRows'], $rowIndex);
+ $tmpInfo['lastColumnIndex'] = max($tmpInfo['lastColumnIndex'], $columnIndex);
+ }
+ }
+ }
+
+ $tmpInfo['lastColumnLetter'] = PHPExcel_Cell::stringFromColumnIndex($tmpInfo['lastColumnIndex']);
+ $tmpInfo['totalColumns'] = $tmpInfo['lastColumnIndex'] + 1;
+
+ $worksheetInfo[] = $tmpInfo;
+ }
+ }
+ }
+ }
+
+ $zip->close();
+
+ return $worksheetInfo;
+ }
+
+
private static function _castToBool($c) {
// echo 'Initial Cast to Boolean
';
$value = isset($c->v) ? (string) $c->v : NULL;
@@ -353,19 +353,19 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
return $value;
} // function _castToBool()
-
+
private static function _castToError($c) {
// echo 'Initial Cast to Error
';
return isset($c->v) ? (string) $c->v : NULL;
} // function _castToError()
-
+
private static function _castToString($c) {
// echo 'Initial Cast to String
';
return isset($c->v) ? (string) $c->v : NULL;
} // function _castToString()
-
+
private function _castToFormula($c,$r,&$cellDataType,&$value,&$calculatedValue,&$sharedFormulas,$castBaseType) {
// echo 'Formula
';
// echo '$c->f is '.$c->f.'
';
@@ -414,7 +414,7 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
}
}
-
+
public function _getFromZipArchive(ZipArchive $archive, $fileName = '')
{
// Root-relative paths
@@ -434,7 +434,7 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
return $contents;
}
-
+
/**
* Reads names of the worksheets from a file, without parsing the whole file to a PHPExcel object
*
@@ -510,7 +510,7 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
$xmlThemeName = $xmlTheme->attributes();
$xmlTheme = $xmlTheme->children("http://schemas.openxmlformats.org/drawingml/2006/main");
$themeName = (string)$xmlThemeName['name'];
-
+
$colourScheme = $xmlTheme->themeElements->clrScheme->attributes();
$colourSchemeName = (string)$colourScheme['name'];
$colourScheme = $xmlTheme->themeElements->clrScheme->children("http://schemas.openxmlformats.org/drawingml/2006/main");
@@ -689,7 +689,7 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
$dxfs = array();
if (!$this->_readDataOnly && $xmlStyles) {
- // Conditional Styles
+ // Conditional Styles
if ($xmlStyles->dxfs) {
foreach ($xmlStyles->dxfs->dxf as $dxf) {
$style = new PHPExcel_Style(FALSE, TRUE);
@@ -697,7 +697,7 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
$dxfs[] = $style;
}
}
- // Cell Styles
+ // Cell Styles
if ($xmlStyles->cellStyles) {
foreach ($xmlStyles->cellStyles->cellStyle as $cellStyle) {
if (intval($cellStyle['builtinId']) == 0) {
@@ -751,10 +751,10 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
// Load sheet
$docSheet = $excel->createSheet();
- // Use false for $updateFormulaCellReferences to prevent adjustment of worksheet
- // references in formula cells... during the load, all formulae should be correct,
- // and we're simply bringing the worksheet name in line with the formula, not the
- // reverse
+ // Use false for $updateFormulaCellReferences to prevent adjustment of worksheet
+ // references in formula cells... during the load, all formulae should be correct,
+ // and we're simply bringing the worksheet name in line with the formula, not the
+ // reverse
$docSheet->setTitle((string) $eleSheet["name"],false);
$fileWorksheet = $worksheets[(string) self::array_item($eleSheet->attributes("http://schemas.openxmlformats.org/officeDocument/2006/relationships"), "id")];
$xmlSheet = simplexml_load_string($this->_getFromZipArchive($zip, "$dir/$fileWorksheet")); //~ http://schemas.openxmlformats.org/spreadsheetml/2006/main");
@@ -774,10 +774,10 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
$docSheet->getSheetView()->setZoomScaleNormal( intval($xmlSheet->sheetViews->sheetView['zoomScaleNormal']) );
}
- if (isset($xmlSheet->sheetViews->sheetView['view'])) {
- $docSheet->getSheetView()->setView((string) $xmlSheet->sheetViews->sheetView['view']);
- }
-
+ if (isset($xmlSheet->sheetViews->sheetView['view'])) {
+ $docSheet->getSheetView()->setView((string) $xmlSheet->sheetViews->sheetView['view']);
+ }
+
if (isset($xmlSheet->sheetViews->sheetView['showGridLines'])) {
$docSheet->setShowGridLines((string)$xmlSheet->sheetViews->sheetView['showGridLines'] ? true : false);
}
@@ -855,9 +855,9 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
if (isset($xmlSheet->sheetFormatPr['defaultColWidth'])) {
$docSheet->getDefaultColumnDimension()->setWidth( (float)$xmlSheet->sheetFormatPr['defaultColWidth'] );
}
- if (isset($xmlSheet->sheetFormatPr['zeroHeight']) &&
- ((string)$xmlSheet->sheetFormatPr['zeroHeight'] == '1')) {
- $docSheet->getDefaultRowDimension()->setzeroHeight(true);
+ if (isset($xmlSheet->sheetFormatPr['zeroHeight']) &&
+ ((string)$xmlSheet->sheetFormatPr['zeroHeight'] == '1')) {
+ $docSheet->getDefaultRowDimension()->setzeroHeight(true);
}
}
@@ -965,11 +965,11 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
} else {
// Formula
$this->_castToFormula($c,$r,$cellDataType,$value,$calculatedValue,$sharedFormulas,'_castToBool');
- if (isset($c->f['t'])) {
- $att = array();
- $att = $c->f;
- $docSheet->getCell($r)->setFormulaAttributes($att);
- }
+ if (isset($c->f['t'])) {
+ $att = array();
+ $att = $c->f;
+ $docSheet->getCell($r)->setFormulaAttributes($att);
+ }
// echo '$calculatedValue = '.$calculatedValue.'
';
}
break;
@@ -1086,7 +1086,7 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
}
}
}
-
+
$aKeys = array("sheet", "objects", "scenarios", "formatCells", "formatColumns", "formatRows", "insertColumns", "insertRows", "insertHyperlinks", "deleteColumns", "deleteRows", "selectLockedCells", "sort", "autoFilter", "pivotTables", "selectUnlockedCells");
if (!$this->_readDataOnly && $xmlSheet && $xmlSheet->sheetProtection) {
foreach ($aKeys as $key) {
@@ -1105,111 +1105,111 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
}
if ($xmlSheet && $xmlSheet->autoFilter && !$this->_readDataOnly) {
- $autoFilter = $docSheet->getAutoFilter();
+ $autoFilter = $docSheet->getAutoFilter();
$autoFilter->setRange((string) $xmlSheet->autoFilter["ref"]);
- foreach ($xmlSheet->autoFilter->filterColumn as $filterColumn) {
- $column = $autoFilter->getColumnByOffset((integer) $filterColumn["colId"]);
- // Check for standard filters
- if ($filterColumn->filters) {
- $column->setFilterType(PHPExcel_Worksheet_AutoFilter_Column::AUTOFILTER_FILTERTYPE_FILTER);
- $filters = $filterColumn->filters;
- if ((isset($filters["blank"])) && ($filters["blank"] == 1)) {
- $column->createRule()->setRule(
- NULL, // Operator is undefined, but always treated as EQUAL
- ''
- )
- ->setRuleType(PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_FILTER);
- }
- // Standard filters are always an OR join, so no join rule needs to be set
- // Entries can be either filter elements
- foreach ($filters->filter as $filterRule) {
- $column->createRule()->setRule(
- NULL, // Operator is undefined, but always treated as EQUAL
- (string) $filterRule["val"]
- )
- ->setRuleType(PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_FILTER);
- }
- // Or Date Group elements
- foreach ($filters->dateGroupItem as $dateGroupItem) {
- $column->createRule()->setRule(
- NULL, // Operator is undefined, but always treated as EQUAL
- array(
- 'year' => (string) $dateGroupItem["year"],
- 'month' => (string) $dateGroupItem["month"],
- 'day' => (string) $dateGroupItem["day"],
- 'hour' => (string) $dateGroupItem["hour"],
- 'minute' => (string) $dateGroupItem["minute"],
- 'second' => (string) $dateGroupItem["second"],
- ),
- (string) $dateGroupItem["dateTimeGrouping"]
- )
- ->setRuleType(PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DATEGROUP);
- }
- }
- // Check for custom filters
- if ($filterColumn->customFilters) {
- $column->setFilterType(PHPExcel_Worksheet_AutoFilter_Column::AUTOFILTER_FILTERTYPE_CUSTOMFILTER);
- $customFilters = $filterColumn->customFilters;
- // Custom filters can an AND or an OR join;
- // and there should only ever be one or two entries
- if ((isset($customFilters["and"])) && ($customFilters["and"] == 1)) {
- $column->setJoin(PHPExcel_Worksheet_AutoFilter_Column::AUTOFILTER_COLUMN_JOIN_AND);
- }
- foreach ($customFilters->customFilter as $filterRule) {
- $column->createRule()->setRule(
- (string) $filterRule["operator"],
- (string) $filterRule["val"]
- )
- ->setRuleType(PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_CUSTOMFILTER);
- }
- }
- // Check for dynamic filters
- if ($filterColumn->dynamicFilter) {
- $column->setFilterType(PHPExcel_Worksheet_AutoFilter_Column::AUTOFILTER_FILTERTYPE_DYNAMICFILTER);
- // We should only ever have one dynamic filter
- foreach ($filterColumn->dynamicFilter as $filterRule) {
- $column->createRule()->setRule(
- NULL, // Operator is undefined, but always treated as EQUAL
- (string) $filterRule["val"],
- (string) $filterRule["type"]
- )
- ->setRuleType(PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMICFILTER);
- if (isset($filterRule["val"])) {
- $column->setAttribute('val',(string) $filterRule["val"]);
- }
- if (isset($filterRule["maxVal"])) {
- $column->setAttribute('maxVal',(string) $filterRule["maxVal"]);
- }
- }
- }
- // Check for dynamic filters
- if ($filterColumn->top10) {
- $column->setFilterType(PHPExcel_Worksheet_AutoFilter_Column::AUTOFILTER_FILTERTYPE_TOPTENFILTER);
- // We should only ever have one top10 filter
- foreach ($filterColumn->top10 as $filterRule) {
- $column->createRule()->setRule(
- (((isset($filterRule["percent"])) && ($filterRule["percent"] == 1))
- ? PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_COLUMN_RULE_TOPTEN_PERCENT
- : PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_COLUMN_RULE_TOPTEN_BY_VALUE
- ),
- (string) $filterRule["val"],
- (((isset($filterRule["top"])) && ($filterRule["top"] == 1))
- ? PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_COLUMN_RULE_TOPTEN_TOP
- : PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_COLUMN_RULE_TOPTEN_BOTTOM
- )
- )
- ->setRuleType(PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_TOPTENFILTER);
- }
- }
- }
+ foreach ($xmlSheet->autoFilter->filterColumn as $filterColumn) {
+ $column = $autoFilter->getColumnByOffset((integer) $filterColumn["colId"]);
+ // Check for standard filters
+ if ($filterColumn->filters) {
+ $column->setFilterType(PHPExcel_Worksheet_AutoFilter_Column::AUTOFILTER_FILTERTYPE_FILTER);
+ $filters = $filterColumn->filters;
+ if ((isset($filters["blank"])) && ($filters["blank"] == 1)) {
+ $column->createRule()->setRule(
+ NULL, // Operator is undefined, but always treated as EQUAL
+ ''
+ )
+ ->setRuleType(PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_FILTER);
+ }
+ // Standard filters are always an OR join, so no join rule needs to be set
+ // Entries can be either filter elements
+ foreach ($filters->filter as $filterRule) {
+ $column->createRule()->setRule(
+ NULL, // Operator is undefined, but always treated as EQUAL
+ (string) $filterRule["val"]
+ )
+ ->setRuleType(PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_FILTER);
+ }
+ // Or Date Group elements
+ foreach ($filters->dateGroupItem as $dateGroupItem) {
+ $column->createRule()->setRule(
+ NULL, // Operator is undefined, but always treated as EQUAL
+ array(
+ 'year' => (string) $dateGroupItem["year"],
+ 'month' => (string) $dateGroupItem["month"],
+ 'day' => (string) $dateGroupItem["day"],
+ 'hour' => (string) $dateGroupItem["hour"],
+ 'minute' => (string) $dateGroupItem["minute"],
+ 'second' => (string) $dateGroupItem["second"],
+ ),
+ (string) $dateGroupItem["dateTimeGrouping"]
+ )
+ ->setRuleType(PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DATEGROUP);
+ }
+ }
+ // Check for custom filters
+ if ($filterColumn->customFilters) {
+ $column->setFilterType(PHPExcel_Worksheet_AutoFilter_Column::AUTOFILTER_FILTERTYPE_CUSTOMFILTER);
+ $customFilters = $filterColumn->customFilters;
+ // Custom filters can an AND or an OR join;
+ // and there should only ever be one or two entries
+ if ((isset($customFilters["and"])) && ($customFilters["and"] == 1)) {
+ $column->setJoin(PHPExcel_Worksheet_AutoFilter_Column::AUTOFILTER_COLUMN_JOIN_AND);
+ }
+ foreach ($customFilters->customFilter as $filterRule) {
+ $column->createRule()->setRule(
+ (string) $filterRule["operator"],
+ (string) $filterRule["val"]
+ )
+ ->setRuleType(PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_CUSTOMFILTER);
+ }
+ }
+ // Check for dynamic filters
+ if ($filterColumn->dynamicFilter) {
+ $column->setFilterType(PHPExcel_Worksheet_AutoFilter_Column::AUTOFILTER_FILTERTYPE_DYNAMICFILTER);
+ // We should only ever have one dynamic filter
+ foreach ($filterColumn->dynamicFilter as $filterRule) {
+ $column->createRule()->setRule(
+ NULL, // Operator is undefined, but always treated as EQUAL
+ (string) $filterRule["val"],
+ (string) $filterRule["type"]
+ )
+ ->setRuleType(PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMICFILTER);
+ if (isset($filterRule["val"])) {
+ $column->setAttribute('val',(string) $filterRule["val"]);
+ }
+ if (isset($filterRule["maxVal"])) {
+ $column->setAttribute('maxVal',(string) $filterRule["maxVal"]);
+ }
+ }
+ }
+ // Check for dynamic filters
+ if ($filterColumn->top10) {
+ $column->setFilterType(PHPExcel_Worksheet_AutoFilter_Column::AUTOFILTER_FILTERTYPE_TOPTENFILTER);
+ // We should only ever have one top10 filter
+ foreach ($filterColumn->top10 as $filterRule) {
+ $column->createRule()->setRule(
+ (((isset($filterRule["percent"])) && ($filterRule["percent"] == 1))
+ ? PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_COLUMN_RULE_TOPTEN_PERCENT
+ : PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_COLUMN_RULE_TOPTEN_BY_VALUE
+ ),
+ (string) $filterRule["val"],
+ (((isset($filterRule["top"])) && ($filterRule["top"] == 1))
+ ? PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_COLUMN_RULE_TOPTEN_TOP
+ : PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_COLUMN_RULE_TOPTEN_BOTTOM
+ )
+ )
+ ->setRuleType(PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_TOPTENFILTER);
+ }
+ }
+ }
}
if ($xmlSheet && $xmlSheet->mergeCells && $xmlSheet->mergeCells->mergeCell && !$this->_readDataOnly) {
foreach ($xmlSheet->mergeCells->mergeCell as $mergeCell) {
- $mergeRef = (string) $mergeCell["ref"];
- if (strpos($mergeRef,':') !== FALSE) {
+ $mergeRef = (string) $mergeCell["ref"];
+ if (strpos($mergeRef,':') !== FALSE) {
$docSheet->mergeCells((string) $mergeCell["ref"]);
- }
+ }
}
}
@@ -1534,12 +1534,12 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
if ($ele["Type"] == "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image") {
$images[(string) $ele["Id"]] = self::dir_add($fileDrawing, $ele["Target"]);
} elseif ($ele["Type"] == "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart") {
- if ($this->_includeCharts) {
+ if ($this->_includeCharts) {
$charts[self::dir_add($fileDrawing, $ele["Target"])] = array('id' => (string) $ele["Id"],
'sheet' => $docSheet->getTitle()
);
}
- }
+ }
}
}
$xmlDrawing = simplexml_load_string($this->_getFromZipArchive($zip, $fileDrawing))->children("http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing");
@@ -1575,7 +1575,7 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
}
$objDrawing->setWorksheet($docSheet);
} else {
- // ? Can charts be positioned with a oneCellAnchor ?
+ // ? Can charts be positioned with a oneCellAnchor ?
$coordinates = PHPExcel_Cell::stringFromColumnIndex((string) $oneCellAnchor->from->col) . ($oneCellAnchor->from->row + 1);
$offsetX = PHPExcel_Shared_Drawing::EMUToPixels($oneCellAnchor->from->colOff);
$offsetY = PHPExcel_Shared_Drawing::EMUToPixels($oneCellAnchor->from->rowOff);
@@ -1616,7 +1616,7 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
$shadow->setAlpha(self::array_item($outerShdw->srgbClr->alpha->attributes(), "val") / 1000);
}
$objDrawing->setWorksheet($docSheet);
- } elseif(($this->_includeCharts) && ($twoCellAnchor->graphicFrame)) {
+ } elseif(($this->_includeCharts) && ($twoCellAnchor->graphicFrame)) {
$fromCoordinate = PHPExcel_Cell::stringFromColumnIndex((string) $twoCellAnchor->from->col) . ($twoCellAnchor->from->row + 1);
$fromOffsetX = PHPExcel_Shared_Drawing::EMUToPixels($twoCellAnchor->from->colOff);
$fromOffsetY = PHPExcel_Shared_Drawing::EMUToPixels($twoCellAnchor->from->rowOff);
@@ -1636,7 +1636,7 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
'toOffsetY' => $toOffsetY,
'worksheetTitle' => $docSheet->getTitle()
);
- }
+ }
}
}
@@ -1666,10 +1666,10 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
// Switch on type
switch ((string)$definedName['name']) {
- case '_xlnm._FilterDatabase':
- if ((string)$definedName['hidden'] !== '1') {
+ case '_xlnm._FilterDatabase':
+ if ((string)$definedName['hidden'] !== '1') {
$docSheet->getAutoFilter()->setRange($extractedRange);
- }
+ }
break;
case '_xlnm.Print_Titles':
@@ -1805,7 +1805,7 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
foreach ($contentTypes->Override as $contentType) {
switch ($contentType["ContentType"]) {
case "application/vnd.openxmlformats-officedocument.drawingml.chart+xml":
- if ($this->_includeCharts) {
+ if ($this->_includeCharts) {
$chartEntryRef = ltrim($contentType['PartName'],'/');
$chartElements = simplexml_load_string($this->_getFromZipArchive($zip, $chartEntryRef));
$objChart = PHPExcel_Reader_Excel2007_Chart::readChart($chartElements,basename($chartEntryRef,'.xml'));
@@ -1818,7 +1818,7 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
// echo 'Position Ref ',$chartPositionRef,'
';
if (isset($chartDetails[$chartPositionRef])) {
// var_dump($chartDetails[$chartPositionRef]);
-
+
$excel->getSheetByName($charts[$chartEntryRef]['sheet'])->addChart($objChart);
$objChart->setWorksheet($excel->getSheetByName($charts[$chartEntryRef]['sheet']));
$objChart->setTopLeftPosition( $chartDetails[$chartPositionRef]['fromCoordinate'],
@@ -1830,7 +1830,7 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
$chartDetails[$chartPositionRef]['toOffsetY']
);
}
- }
+ }
}
}
}
@@ -1840,7 +1840,7 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
return $excel;
}
-
+
private static function _readColor($color, $background=FALSE) {
if (isset($color["rgb"])) {
@@ -1864,16 +1864,16 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
return 'FF000000';
}
-
+
private static function _readStyle($docStyle, $style) {
// format code
-// if (isset($style->numFmt)) {
-// if (isset($style->numFmt['formatCode'])) {
-// $docStyle->getNumberFormat()->setFormatCode((string) $style->numFmt['formatCode']);
+// if (isset($style->numFmt)) {
+// if (isset($style->numFmt['formatCode'])) {
+// $docStyle->getNumberFormat()->setFormatCode((string) $style->numFmt['formatCode']);
// } else {
$docStyle->getNumberFormat()->setFormatCode($style->numFmt);
-// }
-// }
+// }
+// }
// font
if (isset($style->font)) {
@@ -1911,7 +1911,7 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
if (isset($style->fill)) {
if ($style->fill->gradientFill) {
$gradientFill = $style->fill->gradientFill[0];
- if(!empty($gradientFill["type"])) {
+ if(!empty($gradientFill["type"])) {
$docStyle->getFill()->setFillType((string) $gradientFill["type"]);
}
$docStyle->getFill()->setRotation(floatval($gradientFill["degree"]));
@@ -1995,7 +1995,7 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
}
}
}
-
+
private static function _readBorder($docBorder, $eleBorder) {
if (isset($eleBorder["style"])) {
@@ -2006,7 +2006,7 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
}
}
-
+
private function _parseRichText($is = null) {
$value = new PHPExcel_RichText();
@@ -2069,17 +2069,17 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
return $value;
}
-
+
private static function array_item($array, $key = 0) {
return (isset($array[$key]) ? $array[$key] : null);
}
-
+
private static function dir_add($base, $add) {
return preg_replace('~[^/]+/\.\./~', '', dirname($base) . "/$add");
}
-
+
private static function toCSSArray($style) {
$style = str_replace(array("\r","\n"), "", $style);
diff --git a/htdocs/includes/phpexcel/PHPExcel/Reader/Excel5.php b/htdocs/includes/phpexcel/PHPExcel/Reader/Excel5.php
index 238d17c7324..535654243c2 100644
--- a/htdocs/includes/phpexcel/PHPExcel/Reader/Excel5.php
+++ b/htdocs/includes/phpexcel/PHPExcel/Reader/Excel5.php
@@ -1,6890 +1,6890 @@
-_data
- *
- * @var int
- */
- private $_dataSize;
-
- /**
- * Current position in stream
- *
- * @var integer
- */
- private $_pos;
-
- /**
- * Workbook to be returned by the reader.
- *
- * @var PHPExcel
- */
- private $_phpExcel;
-
- /**
- * Worksheet that is currently being built by the reader.
- *
- * @var PHPExcel_Worksheet
- */
- private $_phpSheet;
-
- /**
- * BIFF version
- *
- * @var int
- */
- private $_version;
-
- /**
- * Codepage set in the Excel file being read. Only important for BIFF5 (Excel 5.0 - Excel 95)
- * For BIFF8 (Excel 97 - Excel 2003) this will always have the value 'UTF-16LE'
- *
- * @var string
- */
- private $_codepage;
-
- /**
- * Shared formats
- *
- * @var array
- */
- private $_formats;
-
- /**
- * Shared fonts
- *
- * @var array
- */
- private $_objFonts;
-
- /**
- * Color palette
- *
- * @var array
- */
- private $_palette;
-
- /**
- * Worksheets
- *
- * @var array
- */
- private $_sheets;
-
- /**
- * External books
- *
- * @var array
- */
- private $_externalBooks;
-
- /**
- * REF structures. Only applies to BIFF8.
- *
- * @var array
- */
- private $_ref;
-
- /**
- * External names
- *
- * @var array
- */
- private $_externalNames;
-
- /**
- * Defined names
- *
- * @var array
- */
- private $_definedname;
-
- /**
- * Shared strings. Only applies to BIFF8.
- *
- * @var array
- */
- private $_sst;
-
- /**
- * Panes are frozen? (in sheet currently being read). See WINDOW2 record.
- *
- * @var boolean
- */
- private $_frozen;
-
- /**
- * Fit printout to number of pages? (in sheet currently being read). See SHEETPR record.
- *
- * @var boolean
- */
- private $_isFitToPages;
-
- /**
- * Objects. One OBJ record contributes with one entry.
- *
- * @var array
- */
- private $_objs;
-
- /**
- * Text Objects. One TXO record corresponds with one entry.
- *
- * @var array
- */
- private $_textObjects;
-
- /**
- * Cell Annotations (BIFF8)
- *
- * @var array
- */
- private $_cellNotes;
-
- /**
- * The combined MSODRAWINGGROUP data
- *
- * @var string
- */
- private $_drawingGroupData;
-
- /**
- * The combined MSODRAWING data (per sheet)
- *
- * @var string
- */
- private $_drawingData;
-
- /**
- * Keep track of XF index
- *
- * @var int
- */
- private $_xfIndex;
-
- /**
- * Mapping of XF index (that is a cell XF) to final index in cellXf collection
- *
- * @var array
- */
- private $_mapCellXfIndex;
-
- /**
- * Mapping of XF index (that is a style XF) to final index in cellStyleXf collection
- *
- * @var array
- */
- private $_mapCellStyleXfIndex;
-
- /**
- * The shared formulas in a sheet. One SHAREDFMLA record contributes with one value.
- *
- * @var array
- */
- private $_sharedFormulas;
-
- /**
- * The shared formula parts in a sheet. One FORMULA record contributes with one value if it
- * refers to a shared formula.
- *
- * @var array
- */
- private $_sharedFormulaParts;
-
-
- /**
- * Create a new PHPExcel_Reader_Excel5 instance
- */
- public function __construct() {
- $this->_readFilter = new PHPExcel_Reader_DefaultReadFilter();
- }
-
-
- /**
- * Read data only?
- * If this is true, then the Reader will only read data values for cells, it will not read any formatting information.
- * If false (the default) it will read data and formatting.
- *
- * @return boolean
- */
- public function getReadDataOnly()
- {
- return $this->_readDataOnly;
- }
-
-
- /**
- * Set read data only
- * Set to true, to advise the Reader only to read data values for cells, and to ignore any formatting information.
- * Set to false (the default) to advise the Reader to read both data and formatting for cells.
- *
- * @param boolean $pValue
- *
- * @return PHPExcel_Reader_Excel5
- */
- public function setReadDataOnly($pValue = false)
- {
- $this->_readDataOnly = $pValue;
- return $this;
- }
-
-
- /**
- * Get which sheets to load
- * Returns either an array of worksheet names (the list of worksheets that should be loaded), or a null
- * indicating that all worksheets in the workbook should be loaded.
- *
- * @return mixed
- */
- public function getLoadSheetsOnly()
- {
- return $this->_loadSheetsOnly;
- }
-
-
- /**
- * Set which sheets to load
- *
- * @param mixed $value
- * This should be either an array of worksheet names to be loaded, or a string containing a single worksheet name.
- * If NULL, then it tells the Reader to read all worksheets in the workbook
- *
- * @return PHPExcel_Reader_Excel5
- */
- public function setLoadSheetsOnly($value = null)
- {
- $this->_loadSheetsOnly = is_array($value) ?
- $value : array($value);
- return $this;
- }
-
-
- /**
- * Set all sheets to load
- * Tells the Reader to load all worksheets from the workbook.
- *
- * @return PHPExcel_Reader_Excel5
- */
- 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_Excel5
- */
- public function setReadFilter(PHPExcel_Reader_IReadFilter $pValue) {
- $this->_readFilter = $pValue;
- return $this;
- }
-
-
- /**
- * Can the current PHPExcel_Reader_IReader read the file?
- *
- * @param string $pFileName
- * @return boolean
- * @throws Exception
- */
- 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.");
- }
-
- try {
- // Use ParseXL for the hard work.
- $ole = new PHPExcel_Shared_OLERead();
-
- // get excel data
- $res = $ole->read($pFilename);
- return true;
-
- } catch (Exception $e) {
- return false;
- }
- }
-
-
- /**
- * Reads names of the worksheets from a file, without parsing the whole file to a PHPExcel object
- *
- * @param string $pFilename
- * @throws Exception
- */
- public function listWorksheetNames($pFilename)
- {
- // Check if file exists
- if (!file_exists($pFilename)) {
- throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
- }
-
- $worksheetNames = array();
-
- // Read the OLE file
- $this->_loadOLE($pFilename);
-
- // total byte size of Excel data (workbook global substream + sheet substreams)
- $this->_dataSize = strlen($this->_data);
-
- $this->_pos = 0;
- $this->_sheets = array();
-
- // Parse Workbook Global Substream
- while ($this->_pos < $this->_dataSize) {
- $code = self::_GetInt2d($this->_data, $this->_pos);
-
- switch ($code) {
- case self::XLS_Type_BOF: $this->_readBof(); break;
- case self::XLS_Type_SHEET: $this->_readSheet(); break;
- case self::XLS_Type_EOF: $this->_readDefault(); break 2;
- default: $this->_readDefault(); break;
- }
- }
-
- foreach ($this->_sheets as $sheet) {
- if ($sheet['sheetType'] != 0x00) {
- // 0x00: Worksheet, 0x02: Chart, 0x06: Visual Basic module
- continue;
- }
-
- $worksheetNames[] = $sheet['name'];
- }
-
- return $worksheetNames;
- }
-
-
- /**
- * Return worksheet info (Name, Last Column Letter, Last Column Index, Total Rows, Total Columns)
- *
- * @param string $pFilename
- * @throws Exception
- */
- public function listWorksheetInfo($pFilename)
- {
- // Check if file exists
- if (!file_exists($pFilename)) {
- throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
- }
-
- $worksheetInfo = array();
-
- // Read the OLE file
- $this->_loadOLE($pFilename);
-
- // total byte size of Excel data (workbook global substream + sheet substreams)
- $this->_dataSize = strlen($this->_data);
-
- // initialize
- $this->_pos = 0;
- $this->_sheets = array();
-
- // Parse Workbook Global Substream
- while ($this->_pos < $this->_dataSize) {
- $code = self::_GetInt2d($this->_data, $this->_pos);
-
- switch ($code) {
- case self::XLS_Type_BOF: $this->_readBof(); break;
- case self::XLS_Type_SHEET: $this->_readSheet(); break;
- case self::XLS_Type_EOF: $this->_readDefault(); break 2;
- default: $this->_readDefault(); break;
- }
- }
-
- // Parse the individual sheets
- foreach ($this->_sheets as $sheet) {
-
- if ($sheet['sheetType'] != 0x00) {
- // 0x00: Worksheet
- // 0x02: Chart
- // 0x06: Visual Basic module
- continue;
- }
-
- $tmpInfo = array();
- $tmpInfo['worksheetName'] = $sheet['name'];
- $tmpInfo['lastColumnLetter'] = 'A';
- $tmpInfo['lastColumnIndex'] = 0;
- $tmpInfo['totalRows'] = 0;
- $tmpInfo['totalColumns'] = 0;
-
- $this->_pos = $sheet['offset'];
-
- while ($this->_pos <= $this->_dataSize - 4) {
- $code = self::_GetInt2d($this->_data, $this->_pos);
-
- switch ($code) {
- case self::XLS_Type_RK:
- case self::XLS_Type_LABELSST:
- case self::XLS_Type_NUMBER:
- case self::XLS_Type_FORMULA:
- case self::XLS_Type_BOOLERR:
- case self::XLS_Type_LABEL:
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- $rowIndex = self::_GetInt2d($recordData, 0) + 1;
- $columnIndex = self::_GetInt2d($recordData, 2);
-
- $tmpInfo['totalRows'] = max($tmpInfo['totalRows'], $rowIndex);
- $tmpInfo['lastColumnIndex'] = max($tmpInfo['lastColumnIndex'], $columnIndex);
- break;
- case self::XLS_Type_BOF: $this->_readBof(); break;
- case self::XLS_Type_EOF: $this->_readDefault(); break 2;
- default: $this->_readDefault(); break;
- }
- }
-
- $tmpInfo['lastColumnLetter'] = PHPExcel_Cell::stringFromColumnIndex($tmpInfo['lastColumnIndex']);
- $tmpInfo['totalColumns'] = $tmpInfo['lastColumnIndex'] + 1;
-
- $worksheetInfo[] = $tmpInfo;
- }
-
- return $worksheetInfo;
- }
-
-
- /**
- * Loads PHPExcel from file
- *
- * @param string $pFilename
- * @return PHPExcel
- * @throws Exception
- */
- public function load($pFilename)
- {
- // Read the OLE file
- $this->_loadOLE($pFilename);
-
- // Initialisations
- $this->_phpExcel = new PHPExcel;
- $this->_phpExcel->removeSheetByIndex(0); // remove 1st sheet
- if (!$this->_readDataOnly) {
- $this->_phpExcel->removeCellStyleXfByIndex(0); // remove the default style
- $this->_phpExcel->removeCellXfByIndex(0); // remove the default style
- }
-
- // Read the summary information stream (containing meta data)
- $this->_readSummaryInformation();
-
- // Read the Additional document summary information stream (containing application-specific meta data)
- $this->_readDocumentSummaryInformation();
-
- // total byte size of Excel data (workbook global substream + sheet substreams)
- $this->_dataSize = strlen($this->_data);
-
- // initialize
- $this->_pos = 0;
- $this->_codepage = 'CP1252';
- $this->_formats = array();
- $this->_objFonts = array();
- $this->_palette = array();
- $this->_sheets = array();
- $this->_externalBooks = array();
- $this->_ref = array();
- $this->_definedname = array();
- $this->_sst = array();
- $this->_drawingGroupData = '';
- $this->_xfIndex = '';
- $this->_mapCellXfIndex = array();
- $this->_mapCellStyleXfIndex = array();
-
- // Parse Workbook Global Substream
- while ($this->_pos < $this->_dataSize) {
- $code = self::_GetInt2d($this->_data, $this->_pos);
-
- switch ($code) {
- case self::XLS_Type_BOF: $this->_readBof(); break;
- case self::XLS_Type_FILEPASS: $this->_readFilepass(); break;
- case self::XLS_Type_CODEPAGE: $this->_readCodepage(); break;
- case self::XLS_Type_DATEMODE: $this->_readDateMode(); break;
- case self::XLS_Type_FONT: $this->_readFont(); break;
- case self::XLS_Type_FORMAT: $this->_readFormat(); break;
- case self::XLS_Type_XF: $this->_readXf(); break;
- case self::XLS_Type_XFEXT: $this->_readXfExt(); break;
- case self::XLS_Type_STYLE: $this->_readStyle(); break;
- case self::XLS_Type_PALETTE: $this->_readPalette(); break;
- case self::XLS_Type_SHEET: $this->_readSheet(); break;
- case self::XLS_Type_EXTERNALBOOK: $this->_readExternalBook(); break;
- case self::XLS_Type_EXTERNNAME: $this->_readExternName(); break;
- case self::XLS_Type_EXTERNSHEET: $this->_readExternSheet(); break;
- case self::XLS_Type_DEFINEDNAME: $this->_readDefinedName(); break;
- case self::XLS_Type_MSODRAWINGGROUP: $this->_readMsoDrawingGroup(); break;
- case self::XLS_Type_SST: $this->_readSst(); break;
- case self::XLS_Type_EOF: $this->_readDefault(); break 2;
- default: $this->_readDefault(); break;
- }
- }
-
- // Resolve indexed colors for font, fill, and border colors
- // Cannot be resolved already in XF record, because PALETTE record comes afterwards
- if (!$this->_readDataOnly) {
- foreach ($this->_objFonts as $objFont) {
- if (isset($objFont->colorIndex)) {
- $color = self::_readColor($objFont->colorIndex,$this->_palette,$this->_version);
- $objFont->getColor()->setRGB($color['rgb']);
- }
- }
-
- foreach ($this->_phpExcel->getCellXfCollection() as $objStyle) {
- // fill start and end color
- $fill = $objStyle->getFill();
-
- if (isset($fill->startcolorIndex)) {
- $startColor = self::_readColor($fill->startcolorIndex,$this->_palette,$this->_version);
- $fill->getStartColor()->setRGB($startColor['rgb']);
- }
-
- if (isset($fill->endcolorIndex)) {
- $endColor = self::_readColor($fill->endcolorIndex,$this->_palette,$this->_version);
- $fill->getEndColor()->setRGB($endColor['rgb']);
- }
-
- // border colors
- $top = $objStyle->getBorders()->getTop();
- $right = $objStyle->getBorders()->getRight();
- $bottom = $objStyle->getBorders()->getBottom();
- $left = $objStyle->getBorders()->getLeft();
- $diagonal = $objStyle->getBorders()->getDiagonal();
-
- if (isset($top->colorIndex)) {
- $borderTopColor = self::_readColor($top->colorIndex,$this->_palette,$this->_version);
- $top->getColor()->setRGB($borderTopColor['rgb']);
- }
-
- if (isset($right->colorIndex)) {
- $borderRightColor = self::_readColor($right->colorIndex,$this->_palette,$this->_version);
- $right->getColor()->setRGB($borderRightColor['rgb']);
- }
-
- if (isset($bottom->colorIndex)) {
- $borderBottomColor = self::_readColor($bottom->colorIndex,$this->_palette,$this->_version);
- $bottom->getColor()->setRGB($borderBottomColor['rgb']);
- }
-
- if (isset($left->colorIndex)) {
- $borderLeftColor = self::_readColor($left->colorIndex,$this->_palette,$this->_version);
- $left->getColor()->setRGB($borderLeftColor['rgb']);
- }
-
- if (isset($diagonal->colorIndex)) {
- $borderDiagonalColor = self::_readColor($diagonal->colorIndex,$this->_palette,$this->_version);
- $diagonal->getColor()->setRGB($borderDiagonalColor['rgb']);
- }
- }
- }
-
- // treat MSODRAWINGGROUP records, workbook-level Escher
- if (!$this->_readDataOnly && $this->_drawingGroupData) {
- $escherWorkbook = new PHPExcel_Shared_Escher();
- $reader = new PHPExcel_Reader_Excel5_Escher($escherWorkbook);
- $escherWorkbook = $reader->load($this->_drawingGroupData);
-
- // debug Escher stream
- //$debug = new Debug_Escher(new PHPExcel_Shared_Escher());
- //$debug->load($this->_drawingGroupData);
- }
-
- // Parse the individual sheets
- foreach ($this->_sheets as $sheet) {
-
- if ($sheet['sheetType'] != 0x00) {
- // 0x00: Worksheet, 0x02: Chart, 0x06: Visual Basic module
- continue;
- }
-
- // check if sheet should be skipped
- if (isset($this->_loadSheetsOnly) && !in_array($sheet['name'], $this->_loadSheetsOnly)) {
- continue;
- }
-
- // add sheet to PHPExcel object
- $this->_phpSheet = $this->_phpExcel->createSheet();
- // Use false for $updateFormulaCellReferences to prevent adjustment of worksheet references in formula
- // cells... during the load, all formulae should be correct, and we're simply bringing the worksheet
- // name in line with the formula, not the reverse
- $this->_phpSheet->setTitle($sheet['name'],false);
- $this->_phpSheet->setSheetState($sheet['sheetState']);
-
- $this->_pos = $sheet['offset'];
-
- // Initialize isFitToPages. May change after reading SHEETPR record.
- $this->_isFitToPages = false;
-
- // Initialize drawingData
- $this->_drawingData = '';
-
- // Initialize objs
- $this->_objs = array();
-
- // Initialize shared formula parts
- $this->_sharedFormulaParts = array();
-
- // Initialize shared formulas
- $this->_sharedFormulas = array();
-
- // Initialize text objs
- $this->_textObjects = array();
-
- // Initialize cell annotations
- $this->_cellNotes = array();
- $this->textObjRef = -1;
-
- while ($this->_pos <= $this->_dataSize - 4) {
- $code = self::_GetInt2d($this->_data, $this->_pos);
-
- switch ($code) {
- case self::XLS_Type_BOF: $this->_readBof(); break;
- case self::XLS_Type_PRINTGRIDLINES: $this->_readPrintGridlines(); break;
- case self::XLS_Type_DEFAULTROWHEIGHT: $this->_readDefaultRowHeight(); break;
- case self::XLS_Type_SHEETPR: $this->_readSheetPr(); break;
- case self::XLS_Type_HORIZONTALPAGEBREAKS: $this->_readHorizontalPageBreaks(); break;
- case self::XLS_Type_VERTICALPAGEBREAKS: $this->_readVerticalPageBreaks(); break;
- case self::XLS_Type_HEADER: $this->_readHeader(); break;
- case self::XLS_Type_FOOTER: $this->_readFooter(); break;
- case self::XLS_Type_HCENTER: $this->_readHcenter(); break;
- case self::XLS_Type_VCENTER: $this->_readVcenter(); break;
- case self::XLS_Type_LEFTMARGIN: $this->_readLeftMargin(); break;
- case self::XLS_Type_RIGHTMARGIN: $this->_readRightMargin(); break;
- case self::XLS_Type_TOPMARGIN: $this->_readTopMargin(); break;
- case self::XLS_Type_BOTTOMMARGIN: $this->_readBottomMargin(); break;
- case self::XLS_Type_PAGESETUP: $this->_readPageSetup(); break;
- case self::XLS_Type_PROTECT: $this->_readProtect(); break;
- case self::XLS_Type_SCENPROTECT: $this->_readScenProtect(); break;
- case self::XLS_Type_OBJECTPROTECT: $this->_readObjectProtect(); break;
- case self::XLS_Type_PASSWORD: $this->_readPassword(); break;
- case self::XLS_Type_DEFCOLWIDTH: $this->_readDefColWidth(); break;
- case self::XLS_Type_COLINFO: $this->_readColInfo(); break;
- case self::XLS_Type_DIMENSION: $this->_readDefault(); break;
- case self::XLS_Type_ROW: $this->_readRow(); break;
- case self::XLS_Type_DBCELL: $this->_readDefault(); break;
- case self::XLS_Type_RK: $this->_readRk(); break;
- case self::XLS_Type_LABELSST: $this->_readLabelSst(); break;
- case self::XLS_Type_MULRK: $this->_readMulRk(); break;
- case self::XLS_Type_NUMBER: $this->_readNumber(); break;
- case self::XLS_Type_FORMULA: $this->_readFormula(); break;
- case self::XLS_Type_SHAREDFMLA: $this->_readSharedFmla(); break;
- case self::XLS_Type_BOOLERR: $this->_readBoolErr(); break;
- case self::XLS_Type_MULBLANK: $this->_readMulBlank(); break;
- case self::XLS_Type_LABEL: $this->_readLabel(); break;
- case self::XLS_Type_BLANK: $this->_readBlank(); break;
- case self::XLS_Type_MSODRAWING: $this->_readMsoDrawing(); break;
- case self::XLS_Type_OBJ: $this->_readObj(); break;
- case self::XLS_Type_WINDOW2: $this->_readWindow2(); break;
- case self::XLS_Type_SCL: $this->_readScl(); break;
- case self::XLS_Type_PANE: $this->_readPane(); break;
- case self::XLS_Type_SELECTION: $this->_readSelection(); break;
- case self::XLS_Type_MERGEDCELLS: $this->_readMergedCells(); break;
- case self::XLS_Type_HYPERLINK: $this->_readHyperLink(); break;
- case self::XLS_Type_DATAVALIDATIONS: $this->_readDataValidations(); break;
- case self::XLS_Type_DATAVALIDATION: $this->_readDataValidation(); break;
- case self::XLS_Type_SHEETLAYOUT: $this->_readSheetLayout(); break;
- case self::XLS_Type_SHEETPROTECTION: $this->_readSheetProtection(); break;
- case self::XLS_Type_RANGEPROTECTION: $this->_readRangeProtection(); break;
- case self::XLS_Type_NOTE: $this->_readNote(); break;
- //case self::XLS_Type_IMDATA: $this->_readImData(); break;
- case self::XLS_Type_TXO: $this->_readTextObject(); break;
- case self::XLS_Type_CONTINUE: $this->_readContinue(); break;
- case self::XLS_Type_EOF: $this->_readDefault(); break 2;
- default: $this->_readDefault(); break;
- }
-
- }
-
- // treat MSODRAWING records, sheet-level Escher
- if (!$this->_readDataOnly && $this->_drawingData) {
- $escherWorksheet = new PHPExcel_Shared_Escher();
- $reader = new PHPExcel_Reader_Excel5_Escher($escherWorksheet);
- $escherWorksheet = $reader->load($this->_drawingData);
-
- // debug Escher stream
- //$debug = new Debug_Escher(new PHPExcel_Shared_Escher());
- //$debug->load($this->_drawingData);
-
- // get all spContainers in one long array, so they can be mapped to OBJ records
- $allSpContainers = $escherWorksheet->getDgContainer()->getSpgrContainer()->getAllSpContainers();
- }
-
- // treat OBJ records
- foreach ($this->_objs as $n => $obj) {
-// echo '
Object reference is ',$n,'
';
-// var_dump($obj);
-// echo '
';
-
- // the first shape container never has a corresponding OBJ record, hence $n + 1
- if (isset($allSpContainers[$n + 1]) && is_object($allSpContainers[$n + 1])) {
- $spContainer = $allSpContainers[$n + 1];
-
- // we skip all spContainers that are a part of a group shape since we cannot yet handle those
- if ($spContainer->getNestingLevel() > 1) {
- continue;
- }
-
- // calculate the width and height of the shape
- list($startColumn, $startRow) = PHPExcel_Cell::coordinateFromString($spContainer->getStartCoordinates());
- list($endColumn, $endRow) = PHPExcel_Cell::coordinateFromString($spContainer->getEndCoordinates());
-
- $startOffsetX = $spContainer->getStartOffsetX();
- $startOffsetY = $spContainer->getStartOffsetY();
- $endOffsetX = $spContainer->getEndOffsetX();
- $endOffsetY = $spContainer->getEndOffsetY();
-
- $width = PHPExcel_Shared_Excel5::getDistanceX($this->_phpSheet, $startColumn, $startOffsetX, $endColumn, $endOffsetX);
- $height = PHPExcel_Shared_Excel5::getDistanceY($this->_phpSheet, $startRow, $startOffsetY, $endRow, $endOffsetY);
-
- // calculate offsetX and offsetY of the shape
- $offsetX = $startOffsetX * PHPExcel_Shared_Excel5::sizeCol($this->_phpSheet, $startColumn) / 1024;
- $offsetY = $startOffsetY * PHPExcel_Shared_Excel5::sizeRow($this->_phpSheet, $startRow) / 256;
-
- switch ($obj['otObjType']) {
- case 0x19:
- // Note
-// echo 'Cell Annotation Object
';
-// echo 'Object ID is ',$obj['idObjID'],'
';
-//
- if (isset($this->_cellNotes[$obj['idObjID']])) {
- $cellNote = $this->_cellNotes[$obj['idObjID']];
-
- if (isset($this->_textObjects[$obj['idObjID']])) {
- $textObject = $this->_textObjects[$obj['idObjID']];
- $this->_cellNotes[$obj['idObjID']]['objTextData'] = $textObject;
- }
- }
- break;
-
- case 0x08:
-// echo 'Picture Object
';
- // picture
-
- // get index to BSE entry (1-based)
- $BSEindex = $spContainer->getOPT(0x0104);
- $BSECollection = $escherWorkbook->getDggContainer()->getBstoreContainer()->getBSECollection();
- $BSE = $BSECollection[$BSEindex - 1];
- $blipType = $BSE->getBlipType();
-
- // need check because some blip types are not supported by Escher reader such as EMF
- if ($blip = $BSE->getBlip()) {
- $ih = imagecreatefromstring($blip->getData());
- $drawing = new PHPExcel_Worksheet_MemoryDrawing();
- $drawing->setImageResource($ih);
-
- // width, height, offsetX, offsetY
- $drawing->setResizeProportional(false);
- $drawing->setWidth($width);
- $drawing->setHeight($height);
- $drawing->setOffsetX($offsetX);
- $drawing->setOffsetY($offsetY);
-
- switch ($blipType) {
- case PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE::BLIPTYPE_JPEG:
- $drawing->setRenderingFunction(PHPExcel_Worksheet_MemoryDrawing::RENDERING_JPEG);
- $drawing->setMimeType(PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_JPEG);
- break;
-
- case PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE::BLIPTYPE_PNG:
- $drawing->setRenderingFunction(PHPExcel_Worksheet_MemoryDrawing::RENDERING_PNG);
- $drawing->setMimeType(PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_PNG);
- break;
- }
-
- $drawing->setWorksheet($this->_phpSheet);
- $drawing->setCoordinates($spContainer->getStartCoordinates());
- }
-
- break;
-
- default:
- // other object type
- break;
-
- }
- }
- }
-
- // treat SHAREDFMLA records
- if ($this->_version == self::XLS_BIFF8) {
- foreach ($this->_sharedFormulaParts as $cell => $baseCell) {
- list($column, $row) = PHPExcel_Cell::coordinateFromString($cell);
- if (($this->getReadFilter() !== NULL) && $this->getReadFilter()->readCell($column, $row, $this->_phpSheet->getTitle()) ) {
- $formula = $this->_getFormulaFromStructure($this->_sharedFormulas[$baseCell], $cell);
- $this->_phpSheet->getCell($cell)->setValueExplicit('=' . $formula, PHPExcel_Cell_DataType::TYPE_FORMULA);
- }
- }
- }
-
- if (!empty($this->_cellNotes)) {
- foreach($this->_cellNotes as $note => $noteDetails) {
- if (!isset($noteDetails['objTextData'])) {
- if (isset($this->_textObjects[$note])) {
- $textObject = $this->_textObjects[$note];
- $noteDetails['objTextData'] = $textObject;
- } else {
- $noteDetails['objTextData']['text'] = '';
- }
- }
-// echo 'Cell annotation ',$note,'
';
-// var_dump($noteDetails);
-// echo '
';
- $cellAddress = str_replace('$','',$noteDetails['cellRef']);
- $this->_phpSheet->getComment( $cellAddress )
- ->setAuthor( $noteDetails['author'] )
- ->setText($this->_parseRichText($noteDetails['objTextData']['text']) );
- }
- }
- }
-
- // add the named ranges (defined names)
- foreach ($this->_definedname as $definedName) {
- if ($definedName['isBuiltInName']) {
- switch ($definedName['name']) {
-
- case pack('C', 0x06):
- // print area
- // in general, formula looks like this: Foo!$C$7:$J$66,Bar!$A$1:$IV$2
-
- $ranges = explode(',', $definedName['formula']); // FIXME: what if sheetname contains comma?
-
- $extractedRanges = array();
- foreach ($ranges as $range) {
- // $range should look like one of these
- // Foo!$C$7:$J$66
- // Bar!$A$1:$IV$2
-
- $explodes = explode('!', $range); // FIXME: what if sheetname contains exclamation mark?
- $sheetName = $explodes[0];
-
- if (count($explodes) == 2) {
- $extractedRanges[] = str_replace('$', '', $explodes[1]); // C7:J66
- }
- }
- if ($docSheet = $this->_phpExcel->getSheetByName($sheetName)) {
- $docSheet->getPageSetup()->setPrintArea(implode(',', $extractedRanges)); // C7:J66,A1:IV2
- }
- break;
-
- case pack('C', 0x07):
- // print titles (repeating rows)
- // Assuming BIFF8, there are 3 cases
- // 1. repeating rows
- // formula looks like this: Sheet!$A$1:$IV$2
- // rows 1-2 repeat
- // 2. repeating columns
- // formula looks like this: Sheet!$A$1:$B$65536
- // columns A-B repeat
- // 3. both repeating rows and repeating columns
- // formula looks like this: Sheet!$A$1:$B$65536,Sheet!$A$1:$IV$2
-
- $ranges = explode(',', $definedName['formula']); // FIXME: what if sheetname contains comma?
-
- foreach ($ranges as $range) {
- // $range should look like this one of these
- // Sheet!$A$1:$B$65536
- // Sheet!$A$1:$IV$2
-
- $explodes = explode('!', $range);
-
- if (count($explodes) == 2) {
- if ($docSheet = $this->_phpExcel->getSheetByName($explodes[0])) {
-
- $extractedRange = $explodes[1];
- $extractedRange = str_replace('$', '', $extractedRange);
-
- $coordinateStrings = explode(':', $extractedRange);
- if (count($coordinateStrings) == 2) {
- list($firstColumn, $firstRow) = PHPExcel_Cell::coordinateFromString($coordinateStrings[0]);
- list($lastColumn, $lastRow) = PHPExcel_Cell::coordinateFromString($coordinateStrings[1]);
-
- if ($firstColumn == 'A' and $lastColumn == 'IV') {
- // then we have repeating rows
- $docSheet->getPageSetup()->setRowsToRepeatAtTop(array($firstRow, $lastRow));
- } elseif ($firstRow == 1 and $lastRow == 65536) {
- // then we have repeating columns
- $docSheet->getPageSetup()->setColumnsToRepeatAtLeft(array($firstColumn, $lastColumn));
- }
- }
- }
- }
- }
- break;
-
- }
- } else {
- // Extract range
- $explodes = explode('!', $definedName['formula']);
-
- if (count($explodes) == 2) {
- if (($docSheet = $this->_phpExcel->getSheetByName($explodes[0])) ||
- ($docSheet = $this->_phpExcel->getSheetByName(trim($explodes[0],"'")))) {
- $extractedRange = $explodes[1];
- $extractedRange = str_replace('$', '', $extractedRange);
-
- $localOnly = ($definedName['scope'] == 0) ? false : true;
-
- $scope = ($definedName['scope'] == 0) ?
- null : $this->_phpExcel->getSheetByName($this->_sheets[$definedName['scope'] - 1]['name']);
-
- $this->_phpExcel->addNamedRange( new PHPExcel_NamedRange((string)$definedName['name'], $docSheet, $extractedRange, $localOnly, $scope) );
- }
- } else {
- // Named Value
- // TODO Provide support for named values
- }
- }
- }
-
- return $this->_phpExcel;
- }
-
-
- /**
- * Use OLE reader to extract the relevant data streams from the OLE file
- *
- * @param string $pFilename
- */
- private function _loadOLE($pFilename)
- {
- // OLE reader
- $ole = new PHPExcel_Shared_OLERead();
-
- // get excel data,
- $res = $ole->read($pFilename);
- // Get workbook data: workbook stream + sheet streams
- $this->_data = $ole->getStream($ole->wrkbook);
-
- // Get summary information data
- $this->_summaryInformation = $ole->getStream($ole->summaryInformation);
-
- // Get additional document summary information data
- $this->_documentSummaryInformation = $ole->getStream($ole->documentSummaryInformation);
-
- // Get user-defined property data
-// $this->_userDefinedProperties = $ole->getUserDefinedProperties();
- }
-
-
- /**
- * Read summary information
- */
- private function _readSummaryInformation()
- {
- if (!isset($this->_summaryInformation)) {
- return;
- }
-
- // offset: 0; size: 2; must be 0xFE 0xFF (UTF-16 LE byte order mark)
- // offset: 2; size: 2;
- // offset: 4; size: 2; OS version
- // offset: 6; size: 2; OS indicator
- // offset: 8; size: 16
- // offset: 24; size: 4; section count
- $secCount = self::_GetInt4d($this->_summaryInformation, 24);
-
- // offset: 28; size: 16; first section's class id: e0 85 9f f2 f9 4f 68 10 ab 91 08 00 2b 27 b3 d9
- // offset: 44; size: 4
- $secOffset = self::_GetInt4d($this->_summaryInformation, 44);
-
- // section header
- // offset: $secOffset; size: 4; section length
- $secLength = self::_GetInt4d($this->_summaryInformation, $secOffset);
-
- // offset: $secOffset+4; size: 4; property count
- $countProperties = self::_GetInt4d($this->_summaryInformation, $secOffset+4);
-
- // initialize code page (used to resolve string values)
- $codePage = 'CP1252';
-
- // offset: ($secOffset+8); size: var
- // loop through property decarations and properties
- for ($i = 0; $i < $countProperties; ++$i) {
-
- // offset: ($secOffset+8) + (8 * $i); size: 4; property ID
- $id = self::_GetInt4d($this->_summaryInformation, ($secOffset+8) + (8 * $i));
-
- // Use value of property id as appropriate
- // offset: ($secOffset+12) + (8 * $i); size: 4; offset from beginning of section (48)
- $offset = self::_GetInt4d($this->_summaryInformation, ($secOffset+12) + (8 * $i));
-
- $type = self::_GetInt4d($this->_summaryInformation, $secOffset + $offset);
-
- // initialize property value
- $value = null;
-
- // extract property value based on property type
- switch ($type) {
- case 0x02: // 2 byte signed integer
- $value = self::_GetInt2d($this->_summaryInformation, $secOffset + 4 + $offset);
- break;
-
- case 0x03: // 4 byte signed integer
- $value = self::_GetInt4d($this->_summaryInformation, $secOffset + 4 + $offset);
- break;
-
- case 0x13: // 4 byte unsigned integer
- // not needed yet, fix later if necessary
- break;
-
- case 0x1E: // null-terminated string prepended by dword string length
- $byteLength = self::_GetInt4d($this->_summaryInformation, $secOffset + 4 + $offset);
- $value = substr($this->_summaryInformation, $secOffset + 8 + $offset, $byteLength);
- $value = PHPExcel_Shared_String::ConvertEncoding($value, 'UTF-8', $codePage);
- $value = rtrim($value);
- break;
-
- case 0x40: // Filetime (64-bit value representing the number of 100-nanosecond intervals since January 1, 1601)
- // PHP-time
- $value = PHPExcel_Shared_OLE::OLE2LocalDate(substr($this->_summaryInformation, $secOffset + 4 + $offset, 8));
- break;
-
- case 0x47: // Clipboard format
- // not needed yet, fix later if necessary
- break;
- }
-
- switch ($id) {
- case 0x01: // Code Page
- $codePage = PHPExcel_Shared_CodePage::NumberToName($value);
- break;
-
- case 0x02: // Title
- $this->_phpExcel->getProperties()->setTitle($value);
- break;
-
- case 0x03: // Subject
- $this->_phpExcel->getProperties()->setSubject($value);
- break;
-
- case 0x04: // Author (Creator)
- $this->_phpExcel->getProperties()->setCreator($value);
- break;
-
- case 0x05: // Keywords
- $this->_phpExcel->getProperties()->setKeywords($value);
- break;
-
- case 0x06: // Comments (Description)
- $this->_phpExcel->getProperties()->setDescription($value);
- break;
-
- case 0x07: // Template
- // Not supported by PHPExcel
- break;
-
- case 0x08: // Last Saved By (LastModifiedBy)
- $this->_phpExcel->getProperties()->setLastModifiedBy($value);
- break;
-
- case 0x09: // Revision
- // Not supported by PHPExcel
- break;
-
- case 0x0A: // Total Editing Time
- // Not supported by PHPExcel
- break;
-
- case 0x0B: // Last Printed
- // Not supported by PHPExcel
- break;
-
- case 0x0C: // Created Date/Time
- $this->_phpExcel->getProperties()->setCreated($value);
- break;
-
- case 0x0D: // Modified Date/Time
- $this->_phpExcel->getProperties()->setModified($value);
- break;
-
- case 0x0E: // Number of Pages
- // Not supported by PHPExcel
- break;
-
- case 0x0F: // Number of Words
- // Not supported by PHPExcel
- break;
-
- case 0x10: // Number of Characters
- // Not supported by PHPExcel
- break;
-
- case 0x11: // Thumbnail
- // Not supported by PHPExcel
- break;
-
- case 0x12: // Name of creating application
- // Not supported by PHPExcel
- break;
-
- case 0x13: // Security
- // Not supported by PHPExcel
- break;
-
- }
- }
- }
-
-
- /**
- * Read additional document summary information
- */
- private function _readDocumentSummaryInformation()
- {
- if (!isset($this->_documentSummaryInformation)) {
- return;
- }
-
- // offset: 0; size: 2; must be 0xFE 0xFF (UTF-16 LE byte order mark)
- // offset: 2; size: 2;
- // offset: 4; size: 2; OS version
- // offset: 6; size: 2; OS indicator
- // offset: 8; size: 16
- // offset: 24; size: 4; section count
- $secCount = self::_GetInt4d($this->_documentSummaryInformation, 24);
-// echo '$secCount = ',$secCount,'
';
-
- // offset: 28; size: 16; first section's class id: 02 d5 cd d5 9c 2e 1b 10 93 97 08 00 2b 2c f9 ae
- // offset: 44; size: 4; first section offset
- $secOffset = self::_GetInt4d($this->_documentSummaryInformation, 44);
-// echo '$secOffset = ',$secOffset,'
';
-
- // section header
- // offset: $secOffset; size: 4; section length
- $secLength = self::_GetInt4d($this->_documentSummaryInformation, $secOffset);
-// echo '$secLength = ',$secLength,'
';
-
- // offset: $secOffset+4; size: 4; property count
- $countProperties = self::_GetInt4d($this->_documentSummaryInformation, $secOffset+4);
-// echo '$countProperties = ',$countProperties,'
';
-
- // initialize code page (used to resolve string values)
- $codePage = 'CP1252';
-
- // offset: ($secOffset+8); size: var
- // loop through property decarations and properties
- for ($i = 0; $i < $countProperties; ++$i) {
-// echo 'Property ',$i,'
';
- // offset: ($secOffset+8) + (8 * $i); size: 4; property ID
- $id = self::_GetInt4d($this->_documentSummaryInformation, ($secOffset+8) + (8 * $i));
-// echo 'ID is ',$id,'
';
-
- // Use value of property id as appropriate
- // offset: 60 + 8 * $i; size: 4; offset from beginning of section (48)
- $offset = self::_GetInt4d($this->_documentSummaryInformation, ($secOffset+12) + (8 * $i));
-
- $type = self::_GetInt4d($this->_documentSummaryInformation, $secOffset + $offset);
-// echo 'Type is ',$type,', ';
-
- // initialize property value
- $value = null;
-
- // extract property value based on property type
- switch ($type) {
- case 0x02: // 2 byte signed integer
- $value = self::_GetInt2d($this->_documentSummaryInformation, $secOffset + 4 + $offset);
- break;
-
- case 0x03: // 4 byte signed integer
- $value = self::_GetInt4d($this->_documentSummaryInformation, $secOffset + 4 + $offset);
- break;
-
- case 0x0B: // Boolean
- $value = self::_GetInt2d($this->_documentSummaryInformation, $secOffset + 4 + $offset);
- $value = ($value == 0 ? false : true);
- break;
-
- case 0x13: // 4 byte unsigned integer
- // not needed yet, fix later if necessary
- break;
-
- case 0x1E: // null-terminated string prepended by dword string length
- $byteLength = self::_GetInt4d($this->_documentSummaryInformation, $secOffset + 4 + $offset);
- $value = substr($this->_documentSummaryInformation, $secOffset + 8 + $offset, $byteLength);
- $value = PHPExcel_Shared_String::ConvertEncoding($value, 'UTF-8', $codePage);
- $value = rtrim($value);
- break;
-
- case 0x40: // Filetime (64-bit value representing the number of 100-nanosecond intervals since January 1, 1601)
- // PHP-Time
- $value = PHPExcel_Shared_OLE::OLE2LocalDate(substr($this->_documentSummaryInformation, $secOffset + 4 + $offset, 8));
- break;
-
- case 0x47: // Clipboard format
- // not needed yet, fix later if necessary
- break;
- }
-
- switch ($id) {
- case 0x01: // Code Page
- $codePage = PHPExcel_Shared_CodePage::NumberToName($value);
- break;
-
- case 0x02: // Category
- $this->_phpExcel->getProperties()->setCategory($value);
- break;
-
- case 0x03: // Presentation Target
- // Not supported by PHPExcel
- break;
-
- case 0x04: // Bytes
- // Not supported by PHPExcel
- break;
-
- case 0x05: // Lines
- // Not supported by PHPExcel
- break;
-
- case 0x06: // Paragraphs
- // Not supported by PHPExcel
- break;
-
- case 0x07: // Slides
- // Not supported by PHPExcel
- break;
-
- case 0x08: // Notes
- // Not supported by PHPExcel
- break;
-
- case 0x09: // Hidden Slides
- // Not supported by PHPExcel
- break;
-
- case 0x0A: // MM Clips
- // Not supported by PHPExcel
- break;
-
- case 0x0B: // Scale Crop
- // Not supported by PHPExcel
- break;
-
- case 0x0C: // Heading Pairs
- // Not supported by PHPExcel
- break;
-
- case 0x0D: // Titles of Parts
- // Not supported by PHPExcel
- break;
-
- case 0x0E: // Manager
- $this->_phpExcel->getProperties()->setManager($value);
- break;
-
- case 0x0F: // Company
- $this->_phpExcel->getProperties()->setCompany($value);
- break;
-
- case 0x10: // Links up-to-date
- // Not supported by PHPExcel
- break;
-
- }
- }
- }
-
-
- /**
- * Reads a general type of BIFF record. Does nothing except for moving stream pointer forward to next record.
- */
- private function _readDefault()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
-// $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
- }
-
-
- /**
- * The NOTE record specifies a comment associated with a particular cell. In Excel 95 (BIFF7) and earlier versions,
- * this record stores a note (cell note). This feature was significantly enhanced in Excel 97.
- */
- private function _readNote()
- {
-// echo 'Read Cell Annotation
';
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- if ($this->_readDataOnly) {
- return;
- }
-
- $cellAddress = $this->_readBIFF8CellAddress(substr($recordData, 0, 4));
- if ($this->_version == self::XLS_BIFF8) {
- $noteObjID = self::_GetInt2d($recordData, 6);
- $noteAuthor = self::_readUnicodeStringLong(substr($recordData, 8));
- $noteAuthor = $noteAuthor['value'];
-// echo 'Note Address=',$cellAddress,'
';
-// echo 'Note Object ID=',$noteObjID,'
';
-// echo 'Note Author=',$noteAuthor,'
';
-//
- $this->_cellNotes[$noteObjID] = array('cellRef' => $cellAddress,
- 'objectID' => $noteObjID,
- 'author' => $noteAuthor
- );
- } else {
- $extension = false;
- if ($cellAddress == '$B$65536') {
- // If the address row is -1 and the column is 0, (which translates as $B$65536) then this is a continuation
- // note from the previous cell annotation. We're not yet handling this, so annotations longer than the
- // max 2048 bytes will probably throw a wobbly.
- $row = self::_GetInt2d($recordData, 0);
- $extension = true;
- $cellAddress = array_pop(array_keys($this->_phpSheet->getComments()));
- }
-// echo 'Note Address=',$cellAddress,'
';
-
- $cellAddress = str_replace('$','',$cellAddress);
- $noteLength = self::_GetInt2d($recordData, 4);
- $noteText = trim(substr($recordData, 6));
-// echo 'Note Length=',$noteLength,'
';
-// echo 'Note Text=',$noteText,'
';
-
- if ($extension) {
- // Concatenate this extension with the currently set comment for the cell
- $comment = $this->_phpSheet->getComment( $cellAddress );
- $commentText = $comment->getText()->getPlainText();
- $comment->setText($this->_parseRichText($commentText.$noteText) );
- } else {
- // Set comment for the cell
- $this->_phpSheet->getComment( $cellAddress )
-// ->setAuthor( $author )
- ->setText($this->_parseRichText($noteText) );
- }
- }
-
- }
-
-
- /**
- * The TEXT Object record contains the text associated with a cell annotation.
- */
- private function _readTextObject()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- if ($this->_readDataOnly) {
- return;
- }
-
- // recordData consists of an array of subrecords looking like this:
- // grbit: 2 bytes; Option Flags
- // rot: 2 bytes; rotation
- // cchText: 2 bytes; length of the text (in the first continue record)
- // cbRuns: 2 bytes; length of the formatting (in the second continue record)
- // followed by the continuation records containing the actual text and formatting
- $grbitOpts = self::_GetInt2d($recordData, 0);
- $rot = self::_GetInt2d($recordData, 2);
- $cchText = self::_GetInt2d($recordData, 10);
- $cbRuns = self::_GetInt2d($recordData, 12);
- $text = $this->_getSplicedRecordData();
-
- $this->_textObjects[$this->textObjRef] = array(
- 'text' => substr($text["recordData"],$text["spliceOffsets"][0]+1,$cchText),
- 'format' => substr($text["recordData"],$text["spliceOffsets"][1],$cbRuns),
- 'alignment' => $grbitOpts,
- 'rotation' => $rot
- );
-
-// echo '_readTextObject()
';
-// var_dump($this->_textObjects[$this->textObjRef]);
-// echo '
';
- }
-
-
- /**
- * Read BOF
- */
- private function _readBof()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- // offset: 2; size: 2; type of the following data
- $substreamType = self::_GetInt2d($recordData, 2);
-
- switch ($substreamType) {
- case self::XLS_WorkbookGlobals:
- $version = self::_GetInt2d($recordData, 0);
- if (($version != self::XLS_BIFF8) && ($version != self::XLS_BIFF7)) {
- throw new Exception('Cannot read this Excel file. Version is too old.');
- }
- $this->_version = $version;
- break;
-
- case self::XLS_Worksheet:
- // do not use this version information for anything
- // it is unreliable (OpenOffice doc, 5.8), use only version information from the global stream
- break;
-
- default:
- // substream, e.g. chart
- // just skip the entire substream
- do {
- $code = self::_GetInt2d($this->_data, $this->_pos);
- $this->_readDefault();
- } while ($code != self::XLS_Type_EOF && $this->_pos < $this->_dataSize);
- break;
- }
- }
-
-
- /**
- * FILEPASS
- *
- * This record is part of the File Protection Block. It
- * contains information about the read/write password of the
- * file. All record contents following this record will be
- * encrypted.
- *
- * -- "OpenOffice.org's Documentation of the Microsoft
- * Excel File Format"
- */
- private function _readFilepass()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
-// $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- throw new Exception('Cannot read encrypted file');
- }
-
-
- /**
- * CODEPAGE
- *
- * This record stores the text encoding used to write byte
- * strings, stored as MS Windows code page identifier.
- *
- * -- "OpenOffice.org's Documentation of the Microsoft
- * Excel File Format"
- */
- private function _readCodepage()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- // offset: 0; size: 2; code page identifier
- $codepage = self::_GetInt2d($recordData, 0);
-
- $this->_codepage = PHPExcel_Shared_CodePage::NumberToName($codepage);
- }
-
-
- /**
- * DATEMODE
- *
- * This record specifies the base date for displaying date
- * values. All dates are stored as count of days past this
- * base date. In BIFF2-BIFF4 this record is part of the
- * Calculation Settings Block. In BIFF5-BIFF8 it is
- * stored in the Workbook Globals Substream.
- *
- * -- "OpenOffice.org's Documentation of the Microsoft
- * Excel File Format"
- */
- private function _readDateMode()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- // offset: 0; size: 2; 0 = base 1900, 1 = base 1904
- PHPExcel_Shared_Date::setExcelCalendar(PHPExcel_Shared_Date::CALENDAR_WINDOWS_1900);
- if (ord($recordData{0}) == 1) {
- PHPExcel_Shared_Date::setExcelCalendar(PHPExcel_Shared_Date::CALENDAR_MAC_1904);
- }
- }
-
-
- /**
- * Read a FONT record
- */
- private function _readFont()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- if (!$this->_readDataOnly) {
- $objFont = new PHPExcel_Style_Font();
-
- // offset: 0; size: 2; height of the font (in twips = 1/20 of a point)
- $size = self::_GetInt2d($recordData, 0);
- $objFont->setSize($size / 20);
-
- // offset: 2; size: 2; option flags
- // bit: 0; mask 0x0001; bold (redundant in BIFF5-BIFF8)
- // bit: 1; mask 0x0002; italic
- $isItalic = (0x0002 & self::_GetInt2d($recordData, 2)) >> 1;
- if ($isItalic) $objFont->setItalic(true);
-
- // bit: 2; mask 0x0004; underlined (redundant in BIFF5-BIFF8)
- // bit: 3; mask 0x0008; strike
- $isStrike = (0x0008 & self::_GetInt2d($recordData, 2)) >> 3;
- if ($isStrike) $objFont->setStrikethrough(true);
-
- // offset: 4; size: 2; colour index
- $colorIndex = self::_GetInt2d($recordData, 4);
- $objFont->colorIndex = $colorIndex;
-
- // offset: 6; size: 2; font weight
- $weight = self::_GetInt2d($recordData, 6);
- switch ($weight) {
- case 0x02BC:
- $objFont->setBold(true);
- break;
- }
-
- // offset: 8; size: 2; escapement type
- $escapement = self::_GetInt2d($recordData, 8);
- switch ($escapement) {
- case 0x0001:
- $objFont->setSuperScript(true);
- break;
- case 0x0002:
- $objFont->setSubScript(true);
- break;
- }
-
- // offset: 10; size: 1; underline type
- $underlineType = ord($recordData{10});
- switch ($underlineType) {
- case 0x00:
- break; // no underline
- case 0x01:
- $objFont->setUnderline(PHPExcel_Style_Font::UNDERLINE_SINGLE);
- break;
- case 0x02:
- $objFont->setUnderline(PHPExcel_Style_Font::UNDERLINE_DOUBLE);
- break;
- case 0x21:
- $objFont->setUnderline(PHPExcel_Style_Font::UNDERLINE_SINGLEACCOUNTING);
- break;
- case 0x22:
- $objFont->setUnderline(PHPExcel_Style_Font::UNDERLINE_DOUBLEACCOUNTING);
- break;
- }
-
- // offset: 11; size: 1; font family
- // offset: 12; size: 1; character set
- // offset: 13; size: 1; not used
- // offset: 14; size: var; font name
- if ($this->_version == self::XLS_BIFF8) {
- $string = self::_readUnicodeStringShort(substr($recordData, 14));
- } else {
- $string = $this->_readByteStringShort(substr($recordData, 14));
- }
- $objFont->setName($string['value']);
-
- $this->_objFonts[] = $objFont;
- }
- }
-
-
- /**
- * FORMAT
- *
- * This record contains information about a number format.
- * All FORMAT records occur together in a sequential list.
- *
- * In BIFF2-BIFF4 other records referencing a FORMAT record
- * contain a zero-based index into this list. From BIFF5 on
- * the FORMAT record contains the index itself that will be
- * used by other records.
- *
- * -- "OpenOffice.org's Documentation of the Microsoft
- * Excel File Format"
- */
- private function _readFormat()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- if (!$this->_readDataOnly) {
- $indexCode = self::_GetInt2d($recordData, 0);
-
- if ($this->_version == self::XLS_BIFF8) {
- $string = self::_readUnicodeStringLong(substr($recordData, 2));
- } else {
- // BIFF7
- $string = $this->_readByteStringShort(substr($recordData, 2));
- }
-
- $formatString = $string['value'];
- $this->_formats[$indexCode] = $formatString;
- }
- }
-
-
- /**
- * XF - Extended Format
- *
- * This record contains formatting information for cells, rows, columns or styles.
- * According to http://support.microsoft.com/kb/147732 there are always at least 15 cell style XF
- * and 1 cell XF.
- * Inspection of Excel files generated by MS Office Excel shows that XF records 0-14 are cell style XF
- * and XF record 15 is a cell XF
- * We only read the first cell style XF and skip the remaining cell style XF records
- * We read all cell XF records.
- *
- * -- "OpenOffice.org's Documentation of the Microsoft
- * Excel File Format"
- */
- private function _readXf()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- $objStyle = new PHPExcel_Style();
-
- if (!$this->_readDataOnly) {
- // offset: 0; size: 2; Index to FONT record
- if (self::_GetInt2d($recordData, 0) < 4) {
- $fontIndex = self::_GetInt2d($recordData, 0);
- } else {
- // this has to do with that index 4 is omitted in all BIFF versions for some strange reason
- // check the OpenOffice documentation of the FONT record
- $fontIndex = self::_GetInt2d($recordData, 0) - 1;
- }
- $objStyle->setFont($this->_objFonts[$fontIndex]);
-
- // offset: 2; size: 2; Index to FORMAT record
- $numberFormatIndex = self::_GetInt2d($recordData, 2);
- if (isset($this->_formats[$numberFormatIndex])) {
- // then we have user-defined format code
- $numberformat = array('code' => $this->_formats[$numberFormatIndex]);
- } elseif (($code = PHPExcel_Style_NumberFormat::builtInFormatCode($numberFormatIndex)) !== '') {
- // then we have built-in format code
- $numberformat = array('code' => $code);
- } else {
- // we set the general format code
- $numberformat = array('code' => 'General');
- }
- $objStyle->getNumberFormat()->setFormatCode($numberformat['code']);
-
- // offset: 4; size: 2; XF type, cell protection, and parent style XF
- // bit 2-0; mask 0x0007; XF_TYPE_PROT
- $xfTypeProt = self::_GetInt2d($recordData, 4);
- // bit 0; mask 0x01; 1 = cell is locked
- $isLocked = (0x01 & $xfTypeProt) >> 0;
- $objStyle->getProtection()->setLocked($isLocked ?
- PHPExcel_Style_Protection::PROTECTION_INHERIT : PHPExcel_Style_Protection::PROTECTION_UNPROTECTED);
-
- // bit 1; mask 0x02; 1 = Formula is hidden
- $isHidden = (0x02 & $xfTypeProt) >> 1;
- $objStyle->getProtection()->setHidden($isHidden ?
- PHPExcel_Style_Protection::PROTECTION_PROTECTED : PHPExcel_Style_Protection::PROTECTION_UNPROTECTED);
-
- // bit 2; mask 0x04; 0 = Cell XF, 1 = Cell Style XF
- $isCellStyleXf = (0x04 & $xfTypeProt) >> 2;
-
- // offset: 6; size: 1; Alignment and text break
- // bit 2-0, mask 0x07; horizontal alignment
- $horAlign = (0x07 & ord($recordData{6})) >> 0;
- switch ($horAlign) {
- case 0:
- $objStyle->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_GENERAL);
- break;
- case 1:
- $objStyle->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
- break;
- case 2:
- $objStyle->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- break;
- case 3:
- $objStyle->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
- break;
- case 5:
- $objStyle->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY);
- break;
- case 6:
- $objStyle->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER_CONTINUOUS);
- break;
- }
- // bit 3, mask 0x08; wrap text
- $wrapText = (0x08 & ord($recordData{6})) >> 3;
- switch ($wrapText) {
- case 0:
- $objStyle->getAlignment()->setWrapText(false);
- break;
- case 1:
- $objStyle->getAlignment()->setWrapText(true);
- break;
- }
- // bit 6-4, mask 0x70; vertical alignment
- $vertAlign = (0x70 & ord($recordData{6})) >> 4;
- switch ($vertAlign) {
- case 0:
- $objStyle->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_TOP);
- break;
- case 1:
- $objStyle->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
- break;
- case 2:
- $objStyle->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_BOTTOM);
- break;
- case 3:
- $objStyle->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_JUSTIFY);
- break;
- }
-
- if ($this->_version == self::XLS_BIFF8) {
- // offset: 7; size: 1; XF_ROTATION: Text rotation angle
- $angle = ord($recordData{7});
- $rotation = 0;
- if ($angle <= 90) {
- $rotation = $angle;
- } else if ($angle <= 180) {
- $rotation = 90 - $angle;
- } else if ($angle == 255) {
- $rotation = -165;
- }
- $objStyle->getAlignment()->setTextRotation($rotation);
-
- // offset: 8; size: 1; Indentation, shrink to cell size, and text direction
- // bit: 3-0; mask: 0x0F; indent level
- $indent = (0x0F & ord($recordData{8})) >> 0;
- $objStyle->getAlignment()->setIndent($indent);
-
- // bit: 4; mask: 0x10; 1 = shrink content to fit into cell
- $shrinkToFit = (0x10 & ord($recordData{8})) >> 4;
- switch ($shrinkToFit) {
- case 0:
- $objStyle->getAlignment()->setShrinkToFit(false);
- break;
- case 1:
- $objStyle->getAlignment()->setShrinkToFit(true);
- break;
- }
-
- // offset: 9; size: 1; Flags used for attribute groups
-
- // offset: 10; size: 4; Cell border lines and background area
- // bit: 3-0; mask: 0x0000000F; left style
- if ($bordersLeftStyle = self::_mapBorderStyle((0x0000000F & self::_GetInt4d($recordData, 10)) >> 0)) {
- $objStyle->getBorders()->getLeft()->setBorderStyle($bordersLeftStyle);
- }
- // bit: 7-4; mask: 0x000000F0; right style
- if ($bordersRightStyle = self::_mapBorderStyle((0x000000F0 & self::_GetInt4d($recordData, 10)) >> 4)) {
- $objStyle->getBorders()->getRight()->setBorderStyle($bordersRightStyle);
- }
- // bit: 11-8; mask: 0x00000F00; top style
- if ($bordersTopStyle = self::_mapBorderStyle((0x00000F00 & self::_GetInt4d($recordData, 10)) >> 8)) {
- $objStyle->getBorders()->getTop()->setBorderStyle($bordersTopStyle);
- }
- // bit: 15-12; mask: 0x0000F000; bottom style
- if ($bordersBottomStyle = self::_mapBorderStyle((0x0000F000 & self::_GetInt4d($recordData, 10)) >> 12)) {
- $objStyle->getBorders()->getBottom()->setBorderStyle($bordersBottomStyle);
- }
- // bit: 22-16; mask: 0x007F0000; left color
- $objStyle->getBorders()->getLeft()->colorIndex = (0x007F0000 & self::_GetInt4d($recordData, 10)) >> 16;
-
- // bit: 29-23; mask: 0x3F800000; right color
- $objStyle->getBorders()->getRight()->colorIndex = (0x3F800000 & self::_GetInt4d($recordData, 10)) >> 23;
-
- // bit: 30; mask: 0x40000000; 1 = diagonal line from top left to right bottom
- $diagonalDown = (0x40000000 & self::_GetInt4d($recordData, 10)) >> 30 ?
- true : false;
-
- // bit: 31; mask: 0x80000000; 1 = diagonal line from bottom left to top right
- $diagonalUp = (0x80000000 & self::_GetInt4d($recordData, 10)) >> 31 ?
- true : false;
-
- if ($diagonalUp == false && $diagonalDown == false) {
- $objStyle->getBorders()->setDiagonalDirection(PHPExcel_Style_Borders::DIAGONAL_NONE);
- } elseif ($diagonalUp == true && $diagonalDown == false) {
- $objStyle->getBorders()->setDiagonalDirection(PHPExcel_Style_Borders::DIAGONAL_UP);
- } elseif ($diagonalUp == false && $diagonalDown == true) {
- $objStyle->getBorders()->setDiagonalDirection(PHPExcel_Style_Borders::DIAGONAL_DOWN);
- } elseif ($diagonalUp == true && $diagonalDown == true) {
- $objStyle->getBorders()->setDiagonalDirection(PHPExcel_Style_Borders::DIAGONAL_BOTH);
- }
-
- // offset: 14; size: 4;
- // bit: 6-0; mask: 0x0000007F; top color
- $objStyle->getBorders()->getTop()->colorIndex = (0x0000007F & self::_GetInt4d($recordData, 14)) >> 0;
-
- // bit: 13-7; mask: 0x00003F80; bottom color
- $objStyle->getBorders()->getBottom()->colorIndex = (0x00003F80 & self::_GetInt4d($recordData, 14)) >> 7;
-
- // bit: 20-14; mask: 0x001FC000; diagonal color
- $objStyle->getBorders()->getDiagonal()->colorIndex = (0x001FC000 & self::_GetInt4d($recordData, 14)) >> 14;
-
- // bit: 24-21; mask: 0x01E00000; diagonal style
- if ($bordersDiagonalStyle = self::_mapBorderStyle((0x01E00000 & self::_GetInt4d($recordData, 14)) >> 21)) {
- $objStyle->getBorders()->getDiagonal()->setBorderStyle($bordersDiagonalStyle);
- }
-
- // bit: 31-26; mask: 0xFC000000 fill pattern
- if ($fillType = self::_mapFillPattern((0xFC000000 & self::_GetInt4d($recordData, 14)) >> 26)) {
- $objStyle->getFill()->setFillType($fillType);
- }
- // offset: 18; size: 2; pattern and background colour
- // bit: 6-0; mask: 0x007F; color index for pattern color
- $objStyle->getFill()->startcolorIndex = (0x007F & self::_GetInt2d($recordData, 18)) >> 0;
-
- // bit: 13-7; mask: 0x3F80; color index for pattern background
- $objStyle->getFill()->endcolorIndex = (0x3F80 & self::_GetInt2d($recordData, 18)) >> 7;
- } else {
- // BIFF5
-
- // offset: 7; size: 1; Text orientation and flags
- $orientationAndFlags = ord($recordData{7});
-
- // bit: 1-0; mask: 0x03; XF_ORIENTATION: Text orientation
- $xfOrientation = (0x03 & $orientationAndFlags) >> 0;
- switch ($xfOrientation) {
- case 0:
- $objStyle->getAlignment()->setTextRotation(0);
- break;
- case 1:
- $objStyle->getAlignment()->setTextRotation(-165);
- break;
- case 2:
- $objStyle->getAlignment()->setTextRotation(90);
- break;
- case 3:
- $objStyle->getAlignment()->setTextRotation(-90);
- break;
- }
-
- // offset: 8; size: 4; cell border lines and background area
- $borderAndBackground = self::_GetInt4d($recordData, 8);
-
- // bit: 6-0; mask: 0x0000007F; color index for pattern color
- $objStyle->getFill()->startcolorIndex = (0x0000007F & $borderAndBackground) >> 0;
-
- // bit: 13-7; mask: 0x00003F80; color index for pattern background
- $objStyle->getFill()->endcolorIndex = (0x00003F80 & $borderAndBackground) >> 7;
-
- // bit: 21-16; mask: 0x003F0000; fill pattern
- $objStyle->getFill()->setFillType(self::_mapFillPattern((0x003F0000 & $borderAndBackground) >> 16));
-
- // bit: 24-22; mask: 0x01C00000; bottom line style
- $objStyle->getBorders()->getBottom()->setBorderStyle(self::_mapBorderStyle((0x01C00000 & $borderAndBackground) >> 22));
-
- // bit: 31-25; mask: 0xFE000000; bottom line color
- $objStyle->getBorders()->getBottom()->colorIndex = (0xFE000000 & $borderAndBackground) >> 25;
-
- // offset: 12; size: 4; cell border lines
- $borderLines = self::_GetInt4d($recordData, 12);
-
- // bit: 2-0; mask: 0x00000007; top line style
- $objStyle->getBorders()->getTop()->setBorderStyle(self::_mapBorderStyle((0x00000007 & $borderLines) >> 0));
-
- // bit: 5-3; mask: 0x00000038; left line style
- $objStyle->getBorders()->getLeft()->setBorderStyle(self::_mapBorderStyle((0x00000038 & $borderLines) >> 3));
-
- // bit: 8-6; mask: 0x000001C0; right line style
- $objStyle->getBorders()->getRight()->setBorderStyle(self::_mapBorderStyle((0x000001C0 & $borderLines) >> 6));
-
- // bit: 15-9; mask: 0x0000FE00; top line color index
- $objStyle->getBorders()->getTop()->colorIndex = (0x0000FE00 & $borderLines) >> 9;
-
- // bit: 22-16; mask: 0x007F0000; left line color index
- $objStyle->getBorders()->getLeft()->colorIndex = (0x007F0000 & $borderLines) >> 16;
-
- // bit: 29-23; mask: 0x3F800000; right line color index
- $objStyle->getBorders()->getRight()->colorIndex = (0x3F800000 & $borderLines) >> 23;
- }
-
- // add cellStyleXf or cellXf and update mapping
- if ($isCellStyleXf) {
- // we only read one style XF record which is always the first
- if ($this->_xfIndex == 0) {
- $this->_phpExcel->addCellStyleXf($objStyle);
- $this->_mapCellStyleXfIndex[$this->_xfIndex] = 0;
- }
- } else {
- // we read all cell XF records
- $this->_phpExcel->addCellXf($objStyle);
- $this->_mapCellXfIndex[$this->_xfIndex] = count($this->_phpExcel->getCellXfCollection()) - 1;
- }
-
- // update XF index for when we read next record
- ++$this->_xfIndex;
- }
- }
-
-
- /**
- *
- */
- private function _readXfExt()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- if (!$this->_readDataOnly) {
- // offset: 0; size: 2; 0x087D = repeated header
-
- // offset: 2; size: 2
-
- // offset: 4; size: 8; not used
-
- // offset: 12; size: 2; record version
-
- // offset: 14; size: 2; index to XF record which this record modifies
- $ixfe = self::_GetInt2d($recordData, 14);
-
- // offset: 16; size: 2; not used
-
- // offset: 18; size: 2; number of extension properties that follow
- $cexts = self::_GetInt2d($recordData, 18);
-
- // start reading the actual extension data
- $offset = 20;
- while ($offset < $length) {
- // extension type
- $extType = self::_GetInt2d($recordData, $offset);
-
- // extension length
- $cb = self::_GetInt2d($recordData, $offset + 2);
-
- // extension data
- $extData = substr($recordData, $offset + 4, $cb);
-
- switch ($extType) {
- case 4: // fill start color
- $xclfType = self::_GetInt2d($extData, 0); // color type
- $xclrValue = substr($extData, 4, 4); // color value (value based on color type)
-
- if ($xclfType == 2) {
- $rgb = sprintf('%02X%02X%02X', ord($xclrValue{0}), ord($xclrValue{1}), ord($xclrValue{2}));
-
- // modify the relevant style property
- if ( isset($this->_mapCellXfIndex[$ixfe]) ) {
- $fill = $this->_phpExcel->getCellXfByIndex($this->_mapCellXfIndex[$ixfe])->getFill();
- $fill->getStartColor()->setRGB($rgb);
- unset($fill->startcolorIndex); // normal color index does not apply, discard
- }
- }
- break;
-
- case 5: // fill end color
- $xclfType = self::_GetInt2d($extData, 0); // color type
- $xclrValue = substr($extData, 4, 4); // color value (value based on color type)
-
- if ($xclfType == 2) {
- $rgb = sprintf('%02X%02X%02X', ord($xclrValue{0}), ord($xclrValue{1}), ord($xclrValue{2}));
-
- // modify the relevant style property
- if ( isset($this->_mapCellXfIndex[$ixfe]) ) {
- $fill = $this->_phpExcel->getCellXfByIndex($this->_mapCellXfIndex[$ixfe])->getFill();
- $fill->getEndColor()->setRGB($rgb);
- unset($fill->endcolorIndex); // normal color index does not apply, discard
- }
- }
- break;
-
- case 7: // border color top
- $xclfType = self::_GetInt2d($extData, 0); // color type
- $xclrValue = substr($extData, 4, 4); // color value (value based on color type)
-
- if ($xclfType == 2) {
- $rgb = sprintf('%02X%02X%02X', ord($xclrValue{0}), ord($xclrValue{1}), ord($xclrValue{2}));
-
- // modify the relevant style property
- if ( isset($this->_mapCellXfIndex[$ixfe]) ) {
- $top = $this->_phpExcel->getCellXfByIndex($this->_mapCellXfIndex[$ixfe])->getBorders()->getTop();
- $top->getColor()->setRGB($rgb);
- unset($top->colorIndex); // normal color index does not apply, discard
- }
- }
- break;
-
- case 8: // border color bottom
- $xclfType = self::_GetInt2d($extData, 0); // color type
- $xclrValue = substr($extData, 4, 4); // color value (value based on color type)
-
- if ($xclfType == 2) {
- $rgb = sprintf('%02X%02X%02X', ord($xclrValue{0}), ord($xclrValue{1}), ord($xclrValue{2}));
-
- // modify the relevant style property
- if ( isset($this->_mapCellXfIndex[$ixfe]) ) {
- $bottom = $this->_phpExcel->getCellXfByIndex($this->_mapCellXfIndex[$ixfe])->getBorders()->getBottom();
- $bottom->getColor()->setRGB($rgb);
- unset($bottom->colorIndex); // normal color index does not apply, discard
- }
- }
- break;
-
- case 9: // border color left
- $xclfType = self::_GetInt2d($extData, 0); // color type
- $xclrValue = substr($extData, 4, 4); // color value (value based on color type)
-
- if ($xclfType == 2) {
- $rgb = sprintf('%02X%02X%02X', ord($xclrValue{0}), ord($xclrValue{1}), ord($xclrValue{2}));
-
- // modify the relevant style property
- if ( isset($this->_mapCellXfIndex[$ixfe]) ) {
- $left = $this->_phpExcel->getCellXfByIndex($this->_mapCellXfIndex[$ixfe])->getBorders()->getLeft();
- $left->getColor()->setRGB($rgb);
- unset($left->colorIndex); // normal color index does not apply, discard
- }
- }
- break;
-
- case 10: // border color right
- $xclfType = self::_GetInt2d($extData, 0); // color type
- $xclrValue = substr($extData, 4, 4); // color value (value based on color type)
-
- if ($xclfType == 2) {
- $rgb = sprintf('%02X%02X%02X', ord($xclrValue{0}), ord($xclrValue{1}), ord($xclrValue{2}));
-
- // modify the relevant style property
- if ( isset($this->_mapCellXfIndex[$ixfe]) ) {
- $right = $this->_phpExcel->getCellXfByIndex($this->_mapCellXfIndex[$ixfe])->getBorders()->getRight();
- $right->getColor()->setRGB($rgb);
- unset($right->colorIndex); // normal color index does not apply, discard
- }
- }
- break;
-
- case 11: // border color diagonal
- $xclfType = self::_GetInt2d($extData, 0); // color type
- $xclrValue = substr($extData, 4, 4); // color value (value based on color type)
-
- if ($xclfType == 2) {
- $rgb = sprintf('%02X%02X%02X', ord($xclrValue{0}), ord($xclrValue{1}), ord($xclrValue{2}));
-
- // modify the relevant style property
- if ( isset($this->_mapCellXfIndex[$ixfe]) ) {
- $diagonal = $this->_phpExcel->getCellXfByIndex($this->_mapCellXfIndex[$ixfe])->getBorders()->getDiagonal();
- $diagonal->getColor()->setRGB($rgb);
- unset($diagonal->colorIndex); // normal color index does not apply, discard
- }
- }
- break;
-
- case 13: // font color
- $xclfType = self::_GetInt2d($extData, 0); // color type
- $xclrValue = substr($extData, 4, 4); // color value (value based on color type)
-
- if ($xclfType == 2) {
- $rgb = sprintf('%02X%02X%02X', ord($xclrValue{0}), ord($xclrValue{1}), ord($xclrValue{2}));
-
- // modify the relevant style property
- if ( isset($this->_mapCellXfIndex[$ixfe]) ) {
- $font = $this->_phpExcel->getCellXfByIndex($this->_mapCellXfIndex[$ixfe])->getFont();
- $font->getColor()->setRGB($rgb);
- unset($font->colorIndex); // normal color index does not apply, discard
- }
- }
- break;
- }
-
- $offset += $cb;
- }
- }
-
- }
-
-
- /**
- * Read STYLE record
- */
- private function _readStyle()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- if (!$this->_readDataOnly) {
- // offset: 0; size: 2; index to XF record and flag for built-in style
- $ixfe = self::_GetInt2d($recordData, 0);
-
- // bit: 11-0; mask 0x0FFF; index to XF record
- $xfIndex = (0x0FFF & $ixfe) >> 0;
-
- // bit: 15; mask 0x8000; 0 = user-defined style, 1 = built-in style
- $isBuiltIn = (bool) ((0x8000 & $ixfe) >> 15);
-
- if ($isBuiltIn) {
- // offset: 2; size: 1; identifier for built-in style
- $builtInId = ord($recordData{2});
-
- switch ($builtInId) {
- case 0x00:
- // currently, we are not using this for anything
- break;
-
- default:
- break;
- }
-
- } else {
- // user-defined; not supported by PHPExcel
- }
- }
- }
-
-
- /**
- * Read PALETTE record
- */
- private function _readPalette()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- if (!$this->_readDataOnly) {
- // offset: 0; size: 2; number of following colors
- $nm = self::_GetInt2d($recordData, 0);
-
- // list of RGB colors
- for ($i = 0; $i < $nm; ++$i) {
- $rgb = substr($recordData, 2 + 4 * $i, 4);
- $this->_palette[] = self::_readRGB($rgb);
- }
- }
- }
-
-
- /**
- * SHEET
- *
- * This record is located in the Workbook Globals
- * Substream and represents a sheet inside the workbook.
- * One SHEET record is written for each sheet. It stores the
- * sheet name and a stream offset to the BOF record of the
- * respective Sheet Substream within the Workbook Stream.
- *
- * -- "OpenOffice.org's Documentation of the Microsoft
- * Excel File Format"
- */
- private function _readSheet()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- // offset: 0; size: 4; absolute stream position of the BOF record of the sheet
- $rec_offset = self::_GetInt4d($recordData, 0);
-
- // offset: 4; size: 1; sheet state
- switch (ord($recordData{4})) {
- case 0x00: $sheetState = PHPExcel_Worksheet::SHEETSTATE_VISIBLE; break;
- case 0x01: $sheetState = PHPExcel_Worksheet::SHEETSTATE_HIDDEN; break;
- case 0x02: $sheetState = PHPExcel_Worksheet::SHEETSTATE_VERYHIDDEN; break;
- default: $sheetState = PHPExcel_Worksheet::SHEETSTATE_VISIBLE; break;
- }
-
- // offset: 5; size: 1; sheet type
- $sheetType = ord($recordData{5});
-
- // offset: 6; size: var; sheet name
- if ($this->_version == self::XLS_BIFF8) {
- $string = self::_readUnicodeStringShort(substr($recordData, 6));
- $rec_name = $string['value'];
- } elseif ($this->_version == self::XLS_BIFF7) {
- $string = $this->_readByteStringShort(substr($recordData, 6));
- $rec_name = $string['value'];
- }
-
- $this->_sheets[] = array(
- 'name' => $rec_name,
- 'offset' => $rec_offset,
- 'sheetState' => $sheetState,
- 'sheetType' => $sheetType,
- );
- }
-
-
- /**
- * Read EXTERNALBOOK record
- */
- private function _readExternalBook()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- // offset within record data
- $offset = 0;
-
- // there are 4 types of records
- if (strlen($recordData) > 4) {
- // external reference
- // offset: 0; size: 2; number of sheet names ($nm)
- $nm = self::_GetInt2d($recordData, 0);
- $offset += 2;
-
- // offset: 2; size: var; encoded URL without sheet name (Unicode string, 16-bit length)
- $encodedUrlString = self::_readUnicodeStringLong(substr($recordData, 2));
- $offset += $encodedUrlString['size'];
-
- // offset: var; size: var; list of $nm sheet names (Unicode strings, 16-bit length)
- $externalSheetNames = array();
- for ($i = 0; $i < $nm; ++$i) {
- $externalSheetNameString = self::_readUnicodeStringLong(substr($recordData, $offset));
- $externalSheetNames[] = $externalSheetNameString['value'];
- $offset += $externalSheetNameString['size'];
- }
-
- // store the record data
- $this->_externalBooks[] = array(
- 'type' => 'external',
- 'encodedUrl' => $encodedUrlString['value'],
- 'externalSheetNames' => $externalSheetNames,
- );
-
- } elseif (substr($recordData, 2, 2) == pack('CC', 0x01, 0x04)) {
- // internal reference
- // offset: 0; size: 2; number of sheet in this document
- // offset: 2; size: 2; 0x01 0x04
- $this->_externalBooks[] = array(
- 'type' => 'internal',
- );
- } elseif (substr($recordData, 0, 4) == pack('vCC', 0x0001, 0x01, 0x3A)) {
- // add-in function
- // offset: 0; size: 2; 0x0001
- $this->_externalBooks[] = array(
- 'type' => 'addInFunction',
- );
- } elseif (substr($recordData, 0, 2) == pack('v', 0x0000)) {
- // DDE links, OLE links
- // offset: 0; size: 2; 0x0000
- // offset: 2; size: var; encoded source document name
- $this->_externalBooks[] = array(
- 'type' => 'DDEorOLE',
- );
- }
- }
-
-
- /**
- * Read EXTERNNAME record.
- */
- private function _readExternName()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- // external sheet references provided for named cells
- if ($this->_version == self::XLS_BIFF8) {
- // offset: 0; size: 2; options
- $options = self::_GetInt2d($recordData, 0);
-
- // offset: 2; size: 2;
-
- // offset: 4; size: 2; not used
-
- // offset: 6; size: var
- $nameString = self::_readUnicodeStringShort(substr($recordData, 6));
-
- // offset: var; size: var; formula data
- $offset = 6 + $nameString['size'];
- $formula = $this->_getFormulaFromStructure(substr($recordData, $offset));
-
- $this->_externalNames[] = array(
- 'name' => $nameString['value'],
- 'formula' => $formula,
- );
- }
- }
-
-
- /**
- * Read EXTERNSHEET record
- */
- private function _readExternSheet()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- // external sheet references provided for named cells
- if ($this->_version == self::XLS_BIFF8) {
- // offset: 0; size: 2; number of following ref structures
- $nm = self::_GetInt2d($recordData, 0);
- for ($i = 0; $i < $nm; ++$i) {
- $this->_ref[] = array(
- // offset: 2 + 6 * $i; index to EXTERNALBOOK record
- 'externalBookIndex' => self::_GetInt2d($recordData, 2 + 6 * $i),
- // offset: 4 + 6 * $i; index to first sheet in EXTERNALBOOK record
- 'firstSheetIndex' => self::_GetInt2d($recordData, 4 + 6 * $i),
- // offset: 6 + 6 * $i; index to last sheet in EXTERNALBOOK record
- 'lastSheetIndex' => self::_GetInt2d($recordData, 6 + 6 * $i),
- );
- }
- }
- }
-
-
- /**
- * DEFINEDNAME
- *
- * This record is part of a Link Table. It contains the name
- * and the token array of an internal defined name. Token
- * arrays of defined names contain tokens with aberrant
- * token classes.
- *
- * -- "OpenOffice.org's Documentation of the Microsoft
- * Excel File Format"
- */
- private function _readDefinedName()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- if ($this->_version == self::XLS_BIFF8) {
- // retrieves named cells
-
- // offset: 0; size: 2; option flags
- $opts = self::_GetInt2d($recordData, 0);
-
- // bit: 5; mask: 0x0020; 0 = user-defined name, 1 = built-in-name
- $isBuiltInName = (0x0020 & $opts) >> 5;
-
- // offset: 2; size: 1; keyboard shortcut
-
- // offset: 3; size: 1; length of the name (character count)
- $nlen = ord($recordData{3});
-
- // offset: 4; size: 2; size of the formula data (it can happen that this is zero)
- // note: there can also be additional data, this is not included in $flen
- $flen = self::_GetInt2d($recordData, 4);
-
- // offset: 8; size: 2; 0=Global name, otherwise index to sheet (1-based)
- $scope = self::_GetInt2d($recordData, 8);
-
- // offset: 14; size: var; Name (Unicode string without length field)
- $string = self::_readUnicodeString(substr($recordData, 14), $nlen);
-
- // offset: var; size: $flen; formula data
- $offset = 14 + $string['size'];
- $formulaStructure = pack('v', $flen) . substr($recordData, $offset);
-
- try {
- $formula = $this->_getFormulaFromStructure($formulaStructure);
- } catch (Exception $e) {
- $formula = '';
- }
-
- $this->_definedname[] = array(
- 'isBuiltInName' => $isBuiltInName,
- 'name' => $string['value'],
- 'formula' => $formula,
- 'scope' => $scope,
- );
- }
- }
-
-
- /**
- * Read MSODRAWINGGROUP record
- */
- private function _readMsoDrawingGroup()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
-
- // get spliced record data
- $splicedRecordData = $this->_getSplicedRecordData();
- $recordData = $splicedRecordData['recordData'];
-
- $this->_drawingGroupData .= $recordData;
- }
-
-
- /**
- * SST - Shared String Table
- *
- * This record contains a list of all strings used anywhere
- * in the workbook. Each string occurs only once. The
- * workbook uses indexes into the list to reference the
- * strings.
- *
- * -- "OpenOffice.org's Documentation of the Microsoft
- * Excel File Format"
- **/
- private function _readSst()
- {
- // offset within (spliced) record data
- $pos = 0;
-
- // get spliced record data
- $splicedRecordData = $this->_getSplicedRecordData();
-
- $recordData = $splicedRecordData['recordData'];
- $spliceOffsets = $splicedRecordData['spliceOffsets'];
-
- // offset: 0; size: 4; total number of strings in the workbook
- $pos += 4;
-
- // offset: 4; size: 4; number of following strings ($nm)
- $nm = self::_GetInt4d($recordData, 4);
- $pos += 4;
-
- // loop through the Unicode strings (16-bit length)
- for ($i = 0; $i < $nm; ++$i) {
-
- // number of characters in the Unicode string
- $numChars = self::_GetInt2d($recordData, $pos);
- $pos += 2;
-
- // option flags
- $optionFlags = ord($recordData{$pos});
- ++$pos;
-
- // bit: 0; mask: 0x01; 0 = compressed; 1 = uncompressed
- $isCompressed = (($optionFlags & 0x01) == 0) ;
-
- // bit: 2; mask: 0x02; 0 = ordinary; 1 = Asian phonetic
- $hasAsian = (($optionFlags & 0x04) != 0);
-
- // bit: 3; mask: 0x03; 0 = ordinary; 1 = Rich-Text
- $hasRichText = (($optionFlags & 0x08) != 0);
-
- if ($hasRichText) {
- // number of Rich-Text formatting runs
- $formattingRuns = self::_GetInt2d($recordData, $pos);
- $pos += 2;
- }
-
- if ($hasAsian) {
- // size of Asian phonetic setting
- $extendedRunLength = self::_GetInt4d($recordData, $pos);
- $pos += 4;
- }
-
- // expected byte length of character array if not split
- $len = ($isCompressed) ? $numChars : $numChars * 2;
-
- // look up limit position
- foreach ($spliceOffsets as $spliceOffset) {
- // it can happen that the string is empty, therefore we need
- // <= and not just <
- if ($pos <= $spliceOffset) {
- $limitpos = $spliceOffset;
- break;
- }
- }
-
- if ($pos + $len <= $limitpos) {
- // character array is not split between records
-
- $retstr = substr($recordData, $pos, $len);
- $pos += $len;
-
- } else {
- // character array is split between records
-
- // first part of character array
- $retstr = substr($recordData, $pos, $limitpos - $pos);
-
- $bytesRead = $limitpos - $pos;
-
- // remaining characters in Unicode string
- $charsLeft = $numChars - (($isCompressed) ? $bytesRead : ($bytesRead / 2));
-
- $pos = $limitpos;
-
- // keep reading the characters
- while ($charsLeft > 0) {
-
- // look up next limit position, in case the string span more than one continue record
- foreach ($spliceOffsets as $spliceOffset) {
- if ($pos < $spliceOffset) {
- $limitpos = $spliceOffset;
- break;
- }
- }
-
- // repeated option flags
- // OpenOffice.org documentation 5.21
- $option = ord($recordData{$pos});
- ++$pos;
-
- if ($isCompressed && ($option == 0)) {
- // 1st fragment compressed
- // this fragment compressed
- $len = min($charsLeft, $limitpos - $pos);
- $retstr .= substr($recordData, $pos, $len);
- $charsLeft -= $len;
- $isCompressed = true;
-
- } elseif (!$isCompressed && ($option != 0)) {
- // 1st fragment uncompressed
- // this fragment uncompressed
- $len = min($charsLeft * 2, $limitpos - $pos);
- $retstr .= substr($recordData, $pos, $len);
- $charsLeft -= $len / 2;
- $isCompressed = false;
-
- } elseif (!$isCompressed && ($option == 0)) {
- // 1st fragment uncompressed
- // this fragment compressed
- $len = min($charsLeft, $limitpos - $pos);
- for ($j = 0; $j < $len; ++$j) {
- $retstr .= $recordData{$pos + $j} . chr(0);
- }
- $charsLeft -= $len;
- $isCompressed = false;
-
- } else {
- // 1st fragment compressed
- // this fragment uncompressed
- $newstr = '';
- for ($j = 0; $j < strlen($retstr); ++$j) {
- $newstr .= $retstr[$j] . chr(0);
- }
- $retstr = $newstr;
- $len = min($charsLeft * 2, $limitpos - $pos);
- $retstr .= substr($recordData, $pos, $len);
- $charsLeft -= $len / 2;
- $isCompressed = false;
- }
-
- $pos += $len;
- }
- }
-
- // convert to UTF-8
- $retstr = self::_encodeUTF16($retstr, $isCompressed);
-
- // read additional Rich-Text information, if any
- $fmtRuns = array();
- if ($hasRichText) {
- // list of formatting runs
- for ($j = 0; $j < $formattingRuns; ++$j) {
- // first formatted character; zero-based
- $charPos = self::_GetInt2d($recordData, $pos + $j * 4);
-
- // index to font record
- $fontIndex = self::_GetInt2d($recordData, $pos + 2 + $j * 4);
-
- $fmtRuns[] = array(
- 'charPos' => $charPos,
- 'fontIndex' => $fontIndex,
- );
- }
- $pos += 4 * $formattingRuns;
- }
-
- // read additional Asian phonetics information, if any
- if ($hasAsian) {
- // For Asian phonetic settings, we skip the extended string data
- $pos += $extendedRunLength;
- }
-
- // store the shared sting
- $this->_sst[] = array(
- 'value' => $retstr,
- 'fmtRuns' => $fmtRuns,
- );
- }
-
- // _getSplicedRecordData() takes care of moving current position in data stream
- }
-
-
- /**
- * Read PRINTGRIDLINES record
- */
- private function _readPrintGridlines()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- if ($this->_version == self::XLS_BIFF8 && !$this->_readDataOnly) {
- // offset: 0; size: 2; 0 = do not print sheet grid lines; 1 = print sheet gridlines
- $printGridlines = (bool) self::_GetInt2d($recordData, 0);
- $this->_phpSheet->setPrintGridlines($printGridlines);
- }
- }
-
-
- /**
- * Read DEFAULTROWHEIGHT record
- */
- private function _readDefaultRowHeight()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- // offset: 0; size: 2; option flags
- // offset: 2; size: 2; default height for unused rows, (twips 1/20 point)
- $height = self::_GetInt2d($recordData, 2);
- $this->_phpSheet->getDefaultRowDimension()->setRowHeight($height / 20);
- }
-
-
- /**
- * Read SHEETPR record
- */
- private function _readSheetPr()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- // offset: 0; size: 2
-
- // bit: 6; mask: 0x0040; 0 = outline buttons above outline group
- $isSummaryBelow = (0x0040 & self::_GetInt2d($recordData, 0)) >> 6;
- $this->_phpSheet->setShowSummaryBelow($isSummaryBelow);
-
- // bit: 7; mask: 0x0080; 0 = outline buttons left of outline group
- $isSummaryRight = (0x0080 & self::_GetInt2d($recordData, 0)) >> 7;
- $this->_phpSheet->setShowSummaryRight($isSummaryRight);
-
- // bit: 8; mask: 0x100; 0 = scale printout in percent, 1 = fit printout to number of pages
- // this corresponds to radio button setting in page setup dialog in Excel
- $this->_isFitToPages = (bool) ((0x0100 & self::_GetInt2d($recordData, 0)) >> 8);
- }
-
-
- /**
- * Read HORIZONTALPAGEBREAKS record
- */
- private function _readHorizontalPageBreaks()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- if ($this->_version == self::XLS_BIFF8 && !$this->_readDataOnly) {
-
- // offset: 0; size: 2; number of the following row index structures
- $nm = self::_GetInt2d($recordData, 0);
-
- // offset: 2; size: 6 * $nm; list of $nm row index structures
- for ($i = 0; $i < $nm; ++$i) {
- $r = self::_GetInt2d($recordData, 2 + 6 * $i);
- $cf = self::_GetInt2d($recordData, 2 + 6 * $i + 2);
- $cl = self::_GetInt2d($recordData, 2 + 6 * $i + 4);
-
- // not sure why two column indexes are necessary?
- $this->_phpSheet->setBreakByColumnAndRow($cf, $r, PHPExcel_Worksheet::BREAK_ROW);
- }
- }
- }
-
-
- /**
- * Read VERTICALPAGEBREAKS record
- */
- private function _readVerticalPageBreaks()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- if ($this->_version == self::XLS_BIFF8 && !$this->_readDataOnly) {
- // offset: 0; size: 2; number of the following column index structures
- $nm = self::_GetInt2d($recordData, 0);
-
- // offset: 2; size: 6 * $nm; list of $nm row index structures
- for ($i = 0; $i < $nm; ++$i) {
- $c = self::_GetInt2d($recordData, 2 + 6 * $i);
- $rf = self::_GetInt2d($recordData, 2 + 6 * $i + 2);
- $rl = self::_GetInt2d($recordData, 2 + 6 * $i + 4);
-
- // not sure why two row indexes are necessary?
- $this->_phpSheet->setBreakByColumnAndRow($c, $rf, PHPExcel_Worksheet::BREAK_COLUMN);
- }
- }
- }
-
-
- /**
- * Read HEADER record
- */
- private function _readHeader()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- if (!$this->_readDataOnly) {
- // offset: 0; size: var
- // realized that $recordData can be empty even when record exists
- if ($recordData) {
- if ($this->_version == self::XLS_BIFF8) {
- $string = self::_readUnicodeStringLong($recordData);
- } else {
- $string = $this->_readByteStringShort($recordData);
- }
-
- $this->_phpSheet->getHeaderFooter()->setOddHeader($string['value']);
- $this->_phpSheet->getHeaderFooter()->setEvenHeader($string['value']);
- }
- }
- }
-
-
- /**
- * Read FOOTER record
- */
- private function _readFooter()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- if (!$this->_readDataOnly) {
- // offset: 0; size: var
- // realized that $recordData can be empty even when record exists
- if ($recordData) {
- if ($this->_version == self::XLS_BIFF8) {
- $string = self::_readUnicodeStringLong($recordData);
- } else {
- $string = $this->_readByteStringShort($recordData);
- }
- $this->_phpSheet->getHeaderFooter()->setOddFooter($string['value']);
- $this->_phpSheet->getHeaderFooter()->setEvenFooter($string['value']);
- }
- }
- }
-
-
- /**
- * Read HCENTER record
- */
- private function _readHcenter()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- if (!$this->_readDataOnly) {
- // offset: 0; size: 2; 0 = print sheet left aligned, 1 = print sheet centered horizontally
- $isHorizontalCentered = (bool) self::_GetInt2d($recordData, 0);
-
- $this->_phpSheet->getPageSetup()->setHorizontalCentered($isHorizontalCentered);
- }
- }
-
-
- /**
- * Read VCENTER record
- */
- private function _readVcenter()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- if (!$this->_readDataOnly) {
- // offset: 0; size: 2; 0 = print sheet aligned at top page border, 1 = print sheet vertically centered
- $isVerticalCentered = (bool) self::_GetInt2d($recordData, 0);
-
- $this->_phpSheet->getPageSetup()->setVerticalCentered($isVerticalCentered);
- }
- }
-
-
- /**
- * Read LEFTMARGIN record
- */
- private function _readLeftMargin()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- if (!$this->_readDataOnly) {
- // offset: 0; size: 8
- $this->_phpSheet->getPageMargins()->setLeft(self::_extractNumber($recordData));
- }
- }
-
-
- /**
- * Read RIGHTMARGIN record
- */
- private function _readRightMargin()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- if (!$this->_readDataOnly) {
- // offset: 0; size: 8
- $this->_phpSheet->getPageMargins()->setRight(self::_extractNumber($recordData));
- }
- }
-
-
- /**
- * Read TOPMARGIN record
- */
- private function _readTopMargin()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- if (!$this->_readDataOnly) {
- // offset: 0; size: 8
- $this->_phpSheet->getPageMargins()->setTop(self::_extractNumber($recordData));
- }
- }
-
-
- /**
- * Read BOTTOMMARGIN record
- */
- private function _readBottomMargin()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- if (!$this->_readDataOnly) {
- // offset: 0; size: 8
- $this->_phpSheet->getPageMargins()->setBottom(self::_extractNumber($recordData));
- }
- }
-
-
- /**
- * Read PAGESETUP record
- */
- private function _readPageSetup()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- if (!$this->_readDataOnly) {
- // offset: 0; size: 2; paper size
- $paperSize = self::_GetInt2d($recordData, 0);
-
- // offset: 2; size: 2; scaling factor
- $scale = self::_GetInt2d($recordData, 2);
-
- // offset: 6; size: 2; fit worksheet width to this number of pages, 0 = use as many as needed
- $fitToWidth = self::_GetInt2d($recordData, 6);
-
- // offset: 8; size: 2; fit worksheet height to this number of pages, 0 = use as many as needed
- $fitToHeight = self::_GetInt2d($recordData, 8);
-
- // offset: 10; size: 2; option flags
-
- // bit: 1; mask: 0x0002; 0=landscape, 1=portrait
- $isPortrait = (0x0002 & self::_GetInt2d($recordData, 10)) >> 1;
-
- // bit: 2; mask: 0x0004; 1= paper size, scaling factor, paper orient. not init
- // when this bit is set, do not use flags for those properties
- $isNotInit = (0x0004 & self::_GetInt2d($recordData, 10)) >> 2;
-
- if (!$isNotInit) {
- $this->_phpSheet->getPageSetup()->setPaperSize($paperSize);
- switch ($isPortrait) {
- case 0: $this->_phpSheet->getPageSetup()->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE); break;
- case 1: $this->_phpSheet->getPageSetup()->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_PORTRAIT); break;
- }
-
- $this->_phpSheet->getPageSetup()->setScale($scale, false);
- $this->_phpSheet->getPageSetup()->setFitToPage((bool) $this->_isFitToPages);
- $this->_phpSheet->getPageSetup()->setFitToWidth($fitToWidth, false);
- $this->_phpSheet->getPageSetup()->setFitToHeight($fitToHeight, false);
- }
-
- // offset: 16; size: 8; header margin (IEEE 754 floating-point value)
- $marginHeader = self::_extractNumber(substr($recordData, 16, 8));
- $this->_phpSheet->getPageMargins()->setHeader($marginHeader);
-
- // offset: 24; size: 8; footer margin (IEEE 754 floating-point value)
- $marginFooter = self::_extractNumber(substr($recordData, 24, 8));
- $this->_phpSheet->getPageMargins()->setFooter($marginFooter);
- }
- }
-
-
- /**
- * PROTECT - Sheet protection (BIFF2 through BIFF8)
- * if this record is omitted, then it also means no sheet protection
- */
- private function _readProtect()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- if ($this->_readDataOnly) {
- return;
- }
-
- // offset: 0; size: 2;
-
- // bit 0, mask 0x01; 1 = sheet is protected
- $bool = (0x01 & self::_GetInt2d($recordData, 0)) >> 0;
- $this->_phpSheet->getProtection()->setSheet((bool)$bool);
- }
-
-
- /**
- * SCENPROTECT
- */
- private function _readScenProtect()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- if ($this->_readDataOnly) {
- return;
- }
-
- // offset: 0; size: 2;
-
- // bit: 0, mask 0x01; 1 = scenarios are protected
- $bool = (0x01 & self::_GetInt2d($recordData, 0)) >> 0;
-
- $this->_phpSheet->getProtection()->setScenarios((bool)$bool);
- }
-
-
- /**
- * OBJECTPROTECT
- */
- private function _readObjectProtect()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- if ($this->_readDataOnly) {
- return;
- }
-
- // offset: 0; size: 2;
-
- // bit: 0, mask 0x01; 1 = objects are protected
- $bool = (0x01 & self::_GetInt2d($recordData, 0)) >> 0;
-
- $this->_phpSheet->getProtection()->setObjects((bool)$bool);
- }
-
-
- /**
- * PASSWORD - Sheet protection (hashed) password (BIFF2 through BIFF8)
- */
- private function _readPassword()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- if (!$this->_readDataOnly) {
- // offset: 0; size: 2; 16-bit hash value of password
- $password = strtoupper(dechex(self::_GetInt2d($recordData, 0))); // the hashed password
- $this->_phpSheet->getProtection()->setPassword($password, true);
- }
- }
-
-
- /**
- * Read DEFCOLWIDTH record
- */
- private function _readDefColWidth()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- // offset: 0; size: 2; default column width
- $width = self::_GetInt2d($recordData, 0);
- if ($width != 8) {
- $this->_phpSheet->getDefaultColumnDimension()->setWidth($width);
- }
- }
-
-
- /**
- * Read COLINFO record
- */
- private function _readColInfo()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- if (!$this->_readDataOnly) {
- // offset: 0; size: 2; index to first column in range
- $fc = self::_GetInt2d($recordData, 0); // first column index
-
- // offset: 2; size: 2; index to last column in range
- $lc = self::_GetInt2d($recordData, 2); // first column index
-
- // offset: 4; size: 2; width of the column in 1/256 of the width of the zero character
- $width = self::_GetInt2d($recordData, 4);
-
- // offset: 6; size: 2; index to XF record for default column formatting
- $xfIndex = self::_GetInt2d($recordData, 6);
-
- // offset: 8; size: 2; option flags
-
- // bit: 0; mask: 0x0001; 1= columns are hidden
- $isHidden = (0x0001 & self::_GetInt2d($recordData, 8)) >> 0;
-
- // bit: 10-8; mask: 0x0700; outline level of the columns (0 = no outline)
- $level = (0x0700 & self::_GetInt2d($recordData, 8)) >> 8;
-
- // bit: 12; mask: 0x1000; 1 = collapsed
- $isCollapsed = (0x1000 & self::_GetInt2d($recordData, 8)) >> 12;
-
- // offset: 10; size: 2; not used
-
- for ($i = $fc; $i <= $lc; ++$i) {
- if ($lc == 255 || $lc == 256) {
- $this->_phpSheet->getDefaultColumnDimension()->setWidth($width / 256);
- break;
- }
- $this->_phpSheet->getColumnDimensionByColumn($i)->setWidth($width / 256);
- $this->_phpSheet->getColumnDimensionByColumn($i)->setVisible(!$isHidden);
- $this->_phpSheet->getColumnDimensionByColumn($i)->setOutlineLevel($level);
- $this->_phpSheet->getColumnDimensionByColumn($i)->setCollapsed($isCollapsed);
- $this->_phpSheet->getColumnDimensionByColumn($i)->setXfIndex($this->_mapCellXfIndex[$xfIndex]);
- }
- }
- }
-
-
- /**
- * ROW
- *
- * This record contains the properties of a single row in a
- * sheet. Rows and cells in a sheet are divided into blocks
- * of 32 rows.
- *
- * -- "OpenOffice.org's Documentation of the Microsoft
- * Excel File Format"
- */
- private function _readRow()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- if (!$this->_readDataOnly) {
- // offset: 0; size: 2; index of this row
- $r = self::_GetInt2d($recordData, 0);
-
- // offset: 2; size: 2; index to column of the first cell which is described by a cell record
-
- // offset: 4; size: 2; index to column of the last cell which is described by a cell record, increased by 1
-
- // offset: 6; size: 2;
-
- // bit: 14-0; mask: 0x7FFF; height of the row, in twips = 1/20 of a point
- $height = (0x7FFF & self::_GetInt2d($recordData, 6)) >> 0;
-
- // bit: 15: mask: 0x8000; 0 = row has custom height; 1= row has default height
- $useDefaultHeight = (0x8000 & self::_GetInt2d($recordData, 6)) >> 15;
-
- if (!$useDefaultHeight) {
- $this->_phpSheet->getRowDimension($r + 1)->setRowHeight($height / 20);
- }
-
- // offset: 8; size: 2; not used
-
- // offset: 10; size: 2; not used in BIFF5-BIFF8
-
- // offset: 12; size: 4; option flags and default row formatting
-
- // bit: 2-0: mask: 0x00000007; outline level of the row
- $level = (0x00000007 & self::_GetInt4d($recordData, 12)) >> 0;
- $this->_phpSheet->getRowDimension($r + 1)->setOutlineLevel($level);
-
- // bit: 4; mask: 0x00000010; 1 = outline group start or ends here... and is collapsed
- $isCollapsed = (0x00000010 & self::_GetInt4d($recordData, 12)) >> 4;
- $this->_phpSheet->getRowDimension($r + 1)->setCollapsed($isCollapsed);
-
- // bit: 5; mask: 0x00000020; 1 = row is hidden
- $isHidden = (0x00000020 & self::_GetInt4d($recordData, 12)) >> 5;
- $this->_phpSheet->getRowDimension($r + 1)->setVisible(!$isHidden);
-
- // bit: 7; mask: 0x00000080; 1 = row has explicit format
- $hasExplicitFormat = (0x00000080 & self::_GetInt4d($recordData, 12)) >> 7;
-
- // bit: 27-16; mask: 0x0FFF0000; only applies when hasExplicitFormat = 1; index to XF record
- $xfIndex = (0x0FFF0000 & self::_GetInt4d($recordData, 12)) >> 16;
-
- if ($hasExplicitFormat) {
- $this->_phpSheet->getRowDimension($r + 1)->setXfIndex($this->_mapCellXfIndex[$xfIndex]);
- }
- }
- }
-
-
- /**
- * Read RK record
- * This record represents a cell that contains an RK value
- * (encoded integer or floating-point value). If a
- * floating-point value cannot be encoded to an RK value,
- * a NUMBER record will be written. This record replaces the
- * record INTEGER written in BIFF2.
- *
- * -- "OpenOffice.org's Documentation of the Microsoft
- * Excel File Format"
- */
- private function _readRk()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- // offset: 0; size: 2; index to row
- $row = self::_GetInt2d($recordData, 0);
-
- // offset: 2; size: 2; index to column
- $column = self::_GetInt2d($recordData, 2);
- $columnString = PHPExcel_Cell::stringFromColumnIndex($column);
-
- // Read cell?
- if (($this->getReadFilter() !== NULL) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->_phpSheet->getTitle()) ) {
- // offset: 4; size: 2; index to XF record
- $xfIndex = self::_GetInt2d($recordData, 4);
-
- // offset: 6; size: 4; RK value
- $rknum = self::_GetInt4d($recordData, 6);
- $numValue = self::_GetIEEE754($rknum);
-
- $cell = $this->_phpSheet->getCell($columnString . ($row + 1));
- if (!$this->_readDataOnly) {
- // add style information
- $cell->setXfIndex($this->_mapCellXfIndex[$xfIndex]);
- }
-
- // add cell
- $cell->setValueExplicit($numValue, PHPExcel_Cell_DataType::TYPE_NUMERIC);
- }
- }
-
-
- /**
- * Read LABELSST record
- * This record represents a cell that contains a string. It
- * replaces the LABEL record and RSTRING record used in
- * BIFF2-BIFF5.
- *
- * -- "OpenOffice.org's Documentation of the Microsoft
- * Excel File Format"
- */
- private function _readLabelSst()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- // offset: 0; size: 2; index to row
- $row = self::_GetInt2d($recordData, 0);
-
- // offset: 2; size: 2; index to column
- $column = self::_GetInt2d($recordData, 2);
- $columnString = PHPExcel_Cell::stringFromColumnIndex($column);
-
- // Read cell?
- if (($this->getReadFilter() !== NULL) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->_phpSheet->getTitle()) ) {
- // offset: 4; size: 2; index to XF record
- $xfIndex = self::_GetInt2d($recordData, 4);
-
- // offset: 6; size: 4; index to SST record
- $index = self::_GetInt4d($recordData, 6);
-
- // add cell
- if (($fmtRuns = $this->_sst[$index]['fmtRuns']) && !$this->_readDataOnly) {
- // then we should treat as rich text
- $richText = new PHPExcel_RichText();
- $charPos = 0;
- $sstCount = count($this->_sst[$index]['fmtRuns']);
- for ($i = 0; $i <= $sstCount; ++$i) {
- if (isset($fmtRuns[$i])) {
- $text = PHPExcel_Shared_String::Substring($this->_sst[$index]['value'], $charPos, $fmtRuns[$i]['charPos'] - $charPos);
- $charPos = $fmtRuns[$i]['charPos'];
- } else {
- $text = PHPExcel_Shared_String::Substring($this->_sst[$index]['value'], $charPos, PHPExcel_Shared_String::CountCharacters($this->_sst[$index]['value']));
- }
-
- if (PHPExcel_Shared_String::CountCharacters($text) > 0) {
- if ($i == 0) { // first text run, no style
- $richText->createText($text);
- } else {
- $textRun = $richText->createTextRun($text);
- if (isset($fmtRuns[$i - 1])) {
- if ($fmtRuns[$i - 1]['fontIndex'] < 4) {
- $fontIndex = $fmtRuns[$i - 1]['fontIndex'];
- } else {
- // this has to do with that index 4 is omitted in all BIFF versions for some strange reason
- // check the OpenOffice documentation of the FONT record
- $fontIndex = $fmtRuns[$i - 1]['fontIndex'] - 1;
- }
- $textRun->setFont(clone $this->_objFonts[$fontIndex]);
- }
- }
- }
- }
- $cell = $this->_phpSheet->getCell($columnString . ($row + 1));
- $cell->setValueExplicit($richText, PHPExcel_Cell_DataType::TYPE_STRING);
- } else {
- $cell = $this->_phpSheet->getCell($columnString . ($row + 1));
- $cell->setValueExplicit($this->_sst[$index]['value'], PHPExcel_Cell_DataType::TYPE_STRING);
- }
-
- if (!$this->_readDataOnly) {
- // add style information
- $cell->setXfIndex($this->_mapCellXfIndex[$xfIndex]);
- }
- }
- }
-
-
- /**
- * Read MULRK record
- * This record represents a cell range containing RK value
- * cells. All cells are located in the same row.
- *
- * -- "OpenOffice.org's Documentation of the Microsoft
- * Excel File Format"
- */
- private function _readMulRk()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- // offset: 0; size: 2; index to row
- $row = self::_GetInt2d($recordData, 0);
-
- // offset: 2; size: 2; index to first column
- $colFirst = self::_GetInt2d($recordData, 2);
-
- // offset: var; size: 2; index to last column
- $colLast = self::_GetInt2d($recordData, $length - 2);
- $columns = $colLast - $colFirst + 1;
-
- // offset within record data
- $offset = 4;
-
- for ($i = 0; $i < $columns; ++$i) {
- $columnString = PHPExcel_Cell::stringFromColumnIndex($colFirst + $i);
-
- // Read cell?
- if (($this->getReadFilter() !== NULL) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->_phpSheet->getTitle()) ) {
-
- // offset: var; size: 2; index to XF record
- $xfIndex = self::_GetInt2d($recordData, $offset);
-
- // offset: var; size: 4; RK value
- $numValue = self::_GetIEEE754(self::_GetInt4d($recordData, $offset + 2));
- $cell = $this->_phpSheet->getCell($columnString . ($row + 1));
- if (!$this->_readDataOnly) {
- // add style
- $cell->setXfIndex($this->_mapCellXfIndex[$xfIndex]);
- }
-
- // add cell value
- $cell->setValueExplicit($numValue, PHPExcel_Cell_DataType::TYPE_NUMERIC);
- }
-
- $offset += 6;
- }
- }
-
-
- /**
- * Read NUMBER record
- * This record represents a cell that contains a
- * floating-point value.
- *
- * -- "OpenOffice.org's Documentation of the Microsoft
- * Excel File Format"
- */
- private function _readNumber()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- // offset: 0; size: 2; index to row
- $row = self::_GetInt2d($recordData, 0);
-
- // offset: 2; size 2; index to column
- $column = self::_GetInt2d($recordData, 2);
- $columnString = PHPExcel_Cell::stringFromColumnIndex($column);
-
- // Read cell?
- if (($this->getReadFilter() !== NULL) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->_phpSheet->getTitle()) ) {
- // offset 4; size: 2; index to XF record
- $xfIndex = self::_GetInt2d($recordData, 4);
-
- $numValue = self::_extractNumber(substr($recordData, 6, 8));
-
- $cell = $this->_phpSheet->getCell($columnString . ($row + 1));
- if (!$this->_readDataOnly) {
- // add cell style
- $cell->setXfIndex($this->_mapCellXfIndex[$xfIndex]);
- }
-
- // add cell value
- $cell->setValueExplicit($numValue, PHPExcel_Cell_DataType::TYPE_NUMERIC);
- }
- }
-
-
- /**
- * Read FORMULA record + perhaps a following STRING record if formula result is a string
- * This record contains the token array and the result of a
- * formula cell.
- *
- * -- "OpenOffice.org's Documentation of the Microsoft
- * Excel File Format"
- */
- private function _readFormula()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- // offset: 0; size: 2; row index
- $row = self::_GetInt2d($recordData, 0);
-
- // offset: 2; size: 2; col index
- $column = self::_GetInt2d($recordData, 2);
- $columnString = PHPExcel_Cell::stringFromColumnIndex($column);
-
- // offset: 20: size: variable; formula structure
- $formulaStructure = substr($recordData, 20);
-
- // offset: 14: size: 2; option flags, recalculate always, recalculate on open etc.
- $options = self::_GetInt2d($recordData, 14);
-
- // bit: 0; mask: 0x0001; 1 = recalculate always
- // bit: 1; mask: 0x0002; 1 = calculate on open
- // bit: 2; mask: 0x0008; 1 = part of a shared formula
- $isPartOfSharedFormula = (bool) (0x0008 & $options);
-
- // WARNING:
- // We can apparently not rely on $isPartOfSharedFormula. Even when $isPartOfSharedFormula = true
- // the formula data may be ordinary formula data, therefore we need to check
- // explicitly for the tExp token (0x01)
- $isPartOfSharedFormula = $isPartOfSharedFormula && ord($formulaStructure{2}) == 0x01;
-
- if ($isPartOfSharedFormula) {
- // part of shared formula which means there will be a formula with a tExp token and nothing else
- // get the base cell, grab tExp token
- $baseRow = self::_GetInt2d($formulaStructure, 3);
- $baseCol = self::_GetInt2d($formulaStructure, 5);
- $this->_baseCell = PHPExcel_Cell::stringFromColumnIndex($baseCol). ($baseRow + 1);
- }
-
- // Read cell?
- if (($this->getReadFilter() !== NULL) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->_phpSheet->getTitle()) ) {
-
- if ($isPartOfSharedFormula) {
- // formula is added to this cell after the sheet has been read
- $this->_sharedFormulaParts[$columnString . ($row + 1)] = $this->_baseCell;
- }
-
- // offset: 16: size: 4; not used
-
- // offset: 4; size: 2; XF index
- $xfIndex = self::_GetInt2d($recordData, 4);
-
- // offset: 6; size: 8; result of the formula
- if ( (ord($recordData{6}) == 0)
- && (ord($recordData{12}) == 255)
- && (ord($recordData{13}) == 255) ) {
-
- // String formula. Result follows in appended STRING record
- $dataType = PHPExcel_Cell_DataType::TYPE_STRING;
-
- // read possible SHAREDFMLA record
- $code = self::_GetInt2d($this->_data, $this->_pos);
- if ($code == self::XLS_Type_SHAREDFMLA) {
- $this->_readSharedFmla();
- }
-
- // read STRING record
- $value = $this->_readString();
-
- } elseif ((ord($recordData{6}) == 1)
- && (ord($recordData{12}) == 255)
- && (ord($recordData{13}) == 255)) {
-
- // Boolean formula. Result is in +2; 0=false, 1=true
- $dataType = PHPExcel_Cell_DataType::TYPE_BOOL;
- $value = (bool) ord($recordData{8});
-
- } elseif ((ord($recordData{6}) == 2)
- && (ord($recordData{12}) == 255)
- && (ord($recordData{13}) == 255)) {
-
- // Error formula. Error code is in +2
- $dataType = PHPExcel_Cell_DataType::TYPE_ERROR;
- $value = self::_mapErrorCode(ord($recordData{8}));
-
- } elseif ((ord($recordData{6}) == 3)
- && (ord($recordData{12}) == 255)
- && (ord($recordData{13}) == 255)) {
-
- // Formula result is a null string
- $dataType = PHPExcel_Cell_DataType::TYPE_NULL;
- $value = '';
-
- } else {
-
- // forumla result is a number, first 14 bytes like _NUMBER record
- $dataType = PHPExcel_Cell_DataType::TYPE_NUMERIC;
- $value = self::_extractNumber(substr($recordData, 6, 8));
-
- }
-
- $cell = $this->_phpSheet->getCell($columnString . ($row + 1));
- if (!$this->_readDataOnly) {
- // add cell style
- $cell->setXfIndex($this->_mapCellXfIndex[$xfIndex]);
- }
-
- // store the formula
- if (!$isPartOfSharedFormula) {
- // not part of shared formula
- // add cell value. If we can read formula, populate with formula, otherwise just used cached value
- try {
- if ($this->_version != self::XLS_BIFF8) {
- throw new Exception('Not BIFF8. Can only read BIFF8 formulas');
- }
- $formula = $this->_getFormulaFromStructure($formulaStructure); // get formula in human language
- $cell->setValueExplicit('=' . $formula, PHPExcel_Cell_DataType::TYPE_FORMULA);
-
- } catch (Exception $e) {
- $cell->setValueExplicit($value, $dataType);
- }
- } else {
- if ($this->_version == self::XLS_BIFF8) {
- // do nothing at this point, formula id added later in the code
- } else {
- $cell->setValueExplicit($value, $dataType);
- }
- }
-
- // store the cached calculated value
- $cell->setCalculatedValue($value);
- }
- }
-
-
- /**
- * Read a SHAREDFMLA record. This function just stores the binary shared formula in the reader,
- * which usually contains relative references.
- * These will be used to construct the formula in each shared formula part after the sheet is read.
- */
- private function _readSharedFmla()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- // offset: 0, size: 6; cell range address of the area used by the shared formula, not used for anything
- $cellRange = substr($recordData, 0, 6);
- $cellRange = $this->_readBIFF5CellRangeAddressFixed($cellRange); // note: even BIFF8 uses BIFF5 syntax
-
- // offset: 6, size: 1; not used
-
- // offset: 7, size: 1; number of existing FORMULA records for this shared formula
- $no = ord($recordData{7});
-
- // offset: 8, size: var; Binary token array of the shared formula
- $formula = substr($recordData, 8);
-
- // at this point we only store the shared formula for later use
- $this->_sharedFormulas[$this->_baseCell] = $formula;
-
- }
-
-
- /**
- * Read a STRING record from current stream position and advance the stream pointer to next record
- * This record is used for storing result from FORMULA record when it is a string, and
- * it occurs directly after the FORMULA record
- *
- * @return string The string contents as UTF-8
- */
- private function _readString()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- if ($this->_version == self::XLS_BIFF8) {
- $string = self::_readUnicodeStringLong($recordData);
- $value = $string['value'];
- } else {
- $string = $this->_readByteStringLong($recordData);
- $value = $string['value'];
- }
-
- return $value;
- }
-
-
- /**
- * Read BOOLERR record
- * This record represents a Boolean value or error value
- * cell.
- *
- * -- "OpenOffice.org's Documentation of the Microsoft
- * Excel File Format"
- */
- private function _readBoolErr()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- // offset: 0; size: 2; row index
- $row = self::_GetInt2d($recordData, 0);
-
- // offset: 2; size: 2; column index
- $column = self::_GetInt2d($recordData, 2);
- $columnString = PHPExcel_Cell::stringFromColumnIndex($column);
-
- // Read cell?
- if (($this->getReadFilter() !== NULL) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->_phpSheet->getTitle()) ) {
- // offset: 4; size: 2; index to XF record
- $xfIndex = self::_GetInt2d($recordData, 4);
-
- // offset: 6; size: 1; the boolean value or error value
- $boolErr = ord($recordData{6});
-
- // offset: 7; size: 1; 0=boolean; 1=error
- $isError = ord($recordData{7});
-
- $cell = $this->_phpSheet->getCell($columnString . ($row + 1));
- switch ($isError) {
- case 0: // boolean
- $value = (bool) $boolErr;
-
- // add cell value
- $cell->setValueExplicit($value, PHPExcel_Cell_DataType::TYPE_BOOL);
- break;
-
- case 1: // error type
- $value = self::_mapErrorCode($boolErr);
-
- // add cell value
- $cell->setValueExplicit($value, PHPExcel_Cell_DataType::TYPE_ERROR);
- break;
- }
-
- if (!$this->_readDataOnly) {
- // add cell style
- $cell->setXfIndex($this->_mapCellXfIndex[$xfIndex]);
- }
- }
- }
-
-
- /**
- * Read MULBLANK record
- * This record represents a cell range of empty cells. All
- * cells are located in the same row
- *
- * -- "OpenOffice.org's Documentation of the Microsoft
- * Excel File Format"
- */
- private function _readMulBlank()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- // offset: 0; size: 2; index to row
- $row = self::_GetInt2d($recordData, 0);
-
- // offset: 2; size: 2; index to first column
- $fc = self::_GetInt2d($recordData, 2);
-
- // offset: 4; size: 2 x nc; list of indexes to XF records
- // add style information
- if (!$this->_readDataOnly) {
- for ($i = 0; $i < $length / 2 - 3; ++$i) {
- $columnString = PHPExcel_Cell::stringFromColumnIndex($fc + $i);
-
- // Read cell?
- if (($this->getReadFilter() !== NULL) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->_phpSheet->getTitle()) ) {
- $xfIndex = self::_GetInt2d($recordData, 4 + 2 * $i);
- $this->_phpSheet->getCell($columnString . ($row + 1))->setXfIndex($this->_mapCellXfIndex[$xfIndex]);
- }
- }
- }
-
- // offset: 6; size 2; index to last column (not needed)
- }
-
-
- /**
- * Read LABEL record
- * This record represents a cell that contains a string. In
- * BIFF8 it is usually replaced by the LABELSST record.
- * Excel still uses this record, if it copies unformatted
- * text cells to the clipboard.
- *
- * -- "OpenOffice.org's Documentation of the Microsoft
- * Excel File Format"
- */
- private function _readLabel()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- // offset: 0; size: 2; index to row
- $row = self::_GetInt2d($recordData, 0);
-
- // offset: 2; size: 2; index to column
- $column = self::_GetInt2d($recordData, 2);
- $columnString = PHPExcel_Cell::stringFromColumnIndex($column);
-
- // Read cell?
- if (($this->getReadFilter() !== NULL) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->_phpSheet->getTitle()) ) {
- // offset: 4; size: 2; XF index
- $xfIndex = self::_GetInt2d($recordData, 4);
-
- // add cell value
- // todo: what if string is very long? continue record
- if ($this->_version == self::XLS_BIFF8) {
- $string = self::_readUnicodeStringLong(substr($recordData, 6));
- $value = $string['value'];
- } else {
- $string = $this->_readByteStringLong(substr($recordData, 6));
- $value = $string['value'];
- }
- $cell = $this->_phpSheet->getCell($columnString . ($row + 1));
- $cell->setValueExplicit($value, PHPExcel_Cell_DataType::TYPE_STRING);
-
- if (!$this->_readDataOnly) {
- // add cell style
- $cell->setXfIndex($this->_mapCellXfIndex[$xfIndex]);
- }
- }
- }
-
-
- /**
- * Read BLANK record
- */
- private function _readBlank()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- // offset: 0; size: 2; row index
- $row = self::_GetInt2d($recordData, 0);
-
- // offset: 2; size: 2; col index
- $col = self::_GetInt2d($recordData, 2);
- $columnString = PHPExcel_Cell::stringFromColumnIndex($col);
-
- // Read cell?
- if (($this->getReadFilter() !== NULL) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->_phpSheet->getTitle()) ) {
- // offset: 4; size: 2; XF index
- $xfIndex = self::_GetInt2d($recordData, 4);
-
- // add style information
- if (!$this->_readDataOnly) {
- $this->_phpSheet->getCell($columnString . ($row + 1))->setXfIndex($this->_mapCellXfIndex[$xfIndex]);
- }
- }
-
- }
-
-
- /**
- * Read MSODRAWING record
- */
- private function _readMsoDrawing()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
-
- // get spliced record data
- $splicedRecordData = $this->_getSplicedRecordData();
- $recordData = $splicedRecordData['recordData'];
-
- $this->_drawingData .= $recordData;
- }
-
-
- /**
- * Read OBJ record
- */
- private function _readObj()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- if ($this->_readDataOnly || $this->_version != self::XLS_BIFF8) {
- return;
- }
-
- // recordData consists of an array of subrecords looking like this:
- // ft: 2 bytes; ftCmo type (0x15)
- // cb: 2 bytes; size in bytes of ftCmo data
- // ot: 2 bytes; Object Type
- // id: 2 bytes; Object id number
- // grbit: 2 bytes; Option Flags
- // data: var; subrecord data
-
- // for now, we are just interested in the second subrecord containing the object type
- $ftCmoType = self::_GetInt2d($recordData, 0);
- $cbCmoSize = self::_GetInt2d($recordData, 2);
- $otObjType = self::_GetInt2d($recordData, 4);
- $idObjID = self::_GetInt2d($recordData, 6);
- $grbitOpts = self::_GetInt2d($recordData, 6);
-
- $this->_objs[] = array(
- 'ftCmoType' => $ftCmoType,
- 'cbCmoSize' => $cbCmoSize,
- 'otObjType' => $otObjType,
- 'idObjID' => $idObjID,
- 'grbitOpts' => $grbitOpts
- );
- $this->textObjRef = $idObjID;
-
-// echo '_readObj()
';
-// var_dump(end($this->_objs));
-// echo '
';
- }
-
-
- /**
- * Read WINDOW2 record
- */
- private function _readWindow2()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- // offset: 0; size: 2; option flags
- $options = self::_GetInt2d($recordData, 0);
-
- // bit: 1; mask: 0x0002; 0 = do not show gridlines, 1 = show gridlines
- $showGridlines = (bool) ((0x0002 & $options) >> 1);
- $this->_phpSheet->setShowGridlines($showGridlines);
-
- // bit: 2; mask: 0x0004; 0 = do not show headers, 1 = show headers
- $showRowColHeaders = (bool) ((0x0004 & $options) >> 2);
- $this->_phpSheet->setShowRowColHeaders($showRowColHeaders);
-
- // bit: 3; mask: 0x0008; 0 = panes are not frozen, 1 = panes are frozen
- $this->_frozen = (bool) ((0x0008 & $options) >> 3);
-
- // bit: 6; mask: 0x0040; 0 = columns from left to right, 1 = columns from right to left
- $this->_phpSheet->setRightToLeft((bool)((0x0040 & $options) >> 6));
-
- // bit: 10; mask: 0x0400; 0 = sheet not active, 1 = sheet active
- $isActive = (bool) ((0x0400 & $options) >> 10);
- if ($isActive) {
- $this->_phpExcel->setActiveSheetIndex($this->_phpExcel->getIndex($this->_phpSheet));
- }
- }
-
-
- /**
- * Read SCL record
- */
- private function _readScl()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- // offset: 0; size: 2; numerator of the view magnification
- $numerator = self::_GetInt2d($recordData, 0);
-
- // offset: 2; size: 2; numerator of the view magnification
- $denumerator = self::_GetInt2d($recordData, 2);
-
- // set the zoom scale (in percent)
- $this->_phpSheet->getSheetView()->setZoomScale($numerator * 100 / $denumerator);
- }
-
-
- /**
- * Read PANE record
- */
- private function _readPane()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- if (!$this->_readDataOnly) {
- // offset: 0; size: 2; position of vertical split
- $px = self::_GetInt2d($recordData, 0);
-
- // offset: 2; size: 2; position of horizontal split
- $py = self::_GetInt2d($recordData, 2);
-
- if ($this->_frozen) {
- // frozen panes
- $this->_phpSheet->freezePane(PHPExcel_Cell::stringFromColumnIndex($px) . ($py + 1));
- } else {
- // unfrozen panes; split windows; not supported by PHPExcel core
- }
- }
- }
-
-
- /**
- * Read SELECTION record. There is one such record for each pane in the sheet.
- */
- private function _readSelection()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- if (!$this->_readDataOnly) {
- // offset: 0; size: 1; pane identifier
- $paneId = ord($recordData{0});
-
- // offset: 1; size: 2; index to row of the active cell
- $r = self::_GetInt2d($recordData, 1);
-
- // offset: 3; size: 2; index to column of the active cell
- $c = self::_GetInt2d($recordData, 3);
-
- // offset: 5; size: 2; index into the following cell range list to the
- // entry that contains the active cell
- $index = self::_GetInt2d($recordData, 5);
-
- // offset: 7; size: var; cell range address list containing all selected cell ranges
- $data = substr($recordData, 7);
- $cellRangeAddressList = $this->_readBIFF5CellRangeAddressList($data); // note: also BIFF8 uses BIFF5 syntax
-
- $selectedCells = $cellRangeAddressList['cellRangeAddresses'][0];
-
- // first row '1' + last row '16384' indicates that full column is selected (apparently also in BIFF8!)
- if (preg_match('/^([A-Z]+1\:[A-Z]+)16384$/', $selectedCells)) {
- $selectedCells = preg_replace('/^([A-Z]+1\:[A-Z]+)16384$/', '${1}1048576', $selectedCells);
- }
-
- // first row '1' + last row '65536' indicates that full column is selected
- if (preg_match('/^([A-Z]+1\:[A-Z]+)65536$/', $selectedCells)) {
- $selectedCells = preg_replace('/^([A-Z]+1\:[A-Z]+)65536$/', '${1}1048576', $selectedCells);
- }
-
- // first column 'A' + last column 'IV' indicates that full row is selected
- if (preg_match('/^(A[0-9]+\:)IV([0-9]+)$/', $selectedCells)) {
- $selectedCells = preg_replace('/^(A[0-9]+\:)IV([0-9]+)$/', '${1}XFD${2}', $selectedCells);
- }
-
- $this->_phpSheet->setSelectedCells($selectedCells);
- }
- }
-
-
- private function _includeCellRangeFiltered($cellRangeAddress)
- {
- $includeCellRange = true;
- if ($this->getReadFilter() !== NULL) {
- $includeCellRange = false;
- $rangeBoundaries = PHPExcel_Cell::getRangeBoundaries($cellRangeAddress);
- $rangeBoundaries[1][0]++;
- for ($row = $rangeBoundaries[0][1]; $row <= $rangeBoundaries[1][1]; $row++) {
- for ($column = $rangeBoundaries[0][0]; $column != $rangeBoundaries[1][0]; $column++) {
- if ($this->getReadFilter()->readCell($column, $row, $this->_phpSheet->getTitle())) {
- $includeCellRange = true;
- break 2;
- }
- }
- }
- }
- return $includeCellRange;
- }
-
-
- /**
- * MERGEDCELLS
- *
- * This record contains the addresses of merged cell ranges
- * in the current sheet.
- *
- * -- "OpenOffice.org's Documentation of the Microsoft
- * Excel File Format"
- */
- private function _readMergedCells()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- if ($this->_version == self::XLS_BIFF8 && !$this->_readDataOnly) {
- $cellRangeAddressList = $this->_readBIFF8CellRangeAddressList($recordData);
- foreach ($cellRangeAddressList['cellRangeAddresses'] as $cellRangeAddress) {
- if ((strpos($cellRangeAddress,':') !== FALSE) &&
- ($this->_includeCellRangeFiltered($cellRangeAddress))) {
- $this->_phpSheet->mergeCells($cellRangeAddress);
- }
- }
- }
- }
-
-
- /**
- * Read HYPERLINK record
- */
- private function _readHyperLink()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer forward to next record
- $this->_pos += 4 + $length;
-
- if (!$this->_readDataOnly) {
- // offset: 0; size: 8; cell range address of all cells containing this hyperlink
- try {
- $cellRange = $this->_readBIFF8CellRangeAddressFixed($recordData, 0, 8);
- } catch (Exception $e) {
- return;
- }
-
- // offset: 8, size: 16; GUID of StdLink
-
- // offset: 24, size: 4; unknown value
-
- // offset: 28, size: 4; option flags
-
- // bit: 0; mask: 0x00000001; 0 = no link or extant, 1 = file link or URL
- $isFileLinkOrUrl = (0x00000001 & self::_GetInt2d($recordData, 28)) >> 0;
-
- // bit: 1; mask: 0x00000002; 0 = relative path, 1 = absolute path or URL
- $isAbsPathOrUrl = (0x00000001 & self::_GetInt2d($recordData, 28)) >> 1;
-
- // bit: 2 (and 4); mask: 0x00000014; 0 = no description
- $hasDesc = (0x00000014 & self::_GetInt2d($recordData, 28)) >> 2;
-
- // bit: 3; mask: 0x00000008; 0 = no text, 1 = has text
- $hasText = (0x00000008 & self::_GetInt2d($recordData, 28)) >> 3;
-
- // bit: 7; mask: 0x00000080; 0 = no target frame, 1 = has target frame
- $hasFrame = (0x00000080 & self::_GetInt2d($recordData, 28)) >> 7;
-
- // bit: 8; mask: 0x00000100; 0 = file link or URL, 1 = UNC path (inc. server name)
- $isUNC = (0x00000100 & self::_GetInt2d($recordData, 28)) >> 8;
-
- // offset within record data
- $offset = 32;
-
- if ($hasDesc) {
- // offset: 32; size: var; character count of description text
- $dl = self::_GetInt4d($recordData, 32);
- // offset: 36; size: var; character array of description text, no Unicode string header, always 16-bit characters, zero terminated
- $desc = self::_encodeUTF16(substr($recordData, 36, 2 * ($dl - 1)), false);
- $offset += 4 + 2 * $dl;
- }
- if ($hasFrame) {
- $fl = self::_GetInt4d($recordData, $offset);
- $offset += 4 + 2 * $fl;
- }
-
- // detect type of hyperlink (there are 4 types)
- $hyperlinkType = null;
-
- if ($isUNC) {
- $hyperlinkType = 'UNC';
- } else if (!$isFileLinkOrUrl) {
- $hyperlinkType = 'workbook';
- } else if (ord($recordData{$offset}) == 0x03) {
- $hyperlinkType = 'local';
- } else if (ord($recordData{$offset}) == 0xE0) {
- $hyperlinkType = 'URL';
- }
-
- switch ($hyperlinkType) {
- case 'URL':
- // section 5.58.2: Hyperlink containing a URL
- // e.g. http://example.org/index.php
-
- // offset: var; size: 16; GUID of URL Moniker
- $offset += 16;
- // offset: var; size: 4; size (in bytes) of character array of the URL including trailing zero word
- $us = self::_GetInt4d($recordData, $offset);
- $offset += 4;
- // offset: var; size: $us; character array of the URL, no Unicode string header, always 16-bit characters, zero-terminated
- $url = self::_encodeUTF16(substr($recordData, $offset, $us - 2), false);
- $url .= $hasText ? '#' : '';
- $offset += $us;
- break;
-
- case 'local':
- // section 5.58.3: Hyperlink to local file
- // examples:
- // mydoc.txt
- // ../../somedoc.xls#Sheet!A1
-
- // offset: var; size: 16; GUI of File Moniker
- $offset += 16;
-
- // offset: var; size: 2; directory up-level count.
- $upLevelCount = self::_GetInt2d($recordData, $offset);
- $offset += 2;
-
- // offset: var; size: 4; character count of the shortened file path and name, including trailing zero word
- $sl = self::_GetInt4d($recordData, $offset);
- $offset += 4;
-
- // offset: var; size: sl; character array of the shortened file path and name in 8.3-DOS-format (compressed Unicode string)
- $shortenedFilePath = substr($recordData, $offset, $sl);
- $shortenedFilePath = self::_encodeUTF16($shortenedFilePath, true);
- $shortenedFilePath = substr($shortenedFilePath, 0, -1); // remove trailing zero
-
- $offset += $sl;
-
- // offset: var; size: 24; unknown sequence
- $offset += 24;
-
- // extended file path
- // offset: var; size: 4; size of the following file link field including string lenth mark
- $sz = self::_GetInt4d($recordData, $offset);
- $offset += 4;
-
- // only present if $sz > 0
- if ($sz > 0) {
- // offset: var; size: 4; size of the character array of the extended file path and name
- $xl = self::_GetInt4d($recordData, $offset);
- $offset += 4;
-
- // offset: var; size 2; unknown
- $offset += 2;
-
- // offset: var; size $xl; character array of the extended file path and name.
- $extendedFilePath = substr($recordData, $offset, $xl);
- $extendedFilePath = self::_encodeUTF16($extendedFilePath, false);
- $offset += $xl;
- }
-
- // construct the path
- $url = str_repeat('..\\', $upLevelCount);
- $url .= ($sz > 0) ?
- $extendedFilePath : $shortenedFilePath; // use extended path if available
- $url .= $hasText ? '#' : '';
-
- break;
-
-
- case 'UNC':
- // section 5.58.4: Hyperlink to a File with UNC (Universal Naming Convention) Path
- // todo: implement
- return;
-
- case 'workbook':
- // section 5.58.5: Hyperlink to the Current Workbook
- // e.g. Sheet2!B1:C2, stored in text mark field
- $url = 'sheet://';
- break;
-
- default:
- return;
-
- }
-
- if ($hasText) {
- // offset: var; size: 4; character count of text mark including trailing zero word
- $tl = self::_GetInt4d($recordData, $offset);
- $offset += 4;
- // offset: var; size: var; character array of the text mark without the # sign, no Unicode header, always 16-bit characters, zero-terminated
- $text = self::_encodeUTF16(substr($recordData, $offset, 2 * ($tl - 1)), false);
- $url .= $text;
- }
-
- // apply the hyperlink to all the relevant cells
- foreach (PHPExcel_Cell::extractAllCellReferencesInRange($cellRange) as $coordinate) {
- $this->_phpSheet->getCell($coordinate)->getHyperLink()->setUrl($url);
- }
- }
- }
-
-
- /**
- * Read DATAVALIDATIONS record
- */
- private function _readDataValidations()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer forward to next record
- $this->_pos += 4 + $length;
- }
-
-
- /**
- * Read DATAVALIDATION record
- */
- private function _readDataValidation()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer forward to next record
- $this->_pos += 4 + $length;
-
- if ($this->_readDataOnly) {
- return;
- }
-
- // offset: 0; size: 4; Options
- $options = self::_GetInt4d($recordData, 0);
-
- // bit: 0-3; mask: 0x0000000F; type
- $type = (0x0000000F & $options) >> 0;
- switch ($type) {
- case 0x00: $type = PHPExcel_Cell_DataValidation::TYPE_NONE; break;
- case 0x01: $type = PHPExcel_Cell_DataValidation::TYPE_WHOLE; break;
- case 0x02: $type = PHPExcel_Cell_DataValidation::TYPE_DECIMAL; break;
- case 0x03: $type = PHPExcel_Cell_DataValidation::TYPE_LIST; break;
- case 0x04: $type = PHPExcel_Cell_DataValidation::TYPE_DATE; break;
- case 0x05: $type = PHPExcel_Cell_DataValidation::TYPE_TIME; break;
- case 0x06: $type = PHPExcel_Cell_DataValidation::TYPE_TEXTLENGTH; break;
- case 0x07: $type = PHPExcel_Cell_DataValidation::TYPE_CUSTOM; break;
- }
-
- // bit: 4-6; mask: 0x00000070; error type
- $errorStyle = (0x00000070 & $options) >> 4;
- switch ($errorStyle) {
- case 0x00: $errorStyle = PHPExcel_Cell_DataValidation::STYLE_STOP; break;
- case 0x01: $errorStyle = PHPExcel_Cell_DataValidation::STYLE_WARNING; break;
- case 0x02: $errorStyle = PHPExcel_Cell_DataValidation::STYLE_INFORMATION; break;
- }
-
- // bit: 7; mask: 0x00000080; 1= formula is explicit (only applies to list)
- // I have only seen cases where this is 1
- $explicitFormula = (0x00000080 & $options) >> 7;
-
- // bit: 8; mask: 0x00000100; 1= empty cells allowed
- $allowBlank = (0x00000100 & $options) >> 8;
-
- // bit: 9; mask: 0x00000200; 1= suppress drop down arrow in list type validity
- $suppressDropDown = (0x00000200 & $options) >> 9;
-
- // bit: 18; mask: 0x00040000; 1= show prompt box if cell selected
- $showInputMessage = (0x00040000 & $options) >> 18;
-
- // bit: 19; mask: 0x00080000; 1= show error box if invalid values entered
- $showErrorMessage = (0x00080000 & $options) >> 19;
-
- // bit: 20-23; mask: 0x00F00000; condition operator
- $operator = (0x00F00000 & $options) >> 20;
- switch ($operator) {
- case 0x00: $operator = PHPExcel_Cell_DataValidation::OPERATOR_BETWEEN ; break;
- case 0x01: $operator = PHPExcel_Cell_DataValidation::OPERATOR_NOTBETWEEN ; break;
- case 0x02: $operator = PHPExcel_Cell_DataValidation::OPERATOR_EQUAL ; break;
- case 0x03: $operator = PHPExcel_Cell_DataValidation::OPERATOR_NOTEQUAL ; break;
- case 0x04: $operator = PHPExcel_Cell_DataValidation::OPERATOR_GREATERTHAN ; break;
- case 0x05: $operator = PHPExcel_Cell_DataValidation::OPERATOR_LESSTHAN ; break;
- case 0x06: $operator = PHPExcel_Cell_DataValidation::OPERATOR_GREATERTHANOREQUAL; break;
- case 0x07: $operator = PHPExcel_Cell_DataValidation::OPERATOR_LESSTHANOREQUAL ; break;
- }
-
- // offset: 4; size: var; title of the prompt box
- $offset = 4;
- $string = self::_readUnicodeStringLong(substr($recordData, $offset));
- $promptTitle = $string['value'] !== chr(0) ?
- $string['value'] : '';
- $offset += $string['size'];
-
- // offset: var; size: var; title of the error box
- $string = self::_readUnicodeStringLong(substr($recordData, $offset));
- $errorTitle = $string['value'] !== chr(0) ?
- $string['value'] : '';
- $offset += $string['size'];
-
- // offset: var; size: var; text of the prompt box
- $string = self::_readUnicodeStringLong(substr($recordData, $offset));
- $prompt = $string['value'] !== chr(0) ?
- $string['value'] : '';
- $offset += $string['size'];
-
- // offset: var; size: var; text of the error box
- $string = self::_readUnicodeStringLong(substr($recordData, $offset));
- $error = $string['value'] !== chr(0) ?
- $string['value'] : '';
- $offset += $string['size'];
-
- // offset: var; size: 2; size of the formula data for the first condition
- $sz1 = self::_GetInt2d($recordData, $offset);
- $offset += 2;
-
- // offset: var; size: 2; not used
- $offset += 2;
-
- // offset: var; size: $sz1; formula data for first condition (without size field)
- $formula1 = substr($recordData, $offset, $sz1);
- $formula1 = pack('v', $sz1) . $formula1; // prepend the length
- try {
- $formula1 = $this->_getFormulaFromStructure($formula1);
-
- // in list type validity, null characters are used as item separators
- if ($type == PHPExcel_Cell_DataValidation::TYPE_LIST) {
- $formula1 = str_replace(chr(0), ',', $formula1);
- }
- } catch (Exception $e) {
- return;
- }
- $offset += $sz1;
-
- // offset: var; size: 2; size of the formula data for the first condition
- $sz2 = self::_GetInt2d($recordData, $offset);
- $offset += 2;
-
- // offset: var; size: 2; not used
- $offset += 2;
-
- // offset: var; size: $sz2; formula data for second condition (without size field)
- $formula2 = substr($recordData, $offset, $sz2);
- $formula2 = pack('v', $sz2) . $formula2; // prepend the length
- try {
- $formula2 = $this->_getFormulaFromStructure($formula2);
- } catch (Exception $e) {
- return;
- }
- $offset += $sz2;
-
- // offset: var; size: var; cell range address list with
- $cellRangeAddressList = $this->_readBIFF8CellRangeAddressList(substr($recordData, $offset));
- $cellRangeAddresses = $cellRangeAddressList['cellRangeAddresses'];
-
- foreach ($cellRangeAddresses as $cellRange) {
- $stRange = $this->_phpSheet->shrinkRangeToFit($cellRange);
- $stRange = PHPExcel_Cell::extractAllCellReferencesInRange($stRange);
- foreach ($stRange as $coordinate) {
- $objValidation = $this->_phpSheet->getCell($coordinate)->getDataValidation();
- $objValidation->setType($type);
- $objValidation->setErrorStyle($errorStyle);
- $objValidation->setAllowBlank((bool)$allowBlank);
- $objValidation->setShowInputMessage((bool)$showInputMessage);
- $objValidation->setShowErrorMessage((bool)$showErrorMessage);
- $objValidation->setShowDropDown(!$suppressDropDown);
- $objValidation->setOperator($operator);
- $objValidation->setErrorTitle($errorTitle);
- $objValidation->setError($error);
- $objValidation->setPromptTitle($promptTitle);
- $objValidation->setPrompt($prompt);
- $objValidation->setFormula1($formula1);
- $objValidation->setFormula2($formula2);
- }
- }
-
- }
-
-
- /**
- * Read SHEETLAYOUT record. Stores sheet tab color information.
- */
- private function _readSheetLayout()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- // local pointer in record data
- $offset = 0;
-
- if (!$this->_readDataOnly) {
- // offset: 0; size: 2; repeated record identifier 0x0862
-
- // offset: 2; size: 10; not used
-
- // offset: 12; size: 4; size of record data
- // Excel 2003 uses size of 0x14 (documented), Excel 2007 uses size of 0x28 (not documented?)
- $sz = self::_GetInt4d($recordData, 12);
-
- switch ($sz) {
- case 0x14:
- // offset: 16; size: 2; color index for sheet tab
- $colorIndex = self::_GetInt2d($recordData, 16);
- $color = self::_readColor($colorIndex,$this->_palette,$this->_version);
- $this->_phpSheet->getTabColor()->setRGB($color['rgb']);
- break;
-
- case 0x28:
- // TODO: Investigate structure for .xls SHEETLAYOUT record as saved by MS Office Excel 2007
- return;
- break;
- }
- }
- }
-
-
- /**
- * Read SHEETPROTECTION record (FEATHEADR)
- */
- private function _readSheetProtection()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- if ($this->_readDataOnly) {
- return;
- }
-
- // offset: 0; size: 2; repeated record header
-
- // offset: 2; size: 2; FRT cell reference flag (=0 currently)
-
- // offset: 4; size: 8; Currently not used and set to 0
-
- // offset: 12; size: 2; Shared feature type index (2=Enhanced Protetion, 4=SmartTag)
- $isf = self::_GetInt2d($recordData, 12);
- if ($isf != 2) {
- return;
- }
-
- // offset: 14; size: 1; =1 since this is a feat header
-
- // offset: 15; size: 4; size of rgbHdrSData
-
- // rgbHdrSData, assume "Enhanced Protection"
- // offset: 19; size: 2; option flags
- $options = self::_GetInt2d($recordData, 19);
-
- // bit: 0; mask 0x0001; 1 = user may edit objects, 0 = users must not edit objects
- $bool = (0x0001 & $options) >> 0;
- $this->_phpSheet->getProtection()->setObjects(!$bool);
-
- // bit: 1; mask 0x0002; edit scenarios
- $bool = (0x0002 & $options) >> 1;
- $this->_phpSheet->getProtection()->setScenarios(!$bool);
-
- // bit: 2; mask 0x0004; format cells
- $bool = (0x0004 & $options) >> 2;
- $this->_phpSheet->getProtection()->setFormatCells(!$bool);
-
- // bit: 3; mask 0x0008; format columns
- $bool = (0x0008 & $options) >> 3;
- $this->_phpSheet->getProtection()->setFormatColumns(!$bool);
-
- // bit: 4; mask 0x0010; format rows
- $bool = (0x0010 & $options) >> 4;
- $this->_phpSheet->getProtection()->setFormatRows(!$bool);
-
- // bit: 5; mask 0x0020; insert columns
- $bool = (0x0020 & $options) >> 5;
- $this->_phpSheet->getProtection()->setInsertColumns(!$bool);
-
- // bit: 6; mask 0x0040; insert rows
- $bool = (0x0040 & $options) >> 6;
- $this->_phpSheet->getProtection()->setInsertRows(!$bool);
-
- // bit: 7; mask 0x0080; insert hyperlinks
- $bool = (0x0080 & $options) >> 7;
- $this->_phpSheet->getProtection()->setInsertHyperlinks(!$bool);
-
- // bit: 8; mask 0x0100; delete columns
- $bool = (0x0100 & $options) >> 8;
- $this->_phpSheet->getProtection()->setDeleteColumns(!$bool);
-
- // bit: 9; mask 0x0200; delete rows
- $bool = (0x0200 & $options) >> 9;
- $this->_phpSheet->getProtection()->setDeleteRows(!$bool);
-
- // bit: 10; mask 0x0400; select locked cells
- $bool = (0x0400 & $options) >> 10;
- $this->_phpSheet->getProtection()->setSelectLockedCells(!$bool);
-
- // bit: 11; mask 0x0800; sort cell range
- $bool = (0x0800 & $options) >> 11;
- $this->_phpSheet->getProtection()->setSort(!$bool);
-
- // bit: 12; mask 0x1000; auto filter
- $bool = (0x1000 & $options) >> 12;
- $this->_phpSheet->getProtection()->setAutoFilter(!$bool);
-
- // bit: 13; mask 0x2000; pivot tables
- $bool = (0x2000 & $options) >> 13;
- $this->_phpSheet->getProtection()->setPivotTables(!$bool);
-
- // bit: 14; mask 0x4000; select unlocked cells
- $bool = (0x4000 & $options) >> 14;
- $this->_phpSheet->getProtection()->setSelectUnlockedCells(!$bool);
-
- // offset: 21; size: 2; not used
- }
-
-
- /**
- * Read RANGEPROTECTION record
- * Reading of this record is based on Microsoft Office Excel 97-2000 Binary File Format Specification,
- * where it is referred to as FEAT record
- */
- private function _readRangeProtection()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- // local pointer in record data
- $offset = 0;
-
- if (!$this->_readDataOnly) {
- $offset += 12;
-
- // offset: 12; size: 2; shared feature type, 2 = enhanced protection, 4 = smart tag
- $isf = self::_GetInt2d($recordData, 12);
- if ($isf != 2) {
- // we only read FEAT records of type 2
- return;
- }
- $offset += 2;
-
- $offset += 5;
-
- // offset: 19; size: 2; count of ref ranges this feature is on
- $cref = self::_GetInt2d($recordData, 19);
- $offset += 2;
-
- $offset += 6;
-
- // offset: 27; size: 8 * $cref; list of cell ranges (like in hyperlink record)
- $cellRanges = array();
- for ($i = 0; $i < $cref; ++$i) {
- try {
- $cellRange = $this->_readBIFF8CellRangeAddressFixed(substr($recordData, 27 + 8 * $i, 8));
- } catch (Exception $e) {
- return;
- }
- $cellRanges[] = $cellRange;
- $offset += 8;
- }
-
- // offset: var; size: var; variable length of feature specific data
- $rgbFeat = substr($recordData, $offset);
- $offset += 4;
-
- // offset: var; size: 4; the encrypted password (only 16-bit although field is 32-bit)
- $wPassword = self::_GetInt4d($recordData, $offset);
- $offset += 4;
-
- // Apply range protection to sheet
- if ($cellRanges) {
- $this->_phpSheet->protectCells(implode(' ', $cellRanges), strtoupper(dechex($wPassword)), true);
- }
- }
- }
-
-
- /**
- * Read IMDATA record
- */
- private function _readImData()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
-
- // get spliced record data
- $splicedRecordData = $this->_getSplicedRecordData();
- $recordData = $splicedRecordData['recordData'];
-
- // UNDER CONSTRUCTION
-
- // offset: 0; size: 2; image format
- $cf = self::_GetInt2d($recordData, 0);
-
- // offset: 2; size: 2; environment from which the file was written
- $env = self::_GetInt2d($recordData, 2);
-
- // offset: 4; size: 4; length of the image data
- $lcb = self::_GetInt4d($recordData, 4);
-
- // offset: 8; size: var; image data
- $iData = substr($recordData, 8);
-
- switch ($cf) {
- case 0x09: // Windows bitmap format
- // BITMAPCOREINFO
- // 1. BITMAPCOREHEADER
- // offset: 0; size: 4; bcSize, Specifies the number of bytes required by the structure
- $bcSize = self::_GetInt4d($iData, 0);
-// var_dump($bcSize);
-
- // offset: 4; size: 2; bcWidth, specifies the width of the bitmap, in pixels
- $bcWidth = self::_GetInt2d($iData, 4);
-// var_dump($bcWidth);
-
- // offset: 6; size: 2; bcHeight, specifies the height of the bitmap, in pixels.
- $bcHeight = self::_GetInt2d($iData, 6);
-// var_dump($bcHeight);
- $ih = imagecreatetruecolor($bcWidth, $bcHeight);
-
- // offset: 8; size: 2; bcPlanes, specifies the number of planes for the target device. This value must be 1
-
- // offset: 10; size: 2; bcBitCount specifies the number of bits-per-pixel. This value must be 1, 4, 8, or 24
- $bcBitCount = self::_GetInt2d($iData, 10);
-// var_dump($bcBitCount);
-
- $rgbString = substr($iData, 12);
- $rgbTriples = array();
- while (strlen($rgbString) > 0) {
- $rgbTriples[] = unpack('Cb/Cg/Cr', $rgbString);
- $rgbString = substr($rgbString, 3);
- }
- $x = 0;
- $y = 0;
- foreach ($rgbTriples as $i => $rgbTriple) {
- $color = imagecolorallocate($ih, $rgbTriple['r'], $rgbTriple['g'], $rgbTriple['b']);
- imagesetpixel($ih, $x, $bcHeight - 1 - $y, $color);
- $x = ($x + 1) % $bcWidth;
- $y = $y + floor(($x + 1) / $bcWidth);
- }
- //imagepng($ih, 'image.png');
-
- $drawing = new PHPExcel_Worksheet_Drawing();
- $drawing->setPath($filename);
- $drawing->setWorksheet($this->_phpSheet);
-
- break;
-
- case 0x02: // Windows metafile or Macintosh PICT format
- case 0x0e: // native format
- default;
- break;
-
- }
-
- // _getSplicedRecordData() takes care of moving current position in data stream
- }
-
-
- /**
- * Read a free CONTINUE record. Free CONTINUE record may be a camouflaged MSODRAWING record
- * When MSODRAWING data on a sheet exceeds 8224 bytes, CONTINUE records are used instead. Undocumented.
- * In this case, we must treat the CONTINUE record as a MSODRAWING record
- */
- private function _readContinue()
- {
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // check if we are reading drawing data
- // this is in case a free CONTINUE record occurs in other circumstances we are unaware of
- if ($this->_drawingData == '') {
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- return;
- }
-
- // check if record data is at least 4 bytes long, otherwise there is no chance this is MSODRAWING data
- if ($length < 4) {
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- return;
- }
-
- // dirty check to see if CONTINUE record could be a camouflaged MSODRAWING record
- // look inside CONTINUE record to see if it looks like a part of an Escher stream
- // we know that Escher stream may be split at least at
- // 0xF003 MsofbtSpgrContainer
- // 0xF004 MsofbtSpContainer
- // 0xF00D MsofbtClientTextbox
- $validSplitPoints = array(0xF003, 0xF004, 0xF00D); // add identifiers if we find more
-
- $splitPoint = self::_GetInt2d($recordData, 2);
- if (in_array($splitPoint, $validSplitPoints)) {
- // get spliced record data (and move pointer to next record)
- $splicedRecordData = $this->_getSplicedRecordData();
- $this->_drawingData .= $splicedRecordData['recordData'];
-
- return;
- }
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- }
-
-
- /**
- * Reads a record from current position in data stream and continues reading data as long as CONTINUE
- * records are found. Splices the record data pieces and returns the combined string as if record data
- * is in one piece.
- * Moves to next current position in data stream to start of next record different from a CONtINUE record
- *
- * @return array
- */
- private function _getSplicedRecordData()
- {
- $data = '';
- $spliceOffsets = array();
-
- $i = 0;
- $spliceOffsets[0] = 0;
-
- do {
- ++$i;
-
- // offset: 0; size: 2; identifier
- $identifier = self::_GetInt2d($this->_data, $this->_pos);
- // offset: 2; size: 2; length
- $length = self::_GetInt2d($this->_data, $this->_pos + 2);
- $data .= substr($this->_data, $this->_pos + 4, $length);
-
- $spliceOffsets[$i] = $spliceOffsets[$i - 1] + $length;
-
- $this->_pos += 4 + $length;
- $nextIdentifier = self::_GetInt2d($this->_data, $this->_pos);
- }
- while ($nextIdentifier == self::XLS_Type_CONTINUE);
-
- $splicedData = array(
- 'recordData' => $data,
- 'spliceOffsets' => $spliceOffsets,
- );
-
- return $splicedData;
-
- }
-
-
- /**
- * Convert formula structure into human readable Excel formula like 'A3+A5*5'
- *
- * @param string $formulaStructure The complete binary data for the formula
- * @param string $baseCell Base cell, only needed when formula contains tRefN tokens, e.g. with shared formulas
- * @return string Human readable formula
- */
- private function _getFormulaFromStructure($formulaStructure, $baseCell = 'A1')
- {
- // offset: 0; size: 2; size of the following formula data
- $sz = self::_GetInt2d($formulaStructure, 0);
-
- // offset: 2; size: sz
- $formulaData = substr($formulaStructure, 2, $sz);
-
- // for debug: dump the formula data
- //echo '';
- //echo 'size: ' . $sz . "\n";
- //echo 'the entire formula data: ';
- //Debug::dump($formulaData);
- //echo "\n----\n";
-
- // offset: 2 + sz; size: variable (optional)
- if (strlen($formulaStructure) > 2 + $sz) {
- $additionalData = substr($formulaStructure, 2 + $sz);
-
- // for debug: dump the additional data
- //echo 'the entire additional data: ';
- //Debug::dump($additionalData);
- //echo "\n----\n";
-
- } else {
- $additionalData = '';
- }
-
- return $this->_getFormulaFromData($formulaData, $additionalData, $baseCell);
- }
-
-
- /**
- * Take formula data and additional data for formula and return human readable formula
- *
- * @param string $formulaData The binary data for the formula itself
- * @param string $additionalData Additional binary data going with the formula
- * @param string $baseCell Base cell, only needed when formula contains tRefN tokens, e.g. with shared formulas
- * @return string Human readable formula
- */
- private function _getFormulaFromData($formulaData, $additionalData = '', $baseCell = 'A1')
- {
- // start parsing the formula data
- $tokens = array();
-
- while (strlen($formulaData) > 0 and $token = $this->_getNextToken($formulaData, $baseCell)) {
- $tokens[] = $token;
- $formulaData = substr($formulaData, $token['size']);
-
- // for debug: dump the token
- //var_dump($token);
- }
-
- $formulaString = $this->_createFormulaFromTokens($tokens, $additionalData);
-
- return $formulaString;
- }
-
-
- /**
- * Take array of tokens together with additional data for formula and return human readable formula
- *
- * @param array $tokens
- * @param array $additionalData Additional binary data going with the formula
- * @param string $baseCell Base cell, only needed when formula contains tRefN tokens, e.g. with shared formulas
- * @return string Human readable formula
- */
- private function _createFormulaFromTokens($tokens, $additionalData)
- {
- // empty formula?
- if (empty($tokens)) {
- return '';
- }
-
- $formulaStrings = array();
- foreach ($tokens as $token) {
- // initialize spaces
- $space0 = isset($space0) ? $space0 : ''; // spaces before next token, not tParen
- $space1 = isset($space1) ? $space1 : ''; // carriage returns before next token, not tParen
- $space2 = isset($space2) ? $space2 : ''; // spaces before opening parenthesis
- $space3 = isset($space3) ? $space3 : ''; // carriage returns before opening parenthesis
- $space4 = isset($space4) ? $space4 : ''; // spaces before closing parenthesis
- $space5 = isset($space5) ? $space5 : ''; // carriage returns before closing parenthesis
-
- switch ($token['name']) {
- case 'tAdd': // addition
- case 'tConcat': // addition
- case 'tDiv': // division
- case 'tEQ': // equality
- case 'tGE': // greater than or equal
- case 'tGT': // greater than
- case 'tIsect': // intersection
- case 'tLE': // less than or equal
- case 'tList': // less than or equal
- case 'tLT': // less than
- case 'tMul': // multiplication
- case 'tNE': // multiplication
- case 'tPower': // power
- case 'tRange': // range
- case 'tSub': // subtraction
- $op2 = array_pop($formulaStrings);
- $op1 = array_pop($formulaStrings);
- $formulaStrings[] = "$op1$space1$space0{$token['data']}$op2";
- unset($space0, $space1);
- break;
- case 'tUplus': // unary plus
- case 'tUminus': // unary minus
- $op = array_pop($formulaStrings);
- $formulaStrings[] = "$space1$space0{$token['data']}$op";
- unset($space0, $space1);
- break;
- case 'tPercent': // percent sign
- $op = array_pop($formulaStrings);
- $formulaStrings[] = "$op$space1$space0{$token['data']}";
- unset($space0, $space1);
- break;
- case 'tAttrVolatile': // indicates volatile function
- case 'tAttrIf':
- case 'tAttrSkip':
- case 'tAttrChoose':
- // token is only important for Excel formula evaluator
- // do nothing
- break;
- case 'tAttrSpace': // space / carriage return
- // space will be used when next token arrives, do not alter formulaString stack
- switch ($token['data']['spacetype']) {
- case 'type0':
- $space0 = str_repeat(' ', $token['data']['spacecount']);
- break;
- case 'type1':
- $space1 = str_repeat("\n", $token['data']['spacecount']);
- break;
- case 'type2':
- $space2 = str_repeat(' ', $token['data']['spacecount']);
- break;
- case 'type3':
- $space3 = str_repeat("\n", $token['data']['spacecount']);
- break;
- case 'type4':
- $space4 = str_repeat(' ', $token['data']['spacecount']);
- break;
- case 'type5':
- $space5 = str_repeat("\n", $token['data']['spacecount']);
- break;
- }
- break;
- case 'tAttrSum': // SUM function with one parameter
- $op = array_pop($formulaStrings);
- $formulaStrings[] = "{$space1}{$space0}SUM($op)";
- unset($space0, $space1);
- break;
- case 'tFunc': // function with fixed number of arguments
- case 'tFuncV': // function with variable number of arguments
- if ($token['data']['function'] != '') {
- // normal function
- $ops = array(); // array of operators
- for ($i = 0; $i < $token['data']['args']; ++$i) {
- $ops[] = array_pop($formulaStrings);
- }
- $ops = array_reverse($ops);
- $formulaStrings[] = "$space1$space0{$token['data']['function']}(" . implode(',', $ops) . ")";
- unset($space0, $space1);
- } else {
- // add-in function
- $ops = array(); // array of operators
- for ($i = 0; $i < $token['data']['args'] - 1; ++$i) {
- $ops[] = array_pop($formulaStrings);
- }
- $ops = array_reverse($ops);
- $function = array_pop($formulaStrings);
- $formulaStrings[] = "$space1$space0$function(" . implode(',', $ops) . ")";
- unset($space0, $space1);
- }
- break;
- case 'tParen': // parenthesis
- $expression = array_pop($formulaStrings);
- $formulaStrings[] = "$space3$space2($expression$space5$space4)";
- unset($space2, $space3, $space4, $space5);
- break;
- case 'tArray': // array constant
- $constantArray = self::_readBIFF8ConstantArray($additionalData);
- $formulaStrings[] = $space1 . $space0 . $constantArray['value'];
- $additionalData = substr($additionalData, $constantArray['size']); // bite of chunk of additional data
- unset($space0, $space1);
- break;
- case 'tMemArea':
- // bite off chunk of additional data
- $cellRangeAddressList = $this->_readBIFF8CellRangeAddressList($additionalData);
- $additionalData = substr($additionalData, $cellRangeAddressList['size']);
- $formulaStrings[] = "$space1$space0{$token['data']}";
- unset($space0, $space1);
- break;
- case 'tArea': // cell range address
- case 'tBool': // boolean
- case 'tErr': // error code
- case 'tInt': // integer
- case 'tMemErr':
- case 'tMemFunc':
- case 'tMissArg':
- case 'tName':
- case 'tNameX':
- case 'tNum': // number
- case 'tRef': // single cell reference
- case 'tRef3d': // 3d cell reference
- case 'tArea3d': // 3d cell range reference
- case 'tRefN':
- case 'tAreaN':
- case 'tStr': // string
- $formulaStrings[] = "$space1$space0{$token['data']}";
- unset($space0, $space1);
- break;
- }
- }
- $formulaString = $formulaStrings[0];
-
- // for debug: dump the human readable formula
- //echo '----' . "\n";
- //echo 'Formula: ' . $formulaString;
-
- return $formulaString;
- }
-
-
- /**
- * Fetch next token from binary formula data
- *
- * @param string Formula data
- * @param string $baseCell Base cell, only needed when formula contains tRefN tokens, e.g. with shared formulas
- * @return array
- * @throws Exception
- */
- private function _getNextToken($formulaData, $baseCell = 'A1')
- {
- // offset: 0; size: 1; token id
- $id = ord($formulaData[0]); // token id
- $name = false; // initialize token name
-
- switch ($id) {
- case 0x03: $name = 'tAdd'; $size = 1; $data = '+'; break;
- case 0x04: $name = 'tSub'; $size = 1; $data = '-'; break;
- case 0x05: $name = 'tMul'; $size = 1; $data = '*'; break;
- case 0x06: $name = 'tDiv'; $size = 1; $data = '/'; break;
- case 0x07: $name = 'tPower'; $size = 1; $data = '^'; break;
- case 0x08: $name = 'tConcat'; $size = 1; $data = '&'; break;
- case 0x09: $name = 'tLT'; $size = 1; $data = '<'; break;
- case 0x0A: $name = 'tLE'; $size = 1; $data = '<='; break;
- case 0x0B: $name = 'tEQ'; $size = 1; $data = '='; break;
- case 0x0C: $name = 'tGE'; $size = 1; $data = '>='; break;
- case 0x0D: $name = 'tGT'; $size = 1; $data = '>'; break;
- case 0x0E: $name = 'tNE'; $size = 1; $data = '<>'; break;
- case 0x0F: $name = 'tIsect'; $size = 1; $data = ' '; break;
- case 0x10: $name = 'tList'; $size = 1; $data = ','; break;
- case 0x11: $name = 'tRange'; $size = 1; $data = ':'; break;
- case 0x12: $name = 'tUplus'; $size = 1; $data = '+'; break;
- case 0x13: $name = 'tUminus'; $size = 1; $data = '-'; break;
- case 0x14: $name = 'tPercent'; $size = 1; $data = '%'; break;
- case 0x15: // parenthesis
- $name = 'tParen';
- $size = 1;
- $data = null;
- break;
- case 0x16: // missing argument
- $name = 'tMissArg';
- $size = 1;
- $data = '';
- break;
- case 0x17: // string
- $name = 'tStr';
- // offset: 1; size: var; Unicode string, 8-bit string length
- $string = self::_readUnicodeStringShort(substr($formulaData, 1));
- $size = 1 + $string['size'];
- $data = self::_UTF8toExcelDoubleQuoted($string['value']);
- break;
- case 0x19: // Special attribute
- // offset: 1; size: 1; attribute type flags:
- switch (ord($formulaData[1])) {
- case 0x01:
- $name = 'tAttrVolatile';
- $size = 4;
- $data = null;
- break;
- case 0x02:
- $name = 'tAttrIf';
- $size = 4;
- $data = null;
- break;
- case 0x04:
- $name = 'tAttrChoose';
- // offset: 2; size: 2; number of choices in the CHOOSE function ($nc, number of parameters decreased by 1)
- $nc = self::_GetInt2d($formulaData, 2);
- // offset: 4; size: 2 * $nc
- // offset: 4 + 2 * $nc; size: 2
- $size = 2 * $nc + 6;
- $data = null;
- break;
- case 0x08:
- $name = 'tAttrSkip';
- $size = 4;
- $data = null;
- break;
- case 0x10:
- $name = 'tAttrSum';
- $size = 4;
- $data = null;
- break;
- case 0x40:
- case 0x41:
- $name = 'tAttrSpace';
- $size = 4;
- // offset: 2; size: 2; space type and position
- switch (ord($formulaData[2])) {
- case 0x00:
- $spacetype = 'type0';
- break;
- case 0x01:
- $spacetype = 'type1';
- break;
- case 0x02:
- $spacetype = 'type2';
- break;
- case 0x03:
- $spacetype = 'type3';
- break;
- case 0x04:
- $spacetype = 'type4';
- break;
- case 0x05:
- $spacetype = 'type5';
- break;
- default:
- throw new Exception('Unrecognized space type in tAttrSpace token');
- break;
- }
- // offset: 3; size: 1; number of inserted spaces/carriage returns
- $spacecount = ord($formulaData[3]);
-
- $data = array('spacetype' => $spacetype, 'spacecount' => $spacecount);
- break;
- default:
- throw new Exception('Unrecognized attribute flag in tAttr token');
- break;
- }
- break;
- case 0x1C: // error code
- // offset: 1; size: 1; error code
- $name = 'tErr';
- $size = 2;
- $data = self::_mapErrorCode(ord($formulaData[1]));
- break;
- case 0x1D: // boolean
- // offset: 1; size: 1; 0 = false, 1 = true;
- $name = 'tBool';
- $size = 2;
- $data = ord($formulaData[1]) ? 'TRUE' : 'FALSE';
- break;
- case 0x1E: // integer
- // offset: 1; size: 2; unsigned 16-bit integer
- $name = 'tInt';
- $size = 3;
- $data = self::_GetInt2d($formulaData, 1);
- break;
- case 0x1F: // number
- // offset: 1; size: 8;
- $name = 'tNum';
- $size = 9;
- $data = self::_extractNumber(substr($formulaData, 1));
- $data = str_replace(',', '.', (string)$data); // in case non-English locale
- break;
- case 0x20: // array constant
- case 0x40:
- case 0x60:
- // offset: 1; size: 7; not used
- $name = 'tArray';
- $size = 8;
- $data = null;
- break;
- case 0x21: // function with fixed number of arguments
- case 0x41:
- case 0x61:
- $name = 'tFunc';
- $size = 3;
- // offset: 1; size: 2; index to built-in sheet function
- switch (self::_GetInt2d($formulaData, 1)) {
- case 2: $function = 'ISNA'; $args = 1; break;
- case 3: $function = 'ISERROR'; $args = 1; break;
- case 10: $function = 'NA'; $args = 0; break;
- case 15: $function = 'SIN'; $args = 1; break;
- case 16: $function = 'COS'; $args = 1; break;
- case 17: $function = 'TAN'; $args = 1; break;
- case 18: $function = 'ATAN'; $args = 1; break;
- case 19: $function = 'PI'; $args = 0; break;
- case 20: $function = 'SQRT'; $args = 1; break;
- case 21: $function = 'EXP'; $args = 1; break;
- case 22: $function = 'LN'; $args = 1; break;
- case 23: $function = 'LOG10'; $args = 1; break;
- case 24: $function = 'ABS'; $args = 1; break;
- case 25: $function = 'INT'; $args = 1; break;
- case 26: $function = 'SIGN'; $args = 1; break;
- case 27: $function = 'ROUND'; $args = 2; break;
- case 30: $function = 'REPT'; $args = 2; break;
- case 31: $function = 'MID'; $args = 3; break;
- case 32: $function = 'LEN'; $args = 1; break;
- case 33: $function = 'VALUE'; $args = 1; break;
- case 34: $function = 'TRUE'; $args = 0; break;
- case 35: $function = 'FALSE'; $args = 0; break;
- case 38: $function = 'NOT'; $args = 1; break;
- case 39: $function = 'MOD'; $args = 2; break;
- case 40: $function = 'DCOUNT'; $args = 3; break;
- case 41: $function = 'DSUM'; $args = 3; break;
- case 42: $function = 'DAVERAGE'; $args = 3; break;
- case 43: $function = 'DMIN'; $args = 3; break;
- case 44: $function = 'DMAX'; $args = 3; break;
- case 45: $function = 'DSTDEV'; $args = 3; break;
- case 48: $function = 'TEXT'; $args = 2; break;
- case 61: $function = 'MIRR'; $args = 3; break;
- case 63: $function = 'RAND'; $args = 0; break;
- case 65: $function = 'DATE'; $args = 3; break;
- case 66: $function = 'TIME'; $args = 3; break;
- case 67: $function = 'DAY'; $args = 1; break;
- case 68: $function = 'MONTH'; $args = 1; break;
- case 69: $function = 'YEAR'; $args = 1; break;
- case 71: $function = 'HOUR'; $args = 1; break;
- case 72: $function = 'MINUTE'; $args = 1; break;
- case 73: $function = 'SECOND'; $args = 1; break;
- case 74: $function = 'NOW'; $args = 0; break;
- case 75: $function = 'AREAS'; $args = 1; break;
- case 76: $function = 'ROWS'; $args = 1; break;
- case 77: $function = 'COLUMNS'; $args = 1; break;
- case 83: $function = 'TRANSPOSE'; $args = 1; break;
- case 86: $function = 'TYPE'; $args = 1; break;
- case 97: $function = 'ATAN2'; $args = 2; break;
- case 98: $function = 'ASIN'; $args = 1; break;
- case 99: $function = 'ACOS'; $args = 1; break;
- case 105: $function = 'ISREF'; $args = 1; break;
- case 111: $function = 'CHAR'; $args = 1; break;
- case 112: $function = 'LOWER'; $args = 1; break;
- case 113: $function = 'UPPER'; $args = 1; break;
- case 114: $function = 'PROPER'; $args = 1; break;
- case 117: $function = 'EXACT'; $args = 2; break;
- case 118: $function = 'TRIM'; $args = 1; break;
- case 119: $function = 'REPLACE'; $args = 4; break;
- case 121: $function = 'CODE'; $args = 1; break;
- case 126: $function = 'ISERR'; $args = 1; break;
- case 127: $function = 'ISTEXT'; $args = 1; break;
- case 128: $function = 'ISNUMBER'; $args = 1; break;
- case 129: $function = 'ISBLANK'; $args = 1; break;
- case 130: $function = 'T'; $args = 1; break;
- case 131: $function = 'N'; $args = 1; break;
- case 140: $function = 'DATEVALUE'; $args = 1; break;
- case 141: $function = 'TIMEVALUE'; $args = 1; break;
- case 142: $function = 'SLN'; $args = 3; break;
- case 143: $function = 'SYD'; $args = 4; break;
- case 162: $function = 'CLEAN'; $args = 1; break;
- case 163: $function = 'MDETERM'; $args = 1; break;
- case 164: $function = 'MINVERSE'; $args = 1; break;
- case 165: $function = 'MMULT'; $args = 2; break;
- case 184: $function = 'FACT'; $args = 1; break;
- case 189: $function = 'DPRODUCT'; $args = 3; break;
- case 190: $function = 'ISNONTEXT'; $args = 1; break;
- case 195: $function = 'DSTDEVP'; $args = 3; break;
- case 196: $function = 'DVARP'; $args = 3; break;
- case 198: $function = 'ISLOGICAL'; $args = 1; break;
- case 199: $function = 'DCOUNTA'; $args = 3; break;
- case 207: $function = 'REPLACEB'; $args = 4; break;
- case 210: $function = 'MIDB'; $args = 3; break;
- case 211: $function = 'LENB'; $args = 1; break;
- case 212: $function = 'ROUNDUP'; $args = 2; break;
- case 213: $function = 'ROUNDDOWN'; $args = 2; break;
- case 214: $function = 'ASC'; $args = 1; break;
- case 215: $function = 'DBCS'; $args = 1; break;
- case 221: $function = 'TODAY'; $args = 0; break;
- case 229: $function = 'SINH'; $args = 1; break;
- case 230: $function = 'COSH'; $args = 1; break;
- case 231: $function = 'TANH'; $args = 1; break;
- case 232: $function = 'ASINH'; $args = 1; break;
- case 233: $function = 'ACOSH'; $args = 1; break;
- case 234: $function = 'ATANH'; $args = 1; break;
- case 235: $function = 'DGET'; $args = 3; break;
- case 244: $function = 'INFO'; $args = 1; break;
- case 252: $function = 'FREQUENCY'; $args = 2; break;
- case 261: $function = 'ERROR.TYPE'; $args = 1; break;
- case 271: $function = 'GAMMALN'; $args = 1; break;
- case 273: $function = 'BINOMDIST'; $args = 4; break;
- case 274: $function = 'CHIDIST'; $args = 2; break;
- case 275: $function = 'CHIINV'; $args = 2; break;
- case 276: $function = 'COMBIN'; $args = 2; break;
- case 277: $function = 'CONFIDENCE'; $args = 3; break;
- case 278: $function = 'CRITBINOM'; $args = 3; break;
- case 279: $function = 'EVEN'; $args = 1; break;
- case 280: $function = 'EXPONDIST'; $args = 3; break;
- case 281: $function = 'FDIST'; $args = 3; break;
- case 282: $function = 'FINV'; $args = 3; break;
- case 283: $function = 'FISHER'; $args = 1; break;
- case 284: $function = 'FISHERINV'; $args = 1; break;
- case 285: $function = 'FLOOR'; $args = 2; break;
- case 286: $function = 'GAMMADIST'; $args = 4; break;
- case 287: $function = 'GAMMAINV'; $args = 3; break;
- case 288: $function = 'CEILING'; $args = 2; break;
- case 289: $function = 'HYPGEOMDIST'; $args = 4; break;
- case 290: $function = 'LOGNORMDIST'; $args = 3; break;
- case 291: $function = 'LOGINV'; $args = 3; break;
- case 292: $function = 'NEGBINOMDIST'; $args = 3; break;
- case 293: $function = 'NORMDIST'; $args = 4; break;
- case 294: $function = 'NORMSDIST'; $args = 1; break;
- case 295: $function = 'NORMINV'; $args = 3; break;
- case 296: $function = 'NORMSINV'; $args = 1; break;
- case 297: $function = 'STANDARDIZE'; $args = 3; break;
- case 298: $function = 'ODD'; $args = 1; break;
- case 299: $function = 'PERMUT'; $args = 2; break;
- case 300: $function = 'POISSON'; $args = 3; break;
- case 301: $function = 'TDIST'; $args = 3; break;
- case 302: $function = 'WEIBULL'; $args = 4; break;
- case 303: $function = 'SUMXMY2'; $args = 2; break;
- case 304: $function = 'SUMX2MY2'; $args = 2; break;
- case 305: $function = 'SUMX2PY2'; $args = 2; break;
- case 306: $function = 'CHITEST'; $args = 2; break;
- case 307: $function = 'CORREL'; $args = 2; break;
- case 308: $function = 'COVAR'; $args = 2; break;
- case 309: $function = 'FORECAST'; $args = 3; break;
- case 310: $function = 'FTEST'; $args = 2; break;
- case 311: $function = 'INTERCEPT'; $args = 2; break;
- case 312: $function = 'PEARSON'; $args = 2; break;
- case 313: $function = 'RSQ'; $args = 2; break;
- case 314: $function = 'STEYX'; $args = 2; break;
- case 315: $function = 'SLOPE'; $args = 2; break;
- case 316: $function = 'TTEST'; $args = 4; break;
- case 325: $function = 'LARGE'; $args = 2; break;
- case 326: $function = 'SMALL'; $args = 2; break;
- case 327: $function = 'QUARTILE'; $args = 2; break;
- case 328: $function = 'PERCENTILE'; $args = 2; break;
- case 331: $function = 'TRIMMEAN'; $args = 2; break;
- case 332: $function = 'TINV'; $args = 2; break;
- case 337: $function = 'POWER'; $args = 2; break;
- case 342: $function = 'RADIANS'; $args = 1; break;
- case 343: $function = 'DEGREES'; $args = 1; break;
- case 346: $function = 'COUNTIF'; $args = 2; break;
- case 347: $function = 'COUNTBLANK'; $args = 1; break;
- case 350: $function = 'ISPMT'; $args = 4; break;
- case 351: $function = 'DATEDIF'; $args = 3; break;
- case 352: $function = 'DATESTRING'; $args = 1; break;
- case 353: $function = 'NUMBERSTRING'; $args = 2; break;
- case 360: $function = 'PHONETIC'; $args = 1; break;
- case 368: $function = 'BAHTTEXT'; $args = 1; break;
- default:
- throw new Exception('Unrecognized function in formula');
- break;
- }
- $data = array('function' => $function, 'args' => $args);
- break;
- case 0x22: // function with variable number of arguments
- case 0x42:
- case 0x62:
- $name = 'tFuncV';
- $size = 4;
- // offset: 1; size: 1; number of arguments
- $args = ord($formulaData[1]);
- // offset: 2: size: 2; index to built-in sheet function
- $index = self::_GetInt2d($formulaData, 2);
- switch ($index) {
- case 0: $function = 'COUNT'; break;
- case 1: $function = 'IF'; break;
- case 4: $function = 'SUM'; break;
- case 5: $function = 'AVERAGE'; break;
- case 6: $function = 'MIN'; break;
- case 7: $function = 'MAX'; break;
- case 8: $function = 'ROW'; break;
- case 9: $function = 'COLUMN'; break;
- case 11: $function = 'NPV'; break;
- case 12: $function = 'STDEV'; break;
- case 13: $function = 'DOLLAR'; break;
- case 14: $function = 'FIXED'; break;
- case 28: $function = 'LOOKUP'; break;
- case 29: $function = 'INDEX'; break;
- case 36: $function = 'AND'; break;
- case 37: $function = 'OR'; break;
- case 46: $function = 'VAR'; break;
- case 49: $function = 'LINEST'; break;
- case 50: $function = 'TREND'; break;
- case 51: $function = 'LOGEST'; break;
- case 52: $function = 'GROWTH'; break;
- case 56: $function = 'PV'; break;
- case 57: $function = 'FV'; break;
- case 58: $function = 'NPER'; break;
- case 59: $function = 'PMT'; break;
- case 60: $function = 'RATE'; break;
- case 62: $function = 'IRR'; break;
- case 64: $function = 'MATCH'; break;
- case 70: $function = 'WEEKDAY'; break;
- case 78: $function = 'OFFSET'; break;
- case 82: $function = 'SEARCH'; break;
- case 100: $function = 'CHOOSE'; break;
- case 101: $function = 'HLOOKUP'; break;
- case 102: $function = 'VLOOKUP'; break;
- case 109: $function = 'LOG'; break;
- case 115: $function = 'LEFT'; break;
- case 116: $function = 'RIGHT'; break;
- case 120: $function = 'SUBSTITUTE'; break;
- case 124: $function = 'FIND'; break;
- case 125: $function = 'CELL'; break;
- case 144: $function = 'DDB'; break;
- case 148: $function = 'INDIRECT'; break;
- case 167: $function = 'IPMT'; break;
- case 168: $function = 'PPMT'; break;
- case 169: $function = 'COUNTA'; break;
- case 183: $function = 'PRODUCT'; break;
- case 193: $function = 'STDEVP'; break;
- case 194: $function = 'VARP'; break;
- case 197: $function = 'TRUNC'; break;
- case 204: $function = 'USDOLLAR'; break;
- case 205: $function = 'FINDB'; break;
- case 206: $function = 'SEARCHB'; break;
- case 208: $function = 'LEFTB'; break;
- case 209: $function = 'RIGHTB'; break;
- case 216: $function = 'RANK'; break;
- case 219: $function = 'ADDRESS'; break;
- case 220: $function = 'DAYS360'; break;
- case 222: $function = 'VDB'; break;
- case 227: $function = 'MEDIAN'; break;
- case 228: $function = 'SUMPRODUCT'; break;
- case 247: $function = 'DB'; break;
- case 255: $function = ''; break;
- case 269: $function = 'AVEDEV'; break;
- case 270: $function = 'BETADIST'; break;
- case 272: $function = 'BETAINV'; break;
- case 317: $function = 'PROB'; break;
- case 318: $function = 'DEVSQ'; break;
- case 319: $function = 'GEOMEAN'; break;
- case 320: $function = 'HARMEAN'; break;
- case 321: $function = 'SUMSQ'; break;
- case 322: $function = 'KURT'; break;
- case 323: $function = 'SKEW'; break;
- case 324: $function = 'ZTEST'; break;
- case 329: $function = 'PERCENTRANK'; break;
- case 330: $function = 'MODE'; break;
- case 336: $function = 'CONCATENATE'; break;
- case 344: $function = 'SUBTOTAL'; break;
- case 345: $function = 'SUMIF'; break;
- case 354: $function = 'ROMAN'; break;
- case 358: $function = 'GETPIVOTDATA'; break;
- case 359: $function = 'HYPERLINK'; break;
- case 361: $function = 'AVERAGEA'; break;
- case 362: $function = 'MAXA'; break;
- case 363: $function = 'MINA'; break;
- case 364: $function = 'STDEVPA'; break;
- case 365: $function = 'VARPA'; break;
- case 366: $function = 'STDEVA'; break;
- case 367: $function = 'VARA'; break;
- default:
- throw new Exception('Unrecognized function in formula');
- break;
- }
- $data = array('function' => $function, 'args' => $args);
- break;
- case 0x23: // index to defined name
- case 0x43:
- case 0x63:
- $name = 'tName';
- $size = 5;
- // offset: 1; size: 2; one-based index to definedname record
- $definedNameIndex = self::_GetInt2d($formulaData, 1) - 1;
- // offset: 2; size: 2; not used
- $data = $this->_definedname[$definedNameIndex]['name'];
- break;
- case 0x24: // single cell reference e.g. A5
- case 0x44:
- case 0x64:
- $name = 'tRef';
- $size = 5;
- $data = $this->_readBIFF8CellAddress(substr($formulaData, 1, 4));
- break;
- case 0x25: // cell range reference to cells in the same sheet (2d)
- case 0x45:
- case 0x65:
- $name = 'tArea';
- $size = 9;
- $data = $this->_readBIFF8CellRangeAddress(substr($formulaData, 1, 8));
- break;
- case 0x26: // Constant reference sub-expression
- case 0x46:
- case 0x66:
- $name = 'tMemArea';
- // offset: 1; size: 4; not used
- // offset: 5; size: 2; size of the following subexpression
- $subSize = self::_GetInt2d($formulaData, 5);
- $size = 7 + $subSize;
- $data = $this->_getFormulaFromData(substr($formulaData, 7, $subSize));
- break;
- case 0x27: // Deleted constant reference sub-expression
- case 0x47:
- case 0x67:
- $name = 'tMemErr';
- // offset: 1; size: 4; not used
- // offset: 5; size: 2; size of the following subexpression
- $subSize = self::_GetInt2d($formulaData, 5);
- $size = 7 + $subSize;
- $data = $this->_getFormulaFromData(substr($formulaData, 7, $subSize));
- break;
- case 0x29: // Variable reference sub-expression
- case 0x49:
- case 0x69:
- $name = 'tMemFunc';
- // offset: 1; size: 2; size of the following sub-expression
- $subSize = self::_GetInt2d($formulaData, 1);
- $size = 3 + $subSize;
- $data = $this->_getFormulaFromData(substr($formulaData, 3, $subSize));
- break;
-
- case 0x2C: // Relative 2d cell reference reference, used in shared formulas and some other places
- case 0x4C:
- case 0x6C:
- $name = 'tRefN';
- $size = 5;
- $data = $this->_readBIFF8CellAddressB(substr($formulaData, 1, 4), $baseCell);
- break;
-
- case 0x2D: // Relative 2d range reference
- case 0x4D:
- case 0x6D:
- $name = 'tAreaN';
- $size = 9;
- $data = $this->_readBIFF8CellRangeAddressB(substr($formulaData, 1, 8), $baseCell);
- break;
-
- case 0x39: // External name
- case 0x59:
- case 0x79:
- $name = 'tNameX';
- $size = 7;
- // offset: 1; size: 2; index to REF entry in EXTERNSHEET record
- // offset: 3; size: 2; one-based index to DEFINEDNAME or EXTERNNAME record
- $index = self::_GetInt2d($formulaData, 3);
- // assume index is to EXTERNNAME record
- $data = $this->_externalNames[$index - 1]['name'];
- // offset: 5; size: 2; not used
- break;
-
- case 0x3A: // 3d reference to cell
- case 0x5A:
- case 0x7A:
- $name = 'tRef3d';
- $size = 7;
-
- try {
- // offset: 1; size: 2; index to REF entry
- $sheetRange = $this->_readSheetRangeByRefIndex(self::_GetInt2d($formulaData, 1));
- // offset: 3; size: 4; cell address
- $cellAddress = $this->_readBIFF8CellAddress(substr($formulaData, 3, 4));
-
- $data = "$sheetRange!$cellAddress";
- } catch (Exception $e) {
- // deleted sheet reference
- $data = '#REF!';
- }
-
- break;
- case 0x3B: // 3d reference to cell range
- case 0x5B:
- case 0x7B:
- $name = 'tArea3d';
- $size = 11;
-
- try {
- // offset: 1; size: 2; index to REF entry
- $sheetRange = $this->_readSheetRangeByRefIndex(self::_GetInt2d($formulaData, 1));
- // offset: 3; size: 8; cell address
- $cellRangeAddress = $this->_readBIFF8CellRangeAddress(substr($formulaData, 3, 8));
-
- $data = "$sheetRange!$cellRangeAddress";
- } catch (Exception $e) {
- // deleted sheet reference
- $data = '#REF!';
- }
-
- break;
- // Unknown cases // don't know how to deal with
- default:
- throw new Exception('Unrecognized token ' . sprintf('%02X', $id) . ' in formula');
- break;
- }
-
- return array(
- 'id' => $id,
- 'name' => $name,
- 'size' => $size,
- 'data' => $data,
- );
- }
-
-
- /**
- * Reads a cell address in BIFF8 e.g. 'A2' or '$A$2'
- * section 3.3.4
- *
- * @param string $cellAddressStructure
- * @return string
- */
- private function _readBIFF8CellAddress($cellAddressStructure)
- {
- // offset: 0; size: 2; index to row (0... 65535) (or offset (-32768... 32767))
- $row = self::_GetInt2d($cellAddressStructure, 0) + 1;
-
- // offset: 2; size: 2; index to column or column offset + relative flags
-
- // bit: 7-0; mask 0x00FF; column index
- $column = PHPExcel_Cell::stringFromColumnIndex(0x00FF & self::_GetInt2d($cellAddressStructure, 2));
-
- // bit: 14; mask 0x4000; (1 = relative column index, 0 = absolute column index)
- if (!(0x4000 & self::_GetInt2d($cellAddressStructure, 2))) {
- $column = '$' . $column;
- }
- // bit: 15; mask 0x8000; (1 = relative row index, 0 = absolute row index)
- if (!(0x8000 & self::_GetInt2d($cellAddressStructure, 2))) {
- $row = '$' . $row;
- }
-
- return $column . $row;
- }
-
-
- /**
- * Reads a cell address in BIFF8 for shared formulas. Uses positive and negative values for row and column
- * to indicate offsets from a base cell
- * section 3.3.4
- *
- * @param string $cellAddressStructure
- * @param string $baseCell Base cell, only needed when formula contains tRefN tokens, e.g. with shared formulas
- * @return string
- */
- private function _readBIFF8CellAddressB($cellAddressStructure, $baseCell = 'A1')
- {
- list($baseCol, $baseRow) = PHPExcel_Cell::coordinateFromString($baseCell);
- $baseCol = PHPExcel_Cell::columnIndexFromString($baseCol) - 1;
-
- // offset: 0; size: 2; index to row (0... 65535) (or offset (-32768... 32767))
- $rowIndex = self::_GetInt2d($cellAddressStructure, 0);
- $row = self::_GetInt2d($cellAddressStructure, 0) + 1;
-
- // offset: 2; size: 2; index to column or column offset + relative flags
-
- // bit: 7-0; mask 0x00FF; column index
- $colIndex = 0x00FF & self::_GetInt2d($cellAddressStructure, 2);
-
- // bit: 14; mask 0x4000; (1 = relative column index, 0 = absolute column index)
- if (!(0x4000 & self::_GetInt2d($cellAddressStructure, 2))) {
- $column = PHPExcel_Cell::stringFromColumnIndex($colIndex);
- $column = '$' . $column;
- } else {
- $colIndex = ($colIndex <= 127) ? $colIndex : $colIndex - 256;
- $column = PHPExcel_Cell::stringFromColumnIndex($baseCol + $colIndex);
- }
-
- // bit: 15; mask 0x8000; (1 = relative row index, 0 = absolute row index)
- if (!(0x8000 & self::_GetInt2d($cellAddressStructure, 2))) {
- $row = '$' . $row;
- } else {
- $rowIndex = ($rowIndex <= 32767) ? $rowIndex : $rowIndex - 65536;
- $row = $baseRow + $rowIndex;
- }
-
- return $column . $row;
- }
-
-
- /**
- * Reads a cell range address in BIFF5 e.g. 'A2:B6' or 'A1'
- * always fixed range
- * section 2.5.14
- *
- * @param string $subData
- * @return string
- * @throws Exception
- */
- private function _readBIFF5CellRangeAddressFixed($subData)
- {
- // offset: 0; size: 2; index to first row
- $fr = self::_GetInt2d($subData, 0) + 1;
-
- // offset: 2; size: 2; index to last row
- $lr = self::_GetInt2d($subData, 2) + 1;
-
- // offset: 4; size: 1; index to first column
- $fc = ord($subData{4});
-
- // offset: 5; size: 1; index to last column
- $lc = ord($subData{5});
-
- // check values
- if ($fr > $lr || $fc > $lc) {
- throw new Exception('Not a cell range address');
- }
-
- // column index to letter
- $fc = PHPExcel_Cell::stringFromColumnIndex($fc);
- $lc = PHPExcel_Cell::stringFromColumnIndex($lc);
-
- if ($fr == $lr and $fc == $lc) {
- return "$fc$fr";
- }
- return "$fc$fr:$lc$lr";
- }
-
-
- /**
- * Reads a cell range address in BIFF8 e.g. 'A2:B6' or 'A1'
- * always fixed range
- * section 2.5.14
- *
- * @param string $subData
- * @return string
- * @throws Exception
- */
- private function _readBIFF8CellRangeAddressFixed($subData)
- {
- // offset: 0; size: 2; index to first row
- $fr = self::_GetInt2d($subData, 0) + 1;
-
- // offset: 2; size: 2; index to last row
- $lr = self::_GetInt2d($subData, 2) + 1;
-
- // offset: 4; size: 2; index to first column
- $fc = self::_GetInt2d($subData, 4);
-
- // offset: 6; size: 2; index to last column
- $lc = self::_GetInt2d($subData, 6);
-
- // check values
- if ($fr > $lr || $fc > $lc) {
- throw new Exception('Not a cell range address');
- }
-
- // column index to letter
- $fc = PHPExcel_Cell::stringFromColumnIndex($fc);
- $lc = PHPExcel_Cell::stringFromColumnIndex($lc);
-
- if ($fr == $lr and $fc == $lc) {
- return "$fc$fr";
- }
- return "$fc$fr:$lc$lr";
- }
-
-
- /**
- * Reads a cell range address in BIFF8 e.g. 'A2:B6' or '$A$2:$B$6'
- * there are flags indicating whether column/row index is relative
- * section 3.3.4
- *
- * @param string $subData
- * @return string
- */
- private function _readBIFF8CellRangeAddress($subData)
- {
- // todo: if cell range is just a single cell, should this funciton
- // not just return e.g. 'A1' and not 'A1:A1' ?
-
- // offset: 0; size: 2; index to first row (0... 65535) (or offset (-32768... 32767))
- $fr = self::_GetInt2d($subData, 0) + 1;
-
- // offset: 2; size: 2; index to last row (0... 65535) (or offset (-32768... 32767))
- $lr = self::_GetInt2d($subData, 2) + 1;
-
- // offset: 4; size: 2; index to first column or column offset + relative flags
-
- // bit: 7-0; mask 0x00FF; column index
- $fc = PHPExcel_Cell::stringFromColumnIndex(0x00FF & self::_GetInt2d($subData, 4));
-
- // bit: 14; mask 0x4000; (1 = relative column index, 0 = absolute column index)
- if (!(0x4000 & self::_GetInt2d($subData, 4))) {
- $fc = '$' . $fc;
- }
-
- // bit: 15; mask 0x8000; (1 = relative row index, 0 = absolute row index)
- if (!(0x8000 & self::_GetInt2d($subData, 4))) {
- $fr = '$' . $fr;
- }
-
- // offset: 6; size: 2; index to last column or column offset + relative flags
-
- // bit: 7-0; mask 0x00FF; column index
- $lc = PHPExcel_Cell::stringFromColumnIndex(0x00FF & self::_GetInt2d($subData, 6));
-
- // bit: 14; mask 0x4000; (1 = relative column index, 0 = absolute column index)
- if (!(0x4000 & self::_GetInt2d($subData, 6))) {
- $lc = '$' . $lc;
- }
-
- // bit: 15; mask 0x8000; (1 = relative row index, 0 = absolute row index)
- if (!(0x8000 & self::_GetInt2d($subData, 6))) {
- $lr = '$' . $lr;
- }
-
- return "$fc$fr:$lc$lr";
- }
-
-
- /**
- * Reads a cell range address in BIFF8 for shared formulas. Uses positive and negative values for row and column
- * to indicate offsets from a base cell
- * section 3.3.4
- *
- * @param string $subData
- * @param string $baseCell Base cell
- * @return string Cell range address
- */
- private function _readBIFF8CellRangeAddressB($subData, $baseCell = 'A1')
- {
- list($baseCol, $baseRow) = PHPExcel_Cell::coordinateFromString($baseCell);
- $baseCol = PHPExcel_Cell::columnIndexFromString($baseCol) - 1;
-
- // TODO: if cell range is just a single cell, should this funciton
- // not just return e.g. 'A1' and not 'A1:A1' ?
-
- // offset: 0; size: 2; first row
- $frIndex = self::_GetInt2d($subData, 0); // adjust below
-
- // offset: 2; size: 2; relative index to first row (0... 65535) should be treated as offset (-32768... 32767)
- $lrIndex = self::_GetInt2d($subData, 2); // adjust below
-
- // offset: 4; size: 2; first column with relative/absolute flags
-
- // bit: 7-0; mask 0x00FF; column index
- $fcIndex = 0x00FF & self::_GetInt2d($subData, 4);
-
- // bit: 14; mask 0x4000; (1 = relative column index, 0 = absolute column index)
- if (!(0x4000 & self::_GetInt2d($subData, 4))) {
- // absolute column index
- $fc = PHPExcel_Cell::stringFromColumnIndex($fcIndex);
- $fc = '$' . $fc;
- } else {
- // column offset
- $fcIndex = ($fcIndex <= 127) ? $fcIndex : $fcIndex - 256;
- $fc = PHPExcel_Cell::stringFromColumnIndex($baseCol + $fcIndex);
- }
-
- // bit: 15; mask 0x8000; (1 = relative row index, 0 = absolute row index)
- if (!(0x8000 & self::_GetInt2d($subData, 4))) {
- // absolute row index
- $fr = $frIndex + 1;
- $fr = '$' . $fr;
- } else {
- // row offset
- $frIndex = ($frIndex <= 32767) ? $frIndex : $frIndex - 65536;
- $fr = $baseRow + $frIndex;
- }
-
- // offset: 6; size: 2; last column with relative/absolute flags
-
- // bit: 7-0; mask 0x00FF; column index
- $lcIndex = 0x00FF & self::_GetInt2d($subData, 6);
- $lcIndex = ($lcIndex <= 127) ? $lcIndex : $lcIndex - 256;
- $lc = PHPExcel_Cell::stringFromColumnIndex($baseCol + $lcIndex);
-
- // bit: 14; mask 0x4000; (1 = relative column index, 0 = absolute column index)
- if (!(0x4000 & self::_GetInt2d($subData, 6))) {
- // absolute column index
- $lc = PHPExcel_Cell::stringFromColumnIndex($lcIndex);
- $lc = '$' . $lc;
- } else {
- // column offset
- $lcIndex = ($lcIndex <= 127) ? $lcIndex : $lcIndex - 256;
- $lc = PHPExcel_Cell::stringFromColumnIndex($baseCol + $lcIndex);
- }
-
- // bit: 15; mask 0x8000; (1 = relative row index, 0 = absolute row index)
- if (!(0x8000 & self::_GetInt2d($subData, 6))) {
- // absolute row index
- $lr = $lrIndex + 1;
- $lr = '$' . $lr;
- } else {
- // row offset
- $lrIndex = ($lrIndex <= 32767) ? $lrIndex : $lrIndex - 65536;
- $lr = $baseRow + $lrIndex;
- }
-
- return "$fc$fr:$lc$lr";
- }
-
-
- /**
- * Read BIFF8 cell range address list
- * section 2.5.15
- *
- * @param string $subData
- * @return array
- */
- private function _readBIFF8CellRangeAddressList($subData)
- {
- $cellRangeAddresses = array();
-
- // offset: 0; size: 2; number of the following cell range addresses
- $nm = self::_GetInt2d($subData, 0);
-
- $offset = 2;
- // offset: 2; size: 8 * $nm; list of $nm (fixed) cell range addresses
- for ($i = 0; $i < $nm; ++$i) {
- $cellRangeAddresses[] = $this->_readBIFF8CellRangeAddressFixed(substr($subData, $offset, 8));
- $offset += 8;
- }
-
- return array(
- 'size' => 2 + 8 * $nm,
- 'cellRangeAddresses' => $cellRangeAddresses,
- );
- }
-
-
- /**
- * Read BIFF5 cell range address list
- * section 2.5.15
- *
- * @param string $subData
- * @return array
- */
- private function _readBIFF5CellRangeAddressList($subData)
- {
- $cellRangeAddresses = array();
-
- // offset: 0; size: 2; number of the following cell range addresses
- $nm = self::_GetInt2d($subData, 0);
-
- $offset = 2;
- // offset: 2; size: 6 * $nm; list of $nm (fixed) cell range addresses
- for ($i = 0; $i < $nm; ++$i) {
- $cellRangeAddresses[] = $this->_readBIFF5CellRangeAddressFixed(substr($subData, $offset, 6));
- $offset += 6;
- }
-
- return array(
- 'size' => 2 + 6 * $nm,
- 'cellRangeAddresses' => $cellRangeAddresses,
- );
- }
-
-
- /**
- * Get a sheet range like Sheet1:Sheet3 from REF index
- * Note: If there is only one sheet in the range, one gets e.g Sheet1
- * It can also happen that the REF structure uses the -1 (FFFF) code to indicate deleted sheets,
- * in which case an exception is thrown
- *
- * @param int $index
- * @return string|false
- * @throws Exception
- */
- private function _readSheetRangeByRefIndex($index)
- {
- if (isset($this->_ref[$index])) {
-
- $type = $this->_externalBooks[$this->_ref[$index]['externalBookIndex']]['type'];
-
- switch ($type) {
- case 'internal':
- // check if we have a deleted 3d reference
- if ($this->_ref[$index]['firstSheetIndex'] == 0xFFFF or $this->_ref[$index]['lastSheetIndex'] == 0xFFFF) {
- throw new Exception('Deleted sheet reference');
- }
-
- // we have normal sheet range (collapsed or uncollapsed)
- $firstSheetName = $this->_sheets[$this->_ref[$index]['firstSheetIndex']]['name'];
- $lastSheetName = $this->_sheets[$this->_ref[$index]['lastSheetIndex']]['name'];
-
- if ($firstSheetName == $lastSheetName) {
- // collapsed sheet range
- $sheetRange = $firstSheetName;
- } else {
- $sheetRange = "$firstSheetName:$lastSheetName";
- }
-
- // escape the single-quotes
- $sheetRange = str_replace("'", "''", $sheetRange);
-
- // if there are special characters, we need to enclose the range in single-quotes
- // todo: check if we have identified the whole set of special characters
- // it seems that the following characters are not accepted for sheet names
- // and we may assume that they are not present: []*/:\?
- if (preg_match("/[ !\"@#£$%&{()}<>=+'|^,;-]/", $sheetRange)) {
- $sheetRange = "'$sheetRange'";
- }
-
- return $sheetRange;
- break;
-
- default:
- // TODO: external sheet support
- throw new Exception('Excel5 reader only supports internal sheets in fomulas');
- break;
- }
- }
- return false;
- }
-
-
- /**
- * read BIFF8 constant value array from array data
- * returns e.g. array('value' => '{1,2;3,4}', 'size' => 40}
- * section 2.5.8
- *
- * @param string $arrayData
- * @return array
- */
- private static function _readBIFF8ConstantArray($arrayData)
- {
- // offset: 0; size: 1; number of columns decreased by 1
- $nc = ord($arrayData[0]);
-
- // offset: 1; size: 2; number of rows decreased by 1
- $nr = self::_GetInt2d($arrayData, 1);
- $size = 3; // initialize
- $arrayData = substr($arrayData, 3);
-
- // offset: 3; size: var; list of ($nc + 1) * ($nr + 1) constant values
- $matrixChunks = array();
- for ($r = 1; $r <= $nr + 1; ++$r) {
- $items = array();
- for ($c = 1; $c <= $nc + 1; ++$c) {
- $constant = self::_readBIFF8Constant($arrayData);
- $items[] = $constant['value'];
- $arrayData = substr($arrayData, $constant['size']);
- $size += $constant['size'];
- }
- $matrixChunks[] = implode(',', $items); // looks like e.g. '1,"hello"'
- }
- $matrix = '{' . implode(';', $matrixChunks) . '}';
-
- return array(
- 'value' => $matrix,
- 'size' => $size,
- );
- }
-
-
- /**
- * read BIFF8 constant value which may be 'Empty Value', 'Number', 'String Value', 'Boolean Value', 'Error Value'
- * section 2.5.7
- * returns e.g. array('value' => '5', 'size' => 9)
- *
- * @param string $valueData
- * @return array
- */
- private static function _readBIFF8Constant($valueData)
- {
- // offset: 0; size: 1; identifier for type of constant
- $identifier = ord($valueData[0]);
-
- switch ($identifier) {
- case 0x00: // empty constant (what is this?)
- $value = '';
- $size = 9;
- break;
- case 0x01: // number
- // offset: 1; size: 8; IEEE 754 floating-point value
- $value = self::_extractNumber(substr($valueData, 1, 8));
- $size = 9;
- break;
- case 0x02: // string value
- // offset: 1; size: var; Unicode string, 16-bit string length
- $string = self::_readUnicodeStringLong(substr($valueData, 1));
- $value = '"' . $string['value'] . '"';
- $size = 1 + $string['size'];
- break;
- case 0x04: // boolean
- // offset: 1; size: 1; 0 = FALSE, 1 = TRUE
- if (ord($valueData[1])) {
- $value = 'TRUE';
- } else {
- $value = 'FALSE';
- }
- $size = 9;
- break;
- case 0x10: // error code
- // offset: 1; size: 1; error code
- $value = self::_mapErrorCode(ord($valueData[1]));
- $size = 9;
- break;
- }
- return array(
- 'value' => $value,
- 'size' => $size,
- );
- }
-
-
- /**
- * Extract RGB color
- * OpenOffice.org's Documentation of the Microsoft Excel File Format, section 2.5.4
- *
- * @param string $rgb Encoded RGB value (4 bytes)
- * @return array
- */
- private static function _readRGB($rgb)
- {
- // offset: 0; size 1; Red component
- $r = ord($rgb{0});
-
- // offset: 1; size: 1; Green component
- $g = ord($rgb{1});
-
- // offset: 2; size: 1; Blue component
- $b = ord($rgb{2});
-
- // HEX notation, e.g. 'FF00FC'
- $rgb = sprintf('%02X%02X%02X', $r, $g, $b);
-
- return array('rgb' => $rgb);
- }
-
-
- /**
- * Read byte string (8-bit string length)
- * OpenOffice documentation: 2.5.2
- *
- * @param string $subData
- * @return array
- */
- private function _readByteStringShort($subData)
- {
- // offset: 0; size: 1; length of the string (character count)
- $ln = ord($subData[0]);
-
- // offset: 1: size: var; character array (8-bit characters)
- $value = $this->_decodeCodepage(substr($subData, 1, $ln));
-
- return array(
- 'value' => $value,
- 'size' => 1 + $ln, // size in bytes of data structure
- );
- }
-
-
- /**
- * Read byte string (16-bit string length)
- * OpenOffice documentation: 2.5.2
- *
- * @param string $subData
- * @return array
- */
- private function _readByteStringLong($subData)
- {
- // offset: 0; size: 2; length of the string (character count)
- $ln = self::_GetInt2d($subData, 0);
-
- // offset: 2: size: var; character array (8-bit characters)
- $value = $this->_decodeCodepage(substr($subData, 2));
-
- //return $string;
- return array(
- 'value' => $value,
- 'size' => 2 + $ln, // size in bytes of data structure
- );
- }
-
-
- /**
- * Extracts an Excel Unicode short string (8-bit string length)
- * OpenOffice documentation: 2.5.3
- * function will automatically find out where the Unicode string ends.
- *
- * @param string $subData
- * @return array
- */
- private static function _readUnicodeStringShort($subData)
- {
- $value = '';
-
- // offset: 0: size: 1; length of the string (character count)
- $characterCount = ord($subData[0]);
-
- $string = self::_readUnicodeString(substr($subData, 1), $characterCount);
-
- // add 1 for the string length
- $string['size'] += 1;
-
- return $string;
- }
-
-
- /**
- * Extracts an Excel Unicode long string (16-bit string length)
- * OpenOffice documentation: 2.5.3
- * this function is under construction, needs to support rich text, and Asian phonetic settings
- *
- * @param string $subData
- * @return array
- */
- private static function _readUnicodeStringLong($subData)
- {
- $value = '';
-
- // offset: 0: size: 2; length of the string (character count)
- $characterCount = self::_GetInt2d($subData, 0);
-
- $string = self::_readUnicodeString(substr($subData, 2), $characterCount);
-
- // add 2 for the string length
- $string['size'] += 2;
-
- return $string;
- }
-
-
- /**
- * Read Unicode string with no string length field, but with known character count
- * this function is under construction, needs to support rich text, and Asian phonetic settings
- * OpenOffice.org's Documentation of the Microsoft Excel File Format, section 2.5.3
- *
- * @param string $subData
- * @param int $characterCount
- * @return array
- */
- private static function _readUnicodeString($subData, $characterCount)
- {
- $value = '';
-
- // offset: 0: size: 1; option flags
-
- // bit: 0; mask: 0x01; character compression (0 = compressed 8-bit, 1 = uncompressed 16-bit)
- $isCompressed = !((0x01 & ord($subData[0])) >> 0);
-
- // bit: 2; mask: 0x04; Asian phonetic settings
- $hasAsian = (0x04) & ord($subData[0]) >> 2;
-
- // bit: 3; mask: 0x08; Rich-Text settings
- $hasRichText = (0x08) & ord($subData[0]) >> 3;
-
- // offset: 1: size: var; character array
- // this offset assumes richtext and Asian phonetic settings are off which is generally wrong
- // needs to be fixed
- $value = self::_encodeUTF16(substr($subData, 1, $isCompressed ? $characterCount : 2 * $characterCount), $isCompressed);
-
- return array(
- 'value' => $value,
- 'size' => $isCompressed ? 1 + $characterCount : 1 + 2 * $characterCount, // the size in bytes including the option flags
- );
- }
-
-
- /**
- * Convert UTF-8 string to string surounded by double quotes. Used for explicit string tokens in formulas.
- * Example: hello"world --> "hello""world"
- *
- * @param string $value UTF-8 encoded string
- * @return string
- */
- private static function _UTF8toExcelDoubleQuoted($value)
- {
- return '"' . str_replace('"', '""', $value) . '"';
- }
-
-
- /**
- * Reads first 8 bytes of a string and return IEEE 754 float
- *
- * @param string $data Binary string that is at least 8 bytes long
- * @return float
- */
- private static function _extractNumber($data)
- {
- $rknumhigh = self::_GetInt4d($data, 4);
- $rknumlow = self::_GetInt4d($data, 0);
- $sign = ($rknumhigh & 0x80000000) >> 31;
- $exp = (($rknumhigh & 0x7ff00000) >> 20) - 1023;
- $mantissa = (0x100000 | ($rknumhigh & 0x000fffff));
- $mantissalow1 = ($rknumlow & 0x80000000) >> 31;
- $mantissalow2 = ($rknumlow & 0x7fffffff);
- $value = $mantissa / pow( 2 , (20 - $exp));
-
- if ($mantissalow1 != 0) {
- $value += 1 / pow (2 , (21 - $exp));
- }
-
- $value += $mantissalow2 / pow (2 , (52 - $exp));
- if ($sign) {
- $value *= -1;
- }
-
- return $value;
- }
-
-
- private static function _GetIEEE754($rknum)
- {
- if (($rknum & 0x02) != 0) {
- $value = $rknum >> 2;
- } else {
- // changes by mmp, info on IEEE754 encoding from
- // research.microsoft.com/~hollasch/cgindex/coding/ieeefloat.html
- // The RK format calls for using only the most significant 30 bits
- // of the 64 bit floating point value. The other 34 bits are assumed
- // to be 0 so we use the upper 30 bits of $rknum as follows...
- $sign = ($rknum & 0x80000000) >> 31;
- $exp = ($rknum & 0x7ff00000) >> 20;
- $mantissa = (0x100000 | ($rknum & 0x000ffffc));
- $value = $mantissa / pow( 2 , (20- ($exp - 1023)));
- if ($sign) {
- $value = -1 * $value;
- }
- //end of changes by mmp
- }
- if (($rknum & 0x01) != 0) {
- $value /= 100;
- }
- return $value;
- }
-
-
- /**
- * Get UTF-8 string from (compressed or uncompressed) UTF-16 string
- *
- * @param string $string
- * @param bool $compressed
- * @return string
- */
- private static function _encodeUTF16($string, $compressed = '')
- {
- if ($compressed) {
- $string = self::_uncompressByteString($string);
- }
-
- return PHPExcel_Shared_String::ConvertEncoding($string, 'UTF-8', 'UTF-16LE');
- }
-
-
- /**
- * Convert UTF-16 string in compressed notation to uncompressed form. Only used for BIFF8.
- *
- * @param string $string
- * @return string
- */
- private static function _uncompressByteString($string)
- {
- $uncompressedString = '';
- $strLen = strlen($string);
- for ($i = 0; $i < $strLen; ++$i) {
- $uncompressedString .= $string[$i] . "\0";
- }
-
- return $uncompressedString;
- }
-
-
- /**
- * Convert string to UTF-8. Only used for BIFF5.
- *
- * @param string $string
- * @return string
- */
- private function _decodeCodepage($string)
- {
- return PHPExcel_Shared_String::ConvertEncoding($string, 'UTF-8', $this->_codepage);
- }
-
-
- /**
- * Read 16-bit unsigned integer
- *
- * @param string $data
- * @param int $pos
- * @return int
- */
- public static function _GetInt2d($data, $pos)
- {
- return ord($data[$pos]) | (ord($data[$pos+1]) << 8);
- }
-
-
- /**
- * Read 32-bit signed integer
- *
- * @param string $data
- * @param int $pos
- * @return int
- */
- public static function _GetInt4d($data, $pos)
- {
- // FIX: represent numbers correctly on 64-bit system
- // http://sourceforge.net/tracker/index.php?func=detail&aid=1487372&group_id=99160&atid=623334
- // Hacked by Andreas Rehm 2006 to ensure correct result of the <<24 block on 32 and 64bit systems
- $_or_24 = ord($data[$pos + 3]);
- if ($_or_24 >= 128) {
- // negative number
- $_ord_24 = -abs((256 - $_or_24) << 24);
- } else {
- $_ord_24 = ($_or_24 & 127) << 24;
- }
- return ord($data[$pos]) | (ord($data[$pos+1]) << 8) | (ord($data[$pos+2]) << 16) | $_ord_24;
- }
-
-
- /**
- * Read color
- *
- * @param int $color Indexed color
- * @param array $palette Color palette
- * @return array RGB color value, example: array('rgb' => 'FF0000')
- */
- private static function _readColor($color,$palette,$version)
- {
- if ($color <= 0x07 || $color >= 0x40) {
- // special built-in color
- return self::_mapBuiltInColor($color);
- } elseif (isset($palette) && isset($palette[$color - 8])) {
- // palette color, color index 0x08 maps to pallete index 0
- return $palette[$color - 8];
- } else {
- // default color table
- if ($version == self::XLS_BIFF8) {
- return self::_mapColor($color);
- } else {
- // BIFF5
- return self::_mapColorBIFF5($color);
- }
- }
-
- return $color;
- }
-
-
- /**
- * Map border style
- * OpenOffice documentation: 2.5.11
- *
- * @param int $index
- * @return string
- */
- private static function _mapBorderStyle($index)
- {
- switch ($index) {
- case 0x00: return PHPExcel_Style_Border::BORDER_NONE;
- case 0x01: return PHPExcel_Style_Border::BORDER_THIN;
- case 0x02: return PHPExcel_Style_Border::BORDER_MEDIUM;
- case 0x03: return PHPExcel_Style_Border::BORDER_DASHED;
- case 0x04: return PHPExcel_Style_Border::BORDER_DOTTED;
- case 0x05: return PHPExcel_Style_Border::BORDER_THICK;
- case 0x06: return PHPExcel_Style_Border::BORDER_DOUBLE;
- case 0x07: return PHPExcel_Style_Border::BORDER_HAIR;
- case 0x08: return PHPExcel_Style_Border::BORDER_MEDIUMDASHED;
- case 0x09: return PHPExcel_Style_Border::BORDER_DASHDOT;
- case 0x0A: return PHPExcel_Style_Border::BORDER_MEDIUMDASHDOT;
- case 0x0B: return PHPExcel_Style_Border::BORDER_DASHDOTDOT;
- case 0x0C: return PHPExcel_Style_Border::BORDER_MEDIUMDASHDOTDOT;
- case 0x0D: return PHPExcel_Style_Border::BORDER_SLANTDASHDOT;
- default: return PHPExcel_Style_Border::BORDER_NONE;
- }
- }
-
-
- /**
- * Get fill pattern from index
- * OpenOffice documentation: 2.5.12
- *
- * @param int $index
- * @return string
- */
- private static function _mapFillPattern($index)
- {
- switch ($index) {
- case 0x00: return PHPExcel_Style_Fill::FILL_NONE;
- case 0x01: return PHPExcel_Style_Fill::FILL_SOLID;
- case 0x02: return PHPExcel_Style_Fill::FILL_PATTERN_MEDIUMGRAY;
- case 0x03: return PHPExcel_Style_Fill::FILL_PATTERN_DARKGRAY;
- case 0x04: return PHPExcel_Style_Fill::FILL_PATTERN_LIGHTGRAY;
- case 0x05: return PHPExcel_Style_Fill::FILL_PATTERN_DARKHORIZONTAL;
- case 0x06: return PHPExcel_Style_Fill::FILL_PATTERN_DARKVERTICAL;
- case 0x07: return PHPExcel_Style_Fill::FILL_PATTERN_DARKDOWN;
- case 0x08: return PHPExcel_Style_Fill::FILL_PATTERN_DARKUP;
- case 0x09: return PHPExcel_Style_Fill::FILL_PATTERN_DARKGRID;
- case 0x0A: return PHPExcel_Style_Fill::FILL_PATTERN_DARKTRELLIS;
- case 0x0B: return PHPExcel_Style_Fill::FILL_PATTERN_LIGHTHORIZONTAL;
- case 0x0C: return PHPExcel_Style_Fill::FILL_PATTERN_LIGHTVERTICAL;
- case 0x0D: return PHPExcel_Style_Fill::FILL_PATTERN_LIGHTDOWN;
- case 0x0E: return PHPExcel_Style_Fill::FILL_PATTERN_LIGHTUP;
- case 0x0F: return PHPExcel_Style_Fill::FILL_PATTERN_LIGHTGRID;
- case 0x10: return PHPExcel_Style_Fill::FILL_PATTERN_LIGHTTRELLIS;
- case 0x11: return PHPExcel_Style_Fill::FILL_PATTERN_GRAY125;
- case 0x12: return PHPExcel_Style_Fill::FILL_PATTERN_GRAY0625;
- default: return PHPExcel_Style_Fill::FILL_NONE;
- }
- }
-
-
- /**
- * Map error code, e.g. '#N/A'
- *
- * @param int $subData
- * @return string
- */
- private static function _mapErrorCode($subData)
- {
- switch ($subData) {
- case 0x00: return '#NULL!'; break;
- case 0x07: return '#DIV/0!'; break;
- case 0x0F: return '#VALUE!'; break;
- case 0x17: return '#REF!'; break;
- case 0x1D: return '#NAME?'; break;
- case 0x24: return '#NUM!'; break;
- case 0x2A: return '#N/A'; break;
- default: return false;
- }
- }
-
-
- /**
- * Map built-in color to RGB value
- *
- * @param int $color Indexed color
- * @return array
- */
- private static function _mapBuiltInColor($color)
- {
- switch ($color) {
- case 0x00: return array('rgb' => '000000');
- case 0x01: return array('rgb' => 'FFFFFF');
- case 0x02: return array('rgb' => 'FF0000');
- case 0x03: return array('rgb' => '00FF00');
- case 0x04: return array('rgb' => '0000FF');
- case 0x05: return array('rgb' => 'FFFF00');
- case 0x06: return array('rgb' => 'FF00FF');
- case 0x07: return array('rgb' => '00FFFF');
- case 0x40: return array('rgb' => '000000'); // system window text color
- case 0x41: return array('rgb' => 'FFFFFF'); // system window background color
- default: return array('rgb' => '000000');
- }
- }
-
-
- /**
- * Map color array from BIFF5 built-in color index
- *
- * @param int $subData
- * @return array
- */
- private static function _mapColorBIFF5($subData)
- {
- switch ($subData) {
- case 0x08: return array('rgb' => '000000');
- case 0x09: return array('rgb' => 'FFFFFF');
- case 0x0A: return array('rgb' => 'FF0000');
- case 0x0B: return array('rgb' => '00FF00');
- case 0x0C: return array('rgb' => '0000FF');
- case 0x0D: return array('rgb' => 'FFFF00');
- case 0x0E: return array('rgb' => 'FF00FF');
- case 0x0F: return array('rgb' => '00FFFF');
- case 0x10: return array('rgb' => '800000');
- case 0x11: return array('rgb' => '008000');
- case 0x12: return array('rgb' => '000080');
- case 0x13: return array('rgb' => '808000');
- case 0x14: return array('rgb' => '800080');
- case 0x15: return array('rgb' => '008080');
- case 0x16: return array('rgb' => 'C0C0C0');
- case 0x17: return array('rgb' => '808080');
- case 0x18: return array('rgb' => '8080FF');
- case 0x19: return array('rgb' => '802060');
- case 0x1A: return array('rgb' => 'FFFFC0');
- case 0x1B: return array('rgb' => 'A0E0F0');
- case 0x1C: return array('rgb' => '600080');
- case 0x1D: return array('rgb' => 'FF8080');
- case 0x1E: return array('rgb' => '0080C0');
- case 0x1F: return array('rgb' => 'C0C0FF');
- case 0x20: return array('rgb' => '000080');
- case 0x21: return array('rgb' => 'FF00FF');
- case 0x22: return array('rgb' => 'FFFF00');
- case 0x23: return array('rgb' => '00FFFF');
- case 0x24: return array('rgb' => '800080');
- case 0x25: return array('rgb' => '800000');
- case 0x26: return array('rgb' => '008080');
- case 0x27: return array('rgb' => '0000FF');
- case 0x28: return array('rgb' => '00CFFF');
- case 0x29: return array('rgb' => '69FFFF');
- case 0x2A: return array('rgb' => 'E0FFE0');
- case 0x2B: return array('rgb' => 'FFFF80');
- case 0x2C: return array('rgb' => 'A6CAF0');
- case 0x2D: return array('rgb' => 'DD9CB3');
- case 0x2E: return array('rgb' => 'B38FEE');
- case 0x2F: return array('rgb' => 'E3E3E3');
- case 0x30: return array('rgb' => '2A6FF9');
- case 0x31: return array('rgb' => '3FB8CD');
- case 0x32: return array('rgb' => '488436');
- case 0x33: return array('rgb' => '958C41');
- case 0x34: return array('rgb' => '8E5E42');
- case 0x35: return array('rgb' => 'A0627A');
- case 0x36: return array('rgb' => '624FAC');
- case 0x37: return array('rgb' => '969696');
- case 0x38: return array('rgb' => '1D2FBE');
- case 0x39: return array('rgb' => '286676');
- case 0x3A: return array('rgb' => '004500');
- case 0x3B: return array('rgb' => '453E01');
- case 0x3C: return array('rgb' => '6A2813');
- case 0x3D: return array('rgb' => '85396A');
- case 0x3E: return array('rgb' => '4A3285');
- case 0x3F: return array('rgb' => '424242');
- default: return array('rgb' => '000000');
- }
- }
-
-
- /**
- * Map color array from BIFF8 built-in color index
- *
- * @param int $subData
- * @return array
- */
- private static function _mapColor($subData)
- {
- switch ($subData) {
- case 0x08: return array('rgb' => '000000');
- case 0x09: return array('rgb' => 'FFFFFF');
- case 0x0A: return array('rgb' => 'FF0000');
- case 0x0B: return array('rgb' => '00FF00');
- case 0x0C: return array('rgb' => '0000FF');
- case 0x0D: return array('rgb' => 'FFFF00');
- case 0x0E: return array('rgb' => 'FF00FF');
- case 0x0F: return array('rgb' => '00FFFF');
- case 0x10: return array('rgb' => '800000');
- case 0x11: return array('rgb' => '008000');
- case 0x12: return array('rgb' => '000080');
- case 0x13: return array('rgb' => '808000');
- case 0x14: return array('rgb' => '800080');
- case 0x15: return array('rgb' => '008080');
- case 0x16: return array('rgb' => 'C0C0C0');
- case 0x17: return array('rgb' => '808080');
- case 0x18: return array('rgb' => '9999FF');
- case 0x19: return array('rgb' => '993366');
- case 0x1A: return array('rgb' => 'FFFFCC');
- case 0x1B: return array('rgb' => 'CCFFFF');
- case 0x1C: return array('rgb' => '660066');
- case 0x1D: return array('rgb' => 'FF8080');
- case 0x1E: return array('rgb' => '0066CC');
- case 0x1F: return array('rgb' => 'CCCCFF');
- case 0x20: return array('rgb' => '000080');
- case 0x21: return array('rgb' => 'FF00FF');
- case 0x22: return array('rgb' => 'FFFF00');
- case 0x23: return array('rgb' => '00FFFF');
- case 0x24: return array('rgb' => '800080');
- case 0x25: return array('rgb' => '800000');
- case 0x26: return array('rgb' => '008080');
- case 0x27: return array('rgb' => '0000FF');
- case 0x28: return array('rgb' => '00CCFF');
- case 0x29: return array('rgb' => 'CCFFFF');
- case 0x2A: return array('rgb' => 'CCFFCC');
- case 0x2B: return array('rgb' => 'FFFF99');
- case 0x2C: return array('rgb' => '99CCFF');
- case 0x2D: return array('rgb' => 'FF99CC');
- case 0x2E: return array('rgb' => 'CC99FF');
- case 0x2F: return array('rgb' => 'FFCC99');
- case 0x30: return array('rgb' => '3366FF');
- case 0x31: return array('rgb' => '33CCCC');
- case 0x32: return array('rgb' => '99CC00');
- case 0x33: return array('rgb' => 'FFCC00');
- case 0x34: return array('rgb' => 'FF9900');
- case 0x35: return array('rgb' => 'FF6600');
- case 0x36: return array('rgb' => '666699');
- case 0x37: return array('rgb' => '969696');
- case 0x38: return array('rgb' => '003366');
- case 0x39: return array('rgb' => '339966');
- case 0x3A: return array('rgb' => '003300');
- case 0x3B: return array('rgb' => '333300');
- case 0x3C: return array('rgb' => '993300');
- case 0x3D: return array('rgb' => '993366');
- case 0x3E: return array('rgb' => '333399');
- case 0x3F: return array('rgb' => '333333');
- default: return array('rgb' => '000000');
- }
- }
-
-
- private function _parseRichText($is = '') {
- $value = new PHPExcel_RichText();
-
- $value->createText($is);
-
- return $value;
- }
-
-}
+_data
+ *
+ * @var int
+ */
+ private $_dataSize;
+
+ /**
+ * Current position in stream
+ *
+ * @var integer
+ */
+ private $_pos;
+
+ /**
+ * Workbook to be returned by the reader.
+ *
+ * @var PHPExcel
+ */
+ private $_phpExcel;
+
+ /**
+ * Worksheet that is currently being built by the reader.
+ *
+ * @var PHPExcel_Worksheet
+ */
+ private $_phpSheet;
+
+ /**
+ * BIFF version
+ *
+ * @var int
+ */
+ private $_version;
+
+ /**
+ * Codepage set in the Excel file being read. Only important for BIFF5 (Excel 5.0 - Excel 95)
+ * For BIFF8 (Excel 97 - Excel 2003) this will always have the value 'UTF-16LE'
+ *
+ * @var string
+ */
+ private $_codepage;
+
+ /**
+ * Shared formats
+ *
+ * @var array
+ */
+ private $_formats;
+
+ /**
+ * Shared fonts
+ *
+ * @var array
+ */
+ private $_objFonts;
+
+ /**
+ * Color palette
+ *
+ * @var array
+ */
+ private $_palette;
+
+ /**
+ * Worksheets
+ *
+ * @var array
+ */
+ private $_sheets;
+
+ /**
+ * External books
+ *
+ * @var array
+ */
+ private $_externalBooks;
+
+ /**
+ * REF structures. Only applies to BIFF8.
+ *
+ * @var array
+ */
+ private $_ref;
+
+ /**
+ * External names
+ *
+ * @var array
+ */
+ private $_externalNames;
+
+ /**
+ * Defined names
+ *
+ * @var array
+ */
+ private $_definedname;
+
+ /**
+ * Shared strings. Only applies to BIFF8.
+ *
+ * @var array
+ */
+ private $_sst;
+
+ /**
+ * Panes are frozen? (in sheet currently being read). See WINDOW2 record.
+ *
+ * @var boolean
+ */
+ private $_frozen;
+
+ /**
+ * Fit printout to number of pages? (in sheet currently being read). See SHEETPR record.
+ *
+ * @var boolean
+ */
+ private $_isFitToPages;
+
+ /**
+ * Objects. One OBJ record contributes with one entry.
+ *
+ * @var array
+ */
+ private $_objs;
+
+ /**
+ * Text Objects. One TXO record corresponds with one entry.
+ *
+ * @var array
+ */
+ private $_textObjects;
+
+ /**
+ * Cell Annotations (BIFF8)
+ *
+ * @var array
+ */
+ private $_cellNotes;
+
+ /**
+ * The combined MSODRAWINGGROUP data
+ *
+ * @var string
+ */
+ private $_drawingGroupData;
+
+ /**
+ * The combined MSODRAWING data (per sheet)
+ *
+ * @var string
+ */
+ private $_drawingData;
+
+ /**
+ * Keep track of XF index
+ *
+ * @var int
+ */
+ private $_xfIndex;
+
+ /**
+ * Mapping of XF index (that is a cell XF) to final index in cellXf collection
+ *
+ * @var array
+ */
+ private $_mapCellXfIndex;
+
+ /**
+ * Mapping of XF index (that is a style XF) to final index in cellStyleXf collection
+ *
+ * @var array
+ */
+ private $_mapCellStyleXfIndex;
+
+ /**
+ * The shared formulas in a sheet. One SHAREDFMLA record contributes with one value.
+ *
+ * @var array
+ */
+ private $_sharedFormulas;
+
+ /**
+ * The shared formula parts in a sheet. One FORMULA record contributes with one value if it
+ * refers to a shared formula.
+ *
+ * @var array
+ */
+ private $_sharedFormulaParts;
+
+
+ /**
+ * Create a new PHPExcel_Reader_Excel5 instance
+ */
+ public function __construct() {
+ $this->_readFilter = new PHPExcel_Reader_DefaultReadFilter();
+ }
+
+
+ /**
+ * Read data only?
+ * If this is true, then the Reader will only read data values for cells, it will not read any formatting information.
+ * If false (the default) it will read data and formatting.
+ *
+ * @return boolean
+ */
+ public function getReadDataOnly()
+ {
+ return $this->_readDataOnly;
+ }
+
+
+ /**
+ * Set read data only
+ * Set to true, to advise the Reader only to read data values for cells, and to ignore any formatting information.
+ * Set to false (the default) to advise the Reader to read both data and formatting for cells.
+ *
+ * @param boolean $pValue
+ *
+ * @return PHPExcel_Reader_Excel5
+ */
+ public function setReadDataOnly($pValue = false)
+ {
+ $this->_readDataOnly = $pValue;
+ return $this;
+ }
+
+
+ /**
+ * Get which sheets to load
+ * Returns either an array of worksheet names (the list of worksheets that should be loaded), or a null
+ * indicating that all worksheets in the workbook should be loaded.
+ *
+ * @return mixed
+ */
+ public function getLoadSheetsOnly()
+ {
+ return $this->_loadSheetsOnly;
+ }
+
+
+ /**
+ * Set which sheets to load
+ *
+ * @param mixed $value
+ * This should be either an array of worksheet names to be loaded, or a string containing a single worksheet name.
+ * If NULL, then it tells the Reader to read all worksheets in the workbook
+ *
+ * @return PHPExcel_Reader_Excel5
+ */
+ public function setLoadSheetsOnly($value = null)
+ {
+ $this->_loadSheetsOnly = is_array($value) ?
+ $value : array($value);
+ return $this;
+ }
+
+
+ /**
+ * Set all sheets to load
+ * Tells the Reader to load all worksheets from the workbook.
+ *
+ * @return PHPExcel_Reader_Excel5
+ */
+ 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_Excel5
+ */
+ public function setReadFilter(PHPExcel_Reader_IReadFilter $pValue) {
+ $this->_readFilter = $pValue;
+ return $this;
+ }
+
+
+ /**
+ * Can the current PHPExcel_Reader_IReader read the file?
+ *
+ * @param string $pFileName
+ * @return boolean
+ * @throws Exception
+ */
+ 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.");
+ }
+
+ try {
+ // Use ParseXL for the hard work.
+ $ole = new PHPExcel_Shared_OLERead();
+
+ // get excel data
+ $res = $ole->read($pFilename);
+ return true;
+
+ } catch (Exception $e) {
+ return false;
+ }
+ }
+
+
+ /**
+ * Reads names of the worksheets from a file, without parsing the whole file to a PHPExcel object
+ *
+ * @param string $pFilename
+ * @throws Exception
+ */
+ public function listWorksheetNames($pFilename)
+ {
+ // Check if file exists
+ if (!file_exists($pFilename)) {
+ throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
+ }
+
+ $worksheetNames = array();
+
+ // Read the OLE file
+ $this->_loadOLE($pFilename);
+
+ // total byte size of Excel data (workbook global substream + sheet substreams)
+ $this->_dataSize = strlen($this->_data);
+
+ $this->_pos = 0;
+ $this->_sheets = array();
+
+ // Parse Workbook Global Substream
+ while ($this->_pos < $this->_dataSize) {
+ $code = self::_GetInt2d($this->_data, $this->_pos);
+
+ switch ($code) {
+ case self::XLS_Type_BOF: $this->_readBof(); break;
+ case self::XLS_Type_SHEET: $this->_readSheet(); break;
+ case self::XLS_Type_EOF: $this->_readDefault(); break 2;
+ default: $this->_readDefault(); break;
+ }
+ }
+
+ foreach ($this->_sheets as $sheet) {
+ if ($sheet['sheetType'] != 0x00) {
+ // 0x00: Worksheet, 0x02: Chart, 0x06: Visual Basic module
+ continue;
+ }
+
+ $worksheetNames[] = $sheet['name'];
+ }
+
+ return $worksheetNames;
+ }
+
+
+ /**
+ * Return worksheet info (Name, Last Column Letter, Last Column Index, Total Rows, Total Columns)
+ *
+ * @param string $pFilename
+ * @throws Exception
+ */
+ public function listWorksheetInfo($pFilename)
+ {
+ // Check if file exists
+ if (!file_exists($pFilename)) {
+ throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
+ }
+
+ $worksheetInfo = array();
+
+ // Read the OLE file
+ $this->_loadOLE($pFilename);
+
+ // total byte size of Excel data (workbook global substream + sheet substreams)
+ $this->_dataSize = strlen($this->_data);
+
+ // initialize
+ $this->_pos = 0;
+ $this->_sheets = array();
+
+ // Parse Workbook Global Substream
+ while ($this->_pos < $this->_dataSize) {
+ $code = self::_GetInt2d($this->_data, $this->_pos);
+
+ switch ($code) {
+ case self::XLS_Type_BOF: $this->_readBof(); break;
+ case self::XLS_Type_SHEET: $this->_readSheet(); break;
+ case self::XLS_Type_EOF: $this->_readDefault(); break 2;
+ default: $this->_readDefault(); break;
+ }
+ }
+
+ // Parse the individual sheets
+ foreach ($this->_sheets as $sheet) {
+
+ if ($sheet['sheetType'] != 0x00) {
+ // 0x00: Worksheet
+ // 0x02: Chart
+ // 0x06: Visual Basic module
+ continue;
+ }
+
+ $tmpInfo = array();
+ $tmpInfo['worksheetName'] = $sheet['name'];
+ $tmpInfo['lastColumnLetter'] = 'A';
+ $tmpInfo['lastColumnIndex'] = 0;
+ $tmpInfo['totalRows'] = 0;
+ $tmpInfo['totalColumns'] = 0;
+
+ $this->_pos = $sheet['offset'];
+
+ while ($this->_pos <= $this->_dataSize - 4) {
+ $code = self::_GetInt2d($this->_data, $this->_pos);
+
+ switch ($code) {
+ case self::XLS_Type_RK:
+ case self::XLS_Type_LABELSST:
+ case self::XLS_Type_NUMBER:
+ case self::XLS_Type_FORMULA:
+ case self::XLS_Type_BOOLERR:
+ case self::XLS_Type_LABEL:
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ $rowIndex = self::_GetInt2d($recordData, 0) + 1;
+ $columnIndex = self::_GetInt2d($recordData, 2);
+
+ $tmpInfo['totalRows'] = max($tmpInfo['totalRows'], $rowIndex);
+ $tmpInfo['lastColumnIndex'] = max($tmpInfo['lastColumnIndex'], $columnIndex);
+ break;
+ case self::XLS_Type_BOF: $this->_readBof(); break;
+ case self::XLS_Type_EOF: $this->_readDefault(); break 2;
+ default: $this->_readDefault(); break;
+ }
+ }
+
+ $tmpInfo['lastColumnLetter'] = PHPExcel_Cell::stringFromColumnIndex($tmpInfo['lastColumnIndex']);
+ $tmpInfo['totalColumns'] = $tmpInfo['lastColumnIndex'] + 1;
+
+ $worksheetInfo[] = $tmpInfo;
+ }
+
+ return $worksheetInfo;
+ }
+
+
+ /**
+ * Loads PHPExcel from file
+ *
+ * @param string $pFilename
+ * @return PHPExcel
+ * @throws Exception
+ */
+ public function load($pFilename)
+ {
+ // Read the OLE file
+ $this->_loadOLE($pFilename);
+
+ // Initialisations
+ $this->_phpExcel = new PHPExcel;
+ $this->_phpExcel->removeSheetByIndex(0); // remove 1st sheet
+ if (!$this->_readDataOnly) {
+ $this->_phpExcel->removeCellStyleXfByIndex(0); // remove the default style
+ $this->_phpExcel->removeCellXfByIndex(0); // remove the default style
+ }
+
+ // Read the summary information stream (containing meta data)
+ $this->_readSummaryInformation();
+
+ // Read the Additional document summary information stream (containing application-specific meta data)
+ $this->_readDocumentSummaryInformation();
+
+ // total byte size of Excel data (workbook global substream + sheet substreams)
+ $this->_dataSize = strlen($this->_data);
+
+ // initialize
+ $this->_pos = 0;
+ $this->_codepage = 'CP1252';
+ $this->_formats = array();
+ $this->_objFonts = array();
+ $this->_palette = array();
+ $this->_sheets = array();
+ $this->_externalBooks = array();
+ $this->_ref = array();
+ $this->_definedname = array();
+ $this->_sst = array();
+ $this->_drawingGroupData = '';
+ $this->_xfIndex = '';
+ $this->_mapCellXfIndex = array();
+ $this->_mapCellStyleXfIndex = array();
+
+ // Parse Workbook Global Substream
+ while ($this->_pos < $this->_dataSize) {
+ $code = self::_GetInt2d($this->_data, $this->_pos);
+
+ switch ($code) {
+ case self::XLS_Type_BOF: $this->_readBof(); break;
+ case self::XLS_Type_FILEPASS: $this->_readFilepass(); break;
+ case self::XLS_Type_CODEPAGE: $this->_readCodepage(); break;
+ case self::XLS_Type_DATEMODE: $this->_readDateMode(); break;
+ case self::XLS_Type_FONT: $this->_readFont(); break;
+ case self::XLS_Type_FORMAT: $this->_readFormat(); break;
+ case self::XLS_Type_XF: $this->_readXf(); break;
+ case self::XLS_Type_XFEXT: $this->_readXfExt(); break;
+ case self::XLS_Type_STYLE: $this->_readStyle(); break;
+ case self::XLS_Type_PALETTE: $this->_readPalette(); break;
+ case self::XLS_Type_SHEET: $this->_readSheet(); break;
+ case self::XLS_Type_EXTERNALBOOK: $this->_readExternalBook(); break;
+ case self::XLS_Type_EXTERNNAME: $this->_readExternName(); break;
+ case self::XLS_Type_EXTERNSHEET: $this->_readExternSheet(); break;
+ case self::XLS_Type_DEFINEDNAME: $this->_readDefinedName(); break;
+ case self::XLS_Type_MSODRAWINGGROUP: $this->_readMsoDrawingGroup(); break;
+ case self::XLS_Type_SST: $this->_readSst(); break;
+ case self::XLS_Type_EOF: $this->_readDefault(); break 2;
+ default: $this->_readDefault(); break;
+ }
+ }
+
+ // Resolve indexed colors for font, fill, and border colors
+ // Cannot be resolved already in XF record, because PALETTE record comes afterwards
+ if (!$this->_readDataOnly) {
+ foreach ($this->_objFonts as $objFont) {
+ if (isset($objFont->colorIndex)) {
+ $color = self::_readColor($objFont->colorIndex,$this->_palette,$this->_version);
+ $objFont->getColor()->setRGB($color['rgb']);
+ }
+ }
+
+ foreach ($this->_phpExcel->getCellXfCollection() as $objStyle) {
+ // fill start and end color
+ $fill = $objStyle->getFill();
+
+ if (isset($fill->startcolorIndex)) {
+ $startColor = self::_readColor($fill->startcolorIndex,$this->_palette,$this->_version);
+ $fill->getStartColor()->setRGB($startColor['rgb']);
+ }
+
+ if (isset($fill->endcolorIndex)) {
+ $endColor = self::_readColor($fill->endcolorIndex,$this->_palette,$this->_version);
+ $fill->getEndColor()->setRGB($endColor['rgb']);
+ }
+
+ // border colors
+ $top = $objStyle->getBorders()->getTop();
+ $right = $objStyle->getBorders()->getRight();
+ $bottom = $objStyle->getBorders()->getBottom();
+ $left = $objStyle->getBorders()->getLeft();
+ $diagonal = $objStyle->getBorders()->getDiagonal();
+
+ if (isset($top->colorIndex)) {
+ $borderTopColor = self::_readColor($top->colorIndex,$this->_palette,$this->_version);
+ $top->getColor()->setRGB($borderTopColor['rgb']);
+ }
+
+ if (isset($right->colorIndex)) {
+ $borderRightColor = self::_readColor($right->colorIndex,$this->_palette,$this->_version);
+ $right->getColor()->setRGB($borderRightColor['rgb']);
+ }
+
+ if (isset($bottom->colorIndex)) {
+ $borderBottomColor = self::_readColor($bottom->colorIndex,$this->_palette,$this->_version);
+ $bottom->getColor()->setRGB($borderBottomColor['rgb']);
+ }
+
+ if (isset($left->colorIndex)) {
+ $borderLeftColor = self::_readColor($left->colorIndex,$this->_palette,$this->_version);
+ $left->getColor()->setRGB($borderLeftColor['rgb']);
+ }
+
+ if (isset($diagonal->colorIndex)) {
+ $borderDiagonalColor = self::_readColor($diagonal->colorIndex,$this->_palette,$this->_version);
+ $diagonal->getColor()->setRGB($borderDiagonalColor['rgb']);
+ }
+ }
+ }
+
+ // treat MSODRAWINGGROUP records, workbook-level Escher
+ if (!$this->_readDataOnly && $this->_drawingGroupData) {
+ $escherWorkbook = new PHPExcel_Shared_Escher();
+ $reader = new PHPExcel_Reader_Excel5_Escher($escherWorkbook);
+ $escherWorkbook = $reader->load($this->_drawingGroupData);
+
+ // debug Escher stream
+ //$debug = new Debug_Escher(new PHPExcel_Shared_Escher());
+ //$debug->load($this->_drawingGroupData);
+ }
+
+ // Parse the individual sheets
+ foreach ($this->_sheets as $sheet) {
+
+ if ($sheet['sheetType'] != 0x00) {
+ // 0x00: Worksheet, 0x02: Chart, 0x06: Visual Basic module
+ continue;
+ }
+
+ // check if sheet should be skipped
+ if (isset($this->_loadSheetsOnly) && !in_array($sheet['name'], $this->_loadSheetsOnly)) {
+ continue;
+ }
+
+ // add sheet to PHPExcel object
+ $this->_phpSheet = $this->_phpExcel->createSheet();
+ // Use false for $updateFormulaCellReferences to prevent adjustment of worksheet references in formula
+ // cells... during the load, all formulae should be correct, and we're simply bringing the worksheet
+ // name in line with the formula, not the reverse
+ $this->_phpSheet->setTitle($sheet['name'],false);
+ $this->_phpSheet->setSheetState($sheet['sheetState']);
+
+ $this->_pos = $sheet['offset'];
+
+ // Initialize isFitToPages. May change after reading SHEETPR record.
+ $this->_isFitToPages = false;
+
+ // Initialize drawingData
+ $this->_drawingData = '';
+
+ // Initialize objs
+ $this->_objs = array();
+
+ // Initialize shared formula parts
+ $this->_sharedFormulaParts = array();
+
+ // Initialize shared formulas
+ $this->_sharedFormulas = array();
+
+ // Initialize text objs
+ $this->_textObjects = array();
+
+ // Initialize cell annotations
+ $this->_cellNotes = array();
+ $this->textObjRef = -1;
+
+ while ($this->_pos <= $this->_dataSize - 4) {
+ $code = self::_GetInt2d($this->_data, $this->_pos);
+
+ switch ($code) {
+ case self::XLS_Type_BOF: $this->_readBof(); break;
+ case self::XLS_Type_PRINTGRIDLINES: $this->_readPrintGridlines(); break;
+ case self::XLS_Type_DEFAULTROWHEIGHT: $this->_readDefaultRowHeight(); break;
+ case self::XLS_Type_SHEETPR: $this->_readSheetPr(); break;
+ case self::XLS_Type_HORIZONTALPAGEBREAKS: $this->_readHorizontalPageBreaks(); break;
+ case self::XLS_Type_VERTICALPAGEBREAKS: $this->_readVerticalPageBreaks(); break;
+ case self::XLS_Type_HEADER: $this->_readHeader(); break;
+ case self::XLS_Type_FOOTER: $this->_readFooter(); break;
+ case self::XLS_Type_HCENTER: $this->_readHcenter(); break;
+ case self::XLS_Type_VCENTER: $this->_readVcenter(); break;
+ case self::XLS_Type_LEFTMARGIN: $this->_readLeftMargin(); break;
+ case self::XLS_Type_RIGHTMARGIN: $this->_readRightMargin(); break;
+ case self::XLS_Type_TOPMARGIN: $this->_readTopMargin(); break;
+ case self::XLS_Type_BOTTOMMARGIN: $this->_readBottomMargin(); break;
+ case self::XLS_Type_PAGESETUP: $this->_readPageSetup(); break;
+ case self::XLS_Type_PROTECT: $this->_readProtect(); break;
+ case self::XLS_Type_SCENPROTECT: $this->_readScenProtect(); break;
+ case self::XLS_Type_OBJECTPROTECT: $this->_readObjectProtect(); break;
+ case self::XLS_Type_PASSWORD: $this->_readPassword(); break;
+ case self::XLS_Type_DEFCOLWIDTH: $this->_readDefColWidth(); break;
+ case self::XLS_Type_COLINFO: $this->_readColInfo(); break;
+ case self::XLS_Type_DIMENSION: $this->_readDefault(); break;
+ case self::XLS_Type_ROW: $this->_readRow(); break;
+ case self::XLS_Type_DBCELL: $this->_readDefault(); break;
+ case self::XLS_Type_RK: $this->_readRk(); break;
+ case self::XLS_Type_LABELSST: $this->_readLabelSst(); break;
+ case self::XLS_Type_MULRK: $this->_readMulRk(); break;
+ case self::XLS_Type_NUMBER: $this->_readNumber(); break;
+ case self::XLS_Type_FORMULA: $this->_readFormula(); break;
+ case self::XLS_Type_SHAREDFMLA: $this->_readSharedFmla(); break;
+ case self::XLS_Type_BOOLERR: $this->_readBoolErr(); break;
+ case self::XLS_Type_MULBLANK: $this->_readMulBlank(); break;
+ case self::XLS_Type_LABEL: $this->_readLabel(); break;
+ case self::XLS_Type_BLANK: $this->_readBlank(); break;
+ case self::XLS_Type_MSODRAWING: $this->_readMsoDrawing(); break;
+ case self::XLS_Type_OBJ: $this->_readObj(); break;
+ case self::XLS_Type_WINDOW2: $this->_readWindow2(); break;
+ case self::XLS_Type_SCL: $this->_readScl(); break;
+ case self::XLS_Type_PANE: $this->_readPane(); break;
+ case self::XLS_Type_SELECTION: $this->_readSelection(); break;
+ case self::XLS_Type_MERGEDCELLS: $this->_readMergedCells(); break;
+ case self::XLS_Type_HYPERLINK: $this->_readHyperLink(); break;
+ case self::XLS_Type_DATAVALIDATIONS: $this->_readDataValidations(); break;
+ case self::XLS_Type_DATAVALIDATION: $this->_readDataValidation(); break;
+ case self::XLS_Type_SHEETLAYOUT: $this->_readSheetLayout(); break;
+ case self::XLS_Type_SHEETPROTECTION: $this->_readSheetProtection(); break;
+ case self::XLS_Type_RANGEPROTECTION: $this->_readRangeProtection(); break;
+ case self::XLS_Type_NOTE: $this->_readNote(); break;
+ //case self::XLS_Type_IMDATA: $this->_readImData(); break;
+ case self::XLS_Type_TXO: $this->_readTextObject(); break;
+ case self::XLS_Type_CONTINUE: $this->_readContinue(); break;
+ case self::XLS_Type_EOF: $this->_readDefault(); break 2;
+ default: $this->_readDefault(); break;
+ }
+
+ }
+
+ // treat MSODRAWING records, sheet-level Escher
+ if (!$this->_readDataOnly && $this->_drawingData) {
+ $escherWorksheet = new PHPExcel_Shared_Escher();
+ $reader = new PHPExcel_Reader_Excel5_Escher($escherWorksheet);
+ $escherWorksheet = $reader->load($this->_drawingData);
+
+ // debug Escher stream
+ //$debug = new Debug_Escher(new PHPExcel_Shared_Escher());
+ //$debug->load($this->_drawingData);
+
+ // get all spContainers in one long array, so they can be mapped to OBJ records
+ $allSpContainers = $escherWorksheet->getDgContainer()->getSpgrContainer()->getAllSpContainers();
+ }
+
+ // treat OBJ records
+ foreach ($this->_objs as $n => $obj) {
+// echo '
Object reference is ',$n,'
';
+// var_dump($obj);
+// echo '
';
+
+ // the first shape container never has a corresponding OBJ record, hence $n + 1
+ if (isset($allSpContainers[$n + 1]) && is_object($allSpContainers[$n + 1])) {
+ $spContainer = $allSpContainers[$n + 1];
+
+ // we skip all spContainers that are a part of a group shape since we cannot yet handle those
+ if ($spContainer->getNestingLevel() > 1) {
+ continue;
+ }
+
+ // calculate the width and height of the shape
+ list($startColumn, $startRow) = PHPExcel_Cell::coordinateFromString($spContainer->getStartCoordinates());
+ list($endColumn, $endRow) = PHPExcel_Cell::coordinateFromString($spContainer->getEndCoordinates());
+
+ $startOffsetX = $spContainer->getStartOffsetX();
+ $startOffsetY = $spContainer->getStartOffsetY();
+ $endOffsetX = $spContainer->getEndOffsetX();
+ $endOffsetY = $spContainer->getEndOffsetY();
+
+ $width = PHPExcel_Shared_Excel5::getDistanceX($this->_phpSheet, $startColumn, $startOffsetX, $endColumn, $endOffsetX);
+ $height = PHPExcel_Shared_Excel5::getDistanceY($this->_phpSheet, $startRow, $startOffsetY, $endRow, $endOffsetY);
+
+ // calculate offsetX and offsetY of the shape
+ $offsetX = $startOffsetX * PHPExcel_Shared_Excel5::sizeCol($this->_phpSheet, $startColumn) / 1024;
+ $offsetY = $startOffsetY * PHPExcel_Shared_Excel5::sizeRow($this->_phpSheet, $startRow) / 256;
+
+ switch ($obj['otObjType']) {
+ case 0x19:
+ // Note
+// echo 'Cell Annotation Object
';
+// echo 'Object ID is ',$obj['idObjID'],'
';
+//
+ if (isset($this->_cellNotes[$obj['idObjID']])) {
+ $cellNote = $this->_cellNotes[$obj['idObjID']];
+
+ if (isset($this->_textObjects[$obj['idObjID']])) {
+ $textObject = $this->_textObjects[$obj['idObjID']];
+ $this->_cellNotes[$obj['idObjID']]['objTextData'] = $textObject;
+ }
+ }
+ break;
+
+ case 0x08:
+// echo 'Picture Object
';
+ // picture
+
+ // get index to BSE entry (1-based)
+ $BSEindex = $spContainer->getOPT(0x0104);
+ $BSECollection = $escherWorkbook->getDggContainer()->getBstoreContainer()->getBSECollection();
+ $BSE = $BSECollection[$BSEindex - 1];
+ $blipType = $BSE->getBlipType();
+
+ // need check because some blip types are not supported by Escher reader such as EMF
+ if ($blip = $BSE->getBlip()) {
+ $ih = imagecreatefromstring($blip->getData());
+ $drawing = new PHPExcel_Worksheet_MemoryDrawing();
+ $drawing->setImageResource($ih);
+
+ // width, height, offsetX, offsetY
+ $drawing->setResizeProportional(false);
+ $drawing->setWidth($width);
+ $drawing->setHeight($height);
+ $drawing->setOffsetX($offsetX);
+ $drawing->setOffsetY($offsetY);
+
+ switch ($blipType) {
+ case PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE::BLIPTYPE_JPEG:
+ $drawing->setRenderingFunction(PHPExcel_Worksheet_MemoryDrawing::RENDERING_JPEG);
+ $drawing->setMimeType(PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_JPEG);
+ break;
+
+ case PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE::BLIPTYPE_PNG:
+ $drawing->setRenderingFunction(PHPExcel_Worksheet_MemoryDrawing::RENDERING_PNG);
+ $drawing->setMimeType(PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_PNG);
+ break;
+ }
+
+ $drawing->setWorksheet($this->_phpSheet);
+ $drawing->setCoordinates($spContainer->getStartCoordinates());
+ }
+
+ break;
+
+ default:
+ // other object type
+ break;
+
+ }
+ }
+ }
+
+ // treat SHAREDFMLA records
+ if ($this->_version == self::XLS_BIFF8) {
+ foreach ($this->_sharedFormulaParts as $cell => $baseCell) {
+ list($column, $row) = PHPExcel_Cell::coordinateFromString($cell);
+ if (($this->getReadFilter() !== NULL) && $this->getReadFilter()->readCell($column, $row, $this->_phpSheet->getTitle()) ) {
+ $formula = $this->_getFormulaFromStructure($this->_sharedFormulas[$baseCell], $cell);
+ $this->_phpSheet->getCell($cell)->setValueExplicit('=' . $formula, PHPExcel_Cell_DataType::TYPE_FORMULA);
+ }
+ }
+ }
+
+ if (!empty($this->_cellNotes)) {
+ foreach($this->_cellNotes as $note => $noteDetails) {
+ if (!isset($noteDetails['objTextData'])) {
+ if (isset($this->_textObjects[$note])) {
+ $textObject = $this->_textObjects[$note];
+ $noteDetails['objTextData'] = $textObject;
+ } else {
+ $noteDetails['objTextData']['text'] = '';
+ }
+ }
+// echo 'Cell annotation ',$note,'
';
+// var_dump($noteDetails);
+// echo '
';
+ $cellAddress = str_replace('$','',$noteDetails['cellRef']);
+ $this->_phpSheet->getComment( $cellAddress )
+ ->setAuthor( $noteDetails['author'] )
+ ->setText($this->_parseRichText($noteDetails['objTextData']['text']) );
+ }
+ }
+ }
+
+ // add the named ranges (defined names)
+ foreach ($this->_definedname as $definedName) {
+ if ($definedName['isBuiltInName']) {
+ switch ($definedName['name']) {
+
+ case pack('C', 0x06):
+ // print area
+ // in general, formula looks like this: Foo!$C$7:$J$66,Bar!$A$1:$IV$2
+
+ $ranges = explode(',', $definedName['formula']); // FIXME: what if sheetname contains comma?
+
+ $extractedRanges = array();
+ foreach ($ranges as $range) {
+ // $range should look like one of these
+ // Foo!$C$7:$J$66
+ // Bar!$A$1:$IV$2
+
+ $explodes = explode('!', $range); // FIXME: what if sheetname contains exclamation mark?
+ $sheetName = $explodes[0];
+
+ if (count($explodes) == 2) {
+ $extractedRanges[] = str_replace('$', '', $explodes[1]); // C7:J66
+ }
+ }
+ if ($docSheet = $this->_phpExcel->getSheetByName($sheetName)) {
+ $docSheet->getPageSetup()->setPrintArea(implode(',', $extractedRanges)); // C7:J66,A1:IV2
+ }
+ break;
+
+ case pack('C', 0x07):
+ // print titles (repeating rows)
+ // Assuming BIFF8, there are 3 cases
+ // 1. repeating rows
+ // formula looks like this: Sheet!$A$1:$IV$2
+ // rows 1-2 repeat
+ // 2. repeating columns
+ // formula looks like this: Sheet!$A$1:$B$65536
+ // columns A-B repeat
+ // 3. both repeating rows and repeating columns
+ // formula looks like this: Sheet!$A$1:$B$65536,Sheet!$A$1:$IV$2
+
+ $ranges = explode(',', $definedName['formula']); // FIXME: what if sheetname contains comma?
+
+ foreach ($ranges as $range) {
+ // $range should look like this one of these
+ // Sheet!$A$1:$B$65536
+ // Sheet!$A$1:$IV$2
+
+ $explodes = explode('!', $range);
+
+ if (count($explodes) == 2) {
+ if ($docSheet = $this->_phpExcel->getSheetByName($explodes[0])) {
+
+ $extractedRange = $explodes[1];
+ $extractedRange = str_replace('$', '', $extractedRange);
+
+ $coordinateStrings = explode(':', $extractedRange);
+ if (count($coordinateStrings) == 2) {
+ list($firstColumn, $firstRow) = PHPExcel_Cell::coordinateFromString($coordinateStrings[0]);
+ list($lastColumn, $lastRow) = PHPExcel_Cell::coordinateFromString($coordinateStrings[1]);
+
+ if ($firstColumn == 'A' and $lastColumn == 'IV') {
+ // then we have repeating rows
+ $docSheet->getPageSetup()->setRowsToRepeatAtTop(array($firstRow, $lastRow));
+ } elseif ($firstRow == 1 and $lastRow == 65536) {
+ // then we have repeating columns
+ $docSheet->getPageSetup()->setColumnsToRepeatAtLeft(array($firstColumn, $lastColumn));
+ }
+ }
+ }
+ }
+ }
+ break;
+
+ }
+ } else {
+ // Extract range
+ $explodes = explode('!', $definedName['formula']);
+
+ if (count($explodes) == 2) {
+ if (($docSheet = $this->_phpExcel->getSheetByName($explodes[0])) ||
+ ($docSheet = $this->_phpExcel->getSheetByName(trim($explodes[0],"'")))) {
+ $extractedRange = $explodes[1];
+ $extractedRange = str_replace('$', '', $extractedRange);
+
+ $localOnly = ($definedName['scope'] == 0) ? false : true;
+
+ $scope = ($definedName['scope'] == 0) ?
+ null : $this->_phpExcel->getSheetByName($this->_sheets[$definedName['scope'] - 1]['name']);
+
+ $this->_phpExcel->addNamedRange( new PHPExcel_NamedRange((string)$definedName['name'], $docSheet, $extractedRange, $localOnly, $scope) );
+ }
+ } else {
+ // Named Value
+ // TODO Provide support for named values
+ }
+ }
+ }
+
+ return $this->_phpExcel;
+ }
+
+
+ /**
+ * Use OLE reader to extract the relevant data streams from the OLE file
+ *
+ * @param string $pFilename
+ */
+ private function _loadOLE($pFilename)
+ {
+ // OLE reader
+ $ole = new PHPExcel_Shared_OLERead();
+
+ // get excel data,
+ $res = $ole->read($pFilename);
+ // Get workbook data: workbook stream + sheet streams
+ $this->_data = $ole->getStream($ole->wrkbook);
+
+ // Get summary information data
+ $this->_summaryInformation = $ole->getStream($ole->summaryInformation);
+
+ // Get additional document summary information data
+ $this->_documentSummaryInformation = $ole->getStream($ole->documentSummaryInformation);
+
+ // Get user-defined property data
+// $this->_userDefinedProperties = $ole->getUserDefinedProperties();
+ }
+
+
+ /**
+ * Read summary information
+ */
+ private function _readSummaryInformation()
+ {
+ if (!isset($this->_summaryInformation)) {
+ return;
+ }
+
+ // offset: 0; size: 2; must be 0xFE 0xFF (UTF-16 LE byte order mark)
+ // offset: 2; size: 2;
+ // offset: 4; size: 2; OS version
+ // offset: 6; size: 2; OS indicator
+ // offset: 8; size: 16
+ // offset: 24; size: 4; section count
+ $secCount = self::_GetInt4d($this->_summaryInformation, 24);
+
+ // offset: 28; size: 16; first section's class id: e0 85 9f f2 f9 4f 68 10 ab 91 08 00 2b 27 b3 d9
+ // offset: 44; size: 4
+ $secOffset = self::_GetInt4d($this->_summaryInformation, 44);
+
+ // section header
+ // offset: $secOffset; size: 4; section length
+ $secLength = self::_GetInt4d($this->_summaryInformation, $secOffset);
+
+ // offset: $secOffset+4; size: 4; property count
+ $countProperties = self::_GetInt4d($this->_summaryInformation, $secOffset+4);
+
+ // initialize code page (used to resolve string values)
+ $codePage = 'CP1252';
+
+ // offset: ($secOffset+8); size: var
+ // loop through property decarations and properties
+ for ($i = 0; $i < $countProperties; ++$i) {
+
+ // offset: ($secOffset+8) + (8 * $i); size: 4; property ID
+ $id = self::_GetInt4d($this->_summaryInformation, ($secOffset+8) + (8 * $i));
+
+ // Use value of property id as appropriate
+ // offset: ($secOffset+12) + (8 * $i); size: 4; offset from beginning of section (48)
+ $offset = self::_GetInt4d($this->_summaryInformation, ($secOffset+12) + (8 * $i));
+
+ $type = self::_GetInt4d($this->_summaryInformation, $secOffset + $offset);
+
+ // initialize property value
+ $value = null;
+
+ // extract property value based on property type
+ switch ($type) {
+ case 0x02: // 2 byte signed integer
+ $value = self::_GetInt2d($this->_summaryInformation, $secOffset + 4 + $offset);
+ break;
+
+ case 0x03: // 4 byte signed integer
+ $value = self::_GetInt4d($this->_summaryInformation, $secOffset + 4 + $offset);
+ break;
+
+ case 0x13: // 4 byte unsigned integer
+ // not needed yet, fix later if necessary
+ break;
+
+ case 0x1E: // null-terminated string prepended by dword string length
+ $byteLength = self::_GetInt4d($this->_summaryInformation, $secOffset + 4 + $offset);
+ $value = substr($this->_summaryInformation, $secOffset + 8 + $offset, $byteLength);
+ $value = PHPExcel_Shared_String::ConvertEncoding($value, 'UTF-8', $codePage);
+ $value = rtrim($value);
+ break;
+
+ case 0x40: // Filetime (64-bit value representing the number of 100-nanosecond intervals since January 1, 1601)
+ // PHP-time
+ $value = PHPExcel_Shared_OLE::OLE2LocalDate(substr($this->_summaryInformation, $secOffset + 4 + $offset, 8));
+ break;
+
+ case 0x47: // Clipboard format
+ // not needed yet, fix later if necessary
+ break;
+ }
+
+ switch ($id) {
+ case 0x01: // Code Page
+ $codePage = PHPExcel_Shared_CodePage::NumberToName($value);
+ break;
+
+ case 0x02: // Title
+ $this->_phpExcel->getProperties()->setTitle($value);
+ break;
+
+ case 0x03: // Subject
+ $this->_phpExcel->getProperties()->setSubject($value);
+ break;
+
+ case 0x04: // Author (Creator)
+ $this->_phpExcel->getProperties()->setCreator($value);
+ break;
+
+ case 0x05: // Keywords
+ $this->_phpExcel->getProperties()->setKeywords($value);
+ break;
+
+ case 0x06: // Comments (Description)
+ $this->_phpExcel->getProperties()->setDescription($value);
+ break;
+
+ case 0x07: // Template
+ // Not supported by PHPExcel
+ break;
+
+ case 0x08: // Last Saved By (LastModifiedBy)
+ $this->_phpExcel->getProperties()->setLastModifiedBy($value);
+ break;
+
+ case 0x09: // Revision
+ // Not supported by PHPExcel
+ break;
+
+ case 0x0A: // Total Editing Time
+ // Not supported by PHPExcel
+ break;
+
+ case 0x0B: // Last Printed
+ // Not supported by PHPExcel
+ break;
+
+ case 0x0C: // Created Date/Time
+ $this->_phpExcel->getProperties()->setCreated($value);
+ break;
+
+ case 0x0D: // Modified Date/Time
+ $this->_phpExcel->getProperties()->setModified($value);
+ break;
+
+ case 0x0E: // Number of Pages
+ // Not supported by PHPExcel
+ break;
+
+ case 0x0F: // Number of Words
+ // Not supported by PHPExcel
+ break;
+
+ case 0x10: // Number of Characters
+ // Not supported by PHPExcel
+ break;
+
+ case 0x11: // Thumbnail
+ // Not supported by PHPExcel
+ break;
+
+ case 0x12: // Name of creating application
+ // Not supported by PHPExcel
+ break;
+
+ case 0x13: // Security
+ // Not supported by PHPExcel
+ break;
+
+ }
+ }
+ }
+
+
+ /**
+ * Read additional document summary information
+ */
+ private function _readDocumentSummaryInformation()
+ {
+ if (!isset($this->_documentSummaryInformation)) {
+ return;
+ }
+
+ // offset: 0; size: 2; must be 0xFE 0xFF (UTF-16 LE byte order mark)
+ // offset: 2; size: 2;
+ // offset: 4; size: 2; OS version
+ // offset: 6; size: 2; OS indicator
+ // offset: 8; size: 16
+ // offset: 24; size: 4; section count
+ $secCount = self::_GetInt4d($this->_documentSummaryInformation, 24);
+// echo '$secCount = ',$secCount,'
';
+
+ // offset: 28; size: 16; first section's class id: 02 d5 cd d5 9c 2e 1b 10 93 97 08 00 2b 2c f9 ae
+ // offset: 44; size: 4; first section offset
+ $secOffset = self::_GetInt4d($this->_documentSummaryInformation, 44);
+// echo '$secOffset = ',$secOffset,'
';
+
+ // section header
+ // offset: $secOffset; size: 4; section length
+ $secLength = self::_GetInt4d($this->_documentSummaryInformation, $secOffset);
+// echo '$secLength = ',$secLength,'
';
+
+ // offset: $secOffset+4; size: 4; property count
+ $countProperties = self::_GetInt4d($this->_documentSummaryInformation, $secOffset+4);
+// echo '$countProperties = ',$countProperties,'
';
+
+ // initialize code page (used to resolve string values)
+ $codePage = 'CP1252';
+
+ // offset: ($secOffset+8); size: var
+ // loop through property decarations and properties
+ for ($i = 0; $i < $countProperties; ++$i) {
+// echo 'Property ',$i,'
';
+ // offset: ($secOffset+8) + (8 * $i); size: 4; property ID
+ $id = self::_GetInt4d($this->_documentSummaryInformation, ($secOffset+8) + (8 * $i));
+// echo 'ID is ',$id,'
';
+
+ // Use value of property id as appropriate
+ // offset: 60 + 8 * $i; size: 4; offset from beginning of section (48)
+ $offset = self::_GetInt4d($this->_documentSummaryInformation, ($secOffset+12) + (8 * $i));
+
+ $type = self::_GetInt4d($this->_documentSummaryInformation, $secOffset + $offset);
+// echo 'Type is ',$type,', ';
+
+ // initialize property value
+ $value = null;
+
+ // extract property value based on property type
+ switch ($type) {
+ case 0x02: // 2 byte signed integer
+ $value = self::_GetInt2d($this->_documentSummaryInformation, $secOffset + 4 + $offset);
+ break;
+
+ case 0x03: // 4 byte signed integer
+ $value = self::_GetInt4d($this->_documentSummaryInformation, $secOffset + 4 + $offset);
+ break;
+
+ case 0x0B: // Boolean
+ $value = self::_GetInt2d($this->_documentSummaryInformation, $secOffset + 4 + $offset);
+ $value = ($value == 0 ? false : true);
+ break;
+
+ case 0x13: // 4 byte unsigned integer
+ // not needed yet, fix later if necessary
+ break;
+
+ case 0x1E: // null-terminated string prepended by dword string length
+ $byteLength = self::_GetInt4d($this->_documentSummaryInformation, $secOffset + 4 + $offset);
+ $value = substr($this->_documentSummaryInformation, $secOffset + 8 + $offset, $byteLength);
+ $value = PHPExcel_Shared_String::ConvertEncoding($value, 'UTF-8', $codePage);
+ $value = rtrim($value);
+ break;
+
+ case 0x40: // Filetime (64-bit value representing the number of 100-nanosecond intervals since January 1, 1601)
+ // PHP-Time
+ $value = PHPExcel_Shared_OLE::OLE2LocalDate(substr($this->_documentSummaryInformation, $secOffset + 4 + $offset, 8));
+ break;
+
+ case 0x47: // Clipboard format
+ // not needed yet, fix later if necessary
+ break;
+ }
+
+ switch ($id) {
+ case 0x01: // Code Page
+ $codePage = PHPExcel_Shared_CodePage::NumberToName($value);
+ break;
+
+ case 0x02: // Category
+ $this->_phpExcel->getProperties()->setCategory($value);
+ break;
+
+ case 0x03: // Presentation Target
+ // Not supported by PHPExcel
+ break;
+
+ case 0x04: // Bytes
+ // Not supported by PHPExcel
+ break;
+
+ case 0x05: // Lines
+ // Not supported by PHPExcel
+ break;
+
+ case 0x06: // Paragraphs
+ // Not supported by PHPExcel
+ break;
+
+ case 0x07: // Slides
+ // Not supported by PHPExcel
+ break;
+
+ case 0x08: // Notes
+ // Not supported by PHPExcel
+ break;
+
+ case 0x09: // Hidden Slides
+ // Not supported by PHPExcel
+ break;
+
+ case 0x0A: // MM Clips
+ // Not supported by PHPExcel
+ break;
+
+ case 0x0B: // Scale Crop
+ // Not supported by PHPExcel
+ break;
+
+ case 0x0C: // Heading Pairs
+ // Not supported by PHPExcel
+ break;
+
+ case 0x0D: // Titles of Parts
+ // Not supported by PHPExcel
+ break;
+
+ case 0x0E: // Manager
+ $this->_phpExcel->getProperties()->setManager($value);
+ break;
+
+ case 0x0F: // Company
+ $this->_phpExcel->getProperties()->setCompany($value);
+ break;
+
+ case 0x10: // Links up-to-date
+ // Not supported by PHPExcel
+ break;
+
+ }
+ }
+ }
+
+
+ /**
+ * Reads a general type of BIFF record. Does nothing except for moving stream pointer forward to next record.
+ */
+ private function _readDefault()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+// $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+ }
+
+
+ /**
+ * The NOTE record specifies a comment associated with a particular cell. In Excel 95 (BIFF7) and earlier versions,
+ * this record stores a note (cell note). This feature was significantly enhanced in Excel 97.
+ */
+ private function _readNote()
+ {
+// echo 'Read Cell Annotation
';
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ if ($this->_readDataOnly) {
+ return;
+ }
+
+ $cellAddress = $this->_readBIFF8CellAddress(substr($recordData, 0, 4));
+ if ($this->_version == self::XLS_BIFF8) {
+ $noteObjID = self::_GetInt2d($recordData, 6);
+ $noteAuthor = self::_readUnicodeStringLong(substr($recordData, 8));
+ $noteAuthor = $noteAuthor['value'];
+// echo 'Note Address=',$cellAddress,'
';
+// echo 'Note Object ID=',$noteObjID,'
';
+// echo 'Note Author=',$noteAuthor,'
';
+//
+ $this->_cellNotes[$noteObjID] = array('cellRef' => $cellAddress,
+ 'objectID' => $noteObjID,
+ 'author' => $noteAuthor
+ );
+ } else {
+ $extension = false;
+ if ($cellAddress == '$B$65536') {
+ // If the address row is -1 and the column is 0, (which translates as $B$65536) then this is a continuation
+ // note from the previous cell annotation. We're not yet handling this, so annotations longer than the
+ // max 2048 bytes will probably throw a wobbly.
+ $row = self::_GetInt2d($recordData, 0);
+ $extension = true;
+ $cellAddress = array_pop(array_keys($this->_phpSheet->getComments()));
+ }
+// echo 'Note Address=',$cellAddress,'
';
+
+ $cellAddress = str_replace('$','',$cellAddress);
+ $noteLength = self::_GetInt2d($recordData, 4);
+ $noteText = trim(substr($recordData, 6));
+// echo 'Note Length=',$noteLength,'
';
+// echo 'Note Text=',$noteText,'
';
+
+ if ($extension) {
+ // Concatenate this extension with the currently set comment for the cell
+ $comment = $this->_phpSheet->getComment( $cellAddress );
+ $commentText = $comment->getText()->getPlainText();
+ $comment->setText($this->_parseRichText($commentText.$noteText) );
+ } else {
+ // Set comment for the cell
+ $this->_phpSheet->getComment( $cellAddress )
+// ->setAuthor( $author )
+ ->setText($this->_parseRichText($noteText) );
+ }
+ }
+
+ }
+
+
+ /**
+ * The TEXT Object record contains the text associated with a cell annotation.
+ */
+ private function _readTextObject()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ if ($this->_readDataOnly) {
+ return;
+ }
+
+ // recordData consists of an array of subrecords looking like this:
+ // grbit: 2 bytes; Option Flags
+ // rot: 2 bytes; rotation
+ // cchText: 2 bytes; length of the text (in the first continue record)
+ // cbRuns: 2 bytes; length of the formatting (in the second continue record)
+ // followed by the continuation records containing the actual text and formatting
+ $grbitOpts = self::_GetInt2d($recordData, 0);
+ $rot = self::_GetInt2d($recordData, 2);
+ $cchText = self::_GetInt2d($recordData, 10);
+ $cbRuns = self::_GetInt2d($recordData, 12);
+ $text = $this->_getSplicedRecordData();
+
+ $this->_textObjects[$this->textObjRef] = array(
+ 'text' => substr($text["recordData"],$text["spliceOffsets"][0]+1,$cchText),
+ 'format' => substr($text["recordData"],$text["spliceOffsets"][1],$cbRuns),
+ 'alignment' => $grbitOpts,
+ 'rotation' => $rot
+ );
+
+// echo '_readTextObject()
';
+// var_dump($this->_textObjects[$this->textObjRef]);
+// echo '
';
+ }
+
+
+ /**
+ * Read BOF
+ */
+ private function _readBof()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ // offset: 2; size: 2; type of the following data
+ $substreamType = self::_GetInt2d($recordData, 2);
+
+ switch ($substreamType) {
+ case self::XLS_WorkbookGlobals:
+ $version = self::_GetInt2d($recordData, 0);
+ if (($version != self::XLS_BIFF8) && ($version != self::XLS_BIFF7)) {
+ throw new Exception('Cannot read this Excel file. Version is too old.');
+ }
+ $this->_version = $version;
+ break;
+
+ case self::XLS_Worksheet:
+ // do not use this version information for anything
+ // it is unreliable (OpenOffice doc, 5.8), use only version information from the global stream
+ break;
+
+ default:
+ // substream, e.g. chart
+ // just skip the entire substream
+ do {
+ $code = self::_GetInt2d($this->_data, $this->_pos);
+ $this->_readDefault();
+ } while ($code != self::XLS_Type_EOF && $this->_pos < $this->_dataSize);
+ break;
+ }
+ }
+
+
+ /**
+ * FILEPASS
+ *
+ * This record is part of the File Protection Block. It
+ * contains information about the read/write password of the
+ * file. All record contents following this record will be
+ * encrypted.
+ *
+ * -- "OpenOffice.org's Documentation of the Microsoft
+ * Excel File Format"
+ */
+ private function _readFilepass()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+// $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ throw new Exception('Cannot read encrypted file');
+ }
+
+
+ /**
+ * CODEPAGE
+ *
+ * This record stores the text encoding used to write byte
+ * strings, stored as MS Windows code page identifier.
+ *
+ * -- "OpenOffice.org's Documentation of the Microsoft
+ * Excel File Format"
+ */
+ private function _readCodepage()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ // offset: 0; size: 2; code page identifier
+ $codepage = self::_GetInt2d($recordData, 0);
+
+ $this->_codepage = PHPExcel_Shared_CodePage::NumberToName($codepage);
+ }
+
+
+ /**
+ * DATEMODE
+ *
+ * This record specifies the base date for displaying date
+ * values. All dates are stored as count of days past this
+ * base date. In BIFF2-BIFF4 this record is part of the
+ * Calculation Settings Block. In BIFF5-BIFF8 it is
+ * stored in the Workbook Globals Substream.
+ *
+ * -- "OpenOffice.org's Documentation of the Microsoft
+ * Excel File Format"
+ */
+ private function _readDateMode()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ // offset: 0; size: 2; 0 = base 1900, 1 = base 1904
+ PHPExcel_Shared_Date::setExcelCalendar(PHPExcel_Shared_Date::CALENDAR_WINDOWS_1900);
+ if (ord($recordData{0}) == 1) {
+ PHPExcel_Shared_Date::setExcelCalendar(PHPExcel_Shared_Date::CALENDAR_MAC_1904);
+ }
+ }
+
+
+ /**
+ * Read a FONT record
+ */
+ private function _readFont()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ if (!$this->_readDataOnly) {
+ $objFont = new PHPExcel_Style_Font();
+
+ // offset: 0; size: 2; height of the font (in twips = 1/20 of a point)
+ $size = self::_GetInt2d($recordData, 0);
+ $objFont->setSize($size / 20);
+
+ // offset: 2; size: 2; option flags
+ // bit: 0; mask 0x0001; bold (redundant in BIFF5-BIFF8)
+ // bit: 1; mask 0x0002; italic
+ $isItalic = (0x0002 & self::_GetInt2d($recordData, 2)) >> 1;
+ if ($isItalic) $objFont->setItalic(true);
+
+ // bit: 2; mask 0x0004; underlined (redundant in BIFF5-BIFF8)
+ // bit: 3; mask 0x0008; strike
+ $isStrike = (0x0008 & self::_GetInt2d($recordData, 2)) >> 3;
+ if ($isStrike) $objFont->setStrikethrough(true);
+
+ // offset: 4; size: 2; colour index
+ $colorIndex = self::_GetInt2d($recordData, 4);
+ $objFont->colorIndex = $colorIndex;
+
+ // offset: 6; size: 2; font weight
+ $weight = self::_GetInt2d($recordData, 6);
+ switch ($weight) {
+ case 0x02BC:
+ $objFont->setBold(true);
+ break;
+ }
+
+ // offset: 8; size: 2; escapement type
+ $escapement = self::_GetInt2d($recordData, 8);
+ switch ($escapement) {
+ case 0x0001:
+ $objFont->setSuperScript(true);
+ break;
+ case 0x0002:
+ $objFont->setSubScript(true);
+ break;
+ }
+
+ // offset: 10; size: 1; underline type
+ $underlineType = ord($recordData{10});
+ switch ($underlineType) {
+ case 0x00:
+ break; // no underline
+ case 0x01:
+ $objFont->setUnderline(PHPExcel_Style_Font::UNDERLINE_SINGLE);
+ break;
+ case 0x02:
+ $objFont->setUnderline(PHPExcel_Style_Font::UNDERLINE_DOUBLE);
+ break;
+ case 0x21:
+ $objFont->setUnderline(PHPExcel_Style_Font::UNDERLINE_SINGLEACCOUNTING);
+ break;
+ case 0x22:
+ $objFont->setUnderline(PHPExcel_Style_Font::UNDERLINE_DOUBLEACCOUNTING);
+ break;
+ }
+
+ // offset: 11; size: 1; font family
+ // offset: 12; size: 1; character set
+ // offset: 13; size: 1; not used
+ // offset: 14; size: var; font name
+ if ($this->_version == self::XLS_BIFF8) {
+ $string = self::_readUnicodeStringShort(substr($recordData, 14));
+ } else {
+ $string = $this->_readByteStringShort(substr($recordData, 14));
+ }
+ $objFont->setName($string['value']);
+
+ $this->_objFonts[] = $objFont;
+ }
+ }
+
+
+ /**
+ * FORMAT
+ *
+ * This record contains information about a number format.
+ * All FORMAT records occur together in a sequential list.
+ *
+ * In BIFF2-BIFF4 other records referencing a FORMAT record
+ * contain a zero-based index into this list. From BIFF5 on
+ * the FORMAT record contains the index itself that will be
+ * used by other records.
+ *
+ * -- "OpenOffice.org's Documentation of the Microsoft
+ * Excel File Format"
+ */
+ private function _readFormat()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ if (!$this->_readDataOnly) {
+ $indexCode = self::_GetInt2d($recordData, 0);
+
+ if ($this->_version == self::XLS_BIFF8) {
+ $string = self::_readUnicodeStringLong(substr($recordData, 2));
+ } else {
+ // BIFF7
+ $string = $this->_readByteStringShort(substr($recordData, 2));
+ }
+
+ $formatString = $string['value'];
+ $this->_formats[$indexCode] = $formatString;
+ }
+ }
+
+
+ /**
+ * XF - Extended Format
+ *
+ * This record contains formatting information for cells, rows, columns or styles.
+ * According to http://support.microsoft.com/kb/147732 there are always at least 15 cell style XF
+ * and 1 cell XF.
+ * Inspection of Excel files generated by MS Office Excel shows that XF records 0-14 are cell style XF
+ * and XF record 15 is a cell XF
+ * We only read the first cell style XF and skip the remaining cell style XF records
+ * We read all cell XF records.
+ *
+ * -- "OpenOffice.org's Documentation of the Microsoft
+ * Excel File Format"
+ */
+ private function _readXf()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ $objStyle = new PHPExcel_Style();
+
+ if (!$this->_readDataOnly) {
+ // offset: 0; size: 2; Index to FONT record
+ if (self::_GetInt2d($recordData, 0) < 4) {
+ $fontIndex = self::_GetInt2d($recordData, 0);
+ } else {
+ // this has to do with that index 4 is omitted in all BIFF versions for some strange reason
+ // check the OpenOffice documentation of the FONT record
+ $fontIndex = self::_GetInt2d($recordData, 0) - 1;
+ }
+ $objStyle->setFont($this->_objFonts[$fontIndex]);
+
+ // offset: 2; size: 2; Index to FORMAT record
+ $numberFormatIndex = self::_GetInt2d($recordData, 2);
+ if (isset($this->_formats[$numberFormatIndex])) {
+ // then we have user-defined format code
+ $numberformat = array('code' => $this->_formats[$numberFormatIndex]);
+ } elseif (($code = PHPExcel_Style_NumberFormat::builtInFormatCode($numberFormatIndex)) !== '') {
+ // then we have built-in format code
+ $numberformat = array('code' => $code);
+ } else {
+ // we set the general format code
+ $numberformat = array('code' => 'General');
+ }
+ $objStyle->getNumberFormat()->setFormatCode($numberformat['code']);
+
+ // offset: 4; size: 2; XF type, cell protection, and parent style XF
+ // bit 2-0; mask 0x0007; XF_TYPE_PROT
+ $xfTypeProt = self::_GetInt2d($recordData, 4);
+ // bit 0; mask 0x01; 1 = cell is locked
+ $isLocked = (0x01 & $xfTypeProt) >> 0;
+ $objStyle->getProtection()->setLocked($isLocked ?
+ PHPExcel_Style_Protection::PROTECTION_INHERIT : PHPExcel_Style_Protection::PROTECTION_UNPROTECTED);
+
+ // bit 1; mask 0x02; 1 = Formula is hidden
+ $isHidden = (0x02 & $xfTypeProt) >> 1;
+ $objStyle->getProtection()->setHidden($isHidden ?
+ PHPExcel_Style_Protection::PROTECTION_PROTECTED : PHPExcel_Style_Protection::PROTECTION_UNPROTECTED);
+
+ // bit 2; mask 0x04; 0 = Cell XF, 1 = Cell Style XF
+ $isCellStyleXf = (0x04 & $xfTypeProt) >> 2;
+
+ // offset: 6; size: 1; Alignment and text break
+ // bit 2-0, mask 0x07; horizontal alignment
+ $horAlign = (0x07 & ord($recordData{6})) >> 0;
+ switch ($horAlign) {
+ case 0:
+ $objStyle->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_GENERAL);
+ break;
+ case 1:
+ $objStyle->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
+ break;
+ case 2:
+ $objStyle->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+ break;
+ case 3:
+ $objStyle->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
+ break;
+ case 5:
+ $objStyle->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY);
+ break;
+ case 6:
+ $objStyle->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER_CONTINUOUS);
+ break;
+ }
+ // bit 3, mask 0x08; wrap text
+ $wrapText = (0x08 & ord($recordData{6})) >> 3;
+ switch ($wrapText) {
+ case 0:
+ $objStyle->getAlignment()->setWrapText(false);
+ break;
+ case 1:
+ $objStyle->getAlignment()->setWrapText(true);
+ break;
+ }
+ // bit 6-4, mask 0x70; vertical alignment
+ $vertAlign = (0x70 & ord($recordData{6})) >> 4;
+ switch ($vertAlign) {
+ case 0:
+ $objStyle->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_TOP);
+ break;
+ case 1:
+ $objStyle->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
+ break;
+ case 2:
+ $objStyle->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_BOTTOM);
+ break;
+ case 3:
+ $objStyle->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_JUSTIFY);
+ break;
+ }
+
+ if ($this->_version == self::XLS_BIFF8) {
+ // offset: 7; size: 1; XF_ROTATION: Text rotation angle
+ $angle = ord($recordData{7});
+ $rotation = 0;
+ if ($angle <= 90) {
+ $rotation = $angle;
+ } else if ($angle <= 180) {
+ $rotation = 90 - $angle;
+ } else if ($angle == 255) {
+ $rotation = -165;
+ }
+ $objStyle->getAlignment()->setTextRotation($rotation);
+
+ // offset: 8; size: 1; Indentation, shrink to cell size, and text direction
+ // bit: 3-0; mask: 0x0F; indent level
+ $indent = (0x0F & ord($recordData{8})) >> 0;
+ $objStyle->getAlignment()->setIndent($indent);
+
+ // bit: 4; mask: 0x10; 1 = shrink content to fit into cell
+ $shrinkToFit = (0x10 & ord($recordData{8})) >> 4;
+ switch ($shrinkToFit) {
+ case 0:
+ $objStyle->getAlignment()->setShrinkToFit(false);
+ break;
+ case 1:
+ $objStyle->getAlignment()->setShrinkToFit(true);
+ break;
+ }
+
+ // offset: 9; size: 1; Flags used for attribute groups
+
+ // offset: 10; size: 4; Cell border lines and background area
+ // bit: 3-0; mask: 0x0000000F; left style
+ if ($bordersLeftStyle = self::_mapBorderStyle((0x0000000F & self::_GetInt4d($recordData, 10)) >> 0)) {
+ $objStyle->getBorders()->getLeft()->setBorderStyle($bordersLeftStyle);
+ }
+ // bit: 7-4; mask: 0x000000F0; right style
+ if ($bordersRightStyle = self::_mapBorderStyle((0x000000F0 & self::_GetInt4d($recordData, 10)) >> 4)) {
+ $objStyle->getBorders()->getRight()->setBorderStyle($bordersRightStyle);
+ }
+ // bit: 11-8; mask: 0x00000F00; top style
+ if ($bordersTopStyle = self::_mapBorderStyle((0x00000F00 & self::_GetInt4d($recordData, 10)) >> 8)) {
+ $objStyle->getBorders()->getTop()->setBorderStyle($bordersTopStyle);
+ }
+ // bit: 15-12; mask: 0x0000F000; bottom style
+ if ($bordersBottomStyle = self::_mapBorderStyle((0x0000F000 & self::_GetInt4d($recordData, 10)) >> 12)) {
+ $objStyle->getBorders()->getBottom()->setBorderStyle($bordersBottomStyle);
+ }
+ // bit: 22-16; mask: 0x007F0000; left color
+ $objStyle->getBorders()->getLeft()->colorIndex = (0x007F0000 & self::_GetInt4d($recordData, 10)) >> 16;
+
+ // bit: 29-23; mask: 0x3F800000; right color
+ $objStyle->getBorders()->getRight()->colorIndex = (0x3F800000 & self::_GetInt4d($recordData, 10)) >> 23;
+
+ // bit: 30; mask: 0x40000000; 1 = diagonal line from top left to right bottom
+ $diagonalDown = (0x40000000 & self::_GetInt4d($recordData, 10)) >> 30 ?
+ true : false;
+
+ // bit: 31; mask: 0x80000000; 1 = diagonal line from bottom left to top right
+ $diagonalUp = (0x80000000 & self::_GetInt4d($recordData, 10)) >> 31 ?
+ true : false;
+
+ if ($diagonalUp == false && $diagonalDown == false) {
+ $objStyle->getBorders()->setDiagonalDirection(PHPExcel_Style_Borders::DIAGONAL_NONE);
+ } elseif ($diagonalUp == true && $diagonalDown == false) {
+ $objStyle->getBorders()->setDiagonalDirection(PHPExcel_Style_Borders::DIAGONAL_UP);
+ } elseif ($diagonalUp == false && $diagonalDown == true) {
+ $objStyle->getBorders()->setDiagonalDirection(PHPExcel_Style_Borders::DIAGONAL_DOWN);
+ } elseif ($diagonalUp == true && $diagonalDown == true) {
+ $objStyle->getBorders()->setDiagonalDirection(PHPExcel_Style_Borders::DIAGONAL_BOTH);
+ }
+
+ // offset: 14; size: 4;
+ // bit: 6-0; mask: 0x0000007F; top color
+ $objStyle->getBorders()->getTop()->colorIndex = (0x0000007F & self::_GetInt4d($recordData, 14)) >> 0;
+
+ // bit: 13-7; mask: 0x00003F80; bottom color
+ $objStyle->getBorders()->getBottom()->colorIndex = (0x00003F80 & self::_GetInt4d($recordData, 14)) >> 7;
+
+ // bit: 20-14; mask: 0x001FC000; diagonal color
+ $objStyle->getBorders()->getDiagonal()->colorIndex = (0x001FC000 & self::_GetInt4d($recordData, 14)) >> 14;
+
+ // bit: 24-21; mask: 0x01E00000; diagonal style
+ if ($bordersDiagonalStyle = self::_mapBorderStyle((0x01E00000 & self::_GetInt4d($recordData, 14)) >> 21)) {
+ $objStyle->getBorders()->getDiagonal()->setBorderStyle($bordersDiagonalStyle);
+ }
+
+ // bit: 31-26; mask: 0xFC000000 fill pattern
+ if ($fillType = self::_mapFillPattern((0xFC000000 & self::_GetInt4d($recordData, 14)) >> 26)) {
+ $objStyle->getFill()->setFillType($fillType);
+ }
+ // offset: 18; size: 2; pattern and background colour
+ // bit: 6-0; mask: 0x007F; color index for pattern color
+ $objStyle->getFill()->startcolorIndex = (0x007F & self::_GetInt2d($recordData, 18)) >> 0;
+
+ // bit: 13-7; mask: 0x3F80; color index for pattern background
+ $objStyle->getFill()->endcolorIndex = (0x3F80 & self::_GetInt2d($recordData, 18)) >> 7;
+ } else {
+ // BIFF5
+
+ // offset: 7; size: 1; Text orientation and flags
+ $orientationAndFlags = ord($recordData{7});
+
+ // bit: 1-0; mask: 0x03; XF_ORIENTATION: Text orientation
+ $xfOrientation = (0x03 & $orientationAndFlags) >> 0;
+ switch ($xfOrientation) {
+ case 0:
+ $objStyle->getAlignment()->setTextRotation(0);
+ break;
+ case 1:
+ $objStyle->getAlignment()->setTextRotation(-165);
+ break;
+ case 2:
+ $objStyle->getAlignment()->setTextRotation(90);
+ break;
+ case 3:
+ $objStyle->getAlignment()->setTextRotation(-90);
+ break;
+ }
+
+ // offset: 8; size: 4; cell border lines and background area
+ $borderAndBackground = self::_GetInt4d($recordData, 8);
+
+ // bit: 6-0; mask: 0x0000007F; color index for pattern color
+ $objStyle->getFill()->startcolorIndex = (0x0000007F & $borderAndBackground) >> 0;
+
+ // bit: 13-7; mask: 0x00003F80; color index for pattern background
+ $objStyle->getFill()->endcolorIndex = (0x00003F80 & $borderAndBackground) >> 7;
+
+ // bit: 21-16; mask: 0x003F0000; fill pattern
+ $objStyle->getFill()->setFillType(self::_mapFillPattern((0x003F0000 & $borderAndBackground) >> 16));
+
+ // bit: 24-22; mask: 0x01C00000; bottom line style
+ $objStyle->getBorders()->getBottom()->setBorderStyle(self::_mapBorderStyle((0x01C00000 & $borderAndBackground) >> 22));
+
+ // bit: 31-25; mask: 0xFE000000; bottom line color
+ $objStyle->getBorders()->getBottom()->colorIndex = (0xFE000000 & $borderAndBackground) >> 25;
+
+ // offset: 12; size: 4; cell border lines
+ $borderLines = self::_GetInt4d($recordData, 12);
+
+ // bit: 2-0; mask: 0x00000007; top line style
+ $objStyle->getBorders()->getTop()->setBorderStyle(self::_mapBorderStyle((0x00000007 & $borderLines) >> 0));
+
+ // bit: 5-3; mask: 0x00000038; left line style
+ $objStyle->getBorders()->getLeft()->setBorderStyle(self::_mapBorderStyle((0x00000038 & $borderLines) >> 3));
+
+ // bit: 8-6; mask: 0x000001C0; right line style
+ $objStyle->getBorders()->getRight()->setBorderStyle(self::_mapBorderStyle((0x000001C0 & $borderLines) >> 6));
+
+ // bit: 15-9; mask: 0x0000FE00; top line color index
+ $objStyle->getBorders()->getTop()->colorIndex = (0x0000FE00 & $borderLines) >> 9;
+
+ // bit: 22-16; mask: 0x007F0000; left line color index
+ $objStyle->getBorders()->getLeft()->colorIndex = (0x007F0000 & $borderLines) >> 16;
+
+ // bit: 29-23; mask: 0x3F800000; right line color index
+ $objStyle->getBorders()->getRight()->colorIndex = (0x3F800000 & $borderLines) >> 23;
+ }
+
+ // add cellStyleXf or cellXf and update mapping
+ if ($isCellStyleXf) {
+ // we only read one style XF record which is always the first
+ if ($this->_xfIndex == 0) {
+ $this->_phpExcel->addCellStyleXf($objStyle);
+ $this->_mapCellStyleXfIndex[$this->_xfIndex] = 0;
+ }
+ } else {
+ // we read all cell XF records
+ $this->_phpExcel->addCellXf($objStyle);
+ $this->_mapCellXfIndex[$this->_xfIndex] = count($this->_phpExcel->getCellXfCollection()) - 1;
+ }
+
+ // update XF index for when we read next record
+ ++$this->_xfIndex;
+ }
+ }
+
+
+ /**
+ *
+ */
+ private function _readXfExt()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ if (!$this->_readDataOnly) {
+ // offset: 0; size: 2; 0x087D = repeated header
+
+ // offset: 2; size: 2
+
+ // offset: 4; size: 8; not used
+
+ // offset: 12; size: 2; record version
+
+ // offset: 14; size: 2; index to XF record which this record modifies
+ $ixfe = self::_GetInt2d($recordData, 14);
+
+ // offset: 16; size: 2; not used
+
+ // offset: 18; size: 2; number of extension properties that follow
+ $cexts = self::_GetInt2d($recordData, 18);
+
+ // start reading the actual extension data
+ $offset = 20;
+ while ($offset < $length) {
+ // extension type
+ $extType = self::_GetInt2d($recordData, $offset);
+
+ // extension length
+ $cb = self::_GetInt2d($recordData, $offset + 2);
+
+ // extension data
+ $extData = substr($recordData, $offset + 4, $cb);
+
+ switch ($extType) {
+ case 4: // fill start color
+ $xclfType = self::_GetInt2d($extData, 0); // color type
+ $xclrValue = substr($extData, 4, 4); // color value (value based on color type)
+
+ if ($xclfType == 2) {
+ $rgb = sprintf('%02X%02X%02X', ord($xclrValue{0}), ord($xclrValue{1}), ord($xclrValue{2}));
+
+ // modify the relevant style property
+ if ( isset($this->_mapCellXfIndex[$ixfe]) ) {
+ $fill = $this->_phpExcel->getCellXfByIndex($this->_mapCellXfIndex[$ixfe])->getFill();
+ $fill->getStartColor()->setRGB($rgb);
+ unset($fill->startcolorIndex); // normal color index does not apply, discard
+ }
+ }
+ break;
+
+ case 5: // fill end color
+ $xclfType = self::_GetInt2d($extData, 0); // color type
+ $xclrValue = substr($extData, 4, 4); // color value (value based on color type)
+
+ if ($xclfType == 2) {
+ $rgb = sprintf('%02X%02X%02X', ord($xclrValue{0}), ord($xclrValue{1}), ord($xclrValue{2}));
+
+ // modify the relevant style property
+ if ( isset($this->_mapCellXfIndex[$ixfe]) ) {
+ $fill = $this->_phpExcel->getCellXfByIndex($this->_mapCellXfIndex[$ixfe])->getFill();
+ $fill->getEndColor()->setRGB($rgb);
+ unset($fill->endcolorIndex); // normal color index does not apply, discard
+ }
+ }
+ break;
+
+ case 7: // border color top
+ $xclfType = self::_GetInt2d($extData, 0); // color type
+ $xclrValue = substr($extData, 4, 4); // color value (value based on color type)
+
+ if ($xclfType == 2) {
+ $rgb = sprintf('%02X%02X%02X', ord($xclrValue{0}), ord($xclrValue{1}), ord($xclrValue{2}));
+
+ // modify the relevant style property
+ if ( isset($this->_mapCellXfIndex[$ixfe]) ) {
+ $top = $this->_phpExcel->getCellXfByIndex($this->_mapCellXfIndex[$ixfe])->getBorders()->getTop();
+ $top->getColor()->setRGB($rgb);
+ unset($top->colorIndex); // normal color index does not apply, discard
+ }
+ }
+ break;
+
+ case 8: // border color bottom
+ $xclfType = self::_GetInt2d($extData, 0); // color type
+ $xclrValue = substr($extData, 4, 4); // color value (value based on color type)
+
+ if ($xclfType == 2) {
+ $rgb = sprintf('%02X%02X%02X', ord($xclrValue{0}), ord($xclrValue{1}), ord($xclrValue{2}));
+
+ // modify the relevant style property
+ if ( isset($this->_mapCellXfIndex[$ixfe]) ) {
+ $bottom = $this->_phpExcel->getCellXfByIndex($this->_mapCellXfIndex[$ixfe])->getBorders()->getBottom();
+ $bottom->getColor()->setRGB($rgb);
+ unset($bottom->colorIndex); // normal color index does not apply, discard
+ }
+ }
+ break;
+
+ case 9: // border color left
+ $xclfType = self::_GetInt2d($extData, 0); // color type
+ $xclrValue = substr($extData, 4, 4); // color value (value based on color type)
+
+ if ($xclfType == 2) {
+ $rgb = sprintf('%02X%02X%02X', ord($xclrValue{0}), ord($xclrValue{1}), ord($xclrValue{2}));
+
+ // modify the relevant style property
+ if ( isset($this->_mapCellXfIndex[$ixfe]) ) {
+ $left = $this->_phpExcel->getCellXfByIndex($this->_mapCellXfIndex[$ixfe])->getBorders()->getLeft();
+ $left->getColor()->setRGB($rgb);
+ unset($left->colorIndex); // normal color index does not apply, discard
+ }
+ }
+ break;
+
+ case 10: // border color right
+ $xclfType = self::_GetInt2d($extData, 0); // color type
+ $xclrValue = substr($extData, 4, 4); // color value (value based on color type)
+
+ if ($xclfType == 2) {
+ $rgb = sprintf('%02X%02X%02X', ord($xclrValue{0}), ord($xclrValue{1}), ord($xclrValue{2}));
+
+ // modify the relevant style property
+ if ( isset($this->_mapCellXfIndex[$ixfe]) ) {
+ $right = $this->_phpExcel->getCellXfByIndex($this->_mapCellXfIndex[$ixfe])->getBorders()->getRight();
+ $right->getColor()->setRGB($rgb);
+ unset($right->colorIndex); // normal color index does not apply, discard
+ }
+ }
+ break;
+
+ case 11: // border color diagonal
+ $xclfType = self::_GetInt2d($extData, 0); // color type
+ $xclrValue = substr($extData, 4, 4); // color value (value based on color type)
+
+ if ($xclfType == 2) {
+ $rgb = sprintf('%02X%02X%02X', ord($xclrValue{0}), ord($xclrValue{1}), ord($xclrValue{2}));
+
+ // modify the relevant style property
+ if ( isset($this->_mapCellXfIndex[$ixfe]) ) {
+ $diagonal = $this->_phpExcel->getCellXfByIndex($this->_mapCellXfIndex[$ixfe])->getBorders()->getDiagonal();
+ $diagonal->getColor()->setRGB($rgb);
+ unset($diagonal->colorIndex); // normal color index does not apply, discard
+ }
+ }
+ break;
+
+ case 13: // font color
+ $xclfType = self::_GetInt2d($extData, 0); // color type
+ $xclrValue = substr($extData, 4, 4); // color value (value based on color type)
+
+ if ($xclfType == 2) {
+ $rgb = sprintf('%02X%02X%02X', ord($xclrValue{0}), ord($xclrValue{1}), ord($xclrValue{2}));
+
+ // modify the relevant style property
+ if ( isset($this->_mapCellXfIndex[$ixfe]) ) {
+ $font = $this->_phpExcel->getCellXfByIndex($this->_mapCellXfIndex[$ixfe])->getFont();
+ $font->getColor()->setRGB($rgb);
+ unset($font->colorIndex); // normal color index does not apply, discard
+ }
+ }
+ break;
+ }
+
+ $offset += $cb;
+ }
+ }
+
+ }
+
+
+ /**
+ * Read STYLE record
+ */
+ private function _readStyle()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ if (!$this->_readDataOnly) {
+ // offset: 0; size: 2; index to XF record and flag for built-in style
+ $ixfe = self::_GetInt2d($recordData, 0);
+
+ // bit: 11-0; mask 0x0FFF; index to XF record
+ $xfIndex = (0x0FFF & $ixfe) >> 0;
+
+ // bit: 15; mask 0x8000; 0 = user-defined style, 1 = built-in style
+ $isBuiltIn = (bool) ((0x8000 & $ixfe) >> 15);
+
+ if ($isBuiltIn) {
+ // offset: 2; size: 1; identifier for built-in style
+ $builtInId = ord($recordData{2});
+
+ switch ($builtInId) {
+ case 0x00:
+ // currently, we are not using this for anything
+ break;
+
+ default:
+ break;
+ }
+
+ } else {
+ // user-defined; not supported by PHPExcel
+ }
+ }
+ }
+
+
+ /**
+ * Read PALETTE record
+ */
+ private function _readPalette()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ if (!$this->_readDataOnly) {
+ // offset: 0; size: 2; number of following colors
+ $nm = self::_GetInt2d($recordData, 0);
+
+ // list of RGB colors
+ for ($i = 0; $i < $nm; ++$i) {
+ $rgb = substr($recordData, 2 + 4 * $i, 4);
+ $this->_palette[] = self::_readRGB($rgb);
+ }
+ }
+ }
+
+
+ /**
+ * SHEET
+ *
+ * This record is located in the Workbook Globals
+ * Substream and represents a sheet inside the workbook.
+ * One SHEET record is written for each sheet. It stores the
+ * sheet name and a stream offset to the BOF record of the
+ * respective Sheet Substream within the Workbook Stream.
+ *
+ * -- "OpenOffice.org's Documentation of the Microsoft
+ * Excel File Format"
+ */
+ private function _readSheet()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ // offset: 0; size: 4; absolute stream position of the BOF record of the sheet
+ $rec_offset = self::_GetInt4d($recordData, 0);
+
+ // offset: 4; size: 1; sheet state
+ switch (ord($recordData{4})) {
+ case 0x00: $sheetState = PHPExcel_Worksheet::SHEETSTATE_VISIBLE; break;
+ case 0x01: $sheetState = PHPExcel_Worksheet::SHEETSTATE_HIDDEN; break;
+ case 0x02: $sheetState = PHPExcel_Worksheet::SHEETSTATE_VERYHIDDEN; break;
+ default: $sheetState = PHPExcel_Worksheet::SHEETSTATE_VISIBLE; break;
+ }
+
+ // offset: 5; size: 1; sheet type
+ $sheetType = ord($recordData{5});
+
+ // offset: 6; size: var; sheet name
+ if ($this->_version == self::XLS_BIFF8) {
+ $string = self::_readUnicodeStringShort(substr($recordData, 6));
+ $rec_name = $string['value'];
+ } elseif ($this->_version == self::XLS_BIFF7) {
+ $string = $this->_readByteStringShort(substr($recordData, 6));
+ $rec_name = $string['value'];
+ }
+
+ $this->_sheets[] = array(
+ 'name' => $rec_name,
+ 'offset' => $rec_offset,
+ 'sheetState' => $sheetState,
+ 'sheetType' => $sheetType,
+ );
+ }
+
+
+ /**
+ * Read EXTERNALBOOK record
+ */
+ private function _readExternalBook()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ // offset within record data
+ $offset = 0;
+
+ // there are 4 types of records
+ if (strlen($recordData) > 4) {
+ // external reference
+ // offset: 0; size: 2; number of sheet names ($nm)
+ $nm = self::_GetInt2d($recordData, 0);
+ $offset += 2;
+
+ // offset: 2; size: var; encoded URL without sheet name (Unicode string, 16-bit length)
+ $encodedUrlString = self::_readUnicodeStringLong(substr($recordData, 2));
+ $offset += $encodedUrlString['size'];
+
+ // offset: var; size: var; list of $nm sheet names (Unicode strings, 16-bit length)
+ $externalSheetNames = array();
+ for ($i = 0; $i < $nm; ++$i) {
+ $externalSheetNameString = self::_readUnicodeStringLong(substr($recordData, $offset));
+ $externalSheetNames[] = $externalSheetNameString['value'];
+ $offset += $externalSheetNameString['size'];
+ }
+
+ // store the record data
+ $this->_externalBooks[] = array(
+ 'type' => 'external',
+ 'encodedUrl' => $encodedUrlString['value'],
+ 'externalSheetNames' => $externalSheetNames,
+ );
+
+ } elseif (substr($recordData, 2, 2) == pack('CC', 0x01, 0x04)) {
+ // internal reference
+ // offset: 0; size: 2; number of sheet in this document
+ // offset: 2; size: 2; 0x01 0x04
+ $this->_externalBooks[] = array(
+ 'type' => 'internal',
+ );
+ } elseif (substr($recordData, 0, 4) == pack('vCC', 0x0001, 0x01, 0x3A)) {
+ // add-in function
+ // offset: 0; size: 2; 0x0001
+ $this->_externalBooks[] = array(
+ 'type' => 'addInFunction',
+ );
+ } elseif (substr($recordData, 0, 2) == pack('v', 0x0000)) {
+ // DDE links, OLE links
+ // offset: 0; size: 2; 0x0000
+ // offset: 2; size: var; encoded source document name
+ $this->_externalBooks[] = array(
+ 'type' => 'DDEorOLE',
+ );
+ }
+ }
+
+
+ /**
+ * Read EXTERNNAME record.
+ */
+ private function _readExternName()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ // external sheet references provided for named cells
+ if ($this->_version == self::XLS_BIFF8) {
+ // offset: 0; size: 2; options
+ $options = self::_GetInt2d($recordData, 0);
+
+ // offset: 2; size: 2;
+
+ // offset: 4; size: 2; not used
+
+ // offset: 6; size: var
+ $nameString = self::_readUnicodeStringShort(substr($recordData, 6));
+
+ // offset: var; size: var; formula data
+ $offset = 6 + $nameString['size'];
+ $formula = $this->_getFormulaFromStructure(substr($recordData, $offset));
+
+ $this->_externalNames[] = array(
+ 'name' => $nameString['value'],
+ 'formula' => $formula,
+ );
+ }
+ }
+
+
+ /**
+ * Read EXTERNSHEET record
+ */
+ private function _readExternSheet()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ // external sheet references provided for named cells
+ if ($this->_version == self::XLS_BIFF8) {
+ // offset: 0; size: 2; number of following ref structures
+ $nm = self::_GetInt2d($recordData, 0);
+ for ($i = 0; $i < $nm; ++$i) {
+ $this->_ref[] = array(
+ // offset: 2 + 6 * $i; index to EXTERNALBOOK record
+ 'externalBookIndex' => self::_GetInt2d($recordData, 2 + 6 * $i),
+ // offset: 4 + 6 * $i; index to first sheet in EXTERNALBOOK record
+ 'firstSheetIndex' => self::_GetInt2d($recordData, 4 + 6 * $i),
+ // offset: 6 + 6 * $i; index to last sheet in EXTERNALBOOK record
+ 'lastSheetIndex' => self::_GetInt2d($recordData, 6 + 6 * $i),
+ );
+ }
+ }
+ }
+
+
+ /**
+ * DEFINEDNAME
+ *
+ * This record is part of a Link Table. It contains the name
+ * and the token array of an internal defined name. Token
+ * arrays of defined names contain tokens with aberrant
+ * token classes.
+ *
+ * -- "OpenOffice.org's Documentation of the Microsoft
+ * Excel File Format"
+ */
+ private function _readDefinedName()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ if ($this->_version == self::XLS_BIFF8) {
+ // retrieves named cells
+
+ // offset: 0; size: 2; option flags
+ $opts = self::_GetInt2d($recordData, 0);
+
+ // bit: 5; mask: 0x0020; 0 = user-defined name, 1 = built-in-name
+ $isBuiltInName = (0x0020 & $opts) >> 5;
+
+ // offset: 2; size: 1; keyboard shortcut
+
+ // offset: 3; size: 1; length of the name (character count)
+ $nlen = ord($recordData{3});
+
+ // offset: 4; size: 2; size of the formula data (it can happen that this is zero)
+ // note: there can also be additional data, this is not included in $flen
+ $flen = self::_GetInt2d($recordData, 4);
+
+ // offset: 8; size: 2; 0=Global name, otherwise index to sheet (1-based)
+ $scope = self::_GetInt2d($recordData, 8);
+
+ // offset: 14; size: var; Name (Unicode string without length field)
+ $string = self::_readUnicodeString(substr($recordData, 14), $nlen);
+
+ // offset: var; size: $flen; formula data
+ $offset = 14 + $string['size'];
+ $formulaStructure = pack('v', $flen) . substr($recordData, $offset);
+
+ try {
+ $formula = $this->_getFormulaFromStructure($formulaStructure);
+ } catch (Exception $e) {
+ $formula = '';
+ }
+
+ $this->_definedname[] = array(
+ 'isBuiltInName' => $isBuiltInName,
+ 'name' => $string['value'],
+ 'formula' => $formula,
+ 'scope' => $scope,
+ );
+ }
+ }
+
+
+ /**
+ * Read MSODRAWINGGROUP record
+ */
+ private function _readMsoDrawingGroup()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+
+ // get spliced record data
+ $splicedRecordData = $this->_getSplicedRecordData();
+ $recordData = $splicedRecordData['recordData'];
+
+ $this->_drawingGroupData .= $recordData;
+ }
+
+
+ /**
+ * SST - Shared String Table
+ *
+ * This record contains a list of all strings used anywhere
+ * in the workbook. Each string occurs only once. The
+ * workbook uses indexes into the list to reference the
+ * strings.
+ *
+ * -- "OpenOffice.org's Documentation of the Microsoft
+ * Excel File Format"
+ **/
+ private function _readSst()
+ {
+ // offset within (spliced) record data
+ $pos = 0;
+
+ // get spliced record data
+ $splicedRecordData = $this->_getSplicedRecordData();
+
+ $recordData = $splicedRecordData['recordData'];
+ $spliceOffsets = $splicedRecordData['spliceOffsets'];
+
+ // offset: 0; size: 4; total number of strings in the workbook
+ $pos += 4;
+
+ // offset: 4; size: 4; number of following strings ($nm)
+ $nm = self::_GetInt4d($recordData, 4);
+ $pos += 4;
+
+ // loop through the Unicode strings (16-bit length)
+ for ($i = 0; $i < $nm; ++$i) {
+
+ // number of characters in the Unicode string
+ $numChars = self::_GetInt2d($recordData, $pos);
+ $pos += 2;
+
+ // option flags
+ $optionFlags = ord($recordData{$pos});
+ ++$pos;
+
+ // bit: 0; mask: 0x01; 0 = compressed; 1 = uncompressed
+ $isCompressed = (($optionFlags & 0x01) == 0) ;
+
+ // bit: 2; mask: 0x02; 0 = ordinary; 1 = Asian phonetic
+ $hasAsian = (($optionFlags & 0x04) != 0);
+
+ // bit: 3; mask: 0x03; 0 = ordinary; 1 = Rich-Text
+ $hasRichText = (($optionFlags & 0x08) != 0);
+
+ if ($hasRichText) {
+ // number of Rich-Text formatting runs
+ $formattingRuns = self::_GetInt2d($recordData, $pos);
+ $pos += 2;
+ }
+
+ if ($hasAsian) {
+ // size of Asian phonetic setting
+ $extendedRunLength = self::_GetInt4d($recordData, $pos);
+ $pos += 4;
+ }
+
+ // expected byte length of character array if not split
+ $len = ($isCompressed) ? $numChars : $numChars * 2;
+
+ // look up limit position
+ foreach ($spliceOffsets as $spliceOffset) {
+ // it can happen that the string is empty, therefore we need
+ // <= and not just <
+ if ($pos <= $spliceOffset) {
+ $limitpos = $spliceOffset;
+ break;
+ }
+ }
+
+ if ($pos + $len <= $limitpos) {
+ // character array is not split between records
+
+ $retstr = substr($recordData, $pos, $len);
+ $pos += $len;
+
+ } else {
+ // character array is split between records
+
+ // first part of character array
+ $retstr = substr($recordData, $pos, $limitpos - $pos);
+
+ $bytesRead = $limitpos - $pos;
+
+ // remaining characters in Unicode string
+ $charsLeft = $numChars - (($isCompressed) ? $bytesRead : ($bytesRead / 2));
+
+ $pos = $limitpos;
+
+ // keep reading the characters
+ while ($charsLeft > 0) {
+
+ // look up next limit position, in case the string span more than one continue record
+ foreach ($spliceOffsets as $spliceOffset) {
+ if ($pos < $spliceOffset) {
+ $limitpos = $spliceOffset;
+ break;
+ }
+ }
+
+ // repeated option flags
+ // OpenOffice.org documentation 5.21
+ $option = ord($recordData{$pos});
+ ++$pos;
+
+ if ($isCompressed && ($option == 0)) {
+ // 1st fragment compressed
+ // this fragment compressed
+ $len = min($charsLeft, $limitpos - $pos);
+ $retstr .= substr($recordData, $pos, $len);
+ $charsLeft -= $len;
+ $isCompressed = true;
+
+ } elseif (!$isCompressed && ($option != 0)) {
+ // 1st fragment uncompressed
+ // this fragment uncompressed
+ $len = min($charsLeft * 2, $limitpos - $pos);
+ $retstr .= substr($recordData, $pos, $len);
+ $charsLeft -= $len / 2;
+ $isCompressed = false;
+
+ } elseif (!$isCompressed && ($option == 0)) {
+ // 1st fragment uncompressed
+ // this fragment compressed
+ $len = min($charsLeft, $limitpos - $pos);
+ for ($j = 0; $j < $len; ++$j) {
+ $retstr .= $recordData{$pos + $j} . chr(0);
+ }
+ $charsLeft -= $len;
+ $isCompressed = false;
+
+ } else {
+ // 1st fragment compressed
+ // this fragment uncompressed
+ $newstr = '';
+ for ($j = 0; $j < strlen($retstr); ++$j) {
+ $newstr .= $retstr[$j] . chr(0);
+ }
+ $retstr = $newstr;
+ $len = min($charsLeft * 2, $limitpos - $pos);
+ $retstr .= substr($recordData, $pos, $len);
+ $charsLeft -= $len / 2;
+ $isCompressed = false;
+ }
+
+ $pos += $len;
+ }
+ }
+
+ // convert to UTF-8
+ $retstr = self::_encodeUTF16($retstr, $isCompressed);
+
+ // read additional Rich-Text information, if any
+ $fmtRuns = array();
+ if ($hasRichText) {
+ // list of formatting runs
+ for ($j = 0; $j < $formattingRuns; ++$j) {
+ // first formatted character; zero-based
+ $charPos = self::_GetInt2d($recordData, $pos + $j * 4);
+
+ // index to font record
+ $fontIndex = self::_GetInt2d($recordData, $pos + 2 + $j * 4);
+
+ $fmtRuns[] = array(
+ 'charPos' => $charPos,
+ 'fontIndex' => $fontIndex,
+ );
+ }
+ $pos += 4 * $formattingRuns;
+ }
+
+ // read additional Asian phonetics information, if any
+ if ($hasAsian) {
+ // For Asian phonetic settings, we skip the extended string data
+ $pos += $extendedRunLength;
+ }
+
+ // store the shared sting
+ $this->_sst[] = array(
+ 'value' => $retstr,
+ 'fmtRuns' => $fmtRuns,
+ );
+ }
+
+ // _getSplicedRecordData() takes care of moving current position in data stream
+ }
+
+
+ /**
+ * Read PRINTGRIDLINES record
+ */
+ private function _readPrintGridlines()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ if ($this->_version == self::XLS_BIFF8 && !$this->_readDataOnly) {
+ // offset: 0; size: 2; 0 = do not print sheet grid lines; 1 = print sheet gridlines
+ $printGridlines = (bool) self::_GetInt2d($recordData, 0);
+ $this->_phpSheet->setPrintGridlines($printGridlines);
+ }
+ }
+
+
+ /**
+ * Read DEFAULTROWHEIGHT record
+ */
+ private function _readDefaultRowHeight()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ // offset: 0; size: 2; option flags
+ // offset: 2; size: 2; default height for unused rows, (twips 1/20 point)
+ $height = self::_GetInt2d($recordData, 2);
+ $this->_phpSheet->getDefaultRowDimension()->setRowHeight($height / 20);
+ }
+
+
+ /**
+ * Read SHEETPR record
+ */
+ private function _readSheetPr()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ // offset: 0; size: 2
+
+ // bit: 6; mask: 0x0040; 0 = outline buttons above outline group
+ $isSummaryBelow = (0x0040 & self::_GetInt2d($recordData, 0)) >> 6;
+ $this->_phpSheet->setShowSummaryBelow($isSummaryBelow);
+
+ // bit: 7; mask: 0x0080; 0 = outline buttons left of outline group
+ $isSummaryRight = (0x0080 & self::_GetInt2d($recordData, 0)) >> 7;
+ $this->_phpSheet->setShowSummaryRight($isSummaryRight);
+
+ // bit: 8; mask: 0x100; 0 = scale printout in percent, 1 = fit printout to number of pages
+ // this corresponds to radio button setting in page setup dialog in Excel
+ $this->_isFitToPages = (bool) ((0x0100 & self::_GetInt2d($recordData, 0)) >> 8);
+ }
+
+
+ /**
+ * Read HORIZONTALPAGEBREAKS record
+ */
+ private function _readHorizontalPageBreaks()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ if ($this->_version == self::XLS_BIFF8 && !$this->_readDataOnly) {
+
+ // offset: 0; size: 2; number of the following row index structures
+ $nm = self::_GetInt2d($recordData, 0);
+
+ // offset: 2; size: 6 * $nm; list of $nm row index structures
+ for ($i = 0; $i < $nm; ++$i) {
+ $r = self::_GetInt2d($recordData, 2 + 6 * $i);
+ $cf = self::_GetInt2d($recordData, 2 + 6 * $i + 2);
+ $cl = self::_GetInt2d($recordData, 2 + 6 * $i + 4);
+
+ // not sure why two column indexes are necessary?
+ $this->_phpSheet->setBreakByColumnAndRow($cf, $r, PHPExcel_Worksheet::BREAK_ROW);
+ }
+ }
+ }
+
+
+ /**
+ * Read VERTICALPAGEBREAKS record
+ */
+ private function _readVerticalPageBreaks()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ if ($this->_version == self::XLS_BIFF8 && !$this->_readDataOnly) {
+ // offset: 0; size: 2; number of the following column index structures
+ $nm = self::_GetInt2d($recordData, 0);
+
+ // offset: 2; size: 6 * $nm; list of $nm row index structures
+ for ($i = 0; $i < $nm; ++$i) {
+ $c = self::_GetInt2d($recordData, 2 + 6 * $i);
+ $rf = self::_GetInt2d($recordData, 2 + 6 * $i + 2);
+ $rl = self::_GetInt2d($recordData, 2 + 6 * $i + 4);
+
+ // not sure why two row indexes are necessary?
+ $this->_phpSheet->setBreakByColumnAndRow($c, $rf, PHPExcel_Worksheet::BREAK_COLUMN);
+ }
+ }
+ }
+
+
+ /**
+ * Read HEADER record
+ */
+ private function _readHeader()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ if (!$this->_readDataOnly) {
+ // offset: 0; size: var
+ // realized that $recordData can be empty even when record exists
+ if ($recordData) {
+ if ($this->_version == self::XLS_BIFF8) {
+ $string = self::_readUnicodeStringLong($recordData);
+ } else {
+ $string = $this->_readByteStringShort($recordData);
+ }
+
+ $this->_phpSheet->getHeaderFooter()->setOddHeader($string['value']);
+ $this->_phpSheet->getHeaderFooter()->setEvenHeader($string['value']);
+ }
+ }
+ }
+
+
+ /**
+ * Read FOOTER record
+ */
+ private function _readFooter()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ if (!$this->_readDataOnly) {
+ // offset: 0; size: var
+ // realized that $recordData can be empty even when record exists
+ if ($recordData) {
+ if ($this->_version == self::XLS_BIFF8) {
+ $string = self::_readUnicodeStringLong($recordData);
+ } else {
+ $string = $this->_readByteStringShort($recordData);
+ }
+ $this->_phpSheet->getHeaderFooter()->setOddFooter($string['value']);
+ $this->_phpSheet->getHeaderFooter()->setEvenFooter($string['value']);
+ }
+ }
+ }
+
+
+ /**
+ * Read HCENTER record
+ */
+ private function _readHcenter()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ if (!$this->_readDataOnly) {
+ // offset: 0; size: 2; 0 = print sheet left aligned, 1 = print sheet centered horizontally
+ $isHorizontalCentered = (bool) self::_GetInt2d($recordData, 0);
+
+ $this->_phpSheet->getPageSetup()->setHorizontalCentered($isHorizontalCentered);
+ }
+ }
+
+
+ /**
+ * Read VCENTER record
+ */
+ private function _readVcenter()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ if (!$this->_readDataOnly) {
+ // offset: 0; size: 2; 0 = print sheet aligned at top page border, 1 = print sheet vertically centered
+ $isVerticalCentered = (bool) self::_GetInt2d($recordData, 0);
+
+ $this->_phpSheet->getPageSetup()->setVerticalCentered($isVerticalCentered);
+ }
+ }
+
+
+ /**
+ * Read LEFTMARGIN record
+ */
+ private function _readLeftMargin()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ if (!$this->_readDataOnly) {
+ // offset: 0; size: 8
+ $this->_phpSheet->getPageMargins()->setLeft(self::_extractNumber($recordData));
+ }
+ }
+
+
+ /**
+ * Read RIGHTMARGIN record
+ */
+ private function _readRightMargin()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ if (!$this->_readDataOnly) {
+ // offset: 0; size: 8
+ $this->_phpSheet->getPageMargins()->setRight(self::_extractNumber($recordData));
+ }
+ }
+
+
+ /**
+ * Read TOPMARGIN record
+ */
+ private function _readTopMargin()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ if (!$this->_readDataOnly) {
+ // offset: 0; size: 8
+ $this->_phpSheet->getPageMargins()->setTop(self::_extractNumber($recordData));
+ }
+ }
+
+
+ /**
+ * Read BOTTOMMARGIN record
+ */
+ private function _readBottomMargin()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ if (!$this->_readDataOnly) {
+ // offset: 0; size: 8
+ $this->_phpSheet->getPageMargins()->setBottom(self::_extractNumber($recordData));
+ }
+ }
+
+
+ /**
+ * Read PAGESETUP record
+ */
+ private function _readPageSetup()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ if (!$this->_readDataOnly) {
+ // offset: 0; size: 2; paper size
+ $paperSize = self::_GetInt2d($recordData, 0);
+
+ // offset: 2; size: 2; scaling factor
+ $scale = self::_GetInt2d($recordData, 2);
+
+ // offset: 6; size: 2; fit worksheet width to this number of pages, 0 = use as many as needed
+ $fitToWidth = self::_GetInt2d($recordData, 6);
+
+ // offset: 8; size: 2; fit worksheet height to this number of pages, 0 = use as many as needed
+ $fitToHeight = self::_GetInt2d($recordData, 8);
+
+ // offset: 10; size: 2; option flags
+
+ // bit: 1; mask: 0x0002; 0=landscape, 1=portrait
+ $isPortrait = (0x0002 & self::_GetInt2d($recordData, 10)) >> 1;
+
+ // bit: 2; mask: 0x0004; 1= paper size, scaling factor, paper orient. not init
+ // when this bit is set, do not use flags for those properties
+ $isNotInit = (0x0004 & self::_GetInt2d($recordData, 10)) >> 2;
+
+ if (!$isNotInit) {
+ $this->_phpSheet->getPageSetup()->setPaperSize($paperSize);
+ switch ($isPortrait) {
+ case 0: $this->_phpSheet->getPageSetup()->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE); break;
+ case 1: $this->_phpSheet->getPageSetup()->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_PORTRAIT); break;
+ }
+
+ $this->_phpSheet->getPageSetup()->setScale($scale, false);
+ $this->_phpSheet->getPageSetup()->setFitToPage((bool) $this->_isFitToPages);
+ $this->_phpSheet->getPageSetup()->setFitToWidth($fitToWidth, false);
+ $this->_phpSheet->getPageSetup()->setFitToHeight($fitToHeight, false);
+ }
+
+ // offset: 16; size: 8; header margin (IEEE 754 floating-point value)
+ $marginHeader = self::_extractNumber(substr($recordData, 16, 8));
+ $this->_phpSheet->getPageMargins()->setHeader($marginHeader);
+
+ // offset: 24; size: 8; footer margin (IEEE 754 floating-point value)
+ $marginFooter = self::_extractNumber(substr($recordData, 24, 8));
+ $this->_phpSheet->getPageMargins()->setFooter($marginFooter);
+ }
+ }
+
+
+ /**
+ * PROTECT - Sheet protection (BIFF2 through BIFF8)
+ * if this record is omitted, then it also means no sheet protection
+ */
+ private function _readProtect()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ if ($this->_readDataOnly) {
+ return;
+ }
+
+ // offset: 0; size: 2;
+
+ // bit 0, mask 0x01; 1 = sheet is protected
+ $bool = (0x01 & self::_GetInt2d($recordData, 0)) >> 0;
+ $this->_phpSheet->getProtection()->setSheet((bool)$bool);
+ }
+
+
+ /**
+ * SCENPROTECT
+ */
+ private function _readScenProtect()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ if ($this->_readDataOnly) {
+ return;
+ }
+
+ // offset: 0; size: 2;
+
+ // bit: 0, mask 0x01; 1 = scenarios are protected
+ $bool = (0x01 & self::_GetInt2d($recordData, 0)) >> 0;
+
+ $this->_phpSheet->getProtection()->setScenarios((bool)$bool);
+ }
+
+
+ /**
+ * OBJECTPROTECT
+ */
+ private function _readObjectProtect()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ if ($this->_readDataOnly) {
+ return;
+ }
+
+ // offset: 0; size: 2;
+
+ // bit: 0, mask 0x01; 1 = objects are protected
+ $bool = (0x01 & self::_GetInt2d($recordData, 0)) >> 0;
+
+ $this->_phpSheet->getProtection()->setObjects((bool)$bool);
+ }
+
+
+ /**
+ * PASSWORD - Sheet protection (hashed) password (BIFF2 through BIFF8)
+ */
+ private function _readPassword()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ if (!$this->_readDataOnly) {
+ // offset: 0; size: 2; 16-bit hash value of password
+ $password = strtoupper(dechex(self::_GetInt2d($recordData, 0))); // the hashed password
+ $this->_phpSheet->getProtection()->setPassword($password, true);
+ }
+ }
+
+
+ /**
+ * Read DEFCOLWIDTH record
+ */
+ private function _readDefColWidth()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ // offset: 0; size: 2; default column width
+ $width = self::_GetInt2d($recordData, 0);
+ if ($width != 8) {
+ $this->_phpSheet->getDefaultColumnDimension()->setWidth($width);
+ }
+ }
+
+
+ /**
+ * Read COLINFO record
+ */
+ private function _readColInfo()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ if (!$this->_readDataOnly) {
+ // offset: 0; size: 2; index to first column in range
+ $fc = self::_GetInt2d($recordData, 0); // first column index
+
+ // offset: 2; size: 2; index to last column in range
+ $lc = self::_GetInt2d($recordData, 2); // first column index
+
+ // offset: 4; size: 2; width of the column in 1/256 of the width of the zero character
+ $width = self::_GetInt2d($recordData, 4);
+
+ // offset: 6; size: 2; index to XF record for default column formatting
+ $xfIndex = self::_GetInt2d($recordData, 6);
+
+ // offset: 8; size: 2; option flags
+
+ // bit: 0; mask: 0x0001; 1= columns are hidden
+ $isHidden = (0x0001 & self::_GetInt2d($recordData, 8)) >> 0;
+
+ // bit: 10-8; mask: 0x0700; outline level of the columns (0 = no outline)
+ $level = (0x0700 & self::_GetInt2d($recordData, 8)) >> 8;
+
+ // bit: 12; mask: 0x1000; 1 = collapsed
+ $isCollapsed = (0x1000 & self::_GetInt2d($recordData, 8)) >> 12;
+
+ // offset: 10; size: 2; not used
+
+ for ($i = $fc; $i <= $lc; ++$i) {
+ if ($lc == 255 || $lc == 256) {
+ $this->_phpSheet->getDefaultColumnDimension()->setWidth($width / 256);
+ break;
+ }
+ $this->_phpSheet->getColumnDimensionByColumn($i)->setWidth($width / 256);
+ $this->_phpSheet->getColumnDimensionByColumn($i)->setVisible(!$isHidden);
+ $this->_phpSheet->getColumnDimensionByColumn($i)->setOutlineLevel($level);
+ $this->_phpSheet->getColumnDimensionByColumn($i)->setCollapsed($isCollapsed);
+ $this->_phpSheet->getColumnDimensionByColumn($i)->setXfIndex($this->_mapCellXfIndex[$xfIndex]);
+ }
+ }
+ }
+
+
+ /**
+ * ROW
+ *
+ * This record contains the properties of a single row in a
+ * sheet. Rows and cells in a sheet are divided into blocks
+ * of 32 rows.
+ *
+ * -- "OpenOffice.org's Documentation of the Microsoft
+ * Excel File Format"
+ */
+ private function _readRow()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ if (!$this->_readDataOnly) {
+ // offset: 0; size: 2; index of this row
+ $r = self::_GetInt2d($recordData, 0);
+
+ // offset: 2; size: 2; index to column of the first cell which is described by a cell record
+
+ // offset: 4; size: 2; index to column of the last cell which is described by a cell record, increased by 1
+
+ // offset: 6; size: 2;
+
+ // bit: 14-0; mask: 0x7FFF; height of the row, in twips = 1/20 of a point
+ $height = (0x7FFF & self::_GetInt2d($recordData, 6)) >> 0;
+
+ // bit: 15: mask: 0x8000; 0 = row has custom height; 1= row has default height
+ $useDefaultHeight = (0x8000 & self::_GetInt2d($recordData, 6)) >> 15;
+
+ if (!$useDefaultHeight) {
+ $this->_phpSheet->getRowDimension($r + 1)->setRowHeight($height / 20);
+ }
+
+ // offset: 8; size: 2; not used
+
+ // offset: 10; size: 2; not used in BIFF5-BIFF8
+
+ // offset: 12; size: 4; option flags and default row formatting
+
+ // bit: 2-0: mask: 0x00000007; outline level of the row
+ $level = (0x00000007 & self::_GetInt4d($recordData, 12)) >> 0;
+ $this->_phpSheet->getRowDimension($r + 1)->setOutlineLevel($level);
+
+ // bit: 4; mask: 0x00000010; 1 = outline group start or ends here... and is collapsed
+ $isCollapsed = (0x00000010 & self::_GetInt4d($recordData, 12)) >> 4;
+ $this->_phpSheet->getRowDimension($r + 1)->setCollapsed($isCollapsed);
+
+ // bit: 5; mask: 0x00000020; 1 = row is hidden
+ $isHidden = (0x00000020 & self::_GetInt4d($recordData, 12)) >> 5;
+ $this->_phpSheet->getRowDimension($r + 1)->setVisible(!$isHidden);
+
+ // bit: 7; mask: 0x00000080; 1 = row has explicit format
+ $hasExplicitFormat = (0x00000080 & self::_GetInt4d($recordData, 12)) >> 7;
+
+ // bit: 27-16; mask: 0x0FFF0000; only applies when hasExplicitFormat = 1; index to XF record
+ $xfIndex = (0x0FFF0000 & self::_GetInt4d($recordData, 12)) >> 16;
+
+ if ($hasExplicitFormat) {
+ $this->_phpSheet->getRowDimension($r + 1)->setXfIndex($this->_mapCellXfIndex[$xfIndex]);
+ }
+ }
+ }
+
+
+ /**
+ * Read RK record
+ * This record represents a cell that contains an RK value
+ * (encoded integer or floating-point value). If a
+ * floating-point value cannot be encoded to an RK value,
+ * a NUMBER record will be written. This record replaces the
+ * record INTEGER written in BIFF2.
+ *
+ * -- "OpenOffice.org's Documentation of the Microsoft
+ * Excel File Format"
+ */
+ private function _readRk()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ // offset: 0; size: 2; index to row
+ $row = self::_GetInt2d($recordData, 0);
+
+ // offset: 2; size: 2; index to column
+ $column = self::_GetInt2d($recordData, 2);
+ $columnString = PHPExcel_Cell::stringFromColumnIndex($column);
+
+ // Read cell?
+ if (($this->getReadFilter() !== NULL) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->_phpSheet->getTitle()) ) {
+ // offset: 4; size: 2; index to XF record
+ $xfIndex = self::_GetInt2d($recordData, 4);
+
+ // offset: 6; size: 4; RK value
+ $rknum = self::_GetInt4d($recordData, 6);
+ $numValue = self::_GetIEEE754($rknum);
+
+ $cell = $this->_phpSheet->getCell($columnString . ($row + 1));
+ if (!$this->_readDataOnly) {
+ // add style information
+ $cell->setXfIndex($this->_mapCellXfIndex[$xfIndex]);
+ }
+
+ // add cell
+ $cell->setValueExplicit($numValue, PHPExcel_Cell_DataType::TYPE_NUMERIC);
+ }
+ }
+
+
+ /**
+ * Read LABELSST record
+ * This record represents a cell that contains a string. It
+ * replaces the LABEL record and RSTRING record used in
+ * BIFF2-BIFF5.
+ *
+ * -- "OpenOffice.org's Documentation of the Microsoft
+ * Excel File Format"
+ */
+ private function _readLabelSst()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ // offset: 0; size: 2; index to row
+ $row = self::_GetInt2d($recordData, 0);
+
+ // offset: 2; size: 2; index to column
+ $column = self::_GetInt2d($recordData, 2);
+ $columnString = PHPExcel_Cell::stringFromColumnIndex($column);
+
+ // Read cell?
+ if (($this->getReadFilter() !== NULL) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->_phpSheet->getTitle()) ) {
+ // offset: 4; size: 2; index to XF record
+ $xfIndex = self::_GetInt2d($recordData, 4);
+
+ // offset: 6; size: 4; index to SST record
+ $index = self::_GetInt4d($recordData, 6);
+
+ // add cell
+ if (($fmtRuns = $this->_sst[$index]['fmtRuns']) && !$this->_readDataOnly) {
+ // then we should treat as rich text
+ $richText = new PHPExcel_RichText();
+ $charPos = 0;
+ $sstCount = count($this->_sst[$index]['fmtRuns']);
+ for ($i = 0; $i <= $sstCount; ++$i) {
+ if (isset($fmtRuns[$i])) {
+ $text = PHPExcel_Shared_String::Substring($this->_sst[$index]['value'], $charPos, $fmtRuns[$i]['charPos'] - $charPos);
+ $charPos = $fmtRuns[$i]['charPos'];
+ } else {
+ $text = PHPExcel_Shared_String::Substring($this->_sst[$index]['value'], $charPos, PHPExcel_Shared_String::CountCharacters($this->_sst[$index]['value']));
+ }
+
+ if (PHPExcel_Shared_String::CountCharacters($text) > 0) {
+ if ($i == 0) { // first text run, no style
+ $richText->createText($text);
+ } else {
+ $textRun = $richText->createTextRun($text);
+ if (isset($fmtRuns[$i - 1])) {
+ if ($fmtRuns[$i - 1]['fontIndex'] < 4) {
+ $fontIndex = $fmtRuns[$i - 1]['fontIndex'];
+ } else {
+ // this has to do with that index 4 is omitted in all BIFF versions for some strange reason
+ // check the OpenOffice documentation of the FONT record
+ $fontIndex = $fmtRuns[$i - 1]['fontIndex'] - 1;
+ }
+ $textRun->setFont(clone $this->_objFonts[$fontIndex]);
+ }
+ }
+ }
+ }
+ $cell = $this->_phpSheet->getCell($columnString . ($row + 1));
+ $cell->setValueExplicit($richText, PHPExcel_Cell_DataType::TYPE_STRING);
+ } else {
+ $cell = $this->_phpSheet->getCell($columnString . ($row + 1));
+ $cell->setValueExplicit($this->_sst[$index]['value'], PHPExcel_Cell_DataType::TYPE_STRING);
+ }
+
+ if (!$this->_readDataOnly) {
+ // add style information
+ $cell->setXfIndex($this->_mapCellXfIndex[$xfIndex]);
+ }
+ }
+ }
+
+
+ /**
+ * Read MULRK record
+ * This record represents a cell range containing RK value
+ * cells. All cells are located in the same row.
+ *
+ * -- "OpenOffice.org's Documentation of the Microsoft
+ * Excel File Format"
+ */
+ private function _readMulRk()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ // offset: 0; size: 2; index to row
+ $row = self::_GetInt2d($recordData, 0);
+
+ // offset: 2; size: 2; index to first column
+ $colFirst = self::_GetInt2d($recordData, 2);
+
+ // offset: var; size: 2; index to last column
+ $colLast = self::_GetInt2d($recordData, $length - 2);
+ $columns = $colLast - $colFirst + 1;
+
+ // offset within record data
+ $offset = 4;
+
+ for ($i = 0; $i < $columns; ++$i) {
+ $columnString = PHPExcel_Cell::stringFromColumnIndex($colFirst + $i);
+
+ // Read cell?
+ if (($this->getReadFilter() !== NULL) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->_phpSheet->getTitle()) ) {
+
+ // offset: var; size: 2; index to XF record
+ $xfIndex = self::_GetInt2d($recordData, $offset);
+
+ // offset: var; size: 4; RK value
+ $numValue = self::_GetIEEE754(self::_GetInt4d($recordData, $offset + 2));
+ $cell = $this->_phpSheet->getCell($columnString . ($row + 1));
+ if (!$this->_readDataOnly) {
+ // add style
+ $cell->setXfIndex($this->_mapCellXfIndex[$xfIndex]);
+ }
+
+ // add cell value
+ $cell->setValueExplicit($numValue, PHPExcel_Cell_DataType::TYPE_NUMERIC);
+ }
+
+ $offset += 6;
+ }
+ }
+
+
+ /**
+ * Read NUMBER record
+ * This record represents a cell that contains a
+ * floating-point value.
+ *
+ * -- "OpenOffice.org's Documentation of the Microsoft
+ * Excel File Format"
+ */
+ private function _readNumber()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ // offset: 0; size: 2; index to row
+ $row = self::_GetInt2d($recordData, 0);
+
+ // offset: 2; size 2; index to column
+ $column = self::_GetInt2d($recordData, 2);
+ $columnString = PHPExcel_Cell::stringFromColumnIndex($column);
+
+ // Read cell?
+ if (($this->getReadFilter() !== NULL) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->_phpSheet->getTitle()) ) {
+ // offset 4; size: 2; index to XF record
+ $xfIndex = self::_GetInt2d($recordData, 4);
+
+ $numValue = self::_extractNumber(substr($recordData, 6, 8));
+
+ $cell = $this->_phpSheet->getCell($columnString . ($row + 1));
+ if (!$this->_readDataOnly) {
+ // add cell style
+ $cell->setXfIndex($this->_mapCellXfIndex[$xfIndex]);
+ }
+
+ // add cell value
+ $cell->setValueExplicit($numValue, PHPExcel_Cell_DataType::TYPE_NUMERIC);
+ }
+ }
+
+
+ /**
+ * Read FORMULA record + perhaps a following STRING record if formula result is a string
+ * This record contains the token array and the result of a
+ * formula cell.
+ *
+ * -- "OpenOffice.org's Documentation of the Microsoft
+ * Excel File Format"
+ */
+ private function _readFormula()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ // offset: 0; size: 2; row index
+ $row = self::_GetInt2d($recordData, 0);
+
+ // offset: 2; size: 2; col index
+ $column = self::_GetInt2d($recordData, 2);
+ $columnString = PHPExcel_Cell::stringFromColumnIndex($column);
+
+ // offset: 20: size: variable; formula structure
+ $formulaStructure = substr($recordData, 20);
+
+ // offset: 14: size: 2; option flags, recalculate always, recalculate on open etc.
+ $options = self::_GetInt2d($recordData, 14);
+
+ // bit: 0; mask: 0x0001; 1 = recalculate always
+ // bit: 1; mask: 0x0002; 1 = calculate on open
+ // bit: 2; mask: 0x0008; 1 = part of a shared formula
+ $isPartOfSharedFormula = (bool) (0x0008 & $options);
+
+ // WARNING:
+ // We can apparently not rely on $isPartOfSharedFormula. Even when $isPartOfSharedFormula = true
+ // the formula data may be ordinary formula data, therefore we need to check
+ // explicitly for the tExp token (0x01)
+ $isPartOfSharedFormula = $isPartOfSharedFormula && ord($formulaStructure{2}) == 0x01;
+
+ if ($isPartOfSharedFormula) {
+ // part of shared formula which means there will be a formula with a tExp token and nothing else
+ // get the base cell, grab tExp token
+ $baseRow = self::_GetInt2d($formulaStructure, 3);
+ $baseCol = self::_GetInt2d($formulaStructure, 5);
+ $this->_baseCell = PHPExcel_Cell::stringFromColumnIndex($baseCol). ($baseRow + 1);
+ }
+
+ // Read cell?
+ if (($this->getReadFilter() !== NULL) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->_phpSheet->getTitle()) ) {
+
+ if ($isPartOfSharedFormula) {
+ // formula is added to this cell after the sheet has been read
+ $this->_sharedFormulaParts[$columnString . ($row + 1)] = $this->_baseCell;
+ }
+
+ // offset: 16: size: 4; not used
+
+ // offset: 4; size: 2; XF index
+ $xfIndex = self::_GetInt2d($recordData, 4);
+
+ // offset: 6; size: 8; result of the formula
+ if ( (ord($recordData{6}) == 0)
+ && (ord($recordData{12}) == 255)
+ && (ord($recordData{13}) == 255) ) {
+
+ // String formula. Result follows in appended STRING record
+ $dataType = PHPExcel_Cell_DataType::TYPE_STRING;
+
+ // read possible SHAREDFMLA record
+ $code = self::_GetInt2d($this->_data, $this->_pos);
+ if ($code == self::XLS_Type_SHAREDFMLA) {
+ $this->_readSharedFmla();
+ }
+
+ // read STRING record
+ $value = $this->_readString();
+
+ } elseif ((ord($recordData{6}) == 1)
+ && (ord($recordData{12}) == 255)
+ && (ord($recordData{13}) == 255)) {
+
+ // Boolean formula. Result is in +2; 0=false, 1=true
+ $dataType = PHPExcel_Cell_DataType::TYPE_BOOL;
+ $value = (bool) ord($recordData{8});
+
+ } elseif ((ord($recordData{6}) == 2)
+ && (ord($recordData{12}) == 255)
+ && (ord($recordData{13}) == 255)) {
+
+ // Error formula. Error code is in +2
+ $dataType = PHPExcel_Cell_DataType::TYPE_ERROR;
+ $value = self::_mapErrorCode(ord($recordData{8}));
+
+ } elseif ((ord($recordData{6}) == 3)
+ && (ord($recordData{12}) == 255)
+ && (ord($recordData{13}) == 255)) {
+
+ // Formula result is a null string
+ $dataType = PHPExcel_Cell_DataType::TYPE_NULL;
+ $value = '';
+
+ } else {
+
+ // forumla result is a number, first 14 bytes like _NUMBER record
+ $dataType = PHPExcel_Cell_DataType::TYPE_NUMERIC;
+ $value = self::_extractNumber(substr($recordData, 6, 8));
+
+ }
+
+ $cell = $this->_phpSheet->getCell($columnString . ($row + 1));
+ if (!$this->_readDataOnly) {
+ // add cell style
+ $cell->setXfIndex($this->_mapCellXfIndex[$xfIndex]);
+ }
+
+ // store the formula
+ if (!$isPartOfSharedFormula) {
+ // not part of shared formula
+ // add cell value. If we can read formula, populate with formula, otherwise just used cached value
+ try {
+ if ($this->_version != self::XLS_BIFF8) {
+ throw new Exception('Not BIFF8. Can only read BIFF8 formulas');
+ }
+ $formula = $this->_getFormulaFromStructure($formulaStructure); // get formula in human language
+ $cell->setValueExplicit('=' . $formula, PHPExcel_Cell_DataType::TYPE_FORMULA);
+
+ } catch (Exception $e) {
+ $cell->setValueExplicit($value, $dataType);
+ }
+ } else {
+ if ($this->_version == self::XLS_BIFF8) {
+ // do nothing at this point, formula id added later in the code
+ } else {
+ $cell->setValueExplicit($value, $dataType);
+ }
+ }
+
+ // store the cached calculated value
+ $cell->setCalculatedValue($value);
+ }
+ }
+
+
+ /**
+ * Read a SHAREDFMLA record. This function just stores the binary shared formula in the reader,
+ * which usually contains relative references.
+ * These will be used to construct the formula in each shared formula part after the sheet is read.
+ */
+ private function _readSharedFmla()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ // offset: 0, size: 6; cell range address of the area used by the shared formula, not used for anything
+ $cellRange = substr($recordData, 0, 6);
+ $cellRange = $this->_readBIFF5CellRangeAddressFixed($cellRange); // note: even BIFF8 uses BIFF5 syntax
+
+ // offset: 6, size: 1; not used
+
+ // offset: 7, size: 1; number of existing FORMULA records for this shared formula
+ $no = ord($recordData{7});
+
+ // offset: 8, size: var; Binary token array of the shared formula
+ $formula = substr($recordData, 8);
+
+ // at this point we only store the shared formula for later use
+ $this->_sharedFormulas[$this->_baseCell] = $formula;
+
+ }
+
+
+ /**
+ * Read a STRING record from current stream position and advance the stream pointer to next record
+ * This record is used for storing result from FORMULA record when it is a string, and
+ * it occurs directly after the FORMULA record
+ *
+ * @return string The string contents as UTF-8
+ */
+ private function _readString()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ if ($this->_version == self::XLS_BIFF8) {
+ $string = self::_readUnicodeStringLong($recordData);
+ $value = $string['value'];
+ } else {
+ $string = $this->_readByteStringLong($recordData);
+ $value = $string['value'];
+ }
+
+ return $value;
+ }
+
+
+ /**
+ * Read BOOLERR record
+ * This record represents a Boolean value or error value
+ * cell.
+ *
+ * -- "OpenOffice.org's Documentation of the Microsoft
+ * Excel File Format"
+ */
+ private function _readBoolErr()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ // offset: 0; size: 2; row index
+ $row = self::_GetInt2d($recordData, 0);
+
+ // offset: 2; size: 2; column index
+ $column = self::_GetInt2d($recordData, 2);
+ $columnString = PHPExcel_Cell::stringFromColumnIndex($column);
+
+ // Read cell?
+ if (($this->getReadFilter() !== NULL) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->_phpSheet->getTitle()) ) {
+ // offset: 4; size: 2; index to XF record
+ $xfIndex = self::_GetInt2d($recordData, 4);
+
+ // offset: 6; size: 1; the boolean value or error value
+ $boolErr = ord($recordData{6});
+
+ // offset: 7; size: 1; 0=boolean; 1=error
+ $isError = ord($recordData{7});
+
+ $cell = $this->_phpSheet->getCell($columnString . ($row + 1));
+ switch ($isError) {
+ case 0: // boolean
+ $value = (bool) $boolErr;
+
+ // add cell value
+ $cell->setValueExplicit($value, PHPExcel_Cell_DataType::TYPE_BOOL);
+ break;
+
+ case 1: // error type
+ $value = self::_mapErrorCode($boolErr);
+
+ // add cell value
+ $cell->setValueExplicit($value, PHPExcel_Cell_DataType::TYPE_ERROR);
+ break;
+ }
+
+ if (!$this->_readDataOnly) {
+ // add cell style
+ $cell->setXfIndex($this->_mapCellXfIndex[$xfIndex]);
+ }
+ }
+ }
+
+
+ /**
+ * Read MULBLANK record
+ * This record represents a cell range of empty cells. All
+ * cells are located in the same row
+ *
+ * -- "OpenOffice.org's Documentation of the Microsoft
+ * Excel File Format"
+ */
+ private function _readMulBlank()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ // offset: 0; size: 2; index to row
+ $row = self::_GetInt2d($recordData, 0);
+
+ // offset: 2; size: 2; index to first column
+ $fc = self::_GetInt2d($recordData, 2);
+
+ // offset: 4; size: 2 x nc; list of indexes to XF records
+ // add style information
+ if (!$this->_readDataOnly) {
+ for ($i = 0; $i < $length / 2 - 3; ++$i) {
+ $columnString = PHPExcel_Cell::stringFromColumnIndex($fc + $i);
+
+ // Read cell?
+ if (($this->getReadFilter() !== NULL) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->_phpSheet->getTitle()) ) {
+ $xfIndex = self::_GetInt2d($recordData, 4 + 2 * $i);
+ $this->_phpSheet->getCell($columnString . ($row + 1))->setXfIndex($this->_mapCellXfIndex[$xfIndex]);
+ }
+ }
+ }
+
+ // offset: 6; size 2; index to last column (not needed)
+ }
+
+
+ /**
+ * Read LABEL record
+ * This record represents a cell that contains a string. In
+ * BIFF8 it is usually replaced by the LABELSST record.
+ * Excel still uses this record, if it copies unformatted
+ * text cells to the clipboard.
+ *
+ * -- "OpenOffice.org's Documentation of the Microsoft
+ * Excel File Format"
+ */
+ private function _readLabel()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ // offset: 0; size: 2; index to row
+ $row = self::_GetInt2d($recordData, 0);
+
+ // offset: 2; size: 2; index to column
+ $column = self::_GetInt2d($recordData, 2);
+ $columnString = PHPExcel_Cell::stringFromColumnIndex($column);
+
+ // Read cell?
+ if (($this->getReadFilter() !== NULL) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->_phpSheet->getTitle()) ) {
+ // offset: 4; size: 2; XF index
+ $xfIndex = self::_GetInt2d($recordData, 4);
+
+ // add cell value
+ // todo: what if string is very long? continue record
+ if ($this->_version == self::XLS_BIFF8) {
+ $string = self::_readUnicodeStringLong(substr($recordData, 6));
+ $value = $string['value'];
+ } else {
+ $string = $this->_readByteStringLong(substr($recordData, 6));
+ $value = $string['value'];
+ }
+ $cell = $this->_phpSheet->getCell($columnString . ($row + 1));
+ $cell->setValueExplicit($value, PHPExcel_Cell_DataType::TYPE_STRING);
+
+ if (!$this->_readDataOnly) {
+ // add cell style
+ $cell->setXfIndex($this->_mapCellXfIndex[$xfIndex]);
+ }
+ }
+ }
+
+
+ /**
+ * Read BLANK record
+ */
+ private function _readBlank()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ // offset: 0; size: 2; row index
+ $row = self::_GetInt2d($recordData, 0);
+
+ // offset: 2; size: 2; col index
+ $col = self::_GetInt2d($recordData, 2);
+ $columnString = PHPExcel_Cell::stringFromColumnIndex($col);
+
+ // Read cell?
+ if (($this->getReadFilter() !== NULL) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->_phpSheet->getTitle()) ) {
+ // offset: 4; size: 2; XF index
+ $xfIndex = self::_GetInt2d($recordData, 4);
+
+ // add style information
+ if (!$this->_readDataOnly) {
+ $this->_phpSheet->getCell($columnString . ($row + 1))->setXfIndex($this->_mapCellXfIndex[$xfIndex]);
+ }
+ }
+
+ }
+
+
+ /**
+ * Read MSODRAWING record
+ */
+ private function _readMsoDrawing()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+
+ // get spliced record data
+ $splicedRecordData = $this->_getSplicedRecordData();
+ $recordData = $splicedRecordData['recordData'];
+
+ $this->_drawingData .= $recordData;
+ }
+
+
+ /**
+ * Read OBJ record
+ */
+ private function _readObj()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ if ($this->_readDataOnly || $this->_version != self::XLS_BIFF8) {
+ return;
+ }
+
+ // recordData consists of an array of subrecords looking like this:
+ // ft: 2 bytes; ftCmo type (0x15)
+ // cb: 2 bytes; size in bytes of ftCmo data
+ // ot: 2 bytes; Object Type
+ // id: 2 bytes; Object id number
+ // grbit: 2 bytes; Option Flags
+ // data: var; subrecord data
+
+ // for now, we are just interested in the second subrecord containing the object type
+ $ftCmoType = self::_GetInt2d($recordData, 0);
+ $cbCmoSize = self::_GetInt2d($recordData, 2);
+ $otObjType = self::_GetInt2d($recordData, 4);
+ $idObjID = self::_GetInt2d($recordData, 6);
+ $grbitOpts = self::_GetInt2d($recordData, 6);
+
+ $this->_objs[] = array(
+ 'ftCmoType' => $ftCmoType,
+ 'cbCmoSize' => $cbCmoSize,
+ 'otObjType' => $otObjType,
+ 'idObjID' => $idObjID,
+ 'grbitOpts' => $grbitOpts
+ );
+ $this->textObjRef = $idObjID;
+
+// echo '_readObj()
';
+// var_dump(end($this->_objs));
+// echo '
';
+ }
+
+
+ /**
+ * Read WINDOW2 record
+ */
+ private function _readWindow2()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ // offset: 0; size: 2; option flags
+ $options = self::_GetInt2d($recordData, 0);
+
+ // bit: 1; mask: 0x0002; 0 = do not show gridlines, 1 = show gridlines
+ $showGridlines = (bool) ((0x0002 & $options) >> 1);
+ $this->_phpSheet->setShowGridlines($showGridlines);
+
+ // bit: 2; mask: 0x0004; 0 = do not show headers, 1 = show headers
+ $showRowColHeaders = (bool) ((0x0004 & $options) >> 2);
+ $this->_phpSheet->setShowRowColHeaders($showRowColHeaders);
+
+ // bit: 3; mask: 0x0008; 0 = panes are not frozen, 1 = panes are frozen
+ $this->_frozen = (bool) ((0x0008 & $options) >> 3);
+
+ // bit: 6; mask: 0x0040; 0 = columns from left to right, 1 = columns from right to left
+ $this->_phpSheet->setRightToLeft((bool)((0x0040 & $options) >> 6));
+
+ // bit: 10; mask: 0x0400; 0 = sheet not active, 1 = sheet active
+ $isActive = (bool) ((0x0400 & $options) >> 10);
+ if ($isActive) {
+ $this->_phpExcel->setActiveSheetIndex($this->_phpExcel->getIndex($this->_phpSheet));
+ }
+ }
+
+
+ /**
+ * Read SCL record
+ */
+ private function _readScl()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ // offset: 0; size: 2; numerator of the view magnification
+ $numerator = self::_GetInt2d($recordData, 0);
+
+ // offset: 2; size: 2; numerator of the view magnification
+ $denumerator = self::_GetInt2d($recordData, 2);
+
+ // set the zoom scale (in percent)
+ $this->_phpSheet->getSheetView()->setZoomScale($numerator * 100 / $denumerator);
+ }
+
+
+ /**
+ * Read PANE record
+ */
+ private function _readPane()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ if (!$this->_readDataOnly) {
+ // offset: 0; size: 2; position of vertical split
+ $px = self::_GetInt2d($recordData, 0);
+
+ // offset: 2; size: 2; position of horizontal split
+ $py = self::_GetInt2d($recordData, 2);
+
+ if ($this->_frozen) {
+ // frozen panes
+ $this->_phpSheet->freezePane(PHPExcel_Cell::stringFromColumnIndex($px) . ($py + 1));
+ } else {
+ // unfrozen panes; split windows; not supported by PHPExcel core
+ }
+ }
+ }
+
+
+ /**
+ * Read SELECTION record. There is one such record for each pane in the sheet.
+ */
+ private function _readSelection()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ if (!$this->_readDataOnly) {
+ // offset: 0; size: 1; pane identifier
+ $paneId = ord($recordData{0});
+
+ // offset: 1; size: 2; index to row of the active cell
+ $r = self::_GetInt2d($recordData, 1);
+
+ // offset: 3; size: 2; index to column of the active cell
+ $c = self::_GetInt2d($recordData, 3);
+
+ // offset: 5; size: 2; index into the following cell range list to the
+ // entry that contains the active cell
+ $index = self::_GetInt2d($recordData, 5);
+
+ // offset: 7; size: var; cell range address list containing all selected cell ranges
+ $data = substr($recordData, 7);
+ $cellRangeAddressList = $this->_readBIFF5CellRangeAddressList($data); // note: also BIFF8 uses BIFF5 syntax
+
+ $selectedCells = $cellRangeAddressList['cellRangeAddresses'][0];
+
+ // first row '1' + last row '16384' indicates that full column is selected (apparently also in BIFF8!)
+ if (preg_match('/^([A-Z]+1\:[A-Z]+)16384$/', $selectedCells)) {
+ $selectedCells = preg_replace('/^([A-Z]+1\:[A-Z]+)16384$/', '${1}1048576', $selectedCells);
+ }
+
+ // first row '1' + last row '65536' indicates that full column is selected
+ if (preg_match('/^([A-Z]+1\:[A-Z]+)65536$/', $selectedCells)) {
+ $selectedCells = preg_replace('/^([A-Z]+1\:[A-Z]+)65536$/', '${1}1048576', $selectedCells);
+ }
+
+ // first column 'A' + last column 'IV' indicates that full row is selected
+ if (preg_match('/^(A[0-9]+\:)IV([0-9]+)$/', $selectedCells)) {
+ $selectedCells = preg_replace('/^(A[0-9]+\:)IV([0-9]+)$/', '${1}XFD${2}', $selectedCells);
+ }
+
+ $this->_phpSheet->setSelectedCells($selectedCells);
+ }
+ }
+
+
+ private function _includeCellRangeFiltered($cellRangeAddress)
+ {
+ $includeCellRange = true;
+ if ($this->getReadFilter() !== NULL) {
+ $includeCellRange = false;
+ $rangeBoundaries = PHPExcel_Cell::getRangeBoundaries($cellRangeAddress);
+ $rangeBoundaries[1][0]++;
+ for ($row = $rangeBoundaries[0][1]; $row <= $rangeBoundaries[1][1]; $row++) {
+ for ($column = $rangeBoundaries[0][0]; $column != $rangeBoundaries[1][0]; $column++) {
+ if ($this->getReadFilter()->readCell($column, $row, $this->_phpSheet->getTitle())) {
+ $includeCellRange = true;
+ break 2;
+ }
+ }
+ }
+ }
+ return $includeCellRange;
+ }
+
+
+ /**
+ * MERGEDCELLS
+ *
+ * This record contains the addresses of merged cell ranges
+ * in the current sheet.
+ *
+ * -- "OpenOffice.org's Documentation of the Microsoft
+ * Excel File Format"
+ */
+ private function _readMergedCells()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ if ($this->_version == self::XLS_BIFF8 && !$this->_readDataOnly) {
+ $cellRangeAddressList = $this->_readBIFF8CellRangeAddressList($recordData);
+ foreach ($cellRangeAddressList['cellRangeAddresses'] as $cellRangeAddress) {
+ if ((strpos($cellRangeAddress,':') !== FALSE) &&
+ ($this->_includeCellRangeFiltered($cellRangeAddress))) {
+ $this->_phpSheet->mergeCells($cellRangeAddress);
+ }
+ }
+ }
+ }
+
+
+ /**
+ * Read HYPERLINK record
+ */
+ private function _readHyperLink()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer forward to next record
+ $this->_pos += 4 + $length;
+
+ if (!$this->_readDataOnly) {
+ // offset: 0; size: 8; cell range address of all cells containing this hyperlink
+ try {
+ $cellRange = $this->_readBIFF8CellRangeAddressFixed($recordData, 0, 8);
+ } catch (Exception $e) {
+ return;
+ }
+
+ // offset: 8, size: 16; GUID of StdLink
+
+ // offset: 24, size: 4; unknown value
+
+ // offset: 28, size: 4; option flags
+
+ // bit: 0; mask: 0x00000001; 0 = no link or extant, 1 = file link or URL
+ $isFileLinkOrUrl = (0x00000001 & self::_GetInt2d($recordData, 28)) >> 0;
+
+ // bit: 1; mask: 0x00000002; 0 = relative path, 1 = absolute path or URL
+ $isAbsPathOrUrl = (0x00000001 & self::_GetInt2d($recordData, 28)) >> 1;
+
+ // bit: 2 (and 4); mask: 0x00000014; 0 = no description
+ $hasDesc = (0x00000014 & self::_GetInt2d($recordData, 28)) >> 2;
+
+ // bit: 3; mask: 0x00000008; 0 = no text, 1 = has text
+ $hasText = (0x00000008 & self::_GetInt2d($recordData, 28)) >> 3;
+
+ // bit: 7; mask: 0x00000080; 0 = no target frame, 1 = has target frame
+ $hasFrame = (0x00000080 & self::_GetInt2d($recordData, 28)) >> 7;
+
+ // bit: 8; mask: 0x00000100; 0 = file link or URL, 1 = UNC path (inc. server name)
+ $isUNC = (0x00000100 & self::_GetInt2d($recordData, 28)) >> 8;
+
+ // offset within record data
+ $offset = 32;
+
+ if ($hasDesc) {
+ // offset: 32; size: var; character count of description text
+ $dl = self::_GetInt4d($recordData, 32);
+ // offset: 36; size: var; character array of description text, no Unicode string header, always 16-bit characters, zero terminated
+ $desc = self::_encodeUTF16(substr($recordData, 36, 2 * ($dl - 1)), false);
+ $offset += 4 + 2 * $dl;
+ }
+ if ($hasFrame) {
+ $fl = self::_GetInt4d($recordData, $offset);
+ $offset += 4 + 2 * $fl;
+ }
+
+ // detect type of hyperlink (there are 4 types)
+ $hyperlinkType = null;
+
+ if ($isUNC) {
+ $hyperlinkType = 'UNC';
+ } else if (!$isFileLinkOrUrl) {
+ $hyperlinkType = 'workbook';
+ } else if (ord($recordData{$offset}) == 0x03) {
+ $hyperlinkType = 'local';
+ } else if (ord($recordData{$offset}) == 0xE0) {
+ $hyperlinkType = 'URL';
+ }
+
+ switch ($hyperlinkType) {
+ case 'URL':
+ // section 5.58.2: Hyperlink containing a URL
+ // e.g. http://example.org/index.php
+
+ // offset: var; size: 16; GUID of URL Moniker
+ $offset += 16;
+ // offset: var; size: 4; size (in bytes) of character array of the URL including trailing zero word
+ $us = self::_GetInt4d($recordData, $offset);
+ $offset += 4;
+ // offset: var; size: $us; character array of the URL, no Unicode string header, always 16-bit characters, zero-terminated
+ $url = self::_encodeUTF16(substr($recordData, $offset, $us - 2), false);
+ $url .= $hasText ? '#' : '';
+ $offset += $us;
+ break;
+
+ case 'local':
+ // section 5.58.3: Hyperlink to local file
+ // examples:
+ // mydoc.txt
+ // ../../somedoc.xls#Sheet!A1
+
+ // offset: var; size: 16; GUI of File Moniker
+ $offset += 16;
+
+ // offset: var; size: 2; directory up-level count.
+ $upLevelCount = self::_GetInt2d($recordData, $offset);
+ $offset += 2;
+
+ // offset: var; size: 4; character count of the shortened file path and name, including trailing zero word
+ $sl = self::_GetInt4d($recordData, $offset);
+ $offset += 4;
+
+ // offset: var; size: sl; character array of the shortened file path and name in 8.3-DOS-format (compressed Unicode string)
+ $shortenedFilePath = substr($recordData, $offset, $sl);
+ $shortenedFilePath = self::_encodeUTF16($shortenedFilePath, true);
+ $shortenedFilePath = substr($shortenedFilePath, 0, -1); // remove trailing zero
+
+ $offset += $sl;
+
+ // offset: var; size: 24; unknown sequence
+ $offset += 24;
+
+ // extended file path
+ // offset: var; size: 4; size of the following file link field including string lenth mark
+ $sz = self::_GetInt4d($recordData, $offset);
+ $offset += 4;
+
+ // only present if $sz > 0
+ if ($sz > 0) {
+ // offset: var; size: 4; size of the character array of the extended file path and name
+ $xl = self::_GetInt4d($recordData, $offset);
+ $offset += 4;
+
+ // offset: var; size 2; unknown
+ $offset += 2;
+
+ // offset: var; size $xl; character array of the extended file path and name.
+ $extendedFilePath = substr($recordData, $offset, $xl);
+ $extendedFilePath = self::_encodeUTF16($extendedFilePath, false);
+ $offset += $xl;
+ }
+
+ // construct the path
+ $url = str_repeat('..\\', $upLevelCount);
+ $url .= ($sz > 0) ?
+ $extendedFilePath : $shortenedFilePath; // use extended path if available
+ $url .= $hasText ? '#' : '';
+
+ break;
+
+
+ case 'UNC':
+ // section 5.58.4: Hyperlink to a File with UNC (Universal Naming Convention) Path
+ // todo: implement
+ return;
+
+ case 'workbook':
+ // section 5.58.5: Hyperlink to the Current Workbook
+ // e.g. Sheet2!B1:C2, stored in text mark field
+ $url = 'sheet://';
+ break;
+
+ default:
+ return;
+
+ }
+
+ if ($hasText) {
+ // offset: var; size: 4; character count of text mark including trailing zero word
+ $tl = self::_GetInt4d($recordData, $offset);
+ $offset += 4;
+ // offset: var; size: var; character array of the text mark without the # sign, no Unicode header, always 16-bit characters, zero-terminated
+ $text = self::_encodeUTF16(substr($recordData, $offset, 2 * ($tl - 1)), false);
+ $url .= $text;
+ }
+
+ // apply the hyperlink to all the relevant cells
+ foreach (PHPExcel_Cell::extractAllCellReferencesInRange($cellRange) as $coordinate) {
+ $this->_phpSheet->getCell($coordinate)->getHyperLink()->setUrl($url);
+ }
+ }
+ }
+
+
+ /**
+ * Read DATAVALIDATIONS record
+ */
+ private function _readDataValidations()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer forward to next record
+ $this->_pos += 4 + $length;
+ }
+
+
+ /**
+ * Read DATAVALIDATION record
+ */
+ private function _readDataValidation()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer forward to next record
+ $this->_pos += 4 + $length;
+
+ if ($this->_readDataOnly) {
+ return;
+ }
+
+ // offset: 0; size: 4; Options
+ $options = self::_GetInt4d($recordData, 0);
+
+ // bit: 0-3; mask: 0x0000000F; type
+ $type = (0x0000000F & $options) >> 0;
+ switch ($type) {
+ case 0x00: $type = PHPExcel_Cell_DataValidation::TYPE_NONE; break;
+ case 0x01: $type = PHPExcel_Cell_DataValidation::TYPE_WHOLE; break;
+ case 0x02: $type = PHPExcel_Cell_DataValidation::TYPE_DECIMAL; break;
+ case 0x03: $type = PHPExcel_Cell_DataValidation::TYPE_LIST; break;
+ case 0x04: $type = PHPExcel_Cell_DataValidation::TYPE_DATE; break;
+ case 0x05: $type = PHPExcel_Cell_DataValidation::TYPE_TIME; break;
+ case 0x06: $type = PHPExcel_Cell_DataValidation::TYPE_TEXTLENGTH; break;
+ case 0x07: $type = PHPExcel_Cell_DataValidation::TYPE_CUSTOM; break;
+ }
+
+ // bit: 4-6; mask: 0x00000070; error type
+ $errorStyle = (0x00000070 & $options) >> 4;
+ switch ($errorStyle) {
+ case 0x00: $errorStyle = PHPExcel_Cell_DataValidation::STYLE_STOP; break;
+ case 0x01: $errorStyle = PHPExcel_Cell_DataValidation::STYLE_WARNING; break;
+ case 0x02: $errorStyle = PHPExcel_Cell_DataValidation::STYLE_INFORMATION; break;
+ }
+
+ // bit: 7; mask: 0x00000080; 1= formula is explicit (only applies to list)
+ // I have only seen cases where this is 1
+ $explicitFormula = (0x00000080 & $options) >> 7;
+
+ // bit: 8; mask: 0x00000100; 1= empty cells allowed
+ $allowBlank = (0x00000100 & $options) >> 8;
+
+ // bit: 9; mask: 0x00000200; 1= suppress drop down arrow in list type validity
+ $suppressDropDown = (0x00000200 & $options) >> 9;
+
+ // bit: 18; mask: 0x00040000; 1= show prompt box if cell selected
+ $showInputMessage = (0x00040000 & $options) >> 18;
+
+ // bit: 19; mask: 0x00080000; 1= show error box if invalid values entered
+ $showErrorMessage = (0x00080000 & $options) >> 19;
+
+ // bit: 20-23; mask: 0x00F00000; condition operator
+ $operator = (0x00F00000 & $options) >> 20;
+ switch ($operator) {
+ case 0x00: $operator = PHPExcel_Cell_DataValidation::OPERATOR_BETWEEN ; break;
+ case 0x01: $operator = PHPExcel_Cell_DataValidation::OPERATOR_NOTBETWEEN ; break;
+ case 0x02: $operator = PHPExcel_Cell_DataValidation::OPERATOR_EQUAL ; break;
+ case 0x03: $operator = PHPExcel_Cell_DataValidation::OPERATOR_NOTEQUAL ; break;
+ case 0x04: $operator = PHPExcel_Cell_DataValidation::OPERATOR_GREATERTHAN ; break;
+ case 0x05: $operator = PHPExcel_Cell_DataValidation::OPERATOR_LESSTHAN ; break;
+ case 0x06: $operator = PHPExcel_Cell_DataValidation::OPERATOR_GREATERTHANOREQUAL; break;
+ case 0x07: $operator = PHPExcel_Cell_DataValidation::OPERATOR_LESSTHANOREQUAL ; break;
+ }
+
+ // offset: 4; size: var; title of the prompt box
+ $offset = 4;
+ $string = self::_readUnicodeStringLong(substr($recordData, $offset));
+ $promptTitle = $string['value'] !== chr(0) ?
+ $string['value'] : '';
+ $offset += $string['size'];
+
+ // offset: var; size: var; title of the error box
+ $string = self::_readUnicodeStringLong(substr($recordData, $offset));
+ $errorTitle = $string['value'] !== chr(0) ?
+ $string['value'] : '';
+ $offset += $string['size'];
+
+ // offset: var; size: var; text of the prompt box
+ $string = self::_readUnicodeStringLong(substr($recordData, $offset));
+ $prompt = $string['value'] !== chr(0) ?
+ $string['value'] : '';
+ $offset += $string['size'];
+
+ // offset: var; size: var; text of the error box
+ $string = self::_readUnicodeStringLong(substr($recordData, $offset));
+ $error = $string['value'] !== chr(0) ?
+ $string['value'] : '';
+ $offset += $string['size'];
+
+ // offset: var; size: 2; size of the formula data for the first condition
+ $sz1 = self::_GetInt2d($recordData, $offset);
+ $offset += 2;
+
+ // offset: var; size: 2; not used
+ $offset += 2;
+
+ // offset: var; size: $sz1; formula data for first condition (without size field)
+ $formula1 = substr($recordData, $offset, $sz1);
+ $formula1 = pack('v', $sz1) . $formula1; // prepend the length
+ try {
+ $formula1 = $this->_getFormulaFromStructure($formula1);
+
+ // in list type validity, null characters are used as item separators
+ if ($type == PHPExcel_Cell_DataValidation::TYPE_LIST) {
+ $formula1 = str_replace(chr(0), ',', $formula1);
+ }
+ } catch (Exception $e) {
+ return;
+ }
+ $offset += $sz1;
+
+ // offset: var; size: 2; size of the formula data for the first condition
+ $sz2 = self::_GetInt2d($recordData, $offset);
+ $offset += 2;
+
+ // offset: var; size: 2; not used
+ $offset += 2;
+
+ // offset: var; size: $sz2; formula data for second condition (without size field)
+ $formula2 = substr($recordData, $offset, $sz2);
+ $formula2 = pack('v', $sz2) . $formula2; // prepend the length
+ try {
+ $formula2 = $this->_getFormulaFromStructure($formula2);
+ } catch (Exception $e) {
+ return;
+ }
+ $offset += $sz2;
+
+ // offset: var; size: var; cell range address list with
+ $cellRangeAddressList = $this->_readBIFF8CellRangeAddressList(substr($recordData, $offset));
+ $cellRangeAddresses = $cellRangeAddressList['cellRangeAddresses'];
+
+ foreach ($cellRangeAddresses as $cellRange) {
+ $stRange = $this->_phpSheet->shrinkRangeToFit($cellRange);
+ $stRange = PHPExcel_Cell::extractAllCellReferencesInRange($stRange);
+ foreach ($stRange as $coordinate) {
+ $objValidation = $this->_phpSheet->getCell($coordinate)->getDataValidation();
+ $objValidation->setType($type);
+ $objValidation->setErrorStyle($errorStyle);
+ $objValidation->setAllowBlank((bool)$allowBlank);
+ $objValidation->setShowInputMessage((bool)$showInputMessage);
+ $objValidation->setShowErrorMessage((bool)$showErrorMessage);
+ $objValidation->setShowDropDown(!$suppressDropDown);
+ $objValidation->setOperator($operator);
+ $objValidation->setErrorTitle($errorTitle);
+ $objValidation->setError($error);
+ $objValidation->setPromptTitle($promptTitle);
+ $objValidation->setPrompt($prompt);
+ $objValidation->setFormula1($formula1);
+ $objValidation->setFormula2($formula2);
+ }
+ }
+
+ }
+
+
+ /**
+ * Read SHEETLAYOUT record. Stores sheet tab color information.
+ */
+ private function _readSheetLayout()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ // local pointer in record data
+ $offset = 0;
+
+ if (!$this->_readDataOnly) {
+ // offset: 0; size: 2; repeated record identifier 0x0862
+
+ // offset: 2; size: 10; not used
+
+ // offset: 12; size: 4; size of record data
+ // Excel 2003 uses size of 0x14 (documented), Excel 2007 uses size of 0x28 (not documented?)
+ $sz = self::_GetInt4d($recordData, 12);
+
+ switch ($sz) {
+ case 0x14:
+ // offset: 16; size: 2; color index for sheet tab
+ $colorIndex = self::_GetInt2d($recordData, 16);
+ $color = self::_readColor($colorIndex,$this->_palette,$this->_version);
+ $this->_phpSheet->getTabColor()->setRGB($color['rgb']);
+ break;
+
+ case 0x28:
+ // TODO: Investigate structure for .xls SHEETLAYOUT record as saved by MS Office Excel 2007
+ return;
+ break;
+ }
+ }
+ }
+
+
+ /**
+ * Read SHEETPROTECTION record (FEATHEADR)
+ */
+ private function _readSheetProtection()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ if ($this->_readDataOnly) {
+ return;
+ }
+
+ // offset: 0; size: 2; repeated record header
+
+ // offset: 2; size: 2; FRT cell reference flag (=0 currently)
+
+ // offset: 4; size: 8; Currently not used and set to 0
+
+ // offset: 12; size: 2; Shared feature type index (2=Enhanced Protetion, 4=SmartTag)
+ $isf = self::_GetInt2d($recordData, 12);
+ if ($isf != 2) {
+ return;
+ }
+
+ // offset: 14; size: 1; =1 since this is a feat header
+
+ // offset: 15; size: 4; size of rgbHdrSData
+
+ // rgbHdrSData, assume "Enhanced Protection"
+ // offset: 19; size: 2; option flags
+ $options = self::_GetInt2d($recordData, 19);
+
+ // bit: 0; mask 0x0001; 1 = user may edit objects, 0 = users must not edit objects
+ $bool = (0x0001 & $options) >> 0;
+ $this->_phpSheet->getProtection()->setObjects(!$bool);
+
+ // bit: 1; mask 0x0002; edit scenarios
+ $bool = (0x0002 & $options) >> 1;
+ $this->_phpSheet->getProtection()->setScenarios(!$bool);
+
+ // bit: 2; mask 0x0004; format cells
+ $bool = (0x0004 & $options) >> 2;
+ $this->_phpSheet->getProtection()->setFormatCells(!$bool);
+
+ // bit: 3; mask 0x0008; format columns
+ $bool = (0x0008 & $options) >> 3;
+ $this->_phpSheet->getProtection()->setFormatColumns(!$bool);
+
+ // bit: 4; mask 0x0010; format rows
+ $bool = (0x0010 & $options) >> 4;
+ $this->_phpSheet->getProtection()->setFormatRows(!$bool);
+
+ // bit: 5; mask 0x0020; insert columns
+ $bool = (0x0020 & $options) >> 5;
+ $this->_phpSheet->getProtection()->setInsertColumns(!$bool);
+
+ // bit: 6; mask 0x0040; insert rows
+ $bool = (0x0040 & $options) >> 6;
+ $this->_phpSheet->getProtection()->setInsertRows(!$bool);
+
+ // bit: 7; mask 0x0080; insert hyperlinks
+ $bool = (0x0080 & $options) >> 7;
+ $this->_phpSheet->getProtection()->setInsertHyperlinks(!$bool);
+
+ // bit: 8; mask 0x0100; delete columns
+ $bool = (0x0100 & $options) >> 8;
+ $this->_phpSheet->getProtection()->setDeleteColumns(!$bool);
+
+ // bit: 9; mask 0x0200; delete rows
+ $bool = (0x0200 & $options) >> 9;
+ $this->_phpSheet->getProtection()->setDeleteRows(!$bool);
+
+ // bit: 10; mask 0x0400; select locked cells
+ $bool = (0x0400 & $options) >> 10;
+ $this->_phpSheet->getProtection()->setSelectLockedCells(!$bool);
+
+ // bit: 11; mask 0x0800; sort cell range
+ $bool = (0x0800 & $options) >> 11;
+ $this->_phpSheet->getProtection()->setSort(!$bool);
+
+ // bit: 12; mask 0x1000; auto filter
+ $bool = (0x1000 & $options) >> 12;
+ $this->_phpSheet->getProtection()->setAutoFilter(!$bool);
+
+ // bit: 13; mask 0x2000; pivot tables
+ $bool = (0x2000 & $options) >> 13;
+ $this->_phpSheet->getProtection()->setPivotTables(!$bool);
+
+ // bit: 14; mask 0x4000; select unlocked cells
+ $bool = (0x4000 & $options) >> 14;
+ $this->_phpSheet->getProtection()->setSelectUnlockedCells(!$bool);
+
+ // offset: 21; size: 2; not used
+ }
+
+
+ /**
+ * Read RANGEPROTECTION record
+ * Reading of this record is based on Microsoft Office Excel 97-2000 Binary File Format Specification,
+ * where it is referred to as FEAT record
+ */
+ private function _readRangeProtection()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ // local pointer in record data
+ $offset = 0;
+
+ if (!$this->_readDataOnly) {
+ $offset += 12;
+
+ // offset: 12; size: 2; shared feature type, 2 = enhanced protection, 4 = smart tag
+ $isf = self::_GetInt2d($recordData, 12);
+ if ($isf != 2) {
+ // we only read FEAT records of type 2
+ return;
+ }
+ $offset += 2;
+
+ $offset += 5;
+
+ // offset: 19; size: 2; count of ref ranges this feature is on
+ $cref = self::_GetInt2d($recordData, 19);
+ $offset += 2;
+
+ $offset += 6;
+
+ // offset: 27; size: 8 * $cref; list of cell ranges (like in hyperlink record)
+ $cellRanges = array();
+ for ($i = 0; $i < $cref; ++$i) {
+ try {
+ $cellRange = $this->_readBIFF8CellRangeAddressFixed(substr($recordData, 27 + 8 * $i, 8));
+ } catch (Exception $e) {
+ return;
+ }
+ $cellRanges[] = $cellRange;
+ $offset += 8;
+ }
+
+ // offset: var; size: var; variable length of feature specific data
+ $rgbFeat = substr($recordData, $offset);
+ $offset += 4;
+
+ // offset: var; size: 4; the encrypted password (only 16-bit although field is 32-bit)
+ $wPassword = self::_GetInt4d($recordData, $offset);
+ $offset += 4;
+
+ // Apply range protection to sheet
+ if ($cellRanges) {
+ $this->_phpSheet->protectCells(implode(' ', $cellRanges), strtoupper(dechex($wPassword)), true);
+ }
+ }
+ }
+
+
+ /**
+ * Read IMDATA record
+ */
+ private function _readImData()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+
+ // get spliced record data
+ $splicedRecordData = $this->_getSplicedRecordData();
+ $recordData = $splicedRecordData['recordData'];
+
+ // UNDER CONSTRUCTION
+
+ // offset: 0; size: 2; image format
+ $cf = self::_GetInt2d($recordData, 0);
+
+ // offset: 2; size: 2; environment from which the file was written
+ $env = self::_GetInt2d($recordData, 2);
+
+ // offset: 4; size: 4; length of the image data
+ $lcb = self::_GetInt4d($recordData, 4);
+
+ // offset: 8; size: var; image data
+ $iData = substr($recordData, 8);
+
+ switch ($cf) {
+ case 0x09: // Windows bitmap format
+ // BITMAPCOREINFO
+ // 1. BITMAPCOREHEADER
+ // offset: 0; size: 4; bcSize, Specifies the number of bytes required by the structure
+ $bcSize = self::_GetInt4d($iData, 0);
+// var_dump($bcSize);
+
+ // offset: 4; size: 2; bcWidth, specifies the width of the bitmap, in pixels
+ $bcWidth = self::_GetInt2d($iData, 4);
+// var_dump($bcWidth);
+
+ // offset: 6; size: 2; bcHeight, specifies the height of the bitmap, in pixels.
+ $bcHeight = self::_GetInt2d($iData, 6);
+// var_dump($bcHeight);
+ $ih = imagecreatetruecolor($bcWidth, $bcHeight);
+
+ // offset: 8; size: 2; bcPlanes, specifies the number of planes for the target device. This value must be 1
+
+ // offset: 10; size: 2; bcBitCount specifies the number of bits-per-pixel. This value must be 1, 4, 8, or 24
+ $bcBitCount = self::_GetInt2d($iData, 10);
+// var_dump($bcBitCount);
+
+ $rgbString = substr($iData, 12);
+ $rgbTriples = array();
+ while (strlen($rgbString) > 0) {
+ $rgbTriples[] = unpack('Cb/Cg/Cr', $rgbString);
+ $rgbString = substr($rgbString, 3);
+ }
+ $x = 0;
+ $y = 0;
+ foreach ($rgbTriples as $i => $rgbTriple) {
+ $color = imagecolorallocate($ih, $rgbTriple['r'], $rgbTriple['g'], $rgbTriple['b']);
+ imagesetpixel($ih, $x, $bcHeight - 1 - $y, $color);
+ $x = ($x + 1) % $bcWidth;
+ $y = $y + floor(($x + 1) / $bcWidth);
+ }
+ //imagepng($ih, 'image.png');
+
+ $drawing = new PHPExcel_Worksheet_Drawing();
+ $drawing->setPath($filename);
+ $drawing->setWorksheet($this->_phpSheet);
+
+ break;
+
+ case 0x02: // Windows metafile or Macintosh PICT format
+ case 0x0e: // native format
+ default;
+ break;
+
+ }
+
+ // _getSplicedRecordData() takes care of moving current position in data stream
+ }
+
+
+ /**
+ * Read a free CONTINUE record. Free CONTINUE record may be a camouflaged MSODRAWING record
+ * When MSODRAWING data on a sheet exceeds 8224 bytes, CONTINUE records are used instead. Undocumented.
+ * In this case, we must treat the CONTINUE record as a MSODRAWING record
+ */
+ private function _readContinue()
+ {
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $recordData = substr($this->_data, $this->_pos + 4, $length);
+
+ // check if we are reading drawing data
+ // this is in case a free CONTINUE record occurs in other circumstances we are unaware of
+ if ($this->_drawingData == '') {
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ return;
+ }
+
+ // check if record data is at least 4 bytes long, otherwise there is no chance this is MSODRAWING data
+ if ($length < 4) {
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ return;
+ }
+
+ // dirty check to see if CONTINUE record could be a camouflaged MSODRAWING record
+ // look inside CONTINUE record to see if it looks like a part of an Escher stream
+ // we know that Escher stream may be split at least at
+ // 0xF003 MsofbtSpgrContainer
+ // 0xF004 MsofbtSpContainer
+ // 0xF00D MsofbtClientTextbox
+ $validSplitPoints = array(0xF003, 0xF004, 0xF00D); // add identifiers if we find more
+
+ $splitPoint = self::_GetInt2d($recordData, 2);
+ if (in_array($splitPoint, $validSplitPoints)) {
+ // get spliced record data (and move pointer to next record)
+ $splicedRecordData = $this->_getSplicedRecordData();
+ $this->_drawingData .= $splicedRecordData['recordData'];
+
+ return;
+ }
+
+ // move stream pointer to next record
+ $this->_pos += 4 + $length;
+
+ }
+
+
+ /**
+ * Reads a record from current position in data stream and continues reading data as long as CONTINUE
+ * records are found. Splices the record data pieces and returns the combined string as if record data
+ * is in one piece.
+ * Moves to next current position in data stream to start of next record different from a CONtINUE record
+ *
+ * @return array
+ */
+ private function _getSplicedRecordData()
+ {
+ $data = '';
+ $spliceOffsets = array();
+
+ $i = 0;
+ $spliceOffsets[0] = 0;
+
+ do {
+ ++$i;
+
+ // offset: 0; size: 2; identifier
+ $identifier = self::_GetInt2d($this->_data, $this->_pos);
+ // offset: 2; size: 2; length
+ $length = self::_GetInt2d($this->_data, $this->_pos + 2);
+ $data .= substr($this->_data, $this->_pos + 4, $length);
+
+ $spliceOffsets[$i] = $spliceOffsets[$i - 1] + $length;
+
+ $this->_pos += 4 + $length;
+ $nextIdentifier = self::_GetInt2d($this->_data, $this->_pos);
+ }
+ while ($nextIdentifier == self::XLS_Type_CONTINUE);
+
+ $splicedData = array(
+ 'recordData' => $data,
+ 'spliceOffsets' => $spliceOffsets,
+ );
+
+ return $splicedData;
+
+ }
+
+
+ /**
+ * Convert formula structure into human readable Excel formula like 'A3+A5*5'
+ *
+ * @param string $formulaStructure The complete binary data for the formula
+ * @param string $baseCell Base cell, only needed when formula contains tRefN tokens, e.g. with shared formulas
+ * @return string Human readable formula
+ */
+ private function _getFormulaFromStructure($formulaStructure, $baseCell = 'A1')
+ {
+ // offset: 0; size: 2; size of the following formula data
+ $sz = self::_GetInt2d($formulaStructure, 0);
+
+ // offset: 2; size: sz
+ $formulaData = substr($formulaStructure, 2, $sz);
+
+ // for debug: dump the formula data
+ //echo '';
+ //echo 'size: ' . $sz . "\n";
+ //echo 'the entire formula data: ';
+ //Debug::dump($formulaData);
+ //echo "\n----\n";
+
+ // offset: 2 + sz; size: variable (optional)
+ if (strlen($formulaStructure) > 2 + $sz) {
+ $additionalData = substr($formulaStructure, 2 + $sz);
+
+ // for debug: dump the additional data
+ //echo 'the entire additional data: ';
+ //Debug::dump($additionalData);
+ //echo "\n----\n";
+
+ } else {
+ $additionalData = '';
+ }
+
+ return $this->_getFormulaFromData($formulaData, $additionalData, $baseCell);
+ }
+
+
+ /**
+ * Take formula data and additional data for formula and return human readable formula
+ *
+ * @param string $formulaData The binary data for the formula itself
+ * @param string $additionalData Additional binary data going with the formula
+ * @param string $baseCell Base cell, only needed when formula contains tRefN tokens, e.g. with shared formulas
+ * @return string Human readable formula
+ */
+ private function _getFormulaFromData($formulaData, $additionalData = '', $baseCell = 'A1')
+ {
+ // start parsing the formula data
+ $tokens = array();
+
+ while (strlen($formulaData) > 0 and $token = $this->_getNextToken($formulaData, $baseCell)) {
+ $tokens[] = $token;
+ $formulaData = substr($formulaData, $token['size']);
+
+ // for debug: dump the token
+ //var_dump($token);
+ }
+
+ $formulaString = $this->_createFormulaFromTokens($tokens, $additionalData);
+
+ return $formulaString;
+ }
+
+
+ /**
+ * Take array of tokens together with additional data for formula and return human readable formula
+ *
+ * @param array $tokens
+ * @param array $additionalData Additional binary data going with the formula
+ * @param string $baseCell Base cell, only needed when formula contains tRefN tokens, e.g. with shared formulas
+ * @return string Human readable formula
+ */
+ private function _createFormulaFromTokens($tokens, $additionalData)
+ {
+ // empty formula?
+ if (empty($tokens)) {
+ return '';
+ }
+
+ $formulaStrings = array();
+ foreach ($tokens as $token) {
+ // initialize spaces
+ $space0 = isset($space0) ? $space0 : ''; // spaces before next token, not tParen
+ $space1 = isset($space1) ? $space1 : ''; // carriage returns before next token, not tParen
+ $space2 = isset($space2) ? $space2 : ''; // spaces before opening parenthesis
+ $space3 = isset($space3) ? $space3 : ''; // carriage returns before opening parenthesis
+ $space4 = isset($space4) ? $space4 : ''; // spaces before closing parenthesis
+ $space5 = isset($space5) ? $space5 : ''; // carriage returns before closing parenthesis
+
+ switch ($token['name']) {
+ case 'tAdd': // addition
+ case 'tConcat': // addition
+ case 'tDiv': // division
+ case 'tEQ': // equality
+ case 'tGE': // greater than or equal
+ case 'tGT': // greater than
+ case 'tIsect': // intersection
+ case 'tLE': // less than or equal
+ case 'tList': // less than or equal
+ case 'tLT': // less than
+ case 'tMul': // multiplication
+ case 'tNE': // multiplication
+ case 'tPower': // power
+ case 'tRange': // range
+ case 'tSub': // subtraction
+ $op2 = array_pop($formulaStrings);
+ $op1 = array_pop($formulaStrings);
+ $formulaStrings[] = "$op1$space1$space0{$token['data']}$op2";
+ unset($space0, $space1);
+ break;
+ case 'tUplus': // unary plus
+ case 'tUminus': // unary minus
+ $op = array_pop($formulaStrings);
+ $formulaStrings[] = "$space1$space0{$token['data']}$op";
+ unset($space0, $space1);
+ break;
+ case 'tPercent': // percent sign
+ $op = array_pop($formulaStrings);
+ $formulaStrings[] = "$op$space1$space0{$token['data']}";
+ unset($space0, $space1);
+ break;
+ case 'tAttrVolatile': // indicates volatile function
+ case 'tAttrIf':
+ case 'tAttrSkip':
+ case 'tAttrChoose':
+ // token is only important for Excel formula evaluator
+ // do nothing
+ break;
+ case 'tAttrSpace': // space / carriage return
+ // space will be used when next token arrives, do not alter formulaString stack
+ switch ($token['data']['spacetype']) {
+ case 'type0':
+ $space0 = str_repeat(' ', $token['data']['spacecount']);
+ break;
+ case 'type1':
+ $space1 = str_repeat("\n", $token['data']['spacecount']);
+ break;
+ case 'type2':
+ $space2 = str_repeat(' ', $token['data']['spacecount']);
+ break;
+ case 'type3':
+ $space3 = str_repeat("\n", $token['data']['spacecount']);
+ break;
+ case 'type4':
+ $space4 = str_repeat(' ', $token['data']['spacecount']);
+ break;
+ case 'type5':
+ $space5 = str_repeat("\n", $token['data']['spacecount']);
+ break;
+ }
+ break;
+ case 'tAttrSum': // SUM function with one parameter
+ $op = array_pop($formulaStrings);
+ $formulaStrings[] = "{$space1}{$space0}SUM($op)";
+ unset($space0, $space1);
+ break;
+ case 'tFunc': // function with fixed number of arguments
+ case 'tFuncV': // function with variable number of arguments
+ if ($token['data']['function'] != '') {
+ // normal function
+ $ops = array(); // array of operators
+ for ($i = 0; $i < $token['data']['args']; ++$i) {
+ $ops[] = array_pop($formulaStrings);
+ }
+ $ops = array_reverse($ops);
+ $formulaStrings[] = "$space1$space0{$token['data']['function']}(" . implode(',', $ops) . ")";
+ unset($space0, $space1);
+ } else {
+ // add-in function
+ $ops = array(); // array of operators
+ for ($i = 0; $i < $token['data']['args'] - 1; ++$i) {
+ $ops[] = array_pop($formulaStrings);
+ }
+ $ops = array_reverse($ops);
+ $function = array_pop($formulaStrings);
+ $formulaStrings[] = "$space1$space0$function(" . implode(',', $ops) . ")";
+ unset($space0, $space1);
+ }
+ break;
+ case 'tParen': // parenthesis
+ $expression = array_pop($formulaStrings);
+ $formulaStrings[] = "$space3$space2($expression$space5$space4)";
+ unset($space2, $space3, $space4, $space5);
+ break;
+ case 'tArray': // array constant
+ $constantArray = self::_readBIFF8ConstantArray($additionalData);
+ $formulaStrings[] = $space1 . $space0 . $constantArray['value'];
+ $additionalData = substr($additionalData, $constantArray['size']); // bite of chunk of additional data
+ unset($space0, $space1);
+ break;
+ case 'tMemArea':
+ // bite off chunk of additional data
+ $cellRangeAddressList = $this->_readBIFF8CellRangeAddressList($additionalData);
+ $additionalData = substr($additionalData, $cellRangeAddressList['size']);
+ $formulaStrings[] = "$space1$space0{$token['data']}";
+ unset($space0, $space1);
+ break;
+ case 'tArea': // cell range address
+ case 'tBool': // boolean
+ case 'tErr': // error code
+ case 'tInt': // integer
+ case 'tMemErr':
+ case 'tMemFunc':
+ case 'tMissArg':
+ case 'tName':
+ case 'tNameX':
+ case 'tNum': // number
+ case 'tRef': // single cell reference
+ case 'tRef3d': // 3d cell reference
+ case 'tArea3d': // 3d cell range reference
+ case 'tRefN':
+ case 'tAreaN':
+ case 'tStr': // string
+ $formulaStrings[] = "$space1$space0{$token['data']}";
+ unset($space0, $space1);
+ break;
+ }
+ }
+ $formulaString = $formulaStrings[0];
+
+ // for debug: dump the human readable formula
+ //echo '----' . "\n";
+ //echo 'Formula: ' . $formulaString;
+
+ return $formulaString;
+ }
+
+
+ /**
+ * Fetch next token from binary formula data
+ *
+ * @param string Formula data
+ * @param string $baseCell Base cell, only needed when formula contains tRefN tokens, e.g. with shared formulas
+ * @return array
+ * @throws Exception
+ */
+ private function _getNextToken($formulaData, $baseCell = 'A1')
+ {
+ // offset: 0; size: 1; token id
+ $id = ord($formulaData[0]); // token id
+ $name = false; // initialize token name
+
+ switch ($id) {
+ case 0x03: $name = 'tAdd'; $size = 1; $data = '+'; break;
+ case 0x04: $name = 'tSub'; $size = 1; $data = '-'; break;
+ case 0x05: $name = 'tMul'; $size = 1; $data = '*'; break;
+ case 0x06: $name = 'tDiv'; $size = 1; $data = '/'; break;
+ case 0x07: $name = 'tPower'; $size = 1; $data = '^'; break;
+ case 0x08: $name = 'tConcat'; $size = 1; $data = '&'; break;
+ case 0x09: $name = 'tLT'; $size = 1; $data = '<'; break;
+ case 0x0A: $name = 'tLE'; $size = 1; $data = '<='; break;
+ case 0x0B: $name = 'tEQ'; $size = 1; $data = '='; break;
+ case 0x0C: $name = 'tGE'; $size = 1; $data = '>='; break;
+ case 0x0D: $name = 'tGT'; $size = 1; $data = '>'; break;
+ case 0x0E: $name = 'tNE'; $size = 1; $data = '<>'; break;
+ case 0x0F: $name = 'tIsect'; $size = 1; $data = ' '; break;
+ case 0x10: $name = 'tList'; $size = 1; $data = ','; break;
+ case 0x11: $name = 'tRange'; $size = 1; $data = ':'; break;
+ case 0x12: $name = 'tUplus'; $size = 1; $data = '+'; break;
+ case 0x13: $name = 'tUminus'; $size = 1; $data = '-'; break;
+ case 0x14: $name = 'tPercent'; $size = 1; $data = '%'; break;
+ case 0x15: // parenthesis
+ $name = 'tParen';
+ $size = 1;
+ $data = null;
+ break;
+ case 0x16: // missing argument
+ $name = 'tMissArg';
+ $size = 1;
+ $data = '';
+ break;
+ case 0x17: // string
+ $name = 'tStr';
+ // offset: 1; size: var; Unicode string, 8-bit string length
+ $string = self::_readUnicodeStringShort(substr($formulaData, 1));
+ $size = 1 + $string['size'];
+ $data = self::_UTF8toExcelDoubleQuoted($string['value']);
+ break;
+ case 0x19: // Special attribute
+ // offset: 1; size: 1; attribute type flags:
+ switch (ord($formulaData[1])) {
+ case 0x01:
+ $name = 'tAttrVolatile';
+ $size = 4;
+ $data = null;
+ break;
+ case 0x02:
+ $name = 'tAttrIf';
+ $size = 4;
+ $data = null;
+ break;
+ case 0x04:
+ $name = 'tAttrChoose';
+ // offset: 2; size: 2; number of choices in the CHOOSE function ($nc, number of parameters decreased by 1)
+ $nc = self::_GetInt2d($formulaData, 2);
+ // offset: 4; size: 2 * $nc
+ // offset: 4 + 2 * $nc; size: 2
+ $size = 2 * $nc + 6;
+ $data = null;
+ break;
+ case 0x08:
+ $name = 'tAttrSkip';
+ $size = 4;
+ $data = null;
+ break;
+ case 0x10:
+ $name = 'tAttrSum';
+ $size = 4;
+ $data = null;
+ break;
+ case 0x40:
+ case 0x41:
+ $name = 'tAttrSpace';
+ $size = 4;
+ // offset: 2; size: 2; space type and position
+ switch (ord($formulaData[2])) {
+ case 0x00:
+ $spacetype = 'type0';
+ break;
+ case 0x01:
+ $spacetype = 'type1';
+ break;
+ case 0x02:
+ $spacetype = 'type2';
+ break;
+ case 0x03:
+ $spacetype = 'type3';
+ break;
+ case 0x04:
+ $spacetype = 'type4';
+ break;
+ case 0x05:
+ $spacetype = 'type5';
+ break;
+ default:
+ throw new Exception('Unrecognized space type in tAttrSpace token');
+ break;
+ }
+ // offset: 3; size: 1; number of inserted spaces/carriage returns
+ $spacecount = ord($formulaData[3]);
+
+ $data = array('spacetype' => $spacetype, 'spacecount' => $spacecount);
+ break;
+ default:
+ throw new Exception('Unrecognized attribute flag in tAttr token');
+ break;
+ }
+ break;
+ case 0x1C: // error code
+ // offset: 1; size: 1; error code
+ $name = 'tErr';
+ $size = 2;
+ $data = self::_mapErrorCode(ord($formulaData[1]));
+ break;
+ case 0x1D: // boolean
+ // offset: 1; size: 1; 0 = false, 1 = true;
+ $name = 'tBool';
+ $size = 2;
+ $data = ord($formulaData[1]) ? 'TRUE' : 'FALSE';
+ break;
+ case 0x1E: // integer
+ // offset: 1; size: 2; unsigned 16-bit integer
+ $name = 'tInt';
+ $size = 3;
+ $data = self::_GetInt2d($formulaData, 1);
+ break;
+ case 0x1F: // number
+ // offset: 1; size: 8;
+ $name = 'tNum';
+ $size = 9;
+ $data = self::_extractNumber(substr($formulaData, 1));
+ $data = str_replace(',', '.', (string)$data); // in case non-English locale
+ break;
+ case 0x20: // array constant
+ case 0x40:
+ case 0x60:
+ // offset: 1; size: 7; not used
+ $name = 'tArray';
+ $size = 8;
+ $data = null;
+ break;
+ case 0x21: // function with fixed number of arguments
+ case 0x41:
+ case 0x61:
+ $name = 'tFunc';
+ $size = 3;
+ // offset: 1; size: 2; index to built-in sheet function
+ switch (self::_GetInt2d($formulaData, 1)) {
+ case 2: $function = 'ISNA'; $args = 1; break;
+ case 3: $function = 'ISERROR'; $args = 1; break;
+ case 10: $function = 'NA'; $args = 0; break;
+ case 15: $function = 'SIN'; $args = 1; break;
+ case 16: $function = 'COS'; $args = 1; break;
+ case 17: $function = 'TAN'; $args = 1; break;
+ case 18: $function = 'ATAN'; $args = 1; break;
+ case 19: $function = 'PI'; $args = 0; break;
+ case 20: $function = 'SQRT'; $args = 1; break;
+ case 21: $function = 'EXP'; $args = 1; break;
+ case 22: $function = 'LN'; $args = 1; break;
+ case 23: $function = 'LOG10'; $args = 1; break;
+ case 24: $function = 'ABS'; $args = 1; break;
+ case 25: $function = 'INT'; $args = 1; break;
+ case 26: $function = 'SIGN'; $args = 1; break;
+ case 27: $function = 'ROUND'; $args = 2; break;
+ case 30: $function = 'REPT'; $args = 2; break;
+ case 31: $function = 'MID'; $args = 3; break;
+ case 32: $function = 'LEN'; $args = 1; break;
+ case 33: $function = 'VALUE'; $args = 1; break;
+ case 34: $function = 'TRUE'; $args = 0; break;
+ case 35: $function = 'FALSE'; $args = 0; break;
+ case 38: $function = 'NOT'; $args = 1; break;
+ case 39: $function = 'MOD'; $args = 2; break;
+ case 40: $function = 'DCOUNT'; $args = 3; break;
+ case 41: $function = 'DSUM'; $args = 3; break;
+ case 42: $function = 'DAVERAGE'; $args = 3; break;
+ case 43: $function = 'DMIN'; $args = 3; break;
+ case 44: $function = 'DMAX'; $args = 3; break;
+ case 45: $function = 'DSTDEV'; $args = 3; break;
+ case 48: $function = 'TEXT'; $args = 2; break;
+ case 61: $function = 'MIRR'; $args = 3; break;
+ case 63: $function = 'RAND'; $args = 0; break;
+ case 65: $function = 'DATE'; $args = 3; break;
+ case 66: $function = 'TIME'; $args = 3; break;
+ case 67: $function = 'DAY'; $args = 1; break;
+ case 68: $function = 'MONTH'; $args = 1; break;
+ case 69: $function = 'YEAR'; $args = 1; break;
+ case 71: $function = 'HOUR'; $args = 1; break;
+ case 72: $function = 'MINUTE'; $args = 1; break;
+ case 73: $function = 'SECOND'; $args = 1; break;
+ case 74: $function = 'NOW'; $args = 0; break;
+ case 75: $function = 'AREAS'; $args = 1; break;
+ case 76: $function = 'ROWS'; $args = 1; break;
+ case 77: $function = 'COLUMNS'; $args = 1; break;
+ case 83: $function = 'TRANSPOSE'; $args = 1; break;
+ case 86: $function = 'TYPE'; $args = 1; break;
+ case 97: $function = 'ATAN2'; $args = 2; break;
+ case 98: $function = 'ASIN'; $args = 1; break;
+ case 99: $function = 'ACOS'; $args = 1; break;
+ case 105: $function = 'ISREF'; $args = 1; break;
+ case 111: $function = 'CHAR'; $args = 1; break;
+ case 112: $function = 'LOWER'; $args = 1; break;
+ case 113: $function = 'UPPER'; $args = 1; break;
+ case 114: $function = 'PROPER'; $args = 1; break;
+ case 117: $function = 'EXACT'; $args = 2; break;
+ case 118: $function = 'TRIM'; $args = 1; break;
+ case 119: $function = 'REPLACE'; $args = 4; break;
+ case 121: $function = 'CODE'; $args = 1; break;
+ case 126: $function = 'ISERR'; $args = 1; break;
+ case 127: $function = 'ISTEXT'; $args = 1; break;
+ case 128: $function = 'ISNUMBER'; $args = 1; break;
+ case 129: $function = 'ISBLANK'; $args = 1; break;
+ case 130: $function = 'T'; $args = 1; break;
+ case 131: $function = 'N'; $args = 1; break;
+ case 140: $function = 'DATEVALUE'; $args = 1; break;
+ case 141: $function = 'TIMEVALUE'; $args = 1; break;
+ case 142: $function = 'SLN'; $args = 3; break;
+ case 143: $function = 'SYD'; $args = 4; break;
+ case 162: $function = 'CLEAN'; $args = 1; break;
+ case 163: $function = 'MDETERM'; $args = 1; break;
+ case 164: $function = 'MINVERSE'; $args = 1; break;
+ case 165: $function = 'MMULT'; $args = 2; break;
+ case 184: $function = 'FACT'; $args = 1; break;
+ case 189: $function = 'DPRODUCT'; $args = 3; break;
+ case 190: $function = 'ISNONTEXT'; $args = 1; break;
+ case 195: $function = 'DSTDEVP'; $args = 3; break;
+ case 196: $function = 'DVARP'; $args = 3; break;
+ case 198: $function = 'ISLOGICAL'; $args = 1; break;
+ case 199: $function = 'DCOUNTA'; $args = 3; break;
+ case 207: $function = 'REPLACEB'; $args = 4; break;
+ case 210: $function = 'MIDB'; $args = 3; break;
+ case 211: $function = 'LENB'; $args = 1; break;
+ case 212: $function = 'ROUNDUP'; $args = 2; break;
+ case 213: $function = 'ROUNDDOWN'; $args = 2; break;
+ case 214: $function = 'ASC'; $args = 1; break;
+ case 215: $function = 'DBCS'; $args = 1; break;
+ case 221: $function = 'TODAY'; $args = 0; break;
+ case 229: $function = 'SINH'; $args = 1; break;
+ case 230: $function = 'COSH'; $args = 1; break;
+ case 231: $function = 'TANH'; $args = 1; break;
+ case 232: $function = 'ASINH'; $args = 1; break;
+ case 233: $function = 'ACOSH'; $args = 1; break;
+ case 234: $function = 'ATANH'; $args = 1; break;
+ case 235: $function = 'DGET'; $args = 3; break;
+ case 244: $function = 'INFO'; $args = 1; break;
+ case 252: $function = 'FREQUENCY'; $args = 2; break;
+ case 261: $function = 'ERROR.TYPE'; $args = 1; break;
+ case 271: $function = 'GAMMALN'; $args = 1; break;
+ case 273: $function = 'BINOMDIST'; $args = 4; break;
+ case 274: $function = 'CHIDIST'; $args = 2; break;
+ case 275: $function = 'CHIINV'; $args = 2; break;
+ case 276: $function = 'COMBIN'; $args = 2; break;
+ case 277: $function = 'CONFIDENCE'; $args = 3; break;
+ case 278: $function = 'CRITBINOM'; $args = 3; break;
+ case 279: $function = 'EVEN'; $args = 1; break;
+ case 280: $function = 'EXPONDIST'; $args = 3; break;
+ case 281: $function = 'FDIST'; $args = 3; break;
+ case 282: $function = 'FINV'; $args = 3; break;
+ case 283: $function = 'FISHER'; $args = 1; break;
+ case 284: $function = 'FISHERINV'; $args = 1; break;
+ case 285: $function = 'FLOOR'; $args = 2; break;
+ case 286: $function = 'GAMMADIST'; $args = 4; break;
+ case 287: $function = 'GAMMAINV'; $args = 3; break;
+ case 288: $function = 'CEILING'; $args = 2; break;
+ case 289: $function = 'HYPGEOMDIST'; $args = 4; break;
+ case 290: $function = 'LOGNORMDIST'; $args = 3; break;
+ case 291: $function = 'LOGINV'; $args = 3; break;
+ case 292: $function = 'NEGBINOMDIST'; $args = 3; break;
+ case 293: $function = 'NORMDIST'; $args = 4; break;
+ case 294: $function = 'NORMSDIST'; $args = 1; break;
+ case 295: $function = 'NORMINV'; $args = 3; break;
+ case 296: $function = 'NORMSINV'; $args = 1; break;
+ case 297: $function = 'STANDARDIZE'; $args = 3; break;
+ case 298: $function = 'ODD'; $args = 1; break;
+ case 299: $function = 'PERMUT'; $args = 2; break;
+ case 300: $function = 'POISSON'; $args = 3; break;
+ case 301: $function = 'TDIST'; $args = 3; break;
+ case 302: $function = 'WEIBULL'; $args = 4; break;
+ case 303: $function = 'SUMXMY2'; $args = 2; break;
+ case 304: $function = 'SUMX2MY2'; $args = 2; break;
+ case 305: $function = 'SUMX2PY2'; $args = 2; break;
+ case 306: $function = 'CHITEST'; $args = 2; break;
+ case 307: $function = 'CORREL'; $args = 2; break;
+ case 308: $function = 'COVAR'; $args = 2; break;
+ case 309: $function = 'FORECAST'; $args = 3; break;
+ case 310: $function = 'FTEST'; $args = 2; break;
+ case 311: $function = 'INTERCEPT'; $args = 2; break;
+ case 312: $function = 'PEARSON'; $args = 2; break;
+ case 313: $function = 'RSQ'; $args = 2; break;
+ case 314: $function = 'STEYX'; $args = 2; break;
+ case 315: $function = 'SLOPE'; $args = 2; break;
+ case 316: $function = 'TTEST'; $args = 4; break;
+ case 325: $function = 'LARGE'; $args = 2; break;
+ case 326: $function = 'SMALL'; $args = 2; break;
+ case 327: $function = 'QUARTILE'; $args = 2; break;
+ case 328: $function = 'PERCENTILE'; $args = 2; break;
+ case 331: $function = 'TRIMMEAN'; $args = 2; break;
+ case 332: $function = 'TINV'; $args = 2; break;
+ case 337: $function = 'POWER'; $args = 2; break;
+ case 342: $function = 'RADIANS'; $args = 1; break;
+ case 343: $function = 'DEGREES'; $args = 1; break;
+ case 346: $function = 'COUNTIF'; $args = 2; break;
+ case 347: $function = 'COUNTBLANK'; $args = 1; break;
+ case 350: $function = 'ISPMT'; $args = 4; break;
+ case 351: $function = 'DATEDIF'; $args = 3; break;
+ case 352: $function = 'DATESTRING'; $args = 1; break;
+ case 353: $function = 'NUMBERSTRING'; $args = 2; break;
+ case 360: $function = 'PHONETIC'; $args = 1; break;
+ case 368: $function = 'BAHTTEXT'; $args = 1; break;
+ default:
+ throw new Exception('Unrecognized function in formula');
+ break;
+ }
+ $data = array('function' => $function, 'args' => $args);
+ break;
+ case 0x22: // function with variable number of arguments
+ case 0x42:
+ case 0x62:
+ $name = 'tFuncV';
+ $size = 4;
+ // offset: 1; size: 1; number of arguments
+ $args = ord($formulaData[1]);
+ // offset: 2: size: 2; index to built-in sheet function
+ $index = self::_GetInt2d($formulaData, 2);
+ switch ($index) {
+ case 0: $function = 'COUNT'; break;
+ case 1: $function = 'IF'; break;
+ case 4: $function = 'SUM'; break;
+ case 5: $function = 'AVERAGE'; break;
+ case 6: $function = 'MIN'; break;
+ case 7: $function = 'MAX'; break;
+ case 8: $function = 'ROW'; break;
+ case 9: $function = 'COLUMN'; break;
+ case 11: $function = 'NPV'; break;
+ case 12: $function = 'STDEV'; break;
+ case 13: $function = 'DOLLAR'; break;
+ case 14: $function = 'FIXED'; break;
+ case 28: $function = 'LOOKUP'; break;
+ case 29: $function = 'INDEX'; break;
+ case 36: $function = 'AND'; break;
+ case 37: $function = 'OR'; break;
+ case 46: $function = 'VAR'; break;
+ case 49: $function = 'LINEST'; break;
+ case 50: $function = 'TREND'; break;
+ case 51: $function = 'LOGEST'; break;
+ case 52: $function = 'GROWTH'; break;
+ case 56: $function = 'PV'; break;
+ case 57: $function = 'FV'; break;
+ case 58: $function = 'NPER'; break;
+ case 59: $function = 'PMT'; break;
+ case 60: $function = 'RATE'; break;
+ case 62: $function = 'IRR'; break;
+ case 64: $function = 'MATCH'; break;
+ case 70: $function = 'WEEKDAY'; break;
+ case 78: $function = 'OFFSET'; break;
+ case 82: $function = 'SEARCH'; break;
+ case 100: $function = 'CHOOSE'; break;
+ case 101: $function = 'HLOOKUP'; break;
+ case 102: $function = 'VLOOKUP'; break;
+ case 109: $function = 'LOG'; break;
+ case 115: $function = 'LEFT'; break;
+ case 116: $function = 'RIGHT'; break;
+ case 120: $function = 'SUBSTITUTE'; break;
+ case 124: $function = 'FIND'; break;
+ case 125: $function = 'CELL'; break;
+ case 144: $function = 'DDB'; break;
+ case 148: $function = 'INDIRECT'; break;
+ case 167: $function = 'IPMT'; break;
+ case 168: $function = 'PPMT'; break;
+ case 169: $function = 'COUNTA'; break;
+ case 183: $function = 'PRODUCT'; break;
+ case 193: $function = 'STDEVP'; break;
+ case 194: $function = 'VARP'; break;
+ case 197: $function = 'TRUNC'; break;
+ case 204: $function = 'USDOLLAR'; break;
+ case 205: $function = 'FINDB'; break;
+ case 206: $function = 'SEARCHB'; break;
+ case 208: $function = 'LEFTB'; break;
+ case 209: $function = 'RIGHTB'; break;
+ case 216: $function = 'RANK'; break;
+ case 219: $function = 'ADDRESS'; break;
+ case 220: $function = 'DAYS360'; break;
+ case 222: $function = 'VDB'; break;
+ case 227: $function = 'MEDIAN'; break;
+ case 228: $function = 'SUMPRODUCT'; break;
+ case 247: $function = 'DB'; break;
+ case 255: $function = ''; break;
+ case 269: $function = 'AVEDEV'; break;
+ case 270: $function = 'BETADIST'; break;
+ case 272: $function = 'BETAINV'; break;
+ case 317: $function = 'PROB'; break;
+ case 318: $function = 'DEVSQ'; break;
+ case 319: $function = 'GEOMEAN'; break;
+ case 320: $function = 'HARMEAN'; break;
+ case 321: $function = 'SUMSQ'; break;
+ case 322: $function = 'KURT'; break;
+ case 323: $function = 'SKEW'; break;
+ case 324: $function = 'ZTEST'; break;
+ case 329: $function = 'PERCENTRANK'; break;
+ case 330: $function = 'MODE'; break;
+ case 336: $function = 'CONCATENATE'; break;
+ case 344: $function = 'SUBTOTAL'; break;
+ case 345: $function = 'SUMIF'; break;
+ case 354: $function = 'ROMAN'; break;
+ case 358: $function = 'GETPIVOTDATA'; break;
+ case 359: $function = 'HYPERLINK'; break;
+ case 361: $function = 'AVERAGEA'; break;
+ case 362: $function = 'MAXA'; break;
+ case 363: $function = 'MINA'; break;
+ case 364: $function = 'STDEVPA'; break;
+ case 365: $function = 'VARPA'; break;
+ case 366: $function = 'STDEVA'; break;
+ case 367: $function = 'VARA'; break;
+ default:
+ throw new Exception('Unrecognized function in formula');
+ break;
+ }
+ $data = array('function' => $function, 'args' => $args);
+ break;
+ case 0x23: // index to defined name
+ case 0x43:
+ case 0x63:
+ $name = 'tName';
+ $size = 5;
+ // offset: 1; size: 2; one-based index to definedname record
+ $definedNameIndex = self::_GetInt2d($formulaData, 1) - 1;
+ // offset: 2; size: 2; not used
+ $data = $this->_definedname[$definedNameIndex]['name'];
+ break;
+ case 0x24: // single cell reference e.g. A5
+ case 0x44:
+ case 0x64:
+ $name = 'tRef';
+ $size = 5;
+ $data = $this->_readBIFF8CellAddress(substr($formulaData, 1, 4));
+ break;
+ case 0x25: // cell range reference to cells in the same sheet (2d)
+ case 0x45:
+ case 0x65:
+ $name = 'tArea';
+ $size = 9;
+ $data = $this->_readBIFF8CellRangeAddress(substr($formulaData, 1, 8));
+ break;
+ case 0x26: // Constant reference sub-expression
+ case 0x46:
+ case 0x66:
+ $name = 'tMemArea';
+ // offset: 1; size: 4; not used
+ // offset: 5; size: 2; size of the following subexpression
+ $subSize = self::_GetInt2d($formulaData, 5);
+ $size = 7 + $subSize;
+ $data = $this->_getFormulaFromData(substr($formulaData, 7, $subSize));
+ break;
+ case 0x27: // Deleted constant reference sub-expression
+ case 0x47:
+ case 0x67:
+ $name = 'tMemErr';
+ // offset: 1; size: 4; not used
+ // offset: 5; size: 2; size of the following subexpression
+ $subSize = self::_GetInt2d($formulaData, 5);
+ $size = 7 + $subSize;
+ $data = $this->_getFormulaFromData(substr($formulaData, 7, $subSize));
+ break;
+ case 0x29: // Variable reference sub-expression
+ case 0x49:
+ case 0x69:
+ $name = 'tMemFunc';
+ // offset: 1; size: 2; size of the following sub-expression
+ $subSize = self::_GetInt2d($formulaData, 1);
+ $size = 3 + $subSize;
+ $data = $this->_getFormulaFromData(substr($formulaData, 3, $subSize));
+ break;
+
+ case 0x2C: // Relative 2d cell reference reference, used in shared formulas and some other places
+ case 0x4C:
+ case 0x6C:
+ $name = 'tRefN';
+ $size = 5;
+ $data = $this->_readBIFF8CellAddressB(substr($formulaData, 1, 4), $baseCell);
+ break;
+
+ case 0x2D: // Relative 2d range reference
+ case 0x4D:
+ case 0x6D:
+ $name = 'tAreaN';
+ $size = 9;
+ $data = $this->_readBIFF8CellRangeAddressB(substr($formulaData, 1, 8), $baseCell);
+ break;
+
+ case 0x39: // External name
+ case 0x59:
+ case 0x79:
+ $name = 'tNameX';
+ $size = 7;
+ // offset: 1; size: 2; index to REF entry in EXTERNSHEET record
+ // offset: 3; size: 2; one-based index to DEFINEDNAME or EXTERNNAME record
+ $index = self::_GetInt2d($formulaData, 3);
+ // assume index is to EXTERNNAME record
+ $data = $this->_externalNames[$index - 1]['name'];
+ // offset: 5; size: 2; not used
+ break;
+
+ case 0x3A: // 3d reference to cell
+ case 0x5A:
+ case 0x7A:
+ $name = 'tRef3d';
+ $size = 7;
+
+ try {
+ // offset: 1; size: 2; index to REF entry
+ $sheetRange = $this->_readSheetRangeByRefIndex(self::_GetInt2d($formulaData, 1));
+ // offset: 3; size: 4; cell address
+ $cellAddress = $this->_readBIFF8CellAddress(substr($formulaData, 3, 4));
+
+ $data = "$sheetRange!$cellAddress";
+ } catch (Exception $e) {
+ // deleted sheet reference
+ $data = '#REF!';
+ }
+
+ break;
+ case 0x3B: // 3d reference to cell range
+ case 0x5B:
+ case 0x7B:
+ $name = 'tArea3d';
+ $size = 11;
+
+ try {
+ // offset: 1; size: 2; index to REF entry
+ $sheetRange = $this->_readSheetRangeByRefIndex(self::_GetInt2d($formulaData, 1));
+ // offset: 3; size: 8; cell address
+ $cellRangeAddress = $this->_readBIFF8CellRangeAddress(substr($formulaData, 3, 8));
+
+ $data = "$sheetRange!$cellRangeAddress";
+ } catch (Exception $e) {
+ // deleted sheet reference
+ $data = '#REF!';
+ }
+
+ break;
+ // Unknown cases // don't know how to deal with
+ default:
+ throw new Exception('Unrecognized token ' . sprintf('%02X', $id) . ' in formula');
+ break;
+ }
+
+ return array(
+ 'id' => $id,
+ 'name' => $name,
+ 'size' => $size,
+ 'data' => $data,
+ );
+ }
+
+
+ /**
+ * Reads a cell address in BIFF8 e.g. 'A2' or '$A$2'
+ * section 3.3.4
+ *
+ * @param string $cellAddressStructure
+ * @return string
+ */
+ private function _readBIFF8CellAddress($cellAddressStructure)
+ {
+ // offset: 0; size: 2; index to row (0... 65535) (or offset (-32768... 32767))
+ $row = self::_GetInt2d($cellAddressStructure, 0) + 1;
+
+ // offset: 2; size: 2; index to column or column offset + relative flags
+
+ // bit: 7-0; mask 0x00FF; column index
+ $column = PHPExcel_Cell::stringFromColumnIndex(0x00FF & self::_GetInt2d($cellAddressStructure, 2));
+
+ // bit: 14; mask 0x4000; (1 = relative column index, 0 = absolute column index)
+ if (!(0x4000 & self::_GetInt2d($cellAddressStructure, 2))) {
+ $column = '$' . $column;
+ }
+ // bit: 15; mask 0x8000; (1 = relative row index, 0 = absolute row index)
+ if (!(0x8000 & self::_GetInt2d($cellAddressStructure, 2))) {
+ $row = '$' . $row;
+ }
+
+ return $column . $row;
+ }
+
+
+ /**
+ * Reads a cell address in BIFF8 for shared formulas. Uses positive and negative values for row and column
+ * to indicate offsets from a base cell
+ * section 3.3.4
+ *
+ * @param string $cellAddressStructure
+ * @param string $baseCell Base cell, only needed when formula contains tRefN tokens, e.g. with shared formulas
+ * @return string
+ */
+ private function _readBIFF8CellAddressB($cellAddressStructure, $baseCell = 'A1')
+ {
+ list($baseCol, $baseRow) = PHPExcel_Cell::coordinateFromString($baseCell);
+ $baseCol = PHPExcel_Cell::columnIndexFromString($baseCol) - 1;
+
+ // offset: 0; size: 2; index to row (0... 65535) (or offset (-32768... 32767))
+ $rowIndex = self::_GetInt2d($cellAddressStructure, 0);
+ $row = self::_GetInt2d($cellAddressStructure, 0) + 1;
+
+ // offset: 2; size: 2; index to column or column offset + relative flags
+
+ // bit: 7-0; mask 0x00FF; column index
+ $colIndex = 0x00FF & self::_GetInt2d($cellAddressStructure, 2);
+
+ // bit: 14; mask 0x4000; (1 = relative column index, 0 = absolute column index)
+ if (!(0x4000 & self::_GetInt2d($cellAddressStructure, 2))) {
+ $column = PHPExcel_Cell::stringFromColumnIndex($colIndex);
+ $column = '$' . $column;
+ } else {
+ $colIndex = ($colIndex <= 127) ? $colIndex : $colIndex - 256;
+ $column = PHPExcel_Cell::stringFromColumnIndex($baseCol + $colIndex);
+ }
+
+ // bit: 15; mask 0x8000; (1 = relative row index, 0 = absolute row index)
+ if (!(0x8000 & self::_GetInt2d($cellAddressStructure, 2))) {
+ $row = '$' . $row;
+ } else {
+ $rowIndex = ($rowIndex <= 32767) ? $rowIndex : $rowIndex - 65536;
+ $row = $baseRow + $rowIndex;
+ }
+
+ return $column . $row;
+ }
+
+
+ /**
+ * Reads a cell range address in BIFF5 e.g. 'A2:B6' or 'A1'
+ * always fixed range
+ * section 2.5.14
+ *
+ * @param string $subData
+ * @return string
+ * @throws Exception
+ */
+ private function _readBIFF5CellRangeAddressFixed($subData)
+ {
+ // offset: 0; size: 2; index to first row
+ $fr = self::_GetInt2d($subData, 0) + 1;
+
+ // offset: 2; size: 2; index to last row
+ $lr = self::_GetInt2d($subData, 2) + 1;
+
+ // offset: 4; size: 1; index to first column
+ $fc = ord($subData{4});
+
+ // offset: 5; size: 1; index to last column
+ $lc = ord($subData{5});
+
+ // check values
+ if ($fr > $lr || $fc > $lc) {
+ throw new Exception('Not a cell range address');
+ }
+
+ // column index to letter
+ $fc = PHPExcel_Cell::stringFromColumnIndex($fc);
+ $lc = PHPExcel_Cell::stringFromColumnIndex($lc);
+
+ if ($fr == $lr and $fc == $lc) {
+ return "$fc$fr";
+ }
+ return "$fc$fr:$lc$lr";
+ }
+
+
+ /**
+ * Reads a cell range address in BIFF8 e.g. 'A2:B6' or 'A1'
+ * always fixed range
+ * section 2.5.14
+ *
+ * @param string $subData
+ * @return string
+ * @throws Exception
+ */
+ private function _readBIFF8CellRangeAddressFixed($subData)
+ {
+ // offset: 0; size: 2; index to first row
+ $fr = self::_GetInt2d($subData, 0) + 1;
+
+ // offset: 2; size: 2; index to last row
+ $lr = self::_GetInt2d($subData, 2) + 1;
+
+ // offset: 4; size: 2; index to first column
+ $fc = self::_GetInt2d($subData, 4);
+
+ // offset: 6; size: 2; index to last column
+ $lc = self::_GetInt2d($subData, 6);
+
+ // check values
+ if ($fr > $lr || $fc > $lc) {
+ throw new Exception('Not a cell range address');
+ }
+
+ // column index to letter
+ $fc = PHPExcel_Cell::stringFromColumnIndex($fc);
+ $lc = PHPExcel_Cell::stringFromColumnIndex($lc);
+
+ if ($fr == $lr and $fc == $lc) {
+ return "$fc$fr";
+ }
+ return "$fc$fr:$lc$lr";
+ }
+
+
+ /**
+ * Reads a cell range address in BIFF8 e.g. 'A2:B6' or '$A$2:$B$6'
+ * there are flags indicating whether column/row index is relative
+ * section 3.3.4
+ *
+ * @param string $subData
+ * @return string
+ */
+ private function _readBIFF8CellRangeAddress($subData)
+ {
+ // todo: if cell range is just a single cell, should this funciton
+ // not just return e.g. 'A1' and not 'A1:A1' ?
+
+ // offset: 0; size: 2; index to first row (0... 65535) (or offset (-32768... 32767))
+ $fr = self::_GetInt2d($subData, 0) + 1;
+
+ // offset: 2; size: 2; index to last row (0... 65535) (or offset (-32768... 32767))
+ $lr = self::_GetInt2d($subData, 2) + 1;
+
+ // offset: 4; size: 2; index to first column or column offset + relative flags
+
+ // bit: 7-0; mask 0x00FF; column index
+ $fc = PHPExcel_Cell::stringFromColumnIndex(0x00FF & self::_GetInt2d($subData, 4));
+
+ // bit: 14; mask 0x4000; (1 = relative column index, 0 = absolute column index)
+ if (!(0x4000 & self::_GetInt2d($subData, 4))) {
+ $fc = '$' . $fc;
+ }
+
+ // bit: 15; mask 0x8000; (1 = relative row index, 0 = absolute row index)
+ if (!(0x8000 & self::_GetInt2d($subData, 4))) {
+ $fr = '$' . $fr;
+ }
+
+ // offset: 6; size: 2; index to last column or column offset + relative flags
+
+ // bit: 7-0; mask 0x00FF; column index
+ $lc = PHPExcel_Cell::stringFromColumnIndex(0x00FF & self::_GetInt2d($subData, 6));
+
+ // bit: 14; mask 0x4000; (1 = relative column index, 0 = absolute column index)
+ if (!(0x4000 & self::_GetInt2d($subData, 6))) {
+ $lc = '$' . $lc;
+ }
+
+ // bit: 15; mask 0x8000; (1 = relative row index, 0 = absolute row index)
+ if (!(0x8000 & self::_GetInt2d($subData, 6))) {
+ $lr = '$' . $lr;
+ }
+
+ return "$fc$fr:$lc$lr";
+ }
+
+
+ /**
+ * Reads a cell range address in BIFF8 for shared formulas. Uses positive and negative values for row and column
+ * to indicate offsets from a base cell
+ * section 3.3.4
+ *
+ * @param string $subData
+ * @param string $baseCell Base cell
+ * @return string Cell range address
+ */
+ private function _readBIFF8CellRangeAddressB($subData, $baseCell = 'A1')
+ {
+ list($baseCol, $baseRow) = PHPExcel_Cell::coordinateFromString($baseCell);
+ $baseCol = PHPExcel_Cell::columnIndexFromString($baseCol) - 1;
+
+ // TODO: if cell range is just a single cell, should this funciton
+ // not just return e.g. 'A1' and not 'A1:A1' ?
+
+ // offset: 0; size: 2; first row
+ $frIndex = self::_GetInt2d($subData, 0); // adjust below
+
+ // offset: 2; size: 2; relative index to first row (0... 65535) should be treated as offset (-32768... 32767)
+ $lrIndex = self::_GetInt2d($subData, 2); // adjust below
+
+ // offset: 4; size: 2; first column with relative/absolute flags
+
+ // bit: 7-0; mask 0x00FF; column index
+ $fcIndex = 0x00FF & self::_GetInt2d($subData, 4);
+
+ // bit: 14; mask 0x4000; (1 = relative column index, 0 = absolute column index)
+ if (!(0x4000 & self::_GetInt2d($subData, 4))) {
+ // absolute column index
+ $fc = PHPExcel_Cell::stringFromColumnIndex($fcIndex);
+ $fc = '$' . $fc;
+ } else {
+ // column offset
+ $fcIndex = ($fcIndex <= 127) ? $fcIndex : $fcIndex - 256;
+ $fc = PHPExcel_Cell::stringFromColumnIndex($baseCol + $fcIndex);
+ }
+
+ // bit: 15; mask 0x8000; (1 = relative row index, 0 = absolute row index)
+ if (!(0x8000 & self::_GetInt2d($subData, 4))) {
+ // absolute row index
+ $fr = $frIndex + 1;
+ $fr = '$' . $fr;
+ } else {
+ // row offset
+ $frIndex = ($frIndex <= 32767) ? $frIndex : $frIndex - 65536;
+ $fr = $baseRow + $frIndex;
+ }
+
+ // offset: 6; size: 2; last column with relative/absolute flags
+
+ // bit: 7-0; mask 0x00FF; column index
+ $lcIndex = 0x00FF & self::_GetInt2d($subData, 6);
+ $lcIndex = ($lcIndex <= 127) ? $lcIndex : $lcIndex - 256;
+ $lc = PHPExcel_Cell::stringFromColumnIndex($baseCol + $lcIndex);
+
+ // bit: 14; mask 0x4000; (1 = relative column index, 0 = absolute column index)
+ if (!(0x4000 & self::_GetInt2d($subData, 6))) {
+ // absolute column index
+ $lc = PHPExcel_Cell::stringFromColumnIndex($lcIndex);
+ $lc = '$' . $lc;
+ } else {
+ // column offset
+ $lcIndex = ($lcIndex <= 127) ? $lcIndex : $lcIndex - 256;
+ $lc = PHPExcel_Cell::stringFromColumnIndex($baseCol + $lcIndex);
+ }
+
+ // bit: 15; mask 0x8000; (1 = relative row index, 0 = absolute row index)
+ if (!(0x8000 & self::_GetInt2d($subData, 6))) {
+ // absolute row index
+ $lr = $lrIndex + 1;
+ $lr = '$' . $lr;
+ } else {
+ // row offset
+ $lrIndex = ($lrIndex <= 32767) ? $lrIndex : $lrIndex - 65536;
+ $lr = $baseRow + $lrIndex;
+ }
+
+ return "$fc$fr:$lc$lr";
+ }
+
+
+ /**
+ * Read BIFF8 cell range address list
+ * section 2.5.15
+ *
+ * @param string $subData
+ * @return array
+ */
+ private function _readBIFF8CellRangeAddressList($subData)
+ {
+ $cellRangeAddresses = array();
+
+ // offset: 0; size: 2; number of the following cell range addresses
+ $nm = self::_GetInt2d($subData, 0);
+
+ $offset = 2;
+ // offset: 2; size: 8 * $nm; list of $nm (fixed) cell range addresses
+ for ($i = 0; $i < $nm; ++$i) {
+ $cellRangeAddresses[] = $this->_readBIFF8CellRangeAddressFixed(substr($subData, $offset, 8));
+ $offset += 8;
+ }
+
+ return array(
+ 'size' => 2 + 8 * $nm,
+ 'cellRangeAddresses' => $cellRangeAddresses,
+ );
+ }
+
+
+ /**
+ * Read BIFF5 cell range address list
+ * section 2.5.15
+ *
+ * @param string $subData
+ * @return array
+ */
+ private function _readBIFF5CellRangeAddressList($subData)
+ {
+ $cellRangeAddresses = array();
+
+ // offset: 0; size: 2; number of the following cell range addresses
+ $nm = self::_GetInt2d($subData, 0);
+
+ $offset = 2;
+ // offset: 2; size: 6 * $nm; list of $nm (fixed) cell range addresses
+ for ($i = 0; $i < $nm; ++$i) {
+ $cellRangeAddresses[] = $this->_readBIFF5CellRangeAddressFixed(substr($subData, $offset, 6));
+ $offset += 6;
+ }
+
+ return array(
+ 'size' => 2 + 6 * $nm,
+ 'cellRangeAddresses' => $cellRangeAddresses,
+ );
+ }
+
+
+ /**
+ * Get a sheet range like Sheet1:Sheet3 from REF index
+ * Note: If there is only one sheet in the range, one gets e.g Sheet1
+ * It can also happen that the REF structure uses the -1 (FFFF) code to indicate deleted sheets,
+ * in which case an exception is thrown
+ *
+ * @param int $index
+ * @return string|false
+ * @throws Exception
+ */
+ private function _readSheetRangeByRefIndex($index)
+ {
+ if (isset($this->_ref[$index])) {
+
+ $type = $this->_externalBooks[$this->_ref[$index]['externalBookIndex']]['type'];
+
+ switch ($type) {
+ case 'internal':
+ // check if we have a deleted 3d reference
+ if ($this->_ref[$index]['firstSheetIndex'] == 0xFFFF or $this->_ref[$index]['lastSheetIndex'] == 0xFFFF) {
+ throw new Exception('Deleted sheet reference');
+ }
+
+ // we have normal sheet range (collapsed or uncollapsed)
+ $firstSheetName = $this->_sheets[$this->_ref[$index]['firstSheetIndex']]['name'];
+ $lastSheetName = $this->_sheets[$this->_ref[$index]['lastSheetIndex']]['name'];
+
+ if ($firstSheetName == $lastSheetName) {
+ // collapsed sheet range
+ $sheetRange = $firstSheetName;
+ } else {
+ $sheetRange = "$firstSheetName:$lastSheetName";
+ }
+
+ // escape the single-quotes
+ $sheetRange = str_replace("'", "''", $sheetRange);
+
+ // if there are special characters, we need to enclose the range in single-quotes
+ // todo: check if we have identified the whole set of special characters
+ // it seems that the following characters are not accepted for sheet names
+ // and we may assume that they are not present: []*/:\?
+ if (preg_match("/[ !\"@#£$%&{()}<>=+'|^,;-]/", $sheetRange)) {
+ $sheetRange = "'$sheetRange'";
+ }
+
+ return $sheetRange;
+ break;
+
+ default:
+ // TODO: external sheet support
+ throw new Exception('Excel5 reader only supports internal sheets in fomulas');
+ break;
+ }
+ }
+ return false;
+ }
+
+
+ /**
+ * read BIFF8 constant value array from array data
+ * returns e.g. array('value' => '{1,2;3,4}', 'size' => 40}
+ * section 2.5.8
+ *
+ * @param string $arrayData
+ * @return array
+ */
+ private static function _readBIFF8ConstantArray($arrayData)
+ {
+ // offset: 0; size: 1; number of columns decreased by 1
+ $nc = ord($arrayData[0]);
+
+ // offset: 1; size: 2; number of rows decreased by 1
+ $nr = self::_GetInt2d($arrayData, 1);
+ $size = 3; // initialize
+ $arrayData = substr($arrayData, 3);
+
+ // offset: 3; size: var; list of ($nc + 1) * ($nr + 1) constant values
+ $matrixChunks = array();
+ for ($r = 1; $r <= $nr + 1; ++$r) {
+ $items = array();
+ for ($c = 1; $c <= $nc + 1; ++$c) {
+ $constant = self::_readBIFF8Constant($arrayData);
+ $items[] = $constant['value'];
+ $arrayData = substr($arrayData, $constant['size']);
+ $size += $constant['size'];
+ }
+ $matrixChunks[] = implode(',', $items); // looks like e.g. '1,"hello"'
+ }
+ $matrix = '{' . implode(';', $matrixChunks) . '}';
+
+ return array(
+ 'value' => $matrix,
+ 'size' => $size,
+ );
+ }
+
+
+ /**
+ * read BIFF8 constant value which may be 'Empty Value', 'Number', 'String Value', 'Boolean Value', 'Error Value'
+ * section 2.5.7
+ * returns e.g. array('value' => '5', 'size' => 9)
+ *
+ * @param string $valueData
+ * @return array
+ */
+ private static function _readBIFF8Constant($valueData)
+ {
+ // offset: 0; size: 1; identifier for type of constant
+ $identifier = ord($valueData[0]);
+
+ switch ($identifier) {
+ case 0x00: // empty constant (what is this?)
+ $value = '';
+ $size = 9;
+ break;
+ case 0x01: // number
+ // offset: 1; size: 8; IEEE 754 floating-point value
+ $value = self::_extractNumber(substr($valueData, 1, 8));
+ $size = 9;
+ break;
+ case 0x02: // string value
+ // offset: 1; size: var; Unicode string, 16-bit string length
+ $string = self::_readUnicodeStringLong(substr($valueData, 1));
+ $value = '"' . $string['value'] . '"';
+ $size = 1 + $string['size'];
+ break;
+ case 0x04: // boolean
+ // offset: 1; size: 1; 0 = FALSE, 1 = TRUE
+ if (ord($valueData[1])) {
+ $value = 'TRUE';
+ } else {
+ $value = 'FALSE';
+ }
+ $size = 9;
+ break;
+ case 0x10: // error code
+ // offset: 1; size: 1; error code
+ $value = self::_mapErrorCode(ord($valueData[1]));
+ $size = 9;
+ break;
+ }
+ return array(
+ 'value' => $value,
+ 'size' => $size,
+ );
+ }
+
+
+ /**
+ * Extract RGB color
+ * OpenOffice.org's Documentation of the Microsoft Excel File Format, section 2.5.4
+ *
+ * @param string $rgb Encoded RGB value (4 bytes)
+ * @return array
+ */
+ private static function _readRGB($rgb)
+ {
+ // offset: 0; size 1; Red component
+ $r = ord($rgb{0});
+
+ // offset: 1; size: 1; Green component
+ $g = ord($rgb{1});
+
+ // offset: 2; size: 1; Blue component
+ $b = ord($rgb{2});
+
+ // HEX notation, e.g. 'FF00FC'
+ $rgb = sprintf('%02X%02X%02X', $r, $g, $b);
+
+ return array('rgb' => $rgb);
+ }
+
+
+ /**
+ * Read byte string (8-bit string length)
+ * OpenOffice documentation: 2.5.2
+ *
+ * @param string $subData
+ * @return array
+ */
+ private function _readByteStringShort($subData)
+ {
+ // offset: 0; size: 1; length of the string (character count)
+ $ln = ord($subData[0]);
+
+ // offset: 1: size: var; character array (8-bit characters)
+ $value = $this->_decodeCodepage(substr($subData, 1, $ln));
+
+ return array(
+ 'value' => $value,
+ 'size' => 1 + $ln, // size in bytes of data structure
+ );
+ }
+
+
+ /**
+ * Read byte string (16-bit string length)
+ * OpenOffice documentation: 2.5.2
+ *
+ * @param string $subData
+ * @return array
+ */
+ private function _readByteStringLong($subData)
+ {
+ // offset: 0; size: 2; length of the string (character count)
+ $ln = self::_GetInt2d($subData, 0);
+
+ // offset: 2: size: var; character array (8-bit characters)
+ $value = $this->_decodeCodepage(substr($subData, 2));
+
+ //return $string;
+ return array(
+ 'value' => $value,
+ 'size' => 2 + $ln, // size in bytes of data structure
+ );
+ }
+
+
+ /**
+ * Extracts an Excel Unicode short string (8-bit string length)
+ * OpenOffice documentation: 2.5.3
+ * function will automatically find out where the Unicode string ends.
+ *
+ * @param string $subData
+ * @return array
+ */
+ private static function _readUnicodeStringShort($subData)
+ {
+ $value = '';
+
+ // offset: 0: size: 1; length of the string (character count)
+ $characterCount = ord($subData[0]);
+
+ $string = self::_readUnicodeString(substr($subData, 1), $characterCount);
+
+ // add 1 for the string length
+ $string['size'] += 1;
+
+ return $string;
+ }
+
+
+ /**
+ * Extracts an Excel Unicode long string (16-bit string length)
+ * OpenOffice documentation: 2.5.3
+ * this function is under construction, needs to support rich text, and Asian phonetic settings
+ *
+ * @param string $subData
+ * @return array
+ */
+ private static function _readUnicodeStringLong($subData)
+ {
+ $value = '';
+
+ // offset: 0: size: 2; length of the string (character count)
+ $characterCount = self::_GetInt2d($subData, 0);
+
+ $string = self::_readUnicodeString(substr($subData, 2), $characterCount);
+
+ // add 2 for the string length
+ $string['size'] += 2;
+
+ return $string;
+ }
+
+
+ /**
+ * Read Unicode string with no string length field, but with known character count
+ * this function is under construction, needs to support rich text, and Asian phonetic settings
+ * OpenOffice.org's Documentation of the Microsoft Excel File Format, section 2.5.3
+ *
+ * @param string $subData
+ * @param int $characterCount
+ * @return array
+ */
+ private static function _readUnicodeString($subData, $characterCount)
+ {
+ $value = '';
+
+ // offset: 0: size: 1; option flags
+
+ // bit: 0; mask: 0x01; character compression (0 = compressed 8-bit, 1 = uncompressed 16-bit)
+ $isCompressed = !((0x01 & ord($subData[0])) >> 0);
+
+ // bit: 2; mask: 0x04; Asian phonetic settings
+ $hasAsian = (0x04) & ord($subData[0]) >> 2;
+
+ // bit: 3; mask: 0x08; Rich-Text settings
+ $hasRichText = (0x08) & ord($subData[0]) >> 3;
+
+ // offset: 1: size: var; character array
+ // this offset assumes richtext and Asian phonetic settings are off which is generally wrong
+ // needs to be fixed
+ $value = self::_encodeUTF16(substr($subData, 1, $isCompressed ? $characterCount : 2 * $characterCount), $isCompressed);
+
+ return array(
+ 'value' => $value,
+ 'size' => $isCompressed ? 1 + $characterCount : 1 + 2 * $characterCount, // the size in bytes including the option flags
+ );
+ }
+
+
+ /**
+ * Convert UTF-8 string to string surounded by double quotes. Used for explicit string tokens in formulas.
+ * Example: hello"world --> "hello""world"
+ *
+ * @param string $value UTF-8 encoded string
+ * @return string
+ */
+ private static function _UTF8toExcelDoubleQuoted($value)
+ {
+ return '"' . str_replace('"', '""', $value) . '"';
+ }
+
+
+ /**
+ * Reads first 8 bytes of a string and return IEEE 754 float
+ *
+ * @param string $data Binary string that is at least 8 bytes long
+ * @return float
+ */
+ private static function _extractNumber($data)
+ {
+ $rknumhigh = self::_GetInt4d($data, 4);
+ $rknumlow = self::_GetInt4d($data, 0);
+ $sign = ($rknumhigh & 0x80000000) >> 31;
+ $exp = (($rknumhigh & 0x7ff00000) >> 20) - 1023;
+ $mantissa = (0x100000 | ($rknumhigh & 0x000fffff));
+ $mantissalow1 = ($rknumlow & 0x80000000) >> 31;
+ $mantissalow2 = ($rknumlow & 0x7fffffff);
+ $value = $mantissa / pow( 2 , (20 - $exp));
+
+ if ($mantissalow1 != 0) {
+ $value += 1 / pow (2 , (21 - $exp));
+ }
+
+ $value += $mantissalow2 / pow (2 , (52 - $exp));
+ if ($sign) {
+ $value *= -1;
+ }
+
+ return $value;
+ }
+
+
+ private static function _GetIEEE754($rknum)
+ {
+ if (($rknum & 0x02) != 0) {
+ $value = $rknum >> 2;
+ } else {
+ // changes by mmp, info on IEEE754 encoding from
+ // research.microsoft.com/~hollasch/cgindex/coding/ieeefloat.html
+ // The RK format calls for using only the most significant 30 bits
+ // of the 64 bit floating point value. The other 34 bits are assumed
+ // to be 0 so we use the upper 30 bits of $rknum as follows...
+ $sign = ($rknum & 0x80000000) >> 31;
+ $exp = ($rknum & 0x7ff00000) >> 20;
+ $mantissa = (0x100000 | ($rknum & 0x000ffffc));
+ $value = $mantissa / pow( 2 , (20- ($exp - 1023)));
+ if ($sign) {
+ $value = -1 * $value;
+ }
+ //end of changes by mmp
+ }
+ if (($rknum & 0x01) != 0) {
+ $value /= 100;
+ }
+ return $value;
+ }
+
+
+ /**
+ * Get UTF-8 string from (compressed or uncompressed) UTF-16 string
+ *
+ * @param string $string
+ * @param bool $compressed
+ * @return string
+ */
+ private static function _encodeUTF16($string, $compressed = '')
+ {
+ if ($compressed) {
+ $string = self::_uncompressByteString($string);
+ }
+
+ return PHPExcel_Shared_String::ConvertEncoding($string, 'UTF-8', 'UTF-16LE');
+ }
+
+
+ /**
+ * Convert UTF-16 string in compressed notation to uncompressed form. Only used for BIFF8.
+ *
+ * @param string $string
+ * @return string
+ */
+ private static function _uncompressByteString($string)
+ {
+ $uncompressedString = '';
+ $strLen = strlen($string);
+ for ($i = 0; $i < $strLen; ++$i) {
+ $uncompressedString .= $string[$i] . "\0";
+ }
+
+ return $uncompressedString;
+ }
+
+
+ /**
+ * Convert string to UTF-8. Only used for BIFF5.
+ *
+ * @param string $string
+ * @return string
+ */
+ private function _decodeCodepage($string)
+ {
+ return PHPExcel_Shared_String::ConvertEncoding($string, 'UTF-8', $this->_codepage);
+ }
+
+
+ /**
+ * Read 16-bit unsigned integer
+ *
+ * @param string $data
+ * @param int $pos
+ * @return int
+ */
+ public static function _GetInt2d($data, $pos)
+ {
+ return ord($data[$pos]) | (ord($data[$pos+1]) << 8);
+ }
+
+
+ /**
+ * Read 32-bit signed integer
+ *
+ * @param string $data
+ * @param int $pos
+ * @return int
+ */
+ public static function _GetInt4d($data, $pos)
+ {
+ // FIX: represent numbers correctly on 64-bit system
+ // http://sourceforge.net/tracker/index.php?func=detail&aid=1487372&group_id=99160&atid=623334
+ // Hacked by Andreas Rehm 2006 to ensure correct result of the <<24 block on 32 and 64bit systems
+ $_or_24 = ord($data[$pos + 3]);
+ if ($_or_24 >= 128) {
+ // negative number
+ $_ord_24 = -abs((256 - $_or_24) << 24);
+ } else {
+ $_ord_24 = ($_or_24 & 127) << 24;
+ }
+ return ord($data[$pos]) | (ord($data[$pos+1]) << 8) | (ord($data[$pos+2]) << 16) | $_ord_24;
+ }
+
+
+ /**
+ * Read color
+ *
+ * @param int $color Indexed color
+ * @param array $palette Color palette
+ * @return array RGB color value, example: array('rgb' => 'FF0000')
+ */
+ private static function _readColor($color,$palette,$version)
+ {
+ if ($color <= 0x07 || $color >= 0x40) {
+ // special built-in color
+ return self::_mapBuiltInColor($color);
+ } elseif (isset($palette) && isset($palette[$color - 8])) {
+ // palette color, color index 0x08 maps to pallete index 0
+ return $palette[$color - 8];
+ } else {
+ // default color table
+ if ($version == self::XLS_BIFF8) {
+ return self::_mapColor($color);
+ } else {
+ // BIFF5
+ return self::_mapColorBIFF5($color);
+ }
+ }
+
+ return $color;
+ }
+
+
+ /**
+ * Map border style
+ * OpenOffice documentation: 2.5.11
+ *
+ * @param int $index
+ * @return string
+ */
+ private static function _mapBorderStyle($index)
+ {
+ switch ($index) {
+ case 0x00: return PHPExcel_Style_Border::BORDER_NONE;
+ case 0x01: return PHPExcel_Style_Border::BORDER_THIN;
+ case 0x02: return PHPExcel_Style_Border::BORDER_MEDIUM;
+ case 0x03: return PHPExcel_Style_Border::BORDER_DASHED;
+ case 0x04: return PHPExcel_Style_Border::BORDER_DOTTED;
+ case 0x05: return PHPExcel_Style_Border::BORDER_THICK;
+ case 0x06: return PHPExcel_Style_Border::BORDER_DOUBLE;
+ case 0x07: return PHPExcel_Style_Border::BORDER_HAIR;
+ case 0x08: return PHPExcel_Style_Border::BORDER_MEDIUMDASHED;
+ case 0x09: return PHPExcel_Style_Border::BORDER_DASHDOT;
+ case 0x0A: return PHPExcel_Style_Border::BORDER_MEDIUMDASHDOT;
+ case 0x0B: return PHPExcel_Style_Border::BORDER_DASHDOTDOT;
+ case 0x0C: return PHPExcel_Style_Border::BORDER_MEDIUMDASHDOTDOT;
+ case 0x0D: return PHPExcel_Style_Border::BORDER_SLANTDASHDOT;
+ default: return PHPExcel_Style_Border::BORDER_NONE;
+ }
+ }
+
+
+ /**
+ * Get fill pattern from index
+ * OpenOffice documentation: 2.5.12
+ *
+ * @param int $index
+ * @return string
+ */
+ private static function _mapFillPattern($index)
+ {
+ switch ($index) {
+ case 0x00: return PHPExcel_Style_Fill::FILL_NONE;
+ case 0x01: return PHPExcel_Style_Fill::FILL_SOLID;
+ case 0x02: return PHPExcel_Style_Fill::FILL_PATTERN_MEDIUMGRAY;
+ case 0x03: return PHPExcel_Style_Fill::FILL_PATTERN_DARKGRAY;
+ case 0x04: return PHPExcel_Style_Fill::FILL_PATTERN_LIGHTGRAY;
+ case 0x05: return PHPExcel_Style_Fill::FILL_PATTERN_DARKHORIZONTAL;
+ case 0x06: return PHPExcel_Style_Fill::FILL_PATTERN_DARKVERTICAL;
+ case 0x07: return PHPExcel_Style_Fill::FILL_PATTERN_DARKDOWN;
+ case 0x08: return PHPExcel_Style_Fill::FILL_PATTERN_DARKUP;
+ case 0x09: return PHPExcel_Style_Fill::FILL_PATTERN_DARKGRID;
+ case 0x0A: return PHPExcel_Style_Fill::FILL_PATTERN_DARKTRELLIS;
+ case 0x0B: return PHPExcel_Style_Fill::FILL_PATTERN_LIGHTHORIZONTAL;
+ case 0x0C: return PHPExcel_Style_Fill::FILL_PATTERN_LIGHTVERTICAL;
+ case 0x0D: return PHPExcel_Style_Fill::FILL_PATTERN_LIGHTDOWN;
+ case 0x0E: return PHPExcel_Style_Fill::FILL_PATTERN_LIGHTUP;
+ case 0x0F: return PHPExcel_Style_Fill::FILL_PATTERN_LIGHTGRID;
+ case 0x10: return PHPExcel_Style_Fill::FILL_PATTERN_LIGHTTRELLIS;
+ case 0x11: return PHPExcel_Style_Fill::FILL_PATTERN_GRAY125;
+ case 0x12: return PHPExcel_Style_Fill::FILL_PATTERN_GRAY0625;
+ default: return PHPExcel_Style_Fill::FILL_NONE;
+ }
+ }
+
+
+ /**
+ * Map error code, e.g. '#N/A'
+ *
+ * @param int $subData
+ * @return string
+ */
+ private static function _mapErrorCode($subData)
+ {
+ switch ($subData) {
+ case 0x00: return '#NULL!'; break;
+ case 0x07: return '#DIV/0!'; break;
+ case 0x0F: return '#VALUE!'; break;
+ case 0x17: return '#REF!'; break;
+ case 0x1D: return '#NAME?'; break;
+ case 0x24: return '#NUM!'; break;
+ case 0x2A: return '#N/A'; break;
+ default: return false;
+ }
+ }
+
+
+ /**
+ * Map built-in color to RGB value
+ *
+ * @param int $color Indexed color
+ * @return array
+ */
+ private static function _mapBuiltInColor($color)
+ {
+ switch ($color) {
+ case 0x00: return array('rgb' => '000000');
+ case 0x01: return array('rgb' => 'FFFFFF');
+ case 0x02: return array('rgb' => 'FF0000');
+ case 0x03: return array('rgb' => '00FF00');
+ case 0x04: return array('rgb' => '0000FF');
+ case 0x05: return array('rgb' => 'FFFF00');
+ case 0x06: return array('rgb' => 'FF00FF');
+ case 0x07: return array('rgb' => '00FFFF');
+ case 0x40: return array('rgb' => '000000'); // system window text color
+ case 0x41: return array('rgb' => 'FFFFFF'); // system window background color
+ default: return array('rgb' => '000000');
+ }
+ }
+
+
+ /**
+ * Map color array from BIFF5 built-in color index
+ *
+ * @param int $subData
+ * @return array
+ */
+ private static function _mapColorBIFF5($subData)
+ {
+ switch ($subData) {
+ case 0x08: return array('rgb' => '000000');
+ case 0x09: return array('rgb' => 'FFFFFF');
+ case 0x0A: return array('rgb' => 'FF0000');
+ case 0x0B: return array('rgb' => '00FF00');
+ case 0x0C: return array('rgb' => '0000FF');
+ case 0x0D: return array('rgb' => 'FFFF00');
+ case 0x0E: return array('rgb' => 'FF00FF');
+ case 0x0F: return array('rgb' => '00FFFF');
+ case 0x10: return array('rgb' => '800000');
+ case 0x11: return array('rgb' => '008000');
+ case 0x12: return array('rgb' => '000080');
+ case 0x13: return array('rgb' => '808000');
+ case 0x14: return array('rgb' => '800080');
+ case 0x15: return array('rgb' => '008080');
+ case 0x16: return array('rgb' => 'C0C0C0');
+ case 0x17: return array('rgb' => '808080');
+ case 0x18: return array('rgb' => '8080FF');
+ case 0x19: return array('rgb' => '802060');
+ case 0x1A: return array('rgb' => 'FFFFC0');
+ case 0x1B: return array('rgb' => 'A0E0F0');
+ case 0x1C: return array('rgb' => '600080');
+ case 0x1D: return array('rgb' => 'FF8080');
+ case 0x1E: return array('rgb' => '0080C0');
+ case 0x1F: return array('rgb' => 'C0C0FF');
+ case 0x20: return array('rgb' => '000080');
+ case 0x21: return array('rgb' => 'FF00FF');
+ case 0x22: return array('rgb' => 'FFFF00');
+ case 0x23: return array('rgb' => '00FFFF');
+ case 0x24: return array('rgb' => '800080');
+ case 0x25: return array('rgb' => '800000');
+ case 0x26: return array('rgb' => '008080');
+ case 0x27: return array('rgb' => '0000FF');
+ case 0x28: return array('rgb' => '00CFFF');
+ case 0x29: return array('rgb' => '69FFFF');
+ case 0x2A: return array('rgb' => 'E0FFE0');
+ case 0x2B: return array('rgb' => 'FFFF80');
+ case 0x2C: return array('rgb' => 'A6CAF0');
+ case 0x2D: return array('rgb' => 'DD9CB3');
+ case 0x2E: return array('rgb' => 'B38FEE');
+ case 0x2F: return array('rgb' => 'E3E3E3');
+ case 0x30: return array('rgb' => '2A6FF9');
+ case 0x31: return array('rgb' => '3FB8CD');
+ case 0x32: return array('rgb' => '488436');
+ case 0x33: return array('rgb' => '958C41');
+ case 0x34: return array('rgb' => '8E5E42');
+ case 0x35: return array('rgb' => 'A0627A');
+ case 0x36: return array('rgb' => '624FAC');
+ case 0x37: return array('rgb' => '969696');
+ case 0x38: return array('rgb' => '1D2FBE');
+ case 0x39: return array('rgb' => '286676');
+ case 0x3A: return array('rgb' => '004500');
+ case 0x3B: return array('rgb' => '453E01');
+ case 0x3C: return array('rgb' => '6A2813');
+ case 0x3D: return array('rgb' => '85396A');
+ case 0x3E: return array('rgb' => '4A3285');
+ case 0x3F: return array('rgb' => '424242');
+ default: return array('rgb' => '000000');
+ }
+ }
+
+
+ /**
+ * Map color array from BIFF8 built-in color index
+ *
+ * @param int $subData
+ * @return array
+ */
+ private static function _mapColor($subData)
+ {
+ switch ($subData) {
+ case 0x08: return array('rgb' => '000000');
+ case 0x09: return array('rgb' => 'FFFFFF');
+ case 0x0A: return array('rgb' => 'FF0000');
+ case 0x0B: return array('rgb' => '00FF00');
+ case 0x0C: return array('rgb' => '0000FF');
+ case 0x0D: return array('rgb' => 'FFFF00');
+ case 0x0E: return array('rgb' => 'FF00FF');
+ case 0x0F: return array('rgb' => '00FFFF');
+ case 0x10: return array('rgb' => '800000');
+ case 0x11: return array('rgb' => '008000');
+ case 0x12: return array('rgb' => '000080');
+ case 0x13: return array('rgb' => '808000');
+ case 0x14: return array('rgb' => '800080');
+ case 0x15: return array('rgb' => '008080');
+ case 0x16: return array('rgb' => 'C0C0C0');
+ case 0x17: return array('rgb' => '808080');
+ case 0x18: return array('rgb' => '9999FF');
+ case 0x19: return array('rgb' => '993366');
+ case 0x1A: return array('rgb' => 'FFFFCC');
+ case 0x1B: return array('rgb' => 'CCFFFF');
+ case 0x1C: return array('rgb' => '660066');
+ case 0x1D: return array('rgb' => 'FF8080');
+ case 0x1E: return array('rgb' => '0066CC');
+ case 0x1F: return array('rgb' => 'CCCCFF');
+ case 0x20: return array('rgb' => '000080');
+ case 0x21: return array('rgb' => 'FF00FF');
+ case 0x22: return array('rgb' => 'FFFF00');
+ case 0x23: return array('rgb' => '00FFFF');
+ case 0x24: return array('rgb' => '800080');
+ case 0x25: return array('rgb' => '800000');
+ case 0x26: return array('rgb' => '008080');
+ case 0x27: return array('rgb' => '0000FF');
+ case 0x28: return array('rgb' => '00CCFF');
+ case 0x29: return array('rgb' => 'CCFFFF');
+ case 0x2A: return array('rgb' => 'CCFFCC');
+ case 0x2B: return array('rgb' => 'FFFF99');
+ case 0x2C: return array('rgb' => '99CCFF');
+ case 0x2D: return array('rgb' => 'FF99CC');
+ case 0x2E: return array('rgb' => 'CC99FF');
+ case 0x2F: return array('rgb' => 'FFCC99');
+ case 0x30: return array('rgb' => '3366FF');
+ case 0x31: return array('rgb' => '33CCCC');
+ case 0x32: return array('rgb' => '99CC00');
+ case 0x33: return array('rgb' => 'FFCC00');
+ case 0x34: return array('rgb' => 'FF9900');
+ case 0x35: return array('rgb' => 'FF6600');
+ case 0x36: return array('rgb' => '666699');
+ case 0x37: return array('rgb' => '969696');
+ case 0x38: return array('rgb' => '003366');
+ case 0x39: return array('rgb' => '339966');
+ case 0x3A: return array('rgb' => '003300');
+ case 0x3B: return array('rgb' => '333300');
+ case 0x3C: return array('rgb' => '993300');
+ case 0x3D: return array('rgb' => '993366');
+ case 0x3E: return array('rgb' => '333399');
+ case 0x3F: return array('rgb' => '333333');
+ default: return array('rgb' => '000000');
+ }
+ }
+
+
+ private function _parseRichText($is = '') {
+ $value = new PHPExcel_RichText();
+
+ $value->createText($is);
+
+ return $value;
+ }
+
+}
diff --git a/htdocs/includes/phpexcel/PHPExcel/Shared/OLE/PPS/Root.php b/htdocs/includes/phpexcel/PHPExcel/Shared/OLE/PPS/Root.php
index 9a214167294..7046a0a3aeb 100644
--- a/htdocs/includes/phpexcel/PHPExcel/Shared/OLE/PPS/Root.php
+++ b/htdocs/includes/phpexcel/PHPExcel/Shared/OLE/PPS/Root.php
@@ -78,13 +78,13 @@ class PHPExcel_Shared_OLE_PPS_Root extends PHPExcel_Shared_OLE_PPS
if (is_resource($filename)) {
$this->_FILEH_ = $filename;
- } else if ($filename == '-' || $filename == '') {
- if ($this->_tmp_dir === NULL)
- $this->_tmp_dir = PHPExcel_Shared_File::sys_get_temp_dir();
- $this->_tmp_filename = tempnam($this->_tmp_dir, "OLE_PPS_Root");
- $this->_FILEH_ = fopen($this->_tmp_filename,"w+b");
- if ($this->_FILEH_ == false) {
- throw new Exception("Can't create temporary file.");
+ } else if ($filename == '-' || $filename == '') {
+ if ($this->_tmp_dir === NULL)
+ $this->_tmp_dir = PHPExcel_Shared_File::sys_get_temp_dir();
+ $this->_tmp_filename = tempnam($this->_tmp_dir, "OLE_PPS_Root");
+ $this->_FILEH_ = fopen($this->_tmp_filename,"w+b");
+ if ($this->_FILEH_ == false) {
+ throw new Exception("Can't create temporary file.");
}
} else {
$this->_FILEH_ = fopen($filename, "wb");
@@ -94,7 +94,7 @@ class PHPExcel_Shared_OLE_PPS_Root extends PHPExcel_Shared_OLE_PPS
}
// Make an array of PPS's (for Save)
$aList = array();
- PHPExcel_Shared_OLE_PPS::_savePpsSetPnt($aList, array($this));
+ PHPExcel_Shared_OLE_PPS::_savePpsSetPnt($aList, array($this));
// calculate values for header
list($iSBDcnt, $iBBcnt, $iPPScnt) = $this->_calcSize($aList); //, $rhInfo);
// Save Header
diff --git a/htdocs/includes/phpexcel/PHPExcel/Shared/PCLZip/gnu-lgpl.txt b/htdocs/includes/phpexcel/PHPExcel/Shared/PCLZip/gnu-lgpl.txt
index cbee875ba6d..b1e3f5a2638 100644
--- a/htdocs/includes/phpexcel/PHPExcel/Shared/PCLZip/gnu-lgpl.txt
+++ b/htdocs/includes/phpexcel/PHPExcel/Shared/PCLZip/gnu-lgpl.txt
@@ -1,504 +1,504 @@
- GNU LESSER GENERAL PUBLIC LICENSE
- Version 2.1, February 1999
-
- Copyright (C) 1991, 1999 Free Software Foundation, Inc.
- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
-[This is the first released version of the Lesser GPL. It also counts
- as the successor of the GNU Library Public License, version 2, hence
- the version number 2.1.]
-
- Preamble
-
- The licenses for most software are designed to take away your
-freedom to share and change it. By contrast, the GNU General Public
-Licenses are intended to guarantee your freedom to share and change
-free software--to make sure the software is free for all its users.
-
- This license, the Lesser General Public License, applies to some
-specially designated software packages--typically libraries--of the
-Free Software Foundation and other authors who decide to use it. You
-can use it too, but we suggest you first think carefully about whether
-this license or the ordinary General Public License is the better
-strategy to use in any particular case, based on the explanations below.
-
- When we speak of free software, we are referring to freedom of use,
-not price. Our General Public Licenses are designed to make sure that
-you have the freedom to distribute copies of free software (and charge
-for this service if you wish); that you receive source code or can get
-it if you want it; that you can change the software and use pieces of
-it in new free programs; and that you are informed that you can do
-these things.
-
- To protect your rights, we need to make restrictions that forbid
-distributors to deny you these rights or to ask you to surrender these
-rights. These restrictions translate to certain responsibilities for
-you if you distribute copies of the library or if you modify it.
-
- For example, if you distribute copies of the library, whether gratis
-or for a fee, you must give the recipients all the rights that we gave
-you. You must make sure that they, too, receive or can get the source
-code. If you link other code with the library, you must provide
-complete object files to the recipients, so that they can relink them
-with the library after making changes to the library and recompiling
-it. And you must show them these terms so they know their rights.
-
- We protect your rights with a two-step method: (1) we copyright the
-library, and (2) we offer you this license, which gives you legal
-permission to copy, distribute and/or modify the library.
-
- To protect each distributor, we want to make it very clear that
-there is no warranty for the free library. Also, if the library is
-modified by someone else and passed on, the recipients should know
-that what they have is not the original version, so that the original
-author's reputation will not be affected by problems that might be
-introduced by others.
-
- Finally, software patents pose a constant threat to the existence of
-any free program. We wish to make sure that a company cannot
-effectively restrict the users of a free program by obtaining a
-restrictive license from a patent holder. Therefore, we insist that
-any patent license obtained for a version of the library must be
-consistent with the full freedom of use specified in this license.
-
- Most GNU software, including some libraries, is covered by the
-ordinary GNU General Public License. This license, the GNU Lesser
-General Public License, applies to certain designated libraries, and
-is quite different from the ordinary General Public License. We use
-this license for certain libraries in order to permit linking those
-libraries into non-free programs.
-
- When a program is linked with a library, whether statically or using
-a shared library, the combination of the two is legally speaking a
-combined work, a derivative of the original library. The ordinary
-General Public License therefore permits such linking only if the
-entire combination fits its criteria of freedom. The Lesser General
-Public License permits more lax criteria for linking other code with
-the library.
-
- We call this license the "Lesser" General Public License because it
-does Less to protect the user's freedom than the ordinary General
-Public License. It also provides other free software developers Less
-of an advantage over competing non-free programs. These disadvantages
-are the reason we use the ordinary General Public License for many
-libraries. However, the Lesser license provides advantages in certain
-special circumstances.
-
- For example, on rare occasions, there may be a special need to
-encourage the widest possible use of a certain library, so that it becomes
-a de-facto standard. To achieve this, non-free programs must be
-allowed to use the library. A more frequent case is that a free
-library does the same job as widely used non-free libraries. In this
-case, there is little to gain by limiting the free library to free
-software only, so we use the Lesser General Public License.
-
- In other cases, permission to use a particular library in non-free
-programs enables a greater number of people to use a large body of
-free software. For example, permission to use the GNU C Library in
-non-free programs enables many more people to use the whole GNU
-operating system, as well as its variant, the GNU/Linux operating
-system.
-
- Although the Lesser General Public License is Less protective of the
-users' freedom, it does ensure that the user of a program that is
-linked with the Library has the freedom and the wherewithal to run
-that program using a modified version of the Library.
-
- The precise terms and conditions for copying, distribution and
-modification follow. Pay close attention to the difference between a
-"work based on the library" and a "work that uses the library". The
-former contains code derived from the library, whereas the latter must
-be combined with the library in order to run.
-
- GNU LESSER GENERAL PUBLIC LICENSE
- TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
- 0. This License Agreement applies to any software library or other
-program which contains a notice placed by the copyright holder or
-other authorized party saying it may be distributed under the terms of
-this Lesser General Public License (also called "this License").
-Each licensee is addressed as "you".
-
- A "library" means a collection of software functions and/or data
-prepared so as to be conveniently linked with application programs
-(which use some of those functions and data) to form executables.
-
- The "Library", below, refers to any such software library or work
-which has been distributed under these terms. A "work based on the
-Library" means either the Library or any derivative work under
-copyright law: that is to say, a work containing the Library or a
-portion of it, either verbatim or with modifications and/or translated
-straightforwardly into another language. (Hereinafter, translation is
-included without limitation in the term "modification".)
-
- "Source code" for a work means the preferred form of the work for
-making modifications to it. For a library, complete source code means
-all the source code for all modules it contains, plus any associated
-interface definition files, plus the scripts used to control compilation
-and installation of the library.
-
- Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope. The act of
-running a program using the Library is not restricted, and output from
-such a program is covered only if its contents constitute a work based
-on the Library (independent of the use of the Library in a tool for
-writing it). Whether that is true depends on what the Library does
-and what the program that uses the Library does.
-
- 1. You may copy and distribute verbatim copies of the Library's
-complete source code as you receive it, in any medium, provided that
-you conspicuously and appropriately publish on each copy an
-appropriate copyright notice and disclaimer of warranty; keep intact
-all the notices that refer to this License and to the absence of any
-warranty; and distribute a copy of this License along with the
-Library.
-
- You may charge a fee for the physical act of transferring a copy,
-and you may at your option offer warranty protection in exchange for a
-fee.
-
- 2. You may modify your copy or copies of the Library or any portion
-of it, thus forming a work based on the Library, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
- a) The modified work must itself be a software library.
-
- b) You must cause the files modified to carry prominent notices
- stating that you changed the files and the date of any change.
-
- c) You must cause the whole of the work to be licensed at no
- charge to all third parties under the terms of this License.
-
- d) If a facility in the modified Library refers to a function or a
- table of data to be supplied by an application program that uses
- the facility, other than as an argument passed when the facility
- is invoked, then you must make a good faith effort to ensure that,
- in the event an application does not supply such function or
- table, the facility still operates, and performs whatever part of
- its purpose remains meaningful.
-
- (For example, a function in a library to compute square roots has
- a purpose that is entirely well-defined independent of the
- application. Therefore, Subsection 2d requires that any
- application-supplied function or table used by this function must
- be optional: if the application does not supply it, the square
- root function must still compute square roots.)
-
-These requirements apply to the modified work as a whole. If
-identifiable sections of that work are not derived from the Library,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works. But when you
-distribute the same sections as part of a whole which is a work based
-on the Library, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote
-it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Library.
-
-In addition, mere aggregation of another work not based on the Library
-with the Library (or with a work based on the Library) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
- 3. You may opt to apply the terms of the ordinary GNU General Public
-License instead of this License to a given copy of the Library. To do
-this, you must alter all the notices that refer to this License, so
-that they refer to the ordinary GNU General Public License, version 2,
-instead of to this License. (If a newer version than version 2 of the
-ordinary GNU General Public License has appeared, then you can specify
-that version instead if you wish.) Do not make any other change in
-these notices.
-
- Once this change is made in a given copy, it is irreversible for
-that copy, so the ordinary GNU General Public License applies to all
-subsequent copies and derivative works made from that copy.
-
- This option is useful when you wish to copy part of the code of
-the Library into a program that is not a library.
-
- 4. You may copy and distribute the Library (or a portion or
-derivative of it, under Section 2) in object code or executable form
-under the terms of Sections 1 and 2 above provided that you accompany
-it with the complete corresponding machine-readable source code, which
-must be distributed under the terms of Sections 1 and 2 above on a
-medium customarily used for software interchange.
-
- If distribution of object code is made by offering access to copy
-from a designated place, then offering equivalent access to copy the
-source code from the same place satisfies the requirement to
-distribute the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
- 5. A program that contains no derivative of any portion of the
-Library, but is designed to work with the Library by being compiled or
-linked with it, is called a "work that uses the Library". Such a
-work, in isolation, is not a derivative work of the Library, and
-therefore falls outside the scope of this License.
-
- However, linking a "work that uses the Library" with the Library
-creates an executable that is a derivative of the Library (because it
-contains portions of the Library), rather than a "work that uses the
-library". The executable is therefore covered by this License.
-Section 6 states terms for distribution of such executables.
-
- When a "work that uses the Library" uses material from a header file
-that is part of the Library, the object code for the work may be a
-derivative work of the Library even though the source code is not.
-Whether this is true is especially significant if the work can be
-linked without the Library, or if the work is itself a library. The
-threshold for this to be true is not precisely defined by law.
-
- If such an object file uses only numerical parameters, data
-structure layouts and accessors, and small macros and small inline
-functions (ten lines or less in length), then the use of the object
-file is unrestricted, regardless of whether it is legally a derivative
-work. (Executables containing this object code plus portions of the
-Library will still fall under Section 6.)
-
- Otherwise, if the work is a derivative of the Library, you may
-distribute the object code for the work under the terms of Section 6.
-Any executables containing that work also fall under Section 6,
-whether or not they are linked directly with the Library itself.
-
- 6. As an exception to the Sections above, you may also combine or
-link a "work that uses the Library" with the Library to produce a
-work containing portions of the Library, and distribute that work
-under terms of your choice, provided that the terms permit
-modification of the work for the customer's own use and reverse
-engineering for debugging such modifications.
-
- You must give prominent notice with each copy of the work that the
-Library is used in it and that the Library and its use are covered by
-this License. You must supply a copy of this License. If the work
-during execution displays copyright notices, you must include the
-copyright notice for the Library among them, as well as a reference
-directing the user to the copy of this License. Also, you must do one
-of these things:
-
- a) Accompany the work with the complete corresponding
- machine-readable source code for the Library including whatever
- changes were used in the work (which must be distributed under
- Sections 1 and 2 above); and, if the work is an executable linked
- with the Library, with the complete machine-readable "work that
- uses the Library", as object code and/or source code, so that the
- user can modify the Library and then relink to produce a modified
- executable containing the modified Library. (It is understood
- that the user who changes the contents of definitions files in the
- Library will not necessarily be able to recompile the application
- to use the modified definitions.)
-
- b) Use a suitable shared library mechanism for linking with the
- Library. A suitable mechanism is one that (1) uses at run time a
- copy of the library already present on the user's computer system,
- rather than copying library functions into the executable, and (2)
- will operate properly with a modified version of the library, if
- the user installs one, as long as the modified version is
- interface-compatible with the version that the work was made with.
-
- c) Accompany the work with a written offer, valid for at
- least three years, to give the same user the materials
- specified in Subsection 6a, above, for a charge no more
- than the cost of performing this distribution.
-
- d) If distribution of the work is made by offering access to copy
- from a designated place, offer equivalent access to copy the above
- specified materials from the same place.
-
- e) Verify that the user has already received a copy of these
- materials or that you have already sent this user a copy.
-
- For an executable, the required form of the "work that uses the
-Library" must include any data and utility programs needed for
-reproducing the executable from it. However, as a special exception,
-the materials to be distributed need not include anything that is
-normally distributed (in either source or binary form) with the major
-components (compiler, kernel, and so on) of the operating system on
-which the executable runs, unless that component itself accompanies
-the executable.
-
- It may happen that this requirement contradicts the license
-restrictions of other proprietary libraries that do not normally
-accompany the operating system. Such a contradiction means you cannot
-use both them and the Library together in an executable that you
-distribute.
-
- 7. You may place library facilities that are a work based on the
-Library side-by-side in a single library together with other library
-facilities not covered by this License, and distribute such a combined
-library, provided that the separate distribution of the work based on
-the Library and of the other library facilities is otherwise
-permitted, and provided that you do these two things:
-
- a) Accompany the combined library with a copy of the same work
- based on the Library, uncombined with any other library
- facilities. This must be distributed under the terms of the
- Sections above.
-
- b) Give prominent notice with the combined library of the fact
- that part of it is a work based on the Library, and explaining
- where to find the accompanying uncombined form of the same work.
-
- 8. You may not copy, modify, sublicense, link with, or distribute
-the Library except as expressly provided under this License. Any
-attempt otherwise to copy, modify, sublicense, link with, or
-distribute the Library is void, and will automatically terminate your
-rights under this License. However, parties who have received copies,
-or rights, from you under this License will not have their licenses
-terminated so long as such parties remain in full compliance.
-
- 9. You are not required to accept this License, since you have not
-signed it. However, nothing else grants you permission to modify or
-distribute the Library or its derivative works. These actions are
-prohibited by law if you do not accept this License. Therefore, by
-modifying or distributing the Library (or any work based on the
-Library), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Library or works based on it.
-
- 10. Each time you redistribute the Library (or any work based on the
-Library), the recipient automatically receives a license from the
-original licensor to copy, distribute, link with or modify the Library
-subject to these terms and conditions. You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties with
-this License.
-
- 11. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License. If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Library at all. For example, if a patent
-license would not permit royalty-free redistribution of the Library by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Library.
-
-If any portion of this section is held invalid or unenforceable under any
-particular circumstance, the balance of the section is intended to apply,
-and the section as a whole is intended to apply in other circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system which is
-implemented by public license practices. Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
- 12. If the distribution and/or use of the Library is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Library under this License may add
-an explicit geographical distribution limitation excluding those countries,
-so that distribution is permitted only in or among countries not thus
-excluded. In such case, this License incorporates the limitation as if
-written in the body of this License.
-
- 13. The Free Software Foundation may publish revised and/or new
-versions of the Lesser General Public License from time to time.
-Such new versions will be similar in spirit to the present version,
-but may differ in detail to address new problems or concerns.
-
-Each version is given a distinguishing version number. If the Library
-specifies a version number of this License which applies to it and
-"any later version", you have the option of following the terms and
-conditions either of that version or of any later version published by
-the Free Software Foundation. If the Library does not specify a
-license version number, you may choose any version ever published by
-the Free Software Foundation.
-
- 14. If you wish to incorporate parts of the Library into other free
-programs whose distribution conditions are incompatible with these,
-write to the author to ask for permission. For software which is
-copyrighted by the Free Software Foundation, write to the Free
-Software Foundation; we sometimes make exceptions for this. Our
-decision will be guided by the two goals of preserving the free status
-of all derivatives of our free software and of promoting the sharing
-and reuse of software generally.
-
- NO WARRANTY
-
- 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
-WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
-EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
-OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
-KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
-LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
-THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
-
- 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
-WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
-AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
-FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
-CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
-LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
-RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
-FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
-SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
-DAMAGES.
-
- END OF TERMS AND CONDITIONS
-
- How to Apply These Terms to Your New Libraries
-
- If you develop a new library, and you want it to be of the greatest
-possible use to the public, we recommend making it free software that
-everyone can redistribute and change. You can do so by permitting
-redistribution under these terms (or, alternatively, under the terms of the
-ordinary General Public License).
-
- To apply these terms, attach the following notices to the library. It is
-safest to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least the
-"copyright" line and a pointer to where the full notice is found.
-
-
- Copyright (C)
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-Also add information on how to contact you by electronic and paper mail.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the library, if
-necessary. Here is a sample; alter the names:
-
- Yoyodyne, Inc., hereby disclaims all copyright interest in the
- library `Frob' (a library for tweaking knobs) written by James Random Hacker.
-
- , 1 April 1990
- Ty Coon, President of Vice
-
-That's all there is to it!
-
-
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 2.1, February 1999
+
+ Copyright (C) 1991, 1999 Free Software Foundation, Inc.
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+[This is the first released version of the Lesser GPL. It also counts
+ as the successor of the GNU Library Public License, version 2, hence
+ the version number 2.1.]
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+Licenses are intended to guarantee your freedom to share and change
+free software--to make sure the software is free for all its users.
+
+ This license, the Lesser General Public License, applies to some
+specially designated software packages--typically libraries--of the
+Free Software Foundation and other authors who decide to use it. You
+can use it too, but we suggest you first think carefully about whether
+this license or the ordinary General Public License is the better
+strategy to use in any particular case, based on the explanations below.
+
+ When we speak of free software, we are referring to freedom of use,
+not price. Our General Public Licenses are designed to make sure that
+you have the freedom to distribute copies of free software (and charge
+for this service if you wish); that you receive source code or can get
+it if you want it; that you can change the software and use pieces of
+it in new free programs; and that you are informed that you can do
+these things.
+
+ To protect your rights, we need to make restrictions that forbid
+distributors to deny you these rights or to ask you to surrender these
+rights. These restrictions translate to certain responsibilities for
+you if you distribute copies of the library or if you modify it.
+
+ For example, if you distribute copies of the library, whether gratis
+or for a fee, you must give the recipients all the rights that we gave
+you. You must make sure that they, too, receive or can get the source
+code. If you link other code with the library, you must provide
+complete object files to the recipients, so that they can relink them
+with the library after making changes to the library and recompiling
+it. And you must show them these terms so they know their rights.
+
+ We protect your rights with a two-step method: (1) we copyright the
+library, and (2) we offer you this license, which gives you legal
+permission to copy, distribute and/or modify the library.
+
+ To protect each distributor, we want to make it very clear that
+there is no warranty for the free library. Also, if the library is
+modified by someone else and passed on, the recipients should know
+that what they have is not the original version, so that the original
+author's reputation will not be affected by problems that might be
+introduced by others.
+
+ Finally, software patents pose a constant threat to the existence of
+any free program. We wish to make sure that a company cannot
+effectively restrict the users of a free program by obtaining a
+restrictive license from a patent holder. Therefore, we insist that
+any patent license obtained for a version of the library must be
+consistent with the full freedom of use specified in this license.
+
+ Most GNU software, including some libraries, is covered by the
+ordinary GNU General Public License. This license, the GNU Lesser
+General Public License, applies to certain designated libraries, and
+is quite different from the ordinary General Public License. We use
+this license for certain libraries in order to permit linking those
+libraries into non-free programs.
+
+ When a program is linked with a library, whether statically or using
+a shared library, the combination of the two is legally speaking a
+combined work, a derivative of the original library. The ordinary
+General Public License therefore permits such linking only if the
+entire combination fits its criteria of freedom. The Lesser General
+Public License permits more lax criteria for linking other code with
+the library.
+
+ We call this license the "Lesser" General Public License because it
+does Less to protect the user's freedom than the ordinary General
+Public License. It also provides other free software developers Less
+of an advantage over competing non-free programs. These disadvantages
+are the reason we use the ordinary General Public License for many
+libraries. However, the Lesser license provides advantages in certain
+special circumstances.
+
+ For example, on rare occasions, there may be a special need to
+encourage the widest possible use of a certain library, so that it becomes
+a de-facto standard. To achieve this, non-free programs must be
+allowed to use the library. A more frequent case is that a free
+library does the same job as widely used non-free libraries. In this
+case, there is little to gain by limiting the free library to free
+software only, so we use the Lesser General Public License.
+
+ In other cases, permission to use a particular library in non-free
+programs enables a greater number of people to use a large body of
+free software. For example, permission to use the GNU C Library in
+non-free programs enables many more people to use the whole GNU
+operating system, as well as its variant, the GNU/Linux operating
+system.
+
+ Although the Lesser General Public License is Less protective of the
+users' freedom, it does ensure that the user of a program that is
+linked with the Library has the freedom and the wherewithal to run
+that program using a modified version of the Library.
+
+ The precise terms and conditions for copying, distribution and
+modification follow. Pay close attention to the difference between a
+"work based on the library" and a "work that uses the library". The
+former contains code derived from the library, whereas the latter must
+be combined with the library in order to run.
+
+ GNU LESSER GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License Agreement applies to any software library or other
+program which contains a notice placed by the copyright holder or
+other authorized party saying it may be distributed under the terms of
+this Lesser General Public License (also called "this License").
+Each licensee is addressed as "you".
+
+ A "library" means a collection of software functions and/or data
+prepared so as to be conveniently linked with application programs
+(which use some of those functions and data) to form executables.
+
+ The "Library", below, refers to any such software library or work
+which has been distributed under these terms. A "work based on the
+Library" means either the Library or any derivative work under
+copyright law: that is to say, a work containing the Library or a
+portion of it, either verbatim or with modifications and/or translated
+straightforwardly into another language. (Hereinafter, translation is
+included without limitation in the term "modification".)
+
+ "Source code" for a work means the preferred form of the work for
+making modifications to it. For a library, complete source code means
+all the source code for all modules it contains, plus any associated
+interface definition files, plus the scripts used to control compilation
+and installation of the library.
+
+ Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running a program using the Library is not restricted, and output from
+such a program is covered only if its contents constitute a work based
+on the Library (independent of the use of the Library in a tool for
+writing it). Whether that is true depends on what the Library does
+and what the program that uses the Library does.
+
+ 1. You may copy and distribute verbatim copies of the Library's
+complete source code as you receive it, in any medium, provided that
+you conspicuously and appropriately publish on each copy an
+appropriate copyright notice and disclaimer of warranty; keep intact
+all the notices that refer to this License and to the absence of any
+warranty; and distribute a copy of this License along with the
+Library.
+
+ You may charge a fee for the physical act of transferring a copy,
+and you may at your option offer warranty protection in exchange for a
+fee.
+
+ 2. You may modify your copy or copies of the Library or any portion
+of it, thus forming a work based on the Library, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) The modified work must itself be a software library.
+
+ b) You must cause the files modified to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ c) You must cause the whole of the work to be licensed at no
+ charge to all third parties under the terms of this License.
+
+ d) If a facility in the modified Library refers to a function or a
+ table of data to be supplied by an application program that uses
+ the facility, other than as an argument passed when the facility
+ is invoked, then you must make a good faith effort to ensure that,
+ in the event an application does not supply such function or
+ table, the facility still operates, and performs whatever part of
+ its purpose remains meaningful.
+
+ (For example, a function in a library to compute square roots has
+ a purpose that is entirely well-defined independent of the
+ application. Therefore, Subsection 2d requires that any
+ application-supplied function or table used by this function must
+ be optional: if the application does not supply it, the square
+ root function must still compute square roots.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Library,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Library, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote
+it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Library.
+
+In addition, mere aggregation of another work not based on the Library
+with the Library (or with a work based on the Library) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may opt to apply the terms of the ordinary GNU General Public
+License instead of this License to a given copy of the Library. To do
+this, you must alter all the notices that refer to this License, so
+that they refer to the ordinary GNU General Public License, version 2,
+instead of to this License. (If a newer version than version 2 of the
+ordinary GNU General Public License has appeared, then you can specify
+that version instead if you wish.) Do not make any other change in
+these notices.
+
+ Once this change is made in a given copy, it is irreversible for
+that copy, so the ordinary GNU General Public License applies to all
+subsequent copies and derivative works made from that copy.
+
+ This option is useful when you wish to copy part of the code of
+the Library into a program that is not a library.
+
+ 4. You may copy and distribute the Library (or a portion or
+derivative of it, under Section 2) in object code or executable form
+under the terms of Sections 1 and 2 above provided that you accompany
+it with the complete corresponding machine-readable source code, which
+must be distributed under the terms of Sections 1 and 2 above on a
+medium customarily used for software interchange.
+
+ If distribution of object code is made by offering access to copy
+from a designated place, then offering equivalent access to copy the
+source code from the same place satisfies the requirement to
+distribute the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 5. A program that contains no derivative of any portion of the
+Library, but is designed to work with the Library by being compiled or
+linked with it, is called a "work that uses the Library". Such a
+work, in isolation, is not a derivative work of the Library, and
+therefore falls outside the scope of this License.
+
+ However, linking a "work that uses the Library" with the Library
+creates an executable that is a derivative of the Library (because it
+contains portions of the Library), rather than a "work that uses the
+library". The executable is therefore covered by this License.
+Section 6 states terms for distribution of such executables.
+
+ When a "work that uses the Library" uses material from a header file
+that is part of the Library, the object code for the work may be a
+derivative work of the Library even though the source code is not.
+Whether this is true is especially significant if the work can be
+linked without the Library, or if the work is itself a library. The
+threshold for this to be true is not precisely defined by law.
+
+ If such an object file uses only numerical parameters, data
+structure layouts and accessors, and small macros and small inline
+functions (ten lines or less in length), then the use of the object
+file is unrestricted, regardless of whether it is legally a derivative
+work. (Executables containing this object code plus portions of the
+Library will still fall under Section 6.)
+
+ Otherwise, if the work is a derivative of the Library, you may
+distribute the object code for the work under the terms of Section 6.
+Any executables containing that work also fall under Section 6,
+whether or not they are linked directly with the Library itself.
+
+ 6. As an exception to the Sections above, you may also combine or
+link a "work that uses the Library" with the Library to produce a
+work containing portions of the Library, and distribute that work
+under terms of your choice, provided that the terms permit
+modification of the work for the customer's own use and reverse
+engineering for debugging such modifications.
+
+ You must give prominent notice with each copy of the work that the
+Library is used in it and that the Library and its use are covered by
+this License. You must supply a copy of this License. If the work
+during execution displays copyright notices, you must include the
+copyright notice for the Library among them, as well as a reference
+directing the user to the copy of this License. Also, you must do one
+of these things:
+
+ a) Accompany the work with the complete corresponding
+ machine-readable source code for the Library including whatever
+ changes were used in the work (which must be distributed under
+ Sections 1 and 2 above); and, if the work is an executable linked
+ with the Library, with the complete machine-readable "work that
+ uses the Library", as object code and/or source code, so that the
+ user can modify the Library and then relink to produce a modified
+ executable containing the modified Library. (It is understood
+ that the user who changes the contents of definitions files in the
+ Library will not necessarily be able to recompile the application
+ to use the modified definitions.)
+
+ b) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (1) uses at run time a
+ copy of the library already present on the user's computer system,
+ rather than copying library functions into the executable, and (2)
+ will operate properly with a modified version of the library, if
+ the user installs one, as long as the modified version is
+ interface-compatible with the version that the work was made with.
+
+ c) Accompany the work with a written offer, valid for at
+ least three years, to give the same user the materials
+ specified in Subsection 6a, above, for a charge no more
+ than the cost of performing this distribution.
+
+ d) If distribution of the work is made by offering access to copy
+ from a designated place, offer equivalent access to copy the above
+ specified materials from the same place.
+
+ e) Verify that the user has already received a copy of these
+ materials or that you have already sent this user a copy.
+
+ For an executable, the required form of the "work that uses the
+Library" must include any data and utility programs needed for
+reproducing the executable from it. However, as a special exception,
+the materials to be distributed need not include anything that is
+normally distributed (in either source or binary form) with the major
+components (compiler, kernel, and so on) of the operating system on
+which the executable runs, unless that component itself accompanies
+the executable.
+
+ It may happen that this requirement contradicts the license
+restrictions of other proprietary libraries that do not normally
+accompany the operating system. Such a contradiction means you cannot
+use both them and the Library together in an executable that you
+distribute.
+
+ 7. You may place library facilities that are a work based on the
+Library side-by-side in a single library together with other library
+facilities not covered by this License, and distribute such a combined
+library, provided that the separate distribution of the work based on
+the Library and of the other library facilities is otherwise
+permitted, and provided that you do these two things:
+
+ a) Accompany the combined library with a copy of the same work
+ based on the Library, uncombined with any other library
+ facilities. This must be distributed under the terms of the
+ Sections above.
+
+ b) Give prominent notice with the combined library of the fact
+ that part of it is a work based on the Library, and explaining
+ where to find the accompanying uncombined form of the same work.
+
+ 8. You may not copy, modify, sublicense, link with, or distribute
+the Library except as expressly provided under this License. Any
+attempt otherwise to copy, modify, sublicense, link with, or
+distribute the Library is void, and will automatically terminate your
+rights under this License. However, parties who have received copies,
+or rights, from you under this License will not have their licenses
+terminated so long as such parties remain in full compliance.
+
+ 9. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Library or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Library (or any work based on the
+Library), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Library or works based on it.
+
+ 10. Each time you redistribute the Library (or any work based on the
+Library), the recipient automatically receives a license from the
+original licensor to copy, distribute, link with or modify the Library
+subject to these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties with
+this License.
+
+ 11. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Library at all. For example, if a patent
+license would not permit royalty-free redistribution of the Library by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Library.
+
+If any portion of this section is held invalid or unenforceable under any
+particular circumstance, the balance of the section is intended to apply,
+and the section as a whole is intended to apply in other circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 12. If the distribution and/or use of the Library is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Library under this License may add
+an explicit geographical distribution limitation excluding those countries,
+so that distribution is permitted only in or among countries not thus
+excluded. In such case, this License incorporates the limitation as if
+written in the body of this License.
+
+ 13. The Free Software Foundation may publish revised and/or new
+versions of the Lesser General Public License from time to time.
+Such new versions will be similar in spirit to the present version,
+but may differ in detail to address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Library
+specifies a version number of this License which applies to it and
+"any later version", you have the option of following the terms and
+conditions either of that version or of any later version published by
+the Free Software Foundation. If the Library does not specify a
+license version number, you may choose any version ever published by
+the Free Software Foundation.
+
+ 14. If you wish to incorporate parts of the Library into other free
+programs whose distribution conditions are incompatible with these,
+write to the author to ask for permission. For software which is
+copyrighted by the Free Software Foundation, write to the Free
+Software Foundation; we sometimes make exceptions for this. Our
+decision will be guided by the two goals of preserving the free status
+of all derivatives of our free software and of promoting the sharing
+and reuse of software generally.
+
+ NO WARRANTY
+
+ 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
+WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
+KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
+LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
+THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
+WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
+AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
+FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
+CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
+LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
+RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
+FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
+SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Libraries
+
+ If you develop a new library, and you want it to be of the greatest
+possible use to the public, we recommend making it free software that
+everyone can redistribute and change. You can do so by permitting
+redistribution under these terms (or, alternatively, under the terms of the
+ordinary General Public License).
+
+ To apply these terms, attach the following notices to the library. It is
+safest to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least the
+"copyright" line and a pointer to where the full notice is found.
+
+
+ Copyright (C)
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+Also add information on how to contact you by electronic and paper mail.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the library, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the
+ library `Frob' (a library for tweaking knobs) written by James Random Hacker.
+
+ , 1 April 1990
+ Ty Coon, President of Vice
+
+That's all there is to it!
+
+
diff --git a/htdocs/includes/phpexcel/PHPExcel/Shared/PCLZip/pclzip.lib.php b/htdocs/includes/phpexcel/PHPExcel/Shared/PCLZip/pclzip.lib.php
index 4bf05a52365..e7facc1eaa1 100644
--- a/htdocs/includes/phpexcel/PHPExcel/Shared/PCLZip/pclzip.lib.php
+++ b/htdocs/includes/phpexcel/PHPExcel/Shared/PCLZip/pclzip.lib.php
@@ -1,5694 +1,5694 @@
-zipname = $p_zipname;
- $this->zip_fd = 0;
- $this->magic_quotes_status = -1;
-
- // ----- Return
- return;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function :
- // create($p_filelist, $p_add_dir="", $p_remove_dir="")
- // create($p_filelist, $p_option, $p_option_value, ...)
- // Description :
- // This method supports two different synopsis. The first one is historical.
- // This method creates a Zip Archive. The Zip file is created in the
- // filesystem. The files and directories indicated in $p_filelist
- // are added in the archive. See the parameters description for the
- // supported format of $p_filelist.
- // When a directory is in the list, the directory and its content is added
- // in the archive.
- // In this synopsis, the function takes an optional variable list of
- // options. See bellow the supported options.
- // Parameters :
- // $p_filelist : An array containing file or directory names, or
- // a string containing one filename or one directory name, or
- // a string containing a list of filenames and/or directory
- // names separated by spaces.
- // $p_add_dir : A path to add before the real path of the archived file,
- // in order to have it memorized in the archive.
- // $p_remove_dir : A path to remove from the real path of the file to archive,
- // in order to have a shorter path memorized in the archive.
- // When $p_add_dir and $p_remove_dir are set, $p_remove_dir
- // is removed first, before $p_add_dir is added.
- // Options :
- // PCLZIP_OPT_ADD_PATH :
- // PCLZIP_OPT_REMOVE_PATH :
- // PCLZIP_OPT_REMOVE_ALL_PATH :
- // PCLZIP_OPT_COMMENT :
- // PCLZIP_CB_PRE_ADD :
- // PCLZIP_CB_POST_ADD :
- // Return Values :
- // 0 on failure,
- // The list of the added files, with a status of the add action.
- // (see PclZip::listContent() for list entry format)
- // --------------------------------------------------------------------------------
- function create($p_filelist)
- {
- $v_result=1;
-
- // ----- Reset the error handler
- $this->privErrorReset();
-
- // ----- Set default values
- $v_options = array();
- $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE;
-
- // ----- Look for variable options arguments
- $v_size = func_num_args();
-
- // ----- Look for arguments
- if ($v_size > 1) {
- // ----- Get the arguments
- $v_arg_list = func_get_args();
-
- // ----- Remove from the options list the first argument
- array_shift($v_arg_list);
- $v_size--;
-
- // ----- Look for first arg
- if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
-
- // ----- Parse the options
- $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
- array (PCLZIP_OPT_REMOVE_PATH => 'optional',
- PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
- PCLZIP_OPT_ADD_PATH => 'optional',
- PCLZIP_CB_PRE_ADD => 'optional',
- PCLZIP_CB_POST_ADD => 'optional',
- PCLZIP_OPT_NO_COMPRESSION => 'optional',
- PCLZIP_OPT_COMMENT => 'optional',
- PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
- PCLZIP_OPT_TEMP_FILE_ON => 'optional',
- PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
- //, PCLZIP_OPT_CRYPT => 'optional'
- ));
- if ($v_result != 1) {
- return 0;
- }
- }
-
- // ----- Look for 2 args
- // Here we need to support the first historic synopsis of the
- // method.
- else {
-
- // ----- Get the first argument
- $v_options[PCLZIP_OPT_ADD_PATH] = $v_arg_list[0];
-
- // ----- Look for the optional second argument
- if ($v_size == 2) {
- $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1];
- }
- else if ($v_size > 2) {
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,
- "Invalid number / type of arguments");
- return 0;
- }
- }
- }
-
- // ----- Look for default option values
- $this->privOptionDefaultThreshold($v_options);
-
- // ----- Init
- $v_string_list = array();
- $v_att_list = array();
- $v_filedescr_list = array();
- $p_result_list = array();
-
- // ----- Look if the $p_filelist is really an array
- if (is_array($p_filelist)) {
-
- // ----- Look if the first element is also an array
- // This will mean that this is a file description entry
- if (isset($p_filelist[0]) && is_array($p_filelist[0])) {
- $v_att_list = $p_filelist;
- }
-
- // ----- The list is a list of string names
- else {
- $v_string_list = $p_filelist;
- }
- }
-
- // ----- Look if the $p_filelist is a string
- else if (is_string($p_filelist)) {
- // ----- Create a list from the string
- $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist);
- }
-
- // ----- Invalid variable type for $p_filelist
- else {
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_filelist");
- return 0;
- }
-
- // ----- Reformat the string list
- if (sizeof($v_string_list) != 0) {
- foreach ($v_string_list as $v_string) {
- if ($v_string != '') {
- $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string;
- }
- else {
- }
- }
- }
-
- // ----- For each file in the list check the attributes
- $v_supported_attributes
- = array ( PCLZIP_ATT_FILE_NAME => 'mandatory'
- ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional'
- ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional'
- ,PCLZIP_ATT_FILE_MTIME => 'optional'
- ,PCLZIP_ATT_FILE_CONTENT => 'optional'
- ,PCLZIP_ATT_FILE_COMMENT => 'optional'
- );
- foreach ($v_att_list as $v_entry) {
- $v_result = $this->privFileDescrParseAtt($v_entry,
- $v_filedescr_list[],
- $v_options,
- $v_supported_attributes);
- if ($v_result != 1) {
- return 0;
- }
- }
-
- // ----- Expand the filelist (expand directories)
- $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options);
- if ($v_result != 1) {
- return 0;
- }
-
- // ----- Call the create fct
- $v_result = $this->privCreate($v_filedescr_list, $p_result_list, $v_options);
- if ($v_result != 1) {
- return 0;
- }
-
- // ----- Return
- return $p_result_list;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function :
- // add($p_filelist, $p_add_dir="", $p_remove_dir="")
- // add($p_filelist, $p_option, $p_option_value, ...)
- // Description :
- // This method supports two synopsis. The first one is historical.
- // This methods add the list of files in an existing archive.
- // If a file with the same name already exists, it is added at the end of the
- // archive, the first one is still present.
- // If the archive does not exist, it is created.
- // Parameters :
- // $p_filelist : An array containing file or directory names, or
- // a string containing one filename or one directory name, or
- // a string containing a list of filenames and/or directory
- // names separated by spaces.
- // $p_add_dir : A path to add before the real path of the archived file,
- // in order to have it memorized in the archive.
- // $p_remove_dir : A path to remove from the real path of the file to archive,
- // in order to have a shorter path memorized in the archive.
- // When $p_add_dir and $p_remove_dir are set, $p_remove_dir
- // is removed first, before $p_add_dir is added.
- // Options :
- // PCLZIP_OPT_ADD_PATH :
- // PCLZIP_OPT_REMOVE_PATH :
- // PCLZIP_OPT_REMOVE_ALL_PATH :
- // PCLZIP_OPT_COMMENT :
- // PCLZIP_OPT_ADD_COMMENT :
- // PCLZIP_OPT_PREPEND_COMMENT :
- // PCLZIP_CB_PRE_ADD :
- // PCLZIP_CB_POST_ADD :
- // Return Values :
- // 0 on failure,
- // The list of the added files, with a status of the add action.
- // (see PclZip::listContent() for list entry format)
- // --------------------------------------------------------------------------------
- function add($p_filelist)
- {
- $v_result=1;
-
- // ----- Reset the error handler
- $this->privErrorReset();
-
- // ----- Set default values
- $v_options = array();
- $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE;
-
- // ----- Look for variable options arguments
- $v_size = func_num_args();
-
- // ----- Look for arguments
- if ($v_size > 1) {
- // ----- Get the arguments
- $v_arg_list = func_get_args();
-
- // ----- Remove form the options list the first argument
- array_shift($v_arg_list);
- $v_size--;
-
- // ----- Look for first arg
- if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
-
- // ----- Parse the options
- $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
- array (PCLZIP_OPT_REMOVE_PATH => 'optional',
- PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
- PCLZIP_OPT_ADD_PATH => 'optional',
- PCLZIP_CB_PRE_ADD => 'optional',
- PCLZIP_CB_POST_ADD => 'optional',
- PCLZIP_OPT_NO_COMPRESSION => 'optional',
- PCLZIP_OPT_COMMENT => 'optional',
- PCLZIP_OPT_ADD_COMMENT => 'optional',
- PCLZIP_OPT_PREPEND_COMMENT => 'optional',
- PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
- PCLZIP_OPT_TEMP_FILE_ON => 'optional',
- PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
- //, PCLZIP_OPT_CRYPT => 'optional'
- ));
- if ($v_result != 1) {
- return 0;
- }
- }
-
- // ----- Look for 2 args
- // Here we need to support the first historic synopsis of the
- // method.
- else {
-
- // ----- Get the first argument
- $v_options[PCLZIP_OPT_ADD_PATH] = $v_add_path = $v_arg_list[0];
-
- // ----- Look for the optional second argument
- if ($v_size == 2) {
- $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1];
- }
- else if ($v_size > 2) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
-
- // ----- Return
- return 0;
- }
- }
- }
-
- // ----- Look for default option values
- $this->privOptionDefaultThreshold($v_options);
-
- // ----- Init
- $v_string_list = array();
- $v_att_list = array();
- $v_filedescr_list = array();
- $p_result_list = array();
-
- // ----- Look if the $p_filelist is really an array
- if (is_array($p_filelist)) {
-
- // ----- Look if the first element is also an array
- // This will mean that this is a file description entry
- if (isset($p_filelist[0]) && is_array($p_filelist[0])) {
- $v_att_list = $p_filelist;
- }
-
- // ----- The list is a list of string names
- else {
- $v_string_list = $p_filelist;
- }
- }
-
- // ----- Look if the $p_filelist is a string
- else if (is_string($p_filelist)) {
- // ----- Create a list from the string
- $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist);
- }
-
- // ----- Invalid variable type for $p_filelist
- else {
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type '".gettype($p_filelist)."' for p_filelist");
- return 0;
- }
-
- // ----- Reformat the string list
- if (sizeof($v_string_list) != 0) {
- foreach ($v_string_list as $v_string) {
- $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string;
- }
- }
-
- // ----- For each file in the list check the attributes
- $v_supported_attributes
- = array ( PCLZIP_ATT_FILE_NAME => 'mandatory'
- ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional'
- ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional'
- ,PCLZIP_ATT_FILE_MTIME => 'optional'
- ,PCLZIP_ATT_FILE_CONTENT => 'optional'
- ,PCLZIP_ATT_FILE_COMMENT => 'optional'
- );
- foreach ($v_att_list as $v_entry) {
- $v_result = $this->privFileDescrParseAtt($v_entry,
- $v_filedescr_list[],
- $v_options,
- $v_supported_attributes);
- if ($v_result != 1) {
- return 0;
- }
- }
-
- // ----- Expand the filelist (expand directories)
- $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options);
- if ($v_result != 1) {
- return 0;
- }
-
- // ----- Call the create fct
- $v_result = $this->privAdd($v_filedescr_list, $p_result_list, $v_options);
- if ($v_result != 1) {
- return 0;
- }
-
- // ----- Return
- return $p_result_list;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : listContent()
- // Description :
- // This public method, gives the list of the files and directories, with their
- // properties.
- // The properties of each entries in the list are (used also in other functions) :
- // filename : Name of the file. For a create or add action it is the filename
- // given by the user. For an extract function it is the filename
- // of the extracted file.
- // stored_filename : Name of the file / directory stored in the archive.
- // size : Size of the stored file.
- // compressed_size : Size of the file's data compressed in the archive
- // (without the headers overhead)
- // mtime : Last known modification date of the file (UNIX timestamp)
- // comment : Comment associated with the file
- // folder : true | false
- // index : index of the file in the archive
- // status : status of the action (depending of the action) :
- // Values are :
- // ok : OK !
- // filtered : the file / dir is not extracted (filtered by user)
- // already_a_directory : the file can not be extracted because a
- // directory with the same name already exists
- // write_protected : the file can not be extracted because a file
- // with the same name already exists and is
- // write protected
- // newer_exist : the file was not extracted because a newer file exists
- // path_creation_fail : the file is not extracted because the folder
- // does not exist and can not be created
- // write_error : the file was not extracted because there was a
- // error while writing the file
- // read_error : the file was not extracted because there was a error
- // while reading the file
- // invalid_header : the file was not extracted because of an archive
- // format error (bad file header)
- // Note that each time a method can continue operating when there
- // is an action error on a file, the error is only logged in the file status.
- // Return Values :
- // 0 on an unrecoverable failure,
- // The list of the files in the archive.
- // --------------------------------------------------------------------------------
- function listContent()
- {
- $v_result=1;
-
- // ----- Reset the error handler
- $this->privErrorReset();
-
- // ----- Check archive
- if (!$this->privCheckFormat()) {
- return(0);
- }
-
- // ----- Call the extracting fct
- $p_list = array();
- if (($v_result = $this->privList($p_list)) != 1)
- {
- unset($p_list);
- return(0);
- }
-
- // ----- Return
- return $p_list;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function :
- // extract($p_path="./", $p_remove_path="")
- // extract([$p_option, $p_option_value, ...])
- // Description :
- // This method supports two synopsis. The first one is historical.
- // This method extract all the files / directories from the archive to the
- // folder indicated in $p_path.
- // If you want to ignore the 'root' part of path of the memorized files
- // you can indicate this in the optional $p_remove_path parameter.
- // By default, if a newer file with the same name already exists, the
- // file is not extracted.
- //
- // If both PCLZIP_OPT_PATH and PCLZIP_OPT_ADD_PATH aoptions
- // are used, the path indicated in PCLZIP_OPT_ADD_PATH is append
- // at the end of the path value of PCLZIP_OPT_PATH.
- // Parameters :
- // $p_path : Path where the files and directories are to be extracted
- // $p_remove_path : First part ('root' part) of the memorized path
- // (if any similar) to remove while extracting.
- // Options :
- // PCLZIP_OPT_PATH :
- // PCLZIP_OPT_ADD_PATH :
- // PCLZIP_OPT_REMOVE_PATH :
- // PCLZIP_OPT_REMOVE_ALL_PATH :
- // PCLZIP_CB_PRE_EXTRACT :
- // PCLZIP_CB_POST_EXTRACT :
- // Return Values :
- // 0 or a negative value on failure,
- // The list of the extracted files, with a status of the action.
- // (see PclZip::listContent() for list entry format)
- // --------------------------------------------------------------------------------
- function extract()
- {
- $v_result=1;
-
- // ----- Reset the error handler
- $this->privErrorReset();
-
- // ----- Check archive
- if (!$this->privCheckFormat()) {
- return(0);
- }
-
- // ----- Set default values
- $v_options = array();
-// $v_path = "./";
- $v_path = '';
- $v_remove_path = "";
- $v_remove_all_path = false;
-
- // ----- Look for variable options arguments
- $v_size = func_num_args();
-
- // ----- Default values for option
- $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
-
- // ----- Look for arguments
- if ($v_size > 0) {
- // ----- Get the arguments
- $v_arg_list = func_get_args();
-
- // ----- Look for first arg
- if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
-
- // ----- Parse the options
- $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
- array (PCLZIP_OPT_PATH => 'optional',
- PCLZIP_OPT_REMOVE_PATH => 'optional',
- PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
- PCLZIP_OPT_ADD_PATH => 'optional',
- PCLZIP_CB_PRE_EXTRACT => 'optional',
- PCLZIP_CB_POST_EXTRACT => 'optional',
- PCLZIP_OPT_SET_CHMOD => 'optional',
- PCLZIP_OPT_BY_NAME => 'optional',
- PCLZIP_OPT_BY_EREG => 'optional',
- PCLZIP_OPT_BY_PREG => 'optional',
- PCLZIP_OPT_BY_INDEX => 'optional',
- PCLZIP_OPT_EXTRACT_AS_STRING => 'optional',
- PCLZIP_OPT_EXTRACT_IN_OUTPUT => 'optional',
- PCLZIP_OPT_REPLACE_NEWER => 'optional'
- ,PCLZIP_OPT_STOP_ON_ERROR => 'optional'
- ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional',
- PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
- PCLZIP_OPT_TEMP_FILE_ON => 'optional',
- PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
- ));
- if ($v_result != 1) {
- return 0;
- }
-
- // ----- Set the arguments
- if (isset($v_options[PCLZIP_OPT_PATH])) {
- $v_path = $v_options[PCLZIP_OPT_PATH];
- }
- if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {
- $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH];
- }
- if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
- $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];
- }
- if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {
- // ----- Check for '/' in last path char
- if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) {
- $v_path .= '/';
- }
- $v_path .= $v_options[PCLZIP_OPT_ADD_PATH];
- }
- }
-
- // ----- Look for 2 args
- // Here we need to support the first historic synopsis of the
- // method.
- else {
-
- // ----- Get the first argument
- $v_path = $v_arg_list[0];
-
- // ----- Look for the optional second argument
- if ($v_size == 2) {
- $v_remove_path = $v_arg_list[1];
- }
- else if ($v_size > 2) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
-
- // ----- Return
- return 0;
- }
- }
- }
-
- // ----- Look for default option values
- $this->privOptionDefaultThreshold($v_options);
-
- // ----- Trace
-
- // ----- Call the extracting fct
- $p_list = array();
- $v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path,
- $v_remove_all_path, $v_options);
- if ($v_result < 1) {
- unset($p_list);
- return(0);
- }
-
- // ----- Return
- return $p_list;
- }
- // --------------------------------------------------------------------------------
-
-
- // --------------------------------------------------------------------------------
- // Function :
- // extractByIndex($p_index, $p_path="./", $p_remove_path="")
- // extractByIndex($p_index, [$p_option, $p_option_value, ...])
- // Description :
- // This method supports two synopsis. The first one is historical.
- // This method is doing a partial extract of the archive.
- // The extracted files or folders are identified by their index in the
- // archive (from 0 to n).
- // Note that if the index identify a folder, only the folder entry is
- // extracted, not all the files included in the archive.
- // Parameters :
- // $p_index : A single index (integer) or a string of indexes of files to
- // extract. The form of the string is "0,4-6,8-12" with only numbers
- // and '-' for range or ',' to separate ranges. No spaces or ';'
- // are allowed.
- // $p_path : Path where the files and directories are to be extracted
- // $p_remove_path : First part ('root' part) of the memorized path
- // (if any similar) to remove while extracting.
- // Options :
- // PCLZIP_OPT_PATH :
- // PCLZIP_OPT_ADD_PATH :
- // PCLZIP_OPT_REMOVE_PATH :
- // PCLZIP_OPT_REMOVE_ALL_PATH :
- // PCLZIP_OPT_EXTRACT_AS_STRING : The files are extracted as strings and
- // not as files.
- // The resulting content is in a new field 'content' in the file
- // structure.
- // This option must be used alone (any other options are ignored).
- // PCLZIP_CB_PRE_EXTRACT :
- // PCLZIP_CB_POST_EXTRACT :
- // Return Values :
- // 0 on failure,
- // The list of the extracted files, with a status of the action.
- // (see PclZip::listContent() for list entry format)
- // --------------------------------------------------------------------------------
- //function extractByIndex($p_index, options...)
- function extractByIndex($p_index)
- {
- $v_result=1;
-
- // ----- Reset the error handler
- $this->privErrorReset();
-
- // ----- Check archive
- if (!$this->privCheckFormat()) {
- return(0);
- }
-
- // ----- Set default values
- $v_options = array();
-// $v_path = "./";
- $v_path = '';
- $v_remove_path = "";
- $v_remove_all_path = false;
-
- // ----- Look for variable options arguments
- $v_size = func_num_args();
-
- // ----- Default values for option
- $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
-
- // ----- Look for arguments
- if ($v_size > 1) {
- // ----- Get the arguments
- $v_arg_list = func_get_args();
-
- // ----- Remove form the options list the first argument
- array_shift($v_arg_list);
- $v_size--;
-
- // ----- Look for first arg
- if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
-
- // ----- Parse the options
- $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
- array (PCLZIP_OPT_PATH => 'optional',
- PCLZIP_OPT_REMOVE_PATH => 'optional',
- PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
- PCLZIP_OPT_EXTRACT_AS_STRING => 'optional',
- PCLZIP_OPT_ADD_PATH => 'optional',
- PCLZIP_CB_PRE_EXTRACT => 'optional',
- PCLZIP_CB_POST_EXTRACT => 'optional',
- PCLZIP_OPT_SET_CHMOD => 'optional',
- PCLZIP_OPT_REPLACE_NEWER => 'optional'
- ,PCLZIP_OPT_STOP_ON_ERROR => 'optional'
- ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional',
- PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
- PCLZIP_OPT_TEMP_FILE_ON => 'optional',
- PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
- ));
- if ($v_result != 1) {
- return 0;
- }
-
- // ----- Set the arguments
- if (isset($v_options[PCLZIP_OPT_PATH])) {
- $v_path = $v_options[PCLZIP_OPT_PATH];
- }
- if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {
- $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH];
- }
- if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
- $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];
- }
- if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {
- // ----- Check for '/' in last path char
- if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) {
- $v_path .= '/';
- }
- $v_path .= $v_options[PCLZIP_OPT_ADD_PATH];
- }
- if (!isset($v_options[PCLZIP_OPT_EXTRACT_AS_STRING])) {
- $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
- }
- else {
- }
- }
-
- // ----- Look for 2 args
- // Here we need to support the first historic synopsis of the
- // method.
- else {
-
- // ----- Get the first argument
- $v_path = $v_arg_list[0];
-
- // ----- Look for the optional second argument
- if ($v_size == 2) {
- $v_remove_path = $v_arg_list[1];
- }
- else if ($v_size > 2) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
-
- // ----- Return
- return 0;
- }
- }
- }
-
- // ----- Trace
-
- // ----- Trick
- // Here I want to reuse extractByRule(), so I need to parse the $p_index
- // with privParseOptions()
- $v_arg_trick = array (PCLZIP_OPT_BY_INDEX, $p_index);
- $v_options_trick = array();
- $v_result = $this->privParseOptions($v_arg_trick, sizeof($v_arg_trick), $v_options_trick,
- array (PCLZIP_OPT_BY_INDEX => 'optional' ));
- if ($v_result != 1) {
- return 0;
- }
- $v_options[PCLZIP_OPT_BY_INDEX] = $v_options_trick[PCLZIP_OPT_BY_INDEX];
-
- // ----- Look for default option values
- $this->privOptionDefaultThreshold($v_options);
-
- // ----- Call the extracting fct
- if (($v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path, $v_remove_all_path, $v_options)) < 1) {
- return(0);
- }
-
- // ----- Return
- return $p_list;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function :
- // delete([$p_option, $p_option_value, ...])
- // Description :
- // This method removes files from the archive.
- // If no parameters are given, then all the archive is emptied.
- // Parameters :
- // None or optional arguments.
- // Options :
- // PCLZIP_OPT_BY_INDEX :
- // PCLZIP_OPT_BY_NAME :
- // PCLZIP_OPT_BY_EREG :
- // PCLZIP_OPT_BY_PREG :
- // Return Values :
- // 0 on failure,
- // The list of the files which are still present in the archive.
- // (see PclZip::listContent() for list entry format)
- // --------------------------------------------------------------------------------
- function delete()
- {
- $v_result=1;
-
- // ----- Reset the error handler
- $this->privErrorReset();
-
- // ----- Check archive
- if (!$this->privCheckFormat()) {
- return(0);
- }
-
- // ----- Set default values
- $v_options = array();
-
- // ----- Look for variable options arguments
- $v_size = func_num_args();
-
- // ----- Look for arguments
- if ($v_size > 0) {
- // ----- Get the arguments
- $v_arg_list = func_get_args();
-
- // ----- Parse the options
- $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
- array (PCLZIP_OPT_BY_NAME => 'optional',
- PCLZIP_OPT_BY_EREG => 'optional',
- PCLZIP_OPT_BY_PREG => 'optional',
- PCLZIP_OPT_BY_INDEX => 'optional' ));
- if ($v_result != 1) {
- return 0;
- }
- }
-
- // ----- Magic quotes trick
- $this->privDisableMagicQuotes();
-
- // ----- Call the delete fct
- $v_list = array();
- if (($v_result = $this->privDeleteByRule($v_list, $v_options)) != 1) {
- $this->privSwapBackMagicQuotes();
- unset($v_list);
- return(0);
- }
-
- // ----- Magic quotes trick
- $this->privSwapBackMagicQuotes();
-
- // ----- Return
- return $v_list;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : deleteByIndex()
- // Description :
- // ***** Deprecated *****
- // delete(PCLZIP_OPT_BY_INDEX, $p_index) should be prefered.
- // --------------------------------------------------------------------------------
- function deleteByIndex($p_index)
- {
-
- $p_list = $this->delete(PCLZIP_OPT_BY_INDEX, $p_index);
-
- // ----- Return
- return $p_list;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : properties()
- // Description :
- // This method gives the properties of the archive.
- // The properties are :
- // nb : Number of files in the archive
- // comment : Comment associated with the archive file
- // status : not_exist, ok
- // Parameters :
- // None
- // Return Values :
- // 0 on failure,
- // An array with the archive properties.
- // --------------------------------------------------------------------------------
- function properties()
- {
-
- // ----- Reset the error handler
- $this->privErrorReset();
-
- // ----- Magic quotes trick
- $this->privDisableMagicQuotes();
-
- // ----- Check archive
- if (!$this->privCheckFormat()) {
- $this->privSwapBackMagicQuotes();
- return(0);
- }
-
- // ----- Default properties
- $v_prop = array();
- $v_prop['comment'] = '';
- $v_prop['nb'] = 0;
- $v_prop['status'] = 'not_exist';
-
- // ----- Look if file exists
- if (@is_file($this->zipname))
- {
- // ----- Open the zip file
- if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0)
- {
- $this->privSwapBackMagicQuotes();
-
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode');
-
- // ----- Return
- return 0;
- }
-
- // ----- Read the central directory informations
- $v_central_dir = array();
- if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
- {
- $this->privSwapBackMagicQuotes();
- return 0;
- }
-
- // ----- Close the zip file
- $this->privCloseFd();
-
- // ----- Set the user attributes
- $v_prop['comment'] = $v_central_dir['comment'];
- $v_prop['nb'] = $v_central_dir['entries'];
- $v_prop['status'] = 'ok';
- }
-
- // ----- Magic quotes trick
- $this->privSwapBackMagicQuotes();
-
- // ----- Return
- return $v_prop;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : duplicate()
- // Description :
- // This method creates an archive by copying the content of an other one. If
- // the archive already exist, it is replaced by the new one without any warning.
- // Parameters :
- // $p_archive : The filename of a valid archive, or
- // a valid PclZip object.
- // Return Values :
- // 1 on success.
- // 0 or a negative value on error (error code).
- // --------------------------------------------------------------------------------
- function duplicate($p_archive)
- {
- $v_result = 1;
-
- // ----- Reset the error handler
- $this->privErrorReset();
-
- // ----- Look if the $p_archive is a PclZip object
- if ((is_object($p_archive)) && (get_class($p_archive) == 'pclzip'))
- {
-
- // ----- Duplicate the archive
- $v_result = $this->privDuplicate($p_archive->zipname);
- }
-
- // ----- Look if the $p_archive is a string (so a filename)
- else if (is_string($p_archive))
- {
-
- // ----- Check that $p_archive is a valid zip file
- // TBC : Should also check the archive format
- if (!is_file($p_archive)) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "No file with filename '".$p_archive."'");
- $v_result = PCLZIP_ERR_MISSING_FILE;
- }
- else {
- // ----- Duplicate the archive
- $v_result = $this->privDuplicate($p_archive);
- }
- }
-
- // ----- Invalid variable
- else
- {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add");
- $v_result = PCLZIP_ERR_INVALID_PARAMETER;
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : merge()
- // Description :
- // This method merge the $p_archive_to_add archive at the end of the current
- // one ($this).
- // If the archive ($this) does not exist, the merge becomes a duplicate.
- // If the $p_archive_to_add archive does not exist, the merge is a success.
- // Parameters :
- // $p_archive_to_add : It can be directly the filename of a valid zip archive,
- // or a PclZip object archive.
- // Return Values :
- // 1 on success,
- // 0 or negative values on error (see below).
- // --------------------------------------------------------------------------------
- function merge($p_archive_to_add)
- {
- $v_result = 1;
-
- // ----- Reset the error handler
- $this->privErrorReset();
-
- // ----- Check archive
- if (!$this->privCheckFormat()) {
- return(0);
- }
-
- // ----- Look if the $p_archive_to_add is a PclZip object
- if ((is_object($p_archive_to_add)) && (get_class($p_archive_to_add) == 'pclzip'))
- {
-
- // ----- Merge the archive
- $v_result = $this->privMerge($p_archive_to_add);
- }
-
- // ----- Look if the $p_archive_to_add is a string (so a filename)
- else if (is_string($p_archive_to_add))
- {
-
- // ----- Create a temporary archive
- $v_object_archive = new PclZip($p_archive_to_add);
-
- // ----- Merge the archive
- $v_result = $this->privMerge($v_object_archive);
- }
-
- // ----- Invalid variable
- else
- {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add");
- $v_result = PCLZIP_ERR_INVALID_PARAMETER;
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
-
-
- // --------------------------------------------------------------------------------
- // Function : errorCode()
- // Description :
- // Parameters :
- // --------------------------------------------------------------------------------
- function errorCode()
- {
- if (PCLZIP_ERROR_EXTERNAL == 1) {
- return(PclErrorCode());
- }
- else {
- return($this->error_code);
- }
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : errorName()
- // Description :
- // Parameters :
- // --------------------------------------------------------------------------------
- function errorName($p_with_code=false)
- {
- $v_name = array ( PCLZIP_ERR_NO_ERROR => 'PCLZIP_ERR_NO_ERROR',
- PCLZIP_ERR_WRITE_OPEN_FAIL => 'PCLZIP_ERR_WRITE_OPEN_FAIL',
- PCLZIP_ERR_READ_OPEN_FAIL => 'PCLZIP_ERR_READ_OPEN_FAIL',
- PCLZIP_ERR_INVALID_PARAMETER => 'PCLZIP_ERR_INVALID_PARAMETER',
- PCLZIP_ERR_MISSING_FILE => 'PCLZIP_ERR_MISSING_FILE',
- PCLZIP_ERR_FILENAME_TOO_LONG => 'PCLZIP_ERR_FILENAME_TOO_LONG',
- PCLZIP_ERR_INVALID_ZIP => 'PCLZIP_ERR_INVALID_ZIP',
- PCLZIP_ERR_BAD_EXTRACTED_FILE => 'PCLZIP_ERR_BAD_EXTRACTED_FILE',
- PCLZIP_ERR_DIR_CREATE_FAIL => 'PCLZIP_ERR_DIR_CREATE_FAIL',
- PCLZIP_ERR_BAD_EXTENSION => 'PCLZIP_ERR_BAD_EXTENSION',
- PCLZIP_ERR_BAD_FORMAT => 'PCLZIP_ERR_BAD_FORMAT',
- PCLZIP_ERR_DELETE_FILE_FAIL => 'PCLZIP_ERR_DELETE_FILE_FAIL',
- PCLZIP_ERR_RENAME_FILE_FAIL => 'PCLZIP_ERR_RENAME_FILE_FAIL',
- PCLZIP_ERR_BAD_CHECKSUM => 'PCLZIP_ERR_BAD_CHECKSUM',
- PCLZIP_ERR_INVALID_ARCHIVE_ZIP => 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP',
- PCLZIP_ERR_MISSING_OPTION_VALUE => 'PCLZIP_ERR_MISSING_OPTION_VALUE',
- PCLZIP_ERR_INVALID_OPTION_VALUE => 'PCLZIP_ERR_INVALID_OPTION_VALUE',
- PCLZIP_ERR_UNSUPPORTED_COMPRESSION => 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION',
- PCLZIP_ERR_UNSUPPORTED_ENCRYPTION => 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION'
- ,PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE => 'PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE'
- ,PCLZIP_ERR_DIRECTORY_RESTRICTION => 'PCLZIP_ERR_DIRECTORY_RESTRICTION'
- );
-
- if (isset($v_name[$this->error_code])) {
- $v_value = $v_name[$this->error_code];
- }
- else {
- $v_value = 'NoName';
- }
-
- if ($p_with_code) {
- return($v_value.' ('.$this->error_code.')');
- }
- else {
- return($v_value);
- }
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : errorInfo()
- // Description :
- // Parameters :
- // --------------------------------------------------------------------------------
- function errorInfo($p_full=false)
- {
- if (PCLZIP_ERROR_EXTERNAL == 1) {
- return(PclErrorString());
- }
- else {
- if ($p_full) {
- return($this->errorName(true)." : ".$this->error_string);
- }
- else {
- return($this->error_string." [code ".$this->error_code."]");
- }
- }
- }
- // --------------------------------------------------------------------------------
-
-
-// --------------------------------------------------------------------------------
-// ***** UNDER THIS LINE ARE DEFINED PRIVATE INTERNAL FUNCTIONS *****
-// ***** *****
-// ***** THESES FUNCTIONS MUST NOT BE USED DIRECTLY *****
-// --------------------------------------------------------------------------------
-
-
-
- // --------------------------------------------------------------------------------
- // Function : privCheckFormat()
- // Description :
- // This method check that the archive exists and is a valid zip archive.
- // Several level of check exists. (futur)
- // Parameters :
- // $p_level : Level of check. Default 0.
- // 0 : Check the first bytes (magic codes) (default value))
- // 1 : 0 + Check the central directory (futur)
- // 2 : 1 + Check each file header (futur)
- // Return Values :
- // true on success,
- // false on error, the error code is set.
- // --------------------------------------------------------------------------------
- function privCheckFormat($p_level=0)
- {
- $v_result = true;
-
- // ----- Reset the file system cache
- clearstatcache();
-
- // ----- Reset the error handler
- $this->privErrorReset();
-
- // ----- Look if the file exits
- if (!is_file($this->zipname)) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "Missing archive file '".$this->zipname."'");
- return(false);
- }
-
- // ----- Check that the file is readeable
- if (!is_readable($this->zipname)) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to read archive '".$this->zipname."'");
- return(false);
- }
-
- // ----- Check the magic code
- // TBC
-
- // ----- Check the central header
- // TBC
-
- // ----- Check each file header
- // TBC
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privParseOptions()
- // Description :
- // This internal methods reads the variable list of arguments ($p_options_list,
- // $p_size) and generate an array with the options and values ($v_result_list).
- // $v_requested_options contains the options that can be present and those that
- // must be present.
- // $v_requested_options is an array, with the option value as key, and 'optional',
- // or 'mandatory' as value.
- // Parameters :
- // See above.
- // Return Values :
- // 1 on success.
- // 0 on failure.
- // --------------------------------------------------------------------------------
- function privParseOptions(&$p_options_list, $p_size, &$v_result_list, $v_requested_options=false)
- {
- $v_result=1;
-
- // ----- Read the options
- $i=0;
- while ($i<$p_size) {
-
- // ----- Check if the option is supported
- if (!isset($v_requested_options[$p_options_list[$i]])) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid optional parameter '".$p_options_list[$i]."' for this method");
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Look for next option
- switch ($p_options_list[$i]) {
- // ----- Look for options that request a path value
- case PCLZIP_OPT_PATH :
- case PCLZIP_OPT_REMOVE_PATH :
- case PCLZIP_OPT_ADD_PATH :
- // ----- Check the number of parameters
- if (($i+1) >= $p_size) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Get the value
- $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE);
- $i++;
- break;
-
- case PCLZIP_OPT_TEMP_FILE_THRESHOLD :
- // ----- Check the number of parameters
- if (($i+1) >= $p_size) {
- PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
- return PclZip::errorCode();
- }
-
- // ----- Check for incompatible options
- if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_OFF])) {
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_OFF'");
- return PclZip::errorCode();
- }
-
- // ----- Check the value
- $v_value = $p_options_list[$i+1];
- if ((!is_integer($v_value)) || ($v_value<0)) {
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Integer expected for option '".PclZipUtilOptionText($p_options_list[$i])."'");
- return PclZip::errorCode();
- }
-
- // ----- Get the value (and convert it in bytes)
- $v_result_list[$p_options_list[$i]] = $v_value*1048576;
- $i++;
- break;
-
- case PCLZIP_OPT_TEMP_FILE_ON :
- // ----- Check for incompatible options
- if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_OFF])) {
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_OFF'");
- return PclZip::errorCode();
- }
-
- $v_result_list[$p_options_list[$i]] = true;
- break;
-
- case PCLZIP_OPT_TEMP_FILE_OFF :
- // ----- Check for incompatible options
- if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_ON])) {
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_ON'");
- return PclZip::errorCode();
- }
- // ----- Check for incompatible options
- if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_THRESHOLD])) {
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_THRESHOLD'");
- return PclZip::errorCode();
- }
-
- $v_result_list[$p_options_list[$i]] = true;
- break;
-
- case PCLZIP_OPT_EXTRACT_DIR_RESTRICTION :
- // ----- Check the number of parameters
- if (($i+1) >= $p_size) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Get the value
- if ( is_string($p_options_list[$i+1])
- && ($p_options_list[$i+1] != '')) {
- $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE);
- $i++;
- }
- else {
- }
- break;
-
- // ----- Look for options that request an array of string for value
- case PCLZIP_OPT_BY_NAME :
- // ----- Check the number of parameters
- if (($i+1) >= $p_size) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Get the value
- if (is_string($p_options_list[$i+1])) {
- $v_result_list[$p_options_list[$i]][0] = $p_options_list[$i+1];
- }
- else if (is_array($p_options_list[$i+1])) {
- $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
- }
- else {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
-
- // ----- Return
- return PclZip::errorCode();
- }
- $i++;
- break;
-
- // ----- Look for options that request an EREG or PREG expression
- case PCLZIP_OPT_BY_EREG :
- // ereg() is deprecated starting with PHP 5.3. Move PCLZIP_OPT_BY_EREG
- // to PCLZIP_OPT_BY_PREG
- $p_options_list[$i] = PCLZIP_OPT_BY_PREG;
- case PCLZIP_OPT_BY_PREG :
- //case PCLZIP_OPT_CRYPT :
- // ----- Check the number of parameters
- if (($i+1) >= $p_size) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Get the value
- if (is_string($p_options_list[$i+1])) {
- $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
- }
- else {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
-
- // ----- Return
- return PclZip::errorCode();
- }
- $i++;
- break;
-
- // ----- Look for options that takes a string
- case PCLZIP_OPT_COMMENT :
- case PCLZIP_OPT_ADD_COMMENT :
- case PCLZIP_OPT_PREPEND_COMMENT :
- // ----- Check the number of parameters
- if (($i+1) >= $p_size) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE,
- "Missing parameter value for option '"
- .PclZipUtilOptionText($p_options_list[$i])
- ."'");
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Get the value
- if (is_string($p_options_list[$i+1])) {
- $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
- }
- else {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE,
- "Wrong parameter value for option '"
- .PclZipUtilOptionText($p_options_list[$i])
- ."'");
-
- // ----- Return
- return PclZip::errorCode();
- }
- $i++;
- break;
-
- // ----- Look for options that request an array of index
- case PCLZIP_OPT_BY_INDEX :
- // ----- Check the number of parameters
- if (($i+1) >= $p_size) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Get the value
- $v_work_list = array();
- if (is_string($p_options_list[$i+1])) {
-
- // ----- Remove spaces
- $p_options_list[$i+1] = strtr($p_options_list[$i+1], ' ', '');
-
- // ----- Parse items
- $v_work_list = explode(",", $p_options_list[$i+1]);
- }
- else if (is_integer($p_options_list[$i+1])) {
- $v_work_list[0] = $p_options_list[$i+1].'-'.$p_options_list[$i+1];
- }
- else if (is_array($p_options_list[$i+1])) {
- $v_work_list = $p_options_list[$i+1];
- }
- else {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Value must be integer, string or array for option '".PclZipUtilOptionText($p_options_list[$i])."'");
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Reduce the index list
- // each index item in the list must be a couple with a start and
- // an end value : [0,3], [5-5], [8-10], ...
- // ----- Check the format of each item
- $v_sort_flag=false;
- $v_sort_value=0;
- for ($j=0; $j= $p_size) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Get the value
- $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
- $i++;
- break;
-
- // ----- Look for options that request a call-back
- case PCLZIP_CB_PRE_EXTRACT :
- case PCLZIP_CB_POST_EXTRACT :
- case PCLZIP_CB_PRE_ADD :
- case PCLZIP_CB_POST_ADD :
- /* for futur use
- case PCLZIP_CB_PRE_DELETE :
- case PCLZIP_CB_POST_DELETE :
- case PCLZIP_CB_PRE_LIST :
- case PCLZIP_CB_POST_LIST :
- */
- // ----- Check the number of parameters
- if (($i+1) >= $p_size) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Get the value
- $v_function_name = $p_options_list[$i+1];
-
- // ----- Check that the value is a valid existing function
- if (!function_exists($v_function_name)) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Function '".$v_function_name."()' is not an existing function for option '".PclZipUtilOptionText($p_options_list[$i])."'");
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Set the attribute
- $v_result_list[$p_options_list[$i]] = $v_function_name;
- $i++;
- break;
-
- default :
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,
- "Unknown parameter '"
- .$p_options_list[$i]."'");
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Next options
- $i++;
- }
-
- // ----- Look for mandatory options
- if ($v_requested_options !== false) {
- for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) {
- // ----- Look for mandatory option
- if ($v_requested_options[$key] == 'mandatory') {
- // ----- Look if present
- if (!isset($v_result_list[$key])) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")");
-
- // ----- Return
- return PclZip::errorCode();
- }
- }
- }
- }
-
- // ----- Look for default values
- if (!isset($v_result_list[PCLZIP_OPT_TEMP_FILE_THRESHOLD])) {
-
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privOptionDefaultThreshold()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privOptionDefaultThreshold(&$p_options)
- {
- $v_result=1;
-
- if (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD])
- || isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) {
- return $v_result;
- }
-
- // ----- Get 'memory_limit' configuration value
- $v_memory_limit = ini_get('memory_limit');
- $v_memory_limit = trim($v_memory_limit);
- $last = strtolower(substr($v_memory_limit, -1));
-
- if($last == 'g')
- //$v_memory_limit = $v_memory_limit*1024*1024*1024;
- $v_memory_limit = $v_memory_limit*1073741824;
- if($last == 'm')
- //$v_memory_limit = $v_memory_limit*1024*1024;
- $v_memory_limit = $v_memory_limit*1048576;
- if($last == 'k')
- $v_memory_limit = $v_memory_limit*1024;
-
- $p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] = floor($v_memory_limit*PCLZIP_TEMPORARY_FILE_RATIO);
-
-
- // ----- Sanity check : No threshold if value lower than 1M
- if ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] < 1048576) {
- unset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]);
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privFileDescrParseAtt()
- // Description :
- // Parameters :
- // Return Values :
- // 1 on success.
- // 0 on failure.
- // --------------------------------------------------------------------------------
- function privFileDescrParseAtt(&$p_file_list, &$p_filedescr, $v_options, $v_requested_options=false)
- {
- $v_result=1;
-
- // ----- For each file in the list check the attributes
- foreach ($p_file_list as $v_key => $v_value) {
-
- // ----- Check if the option is supported
- if (!isset($v_requested_options[$v_key])) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file attribute '".$v_key."' for this file");
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Look for attribute
- switch ($v_key) {
- case PCLZIP_ATT_FILE_NAME :
- if (!is_string($v_value)) {
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
- return PclZip::errorCode();
- }
-
- $p_filedescr['filename'] = PclZipUtilPathReduction($v_value);
-
- if ($p_filedescr['filename'] == '') {
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty filename for attribute '".PclZipUtilOptionText($v_key)."'");
- return PclZip::errorCode();
- }
-
- break;
-
- case PCLZIP_ATT_FILE_NEW_SHORT_NAME :
- if (!is_string($v_value)) {
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
- return PclZip::errorCode();
- }
-
- $p_filedescr['new_short_name'] = PclZipUtilPathReduction($v_value);
-
- if ($p_filedescr['new_short_name'] == '') {
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty short filename for attribute '".PclZipUtilOptionText($v_key)."'");
- return PclZip::errorCode();
- }
- break;
-
- case PCLZIP_ATT_FILE_NEW_FULL_NAME :
- if (!is_string($v_value)) {
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
- return PclZip::errorCode();
- }
-
- $p_filedescr['new_full_name'] = PclZipUtilPathReduction($v_value);
-
- if ($p_filedescr['new_full_name'] == '') {
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty full filename for attribute '".PclZipUtilOptionText($v_key)."'");
- return PclZip::errorCode();
- }
- break;
-
- // ----- Look for options that takes a string
- case PCLZIP_ATT_FILE_COMMENT :
- if (!is_string($v_value)) {
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
- return PclZip::errorCode();
- }
-
- $p_filedescr['comment'] = $v_value;
- break;
-
- case PCLZIP_ATT_FILE_MTIME :
- if (!is_integer($v_value)) {
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". Integer expected for attribute '".PclZipUtilOptionText($v_key)."'");
- return PclZip::errorCode();
- }
-
- $p_filedescr['mtime'] = $v_value;
- break;
-
- case PCLZIP_ATT_FILE_CONTENT :
- $p_filedescr['content'] = $v_value;
- break;
-
- default :
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,
- "Unknown parameter '".$v_key."'");
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Look for mandatory options
- if ($v_requested_options !== false) {
- for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) {
- // ----- Look for mandatory option
- if ($v_requested_options[$key] == 'mandatory') {
- // ----- Look if present
- if (!isset($p_file_list[$key])) {
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")");
- return PclZip::errorCode();
- }
- }
- }
- }
-
- // end foreach
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privFileDescrExpand()
- // Description :
- // This method look for each item of the list to see if its a file, a folder
- // or a string to be added as file. For any other type of files (link, other)
- // just ignore the item.
- // Then prepare the information that will be stored for that file.
- // When its a folder, expand the folder with all the files that are in that
- // folder (recursively).
- // Parameters :
- // Return Values :
- // 1 on success.
- // 0 on failure.
- // --------------------------------------------------------------------------------
- function privFileDescrExpand(&$p_filedescr_list, &$p_options)
- {
- $v_result=1;
-
- // ----- Create a result list
- $v_result_list = array();
-
- // ----- Look each entry
- for ($i=0; $iprivCalculateStoredFilename($v_descr, $p_options);
-
- // ----- Add the descriptor in result list
- $v_result_list[sizeof($v_result_list)] = $v_descr;
-
- // ----- Look for folder
- if ($v_descr['type'] == 'folder') {
- // ----- List of items in folder
- $v_dirlist_descr = array();
- $v_dirlist_nb = 0;
- if ($v_folder_handler = @opendir($v_descr['filename'])) {
- while (($v_item_handler = @readdir($v_folder_handler)) !== false) {
-
- // ----- Skip '.' and '..'
- if (($v_item_handler == '.') || ($v_item_handler == '..')) {
- continue;
- }
-
- // ----- Compose the full filename
- $v_dirlist_descr[$v_dirlist_nb]['filename'] = $v_descr['filename'].'/'.$v_item_handler;
-
- // ----- Look for different stored filename
- // Because the name of the folder was changed, the name of the
- // files/sub-folders also change
- if (($v_descr['stored_filename'] != $v_descr['filename'])
- && (!isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH]))) {
- if ($v_descr['stored_filename'] != '') {
- $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_descr['stored_filename'].'/'.$v_item_handler;
- }
- else {
- $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_item_handler;
- }
- }
-
- $v_dirlist_nb++;
- }
-
- @closedir($v_folder_handler);
- }
- else {
- // TBC : unable to open folder in read mode
- }
-
- // ----- Expand each element of the list
- if ($v_dirlist_nb != 0) {
- // ----- Expand
- if (($v_result = $this->privFileDescrExpand($v_dirlist_descr, $p_options)) != 1) {
- return $v_result;
- }
-
- // ----- Concat the resulting list
- $v_result_list = array_merge($v_result_list, $v_dirlist_descr);
- }
- else {
- }
-
- // ----- Free local array
- unset($v_dirlist_descr);
- }
- }
-
- // ----- Get the result list
- $p_filedescr_list = $v_result_list;
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privCreate()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privCreate($p_filedescr_list, &$p_result_list, &$p_options)
- {
- $v_result=1;
- $v_list_detail = array();
-
- // ----- Magic quotes trick
- $this->privDisableMagicQuotes();
-
- // ----- Open the file in write mode
- if (($v_result = $this->privOpenFd('wb')) != 1)
- {
- // ----- Return
- return $v_result;
- }
-
- // ----- Add the list of files
- $v_result = $this->privAddList($p_filedescr_list, $p_result_list, $p_options);
-
- // ----- Close
- $this->privCloseFd();
-
- // ----- Magic quotes trick
- $this->privSwapBackMagicQuotes();
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privAdd()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privAdd($p_filedescr_list, &$p_result_list, &$p_options)
- {
- $v_result=1;
- $v_list_detail = array();
-
- // ----- Look if the archive exists or is empty
- if ((!is_file($this->zipname)) || (filesize($this->zipname) == 0))
- {
-
- // ----- Do a create
- $v_result = $this->privCreate($p_filedescr_list, $p_result_list, $p_options);
-
- // ----- Return
- return $v_result;
- }
- // ----- Magic quotes trick
- $this->privDisableMagicQuotes();
-
- // ----- Open the zip file
- if (($v_result=$this->privOpenFd('rb')) != 1)
- {
- // ----- Magic quotes trick
- $this->privSwapBackMagicQuotes();
-
- // ----- Return
- return $v_result;
- }
-
- // ----- Read the central directory informations
- $v_central_dir = array();
- if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
- {
- $this->privCloseFd();
- $this->privSwapBackMagicQuotes();
- return $v_result;
- }
-
- // ----- Go to beginning of File
- @rewind($this->zip_fd);
-
- // ----- Creates a temporay file
- $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
-
- // ----- Open the temporary file in write mode
- if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0)
- {
- $this->privCloseFd();
- $this->privSwapBackMagicQuotes();
-
- PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode');
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Copy the files from the archive to the temporary file
- // TBC : Here I should better append the file and go back to erase the central dir
- $v_size = $v_central_dir['offset'];
- while ($v_size != 0)
- {
- $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
- $v_buffer = fread($this->zip_fd, $v_read_size);
- @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
- $v_size -= $v_read_size;
- }
-
- // ----- Swap the file descriptor
- // Here is a trick : I swap the temporary fd with the zip fd, in order to use
- // the following methods on the temporary fil and not the real archive
- $v_swap = $this->zip_fd;
- $this->zip_fd = $v_zip_temp_fd;
- $v_zip_temp_fd = $v_swap;
-
- // ----- Add the files
- $v_header_list = array();
- if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1)
- {
- fclose($v_zip_temp_fd);
- $this->privCloseFd();
- @unlink($v_zip_temp_name);
- $this->privSwapBackMagicQuotes();
-
- // ----- Return
- return $v_result;
- }
-
- // ----- Store the offset of the central dir
- $v_offset = @ftell($this->zip_fd);
-
- // ----- Copy the block of file headers from the old archive
- $v_size = $v_central_dir['size'];
- while ($v_size != 0)
- {
- $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
- $v_buffer = @fread($v_zip_temp_fd, $v_read_size);
- @fwrite($this->zip_fd, $v_buffer, $v_read_size);
- $v_size -= $v_read_size;
- }
-
- // ----- Create the Central Dir files header
- for ($i=0, $v_count=0; $iprivWriteCentralFileHeader($v_header_list[$i])) != 1) {
- fclose($v_zip_temp_fd);
- $this->privCloseFd();
- @unlink($v_zip_temp_name);
- $this->privSwapBackMagicQuotes();
-
- // ----- Return
- return $v_result;
- }
- $v_count++;
- }
-
- // ----- Transform the header to a 'usable' info
- $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
- }
-
- // ----- Zip file comment
- $v_comment = $v_central_dir['comment'];
- if (isset($p_options[PCLZIP_OPT_COMMENT])) {
- $v_comment = $p_options[PCLZIP_OPT_COMMENT];
- }
- if (isset($p_options[PCLZIP_OPT_ADD_COMMENT])) {
- $v_comment = $v_comment.$p_options[PCLZIP_OPT_ADD_COMMENT];
- }
- if (isset($p_options[PCLZIP_OPT_PREPEND_COMMENT])) {
- $v_comment = $p_options[PCLZIP_OPT_PREPEND_COMMENT].$v_comment;
- }
-
- // ----- Calculate the size of the central header
- $v_size = @ftell($this->zip_fd)-$v_offset;
-
- // ----- Create the central dir footer
- if (($v_result = $this->privWriteCentralHeader($v_count+$v_central_dir['entries'], $v_size, $v_offset, $v_comment)) != 1)
- {
- // ----- Reset the file list
- unset($v_header_list);
- $this->privSwapBackMagicQuotes();
-
- // ----- Return
- return $v_result;
- }
-
- // ----- Swap back the file descriptor
- $v_swap = $this->zip_fd;
- $this->zip_fd = $v_zip_temp_fd;
- $v_zip_temp_fd = $v_swap;
-
- // ----- Close
- $this->privCloseFd();
-
- // ----- Close the temporary file
- @fclose($v_zip_temp_fd);
-
- // ----- Magic quotes trick
- $this->privSwapBackMagicQuotes();
-
- // ----- Delete the zip file
- // TBC : I should test the result ...
- @unlink($this->zipname);
-
- // ----- Rename the temporary file
- // TBC : I should test the result ...
- //@rename($v_zip_temp_name, $this->zipname);
- PclZipUtilRename($v_zip_temp_name, $this->zipname);
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privOpenFd()
- // Description :
- // Parameters :
- // --------------------------------------------------------------------------------
- function privOpenFd($p_mode)
- {
- $v_result=1;
-
- // ----- Look if already open
- if ($this->zip_fd != 0)
- {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Zip file \''.$this->zipname.'\' already open');
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Open the zip file
- if (($this->zip_fd = @fopen($this->zipname, $p_mode)) == 0)
- {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in '.$p_mode.' mode');
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privCloseFd()
- // Description :
- // Parameters :
- // --------------------------------------------------------------------------------
- function privCloseFd()
- {
- $v_result=1;
-
- if ($this->zip_fd != 0)
- @fclose($this->zip_fd);
- $this->zip_fd = 0;
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privAddList()
- // Description :
- // $p_add_dir and $p_remove_dir will give the ability to memorize a path which is
- // different from the real path of the file. This is usefull if you want to have PclTar
- // running in any directory, and memorize relative path from an other directory.
- // Parameters :
- // $p_list : An array containing the file or directory names to add in the tar
- // $p_result_list : list of added files with their properties (specially the status field)
- // $p_add_dir : Path to add in the filename path archived
- // $p_remove_dir : Path to remove in the filename path archived
- // Return Values :
- // --------------------------------------------------------------------------------
-// function privAddList($p_list, &$p_result_list, $p_add_dir, $p_remove_dir, $p_remove_all_dir, &$p_options)
- function privAddList($p_filedescr_list, &$p_result_list, &$p_options)
- {
- $v_result=1;
-
- // ----- Add the files
- $v_header_list = array();
- if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1)
- {
- // ----- Return
- return $v_result;
- }
-
- // ----- Store the offset of the central dir
- $v_offset = @ftell($this->zip_fd);
-
- // ----- Create the Central Dir files header
- for ($i=0,$v_count=0; $iprivWriteCentralFileHeader($v_header_list[$i])) != 1) {
- // ----- Return
- return $v_result;
- }
- $v_count++;
- }
-
- // ----- Transform the header to a 'usable' info
- $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
- }
-
- // ----- Zip file comment
- $v_comment = '';
- if (isset($p_options[PCLZIP_OPT_COMMENT])) {
- $v_comment = $p_options[PCLZIP_OPT_COMMENT];
- }
-
- // ----- Calculate the size of the central header
- $v_size = @ftell($this->zip_fd)-$v_offset;
-
- // ----- Create the central dir footer
- if (($v_result = $this->privWriteCentralHeader($v_count, $v_size, $v_offset, $v_comment)) != 1)
- {
- // ----- Reset the file list
- unset($v_header_list);
-
- // ----- Return
- return $v_result;
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privAddFileList()
- // Description :
- // Parameters :
- // $p_filedescr_list : An array containing the file description
- // or directory names to add in the zip
- // $p_result_list : list of added files with their properties (specially the status field)
- // Return Values :
- // --------------------------------------------------------------------------------
- function privAddFileList($p_filedescr_list, &$p_result_list, &$p_options)
- {
- $v_result=1;
- $v_header = array();
-
- // ----- Recuperate the current number of elt in list
- $v_nb = sizeof($p_result_list);
-
- // ----- Loop on the files
- for ($j=0; ($jprivAddFile($p_filedescr_list[$j], $v_header,
- $p_options);
- if ($v_result != 1) {
- return $v_result;
- }
-
- // ----- Store the file infos
- $p_result_list[$v_nb++] = $v_header;
- }
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privAddFile()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privAddFile($p_filedescr, &$p_header, &$p_options)
- {
- $v_result=1;
-
- // ----- Working variable
- $p_filename = $p_filedescr['filename'];
-
- // TBC : Already done in the fileAtt check ... ?
- if ($p_filename == "") {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file list parameter (invalid or empty list)");
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Look for a stored different filename
- /* TBC : Removed
- if (isset($p_filedescr['stored_filename'])) {
- $v_stored_filename = $p_filedescr['stored_filename'];
- }
- else {
- $v_stored_filename = $p_filedescr['stored_filename'];
- }
- */
-
- // ----- Set the file properties
- clearstatcache();
- $p_header['version'] = 20;
- $p_header['version_extracted'] = 10;
- $p_header['flag'] = 0;
- $p_header['compression'] = 0;
- $p_header['crc'] = 0;
- $p_header['compressed_size'] = 0;
- $p_header['filename_len'] = strlen($p_filename);
- $p_header['extra_len'] = 0;
- $p_header['disk'] = 0;
- $p_header['internal'] = 0;
- $p_header['offset'] = 0;
- $p_header['filename'] = $p_filename;
-// TBC : Removed $p_header['stored_filename'] = $v_stored_filename;
- $p_header['stored_filename'] = $p_filedescr['stored_filename'];
- $p_header['extra'] = '';
- $p_header['status'] = 'ok';
- $p_header['index'] = -1;
-
- // ----- Look for regular file
- if ($p_filedescr['type']=='file') {
- $p_header['external'] = 0x00000000;
- $p_header['size'] = filesize($p_filename);
- }
-
- // ----- Look for regular folder
- else if ($p_filedescr['type']=='folder') {
- $p_header['external'] = 0x00000010;
- $p_header['mtime'] = filemtime($p_filename);
- $p_header['size'] = filesize($p_filename);
- }
-
- // ----- Look for virtual file
- else if ($p_filedescr['type'] == 'virtual_file') {
- $p_header['external'] = 0x00000000;
- $p_header['size'] = strlen($p_filedescr['content']);
- }
-
-
- // ----- Look for filetime
- if (isset($p_filedescr['mtime'])) {
- $p_header['mtime'] = $p_filedescr['mtime'];
- }
- else if ($p_filedescr['type'] == 'virtual_file') {
- $p_header['mtime'] = time();
- }
- else {
- $p_header['mtime'] = filemtime($p_filename);
- }
-
- // ------ Look for file comment
- if (isset($p_filedescr['comment'])) {
- $p_header['comment_len'] = strlen($p_filedescr['comment']);
- $p_header['comment'] = $p_filedescr['comment'];
- }
- else {
- $p_header['comment_len'] = 0;
- $p_header['comment'] = '';
- }
-
- // ----- Look for pre-add callback
- if (isset($p_options[PCLZIP_CB_PRE_ADD])) {
-
- // ----- Generate a local information
- $v_local_header = array();
- $this->privConvertHeader2FileInfo($p_header, $v_local_header);
-
- // ----- Call the callback
- // Here I do not use call_user_func() because I need to send a reference to the
- // header.
-// eval('$v_result = '.$p_options[PCLZIP_CB_PRE_ADD].'(PCLZIP_CB_PRE_ADD, $v_local_header);');
- $v_result = $p_options[PCLZIP_CB_PRE_ADD](PCLZIP_CB_PRE_ADD, $v_local_header);
- if ($v_result == 0) {
- // ----- Change the file status
- $p_header['status'] = "skipped";
- $v_result = 1;
- }
-
- // ----- Update the informations
- // Only some fields can be modified
- if ($p_header['stored_filename'] != $v_local_header['stored_filename']) {
- $p_header['stored_filename'] = PclZipUtilPathReduction($v_local_header['stored_filename']);
- }
- }
-
- // ----- Look for empty stored filename
- if ($p_header['stored_filename'] == "") {
- $p_header['status'] = "filtered";
- }
-
- // ----- Check the path length
- if (strlen($p_header['stored_filename']) > 0xFF) {
- $p_header['status'] = 'filename_too_long';
- }
-
- // ----- Look if no error, or file not skipped
- if ($p_header['status'] == 'ok') {
-
- // ----- Look for a file
- if ($p_filedescr['type'] == 'file') {
- // ----- Look for using temporary file to zip
- if ( (!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF]))
- && (isset($p_options[PCLZIP_OPT_TEMP_FILE_ON])
- || (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD])
- && ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] <= $p_header['size'])) ) ) {
- $v_result = $this->privAddFileUsingTempFile($p_filedescr, $p_header, $p_options);
- if ($v_result < PCLZIP_ERR_NO_ERROR) {
- return $v_result;
- }
- }
-
- // ----- Use "in memory" zip algo
- else {
-
- // ----- Open the source file
- if (($v_file = @fopen($p_filename, "rb")) == 0) {
- PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode");
- return PclZip::errorCode();
- }
-
- // ----- Read the file content
- $v_content = @fread($v_file, $p_header['size']);
-
- // ----- Close the file
- @fclose($v_file);
-
- // ----- Calculate the CRC
- $p_header['crc'] = @crc32($v_content);
-
- // ----- Look for no compression
- if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) {
- // ----- Set header parameters
- $p_header['compressed_size'] = $p_header['size'];
- $p_header['compression'] = 0;
- }
-
- // ----- Look for normal compression
- else {
- // ----- Compress the content
- $v_content = @gzdeflate($v_content);
-
- // ----- Set header parameters
- $p_header['compressed_size'] = strlen($v_content);
- $p_header['compression'] = 8;
- }
-
- // ----- Call the header generation
- if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
- @fclose($v_file);
- return $v_result;
- }
-
- // ----- Write the compressed (or not) content
- @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']);
-
- }
-
- }
-
- // ----- Look for a virtual file (a file from string)
- else if ($p_filedescr['type'] == 'virtual_file') {
-
- $v_content = $p_filedescr['content'];
-
- // ----- Calculate the CRC
- $p_header['crc'] = @crc32($v_content);
-
- // ----- Look for no compression
- if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) {
- // ----- Set header parameters
- $p_header['compressed_size'] = $p_header['size'];
- $p_header['compression'] = 0;
- }
-
- // ----- Look for normal compression
- else {
- // ----- Compress the content
- $v_content = @gzdeflate($v_content);
-
- // ----- Set header parameters
- $p_header['compressed_size'] = strlen($v_content);
- $p_header['compression'] = 8;
- }
-
- // ----- Call the header generation
- if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
- @fclose($v_file);
- return $v_result;
- }
-
- // ----- Write the compressed (or not) content
- @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']);
- }
-
- // ----- Look for a directory
- else if ($p_filedescr['type'] == 'folder') {
- // ----- Look for directory last '/'
- if (@substr($p_header['stored_filename'], -1) != '/') {
- $p_header['stored_filename'] .= '/';
- }
-
- // ----- Set the file properties
- $p_header['size'] = 0;
- //$p_header['external'] = 0x41FF0010; // Value for a folder : to be checked
- $p_header['external'] = 0x00000010; // Value for a folder : to be checked
-
- // ----- Call the header generation
- if (($v_result = $this->privWriteFileHeader($p_header)) != 1)
- {
- return $v_result;
- }
- }
- }
-
- // ----- Look for post-add callback
- if (isset($p_options[PCLZIP_CB_POST_ADD])) {
-
- // ----- Generate a local information
- $v_local_header = array();
- $this->privConvertHeader2FileInfo($p_header, $v_local_header);
-
- // ----- Call the callback
- // Here I do not use call_user_func() because I need to send a reference to the
- // header.
-// eval('$v_result = '.$p_options[PCLZIP_CB_POST_ADD].'(PCLZIP_CB_POST_ADD, $v_local_header);');
- $v_result = $p_options[PCLZIP_CB_POST_ADD](PCLZIP_CB_POST_ADD, $v_local_header);
- if ($v_result == 0) {
- // ----- Ignored
- $v_result = 1;
- }
-
- // ----- Update the informations
- // Nothing can be modified
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privAddFileUsingTempFile()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privAddFileUsingTempFile($p_filedescr, &$p_header, &$p_options)
- {
- $v_result=PCLZIP_ERR_NO_ERROR;
-
- // ----- Working variable
- $p_filename = $p_filedescr['filename'];
-
-
- // ----- Open the source file
- if (($v_file = @fopen($p_filename, "rb")) == 0) {
- PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode");
- return PclZip::errorCode();
- }
-
- // ----- Creates a compressed temporary file
- $v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz';
- if (($v_file_compressed = @gzopen($v_gzip_temp_name, "wb")) == 0) {
- fclose($v_file);
- PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode');
- return PclZip::errorCode();
- }
-
- // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks
- $v_size = filesize($p_filename);
- while ($v_size != 0) {
- $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
- $v_buffer = @fread($v_file, $v_read_size);
- //$v_binary_data = pack('a'.$v_read_size, $v_buffer);
- @gzputs($v_file_compressed, $v_buffer, $v_read_size);
- $v_size -= $v_read_size;
- }
-
- // ----- Close the file
- @fclose($v_file);
- @gzclose($v_file_compressed);
-
- // ----- Check the minimum file size
- if (filesize($v_gzip_temp_name) < 18) {
- PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'gzip temporary file \''.$v_gzip_temp_name.'\' has invalid filesize - should be minimum 18 bytes');
- return PclZip::errorCode();
- }
-
- // ----- Extract the compressed attributes
- if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0) {
- PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode');
- return PclZip::errorCode();
- }
-
- // ----- Read the gzip file header
- $v_binary_data = @fread($v_file_compressed, 10);
- $v_data_header = unpack('a1id1/a1id2/a1cm/a1flag/Vmtime/a1xfl/a1os', $v_binary_data);
-
- // ----- Check some parameters
- $v_data_header['os'] = bin2hex($v_data_header['os']);
-
- // ----- Read the gzip file footer
- @fseek($v_file_compressed, filesize($v_gzip_temp_name)-8);
- $v_binary_data = @fread($v_file_compressed, 8);
- $v_data_footer = unpack('Vcrc/Vcompressed_size', $v_binary_data);
-
- // ----- Set the attributes
- $p_header['compression'] = ord($v_data_header['cm']);
- //$p_header['mtime'] = $v_data_header['mtime'];
- $p_header['crc'] = $v_data_footer['crc'];
- $p_header['compressed_size'] = filesize($v_gzip_temp_name)-18;
-
- // ----- Close the file
- @fclose($v_file_compressed);
-
- // ----- Call the header generation
- if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
- return $v_result;
- }
-
- // ----- Add the compressed data
- if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0)
- {
- PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode');
- return PclZip::errorCode();
- }
-
- // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks
- fseek($v_file_compressed, 10);
- $v_size = $p_header['compressed_size'];
- while ($v_size != 0)
- {
- $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
- $v_buffer = @fread($v_file_compressed, $v_read_size);
- //$v_binary_data = pack('a'.$v_read_size, $v_buffer);
- @fwrite($this->zip_fd, $v_buffer, $v_read_size);
- $v_size -= $v_read_size;
- }
-
- // ----- Close the file
- @fclose($v_file_compressed);
-
- // ----- Unlink the temporary file
- @unlink($v_gzip_temp_name);
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privCalculateStoredFilename()
- // Description :
- // Based on file descriptor properties and global options, this method
- // calculate the filename that will be stored in the archive.
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privCalculateStoredFilename(&$p_filedescr, &$p_options)
- {
- $v_result=1;
-
- // ----- Working variables
- $p_filename = $p_filedescr['filename'];
- if (isset($p_options[PCLZIP_OPT_ADD_PATH])) {
- $p_add_dir = $p_options[PCLZIP_OPT_ADD_PATH];
- }
- else {
- $p_add_dir = '';
- }
- if (isset($p_options[PCLZIP_OPT_REMOVE_PATH])) {
- $p_remove_dir = $p_options[PCLZIP_OPT_REMOVE_PATH];
- }
- else {
- $p_remove_dir = '';
- }
- if (isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
- $p_remove_all_dir = $p_options[PCLZIP_OPT_REMOVE_ALL_PATH];
- }
- else {
- $p_remove_all_dir = 0;
- }
-
-
- // ----- Look for full name change
- if (isset($p_filedescr['new_full_name'])) {
- // ----- Remove drive letter if any
- $v_stored_filename = PclZipUtilTranslateWinPath($p_filedescr['new_full_name']);
- }
-
- // ----- Look for path and/or short name change
- else {
-
- // ----- Look for short name change
- // Its when we cahnge just the filename but not the path
- if (isset($p_filedescr['new_short_name'])) {
- $v_path_info = pathinfo($p_filename);
- $v_dir = '';
- if ($v_path_info['dirname'] != '') {
- $v_dir = $v_path_info['dirname'].'/';
- }
- $v_stored_filename = $v_dir.$p_filedescr['new_short_name'];
- }
- else {
- // ----- Calculate the stored filename
- $v_stored_filename = $p_filename;
- }
-
- // ----- Look for all path to remove
- if ($p_remove_all_dir) {
- $v_stored_filename = basename($p_filename);
- }
- // ----- Look for partial path remove
- else if ($p_remove_dir != "") {
- if (substr($p_remove_dir, -1) != '/')
- $p_remove_dir .= "/";
-
- if ( (substr($p_filename, 0, 2) == "./")
- || (substr($p_remove_dir, 0, 2) == "./")) {
-
- if ( (substr($p_filename, 0, 2) == "./")
- && (substr($p_remove_dir, 0, 2) != "./")) {
- $p_remove_dir = "./".$p_remove_dir;
- }
- if ( (substr($p_filename, 0, 2) != "./")
- && (substr($p_remove_dir, 0, 2) == "./")) {
- $p_remove_dir = substr($p_remove_dir, 2);
- }
- }
-
- $v_compare = PclZipUtilPathInclusion($p_remove_dir,
- $v_stored_filename);
- if ($v_compare > 0) {
- if ($v_compare == 2) {
- $v_stored_filename = "";
- }
- else {
- $v_stored_filename = substr($v_stored_filename,
- strlen($p_remove_dir));
- }
- }
- }
-
- // ----- Remove drive letter if any
- $v_stored_filename = PclZipUtilTranslateWinPath($v_stored_filename);
-
- // ----- Look for path to add
- if ($p_add_dir != "") {
- if (substr($p_add_dir, -1) == "/")
- $v_stored_filename = $p_add_dir.$v_stored_filename;
- else
- $v_stored_filename = $p_add_dir."/".$v_stored_filename;
- }
- }
-
- // ----- Filename (reduce the path of stored name)
- $v_stored_filename = PclZipUtilPathReduction($v_stored_filename);
- $p_filedescr['stored_filename'] = $v_stored_filename;
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privWriteFileHeader()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privWriteFileHeader(&$p_header)
- {
- $v_result=1;
-
- // ----- Store the offset position of the file
- $p_header['offset'] = ftell($this->zip_fd);
-
- // ----- Transform UNIX mtime to DOS format mdate/mtime
- $v_date = getdate($p_header['mtime']);
- $v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2;
- $v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday'];
-
- // ----- Packed data
- $v_binary_data = pack("VvvvvvVVVvv", 0x04034b50,
- $p_header['version_extracted'], $p_header['flag'],
- $p_header['compression'], $v_mtime, $v_mdate,
- $p_header['crc'], $p_header['compressed_size'],
- $p_header['size'],
- strlen($p_header['stored_filename']),
- $p_header['extra_len']);
-
- // ----- Write the first 148 bytes of the header in the archive
- fputs($this->zip_fd, $v_binary_data, 30);
-
- // ----- Write the variable fields
- if (strlen($p_header['stored_filename']) != 0)
- {
- fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename']));
- }
- if ($p_header['extra_len'] != 0)
- {
- fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']);
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privWriteCentralFileHeader()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privWriteCentralFileHeader(&$p_header)
- {
- $v_result=1;
-
- // TBC
- //for(reset($p_header); $key = key($p_header); next($p_header)) {
- //}
-
- // ----- Transform UNIX mtime to DOS format mdate/mtime
- $v_date = getdate($p_header['mtime']);
- $v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2;
- $v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday'];
-
-
- // ----- Packed data
- $v_binary_data = pack("VvvvvvvVVVvvvvvVV", 0x02014b50,
- $p_header['version'], $p_header['version_extracted'],
- $p_header['flag'], $p_header['compression'],
- $v_mtime, $v_mdate, $p_header['crc'],
- $p_header['compressed_size'], $p_header['size'],
- strlen($p_header['stored_filename']),
- $p_header['extra_len'], $p_header['comment_len'],
- $p_header['disk'], $p_header['internal'],
- $p_header['external'], $p_header['offset']);
-
- // ----- Write the 42 bytes of the header in the zip file
- fputs($this->zip_fd, $v_binary_data, 46);
-
- // ----- Write the variable fields
- if (strlen($p_header['stored_filename']) != 0)
- {
- fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename']));
- }
- if ($p_header['extra_len'] != 0)
- {
- fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']);
- }
- if ($p_header['comment_len'] != 0)
- {
- fputs($this->zip_fd, $p_header['comment'], $p_header['comment_len']);
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privWriteCentralHeader()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privWriteCentralHeader($p_nb_entries, $p_size, $p_offset, $p_comment)
- {
- $v_result=1;
-
- // ----- Packed data
- $v_binary_data = pack("VvvvvVVv", 0x06054b50, 0, 0, $p_nb_entries,
- $p_nb_entries, $p_size,
- $p_offset, strlen($p_comment));
-
- // ----- Write the 22 bytes of the header in the zip file
- fputs($this->zip_fd, $v_binary_data, 22);
-
- // ----- Write the variable fields
- if (strlen($p_comment) != 0)
- {
- fputs($this->zip_fd, $p_comment, strlen($p_comment));
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privList()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privList(&$p_list)
- {
- $v_result=1;
-
- // ----- Magic quotes trick
- $this->privDisableMagicQuotes();
-
- // ----- Open the zip file
- if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0)
- {
- // ----- Magic quotes trick
- $this->privSwapBackMagicQuotes();
-
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode');
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Read the central directory informations
- $v_central_dir = array();
- if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
- {
- $this->privSwapBackMagicQuotes();
- return $v_result;
- }
-
- // ----- Go to beginning of Central Dir
- @rewind($this->zip_fd);
- if (@fseek($this->zip_fd, $v_central_dir['offset']))
- {
- $this->privSwapBackMagicQuotes();
-
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Read each entry
- for ($i=0; $i<$v_central_dir['entries']; $i++)
- {
- // ----- Read the file header
- if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1)
- {
- $this->privSwapBackMagicQuotes();
- return $v_result;
- }
- $v_header['index'] = $i;
-
- // ----- Get the only interesting attributes
- $this->privConvertHeader2FileInfo($v_header, $p_list[$i]);
- unset($v_header);
- }
-
- // ----- Close the zip file
- $this->privCloseFd();
-
- // ----- Magic quotes trick
- $this->privSwapBackMagicQuotes();
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privConvertHeader2FileInfo()
- // Description :
- // This function takes the file informations from the central directory
- // entries and extract the interesting parameters that will be given back.
- // The resulting file infos are set in the array $p_info
- // $p_info['filename'] : Filename with full path. Given by user (add),
- // extracted in the filesystem (extract).
- // $p_info['stored_filename'] : Stored filename in the archive.
- // $p_info['size'] = Size of the file.
- // $p_info['compressed_size'] = Compressed size of the file.
- // $p_info['mtime'] = Last modification date of the file.
- // $p_info['comment'] = Comment associated with the file.
- // $p_info['folder'] = true/false : indicates if the entry is a folder or not.
- // $p_info['status'] = status of the action on the file.
- // $p_info['crc'] = CRC of the file content.
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privConvertHeader2FileInfo($p_header, &$p_info)
- {
- $v_result=1;
-
- // ----- Get the interesting attributes
- $v_temp_path = PclZipUtilPathReduction($p_header['filename']);
- $p_info['filename'] = $v_temp_path;
- $v_temp_path = PclZipUtilPathReduction($p_header['stored_filename']);
- $p_info['stored_filename'] = $v_temp_path;
- $p_info['size'] = $p_header['size'];
- $p_info['compressed_size'] = $p_header['compressed_size'];
- $p_info['mtime'] = $p_header['mtime'];
- $p_info['comment'] = $p_header['comment'];
- $p_info['folder'] = (($p_header['external']&0x00000010)==0x00000010);
- $p_info['index'] = $p_header['index'];
- $p_info['status'] = $p_header['status'];
- $p_info['crc'] = $p_header['crc'];
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privExtractByRule()
- // Description :
- // Extract a file or directory depending of rules (by index, by name, ...)
- // Parameters :
- // $p_file_list : An array where will be placed the properties of each
- // extracted file
- // $p_path : Path to add while writing the extracted files
- // $p_remove_path : Path to remove (from the file memorized path) while writing the
- // extracted files. If the path does not match the file path,
- // the file is extracted with its memorized path.
- // $p_remove_path does not apply to 'list' mode.
- // $p_path and $p_remove_path are commulative.
- // Return Values :
- // 1 on success,0 or less on error (see error code list)
- // --------------------------------------------------------------------------------
- function privExtractByRule(&$p_file_list, $p_path, $p_remove_path, $p_remove_all_path, &$p_options)
- {
- $v_result=1;
-
- // ----- Magic quotes trick
- $this->privDisableMagicQuotes();
-
- // ----- Check the path
- if ( ($p_path == "")
- || ( (substr($p_path, 0, 1) != "/")
- && (substr($p_path, 0, 3) != "../")
- && (substr($p_path,1,2)!=":/")))
- $p_path = "./".$p_path;
-
- // ----- Reduce the path last (and duplicated) '/'
- if (($p_path != "./") && ($p_path != "/"))
- {
- // ----- Look for the path end '/'
- while (substr($p_path, -1) == "/")
- {
- $p_path = substr($p_path, 0, strlen($p_path)-1);
- }
- }
-
- // ----- Look for path to remove format (should end by /)
- if (($p_remove_path != "") && (substr($p_remove_path, -1) != '/'))
- {
- $p_remove_path .= '/';
- }
- $p_remove_path_size = strlen($p_remove_path);
-
- // ----- Open the zip file
- if (($v_result = $this->privOpenFd('rb')) != 1)
- {
- $this->privSwapBackMagicQuotes();
- return $v_result;
- }
-
- // ----- Read the central directory informations
- $v_central_dir = array();
- if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
- {
- // ----- Close the zip file
- $this->privCloseFd();
- $this->privSwapBackMagicQuotes();
-
- return $v_result;
- }
-
- // ----- Start at beginning of Central Dir
- $v_pos_entry = $v_central_dir['offset'];
-
- // ----- Read each entry
- $j_start = 0;
- for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++)
- {
-
- // ----- Read next Central dir entry
- @rewind($this->zip_fd);
- if (@fseek($this->zip_fd, $v_pos_entry))
- {
- // ----- Close the zip file
- $this->privCloseFd();
- $this->privSwapBackMagicQuotes();
-
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Read the file header
- $v_header = array();
- if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1)
- {
- // ----- Close the zip file
- $this->privCloseFd();
- $this->privSwapBackMagicQuotes();
-
- return $v_result;
- }
-
- // ----- Store the index
- $v_header['index'] = $i;
-
- // ----- Store the file position
- $v_pos_entry = ftell($this->zip_fd);
-
- // ----- Look for the specific extract rules
- $v_extract = false;
-
- // ----- Look for extract by name rule
- if ( (isset($p_options[PCLZIP_OPT_BY_NAME]))
- && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) {
-
- // ----- Look if the filename is in the list
- for ($j=0; ($j strlen($p_options[PCLZIP_OPT_BY_NAME][$j]))
- && (substr($v_header['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) {
- $v_extract = true;
- }
- }
- // ----- Look for a filename
- elseif ($v_header['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) {
- $v_extract = true;
- }
- }
- }
-
- // ----- Look for extract by ereg rule
- // ereg() is deprecated with PHP 5.3
- /*
- else if ( (isset($p_options[PCLZIP_OPT_BY_EREG]))
- && ($p_options[PCLZIP_OPT_BY_EREG] != "")) {
-
- if (ereg($p_options[PCLZIP_OPT_BY_EREG], $v_header['stored_filename'])) {
- $v_extract = true;
- }
- }
- */
-
- // ----- Look for extract by preg rule
- else if ( (isset($p_options[PCLZIP_OPT_BY_PREG]))
- && ($p_options[PCLZIP_OPT_BY_PREG] != "")) {
-
- if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header['stored_filename'])) {
- $v_extract = true;
- }
- }
-
- // ----- Look for extract by index rule
- else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX]))
- && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) {
-
- // ----- Look if the index is in the list
- for ($j=$j_start; ($j=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) {
- $v_extract = true;
- }
- if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) {
- $j_start = $j+1;
- }
-
- if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) {
- break;
- }
- }
- }
-
- // ----- Look for no rule, which means extract all the archive
- else {
- $v_extract = true;
- }
-
- // ----- Check compression method
- if ( ($v_extract)
- && ( ($v_header['compression'] != 8)
- && ($v_header['compression'] != 0))) {
- $v_header['status'] = 'unsupported_compression';
-
- // ----- Look for PCLZIP_OPT_STOP_ON_ERROR
- if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
- && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
-
- $this->privSwapBackMagicQuotes();
-
- PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_COMPRESSION,
- "Filename '".$v_header['stored_filename']."' is "
- ."compressed by an unsupported compression "
- ."method (".$v_header['compression'].") ");
-
- return PclZip::errorCode();
- }
- }
-
- // ----- Check encrypted files
- if (($v_extract) && (($v_header['flag'] & 1) == 1)) {
- $v_header['status'] = 'unsupported_encryption';
-
- // ----- Look for PCLZIP_OPT_STOP_ON_ERROR
- if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
- && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
-
- $this->privSwapBackMagicQuotes();
-
- PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION,
- "Unsupported encryption for "
- ." filename '".$v_header['stored_filename']
- ."'");
-
- return PclZip::errorCode();
- }
- }
-
- // ----- Look for real extraction
- if (($v_extract) && ($v_header['status'] != 'ok')) {
- $v_result = $this->privConvertHeader2FileInfo($v_header,
- $p_file_list[$v_nb_extracted++]);
- if ($v_result != 1) {
- $this->privCloseFd();
- $this->privSwapBackMagicQuotes();
- return $v_result;
- }
-
- $v_extract = false;
- }
-
- // ----- Look for real extraction
- if ($v_extract)
- {
-
- // ----- Go to the file position
- @rewind($this->zip_fd);
- if (@fseek($this->zip_fd, $v_header['offset']))
- {
- // ----- Close the zip file
- $this->privCloseFd();
-
- $this->privSwapBackMagicQuotes();
-
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Look for extraction as string
- if ($p_options[PCLZIP_OPT_EXTRACT_AS_STRING]) {
-
- $v_string = '';
-
- // ----- Extracting the file
- $v_result1 = $this->privExtractFileAsString($v_header, $v_string, $p_options);
- if ($v_result1 < 1) {
- $this->privCloseFd();
- $this->privSwapBackMagicQuotes();
- return $v_result1;
- }
-
- // ----- Get the only interesting attributes
- if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted])) != 1)
- {
- // ----- Close the zip file
- $this->privCloseFd();
- $this->privSwapBackMagicQuotes();
-
- return $v_result;
- }
-
- // ----- Set the file content
- $p_file_list[$v_nb_extracted]['content'] = $v_string;
-
- // ----- Next extracted file
- $v_nb_extracted++;
-
- // ----- Look for user callback abort
- if ($v_result1 == 2) {
- break;
- }
- }
- // ----- Look for extraction in standard output
- elseif ( (isset($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT]))
- && ($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) {
- // ----- Extracting the file in standard output
- $v_result1 = $this->privExtractFileInOutput($v_header, $p_options);
- if ($v_result1 < 1) {
- $this->privCloseFd();
- $this->privSwapBackMagicQuotes();
- return $v_result1;
- }
-
- // ----- Get the only interesting attributes
- if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1) {
- $this->privCloseFd();
- $this->privSwapBackMagicQuotes();
- return $v_result;
- }
-
- // ----- Look for user callback abort
- if ($v_result1 == 2) {
- break;
- }
- }
- // ----- Look for normal extraction
- else {
- // ----- Extracting the file
- $v_result1 = $this->privExtractFile($v_header,
- $p_path, $p_remove_path,
- $p_remove_all_path,
- $p_options);
- if ($v_result1 < 1) {
- $this->privCloseFd();
- $this->privSwapBackMagicQuotes();
- return $v_result1;
- }
-
- // ----- Get the only interesting attributes
- if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1)
- {
- // ----- Close the zip file
- $this->privCloseFd();
- $this->privSwapBackMagicQuotes();
-
- return $v_result;
- }
-
- // ----- Look for user callback abort
- if ($v_result1 == 2) {
- break;
- }
- }
- }
- }
-
- // ----- Close the zip file
- $this->privCloseFd();
- $this->privSwapBackMagicQuotes();
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privExtractFile()
- // Description :
- // Parameters :
- // Return Values :
- //
- // 1 : ... ?
- // PCLZIP_ERR_USER_ABORTED(2) : User ask for extraction stop in callback
- // --------------------------------------------------------------------------------
- function privExtractFile(&$p_entry, $p_path, $p_remove_path, $p_remove_all_path, &$p_options)
- {
- $v_result=1;
-
- // ----- Read the file header
- if (($v_result = $this->privReadFileHeader($v_header)) != 1)
- {
- // ----- Return
- return $v_result;
- }
-
-
- // ----- Check that the file header is coherent with $p_entry info
- if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {
- // TBC
- }
-
- // ----- Look for all path to remove
- if ($p_remove_all_path == true) {
- // ----- Look for folder entry that not need to be extracted
- if (($p_entry['external']&0x00000010)==0x00000010) {
-
- $p_entry['status'] = "filtered";
-
- return $v_result;
- }
-
- // ----- Get the basename of the path
- $p_entry['filename'] = basename($p_entry['filename']);
- }
-
- // ----- Look for path to remove
- else if ($p_remove_path != "")
- {
- if (PclZipUtilPathInclusion($p_remove_path, $p_entry['filename']) == 2)
- {
-
- // ----- Change the file status
- $p_entry['status'] = "filtered";
-
- // ----- Return
- return $v_result;
- }
-
- $p_remove_path_size = strlen($p_remove_path);
- if (substr($p_entry['filename'], 0, $p_remove_path_size) == $p_remove_path)
- {
-
- // ----- Remove the path
- $p_entry['filename'] = substr($p_entry['filename'], $p_remove_path_size);
-
- }
- }
-
- // ----- Add the path
- if ($p_path != '') {
- $p_entry['filename'] = $p_path."/".$p_entry['filename'];
- }
-
- // ----- Check a base_dir_restriction
- if (isset($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION])) {
- $v_inclusion
- = PclZipUtilPathInclusion($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION],
- $p_entry['filename']);
- if ($v_inclusion == 0) {
-
- PclZip::privErrorLog(PCLZIP_ERR_DIRECTORY_RESTRICTION,
- "Filename '".$p_entry['filename']."' is "
- ."outside PCLZIP_OPT_EXTRACT_DIR_RESTRICTION");
-
- return PclZip::errorCode();
- }
- }
-
- // ----- Look for pre-extract callback
- if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {
-
- // ----- Generate a local information
- $v_local_header = array();
- $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
-
- // ----- Call the callback
- // Here I do not use call_user_func() because I need to send a reference to the
- // header.
-// eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);');
- $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header);
- if ($v_result == 0) {
- // ----- Change the file status
- $p_entry['status'] = "skipped";
- $v_result = 1;
- }
-
- // ----- Look for abort result
- if ($v_result == 2) {
- // ----- This status is internal and will be changed in 'skipped'
- $p_entry['status'] = "aborted";
- $v_result = PCLZIP_ERR_USER_ABORTED;
- }
-
- // ----- Update the informations
- // Only some fields can be modified
- $p_entry['filename'] = $v_local_header['filename'];
- }
-
-
- // ----- Look if extraction should be done
- if ($p_entry['status'] == 'ok') {
-
- // ----- Look for specific actions while the file exist
- if (file_exists($p_entry['filename']))
- {
-
- // ----- Look if file is a directory
- if (is_dir($p_entry['filename']))
- {
-
- // ----- Change the file status
- $p_entry['status'] = "already_a_directory";
-
- // ----- Look for PCLZIP_OPT_STOP_ON_ERROR
- // For historical reason first PclZip implementation does not stop
- // when this kind of error occurs.
- if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
- && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
-
- PclZip::privErrorLog(PCLZIP_ERR_ALREADY_A_DIRECTORY,
- "Filename '".$p_entry['filename']."' is "
- ."already used by an existing directory");
-
- return PclZip::errorCode();
- }
- }
- // ----- Look if file is write protected
- else if (!is_writeable($p_entry['filename']))
- {
-
- // ----- Change the file status
- $p_entry['status'] = "write_protected";
-
- // ----- Look for PCLZIP_OPT_STOP_ON_ERROR
- // For historical reason first PclZip implementation does not stop
- // when this kind of error occurs.
- if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
- && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
-
- PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL,
- "Filename '".$p_entry['filename']."' exists "
- ."and is write protected");
-
- return PclZip::errorCode();
- }
- }
-
- // ----- Look if the extracted file is older
- else if (filemtime($p_entry['filename']) > $p_entry['mtime'])
- {
- // ----- Change the file status
- if ( (isset($p_options[PCLZIP_OPT_REPLACE_NEWER]))
- && ($p_options[PCLZIP_OPT_REPLACE_NEWER]===true)) {
- }
- else {
- $p_entry['status'] = "newer_exist";
-
- // ----- Look for PCLZIP_OPT_STOP_ON_ERROR
- // For historical reason first PclZip implementation does not stop
- // when this kind of error occurs.
- if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
- && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
-
- PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL,
- "Newer version of '".$p_entry['filename']."' exists "
- ."and option PCLZIP_OPT_REPLACE_NEWER is not selected");
-
- return PclZip::errorCode();
- }
- }
- }
- else {
- }
- }
-
- // ----- Check the directory availability and create it if necessary
- else {
- if ((($p_entry['external']&0x00000010)==0x00000010) || (substr($p_entry['filename'], -1) == '/'))
- $v_dir_to_check = $p_entry['filename'];
- else if (!strstr($p_entry['filename'], "/"))
- $v_dir_to_check = "";
- else
- $v_dir_to_check = dirname($p_entry['filename']);
-
- if (($v_result = $this->privDirCheck($v_dir_to_check, (($p_entry['external']&0x00000010)==0x00000010))) != 1) {
-
- // ----- Change the file status
- $p_entry['status'] = "path_creation_fail";
-
- // ----- Return
- //return $v_result;
- $v_result = 1;
- }
- }
- }
-
- // ----- Look if extraction should be done
- if ($p_entry['status'] == 'ok') {
-
- // ----- Do the extraction (if not a folder)
- if (!(($p_entry['external']&0x00000010)==0x00000010))
- {
- // ----- Look for not compressed file
- if ($p_entry['compression'] == 0) {
-
- // ----- Opening destination file
- if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0)
- {
-
- // ----- Change the file status
- $p_entry['status'] = "write_error";
-
- // ----- Return
- return $v_result;
- }
-
-
- // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks
- $v_size = $p_entry['compressed_size'];
- while ($v_size != 0)
- {
- $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
- $v_buffer = @fread($this->zip_fd, $v_read_size);
- /* Try to speed up the code
- $v_binary_data = pack('a'.$v_read_size, $v_buffer);
- @fwrite($v_dest_file, $v_binary_data, $v_read_size);
- */
- @fwrite($v_dest_file, $v_buffer, $v_read_size);
- $v_size -= $v_read_size;
- }
-
- // ----- Closing the destination file
- fclose($v_dest_file);
-
- // ----- Change the file mtime
- touch($p_entry['filename'], $p_entry['mtime']);
-
-
- }
- else {
- // ----- TBC
- // Need to be finished
- if (($p_entry['flag'] & 1) == 1) {
- PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION, 'File \''.$p_entry['filename'].'\' is encrypted. Encrypted files are not supported.');
- return PclZip::errorCode();
- }
-
-
- // ----- Look for using temporary file to unzip
- if ( (!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF]))
- && (isset($p_options[PCLZIP_OPT_TEMP_FILE_ON])
- || (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD])
- && ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] <= $p_entry['size'])) ) ) {
- $v_result = $this->privExtractFileUsingTempFile($p_entry, $p_options);
- if ($v_result < PCLZIP_ERR_NO_ERROR) {
- return $v_result;
- }
- }
-
- // ----- Look for extract in memory
- else {
-
-
- // ----- Read the compressed file in a buffer (one shot)
- $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
-
- // ----- Decompress the file
- $v_file_content = @gzinflate($v_buffer);
- unset($v_buffer);
- if ($v_file_content === FALSE) {
-
- // ----- Change the file status
- // TBC
- $p_entry['status'] = "error";
-
- return $v_result;
- }
-
- // ----- Opening destination file
- if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) {
-
- // ----- Change the file status
- $p_entry['status'] = "write_error";
-
- return $v_result;
- }
-
- // ----- Write the uncompressed data
- @fwrite($v_dest_file, $v_file_content, $p_entry['size']);
- unset($v_file_content);
-
- // ----- Closing the destination file
- @fclose($v_dest_file);
-
- }
-
- // ----- Change the file mtime
- @touch($p_entry['filename'], $p_entry['mtime']);
- }
-
- // ----- Look for chmod option
- if (isset($p_options[PCLZIP_OPT_SET_CHMOD])) {
-
- // ----- Change the mode of the file
- @chmod($p_entry['filename'], $p_options[PCLZIP_OPT_SET_CHMOD]);
- }
-
- }
- }
-
- // ----- Change abort status
- if ($p_entry['status'] == "aborted") {
- $p_entry['status'] = "skipped";
- }
-
- // ----- Look for post-extract callback
- elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) {
-
- // ----- Generate a local information
- $v_local_header = array();
- $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
-
- // ----- Call the callback
- // Here I do not use call_user_func() because I need to send a reference to the
- // header.
-// eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);');
- $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header);
-
- // ----- Look for abort result
- if ($v_result == 2) {
- $v_result = PCLZIP_ERR_USER_ABORTED;
- }
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privExtractFileUsingTempFile()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privExtractFileUsingTempFile(&$p_entry, &$p_options)
- {
- $v_result=1;
-
- // ----- Creates a temporary file
- $v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz';
- if (($v_dest_file = @fopen($v_gzip_temp_name, "wb")) == 0) {
- fclose($v_file);
- PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode');
- return PclZip::errorCode();
- }
-
-
- // ----- Write gz file format header
- $v_binary_data = pack('va1a1Va1a1', 0x8b1f, Chr($p_entry['compression']), Chr(0x00), time(), Chr(0x00), Chr(3));
- @fwrite($v_dest_file, $v_binary_data, 10);
-
- // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks
- $v_size = $p_entry['compressed_size'];
- while ($v_size != 0)
- {
- $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
- $v_buffer = @fread($this->zip_fd, $v_read_size);
- //$v_binary_data = pack('a'.$v_read_size, $v_buffer);
- @fwrite($v_dest_file, $v_buffer, $v_read_size);
- $v_size -= $v_read_size;
- }
-
- // ----- Write gz file format footer
- $v_binary_data = pack('VV', $p_entry['crc'], $p_entry['size']);
- @fwrite($v_dest_file, $v_binary_data, 8);
-
- // ----- Close the temporary file
- @fclose($v_dest_file);
-
- // ----- Opening destination file
- if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) {
- $p_entry['status'] = "write_error";
- return $v_result;
- }
-
- // ----- Open the temporary gz file
- if (($v_src_file = @gzopen($v_gzip_temp_name, 'rb')) == 0) {
- @fclose($v_dest_file);
- $p_entry['status'] = "read_error";
- PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode');
- return PclZip::errorCode();
- }
-
-
- // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks
- $v_size = $p_entry['size'];
- while ($v_size != 0) {
- $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
- $v_buffer = @gzread($v_src_file, $v_read_size);
- //$v_binary_data = pack('a'.$v_read_size, $v_buffer);
- @fwrite($v_dest_file, $v_buffer, $v_read_size);
- $v_size -= $v_read_size;
- }
- @fclose($v_dest_file);
- @gzclose($v_src_file);
-
- // ----- Delete the temporary file
- @unlink($v_gzip_temp_name);
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privExtractFileInOutput()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privExtractFileInOutput(&$p_entry, &$p_options)
- {
- $v_result=1;
-
- // ----- Read the file header
- if (($v_result = $this->privReadFileHeader($v_header)) != 1) {
- return $v_result;
- }
-
-
- // ----- Check that the file header is coherent with $p_entry info
- if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {
- // TBC
- }
-
- // ----- Look for pre-extract callback
- if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {
-
- // ----- Generate a local information
- $v_local_header = array();
- $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
-
- // ----- Call the callback
- // Here I do not use call_user_func() because I need to send a reference to the
- // header.
-// eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);');
- $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header);
- if ($v_result == 0) {
- // ----- Change the file status
- $p_entry['status'] = "skipped";
- $v_result = 1;
- }
-
- // ----- Look for abort result
- if ($v_result == 2) {
- // ----- This status is internal and will be changed in 'skipped'
- $p_entry['status'] = "aborted";
- $v_result = PCLZIP_ERR_USER_ABORTED;
- }
-
- // ----- Update the informations
- // Only some fields can be modified
- $p_entry['filename'] = $v_local_header['filename'];
- }
-
- // ----- Trace
-
- // ----- Look if extraction should be done
- if ($p_entry['status'] == 'ok') {
-
- // ----- Do the extraction (if not a folder)
- if (!(($p_entry['external']&0x00000010)==0x00000010)) {
- // ----- Look for not compressed file
- if ($p_entry['compressed_size'] == $p_entry['size']) {
-
- // ----- Read the file in a buffer (one shot)
- $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
-
- // ----- Send the file to the output
- echo $v_buffer;
- unset($v_buffer);
- }
- else {
-
- // ----- Read the compressed file in a buffer (one shot)
- $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
-
- // ----- Decompress the file
- $v_file_content = gzinflate($v_buffer);
- unset($v_buffer);
-
- // ----- Send the file to the output
- echo $v_file_content;
- unset($v_file_content);
- }
- }
- }
-
- // ----- Change abort status
- if ($p_entry['status'] == "aborted") {
- $p_entry['status'] = "skipped";
- }
-
- // ----- Look for post-extract callback
- elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) {
-
- // ----- Generate a local information
- $v_local_header = array();
- $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
-
- // ----- Call the callback
- // Here I do not use call_user_func() because I need to send a reference to the
- // header.
-// eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);');
- $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header);
-
- // ----- Look for abort result
- if ($v_result == 2) {
- $v_result = PCLZIP_ERR_USER_ABORTED;
- }
- }
-
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privExtractFileAsString()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privExtractFileAsString(&$p_entry, &$p_string, &$p_options)
- {
- $v_result=1;
-
- // ----- Read the file header
- $v_header = array();
- if (($v_result = $this->privReadFileHeader($v_header)) != 1)
- {
- // ----- Return
- return $v_result;
- }
-
-
- // ----- Check that the file header is coherent with $p_entry info
- if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {
- // TBC
- }
-
- // ----- Look for pre-extract callback
- if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {
-
- // ----- Generate a local information
- $v_local_header = array();
- $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
-
- // ----- Call the callback
- // Here I do not use call_user_func() because I need to send a reference to the
- // header.
-// eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);');
- $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header);
- if ($v_result == 0) {
- // ----- Change the file status
- $p_entry['status'] = "skipped";
- $v_result = 1;
- }
-
- // ----- Look for abort result
- if ($v_result == 2) {
- // ----- This status is internal and will be changed in 'skipped'
- $p_entry['status'] = "aborted";
- $v_result = PCLZIP_ERR_USER_ABORTED;
- }
-
- // ----- Update the informations
- // Only some fields can be modified
- $p_entry['filename'] = $v_local_header['filename'];
- }
-
-
- // ----- Look if extraction should be done
- if ($p_entry['status'] == 'ok') {
-
- // ----- Do the extraction (if not a folder)
- if (!(($p_entry['external']&0x00000010)==0x00000010)) {
- // ----- Look for not compressed file
- // if ($p_entry['compressed_size'] == $p_entry['size'])
- if ($p_entry['compression'] == 0) {
-
- // ----- Reading the file
- $p_string = @fread($this->zip_fd, $p_entry['compressed_size']);
- }
- else {
-
- // ----- Reading the file
- $v_data = @fread($this->zip_fd, $p_entry['compressed_size']);
-
- // ----- Decompress the file
- if (($p_string = @gzinflate($v_data)) === FALSE) {
- // TBC
- }
- }
-
- // ----- Trace
- }
- else {
- // TBC : error : can not extract a folder in a string
- }
-
- }
-
- // ----- Change abort status
- if ($p_entry['status'] == "aborted") {
- $p_entry['status'] = "skipped";
- }
-
- // ----- Look for post-extract callback
- elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) {
-
- // ----- Generate a local information
- $v_local_header = array();
- $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
-
- // ----- Swap the content to header
- $v_local_header['content'] = $p_string;
- $p_string = '';
-
- // ----- Call the callback
- // Here I do not use call_user_func() because I need to send a reference to the
- // header.
-// eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);');
- $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header);
-
- // ----- Swap back the content to header
- $p_string = $v_local_header['content'];
- unset($v_local_header['content']);
-
- // ----- Look for abort result
- if ($v_result == 2) {
- $v_result = PCLZIP_ERR_USER_ABORTED;
- }
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privReadFileHeader()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privReadFileHeader(&$p_header)
- {
- $v_result=1;
-
- // ----- Read the 4 bytes signature
- $v_binary_data = @fread($this->zip_fd, 4);
- $v_data = unpack('Vid', $v_binary_data);
-
- // ----- Check signature
- if ($v_data['id'] != 0x04034b50)
- {
-
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure');
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Read the first 42 bytes of the header
- $v_binary_data = fread($this->zip_fd, 26);
-
- // ----- Look for invalid block size
- if (strlen($v_binary_data) != 26)
- {
- $p_header['filename'] = "";
- $p_header['status'] = "invalid_header";
-
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data));
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Extract the values
- $v_data = unpack('vversion/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len', $v_binary_data);
-
- // ----- Get filename
- $p_header['filename'] = fread($this->zip_fd, $v_data['filename_len']);
-
- // ----- Get extra_fields
- if ($v_data['extra_len'] != 0) {
- $p_header['extra'] = fread($this->zip_fd, $v_data['extra_len']);
- }
- else {
- $p_header['extra'] = '';
- }
-
- // ----- Extract properties
- $p_header['version_extracted'] = $v_data['version'];
- $p_header['compression'] = $v_data['compression'];
- $p_header['size'] = $v_data['size'];
- $p_header['compressed_size'] = $v_data['compressed_size'];
- $p_header['crc'] = $v_data['crc'];
- $p_header['flag'] = $v_data['flag'];
- $p_header['filename_len'] = $v_data['filename_len'];
-
- // ----- Recuperate date in UNIX format
- $p_header['mdate'] = $v_data['mdate'];
- $p_header['mtime'] = $v_data['mtime'];
- if ($p_header['mdate'] && $p_header['mtime'])
- {
- // ----- Extract time
- $v_hour = ($p_header['mtime'] & 0xF800) >> 11;
- $v_minute = ($p_header['mtime'] & 0x07E0) >> 5;
- $v_seconde = ($p_header['mtime'] & 0x001F)*2;
-
- // ----- Extract date
- $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980;
- $v_month = ($p_header['mdate'] & 0x01E0) >> 5;
- $v_day = $p_header['mdate'] & 0x001F;
-
- // ----- Get UNIX date format
- $p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year);
-
- }
- else
- {
- $p_header['mtime'] = time();
- }
-
- // TBC
- //for(reset($v_data); $key = key($v_data); next($v_data)) {
- //}
-
- // ----- Set the stored filename
- $p_header['stored_filename'] = $p_header['filename'];
-
- // ----- Set the status field
- $p_header['status'] = "ok";
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privReadCentralFileHeader()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privReadCentralFileHeader(&$p_header)
- {
- $v_result=1;
-
- // ----- Read the 4 bytes signature
- $v_binary_data = @fread($this->zip_fd, 4);
- $v_data = unpack('Vid', $v_binary_data);
-
- // ----- Check signature
- if ($v_data['id'] != 0x02014b50)
- {
-
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure');
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Read the first 42 bytes of the header
- $v_binary_data = fread($this->zip_fd, 42);
-
- // ----- Look for invalid block size
- if (strlen($v_binary_data) != 42)
- {
- $p_header['filename'] = "";
- $p_header['status'] = "invalid_header";
-
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data));
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Extract the values
- $p_header = unpack('vversion/vversion_extracted/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len/vcomment_len/vdisk/vinternal/Vexternal/Voffset', $v_binary_data);
-
- // ----- Get filename
- if ($p_header['filename_len'] != 0)
- $p_header['filename'] = fread($this->zip_fd, $p_header['filename_len']);
- else
- $p_header['filename'] = '';
-
- // ----- Get extra
- if ($p_header['extra_len'] != 0)
- $p_header['extra'] = fread($this->zip_fd, $p_header['extra_len']);
- else
- $p_header['extra'] = '';
-
- // ----- Get comment
- if ($p_header['comment_len'] != 0)
- $p_header['comment'] = fread($this->zip_fd, $p_header['comment_len']);
- else
- $p_header['comment'] = '';
-
- // ----- Extract properties
-
- // ----- Recuperate date in UNIX format
- //if ($p_header['mdate'] && $p_header['mtime'])
- // TBC : bug : this was ignoring time with 0/0/0
- if (1)
- {
- // ----- Extract time
- $v_hour = ($p_header['mtime'] & 0xF800) >> 11;
- $v_minute = ($p_header['mtime'] & 0x07E0) >> 5;
- $v_seconde = ($p_header['mtime'] & 0x001F)*2;
-
- // ----- Extract date
- $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980;
- $v_month = ($p_header['mdate'] & 0x01E0) >> 5;
- $v_day = $p_header['mdate'] & 0x001F;
-
- // ----- Get UNIX date format
- $p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year);
-
- }
- else
- {
- $p_header['mtime'] = time();
- }
-
- // ----- Set the stored filename
- $p_header['stored_filename'] = $p_header['filename'];
-
- // ----- Set default status to ok
- $p_header['status'] = 'ok';
-
- // ----- Look if it is a directory
- if (substr($p_header['filename'], -1) == '/') {
- //$p_header['external'] = 0x41FF0010;
- $p_header['external'] = 0x00000010;
- }
-
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privCheckFileHeaders()
- // Description :
- // Parameters :
- // Return Values :
- // 1 on success,
- // 0 on error;
- // --------------------------------------------------------------------------------
- function privCheckFileHeaders(&$p_local_header, &$p_central_header)
- {
- $v_result=1;
-
- // ----- Check the static values
- // TBC
- if ($p_local_header['filename'] != $p_central_header['filename']) {
- }
- if ($p_local_header['version_extracted'] != $p_central_header['version_extracted']) {
- }
- if ($p_local_header['flag'] != $p_central_header['flag']) {
- }
- if ($p_local_header['compression'] != $p_central_header['compression']) {
- }
- if ($p_local_header['mtime'] != $p_central_header['mtime']) {
- }
- if ($p_local_header['filename_len'] != $p_central_header['filename_len']) {
- }
-
- // ----- Look for flag bit 3
- if (($p_local_header['flag'] & 8) == 8) {
- $p_local_header['size'] = $p_central_header['size'];
- $p_local_header['compressed_size'] = $p_central_header['compressed_size'];
- $p_local_header['crc'] = $p_central_header['crc'];
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privReadEndCentralDir()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privReadEndCentralDir(&$p_central_dir)
- {
- $v_result=1;
-
- // ----- Go to the end of the zip file
- $v_size = filesize($this->zipname);
- @fseek($this->zip_fd, $v_size);
- if (@ftell($this->zip_fd) != $v_size)
- {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to go to the end of the archive \''.$this->zipname.'\'');
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- First try : look if this is an archive with no commentaries (most of the time)
- // in this case the end of central dir is at 22 bytes of the file end
- $v_found = 0;
- if ($v_size > 26) {
- @fseek($this->zip_fd, $v_size-22);
- if (($v_pos = @ftell($this->zip_fd)) != ($v_size-22))
- {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\'');
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Read for bytes
- $v_binary_data = @fread($this->zip_fd, 4);
- $v_data = @unpack('Vid', $v_binary_data);
-
- // ----- Check signature
- if ($v_data['id'] == 0x06054b50) {
- $v_found = 1;
- }
-
- $v_pos = ftell($this->zip_fd);
- }
-
- // ----- Go back to the maximum possible size of the Central Dir End Record
- if (!$v_found) {
- $v_maximum_size = 65557; // 0xFFFF + 22;
- if ($v_maximum_size > $v_size)
- $v_maximum_size = $v_size;
- @fseek($this->zip_fd, $v_size-$v_maximum_size);
- if (@ftell($this->zip_fd) != ($v_size-$v_maximum_size))
- {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\'');
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Read byte per byte in order to find the signature
- $v_pos = ftell($this->zip_fd);
- $v_bytes = 0x00000000;
- while ($v_pos < $v_size)
- {
- // ----- Read a byte
- $v_byte = @fread($this->zip_fd, 1);
-
- // ----- Add the byte
- //$v_bytes = ($v_bytes << 8) | Ord($v_byte);
- // Note we mask the old value down such that once shifted we can never end up with more than a 32bit number
- // Otherwise on systems where we have 64bit integers the check below for the magic number will fail.
- $v_bytes = ( ($v_bytes & 0xFFFFFF) << 8) | Ord($v_byte);
-
- // ----- Compare the bytes
- if ($v_bytes == 0x504b0506)
- {
- $v_pos++;
- break;
- }
-
- $v_pos++;
- }
-
- // ----- Look if not found end of central dir
- if ($v_pos == $v_size)
- {
-
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Unable to find End of Central Dir Record signature");
-
- // ----- Return
- return PclZip::errorCode();
- }
- }
-
- // ----- Read the first 18 bytes of the header
- $v_binary_data = fread($this->zip_fd, 18);
-
- // ----- Look for invalid block size
- if (strlen($v_binary_data) != 18)
- {
-
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid End of Central Dir Record size : ".strlen($v_binary_data));
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Extract the values
- $v_data = unpack('vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size', $v_binary_data);
-
- // ----- Check the global size
- if (($v_pos + $v_data['comment_size'] + 18) != $v_size) {
-
- // ----- Removed in release 2.2 see readme file
- // The check of the file size is a little too strict.
- // Some bugs where found when a zip is encrypted/decrypted with 'crypt'.
- // While decrypted, zip has training 0 bytes
- if (0) {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT,
- 'The central dir is not at the end of the archive.'
- .' Some trailing bytes exists after the archive.');
-
- // ----- Return
- return PclZip::errorCode();
- }
- }
-
- // ----- Get comment
- if ($v_data['comment_size'] != 0) {
- $p_central_dir['comment'] = fread($this->zip_fd, $v_data['comment_size']);
- }
- else
- $p_central_dir['comment'] = '';
-
- $p_central_dir['entries'] = $v_data['entries'];
- $p_central_dir['disk_entries'] = $v_data['disk_entries'];
- $p_central_dir['offset'] = $v_data['offset'];
- $p_central_dir['size'] = $v_data['size'];
- $p_central_dir['disk'] = $v_data['disk'];
- $p_central_dir['disk_start'] = $v_data['disk_start'];
-
- // TBC
- //for(reset($p_central_dir); $key = key($p_central_dir); next($p_central_dir)) {
- //}
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privDeleteByRule()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privDeleteByRule(&$p_result_list, &$p_options)
- {
- $v_result=1;
- $v_list_detail = array();
-
- // ----- Open the zip file
- if (($v_result=$this->privOpenFd('rb')) != 1)
- {
- // ----- Return
- return $v_result;
- }
-
- // ----- Read the central directory informations
- $v_central_dir = array();
- if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
- {
- $this->privCloseFd();
- return $v_result;
- }
-
- // ----- Go to beginning of File
- @rewind($this->zip_fd);
-
- // ----- Scan all the files
- // ----- Start at beginning of Central Dir
- $v_pos_entry = $v_central_dir['offset'];
- @rewind($this->zip_fd);
- if (@fseek($this->zip_fd, $v_pos_entry))
- {
- // ----- Close the zip file
- $this->privCloseFd();
-
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Read each entry
- $v_header_list = array();
- $j_start = 0;
- for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++)
- {
-
- // ----- Read the file header
- $v_header_list[$v_nb_extracted] = array();
- if (($v_result = $this->privReadCentralFileHeader($v_header_list[$v_nb_extracted])) != 1)
- {
- // ----- Close the zip file
- $this->privCloseFd();
-
- return $v_result;
- }
-
-
- // ----- Store the index
- $v_header_list[$v_nb_extracted]['index'] = $i;
-
- // ----- Look for the specific extract rules
- $v_found = false;
-
- // ----- Look for extract by name rule
- if ( (isset($p_options[PCLZIP_OPT_BY_NAME]))
- && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) {
-
- // ----- Look if the filename is in the list
- for ($j=0; ($j strlen($p_options[PCLZIP_OPT_BY_NAME][$j]))
- && (substr($v_header_list[$v_nb_extracted]['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) {
- $v_found = true;
- }
- elseif ( (($v_header_list[$v_nb_extracted]['external']&0x00000010)==0x00000010) /* Indicates a folder */
- && ($v_header_list[$v_nb_extracted]['stored_filename'].'/' == $p_options[PCLZIP_OPT_BY_NAME][$j])) {
- $v_found = true;
- }
- }
- // ----- Look for a filename
- elseif ($v_header_list[$v_nb_extracted]['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) {
- $v_found = true;
- }
- }
- }
-
- // ----- Look for extract by ereg rule
- // ereg() is deprecated with PHP 5.3
- /*
- else if ( (isset($p_options[PCLZIP_OPT_BY_EREG]))
- && ($p_options[PCLZIP_OPT_BY_EREG] != "")) {
-
- if (ereg($p_options[PCLZIP_OPT_BY_EREG], $v_header_list[$v_nb_extracted]['stored_filename'])) {
- $v_found = true;
- }
- }
- */
-
- // ----- Look for extract by preg rule
- else if ( (isset($p_options[PCLZIP_OPT_BY_PREG]))
- && ($p_options[PCLZIP_OPT_BY_PREG] != "")) {
-
- if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header_list[$v_nb_extracted]['stored_filename'])) {
- $v_found = true;
- }
- }
-
- // ----- Look for extract by index rule
- else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX]))
- && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) {
-
- // ----- Look if the index is in the list
- for ($j=$j_start; ($j=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) {
- $v_found = true;
- }
- if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) {
- $j_start = $j+1;
- }
-
- if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) {
- break;
- }
- }
- }
- else {
- $v_found = true;
- }
-
- // ----- Look for deletion
- if ($v_found)
- {
- unset($v_header_list[$v_nb_extracted]);
- }
- else
- {
- $v_nb_extracted++;
- }
- }
-
- // ----- Look if something need to be deleted
- if ($v_nb_extracted > 0) {
-
- // ----- Creates a temporay file
- $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
-
- // ----- Creates a temporary zip archive
- $v_temp_zip = new PclZip($v_zip_temp_name);
-
- // ----- Open the temporary zip file in write mode
- if (($v_result = $v_temp_zip->privOpenFd('wb')) != 1) {
- $this->privCloseFd();
-
- // ----- Return
- return $v_result;
- }
-
- // ----- Look which file need to be kept
- for ($i=0; $izip_fd);
- if (@fseek($this->zip_fd, $v_header_list[$i]['offset'])) {
- // ----- Close the zip file
- $this->privCloseFd();
- $v_temp_zip->privCloseFd();
- @unlink($v_zip_temp_name);
-
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Read the file header
- $v_local_header = array();
- if (($v_result = $this->privReadFileHeader($v_local_header)) != 1) {
- // ----- Close the zip file
- $this->privCloseFd();
- $v_temp_zip->privCloseFd();
- @unlink($v_zip_temp_name);
-
- // ----- Return
- return $v_result;
- }
-
- // ----- Check that local file header is same as central file header
- if ($this->privCheckFileHeaders($v_local_header,
- $v_header_list[$i]) != 1) {
- // TBC
- }
- unset($v_local_header);
-
- // ----- Write the file header
- if (($v_result = $v_temp_zip->privWriteFileHeader($v_header_list[$i])) != 1) {
- // ----- Close the zip file
- $this->privCloseFd();
- $v_temp_zip->privCloseFd();
- @unlink($v_zip_temp_name);
-
- // ----- Return
- return $v_result;
- }
-
- // ----- Read/write the data block
- if (($v_result = PclZipUtilCopyBlock($this->zip_fd, $v_temp_zip->zip_fd, $v_header_list[$i]['compressed_size'])) != 1) {
- // ----- Close the zip file
- $this->privCloseFd();
- $v_temp_zip->privCloseFd();
- @unlink($v_zip_temp_name);
-
- // ----- Return
- return $v_result;
- }
- }
-
- // ----- Store the offset of the central dir
- $v_offset = @ftell($v_temp_zip->zip_fd);
-
- // ----- Re-Create the Central Dir files header
- for ($i=0; $iprivWriteCentralFileHeader($v_header_list[$i])) != 1) {
- $v_temp_zip->privCloseFd();
- $this->privCloseFd();
- @unlink($v_zip_temp_name);
-
- // ----- Return
- return $v_result;
- }
-
- // ----- Transform the header to a 'usable' info
- $v_temp_zip->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
- }
-
-
- // ----- Zip file comment
- $v_comment = '';
- if (isset($p_options[PCLZIP_OPT_COMMENT])) {
- $v_comment = $p_options[PCLZIP_OPT_COMMENT];
- }
-
- // ----- Calculate the size of the central header
- $v_size = @ftell($v_temp_zip->zip_fd)-$v_offset;
-
- // ----- Create the central dir footer
- if (($v_result = $v_temp_zip->privWriteCentralHeader(sizeof($v_header_list), $v_size, $v_offset, $v_comment)) != 1) {
- // ----- Reset the file list
- unset($v_header_list);
- $v_temp_zip->privCloseFd();
- $this->privCloseFd();
- @unlink($v_zip_temp_name);
-
- // ----- Return
- return $v_result;
- }
-
- // ----- Close
- $v_temp_zip->privCloseFd();
- $this->privCloseFd();
-
- // ----- Delete the zip file
- // TBC : I should test the result ...
- @unlink($this->zipname);
-
- // ----- Rename the temporary file
- // TBC : I should test the result ...
- //@rename($v_zip_temp_name, $this->zipname);
- PclZipUtilRename($v_zip_temp_name, $this->zipname);
-
- // ----- Destroy the temporary archive
- unset($v_temp_zip);
- }
-
- // ----- Remove every files : reset the file
- else if ($v_central_dir['entries'] != 0) {
- $this->privCloseFd();
-
- if (($v_result = $this->privOpenFd('wb')) != 1) {
- return $v_result;
- }
-
- if (($v_result = $this->privWriteCentralHeader(0, 0, 0, '')) != 1) {
- return $v_result;
- }
-
- $this->privCloseFd();
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privDirCheck()
- // Description :
- // Check if a directory exists, if not it creates it and all the parents directory
- // which may be useful.
- // Parameters :
- // $p_dir : Directory path to check.
- // Return Values :
- // 1 : OK
- // -1 : Unable to create directory
- // --------------------------------------------------------------------------------
- function privDirCheck($p_dir, $p_is_dir=false)
- {
- $v_result = 1;
-
-
- // ----- Remove the final '/'
- if (($p_is_dir) && (substr($p_dir, -1)=='/'))
- {
- $p_dir = substr($p_dir, 0, strlen($p_dir)-1);
- }
-
- // ----- Check the directory availability
- if ((is_dir($p_dir)) || ($p_dir == ""))
- {
- return 1;
- }
-
- // ----- Extract parent directory
- $p_parent_dir = dirname($p_dir);
-
- // ----- Just a check
- if ($p_parent_dir != $p_dir)
- {
- // ----- Look for parent directory
- if ($p_parent_dir != "")
- {
- if (($v_result = $this->privDirCheck($p_parent_dir)) != 1)
- {
- return $v_result;
- }
- }
- }
-
- // ----- Create the directory
- if (!@mkdir($p_dir, 0777))
- {
- // ----- Error log
- PclZip::privErrorLog(PCLZIP_ERR_DIR_CREATE_FAIL, "Unable to create directory '$p_dir'");
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privMerge()
- // Description :
- // If $p_archive_to_add does not exist, the function exit with a success result.
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privMerge(&$p_archive_to_add)
- {
- $v_result=1;
-
- // ----- Look if the archive_to_add exists
- if (!is_file($p_archive_to_add->zipname))
- {
-
- // ----- Nothing to merge, so merge is a success
- $v_result = 1;
-
- // ----- Return
- return $v_result;
- }
-
- // ----- Look if the archive exists
- if (!is_file($this->zipname))
- {
-
- // ----- Do a duplicate
- $v_result = $this->privDuplicate($p_archive_to_add->zipname);
-
- // ----- Return
- return $v_result;
- }
-
- // ----- Open the zip file
- if (($v_result=$this->privOpenFd('rb')) != 1)
- {
- // ----- Return
- return $v_result;
- }
-
- // ----- Read the central directory informations
- $v_central_dir = array();
- if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
- {
- $this->privCloseFd();
- return $v_result;
- }
-
- // ----- Go to beginning of File
- @rewind($this->zip_fd);
-
- // ----- Open the archive_to_add file
- if (($v_result=$p_archive_to_add->privOpenFd('rb')) != 1)
- {
- $this->privCloseFd();
-
- // ----- Return
- return $v_result;
- }
-
- // ----- Read the central directory informations
- $v_central_dir_to_add = array();
- if (($v_result = $p_archive_to_add->privReadEndCentralDir($v_central_dir_to_add)) != 1)
- {
- $this->privCloseFd();
- $p_archive_to_add->privCloseFd();
-
- return $v_result;
- }
-
- // ----- Go to beginning of File
- @rewind($p_archive_to_add->zip_fd);
-
- // ----- Creates a temporay file
- $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
-
- // ----- Open the temporary file in write mode
- if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0)
- {
- $this->privCloseFd();
- $p_archive_to_add->privCloseFd();
-
- PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode');
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Copy the files from the archive to the temporary file
- // TBC : Here I should better append the file and go back to erase the central dir
- $v_size = $v_central_dir['offset'];
- while ($v_size != 0)
- {
- $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
- $v_buffer = fread($this->zip_fd, $v_read_size);
- @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
- $v_size -= $v_read_size;
- }
-
- // ----- Copy the files from the archive_to_add into the temporary file
- $v_size = $v_central_dir_to_add['offset'];
- while ($v_size != 0)
- {
- $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
- $v_buffer = fread($p_archive_to_add->zip_fd, $v_read_size);
- @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
- $v_size -= $v_read_size;
- }
-
- // ----- Store the offset of the central dir
- $v_offset = @ftell($v_zip_temp_fd);
-
- // ----- Copy the block of file headers from the old archive
- $v_size = $v_central_dir['size'];
- while ($v_size != 0)
- {
- $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
- $v_buffer = @fread($this->zip_fd, $v_read_size);
- @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
- $v_size -= $v_read_size;
- }
-
- // ----- Copy the block of file headers from the archive_to_add
- $v_size = $v_central_dir_to_add['size'];
- while ($v_size != 0)
- {
- $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
- $v_buffer = @fread($p_archive_to_add->zip_fd, $v_read_size);
- @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
- $v_size -= $v_read_size;
- }
-
- // ----- Merge the file comments
- $v_comment = $v_central_dir['comment'].' '.$v_central_dir_to_add['comment'];
-
- // ----- Calculate the size of the (new) central header
- $v_size = @ftell($v_zip_temp_fd)-$v_offset;
-
- // ----- Swap the file descriptor
- // Here is a trick : I swap the temporary fd with the zip fd, in order to use
- // the following methods on the temporary fil and not the real archive fd
- $v_swap = $this->zip_fd;
- $this->zip_fd = $v_zip_temp_fd;
- $v_zip_temp_fd = $v_swap;
-
- // ----- Create the central dir footer
- if (($v_result = $this->privWriteCentralHeader($v_central_dir['entries']+$v_central_dir_to_add['entries'], $v_size, $v_offset, $v_comment)) != 1)
- {
- $this->privCloseFd();
- $p_archive_to_add->privCloseFd();
- @fclose($v_zip_temp_fd);
- $this->zip_fd = null;
-
- // ----- Reset the file list
- unset($v_header_list);
-
- // ----- Return
- return $v_result;
- }
-
- // ----- Swap back the file descriptor
- $v_swap = $this->zip_fd;
- $this->zip_fd = $v_zip_temp_fd;
- $v_zip_temp_fd = $v_swap;
-
- // ----- Close
- $this->privCloseFd();
- $p_archive_to_add->privCloseFd();
-
- // ----- Close the temporary file
- @fclose($v_zip_temp_fd);
-
- // ----- Delete the zip file
- // TBC : I should test the result ...
- @unlink($this->zipname);
-
- // ----- Rename the temporary file
- // TBC : I should test the result ...
- //@rename($v_zip_temp_name, $this->zipname);
- PclZipUtilRename($v_zip_temp_name, $this->zipname);
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privDuplicate()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privDuplicate($p_archive_filename)
- {
- $v_result=1;
-
- // ----- Look if the $p_archive_filename exists
- if (!is_file($p_archive_filename))
- {
-
- // ----- Nothing to duplicate, so duplicate is a success.
- $v_result = 1;
-
- // ----- Return
- return $v_result;
- }
-
- // ----- Open the zip file
- if (($v_result=$this->privOpenFd('wb')) != 1)
- {
- // ----- Return
- return $v_result;
- }
-
- // ----- Open the temporary file in write mode
- if (($v_zip_temp_fd = @fopen($p_archive_filename, 'rb')) == 0)
- {
- $this->privCloseFd();
-
- PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive file \''.$p_archive_filename.'\' in binary write mode');
-
- // ----- Return
- return PclZip::errorCode();
- }
-
- // ----- Copy the files from the archive to the temporary file
- // TBC : Here I should better append the file and go back to erase the central dir
- $v_size = filesize($p_archive_filename);
- while ($v_size != 0)
- {
- $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
- $v_buffer = fread($v_zip_temp_fd, $v_read_size);
- @fwrite($this->zip_fd, $v_buffer, $v_read_size);
- $v_size -= $v_read_size;
- }
-
- // ----- Close
- $this->privCloseFd();
-
- // ----- Close the temporary file
- @fclose($v_zip_temp_fd);
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privErrorLog()
- // Description :
- // Parameters :
- // --------------------------------------------------------------------------------
- function privErrorLog($p_error_code=0, $p_error_string='')
- {
- if (PCLZIP_ERROR_EXTERNAL == 1) {
- PclError($p_error_code, $p_error_string);
- }
- else {
- $this->error_code = $p_error_code;
- $this->error_string = $p_error_string;
- }
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privErrorReset()
- // Description :
- // Parameters :
- // --------------------------------------------------------------------------------
- function privErrorReset()
- {
- if (PCLZIP_ERROR_EXTERNAL == 1) {
- PclErrorReset();
- }
- else {
- $this->error_code = 0;
- $this->error_string = '';
- }
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privDisableMagicQuotes()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privDisableMagicQuotes()
- {
- $v_result=1;
-
- // ----- Look if function exists
- if ( (!function_exists("get_magic_quotes_runtime"))
- || (!function_exists("set_magic_quotes_runtime"))) {
- return $v_result;
- }
-
- // ----- Look if already done
- if ($this->magic_quotes_status != -1) {
- return $v_result;
- }
-
- // ----- Get and memorize the magic_quote value
- $this->magic_quotes_status = @get_magic_quotes_runtime();
-
- // ----- Disable magic_quotes
- if ($this->magic_quotes_status == 1) {
- @set_magic_quotes_runtime(0);
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : privSwapBackMagicQuotes()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function privSwapBackMagicQuotes()
- {
- $v_result=1;
-
- // ----- Look if function exists
- if ( (!function_exists("get_magic_quotes_runtime"))
- || (!function_exists("set_magic_quotes_runtime"))) {
- return $v_result;
- }
-
- // ----- Look if something to do
- if ($this->magic_quotes_status != -1) {
- return $v_result;
- }
-
- // ----- Swap back magic_quotes
- if ($this->magic_quotes_status == 1) {
- @set_magic_quotes_runtime($this->magic_quotes_status);
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- }
- // End of class
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : PclZipUtilPathReduction()
- // Description :
- // Parameters :
- // Return Values :
- // --------------------------------------------------------------------------------
- function PclZipUtilPathReduction($p_dir)
- {
- $v_result = "";
-
- // ----- Look for not empty path
- if ($p_dir != "") {
- // ----- Explode path by directory names
- $v_list = explode("/", $p_dir);
-
- // ----- Study directories from last to first
- $v_skip = 0;
- for ($i=sizeof($v_list)-1; $i>=0; $i--) {
- // ----- Look for current path
- if ($v_list[$i] == ".") {
- // ----- Ignore this directory
- // Should be the first $i=0, but no check is done
- }
- else if ($v_list[$i] == "..") {
- $v_skip++;
- }
- else if ($v_list[$i] == "") {
- // ----- First '/' i.e. root slash
- if ($i == 0) {
- $v_result = "/".$v_result;
- if ($v_skip > 0) {
- // ----- It is an invalid path, so the path is not modified
- // TBC
- $v_result = $p_dir;
- $v_skip = 0;
- }
- }
- // ----- Last '/' i.e. indicates a directory
- else if ($i == (sizeof($v_list)-1)) {
- $v_result = $v_list[$i];
- }
- // ----- Double '/' inside the path
- else {
- // ----- Ignore only the double '//' in path,
- // but not the first and last '/'
- }
- }
- else {
- // ----- Look for item to skip
- if ($v_skip > 0) {
- $v_skip--;
- }
- else {
- $v_result = $v_list[$i].($i!=(sizeof($v_list)-1)?"/".$v_result:"");
- }
- }
- }
-
- // ----- Look for skip
- if ($v_skip > 0) {
- while ($v_skip > 0) {
- $v_result = '../'.$v_result;
- $v_skip--;
- }
- }
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : PclZipUtilPathInclusion()
- // Description :
- // This function indicates if the path $p_path is under the $p_dir tree. Or,
- // said in an other way, if the file or sub-dir $p_path is inside the dir
- // $p_dir.
- // The function indicates also if the path is exactly the same as the dir.
- // This function supports path with duplicated '/' like '//', but does not
- // support '.' or '..' statements.
- // Parameters :
- // Return Values :
- // 0 if $p_path is not inside directory $p_dir
- // 1 if $p_path is inside directory $p_dir
- // 2 if $p_path is exactly the same as $p_dir
- // --------------------------------------------------------------------------------
- function PclZipUtilPathInclusion($p_dir, $p_path)
- {
- $v_result = 1;
-
- // ----- Look for path beginning by ./
- if ( ($p_dir == '.')
- || ((strlen($p_dir) >=2) && (substr($p_dir, 0, 2) == './'))) {
- $p_dir = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_dir, 1);
- }
- if ( ($p_path == '.')
- || ((strlen($p_path) >=2) && (substr($p_path, 0, 2) == './'))) {
- $p_path = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_path, 1);
- }
-
- // ----- Explode dir and path by directory separator
- $v_list_dir = explode("/", $p_dir);
- $v_list_dir_size = sizeof($v_list_dir);
- $v_list_path = explode("/", $p_path);
- $v_list_path_size = sizeof($v_list_path);
-
- // ----- Study directories paths
- $i = 0;
- $j = 0;
- while (($i < $v_list_dir_size) && ($j < $v_list_path_size) && ($v_result)) {
-
- // ----- Look for empty dir (path reduction)
- if ($v_list_dir[$i] == '') {
- $i++;
- continue;
- }
- if ($v_list_path[$j] == '') {
- $j++;
- continue;
- }
-
- // ----- Compare the items
- if (($v_list_dir[$i] != $v_list_path[$j]) && ($v_list_dir[$i] != '') && ( $v_list_path[$j] != '')) {
- $v_result = 0;
- }
-
- // ----- Next items
- $i++;
- $j++;
- }
-
- // ----- Look if everything seems to be the same
- if ($v_result) {
- // ----- Skip all the empty items
- while (($j < $v_list_path_size) && ($v_list_path[$j] == '')) $j++;
- while (($i < $v_list_dir_size) && ($v_list_dir[$i] == '')) $i++;
-
- if (($i >= $v_list_dir_size) && ($j >= $v_list_path_size)) {
- // ----- There are exactly the same
- $v_result = 2;
- }
- else if ($i < $v_list_dir_size) {
- // ----- The path is shorter than the dir
- $v_result = 0;
- }
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : PclZipUtilCopyBlock()
- // Description :
- // Parameters :
- // $p_mode : read/write compression mode
- // 0 : src & dest normal
- // 1 : src gzip, dest normal
- // 2 : src normal, dest gzip
- // 3 : src & dest gzip
- // Return Values :
- // --------------------------------------------------------------------------------
- function PclZipUtilCopyBlock($p_src, $p_dest, $p_size, $p_mode=0)
- {
- $v_result = 1;
-
- if ($p_mode==0)
- {
- while ($p_size != 0)
- {
- $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
- $v_buffer = @fread($p_src, $v_read_size);
- @fwrite($p_dest, $v_buffer, $v_read_size);
- $p_size -= $v_read_size;
- }
- }
- else if ($p_mode==1)
- {
- while ($p_size != 0)
- {
- $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
- $v_buffer = @gzread($p_src, $v_read_size);
- @fwrite($p_dest, $v_buffer, $v_read_size);
- $p_size -= $v_read_size;
- }
- }
- else if ($p_mode==2)
- {
- while ($p_size != 0)
- {
- $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
- $v_buffer = @fread($p_src, $v_read_size);
- @gzwrite($p_dest, $v_buffer, $v_read_size);
- $p_size -= $v_read_size;
- }
- }
- else if ($p_mode==3)
- {
- while ($p_size != 0)
- {
- $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
- $v_buffer = @gzread($p_src, $v_read_size);
- @gzwrite($p_dest, $v_buffer, $v_read_size);
- $p_size -= $v_read_size;
- }
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : PclZipUtilRename()
- // Description :
- // This function tries to do a simple rename() function. If it fails, it
- // tries to copy the $p_src file in a new $p_dest file and then unlink the
- // first one.
- // Parameters :
- // $p_src : Old filename
- // $p_dest : New filename
- // Return Values :
- // 1 on success, 0 on failure.
- // --------------------------------------------------------------------------------
- function PclZipUtilRename($p_src, $p_dest)
- {
- $v_result = 1;
-
- // ----- Try to rename the files
- if (!@rename($p_src, $p_dest)) {
-
- // ----- Try to copy & unlink the src
- if (!@copy($p_src, $p_dest)) {
- $v_result = 0;
- }
- else if (!@unlink($p_src)) {
- $v_result = 0;
- }
- }
-
- // ----- Return
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : PclZipUtilOptionText()
- // Description :
- // Translate option value in text. Mainly for debug purpose.
- // Parameters :
- // $p_option : the option value.
- // Return Values :
- // The option text value.
- // --------------------------------------------------------------------------------
- function PclZipUtilOptionText($p_option)
- {
-
- $v_list = get_defined_constants();
- for (reset($v_list); $v_key = key($v_list); next($v_list)) {
- $v_prefix = substr($v_key, 0, 10);
- if (( ($v_prefix == 'PCLZIP_OPT')
- || ($v_prefix == 'PCLZIP_CB_')
- || ($v_prefix == 'PCLZIP_ATT'))
- && ($v_list[$v_key] == $p_option)) {
- return $v_key;
- }
- }
-
- $v_result = 'Unknown';
-
- return $v_result;
- }
- // --------------------------------------------------------------------------------
-
- // --------------------------------------------------------------------------------
- // Function : PclZipUtilTranslateWinPath()
- // Description :
- // Translate windows path by replacing '\' by '/' and optionally removing
- // drive letter.
- // Parameters :
- // $p_path : path to translate.
- // $p_remove_disk_letter : true | false
- // Return Values :
- // The path translated.
- // --------------------------------------------------------------------------------
- function PclZipUtilTranslateWinPath($p_path, $p_remove_disk_letter=true)
- {
- if (stristr(php_uname(), 'windows')) {
- // ----- Look for potential disk letter
- if (($p_remove_disk_letter) && (($v_position = strpos($p_path, ':')) != false)) {
- $p_path = substr($p_path, $v_position+1);
- }
- // ----- Change potential windows directory separator
- if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0,1) == '\\')) {
- $p_path = strtr($p_path, '\\', '/');
- }
- }
- return $p_path;
- }
- // --------------------------------------------------------------------------------
-
-
-?>
+zipname = $p_zipname;
+ $this->zip_fd = 0;
+ $this->magic_quotes_status = -1;
+
+ // ----- Return
+ return;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function :
+ // create($p_filelist, $p_add_dir="", $p_remove_dir="")
+ // create($p_filelist, $p_option, $p_option_value, ...)
+ // Description :
+ // This method supports two different synopsis. The first one is historical.
+ // This method creates a Zip Archive. The Zip file is created in the
+ // filesystem. The files and directories indicated in $p_filelist
+ // are added in the archive. See the parameters description for the
+ // supported format of $p_filelist.
+ // When a directory is in the list, the directory and its content is added
+ // in the archive.
+ // In this synopsis, the function takes an optional variable list of
+ // options. See bellow the supported options.
+ // Parameters :
+ // $p_filelist : An array containing file or directory names, or
+ // a string containing one filename or one directory name, or
+ // a string containing a list of filenames and/or directory
+ // names separated by spaces.
+ // $p_add_dir : A path to add before the real path of the archived file,
+ // in order to have it memorized in the archive.
+ // $p_remove_dir : A path to remove from the real path of the file to archive,
+ // in order to have a shorter path memorized in the archive.
+ // When $p_add_dir and $p_remove_dir are set, $p_remove_dir
+ // is removed first, before $p_add_dir is added.
+ // Options :
+ // PCLZIP_OPT_ADD_PATH :
+ // PCLZIP_OPT_REMOVE_PATH :
+ // PCLZIP_OPT_REMOVE_ALL_PATH :
+ // PCLZIP_OPT_COMMENT :
+ // PCLZIP_CB_PRE_ADD :
+ // PCLZIP_CB_POST_ADD :
+ // Return Values :
+ // 0 on failure,
+ // The list of the added files, with a status of the add action.
+ // (see PclZip::listContent() for list entry format)
+ // --------------------------------------------------------------------------------
+ function create($p_filelist)
+ {
+ $v_result=1;
+
+ // ----- Reset the error handler
+ $this->privErrorReset();
+
+ // ----- Set default values
+ $v_options = array();
+ $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE;
+
+ // ----- Look for variable options arguments
+ $v_size = func_num_args();
+
+ // ----- Look for arguments
+ if ($v_size > 1) {
+ // ----- Get the arguments
+ $v_arg_list = func_get_args();
+
+ // ----- Remove from the options list the first argument
+ array_shift($v_arg_list);
+ $v_size--;
+
+ // ----- Look for first arg
+ if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
+
+ // ----- Parse the options
+ $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
+ array (PCLZIP_OPT_REMOVE_PATH => 'optional',
+ PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
+ PCLZIP_OPT_ADD_PATH => 'optional',
+ PCLZIP_CB_PRE_ADD => 'optional',
+ PCLZIP_CB_POST_ADD => 'optional',
+ PCLZIP_OPT_NO_COMPRESSION => 'optional',
+ PCLZIP_OPT_COMMENT => 'optional',
+ PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
+ PCLZIP_OPT_TEMP_FILE_ON => 'optional',
+ PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
+ //, PCLZIP_OPT_CRYPT => 'optional'
+ ));
+ if ($v_result != 1) {
+ return 0;
+ }
+ }
+
+ // ----- Look for 2 args
+ // Here we need to support the first historic synopsis of the
+ // method.
+ else {
+
+ // ----- Get the first argument
+ $v_options[PCLZIP_OPT_ADD_PATH] = $v_arg_list[0];
+
+ // ----- Look for the optional second argument
+ if ($v_size == 2) {
+ $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1];
+ }
+ else if ($v_size > 2) {
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,
+ "Invalid number / type of arguments");
+ return 0;
+ }
+ }
+ }
+
+ // ----- Look for default option values
+ $this->privOptionDefaultThreshold($v_options);
+
+ // ----- Init
+ $v_string_list = array();
+ $v_att_list = array();
+ $v_filedescr_list = array();
+ $p_result_list = array();
+
+ // ----- Look if the $p_filelist is really an array
+ if (is_array($p_filelist)) {
+
+ // ----- Look if the first element is also an array
+ // This will mean that this is a file description entry
+ if (isset($p_filelist[0]) && is_array($p_filelist[0])) {
+ $v_att_list = $p_filelist;
+ }
+
+ // ----- The list is a list of string names
+ else {
+ $v_string_list = $p_filelist;
+ }
+ }
+
+ // ----- Look if the $p_filelist is a string
+ else if (is_string($p_filelist)) {
+ // ----- Create a list from the string
+ $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist);
+ }
+
+ // ----- Invalid variable type for $p_filelist
+ else {
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_filelist");
+ return 0;
+ }
+
+ // ----- Reformat the string list
+ if (sizeof($v_string_list) != 0) {
+ foreach ($v_string_list as $v_string) {
+ if ($v_string != '') {
+ $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string;
+ }
+ else {
+ }
+ }
+ }
+
+ // ----- For each file in the list check the attributes
+ $v_supported_attributes
+ = array ( PCLZIP_ATT_FILE_NAME => 'mandatory'
+ ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional'
+ ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional'
+ ,PCLZIP_ATT_FILE_MTIME => 'optional'
+ ,PCLZIP_ATT_FILE_CONTENT => 'optional'
+ ,PCLZIP_ATT_FILE_COMMENT => 'optional'
+ );
+ foreach ($v_att_list as $v_entry) {
+ $v_result = $this->privFileDescrParseAtt($v_entry,
+ $v_filedescr_list[],
+ $v_options,
+ $v_supported_attributes);
+ if ($v_result != 1) {
+ return 0;
+ }
+ }
+
+ // ----- Expand the filelist (expand directories)
+ $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options);
+ if ($v_result != 1) {
+ return 0;
+ }
+
+ // ----- Call the create fct
+ $v_result = $this->privCreate($v_filedescr_list, $p_result_list, $v_options);
+ if ($v_result != 1) {
+ return 0;
+ }
+
+ // ----- Return
+ return $p_result_list;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function :
+ // add($p_filelist, $p_add_dir="", $p_remove_dir="")
+ // add($p_filelist, $p_option, $p_option_value, ...)
+ // Description :
+ // This method supports two synopsis. The first one is historical.
+ // This methods add the list of files in an existing archive.
+ // If a file with the same name already exists, it is added at the end of the
+ // archive, the first one is still present.
+ // If the archive does not exist, it is created.
+ // Parameters :
+ // $p_filelist : An array containing file or directory names, or
+ // a string containing one filename or one directory name, or
+ // a string containing a list of filenames and/or directory
+ // names separated by spaces.
+ // $p_add_dir : A path to add before the real path of the archived file,
+ // in order to have it memorized in the archive.
+ // $p_remove_dir : A path to remove from the real path of the file to archive,
+ // in order to have a shorter path memorized in the archive.
+ // When $p_add_dir and $p_remove_dir are set, $p_remove_dir
+ // is removed first, before $p_add_dir is added.
+ // Options :
+ // PCLZIP_OPT_ADD_PATH :
+ // PCLZIP_OPT_REMOVE_PATH :
+ // PCLZIP_OPT_REMOVE_ALL_PATH :
+ // PCLZIP_OPT_COMMENT :
+ // PCLZIP_OPT_ADD_COMMENT :
+ // PCLZIP_OPT_PREPEND_COMMENT :
+ // PCLZIP_CB_PRE_ADD :
+ // PCLZIP_CB_POST_ADD :
+ // Return Values :
+ // 0 on failure,
+ // The list of the added files, with a status of the add action.
+ // (see PclZip::listContent() for list entry format)
+ // --------------------------------------------------------------------------------
+ function add($p_filelist)
+ {
+ $v_result=1;
+
+ // ----- Reset the error handler
+ $this->privErrorReset();
+
+ // ----- Set default values
+ $v_options = array();
+ $v_options[PCLZIP_OPT_NO_COMPRESSION] = FALSE;
+
+ // ----- Look for variable options arguments
+ $v_size = func_num_args();
+
+ // ----- Look for arguments
+ if ($v_size > 1) {
+ // ----- Get the arguments
+ $v_arg_list = func_get_args();
+
+ // ----- Remove form the options list the first argument
+ array_shift($v_arg_list);
+ $v_size--;
+
+ // ----- Look for first arg
+ if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
+
+ // ----- Parse the options
+ $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
+ array (PCLZIP_OPT_REMOVE_PATH => 'optional',
+ PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
+ PCLZIP_OPT_ADD_PATH => 'optional',
+ PCLZIP_CB_PRE_ADD => 'optional',
+ PCLZIP_CB_POST_ADD => 'optional',
+ PCLZIP_OPT_NO_COMPRESSION => 'optional',
+ PCLZIP_OPT_COMMENT => 'optional',
+ PCLZIP_OPT_ADD_COMMENT => 'optional',
+ PCLZIP_OPT_PREPEND_COMMENT => 'optional',
+ PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
+ PCLZIP_OPT_TEMP_FILE_ON => 'optional',
+ PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
+ //, PCLZIP_OPT_CRYPT => 'optional'
+ ));
+ if ($v_result != 1) {
+ return 0;
+ }
+ }
+
+ // ----- Look for 2 args
+ // Here we need to support the first historic synopsis of the
+ // method.
+ else {
+
+ // ----- Get the first argument
+ $v_options[PCLZIP_OPT_ADD_PATH] = $v_add_path = $v_arg_list[0];
+
+ // ----- Look for the optional second argument
+ if ($v_size == 2) {
+ $v_options[PCLZIP_OPT_REMOVE_PATH] = $v_arg_list[1];
+ }
+ else if ($v_size > 2) {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
+
+ // ----- Return
+ return 0;
+ }
+ }
+ }
+
+ // ----- Look for default option values
+ $this->privOptionDefaultThreshold($v_options);
+
+ // ----- Init
+ $v_string_list = array();
+ $v_att_list = array();
+ $v_filedescr_list = array();
+ $p_result_list = array();
+
+ // ----- Look if the $p_filelist is really an array
+ if (is_array($p_filelist)) {
+
+ // ----- Look if the first element is also an array
+ // This will mean that this is a file description entry
+ if (isset($p_filelist[0]) && is_array($p_filelist[0])) {
+ $v_att_list = $p_filelist;
+ }
+
+ // ----- The list is a list of string names
+ else {
+ $v_string_list = $p_filelist;
+ }
+ }
+
+ // ----- Look if the $p_filelist is a string
+ else if (is_string($p_filelist)) {
+ // ----- Create a list from the string
+ $v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist);
+ }
+
+ // ----- Invalid variable type for $p_filelist
+ else {
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type '".gettype($p_filelist)."' for p_filelist");
+ return 0;
+ }
+
+ // ----- Reformat the string list
+ if (sizeof($v_string_list) != 0) {
+ foreach ($v_string_list as $v_string) {
+ $v_att_list[][PCLZIP_ATT_FILE_NAME] = $v_string;
+ }
+ }
+
+ // ----- For each file in the list check the attributes
+ $v_supported_attributes
+ = array ( PCLZIP_ATT_FILE_NAME => 'mandatory'
+ ,PCLZIP_ATT_FILE_NEW_SHORT_NAME => 'optional'
+ ,PCLZIP_ATT_FILE_NEW_FULL_NAME => 'optional'
+ ,PCLZIP_ATT_FILE_MTIME => 'optional'
+ ,PCLZIP_ATT_FILE_CONTENT => 'optional'
+ ,PCLZIP_ATT_FILE_COMMENT => 'optional'
+ );
+ foreach ($v_att_list as $v_entry) {
+ $v_result = $this->privFileDescrParseAtt($v_entry,
+ $v_filedescr_list[],
+ $v_options,
+ $v_supported_attributes);
+ if ($v_result != 1) {
+ return 0;
+ }
+ }
+
+ // ----- Expand the filelist (expand directories)
+ $v_result = $this->privFileDescrExpand($v_filedescr_list, $v_options);
+ if ($v_result != 1) {
+ return 0;
+ }
+
+ // ----- Call the create fct
+ $v_result = $this->privAdd($v_filedescr_list, $p_result_list, $v_options);
+ if ($v_result != 1) {
+ return 0;
+ }
+
+ // ----- Return
+ return $p_result_list;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : listContent()
+ // Description :
+ // This public method, gives the list of the files and directories, with their
+ // properties.
+ // The properties of each entries in the list are (used also in other functions) :
+ // filename : Name of the file. For a create or add action it is the filename
+ // given by the user. For an extract function it is the filename
+ // of the extracted file.
+ // stored_filename : Name of the file / directory stored in the archive.
+ // size : Size of the stored file.
+ // compressed_size : Size of the file's data compressed in the archive
+ // (without the headers overhead)
+ // mtime : Last known modification date of the file (UNIX timestamp)
+ // comment : Comment associated with the file
+ // folder : true | false
+ // index : index of the file in the archive
+ // status : status of the action (depending of the action) :
+ // Values are :
+ // ok : OK !
+ // filtered : the file / dir is not extracted (filtered by user)
+ // already_a_directory : the file can not be extracted because a
+ // directory with the same name already exists
+ // write_protected : the file can not be extracted because a file
+ // with the same name already exists and is
+ // write protected
+ // newer_exist : the file was not extracted because a newer file exists
+ // path_creation_fail : the file is not extracted because the folder
+ // does not exist and can not be created
+ // write_error : the file was not extracted because there was a
+ // error while writing the file
+ // read_error : the file was not extracted because there was a error
+ // while reading the file
+ // invalid_header : the file was not extracted because of an archive
+ // format error (bad file header)
+ // Note that each time a method can continue operating when there
+ // is an action error on a file, the error is only logged in the file status.
+ // Return Values :
+ // 0 on an unrecoverable failure,
+ // The list of the files in the archive.
+ // --------------------------------------------------------------------------------
+ function listContent()
+ {
+ $v_result=1;
+
+ // ----- Reset the error handler
+ $this->privErrorReset();
+
+ // ----- Check archive
+ if (!$this->privCheckFormat()) {
+ return(0);
+ }
+
+ // ----- Call the extracting fct
+ $p_list = array();
+ if (($v_result = $this->privList($p_list)) != 1)
+ {
+ unset($p_list);
+ return(0);
+ }
+
+ // ----- Return
+ return $p_list;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function :
+ // extract($p_path="./", $p_remove_path="")
+ // extract([$p_option, $p_option_value, ...])
+ // Description :
+ // This method supports two synopsis. The first one is historical.
+ // This method extract all the files / directories from the archive to the
+ // folder indicated in $p_path.
+ // If you want to ignore the 'root' part of path of the memorized files
+ // you can indicate this in the optional $p_remove_path parameter.
+ // By default, if a newer file with the same name already exists, the
+ // file is not extracted.
+ //
+ // If both PCLZIP_OPT_PATH and PCLZIP_OPT_ADD_PATH aoptions
+ // are used, the path indicated in PCLZIP_OPT_ADD_PATH is append
+ // at the end of the path value of PCLZIP_OPT_PATH.
+ // Parameters :
+ // $p_path : Path where the files and directories are to be extracted
+ // $p_remove_path : First part ('root' part) of the memorized path
+ // (if any similar) to remove while extracting.
+ // Options :
+ // PCLZIP_OPT_PATH :
+ // PCLZIP_OPT_ADD_PATH :
+ // PCLZIP_OPT_REMOVE_PATH :
+ // PCLZIP_OPT_REMOVE_ALL_PATH :
+ // PCLZIP_CB_PRE_EXTRACT :
+ // PCLZIP_CB_POST_EXTRACT :
+ // Return Values :
+ // 0 or a negative value on failure,
+ // The list of the extracted files, with a status of the action.
+ // (see PclZip::listContent() for list entry format)
+ // --------------------------------------------------------------------------------
+ function extract()
+ {
+ $v_result=1;
+
+ // ----- Reset the error handler
+ $this->privErrorReset();
+
+ // ----- Check archive
+ if (!$this->privCheckFormat()) {
+ return(0);
+ }
+
+ // ----- Set default values
+ $v_options = array();
+// $v_path = "./";
+ $v_path = '';
+ $v_remove_path = "";
+ $v_remove_all_path = false;
+
+ // ----- Look for variable options arguments
+ $v_size = func_num_args();
+
+ // ----- Default values for option
+ $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
+
+ // ----- Look for arguments
+ if ($v_size > 0) {
+ // ----- Get the arguments
+ $v_arg_list = func_get_args();
+
+ // ----- Look for first arg
+ if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
+
+ // ----- Parse the options
+ $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
+ array (PCLZIP_OPT_PATH => 'optional',
+ PCLZIP_OPT_REMOVE_PATH => 'optional',
+ PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
+ PCLZIP_OPT_ADD_PATH => 'optional',
+ PCLZIP_CB_PRE_EXTRACT => 'optional',
+ PCLZIP_CB_POST_EXTRACT => 'optional',
+ PCLZIP_OPT_SET_CHMOD => 'optional',
+ PCLZIP_OPT_BY_NAME => 'optional',
+ PCLZIP_OPT_BY_EREG => 'optional',
+ PCLZIP_OPT_BY_PREG => 'optional',
+ PCLZIP_OPT_BY_INDEX => 'optional',
+ PCLZIP_OPT_EXTRACT_AS_STRING => 'optional',
+ PCLZIP_OPT_EXTRACT_IN_OUTPUT => 'optional',
+ PCLZIP_OPT_REPLACE_NEWER => 'optional'
+ ,PCLZIP_OPT_STOP_ON_ERROR => 'optional'
+ ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional',
+ PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
+ PCLZIP_OPT_TEMP_FILE_ON => 'optional',
+ PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
+ ));
+ if ($v_result != 1) {
+ return 0;
+ }
+
+ // ----- Set the arguments
+ if (isset($v_options[PCLZIP_OPT_PATH])) {
+ $v_path = $v_options[PCLZIP_OPT_PATH];
+ }
+ if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {
+ $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH];
+ }
+ if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
+ $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];
+ }
+ if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {
+ // ----- Check for '/' in last path char
+ if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) {
+ $v_path .= '/';
+ }
+ $v_path .= $v_options[PCLZIP_OPT_ADD_PATH];
+ }
+ }
+
+ // ----- Look for 2 args
+ // Here we need to support the first historic synopsis of the
+ // method.
+ else {
+
+ // ----- Get the first argument
+ $v_path = $v_arg_list[0];
+
+ // ----- Look for the optional second argument
+ if ($v_size == 2) {
+ $v_remove_path = $v_arg_list[1];
+ }
+ else if ($v_size > 2) {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
+
+ // ----- Return
+ return 0;
+ }
+ }
+ }
+
+ // ----- Look for default option values
+ $this->privOptionDefaultThreshold($v_options);
+
+ // ----- Trace
+
+ // ----- Call the extracting fct
+ $p_list = array();
+ $v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path,
+ $v_remove_all_path, $v_options);
+ if ($v_result < 1) {
+ unset($p_list);
+ return(0);
+ }
+
+ // ----- Return
+ return $p_list;
+ }
+ // --------------------------------------------------------------------------------
+
+
+ // --------------------------------------------------------------------------------
+ // Function :
+ // extractByIndex($p_index, $p_path="./", $p_remove_path="")
+ // extractByIndex($p_index, [$p_option, $p_option_value, ...])
+ // Description :
+ // This method supports two synopsis. The first one is historical.
+ // This method is doing a partial extract of the archive.
+ // The extracted files or folders are identified by their index in the
+ // archive (from 0 to n).
+ // Note that if the index identify a folder, only the folder entry is
+ // extracted, not all the files included in the archive.
+ // Parameters :
+ // $p_index : A single index (integer) or a string of indexes of files to
+ // extract. The form of the string is "0,4-6,8-12" with only numbers
+ // and '-' for range or ',' to separate ranges. No spaces or ';'
+ // are allowed.
+ // $p_path : Path where the files and directories are to be extracted
+ // $p_remove_path : First part ('root' part) of the memorized path
+ // (if any similar) to remove while extracting.
+ // Options :
+ // PCLZIP_OPT_PATH :
+ // PCLZIP_OPT_ADD_PATH :
+ // PCLZIP_OPT_REMOVE_PATH :
+ // PCLZIP_OPT_REMOVE_ALL_PATH :
+ // PCLZIP_OPT_EXTRACT_AS_STRING : The files are extracted as strings and
+ // not as files.
+ // The resulting content is in a new field 'content' in the file
+ // structure.
+ // This option must be used alone (any other options are ignored).
+ // PCLZIP_CB_PRE_EXTRACT :
+ // PCLZIP_CB_POST_EXTRACT :
+ // Return Values :
+ // 0 on failure,
+ // The list of the extracted files, with a status of the action.
+ // (see PclZip::listContent() for list entry format)
+ // --------------------------------------------------------------------------------
+ //function extractByIndex($p_index, options...)
+ function extractByIndex($p_index)
+ {
+ $v_result=1;
+
+ // ----- Reset the error handler
+ $this->privErrorReset();
+
+ // ----- Check archive
+ if (!$this->privCheckFormat()) {
+ return(0);
+ }
+
+ // ----- Set default values
+ $v_options = array();
+// $v_path = "./";
+ $v_path = '';
+ $v_remove_path = "";
+ $v_remove_all_path = false;
+
+ // ----- Look for variable options arguments
+ $v_size = func_num_args();
+
+ // ----- Default values for option
+ $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
+
+ // ----- Look for arguments
+ if ($v_size > 1) {
+ // ----- Get the arguments
+ $v_arg_list = func_get_args();
+
+ // ----- Remove form the options list the first argument
+ array_shift($v_arg_list);
+ $v_size--;
+
+ // ----- Look for first arg
+ if ((is_integer($v_arg_list[0])) && ($v_arg_list[0] > 77000)) {
+
+ // ----- Parse the options
+ $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
+ array (PCLZIP_OPT_PATH => 'optional',
+ PCLZIP_OPT_REMOVE_PATH => 'optional',
+ PCLZIP_OPT_REMOVE_ALL_PATH => 'optional',
+ PCLZIP_OPT_EXTRACT_AS_STRING => 'optional',
+ PCLZIP_OPT_ADD_PATH => 'optional',
+ PCLZIP_CB_PRE_EXTRACT => 'optional',
+ PCLZIP_CB_POST_EXTRACT => 'optional',
+ PCLZIP_OPT_SET_CHMOD => 'optional',
+ PCLZIP_OPT_REPLACE_NEWER => 'optional'
+ ,PCLZIP_OPT_STOP_ON_ERROR => 'optional'
+ ,PCLZIP_OPT_EXTRACT_DIR_RESTRICTION => 'optional',
+ PCLZIP_OPT_TEMP_FILE_THRESHOLD => 'optional',
+ PCLZIP_OPT_TEMP_FILE_ON => 'optional',
+ PCLZIP_OPT_TEMP_FILE_OFF => 'optional'
+ ));
+ if ($v_result != 1) {
+ return 0;
+ }
+
+ // ----- Set the arguments
+ if (isset($v_options[PCLZIP_OPT_PATH])) {
+ $v_path = $v_options[PCLZIP_OPT_PATH];
+ }
+ if (isset($v_options[PCLZIP_OPT_REMOVE_PATH])) {
+ $v_remove_path = $v_options[PCLZIP_OPT_REMOVE_PATH];
+ }
+ if (isset($v_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
+ $v_remove_all_path = $v_options[PCLZIP_OPT_REMOVE_ALL_PATH];
+ }
+ if (isset($v_options[PCLZIP_OPT_ADD_PATH])) {
+ // ----- Check for '/' in last path char
+ if ((strlen($v_path) > 0) && (substr($v_path, -1) != '/')) {
+ $v_path .= '/';
+ }
+ $v_path .= $v_options[PCLZIP_OPT_ADD_PATH];
+ }
+ if (!isset($v_options[PCLZIP_OPT_EXTRACT_AS_STRING])) {
+ $v_options[PCLZIP_OPT_EXTRACT_AS_STRING] = FALSE;
+ }
+ else {
+ }
+ }
+
+ // ----- Look for 2 args
+ // Here we need to support the first historic synopsis of the
+ // method.
+ else {
+
+ // ----- Get the first argument
+ $v_path = $v_arg_list[0];
+
+ // ----- Look for the optional second argument
+ if ($v_size == 2) {
+ $v_remove_path = $v_arg_list[1];
+ }
+ else if ($v_size > 2) {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid number / type of arguments");
+
+ // ----- Return
+ return 0;
+ }
+ }
+ }
+
+ // ----- Trace
+
+ // ----- Trick
+ // Here I want to reuse extractByRule(), so I need to parse the $p_index
+ // with privParseOptions()
+ $v_arg_trick = array (PCLZIP_OPT_BY_INDEX, $p_index);
+ $v_options_trick = array();
+ $v_result = $this->privParseOptions($v_arg_trick, sizeof($v_arg_trick), $v_options_trick,
+ array (PCLZIP_OPT_BY_INDEX => 'optional' ));
+ if ($v_result != 1) {
+ return 0;
+ }
+ $v_options[PCLZIP_OPT_BY_INDEX] = $v_options_trick[PCLZIP_OPT_BY_INDEX];
+
+ // ----- Look for default option values
+ $this->privOptionDefaultThreshold($v_options);
+
+ // ----- Call the extracting fct
+ if (($v_result = $this->privExtractByRule($p_list, $v_path, $v_remove_path, $v_remove_all_path, $v_options)) < 1) {
+ return(0);
+ }
+
+ // ----- Return
+ return $p_list;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function :
+ // delete([$p_option, $p_option_value, ...])
+ // Description :
+ // This method removes files from the archive.
+ // If no parameters are given, then all the archive is emptied.
+ // Parameters :
+ // None or optional arguments.
+ // Options :
+ // PCLZIP_OPT_BY_INDEX :
+ // PCLZIP_OPT_BY_NAME :
+ // PCLZIP_OPT_BY_EREG :
+ // PCLZIP_OPT_BY_PREG :
+ // Return Values :
+ // 0 on failure,
+ // The list of the files which are still present in the archive.
+ // (see PclZip::listContent() for list entry format)
+ // --------------------------------------------------------------------------------
+ function delete()
+ {
+ $v_result=1;
+
+ // ----- Reset the error handler
+ $this->privErrorReset();
+
+ // ----- Check archive
+ if (!$this->privCheckFormat()) {
+ return(0);
+ }
+
+ // ----- Set default values
+ $v_options = array();
+
+ // ----- Look for variable options arguments
+ $v_size = func_num_args();
+
+ // ----- Look for arguments
+ if ($v_size > 0) {
+ // ----- Get the arguments
+ $v_arg_list = func_get_args();
+
+ // ----- Parse the options
+ $v_result = $this->privParseOptions($v_arg_list, $v_size, $v_options,
+ array (PCLZIP_OPT_BY_NAME => 'optional',
+ PCLZIP_OPT_BY_EREG => 'optional',
+ PCLZIP_OPT_BY_PREG => 'optional',
+ PCLZIP_OPT_BY_INDEX => 'optional' ));
+ if ($v_result != 1) {
+ return 0;
+ }
+ }
+
+ // ----- Magic quotes trick
+ $this->privDisableMagicQuotes();
+
+ // ----- Call the delete fct
+ $v_list = array();
+ if (($v_result = $this->privDeleteByRule($v_list, $v_options)) != 1) {
+ $this->privSwapBackMagicQuotes();
+ unset($v_list);
+ return(0);
+ }
+
+ // ----- Magic quotes trick
+ $this->privSwapBackMagicQuotes();
+
+ // ----- Return
+ return $v_list;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : deleteByIndex()
+ // Description :
+ // ***** Deprecated *****
+ // delete(PCLZIP_OPT_BY_INDEX, $p_index) should be prefered.
+ // --------------------------------------------------------------------------------
+ function deleteByIndex($p_index)
+ {
+
+ $p_list = $this->delete(PCLZIP_OPT_BY_INDEX, $p_index);
+
+ // ----- Return
+ return $p_list;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : properties()
+ // Description :
+ // This method gives the properties of the archive.
+ // The properties are :
+ // nb : Number of files in the archive
+ // comment : Comment associated with the archive file
+ // status : not_exist, ok
+ // Parameters :
+ // None
+ // Return Values :
+ // 0 on failure,
+ // An array with the archive properties.
+ // --------------------------------------------------------------------------------
+ function properties()
+ {
+
+ // ----- Reset the error handler
+ $this->privErrorReset();
+
+ // ----- Magic quotes trick
+ $this->privDisableMagicQuotes();
+
+ // ----- Check archive
+ if (!$this->privCheckFormat()) {
+ $this->privSwapBackMagicQuotes();
+ return(0);
+ }
+
+ // ----- Default properties
+ $v_prop = array();
+ $v_prop['comment'] = '';
+ $v_prop['nb'] = 0;
+ $v_prop['status'] = 'not_exist';
+
+ // ----- Look if file exists
+ if (@is_file($this->zipname))
+ {
+ // ----- Open the zip file
+ if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0)
+ {
+ $this->privSwapBackMagicQuotes();
+
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode');
+
+ // ----- Return
+ return 0;
+ }
+
+ // ----- Read the central directory informations
+ $v_central_dir = array();
+ if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
+ {
+ $this->privSwapBackMagicQuotes();
+ return 0;
+ }
+
+ // ----- Close the zip file
+ $this->privCloseFd();
+
+ // ----- Set the user attributes
+ $v_prop['comment'] = $v_central_dir['comment'];
+ $v_prop['nb'] = $v_central_dir['entries'];
+ $v_prop['status'] = 'ok';
+ }
+
+ // ----- Magic quotes trick
+ $this->privSwapBackMagicQuotes();
+
+ // ----- Return
+ return $v_prop;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : duplicate()
+ // Description :
+ // This method creates an archive by copying the content of an other one. If
+ // the archive already exist, it is replaced by the new one without any warning.
+ // Parameters :
+ // $p_archive : The filename of a valid archive, or
+ // a valid PclZip object.
+ // Return Values :
+ // 1 on success.
+ // 0 or a negative value on error (error code).
+ // --------------------------------------------------------------------------------
+ function duplicate($p_archive)
+ {
+ $v_result = 1;
+
+ // ----- Reset the error handler
+ $this->privErrorReset();
+
+ // ----- Look if the $p_archive is a PclZip object
+ if ((is_object($p_archive)) && (get_class($p_archive) == 'pclzip'))
+ {
+
+ // ----- Duplicate the archive
+ $v_result = $this->privDuplicate($p_archive->zipname);
+ }
+
+ // ----- Look if the $p_archive is a string (so a filename)
+ else if (is_string($p_archive))
+ {
+
+ // ----- Check that $p_archive is a valid zip file
+ // TBC : Should also check the archive format
+ if (!is_file($p_archive)) {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "No file with filename '".$p_archive."'");
+ $v_result = PCLZIP_ERR_MISSING_FILE;
+ }
+ else {
+ // ----- Duplicate the archive
+ $v_result = $this->privDuplicate($p_archive);
+ }
+ }
+
+ // ----- Invalid variable
+ else
+ {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add");
+ $v_result = PCLZIP_ERR_INVALID_PARAMETER;
+ }
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : merge()
+ // Description :
+ // This method merge the $p_archive_to_add archive at the end of the current
+ // one ($this).
+ // If the archive ($this) does not exist, the merge becomes a duplicate.
+ // If the $p_archive_to_add archive does not exist, the merge is a success.
+ // Parameters :
+ // $p_archive_to_add : It can be directly the filename of a valid zip archive,
+ // or a PclZip object archive.
+ // Return Values :
+ // 1 on success,
+ // 0 or negative values on error (see below).
+ // --------------------------------------------------------------------------------
+ function merge($p_archive_to_add)
+ {
+ $v_result = 1;
+
+ // ----- Reset the error handler
+ $this->privErrorReset();
+
+ // ----- Check archive
+ if (!$this->privCheckFormat()) {
+ return(0);
+ }
+
+ // ----- Look if the $p_archive_to_add is a PclZip object
+ if ((is_object($p_archive_to_add)) && (get_class($p_archive_to_add) == 'pclzip'))
+ {
+
+ // ----- Merge the archive
+ $v_result = $this->privMerge($p_archive_to_add);
+ }
+
+ // ----- Look if the $p_archive_to_add is a string (so a filename)
+ else if (is_string($p_archive_to_add))
+ {
+
+ // ----- Create a temporary archive
+ $v_object_archive = new PclZip($p_archive_to_add);
+
+ // ----- Merge the archive
+ $v_result = $this->privMerge($v_object_archive);
+ }
+
+ // ----- Invalid variable
+ else
+ {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_archive_to_add");
+ $v_result = PCLZIP_ERR_INVALID_PARAMETER;
+ }
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+
+
+ // --------------------------------------------------------------------------------
+ // Function : errorCode()
+ // Description :
+ // Parameters :
+ // --------------------------------------------------------------------------------
+ function errorCode()
+ {
+ if (PCLZIP_ERROR_EXTERNAL == 1) {
+ return(PclErrorCode());
+ }
+ else {
+ return($this->error_code);
+ }
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : errorName()
+ // Description :
+ // Parameters :
+ // --------------------------------------------------------------------------------
+ function errorName($p_with_code=false)
+ {
+ $v_name = array ( PCLZIP_ERR_NO_ERROR => 'PCLZIP_ERR_NO_ERROR',
+ PCLZIP_ERR_WRITE_OPEN_FAIL => 'PCLZIP_ERR_WRITE_OPEN_FAIL',
+ PCLZIP_ERR_READ_OPEN_FAIL => 'PCLZIP_ERR_READ_OPEN_FAIL',
+ PCLZIP_ERR_INVALID_PARAMETER => 'PCLZIP_ERR_INVALID_PARAMETER',
+ PCLZIP_ERR_MISSING_FILE => 'PCLZIP_ERR_MISSING_FILE',
+ PCLZIP_ERR_FILENAME_TOO_LONG => 'PCLZIP_ERR_FILENAME_TOO_LONG',
+ PCLZIP_ERR_INVALID_ZIP => 'PCLZIP_ERR_INVALID_ZIP',
+ PCLZIP_ERR_BAD_EXTRACTED_FILE => 'PCLZIP_ERR_BAD_EXTRACTED_FILE',
+ PCLZIP_ERR_DIR_CREATE_FAIL => 'PCLZIP_ERR_DIR_CREATE_FAIL',
+ PCLZIP_ERR_BAD_EXTENSION => 'PCLZIP_ERR_BAD_EXTENSION',
+ PCLZIP_ERR_BAD_FORMAT => 'PCLZIP_ERR_BAD_FORMAT',
+ PCLZIP_ERR_DELETE_FILE_FAIL => 'PCLZIP_ERR_DELETE_FILE_FAIL',
+ PCLZIP_ERR_RENAME_FILE_FAIL => 'PCLZIP_ERR_RENAME_FILE_FAIL',
+ PCLZIP_ERR_BAD_CHECKSUM => 'PCLZIP_ERR_BAD_CHECKSUM',
+ PCLZIP_ERR_INVALID_ARCHIVE_ZIP => 'PCLZIP_ERR_INVALID_ARCHIVE_ZIP',
+ PCLZIP_ERR_MISSING_OPTION_VALUE => 'PCLZIP_ERR_MISSING_OPTION_VALUE',
+ PCLZIP_ERR_INVALID_OPTION_VALUE => 'PCLZIP_ERR_INVALID_OPTION_VALUE',
+ PCLZIP_ERR_UNSUPPORTED_COMPRESSION => 'PCLZIP_ERR_UNSUPPORTED_COMPRESSION',
+ PCLZIP_ERR_UNSUPPORTED_ENCRYPTION => 'PCLZIP_ERR_UNSUPPORTED_ENCRYPTION'
+ ,PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE => 'PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE'
+ ,PCLZIP_ERR_DIRECTORY_RESTRICTION => 'PCLZIP_ERR_DIRECTORY_RESTRICTION'
+ );
+
+ if (isset($v_name[$this->error_code])) {
+ $v_value = $v_name[$this->error_code];
+ }
+ else {
+ $v_value = 'NoName';
+ }
+
+ if ($p_with_code) {
+ return($v_value.' ('.$this->error_code.')');
+ }
+ else {
+ return($v_value);
+ }
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : errorInfo()
+ // Description :
+ // Parameters :
+ // --------------------------------------------------------------------------------
+ function errorInfo($p_full=false)
+ {
+ if (PCLZIP_ERROR_EXTERNAL == 1) {
+ return(PclErrorString());
+ }
+ else {
+ if ($p_full) {
+ return($this->errorName(true)." : ".$this->error_string);
+ }
+ else {
+ return($this->error_string." [code ".$this->error_code."]");
+ }
+ }
+ }
+ // --------------------------------------------------------------------------------
+
+
+// --------------------------------------------------------------------------------
+// ***** UNDER THIS LINE ARE DEFINED PRIVATE INTERNAL FUNCTIONS *****
+// ***** *****
+// ***** THESES FUNCTIONS MUST NOT BE USED DIRECTLY *****
+// --------------------------------------------------------------------------------
+
+
+
+ // --------------------------------------------------------------------------------
+ // Function : privCheckFormat()
+ // Description :
+ // This method check that the archive exists and is a valid zip archive.
+ // Several level of check exists. (futur)
+ // Parameters :
+ // $p_level : Level of check. Default 0.
+ // 0 : Check the first bytes (magic codes) (default value))
+ // 1 : 0 + Check the central directory (futur)
+ // 2 : 1 + Check each file header (futur)
+ // Return Values :
+ // true on success,
+ // false on error, the error code is set.
+ // --------------------------------------------------------------------------------
+ function privCheckFormat($p_level=0)
+ {
+ $v_result = true;
+
+ // ----- Reset the file system cache
+ clearstatcache();
+
+ // ----- Reset the error handler
+ $this->privErrorReset();
+
+ // ----- Look if the file exits
+ if (!is_file($this->zipname)) {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_MISSING_FILE, "Missing archive file '".$this->zipname."'");
+ return(false);
+ }
+
+ // ----- Check that the file is readeable
+ if (!is_readable($this->zipname)) {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to read archive '".$this->zipname."'");
+ return(false);
+ }
+
+ // ----- Check the magic code
+ // TBC
+
+ // ----- Check the central header
+ // TBC
+
+ // ----- Check each file header
+ // TBC
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privParseOptions()
+ // Description :
+ // This internal methods reads the variable list of arguments ($p_options_list,
+ // $p_size) and generate an array with the options and values ($v_result_list).
+ // $v_requested_options contains the options that can be present and those that
+ // must be present.
+ // $v_requested_options is an array, with the option value as key, and 'optional',
+ // or 'mandatory' as value.
+ // Parameters :
+ // See above.
+ // Return Values :
+ // 1 on success.
+ // 0 on failure.
+ // --------------------------------------------------------------------------------
+ function privParseOptions(&$p_options_list, $p_size, &$v_result_list, $v_requested_options=false)
+ {
+ $v_result=1;
+
+ // ----- Read the options
+ $i=0;
+ while ($i<$p_size) {
+
+ // ----- Check if the option is supported
+ if (!isset($v_requested_options[$p_options_list[$i]])) {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid optional parameter '".$p_options_list[$i]."' for this method");
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Look for next option
+ switch ($p_options_list[$i]) {
+ // ----- Look for options that request a path value
+ case PCLZIP_OPT_PATH :
+ case PCLZIP_OPT_REMOVE_PATH :
+ case PCLZIP_OPT_ADD_PATH :
+ // ----- Check the number of parameters
+ if (($i+1) >= $p_size) {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Get the value
+ $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE);
+ $i++;
+ break;
+
+ case PCLZIP_OPT_TEMP_FILE_THRESHOLD :
+ // ----- Check the number of parameters
+ if (($i+1) >= $p_size) {
+ PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
+ return PclZip::errorCode();
+ }
+
+ // ----- Check for incompatible options
+ if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_OFF])) {
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_OFF'");
+ return PclZip::errorCode();
+ }
+
+ // ----- Check the value
+ $v_value = $p_options_list[$i+1];
+ if ((!is_integer($v_value)) || ($v_value<0)) {
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Integer expected for option '".PclZipUtilOptionText($p_options_list[$i])."'");
+ return PclZip::errorCode();
+ }
+
+ // ----- Get the value (and convert it in bytes)
+ $v_result_list[$p_options_list[$i]] = $v_value*1048576;
+ $i++;
+ break;
+
+ case PCLZIP_OPT_TEMP_FILE_ON :
+ // ----- Check for incompatible options
+ if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_OFF])) {
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_OFF'");
+ return PclZip::errorCode();
+ }
+
+ $v_result_list[$p_options_list[$i]] = true;
+ break;
+
+ case PCLZIP_OPT_TEMP_FILE_OFF :
+ // ----- Check for incompatible options
+ if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_ON])) {
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_ON'");
+ return PclZip::errorCode();
+ }
+ // ----- Check for incompatible options
+ if (isset($v_result_list[PCLZIP_OPT_TEMP_FILE_THRESHOLD])) {
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Option '".PclZipUtilOptionText($p_options_list[$i])."' can not be used with option 'PCLZIP_OPT_TEMP_FILE_THRESHOLD'");
+ return PclZip::errorCode();
+ }
+
+ $v_result_list[$p_options_list[$i]] = true;
+ break;
+
+ case PCLZIP_OPT_EXTRACT_DIR_RESTRICTION :
+ // ----- Check the number of parameters
+ if (($i+1) >= $p_size) {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Get the value
+ if ( is_string($p_options_list[$i+1])
+ && ($p_options_list[$i+1] != '')) {
+ $v_result_list[$p_options_list[$i]] = PclZipUtilTranslateWinPath($p_options_list[$i+1], FALSE);
+ $i++;
+ }
+ else {
+ }
+ break;
+
+ // ----- Look for options that request an array of string for value
+ case PCLZIP_OPT_BY_NAME :
+ // ----- Check the number of parameters
+ if (($i+1) >= $p_size) {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Get the value
+ if (is_string($p_options_list[$i+1])) {
+ $v_result_list[$p_options_list[$i]][0] = $p_options_list[$i+1];
+ }
+ else if (is_array($p_options_list[$i+1])) {
+ $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
+ }
+ else {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+ $i++;
+ break;
+
+ // ----- Look for options that request an EREG or PREG expression
+ case PCLZIP_OPT_BY_EREG :
+ // ereg() is deprecated starting with PHP 5.3. Move PCLZIP_OPT_BY_EREG
+ // to PCLZIP_OPT_BY_PREG
+ $p_options_list[$i] = PCLZIP_OPT_BY_PREG;
+ case PCLZIP_OPT_BY_PREG :
+ //case PCLZIP_OPT_CRYPT :
+ // ----- Check the number of parameters
+ if (($i+1) >= $p_size) {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Get the value
+ if (is_string($p_options_list[$i+1])) {
+ $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
+ }
+ else {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Wrong parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+ $i++;
+ break;
+
+ // ----- Look for options that takes a string
+ case PCLZIP_OPT_COMMENT :
+ case PCLZIP_OPT_ADD_COMMENT :
+ case PCLZIP_OPT_PREPEND_COMMENT :
+ // ----- Check the number of parameters
+ if (($i+1) >= $p_size) {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE,
+ "Missing parameter value for option '"
+ .PclZipUtilOptionText($p_options_list[$i])
+ ."'");
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Get the value
+ if (is_string($p_options_list[$i+1])) {
+ $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
+ }
+ else {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE,
+ "Wrong parameter value for option '"
+ .PclZipUtilOptionText($p_options_list[$i])
+ ."'");
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+ $i++;
+ break;
+
+ // ----- Look for options that request an array of index
+ case PCLZIP_OPT_BY_INDEX :
+ // ----- Check the number of parameters
+ if (($i+1) >= $p_size) {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Get the value
+ $v_work_list = array();
+ if (is_string($p_options_list[$i+1])) {
+
+ // ----- Remove spaces
+ $p_options_list[$i+1] = strtr($p_options_list[$i+1], ' ', '');
+
+ // ----- Parse items
+ $v_work_list = explode(",", $p_options_list[$i+1]);
+ }
+ else if (is_integer($p_options_list[$i+1])) {
+ $v_work_list[0] = $p_options_list[$i+1].'-'.$p_options_list[$i+1];
+ }
+ else if (is_array($p_options_list[$i+1])) {
+ $v_work_list = $p_options_list[$i+1];
+ }
+ else {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Value must be integer, string or array for option '".PclZipUtilOptionText($p_options_list[$i])."'");
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Reduce the index list
+ // each index item in the list must be a couple with a start and
+ // an end value : [0,3], [5-5], [8-10], ...
+ // ----- Check the format of each item
+ $v_sort_flag=false;
+ $v_sort_value=0;
+ for ($j=0; $j= $p_size) {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Get the value
+ $v_result_list[$p_options_list[$i]] = $p_options_list[$i+1];
+ $i++;
+ break;
+
+ // ----- Look for options that request a call-back
+ case PCLZIP_CB_PRE_EXTRACT :
+ case PCLZIP_CB_POST_EXTRACT :
+ case PCLZIP_CB_PRE_ADD :
+ case PCLZIP_CB_POST_ADD :
+ /* for futur use
+ case PCLZIP_CB_PRE_DELETE :
+ case PCLZIP_CB_POST_DELETE :
+ case PCLZIP_CB_PRE_LIST :
+ case PCLZIP_CB_POST_LIST :
+ */
+ // ----- Check the number of parameters
+ if (($i+1) >= $p_size) {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_MISSING_OPTION_VALUE, "Missing parameter value for option '".PclZipUtilOptionText($p_options_list[$i])."'");
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Get the value
+ $v_function_name = $p_options_list[$i+1];
+
+ // ----- Check that the value is a valid existing function
+ if (!function_exists($v_function_name)) {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_OPTION_VALUE, "Function '".$v_function_name."()' is not an existing function for option '".PclZipUtilOptionText($p_options_list[$i])."'");
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Set the attribute
+ $v_result_list[$p_options_list[$i]] = $v_function_name;
+ $i++;
+ break;
+
+ default :
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,
+ "Unknown parameter '"
+ .$p_options_list[$i]."'");
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Next options
+ $i++;
+ }
+
+ // ----- Look for mandatory options
+ if ($v_requested_options !== false) {
+ for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) {
+ // ----- Look for mandatory option
+ if ($v_requested_options[$key] == 'mandatory') {
+ // ----- Look if present
+ if (!isset($v_result_list[$key])) {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")");
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+ }
+ }
+ }
+
+ // ----- Look for default values
+ if (!isset($v_result_list[PCLZIP_OPT_TEMP_FILE_THRESHOLD])) {
+
+ }
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privOptionDefaultThreshold()
+ // Description :
+ // Parameters :
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function privOptionDefaultThreshold(&$p_options)
+ {
+ $v_result=1;
+
+ if (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD])
+ || isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF])) {
+ return $v_result;
+ }
+
+ // ----- Get 'memory_limit' configuration value
+ $v_memory_limit = ini_get('memory_limit');
+ $v_memory_limit = trim($v_memory_limit);
+ $last = strtolower(substr($v_memory_limit, -1));
+
+ if($last == 'g')
+ //$v_memory_limit = $v_memory_limit*1024*1024*1024;
+ $v_memory_limit = $v_memory_limit*1073741824;
+ if($last == 'm')
+ //$v_memory_limit = $v_memory_limit*1024*1024;
+ $v_memory_limit = $v_memory_limit*1048576;
+ if($last == 'k')
+ $v_memory_limit = $v_memory_limit*1024;
+
+ $p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] = floor($v_memory_limit*PCLZIP_TEMPORARY_FILE_RATIO);
+
+
+ // ----- Sanity check : No threshold if value lower than 1M
+ if ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] < 1048576) {
+ unset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD]);
+ }
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privFileDescrParseAtt()
+ // Description :
+ // Parameters :
+ // Return Values :
+ // 1 on success.
+ // 0 on failure.
+ // --------------------------------------------------------------------------------
+ function privFileDescrParseAtt(&$p_file_list, &$p_filedescr, $v_options, $v_requested_options=false)
+ {
+ $v_result=1;
+
+ // ----- For each file in the list check the attributes
+ foreach ($p_file_list as $v_key => $v_value) {
+
+ // ----- Check if the option is supported
+ if (!isset($v_requested_options[$v_key])) {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file attribute '".$v_key."' for this file");
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Look for attribute
+ switch ($v_key) {
+ case PCLZIP_ATT_FILE_NAME :
+ if (!is_string($v_value)) {
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
+ return PclZip::errorCode();
+ }
+
+ $p_filedescr['filename'] = PclZipUtilPathReduction($v_value);
+
+ if ($p_filedescr['filename'] == '') {
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty filename for attribute '".PclZipUtilOptionText($v_key)."'");
+ return PclZip::errorCode();
+ }
+
+ break;
+
+ case PCLZIP_ATT_FILE_NEW_SHORT_NAME :
+ if (!is_string($v_value)) {
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
+ return PclZip::errorCode();
+ }
+
+ $p_filedescr['new_short_name'] = PclZipUtilPathReduction($v_value);
+
+ if ($p_filedescr['new_short_name'] == '') {
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty short filename for attribute '".PclZipUtilOptionText($v_key)."'");
+ return PclZip::errorCode();
+ }
+ break;
+
+ case PCLZIP_ATT_FILE_NEW_FULL_NAME :
+ if (!is_string($v_value)) {
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
+ return PclZip::errorCode();
+ }
+
+ $p_filedescr['new_full_name'] = PclZipUtilPathReduction($v_value);
+
+ if ($p_filedescr['new_full_name'] == '') {
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid empty full filename for attribute '".PclZipUtilOptionText($v_key)."'");
+ return PclZip::errorCode();
+ }
+ break;
+
+ // ----- Look for options that takes a string
+ case PCLZIP_ATT_FILE_COMMENT :
+ if (!is_string($v_value)) {
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". String expected for attribute '".PclZipUtilOptionText($v_key)."'");
+ return PclZip::errorCode();
+ }
+
+ $p_filedescr['comment'] = $v_value;
+ break;
+
+ case PCLZIP_ATT_FILE_MTIME :
+ if (!is_integer($v_value)) {
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE, "Invalid type ".gettype($v_value).". Integer expected for attribute '".PclZipUtilOptionText($v_key)."'");
+ return PclZip::errorCode();
+ }
+
+ $p_filedescr['mtime'] = $v_value;
+ break;
+
+ case PCLZIP_ATT_FILE_CONTENT :
+ $p_filedescr['content'] = $v_value;
+ break;
+
+ default :
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER,
+ "Unknown parameter '".$v_key."'");
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Look for mandatory options
+ if ($v_requested_options !== false) {
+ for ($key=reset($v_requested_options); $key=key($v_requested_options); $key=next($v_requested_options)) {
+ // ----- Look for mandatory option
+ if ($v_requested_options[$key] == 'mandatory') {
+ // ----- Look if present
+ if (!isset($p_file_list[$key])) {
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Missing mandatory parameter ".PclZipUtilOptionText($key)."(".$key.")");
+ return PclZip::errorCode();
+ }
+ }
+ }
+ }
+
+ // end foreach
+ }
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privFileDescrExpand()
+ // Description :
+ // This method look for each item of the list to see if its a file, a folder
+ // or a string to be added as file. For any other type of files (link, other)
+ // just ignore the item.
+ // Then prepare the information that will be stored for that file.
+ // When its a folder, expand the folder with all the files that are in that
+ // folder (recursively).
+ // Parameters :
+ // Return Values :
+ // 1 on success.
+ // 0 on failure.
+ // --------------------------------------------------------------------------------
+ function privFileDescrExpand(&$p_filedescr_list, &$p_options)
+ {
+ $v_result=1;
+
+ // ----- Create a result list
+ $v_result_list = array();
+
+ // ----- Look each entry
+ for ($i=0; $iprivCalculateStoredFilename($v_descr, $p_options);
+
+ // ----- Add the descriptor in result list
+ $v_result_list[sizeof($v_result_list)] = $v_descr;
+
+ // ----- Look for folder
+ if ($v_descr['type'] == 'folder') {
+ // ----- List of items in folder
+ $v_dirlist_descr = array();
+ $v_dirlist_nb = 0;
+ if ($v_folder_handler = @opendir($v_descr['filename'])) {
+ while (($v_item_handler = @readdir($v_folder_handler)) !== false) {
+
+ // ----- Skip '.' and '..'
+ if (($v_item_handler == '.') || ($v_item_handler == '..')) {
+ continue;
+ }
+
+ // ----- Compose the full filename
+ $v_dirlist_descr[$v_dirlist_nb]['filename'] = $v_descr['filename'].'/'.$v_item_handler;
+
+ // ----- Look for different stored filename
+ // Because the name of the folder was changed, the name of the
+ // files/sub-folders also change
+ if (($v_descr['stored_filename'] != $v_descr['filename'])
+ && (!isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH]))) {
+ if ($v_descr['stored_filename'] != '') {
+ $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_descr['stored_filename'].'/'.$v_item_handler;
+ }
+ else {
+ $v_dirlist_descr[$v_dirlist_nb]['new_full_name'] = $v_item_handler;
+ }
+ }
+
+ $v_dirlist_nb++;
+ }
+
+ @closedir($v_folder_handler);
+ }
+ else {
+ // TBC : unable to open folder in read mode
+ }
+
+ // ----- Expand each element of the list
+ if ($v_dirlist_nb != 0) {
+ // ----- Expand
+ if (($v_result = $this->privFileDescrExpand($v_dirlist_descr, $p_options)) != 1) {
+ return $v_result;
+ }
+
+ // ----- Concat the resulting list
+ $v_result_list = array_merge($v_result_list, $v_dirlist_descr);
+ }
+ else {
+ }
+
+ // ----- Free local array
+ unset($v_dirlist_descr);
+ }
+ }
+
+ // ----- Get the result list
+ $p_filedescr_list = $v_result_list;
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privCreate()
+ // Description :
+ // Parameters :
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function privCreate($p_filedescr_list, &$p_result_list, &$p_options)
+ {
+ $v_result=1;
+ $v_list_detail = array();
+
+ // ----- Magic quotes trick
+ $this->privDisableMagicQuotes();
+
+ // ----- Open the file in write mode
+ if (($v_result = $this->privOpenFd('wb')) != 1)
+ {
+ // ----- Return
+ return $v_result;
+ }
+
+ // ----- Add the list of files
+ $v_result = $this->privAddList($p_filedescr_list, $p_result_list, $p_options);
+
+ // ----- Close
+ $this->privCloseFd();
+
+ // ----- Magic quotes trick
+ $this->privSwapBackMagicQuotes();
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privAdd()
+ // Description :
+ // Parameters :
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function privAdd($p_filedescr_list, &$p_result_list, &$p_options)
+ {
+ $v_result=1;
+ $v_list_detail = array();
+
+ // ----- Look if the archive exists or is empty
+ if ((!is_file($this->zipname)) || (filesize($this->zipname) == 0))
+ {
+
+ // ----- Do a create
+ $v_result = $this->privCreate($p_filedescr_list, $p_result_list, $p_options);
+
+ // ----- Return
+ return $v_result;
+ }
+ // ----- Magic quotes trick
+ $this->privDisableMagicQuotes();
+
+ // ----- Open the zip file
+ if (($v_result=$this->privOpenFd('rb')) != 1)
+ {
+ // ----- Magic quotes trick
+ $this->privSwapBackMagicQuotes();
+
+ // ----- Return
+ return $v_result;
+ }
+
+ // ----- Read the central directory informations
+ $v_central_dir = array();
+ if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
+ {
+ $this->privCloseFd();
+ $this->privSwapBackMagicQuotes();
+ return $v_result;
+ }
+
+ // ----- Go to beginning of File
+ @rewind($this->zip_fd);
+
+ // ----- Creates a temporay file
+ $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
+
+ // ----- Open the temporary file in write mode
+ if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0)
+ {
+ $this->privCloseFd();
+ $this->privSwapBackMagicQuotes();
+
+ PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode');
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Copy the files from the archive to the temporary file
+ // TBC : Here I should better append the file and go back to erase the central dir
+ $v_size = $v_central_dir['offset'];
+ while ($v_size != 0)
+ {
+ $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
+ $v_buffer = fread($this->zip_fd, $v_read_size);
+ @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
+ $v_size -= $v_read_size;
+ }
+
+ // ----- Swap the file descriptor
+ // Here is a trick : I swap the temporary fd with the zip fd, in order to use
+ // the following methods on the temporary fil and not the real archive
+ $v_swap = $this->zip_fd;
+ $this->zip_fd = $v_zip_temp_fd;
+ $v_zip_temp_fd = $v_swap;
+
+ // ----- Add the files
+ $v_header_list = array();
+ if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1)
+ {
+ fclose($v_zip_temp_fd);
+ $this->privCloseFd();
+ @unlink($v_zip_temp_name);
+ $this->privSwapBackMagicQuotes();
+
+ // ----- Return
+ return $v_result;
+ }
+
+ // ----- Store the offset of the central dir
+ $v_offset = @ftell($this->zip_fd);
+
+ // ----- Copy the block of file headers from the old archive
+ $v_size = $v_central_dir['size'];
+ while ($v_size != 0)
+ {
+ $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
+ $v_buffer = @fread($v_zip_temp_fd, $v_read_size);
+ @fwrite($this->zip_fd, $v_buffer, $v_read_size);
+ $v_size -= $v_read_size;
+ }
+
+ // ----- Create the Central Dir files header
+ for ($i=0, $v_count=0; $iprivWriteCentralFileHeader($v_header_list[$i])) != 1) {
+ fclose($v_zip_temp_fd);
+ $this->privCloseFd();
+ @unlink($v_zip_temp_name);
+ $this->privSwapBackMagicQuotes();
+
+ // ----- Return
+ return $v_result;
+ }
+ $v_count++;
+ }
+
+ // ----- Transform the header to a 'usable' info
+ $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
+ }
+
+ // ----- Zip file comment
+ $v_comment = $v_central_dir['comment'];
+ if (isset($p_options[PCLZIP_OPT_COMMENT])) {
+ $v_comment = $p_options[PCLZIP_OPT_COMMENT];
+ }
+ if (isset($p_options[PCLZIP_OPT_ADD_COMMENT])) {
+ $v_comment = $v_comment.$p_options[PCLZIP_OPT_ADD_COMMENT];
+ }
+ if (isset($p_options[PCLZIP_OPT_PREPEND_COMMENT])) {
+ $v_comment = $p_options[PCLZIP_OPT_PREPEND_COMMENT].$v_comment;
+ }
+
+ // ----- Calculate the size of the central header
+ $v_size = @ftell($this->zip_fd)-$v_offset;
+
+ // ----- Create the central dir footer
+ if (($v_result = $this->privWriteCentralHeader($v_count+$v_central_dir['entries'], $v_size, $v_offset, $v_comment)) != 1)
+ {
+ // ----- Reset the file list
+ unset($v_header_list);
+ $this->privSwapBackMagicQuotes();
+
+ // ----- Return
+ return $v_result;
+ }
+
+ // ----- Swap back the file descriptor
+ $v_swap = $this->zip_fd;
+ $this->zip_fd = $v_zip_temp_fd;
+ $v_zip_temp_fd = $v_swap;
+
+ // ----- Close
+ $this->privCloseFd();
+
+ // ----- Close the temporary file
+ @fclose($v_zip_temp_fd);
+
+ // ----- Magic quotes trick
+ $this->privSwapBackMagicQuotes();
+
+ // ----- Delete the zip file
+ // TBC : I should test the result ...
+ @unlink($this->zipname);
+
+ // ----- Rename the temporary file
+ // TBC : I should test the result ...
+ //@rename($v_zip_temp_name, $this->zipname);
+ PclZipUtilRename($v_zip_temp_name, $this->zipname);
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privOpenFd()
+ // Description :
+ // Parameters :
+ // --------------------------------------------------------------------------------
+ function privOpenFd($p_mode)
+ {
+ $v_result=1;
+
+ // ----- Look if already open
+ if ($this->zip_fd != 0)
+ {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Zip file \''.$this->zipname.'\' already open');
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Open the zip file
+ if (($this->zip_fd = @fopen($this->zipname, $p_mode)) == 0)
+ {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in '.$p_mode.' mode');
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privCloseFd()
+ // Description :
+ // Parameters :
+ // --------------------------------------------------------------------------------
+ function privCloseFd()
+ {
+ $v_result=1;
+
+ if ($this->zip_fd != 0)
+ @fclose($this->zip_fd);
+ $this->zip_fd = 0;
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privAddList()
+ // Description :
+ // $p_add_dir and $p_remove_dir will give the ability to memorize a path which is
+ // different from the real path of the file. This is usefull if you want to have PclTar
+ // running in any directory, and memorize relative path from an other directory.
+ // Parameters :
+ // $p_list : An array containing the file or directory names to add in the tar
+ // $p_result_list : list of added files with their properties (specially the status field)
+ // $p_add_dir : Path to add in the filename path archived
+ // $p_remove_dir : Path to remove in the filename path archived
+ // Return Values :
+ // --------------------------------------------------------------------------------
+// function privAddList($p_list, &$p_result_list, $p_add_dir, $p_remove_dir, $p_remove_all_dir, &$p_options)
+ function privAddList($p_filedescr_list, &$p_result_list, &$p_options)
+ {
+ $v_result=1;
+
+ // ----- Add the files
+ $v_header_list = array();
+ if (($v_result = $this->privAddFileList($p_filedescr_list, $v_header_list, $p_options)) != 1)
+ {
+ // ----- Return
+ return $v_result;
+ }
+
+ // ----- Store the offset of the central dir
+ $v_offset = @ftell($this->zip_fd);
+
+ // ----- Create the Central Dir files header
+ for ($i=0,$v_count=0; $iprivWriteCentralFileHeader($v_header_list[$i])) != 1) {
+ // ----- Return
+ return $v_result;
+ }
+ $v_count++;
+ }
+
+ // ----- Transform the header to a 'usable' info
+ $this->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
+ }
+
+ // ----- Zip file comment
+ $v_comment = '';
+ if (isset($p_options[PCLZIP_OPT_COMMENT])) {
+ $v_comment = $p_options[PCLZIP_OPT_COMMENT];
+ }
+
+ // ----- Calculate the size of the central header
+ $v_size = @ftell($this->zip_fd)-$v_offset;
+
+ // ----- Create the central dir footer
+ if (($v_result = $this->privWriteCentralHeader($v_count, $v_size, $v_offset, $v_comment)) != 1)
+ {
+ // ----- Reset the file list
+ unset($v_header_list);
+
+ // ----- Return
+ return $v_result;
+ }
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privAddFileList()
+ // Description :
+ // Parameters :
+ // $p_filedescr_list : An array containing the file description
+ // or directory names to add in the zip
+ // $p_result_list : list of added files with their properties (specially the status field)
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function privAddFileList($p_filedescr_list, &$p_result_list, &$p_options)
+ {
+ $v_result=1;
+ $v_header = array();
+
+ // ----- Recuperate the current number of elt in list
+ $v_nb = sizeof($p_result_list);
+
+ // ----- Loop on the files
+ for ($j=0; ($jprivAddFile($p_filedescr_list[$j], $v_header,
+ $p_options);
+ if ($v_result != 1) {
+ return $v_result;
+ }
+
+ // ----- Store the file infos
+ $p_result_list[$v_nb++] = $v_header;
+ }
+ }
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privAddFile()
+ // Description :
+ // Parameters :
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function privAddFile($p_filedescr, &$p_header, &$p_options)
+ {
+ $v_result=1;
+
+ // ----- Working variable
+ $p_filename = $p_filedescr['filename'];
+
+ // TBC : Already done in the fileAtt check ... ?
+ if ($p_filename == "") {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid file list parameter (invalid or empty list)");
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Look for a stored different filename
+ /* TBC : Removed
+ if (isset($p_filedescr['stored_filename'])) {
+ $v_stored_filename = $p_filedescr['stored_filename'];
+ }
+ else {
+ $v_stored_filename = $p_filedescr['stored_filename'];
+ }
+ */
+
+ // ----- Set the file properties
+ clearstatcache();
+ $p_header['version'] = 20;
+ $p_header['version_extracted'] = 10;
+ $p_header['flag'] = 0;
+ $p_header['compression'] = 0;
+ $p_header['crc'] = 0;
+ $p_header['compressed_size'] = 0;
+ $p_header['filename_len'] = strlen($p_filename);
+ $p_header['extra_len'] = 0;
+ $p_header['disk'] = 0;
+ $p_header['internal'] = 0;
+ $p_header['offset'] = 0;
+ $p_header['filename'] = $p_filename;
+// TBC : Removed $p_header['stored_filename'] = $v_stored_filename;
+ $p_header['stored_filename'] = $p_filedescr['stored_filename'];
+ $p_header['extra'] = '';
+ $p_header['status'] = 'ok';
+ $p_header['index'] = -1;
+
+ // ----- Look for regular file
+ if ($p_filedescr['type']=='file') {
+ $p_header['external'] = 0x00000000;
+ $p_header['size'] = filesize($p_filename);
+ }
+
+ // ----- Look for regular folder
+ else if ($p_filedescr['type']=='folder') {
+ $p_header['external'] = 0x00000010;
+ $p_header['mtime'] = filemtime($p_filename);
+ $p_header['size'] = filesize($p_filename);
+ }
+
+ // ----- Look for virtual file
+ else if ($p_filedescr['type'] == 'virtual_file') {
+ $p_header['external'] = 0x00000000;
+ $p_header['size'] = strlen($p_filedescr['content']);
+ }
+
+
+ // ----- Look for filetime
+ if (isset($p_filedescr['mtime'])) {
+ $p_header['mtime'] = $p_filedescr['mtime'];
+ }
+ else if ($p_filedescr['type'] == 'virtual_file') {
+ $p_header['mtime'] = time();
+ }
+ else {
+ $p_header['mtime'] = filemtime($p_filename);
+ }
+
+ // ------ Look for file comment
+ if (isset($p_filedescr['comment'])) {
+ $p_header['comment_len'] = strlen($p_filedescr['comment']);
+ $p_header['comment'] = $p_filedescr['comment'];
+ }
+ else {
+ $p_header['comment_len'] = 0;
+ $p_header['comment'] = '';
+ }
+
+ // ----- Look for pre-add callback
+ if (isset($p_options[PCLZIP_CB_PRE_ADD])) {
+
+ // ----- Generate a local information
+ $v_local_header = array();
+ $this->privConvertHeader2FileInfo($p_header, $v_local_header);
+
+ // ----- Call the callback
+ // Here I do not use call_user_func() because I need to send a reference to the
+ // header.
+// eval('$v_result = '.$p_options[PCLZIP_CB_PRE_ADD].'(PCLZIP_CB_PRE_ADD, $v_local_header);');
+ $v_result = $p_options[PCLZIP_CB_PRE_ADD](PCLZIP_CB_PRE_ADD, $v_local_header);
+ if ($v_result == 0) {
+ // ----- Change the file status
+ $p_header['status'] = "skipped";
+ $v_result = 1;
+ }
+
+ // ----- Update the informations
+ // Only some fields can be modified
+ if ($p_header['stored_filename'] != $v_local_header['stored_filename']) {
+ $p_header['stored_filename'] = PclZipUtilPathReduction($v_local_header['stored_filename']);
+ }
+ }
+
+ // ----- Look for empty stored filename
+ if ($p_header['stored_filename'] == "") {
+ $p_header['status'] = "filtered";
+ }
+
+ // ----- Check the path length
+ if (strlen($p_header['stored_filename']) > 0xFF) {
+ $p_header['status'] = 'filename_too_long';
+ }
+
+ // ----- Look if no error, or file not skipped
+ if ($p_header['status'] == 'ok') {
+
+ // ----- Look for a file
+ if ($p_filedescr['type'] == 'file') {
+ // ----- Look for using temporary file to zip
+ if ( (!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF]))
+ && (isset($p_options[PCLZIP_OPT_TEMP_FILE_ON])
+ || (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD])
+ && ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] <= $p_header['size'])) ) ) {
+ $v_result = $this->privAddFileUsingTempFile($p_filedescr, $p_header, $p_options);
+ if ($v_result < PCLZIP_ERR_NO_ERROR) {
+ return $v_result;
+ }
+ }
+
+ // ----- Use "in memory" zip algo
+ else {
+
+ // ----- Open the source file
+ if (($v_file = @fopen($p_filename, "rb")) == 0) {
+ PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode");
+ return PclZip::errorCode();
+ }
+
+ // ----- Read the file content
+ $v_content = @fread($v_file, $p_header['size']);
+
+ // ----- Close the file
+ @fclose($v_file);
+
+ // ----- Calculate the CRC
+ $p_header['crc'] = @crc32($v_content);
+
+ // ----- Look for no compression
+ if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) {
+ // ----- Set header parameters
+ $p_header['compressed_size'] = $p_header['size'];
+ $p_header['compression'] = 0;
+ }
+
+ // ----- Look for normal compression
+ else {
+ // ----- Compress the content
+ $v_content = @gzdeflate($v_content);
+
+ // ----- Set header parameters
+ $p_header['compressed_size'] = strlen($v_content);
+ $p_header['compression'] = 8;
+ }
+
+ // ----- Call the header generation
+ if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
+ @fclose($v_file);
+ return $v_result;
+ }
+
+ // ----- Write the compressed (or not) content
+ @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']);
+
+ }
+
+ }
+
+ // ----- Look for a virtual file (a file from string)
+ else if ($p_filedescr['type'] == 'virtual_file') {
+
+ $v_content = $p_filedescr['content'];
+
+ // ----- Calculate the CRC
+ $p_header['crc'] = @crc32($v_content);
+
+ // ----- Look for no compression
+ if ($p_options[PCLZIP_OPT_NO_COMPRESSION]) {
+ // ----- Set header parameters
+ $p_header['compressed_size'] = $p_header['size'];
+ $p_header['compression'] = 0;
+ }
+
+ // ----- Look for normal compression
+ else {
+ // ----- Compress the content
+ $v_content = @gzdeflate($v_content);
+
+ // ----- Set header parameters
+ $p_header['compressed_size'] = strlen($v_content);
+ $p_header['compression'] = 8;
+ }
+
+ // ----- Call the header generation
+ if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
+ @fclose($v_file);
+ return $v_result;
+ }
+
+ // ----- Write the compressed (or not) content
+ @fwrite($this->zip_fd, $v_content, $p_header['compressed_size']);
+ }
+
+ // ----- Look for a directory
+ else if ($p_filedescr['type'] == 'folder') {
+ // ----- Look for directory last '/'
+ if (@substr($p_header['stored_filename'], -1) != '/') {
+ $p_header['stored_filename'] .= '/';
+ }
+
+ // ----- Set the file properties
+ $p_header['size'] = 0;
+ //$p_header['external'] = 0x41FF0010; // Value for a folder : to be checked
+ $p_header['external'] = 0x00000010; // Value for a folder : to be checked
+
+ // ----- Call the header generation
+ if (($v_result = $this->privWriteFileHeader($p_header)) != 1)
+ {
+ return $v_result;
+ }
+ }
+ }
+
+ // ----- Look for post-add callback
+ if (isset($p_options[PCLZIP_CB_POST_ADD])) {
+
+ // ----- Generate a local information
+ $v_local_header = array();
+ $this->privConvertHeader2FileInfo($p_header, $v_local_header);
+
+ // ----- Call the callback
+ // Here I do not use call_user_func() because I need to send a reference to the
+ // header.
+// eval('$v_result = '.$p_options[PCLZIP_CB_POST_ADD].'(PCLZIP_CB_POST_ADD, $v_local_header);');
+ $v_result = $p_options[PCLZIP_CB_POST_ADD](PCLZIP_CB_POST_ADD, $v_local_header);
+ if ($v_result == 0) {
+ // ----- Ignored
+ $v_result = 1;
+ }
+
+ // ----- Update the informations
+ // Nothing can be modified
+ }
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privAddFileUsingTempFile()
+ // Description :
+ // Parameters :
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function privAddFileUsingTempFile($p_filedescr, &$p_header, &$p_options)
+ {
+ $v_result=PCLZIP_ERR_NO_ERROR;
+
+ // ----- Working variable
+ $p_filename = $p_filedescr['filename'];
+
+
+ // ----- Open the source file
+ if (($v_file = @fopen($p_filename, "rb")) == 0) {
+ PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode");
+ return PclZip::errorCode();
+ }
+
+ // ----- Creates a compressed temporary file
+ $v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz';
+ if (($v_file_compressed = @gzopen($v_gzip_temp_name, "wb")) == 0) {
+ fclose($v_file);
+ PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode');
+ return PclZip::errorCode();
+ }
+
+ // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks
+ $v_size = filesize($p_filename);
+ while ($v_size != 0) {
+ $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
+ $v_buffer = @fread($v_file, $v_read_size);
+ //$v_binary_data = pack('a'.$v_read_size, $v_buffer);
+ @gzputs($v_file_compressed, $v_buffer, $v_read_size);
+ $v_size -= $v_read_size;
+ }
+
+ // ----- Close the file
+ @fclose($v_file);
+ @gzclose($v_file_compressed);
+
+ // ----- Check the minimum file size
+ if (filesize($v_gzip_temp_name) < 18) {
+ PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'gzip temporary file \''.$v_gzip_temp_name.'\' has invalid filesize - should be minimum 18 bytes');
+ return PclZip::errorCode();
+ }
+
+ // ----- Extract the compressed attributes
+ if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0) {
+ PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode');
+ return PclZip::errorCode();
+ }
+
+ // ----- Read the gzip file header
+ $v_binary_data = @fread($v_file_compressed, 10);
+ $v_data_header = unpack('a1id1/a1id2/a1cm/a1flag/Vmtime/a1xfl/a1os', $v_binary_data);
+
+ // ----- Check some parameters
+ $v_data_header['os'] = bin2hex($v_data_header['os']);
+
+ // ----- Read the gzip file footer
+ @fseek($v_file_compressed, filesize($v_gzip_temp_name)-8);
+ $v_binary_data = @fread($v_file_compressed, 8);
+ $v_data_footer = unpack('Vcrc/Vcompressed_size', $v_binary_data);
+
+ // ----- Set the attributes
+ $p_header['compression'] = ord($v_data_header['cm']);
+ //$p_header['mtime'] = $v_data_header['mtime'];
+ $p_header['crc'] = $v_data_footer['crc'];
+ $p_header['compressed_size'] = filesize($v_gzip_temp_name)-18;
+
+ // ----- Close the file
+ @fclose($v_file_compressed);
+
+ // ----- Call the header generation
+ if (($v_result = $this->privWriteFileHeader($p_header)) != 1) {
+ return $v_result;
+ }
+
+ // ----- Add the compressed data
+ if (($v_file_compressed = @fopen($v_gzip_temp_name, "rb")) == 0)
+ {
+ PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode');
+ return PclZip::errorCode();
+ }
+
+ // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks
+ fseek($v_file_compressed, 10);
+ $v_size = $p_header['compressed_size'];
+ while ($v_size != 0)
+ {
+ $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
+ $v_buffer = @fread($v_file_compressed, $v_read_size);
+ //$v_binary_data = pack('a'.$v_read_size, $v_buffer);
+ @fwrite($this->zip_fd, $v_buffer, $v_read_size);
+ $v_size -= $v_read_size;
+ }
+
+ // ----- Close the file
+ @fclose($v_file_compressed);
+
+ // ----- Unlink the temporary file
+ @unlink($v_gzip_temp_name);
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privCalculateStoredFilename()
+ // Description :
+ // Based on file descriptor properties and global options, this method
+ // calculate the filename that will be stored in the archive.
+ // Parameters :
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function privCalculateStoredFilename(&$p_filedescr, &$p_options)
+ {
+ $v_result=1;
+
+ // ----- Working variables
+ $p_filename = $p_filedescr['filename'];
+ if (isset($p_options[PCLZIP_OPT_ADD_PATH])) {
+ $p_add_dir = $p_options[PCLZIP_OPT_ADD_PATH];
+ }
+ else {
+ $p_add_dir = '';
+ }
+ if (isset($p_options[PCLZIP_OPT_REMOVE_PATH])) {
+ $p_remove_dir = $p_options[PCLZIP_OPT_REMOVE_PATH];
+ }
+ else {
+ $p_remove_dir = '';
+ }
+ if (isset($p_options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
+ $p_remove_all_dir = $p_options[PCLZIP_OPT_REMOVE_ALL_PATH];
+ }
+ else {
+ $p_remove_all_dir = 0;
+ }
+
+
+ // ----- Look for full name change
+ if (isset($p_filedescr['new_full_name'])) {
+ // ----- Remove drive letter if any
+ $v_stored_filename = PclZipUtilTranslateWinPath($p_filedescr['new_full_name']);
+ }
+
+ // ----- Look for path and/or short name change
+ else {
+
+ // ----- Look for short name change
+ // Its when we cahnge just the filename but not the path
+ if (isset($p_filedescr['new_short_name'])) {
+ $v_path_info = pathinfo($p_filename);
+ $v_dir = '';
+ if ($v_path_info['dirname'] != '') {
+ $v_dir = $v_path_info['dirname'].'/';
+ }
+ $v_stored_filename = $v_dir.$p_filedescr['new_short_name'];
+ }
+ else {
+ // ----- Calculate the stored filename
+ $v_stored_filename = $p_filename;
+ }
+
+ // ----- Look for all path to remove
+ if ($p_remove_all_dir) {
+ $v_stored_filename = basename($p_filename);
+ }
+ // ----- Look for partial path remove
+ else if ($p_remove_dir != "") {
+ if (substr($p_remove_dir, -1) != '/')
+ $p_remove_dir .= "/";
+
+ if ( (substr($p_filename, 0, 2) == "./")
+ || (substr($p_remove_dir, 0, 2) == "./")) {
+
+ if ( (substr($p_filename, 0, 2) == "./")
+ && (substr($p_remove_dir, 0, 2) != "./")) {
+ $p_remove_dir = "./".$p_remove_dir;
+ }
+ if ( (substr($p_filename, 0, 2) != "./")
+ && (substr($p_remove_dir, 0, 2) == "./")) {
+ $p_remove_dir = substr($p_remove_dir, 2);
+ }
+ }
+
+ $v_compare = PclZipUtilPathInclusion($p_remove_dir,
+ $v_stored_filename);
+ if ($v_compare > 0) {
+ if ($v_compare == 2) {
+ $v_stored_filename = "";
+ }
+ else {
+ $v_stored_filename = substr($v_stored_filename,
+ strlen($p_remove_dir));
+ }
+ }
+ }
+
+ // ----- Remove drive letter if any
+ $v_stored_filename = PclZipUtilTranslateWinPath($v_stored_filename);
+
+ // ----- Look for path to add
+ if ($p_add_dir != "") {
+ if (substr($p_add_dir, -1) == "/")
+ $v_stored_filename = $p_add_dir.$v_stored_filename;
+ else
+ $v_stored_filename = $p_add_dir."/".$v_stored_filename;
+ }
+ }
+
+ // ----- Filename (reduce the path of stored name)
+ $v_stored_filename = PclZipUtilPathReduction($v_stored_filename);
+ $p_filedescr['stored_filename'] = $v_stored_filename;
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privWriteFileHeader()
+ // Description :
+ // Parameters :
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function privWriteFileHeader(&$p_header)
+ {
+ $v_result=1;
+
+ // ----- Store the offset position of the file
+ $p_header['offset'] = ftell($this->zip_fd);
+
+ // ----- Transform UNIX mtime to DOS format mdate/mtime
+ $v_date = getdate($p_header['mtime']);
+ $v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2;
+ $v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday'];
+
+ // ----- Packed data
+ $v_binary_data = pack("VvvvvvVVVvv", 0x04034b50,
+ $p_header['version_extracted'], $p_header['flag'],
+ $p_header['compression'], $v_mtime, $v_mdate,
+ $p_header['crc'], $p_header['compressed_size'],
+ $p_header['size'],
+ strlen($p_header['stored_filename']),
+ $p_header['extra_len']);
+
+ // ----- Write the first 148 bytes of the header in the archive
+ fputs($this->zip_fd, $v_binary_data, 30);
+
+ // ----- Write the variable fields
+ if (strlen($p_header['stored_filename']) != 0)
+ {
+ fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename']));
+ }
+ if ($p_header['extra_len'] != 0)
+ {
+ fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']);
+ }
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privWriteCentralFileHeader()
+ // Description :
+ // Parameters :
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function privWriteCentralFileHeader(&$p_header)
+ {
+ $v_result=1;
+
+ // TBC
+ //for(reset($p_header); $key = key($p_header); next($p_header)) {
+ //}
+
+ // ----- Transform UNIX mtime to DOS format mdate/mtime
+ $v_date = getdate($p_header['mtime']);
+ $v_mtime = ($v_date['hours']<<11) + ($v_date['minutes']<<5) + $v_date['seconds']/2;
+ $v_mdate = (($v_date['year']-1980)<<9) + ($v_date['mon']<<5) + $v_date['mday'];
+
+
+ // ----- Packed data
+ $v_binary_data = pack("VvvvvvvVVVvvvvvVV", 0x02014b50,
+ $p_header['version'], $p_header['version_extracted'],
+ $p_header['flag'], $p_header['compression'],
+ $v_mtime, $v_mdate, $p_header['crc'],
+ $p_header['compressed_size'], $p_header['size'],
+ strlen($p_header['stored_filename']),
+ $p_header['extra_len'], $p_header['comment_len'],
+ $p_header['disk'], $p_header['internal'],
+ $p_header['external'], $p_header['offset']);
+
+ // ----- Write the 42 bytes of the header in the zip file
+ fputs($this->zip_fd, $v_binary_data, 46);
+
+ // ----- Write the variable fields
+ if (strlen($p_header['stored_filename']) != 0)
+ {
+ fputs($this->zip_fd, $p_header['stored_filename'], strlen($p_header['stored_filename']));
+ }
+ if ($p_header['extra_len'] != 0)
+ {
+ fputs($this->zip_fd, $p_header['extra'], $p_header['extra_len']);
+ }
+ if ($p_header['comment_len'] != 0)
+ {
+ fputs($this->zip_fd, $p_header['comment'], $p_header['comment_len']);
+ }
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privWriteCentralHeader()
+ // Description :
+ // Parameters :
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function privWriteCentralHeader($p_nb_entries, $p_size, $p_offset, $p_comment)
+ {
+ $v_result=1;
+
+ // ----- Packed data
+ $v_binary_data = pack("VvvvvVVv", 0x06054b50, 0, 0, $p_nb_entries,
+ $p_nb_entries, $p_size,
+ $p_offset, strlen($p_comment));
+
+ // ----- Write the 22 bytes of the header in the zip file
+ fputs($this->zip_fd, $v_binary_data, 22);
+
+ // ----- Write the variable fields
+ if (strlen($p_comment) != 0)
+ {
+ fputs($this->zip_fd, $p_comment, strlen($p_comment));
+ }
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privList()
+ // Description :
+ // Parameters :
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function privList(&$p_list)
+ {
+ $v_result=1;
+
+ // ----- Magic quotes trick
+ $this->privDisableMagicQuotes();
+
+ // ----- Open the zip file
+ if (($this->zip_fd = @fopen($this->zipname, 'rb')) == 0)
+ {
+ // ----- Magic quotes trick
+ $this->privSwapBackMagicQuotes();
+
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive \''.$this->zipname.'\' in binary read mode');
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Read the central directory informations
+ $v_central_dir = array();
+ if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
+ {
+ $this->privSwapBackMagicQuotes();
+ return $v_result;
+ }
+
+ // ----- Go to beginning of Central Dir
+ @rewind($this->zip_fd);
+ if (@fseek($this->zip_fd, $v_central_dir['offset']))
+ {
+ $this->privSwapBackMagicQuotes();
+
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Read each entry
+ for ($i=0; $i<$v_central_dir['entries']; $i++)
+ {
+ // ----- Read the file header
+ if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1)
+ {
+ $this->privSwapBackMagicQuotes();
+ return $v_result;
+ }
+ $v_header['index'] = $i;
+
+ // ----- Get the only interesting attributes
+ $this->privConvertHeader2FileInfo($v_header, $p_list[$i]);
+ unset($v_header);
+ }
+
+ // ----- Close the zip file
+ $this->privCloseFd();
+
+ // ----- Magic quotes trick
+ $this->privSwapBackMagicQuotes();
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privConvertHeader2FileInfo()
+ // Description :
+ // This function takes the file informations from the central directory
+ // entries and extract the interesting parameters that will be given back.
+ // The resulting file infos are set in the array $p_info
+ // $p_info['filename'] : Filename with full path. Given by user (add),
+ // extracted in the filesystem (extract).
+ // $p_info['stored_filename'] : Stored filename in the archive.
+ // $p_info['size'] = Size of the file.
+ // $p_info['compressed_size'] = Compressed size of the file.
+ // $p_info['mtime'] = Last modification date of the file.
+ // $p_info['comment'] = Comment associated with the file.
+ // $p_info['folder'] = true/false : indicates if the entry is a folder or not.
+ // $p_info['status'] = status of the action on the file.
+ // $p_info['crc'] = CRC of the file content.
+ // Parameters :
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function privConvertHeader2FileInfo($p_header, &$p_info)
+ {
+ $v_result=1;
+
+ // ----- Get the interesting attributes
+ $v_temp_path = PclZipUtilPathReduction($p_header['filename']);
+ $p_info['filename'] = $v_temp_path;
+ $v_temp_path = PclZipUtilPathReduction($p_header['stored_filename']);
+ $p_info['stored_filename'] = $v_temp_path;
+ $p_info['size'] = $p_header['size'];
+ $p_info['compressed_size'] = $p_header['compressed_size'];
+ $p_info['mtime'] = $p_header['mtime'];
+ $p_info['comment'] = $p_header['comment'];
+ $p_info['folder'] = (($p_header['external']&0x00000010)==0x00000010);
+ $p_info['index'] = $p_header['index'];
+ $p_info['status'] = $p_header['status'];
+ $p_info['crc'] = $p_header['crc'];
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privExtractByRule()
+ // Description :
+ // Extract a file or directory depending of rules (by index, by name, ...)
+ // Parameters :
+ // $p_file_list : An array where will be placed the properties of each
+ // extracted file
+ // $p_path : Path to add while writing the extracted files
+ // $p_remove_path : Path to remove (from the file memorized path) while writing the
+ // extracted files. If the path does not match the file path,
+ // the file is extracted with its memorized path.
+ // $p_remove_path does not apply to 'list' mode.
+ // $p_path and $p_remove_path are commulative.
+ // Return Values :
+ // 1 on success,0 or less on error (see error code list)
+ // --------------------------------------------------------------------------------
+ function privExtractByRule(&$p_file_list, $p_path, $p_remove_path, $p_remove_all_path, &$p_options)
+ {
+ $v_result=1;
+
+ // ----- Magic quotes trick
+ $this->privDisableMagicQuotes();
+
+ // ----- Check the path
+ if ( ($p_path == "")
+ || ( (substr($p_path, 0, 1) != "/")
+ && (substr($p_path, 0, 3) != "../")
+ && (substr($p_path,1,2)!=":/")))
+ $p_path = "./".$p_path;
+
+ // ----- Reduce the path last (and duplicated) '/'
+ if (($p_path != "./") && ($p_path != "/"))
+ {
+ // ----- Look for the path end '/'
+ while (substr($p_path, -1) == "/")
+ {
+ $p_path = substr($p_path, 0, strlen($p_path)-1);
+ }
+ }
+
+ // ----- Look for path to remove format (should end by /)
+ if (($p_remove_path != "") && (substr($p_remove_path, -1) != '/'))
+ {
+ $p_remove_path .= '/';
+ }
+ $p_remove_path_size = strlen($p_remove_path);
+
+ // ----- Open the zip file
+ if (($v_result = $this->privOpenFd('rb')) != 1)
+ {
+ $this->privSwapBackMagicQuotes();
+ return $v_result;
+ }
+
+ // ----- Read the central directory informations
+ $v_central_dir = array();
+ if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
+ {
+ // ----- Close the zip file
+ $this->privCloseFd();
+ $this->privSwapBackMagicQuotes();
+
+ return $v_result;
+ }
+
+ // ----- Start at beginning of Central Dir
+ $v_pos_entry = $v_central_dir['offset'];
+
+ // ----- Read each entry
+ $j_start = 0;
+ for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++)
+ {
+
+ // ----- Read next Central dir entry
+ @rewind($this->zip_fd);
+ if (@fseek($this->zip_fd, $v_pos_entry))
+ {
+ // ----- Close the zip file
+ $this->privCloseFd();
+ $this->privSwapBackMagicQuotes();
+
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Read the file header
+ $v_header = array();
+ if (($v_result = $this->privReadCentralFileHeader($v_header)) != 1)
+ {
+ // ----- Close the zip file
+ $this->privCloseFd();
+ $this->privSwapBackMagicQuotes();
+
+ return $v_result;
+ }
+
+ // ----- Store the index
+ $v_header['index'] = $i;
+
+ // ----- Store the file position
+ $v_pos_entry = ftell($this->zip_fd);
+
+ // ----- Look for the specific extract rules
+ $v_extract = false;
+
+ // ----- Look for extract by name rule
+ if ( (isset($p_options[PCLZIP_OPT_BY_NAME]))
+ && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) {
+
+ // ----- Look if the filename is in the list
+ for ($j=0; ($j strlen($p_options[PCLZIP_OPT_BY_NAME][$j]))
+ && (substr($v_header['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) {
+ $v_extract = true;
+ }
+ }
+ // ----- Look for a filename
+ elseif ($v_header['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) {
+ $v_extract = true;
+ }
+ }
+ }
+
+ // ----- Look for extract by ereg rule
+ // ereg() is deprecated with PHP 5.3
+ /*
+ else if ( (isset($p_options[PCLZIP_OPT_BY_EREG]))
+ && ($p_options[PCLZIP_OPT_BY_EREG] != "")) {
+
+ if (ereg($p_options[PCLZIP_OPT_BY_EREG], $v_header['stored_filename'])) {
+ $v_extract = true;
+ }
+ }
+ */
+
+ // ----- Look for extract by preg rule
+ else if ( (isset($p_options[PCLZIP_OPT_BY_PREG]))
+ && ($p_options[PCLZIP_OPT_BY_PREG] != "")) {
+
+ if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header['stored_filename'])) {
+ $v_extract = true;
+ }
+ }
+
+ // ----- Look for extract by index rule
+ else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX]))
+ && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) {
+
+ // ----- Look if the index is in the list
+ for ($j=$j_start; ($j=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) {
+ $v_extract = true;
+ }
+ if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) {
+ $j_start = $j+1;
+ }
+
+ if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) {
+ break;
+ }
+ }
+ }
+
+ // ----- Look for no rule, which means extract all the archive
+ else {
+ $v_extract = true;
+ }
+
+ // ----- Check compression method
+ if ( ($v_extract)
+ && ( ($v_header['compression'] != 8)
+ && ($v_header['compression'] != 0))) {
+ $v_header['status'] = 'unsupported_compression';
+
+ // ----- Look for PCLZIP_OPT_STOP_ON_ERROR
+ if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
+ && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
+
+ $this->privSwapBackMagicQuotes();
+
+ PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_COMPRESSION,
+ "Filename '".$v_header['stored_filename']."' is "
+ ."compressed by an unsupported compression "
+ ."method (".$v_header['compression'].") ");
+
+ return PclZip::errorCode();
+ }
+ }
+
+ // ----- Check encrypted files
+ if (($v_extract) && (($v_header['flag'] & 1) == 1)) {
+ $v_header['status'] = 'unsupported_encryption';
+
+ // ----- Look for PCLZIP_OPT_STOP_ON_ERROR
+ if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
+ && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
+
+ $this->privSwapBackMagicQuotes();
+
+ PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION,
+ "Unsupported encryption for "
+ ." filename '".$v_header['stored_filename']
+ ."'");
+
+ return PclZip::errorCode();
+ }
+ }
+
+ // ----- Look for real extraction
+ if (($v_extract) && ($v_header['status'] != 'ok')) {
+ $v_result = $this->privConvertHeader2FileInfo($v_header,
+ $p_file_list[$v_nb_extracted++]);
+ if ($v_result != 1) {
+ $this->privCloseFd();
+ $this->privSwapBackMagicQuotes();
+ return $v_result;
+ }
+
+ $v_extract = false;
+ }
+
+ // ----- Look for real extraction
+ if ($v_extract)
+ {
+
+ // ----- Go to the file position
+ @rewind($this->zip_fd);
+ if (@fseek($this->zip_fd, $v_header['offset']))
+ {
+ // ----- Close the zip file
+ $this->privCloseFd();
+
+ $this->privSwapBackMagicQuotes();
+
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Look for extraction as string
+ if ($p_options[PCLZIP_OPT_EXTRACT_AS_STRING]) {
+
+ $v_string = '';
+
+ // ----- Extracting the file
+ $v_result1 = $this->privExtractFileAsString($v_header, $v_string, $p_options);
+ if ($v_result1 < 1) {
+ $this->privCloseFd();
+ $this->privSwapBackMagicQuotes();
+ return $v_result1;
+ }
+
+ // ----- Get the only interesting attributes
+ if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted])) != 1)
+ {
+ // ----- Close the zip file
+ $this->privCloseFd();
+ $this->privSwapBackMagicQuotes();
+
+ return $v_result;
+ }
+
+ // ----- Set the file content
+ $p_file_list[$v_nb_extracted]['content'] = $v_string;
+
+ // ----- Next extracted file
+ $v_nb_extracted++;
+
+ // ----- Look for user callback abort
+ if ($v_result1 == 2) {
+ break;
+ }
+ }
+ // ----- Look for extraction in standard output
+ elseif ( (isset($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT]))
+ && ($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) {
+ // ----- Extracting the file in standard output
+ $v_result1 = $this->privExtractFileInOutput($v_header, $p_options);
+ if ($v_result1 < 1) {
+ $this->privCloseFd();
+ $this->privSwapBackMagicQuotes();
+ return $v_result1;
+ }
+
+ // ----- Get the only interesting attributes
+ if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1) {
+ $this->privCloseFd();
+ $this->privSwapBackMagicQuotes();
+ return $v_result;
+ }
+
+ // ----- Look for user callback abort
+ if ($v_result1 == 2) {
+ break;
+ }
+ }
+ // ----- Look for normal extraction
+ else {
+ // ----- Extracting the file
+ $v_result1 = $this->privExtractFile($v_header,
+ $p_path, $p_remove_path,
+ $p_remove_all_path,
+ $p_options);
+ if ($v_result1 < 1) {
+ $this->privCloseFd();
+ $this->privSwapBackMagicQuotes();
+ return $v_result1;
+ }
+
+ // ----- Get the only interesting attributes
+ if (($v_result = $this->privConvertHeader2FileInfo($v_header, $p_file_list[$v_nb_extracted++])) != 1)
+ {
+ // ----- Close the zip file
+ $this->privCloseFd();
+ $this->privSwapBackMagicQuotes();
+
+ return $v_result;
+ }
+
+ // ----- Look for user callback abort
+ if ($v_result1 == 2) {
+ break;
+ }
+ }
+ }
+ }
+
+ // ----- Close the zip file
+ $this->privCloseFd();
+ $this->privSwapBackMagicQuotes();
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privExtractFile()
+ // Description :
+ // Parameters :
+ // Return Values :
+ //
+ // 1 : ... ?
+ // PCLZIP_ERR_USER_ABORTED(2) : User ask for extraction stop in callback
+ // --------------------------------------------------------------------------------
+ function privExtractFile(&$p_entry, $p_path, $p_remove_path, $p_remove_all_path, &$p_options)
+ {
+ $v_result=1;
+
+ // ----- Read the file header
+ if (($v_result = $this->privReadFileHeader($v_header)) != 1)
+ {
+ // ----- Return
+ return $v_result;
+ }
+
+
+ // ----- Check that the file header is coherent with $p_entry info
+ if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {
+ // TBC
+ }
+
+ // ----- Look for all path to remove
+ if ($p_remove_all_path == true) {
+ // ----- Look for folder entry that not need to be extracted
+ if (($p_entry['external']&0x00000010)==0x00000010) {
+
+ $p_entry['status'] = "filtered";
+
+ return $v_result;
+ }
+
+ // ----- Get the basename of the path
+ $p_entry['filename'] = basename($p_entry['filename']);
+ }
+
+ // ----- Look for path to remove
+ else if ($p_remove_path != "")
+ {
+ if (PclZipUtilPathInclusion($p_remove_path, $p_entry['filename']) == 2)
+ {
+
+ // ----- Change the file status
+ $p_entry['status'] = "filtered";
+
+ // ----- Return
+ return $v_result;
+ }
+
+ $p_remove_path_size = strlen($p_remove_path);
+ if (substr($p_entry['filename'], 0, $p_remove_path_size) == $p_remove_path)
+ {
+
+ // ----- Remove the path
+ $p_entry['filename'] = substr($p_entry['filename'], $p_remove_path_size);
+
+ }
+ }
+
+ // ----- Add the path
+ if ($p_path != '') {
+ $p_entry['filename'] = $p_path."/".$p_entry['filename'];
+ }
+
+ // ----- Check a base_dir_restriction
+ if (isset($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION])) {
+ $v_inclusion
+ = PclZipUtilPathInclusion($p_options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION],
+ $p_entry['filename']);
+ if ($v_inclusion == 0) {
+
+ PclZip::privErrorLog(PCLZIP_ERR_DIRECTORY_RESTRICTION,
+ "Filename '".$p_entry['filename']."' is "
+ ."outside PCLZIP_OPT_EXTRACT_DIR_RESTRICTION");
+
+ return PclZip::errorCode();
+ }
+ }
+
+ // ----- Look for pre-extract callback
+ if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {
+
+ // ----- Generate a local information
+ $v_local_header = array();
+ $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
+
+ // ----- Call the callback
+ // Here I do not use call_user_func() because I need to send a reference to the
+ // header.
+// eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);');
+ $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header);
+ if ($v_result == 0) {
+ // ----- Change the file status
+ $p_entry['status'] = "skipped";
+ $v_result = 1;
+ }
+
+ // ----- Look for abort result
+ if ($v_result == 2) {
+ // ----- This status is internal and will be changed in 'skipped'
+ $p_entry['status'] = "aborted";
+ $v_result = PCLZIP_ERR_USER_ABORTED;
+ }
+
+ // ----- Update the informations
+ // Only some fields can be modified
+ $p_entry['filename'] = $v_local_header['filename'];
+ }
+
+
+ // ----- Look if extraction should be done
+ if ($p_entry['status'] == 'ok') {
+
+ // ----- Look for specific actions while the file exist
+ if (file_exists($p_entry['filename']))
+ {
+
+ // ----- Look if file is a directory
+ if (is_dir($p_entry['filename']))
+ {
+
+ // ----- Change the file status
+ $p_entry['status'] = "already_a_directory";
+
+ // ----- Look for PCLZIP_OPT_STOP_ON_ERROR
+ // For historical reason first PclZip implementation does not stop
+ // when this kind of error occurs.
+ if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
+ && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
+
+ PclZip::privErrorLog(PCLZIP_ERR_ALREADY_A_DIRECTORY,
+ "Filename '".$p_entry['filename']."' is "
+ ."already used by an existing directory");
+
+ return PclZip::errorCode();
+ }
+ }
+ // ----- Look if file is write protected
+ else if (!is_writeable($p_entry['filename']))
+ {
+
+ // ----- Change the file status
+ $p_entry['status'] = "write_protected";
+
+ // ----- Look for PCLZIP_OPT_STOP_ON_ERROR
+ // For historical reason first PclZip implementation does not stop
+ // when this kind of error occurs.
+ if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
+ && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
+
+ PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL,
+ "Filename '".$p_entry['filename']."' exists "
+ ."and is write protected");
+
+ return PclZip::errorCode();
+ }
+ }
+
+ // ----- Look if the extracted file is older
+ else if (filemtime($p_entry['filename']) > $p_entry['mtime'])
+ {
+ // ----- Change the file status
+ if ( (isset($p_options[PCLZIP_OPT_REPLACE_NEWER]))
+ && ($p_options[PCLZIP_OPT_REPLACE_NEWER]===true)) {
+ }
+ else {
+ $p_entry['status'] = "newer_exist";
+
+ // ----- Look for PCLZIP_OPT_STOP_ON_ERROR
+ // For historical reason first PclZip implementation does not stop
+ // when this kind of error occurs.
+ if ( (isset($p_options[PCLZIP_OPT_STOP_ON_ERROR]))
+ && ($p_options[PCLZIP_OPT_STOP_ON_ERROR]===true)) {
+
+ PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL,
+ "Newer version of '".$p_entry['filename']."' exists "
+ ."and option PCLZIP_OPT_REPLACE_NEWER is not selected");
+
+ return PclZip::errorCode();
+ }
+ }
+ }
+ else {
+ }
+ }
+
+ // ----- Check the directory availability and create it if necessary
+ else {
+ if ((($p_entry['external']&0x00000010)==0x00000010) || (substr($p_entry['filename'], -1) == '/'))
+ $v_dir_to_check = $p_entry['filename'];
+ else if (!strstr($p_entry['filename'], "/"))
+ $v_dir_to_check = "";
+ else
+ $v_dir_to_check = dirname($p_entry['filename']);
+
+ if (($v_result = $this->privDirCheck($v_dir_to_check, (($p_entry['external']&0x00000010)==0x00000010))) != 1) {
+
+ // ----- Change the file status
+ $p_entry['status'] = "path_creation_fail";
+
+ // ----- Return
+ //return $v_result;
+ $v_result = 1;
+ }
+ }
+ }
+
+ // ----- Look if extraction should be done
+ if ($p_entry['status'] == 'ok') {
+
+ // ----- Do the extraction (if not a folder)
+ if (!(($p_entry['external']&0x00000010)==0x00000010))
+ {
+ // ----- Look for not compressed file
+ if ($p_entry['compression'] == 0) {
+
+ // ----- Opening destination file
+ if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0)
+ {
+
+ // ----- Change the file status
+ $p_entry['status'] = "write_error";
+
+ // ----- Return
+ return $v_result;
+ }
+
+
+ // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks
+ $v_size = $p_entry['compressed_size'];
+ while ($v_size != 0)
+ {
+ $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
+ $v_buffer = @fread($this->zip_fd, $v_read_size);
+ /* Try to speed up the code
+ $v_binary_data = pack('a'.$v_read_size, $v_buffer);
+ @fwrite($v_dest_file, $v_binary_data, $v_read_size);
+ */
+ @fwrite($v_dest_file, $v_buffer, $v_read_size);
+ $v_size -= $v_read_size;
+ }
+
+ // ----- Closing the destination file
+ fclose($v_dest_file);
+
+ // ----- Change the file mtime
+ touch($p_entry['filename'], $p_entry['mtime']);
+
+
+ }
+ else {
+ // ----- TBC
+ // Need to be finished
+ if (($p_entry['flag'] & 1) == 1) {
+ PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_ENCRYPTION, 'File \''.$p_entry['filename'].'\' is encrypted. Encrypted files are not supported.');
+ return PclZip::errorCode();
+ }
+
+
+ // ----- Look for using temporary file to unzip
+ if ( (!isset($p_options[PCLZIP_OPT_TEMP_FILE_OFF]))
+ && (isset($p_options[PCLZIP_OPT_TEMP_FILE_ON])
+ || (isset($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD])
+ && ($p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] <= $p_entry['size'])) ) ) {
+ $v_result = $this->privExtractFileUsingTempFile($p_entry, $p_options);
+ if ($v_result < PCLZIP_ERR_NO_ERROR) {
+ return $v_result;
+ }
+ }
+
+ // ----- Look for extract in memory
+ else {
+
+
+ // ----- Read the compressed file in a buffer (one shot)
+ $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
+
+ // ----- Decompress the file
+ $v_file_content = @gzinflate($v_buffer);
+ unset($v_buffer);
+ if ($v_file_content === FALSE) {
+
+ // ----- Change the file status
+ // TBC
+ $p_entry['status'] = "error";
+
+ return $v_result;
+ }
+
+ // ----- Opening destination file
+ if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) {
+
+ // ----- Change the file status
+ $p_entry['status'] = "write_error";
+
+ return $v_result;
+ }
+
+ // ----- Write the uncompressed data
+ @fwrite($v_dest_file, $v_file_content, $p_entry['size']);
+ unset($v_file_content);
+
+ // ----- Closing the destination file
+ @fclose($v_dest_file);
+
+ }
+
+ // ----- Change the file mtime
+ @touch($p_entry['filename'], $p_entry['mtime']);
+ }
+
+ // ----- Look for chmod option
+ if (isset($p_options[PCLZIP_OPT_SET_CHMOD])) {
+
+ // ----- Change the mode of the file
+ @chmod($p_entry['filename'], $p_options[PCLZIP_OPT_SET_CHMOD]);
+ }
+
+ }
+ }
+
+ // ----- Change abort status
+ if ($p_entry['status'] == "aborted") {
+ $p_entry['status'] = "skipped";
+ }
+
+ // ----- Look for post-extract callback
+ elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) {
+
+ // ----- Generate a local information
+ $v_local_header = array();
+ $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
+
+ // ----- Call the callback
+ // Here I do not use call_user_func() because I need to send a reference to the
+ // header.
+// eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);');
+ $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header);
+
+ // ----- Look for abort result
+ if ($v_result == 2) {
+ $v_result = PCLZIP_ERR_USER_ABORTED;
+ }
+ }
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privExtractFileUsingTempFile()
+ // Description :
+ // Parameters :
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function privExtractFileUsingTempFile(&$p_entry, &$p_options)
+ {
+ $v_result=1;
+
+ // ----- Creates a temporary file
+ $v_gzip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.gz';
+ if (($v_dest_file = @fopen($v_gzip_temp_name, "wb")) == 0) {
+ fclose($v_file);
+ PclZip::privErrorLog(PCLZIP_ERR_WRITE_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary write mode');
+ return PclZip::errorCode();
+ }
+
+
+ // ----- Write gz file format header
+ $v_binary_data = pack('va1a1Va1a1', 0x8b1f, Chr($p_entry['compression']), Chr(0x00), time(), Chr(0x00), Chr(3));
+ @fwrite($v_dest_file, $v_binary_data, 10);
+
+ // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks
+ $v_size = $p_entry['compressed_size'];
+ while ($v_size != 0)
+ {
+ $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
+ $v_buffer = @fread($this->zip_fd, $v_read_size);
+ //$v_binary_data = pack('a'.$v_read_size, $v_buffer);
+ @fwrite($v_dest_file, $v_buffer, $v_read_size);
+ $v_size -= $v_read_size;
+ }
+
+ // ----- Write gz file format footer
+ $v_binary_data = pack('VV', $p_entry['crc'], $p_entry['size']);
+ @fwrite($v_dest_file, $v_binary_data, 8);
+
+ // ----- Close the temporary file
+ @fclose($v_dest_file);
+
+ // ----- Opening destination file
+ if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) {
+ $p_entry['status'] = "write_error";
+ return $v_result;
+ }
+
+ // ----- Open the temporary gz file
+ if (($v_src_file = @gzopen($v_gzip_temp_name, 'rb')) == 0) {
+ @fclose($v_dest_file);
+ $p_entry['status'] = "read_error";
+ PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_gzip_temp_name.'\' in binary read mode');
+ return PclZip::errorCode();
+ }
+
+
+ // ----- Read the file by PCLZIP_READ_BLOCK_SIZE octets blocks
+ $v_size = $p_entry['size'];
+ while ($v_size != 0) {
+ $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
+ $v_buffer = @gzread($v_src_file, $v_read_size);
+ //$v_binary_data = pack('a'.$v_read_size, $v_buffer);
+ @fwrite($v_dest_file, $v_buffer, $v_read_size);
+ $v_size -= $v_read_size;
+ }
+ @fclose($v_dest_file);
+ @gzclose($v_src_file);
+
+ // ----- Delete the temporary file
+ @unlink($v_gzip_temp_name);
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privExtractFileInOutput()
+ // Description :
+ // Parameters :
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function privExtractFileInOutput(&$p_entry, &$p_options)
+ {
+ $v_result=1;
+
+ // ----- Read the file header
+ if (($v_result = $this->privReadFileHeader($v_header)) != 1) {
+ return $v_result;
+ }
+
+
+ // ----- Check that the file header is coherent with $p_entry info
+ if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {
+ // TBC
+ }
+
+ // ----- Look for pre-extract callback
+ if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {
+
+ // ----- Generate a local information
+ $v_local_header = array();
+ $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
+
+ // ----- Call the callback
+ // Here I do not use call_user_func() because I need to send a reference to the
+ // header.
+// eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);');
+ $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header);
+ if ($v_result == 0) {
+ // ----- Change the file status
+ $p_entry['status'] = "skipped";
+ $v_result = 1;
+ }
+
+ // ----- Look for abort result
+ if ($v_result == 2) {
+ // ----- This status is internal and will be changed in 'skipped'
+ $p_entry['status'] = "aborted";
+ $v_result = PCLZIP_ERR_USER_ABORTED;
+ }
+
+ // ----- Update the informations
+ // Only some fields can be modified
+ $p_entry['filename'] = $v_local_header['filename'];
+ }
+
+ // ----- Trace
+
+ // ----- Look if extraction should be done
+ if ($p_entry['status'] == 'ok') {
+
+ // ----- Do the extraction (if not a folder)
+ if (!(($p_entry['external']&0x00000010)==0x00000010)) {
+ // ----- Look for not compressed file
+ if ($p_entry['compressed_size'] == $p_entry['size']) {
+
+ // ----- Read the file in a buffer (one shot)
+ $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
+
+ // ----- Send the file to the output
+ echo $v_buffer;
+ unset($v_buffer);
+ }
+ else {
+
+ // ----- Read the compressed file in a buffer (one shot)
+ $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
+
+ // ----- Decompress the file
+ $v_file_content = gzinflate($v_buffer);
+ unset($v_buffer);
+
+ // ----- Send the file to the output
+ echo $v_file_content;
+ unset($v_file_content);
+ }
+ }
+ }
+
+ // ----- Change abort status
+ if ($p_entry['status'] == "aborted") {
+ $p_entry['status'] = "skipped";
+ }
+
+ // ----- Look for post-extract callback
+ elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) {
+
+ // ----- Generate a local information
+ $v_local_header = array();
+ $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
+
+ // ----- Call the callback
+ // Here I do not use call_user_func() because I need to send a reference to the
+ // header.
+// eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);');
+ $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header);
+
+ // ----- Look for abort result
+ if ($v_result == 2) {
+ $v_result = PCLZIP_ERR_USER_ABORTED;
+ }
+ }
+
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privExtractFileAsString()
+ // Description :
+ // Parameters :
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function privExtractFileAsString(&$p_entry, &$p_string, &$p_options)
+ {
+ $v_result=1;
+
+ // ----- Read the file header
+ $v_header = array();
+ if (($v_result = $this->privReadFileHeader($v_header)) != 1)
+ {
+ // ----- Return
+ return $v_result;
+ }
+
+
+ // ----- Check that the file header is coherent with $p_entry info
+ if ($this->privCheckFileHeaders($v_header, $p_entry) != 1) {
+ // TBC
+ }
+
+ // ----- Look for pre-extract callback
+ if (isset($p_options[PCLZIP_CB_PRE_EXTRACT])) {
+
+ // ----- Generate a local information
+ $v_local_header = array();
+ $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
+
+ // ----- Call the callback
+ // Here I do not use call_user_func() because I need to send a reference to the
+ // header.
+// eval('$v_result = '.$p_options[PCLZIP_CB_PRE_EXTRACT].'(PCLZIP_CB_PRE_EXTRACT, $v_local_header);');
+ $v_result = $p_options[PCLZIP_CB_PRE_EXTRACT](PCLZIP_CB_PRE_EXTRACT, $v_local_header);
+ if ($v_result == 0) {
+ // ----- Change the file status
+ $p_entry['status'] = "skipped";
+ $v_result = 1;
+ }
+
+ // ----- Look for abort result
+ if ($v_result == 2) {
+ // ----- This status is internal and will be changed in 'skipped'
+ $p_entry['status'] = "aborted";
+ $v_result = PCLZIP_ERR_USER_ABORTED;
+ }
+
+ // ----- Update the informations
+ // Only some fields can be modified
+ $p_entry['filename'] = $v_local_header['filename'];
+ }
+
+
+ // ----- Look if extraction should be done
+ if ($p_entry['status'] == 'ok') {
+
+ // ----- Do the extraction (if not a folder)
+ if (!(($p_entry['external']&0x00000010)==0x00000010)) {
+ // ----- Look for not compressed file
+ // if ($p_entry['compressed_size'] == $p_entry['size'])
+ if ($p_entry['compression'] == 0) {
+
+ // ----- Reading the file
+ $p_string = @fread($this->zip_fd, $p_entry['compressed_size']);
+ }
+ else {
+
+ // ----- Reading the file
+ $v_data = @fread($this->zip_fd, $p_entry['compressed_size']);
+
+ // ----- Decompress the file
+ if (($p_string = @gzinflate($v_data)) === FALSE) {
+ // TBC
+ }
+ }
+
+ // ----- Trace
+ }
+ else {
+ // TBC : error : can not extract a folder in a string
+ }
+
+ }
+
+ // ----- Change abort status
+ if ($p_entry['status'] == "aborted") {
+ $p_entry['status'] = "skipped";
+ }
+
+ // ----- Look for post-extract callback
+ elseif (isset($p_options[PCLZIP_CB_POST_EXTRACT])) {
+
+ // ----- Generate a local information
+ $v_local_header = array();
+ $this->privConvertHeader2FileInfo($p_entry, $v_local_header);
+
+ // ----- Swap the content to header
+ $v_local_header['content'] = $p_string;
+ $p_string = '';
+
+ // ----- Call the callback
+ // Here I do not use call_user_func() because I need to send a reference to the
+ // header.
+// eval('$v_result = '.$p_options[PCLZIP_CB_POST_EXTRACT].'(PCLZIP_CB_POST_EXTRACT, $v_local_header);');
+ $v_result = $p_options[PCLZIP_CB_POST_EXTRACT](PCLZIP_CB_POST_EXTRACT, $v_local_header);
+
+ // ----- Swap back the content to header
+ $p_string = $v_local_header['content'];
+ unset($v_local_header['content']);
+
+ // ----- Look for abort result
+ if ($v_result == 2) {
+ $v_result = PCLZIP_ERR_USER_ABORTED;
+ }
+ }
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privReadFileHeader()
+ // Description :
+ // Parameters :
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function privReadFileHeader(&$p_header)
+ {
+ $v_result=1;
+
+ // ----- Read the 4 bytes signature
+ $v_binary_data = @fread($this->zip_fd, 4);
+ $v_data = unpack('Vid', $v_binary_data);
+
+ // ----- Check signature
+ if ($v_data['id'] != 0x04034b50)
+ {
+
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure');
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Read the first 42 bytes of the header
+ $v_binary_data = fread($this->zip_fd, 26);
+
+ // ----- Look for invalid block size
+ if (strlen($v_binary_data) != 26)
+ {
+ $p_header['filename'] = "";
+ $p_header['status'] = "invalid_header";
+
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data));
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Extract the values
+ $v_data = unpack('vversion/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len', $v_binary_data);
+
+ // ----- Get filename
+ $p_header['filename'] = fread($this->zip_fd, $v_data['filename_len']);
+
+ // ----- Get extra_fields
+ if ($v_data['extra_len'] != 0) {
+ $p_header['extra'] = fread($this->zip_fd, $v_data['extra_len']);
+ }
+ else {
+ $p_header['extra'] = '';
+ }
+
+ // ----- Extract properties
+ $p_header['version_extracted'] = $v_data['version'];
+ $p_header['compression'] = $v_data['compression'];
+ $p_header['size'] = $v_data['size'];
+ $p_header['compressed_size'] = $v_data['compressed_size'];
+ $p_header['crc'] = $v_data['crc'];
+ $p_header['flag'] = $v_data['flag'];
+ $p_header['filename_len'] = $v_data['filename_len'];
+
+ // ----- Recuperate date in UNIX format
+ $p_header['mdate'] = $v_data['mdate'];
+ $p_header['mtime'] = $v_data['mtime'];
+ if ($p_header['mdate'] && $p_header['mtime'])
+ {
+ // ----- Extract time
+ $v_hour = ($p_header['mtime'] & 0xF800) >> 11;
+ $v_minute = ($p_header['mtime'] & 0x07E0) >> 5;
+ $v_seconde = ($p_header['mtime'] & 0x001F)*2;
+
+ // ----- Extract date
+ $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980;
+ $v_month = ($p_header['mdate'] & 0x01E0) >> 5;
+ $v_day = $p_header['mdate'] & 0x001F;
+
+ // ----- Get UNIX date format
+ $p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year);
+
+ }
+ else
+ {
+ $p_header['mtime'] = time();
+ }
+
+ // TBC
+ //for(reset($v_data); $key = key($v_data); next($v_data)) {
+ //}
+
+ // ----- Set the stored filename
+ $p_header['stored_filename'] = $p_header['filename'];
+
+ // ----- Set the status field
+ $p_header['status'] = "ok";
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privReadCentralFileHeader()
+ // Description :
+ // Parameters :
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function privReadCentralFileHeader(&$p_header)
+ {
+ $v_result=1;
+
+ // ----- Read the 4 bytes signature
+ $v_binary_data = @fread($this->zip_fd, 4);
+ $v_data = unpack('Vid', $v_binary_data);
+
+ // ----- Check signature
+ if ($v_data['id'] != 0x02014b50)
+ {
+
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Invalid archive structure');
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Read the first 42 bytes of the header
+ $v_binary_data = fread($this->zip_fd, 42);
+
+ // ----- Look for invalid block size
+ if (strlen($v_binary_data) != 42)
+ {
+ $p_header['filename'] = "";
+ $p_header['status'] = "invalid_header";
+
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid block size : ".strlen($v_binary_data));
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Extract the values
+ $p_header = unpack('vversion/vversion_extracted/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len/vcomment_len/vdisk/vinternal/Vexternal/Voffset', $v_binary_data);
+
+ // ----- Get filename
+ if ($p_header['filename_len'] != 0)
+ $p_header['filename'] = fread($this->zip_fd, $p_header['filename_len']);
+ else
+ $p_header['filename'] = '';
+
+ // ----- Get extra
+ if ($p_header['extra_len'] != 0)
+ $p_header['extra'] = fread($this->zip_fd, $p_header['extra_len']);
+ else
+ $p_header['extra'] = '';
+
+ // ----- Get comment
+ if ($p_header['comment_len'] != 0)
+ $p_header['comment'] = fread($this->zip_fd, $p_header['comment_len']);
+ else
+ $p_header['comment'] = '';
+
+ // ----- Extract properties
+
+ // ----- Recuperate date in UNIX format
+ //if ($p_header['mdate'] && $p_header['mtime'])
+ // TBC : bug : this was ignoring time with 0/0/0
+ if (1)
+ {
+ // ----- Extract time
+ $v_hour = ($p_header['mtime'] & 0xF800) >> 11;
+ $v_minute = ($p_header['mtime'] & 0x07E0) >> 5;
+ $v_seconde = ($p_header['mtime'] & 0x001F)*2;
+
+ // ----- Extract date
+ $v_year = (($p_header['mdate'] & 0xFE00) >> 9) + 1980;
+ $v_month = ($p_header['mdate'] & 0x01E0) >> 5;
+ $v_day = $p_header['mdate'] & 0x001F;
+
+ // ----- Get UNIX date format
+ $p_header['mtime'] = @mktime($v_hour, $v_minute, $v_seconde, $v_month, $v_day, $v_year);
+
+ }
+ else
+ {
+ $p_header['mtime'] = time();
+ }
+
+ // ----- Set the stored filename
+ $p_header['stored_filename'] = $p_header['filename'];
+
+ // ----- Set default status to ok
+ $p_header['status'] = 'ok';
+
+ // ----- Look if it is a directory
+ if (substr($p_header['filename'], -1) == '/') {
+ //$p_header['external'] = 0x41FF0010;
+ $p_header['external'] = 0x00000010;
+ }
+
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privCheckFileHeaders()
+ // Description :
+ // Parameters :
+ // Return Values :
+ // 1 on success,
+ // 0 on error;
+ // --------------------------------------------------------------------------------
+ function privCheckFileHeaders(&$p_local_header, &$p_central_header)
+ {
+ $v_result=1;
+
+ // ----- Check the static values
+ // TBC
+ if ($p_local_header['filename'] != $p_central_header['filename']) {
+ }
+ if ($p_local_header['version_extracted'] != $p_central_header['version_extracted']) {
+ }
+ if ($p_local_header['flag'] != $p_central_header['flag']) {
+ }
+ if ($p_local_header['compression'] != $p_central_header['compression']) {
+ }
+ if ($p_local_header['mtime'] != $p_central_header['mtime']) {
+ }
+ if ($p_local_header['filename_len'] != $p_central_header['filename_len']) {
+ }
+
+ // ----- Look for flag bit 3
+ if (($p_local_header['flag'] & 8) == 8) {
+ $p_local_header['size'] = $p_central_header['size'];
+ $p_local_header['compressed_size'] = $p_central_header['compressed_size'];
+ $p_local_header['crc'] = $p_central_header['crc'];
+ }
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privReadEndCentralDir()
+ // Description :
+ // Parameters :
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function privReadEndCentralDir(&$p_central_dir)
+ {
+ $v_result=1;
+
+ // ----- Go to the end of the zip file
+ $v_size = filesize($this->zipname);
+ @fseek($this->zip_fd, $v_size);
+ if (@ftell($this->zip_fd) != $v_size)
+ {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to go to the end of the archive \''.$this->zipname.'\'');
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- First try : look if this is an archive with no commentaries (most of the time)
+ // in this case the end of central dir is at 22 bytes of the file end
+ $v_found = 0;
+ if ($v_size > 26) {
+ @fseek($this->zip_fd, $v_size-22);
+ if (($v_pos = @ftell($this->zip_fd)) != ($v_size-22))
+ {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\'');
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Read for bytes
+ $v_binary_data = @fread($this->zip_fd, 4);
+ $v_data = @unpack('Vid', $v_binary_data);
+
+ // ----- Check signature
+ if ($v_data['id'] == 0x06054b50) {
+ $v_found = 1;
+ }
+
+ $v_pos = ftell($this->zip_fd);
+ }
+
+ // ----- Go back to the maximum possible size of the Central Dir End Record
+ if (!$v_found) {
+ $v_maximum_size = 65557; // 0xFFFF + 22;
+ if ($v_maximum_size > $v_size)
+ $v_maximum_size = $v_size;
+ @fseek($this->zip_fd, $v_size-$v_maximum_size);
+ if (@ftell($this->zip_fd) != ($v_size-$v_maximum_size))
+ {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, 'Unable to seek back to the middle of the archive \''.$this->zipname.'\'');
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Read byte per byte in order to find the signature
+ $v_pos = ftell($this->zip_fd);
+ $v_bytes = 0x00000000;
+ while ($v_pos < $v_size)
+ {
+ // ----- Read a byte
+ $v_byte = @fread($this->zip_fd, 1);
+
+ // ----- Add the byte
+ //$v_bytes = ($v_bytes << 8) | Ord($v_byte);
+ // Note we mask the old value down such that once shifted we can never end up with more than a 32bit number
+ // Otherwise on systems where we have 64bit integers the check below for the magic number will fail.
+ $v_bytes = ( ($v_bytes & 0xFFFFFF) << 8) | Ord($v_byte);
+
+ // ----- Compare the bytes
+ if ($v_bytes == 0x504b0506)
+ {
+ $v_pos++;
+ break;
+ }
+
+ $v_pos++;
+ }
+
+ // ----- Look if not found end of central dir
+ if ($v_pos == $v_size)
+ {
+
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Unable to find End of Central Dir Record signature");
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+ }
+
+ // ----- Read the first 18 bytes of the header
+ $v_binary_data = fread($this->zip_fd, 18);
+
+ // ----- Look for invalid block size
+ if (strlen($v_binary_data) != 18)
+ {
+
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT, "Invalid End of Central Dir Record size : ".strlen($v_binary_data));
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Extract the values
+ $v_data = unpack('vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size', $v_binary_data);
+
+ // ----- Check the global size
+ if (($v_pos + $v_data['comment_size'] + 18) != $v_size) {
+
+ // ----- Removed in release 2.2 see readme file
+ // The check of the file size is a little too strict.
+ // Some bugs where found when a zip is encrypted/decrypted with 'crypt'.
+ // While decrypted, zip has training 0 bytes
+ if (0) {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_BAD_FORMAT,
+ 'The central dir is not at the end of the archive.'
+ .' Some trailing bytes exists after the archive.');
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+ }
+
+ // ----- Get comment
+ if ($v_data['comment_size'] != 0) {
+ $p_central_dir['comment'] = fread($this->zip_fd, $v_data['comment_size']);
+ }
+ else
+ $p_central_dir['comment'] = '';
+
+ $p_central_dir['entries'] = $v_data['entries'];
+ $p_central_dir['disk_entries'] = $v_data['disk_entries'];
+ $p_central_dir['offset'] = $v_data['offset'];
+ $p_central_dir['size'] = $v_data['size'];
+ $p_central_dir['disk'] = $v_data['disk'];
+ $p_central_dir['disk_start'] = $v_data['disk_start'];
+
+ // TBC
+ //for(reset($p_central_dir); $key = key($p_central_dir); next($p_central_dir)) {
+ //}
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privDeleteByRule()
+ // Description :
+ // Parameters :
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function privDeleteByRule(&$p_result_list, &$p_options)
+ {
+ $v_result=1;
+ $v_list_detail = array();
+
+ // ----- Open the zip file
+ if (($v_result=$this->privOpenFd('rb')) != 1)
+ {
+ // ----- Return
+ return $v_result;
+ }
+
+ // ----- Read the central directory informations
+ $v_central_dir = array();
+ if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
+ {
+ $this->privCloseFd();
+ return $v_result;
+ }
+
+ // ----- Go to beginning of File
+ @rewind($this->zip_fd);
+
+ // ----- Scan all the files
+ // ----- Start at beginning of Central Dir
+ $v_pos_entry = $v_central_dir['offset'];
+ @rewind($this->zip_fd);
+ if (@fseek($this->zip_fd, $v_pos_entry))
+ {
+ // ----- Close the zip file
+ $this->privCloseFd();
+
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Read each entry
+ $v_header_list = array();
+ $j_start = 0;
+ for ($i=0, $v_nb_extracted=0; $i<$v_central_dir['entries']; $i++)
+ {
+
+ // ----- Read the file header
+ $v_header_list[$v_nb_extracted] = array();
+ if (($v_result = $this->privReadCentralFileHeader($v_header_list[$v_nb_extracted])) != 1)
+ {
+ // ----- Close the zip file
+ $this->privCloseFd();
+
+ return $v_result;
+ }
+
+
+ // ----- Store the index
+ $v_header_list[$v_nb_extracted]['index'] = $i;
+
+ // ----- Look for the specific extract rules
+ $v_found = false;
+
+ // ----- Look for extract by name rule
+ if ( (isset($p_options[PCLZIP_OPT_BY_NAME]))
+ && ($p_options[PCLZIP_OPT_BY_NAME] != 0)) {
+
+ // ----- Look if the filename is in the list
+ for ($j=0; ($j strlen($p_options[PCLZIP_OPT_BY_NAME][$j]))
+ && (substr($v_header_list[$v_nb_extracted]['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) {
+ $v_found = true;
+ }
+ elseif ( (($v_header_list[$v_nb_extracted]['external']&0x00000010)==0x00000010) /* Indicates a folder */
+ && ($v_header_list[$v_nb_extracted]['stored_filename'].'/' == $p_options[PCLZIP_OPT_BY_NAME][$j])) {
+ $v_found = true;
+ }
+ }
+ // ----- Look for a filename
+ elseif ($v_header_list[$v_nb_extracted]['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) {
+ $v_found = true;
+ }
+ }
+ }
+
+ // ----- Look for extract by ereg rule
+ // ereg() is deprecated with PHP 5.3
+ /*
+ else if ( (isset($p_options[PCLZIP_OPT_BY_EREG]))
+ && ($p_options[PCLZIP_OPT_BY_EREG] != "")) {
+
+ if (ereg($p_options[PCLZIP_OPT_BY_EREG], $v_header_list[$v_nb_extracted]['stored_filename'])) {
+ $v_found = true;
+ }
+ }
+ */
+
+ // ----- Look for extract by preg rule
+ else if ( (isset($p_options[PCLZIP_OPT_BY_PREG]))
+ && ($p_options[PCLZIP_OPT_BY_PREG] != "")) {
+
+ if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header_list[$v_nb_extracted]['stored_filename'])) {
+ $v_found = true;
+ }
+ }
+
+ // ----- Look for extract by index rule
+ else if ( (isset($p_options[PCLZIP_OPT_BY_INDEX]))
+ && ($p_options[PCLZIP_OPT_BY_INDEX] != 0)) {
+
+ // ----- Look if the index is in the list
+ for ($j=$j_start; ($j=$p_options[PCLZIP_OPT_BY_INDEX][$j]['start']) && ($i<=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end'])) {
+ $v_found = true;
+ }
+ if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) {
+ $j_start = $j+1;
+ }
+
+ if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) {
+ break;
+ }
+ }
+ }
+ else {
+ $v_found = true;
+ }
+
+ // ----- Look for deletion
+ if ($v_found)
+ {
+ unset($v_header_list[$v_nb_extracted]);
+ }
+ else
+ {
+ $v_nb_extracted++;
+ }
+ }
+
+ // ----- Look if something need to be deleted
+ if ($v_nb_extracted > 0) {
+
+ // ----- Creates a temporay file
+ $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
+
+ // ----- Creates a temporary zip archive
+ $v_temp_zip = new PclZip($v_zip_temp_name);
+
+ // ----- Open the temporary zip file in write mode
+ if (($v_result = $v_temp_zip->privOpenFd('wb')) != 1) {
+ $this->privCloseFd();
+
+ // ----- Return
+ return $v_result;
+ }
+
+ // ----- Look which file need to be kept
+ for ($i=0; $izip_fd);
+ if (@fseek($this->zip_fd, $v_header_list[$i]['offset'])) {
+ // ----- Close the zip file
+ $this->privCloseFd();
+ $v_temp_zip->privCloseFd();
+ @unlink($v_zip_temp_name);
+
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_INVALID_ARCHIVE_ZIP, 'Invalid archive size');
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Read the file header
+ $v_local_header = array();
+ if (($v_result = $this->privReadFileHeader($v_local_header)) != 1) {
+ // ----- Close the zip file
+ $this->privCloseFd();
+ $v_temp_zip->privCloseFd();
+ @unlink($v_zip_temp_name);
+
+ // ----- Return
+ return $v_result;
+ }
+
+ // ----- Check that local file header is same as central file header
+ if ($this->privCheckFileHeaders($v_local_header,
+ $v_header_list[$i]) != 1) {
+ // TBC
+ }
+ unset($v_local_header);
+
+ // ----- Write the file header
+ if (($v_result = $v_temp_zip->privWriteFileHeader($v_header_list[$i])) != 1) {
+ // ----- Close the zip file
+ $this->privCloseFd();
+ $v_temp_zip->privCloseFd();
+ @unlink($v_zip_temp_name);
+
+ // ----- Return
+ return $v_result;
+ }
+
+ // ----- Read/write the data block
+ if (($v_result = PclZipUtilCopyBlock($this->zip_fd, $v_temp_zip->zip_fd, $v_header_list[$i]['compressed_size'])) != 1) {
+ // ----- Close the zip file
+ $this->privCloseFd();
+ $v_temp_zip->privCloseFd();
+ @unlink($v_zip_temp_name);
+
+ // ----- Return
+ return $v_result;
+ }
+ }
+
+ // ----- Store the offset of the central dir
+ $v_offset = @ftell($v_temp_zip->zip_fd);
+
+ // ----- Re-Create the Central Dir files header
+ for ($i=0; $iprivWriteCentralFileHeader($v_header_list[$i])) != 1) {
+ $v_temp_zip->privCloseFd();
+ $this->privCloseFd();
+ @unlink($v_zip_temp_name);
+
+ // ----- Return
+ return $v_result;
+ }
+
+ // ----- Transform the header to a 'usable' info
+ $v_temp_zip->privConvertHeader2FileInfo($v_header_list[$i], $p_result_list[$i]);
+ }
+
+
+ // ----- Zip file comment
+ $v_comment = '';
+ if (isset($p_options[PCLZIP_OPT_COMMENT])) {
+ $v_comment = $p_options[PCLZIP_OPT_COMMENT];
+ }
+
+ // ----- Calculate the size of the central header
+ $v_size = @ftell($v_temp_zip->zip_fd)-$v_offset;
+
+ // ----- Create the central dir footer
+ if (($v_result = $v_temp_zip->privWriteCentralHeader(sizeof($v_header_list), $v_size, $v_offset, $v_comment)) != 1) {
+ // ----- Reset the file list
+ unset($v_header_list);
+ $v_temp_zip->privCloseFd();
+ $this->privCloseFd();
+ @unlink($v_zip_temp_name);
+
+ // ----- Return
+ return $v_result;
+ }
+
+ // ----- Close
+ $v_temp_zip->privCloseFd();
+ $this->privCloseFd();
+
+ // ----- Delete the zip file
+ // TBC : I should test the result ...
+ @unlink($this->zipname);
+
+ // ----- Rename the temporary file
+ // TBC : I should test the result ...
+ //@rename($v_zip_temp_name, $this->zipname);
+ PclZipUtilRename($v_zip_temp_name, $this->zipname);
+
+ // ----- Destroy the temporary archive
+ unset($v_temp_zip);
+ }
+
+ // ----- Remove every files : reset the file
+ else if ($v_central_dir['entries'] != 0) {
+ $this->privCloseFd();
+
+ if (($v_result = $this->privOpenFd('wb')) != 1) {
+ return $v_result;
+ }
+
+ if (($v_result = $this->privWriteCentralHeader(0, 0, 0, '')) != 1) {
+ return $v_result;
+ }
+
+ $this->privCloseFd();
+ }
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privDirCheck()
+ // Description :
+ // Check if a directory exists, if not it creates it and all the parents directory
+ // which may be useful.
+ // Parameters :
+ // $p_dir : Directory path to check.
+ // Return Values :
+ // 1 : OK
+ // -1 : Unable to create directory
+ // --------------------------------------------------------------------------------
+ function privDirCheck($p_dir, $p_is_dir=false)
+ {
+ $v_result = 1;
+
+
+ // ----- Remove the final '/'
+ if (($p_is_dir) && (substr($p_dir, -1)=='/'))
+ {
+ $p_dir = substr($p_dir, 0, strlen($p_dir)-1);
+ }
+
+ // ----- Check the directory availability
+ if ((is_dir($p_dir)) || ($p_dir == ""))
+ {
+ return 1;
+ }
+
+ // ----- Extract parent directory
+ $p_parent_dir = dirname($p_dir);
+
+ // ----- Just a check
+ if ($p_parent_dir != $p_dir)
+ {
+ // ----- Look for parent directory
+ if ($p_parent_dir != "")
+ {
+ if (($v_result = $this->privDirCheck($p_parent_dir)) != 1)
+ {
+ return $v_result;
+ }
+ }
+ }
+
+ // ----- Create the directory
+ if (!@mkdir($p_dir, 0777))
+ {
+ // ----- Error log
+ PclZip::privErrorLog(PCLZIP_ERR_DIR_CREATE_FAIL, "Unable to create directory '$p_dir'");
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privMerge()
+ // Description :
+ // If $p_archive_to_add does not exist, the function exit with a success result.
+ // Parameters :
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function privMerge(&$p_archive_to_add)
+ {
+ $v_result=1;
+
+ // ----- Look if the archive_to_add exists
+ if (!is_file($p_archive_to_add->zipname))
+ {
+
+ // ----- Nothing to merge, so merge is a success
+ $v_result = 1;
+
+ // ----- Return
+ return $v_result;
+ }
+
+ // ----- Look if the archive exists
+ if (!is_file($this->zipname))
+ {
+
+ // ----- Do a duplicate
+ $v_result = $this->privDuplicate($p_archive_to_add->zipname);
+
+ // ----- Return
+ return $v_result;
+ }
+
+ // ----- Open the zip file
+ if (($v_result=$this->privOpenFd('rb')) != 1)
+ {
+ // ----- Return
+ return $v_result;
+ }
+
+ // ----- Read the central directory informations
+ $v_central_dir = array();
+ if (($v_result = $this->privReadEndCentralDir($v_central_dir)) != 1)
+ {
+ $this->privCloseFd();
+ return $v_result;
+ }
+
+ // ----- Go to beginning of File
+ @rewind($this->zip_fd);
+
+ // ----- Open the archive_to_add file
+ if (($v_result=$p_archive_to_add->privOpenFd('rb')) != 1)
+ {
+ $this->privCloseFd();
+
+ // ----- Return
+ return $v_result;
+ }
+
+ // ----- Read the central directory informations
+ $v_central_dir_to_add = array();
+ if (($v_result = $p_archive_to_add->privReadEndCentralDir($v_central_dir_to_add)) != 1)
+ {
+ $this->privCloseFd();
+ $p_archive_to_add->privCloseFd();
+
+ return $v_result;
+ }
+
+ // ----- Go to beginning of File
+ @rewind($p_archive_to_add->zip_fd);
+
+ // ----- Creates a temporay file
+ $v_zip_temp_name = PCLZIP_TEMPORARY_DIR.uniqid('pclzip-').'.tmp';
+
+ // ----- Open the temporary file in write mode
+ if (($v_zip_temp_fd = @fopen($v_zip_temp_name, 'wb')) == 0)
+ {
+ $this->privCloseFd();
+ $p_archive_to_add->privCloseFd();
+
+ PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open temporary file \''.$v_zip_temp_name.'\' in binary write mode');
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Copy the files from the archive to the temporary file
+ // TBC : Here I should better append the file and go back to erase the central dir
+ $v_size = $v_central_dir['offset'];
+ while ($v_size != 0)
+ {
+ $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
+ $v_buffer = fread($this->zip_fd, $v_read_size);
+ @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
+ $v_size -= $v_read_size;
+ }
+
+ // ----- Copy the files from the archive_to_add into the temporary file
+ $v_size = $v_central_dir_to_add['offset'];
+ while ($v_size != 0)
+ {
+ $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
+ $v_buffer = fread($p_archive_to_add->zip_fd, $v_read_size);
+ @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
+ $v_size -= $v_read_size;
+ }
+
+ // ----- Store the offset of the central dir
+ $v_offset = @ftell($v_zip_temp_fd);
+
+ // ----- Copy the block of file headers from the old archive
+ $v_size = $v_central_dir['size'];
+ while ($v_size != 0)
+ {
+ $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
+ $v_buffer = @fread($this->zip_fd, $v_read_size);
+ @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
+ $v_size -= $v_read_size;
+ }
+
+ // ----- Copy the block of file headers from the archive_to_add
+ $v_size = $v_central_dir_to_add['size'];
+ while ($v_size != 0)
+ {
+ $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
+ $v_buffer = @fread($p_archive_to_add->zip_fd, $v_read_size);
+ @fwrite($v_zip_temp_fd, $v_buffer, $v_read_size);
+ $v_size -= $v_read_size;
+ }
+
+ // ----- Merge the file comments
+ $v_comment = $v_central_dir['comment'].' '.$v_central_dir_to_add['comment'];
+
+ // ----- Calculate the size of the (new) central header
+ $v_size = @ftell($v_zip_temp_fd)-$v_offset;
+
+ // ----- Swap the file descriptor
+ // Here is a trick : I swap the temporary fd with the zip fd, in order to use
+ // the following methods on the temporary fil and not the real archive fd
+ $v_swap = $this->zip_fd;
+ $this->zip_fd = $v_zip_temp_fd;
+ $v_zip_temp_fd = $v_swap;
+
+ // ----- Create the central dir footer
+ if (($v_result = $this->privWriteCentralHeader($v_central_dir['entries']+$v_central_dir_to_add['entries'], $v_size, $v_offset, $v_comment)) != 1)
+ {
+ $this->privCloseFd();
+ $p_archive_to_add->privCloseFd();
+ @fclose($v_zip_temp_fd);
+ $this->zip_fd = null;
+
+ // ----- Reset the file list
+ unset($v_header_list);
+
+ // ----- Return
+ return $v_result;
+ }
+
+ // ----- Swap back the file descriptor
+ $v_swap = $this->zip_fd;
+ $this->zip_fd = $v_zip_temp_fd;
+ $v_zip_temp_fd = $v_swap;
+
+ // ----- Close
+ $this->privCloseFd();
+ $p_archive_to_add->privCloseFd();
+
+ // ----- Close the temporary file
+ @fclose($v_zip_temp_fd);
+
+ // ----- Delete the zip file
+ // TBC : I should test the result ...
+ @unlink($this->zipname);
+
+ // ----- Rename the temporary file
+ // TBC : I should test the result ...
+ //@rename($v_zip_temp_name, $this->zipname);
+ PclZipUtilRename($v_zip_temp_name, $this->zipname);
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privDuplicate()
+ // Description :
+ // Parameters :
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function privDuplicate($p_archive_filename)
+ {
+ $v_result=1;
+
+ // ----- Look if the $p_archive_filename exists
+ if (!is_file($p_archive_filename))
+ {
+
+ // ----- Nothing to duplicate, so duplicate is a success.
+ $v_result = 1;
+
+ // ----- Return
+ return $v_result;
+ }
+
+ // ----- Open the zip file
+ if (($v_result=$this->privOpenFd('wb')) != 1)
+ {
+ // ----- Return
+ return $v_result;
+ }
+
+ // ----- Open the temporary file in write mode
+ if (($v_zip_temp_fd = @fopen($p_archive_filename, 'rb')) == 0)
+ {
+ $this->privCloseFd();
+
+ PclZip::privErrorLog(PCLZIP_ERR_READ_OPEN_FAIL, 'Unable to open archive file \''.$p_archive_filename.'\' in binary write mode');
+
+ // ----- Return
+ return PclZip::errorCode();
+ }
+
+ // ----- Copy the files from the archive to the temporary file
+ // TBC : Here I should better append the file and go back to erase the central dir
+ $v_size = filesize($p_archive_filename);
+ while ($v_size != 0)
+ {
+ $v_read_size = ($v_size < PCLZIP_READ_BLOCK_SIZE ? $v_size : PCLZIP_READ_BLOCK_SIZE);
+ $v_buffer = fread($v_zip_temp_fd, $v_read_size);
+ @fwrite($this->zip_fd, $v_buffer, $v_read_size);
+ $v_size -= $v_read_size;
+ }
+
+ // ----- Close
+ $this->privCloseFd();
+
+ // ----- Close the temporary file
+ @fclose($v_zip_temp_fd);
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privErrorLog()
+ // Description :
+ // Parameters :
+ // --------------------------------------------------------------------------------
+ function privErrorLog($p_error_code=0, $p_error_string='')
+ {
+ if (PCLZIP_ERROR_EXTERNAL == 1) {
+ PclError($p_error_code, $p_error_string);
+ }
+ else {
+ $this->error_code = $p_error_code;
+ $this->error_string = $p_error_string;
+ }
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privErrorReset()
+ // Description :
+ // Parameters :
+ // --------------------------------------------------------------------------------
+ function privErrorReset()
+ {
+ if (PCLZIP_ERROR_EXTERNAL == 1) {
+ PclErrorReset();
+ }
+ else {
+ $this->error_code = 0;
+ $this->error_string = '';
+ }
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privDisableMagicQuotes()
+ // Description :
+ // Parameters :
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function privDisableMagicQuotes()
+ {
+ $v_result=1;
+
+ // ----- Look if function exists
+ if ( (!function_exists("get_magic_quotes_runtime"))
+ || (!function_exists("set_magic_quotes_runtime"))) {
+ return $v_result;
+ }
+
+ // ----- Look if already done
+ if ($this->magic_quotes_status != -1) {
+ return $v_result;
+ }
+
+ // ----- Get and memorize the magic_quote value
+ $this->magic_quotes_status = @get_magic_quotes_runtime();
+
+ // ----- Disable magic_quotes
+ if ($this->magic_quotes_status == 1) {
+ @set_magic_quotes_runtime(0);
+ }
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : privSwapBackMagicQuotes()
+ // Description :
+ // Parameters :
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function privSwapBackMagicQuotes()
+ {
+ $v_result=1;
+
+ // ----- Look if function exists
+ if ( (!function_exists("get_magic_quotes_runtime"))
+ || (!function_exists("set_magic_quotes_runtime"))) {
+ return $v_result;
+ }
+
+ // ----- Look if something to do
+ if ($this->magic_quotes_status != -1) {
+ return $v_result;
+ }
+
+ // ----- Swap back magic_quotes
+ if ($this->magic_quotes_status == 1) {
+ @set_magic_quotes_runtime($this->magic_quotes_status);
+ }
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ }
+ // End of class
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : PclZipUtilPathReduction()
+ // Description :
+ // Parameters :
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function PclZipUtilPathReduction($p_dir)
+ {
+ $v_result = "";
+
+ // ----- Look for not empty path
+ if ($p_dir != "") {
+ // ----- Explode path by directory names
+ $v_list = explode("/", $p_dir);
+
+ // ----- Study directories from last to first
+ $v_skip = 0;
+ for ($i=sizeof($v_list)-1; $i>=0; $i--) {
+ // ----- Look for current path
+ if ($v_list[$i] == ".") {
+ // ----- Ignore this directory
+ // Should be the first $i=0, but no check is done
+ }
+ else if ($v_list[$i] == "..") {
+ $v_skip++;
+ }
+ else if ($v_list[$i] == "") {
+ // ----- First '/' i.e. root slash
+ if ($i == 0) {
+ $v_result = "/".$v_result;
+ if ($v_skip > 0) {
+ // ----- It is an invalid path, so the path is not modified
+ // TBC
+ $v_result = $p_dir;
+ $v_skip = 0;
+ }
+ }
+ // ----- Last '/' i.e. indicates a directory
+ else if ($i == (sizeof($v_list)-1)) {
+ $v_result = $v_list[$i];
+ }
+ // ----- Double '/' inside the path
+ else {
+ // ----- Ignore only the double '//' in path,
+ // but not the first and last '/'
+ }
+ }
+ else {
+ // ----- Look for item to skip
+ if ($v_skip > 0) {
+ $v_skip--;
+ }
+ else {
+ $v_result = $v_list[$i].($i!=(sizeof($v_list)-1)?"/".$v_result:"");
+ }
+ }
+ }
+
+ // ----- Look for skip
+ if ($v_skip > 0) {
+ while ($v_skip > 0) {
+ $v_result = '../'.$v_result;
+ $v_skip--;
+ }
+ }
+ }
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : PclZipUtilPathInclusion()
+ // Description :
+ // This function indicates if the path $p_path is under the $p_dir tree. Or,
+ // said in an other way, if the file or sub-dir $p_path is inside the dir
+ // $p_dir.
+ // The function indicates also if the path is exactly the same as the dir.
+ // This function supports path with duplicated '/' like '//', but does not
+ // support '.' or '..' statements.
+ // Parameters :
+ // Return Values :
+ // 0 if $p_path is not inside directory $p_dir
+ // 1 if $p_path is inside directory $p_dir
+ // 2 if $p_path is exactly the same as $p_dir
+ // --------------------------------------------------------------------------------
+ function PclZipUtilPathInclusion($p_dir, $p_path)
+ {
+ $v_result = 1;
+
+ // ----- Look for path beginning by ./
+ if ( ($p_dir == '.')
+ || ((strlen($p_dir) >=2) && (substr($p_dir, 0, 2) == './'))) {
+ $p_dir = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_dir, 1);
+ }
+ if ( ($p_path == '.')
+ || ((strlen($p_path) >=2) && (substr($p_path, 0, 2) == './'))) {
+ $p_path = PclZipUtilTranslateWinPath(getcwd(), FALSE).'/'.substr($p_path, 1);
+ }
+
+ // ----- Explode dir and path by directory separator
+ $v_list_dir = explode("/", $p_dir);
+ $v_list_dir_size = sizeof($v_list_dir);
+ $v_list_path = explode("/", $p_path);
+ $v_list_path_size = sizeof($v_list_path);
+
+ // ----- Study directories paths
+ $i = 0;
+ $j = 0;
+ while (($i < $v_list_dir_size) && ($j < $v_list_path_size) && ($v_result)) {
+
+ // ----- Look for empty dir (path reduction)
+ if ($v_list_dir[$i] == '') {
+ $i++;
+ continue;
+ }
+ if ($v_list_path[$j] == '') {
+ $j++;
+ continue;
+ }
+
+ // ----- Compare the items
+ if (($v_list_dir[$i] != $v_list_path[$j]) && ($v_list_dir[$i] != '') && ( $v_list_path[$j] != '')) {
+ $v_result = 0;
+ }
+
+ // ----- Next items
+ $i++;
+ $j++;
+ }
+
+ // ----- Look if everything seems to be the same
+ if ($v_result) {
+ // ----- Skip all the empty items
+ while (($j < $v_list_path_size) && ($v_list_path[$j] == '')) $j++;
+ while (($i < $v_list_dir_size) && ($v_list_dir[$i] == '')) $i++;
+
+ if (($i >= $v_list_dir_size) && ($j >= $v_list_path_size)) {
+ // ----- There are exactly the same
+ $v_result = 2;
+ }
+ else if ($i < $v_list_dir_size) {
+ // ----- The path is shorter than the dir
+ $v_result = 0;
+ }
+ }
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : PclZipUtilCopyBlock()
+ // Description :
+ // Parameters :
+ // $p_mode : read/write compression mode
+ // 0 : src & dest normal
+ // 1 : src gzip, dest normal
+ // 2 : src normal, dest gzip
+ // 3 : src & dest gzip
+ // Return Values :
+ // --------------------------------------------------------------------------------
+ function PclZipUtilCopyBlock($p_src, $p_dest, $p_size, $p_mode=0)
+ {
+ $v_result = 1;
+
+ if ($p_mode==0)
+ {
+ while ($p_size != 0)
+ {
+ $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
+ $v_buffer = @fread($p_src, $v_read_size);
+ @fwrite($p_dest, $v_buffer, $v_read_size);
+ $p_size -= $v_read_size;
+ }
+ }
+ else if ($p_mode==1)
+ {
+ while ($p_size != 0)
+ {
+ $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
+ $v_buffer = @gzread($p_src, $v_read_size);
+ @fwrite($p_dest, $v_buffer, $v_read_size);
+ $p_size -= $v_read_size;
+ }
+ }
+ else if ($p_mode==2)
+ {
+ while ($p_size != 0)
+ {
+ $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
+ $v_buffer = @fread($p_src, $v_read_size);
+ @gzwrite($p_dest, $v_buffer, $v_read_size);
+ $p_size -= $v_read_size;
+ }
+ }
+ else if ($p_mode==3)
+ {
+ while ($p_size != 0)
+ {
+ $v_read_size = ($p_size < PCLZIP_READ_BLOCK_SIZE ? $p_size : PCLZIP_READ_BLOCK_SIZE);
+ $v_buffer = @gzread($p_src, $v_read_size);
+ @gzwrite($p_dest, $v_buffer, $v_read_size);
+ $p_size -= $v_read_size;
+ }
+ }
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : PclZipUtilRename()
+ // Description :
+ // This function tries to do a simple rename() function. If it fails, it
+ // tries to copy the $p_src file in a new $p_dest file and then unlink the
+ // first one.
+ // Parameters :
+ // $p_src : Old filename
+ // $p_dest : New filename
+ // Return Values :
+ // 1 on success, 0 on failure.
+ // --------------------------------------------------------------------------------
+ function PclZipUtilRename($p_src, $p_dest)
+ {
+ $v_result = 1;
+
+ // ----- Try to rename the files
+ if (!@rename($p_src, $p_dest)) {
+
+ // ----- Try to copy & unlink the src
+ if (!@copy($p_src, $p_dest)) {
+ $v_result = 0;
+ }
+ else if (!@unlink($p_src)) {
+ $v_result = 0;
+ }
+ }
+
+ // ----- Return
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : PclZipUtilOptionText()
+ // Description :
+ // Translate option value in text. Mainly for debug purpose.
+ // Parameters :
+ // $p_option : the option value.
+ // Return Values :
+ // The option text value.
+ // --------------------------------------------------------------------------------
+ function PclZipUtilOptionText($p_option)
+ {
+
+ $v_list = get_defined_constants();
+ for (reset($v_list); $v_key = key($v_list); next($v_list)) {
+ $v_prefix = substr($v_key, 0, 10);
+ if (( ($v_prefix == 'PCLZIP_OPT')
+ || ($v_prefix == 'PCLZIP_CB_')
+ || ($v_prefix == 'PCLZIP_ATT'))
+ && ($v_list[$v_key] == $p_option)) {
+ return $v_key;
+ }
+ }
+
+ $v_result = 'Unknown';
+
+ return $v_result;
+ }
+ // --------------------------------------------------------------------------------
+
+ // --------------------------------------------------------------------------------
+ // Function : PclZipUtilTranslateWinPath()
+ // Description :
+ // Translate windows path by replacing '\' by '/' and optionally removing
+ // drive letter.
+ // Parameters :
+ // $p_path : path to translate.
+ // $p_remove_disk_letter : true | false
+ // Return Values :
+ // The path translated.
+ // --------------------------------------------------------------------------------
+ function PclZipUtilTranslateWinPath($p_path, $p_remove_disk_letter=true)
+ {
+ if (stristr(php_uname(), 'windows')) {
+ // ----- Look for potential disk letter
+ if (($p_remove_disk_letter) && (($v_position = strpos($p_path, ':')) != false)) {
+ $p_path = substr($p_path, $v_position+1);
+ }
+ // ----- Change potential windows directory separator
+ if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0,1) == '\\')) {
+ $p_path = strtr($p_path, '\\', '/');
+ }
+ }
+ return $p_path;
+ }
+ // --------------------------------------------------------------------------------
+
+
+?>
diff --git a/htdocs/includes/phpexcel/PHPExcel/Shared/PCLZip/readme.txt b/htdocs/includes/phpexcel/PHPExcel/Shared/PCLZip/readme.txt
index 6ed88394772..d1b11e25897 100644
--- a/htdocs/includes/phpexcel/PHPExcel/Shared/PCLZip/readme.txt
+++ b/htdocs/includes/phpexcel/PHPExcel/Shared/PCLZip/readme.txt
@@ -1,421 +1,421 @@
-// --------------------------------------------------------------------------------
-// PclZip 2.8.2 - readme.txt
-// --------------------------------------------------------------------------------
-// License GNU/LGPL - August 2009
-// Vincent Blavet - vincent@phpconcept.net
-// http://www.phpconcept.net
-// --------------------------------------------------------------------------------
-// $Id: readme.txt,v 1.60 2009/09/30 20:35:21 vblavet Exp $
-// --------------------------------------------------------------------------------
-
-
-
-0 - Sommaire
-============
- 1 - Introduction
- 2 - What's new
- 3 - Corrected bugs
- 4 - Known bugs or limitations
- 5 - License
- 6 - Warning
- 7 - Documentation
- 8 - Author
- 9 - Contribute
-
-1 - Introduction
-================
-
- PclZip is a library that allow you to manage a Zip archive.
-
- Full documentation about PclZip can be found here : http://www.phpconcept.net/pclzip
-
-2 - What's new
-==============
-
- Version 2.8.2 :
- - PCLZIP_CB_PRE_EXTRACT and PCLZIP_CB_POST_EXTRACT are now supported with
- extraction as a string (PCLZIP_OPT_EXTRACT_AS_STRING). The string
- can also be modified in the post-extract call back.
- **Bugs correction :
- - PCLZIP_OPT_REMOVE_ALL_PATH was not working correctly
- - Remove use of eval() and do direct call to callback functions
- - Correct support of 64bits systems (Thanks to WordPress team)
-
- Version 2.8.1 :
- - Move option PCLZIP_OPT_BY_EREG to PCLZIP_OPT_BY_PREG because ereg() is
- deprecated in PHP 5.3. When using option PCLZIP_OPT_BY_EREG, PclZip will
- automatically replace it by PCLZIP_OPT_BY_PREG.
-
- Version 2.8 :
- - Improve extraction of zip archive for large files by using temporary files
- This feature is working like the one defined in r2.7.
- Options are renamed : PCLZIP_OPT_TEMP_FILE_ON, PCLZIP_OPT_TEMP_FILE_OFF,
- PCLZIP_OPT_TEMP_FILE_THRESHOLD
- - Add a ratio constant PCLZIP_TEMPORARY_FILE_RATIO to configure the auto
- sense of temporary file use.
- - Bug correction : Reduce filepath in returned file list to remove ennoying
- './/' preambule in file path.
-
- Version 2.7 :
- - Improve creation of zip archive for large files :
- PclZip will now autosense the configured memory and use temporary files
- when large file is suspected.
- This feature can also ne triggered by manual options in create() and add()
- methods. 'PCLZIP_OPT_ADD_TEMP_FILE_ON' force the use of temporary files,
- 'PCLZIP_OPT_ADD_TEMP_FILE_OFF' disable the autosense technic,
- 'PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD' allow for configuration of a size
- threshold to use temporary files.
- Using "temporary files" rather than "memory" might take more time, but
- might give the ability to zip very large files :
- Tested on my win laptop with a 88Mo file :
- Zip "in-memory" : 18sec (max_execution_time=30, memory_limit=180Mo)
- Zip "tmporary-files" : 23sec (max_execution_time=30, memory_limit=30Mo)
- - Replace use of mktime() by time() to limit the E_STRICT error messages.
- - Bug correction : When adding files with full windows path (drive letter)
- PclZip is now working. Before, if the drive letter is not the default
- path, PclZip was not able to add the file.
-
- Version 2.6 :
- - Code optimisation
- - New attributes PCLZIP_ATT_FILE_COMMENT gives the ability to
- add a comment for a specific file. (Don't really know if this is usefull)
- - New attribute PCLZIP_ATT_FILE_CONTENT gives the ability to add a string
- as a file.
- - New attribute PCLZIP_ATT_FILE_MTIME modify the timestamp associated with
- a file.
- - Correct a bug. Files archived with a timestamp with 0h0m0s were extracted
- with current time
- - Add CRC value in the informations returned back for each file after an
- action.
- - Add missing closedir() statement.
- - When adding a folder, and removing the path of this folder, files were
- incorrectly added with a '/' at the beginning. Which means files are
- related to root in unix systems. Corrected.
- - Add conditional if before constant definition. This will allow users
- to redefine constants without changing the file, and then improve
- upgrade of pclzip code for new versions.
-
- Version 2.5 :
- - Introduce the ability to add file/folder with individual properties (file descriptor).
- This gives for example the ability to change the filename of a zipped file.
- . Able to add files individually
- . Able to change full name
- . Able to change short name
- . Compatible with global options
- - New attributes : PCLZIP_ATT_FILE_NAME, PCLZIP_ATT_FILE_NEW_SHORT_NAME, PCLZIP_ATT_FILE_NEW_FULL_NAME
- - New error code : PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE
- - Add a security control feature. PclZip can extract any file in any folder
- of a system. People may use this to upload a zip file and try to override
- a system file. The PCLZIP_OPT_EXTRACT_DIR_RESTRICTION will give the
- ability to forgive any directory transversal behavior.
- - New PCLZIP_OPT_EXTRACT_DIR_RESTRICTION : check extraction path
- - New error code : PCLZIP_ERR_DIRECTORY_RESTRICTION
- - Modification in PclZipUtilPathInclusion() : dir and path beginning with ./ will be prepend
- by current path (getcwd())
-
- Version 2.4 :
- - Code improvment : try to speed up the code by removing unusefull call to pack()
- - Correct bug in delete() : delete() should be called with no argument. This was not
- the case in 2.3. This is corrected in 2.4.
- - Correct a bug in path_inclusion function. When the path has several '../../', the
- result was bad.
- - Add a check for magic_quotes_runtime configuration. If enabled, PclZip will
- disable it while working and det it back to its original value.
- This resolve a lots of bad formated archive errors.
- - Bug correction : PclZip now correctly unzip file in some specific situation,
- when compressed content has same size as uncompressed content.
- - Bug correction : When selecting option 'PCLZIP_OPT_REMOVE_ALL_PATH',
- directories are not any more created.
- - Code improvment : correct unclosed opendir(), better handling of . and .. in
- loops.
-
-
- Version 2.3 :
- - Correct a bug with PHP5 : affecting the value 0xFE49FFE0 to a variable does not
- give the same result in PHP4 and PHP5 ....
-
- Version 2.2 :
- - Try development of PCLZIP_OPT_CRYPT .....
- However this becomes to a stop. To crypt/decrypt I need to multiply 2 long integers,
- the result (greater than a long) is not supported by PHP. Even the use of bcmath
- functions does not help. I did not find yet a solution ...;
- - Add missing '/' at end of directory entries
- - Check is a file is encrypted or not. Returns status 'unsupported_encryption' and/or
- error code PCLZIP_ERR_UNSUPPORTED_ENCRYPTION.
- - Corrected : Bad "version need to extract" field in local file header
- - Add private method privCheckFileHeaders() in order to check local and central
- file headers. PclZip is now supporting purpose bit flag bit 3. Purpose bit flag bit 3 gives
- the ability to have a local file header without size, compressed size and crc filled.
- - Add a generic status 'error' for file status
- - Add control of compression type. PclZip only support deflate compression method.
- Before v2.2, PclZip does not check the compression method used in an archive while
- extracting. With v2.2 PclZip returns a new error status for a file using an unsupported
- compression method. New status is "unsupported_compression". New error code is
- PCLZIP_ERR_UNSUPPORTED_COMPRESSION.
- - Add optional attribute PCLZIP_OPT_STOP_ON_ERROR. This will stop the extract of files
- when errors like 'a folder with same name exists' or 'a newer file exists' or
- 'a write protected file' exists, rather than set a status for the concerning file
- and resume the extract of the zip.
- - Add optional attribute PCLZIP_OPT_REPLACE_NEWER. This will force, during an extract' the
- replacement of the file, even if a newer version of the file exists.
- Note that today if a file with the same name already exists but is older it will be
- replaced by the extracted one.
- - Improve PclZipUtilOption()
- - Support of zip archive with trailing bytes. Before 2.2, PclZip checks that the central
- directory structure is the last data in the archive. Crypt encryption/decryption of
- zip archive put trailing 0 bytes after decryption. PclZip is now supporting this.
-
- Version 2.1 :
- - Add the ability to abort the extraction by using a user callback function.
- The user can now return the value '2' in its callback which indicates to stop the
- extraction. For a pre call-back extract is stopped before the extration of the current
- file. For a post call back, the extraction is stopped after.
- - Add the ability to extract a file (or several files) directly in the standard output.
- This is done by the new parameter PCLZIP_OPT_EXTRACT_IN_OUTPUT with method extract().
- - Add support for parameters PCLZIP_OPT_COMMENT, PCLZIP_OPT_ADD_COMMENT,
- PCLZIP_OPT_PREPEND_COMMENT. This will create, replace, add, or prepend comments
- in the zip archive.
- - When merging two archives, the comments are not any more lost, but merged, with a
- blank space separator.
- - Corrected bug : Files are not deleted when all files are asked to be deleted.
- - Corrected bug : Folders with name '0' made PclZip to abort the create or add feature.
-
-
- Version 2.0 :
- ***** Warning : Some new features may break the backward compatibility for your scripts.
- Please carefully read the readme file.
- - Add the ability to delete by Index, name and regular expression. This feature is
- performed by the method delete(), which uses the optional parameters
- PCLZIP_OPT_BY_INDEX, PCLZIP_OPT_BY_NAME, PCLZIP_OPT_BY_EREG or PCLZIP_OPT_BY_PREG.
- - Add the ability to extract by regular expression. To extract by regexp you must use the method
- extract(), with the option PCLZIP_OPT_BY_EREG or PCLZIP_OPT_BY_PREG
- (depending if you want to use ereg() or preg_match() syntax) followed by the
- regular expression pattern.
- - Add the ability to extract by index, directly with the extract() method. This is a
- code improvment of the extractByIndex() method.
- - Add the ability to extract by name. To extract by name you must use the method
- extract(), with the option PCLZIP_OPT_BY_NAME followed by the filename to
- extract or an array of filenames to extract. To extract all a folder, use the folder
- name rather than the filename with a '/' at the end.
- - Add the ability to add files without compression. This is done with a new attribute
- which is PCLZIP_OPT_NO_COMPRESSION.
- - Add the attribute PCLZIP_OPT_EXTRACT_AS_STRING, which allow to extract a file directly
- in a string without using any file (or temporary file).
- - Add constant PCLZIP_SEPARATOR for static configuration of filename separators in a single string.
- The default separator is now a comma (,) and not any more a blank space.
- THIS BREAK THE BACKWARD COMPATIBILITY : Please check if this may have an impact with
- your script.
- - Improve algorythm performance by removing the use of temporary files when adding or
- extracting files in an archive.
- - Add (correct) detection of empty filename zipping. This can occurs when the removed
- path is the same
- as a zipped dir. The dir is not zipped (['status'] = filtered), only its content.
- - Add better support for windows paths (thanks for help from manus@manusfreedom.com).
- - Corrected bug : When the archive file already exists with size=0, the add() method
- fails. Corrected in 2.0.
- - Remove the use of OS_WINDOWS constant. Use php_uname() function rather.
- - Control the order of index ranges in extract by index feature.
- - Change the internal management of folders (better handling of internal flag).
-
-
- Version 1.3 :
- - Removing the double include check. This is now done by include_once() and require_once()
- PHP directives.
- - Changing the error handling mecanism : Remove the use of an external error library.
- The former PclError...() functions are replaced by internal equivalent methods.
- By changing the environment variable PCLZIP_ERROR_EXTERNAL you can still use the former library.
- Introducing the use of constants for error codes rather than integer values. This will help
- in futur improvment.
- Introduction of error handling functions like errorCode(), errorName() and errorInfo().
- - Remove the deprecated use of calling function with arguments passed by reference.
- - Add the calling of extract(), extractByIndex(), create() and add() functions
- with variable options rather than fixed arguments.
- - Add the ability to remove all the file path while extracting or adding,
- without any need to specify the path to remove.
- This is available for extract(), extractByIndex(), create() and add() functionS by using
- the new variable options parameters :
- - PCLZIP_OPT_REMOVE_ALL_PATH : by indicating this option while calling the fct.
- - Ability to change the mode of a file after the extraction (chmod()).
- This is available for extract() and extractByIndex() functionS by using
- the new variable options parameters.
- - PCLZIP_OPT_SET_CHMOD : by setting the value of this option.
- - Ability to definition call-back options. These call-back will be called during the adding,
- or the extracting of file (extract(), extractByIndex(), create() and add() functions) :
- - PCLZIP_CB_PRE_EXTRACT : will be called before each extraction of a file. The user
- can trigerred the change the filename of the extracted file. The user can triggered the
- skip of the extraction. This is adding a 'skipped' status in the file list result value.
- - PCLZIP_CB_POST_EXTRACT : will be called after each extraction of a file.
- Nothing can be triggered from that point.
- - PCLZIP_CB_PRE_ADD : will be called before each add of a file. The user
- can trigerred the change the stored filename of the added file. The user can triggered the
- skip of the add. This is adding a 'skipped' status in the file list result value.
- - PCLZIP_CB_POST_ADD : will be called after each add of a file.
- Nothing can be triggered from that point.
- - Two status are added in the file list returned as function result : skipped & filename_too_long
- 'skipped' is used when a call-back function ask for skipping the file.
- 'filename_too_long' is used while adding a file with a too long filename to archive (the file is
- not added)
- - Adding the function PclZipUtilPathInclusion(), that check the inclusion of a path into
- a directory.
- - Add a check of the presence of the archive file before some actions (like list, ...)
- - Add the initialisation of field "index" in header array. This means that by
- default index will be -1 when not explicitly set by the methods.
-
- Version 1.2 :
- - Adding a duplicate function.
- - Adding a merge function. The merge function is a "quick merge" function,
- it just append the content of an archive at the end of the first one. There
- is no check for duplicate files or more recent files.
- - Improve the search of the central directory end.
-
- Version 1.1.2 :
-
- - Changing the license of PclZip. PclZip is now released under the GNU / LGPL license
- (see License section).
- - Adding the optional support of a static temporary directory. You will need to configure
- the constant PCLZIP_TEMPORARY_DIR if you want to use this feature.
- - Improving the rename() function. In some cases rename() does not work (different
- Filesystems), so it will be replaced by a copy() + unlink() functions.
-
- Version 1.1.1 :
-
- - Maintenance release, no new feature.
-
- Version 1.1 :
-
- - New method Add() : adding files in the archive
- - New method ExtractByIndex() : partial extract of the archive, files are identified by
- their index in the archive
- - New method DeleteByIndex() : delete some files/folder entries from the archive,
- files are identified by their index in the archive.
- - Adding a test of the zlib extension presence. If not present abort the script.
-
- Version 1.0.1 :
-
- - No new feature
-
-
-3 - Corrected bugs
-==================
-
- Corrected in Version 2.0 :
- - Corrected : During an extraction, if a call-back fucntion is used and try to skip
- a file, all the extraction process is stopped.
-
- Corrected in Version 1.3 :
- - Corrected : Support of static synopsis for method extract() is broken.
- - Corrected : invalid size of archive content field (0xFF) should be (0xFFFF).
- - Corrected : When an extract is done with a remove_path parameter, the entry for
- the directory with exactly the same path is not skipped/filtered.
- - Corrected : extractByIndex() and deleteByIndex() were not managing index in the
- right way. For example indexes '1,3-5,11' will only extract files 1 and 11. This
- is due to a sort of the index resulting table that puts 11 before 3-5 (sort on
- string and not interger). The sort is temporarilly removed, this means that
- you must provide a sorted list of index ranges.
-
- Corrected in Version 1.2 :
-
- - Nothing.
-
- Corrected in Version 1.1.2 :
-
- - Corrected : Winzip is unable to delete or add new files in a PclZip created archives.
-
- Corrected in Version 1.1.1 :
-
- - Corrected : When archived file is not compressed (0% compression), the
- extract method fails.
-
- Corrected in Version 1.1 :
-
- - Corrected : Adding a complete tree of folder may result in a bad archive
- creation.
-
- Corrected in Version 1.0.1 :
-
- - Corrected : Error while compressing files greater than PCLZIP_READ_BLOCK_SIZE (default=1024).
-
-
-4 - Known bugs or limitations
-=============================
-
- Please publish bugs reports in SourceForge :
- http://sourceforge.net/tracker/?group_id=40254&atid=427564
-
- In Version 2.x :
- - PclZip does only support file uncompressed or compressed with deflate (compression method 8)
- - PclZip does not support password protected zip archive
- - Some concern were seen when changing mtime of a file while archiving.
- Seems to be linked to Daylight Saving Time (PclTest_changing_mtime).
-
- In Version 1.2 :
-
- - merge() methods does not check for duplicate files or last date of modifications.
-
- In Version 1.1 :
-
- - Limitation : Using 'extract' fields in the file header in the zip archive is not supported.
- - WinZip is unable to delete a single file in a PclZip created archive. It is also unable to
- add a file in a PclZip created archive. (Corrected in v.1.2)
-
- In Version 1.0.1 :
-
- - Adding a complete tree of folder may result in a bad archive
- creation. (Corrected in V.1.1).
- - Path given to methods must be in the unix format (/) and not the Windows format (\).
- Workaround : Use only / directory separators.
- - PclZip is using temporary files that are sometime the name of the file with a .tmp or .gz
- added suffix. Files with these names may already exist and may be overwritten.
- Workaround : none.
- - PclZip does not check if the zlib extension is present. If it is absent, the zip
- file is not created and the lib abort without warning.
- Workaround : enable the zlib extension on the php install
-
- In Version 1.0 :
-
- - Error while compressing files greater than PCLZIP_READ_BLOCK_SIZE (default=1024).
- (Corrected in v.1.0.1)
- - Limitation : Multi-disk zip archive are not supported.
-
-
-5 - License
-===========
-
- Since version 1.1.2, PclZip Library is released under GNU/LGPL license.
- This library is free, so you can use it at no cost.
-
- HOWEVER, if you release a script, an application, a library or any kind of
- code using PclZip library (or a part of it), YOU MUST :
- - Indicate in the documentation (or a readme file), that your work
- uses PclZip Library, and make a reference to the author and the web site
- http://www.phpconcept.net
- - Gives the ability to the final user to update the PclZip libary.
-
- I will also appreciate that you send me a mail (vincent@phpconcept.net), just to
- be aware that someone is using PclZip.
-
- For more information about GNU/LGPL license : http://www.gnu.org
-
-6 - Warning
-=================
-
- This library and the associated files are non commercial, non professional work.
- It should not have unexpected results. However if any damage is caused by this software
- the author can not be responsible.
- The use of this software is at the risk of the user.
-
-7 - Documentation
-=================
- PclZip User Manuel is available in English on PhpConcept : http://www.phpconcept.net/pclzip/man/en/index.php
- A Russian translation was done by Feskov Kuzma : http://php.russofile.ru/ru/authors/unsort/zip/
-
-8 - Author
-==========
-
- This software was written by Vincent Blavet (vincent@phpconcept.net) on its leasure time.
-
-9 - Contribute
-==============
- If you want to contribute to the development of PclZip, please contact vincent@phpconcept.net.
- If you can help in financing PhpConcept hosting service, please go to
- http://www.phpconcept.net/soutien.php
+// --------------------------------------------------------------------------------
+// PclZip 2.8.2 - readme.txt
+// --------------------------------------------------------------------------------
+// License GNU/LGPL - August 2009
+// Vincent Blavet - vincent@phpconcept.net
+// http://www.phpconcept.net
+// --------------------------------------------------------------------------------
+// $Id: readme.txt,v 1.60 2009/09/30 20:35:21 vblavet Exp $
+// --------------------------------------------------------------------------------
+
+
+
+0 - Sommaire
+============
+ 1 - Introduction
+ 2 - What's new
+ 3 - Corrected bugs
+ 4 - Known bugs or limitations
+ 5 - License
+ 6 - Warning
+ 7 - Documentation
+ 8 - Author
+ 9 - Contribute
+
+1 - Introduction
+================
+
+ PclZip is a library that allow you to manage a Zip archive.
+
+ Full documentation about PclZip can be found here : http://www.phpconcept.net/pclzip
+
+2 - What's new
+==============
+
+ Version 2.8.2 :
+ - PCLZIP_CB_PRE_EXTRACT and PCLZIP_CB_POST_EXTRACT are now supported with
+ extraction as a string (PCLZIP_OPT_EXTRACT_AS_STRING). The string
+ can also be modified in the post-extract call back.
+ **Bugs correction :
+ - PCLZIP_OPT_REMOVE_ALL_PATH was not working correctly
+ - Remove use of eval() and do direct call to callback functions
+ - Correct support of 64bits systems (Thanks to WordPress team)
+
+ Version 2.8.1 :
+ - Move option PCLZIP_OPT_BY_EREG to PCLZIP_OPT_BY_PREG because ereg() is
+ deprecated in PHP 5.3. When using option PCLZIP_OPT_BY_EREG, PclZip will
+ automatically replace it by PCLZIP_OPT_BY_PREG.
+
+ Version 2.8 :
+ - Improve extraction of zip archive for large files by using temporary files
+ This feature is working like the one defined in r2.7.
+ Options are renamed : PCLZIP_OPT_TEMP_FILE_ON, PCLZIP_OPT_TEMP_FILE_OFF,
+ PCLZIP_OPT_TEMP_FILE_THRESHOLD
+ - Add a ratio constant PCLZIP_TEMPORARY_FILE_RATIO to configure the auto
+ sense of temporary file use.
+ - Bug correction : Reduce filepath in returned file list to remove ennoying
+ './/' preambule in file path.
+
+ Version 2.7 :
+ - Improve creation of zip archive for large files :
+ PclZip will now autosense the configured memory and use temporary files
+ when large file is suspected.
+ This feature can also ne triggered by manual options in create() and add()
+ methods. 'PCLZIP_OPT_ADD_TEMP_FILE_ON' force the use of temporary files,
+ 'PCLZIP_OPT_ADD_TEMP_FILE_OFF' disable the autosense technic,
+ 'PCLZIP_OPT_ADD_TEMP_FILE_THRESHOLD' allow for configuration of a size
+ threshold to use temporary files.
+ Using "temporary files" rather than "memory" might take more time, but
+ might give the ability to zip very large files :
+ Tested on my win laptop with a 88Mo file :
+ Zip "in-memory" : 18sec (max_execution_time=30, memory_limit=180Mo)
+ Zip "tmporary-files" : 23sec (max_execution_time=30, memory_limit=30Mo)
+ - Replace use of mktime() by time() to limit the E_STRICT error messages.
+ - Bug correction : When adding files with full windows path (drive letter)
+ PclZip is now working. Before, if the drive letter is not the default
+ path, PclZip was not able to add the file.
+
+ Version 2.6 :
+ - Code optimisation
+ - New attributes PCLZIP_ATT_FILE_COMMENT gives the ability to
+ add a comment for a specific file. (Don't really know if this is usefull)
+ - New attribute PCLZIP_ATT_FILE_CONTENT gives the ability to add a string
+ as a file.
+ - New attribute PCLZIP_ATT_FILE_MTIME modify the timestamp associated with
+ a file.
+ - Correct a bug. Files archived with a timestamp with 0h0m0s were extracted
+ with current time
+ - Add CRC value in the informations returned back for each file after an
+ action.
+ - Add missing closedir() statement.
+ - When adding a folder, and removing the path of this folder, files were
+ incorrectly added with a '/' at the beginning. Which means files are
+ related to root in unix systems. Corrected.
+ - Add conditional if before constant definition. This will allow users
+ to redefine constants without changing the file, and then improve
+ upgrade of pclzip code for new versions.
+
+ Version 2.5 :
+ - Introduce the ability to add file/folder with individual properties (file descriptor).
+ This gives for example the ability to change the filename of a zipped file.
+ . Able to add files individually
+ . Able to change full name
+ . Able to change short name
+ . Compatible with global options
+ - New attributes : PCLZIP_ATT_FILE_NAME, PCLZIP_ATT_FILE_NEW_SHORT_NAME, PCLZIP_ATT_FILE_NEW_FULL_NAME
+ - New error code : PCLZIP_ERR_INVALID_ATTRIBUTE_VALUE
+ - Add a security control feature. PclZip can extract any file in any folder
+ of a system. People may use this to upload a zip file and try to override
+ a system file. The PCLZIP_OPT_EXTRACT_DIR_RESTRICTION will give the
+ ability to forgive any directory transversal behavior.
+ - New PCLZIP_OPT_EXTRACT_DIR_RESTRICTION : check extraction path
+ - New error code : PCLZIP_ERR_DIRECTORY_RESTRICTION
+ - Modification in PclZipUtilPathInclusion() : dir and path beginning with ./ will be prepend
+ by current path (getcwd())
+
+ Version 2.4 :
+ - Code improvment : try to speed up the code by removing unusefull call to pack()
+ - Correct bug in delete() : delete() should be called with no argument. This was not
+ the case in 2.3. This is corrected in 2.4.
+ - Correct a bug in path_inclusion function. When the path has several '../../', the
+ result was bad.
+ - Add a check for magic_quotes_runtime configuration. If enabled, PclZip will
+ disable it while working and det it back to its original value.
+ This resolve a lots of bad formated archive errors.
+ - Bug correction : PclZip now correctly unzip file in some specific situation,
+ when compressed content has same size as uncompressed content.
+ - Bug correction : When selecting option 'PCLZIP_OPT_REMOVE_ALL_PATH',
+ directories are not any more created.
+ - Code improvment : correct unclosed opendir(), better handling of . and .. in
+ loops.
+
+
+ Version 2.3 :
+ - Correct a bug with PHP5 : affecting the value 0xFE49FFE0 to a variable does not
+ give the same result in PHP4 and PHP5 ....
+
+ Version 2.2 :
+ - Try development of PCLZIP_OPT_CRYPT .....
+ However this becomes to a stop. To crypt/decrypt I need to multiply 2 long integers,
+ the result (greater than a long) is not supported by PHP. Even the use of bcmath
+ functions does not help. I did not find yet a solution ...;
+ - Add missing '/' at end of directory entries
+ - Check is a file is encrypted or not. Returns status 'unsupported_encryption' and/or
+ error code PCLZIP_ERR_UNSUPPORTED_ENCRYPTION.
+ - Corrected : Bad "version need to extract" field in local file header
+ - Add private method privCheckFileHeaders() in order to check local and central
+ file headers. PclZip is now supporting purpose bit flag bit 3. Purpose bit flag bit 3 gives
+ the ability to have a local file header without size, compressed size and crc filled.
+ - Add a generic status 'error' for file status
+ - Add control of compression type. PclZip only support deflate compression method.
+ Before v2.2, PclZip does not check the compression method used in an archive while
+ extracting. With v2.2 PclZip returns a new error status for a file using an unsupported
+ compression method. New status is "unsupported_compression". New error code is
+ PCLZIP_ERR_UNSUPPORTED_COMPRESSION.
+ - Add optional attribute PCLZIP_OPT_STOP_ON_ERROR. This will stop the extract of files
+ when errors like 'a folder with same name exists' or 'a newer file exists' or
+ 'a write protected file' exists, rather than set a status for the concerning file
+ and resume the extract of the zip.
+ - Add optional attribute PCLZIP_OPT_REPLACE_NEWER. This will force, during an extract' the
+ replacement of the file, even if a newer version of the file exists.
+ Note that today if a file with the same name already exists but is older it will be
+ replaced by the extracted one.
+ - Improve PclZipUtilOption()
+ - Support of zip archive with trailing bytes. Before 2.2, PclZip checks that the central
+ directory structure is the last data in the archive. Crypt encryption/decryption of
+ zip archive put trailing 0 bytes after decryption. PclZip is now supporting this.
+
+ Version 2.1 :
+ - Add the ability to abort the extraction by using a user callback function.
+ The user can now return the value '2' in its callback which indicates to stop the
+ extraction. For a pre call-back extract is stopped before the extration of the current
+ file. For a post call back, the extraction is stopped after.
+ - Add the ability to extract a file (or several files) directly in the standard output.
+ This is done by the new parameter PCLZIP_OPT_EXTRACT_IN_OUTPUT with method extract().
+ - Add support for parameters PCLZIP_OPT_COMMENT, PCLZIP_OPT_ADD_COMMENT,
+ PCLZIP_OPT_PREPEND_COMMENT. This will create, replace, add, or prepend comments
+ in the zip archive.
+ - When merging two archives, the comments are not any more lost, but merged, with a
+ blank space separator.
+ - Corrected bug : Files are not deleted when all files are asked to be deleted.
+ - Corrected bug : Folders with name '0' made PclZip to abort the create or add feature.
+
+
+ Version 2.0 :
+ ***** Warning : Some new features may break the backward compatibility for your scripts.
+ Please carefully read the readme file.
+ - Add the ability to delete by Index, name and regular expression. This feature is
+ performed by the method delete(), which uses the optional parameters
+ PCLZIP_OPT_BY_INDEX, PCLZIP_OPT_BY_NAME, PCLZIP_OPT_BY_EREG or PCLZIP_OPT_BY_PREG.
+ - Add the ability to extract by regular expression. To extract by regexp you must use the method
+ extract(), with the option PCLZIP_OPT_BY_EREG or PCLZIP_OPT_BY_PREG
+ (depending if you want to use ereg() or preg_match() syntax) followed by the
+ regular expression pattern.
+ - Add the ability to extract by index, directly with the extract() method. This is a
+ code improvment of the extractByIndex() method.
+ - Add the ability to extract by name. To extract by name you must use the method
+ extract(), with the option PCLZIP_OPT_BY_NAME followed by the filename to
+ extract or an array of filenames to extract. To extract all a folder, use the folder
+ name rather than the filename with a '/' at the end.
+ - Add the ability to add files without compression. This is done with a new attribute
+ which is PCLZIP_OPT_NO_COMPRESSION.
+ - Add the attribute PCLZIP_OPT_EXTRACT_AS_STRING, which allow to extract a file directly
+ in a string without using any file (or temporary file).
+ - Add constant PCLZIP_SEPARATOR for static configuration of filename separators in a single string.
+ The default separator is now a comma (,) and not any more a blank space.
+ THIS BREAK THE BACKWARD COMPATIBILITY : Please check if this may have an impact with
+ your script.
+ - Improve algorythm performance by removing the use of temporary files when adding or
+ extracting files in an archive.
+ - Add (correct) detection of empty filename zipping. This can occurs when the removed
+ path is the same
+ as a zipped dir. The dir is not zipped (['status'] = filtered), only its content.
+ - Add better support for windows paths (thanks for help from manus@manusfreedom.com).
+ - Corrected bug : When the archive file already exists with size=0, the add() method
+ fails. Corrected in 2.0.
+ - Remove the use of OS_WINDOWS constant. Use php_uname() function rather.
+ - Control the order of index ranges in extract by index feature.
+ - Change the internal management of folders (better handling of internal flag).
+
+
+ Version 1.3 :
+ - Removing the double include check. This is now done by include_once() and require_once()
+ PHP directives.
+ - Changing the error handling mecanism : Remove the use of an external error library.
+ The former PclError...() functions are replaced by internal equivalent methods.
+ By changing the environment variable PCLZIP_ERROR_EXTERNAL you can still use the former library.
+ Introducing the use of constants for error codes rather than integer values. This will help
+ in futur improvment.
+ Introduction of error handling functions like errorCode(), errorName() and errorInfo().
+ - Remove the deprecated use of calling function with arguments passed by reference.
+ - Add the calling of extract(), extractByIndex(), create() and add() functions
+ with variable options rather than fixed arguments.
+ - Add the ability to remove all the file path while extracting or adding,
+ without any need to specify the path to remove.
+ This is available for extract(), extractByIndex(), create() and add() functionS by using
+ the new variable options parameters :
+ - PCLZIP_OPT_REMOVE_ALL_PATH : by indicating this option while calling the fct.
+ - Ability to change the mode of a file after the extraction (chmod()).
+ This is available for extract() and extractByIndex() functionS by using
+ the new variable options parameters.
+ - PCLZIP_OPT_SET_CHMOD : by setting the value of this option.
+ - Ability to definition call-back options. These call-back will be called during the adding,
+ or the extracting of file (extract(), extractByIndex(), create() and add() functions) :
+ - PCLZIP_CB_PRE_EXTRACT : will be called before each extraction of a file. The user
+ can trigerred the change the filename of the extracted file. The user can triggered the
+ skip of the extraction. This is adding a 'skipped' status in the file list result value.
+ - PCLZIP_CB_POST_EXTRACT : will be called after each extraction of a file.
+ Nothing can be triggered from that point.
+ - PCLZIP_CB_PRE_ADD : will be called before each add of a file. The user
+ can trigerred the change the stored filename of the added file. The user can triggered the
+ skip of the add. This is adding a 'skipped' status in the file list result value.
+ - PCLZIP_CB_POST_ADD : will be called after each add of a file.
+ Nothing can be triggered from that point.
+ - Two status are added in the file list returned as function result : skipped & filename_too_long
+ 'skipped' is used when a call-back function ask for skipping the file.
+ 'filename_too_long' is used while adding a file with a too long filename to archive (the file is
+ not added)
+ - Adding the function PclZipUtilPathInclusion(), that check the inclusion of a path into
+ a directory.
+ - Add a check of the presence of the archive file before some actions (like list, ...)
+ - Add the initialisation of field "index" in header array. This means that by
+ default index will be -1 when not explicitly set by the methods.
+
+ Version 1.2 :
+ - Adding a duplicate function.
+ - Adding a merge function. The merge function is a "quick merge" function,
+ it just append the content of an archive at the end of the first one. There
+ is no check for duplicate files or more recent files.
+ - Improve the search of the central directory end.
+
+ Version 1.1.2 :
+
+ - Changing the license of PclZip. PclZip is now released under the GNU / LGPL license
+ (see License section).
+ - Adding the optional support of a static temporary directory. You will need to configure
+ the constant PCLZIP_TEMPORARY_DIR if you want to use this feature.
+ - Improving the rename() function. In some cases rename() does not work (different
+ Filesystems), so it will be replaced by a copy() + unlink() functions.
+
+ Version 1.1.1 :
+
+ - Maintenance release, no new feature.
+
+ Version 1.1 :
+
+ - New method Add() : adding files in the archive
+ - New method ExtractByIndex() : partial extract of the archive, files are identified by
+ their index in the archive
+ - New method DeleteByIndex() : delete some files/folder entries from the archive,
+ files are identified by their index in the archive.
+ - Adding a test of the zlib extension presence. If not present abort the script.
+
+ Version 1.0.1 :
+
+ - No new feature
+
+
+3 - Corrected bugs
+==================
+
+ Corrected in Version 2.0 :
+ - Corrected : During an extraction, if a call-back fucntion is used and try to skip
+ a file, all the extraction process is stopped.
+
+ Corrected in Version 1.3 :
+ - Corrected : Support of static synopsis for method extract() is broken.
+ - Corrected : invalid size of archive content field (0xFF) should be (0xFFFF).
+ - Corrected : When an extract is done with a remove_path parameter, the entry for
+ the directory with exactly the same path is not skipped/filtered.
+ - Corrected : extractByIndex() and deleteByIndex() were not managing index in the
+ right way. For example indexes '1,3-5,11' will only extract files 1 and 11. This
+ is due to a sort of the index resulting table that puts 11 before 3-5 (sort on
+ string and not interger). The sort is temporarilly removed, this means that
+ you must provide a sorted list of index ranges.
+
+ Corrected in Version 1.2 :
+
+ - Nothing.
+
+ Corrected in Version 1.1.2 :
+
+ - Corrected : Winzip is unable to delete or add new files in a PclZip created archives.
+
+ Corrected in Version 1.1.1 :
+
+ - Corrected : When archived file is not compressed (0% compression), the
+ extract method fails.
+
+ Corrected in Version 1.1 :
+
+ - Corrected : Adding a complete tree of folder may result in a bad archive
+ creation.
+
+ Corrected in Version 1.0.1 :
+
+ - Corrected : Error while compressing files greater than PCLZIP_READ_BLOCK_SIZE (default=1024).
+
+
+4 - Known bugs or limitations
+=============================
+
+ Please publish bugs reports in SourceForge :
+ http://sourceforge.net/tracker/?group_id=40254&atid=427564
+
+ In Version 2.x :
+ - PclZip does only support file uncompressed or compressed with deflate (compression method 8)
+ - PclZip does not support password protected zip archive
+ - Some concern were seen when changing mtime of a file while archiving.
+ Seems to be linked to Daylight Saving Time (PclTest_changing_mtime).
+
+ In Version 1.2 :
+
+ - merge() methods does not check for duplicate files or last date of modifications.
+
+ In Version 1.1 :
+
+ - Limitation : Using 'extract' fields in the file header in the zip archive is not supported.
+ - WinZip is unable to delete a single file in a PclZip created archive. It is also unable to
+ add a file in a PclZip created archive. (Corrected in v.1.2)
+
+ In Version 1.0.1 :
+
+ - Adding a complete tree of folder may result in a bad archive
+ creation. (Corrected in V.1.1).
+ - Path given to methods must be in the unix format (/) and not the Windows format (\).
+ Workaround : Use only / directory separators.
+ - PclZip is using temporary files that are sometime the name of the file with a .tmp or .gz
+ added suffix. Files with these names may already exist and may be overwritten.
+ Workaround : none.
+ - PclZip does not check if the zlib extension is present. If it is absent, the zip
+ file is not created and the lib abort without warning.
+ Workaround : enable the zlib extension on the php install
+
+ In Version 1.0 :
+
+ - Error while compressing files greater than PCLZIP_READ_BLOCK_SIZE (default=1024).
+ (Corrected in v.1.0.1)
+ - Limitation : Multi-disk zip archive are not supported.
+
+
+5 - License
+===========
+
+ Since version 1.1.2, PclZip Library is released under GNU/LGPL license.
+ This library is free, so you can use it at no cost.
+
+ HOWEVER, if you release a script, an application, a library or any kind of
+ code using PclZip library (or a part of it), YOU MUST :
+ - Indicate in the documentation (or a readme file), that your work
+ uses PclZip Library, and make a reference to the author and the web site
+ http://www.phpconcept.net
+ - Gives the ability to the final user to update the PclZip libary.
+
+ I will also appreciate that you send me a mail (vincent@phpconcept.net), just to
+ be aware that someone is using PclZip.
+
+ For more information about GNU/LGPL license : http://www.gnu.org
+
+6 - Warning
+=================
+
+ This library and the associated files are non commercial, non professional work.
+ It should not have unexpected results. However if any damage is caused by this software
+ the author can not be responsible.
+ The use of this software is at the risk of the user.
+
+7 - Documentation
+=================
+ PclZip User Manuel is available in English on PhpConcept : http://www.phpconcept.net/pclzip/man/en/index.php
+ A Russian translation was done by Feskov Kuzma : http://php.russofile.ru/ru/authors/unsort/zip/
+
+8 - Author
+==========
+
+ This software was written by Vincent Blavet (vincent@phpconcept.net) on its leasure time.
+
+9 - Contribute
+==============
+ If you want to contribute to the development of PclZip, please contact vincent@phpconcept.net.
+ If you can help in financing PhpConcept hosting service, please go to
+ http://www.phpconcept.net/soutien.php
diff --git a/htdocs/includes/phpexcel/PHPExcel/locale/pt/br/functions b/htdocs/includes/phpexcel/PHPExcel/locale/pt/br/functions
index c53e4c9a6a7..11d45f1fd77 100644
--- a/htdocs/includes/phpexcel/PHPExcel/locale/pt/br/functions
+++ b/htdocs/includes/phpexcel/PHPExcel/locale/pt/br/functions
@@ -1,408 +1,408 @@
-##
-## Add-in and Automation functions Funções Suplemento e Automação
-##
-GETPIVOTDATA = INFODADOSTABELADINÂMICA ## Retorna os dados armazenados em um relatório de tabela dinâmica
-
-
-##
-## Cube functions Funções de Cubo
-##
-CUBEKPIMEMBER = MEMBROKPICUBO ## Retorna o nome de um KPI (indicador de desempenho-chave), uma propriedade e uma medida e exibe o nome e a propriedade na célula. Um KPI é uma medida quantificável, como o lucro bruto mensal ou a rotatividade trimestral dos funcionários, usada para monitorar o desempenho de uma organização.
-CUBEMEMBER = MEMBROCUBO ## Retorna um membro ou tupla em uma hierarquia de cubo. Use para validar se o membro ou tupla existe no cubo.
-CUBEMEMBERPROPERTY = PROPRIEDADEMEMBROCUBO ## Retorna o valor da propriedade de um membro no cubo. Usada para validar a existência do nome do membro no cubo e para retornar a propriedade especificada para esse membro.
-CUBERANKEDMEMBER = MEMBROCLASSIFICADOCUBO ## Retorna o enésimo membro, ou o membro ordenado, em um conjunto. Use para retornar um ou mais elementos em um conjunto, assim como o melhor vendedor ou os dez melhores alunos.
-CUBESET = CONJUNTOCUBO ## Define um conjunto calculado de membros ou tuplas enviando uma expressão do conjunto para o cubo no servidor, que cria o conjunto e o retorna para o Microsoft Office Excel.
-CUBESETCOUNT = CONTAGEMCONJUNTOCUBO ## Retorna o número de itens em um conjunto.
-CUBEVALUE = VALORCUBO ## Retorna um valor agregado de um cubo.
-
-
-##
-## Database functions Funções de banco de dados
-##
-DAVERAGE = BDMÉDIA ## Retorna a média das entradas selecionadas de um banco de dados
-DCOUNT = BDCONTAR ## Conta as células que contêm números em um banco de dados
-DCOUNTA = BDCONTARA ## Conta células não vazias em um banco de dados
-DGET = BDEXTRAIR ## Extrai de um banco de dados um único registro que corresponde a um critério específico
-DMAX = BDMÁX ## Retorna o valor máximo de entradas selecionadas de um banco de dados
-DMIN = BDMÍN ## Retorna o valor mínimo de entradas selecionadas de um banco de dados
-DPRODUCT = BDMULTIPL ## Multiplica os valores em um campo específico de registros que correspondem ao critério em um banco de dados
-DSTDEV = BDEST ## Estima o desvio padrão com base em uma amostra de entradas selecionadas de um banco de dados
-DSTDEVP = BDDESVPA ## Calcula o desvio padrão com base na população inteira de entradas selecionadas de um banco de dados
-DSUM = BDSOMA ## Adiciona os números à coluna de campos de registros do banco de dados que correspondem ao critério
-DVAR = BDVAREST ## Estima a variância com base em uma amostra de entradas selecionadas de um banco de dados
-DVARP = BDVARP ## Calcula a variância com base na população inteira de entradas selecionadas de um banco de dados
-
-
-##
-## Date and time functions Funções de data e hora
-##
-DATE = DATA ## Retorna o número de série de uma data específica
-DATEVALUE = DATA.VALOR ## Converte uma data na forma de texto para um número de série
-DAY = DIA ## Converte um número de série em um dia do mês
-DAYS360 = DIAS360 ## Calcula o número de dias entre duas datas com base em um ano de 360 dias
-EDATE = DATAM ## Retorna o número de série da data que é o número indicado de meses antes ou depois da data inicial
-EOMONTH = FIMMÊS ## Retorna o número de série do último dia do mês antes ou depois de um número especificado de meses
-HOUR = HORA ## Converte um número de série em uma hora
-MINUTE = MINUTO ## Converte um número de série em um minuto
-MONTH = MÊS ## Converte um número de série em um mês
-NETWORKDAYS = DIATRABALHOTOTAL ## Retorna o número de dias úteis inteiros entre duas datas
-NOW = AGORA ## Retorna o número de série seqüencial da data e hora atuais
-SECOND = SEGUNDO ## Converte um número de série em um segundo
-TIME = HORA ## Retorna o número de série de uma hora específica
-TIMEVALUE = VALOR.TEMPO ## Converte um horário na forma de texto para um número de série
-TODAY = HOJE ## Retorna o número de série da data de hoje
-WEEKDAY = DIA.DA.SEMANA ## Converte um número de série em um dia da semana
-WEEKNUM = NÚMSEMANA ## Converte um número de série em um número que representa onde a semana cai numericamente em um ano
-WORKDAY = DIATRABALHO ## Retorna o número de série da data antes ou depois de um número específico de dias úteis
-YEAR = ANO ## Converte um número de série em um ano
-YEARFRAC = FRAÇÃOANO ## Retorna a fração do ano que representa o número de dias entre data_inicial e data_final
-
-
-##
-## Engineering functions Funções de engenharia
-##
-BESSELI = BESSELI ## Retorna a função de Bessel In(x) modificada
-BESSELJ = BESSELJ ## Retorna a função de Bessel Jn(x)
-BESSELK = BESSELK ## Retorna a função de Bessel Kn(x) modificada
-BESSELY = BESSELY ## Retorna a função de Bessel Yn(x)
-BIN2DEC = BIN2DEC ## Converte um número binário em decimal
-BIN2HEX = BIN2HEX ## Converte um número binário em hexadecimal
-BIN2OCT = BIN2OCT ## Converte um número binário em octal
-COMPLEX = COMPLEX ## Converte coeficientes reais e imaginários e um número complexo
-CONVERT = CONVERTER ## Converte um número de um sistema de medida para outro
-DEC2BIN = DECABIN ## Converte um número decimal em binário
-DEC2HEX = DECAHEX ## Converte um número decimal em hexadecimal
-DEC2OCT = DECAOCT ## Converte um número decimal em octal
-DELTA = DELTA ## Testa se dois valores são iguais
-ERF = FUNERRO ## Retorna a função de erro
-ERFC = FUNERROCOMPL ## Retorna a função de erro complementar
-GESTEP = DEGRAU ## Testa se um número é maior do que um valor limite
-HEX2BIN = HEXABIN ## Converte um número hexadecimal em binário
-HEX2DEC = HEXADEC ## Converte um número hexadecimal em decimal
-HEX2OCT = HEXAOCT ## Converte um número hexadecimal em octal
-IMABS = IMABS ## Retorna o valor absoluto (módulo) de um número complexo
-IMAGINARY = IMAGINÁRIO ## Retorna o coeficiente imaginário de um número complexo
-IMARGUMENT = IMARG ## Retorna o argumento teta, um ângulo expresso em radianos
-IMCONJUGATE = IMCONJ ## Retorna o conjugado complexo de um número complexo
-IMCOS = IMCOS ## Retorna o cosseno de um número complexo
-IMDIV = IMDIV ## Retorna o quociente de dois números complexos
-IMEXP = IMEXP ## Retorna o exponencial de um número complexo
-IMLN = IMLN ## Retorna o logaritmo natural de um número complexo
-IMLOG10 = IMLOG10 ## Retorna o logaritmo de base 10 de um número complexo
-IMLOG2 = IMLOG2 ## Retorna o logaritmo de base 2 de um número complexo
-IMPOWER = IMPOT ## Retorna um número complexo elevado a uma potência inteira
-IMPRODUCT = IMPROD ## Retorna o produto de números complexos
-IMREAL = IMREAL ## Retorna o coeficiente real de um número complexo
-IMSIN = IMSENO ## Retorna o seno de um número complexo
-IMSQRT = IMRAIZ ## Retorna a raiz quadrada de um número complexo
-IMSUB = IMSUBTR ## Retorna a diferença entre dois números complexos
-IMSUM = IMSOMA ## Retorna a soma de números complexos
-OCT2BIN = OCTABIN ## Converte um número octal em binário
-OCT2DEC = OCTADEC ## Converte um número octal em decimal
-OCT2HEX = OCTAHEX ## Converte um número octal em hexadecimal
-
-
-##
-## Financial functions Funções financeiras
-##
-ACCRINT = JUROSACUM ## Retorna a taxa de juros acumulados de um título que paga uma taxa periódica de juros
-ACCRINTM = JUROSACUMV ## Retorna os juros acumulados de um título que paga juros no vencimento
-AMORDEGRC = AMORDEGRC ## Retorna a depreciação para cada período contábil usando o coeficiente de depreciação
-AMORLINC = AMORLINC ## Retorna a depreciação para cada período contábil
-COUPDAYBS = CUPDIASINLIQ ## Retorna o número de dias do início do período de cupom até a data de liquidação
-COUPDAYS = CUPDIAS ## Retorna o número de dias no período de cupom que contém a data de quitação
-COUPDAYSNC = CUPDIASPRÓX ## Retorna o número de dias da data de liquidação até a data do próximo cupom
-COUPNCD = CUPDATAPRÓX ## Retorna a próxima data de cupom após a data de quitação
-COUPNUM = CUPNÚM ## Retorna o número de cupons pagáveis entre as datas de quitação e vencimento
-COUPPCD = CUPDATAANT ## Retorna a data de cupom anterior à data de quitação
-CUMIPMT = PGTOJURACUM ## Retorna os juros acumulados pagos entre dois períodos
-CUMPRINC = PGTOCAPACUM ## Retorna o capital acumulado pago sobre um empréstimo entre dois períodos
-DB = BD ## Retorna a depreciação de um ativo para um período especificado, usando o método de balanço de declínio fixo
-DDB = BDD ## Retorna a depreciação de um ativo com relação a um período especificado usando o método de saldos decrescentes duplos ou qualquer outro método especificado por você
-DISC = DESC ## Retorna a taxa de desconto de um título
-DOLLARDE = MOEDADEC ## Converte um preço em formato de moeda, na forma fracionária, em um preço na forma decimal
-DOLLARFR = MOEDAFRA ## Converte um preço, apresentado na forma decimal, em um preço apresentado na forma fracionária
-DURATION = DURAÇÃO ## Retorna a duração anual de um título com pagamentos de juros periódicos
-EFFECT = EFETIVA ## Retorna a taxa de juros anual efetiva
-FV = VF ## Retorna o valor futuro de um investimento
-FVSCHEDULE = VFPLANO ## Retorna o valor futuro de um capital inicial após a aplicação de uma série de taxas de juros compostas
-INTRATE = TAXAJUROS ## Retorna a taxa de juros de um título totalmente investido
-IPMT = IPGTO ## Retorna o pagamento de juros para um investimento em um determinado período
-IRR = TIR ## Retorna a taxa interna de retorno de uma série de fluxos de caixa
-ISPMT = ÉPGTO ## Calcula os juros pagos durante um período específico de um investimento
-MDURATION = MDURAÇÃO ## Retorna a duração de Macauley modificada para um título com um valor de paridade equivalente a R$ 100
-MIRR = MTIR ## Calcula a taxa interna de retorno em que fluxos de caixa positivos e negativos são financiados com diferentes taxas
-NOMINAL = NOMINAL ## Retorna a taxa de juros nominal anual
-NPER = NPER ## Retorna o número de períodos de um investimento
-NPV = VPL ## Retorna o valor líquido atual de um investimento com base em uma série de fluxos de caixa periódicos e em uma taxa de desconto
-ODDFPRICE = PREÇOPRIMINC ## Retorna o preço por R$ 100 de valor nominal de um título com um primeiro período indefinido
-ODDFYIELD = LUCROPRIMINC ## Retorna o rendimento de um título com um primeiro período indefinido
-ODDLPRICE = PREÇOÚLTINC ## Retorna o preço por R$ 100 de valor nominal de um título com um último período de cupom indefinido
-ODDLYIELD = LUCROÚLTINC ## Retorna o rendimento de um título com um último período indefinido
-PMT = PGTO ## Retorna o pagamento periódico de uma anuidade
-PPMT = PPGTO ## Retorna o pagamento de capital para determinado período de investimento
-PRICE = PREÇO ## Retorna a preço por R$ 100,00 de valor nominal de um título que paga juros periódicos
-PRICEDISC = PREÇODESC ## Retorna o preço por R$ 100,00 de valor nominal de um título descontado
-PRICEMAT = PREÇOVENC ## Retorna o preço por R$ 100,00 de valor nominal de um título que paga juros no vencimento
-PV = VP ## Retorna o valor presente de um investimento
-RATE = TAXA ## Retorna a taxa de juros por período de uma anuidade
-RECEIVED = RECEBER ## Retorna a quantia recebida no vencimento de um título totalmente investido
-SLN = DPD ## Retorna a depreciação em linha reta de um ativo durante um período
-SYD = SDA ## Retorna a depreciação dos dígitos da soma dos anos de um ativo para um período especificado
-TBILLEQ = OTN ## Retorna o rendimento de um título equivalente a uma obrigação do Tesouro
-TBILLPRICE = OTNVALOR ## Retorna o preço por R$ 100,00 de valor nominal de uma obrigação do Tesouro
-TBILLYIELD = OTNLUCRO ## Retorna o rendimento de uma obrigação do Tesouro
-VDB = BDV ## Retorna a depreciação de um ativo para um período especificado ou parcial usando um método de balanço declinante
-XIRR = XTIR ## Fornece a taxa interna de retorno para um programa de fluxos de caixa que não é necessariamente periódico
-XNPV = XVPL ## Retorna o valor presente líquido de um programa de fluxos de caixa que não é necessariamente periódico
-YIELD = LUCRO ## Retorna o lucro de um título que paga juros periódicos
-YIELDDISC = LUCRODESC ## Retorna o rendimento anual de um título descontado. Por exemplo, uma obrigação do Tesouro
-YIELDMAT = LUCROVENC ## Retorna o lucro anual de um título que paga juros no vencimento
-
-
-##
-## Information functions Funções de informação
-##
-CELL = CÉL ## Retorna informações sobre formatação, localização ou conteúdo de uma célula
-ERROR.TYPE = TIPO.ERRO ## Retorna um número correspondente a um tipo de erro
-INFO = INFORMAÇÃO ## Retorna informações sobre o ambiente operacional atual
-ISBLANK = ÉCÉL.VAZIA ## Retorna VERDADEIRO se o valor for vazio
-ISERR = ÉERRO ## Retorna VERDADEIRO se o valor for um valor de erro diferente de #N/D
-ISERROR = ÉERROS ## Retorna VERDADEIRO se o valor for um valor de erro
-ISEVEN = ÉPAR ## Retorna VERDADEIRO se o número for par
-ISLOGICAL = ÉLÓGICO ## Retorna VERDADEIRO se o valor for um valor lógico
-ISNA = É.NÃO.DISP ## Retorna VERDADEIRO se o valor for o valor de erro #N/D
-ISNONTEXT = É.NÃO.TEXTO ## Retorna VERDADEIRO se o valor for diferente de texto
-ISNUMBER = ÉNÚM ## Retorna VERDADEIRO se o valor for um número
-ISODD = ÉIMPAR ## Retorna VERDADEIRO se o número for ímpar
-ISREF = ÉREF ## Retorna VERDADEIRO se o valor for uma referência
-ISTEXT = ÉTEXTO ## Retorna VERDADEIRO se o valor for texto
-N = N ## Retorna um valor convertido em um número
-NA = NÃO.DISP ## Retorna o valor de erro #N/D
-TYPE = TIPO ## Retorna um número indicando o tipo de dados de um valor
-
-
-##
-## Logical functions Funções lógicas
-##
-AND = E ## Retorna VERDADEIRO se todos os seus argumentos forem VERDADEIROS
-FALSE = FALSO ## Retorna o valor lógico FALSO
-IF = SE ## Especifica um teste lógico a ser executado
-IFERROR = SEERRO ## Retornará um valor que você especifica se uma fórmula for avaliada para um erro; do contrário, retornará o resultado da fórmula
-NOT = NÃO ## Inverte o valor lógico do argumento
-OR = OU ## Retorna VERDADEIRO se um dos argumentos for VERDADEIRO
-TRUE = VERDADEIRO ## Retorna o valor lógico VERDADEIRO
-
-
-##
-## Lookup and reference functions Funções de pesquisa e referência
-##
-ADDRESS = ENDEREÇO ## Retorna uma referência como texto para uma única célula em uma planilha
-AREAS = ÁREAS ## Retorna o número de áreas em uma referência
-CHOOSE = ESCOLHER ## Escolhe um valor a partir de uma lista de valores
-COLUMN = COL ## Retorna o número da coluna de uma referência
-COLUMNS = COLS ## Retorna o número de colunas em uma referência
-HLOOKUP = PROCH ## Procura na linha superior de uma matriz e retorna o valor da célula especificada
-HYPERLINK = HYPERLINK ## Cria um atalho ou salto que abre um documento armazenado em um servidor de rede, uma intranet ou na Internet
-INDEX = ÍNDICE ## Usa um índice para escolher um valor de uma referência ou matriz
-INDIRECT = INDIRETO ## Retorna uma referência indicada por um valor de texto
-LOOKUP = PROC ## Procura valores em um vetor ou em uma matriz
-MATCH = CORRESP ## Procura valores em uma referência ou em uma matriz
-OFFSET = DESLOC ## Retorna um deslocamento de referência com base em uma determinada referência
-ROW = LIN ## Retorna o número da linha de uma referência
-ROWS = LINS ## Retorna o número de linhas em uma referência
-RTD = RTD ## Recupera dados em tempo real de um programa que ofereça suporte a automação COM (automação: uma forma de trabalhar com objetos de um aplicativo a partir de outro aplicativo ou ferramenta de desenvolvimento. Chamada inicialmente de automação OLE, a automação é um padrão industrial e um recurso do modelo de objeto componente (COM).)
-TRANSPOSE = TRANSPOR ## Retorna a transposição de uma matriz
-VLOOKUP = PROCV ## Procura na primeira coluna de uma matriz e move ao longo da linha para retornar o valor de uma célula
-
-
-##
-## Math and trigonometry functions Funções matemáticas e trigonométricas
-##
-ABS = ABS ## Retorna o valor absoluto de um número
-ACOS = ACOS ## Retorna o arco cosseno de um número
-ACOSH = ACOSH ## Retorna o cosseno hiperbólico inverso de um número
-ASIN = ASEN ## Retorna o arco seno de um número
-ASINH = ASENH ## Retorna o seno hiperbólico inverso de um número
-ATAN = ATAN ## Retorna o arco tangente de um número
-ATAN2 = ATAN2 ## Retorna o arco tangente das coordenadas x e y especificadas
-ATANH = ATANH ## Retorna a tangente hiperbólica inversa de um número
-CEILING = TETO ## Arredonda um número para o inteiro mais próximo ou para o múltiplo mais próximo de significância
-COMBIN = COMBIN ## Retorna o número de combinações de um determinado número de objetos
-COS = COS ## Retorna o cosseno de um número
-COSH = COSH ## Retorna o cosseno hiperbólico de um número
-DEGREES = GRAUS ## Converte radianos em graus
-EVEN = PAR ## Arredonda um número para cima até o inteiro par mais próximo
-EXP = EXP ## Retorna e elevado à potência de um número especificado
-FACT = FATORIAL ## Retorna o fatorial de um número
-FACTDOUBLE = FATDUPLO ## Retorna o fatorial duplo de um número
-FLOOR = ARREDMULTB ## Arredonda um número para baixo até zero
-GCD = MDC ## Retorna o máximo divisor comum
-INT = INT ## Arredonda um número para baixo até o número inteiro mais próximo
-LCM = MMC ## Retorna o mínimo múltiplo comum
-LN = LN ## Retorna o logaritmo natural de um número
-LOG = LOG ## Retorna o logaritmo de um número de uma base especificada
-LOG10 = LOG10 ## Retorna o logaritmo de base 10 de um número
-MDETERM = MATRIZ.DETERM ## Retorna o determinante de uma matriz de uma variável do tipo matriz
-MINVERSE = MATRIZ.INVERSO ## Retorna a matriz inversa de uma matriz
-MMULT = MATRIZ.MULT ## Retorna o produto de duas matrizes
-MOD = RESTO ## Retorna o resto da divisão
-MROUND = MARRED ## Retorna um número arredondado ao múltiplo desejado
-MULTINOMIAL = MULTINOMIAL ## Retorna o multinomial de um conjunto de números
-ODD = ÍMPAR ## Arredonda um número para cima até o inteiro ímpar mais próximo
-PI = PI ## Retorna o valor de Pi
-POWER = POTÊNCIA ## Fornece o resultado de um número elevado a uma potência
-PRODUCT = MULT ## Multiplica seus argumentos
-QUOTIENT = QUOCIENTE ## Retorna a parte inteira de uma divisão
-RADIANS = RADIANOS ## Converte graus em radianos
-RAND = ALEATÓRIO ## Retorna um número aleatório entre 0 e 1
-RANDBETWEEN = ALEATÓRIOENTRE ## Retorna um número aleatório entre os números especificados
-ROMAN = ROMANO ## Converte um algarismo arábico em romano, como texto
-ROUND = ARRED ## Arredonda um número até uma quantidade especificada de dígitos
-ROUNDDOWN = ARREDONDAR.PARA.BAIXO ## Arredonda um número para baixo até zero
-ROUNDUP = ARREDONDAR.PARA.CIMA ## Arredonda um número para cima, afastando-o de zero
-SERIESSUM = SOMASEQÜÊNCIA ## Retorna a soma de uma série polinomial baseada na fórmula
-SIGN = SINAL ## Retorna o sinal de um número
-SIN = SEN ## Retorna o seno de um ângulo dado
-SINH = SENH ## Retorna o seno hiperbólico de um número
-SQRT = RAIZ ## Retorna uma raiz quadrada positiva
-SQRTPI = RAIZPI ## Retorna a raiz quadrada de (núm* pi)
-SUBTOTAL = SUBTOTAL ## Retorna um subtotal em uma lista ou em um banco de dados
-SUM = SOMA ## Soma seus argumentos
-SUMIF = SOMASE ## Adiciona as células especificadas por um determinado critério
-SUMIFS = SOMASE ## Adiciona as células em um intervalo que atende a vários critérios
-SUMPRODUCT = SOMARPRODUTO ## Retorna a soma dos produtos de componentes correspondentes de matrizes
-SUMSQ = SOMAQUAD ## Retorna a soma dos quadrados dos argumentos
-SUMX2MY2 = SOMAX2DY2 ## Retorna a soma da diferença dos quadrados dos valores correspondentes em duas matrizes
-SUMX2PY2 = SOMAX2SY2 ## Retorna a soma da soma dos quadrados dos valores correspondentes em duas matrizes
-SUMXMY2 = SOMAXMY2 ## Retorna a soma dos quadrados das diferenças dos valores correspondentes em duas matrizes
-TAN = TAN ## Retorna a tangente de um número
-TANH = TANH ## Retorna a tangente hiperbólica de um número
-TRUNC = TRUNCAR ## Trunca um número para um inteiro
-
-
-##
-## Statistical functions Funções estatísticas
-##
-AVEDEV = DESV.MÉDIO ## Retorna a média aritmética dos desvios médios dos pontos de dados a partir de sua média
-AVERAGE = MÉDIA ## Retorna a média dos argumentos
-AVERAGEA = MÉDIAA ## Retorna a média dos argumentos, inclusive números, texto e valores lógicos
-AVERAGEIF = MÉDIASE ## Retorna a média (média aritmética) de todas as células em um intervalo que atendem a um determinado critério
-AVERAGEIFS = MÉDIASES ## Retorna a média (média aritmética) de todas as células que atendem a múltiplos critérios.
-BETADIST = DISTBETA ## Retorna a função de distribuição cumulativa beta
-BETAINV = BETA.ACUM.INV ## Retorna o inverso da função de distribuição cumulativa para uma distribuição beta especificada
-BINOMDIST = DISTRBINOM ## Retorna a probabilidade de distribuição binomial do termo individual
-CHIDIST = DIST.QUI ## Retorna a probabilidade unicaudal da distribuição qui-quadrada
-CHIINV = INV.QUI ## Retorna o inverso da probabilidade uni-caudal da distribuição qui-quadrada
-CHITEST = TESTE.QUI ## Retorna o teste para independência
-CONFIDENCE = INT.CONFIANÇA ## Retorna o intervalo de confiança para uma média da população
-CORREL = CORREL ## Retorna o coeficiente de correlação entre dois conjuntos de dados
-COUNT = CONT.NÚM ## Calcula quantos números há na lista de argumentos
-COUNTA = CONT.VALORES ## Calcula quantos valores há na lista de argumentos
-COUNTBLANK = CONTAR.VAZIO ## Conta o número de células vazias no intervalo especificado
-COUNTIF = CONT.SE ## Calcula o número de células não vazias em um intervalo que corresponde a determinados critérios
-COUNTIFS = CONT.SES ## Conta o número de células dentro de um intervalo que atende a múltiplos critérios
-COVAR = COVAR ## Retorna a covariância, a média dos produtos dos desvios pares
-CRITBINOM = CRIT.BINOM ## Retorna o menor valor para o qual a distribuição binomial cumulativa é menor ou igual ao valor padrão
-DEVSQ = DESVQ ## Retorna a soma dos quadrados dos desvios
-EXPONDIST = DISTEXPON ## Retorna a distribuição exponencial
-FDIST = DISTF ## Retorna a distribuição de probabilidade F
-FINV = INVF ## Retorna o inverso da distribuição de probabilidades F
-FISHER = FISHER ## Retorna a transformação Fisher
-FISHERINV = FISHERINV ## Retorna o inverso da transformação Fisher
-FORECAST = PREVISÃO ## Retorna um valor ao longo de uma linha reta
-FREQUENCY = FREQÜÊNCIA ## Retorna uma distribuição de freqüência como uma matriz vertical
-FTEST = TESTEF ## Retorna o resultado de um teste F
-GAMMADIST = DISTGAMA ## Retorna a distribuição gama
-GAMMAINV = INVGAMA ## Retorna o inverso da distribuição cumulativa gama
-GAMMALN = LNGAMA ## Retorna o logaritmo natural da função gama, G(x)
-GEOMEAN = MÉDIA.GEOMÉTRICA ## Retorna a média geométrica
-GROWTH = CRESCIMENTO ## Retorna valores ao longo de uma tendência exponencial
-HARMEAN = MÉDIA.HARMÔNICA ## Retorna a média harmônica
-HYPGEOMDIST = DIST.HIPERGEOM ## Retorna a distribuição hipergeométrica
-INTERCEPT = INTERCEPÇÃO ## Retorna a intercepção da linha de regressão linear
-KURT = CURT ## Retorna a curtose de um conjunto de dados
-LARGE = MAIOR ## Retorna o maior valor k-ésimo de um conjunto de dados
-LINEST = PROJ.LIN ## Retorna os parâmetros de uma tendência linear
-LOGEST = PROJ.LOG ## Retorna os parâmetros de uma tendência exponencial
-LOGINV = INVLOG ## Retorna o inverso da distribuição lognormal
-LOGNORMDIST = DIST.LOGNORMAL ## Retorna a distribuição lognormal cumulativa
-MAX = MÁXIMO ## Retorna o valor máximo em uma lista de argumentos
-MAXA = MÁXIMOA ## Retorna o maior valor em uma lista de argumentos, inclusive números, texto e valores lógicos
-MEDIAN = MED ## Retorna a mediana dos números indicados
-MIN = MÍNIMO ## Retorna o valor mínimo em uma lista de argumentos
-MINA = MÍNIMOA ## Retorna o menor valor em uma lista de argumentos, inclusive números, texto e valores lógicos
-MODE = MODO ## Retorna o valor mais comum em um conjunto de dados
-NEGBINOMDIST = DIST.BIN.NEG ## Retorna a distribuição binomial negativa
-NORMDIST = DIST.NORM ## Retorna a distribuição cumulativa normal
-NORMINV = INV.NORM ## Retorna o inverso da distribuição cumulativa normal
-NORMSDIST = DIST.NORMP ## Retorna a distribuição cumulativa normal padrão
-NORMSINV = INV.NORMP ## Retorna o inverso da distribuição cumulativa normal padrão
-PEARSON = PEARSON ## Retorna o coeficiente de correlação do momento do produto Pearson
-PERCENTILE = PERCENTIL ## Retorna o k-ésimo percentil de valores em um intervalo
-PERCENTRANK = ORDEM.PORCENTUAL ## Retorna a ordem percentual de um valor em um conjunto de dados
-PERMUT = PERMUT ## Retorna o número de permutações de um determinado número de objetos
-POISSON = POISSON ## Retorna a distribuição Poisson
-PROB = PROB ## Retorna a probabilidade de valores em um intervalo estarem entre dois limites
-QUARTILE = QUARTIL ## Retorna o quartil do conjunto de dados
-RANK = ORDEM ## Retorna a posição de um número em uma lista de números
-RSQ = RQUAD ## Retorna o quadrado do coeficiente de correlação do momento do produto de Pearson
-SKEW = DISTORÇÃO ## Retorna a distorção de uma distribuição
-SLOPE = INCLINAÇÃO ## Retorna a inclinação da linha de regressão linear
-SMALL = MENOR ## Retorna o menor valor k-ésimo do conjunto de dados
-STANDARDIZE = PADRONIZAR ## Retorna um valor normalizado
-STDEV = DESVPAD ## Estima o desvio padrão com base em uma amostra
-STDEVA = DESVPADA ## Estima o desvio padrão com base em uma amostra, inclusive números, texto e valores lógicos
-STDEVP = DESVPADP ## Calcula o desvio padrão com base na população total
-STDEVPA = DESVPADPA ## Calcula o desvio padrão com base na população total, inclusive números, texto e valores lógicos
-STEYX = EPADYX ## Retorna o erro padrão do valor-y previsto para cada x da regressão
-TDIST = DISTT ## Retorna a distribuição t de Student
-TINV = INVT ## Retorna o inverso da distribuição t de Student
-TREND = TENDÊNCIA ## Retorna valores ao longo de uma tendência linear
-TRIMMEAN = MÉDIA.INTERNA ## Retorna a média do interior de um conjunto de dados
-TTEST = TESTET ## Retorna a probabilidade associada ao teste t de Student
-VAR = VAR ## Estima a variância com base em uma amostra
-VARA = VARA ## Estima a variância com base em uma amostra, inclusive números, texto e valores lógicos
-VARP = VARP ## Calcula a variância com base na população inteira
-VARPA = VARPA ## Calcula a variância com base na população total, inclusive números, texto e valores lógicos
-WEIBULL = WEIBULL ## Retorna a distribuição Weibull
-ZTEST = TESTEZ ## Retorna o valor de probabilidade uni-caudal de um teste-z
-
-
-##
-## Text functions Funções de texto
-##
-ASC = ASC ## Altera letras do inglês ou katakana de largura total (bytes duplos) dentro de uma seqüência de caracteres para caracteres de meia largura (byte único)
-BAHTTEXT = BAHTTEXT ## Converte um número em um texto, usando o formato de moeda ß (baht)
-CHAR = CARACT ## Retorna o caractere especificado pelo número de código
-CLEAN = TIRAR ## Remove todos os caracteres do texto que não podem ser impressos
-CODE = CÓDIGO ## Retorna um código numérico para o primeiro caractere de uma seqüência de caracteres de texto
-CONCATENATE = CONCATENAR ## Agrupa vários itens de texto em um único item de texto
-DOLLAR = MOEDA ## Converte um número em texto, usando o formato de moeda $ (dólar)
-EXACT = EXATO ## Verifica se dois valores de texto são idênticos
-FIND = PROCURAR ## Procura um valor de texto dentro de outro (diferencia maiúsculas de minúsculas)
-FINDB = PROCURARB ## Procura um valor de texto dentro de outro (diferencia maiúsculas de minúsculas)
-FIXED = DEF.NÚM.DEC ## Formata um número como texto com um número fixo de decimais
-JIS = JIS ## Altera letras do inglês ou katakana de meia largura (byte único) dentro de uma seqüência de caracteres para caracteres de largura total (bytes duplos)
-LEFT = ESQUERDA ## Retorna os caracteres mais à esquerda de um valor de texto
-LEFTB = ESQUERDAB ## Retorna os caracteres mais à esquerda de um valor de texto
-LEN = NÚM.CARACT ## Retorna o número de caracteres em uma seqüência de texto
-LENB = NÚM.CARACTB ## Retorna o número de caracteres em uma seqüência de texto
-LOWER = MINÚSCULA ## Converte texto para minúsculas
-MID = EXT.TEXTO ## Retorna um número específico de caracteres de uma seqüência de texto começando na posição especificada
-MIDB = EXT.TEXTOB ## Retorna um número específico de caracteres de uma seqüência de texto começando na posição especificada
-PHONETIC = FONÉTICA ## Extrai os caracteres fonéticos (furigana) de uma seqüência de caracteres de texto
-PROPER = PRI.MAIÚSCULA ## Coloca a primeira letra de cada palavra em maiúscula em um valor de texto
-REPLACE = MUDAR ## Muda os caracteres dentro do texto
-REPLACEB = MUDARB ## Muda os caracteres dentro do texto
-REPT = REPT ## Repete o texto um determinado número de vezes
-RIGHT = DIREITA ## Retorna os caracteres mais à direita de um valor de texto
-RIGHTB = DIREITAB ## Retorna os caracteres mais à direita de um valor de texto
-SEARCH = LOCALIZAR ## Localiza um valor de texto dentro de outro (não diferencia maiúsculas de minúsculas)
-SEARCHB = LOCALIZARB ## Localiza um valor de texto dentro de outro (não diferencia maiúsculas de minúsculas)
-SUBSTITUTE = SUBSTITUIR ## Substitui um novo texto por um texto antigo em uma seqüência de texto
-T = T ## Converte os argumentos em texto
-TEXT = TEXTO ## Formata um número e o converte em texto
-TRIM = ARRUMAR ## Remove espaços do texto
-UPPER = MAIÚSCULA ## Converte o texto em maiúsculas
-VALUE = VALOR ## Converte um argumento de texto em um número
+##
+## Add-in and Automation functions Funções Suplemento e Automação
+##
+GETPIVOTDATA = INFODADOSTABELADINÂMICA ## Retorna os dados armazenados em um relatório de tabela dinâmica
+
+
+##
+## Cube functions Funções de Cubo
+##
+CUBEKPIMEMBER = MEMBROKPICUBO ## Retorna o nome de um KPI (indicador de desempenho-chave), uma propriedade e uma medida e exibe o nome e a propriedade na célula. Um KPI é uma medida quantificável, como o lucro bruto mensal ou a rotatividade trimestral dos funcionários, usada para monitorar o desempenho de uma organização.
+CUBEMEMBER = MEMBROCUBO ## Retorna um membro ou tupla em uma hierarquia de cubo. Use para validar se o membro ou tupla existe no cubo.
+CUBEMEMBERPROPERTY = PROPRIEDADEMEMBROCUBO ## Retorna o valor da propriedade de um membro no cubo. Usada para validar a existência do nome do membro no cubo e para retornar a propriedade especificada para esse membro.
+CUBERANKEDMEMBER = MEMBROCLASSIFICADOCUBO ## Retorna o enésimo membro, ou o membro ordenado, em um conjunto. Use para retornar um ou mais elementos em um conjunto, assim como o melhor vendedor ou os dez melhores alunos.
+CUBESET = CONJUNTOCUBO ## Define um conjunto calculado de membros ou tuplas enviando uma expressão do conjunto para o cubo no servidor, que cria o conjunto e o retorna para o Microsoft Office Excel.
+CUBESETCOUNT = CONTAGEMCONJUNTOCUBO ## Retorna o número de itens em um conjunto.
+CUBEVALUE = VALORCUBO ## Retorna um valor agregado de um cubo.
+
+
+##
+## Database functions Funções de banco de dados
+##
+DAVERAGE = BDMÉDIA ## Retorna a média das entradas selecionadas de um banco de dados
+DCOUNT = BDCONTAR ## Conta as células que contêm números em um banco de dados
+DCOUNTA = BDCONTARA ## Conta células não vazias em um banco de dados
+DGET = BDEXTRAIR ## Extrai de um banco de dados um único registro que corresponde a um critério específico
+DMAX = BDMÁX ## Retorna o valor máximo de entradas selecionadas de um banco de dados
+DMIN = BDMÍN ## Retorna o valor mínimo de entradas selecionadas de um banco de dados
+DPRODUCT = BDMULTIPL ## Multiplica os valores em um campo específico de registros que correspondem ao critério em um banco de dados
+DSTDEV = BDEST ## Estima o desvio padrão com base em uma amostra de entradas selecionadas de um banco de dados
+DSTDEVP = BDDESVPA ## Calcula o desvio padrão com base na população inteira de entradas selecionadas de um banco de dados
+DSUM = BDSOMA ## Adiciona os números à coluna de campos de registros do banco de dados que correspondem ao critério
+DVAR = BDVAREST ## Estima a variância com base em uma amostra de entradas selecionadas de um banco de dados
+DVARP = BDVARP ## Calcula a variância com base na população inteira de entradas selecionadas de um banco de dados
+
+
+##
+## Date and time functions Funções de data e hora
+##
+DATE = DATA ## Retorna o número de série de uma data específica
+DATEVALUE = DATA.VALOR ## Converte uma data na forma de texto para um número de série
+DAY = DIA ## Converte um número de série em um dia do mês
+DAYS360 = DIAS360 ## Calcula o número de dias entre duas datas com base em um ano de 360 dias
+EDATE = DATAM ## Retorna o número de série da data que é o número indicado de meses antes ou depois da data inicial
+EOMONTH = FIMMÊS ## Retorna o número de série do último dia do mês antes ou depois de um número especificado de meses
+HOUR = HORA ## Converte um número de série em uma hora
+MINUTE = MINUTO ## Converte um número de série em um minuto
+MONTH = MÊS ## Converte um número de série em um mês
+NETWORKDAYS = DIATRABALHOTOTAL ## Retorna o número de dias úteis inteiros entre duas datas
+NOW = AGORA ## Retorna o número de série seqüencial da data e hora atuais
+SECOND = SEGUNDO ## Converte um número de série em um segundo
+TIME = HORA ## Retorna o número de série de uma hora específica
+TIMEVALUE = VALOR.TEMPO ## Converte um horário na forma de texto para um número de série
+TODAY = HOJE ## Retorna o número de série da data de hoje
+WEEKDAY = DIA.DA.SEMANA ## Converte um número de série em um dia da semana
+WEEKNUM = NÚMSEMANA ## Converte um número de série em um número que representa onde a semana cai numericamente em um ano
+WORKDAY = DIATRABALHO ## Retorna o número de série da data antes ou depois de um número específico de dias úteis
+YEAR = ANO ## Converte um número de série em um ano
+YEARFRAC = FRAÇÃOANO ## Retorna a fração do ano que representa o número de dias entre data_inicial e data_final
+
+
+##
+## Engineering functions Funções de engenharia
+##
+BESSELI = BESSELI ## Retorna a função de Bessel In(x) modificada
+BESSELJ = BESSELJ ## Retorna a função de Bessel Jn(x)
+BESSELK = BESSELK ## Retorna a função de Bessel Kn(x) modificada
+BESSELY = BESSELY ## Retorna a função de Bessel Yn(x)
+BIN2DEC = BIN2DEC ## Converte um número binário em decimal
+BIN2HEX = BIN2HEX ## Converte um número binário em hexadecimal
+BIN2OCT = BIN2OCT ## Converte um número binário em octal
+COMPLEX = COMPLEX ## Converte coeficientes reais e imaginários e um número complexo
+CONVERT = CONVERTER ## Converte um número de um sistema de medida para outro
+DEC2BIN = DECABIN ## Converte um número decimal em binário
+DEC2HEX = DECAHEX ## Converte um número decimal em hexadecimal
+DEC2OCT = DECAOCT ## Converte um número decimal em octal
+DELTA = DELTA ## Testa se dois valores são iguais
+ERF = FUNERRO ## Retorna a função de erro
+ERFC = FUNERROCOMPL ## Retorna a função de erro complementar
+GESTEP = DEGRAU ## Testa se um número é maior do que um valor limite
+HEX2BIN = HEXABIN ## Converte um número hexadecimal em binário
+HEX2DEC = HEXADEC ## Converte um número hexadecimal em decimal
+HEX2OCT = HEXAOCT ## Converte um número hexadecimal em octal
+IMABS = IMABS ## Retorna o valor absoluto (módulo) de um número complexo
+IMAGINARY = IMAGINÁRIO ## Retorna o coeficiente imaginário de um número complexo
+IMARGUMENT = IMARG ## Retorna o argumento teta, um ângulo expresso em radianos
+IMCONJUGATE = IMCONJ ## Retorna o conjugado complexo de um número complexo
+IMCOS = IMCOS ## Retorna o cosseno de um número complexo
+IMDIV = IMDIV ## Retorna o quociente de dois números complexos
+IMEXP = IMEXP ## Retorna o exponencial de um número complexo
+IMLN = IMLN ## Retorna o logaritmo natural de um número complexo
+IMLOG10 = IMLOG10 ## Retorna o logaritmo de base 10 de um número complexo
+IMLOG2 = IMLOG2 ## Retorna o logaritmo de base 2 de um número complexo
+IMPOWER = IMPOT ## Retorna um número complexo elevado a uma potência inteira
+IMPRODUCT = IMPROD ## Retorna o produto de números complexos
+IMREAL = IMREAL ## Retorna o coeficiente real de um número complexo
+IMSIN = IMSENO ## Retorna o seno de um número complexo
+IMSQRT = IMRAIZ ## Retorna a raiz quadrada de um número complexo
+IMSUB = IMSUBTR ## Retorna a diferença entre dois números complexos
+IMSUM = IMSOMA ## Retorna a soma de números complexos
+OCT2BIN = OCTABIN ## Converte um número octal em binário
+OCT2DEC = OCTADEC ## Converte um número octal em decimal
+OCT2HEX = OCTAHEX ## Converte um número octal em hexadecimal
+
+
+##
+## Financial functions Funções financeiras
+##
+ACCRINT = JUROSACUM ## Retorna a taxa de juros acumulados de um título que paga uma taxa periódica de juros
+ACCRINTM = JUROSACUMV ## Retorna os juros acumulados de um título que paga juros no vencimento
+AMORDEGRC = AMORDEGRC ## Retorna a depreciação para cada período contábil usando o coeficiente de depreciação
+AMORLINC = AMORLINC ## Retorna a depreciação para cada período contábil
+COUPDAYBS = CUPDIASINLIQ ## Retorna o número de dias do início do período de cupom até a data de liquidação
+COUPDAYS = CUPDIAS ## Retorna o número de dias no período de cupom que contém a data de quitação
+COUPDAYSNC = CUPDIASPRÓX ## Retorna o número de dias da data de liquidação até a data do próximo cupom
+COUPNCD = CUPDATAPRÓX ## Retorna a próxima data de cupom após a data de quitação
+COUPNUM = CUPNÚM ## Retorna o número de cupons pagáveis entre as datas de quitação e vencimento
+COUPPCD = CUPDATAANT ## Retorna a data de cupom anterior à data de quitação
+CUMIPMT = PGTOJURACUM ## Retorna os juros acumulados pagos entre dois períodos
+CUMPRINC = PGTOCAPACUM ## Retorna o capital acumulado pago sobre um empréstimo entre dois períodos
+DB = BD ## Retorna a depreciação de um ativo para um período especificado, usando o método de balanço de declínio fixo
+DDB = BDD ## Retorna a depreciação de um ativo com relação a um período especificado usando o método de saldos decrescentes duplos ou qualquer outro método especificado por você
+DISC = DESC ## Retorna a taxa de desconto de um título
+DOLLARDE = MOEDADEC ## Converte um preço em formato de moeda, na forma fracionária, em um preço na forma decimal
+DOLLARFR = MOEDAFRA ## Converte um preço, apresentado na forma decimal, em um preço apresentado na forma fracionária
+DURATION = DURAÇÃO ## Retorna a duração anual de um título com pagamentos de juros periódicos
+EFFECT = EFETIVA ## Retorna a taxa de juros anual efetiva
+FV = VF ## Retorna o valor futuro de um investimento
+FVSCHEDULE = VFPLANO ## Retorna o valor futuro de um capital inicial após a aplicação de uma série de taxas de juros compostas
+INTRATE = TAXAJUROS ## Retorna a taxa de juros de um título totalmente investido
+IPMT = IPGTO ## Retorna o pagamento de juros para um investimento em um determinado período
+IRR = TIR ## Retorna a taxa interna de retorno de uma série de fluxos de caixa
+ISPMT = ÉPGTO ## Calcula os juros pagos durante um período específico de um investimento
+MDURATION = MDURAÇÃO ## Retorna a duração de Macauley modificada para um título com um valor de paridade equivalente a R$ 100
+MIRR = MTIR ## Calcula a taxa interna de retorno em que fluxos de caixa positivos e negativos são financiados com diferentes taxas
+NOMINAL = NOMINAL ## Retorna a taxa de juros nominal anual
+NPER = NPER ## Retorna o número de períodos de um investimento
+NPV = VPL ## Retorna o valor líquido atual de um investimento com base em uma série de fluxos de caixa periódicos e em uma taxa de desconto
+ODDFPRICE = PREÇOPRIMINC ## Retorna o preço por R$ 100 de valor nominal de um título com um primeiro período indefinido
+ODDFYIELD = LUCROPRIMINC ## Retorna o rendimento de um título com um primeiro período indefinido
+ODDLPRICE = PREÇOÚLTINC ## Retorna o preço por R$ 100 de valor nominal de um título com um último período de cupom indefinido
+ODDLYIELD = LUCROÚLTINC ## Retorna o rendimento de um título com um último período indefinido
+PMT = PGTO ## Retorna o pagamento periódico de uma anuidade
+PPMT = PPGTO ## Retorna o pagamento de capital para determinado período de investimento
+PRICE = PREÇO ## Retorna a preço por R$ 100,00 de valor nominal de um título que paga juros periódicos
+PRICEDISC = PREÇODESC ## Retorna o preço por R$ 100,00 de valor nominal de um título descontado
+PRICEMAT = PREÇOVENC ## Retorna o preço por R$ 100,00 de valor nominal de um título que paga juros no vencimento
+PV = VP ## Retorna o valor presente de um investimento
+RATE = TAXA ## Retorna a taxa de juros por período de uma anuidade
+RECEIVED = RECEBER ## Retorna a quantia recebida no vencimento de um título totalmente investido
+SLN = DPD ## Retorna a depreciação em linha reta de um ativo durante um período
+SYD = SDA ## Retorna a depreciação dos dígitos da soma dos anos de um ativo para um período especificado
+TBILLEQ = OTN ## Retorna o rendimento de um título equivalente a uma obrigação do Tesouro
+TBILLPRICE = OTNVALOR ## Retorna o preço por R$ 100,00 de valor nominal de uma obrigação do Tesouro
+TBILLYIELD = OTNLUCRO ## Retorna o rendimento de uma obrigação do Tesouro
+VDB = BDV ## Retorna a depreciação de um ativo para um período especificado ou parcial usando um método de balanço declinante
+XIRR = XTIR ## Fornece a taxa interna de retorno para um programa de fluxos de caixa que não é necessariamente periódico
+XNPV = XVPL ## Retorna o valor presente líquido de um programa de fluxos de caixa que não é necessariamente periódico
+YIELD = LUCRO ## Retorna o lucro de um título que paga juros periódicos
+YIELDDISC = LUCRODESC ## Retorna o rendimento anual de um título descontado. Por exemplo, uma obrigação do Tesouro
+YIELDMAT = LUCROVENC ## Retorna o lucro anual de um título que paga juros no vencimento
+
+
+##
+## Information functions Funções de informação
+##
+CELL = CÉL ## Retorna informações sobre formatação, localização ou conteúdo de uma célula
+ERROR.TYPE = TIPO.ERRO ## Retorna um número correspondente a um tipo de erro
+INFO = INFORMAÇÃO ## Retorna informações sobre o ambiente operacional atual
+ISBLANK = ÉCÉL.VAZIA ## Retorna VERDADEIRO se o valor for vazio
+ISERR = ÉERRO ## Retorna VERDADEIRO se o valor for um valor de erro diferente de #N/D
+ISERROR = ÉERROS ## Retorna VERDADEIRO se o valor for um valor de erro
+ISEVEN = ÉPAR ## Retorna VERDADEIRO se o número for par
+ISLOGICAL = ÉLÓGICO ## Retorna VERDADEIRO se o valor for um valor lógico
+ISNA = É.NÃO.DISP ## Retorna VERDADEIRO se o valor for o valor de erro #N/D
+ISNONTEXT = É.NÃO.TEXTO ## Retorna VERDADEIRO se o valor for diferente de texto
+ISNUMBER = ÉNÚM ## Retorna VERDADEIRO se o valor for um número
+ISODD = ÉIMPAR ## Retorna VERDADEIRO se o número for ímpar
+ISREF = ÉREF ## Retorna VERDADEIRO se o valor for uma referência
+ISTEXT = ÉTEXTO ## Retorna VERDADEIRO se o valor for texto
+N = N ## Retorna um valor convertido em um número
+NA = NÃO.DISP ## Retorna o valor de erro #N/D
+TYPE = TIPO ## Retorna um número indicando o tipo de dados de um valor
+
+
+##
+## Logical functions Funções lógicas
+##
+AND = E ## Retorna VERDADEIRO se todos os seus argumentos forem VERDADEIROS
+FALSE = FALSO ## Retorna o valor lógico FALSO
+IF = SE ## Especifica um teste lógico a ser executado
+IFERROR = SEERRO ## Retornará um valor que você especifica se uma fórmula for avaliada para um erro; do contrário, retornará o resultado da fórmula
+NOT = NÃO ## Inverte o valor lógico do argumento
+OR = OU ## Retorna VERDADEIRO se um dos argumentos for VERDADEIRO
+TRUE = VERDADEIRO ## Retorna o valor lógico VERDADEIRO
+
+
+##
+## Lookup and reference functions Funções de pesquisa e referência
+##
+ADDRESS = ENDEREÇO ## Retorna uma referência como texto para uma única célula em uma planilha
+AREAS = ÁREAS ## Retorna o número de áreas em uma referência
+CHOOSE = ESCOLHER ## Escolhe um valor a partir de uma lista de valores
+COLUMN = COL ## Retorna o número da coluna de uma referência
+COLUMNS = COLS ## Retorna o número de colunas em uma referência
+HLOOKUP = PROCH ## Procura na linha superior de uma matriz e retorna o valor da célula especificada
+HYPERLINK = HYPERLINK ## Cria um atalho ou salto que abre um documento armazenado em um servidor de rede, uma intranet ou na Internet
+INDEX = ÍNDICE ## Usa um índice para escolher um valor de uma referência ou matriz
+INDIRECT = INDIRETO ## Retorna uma referência indicada por um valor de texto
+LOOKUP = PROC ## Procura valores em um vetor ou em uma matriz
+MATCH = CORRESP ## Procura valores em uma referência ou em uma matriz
+OFFSET = DESLOC ## Retorna um deslocamento de referência com base em uma determinada referência
+ROW = LIN ## Retorna o número da linha de uma referência
+ROWS = LINS ## Retorna o número de linhas em uma referência
+RTD = RTD ## Recupera dados em tempo real de um programa que ofereça suporte a automação COM (automação: uma forma de trabalhar com objetos de um aplicativo a partir de outro aplicativo ou ferramenta de desenvolvimento. Chamada inicialmente de automação OLE, a automação é um padrão industrial e um recurso do modelo de objeto componente (COM).)
+TRANSPOSE = TRANSPOR ## Retorna a transposição de uma matriz
+VLOOKUP = PROCV ## Procura na primeira coluna de uma matriz e move ao longo da linha para retornar o valor de uma célula
+
+
+##
+## Math and trigonometry functions Funções matemáticas e trigonométricas
+##
+ABS = ABS ## Retorna o valor absoluto de um número
+ACOS = ACOS ## Retorna o arco cosseno de um número
+ACOSH = ACOSH ## Retorna o cosseno hiperbólico inverso de um número
+ASIN = ASEN ## Retorna o arco seno de um número
+ASINH = ASENH ## Retorna o seno hiperbólico inverso de um número
+ATAN = ATAN ## Retorna o arco tangente de um número
+ATAN2 = ATAN2 ## Retorna o arco tangente das coordenadas x e y especificadas
+ATANH = ATANH ## Retorna a tangente hiperbólica inversa de um número
+CEILING = TETO ## Arredonda um número para o inteiro mais próximo ou para o múltiplo mais próximo de significância
+COMBIN = COMBIN ## Retorna o número de combinações de um determinado número de objetos
+COS = COS ## Retorna o cosseno de um número
+COSH = COSH ## Retorna o cosseno hiperbólico de um número
+DEGREES = GRAUS ## Converte radianos em graus
+EVEN = PAR ## Arredonda um número para cima até o inteiro par mais próximo
+EXP = EXP ## Retorna e elevado à potência de um número especificado
+FACT = FATORIAL ## Retorna o fatorial de um número
+FACTDOUBLE = FATDUPLO ## Retorna o fatorial duplo de um número
+FLOOR = ARREDMULTB ## Arredonda um número para baixo até zero
+GCD = MDC ## Retorna o máximo divisor comum
+INT = INT ## Arredonda um número para baixo até o número inteiro mais próximo
+LCM = MMC ## Retorna o mínimo múltiplo comum
+LN = LN ## Retorna o logaritmo natural de um número
+LOG = LOG ## Retorna o logaritmo de um número de uma base especificada
+LOG10 = LOG10 ## Retorna o logaritmo de base 10 de um número
+MDETERM = MATRIZ.DETERM ## Retorna o determinante de uma matriz de uma variável do tipo matriz
+MINVERSE = MATRIZ.INVERSO ## Retorna a matriz inversa de uma matriz
+MMULT = MATRIZ.MULT ## Retorna o produto de duas matrizes
+MOD = RESTO ## Retorna o resto da divisão
+MROUND = MARRED ## Retorna um número arredondado ao múltiplo desejado
+MULTINOMIAL = MULTINOMIAL ## Retorna o multinomial de um conjunto de números
+ODD = ÍMPAR ## Arredonda um número para cima até o inteiro ímpar mais próximo
+PI = PI ## Retorna o valor de Pi
+POWER = POTÊNCIA ## Fornece o resultado de um número elevado a uma potência
+PRODUCT = MULT ## Multiplica seus argumentos
+QUOTIENT = QUOCIENTE ## Retorna a parte inteira de uma divisão
+RADIANS = RADIANOS ## Converte graus em radianos
+RAND = ALEATÓRIO ## Retorna um número aleatório entre 0 e 1
+RANDBETWEEN = ALEATÓRIOENTRE ## Retorna um número aleatório entre os números especificados
+ROMAN = ROMANO ## Converte um algarismo arábico em romano, como texto
+ROUND = ARRED ## Arredonda um número até uma quantidade especificada de dígitos
+ROUNDDOWN = ARREDONDAR.PARA.BAIXO ## Arredonda um número para baixo até zero
+ROUNDUP = ARREDONDAR.PARA.CIMA ## Arredonda um número para cima, afastando-o de zero
+SERIESSUM = SOMASEQÜÊNCIA ## Retorna a soma de uma série polinomial baseada na fórmula
+SIGN = SINAL ## Retorna o sinal de um número
+SIN = SEN ## Retorna o seno de um ângulo dado
+SINH = SENH ## Retorna o seno hiperbólico de um número
+SQRT = RAIZ ## Retorna uma raiz quadrada positiva
+SQRTPI = RAIZPI ## Retorna a raiz quadrada de (núm* pi)
+SUBTOTAL = SUBTOTAL ## Retorna um subtotal em uma lista ou em um banco de dados
+SUM = SOMA ## Soma seus argumentos
+SUMIF = SOMASE ## Adiciona as células especificadas por um determinado critério
+SUMIFS = SOMASE ## Adiciona as células em um intervalo que atende a vários critérios
+SUMPRODUCT = SOMARPRODUTO ## Retorna a soma dos produtos de componentes correspondentes de matrizes
+SUMSQ = SOMAQUAD ## Retorna a soma dos quadrados dos argumentos
+SUMX2MY2 = SOMAX2DY2 ## Retorna a soma da diferença dos quadrados dos valores correspondentes em duas matrizes
+SUMX2PY2 = SOMAX2SY2 ## Retorna a soma da soma dos quadrados dos valores correspondentes em duas matrizes
+SUMXMY2 = SOMAXMY2 ## Retorna a soma dos quadrados das diferenças dos valores correspondentes em duas matrizes
+TAN = TAN ## Retorna a tangente de um número
+TANH = TANH ## Retorna a tangente hiperbólica de um número
+TRUNC = TRUNCAR ## Trunca um número para um inteiro
+
+
+##
+## Statistical functions Funções estatísticas
+##
+AVEDEV = DESV.MÉDIO ## Retorna a média aritmética dos desvios médios dos pontos de dados a partir de sua média
+AVERAGE = MÉDIA ## Retorna a média dos argumentos
+AVERAGEA = MÉDIAA ## Retorna a média dos argumentos, inclusive números, texto e valores lógicos
+AVERAGEIF = MÉDIASE ## Retorna a média (média aritmética) de todas as células em um intervalo que atendem a um determinado critério
+AVERAGEIFS = MÉDIASES ## Retorna a média (média aritmética) de todas as células que atendem a múltiplos critérios.
+BETADIST = DISTBETA ## Retorna a função de distribuição cumulativa beta
+BETAINV = BETA.ACUM.INV ## Retorna o inverso da função de distribuição cumulativa para uma distribuição beta especificada
+BINOMDIST = DISTRBINOM ## Retorna a probabilidade de distribuição binomial do termo individual
+CHIDIST = DIST.QUI ## Retorna a probabilidade unicaudal da distribuição qui-quadrada
+CHIINV = INV.QUI ## Retorna o inverso da probabilidade uni-caudal da distribuição qui-quadrada
+CHITEST = TESTE.QUI ## Retorna o teste para independência
+CONFIDENCE = INT.CONFIANÇA ## Retorna o intervalo de confiança para uma média da população
+CORREL = CORREL ## Retorna o coeficiente de correlação entre dois conjuntos de dados
+COUNT = CONT.NÚM ## Calcula quantos números há na lista de argumentos
+COUNTA = CONT.VALORES ## Calcula quantos valores há na lista de argumentos
+COUNTBLANK = CONTAR.VAZIO ## Conta o número de células vazias no intervalo especificado
+COUNTIF = CONT.SE ## Calcula o número de células não vazias em um intervalo que corresponde a determinados critérios
+COUNTIFS = CONT.SES ## Conta o número de células dentro de um intervalo que atende a múltiplos critérios
+COVAR = COVAR ## Retorna a covariância, a média dos produtos dos desvios pares
+CRITBINOM = CRIT.BINOM ## Retorna o menor valor para o qual a distribuição binomial cumulativa é menor ou igual ao valor padrão
+DEVSQ = DESVQ ## Retorna a soma dos quadrados dos desvios
+EXPONDIST = DISTEXPON ## Retorna a distribuição exponencial
+FDIST = DISTF ## Retorna a distribuição de probabilidade F
+FINV = INVF ## Retorna o inverso da distribuição de probabilidades F
+FISHER = FISHER ## Retorna a transformação Fisher
+FISHERINV = FISHERINV ## Retorna o inverso da transformação Fisher
+FORECAST = PREVISÃO ## Retorna um valor ao longo de uma linha reta
+FREQUENCY = FREQÜÊNCIA ## Retorna uma distribuição de freqüência como uma matriz vertical
+FTEST = TESTEF ## Retorna o resultado de um teste F
+GAMMADIST = DISTGAMA ## Retorna a distribuição gama
+GAMMAINV = INVGAMA ## Retorna o inverso da distribuição cumulativa gama
+GAMMALN = LNGAMA ## Retorna o logaritmo natural da função gama, G(x)
+GEOMEAN = MÉDIA.GEOMÉTRICA ## Retorna a média geométrica
+GROWTH = CRESCIMENTO ## Retorna valores ao longo de uma tendência exponencial
+HARMEAN = MÉDIA.HARMÔNICA ## Retorna a média harmônica
+HYPGEOMDIST = DIST.HIPERGEOM ## Retorna a distribuição hipergeométrica
+INTERCEPT = INTERCEPÇÃO ## Retorna a intercepção da linha de regressão linear
+KURT = CURT ## Retorna a curtose de um conjunto de dados
+LARGE = MAIOR ## Retorna o maior valor k-ésimo de um conjunto de dados
+LINEST = PROJ.LIN ## Retorna os parâmetros de uma tendência linear
+LOGEST = PROJ.LOG ## Retorna os parâmetros de uma tendência exponencial
+LOGINV = INVLOG ## Retorna o inverso da distribuição lognormal
+LOGNORMDIST = DIST.LOGNORMAL ## Retorna a distribuição lognormal cumulativa
+MAX = MÁXIMO ## Retorna o valor máximo em uma lista de argumentos
+MAXA = MÁXIMOA ## Retorna o maior valor em uma lista de argumentos, inclusive números, texto e valores lógicos
+MEDIAN = MED ## Retorna a mediana dos números indicados
+MIN = MÍNIMO ## Retorna o valor mínimo em uma lista de argumentos
+MINA = MÍNIMOA ## Retorna o menor valor em uma lista de argumentos, inclusive números, texto e valores lógicos
+MODE = MODO ## Retorna o valor mais comum em um conjunto de dados
+NEGBINOMDIST = DIST.BIN.NEG ## Retorna a distribuição binomial negativa
+NORMDIST = DIST.NORM ## Retorna a distribuição cumulativa normal
+NORMINV = INV.NORM ## Retorna o inverso da distribuição cumulativa normal
+NORMSDIST = DIST.NORMP ## Retorna a distribuição cumulativa normal padrão
+NORMSINV = INV.NORMP ## Retorna o inverso da distribuição cumulativa normal padrão
+PEARSON = PEARSON ## Retorna o coeficiente de correlação do momento do produto Pearson
+PERCENTILE = PERCENTIL ## Retorna o k-ésimo percentil de valores em um intervalo
+PERCENTRANK = ORDEM.PORCENTUAL ## Retorna a ordem percentual de um valor em um conjunto de dados
+PERMUT = PERMUT ## Retorna o número de permutações de um determinado número de objetos
+POISSON = POISSON ## Retorna a distribuição Poisson
+PROB = PROB ## Retorna a probabilidade de valores em um intervalo estarem entre dois limites
+QUARTILE = QUARTIL ## Retorna o quartil do conjunto de dados
+RANK = ORDEM ## Retorna a posição de um número em uma lista de números
+RSQ = RQUAD ## Retorna o quadrado do coeficiente de correlação do momento do produto de Pearson
+SKEW = DISTORÇÃO ## Retorna a distorção de uma distribuição
+SLOPE = INCLINAÇÃO ## Retorna a inclinação da linha de regressão linear
+SMALL = MENOR ## Retorna o menor valor k-ésimo do conjunto de dados
+STANDARDIZE = PADRONIZAR ## Retorna um valor normalizado
+STDEV = DESVPAD ## Estima o desvio padrão com base em uma amostra
+STDEVA = DESVPADA ## Estima o desvio padrão com base em uma amostra, inclusive números, texto e valores lógicos
+STDEVP = DESVPADP ## Calcula o desvio padrão com base na população total
+STDEVPA = DESVPADPA ## Calcula o desvio padrão com base na população total, inclusive números, texto e valores lógicos
+STEYX = EPADYX ## Retorna o erro padrão do valor-y previsto para cada x da regressão
+TDIST = DISTT ## Retorna a distribuição t de Student
+TINV = INVT ## Retorna o inverso da distribuição t de Student
+TREND = TENDÊNCIA ## Retorna valores ao longo de uma tendência linear
+TRIMMEAN = MÉDIA.INTERNA ## Retorna a média do interior de um conjunto de dados
+TTEST = TESTET ## Retorna a probabilidade associada ao teste t de Student
+VAR = VAR ## Estima a variância com base em uma amostra
+VARA = VARA ## Estima a variância com base em uma amostra, inclusive números, texto e valores lógicos
+VARP = VARP ## Calcula a variância com base na população inteira
+VARPA = VARPA ## Calcula a variância com base na população total, inclusive números, texto e valores lógicos
+WEIBULL = WEIBULL ## Retorna a distribuição Weibull
+ZTEST = TESTEZ ## Retorna o valor de probabilidade uni-caudal de um teste-z
+
+
+##
+## Text functions Funções de texto
+##
+ASC = ASC ## Altera letras do inglês ou katakana de largura total (bytes duplos) dentro de uma seqüência de caracteres para caracteres de meia largura (byte único)
+BAHTTEXT = BAHTTEXT ## Converte um número em um texto, usando o formato de moeda ß (baht)
+CHAR = CARACT ## Retorna o caractere especificado pelo número de código
+CLEAN = TIRAR ## Remove todos os caracteres do texto que não podem ser impressos
+CODE = CÓDIGO ## Retorna um código numérico para o primeiro caractere de uma seqüência de caracteres de texto
+CONCATENATE = CONCATENAR ## Agrupa vários itens de texto em um único item de texto
+DOLLAR = MOEDA ## Converte um número em texto, usando o formato de moeda $ (dólar)
+EXACT = EXATO ## Verifica se dois valores de texto são idênticos
+FIND = PROCURAR ## Procura um valor de texto dentro de outro (diferencia maiúsculas de minúsculas)
+FINDB = PROCURARB ## Procura um valor de texto dentro de outro (diferencia maiúsculas de minúsculas)
+FIXED = DEF.NÚM.DEC ## Formata um número como texto com um número fixo de decimais
+JIS = JIS ## Altera letras do inglês ou katakana de meia largura (byte único) dentro de uma seqüência de caracteres para caracteres de largura total (bytes duplos)
+LEFT = ESQUERDA ## Retorna os caracteres mais à esquerda de um valor de texto
+LEFTB = ESQUERDAB ## Retorna os caracteres mais à esquerda de um valor de texto
+LEN = NÚM.CARACT ## Retorna o número de caracteres em uma seqüência de texto
+LENB = NÚM.CARACTB ## Retorna o número de caracteres em uma seqüência de texto
+LOWER = MINÚSCULA ## Converte texto para minúsculas
+MID = EXT.TEXTO ## Retorna um número específico de caracteres de uma seqüência de texto começando na posição especificada
+MIDB = EXT.TEXTOB ## Retorna um número específico de caracteres de uma seqüência de texto começando na posição especificada
+PHONETIC = FONÉTICA ## Extrai os caracteres fonéticos (furigana) de uma seqüência de caracteres de texto
+PROPER = PRI.MAIÚSCULA ## Coloca a primeira letra de cada palavra em maiúscula em um valor de texto
+REPLACE = MUDAR ## Muda os caracteres dentro do texto
+REPLACEB = MUDARB ## Muda os caracteres dentro do texto
+REPT = REPT ## Repete o texto um determinado número de vezes
+RIGHT = DIREITA ## Retorna os caracteres mais à direita de um valor de texto
+RIGHTB = DIREITAB ## Retorna os caracteres mais à direita de um valor de texto
+SEARCH = LOCALIZAR ## Localiza um valor de texto dentro de outro (não diferencia maiúsculas de minúsculas)
+SEARCHB = LOCALIZARB ## Localiza um valor de texto dentro de outro (não diferencia maiúsculas de minúsculas)
+SUBSTITUTE = SUBSTITUIR ## Substitui um novo texto por um texto antigo em uma seqüência de texto
+T = T ## Converte os argumentos em texto
+TEXT = TEXTO ## Formata um número e o converte em texto
+TRIM = ARRUMAR ## Remove espaços do texto
+UPPER = MAIÚSCULA ## Converte o texto em maiúsculas
+VALUE = VALOR ## Converte um argumento de texto em um número
diff --git a/htdocs/includes/phpexcel/PHPExcel/locale/pt/functions b/htdocs/includes/phpexcel/PHPExcel/locale/pt/functions
index d8e9082f5f8..05e8bcaea7d 100644
--- a/htdocs/includes/phpexcel/PHPExcel/locale/pt/functions
+++ b/htdocs/includes/phpexcel/PHPExcel/locale/pt/functions
@@ -1,408 +1,408 @@
-##
-## Add-in and Automation functions Funções de Suplemento e Automatização
-##
-GETPIVOTDATA = OBTERDADOSDIN ## Devolve dados armazenados num relatório de Tabela Dinâmica
-
-
-##
-## Cube functions Funções de cubo
-##
-CUBEKPIMEMBER = MEMBROKPICUBO ## Devolve o nome, propriedade e medição de um KPI (key performance indicator) e apresenta o nome e a propriedade na célula. Um KPI é uma medida quantificável, como, por exemplo, o lucro mensal bruto ou a rotatividade trimestral de pessoal, utilizada para monitorizar o desempenho de uma organização.
-CUBEMEMBER = MEMBROCUBO ## Devolve um membro ou cadeia de identificação numa hierarquia de cubo. Utilizada para validar a existência do membro ou cadeia de identificação no cubo.
-CUBEMEMBERPROPERTY = PROPRIEDADEMEMBROCUBO ## Devolve o valor de uma propriedade de membro no cubo. Utilizada para validar a existência de um nome de membro no cubo e para devolver a propriedade especificada para esse membro.
-CUBERANKEDMEMBER = MEMBROCLASSIFICADOCUBO ## Devolve o enésimo ou a classificação mais alta num conjunto. Utilizada para devolver um ou mais elementos num conjunto, tal como o melhor vendedor ou os 10 melhores alunos.
-CUBESET = CONJUNTOCUBO ## Define um conjunto calculado de membros ou cadeias de identificação enviando uma expressão de conjunto para o cubo no servidor, que cria o conjunto e, em seguida, devolve o conjunto ao Microsoft Office Excel.
-CUBESETCOUNT = CONTARCONJUNTOCUBO ## Devolve o número de itens num conjunto.
-CUBEVALUE = VALORCUBO ## Devolve um valor agregado do cubo.
-
-
-##
-## Database functions Funções de base de dados
-##
-DAVERAGE = BDMÉDIA ## Devolve a média das entradas da base de dados seleccionadas
-DCOUNT = BDCONTAR ## Conta as células que contêm números numa base de dados
-DCOUNTA = BDCONTAR.VAL ## Conta as células que não estejam em branco numa base de dados
-DGET = BDOBTER ## Extrai de uma base de dados um único registo que corresponde aos critérios especificados
-DMAX = BDMÁX ## Devolve o valor máximo das entradas da base de dados seleccionadas
-DMIN = BDMÍN ## Devolve o valor mínimo das entradas da base de dados seleccionadas
-DPRODUCT = BDMULTIPL ## Multiplica os valores de um determinado campo de registos que correspondem aos critérios numa base de dados
-DSTDEV = BDDESVPAD ## Calcula o desvio-padrão com base numa amostra de entradas da base de dados seleccionadas
-DSTDEVP = BDDESVPADP ## Calcula o desvio-padrão com base na população total das entradas da base de dados seleccionadas
-DSUM = BDSOMA ## Adiciona os números na coluna de campo dos registos de base de dados que correspondem aos critérios
-DVAR = BDVAR ## Calcula a variância com base numa amostra das entradas de base de dados seleccionadas
-DVARP = BDVARP ## Calcula a variância com base na população total das entradas de base de dados seleccionadas
-
-
-##
-## Date and time functions Funções de data e hora
-##
-DATE = DATA ## Devolve o número de série de uma determinada data
-DATEVALUE = DATA.VALOR ## Converte uma data em forma de texto num número de série
-DAY = DIA ## Converte um número de série num dia do mês
-DAYS360 = DIAS360 ## Calcula o número de dias entre duas datas com base num ano com 360 dias
-EDATE = DATAM ## Devolve um número de série de data que corresponde ao número de meses indicado antes ou depois da data de início
-EOMONTH = FIMMÊS ## Devolve o número de série do último dia do mês antes ou depois de um número de meses especificado
-HOUR = HORA ## Converte um número de série numa hora
-MINUTE = MINUTO ## Converte um número de série num minuto
-MONTH = MÊS ## Converte um número de série num mês
-NETWORKDAYS = DIATRABALHOTOTAL ## Devolve o número total de dias úteis entre duas datas
-NOW = AGORA ## Devolve o número de série da data e hora actuais
-SECOND = SEGUNDO ## Converte um número de série num segundo
-TIME = TEMPO ## Devolve o número de série de um determinado tempo
-TIMEVALUE = VALOR.TEMPO ## Converte um tempo em forma de texto num número de série
-TODAY = HOJE ## Devolve o número de série da data actual
-WEEKDAY = DIA.SEMANA ## Converte um número de série num dia da semana
-WEEKNUM = NÚMSEMANA ## Converte um número de série num número que representa o número da semana num determinado ano
-WORKDAY = DIA.TRABALHO ## Devolve o número de série da data antes ou depois de um número de dias úteis especificado
-YEAR = ANO ## Converte um número de série num ano
-YEARFRAC = FRACÇÃOANO ## Devolve a fracção de ano que representa o número de dias inteiros entre a data_de_início e a data_de_fim
-
-
-##
-## Engineering functions Funções de engenharia
-##
-BESSELI = BESSELI ## Devolve a função de Bessel modificada In(x)
-BESSELJ = BESSELJ ## Devolve a função de Bessel Jn(x)
-BESSELK = BESSELK ## Devolve a função de Bessel modificada Kn(x)
-BESSELY = BESSELY ## Devolve a função de Bessel Yn(x)
-BIN2DEC = BINADEC ## Converte um número binário em decimal
-BIN2HEX = BINAHEX ## Converte um número binário em hexadecimal
-BIN2OCT = BINAOCT ## Converte um número binário em octal
-COMPLEX = COMPLEXO ## Converte coeficientes reais e imaginários num número complexo
-CONVERT = CONVERTER ## Converte um número de um sistema de medida noutro
-DEC2BIN = DECABIN ## Converte um número decimal em binário
-DEC2HEX = DECAHEX ## Converte um número decimal em hexadecimal
-DEC2OCT = DECAOCT ## Converte um número decimal em octal
-DELTA = DELTA ## Testa se dois valores são iguais
-ERF = FUNCERRO ## Devolve a função de erro
-ERFC = FUNCERROCOMPL ## Devolve a função de erro complementar
-GESTEP = DEGRAU ## Testa se um número é maior do que um valor limite
-HEX2BIN = HEXABIN ## Converte um número hexadecimal em binário
-HEX2DEC = HEXADEC ## Converte um número hexadecimal em decimal
-HEX2OCT = HEXAOCT ## Converte um número hexadecimal em octal
-IMABS = IMABS ## Devolve o valor absoluto (módulo) de um número complexo
-IMAGINARY = IMAGINÁRIO ## Devolve o coeficiente imaginário de um número complexo
-IMARGUMENT = IMARG ## Devolve o argumento Teta, um ângulo expresso em radianos
-IMCONJUGATE = IMCONJ ## Devolve o conjugado complexo de um número complexo
-IMCOS = IMCOS ## Devolve o co-seno de um número complexo
-IMDIV = IMDIV ## Devolve o quociente de dois números complexos
-IMEXP = IMEXP ## Devolve o exponencial de um número complexo
-IMLN = IMLN ## Devolve o logaritmo natural de um número complexo
-IMLOG10 = IMLOG10 ## Devolve o logaritmo de base 10 de um número complexo
-IMLOG2 = IMLOG2 ## Devolve o logaritmo de base 2 de um número complexo
-IMPOWER = IMPOT ## Devolve um número complexo elevado a uma potência inteira
-IMPRODUCT = IMPROD ## Devolve o produto de números complexos
-IMREAL = IMREAL ## Devolve o coeficiente real de um número complexo
-IMSIN = IMSENO ## Devolve o seno de um número complexo
-IMSQRT = IMRAIZ ## Devolve a raiz quadrada de um número complexo
-IMSUB = IMSUBTR ## Devolve a diferença entre dois números complexos
-IMSUM = IMSOMA ## Devolve a soma de números complexos
-OCT2BIN = OCTABIN ## Converte um número octal em binário
-OCT2DEC = OCTADEC ## Converte um número octal em decimal
-OCT2HEX = OCTAHEX ## Converte um número octal em hexadecimal
-
-
-##
-## Financial functions Funções financeiras
-##
-ACCRINT = JUROSACUM ## Devolve os juros acumulados de um título que paga juros periódicos
-ACCRINTM = JUROSACUMV ## Devolve os juros acumulados de um título que paga juros no vencimento
-AMORDEGRC = AMORDEGRC ## Devolve a depreciação correspondente a cada período contabilístico utilizando um coeficiente de depreciação
-AMORLINC = AMORLINC ## Devolve a depreciação correspondente a cada período contabilístico
-COUPDAYBS = CUPDIASINLIQ ## Devolve o número de dias entre o início do período do cupão e a data de regularização
-COUPDAYS = CUPDIAS ## Devolve o número de dias no período do cupão que contém a data de regularização
-COUPDAYSNC = CUPDIASPRÓX ## Devolve o número de dias entre a data de regularização e a data do cupão seguinte
-COUPNCD = CUPDATAPRÓX ## Devolve a data do cupão seguinte após a data de regularização
-COUPNUM = CUPNÚM ## Devolve o número de cupões a serem pagos entre a data de regularização e a data de vencimento
-COUPPCD = CUPDATAANT ## Devolve a data do cupão anterior antes da data de regularização
-CUMIPMT = PGTOJURACUM ## Devolve os juros cumulativos pagos entre dois períodos
-CUMPRINC = PGTOCAPACUM ## Devolve o capital cumulativo pago a título de empréstimo entre dois períodos
-DB = BD ## Devolve a depreciação de um activo relativo a um período especificado utilizando o método das quotas degressivas fixas
-DDB = BDD ## Devolve a depreciação de um activo relativo a um período especificado utilizando o método das quotas degressivas duplas ou qualquer outro método especificado
-DISC = DESC ## Devolve a taxa de desconto de um título
-DOLLARDE = MOEDADEC ## Converte um preço em unidade monetária, expresso como uma fracção, num preço em unidade monetária, expresso como um número decimal
-DOLLARFR = MOEDAFRA ## Converte um preço em unidade monetária, expresso como um número decimal, num preço em unidade monetária, expresso como uma fracção
-DURATION = DURAÇÃO ## Devolve a duração anual de um título com pagamentos de juros periódicos
-EFFECT = EFECTIVA ## Devolve a taxa de juros anual efectiva
-FV = VF ## Devolve o valor futuro de um investimento
-FVSCHEDULE = VFPLANO ## Devolve o valor futuro de um capital inicial após a aplicação de uma série de taxas de juro compostas
-INTRATE = TAXAJUROS ## Devolve a taxa de juros de um título investido na totalidade
-IPMT = IPGTO ## Devolve o pagamento dos juros de um investimento durante um determinado período
-IRR = TIR ## Devolve a taxa de rentabilidade interna para uma série de fluxos monetários
-ISPMT = É.PGTO ## Calcula os juros pagos durante um período específico de um investimento
-MDURATION = MDURAÇÃO ## Devolve a duração modificada de Macauley de um título com um valor de paridade equivalente a € 100
-MIRR = MTIR ## Devolve a taxa interna de rentabilidade em que os fluxos monetários positivos e negativos são financiados com taxas diferentes
-NOMINAL = NOMINAL ## Devolve a taxa de juros nominal anual
-NPER = NPER ## Devolve o número de períodos de um investimento
-NPV = VAL ## Devolve o valor actual líquido de um investimento com base numa série de fluxos monetários periódicos e numa taxa de desconto
-ODDFPRICE = PREÇOPRIMINC ## Devolve o preço por € 100 do valor nominal de um título com um período inicial incompleto
-ODDFYIELD = LUCROPRIMINC ## Devolve o lucro de um título com um período inicial incompleto
-ODDLPRICE = PREÇOÚLTINC ## Devolve o preço por € 100 do valor nominal de um título com um período final incompleto
-ODDLYIELD = LUCROÚLTINC ## Devolve o lucro de um título com um período final incompleto
-PMT = PGTO ## Devolve o pagamento periódico de uma anuidade
-PPMT = PPGTO ## Devolve o pagamento sobre o capital de um investimento num determinado período
-PRICE = PREÇO ## Devolve o preço por € 100 do valor nominal de um título que paga juros periódicos
-PRICEDISC = PREÇODESC ## Devolve o preço por € 100 do valor nominal de um título descontado
-PRICEMAT = PREÇOVENC ## Devolve o preço por € 100 do valor nominal de um título que paga juros no vencimento
-PV = VA ## Devolve o valor actual de um investimento
-RATE = TAXA ## Devolve a taxa de juros por período de uma anuidade
-RECEIVED = RECEBER ## Devolve o montante recebido no vencimento de um título investido na totalidade
-SLN = AMORT ## Devolve uma depreciação linear de um activo durante um período
-SYD = AMORTD ## Devolve a depreciação por algarismos da soma dos anos de um activo durante um período especificado
-TBILLEQ = OTN ## Devolve o lucro de um título equivalente a uma Obrigação do Tesouro
-TBILLPRICE = OTNVALOR ## Devolve o preço por € 100 de valor nominal de uma Obrigação do Tesouro
-TBILLYIELD = OTNLUCRO ## Devolve o lucro de uma Obrigação do Tesouro
-VDB = BDV ## Devolve a depreciação de um activo relativo a um período específico ou parcial utilizando um método de quotas degressivas
-XIRR = XTIR ## Devolve a taxa interna de rentabilidade de um plano de fluxos monetários que não seja necessariamente periódica
-XNPV = XVAL ## Devolve o valor actual líquido de um plano de fluxos monetários que não seja necessariamente periódico
-YIELD = LUCRO ## Devolve o lucro de um título que paga juros periódicos
-YIELDDISC = LUCRODESC ## Devolve o lucro anual de um título emitido abaixo do valor nominal, por exemplo, uma Obrigação do Tesouro
-YIELDMAT = LUCROVENC ## Devolve o lucro anual de um título que paga juros na data de vencimento
-
-
-##
-## Information functions Funções de informação
-##
-CELL = CÉL ## Devolve informações sobre a formatação, localização ou conteúdo de uma célula
-ERROR.TYPE = TIPO.ERRO ## Devolve um número correspondente a um tipo de erro
-INFO = INFORMAÇÃO ## Devolve informações sobre o ambiente de funcionamento actual
-ISBLANK = É.CÉL.VAZIA ## Devolve VERDADEIRO se o valor estiver em branco
-ISERR = É.ERROS ## Devolve VERDADEIRO se o valor for um valor de erro diferente de #N/D
-ISERROR = É.ERRO ## Devolve VERDADEIRO se o valor for um valor de erro
-ISEVEN = ÉPAR ## Devolve VERDADEIRO se o número for par
-ISLOGICAL = É.LÓGICO ## Devolve VERDADEIRO se o valor for lógico
-ISNA = É.NÃO.DISP ## Devolve VERDADEIRO se o valor for o valor de erro #N/D
-ISNONTEXT = É.NÃO.TEXTO ## Devolve VERDADEIRO se o valor não for texto
-ISNUMBER = É.NÚM ## Devolve VERDADEIRO se o valor for um número
-ISODD = ÉÍMPAR ## Devolve VERDADEIRO se o número for ímpar
-ISREF = É.REF ## Devolve VERDADEIRO se o valor for uma referência
-ISTEXT = É.TEXTO ## Devolve VERDADEIRO se o valor for texto
-N = N ## Devolve um valor convertido num número
-NA = NÃO.DISP ## Devolve o valor de erro #N/D
-TYPE = TIPO ## Devolve um número que indica o tipo de dados de um valor
-
-
-##
-## Logical functions Funções lógicas
-##
-AND = E ## Devolve VERDADEIRO se todos os respectivos argumentos corresponderem a VERDADEIRO
-FALSE = FALSO ## Devolve o valor lógico FALSO
-IF = SE ## Especifica um teste lógico a ser executado
-IFERROR = SE.ERRO ## Devolve um valor definido pelo utilizador se ocorrer um erro na fórmula, e devolve o resultado da fórmula se não ocorrer nenhum erro
-NOT = NÃO ## Inverte a lógica do respectivo argumento
-OR = OU ## Devolve VERDADEIRO se qualquer argumento for VERDADEIRO
-TRUE = VERDADEIRO ## Devolve o valor lógico VERDADEIRO
-
-
-##
-## Lookup and reference functions Funções de pesquisa e referência
-##
-ADDRESS = ENDEREÇO ## Devolve uma referência a uma única célula numa folha de cálculo como texto
-AREAS = ÁREAS ## Devolve o número de áreas numa referência
-CHOOSE = SELECCIONAR ## Selecciona um valor a partir de uma lista de valores
-COLUMN = COL ## Devolve o número da coluna de uma referência
-COLUMNS = COLS ## Devolve o número de colunas numa referência
-HLOOKUP = PROCH ## Procura na linha superior de uma matriz e devolve o valor da célula indicada
-HYPERLINK = HIPERLIGAÇÃO ## Cria um atalho ou hiperligação que abre um documento armazenado num servidor de rede, numa intranet ou na Internet
-INDEX = ÍNDICE ## Utiliza um índice para escolher um valor de uma referência ou de uma matriz
-INDIRECT = INDIRECTO ## Devolve uma referência indicada por um valor de texto
-LOOKUP = PROC ## Procura valores num vector ou numa matriz
-MATCH = CORRESP ## Procura valores numa referência ou numa matriz
-OFFSET = DESLOCAMENTO ## Devolve o deslocamento de referência de uma determinada referência
-ROW = LIN ## Devolve o número da linha de uma referência
-ROWS = LINS ## Devolve o número de linhas numa referência
-RTD = RTD ## Obtém dados em tempo real a partir de um programa que suporte automatização COM (automatização: modo de trabalhar com objectos de uma aplicação a partir de outra aplicação ou ferramenta de desenvolvimento. Anteriormente conhecida como automatização OLE, a automatização é uma norma da indústria de software e uma funcionalidade COM (Component Object Model).)
-TRANSPOSE = TRANSPOR ## Devolve a transposição de uma matriz
-VLOOKUP = PROCV ## Procura na primeira coluna de uma matriz e percorre a linha para devolver o valor de uma célula
-
-
-##
-## Math and trigonometry functions Funções matemáticas e trigonométricas
-##
-ABS = ABS ## Devolve o valor absoluto de um número
-ACOS = ACOS ## Devolve o arco de co-seno de um número
-ACOSH = ACOSH ## Devolve o co-seno hiperbólico inverso de um número
-ASIN = ASEN ## Devolve o arco de seno de um número
-ASINH = ASENH ## Devolve o seno hiperbólico inverso de um número
-ATAN = ATAN ## Devolve o arco de tangente de um número
-ATAN2 = ATAN2 ## Devolve o arco de tangente das coordenadas x e y
-ATANH = ATANH ## Devolve a tangente hiperbólica inversa de um número
-CEILING = ARRED.EXCESSO ## Arredonda um número para o número inteiro mais próximo ou para o múltiplo de significância mais próximo
-COMBIN = COMBIN ## Devolve o número de combinações de um determinado número de objectos
-COS = COS ## Devolve o co-seno de um número
-COSH = COSH ## Devolve o co-seno hiperbólico de um número
-DEGREES = GRAUS ## Converte radianos em graus
-EVEN = PAR ## Arredonda um número por excesso para o número inteiro mais próximo
-EXP = EXP ## Devolve e elevado à potência de um determinado número
-FACT = FACTORIAL ## Devolve o factorial de um número
-FACTDOUBLE = FACTDUPLO ## Devolve o factorial duplo de um número
-FLOOR = ARRED.DEFEITO ## Arredonda um número por defeito até zero
-GCD = MDC ## Devolve o maior divisor comum
-INT = INT ## Arredonda um número por defeito para o número inteiro mais próximo
-LCM = MMC ## Devolve o mínimo múltiplo comum
-LN = LN ## Devolve o logaritmo natural de um número
-LOG = LOG ## Devolve o logaritmo de um número com uma base especificada
-LOG10 = LOG10 ## Devolve o logaritmo de base 10 de um número
-MDETERM = MATRIZ.DETERM ## Devolve o determinante matricial de uma matriz
-MINVERSE = MATRIZ.INVERSA ## Devolve o inverso matricial de uma matriz
-MMULT = MATRIZ.MULT ## Devolve o produto matricial de duas matrizes
-MOD = RESTO ## Devolve o resto da divisão
-MROUND = MARRED ## Devolve um número arredondado para o múltiplo pretendido
-MULTINOMIAL = POLINOMIAL ## Devolve o polinomial de um conjunto de números
-ODD = ÍMPAR ## Arredonda por excesso um número para o número inteiro ímpar mais próximo
-PI = PI ## Devolve o valor de pi
-POWER = POTÊNCIA ## Devolve o resultado de um número elevado a uma potência
-PRODUCT = PRODUTO ## Multiplica os respectivos argumentos
-QUOTIENT = QUOCIENTE ## Devolve a parte inteira de uma divisão
-RADIANS = RADIANOS ## Converte graus em radianos
-RAND = ALEATÓRIO ## Devolve um número aleatório entre 0 e 1
-RANDBETWEEN = ALEATÓRIOENTRE ## Devolve um número aleatório entre os números especificados
-ROMAN = ROMANO ## Converte um número árabe em romano, como texto
-ROUND = ARRED ## Arredonda um número para um número de dígitos especificado
-ROUNDDOWN = ARRED.PARA.BAIXO ## Arredonda um número por defeito até zero
-ROUNDUP = ARRED.PARA.CIMA ## Arredonda um número por excesso, afastando-o de zero
-SERIESSUM = SOMASÉRIE ## Devolve a soma de uma série de potências baseada na fórmula
-SIGN = SINAL ## Devolve o sinal de um número
-SIN = SEN ## Devolve o seno de um determinado ângulo
-SINH = SENH ## Devolve o seno hiperbólico de um número
-SQRT = RAIZQ ## Devolve uma raiz quadrada positiva
-SQRTPI = RAIZPI ## Devolve a raiz quadrada de (núm * pi)
-SUBTOTAL = SUBTOTAL ## Devolve um subtotal numa lista ou base de dados
-SUM = SOMA ## Adiciona os respectivos argumentos
-SUMIF = SOMA.SE ## Adiciona as células especificadas por um determinado critério
-SUMIFS = SOMA.SE.S ## Adiciona as células num intervalo que cumpre vários critérios
-SUMPRODUCT = SOMARPRODUTO ## Devolve a soma dos produtos de componentes de matrizes correspondentes
-SUMSQ = SOMARQUAD ## Devolve a soma dos quadrados dos argumentos
-SUMX2MY2 = SOMAX2DY2 ## Devolve a soma da diferença dos quadrados dos valores correspondentes em duas matrizes
-SUMX2PY2 = SOMAX2SY2 ## Devolve a soma da soma dos quadrados dos valores correspondentes em duas matrizes
-SUMXMY2 = SOMAXMY2 ## Devolve a soma dos quadrados da diferença dos valores correspondentes em duas matrizes
-TAN = TAN ## Devolve a tangente de um número
-TANH = TANH ## Devolve a tangente hiperbólica de um número
-TRUNC = TRUNCAR ## Trunca um número para um número inteiro
-
-
-##
-## Statistical functions Funções estatísticas
-##
-AVEDEV = DESV.MÉDIO ## Devolve a média aritmética dos desvios absolutos à média dos pontos de dados
-AVERAGE = MÉDIA ## Devolve a média dos respectivos argumentos
-AVERAGEA = MÉDIAA ## Devolve uma média dos respectivos argumentos, incluindo números, texto e valores lógicos
-AVERAGEIF = MÉDIA.SE ## Devolve a média aritmética de todas as células num intervalo que cumprem determinado critério
-AVERAGEIFS = MÉDIA.SE.S ## Devolve a média aritmética de todas as células que cumprem múltiplos critérios
-BETADIST = DISTBETA ## Devolve a função de distribuição cumulativa beta
-BETAINV = BETA.ACUM.INV ## Devolve o inverso da função de distribuição cumulativa relativamente a uma distribuição beta específica
-BINOMDIST = DISTRBINOM ## Devolve a probabilidade de distribuição binomial de termo individual
-CHIDIST = DIST.CHI ## Devolve a probabilidade unicaudal da distribuição qui-quadrada
-CHIINV = INV.CHI ## Devolve o inverso da probabilidade unicaudal da distribuição qui-quadrada
-CHITEST = TESTE.CHI ## Devolve o teste para independência
-CONFIDENCE = INT.CONFIANÇA ## Devolve o intervalo de confiança correspondente a uma média de população
-CORREL = CORREL ## Devolve o coeficiente de correlação entre dois conjuntos de dados
-COUNT = CONTAR ## Conta os números que existem na lista de argumentos
-COUNTA = CONTAR.VAL ## Conta os valores que existem na lista de argumentos
-COUNTBLANK = CONTAR.VAZIO ## Conta o número de células em branco num intervalo
-COUNTIF = CONTAR.SE ## Calcula o número de células num intervalo que corresponde aos critérios determinados
-COUNTIFS = CONTAR.SE.S ## Conta o número de células num intervalo que cumprem múltiplos critérios
-COVAR = COVAR ## Devolve a covariância, que é a média dos produtos de desvios de pares
-CRITBINOM = CRIT.BINOM ## Devolve o menor valor em que a distribuição binomial cumulativa é inferior ou igual a um valor de critério
-DEVSQ = DESVQ ## Devolve a soma dos quadrados dos desvios
-EXPONDIST = DISTEXPON ## Devolve a distribuição exponencial
-FDIST = DISTF ## Devolve a distribuição da probabilidade F
-FINV = INVF ## Devolve o inverso da distribuição da probabilidade F
-FISHER = FISHER ## Devolve a transformação Fisher
-FISHERINV = FISHERINV ## Devolve o inverso da transformação Fisher
-FORECAST = PREVISÃO ## Devolve um valor ao longo de uma tendência linear
-FREQUENCY = FREQUÊNCIA ## Devolve uma distribuição de frequência como uma matriz vertical
-FTEST = TESTEF ## Devolve o resultado de um teste F
-GAMMADIST = DISTGAMA ## Devolve a distribuição gama
-GAMMAINV = INVGAMA ## Devolve o inverso da distribuição gama cumulativa
-GAMMALN = LNGAMA ## Devolve o logaritmo natural da função gama, Γ(x)
-GEOMEAN = MÉDIA.GEOMÉTRICA ## Devolve a média geométrica
-GROWTH = CRESCIMENTO ## Devolve valores ao longo de uma tendência exponencial
-HARMEAN = MÉDIA.HARMÓNICA ## Devolve a média harmónica
-HYPGEOMDIST = DIST.HIPERGEOM ## Devolve a distribuição hipergeométrica
-INTERCEPT = INTERCEPTAR ## Devolve a intercepção da linha de regressão linear
-KURT = CURT ## Devolve a curtose de um conjunto de dados
-LARGE = MAIOR ## Devolve o maior valor k-ésimo de um conjunto de dados
-LINEST = PROJ.LIN ## Devolve os parâmetros de uma tendência linear
-LOGEST = PROJ.LOG ## Devolve os parâmetros de uma tendência exponencial
-LOGINV = INVLOG ## Devolve o inverso da distribuição normal logarítmica
-LOGNORMDIST = DIST.NORMALLOG ## Devolve a distribuição normal logarítmica cumulativa
-MAX = MÁXIMO ## Devolve o valor máximo numa lista de argumentos
-MAXA = MÁXIMOA ## Devolve o valor máximo numa lista de argumentos, incluindo números, texto e valores lógicos
-MEDIAN = MED ## Devolve a mediana dos números indicados
-MIN = MÍNIMO ## Devolve o valor mínimo numa lista de argumentos
-MINA = MÍNIMOA ## Devolve o valor mínimo numa lista de argumentos, incluindo números, texto e valores lógicos
-MODE = MODA ## Devolve o valor mais comum num conjunto de dados
-NEGBINOMDIST = DIST.BIN.NEG ## Devolve a distribuição binominal negativa
-NORMDIST = DIST.NORM ## Devolve a distribuição cumulativa normal
-NORMINV = INV.NORM ## Devolve o inverso da distribuição cumulativa normal
-NORMSDIST = DIST.NORMP ## Devolve a distribuição cumulativa normal padrão
-NORMSINV = INV.NORMP ## Devolve o inverso da distribuição cumulativa normal padrão
-PEARSON = PEARSON ## Devolve o coeficiente de correlação momento/produto de Pearson
-PERCENTILE = PERCENTIL ## Devolve o k-ésimo percentil de valores num intervalo
-PERCENTRANK = ORDEM.PERCENTUAL ## Devolve a ordem percentual de um valor num conjunto de dados
-PERMUT = PERMUTAR ## Devolve o número de permutações de um determinado número de objectos
-POISSON = POISSON ## Devolve a distribuição de Poisson
-PROB = PROB ## Devolve a probabilidade dos valores num intervalo se encontrarem entre dois limites
-QUARTILE = QUARTIL ## Devolve o quartil de um conjunto de dados
-RANK = ORDEM ## Devolve a ordem de um número numa lista numérica
-RSQ = RQUAD ## Devolve o quadrado do coeficiente de correlação momento/produto de Pearson
-SKEW = DISTORÇÃO ## Devolve a distorção de uma distribuição
-SLOPE = DECLIVE ## Devolve o declive da linha de regressão linear
-SMALL = MENOR ## Devolve o menor valor de k-ésimo de um conjunto de dados
-STANDARDIZE = NORMALIZAR ## Devolve um valor normalizado
-STDEV = DESVPAD ## Calcula o desvio-padrão com base numa amostra
-STDEVA = DESVPADA ## Calcula o desvio-padrão com base numa amostra, incluindo números, texto e valores lógicos
-STDEVP = DESVPADP ## Calcula o desvio-padrão com base na população total
-STDEVPA = DESVPADPA ## Calcula o desvio-padrão com base na população total, incluindo números, texto e valores lógicos
-STEYX = EPADYX ## Devolve o erro-padrão do valor de y previsto para cada x na regressão
-TDIST = DISTT ## Devolve a distribuição t de Student
-TINV = INVT ## Devolve o inverso da distribuição t de Student
-TREND = TENDÊNCIA ## Devolve valores ao longo de uma tendência linear
-TRIMMEAN = MÉDIA.INTERNA ## Devolve a média do interior de um conjunto de dados
-TTEST = TESTET ## Devolve a probabilidade associada ao teste t de Student
-VAR = VAR ## Calcula a variância com base numa amostra
-VARA = VARA ## Calcula a variância com base numa amostra, incluindo números, texto e valores lógicos
-VARP = VARP ## Calcula a variância com base na população total
-VARPA = VARPA ## Calcula a variância com base na população total, incluindo números, texto e valores lógicos
-WEIBULL = WEIBULL ## Devolve a distribuição Weibull
-ZTEST = TESTEZ ## Devolve o valor de probabilidade unicaudal de um teste-z
-
-
-##
-## Text functions Funções de texto
-##
-ASC = ASC ## Altera letras ou katakana de largura total (byte duplo) numa cadeia de caracteres para caracteres de largura média (byte único)
-BAHTTEXT = TEXTO.BAHT ## Converte um número em texto, utilizando o formato monetário ß (baht)
-CHAR = CARÁCT ## Devolve o carácter especificado pelo número de código
-CLEAN = LIMPAR ## Remove do texto todos os caracteres não imprimíveis
-CODE = CÓDIGO ## Devolve um código numérico correspondente ao primeiro carácter numa cadeia de texto
-CONCATENATE = CONCATENAR ## Agrupa vários itens de texto num único item de texto
-DOLLAR = MOEDA ## Converte um número em texto, utilizando o formato monetário € (Euro)
-EXACT = EXACTO ## Verifica se dois valores de texto são idênticos
-FIND = LOCALIZAR ## Localiza um valor de texto dentro de outro (sensível às maiúsculas e minúsculas)
-FINDB = LOCALIZARB ## Localiza um valor de texto dentro de outro (sensível às maiúsculas e minúsculas)
-FIXED = FIXA ## Formata um número como texto com um número fixo de decimais
-JIS = JIS ## Altera letras ou katakana de largura média (byte único) numa cadeia de caracteres para caracteres de largura total (byte duplo)
-LEFT = ESQUERDA ## Devolve os caracteres mais à esquerda de um valor de texto
-LEFTB = ESQUERDAB ## Devolve os caracteres mais à esquerda de um valor de texto
-LEN = NÚM.CARACT ## Devolve o número de caracteres de uma cadeia de texto
-LENB = NÚM.CARACTB ## Devolve o número de caracteres de uma cadeia de texto
-LOWER = MINÚSCULAS ## Converte o texto em minúsculas
-MID = SEG.TEXTO ## Devolve um número específico de caracteres de uma cadeia de texto, a partir da posição especificada
-MIDB = SEG.TEXTOB ## Devolve um número específico de caracteres de uma cadeia de texto, a partir da posição especificada
-PHONETIC = FONÉTICA ## Retira os caracteres fonéticos (furigana) de uma cadeia de texto
-PROPER = INICIAL.MAIÚSCULA ## Coloca em maiúsculas a primeira letra de cada palavra de um valor de texto
-REPLACE = SUBSTITUIR ## Substitui caracteres no texto
-REPLACEB = SUBSTITUIRB ## Substitui caracteres no texto
-REPT = REPETIR ## Repete texto um determinado número de vezes
-RIGHT = DIREITA ## Devolve os caracteres mais à direita de um valor de texto
-RIGHTB = DIREITAB ## Devolve os caracteres mais à direita de um valor de texto
-SEARCH = PROCURAR ## Localiza um valor de texto dentro de outro (não sensível a maiúsculas e minúsculas)
-SEARCHB = PROCURARB ## Localiza um valor de texto dentro de outro (não sensível a maiúsculas e minúsculas)
-SUBSTITUTE = SUBST ## Substitui texto novo por texto antigo numa cadeia de texto
-T = T ## Converte os respectivos argumentos em texto
-TEXT = TEXTO ## Formata um número e converte-o em texto
-TRIM = COMPACTAR ## Remove espaços do texto
-UPPER = MAIÚSCULAS ## Converte texto em maiúsculas
-VALUE = VALOR ## Converte um argumento de texto num número
+##
+## Add-in and Automation functions Funções de Suplemento e Automatização
+##
+GETPIVOTDATA = OBTERDADOSDIN ## Devolve dados armazenados num relatório de Tabela Dinâmica
+
+
+##
+## Cube functions Funções de cubo
+##
+CUBEKPIMEMBER = MEMBROKPICUBO ## Devolve o nome, propriedade e medição de um KPI (key performance indicator) e apresenta o nome e a propriedade na célula. Um KPI é uma medida quantificável, como, por exemplo, o lucro mensal bruto ou a rotatividade trimestral de pessoal, utilizada para monitorizar o desempenho de uma organização.
+CUBEMEMBER = MEMBROCUBO ## Devolve um membro ou cadeia de identificação numa hierarquia de cubo. Utilizada para validar a existência do membro ou cadeia de identificação no cubo.
+CUBEMEMBERPROPERTY = PROPRIEDADEMEMBROCUBO ## Devolve o valor de uma propriedade de membro no cubo. Utilizada para validar a existência de um nome de membro no cubo e para devolver a propriedade especificada para esse membro.
+CUBERANKEDMEMBER = MEMBROCLASSIFICADOCUBO ## Devolve o enésimo ou a classificação mais alta num conjunto. Utilizada para devolver um ou mais elementos num conjunto, tal como o melhor vendedor ou os 10 melhores alunos.
+CUBESET = CONJUNTOCUBO ## Define um conjunto calculado de membros ou cadeias de identificação enviando uma expressão de conjunto para o cubo no servidor, que cria o conjunto e, em seguida, devolve o conjunto ao Microsoft Office Excel.
+CUBESETCOUNT = CONTARCONJUNTOCUBO ## Devolve o número de itens num conjunto.
+CUBEVALUE = VALORCUBO ## Devolve um valor agregado do cubo.
+
+
+##
+## Database functions Funções de base de dados
+##
+DAVERAGE = BDMÉDIA ## Devolve a média das entradas da base de dados seleccionadas
+DCOUNT = BDCONTAR ## Conta as células que contêm números numa base de dados
+DCOUNTA = BDCONTAR.VAL ## Conta as células que não estejam em branco numa base de dados
+DGET = BDOBTER ## Extrai de uma base de dados um único registo que corresponde aos critérios especificados
+DMAX = BDMÁX ## Devolve o valor máximo das entradas da base de dados seleccionadas
+DMIN = BDMÍN ## Devolve o valor mínimo das entradas da base de dados seleccionadas
+DPRODUCT = BDMULTIPL ## Multiplica os valores de um determinado campo de registos que correspondem aos critérios numa base de dados
+DSTDEV = BDDESVPAD ## Calcula o desvio-padrão com base numa amostra de entradas da base de dados seleccionadas
+DSTDEVP = BDDESVPADP ## Calcula o desvio-padrão com base na população total das entradas da base de dados seleccionadas
+DSUM = BDSOMA ## Adiciona os números na coluna de campo dos registos de base de dados que correspondem aos critérios
+DVAR = BDVAR ## Calcula a variância com base numa amostra das entradas de base de dados seleccionadas
+DVARP = BDVARP ## Calcula a variância com base na população total das entradas de base de dados seleccionadas
+
+
+##
+## Date and time functions Funções de data e hora
+##
+DATE = DATA ## Devolve o número de série de uma determinada data
+DATEVALUE = DATA.VALOR ## Converte uma data em forma de texto num número de série
+DAY = DIA ## Converte um número de série num dia do mês
+DAYS360 = DIAS360 ## Calcula o número de dias entre duas datas com base num ano com 360 dias
+EDATE = DATAM ## Devolve um número de série de data que corresponde ao número de meses indicado antes ou depois da data de início
+EOMONTH = FIMMÊS ## Devolve o número de série do último dia do mês antes ou depois de um número de meses especificado
+HOUR = HORA ## Converte um número de série numa hora
+MINUTE = MINUTO ## Converte um número de série num minuto
+MONTH = MÊS ## Converte um número de série num mês
+NETWORKDAYS = DIATRABALHOTOTAL ## Devolve o número total de dias úteis entre duas datas
+NOW = AGORA ## Devolve o número de série da data e hora actuais
+SECOND = SEGUNDO ## Converte um número de série num segundo
+TIME = TEMPO ## Devolve o número de série de um determinado tempo
+TIMEVALUE = VALOR.TEMPO ## Converte um tempo em forma de texto num número de série
+TODAY = HOJE ## Devolve o número de série da data actual
+WEEKDAY = DIA.SEMANA ## Converte um número de série num dia da semana
+WEEKNUM = NÚMSEMANA ## Converte um número de série num número que representa o número da semana num determinado ano
+WORKDAY = DIA.TRABALHO ## Devolve o número de série da data antes ou depois de um número de dias úteis especificado
+YEAR = ANO ## Converte um número de série num ano
+YEARFRAC = FRACÇÃOANO ## Devolve a fracção de ano que representa o número de dias inteiros entre a data_de_início e a data_de_fim
+
+
+##
+## Engineering functions Funções de engenharia
+##
+BESSELI = BESSELI ## Devolve a função de Bessel modificada In(x)
+BESSELJ = BESSELJ ## Devolve a função de Bessel Jn(x)
+BESSELK = BESSELK ## Devolve a função de Bessel modificada Kn(x)
+BESSELY = BESSELY ## Devolve a função de Bessel Yn(x)
+BIN2DEC = BINADEC ## Converte um número binário em decimal
+BIN2HEX = BINAHEX ## Converte um número binário em hexadecimal
+BIN2OCT = BINAOCT ## Converte um número binário em octal
+COMPLEX = COMPLEXO ## Converte coeficientes reais e imaginários num número complexo
+CONVERT = CONVERTER ## Converte um número de um sistema de medida noutro
+DEC2BIN = DECABIN ## Converte um número decimal em binário
+DEC2HEX = DECAHEX ## Converte um número decimal em hexadecimal
+DEC2OCT = DECAOCT ## Converte um número decimal em octal
+DELTA = DELTA ## Testa se dois valores são iguais
+ERF = FUNCERRO ## Devolve a função de erro
+ERFC = FUNCERROCOMPL ## Devolve a função de erro complementar
+GESTEP = DEGRAU ## Testa se um número é maior do que um valor limite
+HEX2BIN = HEXABIN ## Converte um número hexadecimal em binário
+HEX2DEC = HEXADEC ## Converte um número hexadecimal em decimal
+HEX2OCT = HEXAOCT ## Converte um número hexadecimal em octal
+IMABS = IMABS ## Devolve o valor absoluto (módulo) de um número complexo
+IMAGINARY = IMAGINÁRIO ## Devolve o coeficiente imaginário de um número complexo
+IMARGUMENT = IMARG ## Devolve o argumento Teta, um ângulo expresso em radianos
+IMCONJUGATE = IMCONJ ## Devolve o conjugado complexo de um número complexo
+IMCOS = IMCOS ## Devolve o co-seno de um número complexo
+IMDIV = IMDIV ## Devolve o quociente de dois números complexos
+IMEXP = IMEXP ## Devolve o exponencial de um número complexo
+IMLN = IMLN ## Devolve o logaritmo natural de um número complexo
+IMLOG10 = IMLOG10 ## Devolve o logaritmo de base 10 de um número complexo
+IMLOG2 = IMLOG2 ## Devolve o logaritmo de base 2 de um número complexo
+IMPOWER = IMPOT ## Devolve um número complexo elevado a uma potência inteira
+IMPRODUCT = IMPROD ## Devolve o produto de números complexos
+IMREAL = IMREAL ## Devolve o coeficiente real de um número complexo
+IMSIN = IMSENO ## Devolve o seno de um número complexo
+IMSQRT = IMRAIZ ## Devolve a raiz quadrada de um número complexo
+IMSUB = IMSUBTR ## Devolve a diferença entre dois números complexos
+IMSUM = IMSOMA ## Devolve a soma de números complexos
+OCT2BIN = OCTABIN ## Converte um número octal em binário
+OCT2DEC = OCTADEC ## Converte um número octal em decimal
+OCT2HEX = OCTAHEX ## Converte um número octal em hexadecimal
+
+
+##
+## Financial functions Funções financeiras
+##
+ACCRINT = JUROSACUM ## Devolve os juros acumulados de um título que paga juros periódicos
+ACCRINTM = JUROSACUMV ## Devolve os juros acumulados de um título que paga juros no vencimento
+AMORDEGRC = AMORDEGRC ## Devolve a depreciação correspondente a cada período contabilístico utilizando um coeficiente de depreciação
+AMORLINC = AMORLINC ## Devolve a depreciação correspondente a cada período contabilístico
+COUPDAYBS = CUPDIASINLIQ ## Devolve o número de dias entre o início do período do cupão e a data de regularização
+COUPDAYS = CUPDIAS ## Devolve o número de dias no período do cupão que contém a data de regularização
+COUPDAYSNC = CUPDIASPRÓX ## Devolve o número de dias entre a data de regularização e a data do cupão seguinte
+COUPNCD = CUPDATAPRÓX ## Devolve a data do cupão seguinte após a data de regularização
+COUPNUM = CUPNÚM ## Devolve o número de cupões a serem pagos entre a data de regularização e a data de vencimento
+COUPPCD = CUPDATAANT ## Devolve a data do cupão anterior antes da data de regularização
+CUMIPMT = PGTOJURACUM ## Devolve os juros cumulativos pagos entre dois períodos
+CUMPRINC = PGTOCAPACUM ## Devolve o capital cumulativo pago a título de empréstimo entre dois períodos
+DB = BD ## Devolve a depreciação de um activo relativo a um período especificado utilizando o método das quotas degressivas fixas
+DDB = BDD ## Devolve a depreciação de um activo relativo a um período especificado utilizando o método das quotas degressivas duplas ou qualquer outro método especificado
+DISC = DESC ## Devolve a taxa de desconto de um título
+DOLLARDE = MOEDADEC ## Converte um preço em unidade monetária, expresso como uma fracção, num preço em unidade monetária, expresso como um número decimal
+DOLLARFR = MOEDAFRA ## Converte um preço em unidade monetária, expresso como um número decimal, num preço em unidade monetária, expresso como uma fracção
+DURATION = DURAÇÃO ## Devolve a duração anual de um título com pagamentos de juros periódicos
+EFFECT = EFECTIVA ## Devolve a taxa de juros anual efectiva
+FV = VF ## Devolve o valor futuro de um investimento
+FVSCHEDULE = VFPLANO ## Devolve o valor futuro de um capital inicial após a aplicação de uma série de taxas de juro compostas
+INTRATE = TAXAJUROS ## Devolve a taxa de juros de um título investido na totalidade
+IPMT = IPGTO ## Devolve o pagamento dos juros de um investimento durante um determinado período
+IRR = TIR ## Devolve a taxa de rentabilidade interna para uma série de fluxos monetários
+ISPMT = É.PGTO ## Calcula os juros pagos durante um período específico de um investimento
+MDURATION = MDURAÇÃO ## Devolve a duração modificada de Macauley de um título com um valor de paridade equivalente a € 100
+MIRR = MTIR ## Devolve a taxa interna de rentabilidade em que os fluxos monetários positivos e negativos são financiados com taxas diferentes
+NOMINAL = NOMINAL ## Devolve a taxa de juros nominal anual
+NPER = NPER ## Devolve o número de períodos de um investimento
+NPV = VAL ## Devolve o valor actual líquido de um investimento com base numa série de fluxos monetários periódicos e numa taxa de desconto
+ODDFPRICE = PREÇOPRIMINC ## Devolve o preço por € 100 do valor nominal de um título com um período inicial incompleto
+ODDFYIELD = LUCROPRIMINC ## Devolve o lucro de um título com um período inicial incompleto
+ODDLPRICE = PREÇOÚLTINC ## Devolve o preço por € 100 do valor nominal de um título com um período final incompleto
+ODDLYIELD = LUCROÚLTINC ## Devolve o lucro de um título com um período final incompleto
+PMT = PGTO ## Devolve o pagamento periódico de uma anuidade
+PPMT = PPGTO ## Devolve o pagamento sobre o capital de um investimento num determinado período
+PRICE = PREÇO ## Devolve o preço por € 100 do valor nominal de um título que paga juros periódicos
+PRICEDISC = PREÇODESC ## Devolve o preço por € 100 do valor nominal de um título descontado
+PRICEMAT = PREÇOVENC ## Devolve o preço por € 100 do valor nominal de um título que paga juros no vencimento
+PV = VA ## Devolve o valor actual de um investimento
+RATE = TAXA ## Devolve a taxa de juros por período de uma anuidade
+RECEIVED = RECEBER ## Devolve o montante recebido no vencimento de um título investido na totalidade
+SLN = AMORT ## Devolve uma depreciação linear de um activo durante um período
+SYD = AMORTD ## Devolve a depreciação por algarismos da soma dos anos de um activo durante um período especificado
+TBILLEQ = OTN ## Devolve o lucro de um título equivalente a uma Obrigação do Tesouro
+TBILLPRICE = OTNVALOR ## Devolve o preço por € 100 de valor nominal de uma Obrigação do Tesouro
+TBILLYIELD = OTNLUCRO ## Devolve o lucro de uma Obrigação do Tesouro
+VDB = BDV ## Devolve a depreciação de um activo relativo a um período específico ou parcial utilizando um método de quotas degressivas
+XIRR = XTIR ## Devolve a taxa interna de rentabilidade de um plano de fluxos monetários que não seja necessariamente periódica
+XNPV = XVAL ## Devolve o valor actual líquido de um plano de fluxos monetários que não seja necessariamente periódico
+YIELD = LUCRO ## Devolve o lucro de um título que paga juros periódicos
+YIELDDISC = LUCRODESC ## Devolve o lucro anual de um título emitido abaixo do valor nominal, por exemplo, uma Obrigação do Tesouro
+YIELDMAT = LUCROVENC ## Devolve o lucro anual de um título que paga juros na data de vencimento
+
+
+##
+## Information functions Funções de informação
+##
+CELL = CÉL ## Devolve informações sobre a formatação, localização ou conteúdo de uma célula
+ERROR.TYPE = TIPO.ERRO ## Devolve um número correspondente a um tipo de erro
+INFO = INFORMAÇÃO ## Devolve informações sobre o ambiente de funcionamento actual
+ISBLANK = É.CÉL.VAZIA ## Devolve VERDADEIRO se o valor estiver em branco
+ISERR = É.ERROS ## Devolve VERDADEIRO se o valor for um valor de erro diferente de #N/D
+ISERROR = É.ERRO ## Devolve VERDADEIRO se o valor for um valor de erro
+ISEVEN = ÉPAR ## Devolve VERDADEIRO se o número for par
+ISLOGICAL = É.LÓGICO ## Devolve VERDADEIRO se o valor for lógico
+ISNA = É.NÃO.DISP ## Devolve VERDADEIRO se o valor for o valor de erro #N/D
+ISNONTEXT = É.NÃO.TEXTO ## Devolve VERDADEIRO se o valor não for texto
+ISNUMBER = É.NÚM ## Devolve VERDADEIRO se o valor for um número
+ISODD = ÉÍMPAR ## Devolve VERDADEIRO se o número for ímpar
+ISREF = É.REF ## Devolve VERDADEIRO se o valor for uma referência
+ISTEXT = É.TEXTO ## Devolve VERDADEIRO se o valor for texto
+N = N ## Devolve um valor convertido num número
+NA = NÃO.DISP ## Devolve o valor de erro #N/D
+TYPE = TIPO ## Devolve um número que indica o tipo de dados de um valor
+
+
+##
+## Logical functions Funções lógicas
+##
+AND = E ## Devolve VERDADEIRO se todos os respectivos argumentos corresponderem a VERDADEIRO
+FALSE = FALSO ## Devolve o valor lógico FALSO
+IF = SE ## Especifica um teste lógico a ser executado
+IFERROR = SE.ERRO ## Devolve um valor definido pelo utilizador se ocorrer um erro na fórmula, e devolve o resultado da fórmula se não ocorrer nenhum erro
+NOT = NÃO ## Inverte a lógica do respectivo argumento
+OR = OU ## Devolve VERDADEIRO se qualquer argumento for VERDADEIRO
+TRUE = VERDADEIRO ## Devolve o valor lógico VERDADEIRO
+
+
+##
+## Lookup and reference functions Funções de pesquisa e referência
+##
+ADDRESS = ENDEREÇO ## Devolve uma referência a uma única célula numa folha de cálculo como texto
+AREAS = ÁREAS ## Devolve o número de áreas numa referência
+CHOOSE = SELECCIONAR ## Selecciona um valor a partir de uma lista de valores
+COLUMN = COL ## Devolve o número da coluna de uma referência
+COLUMNS = COLS ## Devolve o número de colunas numa referência
+HLOOKUP = PROCH ## Procura na linha superior de uma matriz e devolve o valor da célula indicada
+HYPERLINK = HIPERLIGAÇÃO ## Cria um atalho ou hiperligação que abre um documento armazenado num servidor de rede, numa intranet ou na Internet
+INDEX = ÍNDICE ## Utiliza um índice para escolher um valor de uma referência ou de uma matriz
+INDIRECT = INDIRECTO ## Devolve uma referência indicada por um valor de texto
+LOOKUP = PROC ## Procura valores num vector ou numa matriz
+MATCH = CORRESP ## Procura valores numa referência ou numa matriz
+OFFSET = DESLOCAMENTO ## Devolve o deslocamento de referência de uma determinada referência
+ROW = LIN ## Devolve o número da linha de uma referência
+ROWS = LINS ## Devolve o número de linhas numa referência
+RTD = RTD ## Obtém dados em tempo real a partir de um programa que suporte automatização COM (automatização: modo de trabalhar com objectos de uma aplicação a partir de outra aplicação ou ferramenta de desenvolvimento. Anteriormente conhecida como automatização OLE, a automatização é uma norma da indústria de software e uma funcionalidade COM (Component Object Model).)
+TRANSPOSE = TRANSPOR ## Devolve a transposição de uma matriz
+VLOOKUP = PROCV ## Procura na primeira coluna de uma matriz e percorre a linha para devolver o valor de uma célula
+
+
+##
+## Math and trigonometry functions Funções matemáticas e trigonométricas
+##
+ABS = ABS ## Devolve o valor absoluto de um número
+ACOS = ACOS ## Devolve o arco de co-seno de um número
+ACOSH = ACOSH ## Devolve o co-seno hiperbólico inverso de um número
+ASIN = ASEN ## Devolve o arco de seno de um número
+ASINH = ASENH ## Devolve o seno hiperbólico inverso de um número
+ATAN = ATAN ## Devolve o arco de tangente de um número
+ATAN2 = ATAN2 ## Devolve o arco de tangente das coordenadas x e y
+ATANH = ATANH ## Devolve a tangente hiperbólica inversa de um número
+CEILING = ARRED.EXCESSO ## Arredonda um número para o número inteiro mais próximo ou para o múltiplo de significância mais próximo
+COMBIN = COMBIN ## Devolve o número de combinações de um determinado número de objectos
+COS = COS ## Devolve o co-seno de um número
+COSH = COSH ## Devolve o co-seno hiperbólico de um número
+DEGREES = GRAUS ## Converte radianos em graus
+EVEN = PAR ## Arredonda um número por excesso para o número inteiro mais próximo
+EXP = EXP ## Devolve e elevado à potência de um determinado número
+FACT = FACTORIAL ## Devolve o factorial de um número
+FACTDOUBLE = FACTDUPLO ## Devolve o factorial duplo de um número
+FLOOR = ARRED.DEFEITO ## Arredonda um número por defeito até zero
+GCD = MDC ## Devolve o maior divisor comum
+INT = INT ## Arredonda um número por defeito para o número inteiro mais próximo
+LCM = MMC ## Devolve o mínimo múltiplo comum
+LN = LN ## Devolve o logaritmo natural de um número
+LOG = LOG ## Devolve o logaritmo de um número com uma base especificada
+LOG10 = LOG10 ## Devolve o logaritmo de base 10 de um número
+MDETERM = MATRIZ.DETERM ## Devolve o determinante matricial de uma matriz
+MINVERSE = MATRIZ.INVERSA ## Devolve o inverso matricial de uma matriz
+MMULT = MATRIZ.MULT ## Devolve o produto matricial de duas matrizes
+MOD = RESTO ## Devolve o resto da divisão
+MROUND = MARRED ## Devolve um número arredondado para o múltiplo pretendido
+MULTINOMIAL = POLINOMIAL ## Devolve o polinomial de um conjunto de números
+ODD = ÍMPAR ## Arredonda por excesso um número para o número inteiro ímpar mais próximo
+PI = PI ## Devolve o valor de pi
+POWER = POTÊNCIA ## Devolve o resultado de um número elevado a uma potência
+PRODUCT = PRODUTO ## Multiplica os respectivos argumentos
+QUOTIENT = QUOCIENTE ## Devolve a parte inteira de uma divisão
+RADIANS = RADIANOS ## Converte graus em radianos
+RAND = ALEATÓRIO ## Devolve um número aleatório entre 0 e 1
+RANDBETWEEN = ALEATÓRIOENTRE ## Devolve um número aleatório entre os números especificados
+ROMAN = ROMANO ## Converte um número árabe em romano, como texto
+ROUND = ARRED ## Arredonda um número para um número de dígitos especificado
+ROUNDDOWN = ARRED.PARA.BAIXO ## Arredonda um número por defeito até zero
+ROUNDUP = ARRED.PARA.CIMA ## Arredonda um número por excesso, afastando-o de zero
+SERIESSUM = SOMASÉRIE ## Devolve a soma de uma série de potências baseada na fórmula
+SIGN = SINAL ## Devolve o sinal de um número
+SIN = SEN ## Devolve o seno de um determinado ângulo
+SINH = SENH ## Devolve o seno hiperbólico de um número
+SQRT = RAIZQ ## Devolve uma raiz quadrada positiva
+SQRTPI = RAIZPI ## Devolve a raiz quadrada de (núm * pi)
+SUBTOTAL = SUBTOTAL ## Devolve um subtotal numa lista ou base de dados
+SUM = SOMA ## Adiciona os respectivos argumentos
+SUMIF = SOMA.SE ## Adiciona as células especificadas por um determinado critério
+SUMIFS = SOMA.SE.S ## Adiciona as células num intervalo que cumpre vários critérios
+SUMPRODUCT = SOMARPRODUTO ## Devolve a soma dos produtos de componentes de matrizes correspondentes
+SUMSQ = SOMARQUAD ## Devolve a soma dos quadrados dos argumentos
+SUMX2MY2 = SOMAX2DY2 ## Devolve a soma da diferença dos quadrados dos valores correspondentes em duas matrizes
+SUMX2PY2 = SOMAX2SY2 ## Devolve a soma da soma dos quadrados dos valores correspondentes em duas matrizes
+SUMXMY2 = SOMAXMY2 ## Devolve a soma dos quadrados da diferença dos valores correspondentes em duas matrizes
+TAN = TAN ## Devolve a tangente de um número
+TANH = TANH ## Devolve a tangente hiperbólica de um número
+TRUNC = TRUNCAR ## Trunca um número para um número inteiro
+
+
+##
+## Statistical functions Funções estatísticas
+##
+AVEDEV = DESV.MÉDIO ## Devolve a média aritmética dos desvios absolutos à média dos pontos de dados
+AVERAGE = MÉDIA ## Devolve a média dos respectivos argumentos
+AVERAGEA = MÉDIAA ## Devolve uma média dos respectivos argumentos, incluindo números, texto e valores lógicos
+AVERAGEIF = MÉDIA.SE ## Devolve a média aritmética de todas as células num intervalo que cumprem determinado critério
+AVERAGEIFS = MÉDIA.SE.S ## Devolve a média aritmética de todas as células que cumprem múltiplos critérios
+BETADIST = DISTBETA ## Devolve a função de distribuição cumulativa beta
+BETAINV = BETA.ACUM.INV ## Devolve o inverso da função de distribuição cumulativa relativamente a uma distribuição beta específica
+BINOMDIST = DISTRBINOM ## Devolve a probabilidade de distribuição binomial de termo individual
+CHIDIST = DIST.CHI ## Devolve a probabilidade unicaudal da distribuição qui-quadrada
+CHIINV = INV.CHI ## Devolve o inverso da probabilidade unicaudal da distribuição qui-quadrada
+CHITEST = TESTE.CHI ## Devolve o teste para independência
+CONFIDENCE = INT.CONFIANÇA ## Devolve o intervalo de confiança correspondente a uma média de população
+CORREL = CORREL ## Devolve o coeficiente de correlação entre dois conjuntos de dados
+COUNT = CONTAR ## Conta os números que existem na lista de argumentos
+COUNTA = CONTAR.VAL ## Conta os valores que existem na lista de argumentos
+COUNTBLANK = CONTAR.VAZIO ## Conta o número de células em branco num intervalo
+COUNTIF = CONTAR.SE ## Calcula o número de células num intervalo que corresponde aos critérios determinados
+COUNTIFS = CONTAR.SE.S ## Conta o número de células num intervalo que cumprem múltiplos critérios
+COVAR = COVAR ## Devolve a covariância, que é a média dos produtos de desvios de pares
+CRITBINOM = CRIT.BINOM ## Devolve o menor valor em que a distribuição binomial cumulativa é inferior ou igual a um valor de critério
+DEVSQ = DESVQ ## Devolve a soma dos quadrados dos desvios
+EXPONDIST = DISTEXPON ## Devolve a distribuição exponencial
+FDIST = DISTF ## Devolve a distribuição da probabilidade F
+FINV = INVF ## Devolve o inverso da distribuição da probabilidade F
+FISHER = FISHER ## Devolve a transformação Fisher
+FISHERINV = FISHERINV ## Devolve o inverso da transformação Fisher
+FORECAST = PREVISÃO ## Devolve um valor ao longo de uma tendência linear
+FREQUENCY = FREQUÊNCIA ## Devolve uma distribuição de frequência como uma matriz vertical
+FTEST = TESTEF ## Devolve o resultado de um teste F
+GAMMADIST = DISTGAMA ## Devolve a distribuição gama
+GAMMAINV = INVGAMA ## Devolve o inverso da distribuição gama cumulativa
+GAMMALN = LNGAMA ## Devolve o logaritmo natural da função gama, Γ(x)
+GEOMEAN = MÉDIA.GEOMÉTRICA ## Devolve a média geométrica
+GROWTH = CRESCIMENTO ## Devolve valores ao longo de uma tendência exponencial
+HARMEAN = MÉDIA.HARMÓNICA ## Devolve a média harmónica
+HYPGEOMDIST = DIST.HIPERGEOM ## Devolve a distribuição hipergeométrica
+INTERCEPT = INTERCEPTAR ## Devolve a intercepção da linha de regressão linear
+KURT = CURT ## Devolve a curtose de um conjunto de dados
+LARGE = MAIOR ## Devolve o maior valor k-ésimo de um conjunto de dados
+LINEST = PROJ.LIN ## Devolve os parâmetros de uma tendência linear
+LOGEST = PROJ.LOG ## Devolve os parâmetros de uma tendência exponencial
+LOGINV = INVLOG ## Devolve o inverso da distribuição normal logarítmica
+LOGNORMDIST = DIST.NORMALLOG ## Devolve a distribuição normal logarítmica cumulativa
+MAX = MÁXIMO ## Devolve o valor máximo numa lista de argumentos
+MAXA = MÁXIMOA ## Devolve o valor máximo numa lista de argumentos, incluindo números, texto e valores lógicos
+MEDIAN = MED ## Devolve a mediana dos números indicados
+MIN = MÍNIMO ## Devolve o valor mínimo numa lista de argumentos
+MINA = MÍNIMOA ## Devolve o valor mínimo numa lista de argumentos, incluindo números, texto e valores lógicos
+MODE = MODA ## Devolve o valor mais comum num conjunto de dados
+NEGBINOMDIST = DIST.BIN.NEG ## Devolve a distribuição binominal negativa
+NORMDIST = DIST.NORM ## Devolve a distribuição cumulativa normal
+NORMINV = INV.NORM ## Devolve o inverso da distribuição cumulativa normal
+NORMSDIST = DIST.NORMP ## Devolve a distribuição cumulativa normal padrão
+NORMSINV = INV.NORMP ## Devolve o inverso da distribuição cumulativa normal padrão
+PEARSON = PEARSON ## Devolve o coeficiente de correlação momento/produto de Pearson
+PERCENTILE = PERCENTIL ## Devolve o k-ésimo percentil de valores num intervalo
+PERCENTRANK = ORDEM.PERCENTUAL ## Devolve a ordem percentual de um valor num conjunto de dados
+PERMUT = PERMUTAR ## Devolve o número de permutações de um determinado número de objectos
+POISSON = POISSON ## Devolve a distribuição de Poisson
+PROB = PROB ## Devolve a probabilidade dos valores num intervalo se encontrarem entre dois limites
+QUARTILE = QUARTIL ## Devolve o quartil de um conjunto de dados
+RANK = ORDEM ## Devolve a ordem de um número numa lista numérica
+RSQ = RQUAD ## Devolve o quadrado do coeficiente de correlação momento/produto de Pearson
+SKEW = DISTORÇÃO ## Devolve a distorção de uma distribuição
+SLOPE = DECLIVE ## Devolve o declive da linha de regressão linear
+SMALL = MENOR ## Devolve o menor valor de k-ésimo de um conjunto de dados
+STANDARDIZE = NORMALIZAR ## Devolve um valor normalizado
+STDEV = DESVPAD ## Calcula o desvio-padrão com base numa amostra
+STDEVA = DESVPADA ## Calcula o desvio-padrão com base numa amostra, incluindo números, texto e valores lógicos
+STDEVP = DESVPADP ## Calcula o desvio-padrão com base na população total
+STDEVPA = DESVPADPA ## Calcula o desvio-padrão com base na população total, incluindo números, texto e valores lógicos
+STEYX = EPADYX ## Devolve o erro-padrão do valor de y previsto para cada x na regressão
+TDIST = DISTT ## Devolve a distribuição t de Student
+TINV = INVT ## Devolve o inverso da distribuição t de Student
+TREND = TENDÊNCIA ## Devolve valores ao longo de uma tendência linear
+TRIMMEAN = MÉDIA.INTERNA ## Devolve a média do interior de um conjunto de dados
+TTEST = TESTET ## Devolve a probabilidade associada ao teste t de Student
+VAR = VAR ## Calcula a variância com base numa amostra
+VARA = VARA ## Calcula a variância com base numa amostra, incluindo números, texto e valores lógicos
+VARP = VARP ## Calcula a variância com base na população total
+VARPA = VARPA ## Calcula a variância com base na população total, incluindo números, texto e valores lógicos
+WEIBULL = WEIBULL ## Devolve a distribuição Weibull
+ZTEST = TESTEZ ## Devolve o valor de probabilidade unicaudal de um teste-z
+
+
+##
+## Text functions Funções de texto
+##
+ASC = ASC ## Altera letras ou katakana de largura total (byte duplo) numa cadeia de caracteres para caracteres de largura média (byte único)
+BAHTTEXT = TEXTO.BAHT ## Converte um número em texto, utilizando o formato monetário ß (baht)
+CHAR = CARÁCT ## Devolve o carácter especificado pelo número de código
+CLEAN = LIMPAR ## Remove do texto todos os caracteres não imprimíveis
+CODE = CÓDIGO ## Devolve um código numérico correspondente ao primeiro carácter numa cadeia de texto
+CONCATENATE = CONCATENAR ## Agrupa vários itens de texto num único item de texto
+DOLLAR = MOEDA ## Converte um número em texto, utilizando o formato monetário € (Euro)
+EXACT = EXACTO ## Verifica se dois valores de texto são idênticos
+FIND = LOCALIZAR ## Localiza um valor de texto dentro de outro (sensível às maiúsculas e minúsculas)
+FINDB = LOCALIZARB ## Localiza um valor de texto dentro de outro (sensível às maiúsculas e minúsculas)
+FIXED = FIXA ## Formata um número como texto com um número fixo de decimais
+JIS = JIS ## Altera letras ou katakana de largura média (byte único) numa cadeia de caracteres para caracteres de largura total (byte duplo)
+LEFT = ESQUERDA ## Devolve os caracteres mais à esquerda de um valor de texto
+LEFTB = ESQUERDAB ## Devolve os caracteres mais à esquerda de um valor de texto
+LEN = NÚM.CARACT ## Devolve o número de caracteres de uma cadeia de texto
+LENB = NÚM.CARACTB ## Devolve o número de caracteres de uma cadeia de texto
+LOWER = MINÚSCULAS ## Converte o texto em minúsculas
+MID = SEG.TEXTO ## Devolve um número específico de caracteres de uma cadeia de texto, a partir da posição especificada
+MIDB = SEG.TEXTOB ## Devolve um número específico de caracteres de uma cadeia de texto, a partir da posição especificada
+PHONETIC = FONÉTICA ## Retira os caracteres fonéticos (furigana) de uma cadeia de texto
+PROPER = INICIAL.MAIÚSCULA ## Coloca em maiúsculas a primeira letra de cada palavra de um valor de texto
+REPLACE = SUBSTITUIR ## Substitui caracteres no texto
+REPLACEB = SUBSTITUIRB ## Substitui caracteres no texto
+REPT = REPETIR ## Repete texto um determinado número de vezes
+RIGHT = DIREITA ## Devolve os caracteres mais à direita de um valor de texto
+RIGHTB = DIREITAB ## Devolve os caracteres mais à direita de um valor de texto
+SEARCH = PROCURAR ## Localiza um valor de texto dentro de outro (não sensível a maiúsculas e minúsculas)
+SEARCHB = PROCURARB ## Localiza um valor de texto dentro de outro (não sensível a maiúsculas e minúsculas)
+SUBSTITUTE = SUBST ## Substitui texto novo por texto antigo numa cadeia de texto
+T = T ## Converte os respectivos argumentos em texto
+TEXT = TEXTO ## Formata um número e converte-o em texto
+TRIM = COMPACTAR ## Remove espaços do texto
+UPPER = MAIÚSCULAS ## Converte texto em maiúsculas
+VALUE = VALOR ## Converte um argumento de texto num número
diff --git a/htdocs/includes/phpexcel/PHPExcel/locale/sv/functions b/htdocs/includes/phpexcel/PHPExcel/locale/sv/functions
index b1dd99522b0..27f61e7f834 100644
--- a/htdocs/includes/phpexcel/PHPExcel/locale/sv/functions
+++ b/htdocs/includes/phpexcel/PHPExcel/locale/sv/functions
@@ -1,408 +1,408 @@
-##
-## Add-in and Automation functions Tilläggs- och automatiseringsfunktioner
-##
-GETPIVOTDATA = HÄMTA.PIVOTDATA ## Returnerar data som lagrats i en pivottabellrapport
-
-
-##
-## Cube functions Kubfunktioner
-##
-CUBEKPIMEMBER = KUBKPIMEDLEM ## Returnerar namn, egenskap och mått för en KPI och visar namnet och egenskapen i cellen. En KPI, eller prestandaindikator, är ett kvantifierbart mått, t.ex. månatlig bruttovinst eller personalomsättning per kvartal, som används för att analysera ett företags resultat.
-CUBEMEMBER = KUBMEDLEM ## Returnerar en medlem eller ett par i en kubhierarki. Används för att verifiera att medlemmen eller paret finns i kuben.
-CUBEMEMBERPROPERTY = KUBMEDLEMSEGENSKAP ## Returnerar värdet för en medlemsegenskap i kuben. Används för att verifiera att ett medlemsnamn finns i kuben, samt för att returnera den angivna egenskapen för medlemmen.
-CUBERANKEDMEMBER = KUBRANGORDNADMEDLEM ## Returnerar den n:te, eller rangordnade, medlemmen i en uppsättning. Används för att returnera ett eller flera element i en uppsättning, till exempelvis den bästa försäljaren eller de tio bästa eleverna.
-CUBESET = KUBINSTÄLLNING ## Definierar en beräknad uppsättning medlemmar eller par genom att skicka ett bestämt uttryck till kuben på servern, som skapar uppsättningen och sedan returnerar den till Microsoft Office Excel.
-CUBESETCOUNT = KUBINSTÄLLNINGANTAL ## Returnerar antalet objekt i en uppsättning.
-CUBEVALUE = KUBVÄRDE ## Returnerar ett mängdvärde från en kub.
-
-
-##
-## Database functions Databasfunktioner
-##
-DAVERAGE = DMEDEL ## Returnerar medelvärdet av databasposterna
-DCOUNT = DANTAL ## Räknar antalet celler som innehåller tal i en databas
-DCOUNTA = DANTALV ## Räknar ifyllda celler i en databas
-DGET = DHÄMTA ## Hämtar en enstaka post från en databas som uppfyller de angivna villkoren
-DMAX = DMAX ## Returnerar det största värdet från databasposterna
-DMIN = DMIN ## Returnerar det minsta värdet från databasposterna
-DPRODUCT = DPRODUKT ## Multiplicerar värdena i ett visst fält i poster som uppfyller villkoret
-DSTDEV = DSTDAV ## Uppskattar standardavvikelsen baserat på ett urval av databasposterna
-DSTDEVP = DSTDAVP ## Beräknar standardavvikelsen utifrån hela populationen av valda databasposter
-DSUM = DSUMMA ## Summerar talen i kolumnfält i databasposter som uppfyller villkoret
-DVAR = DVARIANS ## Uppskattar variansen baserat på ett urval av databasposterna
-DVARP = DVARIANSP ## Beräknar variansen utifrån hela populationen av valda databasposter
-
-
-##
-## Date and time functions Tid- och datumfunktioner
-##
-DATE = DATUM ## Returnerar ett serienummer för ett visst datum
-DATEVALUE = DATUMVÄRDE ## Konverterar ett datum i textformat till ett serienummer
-DAY = DAG ## Konverterar ett serienummer till dag i månaden
-DAYS360 = DAGAR360 ## Beräknar antalet dagar mellan två datum baserat på ett 360-dagarsår
-EDATE = EDATUM ## Returnerar serienumret för ett datum som infaller ett visst antal månader före eller efter startdatumet
-EOMONTH = SLUTMÅNAD ## Returnerar serienumret för sista dagen i månaden ett visst antal månader tidigare eller senare
-HOUR = TIMME ## Konverterar ett serienummer till en timme
-MINUTE = MINUT ## Konverterar ett serienummer till en minut
-MONTH = MÅNAD ## Konverterar ett serienummer till en månad
-NETWORKDAYS = NETTOARBETSDAGAR ## Returnerar antalet hela arbetsdagar mellan två datum
-NOW = NU ## Returnerar serienumret för dagens datum och aktuell tid
-SECOND = SEKUND ## Konverterar ett serienummer till en sekund
-TIME = KLOCKSLAG ## Returnerar serienumret för en viss tid
-TIMEVALUE = TIDVÄRDE ## Konverterar en tid i textformat till ett serienummer
-TODAY = IDAG ## Returnerar serienumret för dagens datum
-WEEKDAY = VECKODAG ## Konverterar ett serienummer till en dag i veckan
-WEEKNUM = VECKONR ## Konverterar ett serienummer till ett veckonummer
-WORKDAY = ARBETSDAGAR ## Returnerar serienumret för ett datum ett visst antal arbetsdagar tidigare eller senare
-YEAR = ÅR ## Konverterar ett serienummer till ett år
-YEARFRAC = ÅRDEL ## Returnerar en del av ett år som representerar antalet hela dagar mellan start- och slutdatum
-
-
-##
-## Engineering functions Tekniska funktioner
-##
-BESSELI = BESSELI ## Returnerar den modifierade Bessel-funktionen In(x)
-BESSELJ = BESSELJ ## Returnerar Bessel-funktionen Jn(x)
-BESSELK = BESSELK ## Returnerar den modifierade Bessel-funktionen Kn(x)
-BESSELY = BESSELY ## Returnerar Bessel-funktionen Yn(x)
-BIN2DEC = BIN.TILL.DEC ## Omvandlar ett binärt tal till decimalt
-BIN2HEX = BIN.TILL.HEX ## Omvandlar ett binärt tal till hexadecimalt
-BIN2OCT = BIN.TILL.OKT ## Omvandlar ett binärt tal till oktalt
-COMPLEX = KOMPLEX ## Omvandlar reella och imaginära koefficienter till ett komplext tal
-CONVERT = KONVERTERA ## Omvandlar ett tal från ett måttsystem till ett annat
-DEC2BIN = DEC.TILL.BIN ## Omvandlar ett decimalt tal till binärt
-DEC2HEX = DEC.TILL.HEX ## Omvandlar ett decimalt tal till hexadecimalt
-DEC2OCT = DEC.TILL.OKT ## Omvandlar ett decimalt tal till oktalt
-DELTA = DELTA ## Testar om två värden är lika
-ERF = FELF ## Returnerar felfunktionen
-ERFC = FELFK ## Returnerar den komplementära felfunktionen
-GESTEP = SLSTEG ## Testar om ett tal är större än ett tröskelvärde
-HEX2BIN = HEX.TILL.BIN ## Omvandlar ett hexadecimalt tal till binärt
-HEX2DEC = HEX.TILL.DEC ## Omvandlar ett hexadecimalt tal till decimalt
-HEX2OCT = HEX.TILL.OKT ## Omvandlar ett hexadecimalt tal till oktalt
-IMABS = IMABS ## Returnerar absolutvärdet (modulus) för ett komplext tal
-IMAGINARY = IMAGINÄR ## Returnerar den imaginära koefficienten för ett komplext tal
-IMARGUMENT = IMARGUMENT ## Returnerar det komplexa talets argument, en vinkel uttryckt i radianer
-IMCONJUGATE = IMKONJUGAT ## Returnerar det komplexa talets konjugat
-IMCOS = IMCOS ## Returnerar cosinus för ett komplext tal
-IMDIV = IMDIV ## Returnerar kvoten för två komplexa tal
-IMEXP = IMEUPPHÖJT ## Returnerar exponenten för ett komplext tal
-IMLN = IMLN ## Returnerar den naturliga logaritmen för ett komplext tal
-IMLOG10 = IMLOG10 ## Returnerar 10-logaritmen för ett komplext tal
-IMLOG2 = IMLOG2 ## Returnerar 2-logaritmen för ett komplext tal
-IMPOWER = IMUPPHÖJT ## Returnerar ett komplext tal upphöjt till en exponent
-IMPRODUCT = IMPRODUKT ## Returnerar produkten av komplexa tal
-IMREAL = IMREAL ## Returnerar den reella koefficienten för ett komplext tal
-IMSIN = IMSIN ## Returnerar sinus för ett komplext tal
-IMSQRT = IMROT ## Returnerar kvadratroten av ett komplext tal
-IMSUB = IMDIFF ## Returnerar differensen mellan två komplexa tal
-IMSUM = IMSUM ## Returnerar summan av komplexa tal
-OCT2BIN = OKT.TILL.BIN ## Omvandlar ett oktalt tal till binärt
-OCT2DEC = OKT.TILL.DEC ## Omvandlar ett oktalt tal till decimalt
-OCT2HEX = OKT.TILL.HEX ## Omvandlar ett oktalt tal till hexadecimalt
-
-
-##
-## Financial functions Finansiella funktioner
-##
-ACCRINT = UPPLRÄNTA ## Returnerar den upplupna räntan för värdepapper med periodisk ränta
-ACCRINTM = UPPLOBLRÄNTA ## Returnerar den upplupna räntan för ett värdepapper som ger avkastning på förfallodagen
-AMORDEGRC = AMORDEGRC ## Returnerar avskrivningen för varje redovisningsperiod med hjälp av en avskrivningskoefficient
-AMORLINC = AMORLINC ## Returnerar avskrivningen för varje redovisningsperiod
-COUPDAYBS = KUPDAGBB ## Returnerar antal dagar från början av kupongperioden till likviddagen
-COUPDAYS = KUPDAGARS ## Returnerar antalet dagar i kupongperioden som innehåller betalningsdatumet
-COUPDAYSNC = KUPDAGNK ## Returnerar antalet dagar från betalningsdatumet till nästa kupongdatum
-COUPNCD = KUPNKD ## Returnerar nästa kupongdatum efter likviddagen
-COUPNUM = KUPANT ## Returnerar kuponger som förfaller till betalning mellan likviddagen och förfallodagen
-COUPPCD = KUPFKD ## Returnerar föregående kupongdatum före likviddagen
-CUMIPMT = KUMRÄNTA ## Returnerar den ackumulerade räntan som betalats mellan två perioder
-CUMPRINC = KUMPRIS ## Returnerar det ackumulerade kapitalbeloppet som betalats på ett lån mellan två perioder
-DB = DB ## Returnerar avskrivningen för en tillgång under en angiven tid enligt metoden för fast degressiv avskrivning
-DDB = DEGAVSKR ## Returnerar en tillgångs värdeminskning under en viss period med hjälp av dubbel degressiv avskrivning eller någon annan metod som du anger
-DISC = DISK ## Returnerar diskonteringsräntan för ett värdepapper
-DOLLARDE = DECTAL ## Omvandlar ett pris uttryckt som ett bråk till ett decimaltal
-DOLLARFR = BRÅK ## Omvandlar ett pris i kronor uttryckt som ett decimaltal till ett bråk
-DURATION = LÖPTID ## Returnerar den årliga löptiden för en säkerhet med periodiska räntebetalningar
-EFFECT = EFFRÄNTA ## Returnerar den årliga effektiva räntesatsen
-FV = SLUTVÄRDE ## Returnerar det framtida värdet på en investering
-FVSCHEDULE = FÖRRÄNTNING ## Returnerar det framtida värdet av ett begynnelsekapital beräknat på olika räntenivåer
-INTRATE = ÅRSRÄNTA ## Returnerar räntesatsen för ett betalt värdepapper
-IPMT = RBETALNING ## Returnerar räntedelen av en betalning för en given period
-IRR = IR ## Returnerar internräntan för en serie betalningar
-ISPMT = RALÅN ## Beräknar räntan som har betalats under en specifik betalningsperiod
-MDURATION = MLÖPTID ## Returnerar den modifierade Macauley-löptiden för ett värdepapper med det antagna nominella värdet 100 kr
-MIRR = MODIR ## Returnerar internräntan där positiva och negativa betalningar finansieras med olika räntor
-NOMINAL = NOMRÄNTA ## Returnerar den årliga nominella räntesatsen
-NPER = PERIODER ## Returnerar antalet perioder för en investering
-NPV = NETNUVÄRDE ## Returnerar nuvärdet av en serie periodiska betalningar vid en given diskonteringsränta
-ODDFPRICE = UDDAFPRIS ## Returnerar priset per 100 kr nominellt värde för ett värdepapper med en udda första period
-ODDFYIELD = UDDAFAVKASTNING ## Returnerar avkastningen för en säkerhet med en udda första period
-ODDLPRICE = UDDASPRIS ## Returnerar priset per 100 kr nominellt värde för ett värdepapper med en udda sista period
-ODDLYIELD = UDDASAVKASTNING ## Returnerar avkastningen för en säkerhet med en udda sista period
-PMT = BETALNING ## Returnerar den periodiska betalningen för en annuitet
-PPMT = AMORT ## Returnerar amorteringsdelen av en annuitetsbetalning för en given period
-PRICE = PRIS ## Returnerar priset per 100 kr nominellt värde för ett värdepapper som ger periodisk ränta
-PRICEDISC = PRISDISK ## Returnerar priset per 100 kr nominellt värde för ett diskonterat värdepapper
-PRICEMAT = PRISFÖRF ## Returnerar priset per 100 kr nominellt värde för ett värdepapper som ger ränta på förfallodagen
-PV = PV ## Returnerar nuvärdet av en serie lika stora periodiska betalningar
-RATE = RÄNTA ## Returnerar räntesatsen per period i en annuitet
-RECEIVED = BELOPP ## Returnerar beloppet som utdelas på förfallodagen för ett betalat värdepapper
-SLN = LINAVSKR ## Returnerar den linjära avskrivningen för en tillgång under en period
-SYD = ÅRSAVSKR ## Returnerar den årliga avskrivningssumman för en tillgång under en angiven period
-TBILLEQ = SSVXEKV ## Returnerar avkastningen motsvarande en obligation för en statsskuldväxel
-TBILLPRICE = SSVXPRIS ## Returnerar priset per 100 kr nominellt värde för en statsskuldväxel
-TBILLYIELD = SSVXRÄNTA ## Returnerar avkastningen för en statsskuldväxel
-VDB = VDEGRAVSKR ## Returnerar avskrivningen för en tillgång under en angiven period (med degressiv avskrivning)
-XIRR = XIRR ## Returnerar internräntan för en serie betalningar som inte nödvändigtvis är periodiska
-XNPV = XNUVÄRDE ## Returnerar det nuvarande nettovärdet för en serie betalningar som inte nödvändigtvis är periodiska
-YIELD = NOMAVK ## Returnerar avkastningen för ett värdepapper som ger periodisk ränta
-YIELDDISC = NOMAVKDISK ## Returnerar den årliga avkastningen för diskonterade värdepapper, exempelvis en statsskuldväxel
-YIELDMAT = NOMAVKFÖRF ## Returnerar den årliga avkastningen för ett värdepapper som ger ränta på förfallodagen
-
-
-##
-## Information functions Informationsfunktioner
-##
-CELL = CELL ## Returnerar information om formatering, plats och innehåll i en cell
-ERROR.TYPE = FEL.TYP ## Returnerar ett tal som motsvarar ett felvärde
-INFO = INFO ## Returnerar information om operativsystemet
-ISBLANK = ÄRREF ## Returnerar SANT om värdet är tomt
-ISERR = Ä ## Returnerar SANT om värdet är ett felvärde annat än #SAKNAS!
-ISERROR = ÄRFEL ## Returnerar SANT om värdet är ett felvärde
-ISEVEN = ÄRJÄMN ## Returnerar SANT om talet är jämnt
-ISLOGICAL = ÄREJTEXT ## Returnerar SANT om värdet är ett logiskt värde
-ISNA = ÄRLOGISK ## Returnerar SANT om värdet är felvärdet #SAKNAS!
-ISNONTEXT = ÄRSAKNAD ## Returnerar SANT om värdet inte är text
-ISNUMBER = ÄRTAL ## Returnerar SANT om värdet är ett tal
-ISODD = ÄRUDDA ## Returnerar SANT om talet är udda
-ISREF = ÄRTOM ## Returnerar SANT om värdet är en referens
-ISTEXT = ÄRTEXT ## Returnerar SANT om värdet är text
-N = N ## Returnerar ett värde omvandlat till ett tal
-NA = SAKNAS ## Returnerar felvärdet #SAKNAS!
-TYPE = VÄRDETYP ## Returnerar ett tal som anger värdets datatyp
-
-
-##
-## Logical functions Logiska funktioner
-##
-AND = OCH ## Returnerar SANT om alla argument är sanna
-FALSE = FALSKT ## Returnerar det logiska värdet FALSKT
-IF = OM ## Anger vilket logiskt test som ska utföras
-IFERROR = OMFEL ## Returnerar ett värde som du anger om en formel utvärderar till ett fel; annars returneras resultatet av formeln
-NOT = ICKE ## Inverterar logiken för argumenten
-OR = ELLER ## Returnerar SANT om något argument är SANT
-TRUE = SANT ## Returnerar det logiska värdet SANT
-
-
-##
-## Lookup and reference functions Sök- och referensfunktioner
-##
-ADDRESS = ADRESS ## Returnerar en referens som text till en enstaka cell i ett kalkylblad
-AREAS = OMRÅDEN ## Returnerar antalet områden i en referens
-CHOOSE = VÄLJ ## Väljer ett värde i en lista över värden
-COLUMN = KOLUMN ## Returnerar kolumnnumret för en referens
-COLUMNS = KOLUMNER ## Returnerar antalet kolumner i en referens
-HLOOKUP = LETAKOLUMN ## Söker i den översta raden i en matris och returnerar värdet för angiven cell
-HYPERLINK = HYPERLÄNK ## Skapar en genväg eller ett hopp till ett dokument i nätverket, i ett intranät eller på Internet
-INDEX = INDEX ## Använder ett index för ett välja ett värde i en referens eller matris
-INDIRECT = INDIREKT ## Returnerar en referens som anges av ett textvärde
-LOOKUP = LETAUPP ## Letar upp värden i en vektor eller matris
-MATCH = PASSA ## Letar upp värden i en referens eller matris
-OFFSET = FÖRSKJUTNING ## Returnerar en referens förskjuten i förhållande till en given referens
-ROW = RAD ## Returnerar radnumret för en referens
-ROWS = RADER ## Returnerar antalet rader i en referens
-RTD = RTD ## Hämtar realtidsdata från ett program som stöder COM-automation (Automation: Ett sätt att arbeta med ett programs objekt från ett annat program eller utvecklingsverktyg. Detta kallades tidigare för OLE Automation, och är en branschstandard och ingår i Component Object Model (COM).)
-TRANSPOSE = TRANSPONERA ## Transponerar en matris
-VLOOKUP = LETARAD ## Letar i den första kolumnen i en matris och flyttar över raden för att returnera värdet för en cell
-
-
-##
-## Math and trigonometry functions Matematiska och trigonometriska funktioner
-##
-ABS = ABS ## Returnerar absolutvärdet av ett tal
-ACOS = ARCCOS ## Returnerar arcus cosinus för ett tal
-ACOSH = ARCCOSH ## Returnerar inverterad hyperbolisk cosinus för ett tal
-ASIN = ARCSIN ## Returnerar arcus cosinus för ett tal
-ASINH = ARCSINH ## Returnerar hyperbolisk arcus sinus för ett tal
-ATAN = ARCTAN ## Returnerar arcus tangens för ett tal
-ATAN2 = ARCTAN2 ## Returnerar arcus tangens för en x- och en y- koordinat
-ATANH = ARCTANH ## Returnerar hyperbolisk arcus tangens för ett tal
-CEILING = RUNDA.UPP ## Avrundar ett tal till närmaste heltal eller närmaste signifikanta multipel
-COMBIN = KOMBIN ## Returnerar antalet kombinationer för ett givet antal objekt
-COS = COS ## Returnerar cosinus för ett tal
-COSH = COSH ## Returnerar hyperboliskt cosinus för ett tal
-DEGREES = GRADER ## Omvandlar radianer till grader
-EVEN = JÄMN ## Avrundar ett tal uppåt till närmaste heltal
-EXP = EXP ## Returnerar e upphöjt till ett givet tal
-FACT = FAKULTET ## Returnerar fakulteten för ett tal
-FACTDOUBLE = DUBBELFAKULTET ## Returnerar dubbelfakulteten för ett tal
-FLOOR = RUNDA.NED ## Avrundar ett tal nedåt mot noll
-GCD = SGD ## Returnerar den största gemensamma nämnaren
-INT = HELTAL ## Avrundar ett tal nedåt till närmaste heltal
-LCM = MGM ## Returnerar den minsta gemensamma multipeln
-LN = LN ## Returnerar den naturliga logaritmen för ett tal
-LOG = LOG ## Returnerar logaritmen för ett tal för en given bas
-LOG10 = LOG10 ## Returnerar 10-logaritmen för ett tal
-MDETERM = MDETERM ## Returnerar matrisen som är avgörandet av en matris
-MINVERSE = MINVERT ## Returnerar matrisinversen av en matris
-MMULT = MMULT ## Returnerar matrisprodukten av två matriser
-MOD = REST ## Returnerar resten vid en division
-MROUND = MAVRUNDA ## Returnerar ett tal avrundat till en given multipel
-MULTINOMIAL = MULTINOMIAL ## Returnerar multinomialen för en uppsättning tal
-ODD = UDDA ## Avrundar ett tal uppåt till närmaste udda heltal
-PI = PI ## Returnerar värdet pi
-POWER = UPPHÖJT.TILL ## Returnerar resultatet av ett tal upphöjt till en exponent
-PRODUCT = PRODUKT ## Multiplicerar argumenten
-QUOTIENT = KVOT ## Returnerar heltalsdelen av en division
-RADIANS = RADIANER ## Omvandlar grader till radianer
-RAND = SLUMP ## Returnerar ett slumptal mellan 0 och 1
-RANDBETWEEN = SLUMP.MELLAN ## Returnerar ett slumptal mellan de tal som du anger
-ROMAN = ROMERSK ## Omvandlar vanliga (arabiska) siffror till romerska som text
-ROUND = AVRUNDA ## Avrundar ett tal till ett angivet antal siffror
-ROUNDDOWN = AVRUNDA.NEDÅT ## Avrundar ett tal nedåt mot noll
-ROUNDUP = AVRUNDA.UPPÅT ## Avrundar ett tal uppåt, från noll
-SERIESSUM = SERIESUMMA ## Returnerar summan av en potensserie baserat på formeln
-SIGN = TECKEN ## Returnerar tecknet för ett tal
-SIN = SIN ## Returnerar sinus för en given vinkel
-SINH = SINH ## Returnerar hyperbolisk sinus för ett tal
-SQRT = ROT ## Returnerar den positiva kvadratroten
-SQRTPI = ROTPI ## Returnerar kvadratroten för (tal * pi)
-SUBTOTAL = DELSUMMA ## Returnerar en delsumma i en lista eller databas
-SUM = SUMMA ## Summerar argumenten
-SUMIF = SUMMA.OM ## Summerar celler enligt ett angivet villkor
-SUMIFS = SUMMA.OMF ## Lägger till cellerna i ett område som uppfyller flera kriterier
-SUMPRODUCT = PRODUKTSUMMA ## Returnerar summan av produkterna i motsvarande matriskomponenter
-SUMSQ = KVADRATSUMMA ## Returnerar summan av argumentens kvadrater
-SUMX2MY2 = SUMMAX2MY2 ## Returnerar summan av differensen mellan kvadraterna för motsvarande värden i två matriser
-SUMX2PY2 = SUMMAX2PY2 ## Returnerar summan av summan av kvadraterna av motsvarande värden i två matriser
-SUMXMY2 = SUMMAXMY2 ## Returnerar summan av kvadraten av skillnaden mellan motsvarande värden i två matriser
-TAN = TAN ## Returnerar tangens för ett tal
-TANH = TANH ## Returnerar hyperbolisk tangens för ett tal
-TRUNC = AVKORTA ## Avkortar ett tal till ett heltal
-
-
-##
-## Statistical functions Statistiska funktioner
-##
-AVEDEV = MEDELAVV ## Returnerar medelvärdet för datapunkters absoluta avvikelse från deras medelvärde
-AVERAGE = MEDEL ## Returnerar medelvärdet av argumenten
-AVERAGEA = AVERAGEA ## Returnerar medelvärdet av argumenten, inklusive tal, text och logiska värden
-AVERAGEIF = MEDELOM ## Returnerar medelvärdet (aritmetiskt medelvärde) för alla celler i ett område som uppfyller ett givet kriterium
-AVERAGEIFS = MEDELOMF ## Returnerar medelvärdet (det aritmetiska medelvärdet) för alla celler som uppfyller flera villkor.
-BETADIST = BETAFÖRD ## Returnerar den kumulativa betafördelningsfunktionen
-BETAINV = BETAINV ## Returnerar inversen till den kumulativa fördelningsfunktionen för en viss betafördelning
-BINOMDIST = BINOMFÖRD ## Returnerar den individuella binomialfördelningen
-CHIDIST = CHI2FÖRD ## Returnerar den ensidiga sannolikheten av c2-fördelningen
-CHIINV = CHI2INV ## Returnerar inversen av chi2-fördelningen
-CHITEST = CHI2TEST ## Returnerar oberoendetesten
-CONFIDENCE = KONFIDENS ## Returnerar konfidensintervallet för en populations medelvärde
-CORREL = KORREL ## Returnerar korrelationskoefficienten mellan två datamängder
-COUNT = ANTAL ## Räknar hur många tal som finns bland argumenten
-COUNTA = ANTALV ## Räknar hur många värden som finns bland argumenten
-COUNTBLANK = ANTAL.TOMMA ## Räknar antalet tomma celler i ett område
-COUNTIF = ANTAL.OM ## Räknar antalet celler i ett område som uppfyller angivna villkor.
-COUNTIFS = ANTAL.OMF ## Räknar antalet celler i ett område som uppfyller flera villkor.
-COVAR = KOVAR ## Returnerar kovariansen, d.v.s. medelvärdet av produkterna för parade avvikelser
-CRITBINOM = KRITBINOM ## Returnerar det minsta värdet för vilket den kumulativa binomialfördelningen är mindre än eller lika med ett villkorsvärde
-DEVSQ = KVADAVV ## Returnerar summan av kvadrater på avvikelser
-EXPONDIST = EXPONFÖRD ## Returnerar exponentialfördelningen
-FDIST = FFÖRD ## Returnerar F-sannolikhetsfördelningen
-FINV = FINV ## Returnerar inversen till F-sannolikhetsfördelningen
-FISHER = FISHER ## Returnerar Fisher-transformationen
-FISHERINV = FISHERINV ## Returnerar inversen till Fisher-transformationen
-FORECAST = PREDIKTION ## Returnerar ett värde längs en linjär trendlinje
-FREQUENCY = FREKVENS ## Returnerar en frekvensfördelning som en lodrät matris
-FTEST = FTEST ## Returnerar resultatet av en F-test
-GAMMADIST = GAMMAFÖRD ## Returnerar gammafördelningen
-GAMMAINV = GAMMAINV ## Returnerar inversen till den kumulativa gammafördelningen
-GAMMALN = GAMMALN ## Returnerar den naturliga logaritmen för gammafunktionen, G(x)
-GEOMEAN = GEOMEDEL ## Returnerar det geometriska medelvärdet
-GROWTH = EXPTREND ## Returnerar värden längs en exponentiell trend
-HARMEAN = HARMMEDEL ## Returnerar det harmoniska medelvärdet
-HYPGEOMDIST = HYPGEOMFÖRD ## Returnerar den hypergeometriska fördelningen
-INTERCEPT = SKÄRNINGSPUNKT ## Returnerar skärningspunkten för en linjär regressionslinje
-KURT = TOPPIGHET ## Returnerar toppigheten av en mängd data
-LARGE = STÖRSTA ## Returnerar det n:te största värdet i en mängd data
-LINEST = REGR ## Returnerar parametrar till en linjär trendlinje
-LOGEST = EXPREGR ## Returnerar parametrarna i en exponentiell trend
-LOGINV = LOGINV ## Returnerar inversen till den lognormala fördelningen
-LOGNORMDIST = LOGNORMFÖRD ## Returnerar den kumulativa lognormala fördelningen
-MAX = MAX ## Returnerar det största värdet i en lista av argument
-MAXA = MAXA ## Returnerar det största värdet i en lista av argument, inklusive tal, text och logiska värden
-MEDIAN = MEDIAN ## Returnerar medianen för angivna tal
-MIN = MIN ## Returnerar det minsta värdet i en lista med argument
-MINA = MINA ## Returnerar det minsta värdet i en lista över argument, inklusive tal, text och logiska värden
-MODE = TYPVÄRDE ## Returnerar det vanligaste värdet i en datamängd
-NEGBINOMDIST = NEGBINOMFÖRD ## Returnerar den negativa binomialfördelningen
-NORMDIST = NORMFÖRD ## Returnerar den kumulativa normalfördelningen
-NORMINV = NORMINV ## Returnerar inversen till den kumulativa normalfördelningen
-NORMSDIST = NORMSFÖRD ## Returnerar den kumulativa standardnormalfördelningen
-NORMSINV = NORMSINV ## Returnerar inversen till den kumulativa standardnormalfördelningen
-PEARSON = PEARSON ## Returnerar korrelationskoefficienten till Pearsons momentprodukt
-PERCENTILE = PERCENTIL ## Returnerar den n:te percentilen av värden i ett område
-PERCENTRANK = PROCENTRANG ## Returnerar procentrangen för ett värde i en datamängd
-PERMUT = PERMUT ## Returnerar antal permutationer för ett givet antal objekt
-POISSON = POISSON ## Returnerar Poisson-fördelningen
-PROB = SANNOLIKHET ## Returnerar sannolikheten att värden i ett område ligger mellan två gränser
-QUARTILE = KVARTIL ## Returnerar kvartilen av en mängd data
-RANK = RANG ## Returnerar rangordningen för ett tal i en lista med tal
-RSQ = RKV ## Returnerar kvadraten av Pearsons produktmomentkorrelationskoefficient
-SKEW = SNEDHET ## Returnerar snedheten för en fördelning
-SLOPE = LUTNING ## Returnerar lutningen på en linjär regressionslinje
-SMALL = MINSTA ## Returnerar det n:te minsta värdet i en mängd data
-STANDARDIZE = STANDARDISERA ## Returnerar ett normaliserat värde
-STDEV = STDAV ## Uppskattar standardavvikelsen baserat på ett urval
-STDEVA = STDEVA ## Uppskattar standardavvikelsen baserat på ett urval, inklusive tal, text och logiska värden
-STDEVP = STDAVP ## Beräknar standardavvikelsen baserat på hela populationen
-STDEVPA = STDEVPA ## Beräknar standardavvikelsen baserat på hela populationen, inklusive tal, text och logiska värden
-STEYX = STDFELYX ## Returnerar standardfelet för ett förutspått y-värde för varje x-värde i regressionen
-TDIST = TFÖRD ## Returnerar Students t-fördelning
-TINV = TINV ## Returnerar inversen till Students t-fördelning
-TREND = TREND ## Returnerar värden längs en linjär trend
-TRIMMEAN = TRIMMEDEL ## Returnerar medelvärdet av mittpunkterna i en datamängd
-TTEST = TTEST ## Returnerar sannolikheten beräknad ur Students t-test
-VAR = VARIANS ## Uppskattar variansen baserat på ett urval
-VARA = VARA ## Uppskattar variansen baserat på ett urval, inklusive tal, text och logiska värden
-VARP = VARIANSP ## Beräknar variansen baserat på hela populationen
-VARPA = VARPA ## Beräknar variansen baserat på hela populationen, inklusive tal, text och logiska värden
-WEIBULL = WEIBULL ## Returnerar Weibull-fördelningen
-ZTEST = ZTEST ## Returnerar det ensidiga sannolikhetsvärdet av ett z-test
-
-
-##
-## Text functions Textfunktioner
-##
-ASC = ASC ## Ändrar helbredds (dubbel byte) engelska bokstäver eller katakana inom en teckensträng till tecken med halvt breddsteg (enkel byte)
-BAHTTEXT = BAHTTEXT ## Omvandlar ett tal till text med valutaformatet ß (baht)
-CHAR = TECKENKOD ## Returnerar tecknet som anges av kod
-CLEAN = STÄDA ## Tar bort alla icke utskrivbara tecken i en text
-CODE = KOD ## Returnerar en numerisk kod för det första tecknet i en textsträng
-CONCATENATE = SAMMANFOGA ## Sammanfogar flera textdelar till en textsträng
-DOLLAR = VALUTA ## Omvandlar ett tal till text med valutaformat
-EXACT = EXAKT ## Kontrollerar om två textvärden är identiska
-FIND = HITTA ## Hittar en text i en annan (skiljer på gemener och versaler)
-FINDB = HITTAB ## Hittar en text i en annan (skiljer på gemener och versaler)
-FIXED = FASTTAL ## Formaterar ett tal som text med ett fast antal decimaler
-JIS = JIS ## Ändrar halvbredds (enkel byte) engelska bokstäver eller katakana inom en teckensträng till tecken med helt breddsteg (dubbel byte)
-LEFT = VÄNSTER ## Returnerar tecken längst till vänster i en sträng
-LEFTB = VÄNSTERB ## Returnerar tecken längst till vänster i en sträng
-LEN = LÄNGD ## Returnerar antalet tecken i en textsträng
-LENB = LÄNGDB ## Returnerar antalet tecken i en textsträng
-LOWER = GEMENER ## Omvandlar text till gemener
-MID = EXTEXT ## Returnerar angivet antal tecken från en text med början vid den position som du anger
-MIDB = EXTEXTB ## Returnerar angivet antal tecken från en text med början vid den position som du anger
-PHONETIC = PHONETIC ## Returnerar de fonetiska (furigana) tecknen i en textsträng
-PROPER = INITIAL ## Ändrar första bokstaven i varje ord i ett textvärde till versal
-REPLACE = ERSÄTT ## Ersätter tecken i text
-REPLACEB = ERSÄTTB ## Ersätter tecken i text
-REPT = REP ## Upprepar en text ett bestämt antal gånger
-RIGHT = HÖGER ## Returnerar tecken längst till höger i en sträng
-RIGHTB = HÖGERB ## Returnerar tecken längst till höger i en sträng
-SEARCH = SÖK ## Hittar ett textvärde i ett annat (skiljer inte på gemener och versaler)
-SEARCHB = SÖKB ## Hittar ett textvärde i ett annat (skiljer inte på gemener och versaler)
-SUBSTITUTE = BYT.UT ## Ersätter gammal text med ny text i en textsträng
-T = T ## Omvandlar argumenten till text
-TEXT = TEXT ## Formaterar ett tal och omvandlar det till text
-TRIM = RENSA ## Tar bort blanksteg från text
-UPPER = VERSALER ## Omvandlar text till versaler
-VALUE = TEXTNUM ## Omvandlar ett textargument till ett tal
+##
+## Add-in and Automation functions Tilläggs- och automatiseringsfunktioner
+##
+GETPIVOTDATA = HÄMTA.PIVOTDATA ## Returnerar data som lagrats i en pivottabellrapport
+
+
+##
+## Cube functions Kubfunktioner
+##
+CUBEKPIMEMBER = KUBKPIMEDLEM ## Returnerar namn, egenskap och mått för en KPI och visar namnet och egenskapen i cellen. En KPI, eller prestandaindikator, är ett kvantifierbart mått, t.ex. månatlig bruttovinst eller personalomsättning per kvartal, som används för att analysera ett företags resultat.
+CUBEMEMBER = KUBMEDLEM ## Returnerar en medlem eller ett par i en kubhierarki. Används för att verifiera att medlemmen eller paret finns i kuben.
+CUBEMEMBERPROPERTY = KUBMEDLEMSEGENSKAP ## Returnerar värdet för en medlemsegenskap i kuben. Används för att verifiera att ett medlemsnamn finns i kuben, samt för att returnera den angivna egenskapen för medlemmen.
+CUBERANKEDMEMBER = KUBRANGORDNADMEDLEM ## Returnerar den n:te, eller rangordnade, medlemmen i en uppsättning. Används för att returnera ett eller flera element i en uppsättning, till exempelvis den bästa försäljaren eller de tio bästa eleverna.
+CUBESET = KUBINSTÄLLNING ## Definierar en beräknad uppsättning medlemmar eller par genom att skicka ett bestämt uttryck till kuben på servern, som skapar uppsättningen och sedan returnerar den till Microsoft Office Excel.
+CUBESETCOUNT = KUBINSTÄLLNINGANTAL ## Returnerar antalet objekt i en uppsättning.
+CUBEVALUE = KUBVÄRDE ## Returnerar ett mängdvärde från en kub.
+
+
+##
+## Database functions Databasfunktioner
+##
+DAVERAGE = DMEDEL ## Returnerar medelvärdet av databasposterna
+DCOUNT = DANTAL ## Räknar antalet celler som innehåller tal i en databas
+DCOUNTA = DANTALV ## Räknar ifyllda celler i en databas
+DGET = DHÄMTA ## Hämtar en enstaka post från en databas som uppfyller de angivna villkoren
+DMAX = DMAX ## Returnerar det största värdet från databasposterna
+DMIN = DMIN ## Returnerar det minsta värdet från databasposterna
+DPRODUCT = DPRODUKT ## Multiplicerar värdena i ett visst fält i poster som uppfyller villkoret
+DSTDEV = DSTDAV ## Uppskattar standardavvikelsen baserat på ett urval av databasposterna
+DSTDEVP = DSTDAVP ## Beräknar standardavvikelsen utifrån hela populationen av valda databasposter
+DSUM = DSUMMA ## Summerar talen i kolumnfält i databasposter som uppfyller villkoret
+DVAR = DVARIANS ## Uppskattar variansen baserat på ett urval av databasposterna
+DVARP = DVARIANSP ## Beräknar variansen utifrån hela populationen av valda databasposter
+
+
+##
+## Date and time functions Tid- och datumfunktioner
+##
+DATE = DATUM ## Returnerar ett serienummer för ett visst datum
+DATEVALUE = DATUMVÄRDE ## Konverterar ett datum i textformat till ett serienummer
+DAY = DAG ## Konverterar ett serienummer till dag i månaden
+DAYS360 = DAGAR360 ## Beräknar antalet dagar mellan två datum baserat på ett 360-dagarsår
+EDATE = EDATUM ## Returnerar serienumret för ett datum som infaller ett visst antal månader före eller efter startdatumet
+EOMONTH = SLUTMÅNAD ## Returnerar serienumret för sista dagen i månaden ett visst antal månader tidigare eller senare
+HOUR = TIMME ## Konverterar ett serienummer till en timme
+MINUTE = MINUT ## Konverterar ett serienummer till en minut
+MONTH = MÅNAD ## Konverterar ett serienummer till en månad
+NETWORKDAYS = NETTOARBETSDAGAR ## Returnerar antalet hela arbetsdagar mellan två datum
+NOW = NU ## Returnerar serienumret för dagens datum och aktuell tid
+SECOND = SEKUND ## Konverterar ett serienummer till en sekund
+TIME = KLOCKSLAG ## Returnerar serienumret för en viss tid
+TIMEVALUE = TIDVÄRDE ## Konverterar en tid i textformat till ett serienummer
+TODAY = IDAG ## Returnerar serienumret för dagens datum
+WEEKDAY = VECKODAG ## Konverterar ett serienummer till en dag i veckan
+WEEKNUM = VECKONR ## Konverterar ett serienummer till ett veckonummer
+WORKDAY = ARBETSDAGAR ## Returnerar serienumret för ett datum ett visst antal arbetsdagar tidigare eller senare
+YEAR = ÅR ## Konverterar ett serienummer till ett år
+YEARFRAC = ÅRDEL ## Returnerar en del av ett år som representerar antalet hela dagar mellan start- och slutdatum
+
+
+##
+## Engineering functions Tekniska funktioner
+##
+BESSELI = BESSELI ## Returnerar den modifierade Bessel-funktionen In(x)
+BESSELJ = BESSELJ ## Returnerar Bessel-funktionen Jn(x)
+BESSELK = BESSELK ## Returnerar den modifierade Bessel-funktionen Kn(x)
+BESSELY = BESSELY ## Returnerar Bessel-funktionen Yn(x)
+BIN2DEC = BIN.TILL.DEC ## Omvandlar ett binärt tal till decimalt
+BIN2HEX = BIN.TILL.HEX ## Omvandlar ett binärt tal till hexadecimalt
+BIN2OCT = BIN.TILL.OKT ## Omvandlar ett binärt tal till oktalt
+COMPLEX = KOMPLEX ## Omvandlar reella och imaginära koefficienter till ett komplext tal
+CONVERT = KONVERTERA ## Omvandlar ett tal från ett måttsystem till ett annat
+DEC2BIN = DEC.TILL.BIN ## Omvandlar ett decimalt tal till binärt
+DEC2HEX = DEC.TILL.HEX ## Omvandlar ett decimalt tal till hexadecimalt
+DEC2OCT = DEC.TILL.OKT ## Omvandlar ett decimalt tal till oktalt
+DELTA = DELTA ## Testar om två värden är lika
+ERF = FELF ## Returnerar felfunktionen
+ERFC = FELFK ## Returnerar den komplementära felfunktionen
+GESTEP = SLSTEG ## Testar om ett tal är större än ett tröskelvärde
+HEX2BIN = HEX.TILL.BIN ## Omvandlar ett hexadecimalt tal till binärt
+HEX2DEC = HEX.TILL.DEC ## Omvandlar ett hexadecimalt tal till decimalt
+HEX2OCT = HEX.TILL.OKT ## Omvandlar ett hexadecimalt tal till oktalt
+IMABS = IMABS ## Returnerar absolutvärdet (modulus) för ett komplext tal
+IMAGINARY = IMAGINÄR ## Returnerar den imaginära koefficienten för ett komplext tal
+IMARGUMENT = IMARGUMENT ## Returnerar det komplexa talets argument, en vinkel uttryckt i radianer
+IMCONJUGATE = IMKONJUGAT ## Returnerar det komplexa talets konjugat
+IMCOS = IMCOS ## Returnerar cosinus för ett komplext tal
+IMDIV = IMDIV ## Returnerar kvoten för två komplexa tal
+IMEXP = IMEUPPHÖJT ## Returnerar exponenten för ett komplext tal
+IMLN = IMLN ## Returnerar den naturliga logaritmen för ett komplext tal
+IMLOG10 = IMLOG10 ## Returnerar 10-logaritmen för ett komplext tal
+IMLOG2 = IMLOG2 ## Returnerar 2-logaritmen för ett komplext tal
+IMPOWER = IMUPPHÖJT ## Returnerar ett komplext tal upphöjt till en exponent
+IMPRODUCT = IMPRODUKT ## Returnerar produkten av komplexa tal
+IMREAL = IMREAL ## Returnerar den reella koefficienten för ett komplext tal
+IMSIN = IMSIN ## Returnerar sinus för ett komplext tal
+IMSQRT = IMROT ## Returnerar kvadratroten av ett komplext tal
+IMSUB = IMDIFF ## Returnerar differensen mellan två komplexa tal
+IMSUM = IMSUM ## Returnerar summan av komplexa tal
+OCT2BIN = OKT.TILL.BIN ## Omvandlar ett oktalt tal till binärt
+OCT2DEC = OKT.TILL.DEC ## Omvandlar ett oktalt tal till decimalt
+OCT2HEX = OKT.TILL.HEX ## Omvandlar ett oktalt tal till hexadecimalt
+
+
+##
+## Financial functions Finansiella funktioner
+##
+ACCRINT = UPPLRÄNTA ## Returnerar den upplupna räntan för värdepapper med periodisk ränta
+ACCRINTM = UPPLOBLRÄNTA ## Returnerar den upplupna räntan för ett värdepapper som ger avkastning på förfallodagen
+AMORDEGRC = AMORDEGRC ## Returnerar avskrivningen för varje redovisningsperiod med hjälp av en avskrivningskoefficient
+AMORLINC = AMORLINC ## Returnerar avskrivningen för varje redovisningsperiod
+COUPDAYBS = KUPDAGBB ## Returnerar antal dagar från början av kupongperioden till likviddagen
+COUPDAYS = KUPDAGARS ## Returnerar antalet dagar i kupongperioden som innehåller betalningsdatumet
+COUPDAYSNC = KUPDAGNK ## Returnerar antalet dagar från betalningsdatumet till nästa kupongdatum
+COUPNCD = KUPNKD ## Returnerar nästa kupongdatum efter likviddagen
+COUPNUM = KUPANT ## Returnerar kuponger som förfaller till betalning mellan likviddagen och förfallodagen
+COUPPCD = KUPFKD ## Returnerar föregående kupongdatum före likviddagen
+CUMIPMT = KUMRÄNTA ## Returnerar den ackumulerade räntan som betalats mellan två perioder
+CUMPRINC = KUMPRIS ## Returnerar det ackumulerade kapitalbeloppet som betalats på ett lån mellan två perioder
+DB = DB ## Returnerar avskrivningen för en tillgång under en angiven tid enligt metoden för fast degressiv avskrivning
+DDB = DEGAVSKR ## Returnerar en tillgångs värdeminskning under en viss period med hjälp av dubbel degressiv avskrivning eller någon annan metod som du anger
+DISC = DISK ## Returnerar diskonteringsräntan för ett värdepapper
+DOLLARDE = DECTAL ## Omvandlar ett pris uttryckt som ett bråk till ett decimaltal
+DOLLARFR = BRÅK ## Omvandlar ett pris i kronor uttryckt som ett decimaltal till ett bråk
+DURATION = LÖPTID ## Returnerar den årliga löptiden för en säkerhet med periodiska räntebetalningar
+EFFECT = EFFRÄNTA ## Returnerar den årliga effektiva räntesatsen
+FV = SLUTVÄRDE ## Returnerar det framtida värdet på en investering
+FVSCHEDULE = FÖRRÄNTNING ## Returnerar det framtida värdet av ett begynnelsekapital beräknat på olika räntenivåer
+INTRATE = ÅRSRÄNTA ## Returnerar räntesatsen för ett betalt värdepapper
+IPMT = RBETALNING ## Returnerar räntedelen av en betalning för en given period
+IRR = IR ## Returnerar internräntan för en serie betalningar
+ISPMT = RALÅN ## Beräknar räntan som har betalats under en specifik betalningsperiod
+MDURATION = MLÖPTID ## Returnerar den modifierade Macauley-löptiden för ett värdepapper med det antagna nominella värdet 100 kr
+MIRR = MODIR ## Returnerar internräntan där positiva och negativa betalningar finansieras med olika räntor
+NOMINAL = NOMRÄNTA ## Returnerar den årliga nominella räntesatsen
+NPER = PERIODER ## Returnerar antalet perioder för en investering
+NPV = NETNUVÄRDE ## Returnerar nuvärdet av en serie periodiska betalningar vid en given diskonteringsränta
+ODDFPRICE = UDDAFPRIS ## Returnerar priset per 100 kr nominellt värde för ett värdepapper med en udda första period
+ODDFYIELD = UDDAFAVKASTNING ## Returnerar avkastningen för en säkerhet med en udda första period
+ODDLPRICE = UDDASPRIS ## Returnerar priset per 100 kr nominellt värde för ett värdepapper med en udda sista period
+ODDLYIELD = UDDASAVKASTNING ## Returnerar avkastningen för en säkerhet med en udda sista period
+PMT = BETALNING ## Returnerar den periodiska betalningen för en annuitet
+PPMT = AMORT ## Returnerar amorteringsdelen av en annuitetsbetalning för en given period
+PRICE = PRIS ## Returnerar priset per 100 kr nominellt värde för ett värdepapper som ger periodisk ränta
+PRICEDISC = PRISDISK ## Returnerar priset per 100 kr nominellt värde för ett diskonterat värdepapper
+PRICEMAT = PRISFÖRF ## Returnerar priset per 100 kr nominellt värde för ett värdepapper som ger ränta på förfallodagen
+PV = PV ## Returnerar nuvärdet av en serie lika stora periodiska betalningar
+RATE = RÄNTA ## Returnerar räntesatsen per period i en annuitet
+RECEIVED = BELOPP ## Returnerar beloppet som utdelas på förfallodagen för ett betalat värdepapper
+SLN = LINAVSKR ## Returnerar den linjära avskrivningen för en tillgång under en period
+SYD = ÅRSAVSKR ## Returnerar den årliga avskrivningssumman för en tillgång under en angiven period
+TBILLEQ = SSVXEKV ## Returnerar avkastningen motsvarande en obligation för en statsskuldväxel
+TBILLPRICE = SSVXPRIS ## Returnerar priset per 100 kr nominellt värde för en statsskuldväxel
+TBILLYIELD = SSVXRÄNTA ## Returnerar avkastningen för en statsskuldväxel
+VDB = VDEGRAVSKR ## Returnerar avskrivningen för en tillgång under en angiven period (med degressiv avskrivning)
+XIRR = XIRR ## Returnerar internräntan för en serie betalningar som inte nödvändigtvis är periodiska
+XNPV = XNUVÄRDE ## Returnerar det nuvarande nettovärdet för en serie betalningar som inte nödvändigtvis är periodiska
+YIELD = NOMAVK ## Returnerar avkastningen för ett värdepapper som ger periodisk ränta
+YIELDDISC = NOMAVKDISK ## Returnerar den årliga avkastningen för diskonterade värdepapper, exempelvis en statsskuldväxel
+YIELDMAT = NOMAVKFÖRF ## Returnerar den årliga avkastningen för ett värdepapper som ger ränta på förfallodagen
+
+
+##
+## Information functions Informationsfunktioner
+##
+CELL = CELL ## Returnerar information om formatering, plats och innehåll i en cell
+ERROR.TYPE = FEL.TYP ## Returnerar ett tal som motsvarar ett felvärde
+INFO = INFO ## Returnerar information om operativsystemet
+ISBLANK = ÄRREF ## Returnerar SANT om värdet är tomt
+ISERR = Ä ## Returnerar SANT om värdet är ett felvärde annat än #SAKNAS!
+ISERROR = ÄRFEL ## Returnerar SANT om värdet är ett felvärde
+ISEVEN = ÄRJÄMN ## Returnerar SANT om talet är jämnt
+ISLOGICAL = ÄREJTEXT ## Returnerar SANT om värdet är ett logiskt värde
+ISNA = ÄRLOGISK ## Returnerar SANT om värdet är felvärdet #SAKNAS!
+ISNONTEXT = ÄRSAKNAD ## Returnerar SANT om värdet inte är text
+ISNUMBER = ÄRTAL ## Returnerar SANT om värdet är ett tal
+ISODD = ÄRUDDA ## Returnerar SANT om talet är udda
+ISREF = ÄRTOM ## Returnerar SANT om värdet är en referens
+ISTEXT = ÄRTEXT ## Returnerar SANT om värdet är text
+N = N ## Returnerar ett värde omvandlat till ett tal
+NA = SAKNAS ## Returnerar felvärdet #SAKNAS!
+TYPE = VÄRDETYP ## Returnerar ett tal som anger värdets datatyp
+
+
+##
+## Logical functions Logiska funktioner
+##
+AND = OCH ## Returnerar SANT om alla argument är sanna
+FALSE = FALSKT ## Returnerar det logiska värdet FALSKT
+IF = OM ## Anger vilket logiskt test som ska utföras
+IFERROR = OMFEL ## Returnerar ett värde som du anger om en formel utvärderar till ett fel; annars returneras resultatet av formeln
+NOT = ICKE ## Inverterar logiken för argumenten
+OR = ELLER ## Returnerar SANT om något argument är SANT
+TRUE = SANT ## Returnerar det logiska värdet SANT
+
+
+##
+## Lookup and reference functions Sök- och referensfunktioner
+##
+ADDRESS = ADRESS ## Returnerar en referens som text till en enstaka cell i ett kalkylblad
+AREAS = OMRÅDEN ## Returnerar antalet områden i en referens
+CHOOSE = VÄLJ ## Väljer ett värde i en lista över värden
+COLUMN = KOLUMN ## Returnerar kolumnnumret för en referens
+COLUMNS = KOLUMNER ## Returnerar antalet kolumner i en referens
+HLOOKUP = LETAKOLUMN ## Söker i den översta raden i en matris och returnerar värdet för angiven cell
+HYPERLINK = HYPERLÄNK ## Skapar en genväg eller ett hopp till ett dokument i nätverket, i ett intranät eller på Internet
+INDEX = INDEX ## Använder ett index för ett välja ett värde i en referens eller matris
+INDIRECT = INDIREKT ## Returnerar en referens som anges av ett textvärde
+LOOKUP = LETAUPP ## Letar upp värden i en vektor eller matris
+MATCH = PASSA ## Letar upp värden i en referens eller matris
+OFFSET = FÖRSKJUTNING ## Returnerar en referens förskjuten i förhållande till en given referens
+ROW = RAD ## Returnerar radnumret för en referens
+ROWS = RADER ## Returnerar antalet rader i en referens
+RTD = RTD ## Hämtar realtidsdata från ett program som stöder COM-automation (Automation: Ett sätt att arbeta med ett programs objekt från ett annat program eller utvecklingsverktyg. Detta kallades tidigare för OLE Automation, och är en branschstandard och ingår i Component Object Model (COM).)
+TRANSPOSE = TRANSPONERA ## Transponerar en matris
+VLOOKUP = LETARAD ## Letar i den första kolumnen i en matris och flyttar över raden för att returnera värdet för en cell
+
+
+##
+## Math and trigonometry functions Matematiska och trigonometriska funktioner
+##
+ABS = ABS ## Returnerar absolutvärdet av ett tal
+ACOS = ARCCOS ## Returnerar arcus cosinus för ett tal
+ACOSH = ARCCOSH ## Returnerar inverterad hyperbolisk cosinus för ett tal
+ASIN = ARCSIN ## Returnerar arcus cosinus för ett tal
+ASINH = ARCSINH ## Returnerar hyperbolisk arcus sinus för ett tal
+ATAN = ARCTAN ## Returnerar arcus tangens för ett tal
+ATAN2 = ARCTAN2 ## Returnerar arcus tangens för en x- och en y- koordinat
+ATANH = ARCTANH ## Returnerar hyperbolisk arcus tangens för ett tal
+CEILING = RUNDA.UPP ## Avrundar ett tal till närmaste heltal eller närmaste signifikanta multipel
+COMBIN = KOMBIN ## Returnerar antalet kombinationer för ett givet antal objekt
+COS = COS ## Returnerar cosinus för ett tal
+COSH = COSH ## Returnerar hyperboliskt cosinus för ett tal
+DEGREES = GRADER ## Omvandlar radianer till grader
+EVEN = JÄMN ## Avrundar ett tal uppåt till närmaste heltal
+EXP = EXP ## Returnerar e upphöjt till ett givet tal
+FACT = FAKULTET ## Returnerar fakulteten för ett tal
+FACTDOUBLE = DUBBELFAKULTET ## Returnerar dubbelfakulteten för ett tal
+FLOOR = RUNDA.NED ## Avrundar ett tal nedåt mot noll
+GCD = SGD ## Returnerar den största gemensamma nämnaren
+INT = HELTAL ## Avrundar ett tal nedåt till närmaste heltal
+LCM = MGM ## Returnerar den minsta gemensamma multipeln
+LN = LN ## Returnerar den naturliga logaritmen för ett tal
+LOG = LOG ## Returnerar logaritmen för ett tal för en given bas
+LOG10 = LOG10 ## Returnerar 10-logaritmen för ett tal
+MDETERM = MDETERM ## Returnerar matrisen som är avgörandet av en matris
+MINVERSE = MINVERT ## Returnerar matrisinversen av en matris
+MMULT = MMULT ## Returnerar matrisprodukten av två matriser
+MOD = REST ## Returnerar resten vid en division
+MROUND = MAVRUNDA ## Returnerar ett tal avrundat till en given multipel
+MULTINOMIAL = MULTINOMIAL ## Returnerar multinomialen för en uppsättning tal
+ODD = UDDA ## Avrundar ett tal uppåt till närmaste udda heltal
+PI = PI ## Returnerar värdet pi
+POWER = UPPHÖJT.TILL ## Returnerar resultatet av ett tal upphöjt till en exponent
+PRODUCT = PRODUKT ## Multiplicerar argumenten
+QUOTIENT = KVOT ## Returnerar heltalsdelen av en division
+RADIANS = RADIANER ## Omvandlar grader till radianer
+RAND = SLUMP ## Returnerar ett slumptal mellan 0 och 1
+RANDBETWEEN = SLUMP.MELLAN ## Returnerar ett slumptal mellan de tal som du anger
+ROMAN = ROMERSK ## Omvandlar vanliga (arabiska) siffror till romerska som text
+ROUND = AVRUNDA ## Avrundar ett tal till ett angivet antal siffror
+ROUNDDOWN = AVRUNDA.NEDÅT ## Avrundar ett tal nedåt mot noll
+ROUNDUP = AVRUNDA.UPPÅT ## Avrundar ett tal uppåt, från noll
+SERIESSUM = SERIESUMMA ## Returnerar summan av en potensserie baserat på formeln
+SIGN = TECKEN ## Returnerar tecknet för ett tal
+SIN = SIN ## Returnerar sinus för en given vinkel
+SINH = SINH ## Returnerar hyperbolisk sinus för ett tal
+SQRT = ROT ## Returnerar den positiva kvadratroten
+SQRTPI = ROTPI ## Returnerar kvadratroten för (tal * pi)
+SUBTOTAL = DELSUMMA ## Returnerar en delsumma i en lista eller databas
+SUM = SUMMA ## Summerar argumenten
+SUMIF = SUMMA.OM ## Summerar celler enligt ett angivet villkor
+SUMIFS = SUMMA.OMF ## Lägger till cellerna i ett område som uppfyller flera kriterier
+SUMPRODUCT = PRODUKTSUMMA ## Returnerar summan av produkterna i motsvarande matriskomponenter
+SUMSQ = KVADRATSUMMA ## Returnerar summan av argumentens kvadrater
+SUMX2MY2 = SUMMAX2MY2 ## Returnerar summan av differensen mellan kvadraterna för motsvarande värden i två matriser
+SUMX2PY2 = SUMMAX2PY2 ## Returnerar summan av summan av kvadraterna av motsvarande värden i två matriser
+SUMXMY2 = SUMMAXMY2 ## Returnerar summan av kvadraten av skillnaden mellan motsvarande värden i två matriser
+TAN = TAN ## Returnerar tangens för ett tal
+TANH = TANH ## Returnerar hyperbolisk tangens för ett tal
+TRUNC = AVKORTA ## Avkortar ett tal till ett heltal
+
+
+##
+## Statistical functions Statistiska funktioner
+##
+AVEDEV = MEDELAVV ## Returnerar medelvärdet för datapunkters absoluta avvikelse från deras medelvärde
+AVERAGE = MEDEL ## Returnerar medelvärdet av argumenten
+AVERAGEA = AVERAGEA ## Returnerar medelvärdet av argumenten, inklusive tal, text och logiska värden
+AVERAGEIF = MEDELOM ## Returnerar medelvärdet (aritmetiskt medelvärde) för alla celler i ett område som uppfyller ett givet kriterium
+AVERAGEIFS = MEDELOMF ## Returnerar medelvärdet (det aritmetiska medelvärdet) för alla celler som uppfyller flera villkor.
+BETADIST = BETAFÖRD ## Returnerar den kumulativa betafördelningsfunktionen
+BETAINV = BETAINV ## Returnerar inversen till den kumulativa fördelningsfunktionen för en viss betafördelning
+BINOMDIST = BINOMFÖRD ## Returnerar den individuella binomialfördelningen
+CHIDIST = CHI2FÖRD ## Returnerar den ensidiga sannolikheten av c2-fördelningen
+CHIINV = CHI2INV ## Returnerar inversen av chi2-fördelningen
+CHITEST = CHI2TEST ## Returnerar oberoendetesten
+CONFIDENCE = KONFIDENS ## Returnerar konfidensintervallet för en populations medelvärde
+CORREL = KORREL ## Returnerar korrelationskoefficienten mellan två datamängder
+COUNT = ANTAL ## Räknar hur många tal som finns bland argumenten
+COUNTA = ANTALV ## Räknar hur många värden som finns bland argumenten
+COUNTBLANK = ANTAL.TOMMA ## Räknar antalet tomma celler i ett område
+COUNTIF = ANTAL.OM ## Räknar antalet celler i ett område som uppfyller angivna villkor.
+COUNTIFS = ANTAL.OMF ## Räknar antalet celler i ett område som uppfyller flera villkor.
+COVAR = KOVAR ## Returnerar kovariansen, d.v.s. medelvärdet av produkterna för parade avvikelser
+CRITBINOM = KRITBINOM ## Returnerar det minsta värdet för vilket den kumulativa binomialfördelningen är mindre än eller lika med ett villkorsvärde
+DEVSQ = KVADAVV ## Returnerar summan av kvadrater på avvikelser
+EXPONDIST = EXPONFÖRD ## Returnerar exponentialfördelningen
+FDIST = FFÖRD ## Returnerar F-sannolikhetsfördelningen
+FINV = FINV ## Returnerar inversen till F-sannolikhetsfördelningen
+FISHER = FISHER ## Returnerar Fisher-transformationen
+FISHERINV = FISHERINV ## Returnerar inversen till Fisher-transformationen
+FORECAST = PREDIKTION ## Returnerar ett värde längs en linjär trendlinje
+FREQUENCY = FREKVENS ## Returnerar en frekvensfördelning som en lodrät matris
+FTEST = FTEST ## Returnerar resultatet av en F-test
+GAMMADIST = GAMMAFÖRD ## Returnerar gammafördelningen
+GAMMAINV = GAMMAINV ## Returnerar inversen till den kumulativa gammafördelningen
+GAMMALN = GAMMALN ## Returnerar den naturliga logaritmen för gammafunktionen, G(x)
+GEOMEAN = GEOMEDEL ## Returnerar det geometriska medelvärdet
+GROWTH = EXPTREND ## Returnerar värden längs en exponentiell trend
+HARMEAN = HARMMEDEL ## Returnerar det harmoniska medelvärdet
+HYPGEOMDIST = HYPGEOMFÖRD ## Returnerar den hypergeometriska fördelningen
+INTERCEPT = SKÄRNINGSPUNKT ## Returnerar skärningspunkten för en linjär regressionslinje
+KURT = TOPPIGHET ## Returnerar toppigheten av en mängd data
+LARGE = STÖRSTA ## Returnerar det n:te största värdet i en mängd data
+LINEST = REGR ## Returnerar parametrar till en linjär trendlinje
+LOGEST = EXPREGR ## Returnerar parametrarna i en exponentiell trend
+LOGINV = LOGINV ## Returnerar inversen till den lognormala fördelningen
+LOGNORMDIST = LOGNORMFÖRD ## Returnerar den kumulativa lognormala fördelningen
+MAX = MAX ## Returnerar det största värdet i en lista av argument
+MAXA = MAXA ## Returnerar det största värdet i en lista av argument, inklusive tal, text och logiska värden
+MEDIAN = MEDIAN ## Returnerar medianen för angivna tal
+MIN = MIN ## Returnerar det minsta värdet i en lista med argument
+MINA = MINA ## Returnerar det minsta värdet i en lista över argument, inklusive tal, text och logiska värden
+MODE = TYPVÄRDE ## Returnerar det vanligaste värdet i en datamängd
+NEGBINOMDIST = NEGBINOMFÖRD ## Returnerar den negativa binomialfördelningen
+NORMDIST = NORMFÖRD ## Returnerar den kumulativa normalfördelningen
+NORMINV = NORMINV ## Returnerar inversen till den kumulativa normalfördelningen
+NORMSDIST = NORMSFÖRD ## Returnerar den kumulativa standardnormalfördelningen
+NORMSINV = NORMSINV ## Returnerar inversen till den kumulativa standardnormalfördelningen
+PEARSON = PEARSON ## Returnerar korrelationskoefficienten till Pearsons momentprodukt
+PERCENTILE = PERCENTIL ## Returnerar den n:te percentilen av värden i ett område
+PERCENTRANK = PROCENTRANG ## Returnerar procentrangen för ett värde i en datamängd
+PERMUT = PERMUT ## Returnerar antal permutationer för ett givet antal objekt
+POISSON = POISSON ## Returnerar Poisson-fördelningen
+PROB = SANNOLIKHET ## Returnerar sannolikheten att värden i ett område ligger mellan två gränser
+QUARTILE = KVARTIL ## Returnerar kvartilen av en mängd data
+RANK = RANG ## Returnerar rangordningen för ett tal i en lista med tal
+RSQ = RKV ## Returnerar kvadraten av Pearsons produktmomentkorrelationskoefficient
+SKEW = SNEDHET ## Returnerar snedheten för en fördelning
+SLOPE = LUTNING ## Returnerar lutningen på en linjär regressionslinje
+SMALL = MINSTA ## Returnerar det n:te minsta värdet i en mängd data
+STANDARDIZE = STANDARDISERA ## Returnerar ett normaliserat värde
+STDEV = STDAV ## Uppskattar standardavvikelsen baserat på ett urval
+STDEVA = STDEVA ## Uppskattar standardavvikelsen baserat på ett urval, inklusive tal, text och logiska värden
+STDEVP = STDAVP ## Beräknar standardavvikelsen baserat på hela populationen
+STDEVPA = STDEVPA ## Beräknar standardavvikelsen baserat på hela populationen, inklusive tal, text och logiska värden
+STEYX = STDFELYX ## Returnerar standardfelet för ett förutspått y-värde för varje x-värde i regressionen
+TDIST = TFÖRD ## Returnerar Students t-fördelning
+TINV = TINV ## Returnerar inversen till Students t-fördelning
+TREND = TREND ## Returnerar värden längs en linjär trend
+TRIMMEAN = TRIMMEDEL ## Returnerar medelvärdet av mittpunkterna i en datamängd
+TTEST = TTEST ## Returnerar sannolikheten beräknad ur Students t-test
+VAR = VARIANS ## Uppskattar variansen baserat på ett urval
+VARA = VARA ## Uppskattar variansen baserat på ett urval, inklusive tal, text och logiska värden
+VARP = VARIANSP ## Beräknar variansen baserat på hela populationen
+VARPA = VARPA ## Beräknar variansen baserat på hela populationen, inklusive tal, text och logiska värden
+WEIBULL = WEIBULL ## Returnerar Weibull-fördelningen
+ZTEST = ZTEST ## Returnerar det ensidiga sannolikhetsvärdet av ett z-test
+
+
+##
+## Text functions Textfunktioner
+##
+ASC = ASC ## Ändrar helbredds (dubbel byte) engelska bokstäver eller katakana inom en teckensträng till tecken med halvt breddsteg (enkel byte)
+BAHTTEXT = BAHTTEXT ## Omvandlar ett tal till text med valutaformatet ß (baht)
+CHAR = TECKENKOD ## Returnerar tecknet som anges av kod
+CLEAN = STÄDA ## Tar bort alla icke utskrivbara tecken i en text
+CODE = KOD ## Returnerar en numerisk kod för det första tecknet i en textsträng
+CONCATENATE = SAMMANFOGA ## Sammanfogar flera textdelar till en textsträng
+DOLLAR = VALUTA ## Omvandlar ett tal till text med valutaformat
+EXACT = EXAKT ## Kontrollerar om två textvärden är identiska
+FIND = HITTA ## Hittar en text i en annan (skiljer på gemener och versaler)
+FINDB = HITTAB ## Hittar en text i en annan (skiljer på gemener och versaler)
+FIXED = FASTTAL ## Formaterar ett tal som text med ett fast antal decimaler
+JIS = JIS ## Ändrar halvbredds (enkel byte) engelska bokstäver eller katakana inom en teckensträng till tecken med helt breddsteg (dubbel byte)
+LEFT = VÄNSTER ## Returnerar tecken längst till vänster i en sträng
+LEFTB = VÄNSTERB ## Returnerar tecken längst till vänster i en sträng
+LEN = LÄNGD ## Returnerar antalet tecken i en textsträng
+LENB = LÄNGDB ## Returnerar antalet tecken i en textsträng
+LOWER = GEMENER ## Omvandlar text till gemener
+MID = EXTEXT ## Returnerar angivet antal tecken från en text med början vid den position som du anger
+MIDB = EXTEXTB ## Returnerar angivet antal tecken från en text med början vid den position som du anger
+PHONETIC = PHONETIC ## Returnerar de fonetiska (furigana) tecknen i en textsträng
+PROPER = INITIAL ## Ändrar första bokstaven i varje ord i ett textvärde till versal
+REPLACE = ERSÄTT ## Ersätter tecken i text
+REPLACEB = ERSÄTTB ## Ersätter tecken i text
+REPT = REP ## Upprepar en text ett bestämt antal gånger
+RIGHT = HÖGER ## Returnerar tecken längst till höger i en sträng
+RIGHTB = HÖGERB ## Returnerar tecken längst till höger i en sträng
+SEARCH = SÖK ## Hittar ett textvärde i ett annat (skiljer inte på gemener och versaler)
+SEARCHB = SÖKB ## Hittar ett textvärde i ett annat (skiljer inte på gemener och versaler)
+SUBSTITUTE = BYT.UT ## Ersätter gammal text med ny text i en textsträng
+T = T ## Omvandlar argumenten till text
+TEXT = TEXT ## Formaterar ett tal och omvandlar det till text
+TRIM = RENSA ## Tar bort blanksteg från text
+UPPER = VERSALER ## Omvandlar text till versaler
+VALUE = TEXTNUM ## Omvandlar ett textargument till ett tal