Ultimate FAQ - Version 1.5.28

Version Description

  • Updated some PHPExcel files for increased import/export compatibility with PHP7
Download this release

Release Info

Developer Rustaurius
Plugin Icon 128x128 Ultimate FAQ
Version 1.5.28
Comparing to
See all releases

Code changes from version 1.5.27 to 1.5.28

Files changed (25) hide show
  1. Main.php +1 -1
  2. PHPExcel/Classes/PHPExcel/Autoloader.php +81 -85
  3. PHPExcel/Classes/PHPExcel/CachedObjectStorage/APC.php +290 -295
  4. PHPExcel/Classes/PHPExcel/CachedObjectStorage/CacheBase.php +368 -347
  5. PHPExcel/Classes/PHPExcel/CachedObjectStorage/DiscISAM.php +208 -219
  6. PHPExcel/Classes/PHPExcel/CachedObjectStorage/ICache.php +103 -112
  7. PHPExcel/Classes/PHPExcel/CachedObjectStorage/Igbinary.php +149 -152
  8. PHPExcel/Classes/PHPExcel/CachedObjectStorage/Memcache.php +308 -312
  9. PHPExcel/Classes/PHPExcel/CachedObjectStorage/Memory.php +118 -125
  10. PHPExcel/Classes/PHPExcel/CachedObjectStorage/MemoryGZip.php +133 -137
  11. PHPExcel/Classes/PHPExcel/CachedObjectStorage/MemorySerialized.php +129 -137
  12. PHPExcel/Classes/PHPExcel/CachedObjectStorage/PHPTemp.php +200 -206
  13. PHPExcel/Classes/PHPExcel/CachedObjectStorage/SQLite.php +307 -306
  14. PHPExcel/Classes/PHPExcel/CachedObjectStorage/SQLite3.php +346 -345
  15. PHPExcel/Classes/PHPExcel/CachedObjectStorage/Wincache.php +289 -294
  16. PHPExcel/Classes/PHPExcel/CachedObjectStorageFactory.php +231 -251
  17. PHPExcel/Classes/PHPExcel/CalcEngine/CyclicReferenceStack.php +94 -98
  18. PHPExcel/Classes/PHPExcel/CalcEngine/Logger.php +151 -153
  19. PHPExcel/Classes/PHPExcel/Calculation.php +4391 -3933
  20. PHPExcel/Classes/PHPExcel/Calculation/Database.php +676 -725
  21. PHPExcel/Classes/PHPExcel/Calculation/DateTime.php +1553 -1475
  22. PHPExcel/Classes/PHPExcel/Calculation/Engineering.php +2650 -2505
  23. PHPExcel/Classes/PHPExcel/Calculation/Exception.php +46 -52
  24. PHPExcel/Classes/PHPExcel/Calculation/ExceptionHandler.php +45 -49
  25. PHPExcel/Classes/PHPExcel/Calculation/Financial.php +0 -233
Main.php CHANGED
@@ -7,7 +7,7 @@ Author: Etoile Web Design
7
  Author URI: http://www.EtoileWebDesign.com/wordpress-plugins/
8
  Terms and Conditions: http://www.etoilewebdesign.com/plugin-terms-and-conditions/
9
  Text Domain: EWD_UFAQ
10
- Version: 1.5.27
11
  */
12
 
13
  global $ewd_ufaq_message;
7
  Author URI: http://www.EtoileWebDesign.com/wordpress-plugins/
8
  Terms and Conditions: http://www.etoilewebdesign.com/plugin-terms-and-conditions/
9
  Text Domain: EWD_UFAQ
10
+ Version: 1.5.28
11
  */
12
 
13
  global $ewd_ufaq_message;
PHPExcel/Classes/PHPExcel/Autoloader.php CHANGED
@@ -1,85 +1,81 @@
1
- <?php
2
- /**
3
- * PHPExcel
4
- *
5
- * Copyright (c) 2006 - 2014 PHPExcel
6
- *
7
- * This library is free software; you can redistribute it and/or
8
- * modify it under the terms of the GNU Lesser General Public
9
- * License as published by the Free Software Foundation; either
10
- * version 2.1 of the License, or (at your option) any later version.
11
- *
12
- * This library is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
- * Lesser General Public License for more details.
16
- *
17
- * You should have received a copy of the GNU Lesser General Public
18
- * License along with this library; if not, write to the Free Software
19
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
- *
21
- * @category PHPExcel
22
- * @package PHPExcel
23
- * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
24
- * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25
- * @version 1.8.0, 2014-03-02
26
- */
27
-
28
- PHPExcel_Autoloader::Register();
29
- // As we always try to run the autoloader before anything else, we can use it to do a few
30
- // simple checks and initialisations
31
- //PHPExcel_Shared_ZipStreamWrapper::register();
32
- // check mbstring.func_overload
33
- if (ini_get('mbstring.func_overload') & 2) {
34
- throw new PHPExcel_Exception('Multibyte function overloading in PHP must be disabled for string functions (2).');
35
- }
36
- PHPExcel_Shared_String::buildCharacterSets();
37
-
38
-
39
- /**
40
- * PHPExcel_Autoloader
41
- *
42
- * @category PHPExcel
43
- * @package PHPExcel
44
- * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
45
- */
46
- class PHPExcel_Autoloader
47
- {
48
- /**
49
- * Register the Autoloader with SPL
50
- *
51
- */
52
- public static function Register() {
53
- if (function_exists('__autoload')) {
54
- // Register any existing autoloader function with SPL, so we don't get any clashes
55
- spl_autoload_register('__autoload');
56
- }
57
- // Register ourselves with SPL
58
- return spl_autoload_register(array('PHPExcel_Autoloader', 'Load'));
59
- } // function Register()
60
-
61
-
62
- /**
63
- * Autoload a class identified by name
64
- *
65
- * @param string $pClassName Name of the object to load
66
- */
67
- public static function Load($pClassName){
68
- if ((class_exists($pClassName,FALSE)) || (strpos($pClassName, 'PHPExcel') !== 0)) {
69
- // Either already loaded, or not a PHPExcel class request
70
- return FALSE;
71
- }
72
-
73
- $pClassFilePath = PHPEXCEL_ROOT .
74
- str_replace('_',DIRECTORY_SEPARATOR,$pClassName) .
75
- '.php';
76
-
77
- if ((file_exists($pClassFilePath) === FALSE) || (is_readable($pClassFilePath) === FALSE)) {
78
- // Can't load
79
- return FALSE;
80
- }
81
-
82
- require($pClassFilePath);
83
- } // function Load()
84
-
85
- }
1
+ <?php
2
+
3
+ PHPExcel_Autoloader::register();
4
+ // As we always try to run the autoloader before anything else, we can use it to do a few
5
+ // simple checks and initialisations
6
+ //PHPExcel_Shared_ZipStreamWrapper::register();
7
+ // check mbstring.func_overload
8
+ if (ini_get('mbstring.func_overload') & 2) {
9
+ throw new PHPExcel_Exception('Multibyte function overloading in PHP must be disabled for string functions (2).');
10
+ }
11
+ PHPExcel_Shared_String::buildCharacterSets();
12
+
13
+ /**
14
+ * PHPExcel
15
+ *
16
+ * Copyright (c) 2006 - 2015 PHPExcel
17
+ *
18
+ * This library is free software; you can redistribute it and/or
19
+ * modify it under the terms of the GNU Lesser General Public
20
+ * License as published by the Free Software Foundation; either
21
+ * version 2.1 of the License, or (at your option) any later version.
22
+ *
23
+ * This library is distributed in the hope that it will be useful,
24
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
25
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26
+ * Lesser General Public License for more details.
27
+ *
28
+ * You should have received a copy of the GNU Lesser General Public
29
+ * License along with this library; if not, write to the Free Software
30
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
31
+ *
32
+ * @category PHPExcel
33
+ * @package PHPExcel
34
+ * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
35
+ * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
36
+ * @version ##VERSION##, ##DATE##
37
+ */
38
+ class PHPExcel_Autoloader
39
+ {
40
+ /**
41
+ * Register the Autoloader with SPL
42
+ *
43
+ */
44
+ public static function register()
45
+ {
46
+ if (function_exists('__autoload')) {
47
+ // Register any existing autoloader function with SPL, so we don't get any clashes
48
+ spl_autoload_register('__autoload');
49
+ }
50
+ // Register ourselves with SPL
51
+ if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
52
+ return spl_autoload_register(array('PHPExcel_Autoloader', 'load'), true, true);
53
+ } else {
54
+ return spl_autoload_register(array('PHPExcel_Autoloader', 'load'));
55
+ }
56
+ }
57
+
58
+ /**
59
+ * Autoload a class identified by name
60
+ *
61
+ * @param string $pClassName Name of the object to load
62
+ */
63
+ public static function load($pClassName)
64
+ {
65
+ if ((class_exists($pClassName, false)) || (strpos($pClassName, 'PHPExcel') !== 0)) {
66
+ // Either already loaded, or not a PHPExcel class request
67
+ return false;
68
+ }
69
+
70
+ $pClassFilePath = PHPEXCEL_ROOT .
71
+ str_replace('_', DIRECTORY_SEPARATOR, $pClassName) .
72
+ '.php';
73
+
74
+ if ((file_exists($pClassFilePath) === false) || (is_readable($pClassFilePath) === false)) {
75
+ // Can't load
76
+ return false;
77
+ }
78
+
79
+ require($pClassFilePath);
80
+ }
81
+ }
 
 
 
 
PHPExcel/Classes/PHPExcel/CachedObjectStorage/APC.php CHANGED
@@ -1,295 +1,290 @@
1
- <?php
2
- /**
3
- * PHPExcel
4
- *
5
- * Copyright (c) 2006 - 2014 PHPExcel
6
- *
7
- * This library is free software; you can redistribute it and/or
8
- * modify it under the terms of the GNU Lesser General Public
9
- * License as published by the Free Software Foundation; either
10
- * version 2.1 of the License, or (at your option) any later version.
11
- *
12
- * This library is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
- * Lesser General Public License for more details.
16
- *
17
- * You should have received a copy of the GNU Lesser General Public
18
- * License along with this library; if not, write to the Free Software
19
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
- *
21
- * @category PHPExcel
22
- * @package PHPExcel_CachedObjectStorage
23
- * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
24
- * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25
- * @version 1.8.0, 2014-03-02
26
- */
27
-
28
-
29
- /**
30
- * PHPExcel_CachedObjectStorage_APC
31
- *
32
- * @category PHPExcel
33
- * @package PHPExcel_CachedObjectStorage
34
- * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
35
- */
36
- class PHPExcel_CachedObjectStorage_APC extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {
37
-
38
- /**
39
- * Prefix used to uniquely identify cache data for this worksheet
40
- *
41
- * @access private
42
- * @var string
43
- */
44
- private $_cachePrefix = null;
45
-
46
- /**
47
- * Cache timeout
48
- *
49
- * @access private
50
- * @var integer
51
- */
52
- private $_cacheTime = 600;
53
-
54
-
55
- /**
56
- * Store cell data in cache for the current cell object if it's "dirty",
57
- * and the 'nullify' the current cell object
58
- *
59
- * @access private
60
- * @return void
61
- * @throws PHPExcel_Exception
62
- */
63
- protected function _storeData() {
64
- if ($this->_currentCellIsDirty && !empty($this->_currentObjectID)) {
65
- $this->_currentObject->detach();
66
-
67
- if (!apc_store($this->_cachePrefix.$this->_currentObjectID.'.cache',serialize($this->_currentObject),$this->_cacheTime)) {
68
- $this->__destruct();
69
- throw new PHPExcel_Exception('Failed to store cell '.$this->_currentObjectID.' in APC');
70
- }
71
- $this->_currentCellIsDirty = false;
72
- }
73
- $this->_currentObjectID = $this->_currentObject = null;
74
- } // function _storeData()
75
-
76
-
77
- /**
78
- * Add or Update a cell in cache identified by coordinate address
79
- *
80
- * @access public
81
- * @param string $pCoord Coordinate address of the cell to update
82
- * @param PHPExcel_Cell $cell Cell to update
83
- * @return void
84
- * @throws PHPExcel_Exception
85
- */
86
- public function addCacheData($pCoord, PHPExcel_Cell $cell) {
87
- if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) {
88
- $this->_storeData();
89
- }
90
- $this->_cellCache[$pCoord] = true;
91
-
92
- $this->_currentObjectID = $pCoord;
93
- $this->_currentObject = $cell;
94
- $this->_currentCellIsDirty = true;
95
-
96
- return $cell;
97
- } // function addCacheData()
98
-
99
-
100
- /**
101
- * Is a value set in the current PHPExcel_CachedObjectStorage_ICache for an indexed cell?
102
- *
103
- * @access public
104
- * @param string $pCoord Coordinate address of the cell to check
105
- * @return void
106
- * @return boolean
107
- */
108
- public function isDataSet($pCoord) {
109
- // Check if the requested entry is the current object, or exists in the cache
110
- if (parent::isDataSet($pCoord)) {
111
- if ($this->_currentObjectID == $pCoord) {
112
- return true;
113
- }
114
- // Check if the requested entry still exists in apc
115
- $success = apc_fetch($this->_cachePrefix.$pCoord.'.cache');
116
- if ($success === FALSE) {
117
- // Entry no longer exists in APC, so clear it from the cache array
118
- parent::deleteCacheData($pCoord);
119
- throw new PHPExcel_Exception('Cell entry '.$pCoord.' no longer exists in APC cache');
120
- }
121
- return true;
122
- }
123
- return false;
124
- } // function isDataSet()
125
-
126
-
127
- /**
128
- * Get cell at a specific coordinate
129
- *
130
- * @access public
131
- * @param string $pCoord Coordinate of the cell
132
- * @throws PHPExcel_Exception
133
- * @return PHPExcel_Cell Cell that was found, or null if not found
134
- */
135
- public function getCacheData($pCoord) {
136
- if ($pCoord === $this->_currentObjectID) {
137
- return $this->_currentObject;
138
- }
139
- $this->_storeData();
140
-
141
- // Check if the entry that has been requested actually exists
142
- if (parent::isDataSet($pCoord)) {
143
- $obj = apc_fetch($this->_cachePrefix.$pCoord.'.cache');
144
- if ($obj === FALSE) {
145
- // Entry no longer exists in APC, so clear it from the cache array
146
- parent::deleteCacheData($pCoord);
147
- throw new PHPExcel_Exception('Cell entry '.$pCoord.' no longer exists in APC cache');
148
- }
149
- } else {
150
- // Return null if requested entry doesn't exist in cache
151
- return null;
152
- }
153
-
154
- // Set current entry to the requested entry
155
- $this->_currentObjectID = $pCoord;
156
- $this->_currentObject = unserialize($obj);
157
- // Re-attach this as the cell's parent
158
- $this->_currentObject->attach($this);
159
-
160
- // Return requested entry
161
- return $this->_currentObject;
162
- } // function getCacheData()
163
-
164
-
165
- /**
166
- * Get a list of all cell addresses currently held in cache
167
- *
168
- * @return array of string
169
- */
170
- public function getCellList() {
171
- if ($this->_currentObjectID !== null) {
172
- $this->_storeData();
173
- }
174
-
175
- return parent::getCellList();
176
- }
177
-
178
-
179
- /**
180
- * Delete a cell in cache identified by coordinate address
181
- *
182
- * @access public
183
- * @param string $pCoord Coordinate address of the cell to delete
184
- * @throws PHPExcel_Exception
185
- */
186
- public function deleteCacheData($pCoord) {
187
- // Delete the entry from APC
188
- apc_delete($this->_cachePrefix.$pCoord.'.cache');
189
-
190
- // Delete the entry from our cell address array
191
- parent::deleteCacheData($pCoord);
192
- } // function deleteCacheData()
193
-
194
-
195
- /**
196
- * Clone the cell collection
197
- *
198
- * @access public
199
- * @param PHPExcel_Worksheet $parent The new worksheet
200
- * @throws PHPExcel_Exception
201
- * @return void
202
- */
203
- public function copyCellCollection(PHPExcel_Worksheet $parent) {
204
- parent::copyCellCollection($parent);
205
- // Get a new id for the new file name
206
- $baseUnique = $this->_getUniqueID();
207
- $newCachePrefix = substr(md5($baseUnique),0,8).'.';
208
- $cacheList = $this->getCellList();
209
- foreach($cacheList as $cellID) {
210
- if ($cellID != $this->_currentObjectID) {
211
- $obj = apc_fetch($this->_cachePrefix.$cellID.'.cache');
212
- if ($obj === FALSE) {
213
- // Entry no longer exists in APC, so clear it from the cache array
214
- parent::deleteCacheData($cellID);
215
- throw new PHPExcel_Exception('Cell entry '.$cellID.' no longer exists in APC');
216
- }
217
- if (!apc_store($newCachePrefix.$cellID.'.cache',$obj,$this->_cacheTime)) {
218
- $this->__destruct();
219
- throw new PHPExcel_Exception('Failed to store cell '.$cellID.' in APC');
220
- }
221
- }
222
- }
223
- $this->_cachePrefix = $newCachePrefix;
224
- } // function copyCellCollection()
225
-
226
-
227
- /**
228
- * Clear the cell collection and disconnect from our parent
229
- *
230
- * @return void
231
- */
232
- public function unsetWorksheetCells() {
233
- if ($this->_currentObject !== NULL) {
234
- $this->_currentObject->detach();
235
- $this->_currentObject = $this->_currentObjectID = null;
236
- }
237
-
238
- // Flush the APC cache
239
- $this->__destruct();
240
-
241
- $this->_cellCache = array();
242
-
243
- // detach ourself from the worksheet, so that it can then delete this object successfully
244
- $this->_parent = null;
245
- } // function unsetWorksheetCells()
246
-
247
-
248
- /**
249
- * Initialise this new cell collection
250
- *
251
- * @param PHPExcel_Worksheet $parent The worksheet for this cell collection
252
- * @param array of mixed $arguments Additional initialisation arguments
253
- */
254
- public function __construct(PHPExcel_Worksheet $parent, $arguments) {
255
- $cacheTime = (isset($arguments['cacheTime'])) ? $arguments['cacheTime'] : 600;
256
-
257
- if ($this->_cachePrefix === NULL) {
258
- $baseUnique = $this->_getUniqueID();
259
- $this->_cachePrefix = substr(md5($baseUnique),0,8).'.';
260
- $this->_cacheTime = $cacheTime;
261
-
262
- parent::__construct($parent);
263
- }
264
- } // function __construct()
265
-
266
-
267
- /**
268
- * Destroy this cell collection
269
- */
270
- public function __destruct() {
271
- $cacheList = $this->getCellList();
272
- foreach($cacheList as $cellID) {
273
- apc_delete($this->_cachePrefix.$cellID.'.cache');
274
- }
275
- } // function __destruct()
276
-
277
-
278
- /**
279
- * Identify whether the caching method is currently available
280
- * Some methods are dependent on the availability of certain extensions being enabled in the PHP build
281
- *
282
- * @return boolean
283
- */
284
- public static function cacheMethodIsAvailable() {
285
- if (!function_exists('apc_store')) {
286
- return FALSE;
287
- }
288
- if (apc_sma_info() === FALSE) {
289
- return FALSE;
290
- }
291
-
292
- return TRUE;
293
- }
294
-
295
- }
1
+ <?php
2
+
3
+ /**
4
+ * PHPExcel_CachedObjectStorage_APC
5
+ *
6
+ * Copyright (c) 2006 - 2015 PHPExcel
7
+ *
8
+ * This library is free software; you can redistribute it and/or
9
+ * modify it under the terms of the GNU Lesser General Public
10
+ * License as published by the Free Software Foundation; either
11
+ * version 2.1 of the License, or (at your option) any later version.
12
+ *
13
+ * This library is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
+ * Lesser General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU Lesser General Public
19
+ * License along with this library; if not, write to the Free Software
20
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
+ *
22
+ * @category PHPExcel
23
+ * @package PHPExcel_CachedObjectStorage
24
+ * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
25
+ * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
26
+ * @version ##VERSION##, ##DATE##
27
+ */
28
+ class PHPExcel_CachedObjectStorage_APC extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache
29
+ {
30
+ /**
31
+ * Prefix used to uniquely identify cache data for this worksheet
32
+ *
33
+ * @access private
34
+ * @var string
35
+ */
36
+ private $cachePrefix = null;
37
+
38
+ /**
39
+ * Cache timeout
40
+ *
41
+ * @access private
42
+ * @var integer
43
+ */
44
+ private $cacheTime = 600;
45
+
46
+ /**
47
+ * Store cell data in cache for the current cell object if it's "dirty",
48
+ * and the 'nullify' the current cell object
49
+ *
50
+ * @access private
51
+ * @return void
52
+ * @throws PHPExcel_Exception
53
+ */
54
+ protected function storeData()
55
+ {
56
+ if ($this->currentCellIsDirty && !empty($this->currentObjectID)) {
57
+ $this->currentObject->detach();
58
+
59
+ if (!apc_store(
60
+ $this->cachePrefix . $this->currentObjectID . '.cache',
61
+ serialize($this->currentObject),
62
+ $this->cacheTime
63
+ )) {
64
+ $this->__destruct();
65
+ throw new PHPExcel_Exception('Failed to store cell ' . $this->currentObjectID . ' in APC');
66
+ }
67
+ $this->currentCellIsDirty = false;
68
+ }
69
+ $this->currentObjectID = $this->currentObject = null;
70
+ }
71
+
72
+ /**
73
+ * Add or Update a cell in cache identified by coordinate address
74
+ *
75
+ * @access public
76
+ * @param string $pCoord Coordinate address of the cell to update
77
+ * @param PHPExcel_Cell $cell Cell to update
78
+ * @return PHPExcel_Cell
79
+ * @throws PHPExcel_Exception
80
+ */
81
+ public function addCacheData($pCoord, PHPExcel_Cell $cell)
82
+ {
83
+ if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) {
84
+ $this->storeData();
85
+ }
86
+ $this->cellCache[$pCoord] = true;
87
+
88
+ $this->currentObjectID = $pCoord;
89
+ $this->currentObject = $cell;
90
+ $this->currentCellIsDirty = true;
91
+
92
+ return $cell;
93
+ }
94
+
95
+ /**
96
+ * Is a value set in the current PHPExcel_CachedObjectStorage_ICache for an indexed cell?
97
+ *
98
+ * @access public
99
+ * @param string $pCoord Coordinate address of the cell to check
100
+ * @throws PHPExcel_Exception
101
+ * @return boolean
102
+ */
103
+ public function isDataSet($pCoord)
104
+ {
105
+ // Check if the requested entry is the current object, or exists in the cache
106
+ if (parent::isDataSet($pCoord)) {
107
+ if ($this->currentObjectID == $pCoord) {
108
+ return true;
109
+ }
110
+ // Check if the requested entry still exists in apc
111
+ $success = apc_fetch($this->cachePrefix.$pCoord.'.cache');
112
+ if ($success === false) {
113
+ // Entry no longer exists in APC, so clear it from the cache array
114
+ parent::deleteCacheData($pCoord);
115
+ throw new PHPExcel_Exception('Cell entry '.$pCoord.' no longer exists in APC cache');
116
+ }
117
+ return true;
118
+ }
119
+ return false;
120
+ }
121
+
122
+ /**
123
+ * Get cell at a specific coordinate
124
+ *
125
+ * @access public
126
+ * @param string $pCoord Coordinate of the cell
127
+ * @throws PHPExcel_Exception
128
+ * @return PHPExcel_Cell Cell that was found, or null if not found
129
+ */
130
+ public function getCacheData($pCoord)
131
+ {
132
+ if ($pCoord === $this->currentObjectID) {
133
+ return $this->currentObject;
134
+ }
135
+ $this->storeData();
136
+
137
+ // Check if the entry that has been requested actually exists
138
+ if (parent::isDataSet($pCoord)) {
139
+ $obj = apc_fetch($this->cachePrefix . $pCoord . '.cache');
140
+ if ($obj === false) {
141
+ // Entry no longer exists in APC, so clear it from the cache array
142
+ parent::deleteCacheData($pCoord);
143
+ throw new PHPExcel_Exception('Cell entry '.$pCoord.' no longer exists in APC cache');
144
+ }
145
+ } else {
146
+ // Return null if requested entry doesn't exist in cache
147
+ return null;
148
+ }
149
+
150
+ // Set current entry to the requested entry
151
+ $this->currentObjectID = $pCoord;
152
+ $this->currentObject = unserialize($obj);
153
+ // Re-attach this as the cell's parent
154
+ $this->currentObject->attach($this);
155
+
156
+ // Return requested entry
157
+ return $this->currentObject;
158
+ }
159
+
160
+ /**
161
+ * Get a list of all cell addresses currently held in cache
162
+ *
163
+ * @return string[]
164
+ */
165
+ public function getCellList()
166
+ {
167
+ if ($this->currentObjectID !== null) {
168
+ $this->storeData();
169
+ }
170
+
171
+ return parent::getCellList();
172
+ }
173
+
174
+ /**
175
+ * Delete a cell in cache identified by coordinate address
176
+ *
177
+ * @access public
178
+ * @param string $pCoord Coordinate address of the cell to delete
179
+ * @throws PHPExcel_Exception
180
+ */
181
+ public function deleteCacheData($pCoord)
182
+ {
183
+ // Delete the entry from APC
184
+ apc_delete($this->cachePrefix.$pCoord.'.cache');
185
+
186
+ // Delete the entry from our cell address array
187
+ parent::deleteCacheData($pCoord);
188
+ }
189
+
190
+ /**
191
+ * Clone the cell collection
192
+ *
193
+ * @access public
194
+ * @param PHPExcel_Worksheet $parent The new worksheet
195
+ * @throws PHPExcel_Exception
196
+ * @return void
197
+ */
198
+ public function copyCellCollection(PHPExcel_Worksheet $parent)
199
+ {
200
+ parent::copyCellCollection($parent);
201
+ // Get a new id for the new file name
202
+ $baseUnique = $this->getUniqueID();
203
+ $newCachePrefix = substr(md5($baseUnique), 0, 8) . '.';
204
+ $cacheList = $this->getCellList();
205
+ foreach ($cacheList as $cellID) {
206
+ if ($cellID != $this->currentObjectID) {
207
+ $obj = apc_fetch($this->cachePrefix . $cellID . '.cache');
208
+ if ($obj === false) {
209
+ // Entry no longer exists in APC, so clear it from the cache array
210
+ parent::deleteCacheData($cellID);
211
+ throw new PHPExcel_Exception('Cell entry ' . $cellID . ' no longer exists in APC');
212
+ }
213
+ if (!apc_store($newCachePrefix . $cellID . '.cache', $obj, $this->cacheTime)) {
214
+ $this->__destruct();
215
+ throw new PHPExcel_Exception('Failed to store cell ' . $cellID . ' in APC');
216
+ }
217
+ }
218
+ }
219
+ $this->cachePrefix = $newCachePrefix;
220
+ }
221
+
222
+ /**
223
+ * Clear the cell collection and disconnect from our parent
224
+ *
225
+ * @return void
226
+ */
227
+ public function unsetWorksheetCells()
228
+ {
229
+ if ($this->currentObject !== null) {
230
+ $this->currentObject->detach();
231
+ $this->currentObject = $this->currentObjectID = null;
232
+ }
233
+
234
+ // Flush the APC cache
235
+ $this->__destruct();
236
+
237
+ $this->cellCache = array();
238
+
239
+ // detach ourself from the worksheet, so that it can then delete this object successfully
240
+ $this->parent = null;
241
+ }
242
+
243
+ /**
244
+ * Initialise this new cell collection
245
+ *
246
+ * @param PHPExcel_Worksheet $parent The worksheet for this cell collection
247
+ * @param array of mixed $arguments Additional initialisation arguments
248
+ */
249
+ public function __construct(PHPExcel_Worksheet $parent, $arguments)
250
+ {
251
+ $cacheTime = (isset($arguments['cacheTime'])) ? $arguments['cacheTime'] : 600;
252
+
253
+ if ($this->cachePrefix === null) {
254
+ $baseUnique = $this->getUniqueID();
255
+ $this->cachePrefix = substr(md5($baseUnique), 0, 8) . '.';
256
+ $this->cacheTime = $cacheTime;
257
+
258
+ parent::__construct($parent);
259
+ }
260
+ }
261
+
262
+ /**
263
+ * Destroy this cell collection
264
+ */
265
+ public function __destruct()
266
+ {
267
+ $cacheList = $this->getCellList();
268
+ foreach ($cacheList as $cellID) {
269
+ apc_delete($this->cachePrefix . $cellID . '.cache');
270
+ }
271
+ }
272
+
273
+ /**
274
+ * Identify whether the caching method is currently available
275
+ * Some methods are dependent on the availability of certain extensions being enabled in the PHP build
276
+ *
277
+ * @return boolean
278
+ */
279
+ public static function cacheMethodIsAvailable()
280
+ {
281
+ if (!function_exists('apc_store')) {
282
+ return false;
283
+ }
284
+ if (apc_sma_info() === false) {
285
+ return false;
286
+ }
287
+
288
+ return true;
289
+ }
290
+ }
 
 
 
 
 
PHPExcel/Classes/PHPExcel/CachedObjectStorage/CacheBase.php CHANGED
@@ -1,347 +1,368 @@
1
- <?php
2
- /**
3
- * PHPExcel
4
- *
5
- * Copyright (c) 2006 - 2014 PHPExcel
6
- *
7
- * This library is free software; you can redistribute it and/or
8
- * modify it under the terms of the GNU Lesser General Public
9
- * License as published by the Free Software Foundation; either
10
- * version 2.1 of the License, or (at your option) any later version.
11
- *
12
- * This library is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
- * Lesser General Public License for more details.
16
- *
17
- * You should have received a copy of the GNU Lesser General Public
18
- * License along with this library; if not, write to the Free Software
19
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
- *
21
- * @category PHPExcel
22
- * @package PHPExcel_CachedObjectStorage
23
- * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
24
- * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25
- * @version 1.8.0, 2014-03-02
26
- */
27
-
28
-
29
- /**
30
- * PHPExcel_CachedObjectStorage_CacheBase
31
- *
32
- * @category PHPExcel
33
- * @package PHPExcel_CachedObjectStorage
34
- * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
35
- */
36
- abstract class PHPExcel_CachedObjectStorage_CacheBase {
37
-
38
- /**
39
- * Parent worksheet
40
- *
41
- * @var PHPExcel_Worksheet
42
- */
43
- protected $_parent;
44
-
45
- /**
46
- * The currently active Cell
47
- *
48
- * @var PHPExcel_Cell
49
- */
50
- protected $_currentObject = null;
51
-
52
- /**
53
- * Coordinate address of the currently active Cell
54
- *
55
- * @var string
56
- */
57
- protected $_currentObjectID = null;
58
-
59
-
60
- /**
61
- * Flag indicating whether the currently active Cell requires saving
62
- *
63
- * @var boolean
64
- */
65
- protected $_currentCellIsDirty = true;
66
-
67
- /**
68
- * An array of cells or cell pointers for the worksheet cells held in this cache,
69
- * and indexed by their coordinate address within the worksheet
70
- *
71
- * @var array of mixed
72
- */
73
- protected $_cellCache = array();
74
-
75
-
76
- /**
77
- * Initialise this new cell collection
78
- *
79
- * @param PHPExcel_Worksheet $parent The worksheet for this cell collection
80
- */
81
- public function __construct(PHPExcel_Worksheet $parent) {
82
- // Set our parent worksheet.
83
- // This is maintained within the cache controller to facilitate re-attaching it to PHPExcel_Cell objects when
84
- // they are woken from a serialized state
85
- $this->_parent = $parent;
86
- } // function __construct()
87
-
88
-
89
- /**
90
- * Return the parent worksheet for this cell collection
91
- *
92
- * @return PHPExcel_Worksheet
93
- */
94
- public function getParent()
95
- {
96
- return $this->_parent;
97
- }
98
-
99
- /**
100
- * Is a value set in the current PHPExcel_CachedObjectStorage_ICache for an indexed cell?
101
- *
102
- * @param string $pCoord Coordinate address of the cell to check
103
- * @return boolean
104
- */
105
- public function isDataSet($pCoord) {
106
- if ($pCoord === $this->_currentObjectID) {
107
- return true;
108
- }
109
- // Check if the requested entry exists in the cache
110
- return isset($this->_cellCache[$pCoord]);
111
- } // function isDataSet()
112
-
113
-
114
- /**
115
- * Move a cell object from one address to another
116
- *
117
- * @param string $fromAddress Current address of the cell to move
118
- * @param string $toAddress Destination address of the cell to move
119
- * @return boolean
120
- */
121
- public function moveCell($fromAddress, $toAddress) {
122
- if ($fromAddress === $this->_currentObjectID) {
123
- $this->_currentObjectID = $toAddress;
124
- }
125
- $this->_currentCellIsDirty = true;
126
- if (isset($this->_cellCache[$fromAddress])) {
127
- $this->_cellCache[$toAddress] = &$this->_cellCache[$fromAddress];
128
- unset($this->_cellCache[$fromAddress]);
129
- }
130
-
131
- return TRUE;
132
- } // function moveCell()
133
-
134
-
135
- /**
136
- * Add or Update a cell in cache
137
- *
138
- * @param PHPExcel_Cell $cell Cell to update
139
- * @return void
140
- * @throws PHPExcel_Exception
141
- */
142
- public function updateCacheData(PHPExcel_Cell $cell) {
143
- return $this->addCacheData($cell->getCoordinate(),$cell);
144
- } // function updateCacheData()
145
-
146
-
147
- /**
148
- * Delete a cell in cache identified by coordinate address
149
- *
150
- * @param string $pCoord Coordinate address of the cell to delete
151
- * @throws PHPExcel_Exception
152
- */
153
- public function deleteCacheData($pCoord) {
154
- if ($pCoord === $this->_currentObjectID) {
155
- $this->_currentObject->detach();
156
- $this->_currentObjectID = $this->_currentObject = null;
157
- }
158
-
159
- if (is_object($this->_cellCache[$pCoord])) {
160
- $this->_cellCache[$pCoord]->detach();
161
- unset($this->_cellCache[$pCoord]);
162
- }
163
- $this->_currentCellIsDirty = false;
164
- } // function deleteCacheData()
165
-
166
-
167
- /**
168
- * Get a list of all cell addresses currently held in cache
169
- *
170
- * @return array of string
171
- */
172
- public function getCellList() {
173
- return array_keys($this->_cellCache);
174
- } // function getCellList()
175
-
176
-
177
- /**
178
- * Sort the list of all cell addresses currently held in cache by row and column
179
- *
180
- * @return void
181
- */
182
- public function getSortedCellList() {
183
- $sortKeys = array();
184
- foreach ($this->getCellList() as $coord) {
185
- sscanf($coord,'%[A-Z]%d', $column, $row);
186
- $sortKeys[sprintf('%09d%3s',$row,$column)] = $coord;
187
- }
188
- ksort($sortKeys);
189
-
190
- return array_values($sortKeys);
191
- } // function sortCellList()
192
-
193
-
194
-
195
- /**
196
- * Get highest worksheet column and highest row that have cell records
197
- *
198
- * @return array Highest column name and highest row number
199
- */
200
- public function getHighestRowAndColumn()
201
- {
202
- // Lookup highest column and highest row
203
- $col = array('A' => '1A');
204
- $row = array(1);
205
- foreach ($this->getCellList() as $coord) {
206
- sscanf($coord,'%[A-Z]%d', $c, $r);
207
- $row[$r] = $r;
208
- $col[$c] = strlen($c).$c;
209
- }
210
- if (!empty($row)) {
211
- // Determine highest column and row
212
- $highestRow = max($row);
213
- $highestColumn = substr(max($col),1);
214
- }
215
-
216
- return array( 'row' => $highestRow,
217
- 'column' => $highestColumn
218
- );
219
- }
220
-
221
-
222
- /**
223
- * Return the cell address of the currently active cell object
224
- *
225
- * @return string
226
- */
227
- public function getCurrentAddress()
228
- {
229
- return $this->_currentObjectID;
230
- }
231
-
232
- /**
233
- * Return the column address of the currently active cell object
234
- *
235
- * @return string
236
- */
237
- public function getCurrentColumn()
238
- {
239
- sscanf($this->_currentObjectID, '%[A-Z]%d', $column, $row);
240
- return $column;
241
- }
242
-
243
- /**
244
- * Return the row address of the currently active cell object
245
- *
246
- * @return string
247
- */
248
- public function getCurrentRow()
249
- {
250
- sscanf($this->_currentObjectID, '%[A-Z]%d', $column, $row);
251
- return $row;
252
- }
253
-
254
- /**
255
- * Get highest worksheet column
256
- *
257
- * @param string $row Return the highest column for the specified row,
258
- * or the highest column of any row if no row number is passed
259
- * @return string Highest column name
260
- */
261
- public function getHighestColumn($row = null)
262
- {
263
- if ($row == null) {
264
- $colRow = $this->getHighestRowAndColumn();
265
- return $colRow['column'];
266
- }
267
-
268
- $columnList = array(1);
269
- foreach ($this->getCellList() as $coord) {
270
- sscanf($coord,'%[A-Z]%d', $c, $r);
271
- if ($r != $row) {
272
- continue;
273
- }
274
- $columnList[] = PHPExcel_Cell::columnIndexFromString($c);
275
- }
276
- return PHPExcel_Cell::stringFromColumnIndex(max($columnList) - 1);
277
- }
278
-
279
- /**
280
- * Get highest worksheet row
281
- *
282
- * @param string $column Return the highest row for the specified column,
283
- * or the highest row of any column if no column letter is passed
284
- * @return int Highest row number
285
- */
286
- public function getHighestRow($column = null)
287
- {
288
- if ($column == null) {
289
- $colRow = $this->getHighestRowAndColumn();
290
- return $colRow['row'];
291
- }
292
-
293
- $rowList = array(0);
294
- foreach ($this->getCellList() as $coord) {
295
- sscanf($coord,'%[A-Z]%d', $c, $r);
296
- if ($c != $column) {
297
- continue;
298
- }
299
- $rowList[] = $r;
300
- }
301
-
302
- return max($rowList);
303
- }
304
-
305
-
306
- /**
307
- * Generate a unique ID for cache referencing
308
- *
309
- * @return string Unique Reference
310
- */
311
- protected function _getUniqueID() {
312
- if (function_exists('posix_getpid')) {
313
- $baseUnique = posix_getpid();
314
- } else {
315
- $baseUnique = mt_rand();
316
- }
317
- return uniqid($baseUnique,true);
318
- }
319
-
320
- /**
321
- * Clone the cell collection
322
- *
323
- * @param PHPExcel_Worksheet $parent The new worksheet
324
- * @return void
325
- */
326
- public function copyCellCollection(PHPExcel_Worksheet $parent) {
327
- $this->_currentCellIsDirty;
328
- $this->_storeData();
329
-
330
- $this->_parent = $parent;
331
- if (($this->_currentObject !== NULL) && (is_object($this->_currentObject))) {
332
- $this->_currentObject->attach($this);
333
- }
334
- } // function copyCellCollection()
335
-
336
-
337
- /**
338
- * Identify whether the caching method is currently available
339
- * Some methods are dependent on the availability of certain extensions being enabled in the PHP build
340
- *
341
- * @return boolean
342
- */
343
- public static function cacheMethodIsAvailable() {
344
- return true;
345
- }
346
-
347
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * PHPExcel_CachedObjectStorage_CacheBase
5
+ *
6
+ * Copyright (c) 2006 - 2015 PHPExcel
7
+ *
8
+ * This library is free software; you can redistribute it and/or
9
+ * modify it under the terms of the GNU Lesser General Public
10
+ * License as published by the Free Software Foundation; either
11
+ * version 2.1 of the License, or (at your option) any later version.
12
+ *
13
+ * This library is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
+ * Lesser General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU Lesser General Public
19
+ * License along with this library; if not, write to the Free Software
20
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
+ *
22
+ * @category PHPExcel
23
+ * @package PHPExcel_CachedObjectStorage
24
+ * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
25
+ * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
26
+ * @version ##VERSION##, ##DATE##
27
+ */
28
+ abstract class PHPExcel_CachedObjectStorage_CacheBase
29
+ {
30
+ /**
31
+ * Parent worksheet
32
+ *
33
+ * @var PHPExcel_Worksheet
34
+ */
35
+ protected $parent;
36
+
37
+ /**
38
+ * The currently active Cell
39
+ *
40
+ * @var PHPExcel_Cell
41
+ */
42
+ protected $currentObject = null;
43
+
44
+ /**
45
+ * Coordinate address of the currently active Cell
46
+ *
47
+ * @var string
48
+ */
49
+ protected $currentObjectID = null;
50
+
51
+ /**
52
+ * Flag indicating whether the currently active Cell requires saving
53
+ *
54
+ * @var boolean
55
+ */
56
+ protected $currentCellIsDirty = true;
57
+
58
+ /**
59
+ * An array of cells or cell pointers for the worksheet cells held in this cache,
60
+ * and indexed by their coordinate address within the worksheet
61
+ *
62
+ * @var array of mixed
63
+ */
64
+ protected $cellCache = array();
65
+
66
+ /**
67
+ * Initialise this new cell collection
68
+ *
69
+ * @param PHPExcel_Worksheet $parent The worksheet for this cell collection
70
+ */
71
+ public function __construct(PHPExcel_Worksheet $parent)
72
+ {
73
+ // Set our parent worksheet.
74
+ // This is maintained within the cache controller to facilitate re-attaching it to PHPExcel_Cell objects when
75
+ // they are woken from a serialized state
76
+ $this->parent = $parent;
77
+ }
78
+
79
+ /**
80
+ * Return the parent worksheet for this cell collection
81
+ *
82
+ * @return PHPExcel_Worksheet
83
+ */
84
+ public function getParent()
85
+ {
86
+ return $this->parent;
87
+ }
88
+
89
+ /**
90
+ * Is a value set in the current PHPExcel_CachedObjectStorage_ICache for an indexed cell?
91
+ *
92
+ * @param string $pCoord Coordinate address of the cell to check
93
+ * @return boolean
94
+ */
95
+ public function isDataSet($pCoord)
96
+ {
97
+ if ($pCoord === $this->currentObjectID) {
98
+ return true;
99
+ }
100
+ // Check if the requested entry exists in the cache
101
+ return isset($this->cellCache[$pCoord]);
102
+ }
103
+
104
+ /**
105
+ * Move a cell object from one address to another
106
+ *
107
+ * @param string $fromAddress Current address of the cell to move
108
+ * @param string $toAddress Destination address of the cell to move
109
+ * @return boolean
110
+ */
111
+ public function moveCell($fromAddress, $toAddress)
112
+ {
113
+ if ($fromAddress === $this->currentObjectID) {
114
+ $this->currentObjectID = $toAddress;
115
+ }
116
+ $this->currentCellIsDirty = true;
117
+ if (isset($this->cellCache[$fromAddress])) {
118
+ $this->cellCache[$toAddress] = &$this->cellCache[$fromAddress];
119
+ unset($this->cellCache[$fromAddress]);
120
+ }
121
+
122
+ return true;
123
+ }
124
+
125
+ /**
126
+ * Add or Update a cell in cache
127
+ *
128
+ * @param PHPExcel_Cell $cell Cell to update
129
+ * @return PHPExcel_Cell
130
+ * @throws PHPExcel_Exception
131
+ */
132
+ public function updateCacheData(PHPExcel_Cell $cell)
133
+ {
134
+ return $this->addCacheData($cell->getCoordinate(), $cell);
135
+ }
136
+
137
+ /**
138
+ * Delete a cell in cache identified by coordinate address
139
+ *
140
+ * @param string $pCoord Coordinate address of the cell to delete
141
+ * @throws PHPExcel_Exception
142
+ */
143
+ public function deleteCacheData($pCoord)
144
+ {
145
+ if ($pCoord === $this->currentObjectID && !is_null($this->currentObject)) {
146
+ $this->currentObject->detach();
147
+ $this->currentObjectID = $this->currentObject = null;
148
+ }
149
+
150
+ if (is_object($this->cellCache[$pCoord])) {
151
+ $this->cellCache[$pCoord]->detach();
152
+ unset($this->cellCache[$pCoord]);
153
+ }
154
+ $this->currentCellIsDirty = false;
155
+ }
156
+
157
+ /**
158
+ * Get a list of all cell addresses currently held in cache
159
+ *
160
+ * @return string[]
161
+ */
162
+ public function getCellList()
163
+ {
164
+ return array_keys($this->cellCache);
165
+ }
166
+
167
+ /**
168
+ * Sort the list of all cell addresses currently held in cache by row and column
169
+ *
170
+ * @return string[]
171
+ */
172
+ public function getSortedCellList()
173
+ {
174
+ $sortKeys = array();
175
+ foreach ($this->getCellList() as $coord) {
176
+ sscanf($coord, '%[A-Z]%d', $column, $row);
177
+ $sortKeys[sprintf('%09d%3s', $row, $column)] = $coord;
178
+ }
179
+ ksort($sortKeys);
180
+
181
+ return array_values($sortKeys);
182
+ }
183
+
184
+ /**
185
+ * Get highest worksheet column and highest row that have cell records
186
+ *
187
+ * @return array Highest column name and highest row number
188
+ */
189
+ public function getHighestRowAndColumn()
190
+ {
191
+ // Lookup highest column and highest row
192
+ $col = array('A' => '1A');
193
+ $row = array(1);
194
+ foreach ($this->getCellList() as $coord) {
195
+ sscanf($coord, '%[A-Z]%d', $c, $r);
196
+ $row[$r] = $r;
197
+ $col[$c] = strlen($c).$c;
198
+ }
199
+ if (!empty($row)) {
200
+ // Determine highest column and row
201
+ $highestRow = max($row);
202
+ $highestColumn = substr(max($col), 1);
203
+ }
204
+
205
+ return array(
206
+ 'row' => $highestRow,
207
+ 'column' => $highestColumn
208
+ );
209
+ }
210
+
211
+ /**
212
+ * Return the cell address of the currently active cell object
213
+ *
214
+ * @return string
215
+ */
216
+ public function getCurrentAddress()
217
+ {
218
+ return $this->currentObjectID;
219
+ }
220
+
221
+ /**
222
+ * Return the column address of the currently active cell object
223
+ *
224
+ * @return string
225
+ */
226
+ public function getCurrentColumn()
227
+ {
228
+ sscanf($this->currentObjectID, '%[A-Z]%d', $column, $row);
229
+ return $column;
230
+ }
231
+
232
+ /**
233
+ * Return the row address of the currently active cell object
234
+ *
235
+ * @return integer
236
+ */
237
+ public function getCurrentRow()
238
+ {
239
+ sscanf($this->currentObjectID, '%[A-Z]%d', $column, $row);
240
+ return (integer) $row;
241
+ }
242
+
243
+ /**
244
+ * Get highest worksheet column
245
+ *
246
+ * @param string $row Return the highest column for the specified row,
247
+ * or the highest column of any row if no row number is passed
248
+ * @return string Highest column name
249
+ */
250
+ public function getHighestColumn($row = null)
251
+ {
252
+ if ($row == null) {
253
+ $colRow = $this->getHighestRowAndColumn();
254
+ return $colRow['column'];
255
+ }
256
+
257
+ $columnList = array(1);
258
+ foreach ($this->getCellList() as $coord) {
259
+ sscanf($coord, '%[A-Z]%d', $c, $r);
260
+ if ($r != $row) {
261
+ continue;
262
+ }
263
+ $columnList[] = PHPExcel_Cell::columnIndexFromString($c);
264
+ }
265
+ return PHPExcel_Cell::stringFromColumnIndex(max($columnList) - 1);
266
+ }
267
+
268
+ /**
269
+ * Get highest worksheet row
270
+ *
271
+ * @param string $column Return the highest row for the specified column,
272
+ * or the highest row of any column if no column letter is passed
273
+ * @return int Highest row number
274
+ */
275
+ public function getHighestRow($column = null)
276
+ {
277
+ if ($column == null) {
278
+ $colRow = $this->getHighestRowAndColumn();
279
+ return $colRow['row'];
280
+ }
281
+
282
+ $rowList = array(0);
283
+ foreach ($this->getCellList() as $coord) {
284
+ sscanf($coord, '%[A-Z]%d', $c, $r);
285
+ if ($c != $column) {
286
+ continue;
287
+ }
288
+ $rowList[] = $r;
289
+ }
290
+
291
+ return max($rowList);
292
+ }
293
+
294
+ /**
295
+ * Generate a unique ID for cache referencing
296
+ *
297
+ * @return string Unique Reference
298
+ */
299
+ protected function getUniqueID()
300
+ {
301
+ if (function_exists('posix_getpid')) {
302
+ $baseUnique = posix_getpid();
303
+ } else {
304
+ $baseUnique = mt_rand();
305
+ }
306
+ return uniqid($baseUnique, true);
307
+ }
308
+
309
+ /**
310
+ * Clone the cell collection
311
+ *
312
+ * @param PHPExcel_Worksheet $parent The new worksheet
313
+ * @return void
314
+ */
315
+ public function copyCellCollection(PHPExcel_Worksheet $parent)
316
+ {
317
+ $this->currentCellIsDirty;
318
+ $this->storeData();
319
+
320
+ $this->parent = $parent;
321
+ if (($this->currentObject !== null) && (is_object($this->currentObject))) {
322
+ $this->currentObject->attach($this);
323
+ }
324
+ } // function copyCellCollection()
325
+
326
+ /**
327
+ * Remove a row, deleting all cells in that row
328
+ *
329
+ * @param string $row Row number to remove
330
+ * @return void
331
+ */
332
+ public function removeRow($row)
333
+ {
334
+ foreach ($this->getCellList() as $coord) {
335
+ sscanf($coord, '%[A-Z]%d', $c, $r);
336
+ if ($r == $row) {
337
+ $this->deleteCacheData($coord);
338
+ }
339
+ }
340
+ }
341
+
342
+ /**
343
+ * Remove a column, deleting all cells in that column
344
+ *
345
+ * @param string $column Column ID to remove
346
+ * @return void
347
+ */
348
+ public function removeColumn($column)
349
+ {
350
+ foreach ($this->getCellList() as $coord) {
351
+ sscanf($coord, '%[A-Z]%d', $c, $r);
352
+ if ($c == $column) {
353
+ $this->deleteCacheData($coord);
354
+ }
355
+ }
356
+ }
357
+
358
+ /**
359
+ * Identify whether the caching method is currently available
360
+ * Some methods are dependent on the availability of certain extensions being enabled in the PHP build
361
+ *
362
+ * @return boolean
363
+ */
364
+ public static function cacheMethodIsAvailable()
365
+ {
366
+ return true;
367
+ }
368
+ }
PHPExcel/Classes/PHPExcel/CachedObjectStorage/DiscISAM.php CHANGED
@@ -1,219 +1,208 @@
1
- <?php
2
- /**
3
- * PHPExcel
4
- *
5
- * Copyright (c) 2006 - 2014 PHPExcel
6
- *
7
- * This library is free software; you can redistribute it and/or
8
- * modify it under the terms of the GNU Lesser General Public
9
- * License as published by the Free Software Foundation; either
10
- * version 2.1 of the License, or (at your option) any later version.
11
- *
12
- * This library is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
- * Lesser General Public License for more details.
16
- *
17
- * You should have received a copy of the GNU Lesser General Public
18
- * License along with this library; if not, write to the Free Software
19
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
- *
21
- * @category PHPExcel
22
- * @package PHPExcel_CachedObjectStorage
23
- * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
24
- * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25
- * @version 1.8.0, 2014-03-02
26
- */
27
-
28
-
29
- /**
30
- * PHPExcel_CachedObjectStorage_DiscISAM
31
- *
32
- * @category PHPExcel
33
- * @package PHPExcel_CachedObjectStorage
34
- * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
35
- */
36
- class PHPExcel_CachedObjectStorage_DiscISAM extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {
37
-
38
- /**
39
- * Name of the file for this cache
40
- *
41
- * @var string
42
- */
43
- private $_fileName = NULL;
44
-
45
- /**
46
- * File handle for this cache file
47
- *
48
- * @var resource
49
- */
50
- private $_fileHandle = NULL;
51
-
52
- /**
53
- * Directory/Folder where the cache file is located
54
- *
55
- * @var string
56
- */
57
- private $_cacheDirectory = NULL;
58
-
59
-
60
- /**
61
- * Store cell data in cache for the current cell object if it's "dirty",
62
- * and the 'nullify' the current cell object
63
- *
64
- * @return void
65
- * @throws PHPExcel_Exception
66
- */
67
- protected function _storeData() {
68
- if ($this->_currentCellIsDirty && !empty($this->_currentObjectID)) {
69
- $this->_currentObject->detach();
70
-
71
- fseek($this->_fileHandle,0,SEEK_END);
72
- $offset = ftell($this->_fileHandle);
73
- fwrite($this->_fileHandle, serialize($this->_currentObject));
74
- $this->_cellCache[$this->_currentObjectID] = array('ptr' => $offset,
75
- 'sz' => ftell($this->_fileHandle) - $offset
76
- );
77
- $this->_currentCellIsDirty = false;
78
- }
79
- $this->_currentObjectID = $this->_currentObject = null;
80
- } // function _storeData()
81
-
82
-
83
- /**
84
- * Add or Update a cell in cache identified by coordinate address
85
- *
86
- * @param string $pCoord Coordinate address of the cell to update
87
- * @param PHPExcel_Cell $cell Cell to update
88
- * @return void
89
- * @throws PHPExcel_Exception
90
- */
91
- public function addCacheData($pCoord, PHPExcel_Cell $cell) {
92
- if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) {
93
- $this->_storeData();
94
- }
95
-
96
- $this->_currentObjectID = $pCoord;
97
- $this->_currentObject = $cell;
98
- $this->_currentCellIsDirty = true;
99
-
100
- return $cell;
101
- } // function addCacheData()
102
-
103
-
104
- /**
105
- * Get cell at a specific coordinate
106
- *
107
- * @param string $pCoord Coordinate of the cell
108
- * @throws PHPExcel_Exception
109
- * @return PHPExcel_Cell Cell that was found, or null if not found
110
- */
111
- public function getCacheData($pCoord) {
112
- if ($pCoord === $this->_currentObjectID) {
113
- return $this->_currentObject;
114
- }
115
- $this->_storeData();
116
-
117
- // Check if the entry that has been requested actually exists
118
- if (!isset($this->_cellCache[$pCoord])) {
119
- // Return null if requested entry doesn't exist in cache
120
- return null;
121
- }
122
-
123
- // Set current entry to the requested entry
124
- $this->_currentObjectID = $pCoord;
125
- fseek($this->_fileHandle,$this->_cellCache[$pCoord]['ptr']);
126
- $this->_currentObject = unserialize(fread($this->_fileHandle,$this->_cellCache[$pCoord]['sz']));
127
- // Re-attach this as the cell's parent
128
- $this->_currentObject->attach($this);
129
-
130
- // Return requested entry
131
- return $this->_currentObject;
132
- } // function getCacheData()
133
-
134
-
135
- /**
136
- * Get a list of all cell addresses currently held in cache
137
- *
138
- * @return array of string
139
- */
140
- public function getCellList() {
141
- if ($this->_currentObjectID !== null) {
142
- $this->_storeData();
143
- }
144
-
145
- return parent::getCellList();
146
- }
147
-
148
-
149
- /**
150
- * Clone the cell collection
151
- *
152
- * @param PHPExcel_Worksheet $parent The new worksheet
153
- * @return void
154
- */
155
- public function copyCellCollection(PHPExcel_Worksheet $parent) {
156
- parent::copyCellCollection($parent);
157
- // Get a new id for the new file name
158
- $baseUnique = $this->_getUniqueID();
159
- $newFileName = $this->_cacheDirectory.'/PHPExcel.'.$baseUnique.'.cache';
160
- // Copy the existing cell cache file
161
- copy ($this->_fileName,$newFileName);
162
- $this->_fileName = $newFileName;
163
- // Open the copied cell cache file
164
- $this->_fileHandle = fopen($this->_fileName,'a+');
165
- } // function copyCellCollection()
166
-
167
-
168
- /**
169
- * Clear the cell collection and disconnect from our parent
170
- *
171
- * @return void
172
- */
173
- public function unsetWorksheetCells() {
174
- if(!is_null($this->_currentObject)) {
175
- $this->_currentObject->detach();
176
- $this->_currentObject = $this->_currentObjectID = null;
177
- }
178
- $this->_cellCache = array();
179
-
180
- // detach ourself from the worksheet, so that it can then delete this object successfully
181
- $this->_parent = null;
182
-
183
- // Close down the temporary cache file
184
- $this->__destruct();
185
- } // function unsetWorksheetCells()
186
-
187
-
188
- /**
189
- * Initialise this new cell collection
190
- *
191
- * @param PHPExcel_Worksheet $parent The worksheet for this cell collection
192
- * @param array of mixed $arguments Additional initialisation arguments
193
- */
194
- public function __construct(PHPExcel_Worksheet $parent, $arguments) {
195
- $this->_cacheDirectory = ((isset($arguments['dir'])) && ($arguments['dir'] !== NULL))
196
- ? $arguments['dir']
197
- : PHPExcel_Shared_File::sys_get_temp_dir();
198
-
199
- parent::__construct($parent);
200
- if (is_null($this->_fileHandle)) {
201
- $baseUnique = $this->_getUniqueID();
202
- $this->_fileName = $this->_cacheDirectory.'/PHPExcel.'.$baseUnique.'.cache';
203
- $this->_fileHandle = fopen($this->_fileName,'a+');
204
- }
205
- } // function __construct()
206
-
207
-
208
- /**
209
- * Destroy this cell collection
210
- */
211
- public function __destruct() {
212
- if (!is_null($this->_fileHandle)) {
213
- fclose($this->_fileHandle);
214
- unlink($this->_fileName);
215
- }
216
- $this->_fileHandle = null;
217
- } // function __destruct()
218
-
219
- }
1
+ <?php
2
+
3
+ /**
4
+ * PHPExcel_CachedObjectStorage_DiscISAM
5
+ *
6
+ * Copyright (c) 2006 - 2015 PHPExcel
7
+ *
8
+ * This library is free software; you can redistribute it and/or
9
+ * modify it under the terms of the GNU Lesser General Public
10
+ * License as published by the Free Software Foundation; either
11
+ * version 2.1 of the License, or (at your option) any later version.
12
+ *
13
+ * This library is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
+ * Lesser General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU Lesser General Public
19
+ * License along with this library; if not, write to the Free Software
20
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
+ *
22
+ * @category PHPExcel
23
+ * @package PHPExcel_CachedObjectStorage
24
+ * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
25
+ * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
26
+ * @version ##VERSION##, ##DATE##
27
+ */
28
+ class PHPExcel_CachedObjectStorage_DiscISAM extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache
29
+ {
30
+ /**
31
+ * Name of the file for this cache
32
+ *
33
+ * @var string
34
+ */
35
+ private $fileName = null;
36
+
37
+ /**
38
+ * File handle for this cache file
39
+ *
40
+ * @var resource
41
+ */
42
+ private $fileHandle = null;
43
+
44
+ /**
45
+ * Directory/Folder where the cache file is located
46
+ *
47
+ * @var string
48
+ */
49
+ private $cacheDirectory = null;
50
+
51
+ /**
52
+ * Store cell data in cache for the current cell object if it's "dirty",
53
+ * and the 'nullify' the current cell object
54
+ *
55
+ * @return void
56
+ * @throws PHPExcel_Exception
57
+ */
58
+ protected function storeData()
59
+ {
60
+ if ($this->currentCellIsDirty && !empty($this->currentObjectID)) {
61
+ $this->currentObject->detach();
62
+
63
+ fseek($this->fileHandle, 0, SEEK_END);
64
+
65
+ $this->cellCache[$this->currentObjectID] = array(
66
+ 'ptr' => ftell($this->fileHandle),
67
+ 'sz' => fwrite($this->fileHandle, serialize($this->currentObject))
68
+ );
69
+ $this->currentCellIsDirty = false;
70
+ }
71
+ $this->currentObjectID = $this->currentObject = null;
72
+ }
73
+
74
+ /**
75
+ * Add or Update a cell in cache identified by coordinate address
76
+ *
77
+ * @param string $pCoord Coordinate address of the cell to update
78
+ * @param PHPExcel_Cell $cell Cell to update
79
+ * @return PHPExcel_Cell
80
+ * @throws PHPExcel_Exception
81
+ */
82
+ public function addCacheData($pCoord, PHPExcel_Cell $cell)
83
+ {
84
+ if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) {
85
+ $this->storeData();
86
+ }
87
+
88
+ $this->currentObjectID = $pCoord;
89
+ $this->currentObject = $cell;
90
+ $this->currentCellIsDirty = true;
91
+
92
+ return $cell;
93
+ }
94
+
95
+ /**
96
+ * Get cell at a specific coordinate
97
+ *
98
+ * @param string $pCoord Coordinate of the cell
99
+ * @throws PHPExcel_Exception
100
+ * @return PHPExcel_Cell Cell that was found, or null if not found
101
+ */
102
+ public function getCacheData($pCoord)
103
+ {
104
+ if ($pCoord === $this->currentObjectID) {
105
+ return $this->currentObject;
106
+ }
107
+ $this->storeData();
108
+
109
+ // Check if the entry that has been requested actually exists
110
+ if (!isset($this->cellCache[$pCoord])) {
111
+ // Return null if requested entry doesn't exist in cache
112
+ return null;
113
+ }
114
+
115
+ // Set current entry to the requested entry
116
+ $this->currentObjectID = $pCoord;
117
+ fseek($this->fileHandle, $this->cellCache[$pCoord]['ptr']);
118
+ $this->currentObject = unserialize(fread($this->fileHandle, $this->cellCache[$pCoord]['sz']));
119
+ // Re-attach this as the cell's parent
120
+ $this->currentObject->attach($this);
121
+
122
+ // Return requested entry
123
+ return $this->currentObject;
124
+ }
125
+
126
+ /**
127
+ * Get a list of all cell addresses currently held in cache
128
+ *
129
+ * @return string[]
130
+ */
131
+ public function getCellList()
132
+ {
133
+ if ($this->currentObjectID !== null) {
134
+ $this->storeData();
135
+ }
136
+
137
+ return parent::getCellList();
138
+ }
139
+
140
+ /**
141
+ * Clone the cell collection
142
+ *
143
+ * @param PHPExcel_Worksheet $parent The new worksheet
144
+ */
145
+ public function copyCellCollection(PHPExcel_Worksheet $parent)
146
+ {
147
+ parent::copyCellCollection($parent);
148
+ // Get a new id for the new file name
149
+ $baseUnique = $this->getUniqueID();
150
+ $newFileName = $this->cacheDirectory.'/PHPExcel.'.$baseUnique.'.cache';
151
+ // Copy the existing cell cache file
152
+ copy($this->fileName, $newFileName);
153
+ $this->fileName = $newFileName;
154
+ // Open the copied cell cache file
155
+ $this->fileHandle = fopen($this->fileName, 'a+');
156
+ }
157
+
158
+ /**
159
+ * Clear the cell collection and disconnect from our parent
160
+ *
161
+ */
162
+ public function unsetWorksheetCells()
163
+ {
164
+ if (!is_null($this->currentObject)) {
165
+ $this->currentObject->detach();
166
+ $this->currentObject = $this->currentObjectID = null;
167
+ }
168
+ $this->cellCache = array();
169
+
170
+ // detach ourself from the worksheet, so that it can then delete this object successfully
171
+ $this->parent = null;
172
+
173
+ // Close down the temporary cache file
174
+ $this->__destruct();
175
+ }
176
+
177
+ /**
178
+ * Initialise this new cell collection
179
+ *
180
+ * @param PHPExcel_Worksheet $parent The worksheet for this cell collection
181
+ * @param array of mixed $arguments Additional initialisation arguments
182
+ */
183
+ public function __construct(PHPExcel_Worksheet $parent, $arguments)
184
+ {
185
+ $this->cacheDirectory = ((isset($arguments['dir'])) && ($arguments['dir'] !== null))
186
+ ? $arguments['dir']
187
+ : PHPExcel_Shared_File::sys_get_temp_dir();
188
+
189
+ parent::__construct($parent);
190
+ if (is_null($this->fileHandle)) {
191
+ $baseUnique = $this->getUniqueID();
192
+ $this->fileName = $this->cacheDirectory.'/PHPExcel.'.$baseUnique.'.cache';
193
+ $this->fileHandle = fopen($this->fileName, 'a+');
194
+ }
195
+ }
196
+
197
+ /**
198
+ * Destroy this cell collection
199
+ */
200
+ public function __destruct()
201
+ {
202
+ if (!is_null($this->fileHandle)) {
203
+ fclose($this->fileHandle);
204
+ unlink($this->fileName);
205
+ }
206
+ $this->fileHandle = null;
207
+ }
208
+ }
 
 
 
 
 
 
 
 
 
 
 
PHPExcel/Classes/PHPExcel/CachedObjectStorage/ICache.php CHANGED
@@ -1,112 +1,103 @@
1
- <?php
2
- /**
3
- * PHPExcel
4
- *
5
- * Copyright (c) 2006 - 2014 PHPExcel
6
- *
7
- * This library is free software; you can redistribute it and/or
8
- * modify it under the terms of the GNU Lesser General Public
9
- * License as published by the Free Software Foundation; either
10
- * version 2.1 of the License, or (at your option) any later version.
11
- *
12
- * This library is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
- * Lesser General Public License for more details.
16
- *
17
- * You should have received a copy of the GNU Lesser General Public
18
- * License along with this library; if not, write to the Free Software
19
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
- *
21
- * @category PHPExcel
22
- * @package PHPExcel_CachedObjectStorage
23
- * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
24
- * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25
- * @version 1.8.0, 2014-03-02
26
- */
27
-
28
-
29
- /**
30
- * PHPExcel_CachedObjectStorage_ICache
31
- *
32
- * @category PHPExcel
33
- * @package PHPExcel_CachedObjectStorage
34
- * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
35
- */
36
- interface PHPExcel_CachedObjectStorage_ICache
37
- {
38
- /**
39
- * Add or Update a cell in cache identified by coordinate address
40
- *
41
- * @param string $pCoord Coordinate address of the cell to update
42
- * @param PHPExcel_Cell $cell Cell to update
43
- * @return void
44
- * @throws PHPExcel_Exception
45
- */
46
- public function addCacheData($pCoord, PHPExcel_Cell $cell);
47
-
48
- /**
49
- * Add or Update a cell in cache
50
- *
51
- * @param PHPExcel_Cell $cell Cell to update
52
- * @return void
53
- * @throws PHPExcel_Exception
54
- */
55
- public function updateCacheData(PHPExcel_Cell $cell);
56
-
57
- /**
58
- * Fetch a cell from cache identified by coordinate address
59
- *
60
- * @param string $pCoord Coordinate address of the cell to retrieve
61
- * @return PHPExcel_Cell Cell that was found, or null if not found
62
- * @throws PHPExcel_Exception
63
- */
64
- public function getCacheData($pCoord);
65
-
66
- /**
67
- * Delete a cell in cache identified by coordinate address
68
- *
69
- * @param string $pCoord Coordinate address of the cell to delete
70
- * @throws PHPExcel_Exception
71
- */
72
- public function deleteCacheData($pCoord);
73
-
74
- /**
75
- * Is a value set in the current PHPExcel_CachedObjectStorage_ICache for an indexed cell?
76
- *
77
- * @param string $pCoord Coordinate address of the cell to check
78
- * @return boolean
79
- */
80
- public function isDataSet($pCoord);
81
-
82
- /**
83
- * Get a list of all cell addresses currently held in cache
84
- *
85
- * @return array of string
86
- */
87
- public function getCellList();
88
-
89
- /**
90
- * Get the list of all cell addresses currently held in cache sorted by column and row
91
- *
92
- * @return void
93
- */
94
- public function getSortedCellList();
95
-
96
- /**
97
- * Clone the cell collection
98
- *
99
- * @param PHPExcel_Worksheet $parent The new worksheet
100
- * @return void
101
- */
102
- public function copyCellCollection(PHPExcel_Worksheet $parent);
103
-
104
- /**
105
- * Identify whether the caching method is currently available
106
- * Some methods are dependent on the availability of certain extensions being enabled in the PHP build
107
- *
108
- * @return boolean
109
- */
110
- public static function cacheMethodIsAvailable();
111
-
112
- }
1
+ <?php
2
+
3
+ /**
4
+ * PHPExcel_CachedObjectStorage_ICache
5
+ *
6
+ * Copyright (c) 2006 - 2015 PHPExcel
7
+ *
8
+ * This library is free software; you can redistribute it and/or
9
+ * modify it under the terms of the GNU Lesser General Public
10
+ * License as published by the Free Software Foundation; either
11
+ * version 2.1 of the License, or (at your option) any later version.
12
+ *
13
+ * This library is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
+ * Lesser General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU Lesser General Public
19
+ * License along with this library; if not, write to the Free Software
20
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
+ *
22
+ * @category PHPExcel
23
+ * @package PHPExcel_CachedObjectStorage
24
+ * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
25
+ * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
26
+ * @version ##VERSION##, ##DATE##
27
+ */
28
+ interface PHPExcel_CachedObjectStorage_ICache
29
+ {
30
+ /**
31
+ * Add or Update a cell in cache identified by coordinate address
32
+ *
33
+ * @param string $pCoord Coordinate address of the cell to update
34
+ * @param PHPExcel_Cell $cell Cell to update
35
+ * @return PHPExcel_Cell
36
+ * @throws PHPExcel_Exception
37
+ */
38
+ public function addCacheData($pCoord, PHPExcel_Cell $cell);
39
+
40
+ /**
41
+ * Add or Update a cell in cache
42
+ *
43
+ * @param PHPExcel_Cell $cell Cell to update
44
+ * @return PHPExcel_Cell
45
+ * @throws PHPExcel_Exception
46
+ */
47
+ public function updateCacheData(PHPExcel_Cell $cell);
48
+
49
+ /**
50
+ * Fetch a cell from cache identified by coordinate address
51
+ *
52
+ * @param string $pCoord Coordinate address of the cell to retrieve
53
+ * @return PHPExcel_Cell Cell that was found, or null if not found
54
+ * @throws PHPExcel_Exception
55
+ */
56
+ public function getCacheData($pCoord);
57
+
58
+ /**
59
+ * Delete a cell in cache identified by coordinate address
60
+ *
61
+ * @param string $pCoord Coordinate address of the cell to delete
62
+ * @throws PHPExcel_Exception
63
+ */
64
+ public function deleteCacheData($pCoord);
65
+
66
+ /**
67
+ * Is a value set in the current PHPExcel_CachedObjectStorage_ICache for an indexed cell?
68
+ *
69
+ * @param string $pCoord Coordinate address of the cell to check
70
+ * @return boolean
71
+ */
72
+ public function isDataSet($pCoord);
73
+
74
+ /**
75
+ * Get a list of all cell addresses currently held in cache
76
+ *
77
+ * @return string[]
78
+ */
79
+ public function getCellList();
80
+
81
+ /**
82
+ * Get the list of all cell addresses currently held in cache sorted by column and row
83
+ *
84
+ * @return string[]
85
+ */
86
+ public function getSortedCellList();
87
+
88
+ /**
89
+ * Clone the cell collection
90
+ *
91
+ * @param PHPExcel_Worksheet $parent The new worksheet
92
+ * @return void
93
+ */
94
+ public function copyCellCollection(PHPExcel_Worksheet $parent);
95
+
96
+ /**
97
+ * Identify whether the caching method is currently available
98
+ * Some methods are dependent on the availability of certain extensions being enabled in the PHP build
99
+ *
100
+ * @return boolean
101
+ */
102
+ public static function cacheMethodIsAvailable();
103
+ }
 
 
 
 
 
 
 
 
 
PHPExcel/Classes/PHPExcel/CachedObjectStorage/Igbinary.php CHANGED
@@ -1,152 +1,149 @@
1
- <?php
2
- /**
3
- * PHPExcel
4
- *
5
- * Copyright (c) 2006 - 2014 PHPExcel
6
- *
7
- * This library is free software; you can redistribute it and/or
8
- * modify it under the terms of the GNU Lesser General Public
9
- * License as published by the Free Software Foundation; either
10
- * version 2.1 of the License, or (at your option) any later version.
11
- *
12
- * This library is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
- * Lesser General Public License for more details.
16
- *
17
- * You should have received a copy of the GNU Lesser General Public
18
- * License along with this library; if not, write to the Free Software
19
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
- *
21
- * @category PHPExcel
22
- * @package PHPExcel_CachedObjectStorage
23
- * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
24
- * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25
- * @version 1.8.0, 2014-03-02
26
- */
27
-
28
-
29
- /**
30
- * PHPExcel_CachedObjectStorage_Igbinary
31
- *
32
- * @category PHPExcel
33
- * @package PHPExcel_CachedObjectStorage
34
- * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
35
- */
36
- class PHPExcel_CachedObjectStorage_Igbinary extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {
37
-
38
- /**
39
- * Store cell data in cache for the current cell object if it's "dirty",
40
- * and the 'nullify' the current cell object
41
- *
42
- * @return void
43
- * @throws PHPExcel_Exception
44
- */
45
- protected function _storeData() {
46
- if ($this->_currentCellIsDirty && !empty($this->_currentObjectID)) {
47
- $this->_currentObject->detach();
48
-
49
- $this->_cellCache[$this->_currentObjectID] = igbinary_serialize($this->_currentObject);
50
- $this->_currentCellIsDirty = false;
51
- }
52
- $this->_currentObjectID = $this->_currentObject = null;
53
- } // function _storeData()
54
-
55
-
56
- /**
57
- * Add or Update a cell in cache identified by coordinate address
58
- *
59
- * @param string $pCoord Coordinate address of the cell to update
60
- * @param PHPExcel_Cell $cell Cell to update
61
- * @return void
62
- * @throws PHPExcel_Exception
63
- */
64
- public function addCacheData($pCoord, PHPExcel_Cell $cell) {
65
- if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) {
66
- $this->_storeData();
67
- }
68
-
69
- $this->_currentObjectID = $pCoord;
70
- $this->_currentObject = $cell;
71
- $this->_currentCellIsDirty = true;
72
-
73
- return $cell;
74
- } // function addCacheData()
75
-
76
-
77
- /**
78
- * Get cell at a specific coordinate
79
- *
80
- * @param string $pCoord Coordinate of the cell
81
- * @throws PHPExcel_Exception
82
- * @return PHPExcel_Cell Cell that was found, or null if not found
83
- */
84
- public function getCacheData($pCoord) {
85
- if ($pCoord === $this->_currentObjectID) {
86
- return $this->_currentObject;
87
- }
88
- $this->_storeData();
89
-
90
- // Check if the entry that has been requested actually exists
91
- if (!isset($this->_cellCache[$pCoord])) {
92
- // Return null if requested entry doesn't exist in cache
93
- return null;
94
- }
95
-
96
- // Set current entry to the requested entry
97
- $this->_currentObjectID = $pCoord;
98
- $this->_currentObject = igbinary_unserialize($this->_cellCache[$pCoord]);
99
- // Re-attach this as the cell's parent
100
- $this->_currentObject->attach($this);
101
-
102
- // Return requested entry
103
- return $this->_currentObject;
104
- } // function getCacheData()
105
-
106
-
107
- /**
108
- * Get a list of all cell addresses currently held in cache
109
- *
110
- * @return array of string
111
- */
112
- public function getCellList() {
113
- if ($this->_currentObjectID !== null) {
114
- $this->_storeData();
115
- }
116
-
117
- return parent::getCellList();
118
- }
119
-
120
-
121
- /**
122
- * Clear the cell collection and disconnect from our parent
123
- *
124
- * @return void
125
- */
126
- public function unsetWorksheetCells() {
127
- if(!is_null($this->_currentObject)) {
128
- $this->_currentObject->detach();
129
- $this->_currentObject = $this->_currentObjectID = null;
130
- }
131
- $this->_cellCache = array();
132
-
133
- // detach ourself from the worksheet, so that it can then delete this object successfully
134
- $this->_parent = null;
135
- } // function unsetWorksheetCells()
136
-
137
-
138
- /**
139
- * Identify whether the caching method is currently available
140
- * Some methods are dependent on the availability of certain extensions being enabled in the PHP build
141
- *
142
- * @return boolean
143
- */
144
- public static function cacheMethodIsAvailable() {
145
- if (!function_exists('igbinary_serialize')) {
146
- return false;
147
- }
148
-
149
- return true;
150
- }
151
-
152
- }
1
+ <?php
2
+
3
+ /**
4
+ * PHPExcel_CachedObjectStorage_Igbinary
5
+ *
6
+ * Copyright (c) 2006 - 2015 PHPExcel
7
+ *
8
+ * This library is free software; you can redistribute it and/or
9
+ * modify it under the terms of the GNU Lesser General Public
10
+ * License as published by the Free Software Foundation; either
11
+ * version 2.1 of the License, or (at your option) any later version.
12
+ *
13
+ * This library is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
+ * Lesser General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU Lesser General Public
19
+ * License along with this library; if not, write to the Free Software
20
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
+ *
22
+ * @category PHPExcel
23
+ * @package PHPExcel_CachedObjectStorage
24
+ * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
25
+ * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
26
+ * @version ##VERSION##, ##DATE##
27
+ */
28
+ class PHPExcel_CachedObjectStorage_Igbinary extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache
29
+ {
30
+ /**
31
+ * Store cell data in cache for the current cell object if it's "dirty",
32
+ * and the 'nullify' the current cell object
33
+ *
34
+ * @return void
35
+ * @throws PHPExcel_Exception
36
+ */
37
+ protected function storeData()
38
+ {
39
+ if ($this->currentCellIsDirty && !empty($this->currentObjectID)) {
40
+ $this->currentObject->detach();
41
+
42
+ $this->cellCache[$this->currentObjectID] = igbinary_serialize($this->currentObject);
43
+ $this->currentCellIsDirty = false;
44
+ }
45
+ $this->currentObjectID = $this->currentObject = null;
46
+ } // function _storeData()
47
+
48
+
49
+ /**
50
+ * Add or Update a cell in cache identified by coordinate address
51
+ *
52
+ * @param string $pCoord Coordinate address of the cell to update
53
+ * @param PHPExcel_Cell $cell Cell to update
54
+ * @return PHPExcel_Cell
55
+ * @throws PHPExcel_Exception
56
+ */
57
+ public function addCacheData($pCoord, PHPExcel_Cell $cell)
58
+ {
59
+ if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) {
60
+ $this->storeData();
61
+ }
62
+
63
+ $this->currentObjectID = $pCoord;
64
+ $this->currentObject = $cell;
65
+ $this->currentCellIsDirty = true;
66
+
67
+ return $cell;
68
+ } // function addCacheData()
69
+
70
+
71
+ /**
72
+ * Get cell at a specific coordinate
73
+ *
74
+ * @param string $pCoord Coordinate of the cell
75
+ * @throws PHPExcel_Exception
76
+ * @return PHPExcel_Cell Cell that was found, or null if not found
77
+ */
78
+ public function getCacheData($pCoord)
79
+ {
80
+ if ($pCoord === $this->currentObjectID) {
81
+ return $this->currentObject;
82
+ }
83
+ $this->storeData();
84
+
85
+ // Check if the entry that has been requested actually exists
86
+ if (!isset($this->cellCache[$pCoord])) {
87
+ // Return null if requested entry doesn't exist in cache
88
+ return null;
89
+ }
90
+
91
+ // Set current entry to the requested entry
92
+ $this->currentObjectID = $pCoord;
93
+ $this->currentObject = igbinary_unserialize($this->cellCache[$pCoord]);
94
+ // Re-attach this as the cell's parent
95
+ $this->currentObject->attach($this);
96
+
97
+ // Return requested entry
98
+ return $this->currentObject;
99
+ } // function getCacheData()
100
+
101
+
102
+ /**
103
+ * Get a list of all cell addresses currently held in cache
104
+ *
105
+ * @return string[]
106
+ */
107
+ public function getCellList()
108
+ {
109
+ if ($this->currentObjectID !== null) {
110
+ $this->storeData();
111
+ }
112
+
113
+ return parent::getCellList();
114
+ }
115
+
116
+
117
+ /**
118
+ * Clear the cell collection and disconnect from our parent
119
+ *
120
+ * @return void
121
+ */
122
+ public function unsetWorksheetCells()
123
+ {
124
+ if (!is_null($this->currentObject)) {
125
+ $this->currentObject->detach();
126
+ $this->currentObject = $this->currentObjectID = null;
127
+ }
128
+ $this->cellCache = array();
129
+
130
+ // detach ourself from the worksheet, so that it can then delete this object successfully
131
+ $this->parent = null;
132
+ } // function unsetWorksheetCells()
133
+
134
+
135
+ /**
136
+ * Identify whether the caching method is currently available
137
+ * Some methods are dependent on the availability of certain extensions being enabled in the PHP build
138
+ *
139
+ * @return boolean
140
+ */
141
+ public static function cacheMethodIsAvailable()
142
+ {
143
+ if (!function_exists('igbinary_serialize')) {
144
+ return false;
145
+ }
146
+
147
+ return true;
148
+ }
149
+ }
 
 
 
PHPExcel/Classes/PHPExcel/CachedObjectStorage/Memcache.php CHANGED
@@ -1,312 +1,308 @@
1
- <?php
2
- /**
3
- * PHPExcel
4
- *
5
- * Copyright (c) 2006 - 2014 PHPExcel
6
- *
7
- * This library is free software; you can redistribute it and/or
8
- * modify it under the terms of the GNU Lesser General Public
9
- * License as published by the Free Software Foundation; either
10
- * version 2.1 of the License, or (at your option) any later version.
11
- *
12
- * This library is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
- * Lesser General Public License for more details.
16
- *
17
- * You should have received a copy of the GNU Lesser General Public
18
- * License along with this library; if not, write to the Free Software
19
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
- *
21
- * @category PHPExcel
22
- * @package PHPExcel_CachedObjectStorage
23
- * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
24
- * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25
- * @version 1.8.0, 2014-03-02
26
- */
27
-
28
-
29
- /**
30
- * PHPExcel_CachedObjectStorage_Memcache
31
- *
32
- * @category PHPExcel
33
- * @package PHPExcel_CachedObjectStorage
34
- * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
35
- */
36
- class PHPExcel_CachedObjectStorage_Memcache extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {
37
-
38
- /**
39
- * Prefix used to uniquely identify cache data for this worksheet
40
- *
41
- * @var string
42
- */
43
- private $_cachePrefix = null;
44
-
45
- /**
46
- * Cache timeout
47
- *
48
- * @var integer
49
- */
50
- private $_cacheTime = 600;
51
-
52
- /**
53
- * Memcache interface
54
- *
55
- * @var resource
56
- */
57
- private $_memcache = null;
58
-
59
-
60
- /**
61
- * Store cell data in cache for the current cell object if it's "dirty",
62
- * and the 'nullify' the current cell object
63
- *
64
- * @return void
65
- * @throws PHPExcel_Exception
66
- */
67
- protected function _storeData() {
68
- if ($this->_currentCellIsDirty && !empty($this->_currentObjectID)) {
69
- $this->_currentObject->detach();
70
-
71
- $obj = serialize($this->_currentObject);
72
- if (!$this->_memcache->replace($this->_cachePrefix.$this->_currentObjectID.'.cache',$obj,NULL,$this->_cacheTime)) {
73
- if (!$this->_memcache->add($this->_cachePrefix.$this->_currentObjectID.'.cache',$obj,NULL,$this->_cacheTime)) {
74
- $this->__destruct();
75
- throw new PHPExcel_Exception('Failed to store cell '.$this->_currentObjectID.' in MemCache');
76
- }
77
- }
78
- $this->_currentCellIsDirty = false;
79
- }
80
- $this->_currentObjectID = $this->_currentObject = null;
81
- } // function _storeData()
82
-
83
-
84
- /**
85
- * Add or Update a cell in cache identified by coordinate address
86
- *
87
- * @param string $pCoord Coordinate address of the cell to update
88
- * @param PHPExcel_Cell $cell Cell to update
89
- * @return void
90
- * @throws PHPExcel_Exception
91
- */
92
- public function addCacheData($pCoord, PHPExcel_Cell $cell) {
93
- if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) {
94
- $this->_storeData();
95
- }
96
- $this->_cellCache[$pCoord] = true;
97
-
98
- $this->_currentObjectID = $pCoord;
99
- $this->_currentObject = $cell;
100
- $this->_currentCellIsDirty = true;
101
-
102
- return $cell;
103
- } // function addCacheData()
104
-
105
-
106
- /**
107
- * Is a value set in the current PHPExcel_CachedObjectStorage_ICache for an indexed cell?
108
- *
109
- * @param string $pCoord Coordinate address of the cell to check
110
- * @return void
111
- * @return boolean
112
- */
113
- public function isDataSet($pCoord) {
114
- // Check if the requested entry is the current object, or exists in the cache
115
- if (parent::isDataSet($pCoord)) {
116
- if ($this->_currentObjectID == $pCoord) {
117
- return true;
118
- }
119
- // Check if the requested entry still exists in Memcache
120
- $success = $this->_memcache->get($this->_cachePrefix.$pCoord.'.cache');
121
- if ($success === false) {
122
- // Entry no longer exists in Memcache, so clear it from the cache array
123
- parent::deleteCacheData($pCoord);
124
- throw new PHPExcel_Exception('Cell entry '.$pCoord.' no longer exists in MemCache');
125
- }
126
- return true;
127
- }
128
- return false;
129
- } // function isDataSet()
130
-
131
-
132
- /**
133
- * Get cell at a specific coordinate
134
- *
135
- * @param string $pCoord Coordinate of the cell
136
- * @throws PHPExcel_Exception
137
- * @return PHPExcel_Cell Cell that was found, or null if not found
138
- */
139
- public function getCacheData($pCoord) {
140
- if ($pCoord === $this->_currentObjectID) {
141
- return $this->_currentObject;
142
- }
143
- $this->_storeData();
144
-
145
- // Check if the entry that has been requested actually exists
146
- if (parent::isDataSet($pCoord)) {
147
- $obj = $this->_memcache->get($this->_cachePrefix.$pCoord.'.cache');
148
- if ($obj === false) {
149
- // Entry no longer exists in Memcache, so clear it from the cache array
150
- parent::deleteCacheData($pCoord);
151
- throw new PHPExcel_Exception('Cell entry '.$pCoord.' no longer exists in MemCache');
152
- }
153
- } else {
154
- // Return null if requested entry doesn't exist in cache
155
- return null;
156
- }
157
-
158
- // Set current entry to the requested entry
159
- $this->_currentObjectID = $pCoord;
160
- $this->_currentObject = unserialize($obj);
161
- // Re-attach this as the cell's parent
162
- $this->_currentObject->attach($this);
163
-
164
- // Return requested entry
165
- return $this->_currentObject;
166
- } // function getCacheData()
167
-
168
-
169
- /**
170
- * Get a list of all cell addresses currently held in cache
171
- *
172
- * @return array of string
173
- */
174
- public function getCellList() {
175
- if ($this->_currentObjectID !== null) {
176
- $this->_storeData();
177
- }
178
-
179
- return parent::getCellList();
180
- }
181
-
182
-
183
- /**
184
- * Delete a cell in cache identified by coordinate address
185
- *
186
- * @param string $pCoord Coordinate address of the cell to delete
187
- * @throws PHPExcel_Exception
188
- */
189
- public function deleteCacheData($pCoord) {
190
- // Delete the entry from Memcache
191
- $this->_memcache->delete($this->_cachePrefix.$pCoord.'.cache');
192
-
193
- // Delete the entry from our cell address array
194
- parent::deleteCacheData($pCoord);
195
- } // function deleteCacheData()
196
-
197
-
198
- /**
199
- * Clone the cell collection
200
- *
201
- * @param PHPExcel_Worksheet $parent The new worksheet
202
- * @return void
203
- */
204
- public function copyCellCollection(PHPExcel_Worksheet $parent) {
205
- parent::copyCellCollection($parent);
206
- // Get a new id for the new file name
207
- $baseUnique = $this->_getUniqueID();
208
- $newCachePrefix = substr(md5($baseUnique),0,8).'.';
209
- $cacheList = $this->getCellList();
210
- foreach($cacheList as $cellID) {
211
- if ($cellID != $this->_currentObjectID) {
212
- $obj = $this->_memcache->get($this->_cachePrefix.$cellID.'.cache');
213
- if ($obj === false) {
214
- // Entry no longer exists in Memcache, so clear it from the cache array
215
- parent::deleteCacheData($cellID);
216
- throw new PHPExcel_Exception('Cell entry '.$cellID.' no longer exists in MemCache');
217
- }
218
- if (!$this->_memcache->add($newCachePrefix.$cellID.'.cache',$obj,NULL,$this->_cacheTime)) {
219
- $this->__destruct();
220
- throw new PHPExcel_Exception('Failed to store cell '.$cellID.' in MemCache');
221
- }
222
- }
223
- }
224
- $this->_cachePrefix = $newCachePrefix;
225
- } // function copyCellCollection()
226
-
227
-
228
- /**
229
- * Clear the cell collection and disconnect from our parent
230
- *
231
- * @return void
232
- */
233
- public function unsetWorksheetCells() {
234
- if(!is_null($this->_currentObject)) {
235
- $this->_currentObject->detach();
236
- $this->_currentObject = $this->_currentObjectID = null;
237
- }
238
-
239
- // Flush the Memcache cache
240
- $this->__destruct();
241
-
242
- $this->_cellCache = array();
243
-
244
- // detach ourself from the worksheet, so that it can then delete this object successfully
245
- $this->_parent = null;
246
- } // function unsetWorksheetCells()
247
-
248
-
249
- /**
250
- * Initialise this new cell collection
251
- *
252
- * @param PHPExcel_Worksheet $parent The worksheet for this cell collection
253
- * @param array of mixed $arguments Additional initialisation arguments
254
- */
255
- public function __construct(PHPExcel_Worksheet $parent, $arguments) {
256
- $memcacheServer = (isset($arguments['memcacheServer'])) ? $arguments['memcacheServer'] : 'localhost';
257
- $memcachePort = (isset($arguments['memcachePort'])) ? $arguments['memcachePort'] : 11211;
258
- $cacheTime = (isset($arguments['cacheTime'])) ? $arguments['cacheTime'] : 600;
259
-
260
- if (is_null($this->_cachePrefix)) {
261
- $baseUnique = $this->_getUniqueID();
262
- $this->_cachePrefix = substr(md5($baseUnique),0,8).'.';
263
-
264
- // Set a new Memcache object and connect to the Memcache server
265
- $this->_memcache = new Memcache();
266
- if (!$this->_memcache->addServer($memcacheServer, $memcachePort, false, 50, 5, 5, true, array($this, 'failureCallback'))) {
267
- throw new PHPExcel_Exception('Could not connect to MemCache server at '.$memcacheServer.':'.$memcachePort);
268
- }
269
- $this->_cacheTime = $cacheTime;
270
-
271
- parent::__construct($parent);
272
- }
273
- } // function __construct()
274
-
275
-
276
- /**
277
- * Memcache error handler
278
- *
279
- * @param string $host Memcache server
280
- * @param integer $port Memcache port
281
- * @throws PHPExcel_Exception
282
- */
283
- public function failureCallback($host, $port) {
284
- throw new PHPExcel_Exception('memcache '.$host.':'.$port.' failed');
285
- }
286
-
287
-
288
- /**
289
- * Destroy this cell collection
290
- */
291
- public function __destruct() {
292
- $cacheList = $this->getCellList();
293
- foreach($cacheList as $cellID) {
294
- $this->_memcache->delete($this->_cachePrefix.$cellID.'.cache');
295
- }
296
- } // function __destruct()
297
-
298
- /**
299
- * Identify whether the caching method is currently available
300
- * Some methods are dependent on the availability of certain extensions being enabled in the PHP build
301
- *
302
- * @return boolean
303
- */
304
- public static function cacheMethodIsAvailable() {
305
- if (!function_exists('memcache_add')) {
306
- return false;
307
- }
308
-
309
- return true;
310
- }
311
-
312
- }
1
+ <?php
2
+
3
+ /**
4
+ * PHPExcel_CachedObjectStorage_Memcache
5
+ *
6
+ * Copyright (c) 2006 - 2015 PHPExcel
7
+ *
8
+ * This library is free software; you can redistribute it and/or
9
+ * modify it under the terms of the GNU Lesser General Public
10
+ * License as published by the Free Software Foundation; either
11
+ * version 2.1 of the License, or (at your option) any later version.
12
+ *
13
+ * This library is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
+ * Lesser General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU Lesser General Public
19
+ * License along with this library; if not, write to the Free Software
20
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
+ *
22
+ * @category PHPExcel
23
+ * @package PHPExcel_CachedObjectStorage
24
+ * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
25
+ * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
26
+ * @version ##VERSION##, ##DATE##
27
+ */
28
+ class PHPExcel_CachedObjectStorage_Memcache extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache
29
+ {
30
+ /**
31
+ * Prefix used to uniquely identify cache data for this worksheet
32
+ *
33
+ * @var string
34
+ */
35
+ private $cachePrefix = null;
36
+
37
+ /**
38
+ * Cache timeout
39
+ *
40
+ * @var integer
41
+ */
42
+ private $cacheTime = 600;
43
+
44
+ /**
45
+ * Memcache interface
46
+ *
47
+ * @var resource
48
+ */
49
+ private $memcache = null;
50
+
51
+
52
+ /**
53
+ * Store cell data in cache for the current cell object if it's "dirty",
54
+ * and the 'nullify' the current cell object
55
+ *
56
+ * @return void
57
+ * @throws PHPExcel_Exception
58
+ */
59
+ protected function storeData()
60
+ {
61
+ if ($this->currentCellIsDirty && !empty($this->currentObjectID)) {
62
+ $this->currentObject->detach();
63
+
64
+ $obj = serialize($this->currentObject);
65
+ if (!$this->memcache->replace($this->cachePrefix . $this->currentObjectID . '.cache', $obj, null, $this->cacheTime)) {
66
+ if (!$this->memcache->add($this->cachePrefix . $this->currentObjectID . '.cache', $obj, null, $this->cacheTime)) {
67
+ $this->__destruct();
68
+ throw new PHPExcel_Exception("Failed to store cell {$this->currentObjectID} in MemCache");
69
+ }
70
+ }
71
+ $this->currentCellIsDirty = false;
72
+ }
73
+ $this->currentObjectID = $this->currentObject = null;
74
+ } // function _storeData()
75
+
76
+
77
+ /**
78
+ * Add or Update a cell in cache identified by coordinate address
79
+ *
80
+ * @param string $pCoord Coordinate address of the cell to update
81
+ * @param PHPExcel_Cell $cell Cell to update
82
+ * @return PHPExcel_Cell
83
+ * @throws PHPExcel_Exception
84
+ */
85
+ public function addCacheData($pCoord, PHPExcel_Cell $cell)
86
+ {
87
+ if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) {
88
+ $this->storeData();
89
+ }
90
+ $this->cellCache[$pCoord] = true;
91
+
92
+ $this->currentObjectID = $pCoord;
93
+ $this->currentObject = $cell;
94
+ $this->currentCellIsDirty = true;
95
+
96
+ return $cell;
97
+ } // function addCacheData()
98
+
99
+
100
+ /**
101
+ * Is a value set in the current PHPExcel_CachedObjectStorage_ICache for an indexed cell?
102
+ *
103
+ * @param string $pCoord Coordinate address of the cell to check
104
+ * @return boolean
105
+ * @return boolean
106
+ */
107
+ public function isDataSet($pCoord)
108
+ {
109
+ // Check if the requested entry is the current object, or exists in the cache
110
+ if (parent::isDataSet($pCoord)) {
111
+ if ($this->currentObjectID == $pCoord) {
112
+ return true;
113
+ }
114
+ // Check if the requested entry still exists in Memcache
115
+ $success = $this->memcache->get($this->cachePrefix.$pCoord.'.cache');
116
+ if ($success === false) {
117
+ // Entry no longer exists in Memcache, so clear it from the cache array
118
+ parent::deleteCacheData($pCoord);
119
+ throw new PHPExcel_Exception('Cell entry '.$pCoord.' no longer exists in MemCache');
120
+ }
121
+ return true;
122
+ }
123
+ return false;
124
+ }
125
+
126
+
127
+ /**
128
+ * Get cell at a specific coordinate
129
+ *
130
+ * @param string $pCoord Coordinate of the cell
131
+ * @throws PHPExcel_Exception
132
+ * @return PHPExcel_Cell Cell that was found, or null if not found
133
+ */
134
+ public function getCacheData($pCoord)
135
+ {
136
+ if ($pCoord === $this->currentObjectID) {
137
+ return $this->currentObject;
138
+ }
139
+ $this->storeData();
140
+
141
+ // Check if the entry that has been requested actually exists
142
+ if (parent::isDataSet($pCoord)) {
143
+ $obj = $this->memcache->get($this->cachePrefix . $pCoord . '.cache');
144
+ if ($obj === false) {
145
+ // Entry no longer exists in Memcache, so clear it from the cache array
146
+ parent::deleteCacheData($pCoord);
147
+ throw new PHPExcel_Exception("Cell entry {$pCoord} no longer exists in MemCache");
148
+ }
149
+ } else {
150
+ // Return null if requested entry doesn't exist in cache
151
+ return null;
152
+ }
153
+
154
+ // Set current entry to the requested entry
155
+ $this->currentObjectID = $pCoord;
156
+ $this->currentObject = unserialize($obj);
157
+ // Re-attach this as the cell's parent
158
+ $this->currentObject->attach($this);
159
+
160
+ // Return requested entry
161
+ return $this->currentObject;
162
+ }
163
+
164
+ /**
165
+ * Get a list of all cell addresses currently held in cache
166
+ *
167
+ * @return string[]
168
+ */
169
+ public function getCellList()
170
+ {
171
+ if ($this->currentObjectID !== null) {
172
+ $this->storeData();
173
+ }
174
+
175
+ return parent::getCellList();
176
+ }
177
+
178
+ /**
179
+ * Delete a cell in cache identified by coordinate address
180
+ *
181
+ * @param string $pCoord Coordinate address of the cell to delete
182
+ * @throws PHPExcel_Exception
183
+ */
184
+ public function deleteCacheData($pCoord)
185
+ {
186
+ // Delete the entry from Memcache
187
+ $this->memcache->delete($this->cachePrefix . $pCoord . '.cache');
188
+
189
+ // Delete the entry from our cell address array
190
+ parent::deleteCacheData($pCoord);
191
+ }
192
+
193
+ /**
194
+ * Clone the cell collection
195
+ *
196
+ * @param PHPExcel_Worksheet $parent The new worksheet
197
+ * @return void
198
+ */
199
+ public function copyCellCollection(PHPExcel_Worksheet $parent)
200
+ {
201
+ parent::copyCellCollection($parent);
202
+ // Get a new id for the new file name
203
+ $baseUnique = $this->getUniqueID();
204
+ $newCachePrefix = substr(md5($baseUnique), 0, 8) . '.';
205
+ $cacheList = $this->getCellList();
206
+ foreach ($cacheList as $cellID) {
207
+ if ($cellID != $this->currentObjectID) {
208
+ $obj = $this->memcache->get($this->cachePrefix.$cellID.'.cache');
209
+ if ($obj === false) {
210
+ // Entry no longer exists in Memcache, so clear it from the cache array
211
+ parent::deleteCacheData($cellID);
212
+ throw new PHPExcel_Exception("Cell entry {$cellID} no longer exists in MemCache");
213
+ }
214
+ if (!$this->memcache->add($newCachePrefix . $cellID . '.cache', $obj, null, $this->cacheTime)) {
215
+ $this->__destruct();
216
+ throw new PHPExcel_Exception("Failed to store cell {$cellID} in MemCache");
217
+ }
218
+ }
219
+ }
220
+ $this->cachePrefix = $newCachePrefix;
221
+ }
222
+
223
+ /**
224
+ * Clear the cell collection and disconnect from our parent
225
+ *
226
+ * @return void
227
+ */
228
+ public function unsetWorksheetCells()
229
+ {
230
+ if (!is_null($this->currentObject)) {
231
+ $this->currentObject->detach();
232
+ $this->currentObject = $this->currentObjectID = null;
233
+ }
234
+
235
+ // Flush the Memcache cache
236
+ $this->__destruct();
237
+
238
+ $this->cellCache = array();
239
+
240
+ // detach ourself from the worksheet, so that it can then delete this object successfully
241
+ $this->parent = null;
242
+ }
243
+
244
+ /**
245
+ * Initialise this new cell collection
246
+ *
247
+ * @param PHPExcel_Worksheet $parent The worksheet for this cell collection
248
+ * @param array of mixed $arguments Additional initialisation arguments
249
+ */
250
+ public function __construct(PHPExcel_Worksheet $parent, $arguments)
251
+ {
252
+ $memcacheServer = (isset($arguments['memcacheServer'])) ? $arguments['memcacheServer'] : 'localhost';
253
+ $memcachePort = (isset($arguments['memcachePort'])) ? $arguments['memcachePort'] : 11211;
254
+ $cacheTime = (isset($arguments['cacheTime'])) ? $arguments['cacheTime'] : 600;
255
+
256
+ if (is_null($this->cachePrefix)) {
257
+ $baseUnique = $this->getUniqueID();
258
+ $this->cachePrefix = substr(md5($baseUnique), 0, 8) . '.';
259
+
260
+ // Set a new Memcache object and connect to the Memcache server
261
+ $this->memcache = new Memcache();
262
+ if (!$this->memcache->addServer($memcacheServer, $memcachePort, false, 50, 5, 5, true, array($this, 'failureCallback'))) {
263
+ throw new PHPExcel_Exception("Could not connect to MemCache server at {$memcacheServer}:{$memcachePort}");
264
+ }
265
+ $this->cacheTime = $cacheTime;
266
+
267
+ parent::__construct($parent);
268
+ }
269
+ }
270
+
271
+ /**
272
+ * Memcache error handler
273
+ *
274
+ * @param string $host Memcache server
275
+ * @param integer $port Memcache port
276
+ * @throws PHPExcel_Exception
277
+ */
278
+ public function failureCallback($host, $port)
279
+ {
280
+ throw new PHPExcel_Exception("memcache {$host}:{$port} failed");
281
+ }
282
+
283
+ /**
284
+ * Destroy this cell collection
285
+ */
286
+ public function __destruct()
287
+ {
288
+ $cacheList = $this->getCellList();
289
+ foreach ($cacheList as $cellID) {
290
+ $this->memcache->delete($this->cachePrefix.$cellID . '.cache');
291
+ }
292
+ }
293
+
294
+ /**
295
+ * Identify whether the caching method is currently available
296
+ * Some methods are dependent on the availability of certain extensions being enabled in the PHP build
297
+ *
298
+ * @return boolean
299
+ */
300
+ public static function cacheMethodIsAvailable()
301
+ {
302
+ if (!function_exists('memcache_add')) {
303
+ return false;
304
+ }
305
+
306
+ return true;
307
+ }
308
+ }
 
 
 
 
PHPExcel/Classes/PHPExcel/CachedObjectStorage/Memory.php CHANGED
@@ -1,125 +1,118 @@
1
- <?php
2
- /**
3
- * PHPExcel
4
- *
5
- * Copyright (c) 2006 - 2014 PHPExcel
6
- *
7
- * This library is free software; you can redistribute it and/or
8
- * modify it under the terms of the GNU Lesser General Public
9
- * License as published by the Free Software Foundation; either
10
- * version 2.1 of the License, or (at your option) any later version.
11
- *
12
- * This library is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
- * Lesser General Public License for more details.
16
- *
17
- * You should have received a copy of the GNU Lesser General Public
18
- * License along with this library; if not, write to the Free Software
19
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
- *
21
- * @category PHPExcel
22
- * @package PHPExcel_CachedObjectStorage
23
- * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
24
- * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25
- * @version 1.8.0, 2014-03-02
26
- */
27
-
28
-
29
- /**
30
- * PHPExcel_CachedObjectStorage_Memory
31
- *
32
- * @category PHPExcel
33
- * @package PHPExcel_CachedObjectStorage
34
- * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
35
- */
36
- class PHPExcel_CachedObjectStorage_Memory extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {
37
-
38
- /**
39
- * Dummy method callable from CacheBase, but unused by Memory cache
40
- *
41
- * @return void
42
- */
43
- protected function _storeData() {
44
- } // function _storeData()
45
-
46
- /**
47
- * Add or Update a cell in cache identified by coordinate address
48
- *
49
- * @param string $pCoord Coordinate address of the cell to update
50
- * @param PHPExcel_Cell $cell Cell to update
51
- * @return PHPExcel_Cell
52
- * @throws PHPExcel_Exception
53
- */
54
- public function addCacheData($pCoord, PHPExcel_Cell $cell) {
55
- $this->_cellCache[$pCoord] = $cell;
56
-
57
- // Set current entry to the new/updated entry
58
- $this->_currentObjectID = $pCoord;
59
-
60
- return $cell;
61
- } // function addCacheData()
62
-
63
-
64
- /**
65
- * Get cell at a specific coordinate
66
- *
67
- * @param string $pCoord Coordinate of the cell
68
- * @throws PHPExcel_Exception
69
- * @return PHPExcel_Cell Cell that was found, or null if not found
70
- */
71
- public function getCacheData($pCoord) {
72
- // Check if the entry that has been requested actually exists
73
- if (!isset($this->_cellCache[$pCoord])) {
74
- $this->_currentObjectID = NULL;
75
- // Return null if requested entry doesn't exist in cache
76
- return null;
77
- }
78
-
79
- // Set current entry to the requested entry
80
- $this->_currentObjectID = $pCoord;
81
-
82
- // Return requested entry
83
- return $this->_cellCache[$pCoord];
84
- } // function getCacheData()
85
-
86
-
87
- /**
88
- * Clone the cell collection
89
- *
90
- * @param PHPExcel_Worksheet $parent The new worksheet
91
- * @return void
92
- */
93
- public function copyCellCollection(PHPExcel_Worksheet $parent) {
94
- parent::copyCellCollection($parent);
95
-
96
- $newCollection = array();
97
- foreach($this->_cellCache as $k => &$cell) {
98
- $newCollection[$k] = clone $cell;
99
- $newCollection[$k]->attach($this);
100
- }
101
-
102
- $this->_cellCache = $newCollection;
103
- }
104
-
105
-
106
- /**
107
- * Clear the cell collection and disconnect from our parent
108
- *
109
- * @return void
110
- */
111
- public function unsetWorksheetCells() {
112
- // Because cells are all stored as intact objects in memory, we need to detach each one from the parent
113
- foreach($this->_cellCache as $k => &$cell) {
114
- $cell->detach();
115
- $this->_cellCache[$k] = null;
116
- }
117
- unset($cell);
118
-
119
- $this->_cellCache = array();
120
-
121
- // detach ourself from the worksheet, so that it can then delete this object successfully
122
- $this->_parent = null;
123
- } // function unsetWorksheetCells()
124
-
125
- }
1
+ <?php
2
+
3
+ /**
4
+ * PHPExcel_CachedObjectStorage_Memory
5
+ *
6
+ * Copyright (c) 2006 - 2015 PHPExcel
7
+ *
8
+ * This library is free software; you can redistribute it and/or
9
+ * modify it under the terms of the GNU Lesser General Public
10
+ * License as published by the Free Software Foundation; either
11
+ * version 2.1 of the License, or (at your option) any later version.
12
+ *
13
+ * This library is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
+ * Lesser General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU Lesser General Public
19
+ * License along with this library; if not, write to the Free Software
20
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
+ *
22
+ * @category PHPExcel
23
+ * @package PHPExcel_CachedObjectStorage
24
+ * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
25
+ * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
26
+ * @version ##VERSION##, ##DATE##
27
+ */
28
+ class PHPExcel_CachedObjectStorage_Memory extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache
29
+ {
30
+ /**
31
+ * Dummy method callable from CacheBase, but unused by Memory cache
32
+ *
33
+ * @return void
34
+ */
35
+ protected function storeData()
36
+ {
37
+ }
38
+
39
+ /**
40
+ * Add or Update a cell in cache identified by coordinate address
41
+ *
42
+ * @param string $pCoord Coordinate address of the cell to update
43
+ * @param PHPExcel_Cell $cell Cell to update
44
+ * @return PHPExcel_Cell
45
+ * @throws PHPExcel_Exception
46
+ */
47
+ public function addCacheData($pCoord, PHPExcel_Cell $cell)
48
+ {
49
+ $this->cellCache[$pCoord] = $cell;
50
+
51
+ // Set current entry to the new/updated entry
52
+ $this->currentObjectID = $pCoord;
53
+
54
+ return $cell;
55
+ }
56
+
57
+
58
+ /**
59
+ * Get cell at a specific coordinate
60
+ *
61
+ * @param string $pCoord Coordinate of the cell
62
+ * @throws PHPExcel_Exception
63
+ * @return PHPExcel_Cell Cell that was found, or null if not found
64
+ */
65
+ public function getCacheData($pCoord)
66
+ {
67
+ // Check if the entry that has been requested actually exists
68
+ if (!isset($this->cellCache[$pCoord])) {
69
+ $this->currentObjectID = null;
70
+ // Return null if requested entry doesn't exist in cache
71
+ return null;
72
+ }
73
+
74
+ // Set current entry to the requested entry
75
+ $this->currentObjectID = $pCoord;
76
+
77
+ // Return requested entry
78
+ return $this->cellCache[$pCoord];
79
+ }
80
+
81
+
82
+ /**
83
+ * Clone the cell collection
84
+ *
85
+ * @param PHPExcel_Worksheet $parent The new worksheet
86
+ */
87
+ public function copyCellCollection(PHPExcel_Worksheet $parent)
88
+ {
89
+ parent::copyCellCollection($parent);
90
+
91
+ $newCollection = array();
92
+ foreach ($this->cellCache as $k => &$cell) {
93
+ $newCollection[$k] = clone $cell;
94
+ $newCollection[$k]->attach($this);
95
+ }
96
+
97
+ $this->cellCache = $newCollection;
98
+ }
99
+
100
+ /**
101
+ * Clear the cell collection and disconnect from our parent
102
+ *
103
+ */
104
+ public function unsetWorksheetCells()
105
+ {
106
+ // Because cells are all stored as intact objects in memory, we need to detach each one from the parent
107
+ foreach ($this->cellCache as $k => &$cell) {
108
+ $cell->detach();
109
+ $this->cellCache[$k] = null;
110
+ }
111
+ unset($cell);
112
+
113
+ $this->cellCache = array();
114
+
115
+ // detach ourself from the worksheet, so that it can then delete this object successfully
116
+ $this->parent = null;
117
+ }
118
+ }
 
 
 
 
 
 
 
PHPExcel/Classes/PHPExcel/CachedObjectStorage/MemoryGZip.php CHANGED
@@ -1,137 +1,133 @@
1
- <?php
2
- /**
3
- * PHPExcel
4
- *
5
- * Copyright (c) 2006 - 2014 PHPExcel
6
- *
7
- * This library is free software; you can redistribute it and/or
8
- * modify it under the terms of the GNU Lesser General Public
9
- * License as published by the Free Software Foundation; either
10
- * version 2.1 of the License, or (at your option) any later version.
11
- *
12
- * This library is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
- * Lesser General Public License for more details.
16
- *
17
- * You should have received a copy of the GNU Lesser General Public
18
- * License along with this library; if not, write to the Free Software
19
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
- *
21
- * @category PHPExcel
22
- * @package PHPExcel_CachedObjectStorage
23
- * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
24
- * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25
- * @version 1.8.0, 2014-03-02
26
- */
27
-
28
-
29
- /**
30
- * PHPExcel_CachedObjectStorage_MemoryGZip
31
- *
32
- * @category PHPExcel
33
- * @package PHPExcel_CachedObjectStorage
34
- * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
35
- */
36
- class PHPExcel_CachedObjectStorage_MemoryGZip extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {
37
-
38
- /**
39
- * Store cell data in cache for the current cell object if it's "dirty",
40
- * and the 'nullify' the current cell object
41
- *
42
- * @return void
43
- * @throws PHPExcel_Exception
44
- */
45
- protected function _storeData() {
46
- if ($this->_currentCellIsDirty && !empty($this->_currentObjectID)) {
47
- $this->_currentObject->detach();
48
-
49
- $this->_cellCache[$this->_currentObjectID] = gzdeflate(serialize($this->_currentObject));
50
- $this->_currentCellIsDirty = false;
51
- }
52
- $this->_currentObjectID = $this->_currentObject = null;
53
- } // function _storeData()
54
-
55
-
56
- /**
57
- * Add or Update a cell in cache identified by coordinate address
58
- *
59
- * @param string $pCoord Coordinate address of the cell to update
60
- * @param PHPExcel_Cell $cell Cell to update
61
- * @return void
62
- * @throws PHPExcel_Exception
63
- */
64
- public function addCacheData($pCoord, PHPExcel_Cell $cell) {
65
- if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) {
66
- $this->_storeData();
67
- }
68
-
69
- $this->_currentObjectID = $pCoord;
70
- $this->_currentObject = $cell;
71
- $this->_currentCellIsDirty = true;
72
-
73
- return $cell;
74
- } // function addCacheData()
75
-
76
-
77
- /**
78
- * Get cell at a specific coordinate
79
- *
80
- * @param string $pCoord Coordinate of the cell
81
- * @throws PHPExcel_Exception
82
- * @return PHPExcel_Cell Cell that was found, or null if not found
83
- */
84
- public function getCacheData($pCoord) {
85
- if ($pCoord === $this->_currentObjectID) {
86
- return $this->_currentObject;
87
- }
88
- $this->_storeData();
89
-
90
- // Check if the entry that has been requested actually exists
91
- if (!isset($this->_cellCache[$pCoord])) {
92
- // Return null if requested entry doesn't exist in cache
93
- return null;
94
- }
95
-
96
- // Set current entry to the requested entry
97
- $this->_currentObjectID = $pCoord;
98
- $this->_currentObject = unserialize(gzinflate($this->_cellCache[$pCoord]));
99
- // Re-attach this as the cell's parent
100
- $this->_currentObject->attach($this);
101
-
102
- // Return requested entry
103
- return $this->_currentObject;
104
- } // function getCacheData()
105
-
106
-
107
- /**
108
- * Get a list of all cell addresses currently held in cache
109
- *
110
- * @return array of string
111
- */
112
- public function getCellList() {
113
- if ($this->_currentObjectID !== null) {
114
- $this->_storeData();
115
- }
116
-
117
- return parent::getCellList();
118
- }
119
-
120
-
121
- /**
122
- * Clear the cell collection and disconnect from our parent
123
- *
124
- * @return void
125
- */
126
- public function unsetWorksheetCells() {
127
- if(!is_null($this->_currentObject)) {
128
- $this->_currentObject->detach();
129
- $this->_currentObject = $this->_currentObjectID = null;
130
- }
131
- $this->_cellCache = array();
132
-
133
- // detach ourself from the worksheet, so that it can then delete this object successfully
134
- $this->_parent = null;
135
- } // function unsetWorksheetCells()
136
-
137
- }
1
+ <?php
2
+
3
+ /**
4
+ * PHPExcel_CachedObjectStorage_MemoryGZip
5
+ *
6
+ * Copyright (c) 2006 - 2015 PHPExcel
7
+ *
8
+ * This library is free software; you can redistribute it and/or
9
+ * modify it under the terms of the GNU Lesser General Public
10
+ * License as published by the Free Software Foundation; either
11
+ * version 2.1 of the License, or (at your option) any later version.
12
+ *
13
+ * This library is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
+ * Lesser General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU Lesser General Public
19
+ * License along with this library; if not, write to the Free Software
20
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
+ *
22
+ * @category PHPExcel
23
+ * @package PHPExcel_CachedObjectStorage
24
+ * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
25
+ * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
26
+ * @version ##VERSION##, ##DATE##
27
+ */
28
+ class PHPExcel_CachedObjectStorage_MemoryGZip extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache
29
+ {
30
+ /**
31
+ * Store cell data in cache for the current cell object if it's "dirty",
32
+ * and the 'nullify' the current cell object
33
+ *
34
+ * @return void
35
+ * @throws PHPExcel_Exception
36
+ */
37
+ protected function storeData()
38
+ {
39
+ if ($this->currentCellIsDirty && !empty($this->currentObjectID)) {
40
+ $this->currentObject->detach();
41
+
42
+ $this->cellCache[$this->currentObjectID] = gzdeflate(serialize($this->currentObject));
43
+ $this->currentCellIsDirty = false;
44
+ }
45
+ $this->currentObjectID = $this->currentObject = null;
46
+ }
47
+
48
+
49
+ /**
50
+ * Add or Update a cell in cache identified by coordinate address
51
+ *
52
+ * @param string $pCoord Coordinate address of the cell to update
53
+ * @param PHPExcel_Cell $cell Cell to update
54
+ * @return PHPExcel_Cell
55
+ * @throws PHPExcel_Exception
56
+ */
57
+ public function addCacheData($pCoord, PHPExcel_Cell $cell)
58
+ {
59
+ if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) {
60
+ $this->storeData();
61
+ }
62
+
63
+ $this->currentObjectID = $pCoord;
64
+ $this->currentObject = $cell;
65
+ $this->currentCellIsDirty = true;
66
+
67
+ return $cell;
68
+ }
69
+
70
+
71
+ /**
72
+ * Get cell at a specific coordinate
73
+ *
74
+ * @param string $pCoord Coordinate of the cell
75
+ * @throws PHPExcel_Exception
76
+ * @return PHPExcel_Cell Cell that was found, or null if not found
77
+ */
78
+ public function getCacheData($pCoord)
79
+ {
80
+ if ($pCoord === $this->currentObjectID) {
81
+ return $this->currentObject;
82
+ }
83
+ $this->storeData();
84
+
85
+ // Check if the entry that has been requested actually exists
86
+ if (!isset($this->cellCache[$pCoord])) {
87
+ // Return null if requested entry doesn't exist in cache
88
+ return null;
89
+ }
90
+
91
+ // Set current entry to the requested entry
92
+ $this->currentObjectID = $pCoord;
93
+ $this->currentObject = unserialize(gzinflate($this->cellCache[$pCoord]));
94
+ // Re-attach this as the cell's parent
95
+ $this->currentObject->attach($this);
96
+
97
+ // Return requested entry
98
+ return $this->currentObject;
99
+ }
100
+
101
+
102
+ /**
103
+ * Get a list of all cell addresses currently held in cache
104
+ *
105
+ * @return string[]
106
+ */
107
+ public function getCellList()
108
+ {
109
+ if ($this->currentObjectID !== null) {
110
+ $this->storeData();
111
+ }
112
+
113
+ return parent::getCellList();
114
+ }
115
+
116
+
117
+ /**
118
+ * Clear the cell collection and disconnect from our parent
119
+ *
120
+ * @return void
121
+ */
122
+ public function unsetWorksheetCells()
123
+ {
124
+ if (!is_null($this->currentObject)) {
125
+ $this->currentObject->detach();
126
+ $this->currentObject = $this->currentObjectID = null;
127
+ }
128
+ $this->cellCache = array();
129
+
130
+ // detach ourself from the worksheet, so that it can then delete this object successfully
131
+ $this->parent = null;
132
+ }
133
+ }
 
 
 
 
PHPExcel/Classes/PHPExcel/CachedObjectStorage/MemorySerialized.php CHANGED
@@ -1,137 +1,129 @@
1
- <?php
2
- /**
3
- * PHPExcel
4
- *
5
- * Copyright (c) 2006 - 2014 PHPExcel
6
- *
7
- * This library is free software; you can redistribute it and/or
8
- * modify it under the terms of the GNU Lesser General Public
9
- * License as published by the Free Software Foundation; either
10
- * version 2.1 of the License, or (at your option) any later version.
11
- *
12
- * This library is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
- * Lesser General Public License for more details.
16
- *
17
- * You should have received a copy of the GNU Lesser General Public
18
- * License along with this library; if not, write to the Free Software
19
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
- *
21
- * @category PHPExcel
22
- * @package PHPExcel_CachedObjectStorage
23
- * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
24
- * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25
- * @version 1.8.0, 2014-03-02
26
- */
27
-
28
-
29
- /**
30
- * PHPExcel_CachedObjectStorage_MemorySerialized
31
- *
32
- * @category PHPExcel
33
- * @package PHPExcel_CachedObjectStorage
34
- * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
35
- */
36
- class PHPExcel_CachedObjectStorage_MemorySerialized extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {
37
-
38
- /**
39
- * Store cell data in cache for the current cell object if it's "dirty",
40
- * and the 'nullify' the current cell object
41
- *
42
- * @return void
43
- * @throws PHPExcel_Exception
44
- */
45
- protected function _storeData() {
46
- if ($this->_currentCellIsDirty && !empty($this->_currentObjectID)) {
47
- $this->_currentObject->detach();
48
-
49
- $this->_cellCache[$this->_currentObjectID] = serialize($this->_currentObject);
50
- $this->_currentCellIsDirty = false;
51
- }
52
- $this->_currentObjectID = $this->_currentObject = null;
53
- } // function _storeData()
54
-
55
-
56
- /**
57
- * Add or Update a cell in cache identified by coordinate address
58
- *
59
- * @param string $pCoord Coordinate address of the cell to update
60
- * @param PHPExcel_Cell $cell Cell to update
61
- * @return void
62
- * @throws PHPExcel_Exception
63
- */
64
- public function addCacheData($pCoord, PHPExcel_Cell $cell) {
65
- if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) {
66
- $this->_storeData();
67
- }
68
-
69
- $this->_currentObjectID = $pCoord;
70
- $this->_currentObject = $cell;
71
- $this->_currentCellIsDirty = true;
72
-
73
- return $cell;
74
- } // function addCacheData()
75
-
76
-
77
- /**
78
- * Get cell at a specific coordinate
79
- *
80
- * @param string $pCoord Coordinate of the cell
81
- * @throws PHPExcel_Exception
82
- * @return PHPExcel_Cell Cell that was found, or null if not found
83
- */
84
- public function getCacheData($pCoord) {
85
- if ($pCoord === $this->_currentObjectID) {
86
- return $this->_currentObject;
87
- }
88
- $this->_storeData();
89
-
90
- // Check if the entry that has been requested actually exists
91
- if (!isset($this->_cellCache[$pCoord])) {
92
- // Return null if requested entry doesn't exist in cache
93
- return null;
94
- }
95
-
96
- // Set current entry to the requested entry
97
- $this->_currentObjectID = $pCoord;
98
- $this->_currentObject = unserialize($this->_cellCache[$pCoord]);
99
- // Re-attach this as the cell's parent
100
- $this->_currentObject->attach($this);
101
-
102
- // Return requested entry
103
- return $this->_currentObject;
104
- } // function getCacheData()
105
-
106
-
107
- /**
108
- * Get a list of all cell addresses currently held in cache
109
- *
110
- * @return array of string
111
- */
112
- public function getCellList() {
113
- if ($this->_currentObjectID !== null) {
114
- $this->_storeData();
115
- }
116
-
117
- return parent::getCellList();
118
- }
119
-
120
-
121
- /**
122
- * Clear the cell collection and disconnect from our parent
123
- *
124
- * @return void
125
- */
126
- public function unsetWorksheetCells() {
127
- if(!is_null($this->_currentObject)) {
128
- $this->_currentObject->detach();
129
- $this->_currentObject = $this->_currentObjectID = null;
130
- }
131
- $this->_cellCache = array();
132
-
133
- // detach ourself from the worksheet, so that it can then delete this object successfully
134
- $this->_parent = null;
135
- } // function unsetWorksheetCells()
136
-
137
- }
1
+ <?php
2
+
3
+ /**
4
+ * PHPExcel_CachedObjectStorage_MemorySerialized
5
+ *
6
+ * Copyright (c) 2006 - 2015 PHPExcel
7
+ *
8
+ * This library is free software; you can redistribute it and/or
9
+ * modify it under the terms of the GNU Lesser General Public
10
+ * License as published by the Free Software Foundation; either
11
+ * version 2.1 of the License, or (at your option) any later version.
12
+ *
13
+ * This library is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
+ * Lesser General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU Lesser General Public
19
+ * License along with this library; if not, write to the Free Software
20
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
+ *
22
+ * @category PHPExcel
23
+ * @package PHPExcel_CachedObjectStorage
24
+ * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
25
+ * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
26
+ * @version ##VERSION##, ##DATE##
27
+ */
28
+ class PHPExcel_CachedObjectStorage_MemorySerialized extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache
29
+ {
30
+ /**
31
+ * Store cell data in cache for the current cell object if it's "dirty",
32
+ * and the 'nullify' the current cell object
33
+ *
34
+ * @return void
35
+ * @throws PHPExcel_Exception
36
+ */
37
+ protected function storeData()
38
+ {
39
+ if ($this->currentCellIsDirty && !empty($this->currentObjectID)) {
40
+ $this->currentObject->detach();
41
+
42
+ $this->cellCache[$this->currentObjectID] = serialize($this->currentObject);
43
+ $this->currentCellIsDirty = false;
44
+ }
45
+ $this->currentObjectID = $this->currentObject = null;
46
+ }
47
+
48
+ /**
49
+ * Add or Update a cell in cache identified by coordinate address
50
+ *
51
+ * @param string $pCoord Coordinate address of the cell to update
52
+ * @param PHPExcel_Cell $cell Cell to update
53
+ * @return PHPExcel_Cell
54
+ * @throws PHPExcel_Exception
55
+ */
56
+ public function addCacheData($pCoord, PHPExcel_Cell $cell)
57
+ {
58
+ if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) {
59
+ $this->storeData();
60
+ }
61
+
62
+ $this->currentObjectID = $pCoord;
63
+ $this->currentObject = $cell;
64
+ $this->currentCellIsDirty = true;
65
+
66
+ return $cell;
67
+ }
68
+
69
+ /**
70
+ * Get cell at a specific coordinate
71
+ *
72
+ * @param string $pCoord Coordinate of the cell
73
+ * @throws PHPExcel_Exception
74
+ * @return PHPExcel_Cell Cell that was found, or null if not found
75
+ */
76
+ public function getCacheData($pCoord)
77
+ {
78
+ if ($pCoord === $this->currentObjectID) {
79
+ return $this->currentObject;
80
+ }
81
+ $this->storeData();
82
+
83
+ // Check if the entry that has been requested actually exists
84
+ if (!isset($this->cellCache[$pCoord])) {
85
+ // Return null if requested entry doesn't exist in cache
86
+ return null;
87
+ }
88
+
89
+ // Set current entry to the requested entry
90
+ $this->currentObjectID = $pCoord;
91
+ $this->currentObject = unserialize($this->cellCache[$pCoord]);
92
+ // Re-attach this as the cell's parent
93
+ $this->currentObject->attach($this);
94
+
95
+ // Return requested entry
96
+ return $this->currentObject;
97
+ }
98
+
99
+ /**
100
+ * Get a list of all cell addresses currently held in cache
101
+ *
102
+ * @return string[]
103
+ */
104
+ public function getCellList()
105
+ {
106
+ if ($this->currentObjectID !== null) {
107
+ $this->storeData();
108
+ }
109
+
110
+ return parent::getCellList();
111
+ }
112
+
113
+ /**
114
+ * Clear the cell collection and disconnect from our parent
115
+ *
116
+ * @return void
117
+ */
118
+ public function unsetWorksheetCells()
119
+ {
120
+ if (!is_null($this->currentObject)) {
121
+ $this->currentObject->detach();
122
+ $this->currentObject = $this->currentObjectID = null;
123
+ }
124
+ $this->cellCache = array();
125
+
126
+ // detach ourself from the worksheet, so that it can then delete this object successfully
127
+ $this->parent = null;
128
+ }
129
+ }
 
 
 
 
 
 
 
 
PHPExcel/Classes/PHPExcel/CachedObjectStorage/PHPTemp.php CHANGED
@@ -1,206 +1,200 @@
1
- <?php
2
- /**
3
- * PHPExcel
4
- *
5
- * Copyright (c) 2006 - 2014 PHPExcel
6
- *
7
- * This library is free software; you can redistribute it and/or
8
- * modify it under the terms of the GNU Lesser General Public
9
- * License as published by the Free Software Foundation; either
10
- * version 2.1 of the License, or (at your option) any later version.
11
- *
12
- * This library is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
- * Lesser General Public License for more details.
16
- *
17
- * You should have received a copy of the GNU Lesser General Public
18
- * License along with this library; if not, write to the Free Software
19
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
- *
21
- * @category PHPExcel
22
- * @package PHPExcel_CachedObjectStorage
23
- * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
24
- * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25
- * @version 1.8.0, 2014-03-02
26
- */
27
-
28
-
29
- /**
30
- * PHPExcel_CachedObjectStorage_PHPTemp
31
- *
32
- * @category PHPExcel
33
- * @package PHPExcel_CachedObjectStorage
34
- * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
35
- */
36
- class PHPExcel_CachedObjectStorage_PHPTemp extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {
37
-
38
- /**
39
- * Name of the file for this cache
40
- *
41
- * @var string
42
- */
43
- private $_fileHandle = null;
44
-
45
- /**
46
- * Memory limit to use before reverting to file cache
47
- *
48
- * @var integer
49
- */
50
- private $_memoryCacheSize = null;
51
-
52
- /**
53
- * Store cell data in cache for the current cell object if it's "dirty",
54
- * and the 'nullify' the current cell object
55
- *
56
- * @return void
57
- * @throws PHPExcel_Exception
58
- */
59
- protected function _storeData() {
60
- if ($this->_currentCellIsDirty && !empty($this->_currentObjectID)) {
61
- $this->_currentObject->detach();
62
-
63
- fseek($this->_fileHandle,0,SEEK_END);
64
- $offset = ftell($this->_fileHandle);
65
- fwrite($this->_fileHandle, serialize($this->_currentObject));
66
- $this->_cellCache[$this->_currentObjectID] = array('ptr' => $offset,
67
- 'sz' => ftell($this->_fileHandle) - $offset
68
- );
69
- $this->_currentCellIsDirty = false;
70
- }
71
- $this->_currentObjectID = $this->_currentObject = null;
72
- } // function _storeData()
73
-
74
-
75
- /**
76
- * Add or Update a cell in cache identified by coordinate address
77
- *
78
- * @param string $pCoord Coordinate address of the cell to update
79
- * @param PHPExcel_Cell $cell Cell to update
80
- * @return void
81
- * @throws PHPExcel_Exception
82
- */
83
- public function addCacheData($pCoord, PHPExcel_Cell $cell) {
84
- if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) {
85
- $this->_storeData();
86
- }
87
-
88
- $this->_currentObjectID = $pCoord;
89
- $this->_currentObject = $cell;
90
- $this->_currentCellIsDirty = true;
91
-
92
- return $cell;
93
- } // function addCacheData()
94
-
95
-
96
- /**
97
- * Get cell at a specific coordinate
98
- *
99
- * @param string $pCoord Coordinate of the cell
100
- * @throws PHPExcel_Exception
101
- * @return PHPExcel_Cell Cell that was found, or null if not found
102
- */
103
- public function getCacheData($pCoord) {
104
- if ($pCoord === $this->_currentObjectID) {
105
- return $this->_currentObject;
106
- }
107
- $this->_storeData();
108
-
109
- // Check if the entry that has been requested actually exists
110
- if (!isset($this->_cellCache[$pCoord])) {
111
- // Return null if requested entry doesn't exist in cache
112
- return null;
113
- }
114
-
115
- // Set current entry to the requested entry
116
- $this->_currentObjectID = $pCoord;
117
- fseek($this->_fileHandle,$this->_cellCache[$pCoord]['ptr']);
118
- $this->_currentObject = unserialize(fread($this->_fileHandle,$this->_cellCache[$pCoord]['sz']));
119
- // Re-attach this as the cell's parent
120
- $this->_currentObject->attach($this);
121
-
122
- // Return requested entry
123
- return $this->_currentObject;
124
- } // function getCacheData()
125
-
126
-
127
- /**
128
- * Get a list of all cell addresses currently held in cache
129
- *
130
- * @return array of string
131
- */
132
- public function getCellList() {
133
- if ($this->_currentObjectID !== null) {
134
- $this->_storeData();
135
- }
136
-
137
- return parent::getCellList();
138
- }
139
-
140
-
141
- /**
142
- * Clone the cell collection
143
- *
144
- * @param PHPExcel_Worksheet $parent The new worksheet
145
- * @return void
146
- */
147
- public function copyCellCollection(PHPExcel_Worksheet $parent) {
148
- parent::copyCellCollection($parent);
149
- // Open a new stream for the cell cache data
150
- $newFileHandle = fopen('php://temp/maxmemory:'.$this->_memoryCacheSize,'a+');
151
- // Copy the existing cell cache data to the new stream
152
- fseek($this->_fileHandle,0);
153
- while (!feof($this->_fileHandle)) {
154
- fwrite($newFileHandle,fread($this->_fileHandle, 1024));
155
- }
156
- $this->_fileHandle = $newFileHandle;
157
- } // function copyCellCollection()
158
-
159
-
160
- /**
161
- * Clear the cell collection and disconnect from our parent
162
- *
163
- * @return void
164
- */
165
- public function unsetWorksheetCells() {
166
- if(!is_null($this->_currentObject)) {
167
- $this->_currentObject->detach();
168
- $this->_currentObject = $this->_currentObjectID = null;
169
- }
170
- $this->_cellCache = array();
171
-
172
- // detach ourself from the worksheet, so that it can then delete this object successfully
173
- $this->_parent = null;
174
-
175
- // Close down the php://temp file
176
- $this->__destruct();
177
- } // function unsetWorksheetCells()
178
-
179
-
180
- /**
181
- * Initialise this new cell collection
182
- *
183
- * @param PHPExcel_Worksheet $parent The worksheet for this cell collection
184
- * @param array of mixed $arguments Additional initialisation arguments
185
- */
186
- public function __construct(PHPExcel_Worksheet $parent, $arguments) {
187
- $this->_memoryCacheSize = (isset($arguments['memoryCacheSize'])) ? $arguments['memoryCacheSize'] : '1MB';
188
-
189
- parent::__construct($parent);
190
- if (is_null($this->_fileHandle)) {
191
- $this->_fileHandle = fopen('php://temp/maxmemory:'.$this->_memoryCacheSize,'a+');
192
- }
193
- } // function __construct()
194
-
195
-
196
- /**
197
- * Destroy this cell collection
198
- */
199
- public function __destruct() {
200
- if (!is_null($this->_fileHandle)) {
201
- fclose($this->_fileHandle);
202
- }
203
- $this->_fileHandle = null;
204
- } // function __destruct()
205
-
206
- }
1
+ <?php
2
+
3
+ /**
4
+ * PHPExcel_CachedObjectStorage_PHPTemp
5
+ *
6
+ * Copyright (c) 2006 - 2015 PHPExcel
7
+ *
8
+ * This library is free software; you can redistribute it and/or
9
+ * modify it under the terms of the GNU Lesser General Public
10
+ * License as published by the Free Software Foundation; either
11
+ * version 2.1 of the License, or (at your option) any later version.
12
+ *
13
+ * This library is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
+ * Lesser General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU Lesser General Public
19
+ * License along with this library; if not, write to the Free Software
20
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
+ *
22
+ * @category PHPExcel
23
+ * @package PHPExcel_CachedObjectStorage
24
+ * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
25
+ * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
26
+ * @version ##VERSION##, ##DATE##
27
+ */
28
+ class PHPExcel_CachedObjectStorage_PHPTemp extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache
29
+ {
30
+ /**
31
+ * Name of the file for this cache
32
+ *
33
+ * @var string
34
+ */
35
+ private $fileHandle = null;
36
+
37
+ /**
38
+ * Memory limit to use before reverting to file cache
39
+ *
40
+ * @var integer
41
+ */
42
+ private $memoryCacheSize = null;
43
+
44
+ /**
45
+ * Store cell data in cache for the current cell object if it's "dirty",
46
+ * and the 'nullify' the current cell object
47
+ *
48
+ * @return void
49
+ * @throws PHPExcel_Exception
50
+ */
51
+ protected function storeData()
52
+ {
53
+ if ($this->currentCellIsDirty && !empty($this->currentObjectID)) {
54
+ $this->currentObject->detach();
55
+
56
+ fseek($this->fileHandle, 0, SEEK_END);
57
+
58
+ $this->cellCache[$this->currentObjectID] = array(
59
+ 'ptr' => ftell($this->fileHandle),
60
+ 'sz' => fwrite($this->fileHandle, serialize($this->currentObject))
61
+ );
62
+ $this->currentCellIsDirty = false;
63
+ }
64
+ $this->currentObjectID = $this->currentObject = null;
65
+ }
66
+
67
+
68
+ /**
69
+ * Add or Update a cell in cache identified by coordinate address
70
+ *
71
+ * @param string $pCoord Coordinate address of the cell to update
72
+ * @param PHPExcel_Cell $cell Cell to update
73
+ * @return PHPExcel_Cell
74
+ * @throws PHPExcel_Exception
75
+ */
76
+ public function addCacheData($pCoord, PHPExcel_Cell $cell)
77
+ {
78
+ if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) {
79
+ $this->storeData();
80
+ }
81
+
82
+ $this->currentObjectID = $pCoord;
83
+ $this->currentObject = $cell;
84
+ $this->currentCellIsDirty = true;
85
+
86
+ return $cell;
87
+ }
88
+
89
+
90
+ /**
91
+ * Get cell at a specific coordinate
92
+ *
93
+ * @param string $pCoord Coordinate of the cell
94
+ * @throws PHPExcel_Exception
95
+ * @return PHPExcel_Cell Cell that was found, or null if not found
96
+ */
97
+ public function getCacheData($pCoord)
98
+ {
99
+ if ($pCoord === $this->currentObjectID) {
100
+ return $this->currentObject;
101
+ }
102
+ $this->storeData();
103
+
104
+ // Check if the entry that has been requested actually exists
105
+ if (!isset($this->cellCache[$pCoord])) {
106
+ // Return null if requested entry doesn't exist in cache
107
+ return null;
108
+ }
109
+
110
+ // Set current entry to the requested entry
111
+ $this->currentObjectID = $pCoord;
112
+ fseek($this->fileHandle, $this->cellCache[$pCoord]['ptr']);
113
+ $this->currentObject = unserialize(fread($this->fileHandle, $this->cellCache[$pCoord]['sz']));
114
+ // Re-attach this as the cell's parent
115
+ $this->currentObject->attach($this);
116
+
117
+ // Return requested entry
118
+ return $this->currentObject;
119
+ }
120
+
121
+ /**
122
+ * Get a list of all cell addresses currently held in cache
123
+ *
124
+ * @return string[]
125
+ */
126
+ public function getCellList()
127
+ {
128
+ if ($this->currentObjectID !== null) {
129
+ $this->storeData();
130
+ }
131
+
132
+ return parent::getCellList();
133
+ }
134
+
135
+ /**
136
+ * Clone the cell collection
137
+ *
138
+ * @param PHPExcel_Worksheet $parent The new worksheet
139
+ * @return void
140
+ */
141
+ public function copyCellCollection(PHPExcel_Worksheet $parent)
142
+ {
143
+ parent::copyCellCollection($parent);
144
+ // Open a new stream for the cell cache data
145
+ $newFileHandle = fopen('php://temp/maxmemory:' . $this->memoryCacheSize, 'a+');
146
+ // Copy the existing cell cache data to the new stream
147
+ fseek($this->fileHandle, 0);
148
+ while (!feof($this->fileHandle)) {
149
+ fwrite($newFileHandle, fread($this->fileHandle, 1024));
150
+ }
151
+ $this->fileHandle = $newFileHandle;
152
+ }
153
+
154
+ /**
155
+ * Clear the cell collection and disconnect from our parent
156
+ *
157
+ * @return void
158
+ */
159
+ public function unsetWorksheetCells()
160
+ {
161
+ if (!is_null($this->currentObject)) {
162
+ $this->currentObject->detach();
163
+ $this->currentObject = $this->currentObjectID = null;
164
+ }
165
+ $this->cellCache = array();
166
+
167
+ // detach ourself from the worksheet, so that it can then delete this object successfully
168
+ $this->parent = null;
169
+
170
+ // Close down the php://temp file
171
+ $this->__destruct();
172
+ }
173
+
174
+ /**
175
+ * Initialise this new cell collection
176
+ *
177
+ * @param PHPExcel_Worksheet $parent The worksheet for this cell collection
178
+ * @param array of mixed $arguments Additional initialisation arguments
179
+ */
180
+ public function __construct(PHPExcel_Worksheet $parent, $arguments)
181
+ {
182
+ $this->memoryCacheSize = (isset($arguments['memoryCacheSize'])) ? $arguments['memoryCacheSize'] : '1MB';
183
+
184
+ parent::__construct($parent);
185
+ if (is_null($this->fileHandle)) {
186
+ $this->fileHandle = fopen('php://temp/maxmemory:' . $this->memoryCacheSize, 'a+');
187
+ }
188
+ }
189
+
190
+ /**
191
+ * Destroy this cell collection
192
+ */
193
+ public function __destruct()
194
+ {
195
+ if (!is_null($this->fileHandle)) {
196
+ fclose($this->fileHandle);
197
+ }
198
+ $this->fileHandle = null;
199
+ }
200
+ }
 
 
 
 
 
 
PHPExcel/Classes/PHPExcel/CachedObjectStorage/SQLite.php CHANGED
@@ -1,306 +1,307 @@
1
- <?php
2
- /**
3
- * PHPExcel
4
- *
5
- * Copyright (c) 2006 - 2014 PHPExcel
6
- *
7
- * This library is free software; you can redistribute it and/or
8
- * modify it under the terms of the GNU Lesser General Public
9
- * License as published by the Free Software Foundation; either
10
- * version 2.1 of the License, or (at your option) any later version.
11
- *
12
- * This library is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
- * Lesser General Public License for more details.
16
- *
17
- * You should have received a copy of the GNU Lesser General Public
18
- * License along with this library; if not, write to the Free Software
19
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
- *
21
- * @category PHPExcel
22
- * @package PHPExcel_CachedObjectStorage
23
- * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
24
- * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25
- * @version 1.8.0, 2014-03-02
26
- */
27
-
28
-
29
- /**
30
- * PHPExcel_CachedObjectStorage_SQLite
31
- *
32
- * @category PHPExcel
33
- * @package PHPExcel_CachedObjectStorage
34
- * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
35
- */
36
- class PHPExcel_CachedObjectStorage_SQLite extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {
37
-
38
- /**
39
- * Database table name
40
- *
41
- * @var string
42
- */
43
- private $_TableName = null;
44
-
45
- /**
46
- * Database handle
47
- *
48
- * @var resource
49
- */
50
- private $_DBHandle = null;
51
-
52
- /**
53
- * Store cell data in cache for the current cell object if it's "dirty",
54
- * and the 'nullify' the current cell object
55
- *
56
- * @return void
57
- * @throws PHPExcel_Exception
58
- */
59
- protected function _storeData() {
60
- if ($this->_currentCellIsDirty && !empty($this->_currentObjectID)) {
61
- $this->_currentObject->detach();
62
-
63
- if (!$this->_DBHandle->queryExec("INSERT OR REPLACE INTO kvp_".$this->_TableName." VALUES('".$this->_currentObjectID."','".sqlite_escape_string(serialize($this->_currentObject))."')"))
64
- throw new PHPExcel_Exception(sqlite_error_string($this->_DBHandle->lastError()));
65
- $this->_currentCellIsDirty = false;
66
- }
67
- $this->_currentObjectID = $this->_currentObject = null;
68
- } // function _storeData()
69
-
70
-
71
- /**
72
- * Add or Update a cell in cache identified by coordinate address
73
- *
74
- * @param string $pCoord Coordinate address of the cell to update
75
- * @param PHPExcel_Cell $cell Cell to update
76
- * @return void
77
- * @throws PHPExcel_Exception
78
- */
79
- public function addCacheData($pCoord, PHPExcel_Cell $cell) {
80
- if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) {
81
- $this->_storeData();
82
- }
83
-
84
- $this->_currentObjectID = $pCoord;
85
- $this->_currentObject = $cell;
86
- $this->_currentCellIsDirty = true;
87
-
88
- return $cell;
89
- } // function addCacheData()
90
-
91
-
92
- /**
93
- * Get cell at a specific coordinate
94
- *
95
- * @param string $pCoord Coordinate of the cell
96
- * @throws PHPExcel_Exception
97
- * @return PHPExcel_Cell Cell that was found, or null if not found
98
- */
99
- public function getCacheData($pCoord) {
100
- if ($pCoord === $this->_currentObjectID) {
101
- return $this->_currentObject;
102
- }
103
- $this->_storeData();
104
-
105
- $query = "SELECT value FROM kvp_".$this->_TableName." WHERE id='".$pCoord."'";
106
- $cellResultSet = $this->_DBHandle->query($query,SQLITE_ASSOC);
107
- if ($cellResultSet === false) {
108
- throw new PHPExcel_Exception(sqlite_error_string($this->_DBHandle->lastError()));
109
- } elseif ($cellResultSet->numRows() == 0) {
110
- // Return null if requested entry doesn't exist in cache
111
- return null;
112
- }
113
-
114
- // Set current entry to the requested entry
115
- $this->_currentObjectID = $pCoord;
116
-
117
- $cellResult = $cellResultSet->fetchSingle();
118
- $this->_currentObject = unserialize($cellResult);
119
- // Re-attach this as the cell's parent
120
- $this->_currentObject->attach($this);
121
-
122
- // Return requested entry
123
- return $this->_currentObject;
124
- } // function getCacheData()
125
-
126
-
127
- /**
128
- * Is a value set for an indexed cell?
129
- *
130
- * @param string $pCoord Coordinate address of the cell to check
131
- * @return boolean
132
- */
133
- public function isDataSet($pCoord) {
134
- if ($pCoord === $this->_currentObjectID) {
135
- return true;
136
- }
137
-
138
- // Check if the requested entry exists in the cache
139
- $query = "SELECT id FROM kvp_".$this->_TableName." WHERE id='".$pCoord."'";
140
- $cellResultSet = $this->_DBHandle->query($query,SQLITE_ASSOC);
141
- if ($cellResultSet === false) {
142
- throw new PHPExcel_Exception(sqlite_error_string($this->_DBHandle->lastError()));
143
- } elseif ($cellResultSet->numRows() == 0) {
144
- // Return null if requested entry doesn't exist in cache
145
- return false;
146
- }
147
- return true;
148
- } // function isDataSet()
149
-
150
-
151
- /**
152
- * Delete a cell in cache identified by coordinate address
153
- *
154
- * @param string $pCoord Coordinate address of the cell to delete
155
- * @throws PHPExcel_Exception
156
- */
157
- public function deleteCacheData($pCoord) {
158
- if ($pCoord === $this->_currentObjectID) {
159
- $this->_currentObject->detach();
160
- $this->_currentObjectID = $this->_currentObject = null;
161
- }
162
-
163
- // Check if the requested entry exists in the cache
164
- $query = "DELETE FROM kvp_".$this->_TableName." WHERE id='".$pCoord."'";
165
- if (!$this->_DBHandle->queryExec($query))
166
- throw new PHPExcel_Exception(sqlite_error_string($this->_DBHandle->lastError()));
167
-
168
- $this->_currentCellIsDirty = false;
169
- } // function deleteCacheData()
170
-
171
-
172
- /**
173
- * Move a cell object from one address to another
174
- *
175
- * @param string $fromAddress Current address of the cell to move
176
- * @param string $toAddress Destination address of the cell to move
177
- * @return boolean
178
- */
179
- public function moveCell($fromAddress, $toAddress) {
180
- if ($fromAddress === $this->_currentObjectID) {
181
- $this->_currentObjectID = $toAddress;
182
- }
183
-
184
- $query = "DELETE FROM kvp_".$this->_TableName." WHERE id='".$toAddress."'";
185
- $result = $this->_DBHandle->exec($query);
186
- if ($result === false)
187
- throw new PHPExcel_Exception($this->_DBHandle->lastErrorMsg());
188
-
189
- $query = "UPDATE kvp_".$this->_TableName." SET id='".$toAddress."' WHERE id='".$fromAddress."'";
190
- $result = $this->_DBHandle->exec($query);
191
- if ($result === false)
192
- throw new PHPExcel_Exception($this->_DBHandle->lastErrorMsg());
193
-
194
- return TRUE;
195
- } // function moveCell()
196
-
197
-
198
- /**
199
- * Get a list of all cell addresses currently held in cache
200
- *
201
- * @return array of string
202
- */
203
- public function getCellList() {
204
- if ($this->_currentObjectID !== null) {
205
- $this->_storeData();
206
- }
207
-
208
- $query = "SELECT id FROM kvp_".$this->_TableName;
209
- $cellIdsResult = $this->_DBHandle->unbufferedQuery($query,SQLITE_ASSOC);
210
- if ($cellIdsResult === false)
211
- throw new PHPExcel_Exception(sqlite_error_string($this->_DBHandle->lastError()));
212
-
213
- $cellKeys = array();
214
- foreach($cellIdsResult as $row) {
215
- $cellKeys[] = $row['id'];
216
- }
217
-
218
- return $cellKeys;
219
- } // function getCellList()
220
-
221
-
222
- /**
223
- * Clone the cell collection
224
- *
225
- * @param PHPExcel_Worksheet $parent The new worksheet
226
- * @return void
227
- */
228
- public function copyCellCollection(PHPExcel_Worksheet $parent) {
229
- $this->_currentCellIsDirty;
230
- $this->_storeData();
231
-
232
- // Get a new id for the new table name
233
- $tableName = str_replace('.','_',$this->_getUniqueID());
234
- if (!$this->_DBHandle->queryExec('CREATE TABLE kvp_'.$tableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB)
235
- AS SELECT * FROM kvp_'.$this->_TableName))
236
- throw new PHPExcel_Exception(sqlite_error_string($this->_DBHandle->lastError()));
237
-
238
- // Copy the existing cell cache file
239
- $this->_TableName = $tableName;
240
- } // function copyCellCollection()
241
-
242
-
243
- /**
244
- * Clear the cell collection and disconnect from our parent
245
- *
246
- * @return void
247
- */
248
- public function unsetWorksheetCells() {
249
- if(!is_null($this->_currentObject)) {
250
- $this->_currentObject->detach();
251
- $this->_currentObject = $this->_currentObjectID = null;
252
- }
253
- // detach ourself from the worksheet, so that it can then delete this object successfully
254
- $this->_parent = null;
255
-
256
- // Close down the temporary cache file
257
- $this->__destruct();
258
- } // function unsetWorksheetCells()
259
-
260
-
261
- /**
262
- * Initialise this new cell collection
263
- *
264
- * @param PHPExcel_Worksheet $parent The worksheet for this cell collection
265
- */
266
- public function __construct(PHPExcel_Worksheet $parent) {
267
- parent::__construct($parent);
268
- if (is_null($this->_DBHandle)) {
269
- $this->_TableName = str_replace('.','_',$this->_getUniqueID());
270
- $_DBName = ':memory:';
271
-
272
- $this->_DBHandle = new SQLiteDatabase($_DBName);
273
- if ($this->_DBHandle === false)
274
- throw new PHPExcel_Exception(sqlite_error_string($this->_DBHandle->lastError()));
275
- if (!$this->_DBHandle->queryExec('CREATE TABLE kvp_'.$this->_TableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB)'))
276
- throw new PHPExcel_Exception(sqlite_error_string($this->_DBHandle->lastError()));
277
- }
278
- } // function __construct()
279
-
280
-
281
- /**
282
- * Destroy this cell collection
283
- */
284
- public function __destruct() {
285
- if (!is_null($this->_DBHandle)) {
286
- $this->_DBHandle->queryExec('DROP TABLE kvp_'.$this->_TableName);
287
- }
288
- $this->_DBHandle = null;
289
- } // function __destruct()
290
-
291
-
292
- /**
293
- * Identify whether the caching method is currently available
294
- * Some methods are dependent on the availability of certain extensions being enabled in the PHP build
295
- *
296
- * @return boolean
297
- */
298
- public static function cacheMethodIsAvailable() {
299
- if (!function_exists('sqlite_open')) {
300
- return false;
301
- }
302
-
303
- return true;
304
- }
305
-
306
- }
 
1
+ <?php
2
+
3
+ /**
4
+ * PHPExcel_CachedObjectStorage_SQLite
5
+ *
6
+ * Copyright (c) 2006 - 2015 PHPExcel
7
+ *
8
+ * This library is free software; you can redistribute it and/or
9
+ * modify it under the terms of the GNU Lesser General Public
10
+ * License as published by the Free Software Foundation; either
11
+ * version 2.1 of the License, or (at your option) any later version.
12
+ *
13
+ * This library is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
+ * Lesser General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU Lesser General Public
19
+ * License along with this library; if not, write to the Free Software
20
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
+ *
22
+ * @category PHPExcel
23
+ * @package PHPExcel_CachedObjectStorage
24
+ * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
25
+ * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
26
+ * @version ##VERSION##, ##DATE##
27
+ */
28
+ class PHPExcel_CachedObjectStorage_SQLite extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache
29
+ {
30
+ /**
31
+ * Database table name
32
+ *
33
+ * @var string
34
+ */
35
+ private $TableName = null;
36
+
37
+ /**
38
+ * Database handle
39
+ *
40
+ * @var resource
41
+ */
42
+ private $DBHandle = null;
43
+
44
+ /**
45
+ * Store cell data in cache for the current cell object if it's "dirty",
46
+ * and the 'nullify' the current cell object
47
+ *
48
+ * @return void
49
+ * @throws PHPExcel_Exception
50
+ */
51
+ protected function storeData()
52
+ {
53
+ if ($this->currentCellIsDirty && !empty($this->currentObjectID)) {
54
+ $this->currentObject->detach();
55
+
56
+ if (!$this->DBHandle->queryExec("INSERT OR REPLACE INTO kvp_".$this->TableName." VALUES('".$this->currentObjectID."','".sqlite_escape_string(serialize($this->currentObject))."')")) {
57
+ throw new PHPExcel_Exception(sqlite_error_string($this->DBHandle->lastError()));
58
+ }
59
+ $this->currentCellIsDirty = false;
60
+ }
61
+ $this->currentObjectID = $this->currentObject = null;
62
+ }
63
+
64
+ /**
65
+ * Add or Update a cell in cache identified by coordinate address
66
+ *
67
+ * @param string $pCoord Coordinate address of the cell to update
68
+ * @param PHPExcel_Cell $cell Cell to update
69
+ * @return PHPExcel_Cell
70
+ * @throws PHPExcel_Exception
71
+ */
72
+ public function addCacheData($pCoord, PHPExcel_Cell $cell)
73
+ {
74
+ if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) {
75
+ $this->storeData();
76
+ }
77
+
78
+ $this->currentObjectID = $pCoord;
79
+ $this->currentObject = $cell;
80
+ $this->currentCellIsDirty = true;
81
+
82
+ return $cell;
83
+ }
84
+
85
+ /**
86
+ * Get cell at a specific coordinate
87
+ *
88
+ * @param string $pCoord Coordinate of the cell
89
+ * @throws PHPExcel_Exception
90
+ * @return PHPExcel_Cell Cell that was found, or null if not found
91
+ */
92
+ public function getCacheData($pCoord)
93
+ {
94
+ if ($pCoord === $this->currentObjectID) {
95
+ return $this->currentObject;
96
+ }
97
+ $this->storeData();
98
+
99
+ $query = "SELECT value FROM kvp_".$this->TableName." WHERE id='".$pCoord."'";
100
+ $cellResultSet = $this->DBHandle->query($query, SQLITE_ASSOC);
101
+ if ($cellResultSet === false) {
102
+ throw new PHPExcel_Exception(sqlite_error_string($this->DBHandle->lastError()));
103
+ } elseif ($cellResultSet->numRows() == 0) {
104
+ // Return null if requested entry doesn't exist in cache
105
+ return null;
106
+ }
107
+
108
+ // Set current entry to the requested entry
109
+ $this->currentObjectID = $pCoord;
110
+
111
+ $cellResult = $cellResultSet->fetchSingle();
112
+ $this->currentObject = unserialize($cellResult);
113
+ // Re-attach this as the cell's parent
114
+ $this->currentObject->attach($this);
115
+
116
+ // Return requested entry
117
+ return $this->currentObject;
118
+ }
119
+
120
+ /**
121
+ * Is a value set for an indexed cell?
122
+ *
123
+ * @param string $pCoord Coordinate address of the cell to check
124
+ * @return boolean
125
+ */
126
+ public function isDataSet($pCoord)
127
+ {
128
+ if ($pCoord === $this->currentObjectID) {
129
+ return true;
130
+ }
131
+
132
+ // Check if the requested entry exists in the cache
133
+ $query = "SELECT id FROM kvp_".$this->TableName." WHERE id='".$pCoord."'";
134
+ $cellResultSet = $this->DBHandle->query($query, SQLITE_ASSOC);
135
+ if ($cellResultSet === false) {
136
+ throw new PHPExcel_Exception(sqlite_error_string($this->DBHandle->lastError()));
137
+ } elseif ($cellResultSet->numRows() == 0) {
138
+ // Return null if requested entry doesn't exist in cache
139
+ return false;
140
+ }
141
+ return true;
142
+ }
143
+
144
+ /**
145
+ * Delete a cell in cache identified by coordinate address
146
+ *
147
+ * @param string $pCoord Coordinate address of the cell to delete
148
+ * @throws PHPExcel_Exception
149
+ */
150
+ public function deleteCacheData($pCoord)
151
+ {
152
+ if ($pCoord === $this->currentObjectID) {
153
+ $this->currentObject->detach();
154
+ $this->currentObjectID = $this->currentObject = null;
155
+ }
156
+
157
+ // Check if the requested entry exists in the cache
158
+ $query = "DELETE FROM kvp_".$this->TableName." WHERE id='".$pCoord."'";
159
+ if (!$this->DBHandle->queryExec($query)) {
160
+ throw new PHPExcel_Exception(sqlite_error_string($this->DBHandle->lastError()));
161
+ }
162
+
163
+ $this->currentCellIsDirty = false;
164
+ }
165
+
166
+ /**
167
+ * Move a cell object from one address to another
168
+ *
169
+ * @param string $fromAddress Current address of the cell to move
170
+ * @param string $toAddress Destination address of the cell to move
171
+ * @return boolean
172
+ */
173
+ public function moveCell($fromAddress, $toAddress)
174
+ {
175
+ if ($fromAddress === $this->currentObjectID) {
176
+ $this->currentObjectID = $toAddress;
177
+ }
178
+
179
+ $query = "DELETE FROM kvp_".$this->TableName." WHERE id='".$toAddress."'";
180
+ $result = $this->DBHandle->exec($query);
181
+ if ($result === false) {
182
+ throw new PHPExcel_Exception($this->DBHandle->lastErrorMsg());
183
+ }
184
+
185
+ $query = "UPDATE kvp_".$this->TableName." SET id='".$toAddress."' WHERE id='".$fromAddress."'";
186
+ $result = $this->DBHandle->exec($query);
187
+ if ($result === false) {
188
+ throw new PHPExcel_Exception($this->DBHandle->lastErrorMsg());
189
+ }
190
+
191
+ return true;
192
+ }
193
+
194
+ /**
195
+ * Get a list of all cell addresses currently held in cache
196
+ *
197
+ * @return string[]
198
+ */
199
+ public function getCellList()
200
+ {
201
+ if ($this->currentObjectID !== null) {
202
+ $this->storeData();
203
+ }
204
+
205
+ $query = "SELECT id FROM kvp_".$this->TableName;
206
+ $cellIdsResult = $this->DBHandle->unbufferedQuery($query, SQLITE_ASSOC);
207
+ if ($cellIdsResult === false) {
208
+ throw new PHPExcel_Exception(sqlite_error_string($this->DBHandle->lastError()));
209
+ }
210
+
211
+ $cellKeys = array();
212
+ foreach ($cellIdsResult as $row) {
213
+ $cellKeys[] = $row['id'];
214
+ }
215
+
216
+ return $cellKeys;
217
+ }
218
+
219
+ /**
220
+ * Clone the cell collection
221
+ *
222
+ * @param PHPExcel_Worksheet $parent The new worksheet
223
+ * @return void
224
+ */
225
+ public function copyCellCollection(PHPExcel_Worksheet $parent)
226
+ {
227
+ $this->currentCellIsDirty;
228
+ $this->storeData();
229
+
230
+ // Get a new id for the new table name
231
+ $tableName = str_replace('.', '_', $this->getUniqueID());
232
+ if (!$this->DBHandle->queryExec('CREATE TABLE kvp_'.$tableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB)
233
+ AS SELECT * FROM kvp_'.$this->TableName)
234
+ ) {
235
+ throw new PHPExcel_Exception(sqlite_error_string($this->DBHandle->lastError()));
236
+ }
237
+
238
+ // Copy the existing cell cache file
239
+ $this->TableName = $tableName;
240
+ }
241
+
242
+ /**
243
+ * Clear the cell collection and disconnect from our parent
244
+ *
245
+ * @return void
246
+ */
247
+ public function unsetWorksheetCells()
248
+ {
249
+ if (!is_null($this->currentObject)) {
250
+ $this->currentObject->detach();
251
+ $this->currentObject = $this->currentObjectID = null;
252
+ }
253
+ // detach ourself from the worksheet, so that it can then delete this object successfully
254
+ $this->parent = null;
255
+
256
+ // Close down the temporary cache file
257
+ $this->__destruct();
258
+ }
259
+
260
+ /**
261
+ * Initialise this new cell collection
262
+ *
263
+ * @param PHPExcel_Worksheet $parent The worksheet for this cell collection
264
+ */
265
+ public function __construct(PHPExcel_Worksheet $parent)
266
+ {
267
+ parent::__construct($parent);
268
+ if (is_null($this->DBHandle)) {
269
+ $this->TableName = str_replace('.', '_', $this->getUniqueID());
270
+ $_DBName = ':memory:';
271
+
272
+ $this->DBHandle = new SQLiteDatabase($_DBName);
273
+ if ($this->DBHandle === false) {
274
+ throw new PHPExcel_Exception(sqlite_error_string($this->DBHandle->lastError()));
275
+ }
276
+ if (!$this->DBHandle->queryExec('CREATE TABLE kvp_'.$this->TableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB)')) {
277
+ throw new PHPExcel_Exception(sqlite_error_string($this->DBHandle->lastError()));
278
+ }
279
+ }
280
+ }
281
+
282
+ /**
283
+ * Destroy this cell collection
284
+ */
285
+ public function __destruct()
286
+ {
287
+ if (!is_null($this->DBHandle)) {
288
+ $this->DBHandle->queryExec('DROP TABLE kvp_'.$this->TableName);
289
+ }
290
+ $this->DBHandle = null;
291
+ }
292
+
293
+ /**
294
+ * Identify whether the caching method is currently available
295
+ * Some methods are dependent on the availability of certain extensions being enabled in the PHP build
296
+ *
297
+ * @return boolean
298
+ */
299
+ public static function cacheMethodIsAvailable()
300
+ {
301
+ if (!function_exists('sqlite_open')) {
302
+ return false;
303
+ }
304
+
305
+ return true;
306
+ }
307
+ }
PHPExcel/Classes/PHPExcel/CachedObjectStorage/SQLite3.php CHANGED
@@ -1,345 +1,346 @@
1
- <?php
2
- /**
3
- * PHPExcel
4
- *
5
- * Copyright (c) 2006 - 2014 PHPExcel
6
- *
7
- * This library is free software; you can redistribute it and/or
8
- * modify it under the terms of the GNU Lesser General Public
9
- * License as published by the Free Software Foundation; either
10
- * version 2.1 of the License, or (at your option) any later version.
11
- *
12
- * This library is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
- * Lesser General Public License for more details.
16
- *
17
- * You should have received a copy of the GNU Lesser General Public
18
- * License along with this library; if not, write to the Free Software
19
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
- *
21
- * @category PHPExcel
22
- * @package PHPExcel_CachedObjectStorage
23
- * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
24
- * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25
- * @version 1.8.0, 2014-03-02
26
- */
27
-
28
-
29
- /**
30
- * PHPExcel_CachedObjectStorage_SQLite3
31
- *
32
- * @category PHPExcel
33
- * @package PHPExcel_CachedObjectStorage
34
- * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
35
- */
36
- class PHPExcel_CachedObjectStorage_SQLite3 extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {
37
-
38
- /**
39
- * Database table name
40
- *
41
- * @var string
42
- */
43
- private $_TableName = null;
44
-
45
- /**
46
- * Database handle
47
- *
48
- * @var resource
49
- */
50
- private $_DBHandle = null;
51
-
52
- /**
53
- * Prepared statement for a SQLite3 select query
54
- *
55
- * @var SQLite3Stmt
56
- */
57
- private $_selectQuery;
58
-
59
- /**
60
- * Prepared statement for a SQLite3 insert query
61
- *
62
- * @var SQLite3Stmt
63
- */
64
- private $_insertQuery;
65
-
66
- /**
67
- * Prepared statement for a SQLite3 update query
68
- *
69
- * @var SQLite3Stmt
70
- */
71
- private $_updateQuery;
72
-
73
- /**
74
- * Prepared statement for a SQLite3 delete query
75
- *
76
- * @var SQLite3Stmt
77
- */
78
- private $_deleteQuery;
79
-
80
- /**
81
- * Store cell data in cache for the current cell object if it's "dirty",
82
- * and the 'nullify' the current cell object
83
- *
84
- * @return void
85
- * @throws PHPExcel_Exception
86
- */
87
- protected function _storeData() {
88
- if ($this->_currentCellIsDirty && !empty($this->_currentObjectID)) {
89
- $this->_currentObject->detach();
90
-
91
- $this->_insertQuery->bindValue('id',$this->_currentObjectID,SQLITE3_TEXT);
92
- $this->_insertQuery->bindValue('data',serialize($this->_currentObject),SQLITE3_BLOB);
93
- $result = $this->_insertQuery->execute();
94
- if ($result === false)
95
- throw new PHPExcel_Exception($this->_DBHandle->lastErrorMsg());
96
- $this->_currentCellIsDirty = false;
97
- }
98
- $this->_currentObjectID = $this->_currentObject = null;
99
- } // function _storeData()
100
-
101
-
102
- /**
103
- * Add or Update a cell in cache identified by coordinate address
104
- *
105
- * @param string $pCoord Coordinate address of the cell to update
106
- * @param PHPExcel_Cell $cell Cell to update
107
- * @return void
108
- * @throws PHPExcel_Exception
109
- */
110
- public function addCacheData($pCoord, PHPExcel_Cell $cell) {
111
- if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) {
112
- $this->_storeData();
113
- }
114
-
115
- $this->_currentObjectID = $pCoord;
116
- $this->_currentObject = $cell;
117
- $this->_currentCellIsDirty = true;
118
-
119
- return $cell;
120
- } // function addCacheData()
121
-
122
-
123
- /**
124
- * Get cell at a specific coordinate
125
- *
126
- * @param string $pCoord Coordinate of the cell
127
- * @throws PHPExcel_Exception
128
- * @return PHPExcel_Cell Cell that was found, or null if not found
129
- */
130
- public function getCacheData($pCoord) {
131
- if ($pCoord === $this->_currentObjectID) {
132
- return $this->_currentObject;
133
- }
134
- $this->_storeData();
135
-
136
- $this->_selectQuery->bindValue('id',$pCoord,SQLITE3_TEXT);
137
- $cellResult = $this->_selectQuery->execute();
138
- if ($cellResult === FALSE) {
139
- throw new PHPExcel_Exception($this->_DBHandle->lastErrorMsg());
140
- }
141
- $cellData = $cellResult->fetchArray(SQLITE3_ASSOC);
142
- if ($cellData === FALSE) {
143
- // Return null if requested entry doesn't exist in cache
144
- return NULL;
145
- }
146
-
147
- // Set current entry to the requested entry
148
- $this->_currentObjectID = $pCoord;
149
-
150
- $this->_currentObject = unserialize($cellData['value']);
151
- // Re-attach this as the cell's parent
152
- $this->_currentObject->attach($this);
153
-
154
- // Return requested entry
155
- return $this->_currentObject;
156
- } // function getCacheData()
157
-
158
-
159
- /**
160
- * Is a value set for an indexed cell?
161
- *
162
- * @param string $pCoord Coordinate address of the cell to check
163
- * @return boolean
164
- */
165
- public function isDataSet($pCoord) {
166
- if ($pCoord === $this->_currentObjectID) {
167
- return TRUE;
168
- }
169
-
170
- // Check if the requested entry exists in the cache
171
- $this->_selectQuery->bindValue('id',$pCoord,SQLITE3_TEXT);
172
- $cellResult = $this->_selectQuery->execute();
173
- if ($cellResult === FALSE) {
174
- throw new PHPExcel_Exception($this->_DBHandle->lastErrorMsg());
175
- }
176
- $cellData = $cellResult->fetchArray(SQLITE3_ASSOC);
177
-
178
- return ($cellData === FALSE) ? FALSE : TRUE;
179
- } // function isDataSet()
180
-
181
-
182
- /**
183
- * Delete a cell in cache identified by coordinate address
184
- *
185
- * @param string $pCoord Coordinate address of the cell to delete
186
- * @throws PHPExcel_Exception
187
- */
188
- public function deleteCacheData($pCoord) {
189
- if ($pCoord === $this->_currentObjectID) {
190
- $this->_currentObject->detach();
191
- $this->_currentObjectID = $this->_currentObject = NULL;
192
- }
193
-
194
- // Check if the requested entry exists in the cache
195
- $this->_deleteQuery->bindValue('id',$pCoord,SQLITE3_TEXT);
196
- $result = $this->_deleteQuery->execute();
197
- if ($result === FALSE)
198
- throw new PHPExcel_Exception($this->_DBHandle->lastErrorMsg());
199
-
200
- $this->_currentCellIsDirty = FALSE;
201
- } // function deleteCacheData()
202
-
203
-
204
- /**
205
- * Move a cell object from one address to another
206
- *
207
- * @param string $fromAddress Current address of the cell to move
208
- * @param string $toAddress Destination address of the cell to move
209
- * @return boolean
210
- */
211
- public function moveCell($fromAddress, $toAddress) {
212
- if ($fromAddress === $this->_currentObjectID) {
213
- $this->_currentObjectID = $toAddress;
214
- }
215
-
216
- $this->_deleteQuery->bindValue('id',$toAddress,SQLITE3_TEXT);
217
- $result = $this->_deleteQuery->execute();
218
- if ($result === false)
219
- throw new PHPExcel_Exception($this->_DBHandle->lastErrorMsg());
220
-
221
- $this->_updateQuery->bindValue('toid',$toAddress,SQLITE3_TEXT);
222
- $this->_updateQuery->bindValue('fromid',$fromAddress,SQLITE3_TEXT);
223
- $result = $this->_updateQuery->execute();
224
- if ($result === false)
225
- throw new PHPExcel_Exception($this->_DBHandle->lastErrorMsg());
226
-
227
- return TRUE;
228
- } // function moveCell()
229
-
230
-
231
- /**
232
- * Get a list of all cell addresses currently held in cache
233
- *
234
- * @return array of string
235
- */
236
- public function getCellList() {
237
- if ($this->_currentObjectID !== null) {
238
- $this->_storeData();
239
- }
240
-
241
- $query = "SELECT id FROM kvp_".$this->_TableName;
242
- $cellIdsResult = $this->_DBHandle->query($query);
243
- if ($cellIdsResult === false)
244
- throw new PHPExcel_Exception($this->_DBHandle->lastErrorMsg());
245
-
246
- $cellKeys = array();
247
- while ($row = $cellIdsResult->fetchArray(SQLITE3_ASSOC)) {
248
- $cellKeys[] = $row['id'];
249
- }
250
-
251
- return $cellKeys;
252
- } // function getCellList()
253
-
254
-
255
- /**
256
- * Clone the cell collection
257
- *
258
- * @param PHPExcel_Worksheet $parent The new worksheet
259
- * @return void
260
- */
261
- public function copyCellCollection(PHPExcel_Worksheet $parent) {
262
- $this->_currentCellIsDirty;
263
- $this->_storeData();
264
-
265
- // Get a new id for the new table name
266
- $tableName = str_replace('.','_',$this->_getUniqueID());
267
- if (!$this->_DBHandle->exec('CREATE TABLE kvp_'.$tableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB)
268
- AS SELECT * FROM kvp_'.$this->_TableName))
269
- throw new PHPExcel_Exception($this->_DBHandle->lastErrorMsg());
270
-
271
- // Copy the existing cell cache file
272
- $this->_TableName = $tableName;
273
- } // function copyCellCollection()
274
-
275
-
276
- /**
277
- * Clear the cell collection and disconnect from our parent
278
- *
279
- * @return void
280
- */
281
- public function unsetWorksheetCells() {
282
- if(!is_null($this->_currentObject)) {
283
- $this->_currentObject->detach();
284
- $this->_currentObject = $this->_currentObjectID = null;
285
- }
286
- // detach ourself from the worksheet, so that it can then delete this object successfully
287
- $this->_parent = null;
288
-
289
- // Close down the temporary cache file
290
- $this->__destruct();
291
- } // function unsetWorksheetCells()
292
-
293
-
294
- /**
295
- * Initialise this new cell collection
296
- *
297
- * @param PHPExcel_Worksheet $parent The worksheet for this cell collection
298
- */
299
- public function __construct(PHPExcel_Worksheet $parent) {
300
- parent::__construct($parent);
301
- if (is_null($this->_DBHandle)) {
302
- $this->_TableName = str_replace('.','_',$this->_getUniqueID());
303
- $_DBName = ':memory:';
304
-
305
- $this->_DBHandle = new SQLite3($_DBName);
306
- if ($this->_DBHandle === false)
307
- throw new PHPExcel_Exception($this->_DBHandle->lastErrorMsg());
308
- if (!$this->_DBHandle->exec('CREATE TABLE kvp_'.$this->_TableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB)'))
309
- throw new PHPExcel_Exception($this->_DBHandle->lastErrorMsg());
310
- }
311
-
312
- $this->_selectQuery = $this->_DBHandle->prepare("SELECT value FROM kvp_".$this->_TableName." WHERE id = :id");
313
- $this->_insertQuery = $this->_DBHandle->prepare("INSERT OR REPLACE INTO kvp_".$this->_TableName." VALUES(:id,:data)");
314
- $this->_updateQuery = $this->_DBHandle->prepare("UPDATE kvp_".$this->_TableName." SET id=:toId WHERE id=:fromId");
315
- $this->_deleteQuery = $this->_DBHandle->prepare("DELETE FROM kvp_".$this->_TableName." WHERE id = :id");
316
- } // function __construct()
317
-
318
-
319
- /**
320
- * Destroy this cell collection
321
- */
322
- public function __destruct() {
323
- if (!is_null($this->_DBHandle)) {
324
- $this->_DBHandle->exec('DROP TABLE kvp_'.$this->_TableName);
325
- $this->_DBHandle->close();
326
- }
327
- $this->_DBHandle = null;
328
- } // function __destruct()
329
-
330
-
331
- /**
332
- * Identify whether the caching method is currently available
333
- * Some methods are dependent on the availability of certain extensions being enabled in the PHP build
334
- *
335
- * @return boolean
336
- */
337
- public static function cacheMethodIsAvailable() {
338
- if (!class_exists('SQLite3',FALSE)) {
339
- return false;
340
- }
341
-
342
- return true;
343
- }
344
-
345
- }
 
1
+ <?php
2
+
3
+ /**
4
+ * PHPExcel_CachedObjectStorage_SQLite3
5
+ *
6
+ * Copyright (c) 2006 - 2015 PHPExcel
7
+ *
8
+ * This library is free software; you can redistribute it and/or
9
+ * modify it under the terms of the GNU Lesser General Public
10
+ * License as published by the Free Software Foundation; either
11
+ * version 2.1 of the License, or (at your option) any later version.
12
+ *
13
+ * This library is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
+ * Lesser General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU Lesser General Public
19
+ * License along with this library; if not, write to the Free Software
20
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
+ *
22
+ * @category PHPExcel
23
+ * @package PHPExcel_CachedObjectStorage
24
+ * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
25
+ * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
26
+ * @version ##VERSION##, ##DATE##
27
+ */
28
+ class PHPExcel_CachedObjectStorage_SQLite3 extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache
29
+ {
30
+ /**
31
+ * Database table name
32
+ *
33
+ * @var string
34
+ */
35
+ private $TableName = null;
36
+
37
+ /**
38
+ * Database handle
39
+ *
40
+ * @var resource
41
+ */
42
+ private $DBHandle = null;
43
+
44
+ /**
45
+ * Prepared statement for a SQLite3 select query
46
+ *
47
+ * @var SQLite3Stmt
48
+ */
49
+ private $selectQuery;
50
+
51
+ /**
52
+ * Prepared statement for a SQLite3 insert query
53
+ *
54
+ * @var SQLite3Stmt
55
+ */
56
+ private $insertQuery;
57
+
58
+ /**
59
+ * Prepared statement for a SQLite3 update query
60
+ *
61
+ * @var SQLite3Stmt
62
+ */
63
+ private $updateQuery;
64
+
65
+ /**
66
+ * Prepared statement for a SQLite3 delete query
67
+ *
68
+ * @var SQLite3Stmt
69
+ */
70
+ private $deleteQuery;
71
+
72
+ /**
73
+ * Store cell data in cache for the current cell object if it's "dirty",
74
+ * and the 'nullify' the current cell object
75
+ *
76
+ * @return void
77
+ * @throws PHPExcel_Exception
78
+ */
79
+ protected function storeData()
80
+ {
81
+ if ($this->currentCellIsDirty && !empty($this->currentObjectID)) {
82
+ $this->currentObject->detach();
83
+
84
+ $this->insertQuery->bindValue('id', $this->currentObjectID, SQLITE3_TEXT);
85
+ $this->insertQuery->bindValue('data', serialize($this->currentObject), SQLITE3_BLOB);
86
+ $result = $this->insertQuery->execute();
87
+ if ($result === false) {
88
+ throw new PHPExcel_Exception($this->DBHandle->lastErrorMsg());
89
+ }
90
+ $this->currentCellIsDirty = false;
91
+ }
92
+ $this->currentObjectID = $this->currentObject = null;
93
+ }
94
+
95
+ /**
96
+ * Add or Update a cell in cache identified by coordinate address
97
+ *
98
+ * @param string $pCoord Coordinate address of the cell to update
99
+ * @param PHPExcel_Cell $cell Cell to update
100
+ * @return PHPExcel_Cell
101
+ * @throws PHPExcel_Exception
102
+ */
103
+ public function addCacheData($pCoord, PHPExcel_Cell $cell)
104
+ {
105
+ if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) {
106
+ $this->storeData();
107
+ }
108
+
109
+ $this->currentObjectID = $pCoord;
110
+ $this->currentObject = $cell;
111
+ $this->currentCellIsDirty = true;
112
+
113
+ return $cell;
114
+ }
115
+
116
+ /**
117
+ * Get cell at a specific coordinate
118
+ *
119
+ * @param string $pCoord Coordinate of the cell
120
+ * @throws PHPExcel_Exception
121
+ * @return PHPExcel_Cell Cell that was found, or null if not found
122
+ */
123
+ public function getCacheData($pCoord)
124
+ {
125
+ if ($pCoord === $this->currentObjectID) {
126
+ return $this->currentObject;
127
+ }
128
+ $this->storeData();
129
+
130
+ $this->selectQuery->bindValue('id', $pCoord, SQLITE3_TEXT);
131
+ $cellResult = $this->selectQuery->execute();
132
+ if ($cellResult === false) {
133
+ throw new PHPExcel_Exception($this->DBHandle->lastErrorMsg());
134
+ }
135
+ $cellData = $cellResult->fetchArray(SQLITE3_ASSOC);
136
+ if ($cellData === false) {
137
+ // Return null if requested entry doesn't exist in cache
138
+ return null;
139
+ }
140
+
141
+ // Set current entry to the requested entry
142
+ $this->currentObjectID = $pCoord;
143
+
144
+ $this->currentObject = unserialize($cellData['value']);
145
+ // Re-attach this as the cell's parent
146
+ $this->currentObject->attach($this);
147
+
148
+ // Return requested entry
149
+ return $this->currentObject;
150
+ }
151
+
152
+ /**
153
+ * Is a value set for an indexed cell?
154
+ *
155
+ * @param string $pCoord Coordinate address of the cell to check
156
+ * @return boolean
157
+ */
158
+ public function isDataSet($pCoord)
159
+ {
160
+ if ($pCoord === $this->currentObjectID) {
161
+ return true;
162
+ }
163
+
164
+ // Check if the requested entry exists in the cache
165
+ $this->selectQuery->bindValue('id', $pCoord, SQLITE3_TEXT);
166
+ $cellResult = $this->selectQuery->execute();
167
+ if ($cellResult === false) {
168
+ throw new PHPExcel_Exception($this->DBHandle->lastErrorMsg());
169
+ }
170
+ $cellData = $cellResult->fetchArray(SQLITE3_ASSOC);
171
+
172
+ return ($cellData === false) ? false : true;
173
+ }
174
+
175
+ /**
176
+ * Delete a cell in cache identified by coordinate address
177
+ *
178
+ * @param string $pCoord Coordinate address of the cell to delete
179
+ * @throws PHPExcel_Exception
180
+ */
181
+ public function deleteCacheData($pCoord)
182
+ {
183
+ if ($pCoord === $this->currentObjectID) {
184
+ $this->currentObject->detach();
185
+ $this->currentObjectID = $this->currentObject = null;
186
+ }
187
+
188
+ // Check if the requested entry exists in the cache
189
+ $this->deleteQuery->bindValue('id', $pCoord, SQLITE3_TEXT);
190
+ $result = $this->deleteQuery->execute();
191
+ if ($result === false) {
192
+ throw new PHPExcel_Exception($this->DBHandle->lastErrorMsg());
193
+ }
194
+
195
+ $this->currentCellIsDirty = false;
196
+ }
197
+
198
+ /**
199
+ * Move a cell object from one address to another
200
+ *
201
+ * @param string $fromAddress Current address of the cell to move
202
+ * @param string $toAddress Destination address of the cell to move
203
+ * @return boolean
204
+ */
205
+ public function moveCell($fromAddress, $toAddress)
206
+ {
207
+ if ($fromAddress === $this->currentObjectID) {
208
+ $this->currentObjectID = $toAddress;
209
+ }
210
+
211
+ $this->deleteQuery->bindValue('id', $toAddress, SQLITE3_TEXT);
212
+ $result = $this->deleteQuery->execute();
213
+ if ($result === false) {
214
+ throw new PHPExcel_Exception($this->DBHandle->lastErrorMsg());
215
+ }
216
+
217
+ $this->updateQuery->bindValue('toid', $toAddress, SQLITE3_TEXT);
218
+ $this->updateQuery->bindValue('fromid', $fromAddress, SQLITE3_TEXT);
219
+ $result = $this->updateQuery->execute();
220
+ if ($result === false) {
221
+ throw new PHPExcel_Exception($this->DBHandle->lastErrorMsg());
222
+ }
223
+
224
+ return true;
225
+ }
226
+
227
+ /**
228
+ * Get a list of all cell addresses currently held in cache
229
+ *
230
+ * @return string[]
231
+ */
232
+ public function getCellList()
233
+ {
234
+ if ($this->currentObjectID !== null) {
235
+ $this->storeData();
236
+ }
237
+
238
+ $query = "SELECT id FROM kvp_".$this->TableName;
239
+ $cellIdsResult = $this->DBHandle->query($query);
240
+ if ($cellIdsResult === false) {
241
+ throw new PHPExcel_Exception($this->DBHandle->lastErrorMsg());
242
+ }
243
+
244
+ $cellKeys = array();
245
+ while ($row = $cellIdsResult->fetchArray(SQLITE3_ASSOC)) {
246
+ $cellKeys[] = $row['id'];
247
+ }
248
+
249
+ return $cellKeys;
250
+ }
251
+
252
+ /**
253
+ * Clone the cell collection
254
+ *
255
+ * @param PHPExcel_Worksheet $parent The new worksheet
256
+ * @return void
257
+ */
258
+ public function copyCellCollection(PHPExcel_Worksheet $parent)
259
+ {
260
+ $this->currentCellIsDirty;
261
+ $this->storeData();
262
+
263
+ // Get a new id for the new table name
264
+ $tableName = str_replace('.', '_', $this->getUniqueID());
265
+ if (!$this->DBHandle->exec('CREATE TABLE kvp_'.$tableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB)
266
+ AS SELECT * FROM kvp_'.$this->TableName)
267
+ ) {
268
+ throw new PHPExcel_Exception($this->DBHandle->lastErrorMsg());
269
+ }
270
+
271
+ // Copy the existing cell cache file
272
+ $this->TableName = $tableName;
273
+ }
274
+
275
+ /**
276
+ * Clear the cell collection and disconnect from our parent
277
+ *
278
+ * @return void
279
+ */
280
+ public function unsetWorksheetCells()
281
+ {
282
+ if (!is_null($this->currentObject)) {
283
+ $this->currentObject->detach();
284
+ $this->currentObject = $this->currentObjectID = null;
285
+ }
286
+ // detach ourself from the worksheet, so that it can then delete this object successfully
287
+ $this->parent = null;
288
+
289
+ // Close down the temporary cache file
290
+ $this->__destruct();
291
+ }
292
+
293
+ /**
294
+ * Initialise this new cell collection
295
+ *
296
+ * @param PHPExcel_Worksheet $parent The worksheet for this cell collection
297
+ */
298
+ public function __construct(PHPExcel_Worksheet $parent)
299
+ {
300
+ parent::__construct($parent);
301
+ if (is_null($this->DBHandle)) {
302
+ $this->TableName = str_replace('.', '_', $this->getUniqueID());
303
+ $_DBName = ':memory:';
304
+
305
+ $this->DBHandle = new SQLite3($_DBName);
306
+ if ($this->DBHandle === false) {
307
+ throw new PHPExcel_Exception($this->DBHandle->lastErrorMsg());
308
+ }
309
+ if (!$this->DBHandle->exec('CREATE TABLE kvp_'.$this->TableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB)')) {
310
+ throw new PHPExcel_Exception($this->DBHandle->lastErrorMsg());
311
+ }
312
+ }
313
+
314
+ $this->selectQuery = $this->DBHandle->prepare("SELECT value FROM kvp_".$this->TableName." WHERE id = :id");
315
+ $this->insertQuery = $this->DBHandle->prepare("INSERT OR REPLACE INTO kvp_".$this->TableName." VALUES(:id,:data)");
316
+ $this->updateQuery = $this->DBHandle->prepare("UPDATE kvp_".$this->TableName." SET id=:toId WHERE id=:fromId");
317
+ $this->deleteQuery = $this->DBHandle->prepare("DELETE FROM kvp_".$this->TableName." WHERE id = :id");
318
+ }
319
+
320
+ /**
321
+ * Destroy this cell collection
322
+ */
323
+ public function __destruct()
324
+ {
325
+ if (!is_null($this->DBHandle)) {
326
+ $this->DBHandle->exec('DROP TABLE kvp_'.$this->TableName);
327
+ $this->DBHandle->close();
328
+ }
329
+ $this->DBHandle = null;
330
+ }
331
+
332
+ /**
333
+ * Identify whether the caching method is currently available
334
+ * Some methods are dependent on the availability of certain extensions being enabled in the PHP build
335
+ *
336
+ * @return boolean
337
+ */
338
+ public static function cacheMethodIsAvailable()
339
+ {
340
+ if (!class_exists('SQLite3', false)) {
341
+ return false;
342
+ }
343
+
344
+ return true;
345
+ }
346
+ }
PHPExcel/Classes/PHPExcel/CachedObjectStorage/Wincache.php CHANGED
@@ -1,294 +1,289 @@
1
- <?php
2
- /**
3
- * PHPExcel
4
- *
5
- * Copyright (c) 2006 - 2014 PHPExcel
6
- *
7
- * This library is free software; you can redistribute it and/or
8
- * modify it under the terms of the GNU Lesser General Public
9
- * License as published by the Free Software Foundation; either
10
- * version 2.1 of the License, or (at your option) any later version.
11
- *
12
- * This library is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
- * Lesser General Public License for more details.
16
- *
17
- * You should have received a copy of the GNU Lesser General Public
18
- * License along with this library; if not, write to the Free Software
19
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
- *
21
- * @category PHPExcel
22
- * @package PHPExcel_CachedObjectStorage
23
- * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
24
- * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25
- * @version 1.8.0, 2014-03-02
26
- */
27
-
28
-
29
- /**
30
- * PHPExcel_CachedObjectStorage_Wincache
31
- *
32
- * @category PHPExcel
33
- * @package PHPExcel_CachedObjectStorage
34
- * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
35
- */
36
- class PHPExcel_CachedObjectStorage_Wincache extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {
37
-
38
- /**
39
- * Prefix used to uniquely identify cache data for this worksheet
40
- *
41
- * @var string
42
- */
43
- private $_cachePrefix = null;
44
-
45
- /**
46
- * Cache timeout
47
- *
48
- * @var integer
49
- */
50
- private $_cacheTime = 600;
51
-
52
-
53
- /**
54
- * Store cell data in cache for the current cell object if it's "dirty",
55
- * and the 'nullify' the current cell object
56
- *
57
- * @return void
58
- * @throws PHPExcel_Exception
59
- */
60
- protected function _storeData() {
61
- if ($this->_currentCellIsDirty && !empty($this->_currentObjectID)) {
62
- $this->_currentObject->detach();
63
-
64
- $obj = serialize($this->_currentObject);
65
- if (wincache_ucache_exists($this->_cachePrefix.$this->_currentObjectID.'.cache')) {
66
- if (!wincache_ucache_set($this->_cachePrefix.$this->_currentObjectID.'.cache', $obj, $this->_cacheTime)) {
67
- $this->__destruct();
68
- throw new PHPExcel_Exception('Failed to store cell '.$this->_currentObjectID.' in WinCache');
69
- }
70
- } else {
71
- if (!wincache_ucache_add($this->_cachePrefix.$this->_currentObjectID.'.cache', $obj, $this->_cacheTime)) {
72
- $this->__destruct();
73
- throw new PHPExcel_Exception('Failed to store cell '.$this->_currentObjectID.' in WinCache');
74
- }
75
- }
76
- $this->_currentCellIsDirty = false;
77
- }
78
-
79
- $this->_currentObjectID = $this->_currentObject = null;
80
- } // function _storeData()
81
-
82
-
83
- /**
84
- * Add or Update a cell in cache identified by coordinate address
85
- *
86
- * @param string $pCoord Coordinate address of the cell to update
87
- * @param PHPExcel_Cell $cell Cell to update
88
- * @return void
89
- * @throws PHPExcel_Exception
90
- */
91
- public function addCacheData($pCoord, PHPExcel_Cell $cell) {
92
- if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) {
93
- $this->_storeData();
94
- }
95
- $this->_cellCache[$pCoord] = true;
96
-
97
- $this->_currentObjectID = $pCoord;
98
- $this->_currentObject = $cell;
99
- $this->_currentCellIsDirty = true;
100
-
101
- return $cell;
102
- } // function addCacheData()
103
-
104
-
105
- /**
106
- * Is a value set in the current PHPExcel_CachedObjectStorage_ICache for an indexed cell?
107
- *
108
- * @param string $pCoord Coordinate address of the cell to check
109
- * @return boolean
110
- */
111
- public function isDataSet($pCoord) {
112
- // Check if the requested entry is the current object, or exists in the cache
113
- if (parent::isDataSet($pCoord)) {
114
- if ($this->_currentObjectID == $pCoord) {
115
- return true;
116
- }
117
- // Check if the requested entry still exists in cache
118
- $success = wincache_ucache_exists($this->_cachePrefix.$pCoord.'.cache');
119
- if ($success === false) {
120
- // Entry no longer exists in Wincache, so clear it from the cache array
121
- parent::deleteCacheData($pCoord);
122
- throw new PHPExcel_Exception('Cell entry '.$pCoord.' no longer exists in WinCache');
123
- }
124
- return true;
125
- }
126
- return false;
127
- } // function isDataSet()
128
-
129
-
130
- /**
131
- * Get cell at a specific coordinate
132
- *
133
- * @param string $pCoord Coordinate of the cell
134
- * @throws PHPExcel_Exception
135
- * @return PHPExcel_Cell Cell that was found, or null if not found
136
- */
137
- public function getCacheData($pCoord) {
138
- if ($pCoord === $this->_currentObjectID) {
139
- return $this->_currentObject;
140
- }
141
- $this->_storeData();
142
-
143
- // Check if the entry that has been requested actually exists
144
- $obj = null;
145
- if (parent::isDataSet($pCoord)) {
146
- $success = false;
147
- $obj = wincache_ucache_get($this->_cachePrefix.$pCoord.'.cache', $success);
148
- if ($success === false) {
149
- // Entry no longer exists in WinCache, so clear it from the cache array
150
- parent::deleteCacheData($pCoord);
151
- throw new PHPExcel_Exception('Cell entry '.$pCoord.' no longer exists in WinCache');
152
- }
153
- } else {
154
- // Return null if requested entry doesn't exist in cache
155
- return null;
156
- }
157
-
158
- // Set current entry to the requested entry
159
- $this->_currentObjectID = $pCoord;
160
- $this->_currentObject = unserialize($obj);
161
- // Re-attach this as the cell's parent
162
- $this->_currentObject->attach($this);
163
-
164
- // Return requested entry
165
- return $this->_currentObject;
166
- } // function getCacheData()
167
-
168
-
169
- /**
170
- * Get a list of all cell addresses currently held in cache
171
- *
172
- * @return array of string
173
- */
174
- public function getCellList() {
175
- if ($this->_currentObjectID !== null) {
176
- $this->_storeData();
177
- }
178
-
179
- return parent::getCellList();
180
- }
181
-
182
-
183
- /**
184
- * Delete a cell in cache identified by coordinate address
185
- *
186
- * @param string $pCoord Coordinate address of the cell to delete
187
- * @throws PHPExcel_Exception
188
- */
189
- public function deleteCacheData($pCoord) {
190
- // Delete the entry from Wincache
191
- wincache_ucache_delete($this->_cachePrefix.$pCoord.'.cache');
192
-
193
- // Delete the entry from our cell address array
194
- parent::deleteCacheData($pCoord);
195
- } // function deleteCacheData()
196
-
197
-
198
- /**
199
- * Clone the cell collection
200
- *
201
- * @param PHPExcel_Worksheet $parent The new worksheet
202
- * @return void
203
- */
204
- public function copyCellCollection(PHPExcel_Worksheet $parent) {
205
- parent::copyCellCollection($parent);
206
- // Get a new id for the new file name
207
- $baseUnique = $this->_getUniqueID();
208
- $newCachePrefix = substr(md5($baseUnique),0,8).'.';
209
- $cacheList = $this->getCellList();
210
- foreach($cacheList as $cellID) {
211
- if ($cellID != $this->_currentObjectID) {
212
- $success = false;
213
- $obj = wincache_ucache_get($this->_cachePrefix.$cellID.'.cache', $success);
214
- if ($success === false) {
215
- // Entry no longer exists in WinCache, so clear it from the cache array
216
- parent::deleteCacheData($cellID);
217
- throw new PHPExcel_Exception('Cell entry '.$cellID.' no longer exists in Wincache');
218
- }
219
- if (!wincache_ucache_add($newCachePrefix.$cellID.'.cache', $obj, $this->_cacheTime)) {
220
- $this->__destruct();
221
- throw new PHPExcel_Exception('Failed to store cell '.$cellID.' in Wincache');
222
- }
223
- }
224
- }
225
- $this->_cachePrefix = $newCachePrefix;
226
- } // function copyCellCollection()
227
-
228
-
229
- /**
230
- * Clear the cell collection and disconnect from our parent
231
- *
232
- * @return void
233
- */
234
- public function unsetWorksheetCells() {
235
- if(!is_null($this->_currentObject)) {
236
- $this->_currentObject->detach();
237
- $this->_currentObject = $this->_currentObjectID = null;
238
- }
239
-
240
- // Flush the WinCache cache
241
- $this->__destruct();
242
-
243
- $this->_cellCache = array();
244
-
245
- // detach ourself from the worksheet, so that it can then delete this object successfully
246
- $this->_parent = null;
247
- } // function unsetWorksheetCells()
248
-
249
-
250
- /**
251
- * Initialise this new cell collection
252
- *
253
- * @param PHPExcel_Worksheet $parent The worksheet for this cell collection
254
- * @param array of mixed $arguments Additional initialisation arguments
255
- */
256
- public function __construct(PHPExcel_Worksheet $parent, $arguments) {
257
- $cacheTime = (isset($arguments['cacheTime'])) ? $arguments['cacheTime'] : 600;
258
-
259
- if (is_null($this->_cachePrefix)) {
260
- $baseUnique = $this->_getUniqueID();
261
- $this->_cachePrefix = substr(md5($baseUnique),0,8).'.';
262
- $this->_cacheTime = $cacheTime;
263
-
264
- parent::__construct($parent);
265
- }
266
- } // function __construct()
267
-
268
-
269
- /**
270
- * Destroy this cell collection
271
- */
272
- public function __destruct() {
273
- $cacheList = $this->getCellList();
274
- foreach($cacheList as $cellID) {
275
- wincache_ucache_delete($this->_cachePrefix.$cellID.'.cache');
276
- }
277
- } // function __destruct()
278
-
279
-
280
- /**
281
- * Identify whether the caching method is currently available
282
- * Some methods are dependent on the availability of certain extensions being enabled in the PHP build
283
- *
284
- * @return boolean
285
- */
286
- public static function cacheMethodIsAvailable() {
287
- if (!function_exists('wincache_ucache_add')) {
288
- return false;
289
- }
290
-
291
- return true;
292
- }
293
-
294
- }
1
+ <?php
2
+
3
+ /**
4
+ * PHPExcel_CachedObjectStorage_Wincache
5
+ *
6
+ * Copyright (c) 2006 - 2015 PHPExcel
7
+ *
8
+ * This library is free software; you can redistribute it and/or
9
+ * modify it under the terms of the GNU Lesser General Public
10
+ * License as published by the Free Software Foundation; either
11
+ * version 2.1 of the License, or (at your option) any later version.
12
+ *
13
+ * This library is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
+ * Lesser General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU Lesser General Public
19
+ * License along with this library; if not, write to the Free Software
20
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
+ *
22
+ * @category PHPExcel
23
+ * @package PHPExcel_CachedObjectStorage
24
+ * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
25
+ * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
26
+ * @version ##VERSION##, ##DATE##
27
+ */
28
+ class PHPExcel_CachedObjectStorage_Wincache extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache
29
+ {
30
+ /**
31
+ * Prefix used to uniquely identify cache data for this worksheet
32
+ *
33
+ * @var string
34
+ */
35
+ private $cachePrefix = null;
36
+
37
+ /**
38
+ * Cache timeout
39
+ *
40
+ * @var integer
41
+ */
42
+ private $cacheTime = 600;
43
+
44
+
45
+ /**
46
+ * Store cell data in cache for the current cell object if it's "dirty",
47
+ * and the 'nullify' the current cell object
48
+ *
49
+ * @return void
50
+ * @throws PHPExcel_Exception
51
+ */
52
+ protected function storeData()
53
+ {
54
+ if ($this->currentCellIsDirty && !empty($this->currentObjectID)) {
55
+ $this->currentObject->detach();
56
+
57
+ $obj = serialize($this->currentObject);
58
+ if (wincache_ucache_exists($this->cachePrefix.$this->currentObjectID.'.cache')) {
59
+ if (!wincache_ucache_set($this->cachePrefix.$this->currentObjectID.'.cache', $obj, $this->cacheTime)) {
60
+ $this->__destruct();
61
+ throw new PHPExcel_Exception('Failed to store cell '.$this->currentObjectID.' in WinCache');
62
+ }
63
+ } else {
64
+ if (!wincache_ucache_add($this->cachePrefix.$this->currentObjectID.'.cache', $obj, $this->cacheTime)) {
65
+ $this->__destruct();
66
+ throw new PHPExcel_Exception('Failed to store cell '.$this->currentObjectID.' in WinCache');
67
+ }
68
+ }
69
+ $this->currentCellIsDirty = false;
70
+ }
71
+
72
+ $this->currentObjectID = $this->currentObject = null;
73
+ }
74
+
75
+ /**
76
+ * Add or Update a cell in cache identified by coordinate address
77
+ *
78
+ * @param string $pCoord Coordinate address of the cell to update
79
+ * @param PHPExcel_Cell $cell Cell to update
80
+ * @return PHPExcel_Cell
81
+ * @throws PHPExcel_Exception
82
+ */
83
+ public function addCacheData($pCoord, PHPExcel_Cell $cell)
84
+ {
85
+ if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) {
86
+ $this->storeData();
87
+ }
88
+ $this->cellCache[$pCoord] = true;
89
+
90
+ $this->currentObjectID = $pCoord;
91
+ $this->currentObject = $cell;
92
+ $this->currentCellIsDirty = true;
93
+
94
+ return $cell;
95
+ }
96
+
97
+ /**
98
+ * Is a value set in the current PHPExcel_CachedObjectStorage_ICache for an indexed cell?
99
+ *
100
+ * @param string $pCoord Coordinate address of the cell to check
101
+ * @return boolean
102
+ */
103
+ public function isDataSet($pCoord)
104
+ {
105
+ // Check if the requested entry is the current object, or exists in the cache
106
+ if (parent::isDataSet($pCoord)) {
107
+ if ($this->currentObjectID == $pCoord) {
108
+ return true;
109
+ }
110
+ // Check if the requested entry still exists in cache
111
+ $success = wincache_ucache_exists($this->cachePrefix.$pCoord.'.cache');
112
+ if ($success === false) {
113
+ // Entry no longer exists in Wincache, so clear it from the cache array
114
+ parent::deleteCacheData($pCoord);
115
+ throw new PHPExcel_Exception('Cell entry '.$pCoord.' no longer exists in WinCache');
116
+ }
117
+ return true;
118
+ }
119
+ return false;
120
+ }
121
+
122
+
123
+ /**
124
+ * Get cell at a specific coordinate
125
+ *
126
+ * @param string $pCoord Coordinate of the cell
127
+ * @throws PHPExcel_Exception
128
+ * @return PHPExcel_Cell Cell that was found, or null if not found
129
+ */
130
+ public function getCacheData($pCoord)
131
+ {
132
+ if ($pCoord === $this->currentObjectID) {
133
+ return $this->currentObject;
134
+ }
135
+ $this->storeData();
136
+
137
+ // Check if the entry that has been requested actually exists
138
+ $obj = null;
139
+ if (parent::isDataSet($pCoord)) {
140
+ $success = false;
141
+ $obj = wincache_ucache_get($this->cachePrefix.$pCoord.'.cache', $success);
142
+ if ($success === false) {
143
+ // Entry no longer exists in WinCache, so clear it from the cache array
144
+ parent::deleteCacheData($pCoord);
145
+ throw new PHPExcel_Exception('Cell entry '.$pCoord.' no longer exists in WinCache');
146
+ }
147
+ } else {
148
+ // Return null if requested entry doesn't exist in cache
149
+ return null;
150
+ }
151
+
152
+ // Set current entry to the requested entry
153
+ $this->currentObjectID = $pCoord;
154
+ $this->currentObject = unserialize($obj);
155
+ // Re-attach this as the cell's parent
156
+ $this->currentObject->attach($this);
157
+
158
+ // Return requested entry
159
+ return $this->currentObject;
160
+ }
161
+
162
+
163
+ /**
164
+ * Get a list of all cell addresses currently held in cache
165
+ *
166
+ * @return string[]
167
+ */
168
+ public function getCellList()
169
+ {
170
+ if ($this->currentObjectID !== null) {
171
+ $this->storeData();
172
+ }
173
+
174
+ return parent::getCellList();
175
+ }
176
+
177
+ /**
178
+ * Delete a cell in cache identified by coordinate address
179
+ *
180
+ * @param string $pCoord Coordinate address of the cell to delete
181
+ * @throws PHPExcel_Exception
182
+ */
183
+ public function deleteCacheData($pCoord)
184
+ {
185
+ // Delete the entry from Wincache
186
+ wincache_ucache_delete($this->cachePrefix.$pCoord.'.cache');
187
+
188
+ // Delete the entry from our cell address array
189
+ parent::deleteCacheData($pCoord);
190
+ }
191
+
192
+ /**
193
+ * Clone the cell collection
194
+ *
195
+ * @param PHPExcel_Worksheet $parent The new worksheet
196
+ * @return void
197
+ */
198
+ public function copyCellCollection(PHPExcel_Worksheet $parent)
199
+ {
200
+ parent::copyCellCollection($parent);
201
+ // Get a new id for the new file name
202
+ $baseUnique = $this->getUniqueID();
203
+ $newCachePrefix = substr(md5($baseUnique), 0, 8) . '.';
204
+ $cacheList = $this->getCellList();
205
+ foreach ($cacheList as $cellID) {
206
+ if ($cellID != $this->currentObjectID) {
207
+ $success = false;
208
+ $obj = wincache_ucache_get($this->cachePrefix.$cellID.'.cache', $success);
209
+ if ($success === false) {
210
+ // Entry no longer exists in WinCache, so clear it from the cache array
211
+ parent::deleteCacheData($cellID);
212
+ throw new PHPExcel_Exception('Cell entry '.$cellID.' no longer exists in Wincache');
213
+ }
214
+ if (!wincache_ucache_add($newCachePrefix.$cellID.'.cache', $obj, $this->cacheTime)) {
215
+ $this->__destruct();
216
+ throw new PHPExcel_Exception('Failed to store cell '.$cellID.' in Wincache');
217
+ }
218
+ }
219
+ }
220
+ $this->cachePrefix = $newCachePrefix;
221
+ }
222
+
223
+
224
+ /**
225
+ * Clear the cell collection and disconnect from our parent
226
+ *
227
+ * @return void
228
+ */
229
+ public function unsetWorksheetCells()
230
+ {
231
+ if (!is_null($this->currentObject)) {
232
+ $this->currentObject->detach();
233
+ $this->currentObject = $this->currentObjectID = null;
234
+ }
235
+
236
+ // Flush the WinCache cache
237
+ $this->__destruct();
238
+
239
+ $this->cellCache = array();
240
+
241
+ // detach ourself from the worksheet, so that it can then delete this object successfully
242
+ $this->parent = null;
243
+ }
244
+
245
+ /**
246
+ * Initialise this new cell collection
247
+ *
248
+ * @param PHPExcel_Worksheet $parent The worksheet for this cell collection
249
+ * @param array of mixed $arguments Additional initialisation arguments
250
+ */
251
+ public function __construct(PHPExcel_Worksheet $parent, $arguments)
252
+ {
253
+ $cacheTime = (isset($arguments['cacheTime'])) ? $arguments['cacheTime'] : 600;
254
+
255
+ if (is_null($this->cachePrefix)) {
256
+ $baseUnique = $this->getUniqueID();
257
+ $this->cachePrefix = substr(md5($baseUnique), 0, 8).'.';
258
+ $this->cacheTime = $cacheTime;
259
+
260
+ parent::__construct($parent);
261
+ }
262
+ }
263
+
264
+ /**
265
+ * Destroy this cell collection
266
+ */
267
+ public function __destruct()
268
+ {
269
+ $cacheList = $this->getCellList();
270
+ foreach ($cacheList as $cellID) {
271
+ wincache_ucache_delete($this->cachePrefix.$cellID.'.cache');
272
+ }
273
+ }
274
+
275
+ /**
276
+ * Identify whether the caching method is currently available
277
+ * Some methods are dependent on the availability of certain extensions being enabled in the PHP build
278
+ *
279
+ * @return boolean
280
+ */
281
+ public static function cacheMethodIsAvailable()
282
+ {
283
+ if (!function_exists('wincache_ucache_add')) {
284
+ return false;
285
+ }
286
+
287
+ return true;
288
+ }
289
+ }
 
 
 
 
 
PHPExcel/Classes/PHPExcel/CachedObjectStorageFactory.php CHANGED
@@ -1,251 +1,231 @@
1
- <?php
2
-
3
- /**
4
- * PHPExcel
5
- *
6
- * Copyright (c) 2006 - 2014 PHPExcel
7
- *
8
- * This library is free software; you can redistribute it and/or
9
- * modify it under the terms of the GNU Lesser General Public
10
- * License as published by the Free Software Foundation; either
11
- * version 2.1 of the License, or (at your option) any later version.
12
- *
13
- * This library is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
- * Lesser General Public License for more details.
17
- *
18
- * You should have received a copy of the GNU Lesser General Public
19
- * License along with this library; if not, write to the Free Software
20
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
- *
22
- * @category PHPExcel
23
- * @package PHPExcel_CachedObjectStorage
24
- * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
25
- * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
26
- * @version 1.8.0, 2014-03-02
27
- */
28
-
29
-
30
- /**
31
- * PHPExcel_CachedObjectStorageFactory
32
- *
33
- * @category PHPExcel
34
- * @package PHPExcel_CachedObjectStorage
35
- * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
36
- */
37
- class PHPExcel_CachedObjectStorageFactory
38
- {
39
- const cache_in_memory = 'Memory';
40
- const cache_in_memory_gzip = 'MemoryGZip';
41
- const cache_in_memory_serialized = 'MemorySerialized';
42
- const cache_igbinary = 'Igbinary';
43
- const cache_to_discISAM = 'DiscISAM';
44
- const cache_to_apc = 'APC';
45
- const cache_to_memcache = 'Memcache';
46
- const cache_to_phpTemp = 'PHPTemp';
47
- const cache_to_wincache = 'Wincache';
48
- const cache_to_sqlite = 'SQLite';
49
- const cache_to_sqlite3 = 'SQLite3';
50
-
51
-
52
- /**
53
- * Name of the method used for cell cacheing
54
- *
55
- * @var string
56
- */
57
- private static $_cacheStorageMethod = NULL;
58
-
59
- /**
60
- * Name of the class used for cell cacheing
61
- *
62
- * @var string
63
- */
64
- private static $_cacheStorageClass = NULL;
65
-
66
-
67
- /**
68
- * List of all possible cache storage methods
69
- *
70
- * @var string[]
71
- */
72
- private static $_storageMethods = array(
73
- self::cache_in_memory,
74
- self::cache_in_memory_gzip,
75
- self::cache_in_memory_serialized,
76
- self::cache_igbinary,
77
- self::cache_to_phpTemp,
78
- self::cache_to_discISAM,
79
- self::cache_to_apc,
80
- self::cache_to_memcache,
81
- self::cache_to_wincache,
82
- self::cache_to_sqlite,
83
- self::cache_to_sqlite3,
84
- );
85
-
86
-
87
- /**
88
- * Default arguments for each cache storage method
89
- *
90
- * @var array of mixed array
91
- */
92
- private static $_storageMethodDefaultParameters = array(
93
- self::cache_in_memory => array(
94
- ),
95
- self::cache_in_memory_gzip => array(
96
- ),
97
- self::cache_in_memory_serialized => array(
98
- ),
99
- self::cache_igbinary => array(
100
- ),
101
- self::cache_to_phpTemp => array( 'memoryCacheSize' => '1MB'
102
- ),
103
- self::cache_to_discISAM => array( 'dir' => NULL
104
- ),
105
- self::cache_to_apc => array( 'cacheTime' => 600
106
- ),
107
- self::cache_to_memcache => array( 'memcacheServer' => 'localhost',
108
- 'memcachePort' => 11211,
109
- 'cacheTime' => 600
110
- ),
111
- self::cache_to_wincache => array( 'cacheTime' => 600
112
- ),
113
- self::cache_to_sqlite => array(
114
- ),
115
- self::cache_to_sqlite3 => array(
116
- ),
117
- );
118
-
119
-
120
- /**
121
- * Arguments for the active cache storage method
122
- *
123
- * @var array of mixed array
124
- */
125
- private static $_storageMethodParameters = array();
126
-
127
-
128
- /**
129
- * Return the current cache storage method
130
- *
131
- * @return string|NULL
132
- **/
133
- public static function getCacheStorageMethod()
134
- {
135
- return self::$_cacheStorageMethod;
136
- } // function getCacheStorageMethod()
137
-
138
-
139
- /**
140
- * Return the current cache storage class
141
- *
142
- * @return PHPExcel_CachedObjectStorage_ICache|NULL
143
- **/
144
- public static function getCacheStorageClass()
145
- {
146
- return self::$_cacheStorageClass;
147
- } // function getCacheStorageClass()
148
-
149
-
150
- /**
151
- * Return the list of all possible cache storage methods
152
- *
153
- * @return string[]
154
- **/
155
- public static function getAllCacheStorageMethods()
156
- {
157
- return self::$_storageMethods;
158
- } // function getCacheStorageMethods()
159
-
160
-
161
- /**
162
- * Return the list of all available cache storage methods
163
- *
164
- * @return string[]
165
- **/
166
- public static function getCacheStorageMethods()
167
- {
168
- $activeMethods = array();
169
- foreach(self::$_storageMethods as $storageMethod) {
170
- $cacheStorageClass = 'PHPExcel_CachedObjectStorage_' . $storageMethod;
171
- if (call_user_func(array($cacheStorageClass, 'cacheMethodIsAvailable'))) {
172
- $activeMethods[] = $storageMethod;
173
- }
174
- }
175
- return $activeMethods;
176
- } // function getCacheStorageMethods()
177
-
178
-
179
- /**
180
- * Identify the cache storage method to use
181
- *
182
- * @param string $method Name of the method to use for cell cacheing
183
- * @param array of mixed $arguments Additional arguments to pass to the cell caching class
184
- * when instantiating
185
- * @return boolean
186
- **/
187
- public static function initialize($method = self::cache_in_memory, $arguments = array())
188
- {
189
- if (!in_array($method,self::$_storageMethods)) {
190
- return FALSE;
191
- }
192
-
193
- $cacheStorageClass = 'PHPExcel_CachedObjectStorage_'.$method;
194
- if (!call_user_func(array( $cacheStorageClass,
195
- 'cacheMethodIsAvailable'))) {
196
- return FALSE;
197
- }
198
-
199
- self::$_storageMethodParameters[$method] = self::$_storageMethodDefaultParameters[$method];
200
- foreach($arguments as $k => $v) {
201
- if (array_key_exists($k, self::$_storageMethodParameters[$method])) {
202
- self::$_storageMethodParameters[$method][$k] = $v;
203
- }
204
- }
205
-
206
- if (self::$_cacheStorageMethod === NULL) {
207
- self::$_cacheStorageClass = 'PHPExcel_CachedObjectStorage_' . $method;
208
- self::$_cacheStorageMethod = $method;
209
- }
210
- return TRUE;
211
- } // function initialize()
212
-
213
-
214
- /**
215
- * Initialise the cache storage
216
- *
217
- * @param PHPExcel_Worksheet $parent Enable cell caching for this worksheet
218
- * @return PHPExcel_CachedObjectStorage_ICache
219
- **/
220
- public static function getInstance(PHPExcel_Worksheet $parent)
221
- {
222
- $cacheMethodIsAvailable = TRUE;
223
- if (self::$_cacheStorageMethod === NULL) {
224
- $cacheMethodIsAvailable = self::initialize();
225
- }
226
-
227
- if ($cacheMethodIsAvailable) {
228
- $instance = new self::$_cacheStorageClass( $parent,
229
- self::$_storageMethodParameters[self::$_cacheStorageMethod]
230
- );
231
- if ($instance !== NULL) {
232
- return $instance;
233
- }
234
- }
235
-
236
- return FALSE;
237
- } // function getInstance()
238
-
239
-
240
- /**
241
- * Clear the cache storage
242
- *
243
- **/
244
- public static function finalize()
245
- {
246
- self::$_cacheStorageMethod = NULL;
247
- self::$_cacheStorageClass = NULL;
248
- self::$_storageMethodParameters = array();
249
- }
250
-
251
- }
1
+ <?php
2
+
3
+ /**
4
+ * PHPExcel_CachedObjectStorageFactory
5
+ *
6
+ * Copyright (c) 2006 - 2015 PHPExcel
7
+ *
8
+ * This library is free software; you can redistribute it and/or
9
+ * modify it under the terms of the GNU Lesser General Public
10
+ * License as published by the Free Software Foundation; either
11
+ * version 2.1 of the License, or (at your option) any later version.
12
+ *
13
+ * This library is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
+ * Lesser General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU Lesser General Public
19
+ * License along with this library; if not, write to the Free Software
20
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
+ *
22
+ * @category PHPExcel
23
+ * @package PHPExcel_CachedObjectStorage
24
+ * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
25
+ * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
26
+ * @version ##VERSION##, ##DATE##
27
+ */
28
+ class PHPExcel_CachedObjectStorageFactory
29
+ {
30
+ const cache_in_memory = 'Memory';
31
+ const cache_in_memory_gzip = 'MemoryGZip';
32
+ const cache_in_memory_serialized = 'MemorySerialized';
33
+ const cache_igbinary = 'Igbinary';
34
+ const cache_to_discISAM = 'DiscISAM';
35
+ const cache_to_apc = 'APC';
36
+ const cache_to_memcache = 'Memcache';
37
+ const cache_to_phpTemp = 'PHPTemp';
38
+ const cache_to_wincache = 'Wincache';
39
+ const cache_to_sqlite = 'SQLite';
40
+ const cache_to_sqlite3 = 'SQLite3';
41
+
42
+ /**
43
+ * Name of the method used for cell cacheing
44
+ *
45
+ * @var string
46
+ */
47
+ private static $cacheStorageMethod = null;
48
+
49
+ /**
50
+ * Name of the class used for cell cacheing
51
+ *
52
+ * @var string
53
+ */
54
+ private static $cacheStorageClass = null;
55
+
56
+ /**
57
+ * List of all possible cache storage methods
58
+ *
59
+ * @var string[]
60
+ */
61
+ private static $storageMethods = array(
62
+ self::cache_in_memory,
63
+ self::cache_in_memory_gzip,
64
+ self::cache_in_memory_serialized,
65
+ self::cache_igbinary,
66
+ self::cache_to_phpTemp,
67
+ self::cache_to_discISAM,
68
+ self::cache_to_apc,
69
+ self::cache_to_memcache,
70
+ self::cache_to_wincache,
71
+ self::cache_to_sqlite,
72
+ self::cache_to_sqlite3,
73
+ );
74
+
75
+ /**
76
+ * Default arguments for each cache storage method
77
+ *
78
+ * @var array of mixed array
79
+ */
80
+ private static $storageMethodDefaultParameters = array(
81
+ self::cache_in_memory => array(
82
+ ),
83
+ self::cache_in_memory_gzip => array(
84
+ ),
85
+ self::cache_in_memory_serialized => array(
86
+ ),
87
+ self::cache_igbinary => array(
88
+ ),
89
+ self::cache_to_phpTemp => array( 'memoryCacheSize' => '1MB'
90
+ ),
91
+ self::cache_to_discISAM => array( 'dir' => null
92
+ ),
93
+ self::cache_to_apc => array( 'cacheTime' => 600
94
+ ),
95
+ self::cache_to_memcache => array( 'memcacheServer' => 'localhost',
96
+ 'memcachePort' => 11211,
97
+ 'cacheTime' => 600
98
+ ),
99
+ self::cache_to_wincache => array( 'cacheTime' => 600
100
+ ),
101
+ self::cache_to_sqlite => array(
102
+ ),
103
+ self::cache_to_sqlite3 => array(
104
+ ),
105
+ );
106
+
107
+ /**
108
+ * Arguments for the active cache storage method
109
+ *
110
+ * @var array of mixed array
111
+ */
112
+ private static $storageMethodParameters = array();
113
+
114
+ /**
115
+ * Return the current cache storage method
116
+ *
117
+ * @return string|null
118
+ **/
119
+ public static function getCacheStorageMethod()
120
+ {
121
+ return self::$cacheStorageMethod;
122
+ }
123
+
124
+ /**
125
+ * Return the current cache storage class
126
+ *
127
+ * @return PHPExcel_CachedObjectStorage_ICache|null
128
+ **/
129
+ public static function getCacheStorageClass()
130
+ {
131
+ return self::$cacheStorageClass;
132
+ }
133
+
134
+ /**
135
+ * Return the list of all possible cache storage methods
136
+ *
137
+ * @return string[]
138
+ **/
139
+ public static function getAllCacheStorageMethods()
140
+ {
141
+ return self::$storageMethods;
142
+ }
143
+
144
+ /**
145
+ * Return the list of all available cache storage methods
146
+ *
147
+ * @return string[]
148
+ **/
149
+ public static function getCacheStorageMethods()
150
+ {
151
+ $activeMethods = array();
152
+ foreach (self::$storageMethods as $storageMethod) {
153
+ $cacheStorageClass = 'PHPExcel_CachedObjectStorage_' . $storageMethod;
154
+ if (call_user_func(array($cacheStorageClass, 'cacheMethodIsAvailable'))) {
155
+ $activeMethods[] = $storageMethod;
156
+ }
157
+ }
158
+ return $activeMethods;
159
+ }
160
+
161
+ /**
162
+ * Identify the cache storage method to use
163
+ *
164
+ * @param string $method Name of the method to use for cell cacheing
165
+ * @param array of mixed $arguments Additional arguments to pass to the cell caching class
166
+ * when instantiating
167
+ * @return boolean
168
+ **/
169
+ public static function initialize($method = self::cache_in_memory, $arguments = array())
170
+ {
171
+ if (!in_array($method, self::$storageMethods)) {
172
+ return false;
173
+ }
174
+
175
+ $cacheStorageClass = 'PHPExcel_CachedObjectStorage_'.$method;
176
+ if (!call_user_func(array( $cacheStorageClass,
177
+ 'cacheMethodIsAvailable'))) {
178
+ return false;
179
+ }
180
+
181
+ self::$storageMethodParameters[$method] = self::$storageMethodDefaultParameters[$method];
182
+ foreach ($arguments as $k => $v) {
183
+ if (array_key_exists($k, self::$storageMethodParameters[$method])) {
184
+ self::$storageMethodParameters[$method][$k] = $v;
185
+ }
186
+ }
187
+
188
+ if (self::$cacheStorageMethod === null) {
189
+ self::$cacheStorageClass = 'PHPExcel_CachedObjectStorage_' . $method;
190
+ self::$cacheStorageMethod = $method;
191
+ }
192
+ return true;
193
+ }
194
+
195
+ /**
196
+ * Initialise the cache storage
197
+ *
198
+ * @param PHPExcel_Worksheet $parent Enable cell caching for this worksheet
199
+ * @return PHPExcel_CachedObjectStorage_ICache
200
+ **/
201
+ public static function getInstance(PHPExcel_Worksheet $parent)
202
+ {
203
+ $cacheMethodIsAvailable = true;
204
+ if (self::$cacheStorageMethod === null) {
205
+ $cacheMethodIsAvailable = self::initialize();
206
+ }
207
+
208
+ if ($cacheMethodIsAvailable) {
209
+ $instance = new self::$cacheStorageClass(
210
+ $parent,
211
+ self::$storageMethodParameters[self::$cacheStorageMethod]
212
+ );
213
+ if ($instance !== null) {
214
+ return $instance;
215
+ }
216
+ }
217
+
218
+ return false;
219
+ }
220
+
221
+ /**
222
+ * Clear the cache storage
223
+ *
224
+ **/
225
+ public static function finalize()
226
+ {
227
+ self::$cacheStorageMethod = null;
228
+ self::$cacheStorageClass = null;
229
+ self::$storageMethodParameters = array();
230
+ }
231
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
PHPExcel/Classes/PHPExcel/CalcEngine/CyclicReferenceStack.php CHANGED
@@ -1,98 +1,94 @@
1
- <?php
2
- /**
3
- * PHPExcel
4
- *
5
- * Copyright (c) 2006 - 2014 PHPExcel
6
- *
7
- * This library is free software; you can redistribute it and/or
8
- * modify it under the terms of the GNU Lesser General Public
9
- * License as published by the Free Software Foundation; either
10
- * version 2.1 of the License, or (at your option) any later version.
11
- *
12
- * This library is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
- * Lesser General Public License for more details.
16
- *
17
- * You should have received a copy of the GNU Lesser General Public
18
- * License along with this library; if not, write to the Free Software
19
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
- *
21
- * @category PHPExcel
22
- * @package PHPExcel_Calculation
23
- * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
24
- * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25
- * @version 1.8.0, 2014-03-02
26
- */
27
-
28
-
29
- /**
30
- * PHPExcel_CalcEngine_CyclicReferenceStack
31
- *
32
- * @category PHPExcel_CalcEngine_CyclicReferenceStack
33
- * @package PHPExcel_Calculation
34
- * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
35
- */
36
- class PHPExcel_CalcEngine_CyclicReferenceStack {
37
-
38
- /**
39
- * The call stack for calculated cells
40
- *
41
- * @var mixed[]
42
- */
43
- private $_stack = array();
44
-
45
-
46
- /**
47
- * Return the number of entries on the stack
48
- *
49
- * @return integer
50
- */
51
- public function count() {
52
- return count($this->_stack);
53
- }
54
-
55
- /**
56
- * Push a new entry onto the stack
57
- *
58
- * @param mixed $value
59
- */
60
- public function push($value) {
61
- $this->_stack[] = $value;
62
- } // function push()
63
-
64
- /**
65
- * Pop the last entry from the stack
66
- *
67
- * @return mixed
68
- */
69
- public function pop() {
70
- return array_pop($this->_stack);
71
- } // function pop()
72
-
73
- /**
74
- * Test to see if a specified entry exists on the stack
75
- *
76
- * @param mixed $value The value to test
77
- */
78
- public function onStack($value) {
79
- return in_array($value, $this->_stack);
80
- }
81
-
82
- /**
83
- * Clear the stack
84
- */
85
- public function clear() {
86
- $this->_stack = array();
87
- } // function push()
88
-
89
- /**
90
- * Return an array of all entries on the stack
91
- *
92
- * @return mixed[]
93
- */
94
- public function showStack() {
95
- return $this->_stack;
96
- }
97
-
98
- } // class PHPExcel_CalcEngine_CyclicReferenceStack
1
+ <?php
2
+
3
+ /**
4
+ * PHPExcel_CalcEngine_CyclicReferenceStack
5
+ *
6
+ * Copyright (c) 2006 - 2015 PHPExcel
7
+ *
8
+ * This library is free software; you can redistribute it and/or
9
+ * modify it under the terms of the GNU Lesser General Public
10
+ * License as published by the Free Software Foundation; either
11
+ * version 2.1 of the License, or (at your option) any later version.
12
+ *
13
+ * This library is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
+ * Lesser General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU Lesser General Public
19
+ * License along with this library; if not, write to the Free Software
20
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
+ *
22
+ * @category PHPExcel
23
+ * @package PHPExcel_Calculation
24
+ * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
25
+ * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
26
+ * @version ##VERSION##, ##DATE##
27
+ */
28
+ class PHPExcel_CalcEngine_CyclicReferenceStack
29
+ {
30
+ /**
31
+ * The call stack for calculated cells
32
+ *
33
+ * @var mixed[]
34
+ */
35
+ private $stack = array();
36
+
37
+ /**
38
+ * Return the number of entries on the stack
39
+ *
40
+ * @return integer
41
+ */
42
+ public function count()
43
+ {
44
+ return count($this->stack);
45
+ }
46
+
47
+ /**
48
+ * Push a new entry onto the stack
49
+ *
50
+ * @param mixed $value
51
+ */
52
+ public function push($value)
53
+ {
54
+ $this->stack[$value] = $value;
55
+ }
56
+
57
+ /**
58
+ * Pop the last entry from the stack
59
+ *
60
+ * @return mixed
61
+ */
62
+ public function pop()
63
+ {
64
+ return array_pop($this->stack);
65
+ }
66
+
67
+ /**
68
+ * Test to see if a specified entry exists on the stack
69
+ *
70
+ * @param mixed $value The value to test
71
+ */
72
+ public function onStack($value)
73
+ {
74
+ return isset($this->stack[$value]);
75
+ }
76
+
77
+ /**
78
+ * Clear the stack
79
+ */
80
+ public function clear()
81
+ {
82
+ $this->stack = array();
83
+ }
84
+
85
+ /**
86
+ * Return an array of all entries on the stack
87
+ *
88
+ * @return mixed[]
89
+ */
90
+ public function showStack()
91
+ {
92
+ return $this->stack;
93
+ }
94
+ }
 
 
 
 
PHPExcel/Classes/PHPExcel/CalcEngine/Logger.php CHANGED
@@ -1,153 +1,151 @@
1
- <?php
2
- /**
3
- * PHPExcel
4
- *
5
- * Copyright (c) 2006 - 2014 PHPExcel
6
- *
7
- * This library is free software; you can redistribute it and/or
8
- * modify it under the terms of the GNU Lesser General Public
9
- * License as published by the Free Software Foundation; either
10
- * version 2.1 of the License, or (at your option) any later version.
11
- *
12
- * This library is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
- * Lesser General Public License for more details.
16
- *
17
- * You should have received a copy of the GNU Lesser General Public
18
- * License along with this library; if not, write to the Free Software
19
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
- *
21
- * @category PHPExcel
22
- * @package PHPExcel_Calculation
23
- * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
24
- * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25
- * @version 1.8.0, 2014-03-02
26
- */
27
-
28
- /**
29
- * PHPExcel_CalcEngine_Logger
30
- *
31
- * @category PHPExcel
32
- * @package PHPExcel_Calculation
33
- * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
34
- */
35
- class PHPExcel_CalcEngine_Logger {
36
-
37
- /**
38
- * Flag to determine whether a debug log should be generated by the calculation engine
39
- * If true, then a debug log will be generated
40
- * If false, then a debug log will not be generated
41
- *
42
- * @var boolean
43
- */
44
- private $_writeDebugLog = FALSE;
45
-
46
- /**
47
- * Flag to determine whether a debug log should be echoed by the calculation engine
48
- * If true, then a debug log will be echoed
49
- * If false, then a debug log will not be echoed
50
- * A debug log can only be echoed if it is generated
51
- *
52
- * @var boolean
53
- */
54
- private $_echoDebugLog = FALSE;
55
-
56
- /**
57
- * The debug log generated by the calculation engine
58
- *
59
- * @var string[]
60
- */
61
- private $_debugLog = array();
62
-
63
- /**
64
- * The calculation engine cell reference stack
65
- *
66
- * @var PHPExcel_CalcEngine_CyclicReferenceStack
67
- */
68
- private $_cellStack;
69
-
70
-
71
- /**
72
- * Instantiate a Calculation engine logger
73
- *
74
- * @param PHPExcel_CalcEngine_CyclicReferenceStack $stack
75
- */
76
- public function __construct(PHPExcel_CalcEngine_CyclicReferenceStack $stack) {
77
- $this->_cellStack = $stack;
78
- }
79
-
80
- /**
81
- * Enable/Disable Calculation engine logging
82
- *
83
- * @param boolean $pValue
84
- */
85
- public function setWriteDebugLog($pValue = FALSE) {
86
- $this->_writeDebugLog = $pValue;
87
- }
88
-
89
- /**
90
- * Return whether calculation engine logging is enabled or disabled
91
- *
92
- * @return boolean
93
- */
94
- public function getWriteDebugLog() {
95
- return $this->_writeDebugLog;
96
- }
97
-
98
- /**
99
- * Enable/Disable echoing of debug log information
100
- *
101
- * @param boolean $pValue
102
- */
103
- public function setEchoDebugLog($pValue = FALSE) {
104
- $this->_echoDebugLog = $pValue;
105
- }
106
-
107
- /**
108
- * Return whether echoing of debug log information is enabled or disabled
109
- *
110
- * @return boolean
111
- */
112
- public function getEchoDebugLog() {
113
- return $this->_echoDebugLog;
114
- }
115
-
116
- /**
117
- * Write an entry to the calculation engine debug log
118
- */
119
- public function writeDebugLog() {
120
- // Only write the debug log if logging is enabled
121
- if ($this->_writeDebugLog) {
122
- $message = implode(func_get_args());
123
- $cellReference = implode(' -> ', $this->_cellStack->showStack());
124
- if ($this->_echoDebugLog) {
125
- echo $cellReference,
126
- ($this->_cellStack->count() > 0 ? ' => ' : ''),
127
- $message,
128
- PHP_EOL;
129
- }
130
- $this->_debugLog[] = $cellReference .
131
- ($this->_cellStack->count() > 0 ? ' => ' : '') .
132
- $message;
133
- }
134
- } // function _writeDebug()
135
-
136
- /**
137
- * Clear the calculation engine debug log
138
- */
139
- public function clearLog() {
140
- $this->_debugLog = array();
141
- } // function flushLogger()
142
-
143
- /**
144
- * Return the calculation engine debug log
145
- *
146
- * @return string[]
147
- */
148
- public function getLog() {
149
- return $this->_debugLog;
150
- } // function flushLogger()
151
-
152
- } // class PHPExcel_CalcEngine_Logger
153
-
1
+ <?php
2
+
3
+ /**
4
+ * PHPExcel_CalcEngine_Logger
5
+ *
6
+ * Copyright (c) 2006 - 2015 PHPExcel
7
+ *
8
+ * This library is free software; you can redistribute it and/or
9
+ * modify it under the terms of the GNU Lesser General Public
10
+ * License as published by the Free Software Foundation; either
11
+ * version 2.1 of the License, or (at your option) any later version.
12
+ *
13
+ * This library is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
+ * Lesser General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU Lesser General Public
19
+ * License along with this library; if not, write to the Free Software
20
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
+ *
22
+ * @category PHPExcel
23
+ * @package PHPExcel_Calculation
24
+ * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
25
+ * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
26
+ * @version ##VERSION##, ##DATE##
27
+ */
28
+ class PHPExcel_CalcEngine_Logger
29
+ {
30
+ /**
31
+ * Flag to determine whether a debug log should be generated by the calculation engine
32
+ * If true, then a debug log will be generated
33
+ * If false, then a debug log will not be generated
34
+ *
35
+ * @var boolean
36
+ */
37
+ private $writeDebugLog = false;
38
+
39
+ /**
40
+ * Flag to determine whether a debug log should be echoed by the calculation engine
41
+ * If true, then a debug log will be echoed
42
+ * If false, then a debug log will not be echoed
43
+ * A debug log can only be echoed if it is generated
44
+ *
45
+ * @var boolean
46
+ */
47
+ private $echoDebugLog = false;
48
+
49
+ /**
50
+ * The debug log generated by the calculation engine
51
+ *
52
+ * @var string[]
53
+ */
54
+ private $debugLog = array();
55
+
56
+ /**
57
+ * The calculation engine cell reference stack
58
+ *
59
+ * @var PHPExcel_CalcEngine_CyclicReferenceStack
60
+ */
61
+ private $cellStack;
62
+
63
+ /**
64
+ * Instantiate a Calculation engine logger
65
+ *
66
+ * @param PHPExcel_CalcEngine_CyclicReferenceStack $stack
67
+ */
68
+ public function __construct(PHPExcel_CalcEngine_CyclicReferenceStack $stack)
69
+ {
70
+ $this->cellStack = $stack;
71
+ }
72
+
73
+ /**
74
+ * Enable/Disable Calculation engine logging
75
+ *
76
+ * @param boolean $pValue
77
+ */
78
+ public function setWriteDebugLog($pValue = false)
79
+ {
80
+ $this->writeDebugLog = $pValue;
81
+ }
82
+
83
+ /**
84
+ * Return whether calculation engine logging is enabled or disabled
85
+ *
86
+ * @return boolean
87
+ */
88
+ public function getWriteDebugLog()
89
+ {
90
+ return $this->writeDebugLog;
91
+ }
92
+
93
+ /**
94
+ * Enable/Disable echoing of debug log information
95
+ *
96
+ * @param boolean $pValue
97
+ */
98
+ public function setEchoDebugLog($pValue = false)
99
+ {
100
+ $this->echoDebugLog = $pValue;
101
+ }
102
+
103
+ /**
104
+ * Return whether echoing of debug log information is enabled or disabled
105
+ *
106
+ * @return boolean
107
+ */
108
+ public function getEchoDebugLog()
109
+ {
110
+ return $this->echoDebugLog;
111
+ }
112
+
113
+ /**
114
+ * Write an entry to the calculation engine debug log
115
+ */
116
+ public function writeDebugLog()
117
+ {
118
+ // Only write the debug log if logging is enabled
119
+ if ($this->writeDebugLog) {
120
+ $message = implode(func_get_args());
121
+ $cellReference = implode(' -> ', $this->cellStack->showStack());
122
+ if ($this->echoDebugLog) {
123
+ echo $cellReference,
124
+ ($this->cellStack->count() > 0 ? ' => ' : ''),
125
+ $message,
126
+ PHP_EOL;
127
+ }
128
+ $this->debugLog[] = $cellReference .
129
+ ($this->cellStack->count() > 0 ? ' => ' : '') .
130
+ $message;
131
+ }
132
+ }
133
+
134
+ /**
135
+ * Clear the calculation engine debug log
136
+ */
137
+ public function clearLog()
138
+ {
139
+ $this->debugLog = array();
140
+ }
141
+
142
+ /**
143
+ * Return the calculation engine debug log
144
+ *
145
+ * @return string[]
146
+ */
147
+ public function getLog()
148
+ {
149
+ return $this->debugLog;
150
+ }
151
+ }
 
 
PHPExcel/Classes/PHPExcel/Calculation.php CHANGED
@@ -1,3933 +1,4391 @@
1
- <?php
2
- /**
3
- * PHPExcel
4
- *
5
- * Copyright (c) 2006 - 2014 PHPExcel
6
- *
7
- * This library is free software; you can redistribute it and/or
8
- * modify it under the terms of the GNU Lesser General Public
9
- * License as published by the Free Software Foundation; either
10
- * version 2.1 of the License, or (at your option) any later version.
11
- *
12
- * This library is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
- * Lesser General Public License for more details.
16
- *
17
- * You should have received a copy of the GNU Lesser General Public
18
- * License along with this library; if not, write to the Free Software
19
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
- *
21
- * @category PHPExcel
22
- * @package PHPExcel_Calculation
23
- * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
24
- * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25
- * @version 1.8.0, 2014-03-02
26
- */
27
-
28
-
29
- /** PHPExcel root directory */
30
- if (!defined('PHPEXCEL_ROOT')) {
31
- /**
32
- * @ignore
33
- */
34
- define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../');
35
- require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
36
- }
37
-
38
-
39
- if (!defined('CALCULATION_REGEXP_CELLREF')) {
40
- // Test for support of \P (multibyte options) in PCRE
41
- if(defined('PREG_BAD_UTF8_ERROR')) {
42
- // Cell reference (cell or range of cells, with or without a sheet reference)
43
- define('CALCULATION_REGEXP_CELLREF','((([^\s,!&%^\/\*\+<>=-]*)|(\'[^\']*\')|(\"[^\"]*\"))!)?\$?([a-z]{1,3})\$?(\d{1,7})');
44
- // Named Range of cells
45
- define('CALCULATION_REGEXP_NAMEDRANGE','((([^\s,!&%^\/\*\+<>=-]*)|(\'[^\']*\')|(\"[^\"]*\"))!)?([_A-Z][_A-Z0-9\.]*)');
46
- } else {
47
- // Cell reference (cell or range of cells, with or without a sheet reference)
48
- define('CALCULATION_REGEXP_CELLREF','(((\w*)|(\'[^\']*\')|(\"[^\"]*\"))!)?\$?([a-z]{1,3})\$?(\d+)');
49
- // Named Range of cells
50
- define('CALCULATION_REGEXP_NAMEDRANGE','(((\w*)|(\'.*\')|(\".*\"))!)?([_A-Z][_A-Z0-9\.]*)');
51
- }
52
- }
53
-
54
-
55
- /**
56
- * PHPExcel_Calculation (Multiton)
57
- *
58
- * @category PHPExcel
59
- * @package PHPExcel_Calculation
60
- * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
61
- */
62
- class PHPExcel_Calculation {
63
-
64
- /** Constants */
65
- /** Regular Expressions */
66
- // Numeric operand
67
- const CALCULATION_REGEXP_NUMBER = '[-+]?\d*\.?\d+(e[-+]?\d+)?';
68
- // String operand
69
- const CALCULATION_REGEXP_STRING = '"(?:[^"]|"")*"';
70
- // Opening bracket
71
- const CALCULATION_REGEXP_OPENBRACE = '\(';
72
- // Function (allow for the old @ symbol that could be used to prefix a function, but we'll ignore it)
73
- const CALCULATION_REGEXP_FUNCTION = '@?([A-Z][A-Z0-9\.]*)[\s]*\(';
74
- // Cell reference (cell or range of cells, with or without a sheet reference)
75
- const CALCULATION_REGEXP_CELLREF = CALCULATION_REGEXP_CELLREF;
76
- // Named Range of cells
77
- const CALCULATION_REGEXP_NAMEDRANGE = CALCULATION_REGEXP_NAMEDRANGE;
78
- // Error
79
- const CALCULATION_REGEXP_ERROR = '\#[A-Z][A-Z0_\/]*[!\?]?';
80
-
81
-
82
- /** constants */
83
- const RETURN_ARRAY_AS_ERROR = 'error';
84
- const RETURN_ARRAY_AS_VALUE = 'value';
85
- const RETURN_ARRAY_AS_ARRAY = 'array';
86
-
87
- private static $returnArrayAsType = self::RETURN_ARRAY_AS_VALUE;
88
-
89
-
90
- /**
91
- * Instance of this class
92
- *
93
- * @access private
94
- * @var PHPExcel_Calculation
95
- */
96
- private static $_instance;
97
-
98
-
99
- /**
100
- * Instance of the workbook this Calculation Engine is using
101
- *
102
- * @access private
103
- * @var PHPExcel
104
- */
105
- private $_workbook;
106
-
107
- /**
108
- * List of instances of the calculation engine that we've instantiated for individual workbooks
109
- *
110
- * @access private
111
- * @var PHPExcel_Calculation[]
112
- */
113
- private static $_workbookSets;
114
-
115
- /**
116
- * Calculation cache
117
- *
118
- * @access private
119
- * @var array
120
- */
121
- private $_calculationCache = array ();
122
-
123
-
124
- /**
125
- * Calculation cache enabled
126
- *
127
- * @access private
128
- * @var boolean
129
- */
130
- private $_calculationCacheEnabled = TRUE;
131
-
132
-
133
- /**
134
- * List of operators that can be used within formulae
135
- * The true/false value indicates whether it is a binary operator or a unary operator
136
- *
137
- * @access private
138
- * @var array
139
- */
140
- private static $_operators = array('+' => TRUE, '-' => TRUE, '*' => TRUE, '/' => TRUE,
141
- '^' => TRUE, '&' => TRUE, '%' => FALSE, '~' => FALSE,
142
- '>' => TRUE, '<' => TRUE, '=' => TRUE, '>=' => TRUE,
143
- '<=' => TRUE, '<>' => TRUE, '|' => TRUE, ':' => TRUE
144
- );
145
-
146
-
147
- /**
148
- * List of binary operators (those that expect two operands)
149
- *
150
- * @access private
151
- * @var array
152
- */
153
- private static $_binaryOperators = array('+' => TRUE, '-' => TRUE, '*' => TRUE, '/' => TRUE,
154
- '^' => TRUE, '&' => TRUE, '>' => TRUE, '<' => TRUE,
155
- '=' => TRUE, '>=' => TRUE, '<=' => TRUE, '<>' => TRUE,
156
- '|' => TRUE, ':' => TRUE
157
- );
158
-
159
- /**
160
- * The debug log generated by the calculation engine
161
- *
162
- * @access private
163
- * @var PHPExcel_CalcEngine_Logger
164
- *
165
- */
166
- private $debugLog;
167
-
168
- /**
169
- * Flag to determine how formula errors should be handled
170
- * If true, then a user error will be triggered
171
- * If false, then an exception will be thrown
172
- *
173
- * @access public
174
- * @var boolean
175
- *
176
- */
177
- public $suppressFormulaErrors = FALSE;
178
-
179
- /**
180
- * Error message for any error that was raised/thrown by the calculation engine
181
- *
182
- * @access public
183
- * @var string
184
- *
185
- */
186
- public $formulaError = NULL;
187
-
188
- /**
189
- * An array of the nested cell references accessed by the calculation engine, used for the debug log
190
- *
191
- * @access private
192
- * @var array of string
193
- *
194
- */
195
- private $_cyclicReferenceStack;
196
-
197
- /**
198
- * Current iteration counter for cyclic formulae
199
- * If the value is 0 (or less) then cyclic formulae will throw an exception,
200
- * otherwise they will iterate to the limit defined here before returning a result
201
- *
202
- * @var integer
203
- *
204
- */
205
- private $_cyclicFormulaCount = 0;
206
-
207
- private $_cyclicFormulaCell = '';
208
-
209
- /**
210
- * Number of iterations for cyclic formulae
211
- *
212
- * @var integer
213
- *
214
- */
215
- public $cyclicFormulaCount = 0;
216
-
217
- /**
218
- * Precision used for calculations
219
- *
220
- * @var integer
221
- *
222
- */
223
- private $_savedPrecision = 14;
224
-
225
-
226
- /**
227
- * The current locale setting
228
- *
229
- * @var string
230
- *
231
- */
232
- private static $_localeLanguage = 'en_us'; // US English (default locale)
233
-
234
- /**
235
- * List of available locale settings
236
- * Note that this is read for the locale subdirectory only when requested
237
- *
238
- * @var string[]
239
- *
240
- */
241
- private static $_validLocaleLanguages = array( 'en' // English (default language)
242
- );
243
- /**
244
- * Locale-specific argument separator for function arguments
245
- *
246
- * @var string
247
- *
248
- */
249
- private static $_localeArgumentSeparator = ',';
250
- private static $_localeFunctions = array();
251
-
252
- /**
253
- * Locale-specific translations for Excel constants (True, False and Null)
254
- *
255
- * @var string[]
256
- *
257
- */
258
- public static $_localeBoolean = array( 'TRUE' => 'TRUE',
259
- 'FALSE' => 'FALSE',
260
- 'NULL' => 'NULL'
261
- );
262
-
263
-
264
- /**
265
- * Excel constant string translations to their PHP equivalents
266
- * Constant conversion from text name/value to actual (datatyped) value
267
- *
268
- * @var string[]
269
- *
270
- */
271
- private static $_ExcelConstants = array('TRUE' => TRUE,
272
- 'FALSE' => FALSE,
273
- 'NULL' => NULL
274
- );
275
-
276
- // PHPExcel functions
277
- private static $_PHPExcelFunctions = array( // PHPExcel functions
278
- 'ABS' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
279
- 'functionCall' => 'abs',
280
- 'argumentCount' => '1'
281
- ),
282
- 'ACCRINT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
283
- 'functionCall' => 'PHPExcel_Calculation_Financial::ACCRINT',
284
- 'argumentCount' => '4-7'
285
- ),
286
- 'ACCRINTM' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
287
- 'functionCall' => 'PHPExcel_Calculation_Financial::ACCRINTM',
288
- 'argumentCount' => '3-5'
289
- ),
290
- 'ACOS' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
291
- 'functionCall' => 'acos',
292
- 'argumentCount' => '1'
293
- ),
294
- 'ACOSH' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
295
- 'functionCall' => 'acosh',
296
- 'argumentCount' => '1'
297
- ),
298
- 'ADDRESS' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
299
- 'functionCall' => 'PHPExcel_Calculation_LookupRef::CELL_ADDRESS',
300
- 'argumentCount' => '2-5'
301
- ),
302
- 'AMORDEGRC' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
303
- 'functionCall' => 'PHPExcel_Calculation_Financial::AMORDEGRC',
304
- 'argumentCount' => '6,7'
305
- ),
306
- 'AMORLINC' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
307
- 'functionCall' => 'PHPExcel_Calculation_Financial::AMORLINC',
308
- 'argumentCount' => '6,7'
309
- ),
310
- 'AND' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOGICAL,
311
- 'functionCall' => 'PHPExcel_Calculation_Logical::LOGICAL_AND',
312
- 'argumentCount' => '1+'
313
- ),
314
- 'AREAS' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
315
- 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
316
- 'argumentCount' => '1'
317
- ),
318
- 'ASC' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
319
- 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
320
- 'argumentCount' => '1'
321
- ),
322
- 'ASIN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
323
- 'functionCall' => 'asin',
324
- 'argumentCount' => '1'
325
- ),
326
- 'ASINH' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
327
- 'functionCall' => 'asinh',
328
- 'argumentCount' => '1'
329
- ),
330
- 'ATAN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
331
- 'functionCall' => 'atan',
332
- 'argumentCount' => '1'
333
- ),
334
- 'ATAN2' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
335
- 'functionCall' => 'PHPExcel_Calculation_MathTrig::ATAN2',
336
- 'argumentCount' => '2'
337
- ),
338
- 'ATANH' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
339
- 'functionCall' => 'atanh',
340
- 'argumentCount' => '1'
341
- ),
342
- 'AVEDEV' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
343
- 'functionCall' => 'PHPExcel_Calculation_Statistical::AVEDEV',
344
- 'argumentCount' => '1+'
345
- ),
346
- 'AVERAGE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
347
- 'functionCall' => 'PHPExcel_Calculation_Statistical::AVERAGE',
348
- 'argumentCount' => '1+'
349
- ),
350
- 'AVERAGEA' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
351
- 'functionCall' => 'PHPExcel_Calculation_Statistical::AVERAGEA',
352
- 'argumentCount' => '1+'
353
- ),
354
- 'AVERAGEIF' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
355
- 'functionCall' => 'PHPExcel_Calculation_Statistical::AVERAGEIF',
356
- 'argumentCount' => '2,3'
357
- ),
358
- 'AVERAGEIFS' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
359
- 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
360
- 'argumentCount' => '3+'
361
- ),
362
- 'BAHTTEXT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
363
- 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
364
- 'argumentCount' => '1'
365
- ),
366
- 'BESSELI' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
367
- 'functionCall' => 'PHPExcel_Calculation_Engineering::BESSELI',
368
- 'argumentCount' => '2'
369
- ),
370
- 'BESSELJ' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
371
- 'functionCall' => 'PHPExcel_Calculation_Engineering::BESSELJ',
372
- 'argumentCount' => '2'
373
- ),
374
- 'BESSELK' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
375
- 'functionCall' => 'PHPExcel_Calculation_Engineering::BESSELK',
376
- 'argumentCount' => '2'
377
- ),
378
- 'BESSELY' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
379
- 'functionCall' => 'PHPExcel_Calculation_Engineering::BESSELY',
380
- 'argumentCount' => '2'
381
- ),
382
- 'BETADIST' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
383
- 'functionCall' => 'PHPExcel_Calculation_Statistical::BETADIST',
384
- 'argumentCount' => '3-5'
385
- ),
386
- 'BETAINV' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
387
- 'functionCall' => 'PHPExcel_Calculation_Statistical::BETAINV',
388
- 'argumentCount' => '3-5'
389
- ),
390
- 'BIN2DEC' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
391
- 'functionCall' => 'PHPExcel_Calculation_Engineering::BINTODEC',
392
- 'argumentCount' => '1'
393
- ),
394
- 'BIN2HEX' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
395
- 'functionCall' => 'PHPExcel_Calculation_Engineering::BINTOHEX',
396
- 'argumentCount' => '1,2'
397
- ),
398
- 'BIN2OCT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
399
- 'functionCall' => 'PHPExcel_Calculation_Engineering::BINTOOCT',
400
- 'argumentCount' => '1,2'
401
- ),
402
- 'BINOMDIST' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
403
- 'functionCall' => 'PHPExcel_Calculation_Statistical::BINOMDIST',
404
- 'argumentCount' => '4'
405
- ),
406
- 'CEILING' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
407
- 'functionCall' => 'PHPExcel_Calculation_MathTrig::CEILING',
408
- 'argumentCount' => '2'
409
- ),
410
- 'CELL' => array('category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
411
- 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
412
- 'argumentCount' => '1,2'
413
- ),
414
- 'CHAR' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
415
- 'functionCall' => 'PHPExcel_Calculation_TextData::CHARACTER',
416
- 'argumentCount' => '1'
417
- ),
418
- 'CHIDIST' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
419
- 'functionCall' => 'PHPExcel_Calculation_Statistical::CHIDIST',
420
- 'argumentCount' => '2'
421
- ),
422
- 'CHIINV' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
423
- 'functionCall' => 'PHPExcel_Calculation_Statistical::CHIINV',
424
- 'argumentCount' => '2'
425
- ),
426
- 'CHITEST' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
427
- 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
428
- 'argumentCount' => '2'
429
- ),
430
- 'CHOOSE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
431
- 'functionCall' => 'PHPExcel_Calculation_LookupRef::CHOOSE',
432
- 'argumentCount' => '2+'
433
- ),
434
- 'CLEAN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
435
- 'functionCall' => 'PHPExcel_Calculation_TextData::TRIMNONPRINTABLE',
436
- 'argumentCount' => '1'
437
- ),
438
- 'CODE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
439
- 'functionCall' => 'PHPExcel_Calculation_TextData::ASCIICODE',
440
- 'argumentCount' => '1'
441
- ),
442
- 'COLUMN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
443
- 'functionCall' => 'PHPExcel_Calculation_LookupRef::COLUMN',
444
- 'argumentCount' => '-1',
445
- 'passByReference' => array(TRUE)
446
- ),
447
- 'COLUMNS' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
448
- 'functionCall' => 'PHPExcel_Calculation_LookupRef::COLUMNS',
449
- 'argumentCount' => '1'
450
- ),
451
- 'COMBIN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
452
- 'functionCall' => 'PHPExcel_Calculation_MathTrig::COMBIN',
453
- 'argumentCount' => '2'
454
- ),
455
- 'COMPLEX' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
456
- 'functionCall' => 'PHPExcel_Calculation_Engineering::COMPLEX',
457
- 'argumentCount' => '2,3'
458
- ),
459
- 'CONCATENATE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
460
- 'functionCall' => 'PHPExcel_Calculation_TextData::CONCATENATE',
461
- 'argumentCount' => '1+'
462
- ),
463
- 'CONFIDENCE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
464
- 'functionCall' => 'PHPExcel_Calculation_Statistical::CONFIDENCE',
465
- 'argumentCount' => '3'
466
- ),
467
- 'CONVERT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
468
- 'functionCall' => 'PHPExcel_Calculation_Engineering::CONVERTUOM',
469
- 'argumentCount' => '3'
470
- ),
471
- 'CORREL' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
472
- 'functionCall' => 'PHPExcel_Calculation_Statistical::CORREL',
473
- 'argumentCount' => '2'
474
- ),
475
- 'COS' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
476
- 'functionCall' => 'cos',
477
- 'argumentCount' => '1'
478
- ),
479
- 'COSH' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
480
- 'functionCall' => 'cosh',
481
- 'argumentCount' => '1'
482
- ),
483
- 'COUNT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
484
- 'functionCall' => 'PHPExcel_Calculation_Statistical::COUNT',
485
- 'argumentCount' => '1+'
486
- ),
487
- 'COUNTA' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
488
- 'functionCall' => 'PHPExcel_Calculation_Statistical::COUNTA',
489
- 'argumentCount' => '1+'
490
- ),
491
- 'COUNTBLANK' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
492
- 'functionCall' => 'PHPExcel_Calculation_Statistical::COUNTBLANK',
493
- 'argumentCount' => '1'
494
- ),
495
- 'COUNTIF' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
496
- 'functionCall' => 'PHPExcel_Calculation_Statistical::COUNTIF',
497
- 'argumentCount' => '2'
498
- ),
499
- 'COUNTIFS' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
500
- 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
501
- 'argumentCount' => '2'
502
- ),
503
- 'COUPDAYBS' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
504
- 'functionCall' => 'PHPExcel_Calculation_Financial::COUPDAYBS',
505
- 'argumentCount' => '3,4'
506
- ),
507
- 'COUPDAYS' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
508
- 'functionCall' => 'PHPExcel_Calculation_Financial::COUPDAYS',
509
- 'argumentCount' => '3,4'
510
- ),
511
- 'COUPDAYSNC' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
512
- 'functionCall' => 'PHPExcel_Calculation_Financial::COUPDAYSNC',
513
- 'argumentCount' => '3,4'
514
- ),
515
- 'COUPNCD' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
516
- 'functionCall' => 'PHPExcel_Calculation_Financial::COUPNCD',
517
- 'argumentCount' => '3,4'
518
- ),
519
- 'COUPNUM' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
520
- 'functionCall' => 'PHPExcel_Calculation_Financial::COUPNUM',
521
- 'argumentCount' => '3,4'
522
- ),
523
- 'COUPPCD' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
524
- 'functionCall' => 'PHPExcel_Calculation_Financial::COUPPCD',
525
- 'argumentCount' => '3,4'
526
- ),
527
- 'COVAR' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
528
- 'functionCall' => 'PHPExcel_Calculation_Statistical::COVAR',
529
- 'argumentCount' => '2'
530
- ),
531
- 'CRITBINOM' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
532
- 'functionCall' => 'PHPExcel_Calculation_Statistical::CRITBINOM',
533
- 'argumentCount' => '3'
534
- ),
535
- 'CUBEKPIMEMBER' => array('category' => PHPExcel_Calculation_Function::CATEGORY_CUBE,
536
- 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
537
- 'argumentCount' => '?'
538
- ),
539
- 'CUBEMEMBER' => array('category' => PHPExcel_Calculation_Function::CATEGORY_CUBE,
540
- 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
541
- 'argumentCount' => '?'
542
- ),
543
- 'CUBEMEMBERPROPERTY' => array('category' => PHPExcel_Calculation_Function::CATEGORY_CUBE,
544
- 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
545
- 'argumentCount' => '?'
546
- ),
547
- 'CUBERANKEDMEMBER' => array('category' => PHPExcel_Calculation_Function::CATEGORY_CUBE,
548
- 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
549
- 'argumentCount' => '?'
550
- ),
551
- 'CUBESET' => array('category' => PHPExcel_Calculation_Function::CATEGORY_CUBE,
552
- 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
553
- 'argumentCount' => '?'
554
- ),
555
- 'CUBESETCOUNT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_CUBE,
556
- 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
557
- 'argumentCount' => '?'
558
- ),
559
- 'CUBEVALUE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_CUBE,
560
- 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
561
- 'argumentCount' => '?'
562
- ),
563
- 'CUMIPMT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
564
- 'functionCall' => 'PHPExcel_Calculation_Financial::CUMIPMT',
565
- 'argumentCount' => '6'
566
- ),
567
- 'CUMPRINC' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
568
- 'functionCall' => 'PHPExcel_Calculation_Financial::CUMPRINC',
569
- 'argumentCount' => '6'
570
- ),
571
- 'DATE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
572
- 'functionCall' => 'PHPExcel_Calculation_DateTime::DATE',
573
- 'argumentCount' => '3'
574
- ),
575
- 'DATEDIF' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
576
- 'functionCall' => 'PHPExcel_Calculation_DateTime::DATEDIF',
577
- 'argumentCount' => '2,3'
578
- ),
579
- 'DATEVALUE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
580
- 'functionCall' => 'PHPExcel_Calculation_DateTime::DATEVALUE',
581
- 'argumentCount' => '1'
582
- ),
583
- 'DAVERAGE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATABASE,
584
- 'functionCall' => 'PHPExcel_Calculation_Database::DAVERAGE',
585
- 'argumentCount' => '3'
586
- ),
587
- 'DAY' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
588
- 'functionCall' => 'PHPExcel_Calculation_DateTime::DAYOFMONTH',
589
- 'argumentCount' => '1'
590
- ),
591
- 'DAYS360' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
592
- 'functionCall' => 'PHPExcel_Calculation_DateTime::DAYS360',
593
- 'argumentCount' => '2,3'
594
- ),
595
- 'DB' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
596
- 'functionCall' => 'PHPExcel_Calculation_Financial::DB',
597
- 'argumentCount' => '4,5'
598
- ),
599
- 'DCOUNT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATABASE,
600
- 'functionCall' => 'PHPExcel_Calculation_Database::DCOUNT',
601
- 'argumentCount' => '3'
602
- ),
603
- 'DCOUNTA' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATABASE,
604
- 'functionCall' => 'PHPExcel_Calculation_Database::DCOUNTA',
605
- 'argumentCount' => '3'
606
- ),
607
- 'DDB' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
608
- 'functionCall' => 'PHPExcel_Calculation_Financial::DDB',
609
- 'argumentCount' => '4,5'
610
- ),
611
- 'DEC2BIN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
612
- 'functionCall' => 'PHPExcel_Calculation_Engineering::DECTOBIN',
613
- 'argumentCount' => '1,2'
614
- ),
615
- 'DEC2HEX' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
616
- 'functionCall' => 'PHPExcel_Calculation_Engineering::DECTOHEX',
617
- 'argumentCount' => '1,2'
618
- ),
619
- 'DEC2OCT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
620
- 'functionCall' => 'PHPExcel_Calculation_Engineering::DECTOOCT',
621
- 'argumentCount' => '1,2'
622
- ),
623
- 'DEGREES' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
624
- 'functionCall' => 'rad2deg',
625
- 'argumentCount' => '1'
626
- ),
627
- 'DELTA' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
628
- 'functionCall' => 'PHPExcel_Calculation_Engineering::DELTA',
629
- 'argumentCount' => '1,2'
630
- ),
631
- 'DEVSQ' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
632
- 'functionCall' => 'PHPExcel_Calculation_Statistical::DEVSQ',
633
- 'argumentCount' => '1+'
634
- ),
635
- 'DGET' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATABASE,
636
- 'functionCall' => 'PHPExcel_Calculation_Database::DGET',
637
- 'argumentCount' => '3'
638
- ),
639
- 'DISC' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
640
- 'functionCall' => 'PHPExcel_Calculation_Financial::DISC',
641
- 'argumentCount' => '4,5'
642
- ),
643
- 'DMAX' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATABASE,
644
- 'functionCall' => 'PHPExcel_Calculation_Database::DMAX',
645
- 'argumentCount' => '3'
646
- ),
647
- 'DMIN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATABASE,
648
- 'functionCall' => 'PHPExcel_Calculation_Database::DMIN',
649
- 'argumentCount' => '3'
650
- ),
651
- 'DOLLAR' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
652
- 'functionCall' => 'PHPExcel_Calculation_TextData::DOLLAR',
653
- 'argumentCount' => '1,2'
654
- ),
655
- 'DOLLARDE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
656
- 'functionCall' => 'PHPExcel_Calculation_Financial::DOLLARDE',
657
- 'argumentCount' => '2'
658
- ),
659
- 'DOLLARFR' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
660
- 'functionCall' => 'PHPExcel_Calculation_Financial::DOLLARFR',
661
- 'argumentCount' => '2'
662
- ),
663
- 'DPRODUCT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATABASE,
664
- 'functionCall' => 'PHPExcel_Calculation_Database::DPRODUCT',
665
- 'argumentCount' => '3'
666
- ),
667
- 'DSTDEV' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATABASE,
668
- 'functionCall' => 'PHPExcel_Calculation_Database::DSTDEV',
669
- 'argumentCount' => '3'
670
- ),
671
- 'DSTDEVP' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATABASE,
672
- 'functionCall' => 'PHPExcel_Calculation_Database::DSTDEVP',
673
- 'argumentCount' => '3'
674
- ),
675
- 'DSUM' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATABASE,
676
- 'functionCall' => 'PHPExcel_Calculation_Database::DSUM',
677
- 'argumentCount' => '3'
678
- ),
679
- 'DURATION' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
680
- 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
681
- 'argumentCount' => '5,6'
682
- ),
683
- 'DVAR' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATABASE,
684
- 'functionCall' => 'PHPExcel_Calculation_Database::DVAR',
685
- 'argumentCount' => '3'
686
- ),
687
- 'DVARP' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATABASE,
688
- 'functionCall' => 'PHPExcel_Calculation_Database::DVARP',
689
- 'argumentCount' => '3'
690
- ),
691
- 'EDATE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
692
- 'functionCall' => 'PHPExcel_Calculation_DateTime::EDATE',
693
- 'argumentCount' => '2'
694
- ),
695
- 'EFFECT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
696
- 'functionCall' => 'PHPExcel_Calculation_Financial::EFFECT',
697
- 'argumentCount' => '2'
698
- ),
699
- 'EOMONTH' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
700
- 'functionCall' => 'PHPExcel_Calculation_DateTime::EOMONTH',
701
- 'argumentCount' => '2'
702
- ),
703
- 'ERF' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
704
- 'functionCall' => 'PHPExcel_Calculation_Engineering::ERF',
705
- 'argumentCount' => '1,2'
706
- ),
707
- 'ERFC' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
708
- 'functionCall' => 'PHPExcel_Calculation_Engineering::ERFC',
709
- 'argumentCount' => '1'
710
- ),
711
- 'ERROR.TYPE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
712
- 'functionCall' => 'PHPExcel_Calculation_Functions::ERROR_TYPE',
713
- 'argumentCount' => '1'
714
- ),
715
- 'EVEN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
716
- 'functionCall' => 'PHPExcel_Calculation_MathTrig::EVEN',
717
- 'argumentCount' => '1'
718
- ),
719
- 'EXACT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
720
- 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
721
- 'argumentCount' => '2'
722
- ),
723
- 'EXP' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
724
- 'functionCall' => 'exp',
725
- 'argumentCount' => '1'
726
- ),
727
- 'EXPONDIST' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
728
- 'functionCall' => 'PHPExcel_Calculation_Statistical::EXPONDIST',
729
- 'argumentCount' => '3'
730
- ),
731
- 'FACT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
732
- 'functionCall' => 'PHPExcel_Calculation_MathTrig::FACT',
733
- 'argumentCount' => '1'
734
- ),
735
- 'FACTDOUBLE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
736
- 'functionCall' => 'PHPExcel_Calculation_MathTrig::FACTDOUBLE',
737
- 'argumentCount' => '1'
738
- ),
739
- 'FALSE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOGICAL,
740
- 'functionCall' => 'PHPExcel_Calculation_Logical::FALSE',
741
- 'argumentCount' => '0'
742
- ),
743
- 'FDIST' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
744
- 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
745
- 'argumentCount' => '3'
746
- ),
747
- 'FIND' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
748
- 'functionCall' => 'PHPExcel_Calculation_TextData::SEARCHSENSITIVE',
749
- 'argumentCount' => '2,3'
750
- ),
751
- 'FINDB' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
752
- 'functionCall' => 'PHPExcel_Calculation_TextData::SEARCHSENSITIVE',
753
- 'argumentCount' => '2,3'
754
- ),
755
- 'FINV' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
756
- 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
757
- 'argumentCount' => '3'
758
- ),
759
- 'FISHER' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
760
- 'functionCall' => 'PHPExcel_Calculation_Statistical::FISHER',
761
- 'argumentCount' => '1'
762
- ),
763
- 'FISHERINV' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
764
- 'functionCall' => 'PHPExcel_Calculation_Statistical::FISHERINV',
765
- 'argumentCount' => '1'
766
- ),
767
- 'FIXED' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
768
- 'functionCall' => 'PHPExcel_Calculation_TextData::FIXEDFORMAT',
769
- 'argumentCount' => '1-3'
770
- ),
771
- 'FLOOR' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
772
- 'functionCall' => 'PHPExcel_Calculation_MathTrig::FLOOR',
773
- 'argumentCount' => '2'
774
- ),
775
- 'FORECAST' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
776
- 'functionCall' => 'PHPExcel_Calculation_Statistical::FORECAST',
777
- 'argumentCount' => '3'
778
- ),
779
- 'FREQUENCY' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
780
- 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
781
- 'argumentCount' => '2'
782
- ),
783
- 'FTEST' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
784
- 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
785
- 'argumentCount' => '2'
786
- ),
787
- 'FV' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
788
- 'functionCall' => 'PHPExcel_Calculation_Financial::FV',
789
- 'argumentCount' => '3-5'
790
- ),
791
- 'FVSCHEDULE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
792
- 'functionCall' => 'PHPExcel_Calculation_Financial::FVSCHEDULE',
793
- 'argumentCount' => '2'
794
- ),
795
- 'GAMMADIST' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
796
- 'functionCall' => 'PHPExcel_Calculation_Statistical::GAMMADIST',
797
- 'argumentCount' => '4'
798
- ),
799
- 'GAMMAINV' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
800
- 'functionCall' => 'PHPExcel_Calculation_Statistical::GAMMAINV',
801
- 'argumentCount' => '3'
802
- ),
803
- 'GAMMALN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
804
- 'functionCall' => 'PHPExcel_Calculation_Statistical::GAMMALN',
805
- 'argumentCount' => '1'
806
- ),
807
- 'GCD' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
808
- 'functionCall' => 'PHPExcel_Calculation_MathTrig::GCD',
809
- 'argumentCount' => '1+'
810
- ),
811
- 'GEOMEAN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
812
- 'functionCall' => 'PHPExcel_Calculation_Statistical::GEOMEAN',
813
- 'argumentCount' => '1+'
814
- ),
815
- 'GESTEP' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
816
- 'functionCall' => 'PHPExcel_Calculation_Engineering::GESTEP',
817
- 'argumentCount' => '1,2'
818
- ),
819
- 'GETPIVOTDATA' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
820
- 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
821
- 'argumentCount' => '2+'
822
- ),
823
- 'GROWTH' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
824
- 'functionCall' => 'PHPExcel_Calculation_Statistical::GROWTH',
825
- 'argumentCount' => '1-4'
826
- ),
827
- 'HARMEAN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
828
- 'functionCall' => 'PHPExcel_Calculation_Statistical::HARMEAN',
829
- 'argumentCount' => '1+'
830
- ),
831
- 'HEX2BIN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
832
- 'functionCall' => 'PHPExcel_Calculation_Engineering::HEXTOBIN',
833
- 'argumentCount' => '1,2'
834
- ),
835
- 'HEX2DEC' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
836
- 'functionCall' => 'PHPExcel_Calculation_Engineering::HEXTODEC',
837
- 'argumentCount' => '1'
838
- ),
839
- 'HEX2OCT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
840
- 'functionCall' => 'PHPExcel_Calculation_Engineering::HEXTOOCT',
841
- 'argumentCount' => '1,2'
842
- ),
843
- 'HLOOKUP' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
844
- 'functionCall' => 'PHPExcel_Calculation_LookupRef::HLOOKUP',
845
- 'argumentCount' => '3,4'
846
- ),
847
- 'HOUR' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
848
- 'functionCall' => 'PHPExcel_Calculation_DateTime::HOUROFDAY',
849
- 'argumentCount' => '1'
850
- ),
851
- 'HYPERLINK' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
852
- 'functionCall' => 'PHPExcel_Calculation_LookupRef::HYPERLINK',
853
- 'argumentCount' => '1,2',
854
- 'passCellReference'=> TRUE
855
- ),
856
- 'HYPGEOMDIST' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
857
- 'functionCall' => 'PHPExcel_Calculation_Statistical::HYPGEOMDIST',
858
- 'argumentCount' => '4'
859
- ),
860
- 'IF' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOGICAL,
861
- 'functionCall' => 'PHPExcel_Calculation_Logical::STATEMENT_IF',
862
- 'argumentCount' => '1-3'
863
- ),
864
- 'IFERROR' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOGICAL,
865
- 'functionCall' => 'PHPExcel_Calculation_Logical::IFERROR',
866
- 'argumentCount' => '2'
867
- ),
868
- 'IMABS' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
869
- 'functionCall' => 'PHPExcel_Calculation_Engineering::IMABS',
870
- 'argumentCount' => '1'
871
- ),
872
- 'IMAGINARY' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
873
- 'functionCall' => 'PHPExcel_Calculation_Engineering::IMAGINARY',
874
- 'argumentCount' => '1'
875
- ),
876
- 'IMARGUMENT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
877
- 'functionCall' => 'PHPExcel_Calculation_Engineering::IMARGUMENT',
878
- 'argumentCount' => '1'
879
- ),
880
- 'IMCONJUGATE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
881
- 'functionCall' => 'PHPExcel_Calculation_Engineering::IMCONJUGATE',
882
- 'argumentCount' => '1'
883
- ),
884
- 'IMCOS' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
885
- 'functionCall' => 'PHPExcel_Calculation_Engineering::IMCOS',
886
- 'argumentCount' => '1'
887
- ),
888
- 'IMDIV' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
889
- 'functionCall' => 'PHPExcel_Calculation_Engineering::IMDIV',
890
- 'argumentCount' => '2'
891
- ),
892
- 'IMEXP' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
893
- 'functionCall' => 'PHPExcel_Calculation_Engineering::IMEXP',
894
- 'argumentCount' => '1'
895
- ),
896
- 'IMLN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
897
- 'functionCall' => 'PHPExcel_Calculation_Engineering::IMLN',
898
- 'argumentCount' => '1'
899
- ),
900
- 'IMLOG10' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
901
- 'functionCall' => 'PHPExcel_Calculation_Engineering::IMLOG10',
902
- 'argumentCount' => '1'
903
- ),
904
- 'IMLOG2' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
905
- 'functionCall' => 'PHPExcel_Calculation_Engineering::IMLOG2',
906
- 'argumentCount' => '1'
907
- ),
908
- 'IMPOWER' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
909
- 'functionCall' => 'PHPExcel_Calculation_Engineering::IMPOWER',
910
- 'argumentCount' => '2'
911
- ),
912
- 'IMPRODUCT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
913
- 'functionCall' => 'PHPExcel_Calculation_Engineering::IMPRODUCT',
914
- 'argumentCount' => '1+'
915
- ),
916
- 'IMREAL' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
917
- 'functionCall' => 'PHPExcel_Calculation_Engineering::IMREAL',
918
- 'argumentCount' => '1'
919
- ),
920
- 'IMSIN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
921
- 'functionCall' => 'PHPExcel_Calculation_Engineering::IMSIN',
922
- 'argumentCount' => '1'
923
- ),
924
- 'IMSQRT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
925
- 'functionCall' => 'PHPExcel_Calculation_Engineering::IMSQRT',
926
- 'argumentCount' => '1'
927
- ),
928
- 'IMSUB' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
929
- 'functionCall' => 'PHPExcel_Calculation_Engineering::IMSUB',
930
- 'argumentCount' => '2'
931
- ),
932
- 'IMSUM' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
933
- 'functionCall' => 'PHPExcel_Calculation_Engineering::IMSUM',
934
- 'argumentCount' => '1+'
935
- ),
936
- 'INDEX' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
937
- 'functionCall' => 'PHPExcel_Calculation_LookupRef::INDEX',
938
- 'argumentCount' => '1-4'
939
- ),
940
- 'INDIRECT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
941
- 'functionCall' => 'PHPExcel_Calculation_LookupRef::INDIRECT',
942
- 'argumentCount' => '1,2',
943
- 'passCellReference'=> TRUE
944
- ),
945
- 'INFO' => array('category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
946
- 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
947
- 'argumentCount' => '1'
948
- ),
949
- 'INT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
950
- 'functionCall' => 'PHPExcel_Calculation_MathTrig::INT',
951
- 'argumentCount' => '1'
952
- ),
953
- 'INTERCEPT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
954
- 'functionCall' => 'PHPExcel_Calculation_Statistical::INTERCEPT',
955
- 'argumentCount' => '2'
956
- ),
957
- 'INTRATE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
958
- 'functionCall' => 'PHPExcel_Calculation_Financial::INTRATE',
959
- 'argumentCount' => '4,5'
960
- ),
961
- 'IPMT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
962
- 'functionCall' => 'PHPExcel_Calculation_Financial::IPMT',
963
- 'argumentCount' => '4-6'
964
- ),
965
- 'IRR' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
966
- 'functionCall' => 'PHPExcel_Calculation_Financial::IRR',
967
- 'argumentCount' => '1,2'
968
- ),
969
- 'ISBLANK' => array('category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
970
- 'functionCall' => 'PHPExcel_Calculation_Functions::IS_BLANK',
971
- 'argumentCount' => '1'
972
- ),
973
- 'ISERR' => array('category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
974
- 'functionCall' => 'PHPExcel_Calculation_Functions::IS_ERR',
975
- 'argumentCount' => '1'
976
- ),
977
- 'ISERROR' => array('category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
978
- 'functionCall' => 'PHPExcel_Calculation_Functions::IS_ERROR',
979
- 'argumentCount' => '1'
980
- ),
981
- 'ISEVEN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
982
- 'functionCall' => 'PHPExcel_Calculation_Functions::IS_EVEN',
983
- 'argumentCount' => '1'
984
- ),
985
- 'ISLOGICAL' => array('category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
986
- 'functionCall' => 'PHPExcel_Calculation_Functions::IS_LOGICAL',
987
- 'argumentCount' => '1'
988
- ),
989
- 'ISNA' => array('category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
990
- 'functionCall' => 'PHPExcel_Calculation_Functions::IS_NA',
991
- 'argumentCount' => '1'
992
- ),
993
- 'ISNONTEXT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
994
- 'functionCall' => 'PHPExcel_Calculation_Functions::IS_NONTEXT',
995
- 'argumentCount' => '1'
996
- ),
997
- 'ISNUMBER' => array('category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
998
- 'functionCall' => 'PHPExcel_Calculation_Functions::IS_NUMBER',
999
- 'argumentCount' => '1'
1000
- ),
1001
- 'ISODD' => array('category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
1002
- 'functionCall' => 'PHPExcel_Calculation_Functions::IS_ODD',
1003
- 'argumentCount' => '1'
1004
- ),
1005
- 'ISPMT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1006
- 'functionCall' => 'PHPExcel_Calculation_Financial::ISPMT',
1007
- 'argumentCount' => '4'
1008
- ),
1009
- 'ISREF' => array('category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
1010
- 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
1011
- 'argumentCount' => '1'
1012
- ),
1013
- 'ISTEXT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
1014
- 'functionCall' => 'PHPExcel_Calculation_Functions::IS_TEXT',
1015
- 'argumentCount' => '1'
1016
- ),
1017
- 'JIS' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
1018
- 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
1019
- 'argumentCount' => '1'
1020
- ),
1021
- 'KURT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1022
- 'functionCall' => 'PHPExcel_Calculation_Statistical::KURT',
1023
- 'argumentCount' => '1+'
1024
- ),
1025
- 'LARGE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1026
- 'functionCall' => 'PHPExcel_Calculation_Statistical::LARGE',
1027
- 'argumentCount' => '2'
1028
- ),
1029
- 'LCM' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1030
- 'functionCall' => 'PHPExcel_Calculation_MathTrig::LCM',
1031
- 'argumentCount' => '1+'
1032
- ),
1033
- 'LEFT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
1034
- 'functionCall' => 'PHPExcel_Calculation_TextData::LEFT',
1035
- 'argumentCount' => '1,2'
1036
- ),
1037
- 'LEFTB' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
1038
- 'functionCall' => 'PHPExcel_Calculation_TextData::LEFT',
1039
- 'argumentCount' => '1,2'
1040
- ),
1041
- 'LEN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
1042
- 'functionCall' => 'PHPExcel_Calculation_TextData::STRINGLENGTH',
1043
- 'argumentCount' => '1'
1044
- ),
1045
- 'LENB' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
1046
- 'functionCall' => 'PHPExcel_Calculation_TextData::STRINGLENGTH',
1047
- 'argumentCount' => '1'
1048
- ),
1049
- 'LINEST' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1050
- 'functionCall' => 'PHPExcel_Calculation_Statistical::LINEST',
1051
- 'argumentCount' => '1-4'
1052
- ),
1053
- 'LN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1054
- 'functionCall' => 'log',
1055
- 'argumentCount' => '1'
1056
- ),
1057
- 'LOG' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1058
- 'functionCall' => 'PHPExcel_Calculation_MathTrig::LOG_BASE',
1059
- 'argumentCount' => '1,2'
1060
- ),
1061
- 'LOG10' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1062
- 'functionCall' => 'log10',
1063
- 'argumentCount' => '1'
1064
- ),
1065
- 'LOGEST' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1066
- 'functionCall' => 'PHPExcel_Calculation_Statistical::LOGEST',
1067
- 'argumentCount' => '1-4'
1068
- ),
1069
- 'LOGINV' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1070
- 'functionCall' => 'PHPExcel_Calculation_Statistical::LOGINV',
1071
- 'argumentCount' => '3'
1072
- ),
1073
- 'LOGNORMDIST' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1074
- 'functionCall' => 'PHPExcel_Calculation_Statistical::LOGNORMDIST',
1075
- 'argumentCount' => '3'
1076
- ),
1077
- 'LOOKUP' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
1078
- 'functionCall' => 'PHPExcel_Calculation_LookupRef::LOOKUP',
1079
- 'argumentCount' => '2,3'
1080
- ),
1081
- 'LOWER' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
1082
- 'functionCall' => 'PHPExcel_Calculation_TextData::LOWERCASE',
1083
- 'argumentCount' => '1'
1084
- ),
1085
- 'MATCH' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
1086
- 'functionCall' => 'PHPExcel_Calculation_LookupRef::MATCH',
1087
- 'argumentCount' => '2,3'
1088
- ),
1089
- 'MAX' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1090
- 'functionCall' => 'PHPExcel_Calculation_Statistical::MAX',
1091
- 'argumentCount' => '1+'
1092
- ),
1093
- 'MAXA' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1094
- 'functionCall' => 'PHPExcel_Calculation_Statistical::MAXA',
1095
- 'argumentCount' => '1+'
1096
- ),
1097
- 'MAXIF' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1098
- 'functionCall' => 'PHPExcel_Calculation_Statistical::MAXIF',
1099
- 'argumentCount' => '2+'
1100
- ),
1101
- 'MDETERM' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1102
- 'functionCall' => 'PHPExcel_Calculation_MathTrig::MDETERM',
1103
- 'argumentCount' => '1'
1104
- ),
1105
- 'MDURATION' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1106
- 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
1107
- 'argumentCount' => '5,6'
1108
- ),
1109
- 'MEDIAN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1110
- 'functionCall' => 'PHPExcel_Calculation_Statistical::MEDIAN',
1111
- 'argumentCount' => '1+'
1112
- ),
1113
- 'MEDIANIF' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1114
- 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
1115
- 'argumentCount' => '2+'
1116
- ),
1117
- 'MID' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
1118
- 'functionCall' => 'PHPExcel_Calculation_TextData::MID',
1119
- 'argumentCount' => '3'
1120
- ),
1121
- 'MIDB' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
1122
- 'functionCall' => 'PHPExcel_Calculation_TextData::MID',
1123
- 'argumentCount' => '3'
1124
- ),
1125
- 'MIN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1126
- 'functionCall' => 'PHPExcel_Calculation_Statistical::MIN',
1127
- 'argumentCount' => '1+'
1128
- ),
1129
- 'MINA' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1130
- 'functionCall' => 'PHPExcel_Calculation_Statistical::MINA',
1131
- 'argumentCount' => '1+'
1132
- ),
1133
- 'MINIF' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1134
- 'functionCall' => 'PHPExcel_Calculation_Statistical::MINIF',
1135
- 'argumentCount' => '2+'
1136
- ),
1137
- 'MINUTE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
1138
- 'functionCall' => 'PHPExcel_Calculation_DateTime::MINUTEOFHOUR',
1139
- 'argumentCount' => '1'
1140
- ),
1141
- 'MINVERSE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1142
- 'functionCall' => 'PHPExcel_Calculation_MathTrig::MINVERSE',
1143
- 'argumentCount' => '1'
1144
- ),
1145
- 'MIRR' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1146
- 'functionCall' => 'PHPExcel_Calculation_Financial::MIRR',
1147
- 'argumentCount' => '3'
1148
- ),
1149
- 'MMULT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1150
- 'functionCall' => 'PHPExcel_Calculation_MathTrig::MMULT',
1151
- 'argumentCount' => '2'
1152
- ),
1153
- 'MOD' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1154
- 'functionCall' => 'PHPExcel_Calculation_MathTrig::MOD',
1155
- 'argumentCount' => '2'
1156
- ),
1157
- 'MODE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1158
- 'functionCall' => 'PHPExcel_Calculation_Statistical::MODE',
1159
- 'argumentCount' => '1+'
1160
- ),
1161
- 'MONTH' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
1162
- 'functionCall' => 'PHPExcel_Calculation_DateTime::MONTHOFYEAR',
1163
- 'argumentCount' => '1'
1164
- ),
1165
- 'MROUND' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1166
- 'functionCall' => 'PHPExcel_Calculation_MathTrig::MROUND',
1167
- 'argumentCount' => '2'
1168
- ),
1169
- 'MULTINOMIAL' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1170
- 'functionCall' => 'PHPExcel_Calculation_MathTrig::MULTINOMIAL',
1171
- 'argumentCount' => '1+'
1172
- ),
1173
- 'N' => array('category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
1174
- 'functionCall' => 'PHPExcel_Calculation_Functions::N',
1175
- 'argumentCount' => '1'
1176
- ),
1177
- 'NA' => array('category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
1178
- 'functionCall' => 'PHPExcel_Calculation_Functions::NA',
1179
- 'argumentCount' => '0'
1180
- ),
1181
- 'NEGBINOMDIST' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1182
- 'functionCall' => 'PHPExcel_Calculation_Statistical::NEGBINOMDIST',
1183
- 'argumentCount' => '3'
1184
- ),
1185
- 'NETWORKDAYS' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
1186
- 'functionCall' => 'PHPExcel_Calculation_DateTime::NETWORKDAYS',
1187
- 'argumentCount' => '2+'
1188
- ),
1189
- 'NOMINAL' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1190
- 'functionCall' => 'PHPExcel_Calculation_Financial::NOMINAL',
1191
- 'argumentCount' => '2'
1192
- ),
1193
- 'NORMDIST' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1194
- 'functionCall' => 'PHPExcel_Calculation_Statistical::NORMDIST',
1195
- 'argumentCount' => '4'
1196
- ),
1197
- 'NORMINV' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1198
- 'functionCall' => 'PHPExcel_Calculation_Statistical::NORMINV',
1199
- 'argumentCount' => '3'
1200
- ),
1201
- 'NORMSDIST' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1202
- 'functionCall' => 'PHPExcel_Calculation_Statistical::NORMSDIST',
1203
- 'argumentCount' => '1'
1204
- ),
1205
- 'NORMSINV' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1206
- 'functionCall' => 'PHPExcel_Calculation_Statistical::NORMSINV',
1207
- 'argumentCount' => '1'
1208
- ),
1209
- 'NOT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOGICAL,
1210
- 'functionCall' => 'PHPExcel_Calculation_Logical::NOT',
1211
- 'argumentCount' => '1'
1212
- ),
1213
- 'NOW' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
1214
- 'functionCall' => 'PHPExcel_Calculation_DateTime::DATETIMENOW',
1215
- 'argumentCount' => '0'
1216
- ),
1217
- 'NPER' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1218
- 'functionCall' => 'PHPExcel_Calculation_Financial::NPER',
1219
- 'argumentCount' => '3-5'
1220
- ),
1221
- 'NPV' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1222
- 'functionCall' => 'PHPExcel_Calculation_Financial::NPV',
1223
- 'argumentCount' => '2+'
1224
- ),
1225
- 'OCT2BIN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
1226
- 'functionCall' => 'PHPExcel_Calculation_Engineering::OCTTOBIN',
1227
- 'argumentCount' => '1,2'
1228
- ),
1229
- 'OCT2DEC' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
1230
- 'functionCall' => 'PHPExcel_Calculation_Engineering::OCTTODEC',
1231
- 'argumentCount' => '1'
1232
- ),
1233
- 'OCT2HEX' => array('category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
1234
- 'functionCall' => 'PHPExcel_Calculation_Engineering::OCTTOHEX',
1235
- 'argumentCount' => '1,2'
1236
- ),
1237
- 'ODD' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1238
- 'functionCall' => 'PHPExcel_Calculation_MathTrig::ODD',
1239
- 'argumentCount' => '1'
1240
- ),
1241
- 'ODDFPRICE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1242
- 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
1243
- 'argumentCount' => '8,9'
1244
- ),
1245
- 'ODDFYIELD' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1246
- 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
1247
- 'argumentCount' => '8,9'
1248
- ),
1249
- 'ODDLPRICE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1250
- 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
1251
- 'argumentCount' => '7,8'
1252
- ),
1253
- 'ODDLYIELD' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1254
- 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
1255
- 'argumentCount' => '7,8'
1256
- ),
1257
- 'OFFSET' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
1258
- 'functionCall' => 'PHPExcel_Calculation_LookupRef::OFFSET',
1259
- 'argumentCount' => '3,5',
1260
- 'passCellReference'=> TRUE,
1261
- 'passByReference' => array(TRUE)
1262
- ),
1263
- 'OR' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOGICAL,
1264
- 'functionCall' => 'PHPExcel_Calculation_Logical::LOGICAL_OR',
1265
- 'argumentCount' => '1+'
1266
- ),
1267
- 'PEARSON' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1268
- 'functionCall' => 'PHPExcel_Calculation_Statistical::CORREL',
1269
- 'argumentCount' => '2'
1270
- ),
1271
- 'PERCENTILE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1272
- 'functionCall' => 'PHPExcel_Calculation_Statistical::PERCENTILE',
1273
- 'argumentCount' => '2'
1274
- ),
1275
- 'PERCENTRANK' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1276
- 'functionCall' => 'PHPExcel_Calculation_Statistical::PERCENTRANK',
1277
- 'argumentCount' => '2,3'
1278
- ),
1279
- 'PERMUT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1280
- 'functionCall' => 'PHPExcel_Calculation_Statistical::PERMUT',
1281
- 'argumentCount' => '2'
1282
- ),
1283
- 'PHONETIC' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
1284
- 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
1285
- 'argumentCount' => '1'
1286
- ),
1287
- 'PI' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1288
- 'functionCall' => 'pi',
1289
- 'argumentCount' => '0'
1290
- ),
1291
- 'PMT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1292
- 'functionCall' => 'PHPExcel_Calculation_Financial::PMT',
1293
- 'argumentCount' => '3-5'
1294
- ),
1295
- 'POISSON' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1296
- 'functionCall' => 'PHPExcel_Calculation_Statistical::POISSON',
1297
- 'argumentCount' => '3'
1298
- ),
1299
- 'POWER' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1300
- 'functionCall' => 'PHPExcel_Calculation_MathTrig::POWER',
1301
- 'argumentCount' => '2'
1302
- ),
1303
- 'PPMT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1304
- 'functionCall' => 'PHPExcel_Calculation_Financial::PPMT',
1305
- 'argumentCount' => '4-6'
1306
- ),
1307
- 'PRICE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1308
- 'functionCall' => 'PHPExcel_Calculation_Financial::PRICE',
1309
- 'argumentCount' => '6,7'
1310
- ),
1311
- 'PRICEDISC' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1312
- 'functionCall' => 'PHPExcel_Calculation_Financial::PRICEDISC',
1313
- 'argumentCount' => '4,5'
1314
- ),
1315
- 'PRICEMAT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1316
- 'functionCall' => 'PHPExcel_Calculation_Financial::PRICEMAT',
1317
- 'argumentCount' => '5,6'
1318
- ),
1319
- 'PROB' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1320
- 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
1321
- 'argumentCount' => '3,4'
1322
- ),
1323
- 'PRODUCT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1324
- 'functionCall' => 'PHPExcel_Calculation_MathTrig::PRODUCT',
1325
- 'argumentCount' => '1+'
1326
- ),
1327
- 'PROPER' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
1328
- 'functionCall' => 'PHPExcel_Calculation_TextData::PROPERCASE',
1329
- 'argumentCount' => '1'
1330
- ),
1331
- 'PV' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1332
- 'functionCall' => 'PHPExcel_Calculation_Financial::PV',
1333
- 'argumentCount' => '3-5'
1334
- ),
1335
- 'QUARTILE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1336
- 'functionCall' => 'PHPExcel_Calculation_Statistical::QUARTILE',
1337
- 'argumentCount' => '2'
1338
- ),
1339
- 'QUOTIENT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1340
- 'functionCall' => 'PHPExcel_Calculation_MathTrig::QUOTIENT',
1341
- 'argumentCount' => '2'
1342
- ),
1343
- 'RADIANS' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1344
- 'functionCall' => 'deg2rad',
1345
- 'argumentCount' => '1'
1346
- ),
1347
- 'RAND' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1348
- 'functionCall' => 'PHPExcel_Calculation_MathTrig::RAND',
1349
- 'argumentCount' => '0'
1350
- ),
1351
- 'RANDBETWEEN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1352
- 'functionCall' => 'PHPExcel_Calculation_MathTrig::RAND',
1353
- 'argumentCount' => '2'
1354
- ),
1355
- 'RANK' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1356
- 'functionCall' => 'PHPExcel_Calculation_Statistical::RANK',
1357
- 'argumentCount' => '2,3'
1358
- ),
1359
- 'RATE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1360
- 'functionCall' => 'PHPExcel_Calculation_Financial::RATE',
1361
- 'argumentCount' => '3-6'
1362
- ),
1363
- 'RECEIVED' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1364
- 'functionCall' => 'PHPExcel_Calculation_Financial::RECEIVED',
1365
- 'argumentCount' => '4-5'
1366
- ),
1367
- 'REPLACE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
1368
- 'functionCall' => 'PHPExcel_Calculation_TextData::REPLACE',
1369
- 'argumentCount' => '4'
1370
- ),
1371
- 'REPLACEB' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
1372
- 'functionCall' => 'PHPExcel_Calculation_TextData::REPLACE',
1373
- 'argumentCount' => '4'
1374
- ),
1375
- 'REPT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
1376
- 'functionCall' => 'str_repeat',
1377
- 'argumentCount' => '2'
1378
- ),
1379
- 'RIGHT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
1380
- 'functionCall' => 'PHPExcel_Calculation_TextData::RIGHT',
1381
- 'argumentCount' => '1,2'
1382
- ),
1383
- 'RIGHTB' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
1384
- 'functionCall' => 'PHPExcel_Calculation_TextData::RIGHT',
1385
- 'argumentCount' => '1,2'
1386
- ),
1387
- 'ROMAN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1388
- 'functionCall' => 'PHPExcel_Calculation_MathTrig::ROMAN',
1389
- 'argumentCount' => '1,2'
1390
- ),
1391
- 'ROUND' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1392
- 'functionCall' => 'round',
1393
- 'argumentCount' => '2'
1394
- ),
1395
- 'ROUNDDOWN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1396
- 'functionCall' => 'PHPExcel_Calculation_MathTrig::ROUNDDOWN',
1397
- 'argumentCount' => '2'
1398
- ),
1399
- 'ROUNDUP' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1400
- 'functionCall' => 'PHPExcel_Calculation_MathTrig::ROUNDUP',
1401
- 'argumentCount' => '2'
1402
- ),
1403
- 'ROW' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
1404
- 'functionCall' => 'PHPExcel_Calculation_LookupRef::ROW',
1405
- 'argumentCount' => '-1',
1406
- 'passByReference' => array(TRUE)
1407
- ),
1408
- 'ROWS' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
1409
- 'functionCall' => 'PHPExcel_Calculation_LookupRef::ROWS',
1410
- 'argumentCount' => '1'
1411
- ),
1412
- 'RSQ' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1413
- 'functionCall' => 'PHPExcel_Calculation_Statistical::RSQ',
1414
- 'argumentCount' => '2'
1415
- ),
1416
- 'RTD' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
1417
- 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
1418
- 'argumentCount' => '1+'
1419
- ),
1420
- 'SEARCH' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
1421
- 'functionCall' => 'PHPExcel_Calculation_TextData::SEARCHINSENSITIVE',
1422
- 'argumentCount' => '2,3'
1423
- ),
1424
- 'SEARCHB' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
1425
- 'functionCall' => 'PHPExcel_Calculation_TextData::SEARCHINSENSITIVE',
1426
- 'argumentCount' => '2,3'
1427
- ),
1428
- 'SECOND' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
1429
- 'functionCall' => 'PHPExcel_Calculation_DateTime::SECONDOFMINUTE',
1430
- 'argumentCount' => '1'
1431
- ),
1432
- 'SERIESSUM' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1433
- 'functionCall' => 'PHPExcel_Calculation_MathTrig::SERIESSUM',
1434
- 'argumentCount' => '4'
1435
- ),
1436
- 'SIGN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1437
- 'functionCall' => 'PHPExcel_Calculation_MathTrig::SIGN',
1438
- 'argumentCount' => '1'
1439
- ),
1440
- 'SIN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1441
- 'functionCall' => 'sin',
1442
- 'argumentCount' => '1'
1443
- ),
1444
- 'SINH' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1445
- 'functionCall' => 'sinh',
1446
- 'argumentCount' => '1'
1447
- ),
1448
- 'SKEW' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1449
- 'functionCall' => 'PHPExcel_Calculation_Statistical::SKEW',
1450
- 'argumentCount' => '1+'
1451
- ),
1452
- 'SLN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1453
- 'functionCall' => 'PHPExcel_Calculation_Financial::SLN',
1454
- 'argumentCount' => '3'
1455
- ),
1456
- 'SLOPE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1457
- 'functionCall' => 'PHPExcel_Calculation_Statistical::SLOPE',
1458
- 'argumentCount' => '2'
1459
- ),
1460
- 'SMALL' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1461
- 'functionCall' => 'PHPExcel_Calculation_Statistical::SMALL',
1462
- 'argumentCount' => '2'
1463
- ),
1464
- 'SQRT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1465
- 'functionCall' => 'sqrt',
1466
- 'argumentCount' => '1'
1467
- ),
1468
- 'SQRTPI' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1469
- 'functionCall' => 'PHPExcel_Calculation_MathTrig::SQRTPI',
1470
- 'argumentCount' => '1'
1471
- ),
1472
- 'STANDARDIZE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1473
- 'functionCall' => 'PHPExcel_Calculation_Statistical::STANDARDIZE',
1474
- 'argumentCount' => '3'
1475
- ),
1476
- 'STDEV' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1477
- 'functionCall' => 'PHPExcel_Calculation_Statistical::STDEV',
1478
- 'argumentCount' => '1+'
1479
- ),
1480
- 'STDEVA' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1481
- 'functionCall' => 'PHPExcel_Calculation_Statistical::STDEVA',
1482
- 'argumentCount' => '1+'
1483
- ),
1484
- 'STDEVP' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1485
- 'functionCall' => 'PHPExcel_Calculation_Statistical::STDEVP',
1486
- 'argumentCount' => '1+'
1487
- ),
1488
- 'STDEVPA' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1489
- 'functionCall' => 'PHPExcel_Calculation_Statistical::STDEVPA',
1490
- 'argumentCount' => '1+'
1491
- ),
1492
- 'STEYX' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1493
- 'functionCall' => 'PHPExcel_Calculation_Statistical::STEYX',
1494
- 'argumentCount' => '2'
1495
- ),
1496
- 'SUBSTITUTE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
1497
- 'functionCall' => 'PHPExcel_Calculation_TextData::SUBSTITUTE',
1498
- 'argumentCount' => '3,4'
1499
- ),
1500
- 'SUBTOTAL' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1501
- 'functionCall' => 'PHPExcel_Calculation_MathTrig::SUBTOTAL',
1502
- 'argumentCount' => '2+'
1503
- ),
1504
- 'SUM' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1505
- 'functionCall' => 'PHPExcel_Calculation_MathTrig::SUM',
1506
- 'argumentCount' => '1+'
1507
- ),
1508
- 'SUMIF' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1509
- 'functionCall' => 'PHPExcel_Calculation_MathTrig::SUMIF',
1510
- 'argumentCount' => '2,3'
1511
- ),
1512
- 'SUMIFS' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1513
- 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
1514
- 'argumentCount' => '?'
1515
- ),
1516
- 'SUMPRODUCT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1517
- 'functionCall' => 'PHPExcel_Calculation_MathTrig::SUMPRODUCT',
1518
- 'argumentCount' => '1+'
1519
- ),
1520
- 'SUMSQ' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1521
- 'functionCall' => 'PHPExcel_Calculation_MathTrig::SUMSQ',
1522
- 'argumentCount' => '1+'
1523
- ),
1524
- 'SUMX2MY2' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1525
- 'functionCall' => 'PHPExcel_Calculation_MathTrig::SUMX2MY2',
1526
- 'argumentCount' => '2'
1527
- ),
1528
- 'SUMX2PY2' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1529
- 'functionCall' => 'PHPExcel_Calculation_MathTrig::SUMX2PY2',
1530
- 'argumentCount' => '2'
1531
- ),
1532
- 'SUMXMY2' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1533
- 'functionCall' => 'PHPExcel_Calculation_MathTrig::SUMXMY2',
1534
- 'argumentCount' => '2'
1535
- ),
1536
- 'SYD' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1537
- 'functionCall' => 'PHPExcel_Calculation_Financial::SYD',
1538
- 'argumentCount' => '4'
1539
- ),
1540
- 'T' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
1541
- 'functionCall' => 'PHPExcel_Calculation_TextData::RETURNSTRING',
1542
- 'argumentCount' => '1'
1543
- ),
1544
- 'TAN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1545
- 'functionCall' => 'tan',
1546
- 'argumentCount' => '1'
1547
- ),
1548
- 'TANH' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1549
- 'functionCall' => 'tanh',
1550
- 'argumentCount' => '1'
1551
- ),
1552
- 'TBILLEQ' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1553
- 'functionCall' => 'PHPExcel_Calculation_Financial::TBILLEQ',
1554
- 'argumentCount' => '3'
1555
- ),
1556
- 'TBILLPRICE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1557
- 'functionCall' => 'PHPExcel_Calculation_Financial::TBILLPRICE',
1558
- 'argumentCount' => '3'
1559
- ),
1560
- 'TBILLYIELD' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1561
- 'functionCall' => 'PHPExcel_Calculation_Financial::TBILLYIELD',
1562
- 'argumentCount' => '3'
1563
- ),
1564
- 'TDIST' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1565
- 'functionCall' => 'PHPExcel_Calculation_Statistical::TDIST',
1566
- 'argumentCount' => '3'
1567
- ),
1568
- 'TEXT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
1569
- 'functionCall' => 'PHPExcel_Calculation_TextData::TEXTFORMAT',
1570
- 'argumentCount' => '2'
1571
- ),
1572
- 'TIME' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
1573
- 'functionCall' => 'PHPExcel_Calculation_DateTime::TIME',
1574
- 'argumentCount' => '3'
1575
- ),
1576
- 'TIMEVALUE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
1577
- 'functionCall' => 'PHPExcel_Calculation_DateTime::TIMEVALUE',
1578
- 'argumentCount' => '1'
1579
- ),
1580
- 'TINV' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1581
- 'functionCall' => 'PHPExcel_Calculation_Statistical::TINV',
1582
- 'argumentCount' => '2'
1583
- ),
1584
- 'TODAY' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
1585
- 'functionCall' => 'PHPExcel_Calculation_DateTime::DATENOW',
1586
- 'argumentCount' => '0'
1587
- ),
1588
- 'TRANSPOSE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
1589
- 'functionCall' => 'PHPExcel_Calculation_LookupRef::TRANSPOSE',
1590
- 'argumentCount' => '1'
1591
- ),
1592
- 'TREND' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1593
- 'functionCall' => 'PHPExcel_Calculation_Statistical::TREND',
1594
- 'argumentCount' => '1-4'
1595
- ),
1596
- 'TRIM' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
1597
- 'functionCall' => 'PHPExcel_Calculation_TextData::TRIMSPACES',
1598
- 'argumentCount' => '1'
1599
- ),
1600
- 'TRIMMEAN' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1601
- 'functionCall' => 'PHPExcel_Calculation_Statistical::TRIMMEAN',
1602
- 'argumentCount' => '2'
1603
- ),
1604
- 'TRUE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOGICAL,
1605
- 'functionCall' => 'PHPExcel_Calculation_Logical::TRUE',
1606
- 'argumentCount' => '0'
1607
- ),
1608
- 'TRUNC' => array('category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1609
- 'functionCall' => 'PHPExcel_Calculation_MathTrig::TRUNC',
1610
- 'argumentCount' => '1,2'
1611
- ),
1612
- 'TTEST' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1613
- 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
1614
- 'argumentCount' => '4'
1615
- ),
1616
- 'TYPE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
1617
- 'functionCall' => 'PHPExcel_Calculation_Functions::TYPE',
1618
- 'argumentCount' => '1'
1619
- ),
1620
- 'UPPER' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
1621
- 'functionCall' => 'PHPExcel_Calculation_TextData::UPPERCASE',
1622
- 'argumentCount' => '1'
1623
- ),
1624
- 'USDOLLAR' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1625
- 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
1626
- 'argumentCount' => '2'
1627
- ),
1628
- 'VALUE' => array('category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
1629
- 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
1630
- 'argumentCount' => '1'
1631
- ),
1632
- 'VAR' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1633
- 'functionCall' => 'PHPExcel_Calculation_Statistical::VARFunc',
1634
- 'argumentCount' => '1+'
1635
- ),
1636
- 'VARA' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1637
- 'functionCall' => 'PHPExcel_Calculation_Statistical::VARA',
1638
- 'argumentCount' => '1+'
1639
- ),
1640
- 'VARP' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1641
- 'functionCall' => 'PHPExcel_Calculation_Statistical::VARP',
1642
- 'argumentCount' => '1+'
1643
- ),
1644
- 'VARPA' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1645
- 'functionCall' => 'PHPExcel_Calculation_Statistical::VARPA',
1646
- 'argumentCount' => '1+'
1647
- ),
1648
- 'VDB' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1649
- 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
1650
- 'argumentCount' => '5-7'
1651
- ),
1652
- 'VERSION' => array('category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
1653
- 'functionCall' => 'PHPExcel_Calculation_Functions::VERSION',
1654
- 'argumentCount' => '0'
1655
- ),
1656
- 'VLOOKUP' => array('category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
1657
- 'functionCall' => 'PHPExcel_Calculation_LookupRef::VLOOKUP',
1658
- 'argumentCount' => '3,4'
1659
- ),
1660
- 'WEEKDAY' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
1661
- 'functionCall' => 'PHPExcel_Calculation_DateTime::DAYOFWEEK',
1662
- 'argumentCount' => '1,2'
1663
- ),
1664
- 'WEEKNUM' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
1665
- 'functionCall' => 'PHPExcel_Calculation_DateTime::WEEKOFYEAR',
1666
- 'argumentCount' => '1,2'
1667
- ),
1668
- 'WEIBULL' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1669
- 'functionCall' => 'PHPExcel_Calculation_Statistical::WEIBULL',
1670
- 'argumentCount' => '4'
1671
- ),
1672
- 'WORKDAY' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
1673
- 'functionCall' => 'PHPExcel_Calculation_DateTime::WORKDAY',
1674
- 'argumentCount' => '2+'
1675
- ),
1676
- 'XIRR' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1677
- 'functionCall' => 'PHPExcel_Calculation_Financial::XIRR',
1678
- 'argumentCount' => '2,3'
1679
- ),
1680
- 'XNPV' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1681
- 'functionCall' => 'PHPExcel_Calculation_Financial::XNPV',
1682
- 'argumentCount' => '3'
1683
- ),
1684
- 'YEAR' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
1685
- 'functionCall' => 'PHPExcel_Calculation_DateTime::YEAR',
1686
- 'argumentCount' => '1'
1687
- ),
1688
- 'YEARFRAC' => array('category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
1689
- 'functionCall' => 'PHPExcel_Calculation_DateTime::YEARFRAC',
1690
- 'argumentCount' => '2,3'
1691
- ),
1692
- 'YIELD' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1693
- 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
1694
- 'argumentCount' => '6,7'
1695
- ),
1696
- 'YIELDDISC' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1697
- 'functionCall' => 'PHPExcel_Calculation_Financial::YIELDDISC',
1698
- 'argumentCount' => '4,5'
1699
- ),
1700
- 'YIELDMAT' => array('category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1701
- 'functionCall' => 'PHPExcel_Calculation_Financial::YIELDMAT',
1702
- 'argumentCount' => '5,6'
1703
- ),
1704
- 'ZTEST' => array('category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1705
- 'functionCall' => 'PHPExcel_Calculation_Statistical::ZTEST',
1706
- 'argumentCount' => '2-3'
1707
- )
1708
- );
1709
-
1710
-
1711
- // Internal functions used for special control purposes
1712
- private static $_controlFunctions = array(
1713
- 'MKMATRIX' => array('argumentCount' => '*',
1714
- 'functionCall' => 'self::_mkMatrix'
1715
- )
1716
- );
1717
-
1718
-
1719
-
1720
-
1721
- private function __construct(PHPExcel $workbook = NULL) {
1722
- $setPrecision = (PHP_INT_SIZE == 4) ? 14 : 16;
1723
- $this->_savedPrecision = ini_get('precision');
1724
- if ($this->_savedPrecision < $setPrecision) {
1725
- ini_set('precision',$setPrecision);
1726
- }
1727
-
1728
- if ($workbook !== NULL) {
1729
- self::$_workbookSets[$workbook->getID()] = $this;
1730
- }
1731
-
1732
- $this->_workbook = $workbook;
1733
- $this->_cyclicReferenceStack = new PHPExcel_CalcEngine_CyclicReferenceStack();
1734
- $this->_debugLog = new PHPExcel_CalcEngine_Logger($this->_cyclicReferenceStack);
1735
- } // function __construct()
1736
-
1737
-
1738
- public function __destruct() {
1739
- if ($this->_savedPrecision != ini_get('precision')) {
1740
- ini_set('precision',$this->_savedPrecision);
1741
- }
1742
- }
1743
-
1744
- private static function _loadLocales() {
1745
- $localeFileDirectory = PHPEXCEL_ROOT.'PHPExcel/locale/';
1746
- foreach (glob($localeFileDirectory.'/*',GLOB_ONLYDIR) as $filename) {
1747
- $filename = substr($filename,strlen($localeFileDirectory)+1);
1748
- if ($filename != 'en') {
1749
- self::$_validLocaleLanguages[] = $filename;
1750
- }
1751
- }
1752
- }
1753
-
1754
- /**
1755
- * Get an instance of this class
1756
- *
1757
- * @access public
1758
- * @param PHPExcel $workbook Injected workbook for working with a PHPExcel object,
1759
- * or NULL to create a standalone claculation engine
1760
- * @return PHPExcel_Calculation
1761
- */
1762
- public static function getInstance(PHPExcel $workbook = NULL) {
1763
- if ($workbook !== NULL) {
1764
- if (isset(self::$_workbookSets[$workbook->getID()])) {
1765
- return self::$_workbookSets[$workbook->getID()];
1766
- }
1767
- return new PHPExcel_Calculation($workbook);
1768
- }
1769
-
1770
- if (!isset(self::$_instance) || (self::$_instance === NULL)) {
1771
- self::$_instance = new PHPExcel_Calculation();
1772
- }
1773
-
1774
- return self::$_instance;
1775
- } // function getInstance()
1776
-
1777
- /**
1778
- * Unset an instance of this class
1779
- *
1780
- * @access public
1781
- * @param PHPExcel $workbook Injected workbook identifying the instance to unset
1782
- */
1783
- public static function unsetInstance(PHPExcel $workbook = NULL) {
1784
- if ($workbook !== NULL) {
1785
- if (isset(self::$_workbookSets[$workbook->getID()])) {
1786
- unset(self::$_workbookSets[$workbook->getID()]);
1787
- }
1788
- }
1789
- }
1790
-
1791
- /**
1792
- * Flush the calculation cache for any existing instance of this class
1793
- * but only if a PHPExcel_Calculation instance exists
1794
- *
1795
- * @access public
1796
- * @return null
1797
- */
1798
- public function flushInstance() {
1799
- $this->clearCalculationCache();
1800
- } // function flushInstance()
1801
-
1802
-
1803
- /**
1804
- * Get the debuglog for this claculation engine instance
1805
- *
1806
- * @access public
1807
- * @return PHPExcel_CalcEngine_Logger
1808
- */
1809
- public function getDebugLog() {
1810
- return $this->_debugLog;
1811
- }
1812
-
1813
- /**
1814
- * __clone implementation. Cloning should not be allowed in a Singleton!
1815
- *
1816
- * @access public
1817
- * @throws PHPExcel_Calculation_Exception
1818
- */
1819
- public final function __clone() {
1820
- throw new PHPExcel_Calculation_Exception ('Cloning the calculation engine is not allowed!');
1821
- } // function __clone()
1822
-
1823
-
1824
- /**
1825
- * Return the locale-specific translation of TRUE
1826
- *
1827
- * @access public
1828
- * @return string locale-specific translation of TRUE
1829
- */
1830
- public static function getTRUE() {
1831
- return self::$_localeBoolean['TRUE'];
1832
- }
1833
-
1834
- /**
1835
- * Return the locale-specific translation of FALSE
1836
- *
1837
- * @access public
1838
- * @return string locale-specific translation of FALSE
1839
- */
1840
- public static function getFALSE() {
1841
- return self::$_localeBoolean['FALSE'];
1842
- }
1843
-
1844
- /**
1845
- * Set the Array Return Type (Array or Value of first element in the array)
1846
- *
1847
- * @access public
1848
- * @param string $returnType Array return type
1849
- * @return boolean Success or failure
1850
- */
1851
- public static function setArrayReturnType($returnType) {
1852
- if (($returnType == self::RETURN_ARRAY_AS_VALUE) ||
1853
- ($returnType == self::RETURN_ARRAY_AS_ERROR) ||
1854
- ($returnType == self::RETURN_ARRAY_AS_ARRAY)) {
1855
- self::$returnArrayAsType = $returnType;
1856
- return TRUE;
1857
- }
1858
- return FALSE;
1859
- } // function setArrayReturnType()
1860
-
1861
-
1862
- /**
1863
- * Return the Array Return Type (Array or Value of first element in the array)
1864
- *
1865
- * @access public
1866
- * @return string $returnType Array return type
1867
- */
1868
- public static function getArrayReturnType() {
1869
- return self::$returnArrayAsType;
1870
- } // function getArrayReturnType()
1871
-
1872
-
1873
- /**
1874
- * Is calculation caching enabled?
1875
- *
1876
- * @access public
1877
- * @return boolean
1878
- */
1879
- public function getCalculationCacheEnabled() {
1880
- return $this->_calculationCacheEnabled;
1881
- } // function getCalculationCacheEnabled()
1882
-
1883
- /**
1884
- * Enable/disable calculation cache
1885
- *
1886
- * @access public
1887
- * @param boolean $pValue
1888
- */
1889
- public function setCalculationCacheEnabled($pValue = TRUE) {
1890
- $this->_calculationCacheEnabled = $pValue;
1891
- $this->clearCalculationCache();
1892
- } // function setCalculationCacheEnabled()
1893
-
1894
-
1895
- /**
1896
- * Enable calculation cache
1897
- */
1898
- public function enableCalculationCache() {
1899
- $this->setCalculationCacheEnabled(TRUE);
1900
- } // function enableCalculationCache()
1901
-
1902
-
1903
- /**
1904
- * Disable calculation cache
1905
- */
1906
- public function disableCalculationCache() {
1907
- $this->setCalculationCacheEnabled(FALSE);
1908
- } // function disableCalculationCache()
1909
-
1910
-
1911
- /**
1912
- * Clear calculation cache
1913
- */
1914
- public function clearCalculationCache() {
1915
- $this->_calculationCache = array();
1916
- } // function clearCalculationCache()
1917
-
1918
- /**
1919
- * Clear calculation cache for a specified worksheet
1920
- *
1921
- * @param string $worksheetName
1922
- */
1923
- public function clearCalculationCacheForWorksheet($worksheetName) {
1924
- if (isset($this->_calculationCache[$worksheetName])) {
1925
- unset($this->_calculationCache[$worksheetName]);
1926
- }
1927
- } // function clearCalculationCacheForWorksheet()
1928
-
1929
- /**
1930
- * Rename calculation cache for a specified worksheet
1931
- *
1932
- * @param string $fromWorksheetName
1933
- * @param string $toWorksheetName
1934
- */
1935
- public function renameCalculationCacheForWorksheet($fromWorksheetName, $toWorksheetName) {
1936
- if (isset($this->_calculationCache[$fromWorksheetName])) {
1937
- $this->_calculationCache[$toWorksheetName] = &$this->_calculationCache[$fromWorksheetName];
1938
- unset($this->_calculationCache[$fromWorksheetName]);
1939
- }
1940
- } // function renameCalculationCacheForWorksheet()
1941
-
1942
-
1943
- /**
1944
- * Get the currently defined locale code
1945
- *
1946
- * @return string
1947
- */
1948
- public function getLocale() {
1949
- return self::$_localeLanguage;
1950
- } // function getLocale()
1951
-
1952
-
1953
- /**
1954
- * Set the locale code
1955
- *
1956
- * @param string $locale The locale to use for formula translation
1957
- * @return boolean
1958
- */
1959
- public function setLocale($locale = 'en_us') {
1960
- // Identify our locale and language
1961
- $language = $locale = strtolower($locale);
1962
- if (strpos($locale,'_') !== FALSE) {
1963
- list($language) = explode('_',$locale);
1964
- }
1965
-
1966
- if (count(self::$_validLocaleLanguages) == 1)
1967
- self::_loadLocales();
1968
-
1969
- // Test whether we have any language data for this language (any locale)
1970
- if (in_array($language,self::$_validLocaleLanguages)) {
1971
- // initialise language/locale settings
1972
- self::$_localeFunctions = array();
1973
- self::$_localeArgumentSeparator = ',';
1974
- self::$_localeBoolean = array('TRUE' => 'TRUE', 'FALSE' => 'FALSE', 'NULL' => 'NULL');
1975
- // Default is English, if user isn't requesting english, then read the necessary data from the locale files
1976
- if ($locale != 'en_us') {
1977
- // Search for a file with a list of function names for locale
1978
- $functionNamesFile = PHPEXCEL_ROOT . 'PHPExcel'.DIRECTORY_SEPARATOR.'locale'.DIRECTORY_SEPARATOR.str_replace('_',DIRECTORY_SEPARATOR,$locale).DIRECTORY_SEPARATOR.'functions';
1979
- if (!file_exists($functionNamesFile)) {
1980
- // If there isn't a locale specific function file, look for a language specific function file
1981
- $functionNamesFile = PHPEXCEL_ROOT . 'PHPExcel'.DIRECTORY_SEPARATOR.'locale'.DIRECTORY_SEPARATOR.$language.DIRECTORY_SEPARATOR.'functions';
1982
- if (!file_exists($functionNamesFile)) {
1983
- return FALSE;
1984
- }
1985
- }
1986
- // Retrieve the list of locale or language specific function names
1987
- $localeFunctions = file($functionNamesFile,FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
1988
- foreach ($localeFunctions as $localeFunction) {
1989
- list($localeFunction) = explode('##',$localeFunction); // Strip out comments
1990
- if (strpos($localeFunction,'=') !== FALSE) {
1991
- list($fName,$lfName) = explode('=',$localeFunction);
1992
- $fName = trim($fName);
1993
- $lfName = trim($lfName);
1994
- if ((isset(self::$_PHPExcelFunctions[$fName])) && ($lfName != '') && ($fName != $lfName)) {
1995
- self::$_localeFunctions[$fName] = $lfName;
1996
- }
1997
- }
1998
- }
1999
- // Default the TRUE and FALSE constants to the locale names of the TRUE() and FALSE() functions
2000
- if (isset(self::$_localeFunctions['TRUE'])) { self::$_localeBoolean['TRUE'] = self::$_localeFunctions['TRUE']; }
2001
- if (isset(self::$_localeFunctions['FALSE'])) { self::$_localeBoolean['FALSE'] = self::$_localeFunctions['FALSE']; }
2002
-
2003
- $configFile = PHPEXCEL_ROOT . 'PHPExcel'.DIRECTORY_SEPARATOR.'locale'.DIRECTORY_SEPARATOR.str_replace('_',DIRECTORY_SEPARATOR,$locale).DIRECTORY_SEPARATOR.'config';
2004
- if (!file_exists($configFile)) {
2005
- $configFile = PHPEXCEL_ROOT . 'PHPExcel'.DIRECTORY_SEPARATOR.'locale'.DIRECTORY_SEPARATOR.$language.DIRECTORY_SEPARATOR.'config';
2006
- }
2007
- if (file_exists($configFile)) {
2008
- $localeSettings = file($configFile,FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
2009
- foreach ($localeSettings as $localeSetting) {
2010
- list($localeSetting) = explode('##',$localeSetting); // Strip out comments
2011
- if (strpos($localeSetting,'=') !== FALSE) {
2012
- list($settingName,$settingValue) = explode('=',$localeSetting);
2013
- $settingName = strtoupper(trim($settingName));
2014
- switch ($settingName) {
2015
- case 'ARGUMENTSEPARATOR' :
2016
- self::$_localeArgumentSeparator = trim($settingValue);
2017
- break;
2018
- }
2019
- }
2020
- }
2021
- }
2022
- }
2023
-
2024
- self::$functionReplaceFromExcel = self::$functionReplaceToExcel =
2025
- self::$functionReplaceFromLocale = self::$functionReplaceToLocale = NULL;
2026
- self::$_localeLanguage = $locale;
2027
- return TRUE;
2028
- }
2029
- return FALSE;
2030
- } // function setLocale()
2031
-
2032
-
2033
-
2034
- public static function _translateSeparator($fromSeparator,$toSeparator,$formula,&$inBraces) {
2035
- $strlen = mb_strlen($formula);
2036
- for ($i = 0; $i < $strlen; ++$i) {
2037
- $chr = mb_substr($formula,$i,1);
2038
- switch ($chr) {
2039
- case '{' : $inBraces = TRUE;
2040
- break;
2041
- case '}' : $inBraces = FALSE;
2042
- break;
2043
- case $fromSeparator :
2044
- if (!$inBraces) {
2045
- $formula = mb_substr($formula,0,$i).$toSeparator.mb_substr($formula,$i+1);
2046
- }
2047
- }
2048
- }
2049
- return $formula;
2050
- }
2051
-
2052
- private static function _translateFormula($from,$to,$formula,$fromSeparator,$toSeparator) {
2053
- // Convert any Excel function names to the required language
2054
- if (self::$_localeLanguage !== 'en_us') {
2055
- $inBraces = FALSE;
2056
- // If there is the possibility of braces within a quoted string, then we don't treat those as matrix indicators
2057
- if (strpos($formula,'"') !== FALSE) {
2058
- // So instead we skip replacing in any quoted strings by only replacing in every other array element after we've exploded
2059
- // the formula
2060
- $temp = explode('"',$formula);
2061
- $i = FALSE;
2062
- foreach($temp as &$value) {
2063
- // Only count/replace in alternating array entries
2064
- if ($i = !$i) {
2065
- $value = preg_replace($from,$to,$value);
2066
- $value = self::_translateSeparator($fromSeparator,$toSeparator,$value,$inBraces);
2067
- }
2068
- }
2069
- unset($value);
2070
- // Then rebuild the formula string
2071
- $formula = implode('"',$temp);
2072
- } else {
2073
- // If there's no quoted strings, then we do a simple count/replace
2074
- $formula = preg_replace($from,$to,$formula);
2075
- $formula = self::_translateSeparator($fromSeparator,$toSeparator,$formula,$inBraces);
2076
- }
2077
- }
2078
-
2079
- return $formula;
2080
- }
2081
-
2082
- private static $functionReplaceFromExcel = NULL;
2083
- private static $functionReplaceToLocale = NULL;
2084
-
2085
- public function _translateFormulaToLocale($formula) {
2086
- if (self::$functionReplaceFromExcel === NULL) {
2087
- self::$functionReplaceFromExcel = array();
2088
- foreach(array_keys(self::$_localeFunctions) as $excelFunctionName) {
2089
- self::$functionReplaceFromExcel[] = '/(@?[^\w\.])'.preg_quote($excelFunctionName).'([\s]*\()/Ui';
2090
- }
2091
- foreach(array_keys(self::$_localeBoolean) as $excelBoolean) {
2092
- self::$functionReplaceFromExcel[] = '/(@?[^\w\.])'.preg_quote($excelBoolean).'([^\w\.])/Ui';
2093
- }
2094
-
2095
- }
2096
-
2097
- if (self::$functionReplaceToLocale === NULL) {
2098
- self::$functionReplaceToLocale = array();
2099
- foreach(array_values(self::$_localeFunctions) as $localeFunctionName) {
2100
- self::$functionReplaceToLocale[] = '$1'.trim($localeFunctionName).'$2';
2101
- }
2102
- foreach(array_values(self::$_localeBoolean) as $localeBoolean) {
2103
- self::$functionReplaceToLocale[] = '$1'.trim($localeBoolean).'$2';
2104
- }
2105
- }
2106
-
2107
- return self::_translateFormula(self::$functionReplaceFromExcel,self::$functionReplaceToLocale,$formula,',',self::$_localeArgumentSeparator);
2108
- } // function _translateFormulaToLocale()
2109
-
2110
-
2111
- private static $functionReplaceFromLocale = NULL;
2112
- private static $functionReplaceToExcel = NULL;
2113
-
2114
- public function _translateFormulaToEnglish($formula) {
2115
- if (self::$functionReplaceFromLocale === NULL) {
2116
- self::$functionReplaceFromLocale = array();
2117
- foreach(array_values(self::$_localeFunctions) as $localeFunctionName) {
2118
- self::$functionReplaceFromLocale[] = '/(@?[^\w\.])'.preg_quote($localeFunctionName).'([\s]*\()/Ui';
2119
- }
2120
- foreach(array_values(self::$_localeBoolean) as $excelBoolean) {
2121
- self::$functionReplaceFromLocale[] = '/(@?[^\w\.])'.preg_quote($excelBoolean).'([^\w\.])/Ui';
2122
- }
2123
- }
2124
-
2125
- if (self::$functionReplaceToExcel === NULL) {
2126
- self::$functionReplaceToExcel = array();
2127
- foreach(array_keys(self::$_localeFunctions) as $excelFunctionName) {
2128
- self::$functionReplaceToExcel[] = '$1'.trim($excelFunctionName).'$2';
2129
- }
2130
- foreach(array_keys(self::$_localeBoolean) as $excelBoolean) {
2131
- self::$functionReplaceToExcel[] = '$1'.trim($excelBoolean).'$2';
2132
- }
2133
- }
2134
-
2135
- return self::_translateFormula(self::$functionReplaceFromLocale,self::$functionReplaceToExcel,$formula,self::$_localeArgumentSeparator,',');
2136
- } // function _translateFormulaToEnglish()
2137
-
2138
-
2139
- public static function _localeFunc($function) {
2140
- if (self::$_localeLanguage !== 'en_us') {
2141
- $functionName = trim($function,'(');
2142
- if (isset(self::$_localeFunctions[$functionName])) {
2143
- $brace = ($functionName != $function);
2144
- $function = self::$_localeFunctions[$functionName];
2145
- if ($brace) { $function .= '('; }
2146
- }
2147
- }
2148
- return $function;
2149
- }
2150
-
2151
-
2152
-
2153
-
2154
- /**
2155
- * Wrap string values in quotes
2156
- *
2157
- * @param mixed $value
2158
- * @return mixed
2159
- */
2160
- public static function _wrapResult($value) {
2161
- if (is_string($value)) {
2162
- // Error values cannot be "wrapped"
2163
- if (preg_match('/^'.self::CALCULATION_REGEXP_ERROR.'$/i', $value, $match)) {
2164
- // Return Excel errors "as is"
2165
- return $value;
2166
- }
2167
- // Return strings wrapped in quotes
2168
- return '"'.$value.'"';
2169
- // Convert numeric errors to NaN error
2170
- } else if((is_float($value)) && ((is_nan($value)) || (is_infinite($value)))) {
2171
- return PHPExcel_Calculation_Functions::NaN();
2172
- }
2173
-
2174
- return $value;
2175
- } // function _wrapResult()
2176
-
2177
-
2178
- /**
2179
- * Remove quotes used as a wrapper to identify string values
2180
- *
2181
- * @param mixed $value
2182
- * @return mixed
2183
- */
2184
- public static function _unwrapResult($value) {
2185
- if (is_string($value)) {
2186
- if ((isset($value{0})) && ($value{0} == '"') && (substr($value,-1) == '"')) {
2187
- return substr($value,1,-1);
2188
- }
2189
- // Convert numeric errors to NaN error
2190
- } else if((is_float($value)) && ((is_nan($value)) || (is_infinite($value)))) {
2191
- return PHPExcel_Calculation_Functions::NaN();
2192
- }
2193
- return $value;
2194
- } // function _unwrapResult()
2195
-
2196
-
2197
-
2198
-
2199
- /**
2200
- * Calculate cell value (using formula from a cell ID)
2201
- * Retained for backward compatibility
2202
- *
2203
- * @access public
2204
- * @param PHPExcel_Cell $pCell Cell to calculate
2205
- * @return mixed
2206
- * @throws PHPExcel_Calculation_Exception
2207
- */
2208
- public function calculate(PHPExcel_Cell $pCell = NULL) {
2209
- try {
2210
- return $this->calculateCellValue($pCell);
2211
- } catch (PHPExcel_Exception $e) {
2212
- throw new PHPExcel_Calculation_Exception($e->getMessage());
2213
- }
2214
- } // function calculate()
2215
-
2216
-
2217
- /**
2218
- * Calculate the value of a cell formula
2219
- *
2220
- * @access public
2221
- * @param PHPExcel_Cell $pCell Cell to calculate
2222
- * @param Boolean $resetLog Flag indicating whether the debug log should be reset or not
2223
- * @return mixed
2224
- * @throws PHPExcel_Calculation_Exception
2225
- */
2226
- public function calculateCellValue(PHPExcel_Cell $pCell = NULL, $resetLog = TRUE) {
2227
- if ($pCell === NULL) {
2228
- return NULL;
2229
- }
2230
-
2231
- $returnArrayAsType = self::$returnArrayAsType;
2232
- if ($resetLog) {
2233
- // Initialise the logging settings if requested
2234
- $this->formulaError = null;
2235
- $this->_debugLog->clearLog();
2236
- $this->_cyclicReferenceStack->clear();
2237
- $this->_cyclicFormulaCount = 1;
2238
-
2239
- self::$returnArrayAsType = self::RETURN_ARRAY_AS_ARRAY;
2240
- }
2241
-
2242
- // Execute the calculation for the cell formula
2243
- try {
2244
- $result = self::_unwrapResult($this->_calculateFormulaValue($pCell->getValue(), $pCell->getCoordinate(), $pCell));
2245
- } catch (PHPExcel_Exception $e) {
2246
- throw new PHPExcel_Calculation_Exception($e->getMessage());
2247
- }
2248
-
2249
- if ((is_array($result)) && (self::$returnArrayAsType != self::RETURN_ARRAY_AS_ARRAY)) {
2250
- self::$returnArrayAsType = $returnArrayAsType;
2251
- $testResult = PHPExcel_Calculation_Functions::flattenArray($result);
2252
- if (self::$returnArrayAsType == self::RETURN_ARRAY_AS_ERROR) {
2253
- return PHPExcel_Calculation_Functions::VALUE();
2254
- }
2255
- // If there's only a single cell in the array, then we allow it
2256
- if (count($testResult) != 1) {
2257
- // If keys are numeric, then it's a matrix result rather than a cell range result, so we permit it
2258
- $r = array_keys($result);
2259
- $r = array_shift($r);
2260
- if (!is_numeric($r)) { return PHPExcel_Calculation_Functions::VALUE(); }
2261
- if (is_array($result[$r])) {
2262
- $c = array_keys($result[$r]);
2263
- $c = array_shift($c);
2264
- if (!is_numeric($c)) {
2265
- return PHPExcel_Calculation_Functions::VALUE();
2266
- }
2267
- }
2268
- }
2269
- $result = array_shift($testResult);
2270
- }
2271
- self::$returnArrayAsType = $returnArrayAsType;
2272
-
2273
-
2274
- if ($result === NULL) {
2275
- return 0;
2276
- } elseif((is_float($result)) && ((is_nan($result)) || (is_infinite($result)))) {
2277
- return PHPExcel_Calculation_Functions::NaN();
2278
- }
2279
- return $result;
2280
- } // function calculateCellValue(
2281
-
2282
-
2283
- /**
2284
- * Validate and parse a formula string
2285
- *
2286
- * @param string $formula Formula to parse
2287
- * @return array
2288
- * @throws PHPExcel_Calculation_Exception
2289
- */
2290
- public function parseFormula($formula) {
2291
- // Basic validation that this is indeed a formula
2292
- // We return an empty array if not
2293
- $formula = trim($formula);
2294
- if ((!isset($formula{0})) || ($formula{0} != '=')) return array();
2295
- $formula = ltrim(substr($formula,1));
2296
- if (!isset($formula{0})) return array();
2297
-
2298
- // Parse the formula and return the token stack
2299
- return $this->_parseFormula($formula);
2300
- } // function parseFormula()
2301
-
2302
-
2303
- /**
2304
- * Calculate the value of a formula
2305
- *
2306
- * @param string $formula Formula to parse
2307
- * @param string $cellID Address of the cell to calculate
2308
- * @param PHPExcel_Cell $pCell Cell to calculate
2309
- * @return mixed
2310
- * @throws PHPExcel_Calculation_Exception
2311
- */
2312
- public function calculateFormula($formula, $cellID=NULL, PHPExcel_Cell $pCell = NULL) {
2313
- // Initialise the logging settings
2314
- $this->formulaError = null;
2315
- $this->_debugLog->clearLog();
2316
- $this->_cyclicReferenceStack->clear();
2317
-
2318
- // Disable calculation cacheing because it only applies to cell calculations, not straight formulae
2319
- // But don't actually flush any cache
2320
- $resetCache = $this->getCalculationCacheEnabled();
2321
- $this->_calculationCacheEnabled = FALSE;
2322
- // Execute the calculation
2323
- try {
2324
- $result = self::_unwrapResult($this->_calculateFormulaValue($formula, $cellID, $pCell));
2325
- } catch (PHPExcel_Exception $e) {
2326
- throw new PHPExcel_Calculation_Exception($e->getMessage());
2327
- }
2328
-
2329
- // Reset calculation cacheing to its previous state
2330
- $this->_calculationCacheEnabled = $resetCache;
2331
-
2332
- return $result;
2333
- } // function calculateFormula()
2334
-
2335
-
2336
- public function getValueFromCache($worksheetName, $cellID, &$cellValue) {
2337
- // Is calculation cacheing enabled?
2338
- // Is the value present in calculation cache?
2339
- //echo 'Test cache for ',$worksheetName,'!',$cellID,PHP_EOL;
2340
- $this->_debugLog->writeDebugLog('Testing cache value for cell ', $worksheetName, '!', $cellID);
2341
- if (($this->_calculationCacheEnabled) && (isset($this->_calculationCache[$worksheetName][$cellID]))) {
2342
- //echo 'Retrieve from cache',PHP_EOL;
2343
- $this->_debugLog->writeDebugLog('Retrieving value for cell ', $worksheetName, '!', $cellID, ' from cache');
2344
- // Return the cached result
2345
- $cellValue = $this->_calculationCache[$worksheetName][$cellID];
2346
- return TRUE;
2347
- }
2348
- return FALSE;
2349
- }
2350
-
2351
- public function saveValueToCache($worksheetName, $cellID, $cellValue) {
2352
- if ($this->_calculationCacheEnabled) {
2353
- $this->_calculationCache[$worksheetName][$cellID] = $cellValue;
2354
- }
2355
- }
2356
-
2357
- /**
2358
- * Parse a cell formula and calculate its value
2359
- *
2360
- * @param string $formula The formula to parse and calculate
2361
- * @param string $cellID The ID (e.g. A3) of the cell that we are calculating
2362
- * @param PHPExcel_Cell $pCell Cell to calculate
2363
- * @return mixed
2364
- * @throws PHPExcel_Calculation_Exception
2365
- */
2366
- public function _calculateFormulaValue($formula, $cellID=null, PHPExcel_Cell $pCell = null) {
2367
- $cellValue = '';
2368
-
2369
- // Basic validation that this is indeed a formula
2370
- // We simply return the cell value if not
2371
- $formula = trim($formula);
2372
- if ($formula{0} != '=') return self::_wrapResult($formula);
2373
- $formula = ltrim(substr($formula,1));
2374
- if (!isset($formula{0})) return self::_wrapResult($formula);
2375
-
2376
- $pCellParent = ($pCell !== NULL) ? $pCell->getWorksheet() : NULL;
2377
- $wsTitle = ($pCellParent !== NULL) ? $pCellParent->getTitle() : "\x00Wrk";
2378
-
2379
- if (($cellID !== NULL) && ($this->getValueFromCache($wsTitle, $cellID, $cellValue))) {
2380
- return $cellValue;
2381
- }
2382
-
2383
- if (($wsTitle{0} !== "\x00") && ($this->_cyclicReferenceStack->onStack($wsTitle.'!'.$cellID))) {
2384
- if ($this->cyclicFormulaCount <= 0) {
2385
- return $this->_raiseFormulaError('Cyclic Reference in Formula');
2386
- } elseif (($this->_cyclicFormulaCount >= $this->cyclicFormulaCount) &&
2387
- ($this->_cyclicFormulaCell == $wsTitle.'!'.$cellID)) {
2388
- return $cellValue;
2389
- } elseif ($this->_cyclicFormulaCell == $wsTitle.'!'.$cellID) {
2390
- ++$this->_cyclicFormulaCount;
2391
- if ($this->_cyclicFormulaCount >= $this->cyclicFormulaCount) {
2392
- return $cellValue;
2393
- }
2394
- } elseif ($this->_cyclicFormulaCell == '') {
2395
- $this->_cyclicFormulaCell = $wsTitle.'!'.$cellID;
2396
- if ($this->_cyclicFormulaCount >= $this->cyclicFormulaCount) {
2397
- return $cellValue;
2398
- }
2399
- }
2400
- }
2401
-
2402
- // Parse the formula onto the token stack and calculate the value
2403
- $this->_cyclicReferenceStack->push($wsTitle.'!'.$cellID);
2404
- $cellValue = $this->_processTokenStack($this->_parseFormula($formula, $pCell), $cellID, $pCell);
2405
- $this->_cyclicReferenceStack->pop();
2406
-
2407
- // Save to calculation cache
2408
- if ($cellID !== NULL) {
2409
- $this->saveValueToCache($wsTitle, $cellID, $cellValue);
2410
- }
2411
-
2412
- // Return the calculated value
2413
- return $cellValue;
2414
- } // function _calculateFormulaValue()
2415
-
2416
-
2417
- /**
2418
- * Ensure that paired matrix operands are both matrices and of the same size
2419
- *
2420
- * @param mixed &$operand1 First matrix operand
2421
- * @param mixed &$operand2 Second matrix operand
2422
- * @param integer $resize Flag indicating whether the matrices should be resized to match
2423
- * and (if so), whether the smaller dimension should grow or the
2424
- * larger should shrink.
2425
- * 0 = no resize
2426
- * 1 = shrink to fit
2427
- * 2 = extend to fit
2428
- */
2429
- private static function _checkMatrixOperands(&$operand1,&$operand2,$resize = 1) {
2430
- // Examine each of the two operands, and turn them into an array if they aren't one already
2431
- // Note that this function should only be called if one or both of the operand is already an array
2432
- if (!is_array($operand1)) {
2433
- list($matrixRows,$matrixColumns) = self::_getMatrixDimensions($operand2);
2434
- $operand1 = array_fill(0,$matrixRows,array_fill(0,$matrixColumns,$operand1));
2435
- $resize = 0;
2436
- } elseif (!is_array($operand2)) {
2437
- list($matrixRows,$matrixColumns) = self::_getMatrixDimensions($operand1);
2438
- $operand2 = array_fill(0,$matrixRows,array_fill(0,$matrixColumns,$operand2));
2439
- $resize = 0;
2440
- }
2441
-
2442
- list($matrix1Rows,$matrix1Columns) = self::_getMatrixDimensions($operand1);
2443
- list($matrix2Rows,$matrix2Columns) = self::_getMatrixDimensions($operand2);
2444
- if (($matrix1Rows == $matrix2Columns) && ($matrix2Rows == $matrix1Columns)) {
2445
- $resize = 1;
2446
- }
2447
-
2448
- if ($resize == 2) {
2449
- // Given two matrices of (potentially) unequal size, convert the smaller in each dimension to match the larger
2450
- self::_resizeMatricesExtend($operand1,$operand2,$matrix1Rows,$matrix1Columns,$matrix2Rows,$matrix2Columns);
2451
- } elseif ($resize == 1) {
2452
- // Given two matrices of (potentially) unequal size, convert the larger in each dimension to match the smaller
2453
- self::_resizeMatricesShrink($operand1,$operand2,$matrix1Rows,$matrix1Columns,$matrix2Rows,$matrix2Columns);
2454
- }
2455
- return array( $matrix1Rows,$matrix1Columns,$matrix2Rows,$matrix2Columns);
2456
- } // function _checkMatrixOperands()
2457
-
2458
-
2459
- /**
2460
- * Read the dimensions of a matrix, and re-index it with straight numeric keys starting from row 0, column 0
2461
- *
2462
- * @param mixed &$matrix matrix operand
2463
- * @return array An array comprising the number of rows, and number of columns
2464
- */
2465
- public static function _getMatrixDimensions(&$matrix) {
2466
- $matrixRows = count($matrix);
2467
- $matrixColumns = 0;
2468
- foreach($matrix as $rowKey => $rowValue) {
2469
- $matrixColumns = max(count($rowValue),$matrixColumns);
2470
- if (!is_array($rowValue)) {
2471
- $matrix[$rowKey] = array($rowValue);
2472
- } else {
2473
- $matrix[$rowKey] = array_values($rowValue);
2474
- }
2475
- }
2476
- $matrix = array_values($matrix);
2477
- return array($matrixRows,$matrixColumns);
2478
- } // function _getMatrixDimensions()
2479
-
2480
-
2481
- /**
2482
- * Ensure that paired matrix operands are both matrices of the same size
2483
- *
2484
- * @param mixed &$matrix1 First matrix operand
2485
- * @param mixed &$matrix2 Second matrix operand
2486
- * @param integer $matrix1Rows Row size of first matrix operand
2487
- * @param integer $matrix1Columns Column size of first matrix operand
2488
- * @param integer $matrix2Rows Row size of second matrix operand
2489
- * @param integer $matrix2Columns Column size of second matrix operand
2490
- */
2491
- private static function _resizeMatricesShrink(&$matrix1,&$matrix2,$matrix1Rows,$matrix1Columns,$matrix2Rows,$matrix2Columns) {
2492
- if (($matrix2Columns < $matrix1Columns) || ($matrix2Rows < $matrix1Rows)) {
2493
- if ($matrix2Rows < $matrix1Rows) {
2494
- for ($i = $matrix2Rows; $i < $matrix1Rows; ++$i) {
2495
- unset($matrix1[$i]);
2496
- }
2497
- }
2498
- if ($matrix2Columns < $matrix1Columns) {
2499
- for ($i = 0; $i < $matrix1Rows; ++$i) {
2500
- for ($j = $matrix2Columns; $j < $matrix1Columns; ++$j) {
2501
- unset($matrix1[$i][$j]);
2502
- }
2503
- }
2504
- }
2505
- }
2506
-
2507
- if (($matrix1Columns < $matrix2Columns) || ($matrix1Rows < $matrix2Rows)) {
2508
- if ($matrix1Rows < $matrix2Rows) {
2509
- for ($i = $matrix1Rows; $i < $matrix2Rows; ++$i) {
2510
- unset($matrix2[$i]);
2511
- }
2512
- }
2513
- if ($matrix1Columns < $matrix2Columns) {
2514
- for ($i = 0; $i < $matrix2Rows; ++$i) {
2515
- for ($j = $matrix1Columns; $j < $matrix2Columns; ++$j) {
2516
- unset($matrix2[$i][$j]);
2517
- }
2518
- }
2519
- }
2520
- }
2521
- } // function _resizeMatricesShrink()
2522
-
2523
-
2524
- /**
2525
- * Ensure that paired matrix operands are both matrices of the same size
2526
- *
2527
- * @param mixed &$matrix1 First matrix operand
2528
- * @param mixed &$matrix2 Second matrix operand
2529
- * @param integer $matrix1Rows Row size of first matrix operand
2530
- * @param integer $matrix1Columns Column size of first matrix operand
2531
- * @param integer $matrix2Rows Row size of second matrix operand
2532
- * @param integer $matrix2Columns Column size of second matrix operand
2533
- */
2534
- private static function _resizeMatricesExtend(&$matrix1,&$matrix2,$matrix1Rows,$matrix1Columns,$matrix2Rows,$matrix2Columns) {
2535
- if (($matrix2Columns < $matrix1Columns) || ($matrix2Rows < $matrix1Rows)) {
2536
- if ($matrix2Columns < $matrix1Columns) {
2537
- for ($i = 0; $i < $matrix2Rows; ++$i) {
2538
- $x = $matrix2[$i][$matrix2Columns-1];
2539
- for ($j = $matrix2Columns; $j < $matrix1Columns; ++$j) {
2540
- $matrix2[$i][$j] = $x;
2541
- }
2542
- }
2543
- }
2544
- if ($matrix2Rows < $matrix1Rows) {
2545
- $x = $matrix2[$matrix2Rows-1];
2546
- for ($i = 0; $i < $matrix1Rows; ++$i) {
2547
- $matrix2[$i] = $x;
2548
- }
2549
- }
2550
- }
2551
-
2552
- if (($matrix1Columns < $matrix2Columns) || ($matrix1Rows < $matrix2Rows)) {
2553
- if ($matrix1Columns < $matrix2Columns) {
2554
- for ($i = 0; $i < $matrix1Rows; ++$i) {
2555
- $x = $matrix1[$i][$matrix1Columns-1];
2556
- for ($j = $matrix1Columns; $j < $matrix2Columns; ++$j) {
2557
- $matrix1[$i][$j] = $x;
2558
- }
2559
- }
2560
- }
2561
- if ($matrix1Rows < $matrix2Rows) {
2562
- $x = $matrix1[$matrix1Rows-1];
2563
- for ($i = 0; $i < $matrix2Rows; ++$i) {
2564
- $matrix1[$i] = $x;
2565
- }
2566
- }
2567
- }
2568
- } // function _resizeMatricesExtend()
2569
-
2570
-
2571
- /**
2572
- * Format details of an operand for display in the log (based on operand type)
2573
- *
2574
- * @param mixed $value First matrix operand
2575
- * @return mixed
2576
- */
2577
- private function _showValue($value) {
2578
- if ($this->_debugLog->getWriteDebugLog()) {
2579
- $testArray = PHPExcel_Calculation_Functions::flattenArray($value);
2580
- if (count($testArray) == 1) {
2581
- $value = array_pop($testArray);
2582
- }
2583
-
2584
- if (is_array($value)) {
2585
- $returnMatrix = array();
2586
- $pad = $rpad = ', ';
2587
- foreach($value as $row) {
2588
- if (is_array($row)) {
2589
- $returnMatrix[] = implode($pad,array_map(array($this,'_showValue'),$row));
2590
- $rpad = '; ';
2591
- } else {
2592
- $returnMatrix[] = $this->_showValue($row);
2593
- }
2594
- }
2595
- return '{ '.implode($rpad,$returnMatrix).' }';
2596
- } elseif(is_string($value) && (trim($value,'"') == $value)) {
2597
- return '"'.$value.'"';
2598
- } elseif(is_bool($value)) {
2599
- return ($value) ? self::$_localeBoolean['TRUE'] : self::$_localeBoolean['FALSE'];
2600
- }
2601
- }
2602
- return PHPExcel_Calculation_Functions::flattenSingleValue($value);
2603
- } // function _showValue()
2604
-
2605
-
2606
- /**
2607
- * Format type and details of an operand for display in the log (based on operand type)
2608
- *
2609
- * @param mixed $value First matrix operand
2610
- * @return mixed
2611
- */
2612
- private function _showTypeDetails($value) {
2613
- if ($this->_debugLog->getWriteDebugLog()) {
2614
- $testArray = PHPExcel_Calculation_Functions::flattenArray($value);
2615
- if (count($testArray) == 1) {
2616
- $value = array_pop($testArray);
2617
- }
2618
-
2619
- if ($value === NULL) {
2620
- return 'a NULL value';
2621
- } elseif (is_float($value)) {
2622
- $typeString = 'a floating point number';
2623
- } elseif(is_int($value)) {
2624
- $typeString = 'an integer number';
2625
- } elseif(is_bool($value)) {
2626
- $typeString = 'a boolean';
2627
- } elseif(is_array($value)) {
2628
- $typeString = 'a matrix';
2629
- } else {
2630
- if ($value == '') {
2631
- return 'an empty string';
2632
- } elseif ($value{0} == '#') {
2633
- return 'a '.$value.' error';
2634
- } else {
2635
- $typeString = 'a string';
2636
- }
2637
- }
2638
- return $typeString.' with a value of '.$this->_showValue($value);
2639
- }
2640
- } // function _showTypeDetails()
2641
-
2642
-
2643
- private static function _convertMatrixReferences($formula) {
2644
- static $matrixReplaceFrom = array('{',';','}');
2645
- static $matrixReplaceTo = array('MKMATRIX(MKMATRIX(','),MKMATRIX(','))');
2646
-
2647
- // Convert any Excel matrix references to the MKMATRIX() function
2648
- if (strpos($formula,'{') !== FALSE) {
2649
- // If there is the possibility of braces within a quoted string, then we don't treat those as matrix indicators
2650
- if (strpos($formula,'"') !== FALSE) {
2651
- // So instead we skip replacing in any quoted strings by only replacing in every other array element after we've exploded
2652
- // the formula
2653
- $temp = explode('"',$formula);
2654
- // Open and Closed counts used for trapping mismatched braces in the formula
2655
- $openCount = $closeCount = 0;
2656
- $i = FALSE;
2657
- foreach($temp as &$value) {
2658
- // Only count/replace in alternating array entries
2659
- if ($i = !$i) {
2660
- $openCount += substr_count($value,'{');
2661
- $closeCount += substr_count($value,'}');
2662
- $value = str_replace($matrixReplaceFrom,$matrixReplaceTo,$value);
2663
- }
2664
- }
2665
- unset($value);
2666
- // Then rebuild the formula string
2667
- $formula = implode('"',$temp);
2668
- } else {
2669
- // If there's no quoted strings, then we do a simple count/replace
2670
- $openCount = substr_count($formula,'{');
2671
- $closeCount = substr_count($formula,'}');
2672
- $formula = str_replace($matrixReplaceFrom,$matrixReplaceTo,$formula);
2673
- }
2674
- // Trap for mismatched braces and trigger an appropriate error
2675
- if ($openCount < $closeCount) {
2676
- if ($openCount > 0) {
2677
- return $this->_raiseFormulaError("Formula Error: Mismatched matrix braces '}'");
2678
- } else {
2679
- return $this->_raiseFormulaError("Formula Error: Unexpected '}' encountered");
2680
- }
2681
- } elseif ($openCount > $closeCount) {
2682
- if ($closeCount > 0) {
2683
- return $this->_raiseFormulaError("Formula Error: Mismatched matrix braces '{'");
2684
- } else {
2685
- return $this->_raiseFormulaError("Formula Error: Unexpected '{' encountered");
2686
- }
2687
- }
2688
- }
2689
-
2690
- return $formula;
2691
- } // function _convertMatrixReferences()
2692
-
2693
-
2694
- private static function _mkMatrix() {
2695
- return func_get_args();
2696
- } // function _mkMatrix()
2697
-
2698
-
2699
- // Binary Operators
2700
- // These operators always work on two values
2701
- // Array key is the operator, the value indicates whether this is a left or right associative operator
2702
- private static $_operatorAssociativity = array(
2703
- '^' => 0, // Exponentiation
2704
- '*' => 0, '/' => 0, // Multiplication and Division
2705
- '+' => 0, '-' => 0, // Addition and Subtraction
2706
- '&' => 0, // Concatenation
2707
- '|' => 0, ':' => 0, // Intersect and Range
2708
- '>' => 0, '<' => 0, '=' => 0, '>=' => 0, '<=' => 0, '<>' => 0 // Comparison
2709
- );
2710
-
2711
- // Comparison (Boolean) Operators
2712
- // These operators work on two values, but always return a boolean result
2713
- private static $_comparisonOperators = array('>' => TRUE, '<' => TRUE, '=' => TRUE, '>=' => TRUE, '<=' => TRUE, '<>' => TRUE);
2714
-
2715
- // Operator Precedence
2716
- // This list includes all valid operators, whether binary (including boolean) or unary (such as %)
2717
- // Array key is the operator, the value is its precedence
2718
- private static $_operatorPrecedence = array(
2719
- ':' => 8, // Range
2720
- '|' => 7, // Intersect
2721
- '~' => 6, // Negation
2722
- '%' => 5, // Percentage
2723
- '^' => 4, // Exponentiation
2724
- '*' => 3, '/' => 3, // Multiplication and Division
2725
- '+' => 2, '-' => 2, // Addition and Subtraction
2726
- '&' => 1, // Concatenation
2727
- '>' => 0, '<' => 0, '=' => 0, '>=' => 0, '<=' => 0, '<>' => 0 // Comparison
2728
- );
2729
-
2730
- // Convert infix to postfix notation
2731
- private function _parseFormula($formula, PHPExcel_Cell $pCell = NULL) {
2732
- if (($formula = self::_convertMatrixReferences(trim($formula))) === FALSE) {
2733
- return FALSE;
2734
- }
2735
-
2736
- // If we're using cell caching, then $pCell may well be flushed back to the cache (which detaches the parent worksheet),
2737
- // so we store the parent worksheet so that we can re-attach it when necessary
2738
- $pCellParent = ($pCell !== NULL) ? $pCell->getWorksheet() : NULL;
2739
-
2740
- $regexpMatchString = '/^('.self::CALCULATION_REGEXP_FUNCTION.
2741
- '|'.self::CALCULATION_REGEXP_CELLREF.
2742
- '|'.self::CALCULATION_REGEXP_NUMBER.
2743
- '|'.self::CALCULATION_REGEXP_STRING.
2744
- '|'.self::CALCULATION_REGEXP_OPENBRACE.
2745
- '|'.self::CALCULATION_REGEXP_NAMEDRANGE.
2746
- '|'.self::CALCULATION_REGEXP_ERROR.
2747
- ')/si';
2748
-
2749
- // Start with initialisation
2750
- $index = 0;
2751
- $stack = new PHPExcel_Calculation_Token_Stack;
2752
- $output = array();
2753
- $expectingOperator = FALSE; // We use this test in syntax-checking the expression to determine when a
2754
- // - is a negation or + is a positive operator rather than an operation
2755
- $expectingOperand = FALSE; // We use this test in syntax-checking the expression to determine whether an operand
2756
- // should be null in a function call
2757
- // The guts of the lexical parser
2758
- // Loop through the formula extracting each operator and operand in turn
2759
- while(TRUE) {
2760
- //echo 'Assessing Expression '.substr($formula, $index),PHP_EOL;
2761
- $opCharacter = $formula{$index}; // Get the first character of the value at the current index position
2762
- //echo 'Initial character of expression block is '.$opCharacter,PHP_EOL;
2763
- if ((isset(self::$_comparisonOperators[$opCharacter])) && (strlen($formula) > $index) && (isset(self::$_comparisonOperators[$formula{$index+1}]))) {
2764
- $opCharacter .= $formula{++$index};
2765
- //echo 'Initial character of expression block is comparison operator '.$opCharacter.PHP_EOL;
2766
- }
2767
-
2768
- // Find out if we're currently at the beginning of a number, variable, cell reference, function, parenthesis or operand
2769
- $isOperandOrFunction = preg_match($regexpMatchString, substr($formula, $index), $match);
2770
- //echo '$isOperandOrFunction is '.(($isOperandOrFunction) ? 'True' : 'False').PHP_EOL;
2771
- //var_dump($match);
2772
-
2773
- if ($opCharacter == '-' && !$expectingOperator) { // Is it a negation instead of a minus?
2774
- //echo 'Element is a Negation operator',PHP_EOL;
2775
- $stack->push('Unary Operator','~'); // Put a negation on the stack
2776
- ++$index; // and drop the negation symbol
2777
- } elseif ($opCharacter == '%' && $expectingOperator) {
2778
- //echo 'Element is a Percentage operator',PHP_EOL;
2779
- $stack->push('Unary Operator','%'); // Put a percentage on the stack
2780
- ++$index;
2781
- } elseif ($opCharacter == '+' && !$expectingOperator) { // Positive (unary plus rather than binary operator plus) can be discarded?
2782
- //echo 'Element is a Positive number, not Plus operator',PHP_EOL;
2783
- ++$index; // Drop the redundant plus symbol
2784
- } elseif ((($opCharacter == '~') || ($opCharacter == '|')) && (!$isOperandOrFunction)) { // We have to explicitly deny a tilde or pipe, because they are legal
2785
- return $this->_raiseFormulaError("Formula Error: Illegal character '~'"); // on the stack but not in the input expression
2786
-
2787
- } elseif ((isset(self::$_operators[$opCharacter]) or $isOperandOrFunction) && $expectingOperator) { // Are we putting an operator on the stack?
2788
- //echo 'Element with value '.$opCharacter.' is an Operator',PHP_EOL;
2789
- while($stack->count() > 0 &&
2790
- ($o2 = $stack->last()) &&
2791
- isset(self::$_operators[$o2['value']]) &&
2792
- @(self::$_operatorAssociativity[$opCharacter] ? self::$_operatorPrecedence[$opCharacter] < self::$_operatorPrecedence[$o2['value']] : self::$_operatorPrecedence[$opCharacter] <= self::$_operatorPrecedence[$o2['value']])) {
2793
- $output[] = $stack->pop(); // Swap operands and higher precedence operators from the stack to the output
2794
- }
2795
- $stack->push('Binary Operator',$opCharacter); // Finally put our current operator onto the stack
2796
- ++$index;
2797
- $expectingOperator = FALSE;
2798
-
2799
- } elseif ($opCharacter == ')' && $expectingOperator) { // Are we expecting to close a parenthesis?
2800
- //echo 'Element is a Closing bracket',PHP_EOL;
2801
- $expectingOperand = FALSE;
2802
- while (($o2 = $stack->pop()) && $o2['value'] != '(') { // Pop off the stack back to the last (
2803
- if ($o2 === NULL) return $this->_raiseFormulaError('Formula Error: Unexpected closing brace ")"');
2804
- else $output[] = $o2;
2805
- }
2806
- $d = $stack->last(2);
2807
- if (preg_match('/^'.self::CALCULATION_REGEXP_FUNCTION.'$/i', $d['value'], $matches)) { // Did this parenthesis just close a function?
2808
- $functionName = $matches[1]; // Get the function name
2809
- //echo 'Closed Function is '.$functionName,PHP_EOL;
2810
- $d = $stack->pop();
2811
- $argumentCount = $d['value']; // See how many arguments there were (argument count is the next value stored on the stack)
2812
- //if ($argumentCount == 0) {
2813
- // echo 'With no arguments',PHP_EOL;
2814
- //} elseif ($argumentCount == 1) {
2815
- // echo 'With 1 argument',PHP_EOL;
2816
- //} else {
2817
- // echo 'With '.$argumentCount.' arguments',PHP_EOL;
2818
- //}
2819
- $output[] = $d; // Dump the argument count on the output
2820
- $output[] = $stack->pop(); // Pop the function and push onto the output
2821
- if (isset(self::$_controlFunctions[$functionName])) {
2822
- //echo 'Built-in function '.$functionName,PHP_EOL;
2823
- $expectedArgumentCount = self::$_controlFunctions[$functionName]['argumentCount'];
2824
- $functionCall = self::$_controlFunctions[$functionName]['functionCall'];
2825
- } elseif (isset(self::$_PHPExcelFunctions[$functionName])) {
2826
- //echo 'PHPExcel function '.$functionName,PHP_EOL;
2827
- $expectedArgumentCount = self::$_PHPExcelFunctions[$functionName]['argumentCount'];
2828
- $functionCall = self::$_PHPExcelFunctions[$functionName]['functionCall'];
2829
- } else { // did we somehow push a non-function on the stack? this should never happen
2830
- return $this->_raiseFormulaError("Formula Error: Internal error, non-function on stack");
2831
- }
2832
- // Check the argument count
2833
- $argumentCountError = FALSE;
2834
- if (is_numeric($expectedArgumentCount)) {
2835
- if ($expectedArgumentCount < 0) {
2836
- //echo '$expectedArgumentCount is between 0 and '.abs($expectedArgumentCount),PHP_EOL;
2837
- if ($argumentCount > abs($expectedArgumentCount)) {
2838
- $argumentCountError = TRUE;
2839
- $expectedArgumentCountString = 'no more than '.abs($expectedArgumentCount);
2840
- }
2841
- } else {
2842
- //echo '$expectedArgumentCount is numeric '.$expectedArgumentCount,PHP_EOL;
2843
- if ($argumentCount != $expectedArgumentCount) {
2844
- $argumentCountError = TRUE;
2845
- $expectedArgumentCountString = $expectedArgumentCount;
2846
- }
2847
- }
2848
- } elseif ($expectedArgumentCount != '*') {
2849
- $isOperandOrFunction = preg_match('/(\d*)([-+,])(\d*)/',$expectedArgumentCount,$argMatch);
2850
- //print_r($argMatch);
2851
- //echo PHP_EOL;
2852
- switch ($argMatch[2]) {
2853
- case '+' :
2854
- if ($argumentCount < $argMatch[1]) {
2855
- $argumentCountError = TRUE;
2856
- $expectedArgumentCountString = $argMatch[1].' or more ';
2857
- }
2858
- break;
2859
- case '-' :
2860
- if (($argumentCount < $argMatch[1]) || ($argumentCount > $argMatch[3])) {
2861
- $argumentCountError = TRUE;
2862
- $expectedArgumentCountString = 'between '.$argMatch[1].' and '.$argMatch[3];
2863
- }
2864
- break;
2865
- case ',' :
2866
- if (($argumentCount != $argMatch[1]) && ($argumentCount != $argMatch[3])) {
2867
- $argumentCountError = TRUE;
2868
- $expectedArgumentCountString = 'either '.$argMatch[1].' or '.$argMatch[3];
2869
- }
2870
- break;
2871
- }
2872
- }
2873
- if ($argumentCountError) {
2874
- return $this->_raiseFormulaError("Formula Error: Wrong number of arguments for $functionName() function: $argumentCount given, ".$expectedArgumentCountString." expected");
2875
- }
2876
- }
2877
- ++$index;
2878
-
2879
- } elseif ($opCharacter == ',') { // Is this the separator for function arguments?
2880
- //echo 'Element is a Function argument separator',PHP_EOL;
2881
- while (($o2 = $stack->pop()) && $o2['value'] != '(') { // Pop off the stack back to the last (
2882
- if ($o2 === NULL) return $this->_raiseFormulaError("Formula Error: Unexpected ,");
2883
- else $output[] = $o2; // pop the argument expression stuff and push onto the output
2884
- }
2885
- // If we've a comma when we're expecting an operand, then what we actually have is a null operand;
2886
- // so push a null onto the stack
2887
- if (($expectingOperand) || (!$expectingOperator)) {
2888
- $output[] = array('type' => 'NULL Value', 'value' => self::$_ExcelConstants['NULL'], 'reference' => NULL);
2889
- }
2890
- // make sure there was a function
2891
- $d = $stack->last(2);
2892
- if (!preg_match('/^'.self::CALCULATION_REGEXP_FUNCTION.'$/i', $d['value'], $matches))
2893
- return $this->_raiseFormulaError("Formula Error: Unexpected ,");
2894
- $d = $stack->pop();
2895
- $stack->push($d['type'],++$d['value'],$d['reference']); // increment the argument count
2896
- $stack->push('Brace', '('); // put the ( back on, we'll need to pop back to it again
2897
- $expectingOperator = FALSE;
2898
- $expectingOperand = TRUE;
2899
- ++$index;
2900
-
2901
- } elseif ($opCharacter == '(' && !$expectingOperator) {
2902
- // echo 'Element is an Opening Bracket<br />';
2903
- $stack->push('Brace', '(');
2904
- ++$index;
2905
-
2906
- } elseif ($isOperandOrFunction && !$expectingOperator) { // do we now have a function/variable/number?
2907
- $expectingOperator = TRUE;
2908
- $expectingOperand = FALSE;
2909
- $val = $match[1];
2910
- $length = strlen($val);
2911
- // echo 'Element with value '.$val.' is an Operand, Variable, Constant, String, Number, Cell Reference or Function<br />';
2912
-
2913
- if (preg_match('/^'.self::CALCULATION_REGEXP_FUNCTION.'$/i', $val, $matches)) {
2914
- $val = preg_replace('/\s/','',$val);
2915
- // echo 'Element '.$val.' is a Function<br />';
2916
- if (isset(self::$_PHPExcelFunctions[strtoupper($matches[1])]) || isset(self::$_controlFunctions[strtoupper($matches[1])])) { // it's a function
2917
- $stack->push('Function', strtoupper($val));
2918
- $ax = preg_match('/^\s*(\s*\))/i', substr($formula, $index+$length), $amatch);
2919
- if ($ax) {
2920
- $stack->push('Operand Count for Function '.strtoupper($val).')', 0);
2921
- $expectingOperator = TRUE;
2922
- } else {
2923
- $stack->push('Operand Count for Function '.strtoupper($val).')', 1);
2924
- $expectingOperator = FALSE;
2925
- }
2926
- $stack->push('Brace', '(');
2927
- } else { // it's a var w/ implicit multiplication
2928
- $output[] = array('type' => 'Value', 'value' => $matches[1], 'reference' => NULL);
2929
- }
2930
- } elseif (preg_match('/^'.self::CALCULATION_REGEXP_CELLREF.'$/i', $val, $matches)) {
2931
- // echo 'Element '.$val.' is a Cell reference<br />';
2932
- // Watch for this case-change when modifying to allow cell references in different worksheets...
2933
- // Should only be applied to the actual cell column, not the worksheet name
2934
-
2935
- // If the last entry on the stack was a : operator, then we have a cell range reference
2936
- $testPrevOp = $stack->last(1);
2937
- if ($testPrevOp['value'] == ':') {
2938
- // If we have a worksheet reference, then we're playing with a 3D reference
2939
- if ($matches[2] == '') {
2940
- // Otherwise, we 'inherit' the worksheet reference from the start cell reference
2941
- // The start of the cell range reference should be the last entry in $output
2942
- $startCellRef = $output[count($output)-1]['value'];
2943
- preg_match('/^'.self::CALCULATION_REGEXP_CELLREF.'$/i', $startCellRef, $startMatches);
2944
- if ($startMatches[2] > '') {
2945
- $val = $startMatches[2].'!'.$val;
2946
- }
2947
- } else {
2948
- return $this->_raiseFormulaError("3D Range references are not yet supported");
2949
- }
2950
- }
2951
-
2952
- $output[] = array('type' => 'Cell Reference', 'value' => $val, 'reference' => $val);
2953
- // $expectingOperator = FALSE;
2954
- } else { // it's a variable, constant, string, number or boolean
2955
- // echo 'Element is a Variable, Constant, String, Number or Boolean<br />';
2956
- // If the last entry on the stack was a : operator, then we may have a row or column range reference
2957
- $testPrevOp = $stack->last(1);
2958
- if ($testPrevOp['value'] == ':') {
2959
- $startRowColRef = $output[count($output)-1]['value'];
2960
- $rangeWS1 = '';
2961
- if (strpos('!',$startRowColRef) !== FALSE) {
2962
- list($rangeWS1,$startRowColRef) = explode('!',$startRowColRef);
2963
- }
2964
- if ($rangeWS1 != '') $rangeWS1 .= '!';
2965
- $rangeWS2 = $rangeWS1;
2966
- if (strpos('!',$val) !== FALSE) {
2967
- list($rangeWS2,$val) = explode('!',$val);
2968
- }
2969
- if ($rangeWS2 != '') $rangeWS2 .= '!';
2970
- if ((is_integer($startRowColRef)) && (ctype_digit($val)) &&
2971
- ($startRowColRef <= 1048576) && ($val <= 1048576)) {
2972
- // Row range
2973
- $endRowColRef = ($pCellParent !== NULL) ? $pCellParent->getHighestColumn() : 'XFD'; // Max 16,384 columns for Excel2007
2974
- $output[count($output)-1]['value'] = $rangeWS1.'A'.$startRowColRef;
2975
- $val = $rangeWS2.$endRowColRef.$val;
2976
- } elseif ((ctype_alpha($startRowColRef)) && (ctype_alpha($val)) &&
2977
- (strlen($startRowColRef) <= 3) && (strlen($val) <= 3)) {
2978
- // Column range
2979
- $endRowColRef = ($pCellParent !== NULL) ? $pCellParent->getHighestRow() : 1048576; // Max 1,048,576 rows for Excel2007
2980
- $output[count($output)-1]['value'] = $rangeWS1.strtoupper($startRowColRef).'1';
2981
- $val = $rangeWS2.$val.$endRowColRef;
2982
- }
2983
- }
2984
-
2985
- $localeConstant = FALSE;
2986
- if ($opCharacter == '"') {
2987
- // echo 'Element is a String<br />';
2988
- // UnEscape any quotes within the string
2989
- $val = self::_wrapResult(str_replace('""','"',self::_unwrapResult($val)));
2990
- } elseif (is_numeric($val)) {
2991
- // echo 'Element is a Number<br />';
2992
- if ((strpos($val,'.') !== FALSE) || (stripos($val,'e') !== FALSE) || ($val > PHP_INT_MAX) || ($val < -PHP_INT_MAX)) {
2993
- // echo 'Casting '.$val.' to float<br />';
2994
- $val = (float) $val;
2995
- } else {
2996
- // echo 'Casting '.$val.' to integer<br />';
2997
- $val = (integer) $val;
2998
- }
2999
- } elseif (isset(self::$_ExcelConstants[trim(strtoupper($val))])) {
3000
- $excelConstant = trim(strtoupper($val));
3001
- // echo 'Element '.$excelConstant.' is an Excel Constant<br />';
3002
- $val = self::$_ExcelConstants[$excelConstant];
3003
- } elseif (($localeConstant = array_search(trim(strtoupper($val)), self::$_localeBoolean)) !== FALSE) {
3004
- // echo 'Element '.$localeConstant.' is an Excel Constant<br />';
3005
- $val = self::$_ExcelConstants[$localeConstant];
3006
- }
3007
- $details = array('type' => 'Value', 'value' => $val, 'reference' => NULL);
3008
- if ($localeConstant) { $details['localeValue'] = $localeConstant; }
3009
- $output[] = $details;
3010
- }
3011
- $index += $length;
3012
-
3013
- } elseif ($opCharacter == '$') { // absolute row or column range
3014
- ++$index;
3015
- } elseif ($opCharacter == ')') { // miscellaneous error checking
3016
- if ($expectingOperand) {
3017
- $output[] = array('type' => 'NULL Value', 'value' => self::$_ExcelConstants['NULL'], 'reference' => NULL);
3018
- $expectingOperand = FALSE;
3019
- $expectingOperator = TRUE;
3020
- } else {
3021
- return $this->_raiseFormulaError("Formula Error: Unexpected ')'");
3022
- }
3023
- } elseif (isset(self::$_operators[$opCharacter]) && !$expectingOperator) {
3024
- return $this->_raiseFormulaError("Formula Error: Unexpected operator '$opCharacter'");
3025
- } else { // I don't even want to know what you did to get here
3026
- return $this->_raiseFormulaError("Formula Error: An unexpected error occured");
3027
- }
3028
- // Test for end of formula string
3029
- if ($index == strlen($formula)) {
3030
- // Did we end with an operator?.
3031
- // Only valid for the % unary operator
3032
- if ((isset(self::$_operators[$opCharacter])) && ($opCharacter != '%')) {
3033
- return $this->_raiseFormulaError("Formula Error: Operator '$opCharacter' has no operands");
3034
- } else {
3035
- break;
3036
- }
3037
- }
3038
- // Ignore white space
3039
- while (($formula{$index} == "\n") || ($formula{$index} == "\r")) {
3040
- ++$index;
3041
- }
3042
- if ($formula{$index} == ' ') {
3043
- while ($formula{$index} == ' ') {
3044
- ++$index;
3045
- }
3046
- // If we're expecting an operator, but only have a space between the previous and next operands (and both are
3047
- // Cell References) then we have an INTERSECTION operator
3048
- // echo 'Possible Intersect Operator<br />';
3049
- if (($expectingOperator) && (preg_match('/^'.self::CALCULATION_REGEXP_CELLREF.'.*/Ui', substr($formula, $index), $match)) &&
3050
- ($output[count($output)-1]['type'] == 'Cell Reference')) {
3051
- // echo 'Element is an Intersect Operator<br />';
3052
- while($stack->count() > 0 &&
3053
- ($o2 = $stack->last()) &&
3054
- isset(self::$_operators[$o2['value']]) &&
3055
- @(self::$_operatorAssociativity[$opCharacter] ? self::$_operatorPrecedence[$opCharacter] < self::$_operatorPrecedence[$o2['value']] : self::$_operatorPrecedence[$opCharacter] <= self::$_operatorPrecedence[$o2['value']])) {
3056
- $output[] = $stack->pop(); // Swap operands and higher precedence operators from the stack to the output
3057
- }
3058
- $stack->push('Binary Operator','|'); // Put an Intersect Operator on the stack
3059
- $expectingOperator = FALSE;
3060
- }
3061
- }
3062
- }
3063
-
3064
- while (($op = $stack->pop()) !== NULL) { // pop everything off the stack and push onto output
3065
- if ((is_array($op) && $op['value'] == '(') || ($op === '('))
3066
- return $this->_raiseFormulaError("Formula Error: Expecting ')'"); // if there are any opening braces on the stack, then braces were unbalanced
3067
- $output[] = $op;
3068
- }
3069
- return $output;
3070
- } // function _parseFormula()
3071
-
3072
-
3073
- private static function _dataTestReference(&$operandData)
3074
- {
3075
- $operand = $operandData['value'];
3076
- if (($operandData['reference'] === NULL) && (is_array($operand))) {
3077
- $rKeys = array_keys($operand);
3078
- $rowKey = array_shift($rKeys);
3079
- $cKeys = array_keys(array_keys($operand[$rowKey]));
3080
- $colKey = array_shift($cKeys);
3081
- if (ctype_upper($colKey)) {
3082
- $operandData['reference'] = $colKey.$rowKey;
3083
- }
3084
- }
3085
- return $operand;
3086
- }
3087
-
3088
- // evaluate postfix notation
3089
- private function _processTokenStack($tokens, $cellID = NULL, PHPExcel_Cell $pCell = NULL) {
3090
- if ($tokens == FALSE) return FALSE;
3091
-
3092
- // If we're using cell caching, then $pCell may well be flushed back to the cache (which detaches the parent cell collection),
3093
- // so we store the parent cell collection so that we can re-attach it when necessary
3094
- $pCellWorksheet = ($pCell !== NULL) ? $pCell->getWorksheet() : NULL;
3095
- $pCellParent = ($pCell !== NULL) ? $pCell->getParent() : null;
3096
- $stack = new PHPExcel_Calculation_Token_Stack;
3097
-
3098
- // Loop through each token in turn
3099
- foreach ($tokens as $tokenData) {
3100
- // print_r($tokenData);
3101
- // echo '<br />';
3102
- $token = $tokenData['value'];
3103
- // echo '<b>Token is '.$token.'</b><br />';
3104
- // if the token is a binary operator, pop the top two values off the stack, do the operation, and push the result back on the stack
3105
- if (isset(self::$_binaryOperators[$token])) {
3106
- // echo 'Token is a binary operator<br />';
3107
- // We must have two operands, error if we don't
3108
- if (($operand2Data = $stack->pop()) === NULL) return $this->_raiseFormulaError('Internal error - Operand value missing from stack');
3109
- if (($operand1Data = $stack->pop()) === NULL) return $this->_raiseFormulaError('Internal error - Operand value missing from stack');
3110
-
3111
- $operand1 = self::_dataTestReference($operand1Data);
3112
- $operand2 = self::_dataTestReference($operand2Data);
3113
-
3114
- // Log what we're doing
3115
- if ($token == ':') {
3116
- $this->_debugLog->writeDebugLog('Evaluating Range ', $this->_showValue($operand1Data['reference']), ' ', $token, ' ', $this->_showValue($operand2Data['reference']));
3117
- } else {
3118
- $this->_debugLog->writeDebugLog('Evaluating ', $this->_showValue($operand1), ' ', $token, ' ', $this->_showValue($operand2));
3119
- }
3120
-
3121
- // Process the operation in the appropriate manner
3122
- switch ($token) {
3123
- // Comparison (Boolean) Operators
3124
- case '>' : // Greater than
3125
- case '<' : // Less than
3126
- case '>=' : // Greater than or Equal to
3127
- case '<=' : // Less than or Equal to
3128
- case '=' : // Equality
3129
- case '<>' : // Inequality
3130
- $this->_executeBinaryComparisonOperation($cellID,$operand1,$operand2,$token,$stack);
3131
- break;
3132
- // Binary Operators
3133
- case ':' : // Range
3134
- $sheet1 = $sheet2 = '';
3135
- if (strpos($operand1Data['reference'],'!') !== FALSE) {
3136
- list($sheet1,$operand1Data['reference']) = explode('!',$operand1Data['reference']);
3137
- } else {
3138
- $sheet1 = ($pCellParent !== NULL) ? $pCellWorksheet->getTitle() : '';
3139
- }
3140
- if (strpos($operand2Data['reference'],'!') !== FALSE) {
3141
- list($sheet2,$operand2Data['reference']) = explode('!',$operand2Data['reference']);
3142
- } else {
3143
- $sheet2 = $sheet1;
3144
- }
3145
- if ($sheet1 == $sheet2) {
3146
- if ($operand1Data['reference'] === NULL) {
3147
- if ((trim($operand1Data['value']) != '') && (is_numeric($operand1Data['value']))) {
3148
- $operand1Data['reference'] = $pCell->getColumn().$operand1Data['value'];
3149
- } elseif (trim($operand1Data['reference']) == '') {
3150
- $operand1Data['reference'] = $pCell->getCoordinate();
3151
- } else {
3152
- $operand1Data['reference'] = $operand1Data['value'].$pCell->getRow();
3153
- }
3154
- }
3155
- if ($operand2Data['reference'] === NULL) {
3156
- if ((trim($operand2Data['value']) != '') && (is_numeric($operand2Data['value']))) {
3157
- $operand2Data['reference'] = $pCell->getColumn().$operand2Data['value'];
3158
- } elseif (trim($operand2Data['reference']) == '') {
3159
- $operand2Data['reference'] = $pCell->getCoordinate();
3160
- } else {
3161
- $operand2Data['reference'] = $operand2Data['value'].$pCell->getRow();
3162
- }
3163
- }
3164
-
3165
- $oData = array_merge(explode(':',$operand1Data['reference']),explode(':',$operand2Data['reference']));
3166
- $oCol = $oRow = array();
3167
- foreach($oData as $oDatum) {
3168
- $oCR = PHPExcel_Cell::coordinateFromString($oDatum);
3169
- $oCol[] = PHPExcel_Cell::columnIndexFromString($oCR[0]) - 1;
3170
- $oRow[] = $oCR[1];
3171
- }
3172
- $cellRef = PHPExcel_Cell::stringFromColumnIndex(min($oCol)).min($oRow).':'.PHPExcel_Cell::stringFromColumnIndex(max($oCol)).max($oRow);
3173
- if ($pCellParent !== NULL) {
3174
- $cellValue = $this->extractCellRange($cellRef, $this->_workbook->getSheetByName($sheet1), FALSE);
3175
- } else {
3176
- return $this->_raiseFormulaError('Unable to access Cell Reference');
3177
- }
3178
- $stack->push('Cell Reference',$cellValue,$cellRef);
3179
- } else {
3180
- $stack->push('Error',PHPExcel_Calculation_Functions::REF(),NULL);
3181
- }
3182
-
3183
- break;
3184
- case '+' : // Addition
3185
- $this->_executeNumericBinaryOperation($cellID,$operand1,$operand2,$token,'plusEquals',$stack);
3186
- break;
3187
- case '-' : // Subtraction
3188
- $this->_executeNumericBinaryOperation($cellID,$operand1,$operand2,$token,'minusEquals',$stack);
3189
- break;
3190
- case '*' : // Multiplication
3191
- $this->_executeNumericBinaryOperation($cellID,$operand1,$operand2,$token,'arrayTimesEquals',$stack);
3192
- break;
3193
- case '/' : // Division
3194
- $this->_executeNumericBinaryOperation($cellID,$operand1,$operand2,$token,'arrayRightDivide',$stack);
3195
- break;
3196
- case '^' : // Exponential
3197
- $this->_executeNumericBinaryOperation($cellID,$operand1,$operand2,$token,'power',$stack);
3198
- break;
3199
- case '&' : // Concatenation
3200
- // If either of the operands is a matrix, we need to treat them both as matrices
3201
- // (converting the other operand to a matrix if need be); then perform the required
3202
- // matrix operation
3203
- if (is_bool($operand1)) {
3204
- $operand1 = ($operand1) ? self::$_localeBoolean['TRUE'] : self::$_localeBoolean['FALSE'];
3205
- }
3206
- if (is_bool($operand2)) {
3207
- $operand2 = ($operand2) ? self::$_localeBoolean['TRUE'] : self::$_localeBoolean['FALSE'];
3208
- }
3209
- if ((is_array($operand1)) || (is_array($operand2))) {
3210
- // Ensure that both operands are arrays/matrices
3211
- self::_checkMatrixOperands($operand1,$operand2,2);
3212
- try {
3213
- // Convert operand 1 from a PHP array to a matrix
3214
- $matrix = new PHPExcel_Shared_JAMA_Matrix($operand1);
3215
- // Perform the required operation against the operand 1 matrix, passing in operand 2
3216
- $matrixResult = $matrix->concat($operand2);
3217
- $result = $matrixResult->getArray();
3218
- } catch (PHPExcel_Exception $ex) {
3219
- $this->_debugLog->writeDebugLog('JAMA Matrix Exception: ', $ex->getMessage());
3220
- $result = '#VALUE!';
3221
- }
3222
- } else {
3223
- $result = '"'.str_replace('""','"',self::_unwrapResult($operand1,'"').self::_unwrapResult($operand2,'"')).'"';
3224
- }
3225
- $this->_debugLog->writeDebugLog('Evaluation Result is ', $this->_showTypeDetails($result));
3226
- $stack->push('Value',$result);
3227
- break;
3228
- case '|' : // Intersect
3229
- $rowIntersect = array_intersect_key($operand1,$operand2);
3230
- $cellIntersect = $oCol = $oRow = array();
3231
- foreach(array_keys($rowIntersect) as $row) {
3232
- $oRow[] = $row;
3233
- foreach($rowIntersect[$row] as $col => $data) {
3234
- $oCol[] = PHPExcel_Cell::columnIndexFromString($col) - 1;
3235
- $cellIntersect[$row] = array_intersect_key($operand1[$row],$operand2[$row]);
3236
- }
3237
- }
3238
- $cellRef = PHPExcel_Cell::stringFromColumnIndex(min($oCol)).min($oRow).':'.PHPExcel_Cell::stringFromColumnIndex(max($oCol)).max($oRow);
3239
- $this->_debugLog->writeDebugLog('Evaluation Result is ', $this->_showTypeDetails($cellIntersect));
3240
- $stack->push('Value',$cellIntersect,$cellRef);
3241
- break;
3242
- }
3243
-
3244
- // if the token is a unary operator, pop one value off the stack, do the operation, and push it back on
3245
- } elseif (($token === '~') || ($token === '%')) {
3246
- // echo 'Token is a unary operator<br />';
3247
- if (($arg = $stack->pop()) === NULL) return $this->_raiseFormulaError('Internal error - Operand value missing from stack');
3248
- $arg = $arg['value'];
3249
- if ($token === '~') {
3250
- // echo 'Token is a negation operator<br />';
3251
- $this->_debugLog->writeDebugLog('Evaluating Negation of ', $this->_showValue($arg));
3252
- $multiplier = -1;
3253
- } else {
3254
- // echo 'Token is a percentile operator<br />';
3255
- $this->_debugLog->writeDebugLog('Evaluating Percentile of ', $this->_showValue($arg));
3256
- $multiplier = 0.01;
3257
- }
3258
- if (is_array($arg)) {
3259
- self::_checkMatrixOperands($arg,$multiplier,2);
3260
- try {
3261
- $matrix1 = new PHPExcel_Shared_JAMA_Matrix($arg);
3262
- $matrixResult = $matrix1->arrayTimesEquals($multiplier);
3263
- $result = $matrixResult->getArray();
3264
- } catch (PHPExcel_Exception $ex) {
3265
- $this->_debugLog->writeDebugLog('JAMA Matrix Exception: ', $ex->getMessage());
3266
- $result = '#VALUE!';
3267
- }
3268
- $this->_debugLog->writeDebugLog('Evaluation Result is ', $this->_showTypeDetails($result));
3269
- $stack->push('Value',$result);
3270
- } else {
3271
- $this->_executeNumericBinaryOperation($cellID,$multiplier,$arg,'*','arrayTimesEquals',$stack);
3272
- }
3273
-
3274
- } elseif (preg_match('/^'.self::CALCULATION_REGEXP_CELLREF.'$/i', $token, $matches)) {
3275
- $cellRef = NULL;
3276
- // echo 'Element '.$token.' is a Cell reference<br />';
3277
- if (isset($matches[8])) {
3278
- // echo 'Reference is a Range of cells<br />';
3279
- if ($pCell === NULL) {
3280
- // We can't access the range, so return a REF error
3281
- $cellValue = PHPExcel_Calculation_Functions::REF();
3282
- } else {
3283
- $cellRef = $matches[6].$matches[7].':'.$matches[9].$matches[10];
3284
- if ($matches[2] > '') {
3285
- $matches[2] = trim($matches[2],"\"'");
3286
- if ((strpos($matches[2],'[') !== FALSE) || (strpos($matches[2],']') !== FALSE)) {
3287
- // It's a Reference to an external workbook (not currently supported)
3288
- return $this->_raiseFormulaError('Unable to access External Workbook');
3289
- }
3290
- $matches[2] = trim($matches[2],"\"'");
3291
- // echo '$cellRef='.$cellRef.' in worksheet '.$matches[2].'<br />';
3292
- $this->_debugLog->writeDebugLog('Evaluating Cell Range ', $cellRef, ' in worksheet ', $matches[2]);
3293
- if ($pCellParent !== NULL) {
3294
- $cellValue = $this->extractCellRange($cellRef, $this->_workbook->getSheetByName($matches[2]), FALSE);
3295
- } else {
3296
- return $this->_raiseFormulaError('Unable to access Cell Reference');
3297
- }
3298
- $this->_debugLog->writeDebugLog('Evaluation Result for cells ', $cellRef, ' in worksheet ', $matches[2], ' is ', $this->_showTypeDetails($cellValue));
3299
- // $cellRef = $matches[2].'!'.$cellRef;
3300
- } else {
3301
- // echo '$cellRef='.$cellRef.' in current worksheet<br />';
3302
- $this->_debugLog->writeDebugLog('Evaluating Cell Range ', $cellRef, ' in current worksheet');
3303
- if ($pCellParent !== NULL) {
3304
- $cellValue = $this->extractCellRange($cellRef, $pCellWorksheet, FALSE);
3305
- } else {
3306
- return $this->_raiseFormulaError('Unable to access Cell Reference');
3307
- }
3308
- $this->_debugLog->writeDebugLog('Evaluation Result for cells ', $cellRef, ' is ', $this->_showTypeDetails($cellValue));
3309
- }
3310
- }
3311
- } else {
3312
- // echo 'Reference is a single Cell<br />';
3313
- if ($pCell === NULL) {
3314
- // We can't access the cell, so return a REF error
3315
- $cellValue = PHPExcel_Calculation_Functions::REF();
3316
- } else {
3317
- $cellRef = $matches[6].$matches[7];
3318
- if ($matches[2] > '') {
3319
- $matches[2] = trim($matches[2],"\"'");
3320
- if ((strpos($matches[2],'[') !== FALSE) || (strpos($matches[2],']') !== FALSE)) {
3321
- // It's a Reference to an external workbook (not currently supported)
3322
- return $this->_raiseFormulaError('Unable to access External Workbook');
3323
- }
3324
- // echo '$cellRef='.$cellRef.' in worksheet '.$matches[2].'<br />';
3325
- $this->_debugLog->writeDebugLog('Evaluating Cell ', $cellRef, ' in worksheet ', $matches[2]);
3326
- if ($pCellParent !== NULL) {
3327
- $cellSheet = $this->_workbook->getSheetByName($matches[2]);
3328
- if ($cellSheet && $cellSheet->cellExists($cellRef)) {
3329
- $cellValue = $this->extractCellRange($cellRef, $this->_workbook->getSheetByName($matches[2]), FALSE);
3330
- $pCell->attach($pCellParent);
3331
- } else {
3332
- $cellValue = NULL;
3333
- }
3334
- } else {
3335
- return $this->_raiseFormulaError('Unable to access Cell Reference');
3336
- }
3337
- $this->_debugLog->writeDebugLog('Evaluation Result for cell ', $cellRef, ' in worksheet ', $matches[2], ' is ', $this->_showTypeDetails($cellValue));
3338
- // $cellRef = $matches[2].'!'.$cellRef;
3339
- } else {
3340
- // echo '$cellRef='.$cellRef.' in current worksheet<br />';
3341
- $this->_debugLog->writeDebugLog('Evaluating Cell ', $cellRef, ' in current worksheet');
3342
- if ($pCellParent->isDataSet($cellRef)) {
3343
- $cellValue = $this->extractCellRange($cellRef, $pCellWorksheet, FALSE);
3344
- $pCell->attach($pCellParent);
3345
- } else {
3346
- $cellValue = NULL;
3347
- }
3348
- $this->_debugLog->writeDebugLog('Evaluation Result for cell ', $cellRef, ' is ', $this->_showTypeDetails($cellValue));
3349
- }
3350
- }
3351
- }
3352
- $stack->push('Value',$cellValue,$cellRef);
3353
-
3354
- // if the token is a function, pop arguments off the stack, hand them to the function, and push the result back on
3355
- } elseif (preg_match('/^'.self::CALCULATION_REGEXP_FUNCTION.'$/i', $token, $matches)) {
3356
- // echo 'Token is a function<br />';
3357
- $functionName = $matches[1];
3358
- $argCount = $stack->pop();
3359
- $argCount = $argCount['value'];
3360
- if ($functionName != 'MKMATRIX') {
3361
- $this->_debugLog->writeDebugLog('Evaluating Function ', self::_localeFunc($functionName), '() with ', (($argCount == 0) ? 'no' : $argCount), ' argument', (($argCount == 1) ? '' : 's'));
3362
- }
3363
- if ((isset(self::$_PHPExcelFunctions[$functionName])) || (isset(self::$_controlFunctions[$functionName]))) { // function
3364
- if (isset(self::$_PHPExcelFunctions[$functionName])) {
3365
- $functionCall = self::$_PHPExcelFunctions[$functionName]['functionCall'];
3366
- $passByReference = isset(self::$_PHPExcelFunctions[$functionName]['passByReference']);
3367
- $passCellReference = isset(self::$_PHPExcelFunctions[$functionName]['passCellReference']);
3368
- } elseif (isset(self::$_controlFunctions[$functionName])) {
3369
- $functionCall = self::$_controlFunctions[$functionName]['functionCall'];
3370
- $passByReference = isset(self::$_controlFunctions[$functionName]['passByReference']);
3371
- $passCellReference = isset(self::$_controlFunctions[$functionName]['passCellReference']);
3372
- }
3373
- // get the arguments for this function
3374
- // echo 'Function '.$functionName.' expects '.$argCount.' arguments<br />';
3375
- $args = $argArrayVals = array();
3376
- for ($i = 0; $i < $argCount; ++$i) {
3377
- $arg = $stack->pop();
3378
- $a = $argCount - $i - 1;
3379
- if (($passByReference) &&
3380
- (isset(self::$_PHPExcelFunctions[$functionName]['passByReference'][$a])) &&
3381
- (self::$_PHPExcelFunctions[$functionName]['passByReference'][$a])) {
3382
- if ($arg['reference'] === NULL) {
3383
- $args[] = $cellID;
3384
- if ($functionName != 'MKMATRIX') { $argArrayVals[] = $this->_showValue($cellID); }
3385
- } else {
3386
- $args[] = $arg['reference'];
3387
- if ($functionName != 'MKMATRIX') { $argArrayVals[] = $this->_showValue($arg['reference']); }
3388
- }
3389
- } else {
3390
- $args[] = self::_unwrapResult($arg['value']);
3391
- if ($functionName != 'MKMATRIX') { $argArrayVals[] = $this->_showValue($arg['value']); }
3392
- }
3393
- }
3394
- // Reverse the order of the arguments
3395
- krsort($args);
3396
- if (($passByReference) && ($argCount == 0)) {
3397
- $args[] = $cellID;
3398
- $argArrayVals[] = $this->_showValue($cellID);
3399
- }
3400
- // echo 'Arguments are: ';
3401
- // print_r($args);
3402
- // echo '<br />';
3403
- if ($functionName != 'MKMATRIX') {
3404
- if ($this->_debugLog->getWriteDebugLog()) {
3405
- krsort($argArrayVals);
3406
- $this->_debugLog->writeDebugLog('Evaluating ', self::_localeFunc($functionName), '( ', implode(self::$_localeArgumentSeparator.' ',PHPExcel_Calculation_Functions::flattenArray($argArrayVals)), ' )');
3407
- }
3408
- }
3409
- // Process each argument in turn, building the return value as an array
3410
- // if (($argCount == 1) && (is_array($args[1])) && ($functionName != 'MKMATRIX')) {
3411
- // $operand1 = $args[1];
3412
- // $this->_debugLog->writeDebugLog('Argument is a matrix: ', $this->_showValue($operand1));
3413
- // $result = array();
3414
- // $row = 0;
3415
- // foreach($operand1 as $args) {
3416
- // if (is_array($args)) {
3417
- // foreach($args as $arg) {
3418
- // $this->_debugLog->writeDebugLog('Evaluating ', self::_localeFunc($functionName), '( ', $this->_showValue($arg), ' )');
3419
- // $r = call_user_func_array($functionCall,$arg);
3420
- // $this->_debugLog->writeDebugLog('Evaluation Result for ', self::_localeFunc($functionName), '() function call is ', $this->_showTypeDetails($r));
3421
- // $result[$row][] = $r;
3422
- // }
3423
- // ++$row;
3424
- // } else {
3425
- // $this->_debugLog->writeDebugLog('Evaluating ', self::_localeFunc($functionName), '( ', $this->_showValue($args), ' )');
3426
- // $r = call_user_func_array($functionCall,$args);
3427
- // $this->_debugLog->writeDebugLog('Evaluation Result for ', self::_localeFunc($functionName), '() function call is ', $this->_showTypeDetails($r));
3428
- // $result[] = $r;
3429
- // }
3430
- // }
3431
- // } else {
3432
- // Process the argument with the appropriate function call
3433
- if ($passCellReference) {
3434
- $args[] = $pCell;
3435
- }
3436
- if (strpos($functionCall,'::') !== FALSE) {
3437
- $result = call_user_func_array(explode('::',$functionCall),$args);
3438
- } else {
3439
- foreach($args as &$arg) {
3440
- $arg = PHPExcel_Calculation_Functions::flattenSingleValue($arg);
3441
- }
3442
- unset($arg);
3443
- $result = call_user_func_array($functionCall,$args);
3444
- }
3445
- // }
3446
- if ($functionName != 'MKMATRIX') {
3447
- $this->_debugLog->writeDebugLog('Evaluation Result for ', self::_localeFunc($functionName), '() function call is ', $this->_showTypeDetails($result));
3448
- }
3449
- $stack->push('Value',self::_wrapResult($result));
3450
- }
3451
-
3452
- } else {
3453
- // if the token is a number, boolean, string or an Excel error, push it onto the stack
3454
- if (isset(self::$_ExcelConstants[strtoupper($token)])) {
3455
- $excelConstant = strtoupper($token);
3456
- // echo 'Token is a PHPExcel constant: '.$excelConstant.'<br />';
3457
- $stack->push('Constant Value',self::$_ExcelConstants[$excelConstant]);
3458
- $this->_debugLog->writeDebugLog('Evaluating Constant ', $excelConstant, ' as ', $this->_showTypeDetails(self::$_ExcelConstants[$excelConstant]));
3459
- } elseif ((is_numeric($token)) || ($token === NULL) || (is_bool($token)) || ($token == '') || ($token{0} == '"') || ($token{0} == '#')) {
3460
- // echo 'Token is a number, boolean, string, null or an Excel error<br />';
3461
- $stack->push('Value',$token);
3462
- // if the token is a named range, push the named range name onto the stack
3463
- } elseif (preg_match('/^'.self::CALCULATION_REGEXP_NAMEDRANGE.'$/i', $token, $matches)) {
3464
- // echo 'Token is a named range<br />';
3465
- $namedRange = $matches[6];
3466
- // echo 'Named Range is '.$namedRange.'<br />';
3467
- $this->_debugLog->writeDebugLog('Evaluating Named Range ', $namedRange);
3468
- $cellValue = $this->extractNamedRange($namedRange, ((NULL !== $pCell) ? $pCellWorksheet : NULL), FALSE);
3469
- $pCell->attach($pCellParent);
3470
- $this->_debugLog->writeDebugLog('Evaluation Result for named range ', $namedRange, ' is ', $this->_showTypeDetails($cellValue));
3471
- $stack->push('Named Range',$cellValue,$namedRange);
3472
- } else {
3473
- return $this->_raiseFormulaError("undefined variable '$token'");
3474
- }
3475
- }
3476
- }
3477
- // when we're out of tokens, the stack should have a single element, the final result
3478
- if ($stack->count() != 1) return $this->_raiseFormulaError("internal error");
3479
- $output = $stack->pop();
3480
- $output = $output['value'];
3481
-
3482
- // if ((is_array($output)) && (self::$returnArrayAsType != self::RETURN_ARRAY_AS_ARRAY)) {
3483
- // return array_shift(PHPExcel_Calculation_Functions::flattenArray($output));
3484
- // }
3485
- return $output;
3486
- } // function _processTokenStack()
3487
-
3488
-
3489
- private function _validateBinaryOperand($cellID, &$operand, &$stack) {
3490
- if (is_array($operand)) {
3491
- if ((count($operand, COUNT_RECURSIVE) - count($operand)) == 1) {
3492
- do {
3493
- $operand = array_pop($operand);
3494
- } while (is_array($operand));
3495
- }
3496
- }
3497
- // Numbers, matrices and booleans can pass straight through, as they're already valid
3498
- if (is_string($operand)) {
3499
- // We only need special validations for the operand if it is a string
3500
- // Start by stripping off the quotation marks we use to identify true excel string values internally
3501
- if ($operand > '' && $operand{0} == '"') { $operand = self::_unwrapResult($operand); }
3502
- // If the string is a numeric value, we treat it as a numeric, so no further testing
3503
- if (!is_numeric($operand)) {
3504
- // If not a numeric, test to see if the value is an Excel error, and so can't be used in normal binary operations
3505
- if ($operand > '' && $operand{0} == '#') {
3506
- $stack->push('Value', $operand);
3507
- $this->_debugLog->writeDebugLog('Evaluation Result is ', $this->_showTypeDetails($operand));
3508
- return FALSE;
3509
- } elseif (!PHPExcel_Shared_String::convertToNumberIfFraction($operand)) {
3510
- // If not a numeric or a fraction, then it's a text string, and so can't be used in mathematical binary operations
3511
- $stack->push('Value', '#VALUE!');
3512
- $this->_debugLog->writeDebugLog('Evaluation Result is a ', $this->_showTypeDetails('#VALUE!'));
3513
- return FALSE;
3514
- }
3515
- }
3516
- }
3517
-
3518
- // return a true if the value of the operand is one that we can use in normal binary operations
3519
- return TRUE;
3520
- } // function _validateBinaryOperand()
3521
-
3522
-
3523
- private function _executeBinaryComparisonOperation($cellID, $operand1, $operand2, $operation, &$stack, $recursingArrays=FALSE) {
3524
- // If we're dealing with matrix operations, we want a matrix result
3525
- if ((is_array($operand1)) || (is_array($operand2))) {
3526
- $result = array();
3527
- if ((is_array($operand1)) && (!is_array($operand2))) {
3528
- foreach($operand1 as $x => $operandData) {
3529
- $this->_debugLog->writeDebugLog('Evaluating Comparison ', $this->_showValue($operandData), ' ', $operation, ' ', $this->_showValue($operand2));
3530
- $this->_executeBinaryComparisonOperation($cellID,$operandData,$operand2,$operation,$stack);
3531
- $r = $stack->pop();
3532
- $result[$x] = $r['value'];
3533
- }
3534
- } elseif ((!is_array($operand1)) && (is_array($operand2))) {
3535
- foreach($operand2 as $x => $operandData) {
3536
- $this->_debugLog->writeDebugLog('Evaluating Comparison ', $this->_showValue($operand1), ' ', $operation, ' ', $this->_showValue($operandData));
3537
- $this->_executeBinaryComparisonOperation($cellID,$operand1,$operandData,$operation,$stack);
3538
- $r = $stack->pop();
3539
- $result[$x] = $r['value'];
3540
- }
3541
- } else {
3542
- if (!$recursingArrays) { self::_checkMatrixOperands($operand1,$operand2,2); }
3543
- foreach($operand1 as $x => $operandData) {
3544
- $this->_debugLog->writeDebugLog('Evaluating Comparison ', $this->_showValue($operandData), ' ', $operation, ' ', $this->_showValue($operand2[$x]));
3545
- $this->_executeBinaryComparisonOperation($cellID,$operandData,$operand2[$x],$operation,$stack,TRUE);
3546
- $r = $stack->pop();
3547
- $result[$x] = $r['value'];
3548
- }
3549
- }
3550
- // Log the result details
3551
- $this->_debugLog->writeDebugLog('Comparison Evaluation Result is ', $this->_showTypeDetails($result));
3552
- // And push the result onto the stack
3553
- $stack->push('Array',$result);
3554
- return TRUE;
3555
- }
3556
-
3557
- // Simple validate the two operands if they are string values
3558
- if (is_string($operand1) && $operand1 > '' && $operand1{0} == '"') { $operand1 = self::_unwrapResult($operand1); }
3559
- if (is_string($operand2) && $operand2 > '' && $operand2{0} == '"') { $operand2 = self::_unwrapResult($operand2); }
3560
-
3561
- // Use case insensitive comparaison if not OpenOffice mode
3562
- if (PHPExcel_Calculation_Functions::getCompatibilityMode() != PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE)
3563
- {
3564
- if (is_string($operand1)) {
3565
- $operand1 = strtoupper($operand1);
3566
- }
3567
-
3568
- if (is_string($operand2)) {
3569
- $operand2 = strtoupper($operand2);
3570
- }
3571
- }
3572
-
3573
- $useLowercaseFirstComparison = is_string($operand1) && is_string($operand2) && PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE;
3574
-
3575
- // execute the necessary operation
3576
- switch ($operation) {
3577
- // Greater than
3578
- case '>':
3579
- if ($useLowercaseFirstComparison) {
3580
- $result = $this->strcmpLowercaseFirst($operand1, $operand2) > 0;
3581
- } else {
3582
- $result = ($operand1 > $operand2);
3583
- }
3584
- break;
3585
- // Less than
3586
- case '<':
3587
- if ($useLowercaseFirstComparison) {
3588
- $result = $this->strcmpLowercaseFirst($operand1, $operand2) < 0;
3589
- } else {
3590
- $result = ($operand1 < $operand2);
3591
- }
3592
- break;
3593
- // Equality
3594
- case '=':
3595
- $result = ($operand1 == $operand2);
3596
- break;
3597
- // Greater than or equal
3598
- case '>=':
3599
- if ($useLowercaseFirstComparison) {
3600
- $result = $this->strcmpLowercaseFirst($operand1, $operand2) >= 0;
3601
- } else {
3602
- $result = ($operand1 >= $operand2);
3603
- }
3604
- break;
3605
- // Less than or equal
3606
- case '<=':
3607
- if ($useLowercaseFirstComparison) {
3608
- $result = $this->strcmpLowercaseFirst($operand1, $operand2) <= 0;
3609
- } else {
3610
- $result = ($operand1 <= $operand2);
3611
- }
3612
- break;
3613
- // Inequality
3614
- case '<>':
3615
- $result = ($operand1 != $operand2);
3616
- break;
3617
- }
3618
-
3619
- // Log the result details
3620
- $this->_debugLog->writeDebugLog('Evaluation Result is ', $this->_showTypeDetails($result));
3621
- // And push the result onto the stack
3622
- $stack->push('Value',$result);
3623
- return TRUE;
3624
- } // function _executeBinaryComparisonOperation()
3625
-
3626
- /**
3627
- * Compare two strings in the same way as strcmp() except that lowercase come before uppercase letters
3628
- * @param string $str1
3629
- * @param string $str2
3630
- * @return integer
3631
- */
3632
- private function strcmpLowercaseFirst($str1, $str2)
3633
- {
3634
- $from = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
3635
- $to = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
3636
- $inversedStr1 = strtr($str1, $from, $to);
3637
- $inversedStr2 = strtr($str2, $from, $to);
3638
-
3639
- return strcmp($inversedStr1, $inversedStr2);
3640
- }
3641
-
3642
- private function _executeNumericBinaryOperation($cellID,$operand1,$operand2,$operation,$matrixFunction,&$stack) {
3643
- // Validate the two operands
3644
- if (!$this->_validateBinaryOperand($cellID,$operand1,$stack)) return FALSE;
3645
- if (!$this->_validateBinaryOperand($cellID,$operand2,$stack)) return FALSE;
3646
-
3647
- // If either of the operands is a matrix, we need to treat them both as matrices
3648
- // (converting the other operand to a matrix if need be); then perform the required
3649
- // matrix operation
3650
- if ((is_array($operand1)) || (is_array($operand2))) {
3651
- // Ensure that both operands are arrays/matrices of the same size
3652
- self::_checkMatrixOperands($operand1, $operand2, 2);
3653
-
3654
- try {
3655
- // Convert operand 1 from a PHP array to a matrix
3656
- $matrix = new PHPExcel_Shared_JAMA_Matrix($operand1);
3657
- // Perform the required operation against the operand 1 matrix, passing in operand 2
3658
- $matrixResult = $matrix->$matrixFunction($operand2);
3659
- $result = $matrixResult->getArray();
3660
- } catch (PHPExcel_Exception $ex) {
3661
- $this->_debugLog->writeDebugLog('JAMA Matrix Exception: ', $ex->getMessage());
3662
- $result = '#VALUE!';
3663
- }
3664
- } else {
3665
- if ((PHPExcel_Calculation_Functions::getCompatibilityMode() != PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) &&
3666
- ((is_string($operand1) && !is_numeric($operand1) && strlen($operand1)>0) ||
3667
- (is_string($operand2) && !is_numeric($operand2) && strlen($operand2)>0))) {
3668
- $result = PHPExcel_Calculation_Functions::VALUE();
3669
- } else {
3670
- // If we're dealing with non-matrix operations, execute the necessary operation
3671
- switch ($operation) {
3672
- // Addition
3673
- case '+':
3674
- $result = $operand1 + $operand2;
3675
- break;
3676
- // Subtraction
3677
- case '-':
3678
- $result = $operand1 - $operand2;
3679
- break;
3680
- // Multiplication
3681
- case '*':
3682
- $result = $operand1 * $operand2;
3683
- break;
3684
- // Division
3685
- case '/':
3686
- if ($operand2 == 0) {
3687
- // Trap for Divide by Zero error
3688
- $stack->push('Value','#DIV/0!');
3689
- $this->_debugLog->writeDebugLog('Evaluation Result is ', $this->_showTypeDetails('#DIV/0!'));
3690
- return FALSE;
3691
- } else {
3692
- $result = $operand1 / $operand2;
3693
- }
3694
- break;
3695
- // Power
3696
- case '^':
3697
- $result = pow($operand1, $operand2);
3698
- break;
3699
- }
3700
- }
3701
- }
3702
-
3703
- // Log the result details
3704
- $this->_debugLog->writeDebugLog('Evaluation Result is ', $this->_showTypeDetails($result));
3705
- // And push the result onto the stack
3706
- $stack->push('Value',$result);
3707
- return TRUE;
3708
- } // function _executeNumericBinaryOperation()
3709
-
3710
-
3711
- // trigger an error, but nicely, if need be
3712
- protected function _raiseFormulaError($errorMessage) {
3713
- $this->formulaError = $errorMessage;
3714
- $this->_cyclicReferenceStack->clear();
3715
- if (!$this->suppressFormulaErrors) throw new PHPExcel_Calculation_Exception($errorMessage);
3716
- trigger_error($errorMessage, E_USER_ERROR);
3717
- } // function _raiseFormulaError()
3718
-
3719
-
3720
- /**
3721
- * Extract range values
3722
- *
3723
- * @param string &$pRange String based range representation
3724
- * @param PHPExcel_Worksheet $pSheet Worksheet
3725
- * @param boolean $resetLog Flag indicating whether calculation log should be reset or not
3726
- * @return mixed Array of values in range if range contains more than one element. Otherwise, a single value is returned.
3727
- * @throws PHPExcel_Calculation_Exception
3728
- */
3729
- public function extractCellRange(&$pRange = 'A1', PHPExcel_Worksheet $pSheet = NULL, $resetLog = TRUE) {
3730
- // Return value
3731
- $returnValue = array ();
3732
-
3733
- // echo 'extractCellRange('.$pRange.')',PHP_EOL;
3734
- if ($pSheet !== NULL) {
3735
- $pSheetName = $pSheet->getTitle();
3736
- // echo 'Passed sheet name is '.$pSheetName.PHP_EOL;
3737
- // echo 'Range reference is '.$pRange.PHP_EOL;
3738
- if (strpos ($pRange, '!') !== false) {
3739
- // echo '$pRange reference includes sheet reference',PHP_EOL;
3740
- list($pSheetName,$pRange) = PHPExcel_Worksheet::extractSheetTitle($pRange, true);
3741
- // echo 'New sheet name is '.$pSheetName,PHP_EOL;
3742
- // echo 'Adjusted Range reference is '.$pRange,PHP_EOL;
3743
- $pSheet = $this->_workbook->getSheetByName($pSheetName);
3744
- }
3745
-
3746
- // Extract range
3747
- $aReferences = PHPExcel_Cell::extractAllCellReferencesInRange($pRange);
3748
- $pRange = $pSheetName.'!'.$pRange;
3749
- if (!isset($aReferences[1])) {
3750
- // Single cell in range
3751
- sscanf($aReferences[0],'%[A-Z]%d', $currentCol, $currentRow);
3752
- $cellValue = NULL;
3753
- if ($pSheet->cellExists($aReferences[0])) {
3754
- $returnValue[$currentRow][$currentCol] = $pSheet->getCell($aReferences[0])->getCalculatedValue($resetLog);
3755
- } else {
3756
- $returnValue[$currentRow][$currentCol] = NULL;
3757
- }
3758
- } else {
3759
- // Extract cell data for all cells in the range
3760
- foreach ($aReferences as $reference) {
3761
- // Extract range
3762
- sscanf($reference,'%[A-Z]%d', $currentCol, $currentRow);
3763
- $cellValue = NULL;
3764
- if ($pSheet->cellExists($reference)) {
3765
- $returnValue[$currentRow][$currentCol] = $pSheet->getCell($reference)->getCalculatedValue($resetLog);
3766
- } else {
3767
- $returnValue[$currentRow][$currentCol] = NULL;
3768
- }
3769
- }
3770
- }
3771
- }
3772
-
3773
- // Return
3774
- return $returnValue;
3775
- } // function extractCellRange()
3776
-
3777
-
3778
- /**
3779
- * Extract range values
3780
- *
3781
- * @param string &$pRange String based range representation
3782
- * @param PHPExcel_Worksheet $pSheet Worksheet
3783
- * @return mixed Array of values in range if range contains more than one element. Otherwise, a single value is returned.
3784
- * @param boolean $resetLog Flag indicating whether calculation log should be reset or not
3785
- * @throws PHPExcel_Calculation_Exception
3786
- */
3787
- public function extractNamedRange(&$pRange = 'A1', PHPExcel_Worksheet $pSheet = NULL, $resetLog = TRUE) {
3788
- // Return value
3789
- $returnValue = array ();
3790
-
3791
- // echo 'extractNamedRange('.$pRange.')<br />';
3792
- if ($pSheet !== NULL) {
3793
- $pSheetName = $pSheet->getTitle();
3794
- // echo 'Current sheet name is '.$pSheetName.'<br />';
3795
- // echo 'Range reference is '.$pRange.'<br />';
3796
- if (strpos ($pRange, '!') !== false) {
3797
- // echo '$pRange reference includes sheet reference',PHP_EOL;
3798
- list($pSheetName,$pRange) = PHPExcel_Worksheet::extractSheetTitle($pRange, true);
3799
- // echo 'New sheet name is '.$pSheetName,PHP_EOL;
3800
- // echo 'Adjusted Range reference is '.$pRange,PHP_EOL;
3801
- $pSheet = $this->_workbook->getSheetByName($pSheetName);
3802
- }
3803
-
3804
- // Named range?
3805
- $namedRange = PHPExcel_NamedRange::resolveRange($pRange, $pSheet);
3806
- if ($namedRange !== NULL) {
3807
- $pSheet = $namedRange->getWorksheet();
3808
- // echo 'Named Range '.$pRange.' (';
3809
- $pRange = $namedRange->getRange();
3810
- $splitRange = PHPExcel_Cell::splitRange($pRange);
3811
- // Convert row and column references
3812
- if (ctype_alpha($splitRange[0][0])) {
3813
- $pRange = $splitRange[0][0] . '1:' . $splitRange[0][1] . $namedRange->getWorksheet()->getHighestRow();
3814
- } elseif(ctype_digit($splitRange[0][0])) {
3815
- $pRange = 'A' . $splitRange[0][0] . ':' . $namedRange->getWorksheet()->getHighestColumn() . $splitRange[0][1];
3816
- }
3817
- // echo $pRange.') is in sheet '.$namedRange->getWorksheet()->getTitle().'<br />';
3818
-
3819
- // if ($pSheet->getTitle() != $namedRange->getWorksheet()->getTitle()) {
3820
- // if (!$namedRange->getLocalOnly()) {
3821
- // $pSheet = $namedRange->getWorksheet();
3822
- // } else {
3823
- // return $returnValue;
3824
- // }
3825
- // }
3826
- } else {
3827
- return PHPExcel_Calculation_Functions::REF();
3828
- }
3829
-
3830
- // Extract range
3831
- $aReferences = PHPExcel_Cell::extractAllCellReferencesInRange($pRange);
3832
- // var_dump($aReferences);
3833
- if (!isset($aReferences[1])) {
3834
- // Single cell (or single column or row) in range
3835
- list($currentCol,$currentRow) = PHPExcel_Cell::coordinateFromString($aReferences[0]);
3836
- $cellValue = NULL;
3837
- if ($pSheet->cellExists($aReferences[0])) {
3838
- $returnValue[$currentRow][$currentCol] = $pSheet->getCell($aReferences[0])->getCalculatedValue($resetLog);
3839
- } else {
3840
- $returnValue[$currentRow][$currentCol] = NULL;
3841
- }
3842
- } else {
3843
- // Extract cell data for all cells in the range
3844
- foreach ($aReferences as $reference) {
3845
- // Extract range
3846
- list($currentCol,$currentRow) = PHPExcel_Cell::coordinateFromString($reference);
3847
- // echo 'NAMED RANGE: $currentCol='.$currentCol.' $currentRow='.$currentRow.'<br />';
3848
- $cellValue = NULL;
3849
- if ($pSheet->cellExists($reference)) {
3850
- $returnValue[$currentRow][$currentCol] = $pSheet->getCell($reference)->getCalculatedValue($resetLog);
3851
- } else {
3852
- $returnValue[$currentRow][$currentCol] = NULL;
3853
- }
3854
- }
3855
- }
3856
- // print_r($returnValue);
3857
- // echo '<br />';
3858
- }
3859
-
3860
- // Return
3861
- return $returnValue;
3862
- } // function extractNamedRange()
3863
-
3864
-
3865
- /**
3866
- * Is a specific function implemented?
3867
- *
3868
- * @param string $pFunction Function Name
3869
- * @return boolean
3870
- */
3871
- public function isImplemented($pFunction = '') {
3872
- $pFunction = strtoupper ($pFunction);
3873
- if (isset(self::$_PHPExcelFunctions[$pFunction])) {
3874
- return (self::$_PHPExcelFunctions[$pFunction]['functionCall'] != 'PHPExcel_Calculation_Functions::DUMMY');
3875
- } else {
3876
- return FALSE;
3877
- }
3878
- } // function isImplemented()
3879
-
3880
-
3881
- /**
3882
- * Get a list of all implemented functions as an array of function objects
3883
- *
3884
- * @return array of PHPExcel_Calculation_Function
3885
- */
3886
- public function listFunctions() {
3887
- // Return value
3888
- $returnValue = array();
3889
- // Loop functions
3890
- foreach(self::$_PHPExcelFunctions as $functionName => $function) {
3891
- if ($function['functionCall'] != 'PHPExcel_Calculation_Functions::DUMMY') {
3892
- $returnValue[$functionName] = new PHPExcel_Calculation_Function($function['category'],
3893
- $functionName,
3894
- $function['functionCall']
3895
- );
3896
- }
3897
- }
3898
-
3899
- // Return
3900
- return $returnValue;
3901
- } // function listFunctions()
3902
-
3903
-
3904
- /**
3905
- * Get a list of all Excel function names
3906
- *
3907
- * @return array
3908
- */
3909
- public function listAllFunctionNames() {
3910
- return array_keys(self::$_PHPExcelFunctions);
3911
- } // function listAllFunctionNames()
3912
-
3913
- /**
3914
- * Get a list of implemented Excel function names
3915
- *
3916
- * @return array
3917
- */
3918
- public function listFunctionNames() {
3919
- // Return value
3920
- $returnValue = array();
3921
- // Loop functions
3922
- foreach(self::$_PHPExcelFunctions as $functionName => $function) {
3923
- if ($function['functionCall'] != 'PHPExcel_Calculation_Functions::DUMMY') {
3924
- $returnValue[] = $functionName;
3925
- }
3926
- }
3927
-
3928
- // Return
3929
- return $returnValue;
3930
- } // function listFunctionNames()
3931
-
3932
- } // class PHPExcel_Calculation
3933
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /** PHPExcel root directory */
4
+ if (!defined('PHPEXCEL_ROOT')) {
5
+ /**
6
+ * @ignore
7
+ */
8
+ define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../');
9
+ require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
10
+ }
11
+
12
+ if (!defined('CALCULATION_REGEXP_CELLREF')) {
13
+ // Test for support of \P (multibyte options) in PCRE
14
+ if (defined('PREG_BAD_UTF8_ERROR')) {
15
+ // Cell reference (cell or range of cells, with or without a sheet reference)
16
+ define('CALCULATION_REGEXP_CELLREF', '((([^\s,!&%^\/\*\+<>=-]*)|(\'[^\']*\')|(\"[^\"]*\"))!)?\$?([a-z]{1,3})\$?(\d{1,7})');
17
+ // Named Range of cells
18
+ define('CALCULATION_REGEXP_NAMEDRANGE', '((([^\s,!&%^\/\*\+<>=-]*)|(\'[^\']*\')|(\"[^\"]*\"))!)?([_A-Z][_A-Z0-9\.]*)');
19
+ } else {
20
+ // Cell reference (cell or range of cells, with or without a sheet reference)
21
+ define('CALCULATION_REGEXP_CELLREF', '(((\w*)|(\'[^\']*\')|(\"[^\"]*\"))!)?\$?([a-z]{1,3})\$?(\d+)');
22
+ // Named Range of cells
23
+ define('CALCULATION_REGEXP_NAMEDRANGE', '(((\w*)|(\'.*\')|(\".*\"))!)?([_A-Z][_A-Z0-9\.]*)');
24
+ }
25
+ }
26
+
27
+ /**
28
+ * PHPExcel_Calculation (Multiton)
29
+ *
30
+ * Copyright (c) 2006 - 2015 PHPExcel
31
+ *
32
+ * This library is free software; you can redistribute it and/or
33
+ * modify it under the terms of the GNU Lesser General Public
34
+ * License as published by the Free Software Foundation; either
35
+ * version 2.1 of the License, or (at your option) any later version.
36
+ *
37
+ * This library is distributed in the hope that it will be useful,
38
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
39
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
40
+ * Lesser General Public License for more details.
41
+ *
42
+ * You should have received a copy of the GNU Lesser General Public
43
+ * License along with this library; if not, write to the Free Software
44
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
45
+ *
46
+ * @category PHPExcel
47
+ * @package PHPExcel_Calculation
48
+ * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
49
+ * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
50
+ * @version ##VERSION##, ##DATE##
51
+ */
52
+ class PHPExcel_Calculation
53
+ {
54
+ /** Constants */
55
+ /** Regular Expressions */
56
+ // Numeric operand
57
+ const CALCULATION_REGEXP_NUMBER = '[-+]?\d*\.?\d+(e[-+]?\d+)?';
58
+ // String operand
59
+ const CALCULATION_REGEXP_STRING = '"(?:[^"]|"")*"';
60
+ // Opening bracket
61
+ const CALCULATION_REGEXP_OPENBRACE = '\(';
62
+ // Function (allow for the old @ symbol that could be used to prefix a function, but we'll ignore it)
63
+ const CALCULATION_REGEXP_FUNCTION = '@?([A-Z][A-Z0-9\.]*)[\s]*\(';
64
+ // Cell reference (cell or range of cells, with or without a sheet reference)
65
+ const CALCULATION_REGEXP_CELLREF = CALCULATION_REGEXP_CELLREF;
66
+ // Named Range of cells
67
+ const CALCULATION_REGEXP_NAMEDRANGE = CALCULATION_REGEXP_NAMEDRANGE;
68
+ // Error
69
+ const CALCULATION_REGEXP_ERROR = '\#[A-Z][A-Z0_\/]*[!\?]?';
70
+
71
+
72
+ /** constants */
73
+ const RETURN_ARRAY_AS_ERROR = 'error';
74
+ const RETURN_ARRAY_AS_VALUE = 'value';
75
+ const RETURN_ARRAY_AS_ARRAY = 'array';
76
+
77
+ private static $returnArrayAsType = self::RETURN_ARRAY_AS_VALUE;
78
+
79
+
80
+ /**
81
+ * Instance of this class
82
+ *
83
+ * @access private
84
+ * @var PHPExcel_Calculation
85
+ */
86
+ private static $instance;
87
+
88
+
89
+ /**
90
+ * Instance of the workbook this Calculation Engine is using
91
+ *
92
+ * @access private
93
+ * @var PHPExcel
94
+ */
95
+ private $workbook;
96
+
97
+ /**
98
+ * List of instances of the calculation engine that we've instantiated for individual workbooks
99
+ *
100
+ * @access private
101
+ * @var PHPExcel_Calculation[]
102
+ */
103
+ private static $workbookSets;
104
+
105
+ /**
106
+ * Calculation cache
107
+ *
108
+ * @access private
109
+ * @var array
110
+ */
111
+ private $calculationCache = array ();
112
+
113
+
114
+ /**
115
+ * Calculation cache enabled
116
+ *
117
+ * @access private
118
+ * @var boolean
119
+ */
120
+ private $calculationCacheEnabled = true;
121
+
122
+
123
+ /**
124
+ * List of operators that can be used within formulae
125
+ * The true/false value indicates whether it is a binary operator or a unary operator
126
+ *
127
+ * @access private
128
+ * @var array
129
+ */
130
+ private static $operators = array(
131
+ '+' => true, '-' => true, '*' => true, '/' => true,
132
+ '^' => true, '&' => true, '%' => false, '~' => false,
133
+ '>' => true, '<' => true, '=' => true, '>=' => true,
134
+ '<=' => true, '<>' => true, '|' => true, ':' => true
135
+ );
136
+
137
+ /**
138
+ * List of binary operators (those that expect two operands)
139
+ *
140
+ * @access private
141
+ * @var array
142
+ */
143
+ private static $binaryOperators = array(
144
+ '+' => true, '-' => true, '*' => true, '/' => true,
145
+ '^' => true, '&' => true, '>' => true, '<' => true,
146
+ '=' => true, '>=' => true, '<=' => true, '<>' => true,
147
+ '|' => true, ':' => true
148
+ );
149
+
150
+ /**
151
+ * The debug log generated by the calculation engine
152
+ *
153
+ * @access private
154
+ * @var PHPExcel_CalcEngine_Logger
155
+ *
156
+ */
157
+ private $debugLog;
158
+
159
+ /**
160
+ * Flag to determine how formula errors should be handled
161
+ * If true, then a user error will be triggered
162
+ * If false, then an exception will be thrown
163
+ *
164
+ * @access public
165
+ * @var boolean
166
+ *
167
+ */
168
+ public $suppressFormulaErrors = false;
169
+
170
+ /**
171
+ * Error message for any error that was raised/thrown by the calculation engine
172
+ *
173
+ * @access public
174
+ * @var string
175
+ *
176
+ */
177
+ public $formulaError = null;
178
+
179
+ /**
180
+ * An array of the nested cell references accessed by the calculation engine, used for the debug log
181
+ *
182
+ * @access private
183
+ * @var array of string
184
+ *
185
+ */
186
+ private $cyclicReferenceStack;
187
+
188
+ private $cellStack = array();
189
+
190
+ /**
191
+ * Current iteration counter for cyclic formulae
192
+ * If the value is 0 (or less) then cyclic formulae will throw an exception,
193
+ * otherwise they will iterate to the limit defined here before returning a result
194
+ *
195
+ * @var integer
196
+ *
197
+ */
198
+ private $cyclicFormulaCounter = 1;
199
+
200
+ private $cyclicFormulaCell = '';
201
+
202
+ /**
203
+ * Number of iterations for cyclic formulae
204
+ *
205
+ * @var integer
206
+ *
207
+ */
208
+ public $cyclicFormulaCount = 1;
209
+
210
+ /**
211
+ * Epsilon Precision used for comparisons in calculations
212
+ *
213
+ * @var float
214
+ *
215
+ */
216
+ private $delta = 0.1e-12;
217
+
218
+
219
+ /**
220
+ * The current locale setting
221
+ *
222
+ * @var string
223
+ *
224
+ */
225
+ private static $localeLanguage = 'en_us'; // US English (default locale)
226
+
227
+ /**
228
+ * List of available locale settings
229
+ * Note that this is read for the locale subdirectory only when requested
230
+ *
231
+ * @var string[]
232
+ *
233
+ */
234
+ private static $validLocaleLanguages = array(
235
+ 'en' // English (default language)
236
+ );
237
+
238
+ /**
239
+ * Locale-specific argument separator for function arguments
240
+ *
241
+ * @var string
242
+ *
243
+ */
244
+ private static $localeArgumentSeparator = ',';
245
+ private static $localeFunctions = array();
246
+
247
+ /**
248
+ * Locale-specific translations for Excel constants (True, False and Null)
249
+ *
250
+ * @var string[]
251
+ *
252
+ */
253
+ public static $localeBoolean = array(
254
+ 'TRUE' => 'TRUE',
255
+ 'FALSE' => 'FALSE',
256
+ 'NULL' => 'NULL'
257
+ );
258
+
259
+ /**
260
+ * Excel constant string translations to their PHP equivalents
261
+ * Constant conversion from text name/value to actual (datatyped) value
262
+ *
263
+ * @var string[]
264
+ *
265
+ */
266
+ private static $excelConstants = array(
267
+ 'TRUE' => true,
268
+ 'FALSE' => false,
269
+ 'NULL' => null
270
+ );
271
+
272
+ // PHPExcel functions
273
+ private static $PHPExcelFunctions = array(
274
+ 'ABS' => array(
275
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
276
+ 'functionCall' => 'abs',
277
+ 'argumentCount' => '1'
278
+ ),
279
+ 'ACCRINT' => array(
280
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
281
+ 'functionCall' => 'PHPExcel_Calculation_Financial::ACCRINT',
282
+ 'argumentCount' => '4-7'
283
+ ),
284
+ 'ACCRINTM' => array(
285
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
286
+ 'functionCall' => 'PHPExcel_Calculation_Financial::ACCRINTM',
287
+ 'argumentCount' => '3-5'
288
+ ),
289
+ 'ACOS' => array(
290
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
291
+ 'functionCall' => 'acos',
292
+ 'argumentCount' => '1'
293
+ ),
294
+ 'ACOSH' => array(
295
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
296
+ 'functionCall' => 'acosh',
297
+ 'argumentCount' => '1'
298
+ ),
299
+ 'ADDRESS' => array(
300
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
301
+ 'functionCall' => 'PHPExcel_Calculation_LookupRef::CELL_ADDRESS',
302
+ 'argumentCount' => '2-5'
303
+ ),
304
+ 'AMORDEGRC' => array(
305
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
306
+ 'functionCall' => 'PHPExcel_Calculation_Financial::AMORDEGRC',
307
+ 'argumentCount' => '6,7'
308
+ ),
309
+ 'AMORLINC' => array(
310
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
311
+ 'functionCall' => 'PHPExcel_Calculation_Financial::AMORLINC',
312
+ 'argumentCount' => '6,7'
313
+ ),
314
+ 'AND' => array(
315
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_LOGICAL,
316
+ 'functionCall' => 'PHPExcel_Calculation_Logical::LOGICAL_AND',
317
+ 'argumentCount' => '1+'
318
+ ),
319
+ 'AREAS' => array(
320
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
321
+ 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
322
+ 'argumentCount' => '1'
323
+ ),
324
+ 'ASC' => array(
325
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
326
+ 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
327
+ 'argumentCount' => '1'
328
+ ),
329
+ 'ASIN' => array(
330
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
331
+ 'functionCall' => 'asin',
332
+ 'argumentCount' => '1'
333
+ ),
334
+ 'ASINH' => array(
335
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
336
+ 'functionCall' => 'asinh',
337
+ 'argumentCount' => '1'
338
+ ),
339
+ 'ATAN' => array(
340
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
341
+ 'functionCall' => 'atan',
342
+ 'argumentCount' => '1'
343
+ ),
344
+ 'ATAN2' => array(
345
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
346
+ 'functionCall' => 'PHPExcel_Calculation_MathTrig::ATAN2',
347
+ 'argumentCount' => '2'
348
+ ),
349
+ 'ATANH' => array(
350
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
351
+ 'functionCall' => 'atanh',
352
+ 'argumentCount' => '1'
353
+ ),
354
+ 'AVEDEV' => array(
355
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
356
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::AVEDEV',
357
+ 'argumentCount' => '1+'
358
+ ),
359
+ 'AVERAGE' => array(
360
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
361
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::AVERAGE',
362
+ 'argumentCount' => '1+'
363
+ ),
364
+ 'AVERAGEA' => array(
365
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
366
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::AVERAGEA',
367
+ 'argumentCount' => '1+'
368
+ ),
369
+ 'AVERAGEIF' => array(
370
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
371
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::AVERAGEIF',
372
+ 'argumentCount' => '2,3'
373
+ ),
374
+ 'AVERAGEIFS' => array(
375
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
376
+ 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
377
+ 'argumentCount' => '3+'
378
+ ),
379
+ 'BAHTTEXT' => array(
380
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
381
+ 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
382
+ 'argumentCount' => '1'
383
+ ),
384
+ 'BESSELI' => array(
385
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
386
+ 'functionCall' => 'PHPExcel_Calculation_Engineering::BESSELI',
387
+ 'argumentCount' => '2'
388
+ ),
389
+ 'BESSELJ' => array(
390
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
391
+ 'functionCall' => 'PHPExcel_Calculation_Engineering::BESSELJ',
392
+ 'argumentCount' => '2'
393
+ ),
394
+ 'BESSELK' => array(
395
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
396
+ 'functionCall' => 'PHPExcel_Calculation_Engineering::BESSELK',
397
+ 'argumentCount' => '2'
398
+ ),
399
+ 'BESSELY' => array(
400
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
401
+ 'functionCall' => 'PHPExcel_Calculation_Engineering::BESSELY',
402
+ 'argumentCount' => '2'
403
+ ),
404
+ 'BETADIST' => array(
405
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
406
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::BETADIST',
407
+ 'argumentCount' => '3-5'
408
+ ),
409
+ 'BETAINV' => array(
410
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
411
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::BETAINV',
412
+ 'argumentCount' => '3-5'
413
+ ),
414
+ 'BIN2DEC' => array(
415
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
416
+ 'functionCall' => 'PHPExcel_Calculation_Engineering::BINTODEC',
417
+ 'argumentCount' => '1'
418
+ ),
419
+ 'BIN2HEX' => array(
420
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
421
+ 'functionCall' => 'PHPExcel_Calculation_Engineering::BINTOHEX',
422
+ 'argumentCount' => '1,2'
423
+ ),
424
+ 'BIN2OCT' => array(
425
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
426
+ 'functionCall' => 'PHPExcel_Calculation_Engineering::BINTOOCT',
427
+ 'argumentCount' => '1,2'
428
+ ),
429
+ 'BINOMDIST' => array(
430
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
431
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::BINOMDIST',
432
+ 'argumentCount' => '4'
433
+ ),
434
+ 'CEILING' => array(
435
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
436
+ 'functionCall' => 'PHPExcel_Calculation_MathTrig::CEILING',
437
+ 'argumentCount' => '2'
438
+ ),
439
+ 'CELL' => array(
440
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
441
+ 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
442
+ 'argumentCount' => '1,2'
443
+ ),
444
+ 'CHAR' => array(
445
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
446
+ 'functionCall' => 'PHPExcel_Calculation_TextData::CHARACTER',
447
+ 'argumentCount' => '1'
448
+ ),
449
+ 'CHIDIST' => array(
450
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
451
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::CHIDIST',
452
+ 'argumentCount' => '2'
453
+ ),
454
+ 'CHIINV' => array(
455
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
456
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::CHIINV',
457
+ 'argumentCount' => '2'
458
+ ),
459
+ 'CHITEST' => array(
460
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
461
+ 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
462
+ 'argumentCount' => '2'
463
+ ),
464
+ 'CHOOSE' => array(
465
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
466
+ 'functionCall' => 'PHPExcel_Calculation_LookupRef::CHOOSE',
467
+ 'argumentCount' => '2+'
468
+ ),
469
+ 'CLEAN' => array(
470
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
471
+ 'functionCall' => 'PHPExcel_Calculation_TextData::TRIMNONPRINTABLE',
472
+ 'argumentCount' => '1'
473
+ ),
474
+ 'CODE' => array(
475
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
476
+ 'functionCall' => 'PHPExcel_Calculation_TextData::ASCIICODE',
477
+ 'argumentCount' => '1'
478
+ ),
479
+ 'COLUMN' => array(
480
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
481
+ 'functionCall' => 'PHPExcel_Calculation_LookupRef::COLUMN',
482
+ 'argumentCount' => '-1',
483
+ 'passByReference' => array(true)
484
+ ),
485
+ 'COLUMNS' => array(
486
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
487
+ 'functionCall' => 'PHPExcel_Calculation_LookupRef::COLUMNS',
488
+ 'argumentCount' => '1'
489
+ ),
490
+ 'COMBIN' => array(
491
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
492
+ 'functionCall' => 'PHPExcel_Calculation_MathTrig::COMBIN',
493
+ 'argumentCount' => '2'
494
+ ),
495
+ 'COMPLEX' => array(
496
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
497
+ 'functionCall' => 'PHPExcel_Calculation_Engineering::COMPLEX',
498
+ 'argumentCount' => '2,3'
499
+ ),
500
+ 'CONCATENATE' => array(
501
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
502
+ 'functionCall' => 'PHPExcel_Calculation_TextData::CONCATENATE',
503
+ 'argumentCount' => '1+'
504
+ ),
505
+ 'CONFIDENCE' => array(
506
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
507
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::CONFIDENCE',
508
+ 'argumentCount' => '3'
509
+ ),
510
+ 'CONVERT' => array(
511
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
512
+ 'functionCall' => 'PHPExcel_Calculation_Engineering::CONVERTUOM',
513
+ 'argumentCount' => '3'
514
+ ),
515
+ 'CORREL' => array(
516
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
517
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::CORREL',
518
+ 'argumentCount' => '2'
519
+ ),
520
+ 'COS' => array(
521
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
522
+ 'functionCall' => 'cos',
523
+ 'argumentCount' => '1'
524
+ ),
525
+ 'COSH' => array(
526
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
527
+ 'functionCall' => 'cosh',
528
+ 'argumentCount' => '1'
529
+ ),
530
+ 'COUNT' => array(
531
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
532
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::COUNT',
533
+ 'argumentCount' => '1+'
534
+ ),
535
+ 'COUNTA' => array(
536
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
537
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::COUNTA',
538
+ 'argumentCount' => '1+'
539
+ ),
540
+ 'COUNTBLANK' => array(
541
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
542
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::COUNTBLANK',
543
+ 'argumentCount' => '1'
544
+ ),
545
+ 'COUNTIF' => array(
546
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
547
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::COUNTIF',
548
+ 'argumentCount' => '2'
549
+ ),
550
+ 'COUNTIFS' => array(
551
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
552
+ 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
553
+ 'argumentCount' => '2'
554
+ ),
555
+ 'COUPDAYBS' => array(
556
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
557
+ 'functionCall' => 'PHPExcel_Calculation_Financial::COUPDAYBS',
558
+ 'argumentCount' => '3,4'
559
+ ),
560
+ 'COUPDAYS' => array(
561
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
562
+ 'functionCall' => 'PHPExcel_Calculation_Financial::COUPDAYS',
563
+ 'argumentCount' => '3,4'
564
+ ),
565
+ 'COUPDAYSNC' => array(
566
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
567
+ 'functionCall' => 'PHPExcel_Calculation_Financial::COUPDAYSNC',
568
+ 'argumentCount' => '3,4'
569
+ ),
570
+ 'COUPNCD' => array(
571
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
572
+ 'functionCall' => 'PHPExcel_Calculation_Financial::COUPNCD',
573
+ 'argumentCount' => '3,4'
574
+ ),
575
+ 'COUPNUM' => array(
576
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
577
+ 'functionCall' => 'PHPExcel_Calculation_Financial::COUPNUM',
578
+ 'argumentCount' => '3,4'
579
+ ),
580
+ 'COUPPCD' => array(
581
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
582
+ 'functionCall' => 'PHPExcel_Calculation_Financial::COUPPCD',
583
+ 'argumentCount' => '3,4'
584
+ ),
585
+ 'COVAR' => array(
586
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
587
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::COVAR',
588
+ 'argumentCount' => '2'
589
+ ),
590
+ 'CRITBINOM' => array(
591
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
592
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::CRITBINOM',
593
+ 'argumentCount' => '3'
594
+ ),
595
+ 'CUBEKPIMEMBER' => array(
596
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_CUBE,
597
+ 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
598
+ 'argumentCount' => '?'
599
+ ),
600
+ 'CUBEMEMBER' => array(
601
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_CUBE,
602
+ 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
603
+ 'argumentCount' => '?'
604
+ ),
605
+ 'CUBEMEMBERPROPERTY' => array(
606
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_CUBE,
607
+ 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
608
+ 'argumentCount' => '?'
609
+ ),
610
+ 'CUBERANKEDMEMBER' => array(
611
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_CUBE,
612
+ 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
613
+ 'argumentCount' => '?'
614
+ ),
615
+ 'CUBESET' => array(
616
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_CUBE,
617
+ 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
618
+ 'argumentCount' => '?'
619
+ ),
620
+ 'CUBESETCOUNT' => array(
621
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_CUBE,
622
+ 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
623
+ 'argumentCount' => '?'
624
+ ),
625
+ 'CUBEVALUE' => array(
626
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_CUBE,
627
+ 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
628
+ 'argumentCount' => '?'
629
+ ),
630
+ 'CUMIPMT' => array(
631
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
632
+ 'functionCall' => 'PHPExcel_Calculation_Financial::CUMIPMT',
633
+ 'argumentCount' => '6'
634
+ ),
635
+ 'CUMPRINC' => array(
636
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
637
+ 'functionCall' => 'PHPExcel_Calculation_Financial::CUMPRINC',
638
+ 'argumentCount' => '6'
639
+ ),
640
+ 'DATE' => array(
641
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
642
+ 'functionCall' => 'PHPExcel_Calculation_DateTime::DATE',
643
+ 'argumentCount' => '3'
644
+ ),
645
+ 'DATEDIF' => array(
646
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
647
+ 'functionCall' => 'PHPExcel_Calculation_DateTime::DATEDIF',
648
+ 'argumentCount' => '2,3'
649
+ ),
650
+ 'DATEVALUE' => array(
651
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
652
+ 'functionCall' => 'PHPExcel_Calculation_DateTime::DATEVALUE',
653
+ 'argumentCount' => '1'
654
+ ),
655
+ 'DAVERAGE' => array(
656
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_DATABASE,
657
+ 'functionCall' => 'PHPExcel_Calculation_Database::DAVERAGE',
658
+ 'argumentCount' => '3'
659
+ ),
660
+ 'DAY' => array(
661
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
662
+ 'functionCall' => 'PHPExcel_Calculation_DateTime::DAYOFMONTH',
663
+ 'argumentCount' => '1'
664
+ ),
665
+ 'DAYS360' => array(
666
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
667
+ 'functionCall' => 'PHPExcel_Calculation_DateTime::DAYS360',
668
+ 'argumentCount' => '2,3'
669
+ ),
670
+ 'DB' => array(
671
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
672
+ 'functionCall' => 'PHPExcel_Calculation_Financial::DB',
673
+ 'argumentCount' => '4,5'
674
+ ),
675
+ 'DCOUNT' => array(
676
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_DATABASE,
677
+ 'functionCall' => 'PHPExcel_Calculation_Database::DCOUNT',
678
+ 'argumentCount' => '3'
679
+ ),
680
+ 'DCOUNTA' => array(
681
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_DATABASE,
682
+ 'functionCall' => 'PHPExcel_Calculation_Database::DCOUNTA',
683
+ 'argumentCount' => '3'
684
+ ),
685
+ 'DDB' => array(
686
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
687
+ 'functionCall' => 'PHPExcel_Calculation_Financial::DDB',
688
+ 'argumentCount' => '4,5'
689
+ ),
690
+ 'DEC2BIN' => array(
691
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
692
+ 'functionCall' => 'PHPExcel_Calculation_Engineering::DECTOBIN',
693
+ 'argumentCount' => '1,2'
694
+ ),
695
+ 'DEC2HEX' => array(
696
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
697
+ 'functionCall' => 'PHPExcel_Calculation_Engineering::DECTOHEX',
698
+ 'argumentCount' => '1,2'
699
+ ),
700
+ 'DEC2OCT' => array(
701
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
702
+ 'functionCall' => 'PHPExcel_Calculation_Engineering::DECTOOCT',
703
+ 'argumentCount' => '1,2'
704
+ ),
705
+ 'DEGREES' => array(
706
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
707
+ 'functionCall' => 'rad2deg',
708
+ 'argumentCount' => '1'
709
+ ),
710
+ 'DELTA' => array(
711
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
712
+ 'functionCall' => 'PHPExcel_Calculation_Engineering::DELTA',
713
+ 'argumentCount' => '1,2'
714
+ ),
715
+ 'DEVSQ' => array(
716
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
717
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::DEVSQ',
718
+ 'argumentCount' => '1+'
719
+ ),
720
+ 'DGET' => array(
721
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_DATABASE,
722
+ 'functionCall' => 'PHPExcel_Calculation_Database::DGET',
723
+ 'argumentCount' => '3'
724
+ ),
725
+ 'DISC' => array(
726
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
727
+ 'functionCall' => 'PHPExcel_Calculation_Financial::DISC',
728
+ 'argumentCount' => '4,5'
729
+ ),
730
+ 'DMAX' => array(
731
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_DATABASE,
732
+ 'functionCall' => 'PHPExcel_Calculation_Database::DMAX',
733
+ 'argumentCount' => '3'
734
+ ),
735
+ 'DMIN' => array(
736
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_DATABASE,
737
+ 'functionCall' => 'PHPExcel_Calculation_Database::DMIN',
738
+ 'argumentCount' => '3'
739
+ ),
740
+ 'DOLLAR' => array(
741
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
742
+ 'functionCall' => 'PHPExcel_Calculation_TextData::DOLLAR',
743
+ 'argumentCount' => '1,2'
744
+ ),
745
+ 'DOLLARDE' => array(
746
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
747
+ 'functionCall' => 'PHPExcel_Calculation_Financial::DOLLARDE',
748
+ 'argumentCount' => '2'
749
+ ),
750
+ 'DOLLARFR' => array(
751
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
752
+ 'functionCall' => 'PHPExcel_Calculation_Financial::DOLLARFR',
753
+ 'argumentCount' => '2'
754
+ ),
755
+ 'DPRODUCT' => array(
756
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_DATABASE,
757
+ 'functionCall' => 'PHPExcel_Calculation_Database::DPRODUCT',
758
+ 'argumentCount' => '3'
759
+ ),
760
+ 'DSTDEV' => array(
761
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_DATABASE,
762
+ 'functionCall' => 'PHPExcel_Calculation_Database::DSTDEV',
763
+ 'argumentCount' => '3'
764
+ ),
765
+ 'DSTDEVP' => array(
766
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_DATABASE,
767
+ 'functionCall' => 'PHPExcel_Calculation_Database::DSTDEVP',
768
+ 'argumentCount' => '3'
769
+ ),
770
+ 'DSUM' => array(
771
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_DATABASE,
772
+ 'functionCall' => 'PHPExcel_Calculation_Database::DSUM',
773
+ 'argumentCount' => '3'
774
+ ),
775
+ 'DURATION' => array(
776
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
777
+ 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
778
+ 'argumentCount' => '5,6'
779
+ ),
780
+ 'DVAR' => array(
781
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_DATABASE,
782
+ 'functionCall' => 'PHPExcel_Calculation_Database::DVAR',
783
+ 'argumentCount' => '3'
784
+ ),
785
+ 'DVARP' => array(
786
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_DATABASE,
787
+ 'functionCall' => 'PHPExcel_Calculation_Database::DVARP',
788
+ 'argumentCount' => '3'
789
+ ),
790
+ 'EDATE' => array(
791
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
792
+ 'functionCall' => 'PHPExcel_Calculation_DateTime::EDATE',
793
+ 'argumentCount' => '2'
794
+ ),
795
+ 'EFFECT' => array(
796
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
797
+ 'functionCall' => 'PHPExcel_Calculation_Financial::EFFECT',
798
+ 'argumentCount' => '2'
799
+ ),
800
+ 'EOMONTH' => array(
801
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
802
+ 'functionCall' => 'PHPExcel_Calculation_DateTime::EOMONTH',
803
+ 'argumentCount' => '2'
804
+ ),
805
+ 'ERF' => array(
806
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
807
+ 'functionCall' => 'PHPExcel_Calculation_Engineering::ERF',
808
+ 'argumentCount' => '1,2'
809
+ ),
810
+ 'ERFC' => array(
811
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
812
+ 'functionCall' => 'PHPExcel_Calculation_Engineering::ERFC',
813
+ 'argumentCount' => '1'
814
+ ),
815
+ 'ERROR.TYPE' => array(
816
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
817
+ 'functionCall' => 'PHPExcel_Calculation_Functions::ERROR_TYPE',
818
+ 'argumentCount' => '1'
819
+ ),
820
+ 'EVEN' => array(
821
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
822
+ 'functionCall' => 'PHPExcel_Calculation_MathTrig::EVEN',
823
+ 'argumentCount' => '1'
824
+ ),
825
+ 'EXACT' => array(
826
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
827
+ 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
828
+ 'argumentCount' => '2'
829
+ ),
830
+ 'EXP' => array(
831
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
832
+ 'functionCall' => 'exp',
833
+ 'argumentCount' => '1'
834
+ ),
835
+ 'EXPONDIST' => array(
836
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
837
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::EXPONDIST',
838
+ 'argumentCount' => '3'
839
+ ),
840
+ 'FACT' => array(
841
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
842
+ 'functionCall' => 'PHPExcel_Calculation_MathTrig::FACT',
843
+ 'argumentCount' => '1'
844
+ ),
845
+ 'FACTDOUBLE' => array(
846
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
847
+ 'functionCall' => 'PHPExcel_Calculation_MathTrig::FACTDOUBLE',
848
+ 'argumentCount' => '1'
849
+ ),
850
+ 'FALSE' => array(
851
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_LOGICAL,
852
+ 'functionCall' => 'PHPExcel_Calculation_Logical::FALSE',
853
+ 'argumentCount' => '0'
854
+ ),
855
+ 'FDIST' => array(
856
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
857
+ 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
858
+ 'argumentCount' => '3'
859
+ ),
860
+ 'FIND' => array(
861
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
862
+ 'functionCall' => 'PHPExcel_Calculation_TextData::SEARCHSENSITIVE',
863
+ 'argumentCount' => '2,3'
864
+ ),
865
+ 'FINDB' => array(
866
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
867
+ 'functionCall' => 'PHPExcel_Calculation_TextData::SEARCHSENSITIVE',
868
+ 'argumentCount' => '2,3'
869
+ ),
870
+ 'FINV' => array(
871
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
872
+ 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
873
+ 'argumentCount' => '3'
874
+ ),
875
+ 'FISHER' => array(
876
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
877
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::FISHER',
878
+ 'argumentCount' => '1'
879
+ ),
880
+ 'FISHERINV' => array(
881
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
882
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::FISHERINV',
883
+ 'argumentCount' => '1'
884
+ ),
885
+ 'FIXED' => array(
886
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
887
+ 'functionCall' => 'PHPExcel_Calculation_TextData::FIXEDFORMAT',
888
+ 'argumentCount' => '1-3'
889
+ ),
890
+ 'FLOOR' => array(
891
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
892
+ 'functionCall' => 'PHPExcel_Calculation_MathTrig::FLOOR',
893
+ 'argumentCount' => '2'
894
+ ),
895
+ 'FORECAST' => array(
896
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
897
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::FORECAST',
898
+ 'argumentCount' => '3'
899
+ ),
900
+ 'FREQUENCY' => array(
901
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
902
+ 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
903
+ 'argumentCount' => '2'
904
+ ),
905
+ 'FTEST' => array(
906
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
907
+ 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
908
+ 'argumentCount' => '2'
909
+ ),
910
+ 'FV' => array(
911
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
912
+ 'functionCall' => 'PHPExcel_Calculation_Financial::FV',
913
+ 'argumentCount' => '3-5'
914
+ ),
915
+ 'FVSCHEDULE' => array(
916
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
917
+ 'functionCall' => 'PHPExcel_Calculation_Financial::FVSCHEDULE',
918
+ 'argumentCount' => '2'
919
+ ),
920
+ 'GAMMADIST' => array(
921
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
922
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::GAMMADIST',
923
+ 'argumentCount' => '4'
924
+ ),
925
+ 'GAMMAINV' => array(
926
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
927
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::GAMMAINV',
928
+ 'argumentCount' => '3'
929
+ ),
930
+ 'GAMMALN' => array(
931
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
932
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::GAMMALN',
933
+ 'argumentCount' => '1'
934
+ ),
935
+ 'GCD' => array(
936
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
937
+ 'functionCall' => 'PHPExcel_Calculation_MathTrig::GCD',
938
+ 'argumentCount' => '1+'
939
+ ),
940
+ 'GEOMEAN' => array(
941
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
942
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::GEOMEAN',
943
+ 'argumentCount' => '1+'
944
+ ),
945
+ 'GESTEP' => array(
946
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
947
+ 'functionCall' => 'PHPExcel_Calculation_Engineering::GESTEP',
948
+ 'argumentCount' => '1,2'
949
+ ),
950
+ 'GETPIVOTDATA' => array(
951
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
952
+ 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
953
+ 'argumentCount' => '2+'
954
+ ),
955
+ 'GROWTH' => array(
956
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
957
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::GROWTH',
958
+ 'argumentCount' => '1-4'
959
+ ),
960
+ 'HARMEAN' => array(
961
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
962
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::HARMEAN',
963
+ 'argumentCount' => '1+'
964
+ ),
965
+ 'HEX2BIN' => array(
966
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
967
+ 'functionCall' => 'PHPExcel_Calculation_Engineering::HEXTOBIN',
968
+ 'argumentCount' => '1,2'
969
+ ),
970
+ 'HEX2DEC' => array(
971
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
972
+ 'functionCall' => 'PHPExcel_Calculation_Engineering::HEXTODEC',
973
+ 'argumentCount' => '1'
974
+ ),
975
+ 'HEX2OCT' => array(
976
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
977
+ 'functionCall' => 'PHPExcel_Calculation_Engineering::HEXTOOCT',
978
+ 'argumentCount' => '1,2'
979
+ ),
980
+ 'HLOOKUP' => array(
981
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
982
+ 'functionCall' => 'PHPExcel_Calculation_LookupRef::HLOOKUP',
983
+ 'argumentCount' => '3,4'
984
+ ),
985
+ 'HOUR' => array(
986
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
987
+ 'functionCall' => 'PHPExcel_Calculation_DateTime::HOUROFDAY',
988
+ 'argumentCount' => '1'
989
+ ),
990
+ 'HYPERLINK' => array(
991
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
992
+ 'functionCall' => 'PHPExcel_Calculation_LookupRef::HYPERLINK',
993
+ 'argumentCount' => '1,2',
994
+ 'passCellReference' => true
995
+ ),
996
+ 'HYPGEOMDIST' => array(
997
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
998
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::HYPGEOMDIST',
999
+ 'argumentCount' => '4'
1000
+ ),
1001
+ 'IF' => array(
1002
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_LOGICAL,
1003
+ 'functionCall' => 'PHPExcel_Calculation_Logical::STATEMENT_IF',
1004
+ 'argumentCount' => '1-3'
1005
+ ),
1006
+ 'IFERROR' => array(
1007
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_LOGICAL,
1008
+ 'functionCall' => 'PHPExcel_Calculation_Logical::IFERROR',
1009
+ 'argumentCount' => '2'
1010
+ ),
1011
+ 'IMABS' => array(
1012
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
1013
+ 'functionCall' => 'PHPExcel_Calculation_Engineering::IMABS',
1014
+ 'argumentCount' => '1'
1015
+ ),
1016
+ 'IMAGINARY' => array(
1017
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
1018
+ 'functionCall' => 'PHPExcel_Calculation_Engineering::IMAGINARY',
1019
+ 'argumentCount' => '1'
1020
+ ),
1021
+ 'IMARGUMENT' => array(
1022
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
1023
+ 'functionCall' => 'PHPExcel_Calculation_Engineering::IMARGUMENT',
1024
+ 'argumentCount' => '1'
1025
+ ),
1026
+ 'IMCONJUGATE' => array(
1027
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
1028
+ 'functionCall' => 'PHPExcel_Calculation_Engineering::IMCONJUGATE',
1029
+ 'argumentCount' => '1'
1030
+ ),
1031
+ 'IMCOS' => array(
1032
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
1033
+ 'functionCall' => 'PHPExcel_Calculation_Engineering::IMCOS',
1034
+ 'argumentCount' => '1'
1035
+ ),
1036
+ 'IMDIV' => array(
1037
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
1038
+ 'functionCall' => 'PHPExcel_Calculation_Engineering::IMDIV',
1039
+ 'argumentCount' => '2'
1040
+ ),
1041
+ 'IMEXP' => array(
1042
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
1043
+ 'functionCall' => 'PHPExcel_Calculation_Engineering::IMEXP',
1044
+ 'argumentCount' => '1'
1045
+ ),
1046
+ 'IMLN' => array(
1047
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
1048
+ 'functionCall' => 'PHPExcel_Calculation_Engineering::IMLN',
1049
+ 'argumentCount' => '1'
1050
+ ),
1051
+ 'IMLOG10' => array(
1052
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
1053
+ 'functionCall' => 'PHPExcel_Calculation_Engineering::IMLOG10',
1054
+ 'argumentCount' => '1'
1055
+ ),
1056
+ 'IMLOG2' => array(
1057
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
1058
+ 'functionCall' => 'PHPExcel_Calculation_Engineering::IMLOG2',
1059
+ 'argumentCount' => '1'
1060
+ ),
1061
+ 'IMPOWER' => array(
1062
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
1063
+ 'functionCall' => 'PHPExcel_Calculation_Engineering::IMPOWER',
1064
+ 'argumentCount' => '2'
1065
+ ),
1066
+ 'IMPRODUCT' => array(
1067
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
1068
+ 'functionCall' => 'PHPExcel_Calculation_Engineering::IMPRODUCT',
1069
+ 'argumentCount' => '1+'
1070
+ ),
1071
+ 'IMREAL' => array(
1072
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
1073
+ 'functionCall' => 'PHPExcel_Calculation_Engineering::IMREAL',
1074
+ 'argumentCount' => '1'
1075
+ ),
1076
+ 'IMSIN' => array(
1077
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
1078
+ 'functionCall' => 'PHPExcel_Calculation_Engineering::IMSIN',
1079
+ 'argumentCount' => '1'
1080
+ ),
1081
+ 'IMSQRT' => array(
1082
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
1083
+ 'functionCall' => 'PHPExcel_Calculation_Engineering::IMSQRT',
1084
+ 'argumentCount' => '1'
1085
+ ),
1086
+ 'IMSUB' => array(
1087
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
1088
+ 'functionCall' => 'PHPExcel_Calculation_Engineering::IMSUB',
1089
+ 'argumentCount' => '2'
1090
+ ),
1091
+ 'IMSUM' => array(
1092
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
1093
+ 'functionCall' => 'PHPExcel_Calculation_Engineering::IMSUM',
1094
+ 'argumentCount' => '1+'
1095
+ ),
1096
+ 'INDEX' => array(
1097
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
1098
+ 'functionCall' => 'PHPExcel_Calculation_LookupRef::INDEX',
1099
+ 'argumentCount' => '1-4'
1100
+ ),
1101
+ 'INDIRECT' => array(
1102
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
1103
+ 'functionCall' => 'PHPExcel_Calculation_LookupRef::INDIRECT',
1104
+ 'argumentCount' => '1,2',
1105
+ 'passCellReference' => true
1106
+ ),
1107
+ 'INFO' => array(
1108
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
1109
+ 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
1110
+ 'argumentCount' => '1'
1111
+ ),
1112
+ 'INT' => array(
1113
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1114
+ 'functionCall' => 'PHPExcel_Calculation_MathTrig::INT',
1115
+ 'argumentCount' => '1'
1116
+ ),
1117
+ 'INTERCEPT' => array(
1118
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1119
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::INTERCEPT',
1120
+ 'argumentCount' => '2'
1121
+ ),
1122
+ 'INTRATE' => array(
1123
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1124
+ 'functionCall' => 'PHPExcel_Calculation_Financial::INTRATE',
1125
+ 'argumentCount' => '4,5'
1126
+ ),
1127
+ 'IPMT' => array(
1128
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1129
+ 'functionCall' => 'PHPExcel_Calculation_Financial::IPMT',
1130
+ 'argumentCount' => '4-6'
1131
+ ),
1132
+ 'IRR' => array(
1133
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1134
+ 'functionCall' => 'PHPExcel_Calculation_Financial::IRR',
1135
+ 'argumentCount' => '1,2'
1136
+ ),
1137
+ 'ISBLANK' => array(
1138
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
1139
+ 'functionCall' => 'PHPExcel_Calculation_Functions::IS_BLANK',
1140
+ 'argumentCount' => '1'
1141
+ ),
1142
+ 'ISERR' => array(
1143
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
1144
+ 'functionCall' => 'PHPExcel_Calculation_Functions::IS_ERR',
1145
+ 'argumentCount' => '1'
1146
+ ),
1147
+ 'ISERROR' => array(
1148
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
1149
+ 'functionCall' => 'PHPExcel_Calculation_Functions::IS_ERROR',
1150
+ 'argumentCount' => '1'
1151
+ ),
1152
+ 'ISEVEN' => array(
1153
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
1154
+ 'functionCall' => 'PHPExcel_Calculation_Functions::IS_EVEN',
1155
+ 'argumentCount' => '1'
1156
+ ),
1157
+ 'ISLOGICAL' => array(
1158
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
1159
+ 'functionCall' => 'PHPExcel_Calculation_Functions::IS_LOGICAL',
1160
+ 'argumentCount' => '1'
1161
+ ),
1162
+ 'ISNA' => array(
1163
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
1164
+ 'functionCall' => 'PHPExcel_Calculation_Functions::IS_NA',
1165
+ 'argumentCount' => '1'
1166
+ ),
1167
+ 'ISNONTEXT' => array(
1168
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
1169
+ 'functionCall' => 'PHPExcel_Calculation_Functions::IS_NONTEXT',
1170
+ 'argumentCount' => '1'
1171
+ ),
1172
+ 'ISNUMBER' => array(
1173
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
1174
+ 'functionCall' => 'PHPExcel_Calculation_Functions::IS_NUMBER',
1175
+ 'argumentCount' => '1'
1176
+ ),
1177
+ 'ISODD' => array(
1178
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
1179
+ 'functionCall' => 'PHPExcel_Calculation_Functions::IS_ODD',
1180
+ 'argumentCount' => '1'
1181
+ ),
1182
+ 'ISPMT' => array(
1183
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1184
+ 'functionCall' => 'PHPExcel_Calculation_Financial::ISPMT',
1185
+ 'argumentCount' => '4'
1186
+ ),
1187
+ 'ISREF' => array(
1188
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
1189
+ 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
1190
+ 'argumentCount' => '1'
1191
+ ),
1192
+ 'ISTEXT' => array(
1193
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
1194
+ 'functionCall' => 'PHPExcel_Calculation_Functions::IS_TEXT',
1195
+ 'argumentCount' => '1'
1196
+ ),
1197
+ 'JIS' => array(
1198
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
1199
+ 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
1200
+ 'argumentCount' => '1'
1201
+ ),
1202
+ 'KURT' => array(
1203
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1204
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::KURT',
1205
+ 'argumentCount' => '1+'
1206
+ ),
1207
+ 'LARGE' => array(
1208
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1209
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::LARGE',
1210
+ 'argumentCount' => '2'
1211
+ ),
1212
+ 'LCM' => array(
1213
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1214
+ 'functionCall' => 'PHPExcel_Calculation_MathTrig::LCM',
1215
+ 'argumentCount' => '1+'
1216
+ ),
1217
+ 'LEFT' => array(
1218
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
1219
+ 'functionCall' => 'PHPExcel_Calculation_TextData::LEFT',
1220
+ 'argumentCount' => '1,2'
1221
+ ),
1222
+ 'LEFTB' => array(
1223
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
1224
+ 'functionCall' => 'PHPExcel_Calculation_TextData::LEFT',
1225
+ 'argumentCount' => '1,2'
1226
+ ),
1227
+ 'LEN' => array(
1228
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
1229
+ 'functionCall' => 'PHPExcel_Calculation_TextData::STRINGLENGTH',
1230
+ 'argumentCount' => '1'
1231
+ ),
1232
+ 'LENB' => array(
1233
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
1234
+ 'functionCall' => 'PHPExcel_Calculation_TextData::STRINGLENGTH',
1235
+ 'argumentCount' => '1'
1236
+ ),
1237
+ 'LINEST' => array(
1238
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1239
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::LINEST',
1240
+ 'argumentCount' => '1-4'
1241
+ ),
1242
+ 'LN' => array(
1243
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1244
+ 'functionCall' => 'log',
1245
+ 'argumentCount' => '1'
1246
+ ),
1247
+ 'LOG' => array(
1248
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1249
+ 'functionCall' => 'PHPExcel_Calculation_MathTrig::LOG_BASE',
1250
+ 'argumentCount' => '1,2'
1251
+ ),
1252
+ 'LOG10' => array(
1253
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1254
+ 'functionCall' => 'log10',
1255
+ 'argumentCount' => '1'
1256
+ ),
1257
+ 'LOGEST' => array(
1258
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1259
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::LOGEST',
1260
+ 'argumentCount' => '1-4'
1261
+ ),
1262
+ 'LOGINV' => array(
1263
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1264
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::LOGINV',
1265
+ 'argumentCount' => '3'
1266
+ ),
1267
+ 'LOGNORMDIST' => array(
1268
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1269
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::LOGNORMDIST',
1270
+ 'argumentCount' => '3'
1271
+ ),
1272
+ 'LOOKUP' => array(
1273
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
1274
+ 'functionCall' => 'PHPExcel_Calculation_LookupRef::LOOKUP',
1275
+ 'argumentCount' => '2,3'
1276
+ ),
1277
+ 'LOWER' => array(
1278
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
1279
+ 'functionCall' => 'PHPExcel_Calculation_TextData::LOWERCASE',
1280
+ 'argumentCount' => '1'
1281
+ ),
1282
+ 'MATCH' => array(
1283
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
1284
+ 'functionCall' => 'PHPExcel_Calculation_LookupRef::MATCH',
1285
+ 'argumentCount' => '2,3'
1286
+ ),
1287
+ 'MAX' => array(
1288
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1289
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::MAX',
1290
+ 'argumentCount' => '1+'
1291
+ ),
1292
+ 'MAXA' => array(
1293
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1294
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::MAXA',
1295
+ 'argumentCount' => '1+'
1296
+ ),
1297
+ 'MAXIF' => array(
1298
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1299
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::MAXIF',
1300
+ 'argumentCount' => '2+'
1301
+ ),
1302
+ 'MDETERM' => array(
1303
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1304
+ 'functionCall' => 'PHPExcel_Calculation_MathTrig::MDETERM',
1305
+ 'argumentCount' => '1'
1306
+ ),
1307
+ 'MDURATION' => array(
1308
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1309
+ 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
1310
+ 'argumentCount' => '5,6'
1311
+ ),
1312
+ 'MEDIAN' => array(
1313
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1314
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::MEDIAN',
1315
+ 'argumentCount' => '1+'
1316
+ ),
1317
+ 'MEDIANIF' => array(
1318
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1319
+ 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
1320
+ 'argumentCount' => '2+'
1321
+ ),
1322
+ 'MID' => array(
1323
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
1324
+ 'functionCall' => 'PHPExcel_Calculation_TextData::MID',
1325
+ 'argumentCount' => '3'
1326
+ ),
1327
+ 'MIDB' => array(
1328
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
1329
+ 'functionCall' => 'PHPExcel_Calculation_TextData::MID',
1330
+ 'argumentCount' => '3'
1331
+ ),
1332
+ 'MIN' => array(
1333
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1334
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::MIN',
1335
+ 'argumentCount' => '1+'
1336
+ ),
1337
+ 'MINA' => array(
1338
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1339
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::MINA',
1340
+ 'argumentCount' => '1+'
1341
+ ),
1342
+ 'MINIF' => array(
1343
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1344
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::MINIF',
1345
+ 'argumentCount' => '2+'
1346
+ ),
1347
+ 'MINUTE' => array(
1348
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
1349
+ 'functionCall' => 'PHPExcel_Calculation_DateTime::MINUTEOFHOUR',
1350
+ 'argumentCount' => '1'
1351
+ ),
1352
+ 'MINVERSE' => array(
1353
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1354
+ 'functionCall' => 'PHPExcel_Calculation_MathTrig::MINVERSE',
1355
+ 'argumentCount' => '1'
1356
+ ),
1357
+ 'MIRR' => array(
1358
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1359
+ 'functionCall' => 'PHPExcel_Calculation_Financial::MIRR',
1360
+ 'argumentCount' => '3'
1361
+ ),
1362
+ 'MMULT' => array(
1363
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1364
+ 'functionCall' => 'PHPExcel_Calculation_MathTrig::MMULT',
1365
+ 'argumentCount' => '2'
1366
+ ),
1367
+ 'MOD' => array(
1368
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1369
+ 'functionCall' => 'PHPExcel_Calculation_MathTrig::MOD',
1370
+ 'argumentCount' => '2'
1371
+ ),
1372
+ 'MODE' => array(
1373
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1374
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::MODE',
1375
+ 'argumentCount' => '1+'
1376
+ ),
1377
+ 'MONTH' => array(
1378
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
1379
+ 'functionCall' => 'PHPExcel_Calculation_DateTime::MONTHOFYEAR',
1380
+ 'argumentCount' => '1'
1381
+ ),
1382
+ 'MROUND' => array(
1383
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1384
+ 'functionCall' => 'PHPExcel_Calculation_MathTrig::MROUND',
1385
+ 'argumentCount' => '2'
1386
+ ),
1387
+ 'MULTINOMIAL' => array(
1388
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1389
+ 'functionCall' => 'PHPExcel_Calculation_MathTrig::MULTINOMIAL',
1390
+ 'argumentCount' => '1+'
1391
+ ),
1392
+ 'N' => array(
1393
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
1394
+ 'functionCall' => 'PHPExcel_Calculation_Functions::N',
1395
+ 'argumentCount' => '1'
1396
+ ),
1397
+ 'NA' => array(
1398
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
1399
+ 'functionCall' => 'PHPExcel_Calculation_Functions::NA',
1400
+ 'argumentCount' => '0'
1401
+ ),
1402
+ 'NEGBINOMDIST' => array(
1403
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1404
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::NEGBINOMDIST',
1405
+ 'argumentCount' => '3'
1406
+ ),
1407
+ 'NETWORKDAYS' => array(
1408
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
1409
+ 'functionCall' => 'PHPExcel_Calculation_DateTime::NETWORKDAYS',
1410
+ 'argumentCount' => '2+'
1411
+ ),
1412
+ 'NOMINAL' => array(
1413
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1414
+ 'functionCall' => 'PHPExcel_Calculation_Financial::NOMINAL',
1415
+ 'argumentCount' => '2'
1416
+ ),
1417
+ 'NORMDIST' => array(
1418
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1419
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::NORMDIST',
1420
+ 'argumentCount' => '4'
1421
+ ),
1422
+ 'NORMINV' => array(
1423
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1424
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::NORMINV',
1425
+ 'argumentCount' => '3'
1426
+ ),
1427
+ 'NORMSDIST' => array(
1428
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1429
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::NORMSDIST',
1430
+ 'argumentCount' => '1'
1431
+ ),
1432
+ 'NORMSINV' => array(
1433
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1434
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::NORMSINV',
1435
+ 'argumentCount' => '1'
1436
+ ),
1437
+ 'NOT' => array(
1438
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_LOGICAL,
1439
+ 'functionCall' => 'PHPExcel_Calculation_Logical::NOT',
1440
+ 'argumentCount' => '1'
1441
+ ),
1442
+ 'NOW' => array(
1443
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
1444
+ 'functionCall' => 'PHPExcel_Calculation_DateTime::DATETIMENOW',
1445
+ 'argumentCount' => '0'
1446
+ ),
1447
+ 'NPER' => array(
1448
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1449
+ 'functionCall' => 'PHPExcel_Calculation_Financial::NPER',
1450
+ 'argumentCount' => '3-5'
1451
+ ),
1452
+ 'NPV' => array(
1453
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1454
+ 'functionCall' => 'PHPExcel_Calculation_Financial::NPV',
1455
+ 'argumentCount' => '2+'
1456
+ ),
1457
+ 'OCT2BIN' => array(
1458
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
1459
+ 'functionCall' => 'PHPExcel_Calculation_Engineering::OCTTOBIN',
1460
+ 'argumentCount' => '1,2'
1461
+ ),
1462
+ 'OCT2DEC' => array(
1463
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
1464
+ 'functionCall' => 'PHPExcel_Calculation_Engineering::OCTTODEC',
1465
+ 'argumentCount' => '1'
1466
+ ),
1467
+ 'OCT2HEX' => array(
1468
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_ENGINEERING,
1469
+ 'functionCall' => 'PHPExcel_Calculation_Engineering::OCTTOHEX',
1470
+ 'argumentCount' => '1,2'
1471
+ ),
1472
+ 'ODD' => array(
1473
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1474
+ 'functionCall' => 'PHPExcel_Calculation_MathTrig::ODD',
1475
+ 'argumentCount' => '1'
1476
+ ),
1477
+ 'ODDFPRICE' => array(
1478
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1479
+ 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
1480
+ 'argumentCount' => '8,9'
1481
+ ),
1482
+ 'ODDFYIELD' => array(
1483
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1484
+ 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
1485
+ 'argumentCount' => '8,9'
1486
+ ),
1487
+ 'ODDLPRICE' => array(
1488
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1489
+ 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
1490
+ 'argumentCount' => '7,8'
1491
+ ),
1492
+ 'ODDLYIELD' => array(
1493
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1494
+ 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
1495
+ 'argumentCount' => '7,8'
1496
+ ),
1497
+ 'OFFSET' => array(
1498
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
1499
+ 'functionCall' => 'PHPExcel_Calculation_LookupRef::OFFSET',
1500
+ 'argumentCount' => '3-5',
1501
+ 'passCellReference' => true,
1502
+ 'passByReference' => array(true)
1503
+ ),
1504
+ 'OR' => array(
1505
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_LOGICAL,
1506
+ 'functionCall' => 'PHPExcel_Calculation_Logical::LOGICAL_OR',
1507
+ 'argumentCount' => '1+'
1508
+ ),
1509
+ 'PEARSON' => array(
1510
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1511
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::CORREL',
1512
+ 'argumentCount' => '2'
1513
+ ),
1514
+ 'PERCENTILE' => array(
1515
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1516
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::PERCENTILE',
1517
+ 'argumentCount' => '2'
1518
+ ),
1519
+ 'PERCENTRANK' => array(
1520
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1521
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::PERCENTRANK',
1522
+ 'argumentCount' => '2,3'
1523
+ ),
1524
+ 'PERMUT' => array(
1525
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1526
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::PERMUT',
1527
+ 'argumentCount' => '2'
1528
+ ),
1529
+ 'PHONETIC' => array(
1530
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
1531
+ 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
1532
+ 'argumentCount' => '1'
1533
+ ),
1534
+ 'PI' => array(
1535
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1536
+ 'functionCall' => 'pi',
1537
+ 'argumentCount' => '0'
1538
+ ),
1539
+ 'PMT' => array(
1540
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1541
+ 'functionCall' => 'PHPExcel_Calculation_Financial::PMT',
1542
+ 'argumentCount' => '3-5'
1543
+ ),
1544
+ 'POISSON' => array(
1545
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1546
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::POISSON',
1547
+ 'argumentCount' => '3'
1548
+ ),
1549
+ 'POWER' => array(
1550
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1551
+ 'functionCall' => 'PHPExcel_Calculation_MathTrig::POWER',
1552
+ 'argumentCount' => '2'
1553
+ ),
1554
+ 'PPMT' => array(
1555
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1556
+ 'functionCall' => 'PHPExcel_Calculation_Financial::PPMT',
1557
+ 'argumentCount' => '4-6'
1558
+ ),
1559
+ 'PRICE' => array(
1560
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1561
+ 'functionCall' => 'PHPExcel_Calculation_Financial::PRICE',
1562
+ 'argumentCount' => '6,7'
1563
+ ),
1564
+ 'PRICEDISC' => array(
1565
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1566
+ 'functionCall' => 'PHPExcel_Calculation_Financial::PRICEDISC',
1567
+ 'argumentCount' => '4,5'
1568
+ ),
1569
+ 'PRICEMAT' => array(
1570
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1571
+ 'functionCall' => 'PHPExcel_Calculation_Financial::PRICEMAT',
1572
+ 'argumentCount' => '5,6'
1573
+ ),
1574
+ 'PROB' => array(
1575
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1576
+ 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
1577
+ 'argumentCount' => '3,4'
1578
+ ),
1579
+ 'PRODUCT' => array(
1580
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1581
+ 'functionCall' => 'PHPExcel_Calculation_MathTrig::PRODUCT',
1582
+ 'argumentCount' => '1+'
1583
+ ),
1584
+ 'PROPER' => array(
1585
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
1586
+ 'functionCall' => 'PHPExcel_Calculation_TextData::PROPERCASE',
1587
+ 'argumentCount' => '1'
1588
+ ),
1589
+ 'PV' => array(
1590
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1591
+ 'functionCall' => 'PHPExcel_Calculation_Financial::PV',
1592
+ 'argumentCount' => '3-5'
1593
+ ),
1594
+ 'QUARTILE' => array(
1595
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1596
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::QUARTILE',
1597
+ 'argumentCount' => '2'
1598
+ ),
1599
+ 'QUOTIENT' => array(
1600
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1601
+ 'functionCall' => 'PHPExcel_Calculation_MathTrig::QUOTIENT',
1602
+ 'argumentCount' => '2'
1603
+ ),
1604
+ 'RADIANS' => array(
1605
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1606
+ 'functionCall' => 'deg2rad',
1607
+ 'argumentCount' => '1'
1608
+ ),
1609
+ 'RAND' => array(
1610
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1611
+ 'functionCall' => 'PHPExcel_Calculation_MathTrig::RAND',
1612
+ 'argumentCount' => '0'
1613
+ ),
1614
+ 'RANDBETWEEN' => array(
1615
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1616
+ 'functionCall' => 'PHPExcel_Calculation_MathTrig::RAND',
1617
+ 'argumentCount' => '2'
1618
+ ),
1619
+ 'RANK' => array(
1620
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1621
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::RANK',
1622
+ 'argumentCount' => '2,3'
1623
+ ),
1624
+ 'RATE' => array(
1625
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1626
+ 'functionCall' => 'PHPExcel_Calculation_Financial::RATE',
1627
+ 'argumentCount' => '3-6'
1628
+ ),
1629
+ 'RECEIVED' => array(
1630
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1631
+ 'functionCall' => 'PHPExcel_Calculation_Financial::RECEIVED',
1632
+ 'argumentCount' => '4-5'
1633
+ ),
1634
+ 'REPLACE' => array(
1635
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
1636
+ 'functionCall' => 'PHPExcel_Calculation_TextData::REPLACE',
1637
+ 'argumentCount' => '4'
1638
+ ),
1639
+ 'REPLACEB' => array(
1640
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
1641
+ 'functionCall' => 'PHPExcel_Calculation_TextData::REPLACE',
1642
+ 'argumentCount' => '4'
1643
+ ),
1644
+ 'REPT' => array(
1645
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
1646
+ 'functionCall' => 'str_repeat',
1647
+ 'argumentCount' => '2'
1648
+ ),
1649
+ 'RIGHT' => array(
1650
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
1651
+ 'functionCall' => 'PHPExcel_Calculation_TextData::RIGHT',
1652
+ 'argumentCount' => '1,2'
1653
+ ),
1654
+ 'RIGHTB' => array(
1655
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
1656
+ 'functionCall' => 'PHPExcel_Calculation_TextData::RIGHT',
1657
+ 'argumentCount' => '1,2'
1658
+ ),
1659
+ 'ROMAN' => array(
1660
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1661
+ 'functionCall' => 'PHPExcel_Calculation_MathTrig::ROMAN',
1662
+ 'argumentCount' => '1,2'
1663
+ ),
1664
+ 'ROUND' => array(
1665
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1666
+ 'functionCall' => 'round',
1667
+ 'argumentCount' => '2'
1668
+ ),
1669
+ 'ROUNDDOWN' => array(
1670
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1671
+ 'functionCall' => 'PHPExcel_Calculation_MathTrig::ROUNDDOWN',
1672
+ 'argumentCount' => '2'
1673
+ ),
1674
+ 'ROUNDUP' => array(
1675
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1676
+ 'functionCall' => 'PHPExcel_Calculation_MathTrig::ROUNDUP',
1677
+ 'argumentCount' => '2'
1678
+ ),
1679
+ 'ROW' => array(
1680
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
1681
+ 'functionCall' => 'PHPExcel_Calculation_LookupRef::ROW',
1682
+ 'argumentCount' => '-1',
1683
+ 'passByReference' => array(true)
1684
+ ),
1685
+ 'ROWS' => array(
1686
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
1687
+ 'functionCall' => 'PHPExcel_Calculation_LookupRef::ROWS',
1688
+ 'argumentCount' => '1'
1689
+ ),
1690
+ 'RSQ' => array(
1691
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1692
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::RSQ',
1693
+ 'argumentCount' => '2'
1694
+ ),
1695
+ 'RTD' => array(
1696
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
1697
+ 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
1698
+ 'argumentCount' => '1+'
1699
+ ),
1700
+ 'SEARCH' => array(
1701
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
1702
+ 'functionCall' => 'PHPExcel_Calculation_TextData::SEARCHINSENSITIVE',
1703
+ 'argumentCount' => '2,3'
1704
+ ),
1705
+ 'SEARCHB' => array(
1706
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
1707
+ 'functionCall' => 'PHPExcel_Calculation_TextData::SEARCHINSENSITIVE',
1708
+ 'argumentCount' => '2,3'
1709
+ ),
1710
+ 'SECOND' => array(
1711
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
1712
+ 'functionCall' => 'PHPExcel_Calculation_DateTime::SECONDOFMINUTE',
1713
+ 'argumentCount' => '1'
1714
+ ),
1715
+ 'SERIESSUM' => array(
1716
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1717
+ 'functionCall' => 'PHPExcel_Calculation_MathTrig::SERIESSUM',
1718
+ 'argumentCount' => '4'
1719
+ ),
1720
+ 'SIGN' => array(
1721
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1722
+ 'functionCall' => 'PHPExcel_Calculation_MathTrig::SIGN',
1723
+ 'argumentCount' => '1'
1724
+ ),
1725
+ 'SIN' => array(
1726
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1727
+ 'functionCall' => 'sin',
1728
+ 'argumentCount' => '1'
1729
+ ),
1730
+ 'SINH' => array(
1731
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1732
+ 'functionCall' => 'sinh',
1733
+ 'argumentCount' => '1'
1734
+ ),
1735
+ 'SKEW' => array(
1736
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1737
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::SKEW',
1738
+ 'argumentCount' => '1+'
1739
+ ),
1740
+ 'SLN' => array(
1741
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1742
+ 'functionCall' => 'PHPExcel_Calculation_Financial::SLN',
1743
+ 'argumentCount' => '3'
1744
+ ),
1745
+ 'SLOPE' => array(
1746
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1747
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::SLOPE',
1748
+ 'argumentCount' => '2'
1749
+ ),
1750
+ 'SMALL' => array(
1751
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1752
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::SMALL',
1753
+ 'argumentCount' => '2'
1754
+ ),
1755
+ 'SQRT' => array(
1756
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1757
+ 'functionCall' => 'sqrt',
1758
+ 'argumentCount' => '1'
1759
+ ),
1760
+ 'SQRTPI' => array(
1761
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1762
+ 'functionCall' => 'PHPExcel_Calculation_MathTrig::SQRTPI',
1763
+ 'argumentCount' => '1'
1764
+ ),
1765
+ 'STANDARDIZE' => array(
1766
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1767
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::STANDARDIZE',
1768
+ 'argumentCount' => '3'
1769
+ ),
1770
+ 'STDEV' => array(
1771
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1772
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::STDEV',
1773
+ 'argumentCount' => '1+'
1774
+ ),
1775
+ 'STDEVA' => array(
1776
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1777
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::STDEVA',
1778
+ 'argumentCount' => '1+'
1779
+ ),
1780
+ 'STDEVP' => array(
1781
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1782
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::STDEVP',
1783
+ 'argumentCount' => '1+'
1784
+ ),
1785
+ 'STDEVPA' => array(
1786
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1787
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::STDEVPA',
1788
+ 'argumentCount' => '1+'
1789
+ ),
1790
+ 'STEYX' => array(
1791
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1792
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::STEYX',
1793
+ 'argumentCount' => '2'
1794
+ ),
1795
+ 'SUBSTITUTE' => array(
1796
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
1797
+ 'functionCall' => 'PHPExcel_Calculation_TextData::SUBSTITUTE',
1798
+ 'argumentCount' => '3,4'
1799
+ ),
1800
+ 'SUBTOTAL' => array(
1801
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1802
+ 'functionCall' => 'PHPExcel_Calculation_MathTrig::SUBTOTAL',
1803
+ 'argumentCount' => '2+'
1804
+ ),
1805
+ 'SUM' => array(
1806
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1807
+ 'functionCall' => 'PHPExcel_Calculation_MathTrig::SUM',
1808
+ 'argumentCount' => '1+'
1809
+ ),
1810
+ 'SUMIF' => array(
1811
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1812
+ 'functionCall' => 'PHPExcel_Calculation_MathTrig::SUMIF',
1813
+ 'argumentCount' => '2,3'
1814
+ ),
1815
+ 'SUMIFS' => array(
1816
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1817
+ 'functionCall' => 'PHPExcel_Calculation_MathTrig::SUMIFS',
1818
+ 'argumentCount' => '3+'
1819
+ ),
1820
+ 'SUMPRODUCT' => array(
1821
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1822
+ 'functionCall' => 'PHPExcel_Calculation_MathTrig::SUMPRODUCT',
1823
+ 'argumentCount' => '1+'
1824
+ ),
1825
+ 'SUMSQ' => array(
1826
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1827
+ 'functionCall' => 'PHPExcel_Calculation_MathTrig::SUMSQ',
1828
+ 'argumentCount' => '1+'
1829
+ ),
1830
+ 'SUMX2MY2' => array(
1831
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1832
+ 'functionCall' => 'PHPExcel_Calculation_MathTrig::SUMX2MY2',
1833
+ 'argumentCount' => '2'
1834
+ ),
1835
+ 'SUMX2PY2' => array(
1836
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1837
+ 'functionCall' => 'PHPExcel_Calculation_MathTrig::SUMX2PY2',
1838
+ 'argumentCount' => '2'
1839
+ ),
1840
+ 'SUMXMY2' => array(
1841
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1842
+ 'functionCall' => 'PHPExcel_Calculation_MathTrig::SUMXMY2',
1843
+ 'argumentCount' => '2'
1844
+ ),
1845
+ 'SYD' => array(
1846
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1847
+ 'functionCall' => 'PHPExcel_Calculation_Financial::SYD',
1848
+ 'argumentCount' => '4'
1849
+ ),
1850
+ 'T' => array(
1851
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
1852
+ 'functionCall' => 'PHPExcel_Calculation_TextData::RETURNSTRING',
1853
+ 'argumentCount' => '1'
1854
+ ),
1855
+ 'TAN' => array(
1856
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1857
+ 'functionCall' => 'tan',
1858
+ 'argumentCount' => '1'
1859
+ ),
1860
+ 'TANH' => array(
1861
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1862
+ 'functionCall' => 'tanh',
1863
+ 'argumentCount' => '1'
1864
+ ),
1865
+ 'TBILLEQ' => array(
1866
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1867
+ 'functionCall' => 'PHPExcel_Calculation_Financial::TBILLEQ',
1868
+ 'argumentCount' => '3'
1869
+ ),
1870
+ 'TBILLPRICE' => array(
1871
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1872
+ 'functionCall' => 'PHPExcel_Calculation_Financial::TBILLPRICE',
1873
+ 'argumentCount' => '3'
1874
+ ),
1875
+ 'TBILLYIELD' => array(
1876
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1877
+ 'functionCall' => 'PHPExcel_Calculation_Financial::TBILLYIELD',
1878
+ 'argumentCount' => '3'
1879
+ ),
1880
+ 'TDIST' => array(
1881
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1882
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::TDIST',
1883
+ 'argumentCount' => '3'
1884
+ ),
1885
+ 'TEXT' => array(
1886
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
1887
+ 'functionCall' => 'PHPExcel_Calculation_TextData::TEXTFORMAT',
1888
+ 'argumentCount' => '2'
1889
+ ),
1890
+ 'TIME' => array(
1891
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
1892
+ 'functionCall' => 'PHPExcel_Calculation_DateTime::TIME',
1893
+ 'argumentCount' => '3'
1894
+ ),
1895
+ 'TIMEVALUE' => array(
1896
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
1897
+ 'functionCall' => 'PHPExcel_Calculation_DateTime::TIMEVALUE',
1898
+ 'argumentCount' => '1'
1899
+ ),
1900
+ 'TINV' => array(
1901
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1902
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::TINV',
1903
+ 'argumentCount' => '2'
1904
+ ),
1905
+ 'TODAY' => array(
1906
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
1907
+ 'functionCall' => 'PHPExcel_Calculation_DateTime::DATENOW',
1908
+ 'argumentCount' => '0'
1909
+ ),
1910
+ 'TRANSPOSE' => array(
1911
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
1912
+ 'functionCall' => 'PHPExcel_Calculation_LookupRef::TRANSPOSE',
1913
+ 'argumentCount' => '1'
1914
+ ),
1915
+ 'TREND' => array(
1916
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1917
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::TREND',
1918
+ 'argumentCount' => '1-4'
1919
+ ),
1920
+ 'TRIM' => array(
1921
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
1922
+ 'functionCall' => 'PHPExcel_Calculation_TextData::TRIMSPACES',
1923
+ 'argumentCount' => '1'
1924
+ ),
1925
+ 'TRIMMEAN' => array(
1926
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1927
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::TRIMMEAN',
1928
+ 'argumentCount' => '2'
1929
+ ),
1930
+ 'TRUE' => array(
1931
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_LOGICAL,
1932
+ 'functionCall' => 'PHPExcel_Calculation_Logical::TRUE',
1933
+ 'argumentCount' => '0'
1934
+ ),
1935
+ 'TRUNC' => array(
1936
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_MATH_AND_TRIG,
1937
+ 'functionCall' => 'PHPExcel_Calculation_MathTrig::TRUNC',
1938
+ 'argumentCount' => '1,2'
1939
+ ),
1940
+ 'TTEST' => array(
1941
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1942
+ 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
1943
+ 'argumentCount' => '4'
1944
+ ),
1945
+ 'TYPE' => array(
1946
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
1947
+ 'functionCall' => 'PHPExcel_Calculation_Functions::TYPE',
1948
+ 'argumentCount' => '1'
1949
+ ),
1950
+ 'UPPER' => array(
1951
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
1952
+ 'functionCall' => 'PHPExcel_Calculation_TextData::UPPERCASE',
1953
+ 'argumentCount' => '1'
1954
+ ),
1955
+ 'USDOLLAR' => array(
1956
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1957
+ 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
1958
+ 'argumentCount' => '2'
1959
+ ),
1960
+ 'VALUE' => array(
1961
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_TEXT_AND_DATA,
1962
+ 'functionCall' => 'PHPExcel_Calculation_TextData::VALUE',
1963
+ 'argumentCount' => '1'
1964
+ ),
1965
+ 'VAR' => array(
1966
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1967
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::VARFunc',
1968
+ 'argumentCount' => '1+'
1969
+ ),
1970
+ 'VARA' => array(
1971
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1972
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::VARA',
1973
+ 'argumentCount' => '1+'
1974
+ ),
1975
+ 'VARP' => array(
1976
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1977
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::VARP',
1978
+ 'argumentCount' => '1+'
1979
+ ),
1980
+ 'VARPA' => array(
1981
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
1982
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::VARPA',
1983
+ 'argumentCount' => '1+'
1984
+ ),
1985
+ 'VDB' => array(
1986
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
1987
+ 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
1988
+ 'argumentCount' => '5-7'
1989
+ ),
1990
+ 'VERSION' => array(
1991
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_INFORMATION,
1992
+ 'functionCall' => 'PHPExcel_Calculation_Functions::VERSION',
1993
+ 'argumentCount' => '0'
1994
+ ),
1995
+ 'VLOOKUP' => array(
1996
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_LOOKUP_AND_REFERENCE,
1997
+ 'functionCall' => 'PHPExcel_Calculation_LookupRef::VLOOKUP',
1998
+ 'argumentCount' => '3,4'
1999
+ ),
2000
+ 'WEEKDAY' => array(
2001
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
2002
+ 'functionCall' => 'PHPExcel_Calculation_DateTime::DAYOFWEEK',
2003
+ 'argumentCount' => '1,2'
2004
+ ),
2005
+ 'WEEKNUM' => array(
2006
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
2007
+ 'functionCall' => 'PHPExcel_Calculation_DateTime::WEEKOFYEAR',
2008
+ 'argumentCount' => '1,2'
2009
+ ),
2010
+ 'WEIBULL' => array(
2011
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
2012
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::WEIBULL',
2013
+ 'argumentCount' => '4'
2014
+ ),
2015
+ 'WORKDAY' => array(
2016
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
2017
+ 'functionCall' => 'PHPExcel_Calculation_DateTime::WORKDAY',
2018
+ 'argumentCount' => '2+'
2019
+ ),
2020
+ 'XIRR' => array(
2021
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
2022
+ 'functionCall' => 'PHPExcel_Calculation_Financial::XIRR',
2023
+ 'argumentCount' => '2,3'
2024
+ ),
2025
+ 'XNPV' => array(
2026
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
2027
+ 'functionCall' => 'PHPExcel_Calculation_Financial::XNPV',
2028
+ 'argumentCount' => '3'
2029
+ ),
2030
+ 'YEAR' => array(
2031
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
2032
+ 'functionCall' => 'PHPExcel_Calculation_DateTime::YEAR',
2033
+ 'argumentCount' => '1'
2034
+ ),
2035
+ 'YEARFRAC' => array(
2036
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_DATE_AND_TIME,
2037
+ 'functionCall' => 'PHPExcel_Calculation_DateTime::YEARFRAC',
2038
+ 'argumentCount' => '2,3'
2039
+ ),
2040
+ 'YIELD' => array(
2041
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
2042
+ 'functionCall' => 'PHPExcel_Calculation_Functions::DUMMY',
2043
+ 'argumentCount' => '6,7'
2044
+ ),
2045
+ 'YIELDDISC' => array(
2046
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
2047
+ 'functionCall' => 'PHPExcel_Calculation_Financial::YIELDDISC',
2048
+ 'argumentCount' => '4,5'
2049
+ ),
2050
+ 'YIELDMAT' => array(
2051
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_FINANCIAL,
2052
+ 'functionCall' => 'PHPExcel_Calculation_Financial::YIELDMAT',
2053
+ 'argumentCount' => '5,6'
2054
+ ),
2055
+ 'ZTEST' => array(
2056
+ 'category' => PHPExcel_Calculation_Function::CATEGORY_STATISTICAL,
2057
+ 'functionCall' => 'PHPExcel_Calculation_Statistical::ZTEST',
2058
+ 'argumentCount' => '2-3'
2059
+ )
2060
+ );
2061
+
2062
+ // Internal functions used for special control purposes
2063
+ private static $controlFunctions = array(
2064
+ 'MKMATRIX' => array(
2065
+ 'argumentCount' => '*',
2066
+ 'functionCall' => 'self::mkMatrix'
2067
+ )
2068
+ );
2069
+
2070
+
2071
+ public function __construct(PHPExcel $workbook = null)
2072
+ {
2073
+ $this->delta = 1 * pow(10, 0 - ini_get('precision'));
2074
+
2075
+ $this->workbook = $workbook;
2076
+ $this->cyclicReferenceStack = new PHPExcel_CalcEngine_CyclicReferenceStack();
2077
+ $this->_debugLog = new PHPExcel_CalcEngine_Logger($this->cyclicReferenceStack);
2078
+ }
2079
+
2080
+
2081
+ private static function loadLocales()
2082
+ {
2083
+ $localeFileDirectory = PHPEXCEL_ROOT.'PHPExcel/locale/';
2084
+ foreach (glob($localeFileDirectory.'/*', GLOB_ONLYDIR) as $filename) {
2085
+ $filename = substr($filename, strlen($localeFileDirectory)+1);
2086
+ if ($filename != 'en') {
2087
+ self::$validLocaleLanguages[] = $filename;
2088
+ }
2089
+ }
2090
+ }
2091
+
2092
+ /**
2093
+ * Get an instance of this class
2094
+ *
2095
+ * @access public
2096
+ * @param PHPExcel $workbook Injected workbook for working with a PHPExcel object,
2097
+ * or NULL to create a standalone claculation engine
2098
+ * @return PHPExcel_Calculation
2099
+ */
2100
+ public static function getInstance(PHPExcel $workbook = null)
2101
+ {
2102
+ if ($workbook !== null) {
2103
+ $instance = $workbook->getCalculationEngine();
2104
+ if (isset($instance)) {
2105
+ return $instance;
2106
+ }
2107
+ }
2108
+
2109
+ if (!isset(self::$instance) || (self::$instance === null)) {
2110
+ self::$instance = new PHPExcel_Calculation();
2111
+ }
2112
+ return self::$instance;
2113
+ }
2114
+
2115
+ /**
2116
+ * Unset an instance of this class
2117
+ *
2118
+ * @access public
2119
+ */
2120
+ public function __destruct()
2121
+ {
2122
+ $this->workbook = null;
2123
+ }
2124
+
2125
+ /**
2126
+ * Flush the calculation cache for any existing instance of this class
2127
+ * but only if a PHPExcel_Calculation instance exists
2128
+ *
2129
+ * @access public
2130
+ * @return null
2131
+ */
2132
+ public function flushInstance()
2133
+ {
2134
+ $this->clearCalculationCache();
2135
+ }
2136
+
2137
+
2138
+ /**
2139
+ * Get the debuglog for this claculation engine instance
2140
+ *
2141
+ * @access public
2142
+ * @return PHPExcel_CalcEngine_Logger
2143
+ */
2144
+ public function getDebugLog()
2145
+ {
2146
+ return $this->_debugLog;
2147
+ }
2148
+
2149
+ /**
2150
+ * __clone implementation. Cloning should not be allowed in a Singleton!
2151
+ *
2152
+ * @access public
2153
+ * @throws PHPExcel_Calculation_Exception
2154
+ */
2155
+ final public function __clone()
2156
+ {
2157
+ throw new PHPExcel_Calculation_Exception('Cloning the calculation engine is not allowed!');
2158
+ }
2159
+
2160
+
2161
+ /**
2162
+ * Return the locale-specific translation of TRUE
2163
+ *
2164
+ * @access public
2165
+ * @return string locale-specific translation of TRUE
2166
+ */
2167
+ public static function getTRUE()
2168
+ {
2169
+ return self::$localeBoolean['TRUE'];
2170
+ }
2171
+
2172
+ /**
2173
+ * Return the locale-specific translation of FALSE
2174
+ *
2175
+ * @access public
2176
+ * @return string locale-specific translation of FALSE
2177
+ */
2178
+ public static function getFALSE()
2179
+ {
2180
+ return self::$localeBoolean['FALSE'];
2181
+ }
2182
+
2183
+ /**
2184
+ * Set the Array Return Type (Array or Value of first element in the array)
2185
+ *
2186
+ * @access public
2187
+ * @param string $returnType Array return type
2188
+ * @return boolean Success or failure
2189
+ */
2190
+ public static function setArrayReturnType($returnType)
2191
+ {
2192
+ if (($returnType == self::RETURN_ARRAY_AS_VALUE) ||
2193
+ ($returnType == self::RETURN_ARRAY_AS_ERROR) ||
2194
+ ($returnType == self::RETURN_ARRAY_AS_ARRAY)) {
2195
+ self::$returnArrayAsType = $returnType;
2196
+ return true;
2197
+ }
2198
+ return false;
2199
+ }
2200
+
2201
+
2202
+ /**
2203
+ * Return the Array Return Type (Array or Value of first element in the array)
2204
+ *
2205
+ * @access public
2206
+ * @return string $returnType Array return type
2207
+ */
2208
+ public static function getArrayReturnType()
2209
+ {
2210
+ return self::$returnArrayAsType;
2211
+ }
2212
+
2213
+
2214
+ /**
2215
+ * Is calculation caching enabled?
2216
+ *
2217
+ * @access public
2218
+ * @return boolean
2219
+ */
2220
+ public function getCalculationCacheEnabled()
2221
+ {
2222
+ return $this->calculationCacheEnabled;
2223
+ }
2224
+
2225
+ /**
2226
+ * Enable/disable calculation cache
2227
+ *
2228
+ * @access public
2229
+ * @param boolean $pValue
2230
+ */
2231
+ public function setCalculationCacheEnabled($pValue = true)
2232
+ {
2233
+ $this->calculationCacheEnabled = $pValue;
2234
+ $this->clearCalculationCache();
2235
+ }
2236
+
2237
+
2238
+ /**
2239
+ * Enable calculation cache
2240
+ */
2241
+ public function enableCalculationCache()
2242
+ {
2243
+ $this->setCalculationCacheEnabled(true);
2244
+ }
2245
+
2246
+
2247
+ /**
2248
+ * Disable calculation cache
2249
+ */
2250
+ public function disableCalculationCache()
2251
+ {
2252
+ $this->setCalculationCacheEnabled(false);
2253
+ }
2254
+
2255
+
2256
+ /**
2257
+ * Clear calculation cache
2258
+ */
2259
+ public function clearCalculationCache()
2260
+ {
2261
+ $this->calculationCache = array();
2262
+ }
2263
+
2264
+ /**
2265
+ * Clear calculation cache for a specified worksheet
2266
+ *
2267
+ * @param string $worksheetName
2268
+ */
2269
+ public function clearCalculationCacheForWorksheet($worksheetName)
2270
+ {
2271
+ if (isset($this->calculationCache[$worksheetName])) {
2272
+ unset($this->calculationCache[$worksheetName]);
2273
+ }
2274
+ }
2275
+
2276
+ /**
2277
+ * Rename calculation cache for a specified worksheet
2278
+ *
2279
+ * @param string $fromWorksheetName
2280
+ * @param string $toWorksheetName
2281
+ */
2282
+ public function renameCalculationCacheForWorksheet($fromWorksheetName, $toWorksheetName)
2283
+ {
2284
+ if (isset($this->calculationCache[$fromWorksheetName])) {
2285
+ $this->calculationCache[$toWorksheetName] = &$this->calculationCache[$fromWorksheetName];
2286
+ unset($this->calculationCache[$fromWorksheetName]);
2287
+ }
2288
+ }
2289
+
2290
+
2291
+ /**
2292
+ * Get the currently defined locale code
2293
+ *
2294
+ * @return string
2295
+ */
2296
+ public function getLocale()
2297
+ {
2298
+ return self::$localeLanguage;
2299
+ }
2300
+
2301
+
2302
+ /**
2303
+ * Set the locale code
2304
+ *
2305
+ * @param string $locale The locale to use for formula translation
2306
+ * @return boolean
2307
+ */
2308
+ public function setLocale($locale = 'en_us')
2309
+ {
2310
+ // Identify our locale and language
2311
+ $language = $locale = strtolower($locale);
2312
+ if (strpos($locale, '_') !== false) {
2313
+ list($language) = explode('_', $locale);
2314
+ }
2315
+
2316
+ if (count(self::$validLocaleLanguages) == 1) {
2317
+ self::loadLocales();
2318
+ }
2319
+ // Test whether we have any language data for this language (any locale)
2320
+ if (in_array($language, self::$validLocaleLanguages)) {
2321
+ // initialise language/locale settings
2322
+ self::$localeFunctions = array();
2323
+ self::$localeArgumentSeparator = ',';
2324
+ self::$localeBoolean = array('TRUE' => 'TRUE', 'FALSE' => 'FALSE', 'NULL' => 'NULL');
2325
+ // Default is English, if user isn't requesting english, then read the necessary data from the locale files
2326
+ if ($locale != 'en_us') {
2327
+ // Search for a file with a list of function names for locale
2328
+ $functionNamesFile = PHPEXCEL_ROOT . 'PHPExcel'.DIRECTORY_SEPARATOR.'locale'.DIRECTORY_SEPARATOR.str_replace('_', DIRECTORY_SEPARATOR, $locale).DIRECTORY_SEPARATOR.'functions';
2329
+ if (!file_exists($functionNamesFile)) {
2330
+ // If there isn't a locale specific function file, look for a language specific function file
2331
+ $functionNamesFile = PHPEXCEL_ROOT . 'PHPExcel'.DIRECTORY_SEPARATOR.'locale'.DIRECTORY_SEPARATOR.$language.DIRECTORY_SEPARATOR.'functions';
2332
+ if (!file_exists($functionNamesFile)) {
2333
+ return false;
2334
+ }
2335
+ }
2336
+ // Retrieve the list of locale or language specific function names
2337
+ $localeFunctions = file($functionNamesFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
2338
+ foreach ($localeFunctions as $localeFunction) {
2339
+ list($localeFunction) = explode('##', $localeFunction); // Strip out comments
2340
+ if (strpos($localeFunction, '=') !== false) {
2341
+ list($fName, $lfName) = explode('=', $localeFunction);
2342
+ $fName = trim($fName);
2343
+ $lfName = trim($lfName);
2344
+ if ((isset(self::$PHPExcelFunctions[$fName])) && ($lfName != '') && ($fName != $lfName)) {
2345
+ self::$localeFunctions[$fName] = $lfName;
2346
+ }
2347
+ }
2348
+ }
2349
+ // Default the TRUE and FALSE constants to the locale names of the TRUE() and FALSE() functions
2350
+ if (isset(self::$localeFunctions['TRUE'])) {
2351
+ self::$localeBoolean['TRUE'] = self::$localeFunctions['TRUE'];
2352
+ }
2353
+ if (isset(self::$localeFunctions['FALSE'])) {
2354
+ self::$localeBoolean['FALSE'] = self::$localeFunctions['FALSE'];
2355
+ }
2356
+
2357
+ $configFile = PHPEXCEL_ROOT . 'PHPExcel'.DIRECTORY_SEPARATOR.'locale'.DIRECTORY_SEPARATOR.str_replace('_', DIRECTORY_SEPARATOR, $locale).DIRECTORY_SEPARATOR.'config';
2358
+ if (!file_exists($configFile)) {
2359
+ $configFile = PHPEXCEL_ROOT . 'PHPExcel'.DIRECTORY_SEPARATOR.'locale'.DIRECTORY_SEPARATOR.$language.DIRECTORY_SEPARATOR.'config';
2360
+ }
2361
+ if (file_exists($configFile)) {
2362
+ $localeSettings = file($configFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
2363
+ foreach ($localeSettings as $localeSetting) {
2364
+ list($localeSetting) = explode('##', $localeSetting); // Strip out comments
2365
+ if (strpos($localeSetting, '=') !== false) {
2366
+ list($settingName, $settingValue) = explode('=', $localeSetting);
2367
+ $settingName = strtoupper(trim($settingName));
2368
+ switch ($settingName) {
2369
+ case 'ARGUMENTSEPARATOR':
2370
+ self::$localeArgumentSeparator = trim($settingValue);
2371
+ break;
2372
+ }
2373
+ }
2374
+ }
2375
+ }
2376
+ }
2377
+
2378
+ self::$functionReplaceFromExcel = self::$functionReplaceToExcel =
2379
+ self::$functionReplaceFromLocale = self::$functionReplaceToLocale = null;
2380
+ self::$localeLanguage = $locale;
2381
+ return true;
2382
+ }
2383
+ return false;
2384
+ }
2385
+
2386
+
2387
+
2388
+ public static function translateSeparator($fromSeparator, $toSeparator, $formula, &$inBraces)
2389
+ {
2390
+ $strlen = mb_strlen($formula);
2391
+ for ($i = 0; $i < $strlen; ++$i) {
2392
+ $chr = mb_substr($formula, $i, 1);
2393
+ switch ($chr) {
2394
+ case '{':
2395
+ $inBraces = true;
2396
+ break;
2397
+ case '}':
2398
+ $inBraces = false;
2399
+ break;
2400
+ case $fromSeparator:
2401
+ if (!$inBraces) {
2402
+ $formula = mb_substr($formula, 0, $i).$toSeparator.mb_substr($formula, $i+1);
2403
+ }
2404
+ }
2405
+ }
2406
+ return $formula;
2407
+ }
2408
+
2409
+ private static function translateFormula($from, $to, $formula, $fromSeparator, $toSeparator)
2410
+ {
2411
+ // Convert any Excel function names to the required language
2412
+ if (self::$localeLanguage !== 'en_us') {
2413
+ $inBraces = false;
2414
+ // If there is the possibility of braces within a quoted string, then we don't treat those as matrix indicators
2415
+ if (strpos($formula, '"') !== false) {
2416
+ // So instead we skip replacing in any quoted strings by only replacing in every other array element after we've exploded
2417
+ // the formula
2418
+ $temp = explode('"', $formula);
2419
+ $i = false;
2420
+ foreach ($temp as &$value) {
2421
+ // Only count/replace in alternating array entries
2422
+ if ($i = !$i) {
2423
+ $value = preg_replace($from, $to, $value);
2424
+ $value = self::translateSeparator($fromSeparator, $toSeparator, $value, $inBraces);
2425
+ }
2426
+ }
2427
+ unset($value);
2428
+ // Then rebuild the formula string
2429
+ $formula = implode('"', $temp);
2430
+ } else {
2431
+ // If there's no quoted strings, then we do a simple count/replace
2432
+ $formula = preg_replace($from, $to, $formula);
2433
+ $formula = self::translateSeparator($fromSeparator, $toSeparator, $formula, $inBraces);
2434
+ }
2435
+ }
2436
+
2437
+ return $formula;
2438
+ }
2439
+
2440
+ private static $functionReplaceFromExcel = null;
2441
+ private static $functionReplaceToLocale = null;
2442
+
2443
+ public function _translateFormulaToLocale($formula)
2444
+ {
2445
+ if (self::$functionReplaceFromExcel === null) {
2446
+ self::$functionReplaceFromExcel = array();
2447
+ foreach (array_keys(self::$localeFunctions) as $excelFunctionName) {
2448
+ self::$functionReplaceFromExcel[] = '/(@?[^\w\.])'.preg_quote($excelFunctionName).'([\s]*\()/Ui';
2449
+ }
2450
+ foreach (array_keys(self::$localeBoolean) as $excelBoolean) {
2451
+ self::$functionReplaceFromExcel[] = '/(@?[^\w\.])'.preg_quote($excelBoolean).'([^\w\.])/Ui';
2452
+ }
2453
+
2454
+ }
2455
+
2456
+ if (self::$functionReplaceToLocale === null) {
2457
+ self::$functionReplaceToLocale = array();
2458
+ foreach (array_values(self::$localeFunctions) as $localeFunctionName) {
2459
+ self::$functionReplaceToLocale[] = '$1'.trim($localeFunctionName).'$2';
2460
+ }
2461
+ foreach (array_values(self::$localeBoolean) as $localeBoolean) {
2462
+ self::$functionReplaceToLocale[] = '$1'.trim($localeBoolean).'$2';
2463
+ }
2464
+ }
2465
+
2466
+ return self::translateFormula(self::$functionReplaceFromExcel, self::$functionReplaceToLocale, $formula, ',', self::$localeArgumentSeparator);
2467
+ }
2468
+
2469
+
2470
+ private static $functionReplaceFromLocale = null;
2471
+ private static $functionReplaceToExcel = null;
2472
+
2473
+ public function _translateFormulaToEnglish($formula)
2474
+ {
2475
+ if (self::$functionReplaceFromLocale === null) {
2476
+ self::$functionReplaceFromLocale = array();
2477
+ foreach (array_values(self::$localeFunctions) as $localeFunctionName) {
2478
+ self::$functionReplaceFromLocale[] = '/(@?[^\w\.])'.preg_quote($localeFunctionName).'([\s]*\()/Ui';
2479
+ }
2480
+ foreach (array_values(self::$localeBoolean) as $excelBoolean) {
2481
+ self::$functionReplaceFromLocale[] = '/(@?[^\w\.])'.preg_quote($excelBoolean).'([^\w\.])/Ui';
2482
+ }
2483
+ }
2484
+
2485
+ if (self::$functionReplaceToExcel === null) {
2486
+ self::$functionReplaceToExcel = array();
2487
+ foreach (array_keys(self::$localeFunctions) as $excelFunctionName) {
2488
+ self::$functionReplaceToExcel[] = '$1'.trim($excelFunctionName).'$2';
2489
+ }
2490
+ foreach (array_keys(self::$localeBoolean) as $excelBoolean) {
2491
+ self::$functionReplaceToExcel[] = '$1'.trim($excelBoolean).'$2';
2492
+ }
2493
+ }
2494
+
2495
+ return self::translateFormula(self::$functionReplaceFromLocale, self::$functionReplaceToExcel, $formula, self::$localeArgumentSeparator, ',');
2496
+ }
2497
+
2498
+
2499
+ public static function localeFunc($function)
2500
+ {
2501
+ if (self::$localeLanguage !== 'en_us') {
2502
+ $functionName = trim($function, '(');
2503
+ if (isset(self::$localeFunctions[$functionName])) {
2504
+ $brace = ($functionName != $function);
2505
+ $function = self::$localeFunctions[$functionName];
2506
+ if ($brace) {
2507
+ $function .= '(';
2508
+ }
2509
+ }
2510
+ }
2511
+ return $function;
2512
+ }
2513
+
2514
+
2515
+
2516
+
2517
+ /**
2518
+ * Wrap string values in quotes
2519
+ *
2520
+ * @param mixed $value
2521
+ * @return mixed
2522
+ */
2523
+ public static function wrapResult($value)
2524
+ {
2525
+ if (is_string($value)) {
2526
+ // Error values cannot be "wrapped"
2527
+ if (preg_match('/^'.self::CALCULATION_REGEXP_ERROR.'$/i', $value, $match)) {
2528
+ // Return Excel errors "as is"
2529
+ return $value;
2530
+ }
2531
+ // Return strings wrapped in quotes
2532
+ return '"'.$value.'"';
2533
+ // Convert numeric errors to NaN error
2534
+ } elseif ((is_float($value)) && ((is_nan($value)) || (is_infinite($value)))) {
2535
+ return PHPExcel_Calculation_Functions::NaN();
2536
+ }
2537
+
2538
+ return $value;
2539
+ }
2540
+
2541
+
2542
+ /**
2543
+ * Remove quotes used as a wrapper to identify string values
2544
+ *
2545
+ * @param mixed $value
2546
+ * @return mixed
2547
+ */
2548
+ public static function unwrapResult($value)
2549
+ {
2550
+ if (is_string($value)) {
2551
+ if ((isset($value{0})) && ($value{0} == '"') && (substr($value, -1) == '"')) {
2552
+ return substr($value, 1, -1);
2553
+ }
2554
+ // Convert numeric errors to NaN error
2555
+ } elseif ((is_float($value)) && ((is_nan($value)) || (is_infinite($value)))) {
2556
+ return PHPExcel_Calculation_Functions::NaN();
2557
+ }
2558
+ return $value;
2559
+ }
2560
+
2561
+
2562
+
2563
+
2564
+ /**
2565
+ * Calculate cell value (using formula from a cell ID)
2566
+ * Retained for backward compatibility
2567
+ *
2568
+ * @access public
2569
+ * @param PHPExcel_Cell $pCell Cell to calculate
2570
+ * @return mixed
2571
+ * @throws PHPExcel_Calculation_Exception
2572
+ */
2573
+ public function calculate(PHPExcel_Cell $pCell = null)
2574
+ {
2575
+ try {
2576
+ return $this->calculateCellValue($pCell);
2577
+ } catch (PHPExcel_Exception $e) {
2578
+ throw new PHPExcel_Calculation_Exception($e->getMessage());
2579
+ }
2580
+ }
2581
+
2582
+
2583
+ /**
2584
+ * Calculate the value of a cell formula
2585
+ *
2586
+ * @access public
2587
+ * @param PHPExcel_Cell $pCell Cell to calculate
2588
+ * @param Boolean $resetLog Flag indicating whether the debug log should be reset or not
2589
+ * @return mixed
2590
+ * @throws PHPExcel_Calculation_Exception
2591
+ */
2592
+ public function calculateCellValue(PHPExcel_Cell $pCell = null, $resetLog = true)
2593
+ {
2594
+ if ($pCell === null) {
2595
+ return null;
2596
+ }
2597
+
2598
+ $returnArrayAsType = self::$returnArrayAsType;
2599
+ if ($resetLog) {
2600
+ // Initialise the logging settings if requested
2601
+ $this->formulaError = null;
2602
+ $this->_debugLog->clearLog();
2603
+ $this->cyclicReferenceStack->clear();
2604
+ $this->cyclicFormulaCounter = 1;
2605
+
2606
+ self::$returnArrayAsType = self::RETURN_ARRAY_AS_ARRAY;
2607
+ }
2608
+
2609
+ // Execute the calculation for the cell formula
2610
+ $this->cellStack[] = array(
2611
+ 'sheet' => $pCell->getWorksheet()->getTitle(),
2612
+ 'cell' => $pCell->getCoordinate(),
2613
+ );
2614
+ try {
2615
+ $result = self::unwrapResult($this->_calculateFormulaValue($pCell->getValue(), $pCell->getCoordinate(), $pCell));
2616
+ $cellAddress = array_pop($this->cellStack);
2617
+ $this->workbook->getSheetByName($cellAddress['sheet'])->getCell($cellAddress['cell']);
2618
+ } catch (PHPExcel_Exception $e) {
2619
+ $cellAddress = array_pop($this->cellStack);
2620
+ $this->workbook->getSheetByName($cellAddress['sheet'])->getCell($cellAddress['cell']);
2621
+ throw new PHPExcel_Calculation_Exception($e->getMessage());
2622
+ }
2623
+
2624
+ if ((is_array($result)) && (self::$returnArrayAsType != self::RETURN_ARRAY_AS_ARRAY)) {
2625
+ self::$returnArrayAsType = $returnArrayAsType;
2626
+ $testResult = PHPExcel_Calculation_Functions::flattenArray($result);
2627
+ if (self::$returnArrayAsType == self::RETURN_ARRAY_AS_ERROR) {
2628
+ return PHPExcel_Calculation_Functions::VALUE();
2629
+ }
2630
+ // If there's only a single cell in the array, then we allow it
2631
+ if (count($testResult) != 1) {
2632
+ // If keys are numeric, then it's a matrix result rather than a cell range result, so we permit it
2633
+ $r = array_keys($result);
2634
+ $r = array_shift($r);
2635
+ if (!is_numeric($r)) {
2636
+ return PHPExcel_Calculation_Functions::VALUE();
2637
+ }
2638
+ if (is_array($result[$r])) {
2639
+ $c = array_keys($result[$r]);
2640
+ $c = array_shift($c);
2641
+ if (!is_numeric($c)) {
2642
+ return PHPExcel_Calculation_Functions::VALUE();
2643
+ }
2644
+ }
2645
+ }
2646
+ $result = array_shift($testResult);
2647
+ }
2648
+ self::$returnArrayAsType = $returnArrayAsType;
2649
+
2650
+
2651
+ if ($result === null) {
2652
+ return 0;
2653
+ } elseif ((is_float($result)) && ((is_nan($result)) || (is_infinite($result)))) {
2654
+ return PHPExcel_Calculation_Functions::NaN();
2655
+ }
2656
+ return $result;
2657
+ }
2658
+
2659
+
2660
+ /**
2661
+ * Validate and parse a formula string
2662
+ *
2663
+ * @param string $formula Formula to parse
2664
+ * @return array
2665
+ * @throws PHPExcel_Calculation_Exception
2666
+ */
2667
+ public function parseFormula($formula)
2668
+ {
2669
+ // Basic validation that this is indeed a formula
2670
+ // We return an empty array if not
2671
+ $formula = trim($formula);
2672
+ if ((!isset($formula{0})) || ($formula{0} != '=')) {
2673
+ return array();
2674
+ }
2675
+ $formula = ltrim(substr($formula, 1));
2676
+ if (!isset($formula{0})) {
2677
+ return array();
2678
+ }
2679
+
2680
+ // Parse the formula and return the token stack
2681
+ return $this->_parseFormula($formula);
2682
+ }
2683
+
2684
+
2685
+ /**
2686
+ * Calculate the value of a formula
2687
+ *
2688
+ * @param string $formula Formula to parse
2689
+ * @param string $cellID Address of the cell to calculate
2690
+ * @param PHPExcel_Cell $pCell Cell to calculate
2691
+ * @return mixed
2692
+ * @throws PHPExcel_Calculation_Exception
2693
+ */
2694
+ public function calculateFormula($formula, $cellID = null, PHPExcel_Cell $pCell = null)
2695
+ {
2696
+ // Initialise the logging settings
2697
+ $this->formulaError = null;
2698
+ $this->_debugLog->clearLog();
2699
+ $this->cyclicReferenceStack->clear();
2700
+
2701
+ if ($this->workbook !== null && $cellID === null && $pCell === null) {
2702
+ $cellID = 'A1';
2703
+ $pCell = $this->workbook->getActiveSheet()->getCell($cellID);
2704
+ } else {
2705
+ // Disable calculation cacheing because it only applies to cell calculations, not straight formulae
2706
+ // But don't actually flush any cache
2707
+ $resetCache = $this->getCalculationCacheEnabled();
2708
+ $this->calculationCacheEnabled = false;
2709
+ }
2710
+
2711
+ // Execute the calculation
2712
+ try {
2713
+ $result = self::unwrapResult($this->_calculateFormulaValue($formula, $cellID, $pCell));
2714
+ } catch (PHPExcel_Exception $e) {
2715
+ throw new PHPExcel_Calculation_Exception($e->getMessage());
2716
+ }
2717
+
2718
+ if ($this->workbook === null) {
2719
+ // Reset calculation cacheing to its previous state
2720
+ $this->calculationCacheEnabled = $resetCache;
2721
+ }
2722
+
2723
+ return $result;
2724
+ }
2725
+
2726
+
2727
+ public function getValueFromCache($cellReference, &$cellValue)
2728
+ {
2729
+ // Is calculation cacheing enabled?
2730
+ // Is the value present in calculation cache?
2731
+ $this->_debugLog->writeDebugLog('Testing cache value for cell ', $cellReference);
2732
+ if (($this->calculationCacheEnabled) && (isset($this->calculationCache[$cellReference]))) {
2733
+ $this->_debugLog->writeDebugLog('Retrieving value for cell ', $cellReference, ' from cache');
2734
+ // Return the cached result
2735
+ $cellValue = $this->calculationCache[$cellReference];
2736
+ return true;
2737
+ }
2738
+ return false;
2739
+ }
2740
+
2741
+ public function saveValueToCache($cellReference, $cellValue)
2742
+ {
2743
+ if ($this->calculationCacheEnabled) {
2744
+ $this->calculationCache[$cellReference] = $cellValue;
2745
+ }
2746
+ }
2747
+
2748
+ /**
2749
+ * Parse a cell formula and calculate its value
2750
+ *
2751
+ * @param string $formula The formula to parse and calculate
2752
+ * @param string $cellID The ID (e.g. A3) of the cell that we are calculating
2753
+ * @param PHPExcel_Cell $pCell Cell to calculate
2754
+ * @return mixed
2755
+ * @throws PHPExcel_Calculation_Exception
2756
+ */
2757
+ public function _calculateFormulaValue($formula, $cellID = null, PHPExcel_Cell $pCell = null)
2758
+ {
2759
+ $cellValue = null;
2760
+
2761
+ // Basic validation that this is indeed a formula
2762
+ // We simply return the cell value if not
2763
+ $formula = trim($formula);
2764
+ if ($formula{0} != '=') {
2765
+ return self::wrapResult($formula);
2766
+ }
2767
+ $formula = ltrim(substr($formula, 1));
2768
+ if (!isset($formula{0})) {
2769
+ return self::wrapResult($formula);
2770
+ }
2771
+
2772
+ $pCellParent = ($pCell !== null) ? $pCell->getWorksheet() : null;
2773
+ $wsTitle = ($pCellParent !== null) ? $pCellParent->getTitle() : "\x00Wrk";
2774
+ $wsCellReference = $wsTitle . '!' . $cellID;
2775
+
2776
+ if (($cellID !== null) && ($this->getValueFromCache($wsCellReference, $cellValue))) {
2777
+ return $cellValue;
2778
+ }
2779
+
2780
+ if (($wsTitle{0} !== "\x00") && ($this->cyclicReferenceStack->onStack($wsCellReference))) {
2781
+ if ($this->cyclicFormulaCount <= 0) {
2782
+ $this->cyclicFormulaCell = '';
2783
+ return $this->raiseFormulaError('Cyclic Reference in Formula');
2784
+ } elseif ($this->cyclicFormulaCell === $wsCellReference) {
2785
+ ++$this->cyclicFormulaCounter;
2786
+ if ($this->cyclicFormulaCounter >= $this->cyclicFormulaCount) {
2787
+ $this->cyclicFormulaCell = '';
2788
+ return $cellValue;
2789
+ }
2790
+ } elseif ($this->cyclicFormulaCell == '') {
2791
+ if ($this->cyclicFormulaCounter >= $this->cyclicFormulaCount) {
2792
+ return $cellValue;
2793
+ }
2794
+ $this->cyclicFormulaCell = $wsCellReference;
2795
+ }
2796
+ }
2797
+
2798
+ // Parse the formula onto the token stack and calculate the value
2799
+ $this->cyclicReferenceStack->push($wsCellReference);
2800
+ $cellValue = $this->processTokenStack($this->_parseFormula($formula, $pCell), $cellID, $pCell);
2801
+ $this->cyclicReferenceStack->pop();
2802
+
2803
+ // Save to calculation cache
2804
+ if ($cellID !== null) {
2805
+ $this->saveValueToCache($wsCellReference, $cellValue);
2806
+ }
2807
+
2808
+ // Return the calculated value
2809
+ return $cellValue;
2810
+ }
2811
+
2812
+
2813
+ /**
2814
+ * Ensure that paired matrix operands are both matrices and of the same size
2815
+ *
2816
+ * @param mixed &$operand1 First matrix operand
2817
+ * @param mixed &$operand2 Second matrix operand
2818
+ * @param integer $resize Flag indicating whether the matrices should be resized to match
2819
+ * and (if so), whether the smaller dimension should grow or the
2820
+ * larger should shrink.
2821
+ * 0 = no resize
2822
+ * 1 = shrink to fit
2823
+ * 2 = extend to fit
2824
+ */
2825
+ private static function checkMatrixOperands(&$operand1, &$operand2, $resize = 1)
2826
+ {
2827
+ // Examine each of the two operands, and turn them into an array if they aren't one already
2828
+ // Note that this function should only be called if one or both of the operand is already an array
2829
+ if (!is_array($operand1)) {
2830
+ list($matrixRows, $matrixColumns) = self::getMatrixDimensions($operand2);
2831
+ $operand1 = array_fill(0, $matrixRows, array_fill(0, $matrixColumns, $operand1));
2832
+ $resize = 0;
2833
+ } elseif (!is_array($operand2)) {
2834
+ list($matrixRows, $matrixColumns) = self::getMatrixDimensions($operand1);
2835
+ $operand2 = array_fill(0, $matrixRows, array_fill(0, $matrixColumns, $operand2));
2836
+ $resize = 0;
2837
+ }
2838
+
2839
+ list($matrix1Rows, $matrix1Columns) = self::getMatrixDimensions($operand1);
2840
+ list($matrix2Rows, $matrix2Columns) = self::getMatrixDimensions($operand2);
2841
+ if (($matrix1Rows == $matrix2Columns) && ($matrix2Rows == $matrix1Columns)) {
2842
+ $resize = 1;
2843
+ }
2844
+
2845
+ if ($resize == 2) {
2846
+ // Given two matrices of (potentially) unequal size, convert the smaller in each dimension to match the larger
2847
+ self::resizeMatricesExtend($operand1, $operand2, $matrix1Rows, $matrix1Columns, $matrix2Rows, $matrix2Columns);
2848
+ } elseif ($resize == 1) {
2849
+ // Given two matrices of (potentially) unequal size, convert the larger in each dimension to match the smaller
2850
+ self::resizeMatricesShrink($operand1, $operand2, $matrix1Rows, $matrix1Columns, $matrix2Rows, $matrix2Columns);
2851
+ }
2852
+ return array( $matrix1Rows, $matrix1Columns, $matrix2Rows, $matrix2Columns);
2853
+ }
2854
+
2855
+
2856
+ /**
2857
+ * Read the dimensions of a matrix, and re-index it with straight numeric keys starting from row 0, column 0
2858
+ *
2859
+ * @param mixed &$matrix matrix operand
2860
+ * @return array An array comprising the number of rows, and number of columns
2861
+ */
2862
+ private static function getMatrixDimensions(&$matrix)
2863
+ {
2864
+ $matrixRows = count($matrix);
2865
+ $matrixColumns = 0;
2866
+ foreach ($matrix as $rowKey => $rowValue) {
2867
+ $matrixColumns = max(count($rowValue), $matrixColumns);
2868
+ if (!is_array($rowValue)) {
2869
+ $matrix[$rowKey] = array($rowValue);
2870
+ } else {
2871
+ $matrix[$rowKey] = array_values($rowValue);
2872
+ }
2873
+ }
2874
+ $matrix = array_values($matrix);
2875
+ return array($matrixRows, $matrixColumns);
2876
+ }
2877
+
2878
+
2879
+ /**
2880
+ * Ensure that paired matrix operands are both matrices of the same size
2881
+ *
2882
+ * @param mixed &$matrix1 First matrix operand
2883
+ * @param mixed &$matrix2 Second matrix operand
2884
+ * @param integer $matrix1Rows Row size of first matrix operand
2885
+ * @param integer $matrix1Columns Column size of first matrix operand
2886
+ * @param integer $matrix2Rows Row size of second matrix operand
2887
+ * @param integer $matrix2Columns Column size of second matrix operand
2888
+ */
2889
+ private static function resizeMatricesShrink(&$matrix1, &$matrix2, $matrix1Rows, $matrix1Columns, $matrix2Rows, $matrix2Columns)
2890
+ {
2891
+ if (($matrix2Columns < $matrix1Columns) || ($matrix2Rows < $matrix1Rows)) {
2892
+ if ($matrix2Rows < $matrix1Rows) {
2893
+ for ($i = $matrix2Rows; $i < $matrix1Rows; ++$i) {
2894
+ unset($matrix1[$i]);
2895
+ }
2896
+ }
2897
+ if ($matrix2Columns < $matrix1Columns) {
2898
+ for ($i = 0; $i < $matrix1Rows; ++$i) {
2899
+ for ($j = $matrix2Columns; $j < $matrix1Columns; ++$j) {
2900
+ unset($matrix1[$i][$j]);
2901
+ }
2902
+ }
2903
+ }
2904
+ }
2905
+
2906
+ if (($matrix1Columns < $matrix2Columns) || ($matrix1Rows < $matrix2Rows)) {
2907
+ if ($matrix1Rows < $matrix2Rows) {
2908
+ for ($i = $matrix1Rows; $i < $matrix2Rows; ++$i) {
2909
+ unset($matrix2[$i]);
2910
+ }
2911
+ }
2912
+ if ($matrix1Columns < $matrix2Columns) {
2913
+ for ($i = 0; $i < $matrix2Rows; ++$i) {
2914
+ for ($j = $matrix1Columns; $j < $matrix2Columns; ++$j) {
2915
+ unset($matrix2[$i][$j]);
2916
+ }
2917
+ }
2918
+ }
2919
+ }
2920
+ }
2921
+
2922
+
2923
+ /**
2924
+ * Ensure that paired matrix operands are both matrices of the same size
2925
+ *
2926
+ * @param mixed &$matrix1 First matrix operand
2927
+ * @param mixed &$matrix2 Second matrix operand
2928
+ * @param integer $matrix1Rows Row size of first matrix operand
2929
+ * @param integer $matrix1Columns Column size of first matrix operand
2930
+ * @param integer $matrix2Rows Row size of second matrix operand
2931
+ * @param integer $matrix2Columns Column size of second matrix operand
2932
+ */
2933
+ private static function resizeMatricesExtend(&$matrix1, &$matrix2, $matrix1Rows, $matrix1Columns, $matrix2Rows, $matrix2Columns)
2934
+ {
2935
+ if (($matrix2Columns < $matrix1Columns) || ($matrix2Rows < $matrix1Rows)) {
2936
+ if ($matrix2Columns < $matrix1Columns) {
2937
+ for ($i = 0; $i < $matrix2Rows; ++$i) {
2938
+ $x = $matrix2[$i][$matrix2Columns-1];
2939
+ for ($j = $matrix2Columns; $j < $matrix1Columns; ++$j) {
2940
+ $matrix2[$i][$j] = $x;
2941
+ }
2942
+ }
2943
+ }
2944
+ if ($matrix2Rows < $matrix1Rows) {
2945
+ $x = $matrix2[$matrix2Rows-1];
2946
+ for ($i = 0; $i < $matrix1Rows; ++$i) {
2947
+ $matrix2[$i] = $x;
2948
+ }
2949
+ }
2950
+ }
2951
+
2952
+ if (($matrix1Columns < $matrix2Columns) || ($matrix1Rows < $matrix2Rows)) {
2953
+ if ($matrix1Columns < $matrix2Columns) {
2954
+ for ($i = 0; $i < $matrix1Rows; ++$i) {
2955
+ $x = $matrix1[$i][$matrix1Columns-1];
2956
+ for ($j = $matrix1Columns; $j < $matrix2Columns; ++$j) {
2957
+ $matrix1[$i][$j] = $x;
2958
+ }
2959
+ }
2960
+ }
2961
+ if ($matrix1Rows < $matrix2Rows) {
2962
+ $x = $matrix1[$matrix1Rows-1];
2963
+ for ($i = 0; $i < $matrix2Rows; ++$i) {
2964
+ $matrix1[$i] = $x;
2965
+ }
2966
+ }
2967
+ }
2968
+ }
2969
+
2970
+
2971
+ /**
2972
+ * Format details of an operand for display in the log (based on operand type)
2973
+ *
2974
+ * @param mixed $value First matrix operand
2975
+ * @return mixed
2976
+ */
2977
+ private function showValue($value)
2978
+ {
2979
+ if ($this->_debugLog->getWriteDebugLog()) {
2980
+ $testArray = PHPExcel_Calculation_Functions::flattenArray($value);
2981
+ if (count($testArray) == 1) {
2982
+ $value = array_pop($testArray);
2983
+ }
2984
+
2985
+ if (is_array($value)) {
2986
+ $returnMatrix = array();
2987
+ $pad = $rpad = ', ';
2988
+ foreach ($value as $row) {
2989
+ if (is_array($row)) {
2990
+ $returnMatrix[] = implode($pad, array_map(array($this, 'showValue'), $row));
2991
+ $rpad = '; ';
2992
+ } else {
2993
+ $returnMatrix[] = $this->showValue($row);
2994
+ }
2995
+ }
2996
+ return '{ '.implode($rpad, $returnMatrix).' }';
2997
+ } elseif (is_string($value) && (trim($value, '"') == $value)) {
2998
+ return '"'.$value.'"';
2999
+ } elseif (is_bool($value)) {
3000
+ return ($value) ? self::$localeBoolean['TRUE'] : self::$localeBoolean['FALSE'];
3001
+ }
3002
+ }
3003
+ return PHPExcel_Calculation_Functions::flattenSingleValue($value);
3004
+ }
3005
+
3006
+
3007
+ /**
3008
+ * Format type and details of an operand for display in the log (based on operand type)
3009
+ *
3010
+ * @param mixed $value First matrix operand
3011
+ * @return mixed
3012
+ */
3013
+ private function showTypeDetails($value)
3014
+ {
3015
+ if ($this->_debugLog->getWriteDebugLog()) {
3016
+ $testArray = PHPExcel_Calculation_Functions::flattenArray($value);
3017
+ if (count($testArray) == 1) {
3018
+ $value = array_pop($testArray);
3019
+ }
3020
+
3021
+ if ($value === null) {
3022
+ return 'a NULL value';
3023
+ } elseif (is_float($value)) {
3024
+ $typeString = 'a floating point number';
3025
+ } elseif (is_int($value)) {
3026
+ $typeString = 'an integer number';
3027
+ } elseif (is_bool($value)) {
3028
+ $typeString = 'a boolean';
3029
+ } elseif (is_array($value)) {
3030
+ $typeString = 'a matrix';
3031
+ } else {
3032
+ if ($value == '') {
3033
+ return 'an empty string';
3034
+ } elseif ($value{0} == '#') {
3035
+ return 'a '.$value.' error';
3036
+ } else {
3037
+ $typeString = 'a string';
3038
+ }
3039
+ }
3040
+ return $typeString.' with a value of '.$this->showValue($value);
3041
+ }
3042
+ }
3043
+
3044
+
3045
+ private function convertMatrixReferences($formula)
3046
+ {
3047
+ static $matrixReplaceFrom = array('{', ';', '}');
3048
+ static $matrixReplaceTo = array('MKMATRIX(MKMATRIX(', '),MKMATRIX(', '))');
3049
+
3050
+ // Convert any Excel matrix references to the MKMATRIX() function
3051
+ if (strpos($formula, '{') !== false) {
3052
+ // If there is the possibility of braces within a quoted string, then we don't treat those as matrix indicators
3053
+ if (strpos($formula, '"') !== false) {
3054
+ // So instead we skip replacing in any quoted strings by only replacing in every other array element after we've exploded
3055
+ // the formula
3056
+ $temp = explode('"', $formula);
3057
+ // Open and Closed counts used for trapping mismatched braces in the formula
3058
+ $openCount = $closeCount = 0;
3059
+ $i = false;
3060
+ foreach ($temp as &$value) {
3061
+ // Only count/replace in alternating array entries
3062
+ if ($i = !$i) {
3063
+ $openCount += substr_count($value, '{');
3064
+ $closeCount += substr_count($value, '}');
3065
+ $value = str_replace($matrixReplaceFrom, $matrixReplaceTo, $value);
3066
+ }
3067
+ }
3068
+ unset($value);
3069
+ // Then rebuild the formula string
3070
+ $formula = implode('"', $temp);
3071
+ } else {
3072
+ // If there's no quoted strings, then we do a simple count/replace
3073
+ $openCount = substr_count($formula, '{');
3074
+ $closeCount = substr_count($formula, '}');
3075
+ $formula = str_replace($matrixReplaceFrom, $matrixReplaceTo, $formula);
3076
+ }
3077
+ // Trap for mismatched braces and trigger an appropriate error
3078
+ if ($openCount < $closeCount) {
3079
+ if ($openCount > 0) {
3080
+ return $this->raiseFormulaError("Formula Error: Mismatched matrix braces '}'");
3081
+ } else {
3082
+ return $this->raiseFormulaError("Formula Error: Unexpected '}' encountered");
3083
+ }
3084
+ } elseif ($openCount > $closeCount) {
3085
+ if ($closeCount > 0) {
3086
+ return $this->raiseFormulaError("Formula Error: Mismatched matrix braces '{'");
3087
+ } else {
3088
+ return $this->raiseFormulaError("Formula Error: Unexpected '{' encountered");
3089
+ }
3090
+ }
3091
+ }
3092
+
3093
+ return $formula;
3094
+ }
3095
+
3096
+
3097
+ private static function mkMatrix()
3098
+ {
3099
+ return func_get_args();
3100
+ }
3101
+
3102
+
3103
+ // Binary Operators
3104
+ // These operators always work on two values
3105
+ // Array key is the operator, the value indicates whether this is a left or right associative operator
3106
+ private static $operatorAssociativity = array(
3107
+ '^' => 0, // Exponentiation
3108
+ '*' => 0, '/' => 0, // Multiplication and Division
3109
+ '+' => 0, '-' => 0, // Addition and Subtraction
3110
+ '&' => 0, // Concatenation
3111
+ '|' => 0, ':' => 0, // Intersect and Range
3112
+ '>' => 0, '<' => 0, '=' => 0, '>=' => 0, '<=' => 0, '<>' => 0 // Comparison
3113
+ );
3114
+
3115
+ // Comparison (Boolean) Operators
3116
+ // These operators work on two values, but always return a boolean result
3117
+ private static $comparisonOperators = array('>' => true, '<' => true, '=' => true, '>=' => true, '<=' => true, '<>' => true);
3118
+
3119
+ // Operator Precedence
3120
+ // This list includes all valid operators, whether binary (including boolean) or unary (such as %)
3121
+ // Array key is the operator, the value is its precedence
3122
+ private static $operatorPrecedence = array(
3123
+ ':' => 8, // Range
3124
+ '|' => 7, // Intersect
3125
+ '~' => 6, // Negation
3126
+ '%' => 5, // Percentage
3127
+ '^' => 4, // Exponentiation
3128
+ '*' => 3, '/' => 3, // Multiplication and Division
3129
+ '+' => 2, '-' => 2, // Addition and Subtraction
3130
+ '&' => 1, // Concatenation
3131
+ '>' => 0, '<' => 0, '=' => 0, '>=' => 0, '<=' => 0, '<>' => 0 // Comparison
3132
+ );
3133
+
3134
+ // Convert infix to postfix notation
3135
+ private function _parseFormula($formula, PHPExcel_Cell $pCell = null)
3136
+ {
3137
+ if (($formula = $this->convertMatrixReferences(trim($formula))) === false) {
3138
+ return false;
3139
+ }
3140
+
3141
+ // If we're using cell caching, then $pCell may well be flushed back to the cache (which detaches the parent worksheet),
3142
+ // so we store the parent worksheet so that we can re-attach it when necessary
3143
+ $pCellParent = ($pCell !== null) ? $pCell->getWorksheet() : null;
3144
+
3145
+ $regexpMatchString = '/^('.self::CALCULATION_REGEXP_FUNCTION.
3146
+ '|'.self::CALCULATION_REGEXP_CELLREF.
3147
+ '|'.self::CALCULATION_REGEXP_NUMBER.
3148
+ '|'.self::CALCULATION_REGEXP_STRING.
3149
+ '|'.self::CALCULATION_REGEXP_OPENBRACE.
3150
+ '|'.self::CALCULATION_REGEXP_NAMEDRANGE.
3151
+ '|'.self::CALCULATION_REGEXP_ERROR.
3152
+ ')/si';
3153
+
3154
+ // Start with initialisation
3155
+ $index = 0;
3156
+ $stack = new PHPExcel_Calculation_Token_Stack;
3157
+ $output = array();
3158
+ $expectingOperator = false; // We use this test in syntax-checking the expression to determine when a
3159
+ // - is a negation or + is a positive operator rather than an operation
3160
+ $expectingOperand = false; // We use this test in syntax-checking the expression to determine whether an operand
3161
+ // should be null in a function call
3162
+ // The guts of the lexical parser
3163
+ // Loop through the formula extracting each operator and operand in turn
3164
+ while (true) {
3165
+ //echo 'Assessing Expression '.substr($formula, $index), PHP_EOL;
3166
+ $opCharacter = $formula{$index}; // Get the first character of the value at the current index position
3167
+ //echo 'Initial character of expression block is '.$opCharacter, PHP_EOL;
3168
+ if ((isset(self::$comparisonOperators[$opCharacter])) && (strlen($formula) > $index) && (isset(self::$comparisonOperators[$formula{$index+1}]))) {
3169
+ $opCharacter .= $formula{++$index};
3170
+ //echo 'Initial character of expression block is comparison operator '.$opCharacter.PHP_EOL;
3171
+ }
3172
+
3173
+ // Find out if we're currently at the beginning of a number, variable, cell reference, function, parenthesis or operand
3174
+ $isOperandOrFunction = preg_match($regexpMatchString, substr($formula, $index), $match);
3175
+ //echo '$isOperandOrFunction is '.(($isOperandOrFunction) ? 'True' : 'False').PHP_EOL;
3176
+ //var_dump($match);
3177
+
3178
+ if ($opCharacter == '-' && !$expectingOperator) { // Is it a negation instead of a minus?
3179
+ //echo 'Element is a Negation operator', PHP_EOL;
3180
+ $stack->push('Unary Operator', '~'); // Put a negation on the stack
3181
+ ++$index; // and drop the negation symbol
3182
+ } elseif ($opCharacter == '%' && $expectingOperator) {
3183
+ //echo 'Element is a Percentage operator', PHP_EOL;
3184
+ $stack->push('Unary Operator', '%'); // Put a percentage on the stack
3185
+ ++$index;
3186
+ } elseif ($opCharacter == '+' && !$expectingOperator) { // Positive (unary plus rather than binary operator plus) can be discarded?
3187
+ //echo 'Element is a Positive number, not Plus operator', PHP_EOL;
3188
+ ++$index; // Drop the redundant plus symbol
3189
+ } elseif ((($opCharacter == '~') || ($opCharacter == '|')) && (!$isOperandOrFunction)) { // We have to explicitly deny a tilde or pipe, because they are legal
3190
+ return $this->raiseFormulaError("Formula Error: Illegal character '~'"); // on the stack but not in the input expression
3191
+
3192
+ } elseif ((isset(self::$operators[$opCharacter]) or $isOperandOrFunction) && $expectingOperator) { // Are we putting an operator on the stack?
3193
+ //echo 'Element with value '.$opCharacter.' is an Operator', PHP_EOL;
3194
+ while ($stack->count() > 0 &&
3195
+ ($o2 = $stack->last()) &&
3196
+ isset(self::$operators[$o2['value']]) &&
3197
+ @(self::$operatorAssociativity[$opCharacter] ? self::$operatorPrecedence[$opCharacter] < self::$operatorPrecedence[$o2['value']] : self::$operatorPrecedence[$opCharacter] <= self::$operatorPrecedence[$o2['value']])) {
3198
+ $output[] = $stack->pop(); // Swap operands and higher precedence operators from the stack to the output
3199
+ }
3200
+ $stack->push('Binary Operator', $opCharacter); // Finally put our current operator onto the stack
3201
+ ++$index;
3202
+ $expectingOperator = false;
3203
+
3204
+ } elseif ($opCharacter == ')' && $expectingOperator) { // Are we expecting to close a parenthesis?
3205
+ //echo 'Element is a Closing bracket', PHP_EOL;
3206
+ $expectingOperand = false;
3207
+ while (($o2 = $stack->pop()) && $o2['value'] != '(') { // Pop off the stack back to the last (
3208
+ if ($o2 === null) {
3209
+ return $this->raiseFormulaError('Formula Error: Unexpected closing brace ")"');
3210
+ } else {
3211
+ $output[] = $o2;
3212
+ }
3213
+ }
3214
+ $d = $stack->last(2);
3215
+ if (preg_match('/^'.self::CALCULATION_REGEXP_FUNCTION.'$/i', $d['value'], $matches)) { // Did this parenthesis just close a function?
3216
+ $functionName = $matches[1]; // Get the function name
3217
+ //echo 'Closed Function is '.$functionName, PHP_EOL;
3218
+ $d = $stack->pop();
3219
+ $argumentCount = $d['value']; // See how many arguments there were (argument count is the next value stored on the stack)
3220
+ //if ($argumentCount == 0) {
3221
+ // echo 'With no arguments', PHP_EOL;
3222
+ //} elseif ($argumentCount == 1) {
3223
+ // echo 'With 1 argument', PHP_EOL;
3224
+ //} else {
3225
+ // echo 'With '.$argumentCount.' arguments', PHP_EOL;
3226
+ //}
3227
+ $output[] = $d; // Dump the argument count on the output
3228
+ $output[] = $stack->pop(); // Pop the function and push onto the output
3229
+ if (isset(self::$controlFunctions[$functionName])) {
3230
+ //echo 'Built-in function '.$functionName, PHP_EOL;
3231
+ $expectedArgumentCount = self::$controlFunctions[$functionName]['argumentCount'];
3232
+ $functionCall = self::$controlFunctions[$functionName]['functionCall'];
3233
+ } elseif (isset(self::$PHPExcelFunctions[$functionName])) {
3234
+ //echo 'PHPExcel function '.$functionName, PHP_EOL;
3235
+ $expectedArgumentCount = self::$PHPExcelFunctions[$functionName]['argumentCount'];
3236
+ $functionCall = self::$PHPExcelFunctions[$functionName]['functionCall'];
3237
+ } else { // did we somehow push a non-function on the stack? this should never happen
3238
+ return $this->raiseFormulaError("Formula Error: Internal error, non-function on stack");
3239
+ }
3240
+ // Check the argument count
3241
+ $argumentCountError = false;
3242
+ if (is_numeric($expectedArgumentCount)) {
3243
+ if ($expectedArgumentCount < 0) {
3244
+ //echo '$expectedArgumentCount is between 0 and '.abs($expectedArgumentCount), PHP_EOL;
3245
+ if ($argumentCount > abs($expectedArgumentCount)) {
3246
+ $argumentCountError = true;
3247
+ $expectedArgumentCountString = 'no more than '.abs($expectedArgumentCount);
3248
+ }
3249
+ } else {
3250
+ //echo '$expectedArgumentCount is numeric '.$expectedArgumentCount, PHP_EOL;
3251
+ if ($argumentCount != $expectedArgumentCount) {
3252
+ $argumentCountError = true;
3253
+ $expectedArgumentCountString = $expectedArgumentCount;
3254
+ }
3255
+ }
3256
+ } elseif ($expectedArgumentCount != '*') {
3257
+ $isOperandOrFunction = preg_match('/(\d*)([-+,])(\d*)/', $expectedArgumentCount, $argMatch);
3258
+ //print_r($argMatch);
3259
+ //echo PHP_EOL;
3260
+ switch ($argMatch[2]) {
3261
+ case '+':
3262
+ if ($argumentCount < $argMatch[1]) {
3263
+ $argumentCountError = true;
3264
+ $expectedArgumentCountString = $argMatch[1].' or more ';
3265
+ }
3266
+ break;
3267
+ case '-':
3268
+ if (($argumentCount < $argMatch[1]) || ($argumentCount > $argMatch[3])) {
3269
+ $argumentCountError = true;
3270
+ $expectedArgumentCountString = 'between '.$argMatch[1].' and '.$argMatch[3];
3271
+ }
3272
+ break;
3273
+ case ',':
3274
+ if (($argumentCount != $argMatch[1]) && ($argumentCount != $argMatch[3])) {
3275
+ $argumentCountError = true;
3276
+ $expectedArgumentCountString = 'either '.$argMatch[1].' or '.$argMatch[3];
3277
+ }
3278
+ break;
3279
+ }
3280
+ }
3281
+ if ($argumentCountError) {
3282
+ return $this->raiseFormulaError("Formula Error: Wrong number of arguments for $functionName() function: $argumentCount given, ".$expectedArgumentCountString." expected");
3283
+ }
3284
+ }
3285
+ ++$index;
3286
+
3287
+ } elseif ($opCharacter == ',') { // Is this the separator for function arguments?
3288
+ //echo 'Element is a Function argument separator', PHP_EOL;
3289
+ while (($o2 = $stack->pop()) && $o2['value'] != '(') { // Pop off the stack back to the last (
3290
+ if ($o2 === null) {
3291
+ return $this->raiseFormulaError("Formula Error: Unexpected ,");
3292
+ } else {
3293
+ $output[] = $o2; // pop the argument expression stuff and push onto the output
3294
+ }
3295
+ }
3296
+ // If we've a comma when we're expecting an operand, then what we actually have is a null operand;
3297
+ // so push a null onto the stack
3298
+ if (($expectingOperand) || (!$expectingOperator)) {
3299
+ $output[] = array('type' => 'NULL Value', 'value' => self::$excelConstants['NULL'], 'reference' => null);
3300
+ }
3301
+ // make sure there was a function
3302
+ $d = $stack->last(2);
3303
+ if (!preg_match('/^'.self::CALCULATION_REGEXP_FUNCTION.'$/i', $d['value'], $matches)) {
3304
+ return $this->raiseFormulaError("Formula Error: Unexpected ,");
3305
+ }
3306
+ $d = $stack->pop();
3307
+ $stack->push($d['type'], ++$d['value'], $d['reference']); // increment the argument count
3308
+ $stack->push('Brace', '('); // put the ( back on, we'll need to pop back to it again
3309
+ $expectingOperator = false;
3310
+ $expectingOperand = true;
3311
+ ++$index;
3312
+
3313
+ } elseif ($opCharacter == '(' && !$expectingOperator) {
3314
+ // echo 'Element is an Opening Bracket<br />';
3315
+ $stack->push('Brace', '(');
3316
+ ++$index;
3317
+
3318
+ } elseif ($isOperandOrFunction && !$expectingOperator) { // do we now have a function/variable/number?
3319
+ $expectingOperator = true;
3320
+ $expectingOperand = false;
3321
+ $val = $match[1];
3322
+ $length = strlen($val);
3323
+ // echo 'Element with value '.$val.' is an Operand, Variable, Constant, String, Number, Cell Reference or Function<br />';
3324
+
3325
+ if (preg_match('/^'.self::CALCULATION_REGEXP_FUNCTION.'$/i', $val, $matches)) {
3326
+ $val = preg_replace('/\s/u', '', $val);
3327
+ // echo 'Element '.$val.' is a Function<br />';
3328
+ if (isset(self::$PHPExcelFunctions[strtoupper($matches[1])]) || isset(self::$controlFunctions[strtoupper($matches[1])])) { // it's a function
3329
+ $stack->push('Function', strtoupper($val));
3330
+ $ax = preg_match('/^\s*(\s*\))/ui', substr($formula, $index+$length), $amatch);
3331
+ if ($ax) {
3332
+ $stack->push('Operand Count for Function '.strtoupper($val).')', 0);
3333
+ $expectingOperator = true;
3334
+ } else {
3335
+ $stack->push('Operand Count for Function '.strtoupper($val).')', 1);
3336
+ $expectingOperator = false;
3337
+ }
3338
+ $stack->push('Brace', '(');
3339
+ } else { // it's a var w/ implicit multiplication
3340
+ $output[] = array('type' => 'Value', 'value' => $matches[1], 'reference' => null);
3341
+ }
3342
+ } elseif (preg_match('/^'.self::CALCULATION_REGEXP_CELLREF.'$/i', $val, $matches)) {
3343
+ // echo 'Element '.$val.' is a Cell reference<br />';
3344
+ // Watch for this case-change when modifying to allow cell references in different worksheets...
3345
+ // Should only be applied to the actual cell column, not the worksheet name
3346
+
3347
+ // If the last entry on the stack was a : operator, then we have a cell range reference
3348
+ $testPrevOp = $stack->last(1);
3349
+ if ($testPrevOp['value'] == ':') {
3350
+ // If we have a worksheet reference, then we're playing with a 3D reference
3351
+ if ($matches[2] == '') {
3352
+ // Otherwise, we 'inherit' the worksheet reference from the start cell reference
3353
+ // The start of the cell range reference should be the last entry in $output
3354
+ $startCellRef = $output[count($output)-1]['value'];
3355
+ preg_match('/^'.self::CALCULATION_REGEXP_CELLREF.'$/i', $startCellRef, $startMatches);
3356
+ if ($startMatches[2] > '') {
3357
+ $val = $startMatches[2].'!'.$val;
3358
+ }
3359
+ } else {
3360
+ return $this->raiseFormulaError("3D Range references are not yet supported");
3361
+ }
3362
+ }
3363
+
3364
+ $output[] = array('type' => 'Cell Reference', 'value' => $val, 'reference' => $val);
3365
+ // $expectingOperator = FALSE;
3366
+ } else { // it's a variable, constant, string, number or boolean
3367
+ // echo 'Element is a Variable, Constant, String, Number or Boolean<br />';
3368
+ // If the last entry on the stack was a : operator, then we may have a row or column range reference
3369
+ $testPrevOp = $stack->last(1);
3370
+ if ($testPrevOp['value'] == ':') {
3371
+ $startRowColRef = $output[count($output)-1]['value'];
3372
+ $rangeWS1 = '';
3373
+ if (strpos('!', $startRowColRef) !== false) {
3374
+ list($rangeWS1, $startRowColRef) = explode('!', $startRowColRef);
3375
+ }
3376
+ if ($rangeWS1 != '') {
3377
+ $rangeWS1 .= '!';
3378
+ }
3379
+ $rangeWS2 = $rangeWS1;
3380
+ if (strpos('!', $val) !== false) {
3381
+ list($rangeWS2, $val) = explode('!', $val);
3382
+ }
3383
+ if ($rangeWS2 != '') {
3384
+ $rangeWS2 .= '!';
3385
+ }
3386
+ if ((is_integer($startRowColRef)) && (ctype_digit($val)) &&
3387
+ ($startRowColRef <= 1048576) && ($val <= 1048576)) {
3388
+ // Row range
3389
+ $endRowColRef = ($pCellParent !== null) ? $pCellParent->getHighestColumn() : 'XFD'; // Max 16,384 columns for Excel2007
3390
+ $output[count($output)-1]['value'] = $rangeWS1.'A'.$startRowColRef;
3391
+ $val = $rangeWS2.$endRowColRef.$val;
3392
+ } elseif ((ctype_alpha($startRowColRef)) && (ctype_alpha($val)) &&
3393
+ (strlen($startRowColRef) <= 3) && (strlen($val) <= 3)) {
3394
+ // Column range
3395
+ $endRowColRef = ($pCellParent !== null) ? $pCellParent->getHighestRow() : 1048576; // Max 1,048,576 rows for Excel2007
3396
+ $output[count($output)-1]['value'] = $rangeWS1.strtoupper($startRowColRef).'1';
3397
+ $val = $rangeWS2.$val.$endRowColRef;
3398
+ }
3399
+ }
3400
+
3401
+ $localeConstant = false;
3402
+ if ($opCharacter == '"') {
3403
+ // echo 'Element is a String<br />';
3404
+ // UnEscape any quotes within the string
3405
+ $val = self::wrapResult(str_replace('""', '"', self::unwrapResult($val)));
3406
+ } elseif (is_numeric($val)) {
3407
+ // echo 'Element is a Number<br />';
3408
+ if ((strpos($val, '.') !== false) || (stripos($val, 'e') !== false) || ($val > PHP_INT_MAX) || ($val < -PHP_INT_MAX)) {
3409
+ // echo 'Casting '.$val.' to float<br />';
3410
+ $val = (float) $val;
3411
+ } else {
3412
+ // echo 'Casting '.$val.' to integer<br />';
3413
+ $val = (integer) $val;
3414
+ }
3415
+ } elseif (isset(self::$excelConstants[trim(strtoupper($val))])) {
3416
+ $excelConstant = trim(strtoupper($val));
3417
+ // echo 'Element '.$excelConstant.' is an Excel Constant<br />';
3418
+ $val = self::$excelConstants[$excelConstant];
3419
+ } elseif (($localeConstant = array_search(trim(strtoupper($val)), self::$localeBoolean)) !== false) {
3420
+ // echo 'Element '.$localeConstant.' is an Excel Constant<br />';
3421
+ $val = self::$excelConstants[$localeConstant];
3422
+ }
3423
+ $details = array('type' => 'Value', 'value' => $val, 'reference' => null);
3424
+ if ($localeConstant) {
3425
+ $details['localeValue'] = $localeConstant;
3426
+ }
3427
+ $output[] = $details;
3428
+ }
3429
+ $index += $length;
3430
+
3431
+ } elseif ($opCharacter == '$') { // absolute row or column range
3432
+ ++$index;
3433
+ } elseif ($opCharacter == ')') { // miscellaneous error checking
3434
+ if ($expectingOperand) {
3435
+ $output[] = array('type' => 'NULL Value', 'value' => self::$excelConstants['NULL'], 'reference' => null);
3436
+ $expectingOperand = false;
3437
+ $expectingOperator = true;
3438
+ } else {
3439
+ return $this->raiseFormulaError("Formula Error: Unexpected ')'");
3440
+ }
3441
+ } elseif (isset(self::$operators[$opCharacter]) && !$expectingOperator) {
3442
+ return $this->raiseFormulaError("Formula Error: Unexpected operator '$opCharacter'");
3443
+ } else { // I don't even want to know what you did to get here
3444
+ return $this->raiseFormulaError("Formula Error: An unexpected error occured");
3445
+ }
3446
+ // Test for end of formula string
3447
+ if ($index == strlen($formula)) {
3448
+ // Did we end with an operator?.
3449
+ // Only valid for the % unary operator
3450
+ if ((isset(self::$operators[$opCharacter])) && ($opCharacter != '%')) {
3451
+ return $this->raiseFormulaError("Formula Error: Operator '$opCharacter' has no operands");
3452
+ } else {
3453
+ break;
3454
+ }
3455
+ }
3456
+ // Ignore white space
3457
+ while (($formula{$index} == "\n") || ($formula{$index} == "\r")) {
3458
+ ++$index;
3459
+ }
3460
+ if ($formula{$index} == ' ') {
3461
+ while ($formula{$index} == ' ') {
3462
+ ++$index;
3463
+ }
3464
+ // If we're expecting an operator, but only have a space between the previous and next operands (and both are
3465
+ // Cell References) then we have an INTERSECTION operator
3466
+ // echo 'Possible Intersect Operator<br />';
3467
+ if (($expectingOperator) && (preg_match('/^'.self::CALCULATION_REGEXP_CELLREF.'.*/Ui', substr($formula, $index), $match)) &&
3468
+ ($output[count($output)-1]['type'] == 'Cell Reference')) {
3469
+ // echo 'Element is an Intersect Operator<br />';
3470
+ while ($stack->count() > 0 &&
3471
+ ($o2 = $stack->last()) &&
3472
+ isset(self::$operators[$o2['value']]) &&
3473
+ @(self::$operatorAssociativity[$opCharacter] ? self::$operatorPrecedence[$opCharacter] < self::$operatorPrecedence[$o2['value']] : self::$operatorPrecedence[$opCharacter] <= self::$operatorPrecedence[$o2['value']])) {
3474
+ $output[] = $stack->pop(); // Swap operands and higher precedence operators from the stack to the output
3475
+ }
3476
+ $stack->push('Binary Operator', '|'); // Put an Intersect Operator on the stack
3477
+ $expectingOperator = false;
3478
+ }
3479
+ }
3480
+ }
3481
+
3482
+ while (($op = $stack->pop()) !== null) { // pop everything off the stack and push onto output
3483
+ if ((is_array($op) && $op['value'] == '(') || ($op === '(')) {
3484
+ return $this->raiseFormulaError("Formula Error: Expecting ')'"); // if there are any opening braces on the stack, then braces were unbalanced
3485
+ }
3486
+ $output[] = $op;
3487
+ }
3488
+ return $output;
3489
+ }
3490
+
3491
+
3492
+ private static function dataTestReference(&$operandData)
3493
+ {
3494
+ $operand = $operandData['value'];
3495
+ if (($operandData['reference'] === null) && (is_array($operand))) {
3496
+ $rKeys = array_keys($operand);
3497
+ $rowKey = array_shift($rKeys);
3498
+ $cKeys = array_keys(array_keys($operand[$rowKey]));
3499
+ $colKey = array_shift($cKeys);
3500
+ if (ctype_upper($colKey)) {
3501
+ $operandData['reference'] = $colKey.$rowKey;
3502
+ }
3503
+ }
3504
+ return $operand;
3505
+ }
3506
+
3507
+ // evaluate postfix notation
3508
+ private function processTokenStack($tokens, $cellID = null, PHPExcel_Cell $pCell = null)
3509
+ {
3510
+ if ($tokens == false) {
3511
+ return false;
3512
+ }
3513
+
3514
+ // If we're using cell caching, then $pCell may well be flushed back to the cache (which detaches the parent cell collection),
3515
+ // so we store the parent cell collection so that we can re-attach it when necessary
3516
+ $pCellWorksheet = ($pCell !== null) ? $pCell->getWorksheet() : null;
3517
+ $pCellParent = ($pCell !== null) ? $pCell->getParent() : null;
3518
+ $stack = new PHPExcel_Calculation_Token_Stack;
3519
+
3520
+ // Loop through each token in turn
3521
+ foreach ($tokens as $tokenData) {
3522
+ // print_r($tokenData);
3523
+ // echo '<br />';
3524
+ $token = $tokenData['value'];
3525
+ // echo '<b>Token is '.$token.'</b><br />';
3526
+ // if the token is a binary operator, pop the top two values off the stack, do the operation, and push the result back on the stack
3527
+ if (isset(self::$binaryOperators[$token])) {
3528
+ // echo 'Token is a binary operator<br />';
3529
+ // We must have two operands, error if we don't
3530
+ if (($operand2Data = $stack->pop()) === null) {
3531
+ return $this->raiseFormulaError('Internal error - Operand value missing from stack');
3532
+ }
3533
+ if (($operand1Data = $stack->pop()) === null) {
3534
+ return $this->raiseFormulaError('Internal error - Operand value missing from stack');
3535
+ }
3536
+
3537
+ $operand1 = self::dataTestReference($operand1Data);
3538
+ $operand2 = self::dataTestReference($operand2Data);
3539
+
3540
+ // Log what we're doing
3541
+ if ($token == ':') {
3542
+ $this->_debugLog->writeDebugLog('Evaluating Range ', $this->showValue($operand1Data['reference']), ' ', $token, ' ', $this->showValue($operand2Data['reference']));
3543
+ } else {
3544
+ $this->_debugLog->writeDebugLog('Evaluating ', $this->showValue($operand1), ' ', $token, ' ', $this->showValue($operand2));
3545
+ }
3546
+
3547
+ // Process the operation in the appropriate manner
3548
+ switch ($token) {
3549
+ // Comparison (Boolean) Operators
3550
+ case '>': // Greater than
3551
+ case '<': // Less than
3552
+ case '>=': // Greater than or Equal to
3553
+ case '<=': // Less than or Equal to
3554
+ case '=': // Equality
3555
+ case '<>': // Inequality
3556
+ $this->executeBinaryComparisonOperation($cellID, $operand1, $operand2, $token, $stack);
3557
+ break;
3558
+ // Binary Operators
3559
+ case ':': // Range
3560
+ $sheet1 = $sheet2 = '';
3561
+ if (strpos($operand1Data['reference'], '!') !== false) {
3562
+ list($sheet1, $operand1Data['reference']) = explode('!', $operand1Data['reference']);
3563
+ } else {
3564
+ $sheet1 = ($pCellParent !== null) ? $pCellWorksheet->getTitle() : '';
3565
+ }
3566
+ if (strpos($operand2Data['reference'], '!') !== false) {
3567
+ list($sheet2, $operand2Data['reference']) = explode('!', $operand2Data['reference']);
3568
+ } else {
3569
+ $sheet2 = $sheet1;
3570
+ }
3571
+ if ($sheet1 == $sheet2) {
3572
+ if ($operand1Data['reference'] === null) {
3573
+ if ((trim($operand1Data['value']) != '') && (is_numeric($operand1Data['value']))) {
3574
+ $operand1Data['reference'] = $pCell->getColumn().$operand1Data['value'];
3575
+ } elseif (trim($operand1Data['reference']) == '') {
3576
+ $operand1Data['reference'] = $pCell->getCoordinate();
3577
+ } else {
3578
+ $operand1Data['reference'] = $operand1Data['value'].$pCell->getRow();
3579
+ }
3580
+ }
3581
+ if ($operand2Data['reference'] === null) {
3582
+ if ((trim($operand2Data['value']) != '') && (is_numeric($operand2Data['value']))) {
3583
+ $operand2Data['reference'] = $pCell->getColumn().$operand2Data['value'];
3584
+ } elseif (trim($operand2Data['reference']) == '') {
3585
+ $operand2Data['reference'] = $pCell->getCoordinate();
3586
+ } else {
3587
+ $operand2Data['reference'] = $operand2Data['value'].$pCell->getRow();
3588
+ }
3589
+ }
3590
+
3591
+ $oData = array_merge(explode(':', $operand1Data['reference']), explode(':', $operand2Data['reference']));
3592
+ $oCol = $oRow = array();
3593
+ foreach ($oData as $oDatum) {
3594
+ $oCR = PHPExcel_Cell::coordinateFromString($oDatum);
3595
+ $oCol[] = PHPExcel_Cell::columnIndexFromString($oCR[0]) - 1;
3596
+ $oRow[] = $oCR[1];
3597
+ }
3598
+ $cellRef = PHPExcel_Cell::stringFromColumnIndex(min($oCol)).min($oRow).':'.PHPExcel_Cell::stringFromColumnIndex(max($oCol)).max($oRow);
3599
+ if ($pCellParent !== null) {
3600
+ $cellValue = $this->extractCellRange($cellRef, $this->workbook->getSheetByName($sheet1), false);
3601
+ } else {
3602
+ return $this->raiseFormulaError('Unable to access Cell Reference');
3603
+ }
3604
+ $stack->push('Cell Reference', $cellValue, $cellRef);
3605
+ } else {
3606
+ $stack->push('Error', PHPExcel_Calculation_Functions::REF(), null);
3607
+ }
3608
+ break;
3609
+ case '+': // Addition
3610
+ $this->executeNumericBinaryOperation($cellID, $operand1, $operand2, $token, 'plusEquals', $stack);
3611
+ break;
3612
+ case '-': // Subtraction
3613
+ $this->executeNumericBinaryOperation($cellID, $operand1, $operand2, $token, 'minusEquals', $stack);
3614
+ break;
3615
+ case '*': // Multiplication
3616
+ $this->executeNumericBinaryOperation($cellID, $operand1, $operand2, $token, 'arrayTimesEquals', $stack);
3617
+ break;
3618
+ case '/': // Division
3619
+ $this->executeNumericBinaryOperation($cellID, $operand1, $operand2, $token, 'arrayRightDivide', $stack);
3620
+ break;
3621
+ case '^': // Exponential
3622
+ $this->executeNumericBinaryOperation($cellID, $operand1, $operand2, $token, 'power', $stack);
3623
+ break;
3624
+ case '&': // Concatenation
3625
+ // If either of the operands is a matrix, we need to treat them both as matrices
3626
+ // (converting the other operand to a matrix if need be); then perform the required
3627
+ // matrix operation
3628
+ if (is_bool($operand1)) {
3629
+ $operand1 = ($operand1) ? self::$localeBoolean['TRUE'] : self::$localeBoolean['FALSE'];
3630
+ }
3631
+ if (is_bool($operand2)) {
3632
+ $operand2 = ($operand2) ? self::$localeBoolean['TRUE'] : self::$localeBoolean['FALSE'];
3633
+ }
3634
+ if ((is_array($operand1)) || (is_array($operand2))) {
3635
+ // Ensure that both operands are arrays/matrices
3636
+ self::checkMatrixOperands($operand1, $operand2, 2);
3637
+ try {
3638
+ // Convert operand 1 from a PHP array to a matrix
3639
+ $matrix = new PHPExcel_Shared_JAMA_Matrix($operand1);
3640
+ // Perform the required operation against the operand 1 matrix, passing in operand 2
3641
+ $matrixResult = $matrix->concat($operand2);
3642
+ $result = $matrixResult->getArray();
3643
+ } catch (PHPExcel_Exception $ex) {
3644
+ $this->_debugLog->writeDebugLog('JAMA Matrix Exception: ', $ex->getMessage());
3645
+ $result = '#VALUE!';
3646
+ }
3647
+ } else {
3648
+ $result = '"'.str_replace('""', '"', self::unwrapResult($operand1, '"').self::unwrapResult($operand2, '"')).'"';
3649
+ }
3650
+ $this->_debugLog->writeDebugLog('Evaluation Result is ', $this->showTypeDetails($result));
3651
+ $stack->push('Value', $result);
3652
+ break;
3653
+ case '|': // Intersect
3654
+ $rowIntersect = array_intersect_key($operand1, $operand2);
3655
+ $cellIntersect = $oCol = $oRow = array();
3656
+ foreach (array_keys($rowIntersect) as $row) {
3657
+ $oRow[] = $row;
3658
+ foreach ($rowIntersect[$row] as $col => $data) {
3659
+ $oCol[] = PHPExcel_Cell::columnIndexFromString($col) - 1;
3660
+ $cellIntersect[$row] = array_intersect_key($operand1[$row], $operand2[$row]);
3661
+ }
3662
+ }
3663
+ $cellRef = PHPExcel_Cell::stringFromColumnIndex(min($oCol)).min($oRow).':'.PHPExcel_Cell::stringFromColumnIndex(max($oCol)).max($oRow);
3664
+ $this->_debugLog->writeDebugLog('Evaluation Result is ', $this->showTypeDetails($cellIntersect));
3665
+ $stack->push('Value', $cellIntersect, $cellRef);
3666
+ break;
3667
+ }
3668
+
3669
+ // if the token is a unary operator, pop one value off the stack, do the operation, and push it back on
3670
+ } elseif (($token === '~') || ($token === '%')) {
3671
+ // echo 'Token is a unary operator<br />';
3672
+ if (($arg = $stack->pop()) === null) {
3673
+ return $this->raiseFormulaError('Internal error - Operand value missing from stack');
3674
+ }
3675
+ $arg = $arg['value'];
3676
+ if ($token === '~') {
3677
+ // echo 'Token is a negation operator<br />';
3678
+ $this->_debugLog->writeDebugLog('Evaluating Negation of ', $this->showValue($arg));
3679
+ $multiplier = -1;
3680
+ } else {
3681
+ // echo 'Token is a percentile operator<br />';
3682
+ $this->_debugLog->writeDebugLog('Evaluating Percentile of ', $this->showValue($arg));
3683
+ $multiplier = 0.01;
3684
+ }
3685
+ if (is_array($arg)) {
3686
+ self::checkMatrixOperands($arg, $multiplier, 2);
3687
+ try {
3688
+ $matrix1 = new PHPExcel_Shared_JAMA_Matrix($arg);
3689
+ $matrixResult = $matrix1->arrayTimesEquals($multiplier);
3690
+ $result = $matrixResult->getArray();
3691
+ } catch (PHPExcel_Exception $ex) {
3692
+ $this->_debugLog->writeDebugLog('JAMA Matrix Exception: ', $ex->getMessage());
3693
+ $result = '#VALUE!';
3694
+ }
3695
+ $this->_debugLog->writeDebugLog('Evaluation Result is ', $this->showTypeDetails($result));
3696
+ $stack->push('Value', $result);
3697
+ } else {
3698
+ $this->executeNumericBinaryOperation($cellID, $multiplier, $arg, '*', 'arrayTimesEquals', $stack);
3699
+ }
3700
+
3701
+ } elseif (preg_match('/^'.self::CALCULATION_REGEXP_CELLREF.'$/i', $token, $matches)) {
3702
+ $cellRef = null;
3703
+ // echo 'Element '.$token.' is a Cell reference<br />';
3704
+ if (isset($matches[8])) {
3705
+ // echo 'Reference is a Range of cells<br />';
3706
+ if ($pCell === null) {
3707
+ // We can't access the range, so return a REF error
3708
+ $cellValue = PHPExcel_Calculation_Functions::REF();
3709
+ } else {
3710
+ $cellRef = $matches[6].$matches[7].':'.$matches[9].$matches[10];
3711
+ if ($matches[2] > '') {
3712
+ $matches[2] = trim($matches[2], "\"'");
3713
+ if ((strpos($matches[2], '[') !== false) || (strpos($matches[2], ']') !== false)) {
3714
+ // It's a Reference to an external workbook (not currently supported)
3715
+ return $this->raiseFormulaError('Unable to access External Workbook');
3716
+ }
3717
+ $matches[2] = trim($matches[2], "\"'");
3718
+ // echo '$cellRef='.$cellRef.' in worksheet '.$matches[2].'<br />';
3719
+ $this->_debugLog->writeDebugLog('Evaluating Cell Range ', $cellRef, ' in worksheet ', $matches[2]);
3720
+ if ($pCellParent !== null) {
3721
+ $cellValue = $this->extractCellRange($cellRef, $this->workbook->getSheetByName($matches[2]), false);
3722
+ } else {
3723
+ return $this->raiseFormulaError('Unable to access Cell Reference');
3724
+ }
3725
+ $this->_debugLog->writeDebugLog('Evaluation Result for cells ', $cellRef, ' in worksheet ', $matches[2], ' is ', $this->showTypeDetails($cellValue));
3726
+ // $cellRef = $matches[2].'!'.$cellRef;
3727
+ } else {
3728
+ // echo '$cellRef='.$cellRef.' in current worksheet<br />';
3729
+ $this->_debugLog->writeDebugLog('Evaluating Cell Range ', $cellRef, ' in current worksheet');
3730
+ if ($pCellParent !== null) {
3731
+ $cellValue = $this->extractCellRange($cellRef, $pCellWorksheet, false);
3732
+ } else {
3733
+ return $this->raiseFormulaError('Unable to access Cell Reference');
3734
+ }
3735
+ $this->_debugLog->writeDebugLog('Evaluation Result for cells ', $cellRef, ' is ', $this->showTypeDetails($cellValue));
3736
+ }
3737
+ }
3738
+ } else {
3739
+ // echo 'Reference is a single Cell<br />';
3740
+ if ($pCell === null) {
3741
+ // We can't access the cell, so return a REF error
3742
+ $cellValue = PHPExcel_Calculation_Functions::REF();
3743
+ } else {
3744
+ $cellRef = $matches[6].$matches[7];
3745
+ if ($matches[2] > '') {
3746
+ $matches[2] = trim($matches[2], "\"'");
3747
+ if ((strpos($matches[2], '[') !== false) || (strpos($matches[2], ']') !== false)) {
3748
+ // It's a Reference to an external workbook (not currently supported)
3749
+ return $this->raiseFormulaError('Unable to access External Workbook');
3750
+ }
3751
+ // echo '$cellRef='.$cellRef.' in worksheet '.$matches[2].'<br />';
3752
+ $this->_debugLog->writeDebugLog('Evaluating Cell ', $cellRef, ' in worksheet ', $matches[2]);
3753
+ if ($pCellParent !== null) {
3754
+ $cellSheet = $this->workbook->getSheetByName($matches[2]);
3755
+ if ($cellSheet && $cellSheet->cellExists($cellRef)) {
3756
+ $cellValue = $this->extractCellRange($cellRef, $this->workbook->getSheetByName($matches[2]), false);
3757
+ $pCell->attach($pCellParent);
3758
+ } else {
3759
+ $cellValue = null;
3760
+ }
3761
+ } else {
3762
+ return $this->raiseFormulaError('Unable to access Cell Reference');
3763
+ }
3764
+ $this->_debugLog->writeDebugLog('Evaluation Result for cell ', $cellRef, ' in worksheet ', $matches[2], ' is ', $this->showTypeDetails($cellValue));
3765
+ // $cellRef = $matches[2].'!'.$cellRef;
3766
+ } else {
3767
+ // echo '$cellRef='.$cellRef.' in current worksheet<br />';
3768
+ $this->_debugLog->writeDebugLog('Evaluating Cell ', $cellRef, ' in current worksheet');
3769
+ if ($pCellParent->isDataSet($cellRef)) {
3770
+ $cellValue = $this->extractCellRange($cellRef, $pCellWorksheet, false);
3771
+ $pCell->attach($pCellParent);
3772
+ } else {
3773
+ $cellValue = null;
3774
+ }
3775
+ $this->_debugLog->writeDebugLog('Evaluation Result for cell ', $cellRef, ' is ', $this->showTypeDetails($cellValue));
3776
+ }
3777
+ }
3778
+ }
3779
+ $stack->push('Value', $cellValue, $cellRef);
3780
+
3781
+ // if the token is a function, pop arguments off the stack, hand them to the function, and push the result back on
3782
+ } elseif (preg_match('/^'.self::CALCULATION_REGEXP_FUNCTION.'$/i', $token, $matches)) {
3783
+ // echo 'Token is a function<br />';
3784
+ $functionName = $matches[1];
3785
+ $argCount = $stack->pop();
3786
+ $argCount = $argCount['value'];
3787
+ if ($functionName != 'MKMATRIX') {
3788
+ $this->_debugLog->writeDebugLog('Evaluating Function ', self::localeFunc($functionName), '() with ', (($argCount == 0) ? 'no' : $argCount), ' argument', (($argCount == 1) ? '' : 's'));
3789
+ }
3790
+ if ((isset(self::$PHPExcelFunctions[$functionName])) || (isset(self::$controlFunctions[$functionName]))) { // function
3791
+ if (isset(self::$PHPExcelFunctions[$functionName])) {
3792
+ $functionCall = self::$PHPExcelFunctions[$functionName]['functionCall'];
3793
+ $passByReference = isset(self::$PHPExcelFunctions[$functionName]['passByReference']);
3794
+ $passCellReference = isset(self::$PHPExcelFunctions[$functionName]['passCellReference']);
3795
+ } elseif (isset(self::$controlFunctions[$functionName])) {
3796
+ $functionCall = self::$controlFunctions[$functionName]['functionCall'];
3797
+ $passByReference = isset(self::$controlFunctions[$functionName]['passByReference']);
3798
+ $passCellReference = isset(self::$controlFunctions[$functionName]['passCellReference']);
3799
+ }
3800
+ // get the arguments for this function
3801
+ // echo 'Function '.$functionName.' expects '.$argCount.' arguments<br />';
3802
+ $args = $argArrayVals = array();
3803
+ for ($i = 0; $i < $argCount; ++$i) {
3804
+ $arg = $stack->pop();
3805
+ $a = $argCount - $i - 1;
3806
+ if (($passByReference) &&
3807
+ (isset(self::$PHPExcelFunctions[$functionName]['passByReference'][$a])) &&
3808
+ (self::$PHPExcelFunctions[$functionName]['passByReference'][$a])) {
3809
+ if ($arg['reference'] === null) {
3810
+ $args[] = $cellID;
3811
+ if ($functionName != 'MKMATRIX') {
3812
+ $argArrayVals[] = $this->showValue($cellID);
3813
+ }
3814
+ } else {
3815
+ $args[] = $arg['reference'];
3816
+ if ($functionName != 'MKMATRIX') {
3817
+ $argArrayVals[] = $this->showValue($arg['reference']);
3818
+ }
3819
+ }
3820
+ } else {
3821
+ $args[] = self::unwrapResult($arg['value']);
3822
+ if ($functionName != 'MKMATRIX') {
3823
+ $argArrayVals[] = $this->showValue($arg['value']);
3824
+ }
3825
+ }
3826
+ }
3827
+ // Reverse the order of the arguments
3828
+ krsort($args);
3829
+ if (($passByReference) && ($argCount == 0)) {
3830
+ $args[] = $cellID;
3831
+ $argArrayVals[] = $this->showValue($cellID);
3832
+ }
3833
+ // echo 'Arguments are: ';
3834
+ // print_r($args);
3835
+ // echo '<br />';
3836
+ if ($functionName != 'MKMATRIX') {
3837
+ if ($this->_debugLog->getWriteDebugLog()) {
3838
+ krsort($argArrayVals);
3839
+ $this->_debugLog->writeDebugLog('Evaluating ', self::localeFunc($functionName), '( ', implode(self::$localeArgumentSeparator.' ', PHPExcel_Calculation_Functions::flattenArray($argArrayVals)), ' )');
3840
+ }
3841
+ }
3842
+ // Process each argument in turn, building the return value as an array
3843
+ // if (($argCount == 1) && (is_array($args[1])) && ($functionName != 'MKMATRIX')) {
3844
+ // $operand1 = $args[1];
3845
+ // $this->_debugLog->writeDebugLog('Argument is a matrix: ', $this->showValue($operand1));
3846
+ // $result = array();
3847
+ // $row = 0;
3848
+ // foreach($operand1 as $args) {
3849
+ // if (is_array($args)) {
3850
+ // foreach($args as $arg) {
3851
+ // $this->_debugLog->writeDebugLog('Evaluating ', self::localeFunc($functionName), '( ', $this->showValue($arg), ' )');
3852
+ // $r = call_user_func_array($functionCall, $arg);
3853
+ // $this->_debugLog->writeDebugLog('Evaluation Result for ', self::localeFunc($functionName), '() function call is ', $this->showTypeDetails($r));
3854
+ // $result[$row][] = $r;
3855
+ // }
3856
+ // ++$row;
3857
+ // } else {
3858
+ // $this->_debugLog->writeDebugLog('Evaluating ', self::localeFunc($functionName), '( ', $this->showValue($args), ' )');
3859
+ // $r = call_user_func_array($functionCall, $args);
3860
+ // $this->_debugLog->writeDebugLog('Evaluation Result for ', self::localeFunc($functionName), '() function call is ', $this->showTypeDetails($r));
3861
+ // $result[] = $r;
3862
+ // }
3863
+ // }
3864
+ // } else {
3865
+ // Process the argument with the appropriate function call
3866
+ if ($passCellReference) {
3867
+ $args[] = $pCell;
3868
+ }
3869
+ if (strpos($functionCall, '::') !== false) {
3870
+ $result = call_user_func_array(explode('::', $functionCall), $args);
3871
+ } else {
3872
+ foreach ($args as &$arg) {
3873
+ $arg = PHPExcel_Calculation_Functions::flattenSingleValue($arg);
3874
+ }
3875
+ unset($arg);
3876
+ $result = call_user_func_array($functionCall, $args);
3877
+ }
3878
+ if ($functionName != 'MKMATRIX') {
3879
+ $this->_debugLog->writeDebugLog('Evaluation Result for ', self::localeFunc($functionName), '() function call is ', $this->showTypeDetails($result));
3880
+ }
3881
+ $stack->push('Value', self::wrapResult($result));
3882
+ }
3883
+
3884
+ } else {
3885
+ // if the token is a number, boolean, string or an Excel error, push it onto the stack
3886
+ if (isset(self::$excelConstants[strtoupper($token)])) {
3887
+ $excelConstant = strtoupper($token);
3888
+ // echo 'Token is a PHPExcel constant: '.$excelConstant.'<br />';
3889
+ $stack->push('Constant Value', self::$excelConstants[$excelConstant]);
3890
+ $this->_debugLog->writeDebugLog('Evaluating Constant ', $excelConstant, ' as ', $this->showTypeDetails(self::$excelConstants[$excelConstant]));
3891
+ } elseif ((is_numeric($token)) || ($token === null) || (is_bool($token)) || ($token == '') || ($token{0} == '"') || ($token{0} == '#')) {
3892
+ // echo 'Token is a number, boolean, string, null or an Excel error<br />';
3893
+ $stack->push('Value', $token);
3894
+ // if the token is a named range, push the named range name onto the stack
3895
+ } elseif (preg_match('/^'.self::CALCULATION_REGEXP_NAMEDRANGE.'$/i', $token, $matches)) {
3896
+ // echo 'Token is a named range<br />';
3897
+ $namedRange = $matches[6];
3898
+ // echo 'Named Range is '.$namedRange.'<br />';
3899
+ $this->_debugLog->writeDebugLog('Evaluating Named Range ', $namedRange);
3900
+ $cellValue = $this->extractNamedRange($namedRange, ((null !== $pCell) ? $pCellWorksheet : null), false);
3901
+ $pCell->attach($pCellParent);
3902
+ $this->_debugLog->writeDebugLog('Evaluation Result for named range ', $namedRange, ' is ', $this->showTypeDetails($cellValue));
3903
+ $stack->push('Named Range', $cellValue, $namedRange);
3904
+ } else {
3905
+ return $this->raiseFormulaError("undefined variable '$token'");
3906
+ }
3907
+ }
3908
+ }
3909
+ // when we're out of tokens, the stack should have a single element, the final result
3910
+ if ($stack->count() != 1) {
3911
+ return $this->raiseFormulaError("internal error");
3912
+ }
3913
+ $output = $stack->pop();
3914
+ $output = $output['value'];
3915
+
3916
+ // if ((is_array($output)) && (self::$returnArrayAsType != self::RETURN_ARRAY_AS_ARRAY)) {
3917
+ // return array_shift(PHPExcel_Calculation_Functions::flattenArray($output));
3918
+ // }
3919
+ return $output;
3920
+ }
3921
+
3922
+
3923
+ private function validateBinaryOperand($cellID, &$operand, &$stack)
3924
+ {
3925
+ if (is_array($operand)) {
3926
+ if ((count($operand, COUNT_RECURSIVE) - count($operand)) == 1) {
3927
+ do {
3928
+ $operand = array_pop($operand);
3929
+ } while (is_array($operand));
3930
+ }
3931
+ }
3932
+ // Numbers, matrices and booleans can pass straight through, as they're already valid
3933
+ if (is_string($operand)) {
3934
+ // We only need special validations for the operand if it is a string
3935
+ // Start by stripping off the quotation marks we use to identify true excel string values internally
3936
+ if ($operand > '' && $operand{0} == '"') {
3937
+ $operand = self::unwrapResult($operand);
3938
+ }
3939
+ // If the string is a numeric value, we treat it as a numeric, so no further testing
3940
+ if (!is_numeric($operand)) {
3941
+ // If not a numeric, test to see if the value is an Excel error, and so can't be used in normal binary operations
3942
+ if ($operand > '' && $operand{0} == '#') {
3943
+ $stack->push('Value', $operand);
3944
+ $this->_debugLog->writeDebugLog('Evaluation Result is ', $this->showTypeDetails($operand));
3945
+ return false;
3946
+ } elseif (!PHPExcel_Shared_String::convertToNumberIfFraction($operand)) {
3947
+ // If not a numeric or a fraction, then it's a text string, and so can't be used in mathematical binary operations
3948
+ $stack->push('Value', '#VALUE!');
3949
+ $this->_debugLog->writeDebugLog('Evaluation Result is a ', $this->showTypeDetails('#VALUE!'));
3950
+ return false;
3951
+ }
3952
+ }
3953
+ }
3954
+
3955
+ // return a true if the value of the operand is one that we can use in normal binary operations
3956
+ return true;
3957
+ }
3958
+
3959
+
3960
+ private function executeBinaryComparisonOperation($cellID, $operand1, $operand2, $operation, &$stack, $recursingArrays = false)
3961
+ {
3962
+ // If we're dealing with matrix operations, we want a matrix result
3963
+ if ((is_array($operand1)) || (is_array($operand2))) {
3964
+ $result = array();
3965
+ if ((is_array($operand1)) && (!is_array($operand2))) {
3966
+ foreach ($operand1 as $x => $operandData) {
3967
+ $this->_debugLog->writeDebugLog('Evaluating Comparison ', $this->showValue($operandData), ' ', $operation, ' ', $this->showValue($operand2));
3968
+ $this->executeBinaryComparisonOperation($cellID, $operandData, $operand2, $operation, $stack);
3969
+ $r = $stack->pop();
3970
+ $result[$x] = $r['value'];
3971
+ }
3972
+ } elseif ((!is_array($operand1)) && (is_array($operand2))) {
3973
+ foreach ($operand2 as $x => $operandData) {
3974
+ $this->_debugLog->writeDebugLog('Evaluating Comparison ', $this->showValue($operand1), ' ', $operation, ' ', $this->showValue($operandData));
3975
+ $this->executeBinaryComparisonOperation($cellID, $operand1, $operandData, $operation, $stack);
3976
+ $r = $stack->pop();
3977
+ $result[$x] = $r['value'];
3978
+ }
3979
+ } else {
3980
+ if (!$recursingArrays) {
3981
+ self::checkMatrixOperands($operand1, $operand2, 2);
3982
+ }
3983
+ foreach ($operand1 as $x => $operandData) {
3984
+ $this->_debugLog->writeDebugLog('Evaluating Comparison ', $this->showValue($operandData), ' ', $operation, ' ', $this->showValue($operand2[$x]));
3985
+ $this->executeBinaryComparisonOperation($cellID, $operandData, $operand2[$x], $operation, $stack, true);
3986
+ $r = $stack->pop();
3987
+ $result[$x] = $r['value'];
3988
+ }
3989
+ }
3990
+ // Log the result details
3991
+ $this->_debugLog->writeDebugLog('Comparison Evaluation Result is ', $this->showTypeDetails($result));
3992
+ // And push the result onto the stack
3993
+ $stack->push('Array', $result);
3994
+ return true;
3995
+ }
3996
+
3997
+ // Simple validate the two operands if they are string values
3998
+ if (is_string($operand1) && $operand1 > '' && $operand1{0} == '"') {
3999
+ $operand1 = self::unwrapResult($operand1);
4000
+ }
4001
+ if (is_string($operand2) && $operand2 > '' && $operand2{0} == '"') {
4002
+ $operand2 = self::unwrapResult($operand2);
4003
+ }
4004
+
4005
+ // Use case insensitive comparaison if not OpenOffice mode
4006
+ if (PHPExcel_Calculation_Functions::getCompatibilityMode() != PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) {
4007
+ if (is_string($operand1)) {
4008
+ $operand1 = strtoupper($operand1);
4009
+ }
4010
+ if (is_string($operand2)) {
4011
+ $operand2 = strtoupper($operand2);
4012
+ }
4013
+ }
4014
+
4015
+ $useLowercaseFirstComparison = is_string($operand1) && is_string($operand2) && PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE;
4016
+
4017
+ // execute the necessary operation
4018
+ switch ($operation) {
4019
+ // Greater than
4020
+ case '>':
4021
+ if ($useLowercaseFirstComparison) {
4022
+ $result = $this->strcmpLowercaseFirst($operand1, $operand2) > 0;
4023
+ } else {
4024
+ $result = ($operand1 > $operand2);
4025
+ }
4026
+ break;
4027
+ // Less than
4028
+ case '<':
4029
+ if ($useLowercaseFirstComparison) {
4030
+ $result = $this->strcmpLowercaseFirst($operand1, $operand2) < 0;
4031
+ } else {
4032
+ $result = ($operand1 < $operand2);
4033
+ }
4034
+ break;
4035
+ // Equality
4036
+ case '=':
4037
+ if (is_numeric($operand1) && is_numeric($operand2)) {
4038
+ $result = (abs($operand1 - $operand2) < $this->delta);
4039
+ } else {
4040
+ $result = strcmp($operand1, $operand2) == 0;
4041
+ }
4042
+ break;
4043
+ // Greater than or equal
4044
+ case '>=':
4045
+ if (is_numeric($operand1) && is_numeric($operand2)) {
4046
+ $result = ((abs($operand1 - $operand2) < $this->delta) || ($operand1 > $operand2));
4047
+ } elseif ($useLowercaseFirstComparison) {
4048
+ $result = $this->strcmpLowercaseFirst($operand1, $operand2) >= 0;
4049
+ } else {
4050
+ $result = strcmp($operand1, $operand2) >= 0;
4051
+ }
4052
+ break;
4053
+ // Less than or equal
4054
+ case '<=':
4055
+ if (is_numeric($operand1) && is_numeric($operand2)) {
4056
+ $result = ((abs($operand1 - $operand2) < $this->delta) || ($operand1 < $operand2));
4057
+ } elseif ($useLowercaseFirstComparison) {
4058
+ $result = $this->strcmpLowercaseFirst($operand1, $operand2) <= 0;
4059
+ } else {
4060
+ $result = strcmp($operand1, $operand2) <= 0;
4061
+ }
4062
+ break;
4063
+ // Inequality
4064
+ case '<>':
4065
+ if (is_numeric($operand1) && is_numeric($operand2)) {
4066
+ $result = (abs($operand1 - $operand2) > 1E-14);
4067
+ } else {
4068
+ $result = strcmp($operand1, $operand2) != 0;
4069
+ }
4070
+ break;
4071
+ }
4072
+
4073
+ // Log the result details
4074
+ $this->_debugLog->writeDebugLog('Evaluation Result is ', $this->showTypeDetails($result));
4075
+ // And push the result onto the stack
4076
+ $stack->push('Value', $result);
4077
+ return true;
4078
+ }
4079
+
4080
+ /**
4081
+ * Compare two strings in the same way as strcmp() except that lowercase come before uppercase letters
4082
+ * @param string $str1 First string value for the comparison
4083
+ * @param string $str2 Second string value for the comparison
4084
+ * @return integer
4085
+ */
4086
+ private function strcmpLowercaseFirst($str1, $str2)
4087
+ {
4088
+ $inversedStr1 = PHPExcel_Shared_String::StrCaseReverse($str1);
4089
+ $inversedStr2 = PHPExcel_Shared_String::StrCaseReverse($str2);
4090
+
4091
+ return strcmp($inversedStr1, $inversedStr2);
4092
+ }
4093
+
4094
+ private function executeNumericBinaryOperation($cellID, $operand1, $operand2, $operation, $matrixFunction, &$stack)
4095
+ {
4096
+ // Validate the two operands
4097
+ if (!$this->validateBinaryOperand($cellID, $operand1, $stack)) {
4098
+ return false;
4099
+ }
4100
+ if (!$this->validateBinaryOperand($cellID, $operand2, $stack)) {
4101
+ return false;
4102
+ }
4103
+
4104
+ // If either of the operands is a matrix, we need to treat them both as matrices
4105
+ // (converting the other operand to a matrix if need be); then perform the required
4106
+ // matrix operation
4107
+ if ((is_array($operand1)) || (is_array($operand2))) {
4108
+ // Ensure that both operands are arrays/matrices of the same size
4109
+ self::checkMatrixOperands($operand1, $operand2, 2);
4110
+
4111
+ try {
4112
+ // Convert operand 1 from a PHP array to a matrix
4113
+ $matrix = new PHPExcel_Shared_JAMA_Matrix($operand1);
4114
+ // Perform the required operation against the operand 1 matrix, passing in operand 2
4115
+ $matrixResult = $matrix->$matrixFunction($operand2);
4116
+ $result = $matrixResult->getArray();
4117
+ } catch (PHPExcel_Exception $ex) {
4118
+ $this->_debugLog->writeDebugLog('JAMA Matrix Exception: ', $ex->getMessage());
4119
+ $result = '#VALUE!';
4120
+ }
4121
+ } else {
4122
+ if ((PHPExcel_Calculation_Functions::getCompatibilityMode() != PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) &&
4123
+ ((is_string($operand1) && !is_numeric($operand1) && strlen($operand1)>0) ||
4124
+ (is_string($operand2) && !is_numeric($operand2) && strlen($operand2)>0))) {
4125
+ $result = PHPExcel_Calculation_Functions::VALUE();
4126
+ } else {
4127
+ // If we're dealing with non-matrix operations, execute the necessary operation
4128
+ switch ($operation) {
4129
+ // Addition
4130
+ case '+':
4131
+ $result = $operand1 + $operand2;
4132
+ break;
4133
+ // Subtraction
4134
+ case '-':
4135
+ $result = $operand1 - $operand2;
4136
+ break;
4137
+ // Multiplication
4138
+ case '*':
4139
+ $result = $operand1 * $operand2;
4140
+ break;
4141
+ // Division
4142
+ case '/':
4143
+ if ($operand2 == 0) {
4144
+ // Trap for Divide by Zero error
4145
+ $stack->push('Value', '#DIV/0!');
4146
+ $this->_debugLog->writeDebugLog('Evaluation Result is ', $this->showTypeDetails('#DIV/0!'));
4147
+ return false;
4148
+ } else {
4149
+ $result = $operand1 / $operand2;
4150
+ }
4151
+ break;
4152
+ // Power
4153
+ case '^':
4154
+ $result = pow($operand1, $operand2);
4155
+ break;
4156
+ }
4157
+ }
4158
+ }
4159
+
4160
+ // Log the result details
4161
+ $this->_debugLog->writeDebugLog('Evaluation Result is ', $this->showTypeDetails($result));
4162
+ // And push the result onto the stack
4163
+ $stack->push('Value', $result);
4164
+ return true;
4165
+ }
4166
+
4167
+
4168
+ // trigger an error, but nicely, if need be
4169
+ protected function raiseFormulaError($errorMessage)
4170
+ {
4171
+ $this->formulaError = $errorMessage;
4172
+ $this->cyclicReferenceStack->clear();
4173
+ if (!$this->suppressFormulaErrors) {
4174
+ throw new PHPExcel_Calculation_Exception($errorMessage);
4175
+ }
4176
+ trigger_error($errorMessage, E_USER_ERROR);
4177
+ }
4178
+
4179
+
4180
+ /**
4181
+ * Extract range values
4182
+ *
4183
+ * @param string &$pRange String based range representation
4184
+ * @param PHPExcel_Worksheet $pSheet Worksheet
4185
+ * @param boolean $resetLog Flag indicating whether calculation log should be reset or not
4186
+ * @return mixed Array of values in range if range contains more than one element. Otherwise, a single value is returned.
4187
+ * @throws PHPExcel_Calculation_Exception
4188
+ */
4189
+ public function extractCellRange(&$pRange = 'A1', PHPExcel_Worksheet $pSheet = null, $resetLog = true)
4190
+ {
4191
+ // Return value
4192
+ $returnValue = array ();
4193
+
4194
+ // echo 'extractCellRange('.$pRange.')', PHP_EOL;
4195
+ if ($pSheet !== null) {
4196
+ $pSheetName = $pSheet->getTitle();
4197
+ // echo 'Passed sheet name is '.$pSheetName.PHP_EOL;
4198
+ // echo 'Range reference is '.$pRange.PHP_EOL;
4199
+ if (strpos($pRange, '!') !== false) {
4200
+ // echo '$pRange reference includes sheet reference', PHP_EOL;
4201
+ list($pSheetName, $pRange) = PHPExcel_Worksheet::extractSheetTitle($pRange, true);
4202
+ // echo 'New sheet name is '.$pSheetName, PHP_EOL;
4203
+ // echo 'Adjusted Range reference is '.$pRange, PHP_EOL;
4204
+ $pSheet = $this->workbook->getSheetByName($pSheetName);
4205
+ }
4206
+
4207
+ // Extract range
4208
+ $aReferences = PHPExcel_Cell::extractAllCellReferencesInRange($pRange);
4209
+ $pRange = $pSheetName.'!'.$pRange;
4210
+ if (!isset($aReferences[1])) {
4211
+ // Single cell in range
4212
+ sscanf($aReferences[0], '%[A-Z]%d', $currentCol, $currentRow);
4213
+ $cellValue = null;
4214
+ if ($pSheet->cellExists($aReferences[0])) {
4215
+ $returnValue[$currentRow][$currentCol] = $pSheet->getCell($aReferences[0])->getCalculatedValue($resetLog);
4216
+ } else {
4217
+ $returnValue[$currentRow][$currentCol] = null;
4218
+ }
4219
+ } else {
4220
+ // Extract cell data for all cells in the range
4221
+ foreach ($aReferences as $reference) {
4222
+ // Extract range
4223
+ sscanf($reference, '%[A-Z]%d', $currentCol, $currentRow);
4224
+ $cellValue = null;
4225
+ if ($pSheet->cellExists($reference)) {
4226
+ $returnValue[$currentRow][$currentCol] = $pSheet->getCell($reference)->getCalculatedValue($resetLog);
4227
+ } else {
4228
+ $returnValue[$currentRow][$currentCol] = null;
4229
+ }
4230
+ }
4231
+ }
4232
+ }
4233
+
4234
+ return $returnValue;
4235
+ }
4236
+
4237
+
4238
+ /**
4239
+ * Extract range values
4240
+ *
4241
+ * @param string &$pRange String based range representation
4242
+ * @param PHPExcel_Worksheet $pSheet Worksheet
4243
+ * @return mixed Array of values in range if range contains more than one element. Otherwise, a single value is returned.
4244
+ * @param boolean $resetLog Flag indicating whether calculation log should be reset or not
4245
+ * @throws PHPExcel_Calculation_Exception
4246
+ */
4247
+ public function extractNamedRange(&$pRange = 'A1', PHPExcel_Worksheet $pSheet = null, $resetLog = true)
4248
+ {
4249
+ // Return value
4250
+ $returnValue = array ();
4251
+
4252
+ // echo 'extractNamedRange('.$pRange.')<br />';
4253
+ if ($pSheet !== null) {
4254
+ $pSheetName = $pSheet->getTitle();
4255
+ // echo 'Current sheet name is '.$pSheetName.'<br />';
4256
+ // echo 'Range reference is '.$pRange.'<br />';
4257
+ if (strpos($pRange, '!') !== false) {
4258
+ // echo '$pRange reference includes sheet reference', PHP_EOL;
4259
+ list($pSheetName, $pRange) = PHPExcel_Worksheet::extractSheetTitle($pRange, true);
4260
+ // echo 'New sheet name is '.$pSheetName, PHP_EOL;
4261
+ // echo 'Adjusted Range reference is '.$pRange, PHP_EOL;
4262
+ $pSheet = $this->workbook->getSheetByName($pSheetName);
4263
+ }
4264
+
4265
+ // Named range?
4266
+ $namedRange = PHPExcel_NamedRange::resolveRange($pRange, $pSheet);
4267
+ if ($namedRange !== null) {
4268
+ $pSheet = $namedRange->getWorksheet();
4269
+ // echo 'Named Range '.$pRange.' (';
4270
+ $pRange = $namedRange->getRange();
4271
+ $splitRange = PHPExcel_Cell::splitRange($pRange);
4272
+ // Convert row and column references
4273
+ if (ctype_alpha($splitRange[0][0])) {
4274
+ $pRange = $splitRange[0][0] . '1:' . $splitRange[0][1] . $namedRange->getWorksheet()->getHighestRow();
4275
+ } elseif (ctype_digit($splitRange[0][0])) {
4276
+ $pRange = 'A' . $splitRange[0][0] . ':' . $namedRange->getWorksheet()->getHighestColumn() . $splitRange[0][1];
4277
+ }
4278
+ // echo $pRange.') is in sheet '.$namedRange->getWorksheet()->getTitle().'<br />';
4279
+
4280
+ // if ($pSheet->getTitle() != $namedRange->getWorksheet()->getTitle()) {
4281
+ // if (!$namedRange->getLocalOnly()) {
4282
+ // $pSheet = $namedRange->getWorksheet();
4283
+ // } else {
4284
+ // return $returnValue;
4285
+ // }
4286
+ // }
4287
+ } else {
4288
+ return PHPExcel_Calculation_Functions::REF();
4289
+ }
4290
+
4291
+ // Extract range
4292
+ $aReferences = PHPExcel_Cell::extractAllCellReferencesInRange($pRange);
4293
+ // var_dump($aReferences);
4294
+ if (!isset($aReferences[1])) {
4295
+ // Single cell (or single column or row) in range
4296
+ list($currentCol, $currentRow) = PHPExcel_Cell::coordinateFromString($aReferences[0]);
4297
+ $cellValue = null;
4298
+ if ($pSheet->cellExists($aReferences[0])) {
4299
+ $returnValue[$currentRow][$currentCol] = $pSheet->getCell($aReferences[0])->getCalculatedValue($resetLog);
4300
+ } else {
4301
+ $returnValue[$currentRow][$currentCol] = null;
4302
+ }
4303
+ } else {
4304
+ // Extract cell data for all cells in the range
4305
+ foreach ($aReferences as $reference) {
4306
+ // Extract range
4307
+ list($currentCol, $currentRow) = PHPExcel_Cell::coordinateFromString($reference);
4308
+ // echo 'NAMED RANGE: $currentCol='.$currentCol.' $currentRow='.$currentRow.'<br />';
4309
+ $cellValue = null;
4310
+ if ($pSheet->cellExists($reference)) {
4311
+ $returnValue[$currentRow][$currentCol] = $pSheet->getCell($reference)->getCalculatedValue($resetLog);
4312
+ } else {
4313
+ $returnValue[$currentRow][$currentCol] = null;
4314
+ }
4315
+ }
4316
+ }
4317
+ // print_r($returnValue);
4318
+ // echo '<br />';
4319
+ }
4320
+
4321
+ return $returnValue;
4322
+ }
4323
+
4324
+
4325
+ /**
4326
+ * Is a specific function implemented?
4327
+ *
4328
+ * @param string $pFunction Function Name
4329
+ * @return boolean
4330
+ */
4331
+ public function isImplemented($pFunction = '')
4332
+ {
4333
+ $pFunction = strtoupper($pFunction);
4334
+ if (isset(self::$PHPExcelFunctions[$pFunction])) {
4335
+ return (self::$PHPExcelFunctions[$pFunction]['functionCall'] != 'PHPExcel_Calculation_Functions::DUMMY');
4336
+ } else {
4337
+ return false;
4338
+ }
4339
+ }
4340
+
4341
+
4342
+ /**
4343
+ * Get a list of all implemented functions as an array of function objects
4344
+ *
4345
+ * @return array of PHPExcel_Calculation_Function
4346
+ */
4347
+ public function listFunctions()
4348
+ {
4349
+ $returnValue = array();
4350
+
4351
+ foreach (self::$PHPExcelFunctions as $functionName => $function) {
4352
+ if ($function['functionCall'] != 'PHPExcel_Calculation_Functions::DUMMY') {
4353
+ $returnValue[$functionName] = new PHPExcel_Calculation_Function(
4354
+ $function['category'],
4355
+ $functionName,
4356
+ $function['functionCall']
4357
+ );
4358
+ }
4359
+ }
4360
+
4361
+ return $returnValue;
4362
+ }
4363
+
4364
+
4365
+ /**
4366
+ * Get a list of all Excel function names
4367
+ *
4368
+ * @return array
4369
+ */
4370
+ public function listAllFunctionNames()
4371
+ {
4372
+ return array_keys(self::$PHPExcelFunctions);
4373
+ }
4374
+
4375
+ /**
4376
+ * Get a list of implemented Excel function names
4377
+ *
4378
+ * @return array
4379
+ */
4380
+ public function listFunctionNames()
4381
+ {
4382
+ $returnValue = array();
4383
+ foreach (self::$PHPExcelFunctions as $functionName => $function) {
4384
+ if ($function['functionCall'] != 'PHPExcel_Calculation_Functions::DUMMY') {
4385
+ $returnValue[] = $functionName;
4386
+ }
4387
+ }
4388
+
4389
+ return $returnValue;
4390
+ }
4391
+ }
PHPExcel/Classes/PHPExcel/Calculation/Database.php CHANGED
@@ -1,725 +1,676 @@
1
- <?php
2
- /**
3
- * PHPExcel
4
- *
5
- * Copyright (c) 2006 - 2014 PHPExcel
6
- *
7
- * This library is free software; you can redistribute it and/or
8
- * modify it under the terms of the GNU Lesser General Public
9
- * License as published by the Free Software Foundation; either
10
- * version 2.1 of the License, or (at your option) any later version.
11
- *
12
- * This library is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
- * Lesser General Public License for more details.
16
- *
17
- * You should have received a copy of the GNU Lesser General Public
18
- * License along with this library; if not, write to the Free Software
19
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
- *
21
- * @category PHPExcel
22
- * @package PHPExcel_Calculation
23
- * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
24
- * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25
- * @version 1.8.0, 2014-03-02
26
- */
27
-
28
-
29
- /** PHPExcel root directory */
30
- if (!defined('PHPEXCEL_ROOT')) {
31
- /**
32
- * @ignore
33
- */
34
- define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
35
- require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
36
- }
37
-
38
-
39
- /**
40
- * PHPExcel_Calculation_Database
41
- *
42
- * @category PHPExcel
43
- * @package PHPExcel_Calculation
44
- * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
45
- */
46
- class PHPExcel_Calculation_Database {
47
-
48
-
49
- /**
50
- * __fieldExtract
51
- *
52
- * Extracts the column ID to use for the data field.
53
- *
54
- * @access private
55
- * @param mixed[] $database The range of cells that makes up the list or database.
56
- * A database is a list of related data in which rows of related
57
- * information are records, and columns of data are fields. The
58
- * first row of the list contains labels for each column.
59
- * @param mixed $field Indicates which column is used in the function. Enter the
60
- * column label enclosed between double quotation marks, such as
61
- * "Age" or "Yield," or a number (without quotation marks) that
62
- * represents the position of the column within the list: 1 for
63
- * the first column, 2 for the second column, and so on.
64
- * @return string|NULL
65
- *
66
- */
67
- private static function __fieldExtract($database,$field) {
68
- $field = strtoupper(PHPExcel_Calculation_Functions::flattenSingleValue($field));
69
- $fieldNames = array_map('strtoupper',array_shift($database));
70
-
71
- if (is_numeric($field)) {
72
- $keys = array_keys($fieldNames);
73
- return $keys[$field-1];
74
- }
75
- $key = array_search($field,$fieldNames);
76
- return ($key) ? $key : NULL;
77
- }
78
-
79
- /**
80
- * __filter
81
- *
82
- * Parses the selection criteria, extracts the database rows that match those criteria, and
83
- * returns that subset of rows.
84
- *
85
- * @access private
86
- * @param mixed[] $database The range of cells that makes up the list or database.
87
- * A database is a list of related data in which rows of related
88
- * information are records, and columns of data are fields. The
89
- * first row of the list contains labels for each column.
90
- * @param mixed[] $criteria The range of cells that contains the conditions you specify.
91
- * You can use any range for the criteria argument, as long as it
92
- * includes at least one column label and at least one cell below
93
- * the column label in which you specify a condition for the
94
- * column.
95
- * @return array of mixed
96
- *
97
- */
98
- private static function __filter($database,$criteria) {
99
- $fieldNames = array_shift($database);
100
- $criteriaNames = array_shift($criteria);
101
-
102
- // Convert the criteria into a set of AND/OR conditions with [:placeholders]
103
- $testConditions = $testValues = array();
104
- $testConditionsCount = 0;
105
- foreach($criteriaNames as $key => $criteriaName) {
106
- $testCondition = array();
107
- $testConditionCount = 0;
108
- foreach($criteria as $row => $criterion) {
109
- if ($criterion[$key] > '') {
110
- $testCondition[] = '[:'.$criteriaName.']'.PHPExcel_Calculation_Functions::_ifCondition($criterion[$key]);
111
- $testConditionCount++;
112
- }
113
- }
114
- if ($testConditionCount > 1) {
115
- $testConditions[] = 'OR('.implode(',',$testCondition).')';
116
- $testConditionsCount++;
117
- } elseif($testConditionCount == 1) {
118
- $testConditions[] = $testCondition[0];
119
- $testConditionsCount++;
120
- }
121
- }
122
-
123
- if ($testConditionsCount > 1) {
124
- $testConditionSet = 'AND('.implode(',',$testConditions).')';
125
- } elseif($testConditionsCount == 1) {
126
- $testConditionSet = $testConditions[0];
127
- }
128
-
129
- // Loop through each row of the database
130
- foreach($database as $dataRow => $dataValues) {
131
- // Substitute actual values from the database row for our [:placeholders]
132
- $testConditionList = $testConditionSet;
133
- foreach($criteriaNames as $key => $criteriaName) {
134
- $k = array_search($criteriaName,$fieldNames);
135
- if (isset($dataValues[$k])) {
136
- $dataValue = $dataValues[$k];
137
- $dataValue = (is_string($dataValue)) ? PHPExcel_Calculation::_wrapResult(strtoupper($dataValue)) : $dataValue;
138
- $testConditionList = str_replace('[:'.$criteriaName.']',$dataValue,$testConditionList);
139
- }
140
- }
141
- // evaluate the criteria against the row data
142
- $result = PHPExcel_Calculation::getInstance()->_calculateFormulaValue('='.$testConditionList);
143
- // If the row failed to meet the criteria, remove it from the database
144
- if (!$result) {
145
- unset($database[$dataRow]);
146
- }
147
- }
148
-
149
- return $database;
150
- }
151
-
152
-
153
- /**
154
- * DAVERAGE
155
- *
156
- * Averages the values in a column of a list or database that match conditions you specify.
157
- *
158
- * Excel Function:
159
- * DAVERAGE(database,field,criteria)
160
- *
161
- * @access public
162
- * @category Database Functions
163
- * @param mixed[] $database The range of cells that makes up the list or database.
164
- * A database is a list of related data in which rows of related
165
- * information are records, and columns of data are fields. The
166
- * first row of the list contains labels for each column.
167
- * @param string|integer $field Indicates which column is used in the function. Enter the
168
- * column label enclosed between double quotation marks, such as
169
- * "Age" or "Yield," or a number (without quotation marks) that
170
- * represents the position of the column within the list: 1 for
171
- * the first column, 2 for the second column, and so on.
172
- * @param mixed[] $criteria The range of cells that contains the conditions you specify.
173
- * You can use any range for the criteria argument, as long as it
174
- * includes at least one column label and at least one cell below
175
- * the column label in which you specify a condition for the
176
- * column.
177
- * @return float
178
- *
179
- */
180
- public static function DAVERAGE($database,$field,$criteria) {
181
- $field = self::__fieldExtract($database,$field);
182
- if (is_null($field)) {
183
- return NULL;
184
- }
185
- // reduce the database to a set of rows that match all the criteria
186
- $database = self::__filter($database,$criteria);
187
- // extract an array of values for the requested column
188
- $colData = array();
189
- foreach($database as $row) {
190
- $colData[] = $row[$field];
191
- }
192
-
193
- // Return
194
- return PHPExcel_Calculation_Statistical::AVERAGE($colData);
195
- } // function DAVERAGE()
196
-
197
-
198
- /**
199
- * DCOUNT
200
- *
201
- * Counts the cells that contain numbers in a column of a list or database that match conditions
202
- * that you specify.
203
- *
204
- * Excel Function:
205
- * DCOUNT(database,[field],criteria)
206
- *
207
- * Excel Function:
208
- * DAVERAGE(database,field,criteria)
209
- *
210
- * @access public
211
- * @category Database Functions
212
- * @param mixed[] $database The range of cells that makes up the list or database.
213
- * A database is a list of related data in which rows of related
214
- * information are records, and columns of data are fields. The
215
- * first row of the list contains labels for each column.
216
- * @param string|integer $field Indicates which column is used in the function. Enter the
217
- * column label enclosed between double quotation marks, such as
218
- * "Age" or "Yield," or a number (without quotation marks) that
219
- * represents the position of the column within the list: 1 for
220
- * the first column, 2 for the second column, and so on.
221
- * @param mixed[] $criteria The range of cells that contains the conditions you specify.
222
- * You can use any range for the criteria argument, as long as it
223
- * includes at least one column label and at least one cell below
224
- * the column label in which you specify a condition for the
225
- * column.
226
- * @return integer
227
- *
228
- * @TODO The field argument is optional. If field is omitted, DCOUNT counts all records in the
229
- * database that match the criteria.
230
- *
231
- */
232
- public static function DCOUNT($database,$field,$criteria) {
233
- $field = self::__fieldExtract($database,$field);
234
- if (is_null($field)) {
235
- return NULL;
236
- }
237
-
238
- // reduce the database to a set of rows that match all the criteria
239
- $database = self::__filter($database,$criteria);
240
- // extract an array of values for the requested column
241
- $colData = array();
242
- foreach($database as $row) {
243
- $colData[] = $row[$field];
244
- }
245
-
246
- // Return
247
- return PHPExcel_Calculation_Statistical::COUNT($colData);
248
- } // function DCOUNT()
249
-
250
-
251
- /**
252
- * DCOUNTA
253
- *
254
- * Counts the nonblank cells in a column of a list or database that match conditions that you specify.
255
- *
256
- * Excel Function:
257
- * DCOUNTA(database,[field],criteria)
258
- *
259
- * @access public
260
- * @category Database Functions
261
- * @param mixed[] $database The range of cells that makes up the list or database.
262
- * A database is a list of related data in which rows of related
263
- * information are records, and columns of data are fields. The
264
- * first row of the list contains labels for each column.
265
- * @param string|integer $field Indicates which column is used in the function. Enter the
266
- * column label enclosed between double quotation marks, such as
267
- * "Age" or "Yield," or a number (without quotation marks) that
268
- * represents the position of the column within the list: 1 for
269
- * the first column, 2 for the second column, and so on.
270
- * @param mixed[] $criteria The range of cells that contains the conditions you specify.
271
- * You can use any range for the criteria argument, as long as it
272
- * includes at least one column label and at least one cell below
273
- * the column label in which you specify a condition for the
274
- * column.
275
- * @return integer
276
- *
277
- * @TODO The field argument is optional. If field is omitted, DCOUNTA counts all records in the
278
- * database that match the criteria.
279
- *
280
- */
281
- public static function DCOUNTA($database,$field,$criteria) {
282
- $field = self::__fieldExtract($database,$field);
283
- if (is_null($field)) {
284
- return NULL;
285
- }
286
-
287
- // reduce the database to a set of rows that match all the criteria
288
- $database = self::__filter($database,$criteria);
289
- // extract an array of values for the requested column
290
- $colData = array();
291
- foreach($database as $row) {
292
- $colData[] = $row[$field];
293
- }
294
-
295
- // Return
296
- return PHPExcel_Calculation_Statistical::COUNTA($colData);
297
- } // function DCOUNTA()
298
-
299
-
300
- /**
301
- * DGET
302
- *
303
- * Extracts a single value from a column of a list or database that matches conditions that you
304
- * specify.
305
- *
306
- * Excel Function:
307
- * DGET(database,field,criteria)
308
- *
309
- * @access public
310
- * @category Database Functions
311
- * @param mixed[] $database The range of cells that makes up the list or database.
312
- * A database is a list of related data in which rows of related
313
- * information are records, and columns of data are fields. The
314
- * first row of the list contains labels for each column.
315
- * @param string|integer $field Indicates which column is used in the function. Enter the
316
- * column label enclosed between double quotation marks, such as
317
- * "Age" or "Yield," or a number (without quotation marks) that
318
- * represents the position of the column within the list: 1 for
319
- * the first column, 2 for the second column, and so on.
320
- * @param mixed[] $criteria The range of cells that contains the conditions you specify.
321
- * You can use any range for the criteria argument, as long as it
322
- * includes at least one column label and at least one cell below
323
- * the column label in which you specify a condition for the
324
- * column.
325
- * @return mixed
326
- *
327
- */
328
- public static function DGET($database,$field,$criteria) {
329
- $field = self::__fieldExtract($database,$field);
330
- if (is_null($field)) {
331
- return NULL;
332
- }
333
-
334
- // reduce the database to a set of rows that match all the criteria
335
- $database = self::__filter($database,$criteria);
336
- // extract an array of values for the requested column
337
- $colData = array();
338
- foreach($database as $row) {
339
- $colData[] = $row[$field];
340
- }
341
-
342
- // Return
343
- if (count($colData) > 1) {
344
- return PHPExcel_Calculation_Functions::NaN();
345
- }
346
-
347
- return $colData[0];
348
- } // function DGET()
349
-
350
-
351
- /**
352
- * DMAX
353
- *
354
- * Returns the largest number in a column of a list or database that matches conditions you that
355
- * specify.
356
- *
357
- * Excel Function:
358
- * DMAX(database,field,criteria)
359
- *
360
- * @access public
361
- * @category Database Functions
362
- * @param mixed[] $database The range of cells that makes up the list or database.
363
- * A database is a list of related data in which rows of related
364
- * information are records, and columns of data are fields. The
365
- * first row of the list contains labels for each column.
366
- * @param string|integer $field Indicates which column is used in the function. Enter the
367
- * column label enclosed between double quotation marks, such as
368
- * "Age" or "Yield," or a number (without quotation marks) that
369
- * represents the position of the column within the list: 1 for
370
- * the first column, 2 for the second column, and so on.
371
- * @param mixed[] $criteria The range of cells that contains the conditions you specify.
372
- * You can use any range for the criteria argument, as long as it
373
- * includes at least one column label and at least one cell below
374
- * the column label in which you specify a condition for the
375
- * column.
376
- * @return float
377
- *
378
- */
379
- public static function DMAX($database,$field,$criteria) {
380
- $field = self::__fieldExtract($database,$field);
381
- if (is_null($field)) {
382
- return NULL;
383
- }
384
-
385
- // reduce the database to a set of rows that match all the criteria
386
- $database = self::__filter($database,$criteria);
387
- // extract an array of values for the requested column
388
- $colData = array();
389
- foreach($database as $row) {
390
- $colData[] = $row[$field];
391
- }
392
-
393
- // Return
394
- return PHPExcel_Calculation_Statistical::MAX($colData);
395
- } // function DMAX()
396
-
397
-
398
- /**
399
- * DMIN
400
- *
401
- * Returns the smallest number in a column of a list or database that matches conditions you that
402
- * specify.
403
- *
404
- * Excel Function:
405
- * DMIN(database,field,criteria)
406
- *
407
- * @access public
408
- * @category Database Functions
409
- * @param mixed[] $database The range of cells that makes up the list or database.
410
- * A database is a list of related data in which rows of related
411
- * information are records, and columns of data are fields. The
412
- * first row of the list contains labels for each column.
413
- * @param string|integer $field Indicates which column is used in the function. Enter the
414
- * column label enclosed between double quotation marks, such as
415
- * "Age" or "Yield," or a number (without quotation marks) that
416
- * represents the position of the column within the list: 1 for
417
- * the first column, 2 for the second column, and so on.
418
- * @param mixed[] $criteria The range of cells that contains the conditions you specify.
419
- * You can use any range for the criteria argument, as long as it
420
- * includes at least one column label and at least one cell below
421
- * the column label in which you specify a condition for the
422
- * column.
423
- * @return float
424
- *
425
- */
426
- public static function DMIN($database,$field,$criteria) {
427
- $field = self::__fieldExtract($database,$field);
428
- if (is_null($field)) {
429
- return NULL;
430
- }
431
-
432
- // reduce the database to a set of rows that match all the criteria
433
- $database = self::__filter($database,$criteria);
434
- // extract an array of values for the requested column
435
- $colData = array();
436
- foreach($database as $row) {
437
- $colData[] = $row[$field];
438
- }
439
-
440
- // Return
441
- return PHPExcel_Calculation_Statistical::MIN($colData);
442
- } // function DMIN()
443
-
444
-
445
- /**
446
- * DPRODUCT
447
- *
448
- * Multiplies the values in a column of a list or database that match conditions that you specify.
449
- *
450
- * Excel Function:
451
- * DPRODUCT(database,field,criteria)
452
- *
453
- * @access public
454
- * @category Database Functions
455
- * @param mixed[] $database The range of cells that makes up the list or database.
456
- * A database is a list of related data in which rows of related
457
- * information are records, and columns of data are fields. The
458
- * first row of the list contains labels for each column.
459
- * @param string|integer $field Indicates which column is used in the function. Enter the
460
- * column label enclosed between double quotation marks, such as
461
- * "Age" or "Yield," or a number (without quotation marks) that
462
- * represents the position of the column within the list: 1 for
463
- * the first column, 2 for the second column, and so on.
464
- * @param mixed[] $criteria The range of cells that contains the conditions you specify.
465
- * You can use any range for the criteria argument, as long as it
466
- * includes at least one column label and at least one cell below
467
- * the column label in which you specify a condition for the
468
- * column.
469
- * @return float
470
- *
471
- */
472
- public static function DPRODUCT($database,$field,$criteria) {
473
- $field = self::__fieldExtract($database,$field);
474
- if (is_null($field)) {
475
- return NULL;
476
- }
477
-
478
- // reduce the database to a set of rows that match all the criteria
479
- $database = self::__filter($database,$criteria);
480
- // extract an array of values for the requested column
481
- $colData = array();
482
- foreach($database as $row) {
483
- $colData[] = $row[$field];
484
- }
485
-
486
- // Return
487
- return PHPExcel_Calculation_MathTrig::PRODUCT($colData);
488
- } // function DPRODUCT()
489
-
490
-
491
- /**
492
- * DSTDEV
493
- *
494
- * Estimates the standard deviation of a population based on a sample by using the numbers in a
495
- * column of a list or database that match conditions that you specify.
496
- *
497
- * Excel Function:
498
- * DSTDEV(database,field,criteria)
499
- *
500
- * @access public
501
- * @category Database Functions
502
- * @param mixed[] $database The range of cells that makes up the list or database.
503
- * A database is a list of related data in which rows of related
504
- * information are records, and columns of data are fields. The
505
- * first row of the list contains labels for each column.
506
- * @param string|integer $field Indicates which column is used in the function. Enter the
507
- * column label enclosed between double quotation marks, such as
508
- * "Age" or "Yield," or a number (without quotation marks) that
509
- * represents the position of the column within the list: 1 for
510
- * the first column, 2 for the second column, and so on.
511
- * @param mixed[] $criteria The range of cells that contains the conditions you specify.
512
- * You can use any range for the criteria argument, as long as it
513
- * includes at least one column label and at least one cell below
514
- * the column label in which you specify a condition for the
515
- * column.
516
- * @return float
517
- *
518
- */
519
- public static function DSTDEV($database,$field,$criteria) {
520
- $field = self::__fieldExtract($database,$field);
521
- if (is_null($field)) {
522
- return NULL;
523
- }
524
-
525
- // reduce the database to a set of rows that match all the criteria
526
- $database = self::__filter($database,$criteria);
527
- // extract an array of values for the requested column
528
- $colData = array();
529
- foreach($database as $row) {
530
- $colData[] = $row[$field];
531
- }
532
-
533
- // Return
534
- return PHPExcel_Calculation_Statistical::STDEV($colData);
535
- } // function DSTDEV()
536
-
537
-
538
- /**
539
- * DSTDEVP
540
- *
541
- * Calculates the standard deviation of a population based on the entire population by using the
542
- * numbers in a column of a list or database that match conditions that you specify.
543
- *
544
- * Excel Function:
545
- * DSTDEVP(database,field,criteria)
546
- *
547
- * @access public
548
- * @category Database Functions
549
- * @param mixed[] $database The range of cells that makes up the list or database.
550
- * A database is a list of related data in which rows of related
551
- * information are records, and columns of data are fields. The
552
- * first row of the list contains labels for each column.
553
- * @param string|integer $field Indicates which column is used in the function. Enter the
554
- * column label enclosed between double quotation marks, such as
555
- * "Age" or "Yield," or a number (without quotation marks) that
556
- * represents the position of the column within the list: 1 for
557
- * the first column, 2 for the second column, and so on.
558
- * @param mixed[] $criteria The range of cells that contains the conditions you specify.
559
- * You can use any range for the criteria argument, as long as it
560
- * includes at least one column label and at least one cell below
561
- * the column label in which you specify a condition for the
562
- * column.
563
- * @return float
564
- *
565
- */
566
- public static function DSTDEVP($database,$field,$criteria) {
567
- $field = self::__fieldExtract($database,$field);
568
- if (is_null($field)) {
569
- return NULL;
570
- }
571
-
572
- // reduce the database to a set of rows that match all the criteria
573
- $database = self::__filter($database,$criteria);
574
- // extract an array of values for the requested column
575
- $colData = array();
576
- foreach($database as $row) {
577
- $colData[] = $row[$field];
578
- }
579
-
580
- // Return
581
- return PHPExcel_Calculation_Statistical::STDEVP($colData);
582
- } // function DSTDEVP()
583
-
584
-
585
- /**
586
- * DSUM
587
- *
588
- * Adds the numbers in a column of a list or database that match conditions that you specify.
589
- *
590
- * Excel Function:
591
- * DSUM(database,field,criteria)
592
- *
593
- * @access public
594
- * @category Database Functions
595
- * @param mixed[] $database The range of cells that makes up the list or database.
596
- * A database is a list of related data in which rows of related
597
- * information are records, and columns of data are fields. The
598
- * first row of the list contains labels for each column.
599
- * @param string|integer $field Indicates which column is used in the function. Enter the
600
- * column label enclosed between double quotation marks, such as
601
- * "Age" or "Yield," or a number (without quotation marks) that
602
- * represents the position of the column within the list: 1 for
603
- * the first column, 2 for the second column, and so on.
604
- * @param mixed[] $criteria The range of cells that contains the conditions you specify.
605
- * You can use any range for the criteria argument, as long as it
606
- * includes at least one column label and at least one cell below
607
- * the column label in which you specify a condition for the
608
- * column.
609
- * @return float
610
- *
611
- */
612
- public static function DSUM($database,$field,$criteria) {
613
- $field = self::__fieldExtract($database,$field);
614
- if (is_null($field)) {
615
- return NULL;
616
- }
617
-
618
- // reduce the database to a set of rows that match all the criteria
619
- $database = self::__filter($database,$criteria);
620
- // extract an array of values for the requested column
621
- $colData = array();
622
- foreach($database as $row) {
623
- $colData[] = $row[$field];
624
- }
625
-
626
- // Return
627
- return PHPExcel_Calculation_MathTrig::SUM($colData);
628
- } // function DSUM()
629
-
630
-
631
- /**
632
- * DVAR
633
- *
634
- * Estimates the variance of a population based on a sample by using the numbers in a column
635
- * of a list or database that match conditions that you specify.
636
- *
637
- * Excel Function:
638
- * DVAR(database,field,criteria)
639
- *
640
- * @access public
641
- * @category Database Functions
642
- * @param mixed[] $database The range of cells that makes up the list or database.
643
- * A database is a list of related data in which rows of related
644
- * information are records, and columns of data are fields. The
645
- * first row of the list contains labels for each column.
646
- * @param string|integer $field Indicates which column is used in the function. Enter the
647
- * column label enclosed between double quotation marks, such as
648
- * "Age" or "Yield," or a number (without quotation marks) that
649
- * represents the position of the column within the list: 1 for
650
- * the first column, 2 for the second column, and so on.
651
- * @param mixed[] $criteria The range of cells that contains the conditions you specify.
652
- * You can use any range for the criteria argument, as long as it
653
- * includes at least one column label and at least one cell below
654
- * the column label in which you specify a condition for the
655
- * column.
656
- * @return float
657
- *
658
- */
659
- public static function DVAR($database,$field,$criteria) {
660
- $field = self::__fieldExtract($database,$field);
661
- if (is_null($field)) {
662
- return NULL;
663
- }
664
-
665
- // reduce the database to a set of rows that match all the criteria
666
- $database = self::__filter($database,$criteria);
667
- // extract an array of values for the requested column
668
- $colData = array();
669
- foreach($database as $row) {
670
- $colData[] = $row[$field];
671
- }
672
-
673
- // Return
674
- return PHPExcel_Calculation_Statistical::VARFunc($colData);
675
- } // function DVAR()
676
-
677
-
678
- /**
679
- * DVARP
680
- *
681
- * Calculates the variance of a population based on the entire population by using the numbers
682
- * in a column of a list or database that match conditions that you specify.
683
- *
684
- * Excel Function:
685
- * DVARP(database,field,criteria)
686
- *
687
- * @access public
688
- * @category Database Functions
689
- * @param mixed[] $database The range of cells that makes up the list or database.
690
- * A database is a list of related data in which rows of related
691
- * information are records, and columns of data are fields. The
692
- * first row of the list contains labels for each column.
693
- * @param string|integer $field Indicates which column is used in the function. Enter the
694
- * column label enclosed between double quotation marks, such as
695
- * "Age" or "Yield," or a number (without quotation marks) that
696
- * represents the position of the column within the list: 1 for
697
- * the first column, 2 for the second column, and so on.
698
- * @param mixed[] $criteria The range of cells that contains the conditions you specify.
699
- * You can use any range for the criteria argument, as long as it
700
- * includes at least one column label and at least one cell below
701
- * the column label in which you specify a condition for the
702
- * column.
703
- * @return float
704
- *
705
- */
706
- public static function DVARP($database,$field,$criteria) {
707
- $field = self::__fieldExtract($database,$field);
708
- if (is_null($field)) {
709
- return NULL;
710
- }
711
-
712
- // reduce the database to a set of rows that match all the criteria
713
- $database = self::__filter($database,$criteria);
714
- // extract an array of values for the requested column
715
- $colData = array();
716
- foreach($database as $row) {
717
- $colData[] = $row[$field];
718
- }
719
-
720
- // Return
721
- return PHPExcel_Calculation_Statistical::VARP($colData);
722
- } // function DVARP()
723
-
724
-
725
- } // class PHPExcel_Calculation_Database
1
+ <?php
2
+
3
+ /** PHPExcel root directory */
4
+ if (!defined('PHPEXCEL_ROOT')) {
5
+ /**
6
+ * @ignore
7
+ */
8
+ define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
9
+ require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
10
+ }
11
+
12
+ /**
13
+ * PHPExcel_Calculation_Database
14
+ *
15
+ * Copyright (c) 2006 - 2015 PHPExcel
16
+ *
17
+ * This library is free software; you can redistribute it and/or
18
+ * modify it under the terms of the GNU Lesser General Public
19
+ * License as published by the Free Software Foundation; either
20
+ * version 2.1 of the License, or (at your option) any later version.
21
+ *
22
+ * This library is distributed in the hope that it will be useful,
23
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
24
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25
+ * Lesser General Public License for more details.
26
+ *
27
+ * You should have received a copy of the GNU Lesser General Public
28
+ * License along with this library; if not, write to the Free Software
29
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
30
+ *
31
+ * @category PHPExcel
32
+ * @package PHPExcel_Calculation
33
+ * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
34
+ * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
35
+ * @version ##VERSION##, ##DATE##
36
+ */
37
+ class PHPExcel_Calculation_Database
38
+ {
39
+ /**
40
+ * fieldExtract
41
+ *
42
+ * Extracts the column ID to use for the data field.
43
+ *
44
+ * @access private
45
+ * @param mixed[] $database The range of cells that makes up the list or database.
46
+ * A database is a list of related data in which rows of related
47
+ * information are records, and columns of data are fields. The
48
+ * first row of the list contains labels for each column.
49
+ * @param mixed $field Indicates which column is used in the function. Enter the
50
+ * column label enclosed between double quotation marks, such as
51
+ * "Age" or "Yield," or a number (without quotation marks) that
52
+ * represents the position of the column within the list: 1 for
53
+ * the first column, 2 for the second column, and so on.
54
+ * @return string|NULL
55
+ *
56
+ */
57
+ private static function fieldExtract($database, $field)
58
+ {
59
+ $field = strtoupper(PHPExcel_Calculation_Functions::flattenSingleValue($field));
60
+ $fieldNames = array_map('strtoupper', array_shift($database));
61
+
62
+ if (is_numeric($field)) {
63
+ $keys = array_keys($fieldNames);
64
+ return $keys[$field-1];
65
+ }
66
+ $key = array_search($field, $fieldNames);
67
+ return ($key) ? $key : null;
68
+ }
69
+
70
+ /**
71
+ * filter
72
+ *
73
+ * Parses the selection criteria, extracts the database rows that match those criteria, and
74
+ * returns that subset of rows.
75
+ *
76
+ * @access private
77
+ * @param mixed[] $database The range of cells that makes up the list or database.
78
+ * A database is a list of related data in which rows of related
79
+ * information are records, and columns of data are fields. The
80
+ * first row of the list contains labels for each column.
81
+ * @param mixed[] $criteria The range of cells that contains the conditions you specify.
82
+ * You can use any range for the criteria argument, as long as it
83
+ * includes at least one column label and at least one cell below
84
+ * the column label in which you specify a condition for the
85
+ * column.
86
+ * @return array of mixed
87
+ *
88
+ */
89
+ private static function filter($database, $criteria)
90
+ {
91
+ $fieldNames = array_shift($database);
92
+ $criteriaNames = array_shift($criteria);
93
+
94
+ // Convert the criteria into a set of AND/OR conditions with [:placeholders]
95
+ $testConditions = $testValues = array();
96
+ $testConditionsCount = 0;
97
+ foreach ($criteriaNames as $key => $criteriaName) {
98
+ $testCondition = array();
99
+ $testConditionCount = 0;
100
+ foreach ($criteria as $row => $criterion) {
101
+ if ($criterion[$key] > '') {
102
+ $testCondition[] = '[:'.$criteriaName.']'.PHPExcel_Calculation_Functions::ifCondition($criterion[$key]);
103
+ $testConditionCount++;
104
+ }
105
+ }
106
+ if ($testConditionCount > 1) {
107
+ $testConditions[] = 'OR(' . implode(',', $testCondition) . ')';
108
+ $testConditionsCount++;
109
+ } elseif ($testConditionCount == 1) {
110
+ $testConditions[] = $testCondition[0];
111
+ $testConditionsCount++;
112
+ }
113
+ }
114
+
115
+ if ($testConditionsCount > 1) {
116
+ $testConditionSet = 'AND(' . implode(',', $testConditions) . ')';
117
+ } elseif ($testConditionsCount == 1) {
118
+ $testConditionSet = $testConditions[0];
119
+ }
120
+
121
+ // Loop through each row of the database
122
+ foreach ($database as $dataRow => $dataValues) {
123
+ // Substitute actual values from the database row for our [:placeholders]
124
+ $testConditionList = $testConditionSet;
125
+ foreach ($criteriaNames as $key => $criteriaName) {
126
+ $k = array_search($criteriaName, $fieldNames);
127
+ if (isset($dataValues[$k])) {
128
+ $dataValue = $dataValues[$k];
129
+ $dataValue = (is_string($dataValue)) ? PHPExcel_Calculation::wrapResult(strtoupper($dataValue)) : $dataValue;
130
+ $testConditionList = str_replace('[:' . $criteriaName . ']', $dataValue, $testConditionList);
131
+ }
132
+ }
133
+ // evaluate the criteria against the row data
134
+ $result = PHPExcel_Calculation::getInstance()->_calculateFormulaValue('='.$testConditionList);
135
+ // If the row failed to meet the criteria, remove it from the database
136
+ if (!$result) {
137
+ unset($database[$dataRow]);
138
+ }
139
+ }
140
+
141
+ return $database;
142
+ }
143
+
144
+
145
+ private static function getFilteredColumn($database, $field, $criteria)
146
+ {
147
+ // reduce the database to a set of rows that match all the criteria
148
+ $database = self::filter($database, $criteria);
149
+ // extract an array of values for the requested column
150
+ $colData = array();
151
+ foreach ($database as $row) {
152
+ $colData[] = $row[$field];
153
+ }
154
+
155
+ return $colData;
156
+ }
157
+
158
+ /**
159
+ * DAVERAGE
160
+ *
161
+ * Averages the values in a column of a list or database that match conditions you specify.
162
+ *
163
+ * Excel Function:
164
+ * DAVERAGE(database,field,criteria)
165
+ *
166
+ * @access public
167
+ * @category Database Functions
168
+ * @param mixed[] $database The range of cells that makes up the list or database.
169
+ * A database is a list of related data in which rows of related
170
+ * information are records, and columns of data are fields. The
171
+ * first row of the list contains labels for each column.
172
+ * @param string|integer $field Indicates which column is used in the function. Enter the
173
+ * column label enclosed between double quotation marks, such as
174
+ * "Age" or "Yield," or a number (without quotation marks) that
175
+ * represents the position of the column within the list: 1 for
176
+ * the first column, 2 for the second column, and so on.
177
+ * @param mixed[] $criteria The range of cells that contains the conditions you specify.
178
+ * You can use any range for the criteria argument, as long as it
179
+ * includes at least one column label and at least one cell below
180
+ * the column label in which you specify a condition for the
181
+ * column.
182
+ * @return float
183
+ *
184
+ */
185
+ public static function DAVERAGE($database, $field, $criteria)
186
+ {
187
+ $field = self::fieldExtract($database, $field);
188
+ if (is_null($field)) {
189
+ return null;
190
+ }
191
+
192
+ // Return
193
+ return PHPExcel_Calculation_Statistical::AVERAGE(
194
+ self::getFilteredColumn($database, $field, $criteria)
195
+ );
196
+ }
197
+
198
+
199
+ /**
200
+ * DCOUNT
201
+ *
202
+ * Counts the cells that contain numbers in a column of a list or database that match conditions
203
+ * that you specify.
204
+ *
205
+ * Excel Function:
206
+ * DCOUNT(database,[field],criteria)
207
+ *
208
+ * Excel Function:
209
+ * DAVERAGE(database,field,criteria)
210
+ *
211
+ * @access public
212
+ * @category Database Functions
213
+ * @param mixed[] $database The range of cells that makes up the list or database.
214
+ * A database is a list of related data in which rows of related
215
+ * information are records, and columns of data are fields. The
216
+ * first row of the list contains labels for each column.
217
+ * @param string|integer $field Indicates which column is used in the function. Enter the
218
+ * column label enclosed between double quotation marks, such as
219
+ * "Age" or "Yield," or a number (without quotation marks) that
220
+ * represents the position of the column within the list: 1 for
221
+ * the first column, 2 for the second column, and so on.
222
+ * @param mixed[] $criteria The range of cells that contains the conditions you specify.
223
+ * You can use any range for the criteria argument, as long as it
224
+ * includes at least one column label and at least one cell below
225
+ * the column label in which you specify a condition for the
226
+ * column.
227
+ * @return integer
228
+ *
229
+ * @TODO The field argument is optional. If field is omitted, DCOUNT counts all records in the
230
+ * database that match the criteria.
231
+ *
232
+ */
233
+ public static function DCOUNT($database, $field, $criteria)
234
+ {
235
+ $field = self::fieldExtract($database, $field);
236
+ if (is_null($field)) {
237
+ return null;
238
+ }
239
+
240
+ // Return
241
+ return PHPExcel_Calculation_Statistical::COUNT(
242
+ self::getFilteredColumn($database, $field, $criteria)
243
+ );
244
+ }
245
+
246
+
247
+ /**
248
+ * DCOUNTA
249
+ *
250
+ * Counts the nonblank cells in a column of a list or database that match conditions that you specify.
251
+ *
252
+ * Excel Function:
253
+ * DCOUNTA(database,[field],criteria)
254
+ *
255
+ * @access public
256
+ * @category Database Functions
257
+ * @param mixed[] $database The range of cells that makes up the list or database.
258
+ * A database is a list of related data in which rows of related
259
+ * information are records, and columns of data are fields. The
260
+ * first row of the list contains labels for each column.
261
+ * @param string|integer $field Indicates which column is used in the function. Enter the
262
+ * column label enclosed between double quotation marks, such as
263
+ * "Age" or "Yield," or a number (without quotation marks) that
264
+ * represents the position of the column within the list: 1 for
265
+ * the first column, 2 for the second column, and so on.
266
+ * @param mixed[] $criteria The range of cells that contains the conditions you specify.
267
+ * You can use any range for the criteria argument, as long as it
268
+ * includes at least one column label and at least one cell below
269
+ * the column label in which you specify a condition for the
270
+ * column.
271
+ * @return integer
272
+ *
273
+ * @TODO The field argument is optional. If field is omitted, DCOUNTA counts all records in the
274
+ * database that match the criteria.
275
+ *
276
+ */
277
+ public static function DCOUNTA($database, $field, $criteria)
278
+ {
279
+ $field = self::fieldExtract($database, $field);
280
+ if (is_null($field)) {
281
+ return null;
282
+ }
283
+
284
+ // reduce the database to a set of rows that match all the criteria
285
+ $database = self::filter($database, $criteria);
286
+ // extract an array of values for the requested column
287
+ $colData = array();
288
+ foreach ($database as $row) {
289
+ $colData[] = $row[$field];
290
+ }
291
+
292
+ // Return
293
+ return PHPExcel_Calculation_Statistical::COUNTA(
294
+ self::getFilteredColumn($database, $field, $criteria)
295
+ );
296
+ }
297
+
298
+
299
+ /**
300
+ * DGET
301
+ *
302
+ * Extracts a single value from a column of a list or database that matches conditions that you
303
+ * specify.
304
+ *
305
+ * Excel Function:
306
+ * DGET(database,field,criteria)
307
+ *
308
+ * @access public
309
+ * @category Database Functions
310
+ * @param mixed[] $database The range of cells that makes up the list or database.
311
+ * A database is a list of related data in which rows of related
312
+ * information are records, and columns of data are fields. The
313
+ * first row of the list contains labels for each column.
314
+ * @param string|integer $field Indicates which column is used in the function. Enter the
315
+ * column label enclosed between double quotation marks, such as
316
+ * "Age" or "Yield," or a number (without quotation marks) that
317
+ * represents the position of the column within the list: 1 for
318
+ * the first column, 2 for the second column, and so on.
319
+ * @param mixed[] $criteria The range of cells that contains the conditions you specify.
320
+ * You can use any range for the criteria argument, as long as it
321
+ * includes at least one column label and at least one cell below
322
+ * the column label in which you specify a condition for the
323
+ * column.
324
+ * @return mixed
325
+ *
326
+ */
327
+ public static function DGET($database, $field, $criteria)
328
+ {
329
+ $field = self::fieldExtract($database, $field);
330
+ if (is_null($field)) {
331
+ return null;
332
+ }
333
+
334
+ // Return
335
+ $colData = self::getFilteredColumn($database, $field, $criteria);
336
+ if (count($colData) > 1) {
337
+ return PHPExcel_Calculation_Functions::NaN();
338
+ }
339
+
340
+ return $colData[0];
341
+ }
342
+
343
+
344
+ /**
345
+ * DMAX
346
+ *
347
+ * Returns the largest number in a column of a list or database that matches conditions you that
348
+ * specify.
349
+ *
350
+ * Excel Function:
351
+ * DMAX(database,field,criteria)
352
+ *
353
+ * @access public
354
+ * @category Database Functions
355
+ * @param mixed[] $database The range of cells that makes up the list or database.
356
+ * A database is a list of related data in which rows of related
357
+ * information are records, and columns of data are fields. The
358
+ * first row of the list contains labels for each column.
359
+ * @param string|integer $field Indicates which column is used in the function. Enter the
360
+ * column label enclosed between double quotation marks, such as
361
+ * "Age" or "Yield," or a number (without quotation marks) that
362
+ * represents the position of the column within the list: 1 for
363
+ * the first column, 2 for the second column, and so on.
364
+ * @param mixed[] $criteria The range of cells that contains the conditions you specify.
365
+ * You can use any range for the criteria argument, as long as it
366
+ * includes at least one column label and at least one cell below
367
+ * the column label in which you specify a condition for the
368
+ * column.
369
+ * @return float
370
+ *
371
+ */
372
+ public static function DMAX($database, $field, $criteria)
373
+ {
374
+ $field = self::fieldExtract($database, $field);
375
+ if (is_null($field)) {
376
+ return null;
377
+ }
378
+
379
+ // Return
380
+ return PHPExcel_Calculation_Statistical::MAX(
381
+ self::getFilteredColumn($database, $field, $criteria)
382
+ );
383
+ }
384
+
385
+
386
+ /**
387
+ * DMIN
388
+ *
389
+ * Returns the smallest number in a column of a list or database that matches conditions you that
390
+ * specify.
391
+ *
392
+ * Excel Function:
393
+ * DMIN(database,field,criteria)
394
+ *
395
+ * @access public
396
+ * @category Database Functions
397
+ * @param mixed[] $database The range of cells that makes up the list or database.
398
+ * A database is a list of related data in which rows of related
399
+ * information are records, and columns of data are fields. The
400
+ * first row of the list contains labels for each column.
401
+ * @param string|integer $field Indicates which column is used in the function. Enter the
402
+ * column label enclosed between double quotation marks, such as
403
+ * "Age" or "Yield," or a number (without quotation marks) that
404
+ * represents the position of the column within the list: 1 for
405
+ * the first column, 2 for the second column, and so on.
406
+ * @param mixed[] $criteria The range of cells that contains the conditions you specify.
407
+ * You can use any range for the criteria argument, as long as it
408
+ * includes at least one column label and at least one cell below
409
+ * the column label in which you specify a condition for the
410
+ * column.
411
+ * @return float
412
+ *
413
+ */
414
+ public static function DMIN($database, $field, $criteria)
415
+ {
416
+ $field = self::fieldExtract($database, $field);
417
+ if (is_null($field)) {
418
+ return null;
419
+ }
420
+
421
+ // Return
422
+ return PHPExcel_Calculation_Statistical::MIN(
423
+ self::getFilteredColumn($database, $field, $criteria)
424
+ );
425
+ }
426
+
427
+
428
+ /**
429
+ * DPRODUCT
430
+ *
431
+ * Multiplies the values in a column of a list or database that match conditions that you specify.
432
+ *
433
+ * Excel Function:
434
+ * DPRODUCT(database,field,criteria)
435
+ *
436
+ * @access public
437
+ * @category Database Functions
438
+ * @param mixed[] $database The range of cells that makes up the list or database.
439
+ * A database is a list of related data in which rows of related
440
+ * information are records, and columns of data are fields. The
441
+ * first row of the list contains labels for each column.
442
+ * @param string|integer $field Indicates which column is used in the function. Enter the
443
+ * column label enclosed between double quotation marks, such as
444
+ * "Age" or "Yield," or a number (without quotation marks) that
445
+ * represents the position of the column within the list: 1 for
446
+ * the first column, 2 for the second column, and so on.
447
+ * @param mixed[] $criteria The range of cells that contains the conditions you specify.
448
+ * You can use any range for the criteria argument, as long as it
449
+ * includes at least one column label and at least one cell below
450
+ * the column label in which you specify a condition for the
451
+ * column.
452
+ * @return float
453
+ *
454
+ */
455
+ public static function DPRODUCT($database, $field, $criteria)
456
+ {
457
+ $field = self::fieldExtract($database, $field);
458
+ if (is_null($field)) {
459
+ return null;
460
+ }
461
+
462
+ // Return
463
+ return PHPExcel_Calculation_MathTrig::PRODUCT(
464
+ self::getFilteredColumn($database, $field, $criteria)
465
+ );
466
+ }
467
+
468
+
469
+ /**
470
+ * DSTDEV
471
+ *
472
+ * Estimates the standard deviation of a population based on a sample by using the numbers in a
473
+ * column of a list or database that match conditions that you specify.
474
+ *
475
+ * Excel Function:
476
+ * DSTDEV(database,field,criteria)
477
+ *
478
+ * @access public
479
+ * @category Database Functions
480
+ * @param mixed[] $database The range of cells that makes up the list or database.
481
+ * A database is a list of related data in which rows of related
482
+ * information are records, and columns of data are fields. The
483
+ * first row of the list contains labels for each column.
484
+ * @param string|integer $field Indicates which column is used in the function. Enter the
485
+ * column label enclosed between double quotation marks, such as
486
+ * "Age" or "Yield," or a number (without quotation marks) that
487
+ * represents the position of the column within the list: 1 for
488
+ * the first column, 2 for the second column, and so on.
489
+ * @param mixed[] $criteria The range of cells that contains the conditions you specify.
490
+ * You can use any range for the criteria argument, as long as it
491
+ * includes at least one column label and at least one cell below
492
+ * the column label in which you specify a condition for the
493
+ * column.
494
+ * @return float
495
+ *
496
+ */
497
+ public static function DSTDEV($database, $field, $criteria)
498
+ {
499
+ $field = self::fieldExtract($database, $field);
500
+ if (is_null($field)) {
501
+ return null;
502
+ }
503
+
504
+ // Return
505
+ return PHPExcel_Calculation_Statistical::STDEV(
506
+ self::getFilteredColumn($database, $field, $criteria)
507
+ );
508
+ }
509
+
510
+
511
+ /**
512
+ * DSTDEVP
513
+ *
514
+ * Calculates the standard deviation of a population based on the entire population by using the
515
+ * numbers in a column of a list or database that match conditions that you specify.
516
+ *
517
+ * Excel Function:
518
+ * DSTDEVP(database,field,criteria)
519
+ *
520
+ * @access public
521
+ * @category Database Functions
522
+ * @param mixed[] $database The range of cells that makes up the list or database.
523
+ * A database is a list of related data in which rows of related
524
+ * information are records, and columns of data are fields. The
525
+ * first row of the list contains labels for each column.
526
+ * @param string|integer $field Indicates which column is used in the function. Enter the
527
+ * column label enclosed between double quotation marks, such as
528
+ * "Age" or "Yield," or a number (without quotation marks) that
529
+ * represents the position of the column within the list: 1 for
530
+ * the first column, 2 for the second column, and so on.
531
+ * @param mixed[] $criteria The range of cells that contains the conditions you specify.
532
+ * You can use any range for the criteria argument, as long as it
533
+ * includes at least one column label and at least one cell below
534
+ * the column label in which you specify a condition for the
535
+ * column.
536
+ * @return float
537
+ *
538
+ */
539
+ public static function DSTDEVP($database, $field, $criteria)
540
+ {
541
+ $field = self::fieldExtract($database, $field);
542
+ if (is_null($field)) {
543
+ return null;
544
+ }
545
+
546
+ // Return
547
+ return PHPExcel_Calculation_Statistical::STDEVP(
548
+ self::getFilteredColumn($database, $field, $criteria)
549
+ );
550
+ }
551
+
552
+
553
+ /**
554
+ * DSUM
555
+ *
556
+ * Adds the numbers in a column of a list or database that match conditions that you specify.
557
+ *
558
+ * Excel Function:
559
+ * DSUM(database,field,criteria)
560
+ *
561
+ * @access public
562
+ * @category Database Functions
563
+ * @param mixed[] $database The range of cells that makes up the list or database.
564
+ * A database is a list of related data in which rows of related
565
+ * information are records, and columns of data are fields. The
566
+ * first row of the list contains labels for each column.
567
+ * @param string|integer $field Indicates which column is used in the function. Enter the
568
+ * column label enclosed between double quotation marks, such as
569
+ * "Age" or "Yield," or a number (without quotation marks) that
570
+ * represents the position of the column within the list: 1 for
571
+ * the first column, 2 for the second column, and so on.
572
+ * @param mixed[] $criteria The range of cells that contains the conditions you specify.
573
+ * You can use any range for the criteria argument, as long as it
574
+ * includes at least one column label and at least one cell below
575
+ * the column label in which you specify a condition for the
576
+ * column.
577
+ * @return float
578
+ *
579
+ */
580
+ public static function DSUM($database, $field, $criteria)
581
+ {
582
+ $field = self::fieldExtract($database, $field);
583
+ if (is_null($field)) {
584
+ return null;
585
+ }
586
+
587
+ // Return
588
+ return PHPExcel_Calculation_MathTrig::SUM(
589
+ self::getFilteredColumn($database, $field, $criteria)
590
+ );
591
+ }
592
+
593
+
594
+ /**
595
+ * DVAR
596
+ *
597
+ * Estimates the variance of a population based on a sample by using the numbers in a column
598
+ * of a list or database that match conditions that you specify.
599
+ *
600
+ * Excel Function:
601
+ * DVAR(database,field,criteria)
602
+ *
603
+ * @access public
604
+ * @category Database Functions
605
+ * @param mixed[] $database The range of cells that makes up the list or database.
606
+ * A database is a list of related data in which rows of related
607
+ * information are records, and columns of data are fields. The
608
+ * first row of the list contains labels for each column.
609
+ * @param string|integer $field Indicates which column is used in the function. Enter the
610
+ * column label enclosed between double quotation marks, such as
611
+ * "Age" or "Yield," or a number (without quotation marks) that
612
+ * represents the position of the column within the list: 1 for
613
+ * the first column, 2 for the second column, and so on.
614
+ * @param mixed[] $criteria The range of cells that contains the conditions you specify.
615
+ * You can use any range for the criteria argument, as long as it
616
+ * includes at least one column label and at least one cell below
617
+ * the column label in which you specify a condition for the
618
+ * column.
619
+ * @return float
620
+ *
621
+ */
622
+ public static function DVAR($database, $field, $criteria)
623
+ {
624
+ $field = self::fieldExtract($database, $field);
625
+ if (is_null($field)) {
626
+ return null;
627
+ }
628
+
629
+ // Return
630
+ return PHPExcel_Calculation_Statistical::VARFunc(
631
+ self::getFilteredColumn($database, $field, $criteria)
632
+ );
633
+ }
634
+
635
+
636
+ /**
637
+ * DVARP
638
+ *
639
+ * Calculates the variance of a population based on the entire population by using the numbers
640
+ * in a column of a list or database that match conditions that you specify.
641
+ *
642
+ * Excel Function:
643
+ * DVARP(database,field,criteria)
644
+ *
645
+ * @access public
646
+ * @category Database Functions
647
+ * @param mixed[] $database The range of cells that makes up the list or database.
648
+ * A database is a list of related data in which rows of related
649
+ * information are records, and columns of data are fields. The
650
+ * first row of the list contains labels for each column.
651
+ * @param string|integer $field Indicates which column is used in the function. Enter the
652
+ * column label enclosed between double quotation marks, such as
653
+ * "Age" or "Yield," or a number (without quotation marks) that
654
+ * represents the position of the column within the list: 1 for
655
+ * the first column, 2 for the second column, and so on.
656
+ * @param mixed[] $criteria The range of cells that contains the conditions you specify.
657
+ * You can use any range for the criteria argument, as long as it
658
+ * includes at least one column label and at least one cell below
659
+ * the column label in which you specify a condition for the
660
+ * column.
661
+ * @return float
662
+ *
663
+ */
664
+ public static function DVARP($database, $field, $criteria)
665
+ {
666
+ $field = self::fieldExtract($database, $field);
667
+ if (is_null($field)) {
668
+ return null;
669
+ }
670
+
671
+ // Return
672
+ return PHPExcel_Calculation_Statistical::VARP(
673
+ self::getFilteredColumn($database, $field, $criteria)
674
+ );
675
+ }
676
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
PHPExcel/Classes/PHPExcel/Calculation/DateTime.php CHANGED
@@ -1,1475 +1,1553 @@
1
- <?php
2
- /**
3
- * PHPExcel
4
- *
5
- * Copyright (c) 2006 - 2014 PHPExcel
6
- *
7
- * This library is free software; you can redistribute it and/or
8
- * modify it under the terms of the GNU Lesser General Public
9
- * License as published by the Free Software Foundation; either
10
- * version 2.1 of the License, or (at your option) any later version.
11
- *
12
- * This library is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
- * Lesser General Public License for more details.
16
- *
17
- * You should have received a copy of the GNU Lesser General Public
18
- * License along with this library; if not, write to the Free Software
19
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
- *
21
- * @category PHPExcel
22
- * @package PHPExcel_Calculation
23
- * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
24
- * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25
- * @version 1.8.0, 2014-03-02
26
- */
27
-
28
-
29
- /** PHPExcel root directory */
30
- if (!defined('PHPEXCEL_ROOT')) {
31
- /**
32
- * @ignore
33
- */
34
- define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
35
- require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
36
- }
37
-
38
-
39
- /**
40
- * PHPExcel_Calculation_DateTime
41
- *
42
- * @category PHPExcel
43
- * @package PHPExcel_Calculation
44
- * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
45
- */
46
- class PHPExcel_Calculation_DateTime {
47
-
48
- /**
49
- * Identify if a year is a leap year or not
50
- *
51
- * @param integer $year The year to test
52
- * @return boolean TRUE if the year is a leap year, otherwise FALSE
53
- */
54
- public static function _isLeapYear($year) {
55
- return ((($year % 4) == 0) && (($year % 100) != 0) || (($year % 400) == 0));
56
- } // function _isLeapYear()
57
-
58
-
59
- /**
60
- * Return the number of days between two dates based on a 360 day calendar
61
- *
62
- * @param integer $startDay Day of month of the start date
63
- * @param integer $startMonth Month of the start date
64
- * @param integer $startYear Year of the start date
65
- * @param integer $endDay Day of month of the start date
66
- * @param integer $endMonth Month of the start date
67
- * @param integer $endYear Year of the start date
68
- * @param boolean $methodUS Whether to use the US method or the European method of calculation
69
- * @return integer Number of days between the start date and the end date
70
- */
71
- private static function _dateDiff360($startDay, $startMonth, $startYear, $endDay, $endMonth, $endYear, $methodUS) {
72
- if ($startDay == 31) {
73
- --$startDay;
74
- } elseif ($methodUS && ($startMonth == 2 && ($startDay == 29 || ($startDay == 28 && !self::_isLeapYear($startYear))))) {
75
- $startDay = 30;
76
- }
77
- if ($endDay == 31) {
78
- if ($methodUS && $startDay != 30) {
79
- $endDay = 1;
80
- if ($endMonth == 12) {
81
- ++$endYear;
82
- $endMonth = 1;
83
- } else {
84
- ++$endMonth;
85
- }
86
- } else {
87
- $endDay = 30;
88
- }
89
- }
90
-
91
- return $endDay + $endMonth * 30 + $endYear * 360 - $startDay - $startMonth * 30 - $startYear * 360;
92
- } // function _dateDiff360()
93
-
94
-
95
- /**
96
- * _getDateValue
97
- *
98
- * @param string $dateValue
99
- * @return mixed Excel date/time serial value, or string if error
100
- */
101
- public static function _getDateValue($dateValue) {
102
- if (!is_numeric($dateValue)) {
103
- if ((is_string($dateValue)) &&
104
- (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC)) {
105
- return PHPExcel_Calculation_Functions::VALUE();
106
- }
107
- if ((is_object($dateValue)) && ($dateValue instanceof DateTime)) {
108
- $dateValue = PHPExcel_Shared_Date::PHPToExcel($dateValue);
109
- } else {
110
- $saveReturnDateType = PHPExcel_Calculation_Functions::getReturnDateType();
111
- PHPExcel_Calculation_Functions::setReturnDateType(PHPExcel_Calculation_Functions::RETURNDATE_EXCEL);
112
- $dateValue = self::DATEVALUE($dateValue);
113
- PHPExcel_Calculation_Functions::setReturnDateType($saveReturnDateType);
114
- }
115
- }
116
- return $dateValue;
117
- } // function _getDateValue()
118
-
119
-
120
- /**
121
- * _getTimeValue
122
- *
123
- * @param string $timeValue
124
- * @return mixed Excel date/time serial value, or string if error
125
- */
126
- private static function _getTimeValue($timeValue) {
127
- $saveReturnDateType = PHPExcel_Calculation_Functions::getReturnDateType();
128
- PHPExcel_Calculation_Functions::setReturnDateType(PHPExcel_Calculation_Functions::RETURNDATE_EXCEL);
129
- $timeValue = self::TIMEVALUE($timeValue);
130
- PHPExcel_Calculation_Functions::setReturnDateType($saveReturnDateType);
131
- return $timeValue;
132
- } // function _getTimeValue()
133
-
134
-
135
- private static function _adjustDateByMonths($dateValue = 0, $adjustmentMonths = 0) {
136
- // Execute function
137
- $PHPDateObject = PHPExcel_Shared_Date::ExcelToPHPObject($dateValue);
138
- $oMonth = (int) $PHPDateObject->format('m');
139
- $oYear = (int) $PHPDateObject->format('Y');
140
-
141
- $adjustmentMonthsString = (string) $adjustmentMonths;
142
- if ($adjustmentMonths > 0) {
143
- $adjustmentMonthsString = '+'.$adjustmentMonths;
144
- }
145
- if ($adjustmentMonths != 0) {
146
- $PHPDateObject->modify($adjustmentMonthsString.' months');
147
- }
148
- $nMonth = (int) $PHPDateObject->format('m');
149
- $nYear = (int) $PHPDateObject->format('Y');
150
-
151
- $monthDiff = ($nMonth - $oMonth) + (($nYear - $oYear) * 12);
152
- if ($monthDiff != $adjustmentMonths) {
153
- $adjustDays = (int) $PHPDateObject->format('d');
154
- $adjustDaysString = '-'.$adjustDays.' days';
155
- $PHPDateObject->modify($adjustDaysString);
156
- }
157
- return $PHPDateObject;
158
- } // function _adjustDateByMonths()
159
-
160
-
161
- /**
162
- * DATETIMENOW
163
- *
164
- * Returns the current date and time.
165
- * The NOW function is useful when you need to display the current date and time on a worksheet or
166
- * calculate a value based on the current date and time, and have that value updated each time you
167
- * open the worksheet.
168
- *
169
- * NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the date
170
- * and time format of your regional settings. PHPExcel does not change cell formatting in this way.
171
- *
172
- * Excel Function:
173
- * NOW()
174
- *
175
- * @access public
176
- * @category Date/Time Functions
177
- * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
178
- * depending on the value of the ReturnDateType flag
179
- */
180
- public static function DATETIMENOW() {
181
- $saveTimeZone = date_default_timezone_get();
182
- date_default_timezone_set('UTC');
183
- $retValue = False;
184
- switch (PHPExcel_Calculation_Functions::getReturnDateType()) {
185
- case PHPExcel_Calculation_Functions::RETURNDATE_EXCEL :
186
- $retValue = (float) PHPExcel_Shared_Date::PHPToExcel(time());
187
- break;
188
- case PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC :
189
- $retValue = (integer) time();
190
- break;
191
- case PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT :
192
- $retValue = new DateTime();
193
- break;
194
- }
195
- date_default_timezone_set($saveTimeZone);
196
-
197
- return $retValue;
198
- } // function DATETIMENOW()
199
-
200
-
201
- /**
202
- * DATENOW
203
- *
204
- * Returns the current date.
205
- * The NOW function is useful when you need to display the current date and time on a worksheet or
206
- * calculate a value based on the current date and time, and have that value updated each time you
207
- * open the worksheet.
208
- *
209
- * NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the date
210
- * and time format of your regional settings. PHPExcel does not change cell formatting in this way.
211
- *
212
- * Excel Function:
213
- * TODAY()
214
- *
215
- * @access public
216
- * @category Date/Time Functions
217
- * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
218
- * depending on the value of the ReturnDateType flag
219
- */
220
- public static function DATENOW() {
221
- $saveTimeZone = date_default_timezone_get();
222
- date_default_timezone_set('UTC');
223
- $retValue = False;
224
- $excelDateTime = floor(PHPExcel_Shared_Date::PHPToExcel(time()));
225
- switch (PHPExcel_Calculation_Functions::getReturnDateType()) {
226
- case PHPExcel_Calculation_Functions::RETURNDATE_EXCEL :
227
- $retValue = (float) $excelDateTime;
228
- break;
229
- case PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC :
230
- $retValue = (integer) PHPExcel_Shared_Date::ExcelToPHP($excelDateTime);
231
- break;
232
- case PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT :
233
- $retValue = PHPExcel_Shared_Date::ExcelToPHPObject($excelDateTime);
234
- break;
235
- }
236
- date_default_timezone_set($saveTimeZone);
237
-
238
- return $retValue;
239
- } // function DATENOW()
240
-
241
-
242
- /**
243
- * DATE
244
- *
245
- * The DATE function returns a value that represents a particular date.
246
- *
247
- * NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the date
248
- * format of your regional settings. PHPExcel does not change cell formatting in this way.
249
- *
250
- * Excel Function:
251
- * DATE(year,month,day)
252
- *
253
- * PHPExcel is a lot more forgiving than MS Excel when passing non numeric values to this function.
254
- * A Month name or abbreviation (English only at this point) such as 'January' or 'Jan' will still be accepted,
255
- * as will a day value with a suffix (e.g. '21st' rather than simply 21); again only English language.
256
- *
257
- * @access public
258
- * @category Date/Time Functions
259
- * @param integer $year The value of the year argument can include one to four digits.
260
- * Excel interprets the year argument according to the configured
261
- * date system: 1900 or 1904.
262
- * If year is between 0 (zero) and 1899 (inclusive), Excel adds that
263
- * value to 1900 to calculate the year. For example, DATE(108,1,2)
264
- * returns January 2, 2008 (1900+108).
265
- * If year is between 1900 and 9999 (inclusive), Excel uses that
266
- * value as the year. For example, DATE(2008,1,2) returns January 2,
267
- * 2008.
268
- * If year is less than 0 or is 10000 or greater, Excel returns the
269
- * #NUM! error value.
270
- * @param integer $month A positive or negative integer representing the month of the year
271
- * from 1 to 12 (January to December).
272
- * If month is greater than 12, month adds that number of months to
273
- * the first month in the year specified. For example, DATE(2008,14,2)
274
- * returns the serial number representing February 2, 2009.
275
- * If month is less than 1, month subtracts the magnitude of that
276
- * number of months, plus 1, from the first month in the year
277
- * specified. For example, DATE(2008,-3,2) returns the serial number
278
- * representing September 2, 2007.
279
- * @param integer $day A positive or negative integer representing the day of the month
280
- * from 1 to 31.
281
- * If day is greater than the number of days in the month specified,
282
- * day adds that number of days to the first day in the month. For
283
- * example, DATE(2008,1,35) returns the serial number representing
284
- * February 4, 2008.
285
- * If day is less than 1, day subtracts the magnitude that number of
286
- * days, plus one, from the first day of the month specified. For
287
- * example, DATE(2008,1,-15) returns the serial number representing
288
- * December 16, 2007.
289
- * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
290
- * depending on the value of the ReturnDateType flag
291
- */
292
- public static function DATE($year = 0, $month = 1, $day = 1) {
293
- $year = PHPExcel_Calculation_Functions::flattenSingleValue($year);
294
- $month = PHPExcel_Calculation_Functions::flattenSingleValue($month);
295
- $day = PHPExcel_Calculation_Functions::flattenSingleValue($day);
296
-
297
- if (($month !== NULL) && (!is_numeric($month))) {
298
- $month = PHPExcel_Shared_Date::monthStringToNumber($month);
299
- }
300
-
301
- if (($day !== NULL) && (!is_numeric($day))) {
302
- $day = PHPExcel_Shared_Date::dayStringToNumber($day);
303
- }
304
-
305
- $year = ($year !== NULL) ? PHPExcel_Shared_String::testStringAsNumeric($year) : 0;
306
- $month = ($month !== NULL) ? PHPExcel_Shared_String::testStringAsNumeric($month) : 0;
307
- $day = ($day !== NULL) ? PHPExcel_Shared_String::testStringAsNumeric($day) : 0;
308
- if ((!is_numeric($year)) ||
309
- (!is_numeric($month)) ||
310
- (!is_numeric($day))) {
311
- return PHPExcel_Calculation_Functions::VALUE();
312
- }
313
- $year = (integer) $year;
314
- $month = (integer) $month;
315
- $day = (integer) $day;
316
-
317
- $baseYear = PHPExcel_Shared_Date::getExcelCalendar();
318
- // Validate parameters
319
- if ($year < ($baseYear-1900)) {
320
- return PHPExcel_Calculation_Functions::NaN();
321
- }
322
- if ((($baseYear-1900) != 0) && ($year < $baseYear) && ($year >= 1900)) {
323
- return PHPExcel_Calculation_Functions::NaN();
324
- }
325
-
326
- if (($year < $baseYear) && ($year >= ($baseYear-1900))) {
327
- $year += 1900;
328
- }
329
-
330
- if ($month < 1) {
331
- // Handle year/month adjustment if month < 1
332
- --$month;
333
- $year += ceil($month / 12) - 1;
334
- $month = 13 - abs($month % 12);
335
- } elseif ($month > 12) {
336
- // Handle year/month adjustment if month > 12
337
- $year += floor($month / 12);
338
- $month = ($month % 12);
339
- }
340
-
341
- // Re-validate the year parameter after adjustments
342
- if (($year < $baseYear) || ($year >= 10000)) {
343
- return PHPExcel_Calculation_Functions::NaN();
344
- }
345
-
346
- // Execute function
347
- $excelDateValue = PHPExcel_Shared_Date::FormattedPHPToExcel($year, $month, $day);
348
- switch (PHPExcel_Calculation_Functions::getReturnDateType()) {
349
- case PHPExcel_Calculation_Functions::RETURNDATE_EXCEL :
350
- return (float) $excelDateValue;
351
- case PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC :
352
- return (integer) PHPExcel_Shared_Date::ExcelToPHP($excelDateValue);
353
- case PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT :
354
- return PHPExcel_Shared_Date::ExcelToPHPObject($excelDateValue);
355
- }
356
- } // function DATE()
357
-
358
-
359
- /**
360
- * TIME
361
- *
362
- * The TIME function returns a value that represents a particular time.
363
- *
364
- * NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the time
365
- * format of your regional settings. PHPExcel does not change cell formatting in this way.
366
- *
367
- * Excel Function:
368
- * TIME(hour,minute,second)
369
- *
370
- * @access public
371
- * @category Date/Time Functions
372
- * @param integer $hour A number from 0 (zero) to 32767 representing the hour.
373
- * Any value greater than 23 will be divided by 24 and the remainder
374
- * will be treated as the hour value. For example, TIME(27,0,0) =
375
- * TIME(3,0,0) = .125 or 3:00 AM.
376
- * @param integer $minute A number from 0 to 32767 representing the minute.
377
- * Any value greater than 59 will be converted to hours and minutes.
378
- * For example, TIME(0,750,0) = TIME(12,30,0) = .520833 or 12:30 PM.
379
- * @param integer $second A number from 0 to 32767 representing the second.
380
- * Any value greater than 59 will be converted to hours, minutes,
381
- * and seconds. For example, TIME(0,0,2000) = TIME(0,33,22) = .023148
382
- * or 12:33:20 AM
383
- * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
384
- * depending on the value of the ReturnDateType flag
385
- */
386
- public static function TIME($hour = 0, $minute = 0, $second = 0) {
387
- $hour = PHPExcel_Calculation_Functions::flattenSingleValue($hour);
388
- $minute = PHPExcel_Calculation_Functions::flattenSingleValue($minute);
389
- $second = PHPExcel_Calculation_Functions::flattenSingleValue($second);
390
-
391
- if ($hour == '') { $hour = 0; }
392
- if ($minute == '') { $minute = 0; }
393
- if ($second == '') { $second = 0; }
394
-
395
- if ((!is_numeric($hour)) || (!is_numeric($minute)) || (!is_numeric($second))) {
396
- return PHPExcel_Calculation_Functions::VALUE();
397
- }
398
- $hour = (integer) $hour;
399
- $minute = (integer) $minute;
400
- $second = (integer) $second;
401
-
402
- if ($second < 0) {
403
- $minute += floor($second / 60);
404
- $second = 60 - abs($second % 60);
405
- if ($second == 60) { $second = 0; }
406
- } elseif ($second >= 60) {
407
- $minute += floor($second / 60);
408
- $second = $second % 60;
409
- }
410
- if ($minute < 0) {
411
- $hour += floor($minute / 60);
412
- $minute = 60 - abs($minute % 60);
413
- if ($minute == 60) { $minute = 0; }
414
- } elseif ($minute >= 60) {
415
- $hour += floor($minute / 60);
416
- $minute = $minute % 60;
417
- }
418
-
419
- if ($hour > 23) {
420
- $hour = $hour % 24;
421
- } elseif ($hour < 0) {
422
- return PHPExcel_Calculation_Functions::NaN();
423
- }
424
-
425
- // Execute function
426
- switch (PHPExcel_Calculation_Functions::getReturnDateType()) {
427
- case PHPExcel_Calculation_Functions::RETURNDATE_EXCEL :
428
- $date = 0;
429
- $calendar = PHPExcel_Shared_Date::getExcelCalendar();
430
- if ($calendar != PHPExcel_Shared_Date::CALENDAR_WINDOWS_1900) {
431
- $date = 1;
432
- }
433
- return (float) PHPExcel_Shared_Date::FormattedPHPToExcel($calendar, 1, $date, $hour, $minute, $second);
434
- case PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC :
435
- return (integer) PHPExcel_Shared_Date::ExcelToPHP(PHPExcel_Shared_Date::FormattedPHPToExcel(1970, 1, 1, $hour, $minute, $second)); // -2147468400; // -2147472000 + 3600
436
- case PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT :
437
- $dayAdjust = 0;
438
- if ($hour < 0) {
439
- $dayAdjust = floor($hour / 24);
440
- $hour = 24 - abs($hour % 24);
441
- if ($hour == 24) { $hour = 0; }
442
- } elseif ($hour >= 24) {
443
- $dayAdjust = floor($hour / 24);
444
- $hour = $hour % 24;
445
- }
446
- $phpDateObject = new DateTime('1900-01-01 '.$hour.':'.$minute.':'.$second);
447
- if ($dayAdjust != 0) {
448
- $phpDateObject->modify($dayAdjust.' days');
449
- }
450
- return $phpDateObject;
451
- }
452
- } // function TIME()
453
-
454
-
455
- /**
456
- * DATEVALUE
457
- *
458
- * Returns a value that represents a particular date.
459
- * Use DATEVALUE to convert a date represented by a text string to an Excel or PHP date/time stamp
460
- * value.
461
- *
462
- * NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the date
463
- * format of your regional settings. PHPExcel does not change cell formatting in this way.
464
- *
465
- * Excel Function:
466
- * DATEVALUE(dateValue)
467
- *
468
- * @access public
469
- * @category Date/Time Functions
470
- * @param string $dateValue Text that represents a date in a Microsoft Excel date format.
471
- * For example, "1/30/2008" or "30-Jan-2008" are text strings within
472
- * quotation marks that represent dates. Using the default date
473
- * system in Excel for Windows, date_text must represent a date from
474
- * January 1, 1900, to December 31, 9999. Using the default date
475
- * system in Excel for the Macintosh, date_text must represent a date
476
- * from January 1, 1904, to December 31, 9999. DATEVALUE returns the
477
- * #VALUE! error value if date_text is out of this range.
478
- * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
479
- * depending on the value of the ReturnDateType flag
480
- */
481
- public static function DATEVALUE($dateValue = 1) {
482
- $dateValue = trim(PHPExcel_Calculation_Functions::flattenSingleValue($dateValue),'"');
483
- // Strip any ordinals because they're allowed in Excel (English only)
484
- $dateValue = preg_replace('/(\d)(st|nd|rd|th)([ -\/])/Ui','$1$3',$dateValue);
485
- // Convert separators (/ . or space) to hyphens (should also handle dot used for ordinals in some countries, e.g. Denmark, Germany)
486
- $dateValue = str_replace(array('/','.','-',' '),array(' ',' ',' ',' '),$dateValue);
487
-
488
- $yearFound = false;
489
- $t1 = explode(' ',$dateValue);
490
- foreach($t1 as &$t) {
491
- if ((is_numeric($t)) && ($t > 31)) {
492
- if ($yearFound) {
493
- return PHPExcel_Calculation_Functions::VALUE();
494
- } else {
495
- if ($t < 100) { $t += 1900; }
496
- $yearFound = true;
497
- }
498
- }
499
- }
500
- if ((count($t1) == 1) && (strpos($t,':') != false)) {
501
- // We've been fed a time value without any date
502
- return 0.0;
503
- } elseif (count($t1) == 2) {
504
- // We only have two parts of the date: either day/month or month/year
505
- if ($yearFound) {
506
- array_unshift($t1,1);
507
- } else {
508
- array_push($t1,date('Y'));
509
- }
510
- }
511
- unset($t);
512
- $dateValue = implode(' ',$t1);
513
-
514
- $PHPDateArray = date_parse($dateValue);
515
- if (($PHPDateArray === False) || ($PHPDateArray['error_count'] > 0)) {
516
- $testVal1 = strtok($dateValue,'- ');
517
- if ($testVal1 !== False) {
518
- $testVal2 = strtok('- ');
519
- if ($testVal2 !== False) {
520
- $testVal3 = strtok('- ');
521
- if ($testVal3 === False) {
522
- $testVal3 = strftime('%Y');
523
- }
524
- } else {
525
- return PHPExcel_Calculation_Functions::VALUE();
526
- }
527
- } else {
528
- return PHPExcel_Calculation_Functions::VALUE();
529
- }
530
- $PHPDateArray = date_parse($testVal1.'-'.$testVal2.'-'.$testVal3);
531
- if (($PHPDateArray === False) || ($PHPDateArray['error_count'] > 0)) {
532
- $PHPDateArray = date_parse($testVal2.'-'.$testVal1.'-'.$testVal3);
533
- if (($PHPDateArray === False) || ($PHPDateArray['error_count'] > 0)) {
534
- return PHPExcel_Calculation_Functions::VALUE();
535
- }
536
- }
537
- }
538
-
539
- if (($PHPDateArray !== False) && ($PHPDateArray['error_count'] == 0)) {
540
- // Execute function
541
- if ($PHPDateArray['year'] == '') { $PHPDateArray['year'] = strftime('%Y'); }
542
- if ($PHPDateArray['year'] < 1900)
543
- return PHPExcel_Calculation_Functions::VALUE();
544
- if ($PHPDateArray['month'] == '') { $PHPDateArray['month'] = strftime('%m'); }
545
- if ($PHPDateArray['day'] == '') { $PHPDateArray['day'] = strftime('%d'); }
546
- $excelDateValue = floor(PHPExcel_Shared_Date::FormattedPHPToExcel($PHPDateArray['year'],$PHPDateArray['month'],$PHPDateArray['day'],$PHPDateArray['hour'],$PHPDateArray['minute'],$PHPDateArray['second']));
547
-
548
- switch (PHPExcel_Calculation_Functions::getReturnDateType()) {
549
- case PHPExcel_Calculation_Functions::RETURNDATE_EXCEL :
550
- return (float) $excelDateValue;
551
- case PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC :
552
- return (integer) PHPExcel_Shared_Date::ExcelToPHP($excelDateValue);
553
- case PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT :
554
- return new DateTime($PHPDateArray['year'].'-'.$PHPDateArray['month'].'-'.$PHPDateArray['day'].' 00:00:00');
555
- }
556
- }
557
- return PHPExcel_Calculation_Functions::VALUE();
558
- } // function DATEVALUE()
559
-
560
-
561
- /**
562
- * TIMEVALUE
563
- *
564
- * Returns a value that represents a particular time.
565
- * Use TIMEVALUE to convert a time represented by a text string to an Excel or PHP date/time stamp
566
- * value.
567
- *
568
- * NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the time
569
- * format of your regional settings. PHPExcel does not change cell formatting in this way.
570
- *
571
- * Excel Function:
572
- * TIMEVALUE(timeValue)
573
- *
574
- * @access public
575
- * @category Date/Time Functions
576
- * @param string $timeValue A text string that represents a time in any one of the Microsoft
577
- * Excel time formats; for example, "6:45 PM" and "18:45" text strings
578
- * within quotation marks that represent time.
579
- * Date information in time_text is ignored.
580
- * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
581
- * depending on the value of the ReturnDateType flag
582
- */
583
- public static function TIMEVALUE($timeValue) {
584
- $timeValue = trim(PHPExcel_Calculation_Functions::flattenSingleValue($timeValue),'"');
585
- $timeValue = str_replace(array('/','.'),array('-','-'),$timeValue);
586
-
587
- $PHPDateArray = date_parse($timeValue);
588
- if (($PHPDateArray !== False) && ($PHPDateArray['error_count'] == 0)) {
589
- if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) {
590
- $excelDateValue = PHPExcel_Shared_Date::FormattedPHPToExcel($PHPDateArray['year'],$PHPDateArray['month'],$PHPDateArray['day'],$PHPDateArray['hour'],$PHPDateArray['minute'],$PHPDateArray['second']);
591
- } else {
592
- $excelDateValue = PHPExcel_Shared_Date::FormattedPHPToExcel(1900,1,1,$PHPDateArray['hour'],$PHPDateArray['minute'],$PHPDateArray['second']) - 1;
593
- }
594
-
595
- switch (PHPExcel_Calculation_Functions::getReturnDateType()) {
596
- case PHPExcel_Calculation_Functions::RETURNDATE_EXCEL :
597
- return (float) $excelDateValue;
598
- case PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC :
599
- return (integer) $phpDateValue = PHPExcel_Shared_Date::ExcelToPHP($excelDateValue+25569) - 3600;;
600
- case PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT :
601
- return new DateTime('1900-01-01 '.$PHPDateArray['hour'].':'.$PHPDateArray['minute'].':'.$PHPDateArray['second']);
602
- }
603
- }
604
- return PHPExcel_Calculation_Functions::VALUE();
605
- } // function TIMEVALUE()
606
-
607
-
608
- /**
609
- * DATEDIF
610
- *
611
- * @param mixed $startDate Excel date serial value, PHP date/time stamp, PHP DateTime object
612
- * or a standard date string
613
- * @param mixed $endDate Excel date serial value, PHP date/time stamp, PHP DateTime object
614
- * or a standard date string
615
- * @param string $unit
616
- * @return integer Interval between the dates
617
- */
618
- public static function DATEDIF($startDate = 0, $endDate = 0, $unit = 'D') {
619
- $startDate = PHPExcel_Calculation_Functions::flattenSingleValue($startDate);
620
- $endDate = PHPExcel_Calculation_Functions::flattenSingleValue($endDate);
621
- $unit = strtoupper(PHPExcel_Calculation_Functions::flattenSingleValue($unit));
622
-
623
- if (is_string($startDate = self::_getDateValue($startDate))) {
624
- return PHPExcel_Calculation_Functions::VALUE();
625
- }
626
- if (is_string($endDate = self::_getDateValue($endDate))) {
627
- return PHPExcel_Calculation_Functions::VALUE();
628
- }
629
-
630
- // Validate parameters
631
- if ($startDate >= $endDate) {
632
- return PHPExcel_Calculation_Functions::NaN();
633
- }
634
-
635
- // Execute function
636
- $difference = $endDate - $startDate;
637
-
638
- $PHPStartDateObject = PHPExcel_Shared_Date::ExcelToPHPObject($startDate);
639
- $startDays = $PHPStartDateObject->format('j');
640
- $startMonths = $PHPStartDateObject->format('n');
641
- $startYears = $PHPStartDateObject->format('Y');
642
-
643
- $PHPEndDateObject = PHPExcel_Shared_Date::ExcelToPHPObject($endDate);
644
- $endDays = $PHPEndDateObject->format('j');
645
- $endMonths = $PHPEndDateObject->format('n');
646
- $endYears = $PHPEndDateObject->format('Y');
647
-
648
- $retVal = PHPExcel_Calculation_Functions::NaN();
649
- switch ($unit) {
650
- case 'D':
651
- $retVal = intval($difference);
652
- break;
653
- case 'M':
654
- $retVal = intval($endMonths - $startMonths) + (intval($endYears - $startYears) * 12);
655
- // We're only interested in full months
656
- if ($endDays < $startDays) {
657
- --$retVal;
658
- }
659
- break;
660
- case 'Y':
661
- $retVal = intval($endYears - $startYears);
662
- // We're only interested in full months
663
- if ($endMonths < $startMonths) {
664
- --$retVal;
665
- } elseif (($endMonths == $startMonths) && ($endDays < $startDays)) {
666
- --$retVal;
667
- }
668
- break;
669
- case 'MD':
670
- if ($endDays < $startDays) {
671
- $retVal = $endDays;
672
- $PHPEndDateObject->modify('-'.$endDays.' days');
673
- $adjustDays = $PHPEndDateObject->format('j');
674
- if ($adjustDays > $startDays) {
675
- $retVal += ($adjustDays - $startDays);
676
- }
677
- } else {
678
- $retVal = $endDays - $startDays;
679
- }
680
- break;
681
- case 'YM':
682
- $retVal = intval($endMonths - $startMonths);
683
- if ($retVal < 0) $retVal = 12 + $retVal;
684
- // We're only interested in full months
685
- if ($endDays < $startDays) {
686
- --$retVal;
687
- }
688
- break;
689
- case 'YD':
690
- $retVal = intval($difference);
691
- if ($endYears > $startYears) {
692
- while ($endYears > $startYears) {
693
- $PHPEndDateObject->modify('-1 year');
694
- $endYears = $PHPEndDateObject->format('Y');
695
- }
696
- $retVal = $PHPEndDateObject->format('z') - $PHPStartDateObject->format('z');
697
- if ($retVal < 0) { $retVal += 365; }
698
- }
699
- break;
700
- default:
701
- $retVal = PHPExcel_Calculation_Functions::NaN();
702
- }
703
- return $retVal;
704
- } // function DATEDIF()
705
-
706
-
707
- /**
708
- * DAYS360
709
- *
710
- * Returns the number of days between two dates based on a 360-day year (twelve 30-day months),
711
- * which is used in some accounting calculations. Use this function to help compute payments if
712
- * your accounting system is based on twelve 30-day months.
713
- *
714
- * Excel Function:
715
- * DAYS360(startDate,endDate[,method])
716
- *
717
- * @access public
718
- * @category Date/Time Functions
719
- * @param mixed $startDate Excel date serial value (float), PHP date timestamp (integer),
720
- * PHP DateTime object, or a standard date string
721
- * @param mixed $endDate Excel date serial value (float), PHP date timestamp (integer),
722
- * PHP DateTime object, or a standard date string
723
- * @param boolean $method US or European Method
724
- * FALSE or omitted: U.S. (NASD) method. If the starting date is
725
- * the last day of a month, it becomes equal to the 30th of the
726
- * same month. If the ending date is the last day of a month and
727
- * the starting date is earlier than the 30th of a month, the
728
- * ending date becomes equal to the 1st of the next month;
729
- * otherwise the ending date becomes equal to the 30th of the
730
- * same month.
731
- * TRUE: European method. Starting dates and ending dates that
732
- * occur on the 31st of a month become equal to the 30th of the
733
- * same month.
734
- * @return integer Number of days between start date and end date
735
- */
736
- public static function DAYS360($startDate = 0, $endDate = 0, $method = false) {
737
- $startDate = PHPExcel_Calculation_Functions::flattenSingleValue($startDate);
738
- $endDate = PHPExcel_Calculation_Functions::flattenSingleValue($endDate);
739
-
740
- if (is_string($startDate = self::_getDateValue($startDate))) {
741
- return PHPExcel_Calculation_Functions::VALUE();
742
- }
743
- if (is_string($endDate = self::_getDateValue($endDate))) {
744
- return PHPExcel_Calculation_Functions::VALUE();
745
- }
746
-
747
- if (!is_bool($method)) {
748
- return PHPExcel_Calculation_Functions::VALUE();
749
- }
750
-
751
- // Execute function
752
- $PHPStartDateObject = PHPExcel_Shared_Date::ExcelToPHPObject($startDate);
753
- $startDay = $PHPStartDateObject->format('j');
754
- $startMonth = $PHPStartDateObject->format('n');
755
- $startYear = $PHPStartDateObject->format('Y');
756
-
757
- $PHPEndDateObject = PHPExcel_Shared_Date::ExcelToPHPObject($endDate);
758
- $endDay = $PHPEndDateObject->format('j');
759
- $endMonth = $PHPEndDateObject->format('n');
760
- $endYear = $PHPEndDateObject->format('Y');
761
-
762
- return self::_dateDiff360($startDay, $startMonth, $startYear, $endDay, $endMonth, $endYear, !$method);
763
- } // function DAYS360()
764
-
765
-
766
- /**
767
- * YEARFRAC
768
- *
769
- * Calculates the fraction of the year represented by the number of whole days between two dates
770
- * (the start_date and the end_date).
771
- * Use the YEARFRAC worksheet function to identify the proportion of a whole year's benefits or
772
- * obligations to assign to a specific term.
773
- *
774
- * Excel Function:
775
- * YEARFRAC(startDate,endDate[,method])
776
- *
777
- * @access public
778
- * @category Date/Time Functions
779
- * @param mixed $startDate Excel date serial value (float), PHP date timestamp (integer),
780
- * PHP DateTime object, or a standard date string
781
- * @param mixed $endDate Excel date serial value (float), PHP date timestamp (integer),
782
- * PHP DateTime object, or a standard date string
783
- * @param integer $method Method used for the calculation
784
- * 0 or omitted US (NASD) 30/360
785
- * 1 Actual/actual
786
- * 2 Actual/360
787
- * 3 Actual/365
788
- * 4 European 30/360
789
- * @return float fraction of the year
790
- */
791
- public static function YEARFRAC($startDate = 0, $endDate = 0, $method = 0) {
792
- $startDate = PHPExcel_Calculation_Functions::flattenSingleValue($startDate);
793
- $endDate = PHPExcel_Calculation_Functions::flattenSingleValue($endDate);
794
- $method = PHPExcel_Calculation_Functions::flattenSingleValue($method);
795
-
796
- if (is_string($startDate = self::_getDateValue($startDate))) {
797
- return PHPExcel_Calculation_Functions::VALUE();
798
- }
799
- if (is_string($endDate = self::_getDateValue($endDate))) {
800
- return PHPExcel_Calculation_Functions::VALUE();
801
- }
802
-
803
- if (((is_numeric($method)) && (!is_string($method))) || ($method == '')) {
804
- switch($method) {
805
- case 0 :
806
- return self::DAYS360($startDate,$endDate) / 360;
807
- case 1 :
808
- $days = self::DATEDIF($startDate,$endDate);
809
- $startYear = self::YEAR($startDate);
810
- $endYear = self::YEAR($endDate);
811
- $years = $endYear - $startYear + 1;
812
- $leapDays = 0;
813
- if ($years == 1) {
814
- if (self::_isLeapYear($endYear)) {
815
- $startMonth = self::MONTHOFYEAR($startDate);
816
- $endMonth = self::MONTHOFYEAR($endDate);
817
- $endDay = self::DAYOFMONTH($endDate);
818
- if (($startMonth < 3) ||
819
- (($endMonth * 100 + $endDay) >= (2 * 100 + 29))) {
820
- $leapDays += 1;
821
- }
822
- }
823
- } else {
824
- for($year = $startYear; $year <= $endYear; ++$year) {
825
- if ($year == $startYear) {
826
- $startMonth = self::MONTHOFYEAR($startDate);
827
- $startDay = self::DAYOFMONTH($startDate);
828
- if ($startMonth < 3) {
829
- $leapDays += (self::_isLeapYear($year)) ? 1 : 0;
830
- }
831
- } elseif($year == $endYear) {
832
- $endMonth = self::MONTHOFYEAR($endDate);
833
- $endDay = self::DAYOFMONTH($endDate);
834
- if (($endMonth * 100 + $endDay) >= (2 * 100 + 29)) {
835
- $leapDays += (self::_isLeapYear($year)) ? 1 : 0;
836
- }
837
- } else {
838
- $leapDays += (self::_isLeapYear($year)) ? 1 : 0;
839
- }
840
- }
841
- if ($years == 2) {
842
- if (($leapDays == 0) && (self::_isLeapYear($startYear)) && ($days > 365)) {
843
- $leapDays = 1;
844
- } elseif ($days < 366) {
845
- $years = 1;
846
- }
847
- }
848
- $leapDays /= $years;
849
- }
850
- return $days / (365 + $leapDays);
851
- case 2 :
852
- return self::DATEDIF($startDate,$endDate) / 360;
853
- case 3 :
854
- return self::DATEDIF($startDate,$endDate) / 365;
855
- case 4 :
856
- return self::DAYS360($startDate,$endDate,True) / 360;
857
- }
858
- }
859
- return PHPExcel_Calculation_Functions::VALUE();
860
- } // function YEARFRAC()
861
-
862
-
863
- /**
864
- * NETWORKDAYS
865
- *
866
- * Returns the number of whole working days between start_date and end_date. Working days
867
- * exclude weekends and any dates identified in holidays.
868
- * Use NETWORKDAYS to calculate employee benefits that accrue based on the number of days
869
- * worked during a specific term.
870
- *
871
- * Excel Function:
872
- * NETWORKDAYS(startDate,endDate[,holidays[,holiday[,...]]])
873
- *
874
- * @access public
875
- * @category Date/Time Functions
876
- * @param mixed $startDate Excel date serial value (float), PHP date timestamp (integer),
877
- * PHP DateTime object, or a standard date string
878
- * @param mixed $endDate Excel date serial value (float), PHP date timestamp (integer),
879
- * PHP DateTime object, or a standard date string
880
- * @param mixed $holidays,... Optional series of Excel date serial value (float), PHP date
881
- * timestamp (integer), PHP DateTime object, or a standard date
882
- * strings that will be excluded from the working calendar, such
883
- * as state and federal holidays and floating holidays.
884
- * @return integer Interval between the dates
885
- */
886
- public static function NETWORKDAYS($startDate,$endDate) {
887
- // Retrieve the mandatory start and end date that are referenced in the function definition
888
- $startDate = PHPExcel_Calculation_Functions::flattenSingleValue($startDate);
889
- $endDate = PHPExcel_Calculation_Functions::flattenSingleValue($endDate);
890
- // Flush the mandatory start and end date that are referenced in the function definition, and get the optional days
891
- $dateArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args());
892
- array_shift($dateArgs);
893
- array_shift($dateArgs);
894
-
895
- // Validate the start and end dates
896
- if (is_string($startDate = $sDate = self::_getDateValue($startDate))) {
897
- return PHPExcel_Calculation_Functions::VALUE();
898
- }
899
- $startDate = (float) floor($startDate);
900
- if (is_string($endDate = $eDate = self::_getDateValue($endDate))) {
901
- return PHPExcel_Calculation_Functions::VALUE();
902
- }
903
- $endDate = (float) floor($endDate);
904
-
905
- if ($sDate > $eDate) {
906
- $startDate = $eDate;
907
- $endDate = $sDate;
908
- }
909
-
910
- // Execute function
911
- $startDoW = 6 - self::DAYOFWEEK($startDate,2);
912
- if ($startDoW < 0) { $startDoW = 0; }
913
- $endDoW = self::DAYOFWEEK($endDate,2);
914
- if ($endDoW >= 6) { $endDoW = 0; }
915
-
916
- $wholeWeekDays = floor(($endDate - $startDate) / 7) * 5;
917
- $partWeekDays = $endDoW + $startDoW;
918
- if ($partWeekDays > 5) {
919
- $partWeekDays -= 5;
920
- }
921
-
922
- // Test any extra holiday parameters
923
- $holidayCountedArray = array();
924
- foreach ($dateArgs as $holidayDate) {
925
- if (is_string($holidayDate = self::_getDateValue($holidayDate))) {
926
- return PHPExcel_Calculation_Functions::VALUE();
927
- }
928
- if (($holidayDate >= $startDate) && ($holidayDate <= $endDate)) {
929
- if ((self::DAYOFWEEK($holidayDate,2) < 6) && (!in_array($holidayDate,$holidayCountedArray))) {
930
- --$partWeekDays;
931
- $holidayCountedArray[] = $holidayDate;
932
- }
933
- }
934
- }
935
-
936
- if ($sDate > $eDate) {
937
- return 0 - ($wholeWeekDays + $partWeekDays);
938
- }
939
- return $wholeWeekDays + $partWeekDays;
940
- } // function NETWORKDAYS()
941
-
942
-
943
- /**
944
- * WORKDAY
945
- *
946
- * Returns the date that is the indicated number of working days before or after a date (the
947
- * starting date). Working days exclude weekends and any dates identified as holidays.
948
- * Use WORKDAY to exclude weekends or holidays when you calculate invoice due dates, expected
949
- * delivery times, or the number of days of work performed.
950
- *
951
- * Excel Function:
952
- * WORKDAY(startDate,endDays[,holidays[,holiday[,...]]])
953
- *
954
- * @access public
955
- * @category Date/Time Functions
956
- * @param mixed $startDate Excel date serial value (float), PHP date timestamp (integer),
957
- * PHP DateTime object, or a standard date string
958
- * @param integer $endDays The number of nonweekend and nonholiday days before or after
959
- * startDate. A positive value for days yields a future date; a
960
- * negative value yields a past date.
961
- * @param mixed $holidays,... Optional series of Excel date serial value (float), PHP date
962
- * timestamp (integer), PHP DateTime object, or a standard date
963
- * strings that will be excluded from the working calendar, such
964
- * as state and federal holidays and floating holidays.
965
- * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
966
- * depending on the value of the ReturnDateType flag
967
- */
968
- public static function WORKDAY($startDate,$endDays) {
969
- // Retrieve the mandatory start date and days that are referenced in the function definition
970
- $startDate = PHPExcel_Calculation_Functions::flattenSingleValue($startDate);
971
- $endDays = PHPExcel_Calculation_Functions::flattenSingleValue($endDays);
972
- // Flush the mandatory start date and days that are referenced in the function definition, and get the optional days
973
- $dateArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args());
974
- array_shift($dateArgs);
975
- array_shift($dateArgs);
976
-
977
- if ((is_string($startDate = self::_getDateValue($startDate))) || (!is_numeric($endDays))) {
978
- return PHPExcel_Calculation_Functions::VALUE();
979
- }
980
- $startDate = (float) floor($startDate);
981
- $endDays = (int) floor($endDays);
982
- // If endDays is 0, we always return startDate
983
- if ($endDays == 0) { return $startDate; }
984
-
985
- $decrementing = ($endDays < 0) ? True : False;
986
-
987
- // Adjust the start date if it falls over a weekend
988
-
989
- $startDoW = self::DAYOFWEEK($startDate,3);
990
- if (self::DAYOFWEEK($startDate,3) >= 5) {
991
- $startDate += ($decrementing) ? -$startDoW + 4: 7 - $startDoW;
992
- ($decrementing) ? $endDays++ : $endDays--;
993
- }
994
-
995
- // Add endDays
996
- $endDate = (float) $startDate + (intval($endDays / 5) * 7) + ($endDays % 5);
997
-
998
- // Adjust the calculated end date if it falls over a weekend
999
- $endDoW = self::DAYOFWEEK($endDate,3);
1000
- if ($endDoW >= 5) {
1001
- $endDate += ($decrementing) ? -$endDoW + 4: 7 - $endDoW;
1002
- }
1003
-
1004
- // Test any extra holiday parameters
1005
- if (!empty($dateArgs)) {
1006
- $holidayCountedArray = $holidayDates = array();
1007
- foreach ($dateArgs as $holidayDate) {
1008
- if (($holidayDate !== NULL) && (trim($holidayDate) > '')) {
1009
- if (is_string($holidayDate = self::_getDateValue($holidayDate))) {
1010
- return PHPExcel_Calculation_Functions::VALUE();
1011
- }
1012
- if (self::DAYOFWEEK($holidayDate,3) < 5) {
1013
- $holidayDates[] = $holidayDate;
1014
- }
1015
- }
1016
- }
1017
- if ($decrementing) {
1018
- rsort($holidayDates, SORT_NUMERIC);
1019
- } else {
1020
- sort($holidayDates, SORT_NUMERIC);
1021
- }
1022
- foreach ($holidayDates as $holidayDate) {
1023
- if ($decrementing) {
1024
- if (($holidayDate <= $startDate) && ($holidayDate >= $endDate)) {
1025
- if (!in_array($holidayDate,$holidayCountedArray)) {
1026
- --$endDate;
1027
- $holidayCountedArray[] = $holidayDate;
1028
- }
1029
- }
1030
- } else {
1031
- if (($holidayDate >= $startDate) && ($holidayDate <= $endDate)) {
1032
- if (!in_array($holidayDate,$holidayCountedArray)) {
1033
- ++$endDate;
1034
- $holidayCountedArray[] = $holidayDate;
1035
- }
1036
- }
1037
- }
1038
- // Adjust the calculated end date if it falls over a weekend
1039
- $endDoW = self::DAYOFWEEK($endDate,3);
1040
- if ($endDoW >= 5) {
1041
- $endDate += ($decrementing) ? -$endDoW + 4: 7 - $endDoW;
1042
- }
1043
-
1044
- }
1045
- }
1046
-
1047
- switch (PHPExcel_Calculation_Functions::getReturnDateType()) {
1048
- case PHPExcel_Calculation_Functions::RETURNDATE_EXCEL :
1049
- return (float) $endDate;
1050
- case PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC :
1051
- return (integer) PHPExcel_Shared_Date::ExcelToPHP($endDate);
1052
- case PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT :
1053
- return PHPExcel_Shared_Date::ExcelToPHPObject($endDate);
1054
- }
1055
- } // function WORKDAY()
1056
-
1057
-
1058
- /**
1059
- * DAYOFMONTH
1060
- *
1061
- * Returns the day of the month, for a specified date. The day is given as an integer
1062
- * ranging from 1 to 31.
1063
- *
1064
- * Excel Function:
1065
- * DAY(dateValue)
1066
- *
1067
- * @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer),
1068
- * PHP DateTime object, or a standard date string
1069
- * @return int Day of the month
1070
- */
1071
- public static function DAYOFMONTH($dateValue = 1) {
1072
- $dateValue = PHPExcel_Calculation_Functions::flattenSingleValue($dateValue);
1073
-
1074
- if (is_string($dateValue = self::_getDateValue($dateValue))) {
1075
- return PHPExcel_Calculation_Functions::VALUE();
1076
- } elseif ($dateValue == 0.0) {
1077
- return 0;
1078
- } elseif ($dateValue < 0.0) {
1079
- return PHPExcel_Calculation_Functions::NaN();
1080
- }
1081
-
1082
- // Execute function
1083
- $PHPDateObject = PHPExcel_Shared_Date::ExcelToPHPObject($dateValue);
1084
-
1085
- return (int) $PHPDateObject->format('j');
1086
- } // function DAYOFMONTH()
1087
-
1088
-
1089
- /**
1090
- * DAYOFWEEK
1091
- *
1092
- * Returns the day of the week for a specified date. The day is given as an integer
1093
- * ranging from 0 to 7 (dependent on the requested style).
1094
- *
1095
- * Excel Function:
1096
- * WEEKDAY(dateValue[,style])
1097
- *
1098
- * @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer),
1099
- * PHP DateTime object, or a standard date string
1100
- * @param int $style A number that determines the type of return value
1101
- * 1 or omitted Numbers 1 (Sunday) through 7 (Saturday).
1102
- * 2 Numbers 1 (Monday) through 7 (Sunday).
1103
- * 3 Numbers 0 (Monday) through 6 (Sunday).
1104
- * @return int Day of the week value
1105
- */
1106
- public static function DAYOFWEEK($dateValue = 1, $style = 1) {
1107
- $dateValue = PHPExcel_Calculation_Functions::flattenSingleValue($dateValue);
1108
- $style = PHPExcel_Calculation_Functions::flattenSingleValue($style);
1109
-
1110
- if (!is_numeric($style)) {
1111
- return PHPExcel_Calculation_Functions::VALUE();
1112
- } elseif (($style < 1) || ($style > 3)) {
1113
- return PHPExcel_Calculation_Functions::NaN();
1114
- }
1115
- $style = floor($style);
1116
-
1117
- if (is_string($dateValue = self::_getDateValue($dateValue))) {
1118
- return PHPExcel_Calculation_Functions::VALUE();
1119
- } elseif ($dateValue < 0.0) {
1120
- return PHPExcel_Calculation_Functions::NaN();
1121
- }
1122
-
1123
- // Execute function
1124
- $PHPDateObject = PHPExcel_Shared_Date::ExcelToPHPObject($dateValue);
1125
- $DoW = $PHPDateObject->format('w');
1126
-
1127
- $firstDay = 1;
1128
- switch ($style) {
1129
- case 1: ++$DoW;
1130
- break;
1131
- case 2: if ($DoW == 0) { $DoW = 7; }
1132
- break;
1133
- case 3: if ($DoW == 0) { $DoW = 7; }
1134
- $firstDay = 0;
1135
- --$DoW;
1136
- break;
1137
- }
1138
- if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_EXCEL) {
1139
- // Test for Excel's 1900 leap year, and introduce the error as required
1140
- if (($PHPDateObject->format('Y') == 1900) && ($PHPDateObject->format('n') <= 2)) {
1141
- --$DoW;
1142
- if ($DoW < $firstDay) {
1143
- $DoW += 7;
1144
- }
1145
- }
1146
- }
1147
-
1148
- return (int) $DoW;
1149
- } // function DAYOFWEEK()
1150
-
1151
-
1152
- /**
1153
- * WEEKOFYEAR
1154
- *
1155
- * Returns the week of the year for a specified date.
1156
- * The WEEKNUM function considers the week containing January 1 to be the first week of the year.
1157
- * However, there is a European standard that defines the first week as the one with the majority
1158
- * of days (four or more) falling in the new year. This means that for years in which there are
1159
- * three days or less in the first week of January, the WEEKNUM function returns week numbers
1160
- * that are incorrect according to the European standard.
1161
- *
1162
- * Excel Function:
1163
- * WEEKNUM(dateValue[,style])
1164
- *
1165
- * @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer),
1166
- * PHP DateTime object, or a standard date string
1167
- * @param boolean $method Week begins on Sunday or Monday
1168
- * 1 or omitted Week begins on Sunday.
1169
- * 2 Week begins on Monday.
1170
- * @return int Week Number
1171
- */
1172
- public static function WEEKOFYEAR($dateValue = 1, $method = 1) {
1173
- $dateValue = PHPExcel_Calculation_Functions::flattenSingleValue($dateValue);
1174
- $method = PHPExcel_Calculation_Functions::flattenSingleValue($method);
1175
-
1176
- if (!is_numeric($method)) {
1177
- return PHPExcel_Calculation_Functions::VALUE();
1178
- } elseif (($method < 1) || ($method > 2)) {
1179
- return PHPExcel_Calculation_Functions::NaN();
1180
- }
1181
- $method = floor($method);
1182
-
1183
- if (is_string($dateValue = self::_getDateValue($dateValue))) {
1184
- return PHPExcel_Calculation_Functions::VALUE();
1185
- } elseif ($dateValue < 0.0) {
1186
- return PHPExcel_Calculation_Functions::NaN();
1187
- }
1188
-
1189
- // Execute function
1190
- $PHPDateObject = PHPExcel_Shared_Date::ExcelToPHPObject($dateValue);
1191
- $dayOfYear = $PHPDateObject->format('z');
1192
- $dow = $PHPDateObject->format('w');
1193
- $PHPDateObject->modify('-'.$dayOfYear.' days');
1194
- $dow = $PHPDateObject->format('w');
1195
- $daysInFirstWeek = 7 - (($dow + (2 - $method)) % 7);
1196
- $dayOfYear -= $daysInFirstWeek;
1197
- $weekOfYear = ceil($dayOfYear / 7) + 1;
1198
-
1199
- return (int) $weekOfYear;
1200
- } // function WEEKOFYEAR()
1201
-
1202
-
1203
- /**
1204
- * MONTHOFYEAR
1205
- *
1206
- * Returns the month of a date represented by a serial number.
1207
- * The month is given as an integer, ranging from 1 (January) to 12 (December).
1208
- *
1209
- * Excel Function:
1210
- * MONTH(dateValue)
1211
- *
1212
- * @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer),
1213
- * PHP DateTime object, or a standard date string
1214
- * @return int Month of the year
1215
- */
1216
- public static function MONTHOFYEAR($dateValue = 1) {
1217
- $dateValue = PHPExcel_Calculation_Functions::flattenSingleValue($dateValue);
1218
-
1219
- if (is_string($dateValue = self::_getDateValue($dateValue))) {
1220
- return PHPExcel_Calculation_Functions::VALUE();
1221
- } elseif ($dateValue < 0.0) {
1222
- return PHPExcel_Calculation_Functions::NaN();
1223
- }
1224
-
1225
- // Execute function
1226
- $PHPDateObject = PHPExcel_Shared_Date::ExcelToPHPObject($dateValue);
1227
-
1228
- return (int) $PHPDateObject->format('n');
1229
- } // function MONTHOFYEAR()
1230
-
1231
-
1232
- /**
1233
- * YEAR
1234
- *
1235
- * Returns the year corresponding to a date.
1236
- * The year is returned as an integer in the range 1900-9999.
1237
- *
1238
- * Excel Function:
1239
- * YEAR(dateValue)
1240
- *
1241
- * @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer),
1242
- * PHP DateTime object, or a standard date string
1243
- * @return int Year
1244
- */
1245
- public static function YEAR($dateValue = 1) {
1246
- $dateValue = PHPExcel_Calculation_Functions::flattenSingleValue($dateValue);
1247
-
1248
- if (is_string($dateValue = self::_getDateValue($dateValue))) {
1249
- return PHPExcel_Calculation_Functions::VALUE();
1250
- } elseif ($dateValue < 0.0) {
1251
- return PHPExcel_Calculation_Functions::NaN();
1252
- }
1253
-
1254
- // Execute function
1255
- $PHPDateObject = PHPExcel_Shared_Date::ExcelToPHPObject($dateValue);
1256
-
1257
- return (int) $PHPDateObject->format('Y');
1258
- } // function YEAR()
1259
-
1260
-
1261
- /**
1262
- * HOUROFDAY
1263
- *
1264
- * Returns the hour of a time value.
1265
- * The hour is given as an integer, ranging from 0 (12:00 A.M.) to 23 (11:00 P.M.).
1266
- *
1267
- * Excel Function:
1268
- * HOUR(timeValue)
1269
- *
1270
- * @param mixed $timeValue Excel date serial value (float), PHP date timestamp (integer),
1271
- * PHP DateTime object, or a standard time string
1272
- * @return int Hour
1273
- */
1274
- public static function HOUROFDAY($timeValue = 0) {
1275
- $timeValue = PHPExcel_Calculation_Functions::flattenSingleValue($timeValue);
1276
-
1277
- if (!is_numeric($timeValue)) {
1278
- if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC) {
1279
- $testVal = strtok($timeValue,'/-: ');
1280
- if (strlen($testVal) < strlen($timeValue)) {
1281
- return PHPExcel_Calculation_Functions::VALUE();
1282
- }
1283
- }
1284
- $timeValue = self::_getTimeValue($timeValue);
1285
- if (is_string($timeValue)) {
1286
- return PHPExcel_Calculation_Functions::VALUE();
1287
- }
1288
- }
1289
- // Execute function
1290
- if ($timeValue >= 1) {
1291
- $timeValue = fmod($timeValue,1);
1292
- } elseif ($timeValue < 0.0) {
1293
- return PHPExcel_Calculation_Functions::NaN();
1294
- }
1295
- $timeValue = PHPExcel_Shared_Date::ExcelToPHP($timeValue);
1296
-
1297
- return (int) gmdate('G',$timeValue);
1298
- } // function HOUROFDAY()
1299
-
1300
-
1301
- /**
1302
- * MINUTEOFHOUR
1303
- *
1304
- * Returns the minutes of a time value.
1305
- * The minute is given as an integer, ranging from 0 to 59.
1306
- *
1307
- * Excel Function:
1308
- * MINUTE(timeValue)
1309
- *
1310
- * @param mixed $timeValue Excel date serial value (float), PHP date timestamp (integer),
1311
- * PHP DateTime object, or a standard time string
1312
- * @return int Minute
1313
- */
1314
- public static function MINUTEOFHOUR($timeValue = 0) {
1315
- $timeValue = $timeTester = PHPExcel_Calculation_Functions::flattenSingleValue($timeValue);
1316
-
1317
- if (!is_numeric($timeValue)) {
1318
- if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC) {
1319
- $testVal = strtok($timeValue,'/-: ');
1320
- if (strlen($testVal) < strlen($timeValue)) {
1321
- return PHPExcel_Calculation_Functions::VALUE();
1322
- }
1323
- }
1324
- $timeValue = self::_getTimeValue($timeValue);
1325
- if (is_string($timeValue)) {
1326
- return PHPExcel_Calculation_Functions::VALUE();
1327
- }
1328
- }
1329
- // Execute function
1330
- if ($timeValue >= 1) {
1331
- $timeValue = fmod($timeValue,1);
1332
- } elseif ($timeValue < 0.0) {
1333
- return PHPExcel_Calculation_Functions::NaN();
1334
- }
1335
- $timeValue = PHPExcel_Shared_Date::ExcelToPHP($timeValue);
1336
-
1337
- return (int) gmdate('i',$timeValue);
1338
- } // function MINUTEOFHOUR()
1339
-
1340
-
1341
- /**
1342
- * SECONDOFMINUTE
1343
- *
1344
- * Returns the seconds of a time value.
1345
- * The second is given as an integer in the range 0 (zero) to 59.
1346
- *
1347
- * Excel Function:
1348
- * SECOND(timeValue)
1349
- *
1350
- * @param mixed $timeValue Excel date serial value (float), PHP date timestamp (integer),
1351
- * PHP DateTime object, or a standard time string
1352
- * @return int Second
1353
- */
1354
- public static function SECONDOFMINUTE($timeValue = 0) {
1355
- $timeValue = PHPExcel_Calculation_Functions::flattenSingleValue($timeValue);
1356
-
1357
- if (!is_numeric($timeValue)) {
1358
- if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC) {
1359
- $testVal = strtok($timeValue,'/-: ');
1360
- if (strlen($testVal) < strlen($timeValue)) {
1361
- return PHPExcel_Calculation_Functions::VALUE();
1362
- }
1363
- }
1364
- $timeValue = self::_getTimeValue($timeValue);
1365
- if (is_string($timeValue)) {
1366
- return PHPExcel_Calculation_Functions::VALUE();
1367
- }
1368
- }
1369
- // Execute function
1370
- if ($timeValue >= 1) {
1371
- $timeValue = fmod($timeValue,1);
1372
- } elseif ($timeValue < 0.0) {
1373
- return PHPExcel_Calculation_Functions::NaN();
1374
- }
1375
- $timeValue = PHPExcel_Shared_Date::ExcelToPHP($timeValue);
1376
-
1377
- return (int) gmdate('s',$timeValue);
1378
- } // function SECONDOFMINUTE()
1379
-
1380
-
1381
- /**
1382
- * EDATE
1383
- *
1384
- * Returns the serial number that represents the date that is the indicated number of months
1385
- * before or after a specified date (the start_date).
1386
- * Use EDATE to calculate maturity dates or due dates that fall on the same day of the month
1387
- * as the date of issue.
1388
- *
1389
- * Excel Function:
1390
- * EDATE(dateValue,adjustmentMonths)
1391
- *
1392
- * @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer),
1393
- * PHP DateTime object, or a standard date string
1394
- * @param int $adjustmentMonths The number of months before or after start_date.
1395
- * A positive value for months yields a future date;
1396
- * a negative value yields a past date.
1397
- * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
1398
- * depending on the value of the ReturnDateType flag
1399
- */
1400
- public static function EDATE($dateValue = 1, $adjustmentMonths = 0) {
1401
- $dateValue = PHPExcel_Calculation_Functions::flattenSingleValue($dateValue);
1402
- $adjustmentMonths = PHPExcel_Calculation_Functions::flattenSingleValue($adjustmentMonths);
1403
-
1404
- if (!is_numeric($adjustmentMonths)) {
1405
- return PHPExcel_Calculation_Functions::VALUE();
1406
- }
1407
- $adjustmentMonths = floor($adjustmentMonths);
1408
-
1409
- if (is_string($dateValue = self::_getDateValue($dateValue))) {
1410
- return PHPExcel_Calculation_Functions::VALUE();
1411
- }
1412
-
1413
- // Execute function
1414
- $PHPDateObject = self::_adjustDateByMonths($dateValue,$adjustmentMonths);
1415
-
1416
- switch (PHPExcel_Calculation_Functions::getReturnDateType()) {
1417
- case PHPExcel_Calculation_Functions::RETURNDATE_EXCEL :
1418
- return (float) PHPExcel_Shared_Date::PHPToExcel($PHPDateObject);
1419
- case PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC :
1420
- return (integer) PHPExcel_Shared_Date::ExcelToPHP(PHPExcel_Shared_Date::PHPToExcel($PHPDateObject));
1421
- case PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT :
1422
- return $PHPDateObject;
1423
- }
1424
- } // function EDATE()
1425
-
1426
-
1427
- /**
1428
- * EOMONTH
1429
- *
1430
- * Returns the date value for the last day of the month that is the indicated number of months
1431
- * before or after start_date.
1432
- * Use EOMONTH to calculate maturity dates or due dates that fall on the last day of the month.
1433
- *
1434
- * Excel Function:
1435
- * EOMONTH(dateValue,adjustmentMonths)
1436
- *
1437
- * @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer),
1438
- * PHP DateTime object, or a standard date string
1439
- * @param int $adjustmentMonths The number of months before or after start_date.
1440
- * A positive value for months yields a future date;
1441
- * a negative value yields a past date.
1442
- * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
1443
- * depending on the value of the ReturnDateType flag
1444
- */
1445
- public static function EOMONTH($dateValue = 1, $adjustmentMonths = 0) {
1446
- $dateValue = PHPExcel_Calculation_Functions::flattenSingleValue($dateValue);
1447
- $adjustmentMonths = PHPExcel_Calculation_Functions::flattenSingleValue($adjustmentMonths);
1448
-
1449
- if (!is_numeric($adjustmentMonths)) {
1450
- return PHPExcel_Calculation_Functions::VALUE();
1451
- }
1452
- $adjustmentMonths = floor($adjustmentMonths);
1453
-
1454
- if (is_string($dateValue = self::_getDateValue($dateValue))) {
1455
- return PHPExcel_Calculation_Functions::VALUE();
1456
- }
1457
-
1458
- // Execute function
1459
- $PHPDateObject = self::_adjustDateByMonths($dateValue,$adjustmentMonths+1);
1460
- $adjustDays = (int) $PHPDateObject->format('d');
1461
- $adjustDaysString = '-'.$adjustDays.' days';
1462
- $PHPDateObject->modify($adjustDaysString);
1463
-
1464
- switch (PHPExcel_Calculation_Functions::getReturnDateType()) {
1465
- case PHPExcel_Calculation_Functions::RETURNDATE_EXCEL :
1466
- return (float) PHPExcel_Shared_Date::PHPToExcel($PHPDateObject);
1467
- case PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC :
1468
- return (integer) PHPExcel_Shared_Date::ExcelToPHP(PHPExcel_Shared_Date::PHPToExcel($PHPDateObject));
1469
- case PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT :
1470
- return $PHPDateObject;
1471
- }
1472
- } // function EOMONTH()
1473
-
1474
- } // class PHPExcel_Calculation_DateTime
1475
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /** PHPExcel root directory */
4
+ if (!defined('PHPEXCEL_ROOT')) {
5
+ /**
6
+ * @ignore
7
+ */
8
+ define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
9
+ require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
10
+ }
11
+
12
+ /**
13
+ * PHPExcel_Calculation_DateTime
14
+ *
15
+ * Copyright (c) 2006 - 2015 PHPExcel
16
+ *
17
+ * This library is free software; you can redistribute it and/or
18
+ * modify it under the terms of the GNU Lesser General Public
19
+ * License as published by the Free Software Foundation; either
20
+ * version 2.1 of the License, or (at your option) any later version.
21
+ *
22
+ * This library is distributed in the hope that it will be useful,
23
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
24
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25
+ * Lesser General Public License for more details.
26
+ *
27
+ * You should have received a copy of the GNU Lesser General Public
28
+ * License along with this library; if not, write to the Free Software
29
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
30
+ *
31
+ * @category PHPExcel
32
+ * @package PHPExcel_Calculation
33
+ * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
34
+ * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
35
+ * @version ##VERSION##, ##DATE##
36
+ */
37
+ class PHPExcel_Calculation_DateTime
38
+ {
39
+ /**
40
+ * Identify if a year is a leap year or not
41
+ *
42
+ * @param integer $year The year to test
43
+ * @return boolean TRUE if the year is a leap year, otherwise FALSE
44
+ */
45
+ public static function isLeapYear($year)
46
+ {
47
+ return ((($year % 4) == 0) && (($year % 100) != 0) || (($year % 400) == 0));
48
+ }
49
+
50
+
51
+ /**
52
+ * Return the number of days between two dates based on a 360 day calendar
53
+ *
54
+ * @param integer $startDay Day of month of the start date
55
+ * @param integer $startMonth Month of the start date
56
+ * @param integer $startYear Year of the start date
57
+ * @param integer $endDay Day of month of the start date
58
+ * @param integer $endMonth Month of the start date
59
+ * @param integer $endYear Year of the start date
60
+ * @param boolean $methodUS Whether to use the US method or the European method of calculation
61
+ * @return integer Number of days between the start date and the end date
62
+ */
63
+ private static function dateDiff360($startDay, $startMonth, $startYear, $endDay, $endMonth, $endYear, $methodUS)
64
+ {
65
+ if ($startDay == 31) {
66
+ --$startDay;
67
+ } elseif ($methodUS && ($startMonth == 2 && ($startDay == 29 || ($startDay == 28 && !self::isLeapYear($startYear))))) {
68
+ $startDay = 30;
69
+ }
70
+ if ($endDay == 31) {
71
+ if ($methodUS && $startDay != 30) {
72
+ $endDay = 1;
73
+ if ($endMonth == 12) {
74
+ ++$endYear;
75
+ $endMonth = 1;
76
+ } else {
77
+ ++$endMonth;
78
+ }
79
+ } else {
80
+ $endDay = 30;
81
+ }
82
+ }
83
+
84
+ return $endDay + $endMonth * 30 + $endYear * 360 - $startDay - $startMonth * 30 - $startYear * 360;
85
+ }
86
+
87
+
88
+ /**
89
+ * getDateValue
90
+ *
91
+ * @param string $dateValue
92
+ * @return mixed Excel date/time serial value, or string if error
93
+ */
94
+ public static function getDateValue($dateValue)
95
+ {
96
+ if (!is_numeric($dateValue)) {
97
+ if ((is_string($dateValue)) &&
98
+ (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC)) {
99
+ return PHPExcel_Calculation_Functions::VALUE();
100
+ }
101
+ if ((is_object($dateValue)) && ($dateValue instanceof DateTime)) {
102
+ $dateValue = PHPExcel_Shared_Date::PHPToExcel($dateValue);
103
+ } else {
104
+ $saveReturnDateType = PHPExcel_Calculation_Functions::getReturnDateType();
105
+ PHPExcel_Calculation_Functions::setReturnDateType(PHPExcel_Calculation_Functions::RETURNDATE_EXCEL);
106
+ $dateValue = self::DATEVALUE($dateValue);
107
+ PHPExcel_Calculation_Functions::setReturnDateType($saveReturnDateType);
108
+ }
109
+ }
110
+ return $dateValue;
111
+ }
112
+
113
+
114
+ /**
115
+ * getTimeValue
116
+ *
117
+ * @param string $timeValue
118
+ * @return mixed Excel date/time serial value, or string if error
119
+ */
120
+ private static function getTimeValue($timeValue)
121
+ {
122
+ $saveReturnDateType = PHPExcel_Calculation_Functions::getReturnDateType();
123
+ PHPExcel_Calculation_Functions::setReturnDateType(PHPExcel_Calculation_Functions::RETURNDATE_EXCEL);
124
+ $timeValue = self::TIMEVALUE($timeValue);
125
+ PHPExcel_Calculation_Functions::setReturnDateType($saveReturnDateType);
126
+ return $timeValue;
127
+ }
128
+
129
+
130
+ private static function adjustDateByMonths($dateValue = 0, $adjustmentMonths = 0)
131
+ {
132
+ // Execute function
133
+ $PHPDateObject = PHPExcel_Shared_Date::ExcelToPHPObject($dateValue);
134
+ $oMonth = (int) $PHPDateObject->format('m');
135
+ $oYear = (int) $PHPDateObject->format('Y');
136
+
137
+ $adjustmentMonthsString = (string) $adjustmentMonths;
138
+ if ($adjustmentMonths > 0) {
139
+ $adjustmentMonthsString = '+'.$adjustmentMonths;
140
+ }
141
+ if ($adjustmentMonths != 0) {
142
+ $PHPDateObject->modify($adjustmentMonthsString.' months');
143
+ }
144
+ $nMonth = (int) $PHPDateObject->format('m');
145
+ $nYear = (int) $PHPDateObject->format('Y');
146
+
147
+ $monthDiff = ($nMonth - $oMonth) + (($nYear - $oYear) * 12);
148
+ if ($monthDiff != $adjustmentMonths) {
149
+ $adjustDays = (int) $PHPDateObject->format('d');
150
+ $adjustDaysString = '-'.$adjustDays.' days';
151
+ $PHPDateObject->modify($adjustDaysString);
152
+ }
153
+ return $PHPDateObject;
154
+ }
155
+
156
+
157
+ /**
158
+ * DATETIMENOW
159
+ *
160
+ * Returns the current date and time.
161
+ * The NOW function is useful when you need to display the current date and time on a worksheet or
162
+ * calculate a value based on the current date and time, and have that value updated each time you
163
+ * open the worksheet.
164
+ *
165
+ * NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the date
166
+ * and time format of your regional settings. PHPExcel does not change cell formatting in this way.
167
+ *
168
+ * Excel Function:
169
+ * NOW()
170
+ *
171
+ * @access public
172
+ * @category Date/Time Functions
173
+ * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
174
+ * depending on the value of the ReturnDateType flag
175
+ */
176
+ public static function DATETIMENOW()
177
+ {
178
+ $saveTimeZone = date_default_timezone_get();
179
+ date_default_timezone_set('UTC');
180
+ $retValue = false;
181
+ switch (PHPExcel_Calculation_Functions::getReturnDateType()) {
182
+ case PHPExcel_Calculation_Functions::RETURNDATE_EXCEL:
183
+ $retValue = (float) PHPExcel_Shared_Date::PHPToExcel(time());
184
+ break;
185
+ case PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC:
186
+ $retValue = (integer) time();
187
+ break;
188
+ case PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT:
189
+ $retValue = new DateTime();
190
+ break;
191
+ }
192
+ date_default_timezone_set($saveTimeZone);
193
+
194
+ return $retValue;
195
+ }
196
+
197
+
198
+ /**
199
+ * DATENOW
200
+ *
201
+ * Returns the current date.
202
+ * The NOW function is useful when you need to display the current date and time on a worksheet or
203
+ * calculate a value based on the current date and time, and have that value updated each time you
204
+ * open the worksheet.
205
+ *
206
+ * NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the date
207
+ * and time format of your regional settings. PHPExcel does not change cell formatting in this way.
208
+ *
209
+ * Excel Function:
210
+ * TODAY()
211
+ *
212
+ * @access public
213
+ * @category Date/Time Functions
214
+ * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
215
+ * depending on the value of the ReturnDateType flag
216
+ */
217
+ public static function DATENOW()
218
+ {
219
+ $saveTimeZone = date_default_timezone_get();
220
+ date_default_timezone_set('UTC');
221
+ $retValue = false;
222
+ $excelDateTime = floor(PHPExcel_Shared_Date::PHPToExcel(time()));
223
+ switch (PHPExcel_Calculation_Functions::getReturnDateType()) {
224
+ case PHPExcel_Calculation_Functions::RETURNDATE_EXCEL:
225
+ $retValue = (float) $excelDateTime;
226
+ break;
227
+ case PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC:
228
+ $retValue = (integer) PHPExcel_Shared_Date::ExcelToPHP($excelDateTime);
229
+ break;
230
+ case PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT:
231
+ $retValue = PHPExcel_Shared_Date::ExcelToPHPObject($excelDateTime);
232
+ break;
233
+ }
234
+ date_default_timezone_set($saveTimeZone);
235
+
236
+ return $retValue;
237
+ }
238
+
239
+
240
+ /**
241
+ * DATE
242
+ *
243
+ * The DATE function returns a value that represents a particular date.
244
+ *
245
+ * NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the date
246
+ * format of your regional settings. PHPExcel does not change cell formatting in this way.
247
+ *
248
+ * Excel Function:
249
+ * DATE(year,month,day)
250
+ *
251
+ * PHPExcel is a lot more forgiving than MS Excel when passing non numeric values to this function.
252
+ * A Month name or abbreviation (English only at this point) such as 'January' or 'Jan' will still be accepted,
253
+ * as will a day value with a suffix (e.g. '21st' rather than simply 21); again only English language.
254
+ *
255
+ * @access public
256
+ * @category Date/Time Functions
257
+ * @param integer $year The value of the year argument can include one to four digits.
258
+ * Excel interprets the year argument according to the configured
259
+ * date system: 1900 or 1904.
260
+ * If year is between 0 (zero) and 1899 (inclusive), Excel adds that
261
+ * value to 1900 to calculate the year. For example, DATE(108,1,2)
262
+ * returns January 2, 2008 (1900+108).
263
+ * If year is between 1900 and 9999 (inclusive), Excel uses that
264
+ * value as the year. For example, DATE(2008,1,2) returns January 2,
265
+ * 2008.
266
+ * If year is less than 0 or is 10000 or greater, Excel returns the
267
+ * #NUM! error value.
268
+ * @param integer $month A positive or negative integer representing the month of the year
269
+ * from 1 to 12 (January to December).
270
+ * If month is greater than 12, month adds that number of months to
271
+ * the first month in the year specified. For example, DATE(2008,14,2)
272
+ * returns the serial number representing February 2, 2009.
273
+ * If month is less than 1, month subtracts the magnitude of that
274
+ * number of months, plus 1, from the first month in the year
275
+ * specified. For example, DATE(2008,-3,2) returns the serial number
276
+ * representing September 2, 2007.
277
+ * @param integer $day A positive or negative integer representing the day of the month
278
+ * from 1 to 31.
279
+ * If day is greater than the number of days in the month specified,
280
+ * day adds that number of days to the first day in the month. For
281
+ * example, DATE(2008,1,35) returns the serial number representing
282
+ * February 4, 2008.
283
+ * If day is less than 1, day subtracts the magnitude that number of
284
+ * days, plus one, from the first day of the month specified. For
285
+ * example, DATE(2008,1,-15) returns the serial number representing
286
+ * December 16, 2007.
287
+ * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
288
+ * depending on the value of the ReturnDateType flag
289
+ */
290
+ public static function DATE($year = 0, $month = 1, $day = 1)
291
+ {
292
+ $year = PHPExcel_Calculation_Functions::flattenSingleValue($year);
293
+ $month = PHPExcel_Calculation_Functions::flattenSingleValue($month);
294
+ $day = PHPExcel_Calculation_Functions::flattenSingleValue($day);
295
+
296
+ if (($month !== null) && (!is_numeric($month))) {
297
+ $month = PHPExcel_Shared_Date::monthStringToNumber($month);
298
+ }
299
+
300
+ if (($day !== null) && (!is_numeric($day))) {
301
+ $day = PHPExcel_Shared_Date::dayStringToNumber($day);
302
+ }
303
+
304
+ $year = ($year !== null) ? PHPExcel_Shared_String::testStringAsNumeric($year) : 0;
305
+ $month = ($month !== null) ? PHPExcel_Shared_String::testStringAsNumeric($month) : 0;
306
+ $day = ($day !== null) ? PHPExcel_Shared_String::testStringAsNumeric($day) : 0;
307
+ if ((!is_numeric($year)) ||
308
+ (!is_numeric($month)) ||
309
+ (!is_numeric($day))) {
310
+ return PHPExcel_Calculation_Functions::VALUE();
311
+ }
312
+ $year = (integer) $year;
313
+ $month = (integer) $month;
314
+ $day = (integer) $day;
315
+
316
+ $baseYear = PHPExcel_Shared_Date::getExcelCalendar();
317
+ // Validate parameters
318
+ if ($year < ($baseYear-1900)) {
319
+ return PHPExcel_Calculation_Functions::NaN();
320
+ }
321
+ if ((($baseYear-1900) != 0) && ($year < $baseYear) && ($year >= 1900)) {
322
+ return PHPExcel_Calculation_Functions::NaN();
323
+ }
324
+
325
+ if (($year < $baseYear) && ($year >= ($baseYear-1900))) {
326
+ $year += 1900;
327
+ }
328
+
329
+ if ($month < 1) {
330
+ // Handle year/month adjustment if month < 1
331
+ --$month;
332
+ $year += ceil($month / 12) - 1;
333
+ $month = 13 - abs($month % 12);
334
+ } elseif ($month > 12) {
335
+ // Handle year/month adjustment if month > 12
336
+ $year += floor($month / 12);
337
+ $month = ($month % 12);
338
+ }
339
+
340
+ // Re-validate the year parameter after adjustments
341
+ if (($year < $baseYear) || ($year >= 10000)) {
342
+ return PHPExcel_Calculation_Functions::NaN();
343
+ }
344
+
345
+ // Execute function
346
+ $excelDateValue = PHPExcel_Shared_Date::FormattedPHPToExcel($year, $month, $day);
347
+ switch (PHPExcel_Calculation_Functions::getReturnDateType()) {
348
+ case PHPExcel_Calculation_Functions::RETURNDATE_EXCEL:
349
+ return (float) $excelDateValue;
350
+ case PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC:
351
+ return (integer) PHPExcel_Shared_Date::ExcelToPHP($excelDateValue);
352
+ case PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT:
353
+ return PHPExcel_Shared_Date::ExcelToPHPObject($excelDateValue);
354
+ }
355
+ }
356
+
357
+
358
+ /**
359
+ * TIME
360
+ *
361
+ * The TIME function returns a value that represents a particular time.
362
+ *
363
+ * NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the time
364
+ * format of your regional settings. PHPExcel does not change cell formatting in this way.
365
+ *
366
+ * Excel Function:
367
+ * TIME(hour,minute,second)
368
+ *
369
+ * @access public
370
+ * @category Date/Time Functions
371
+ * @param integer $hour A number from 0 (zero) to 32767 representing the hour.
372
+ * Any value greater than 23 will be divided by 24 and the remainder
373
+ * will be treated as the hour value. For example, TIME(27,0,0) =
374
+ * TIME(3,0,0) = .125 or 3:00 AM.
375
+ * @param integer $minute A number from 0 to 32767 representing the minute.
376
+ * Any value greater than 59 will be converted to hours and minutes.
377
+ * For example, TIME(0,750,0) = TIME(12,30,0) = .520833 or 12:30 PM.
378
+ * @param integer $second A number from 0 to 32767 representing the second.
379
+ * Any value greater than 59 will be converted to hours, minutes,
380
+ * and seconds. For example, TIME(0,0,2000) = TIME(0,33,22) = .023148
381
+ * or 12:33:20 AM
382
+ * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
383
+ * depending on the value of the ReturnDateType flag
384
+ */
385
+ public static function TIME($hour = 0, $minute = 0, $second = 0)
386
+ {
387
+ $hour = PHPExcel_Calculation_Functions::flattenSingleValue($hour);
388
+ $minute = PHPExcel_Calculation_Functions::flattenSingleValue($minute);
389
+ $second = PHPExcel_Calculation_Functions::flattenSingleValue($second);
390
+
391
+ if ($hour == '') {
392
+ $hour = 0;
393
+ }
394
+ if ($minute == '') {
395
+ $minute = 0;
396
+ }
397
+ if ($second == '') {
398
+ $second = 0;
399
+ }
400
+
401
+ if ((!is_numeric($hour)) || (!is_numeric($minute)) || (!is_numeric($second))) {
402
+ return PHPExcel_Calculation_Functions::VALUE();
403
+ }
404
+ $hour = (integer) $hour;
405
+ $minute = (integer) $minute;
406
+ $second = (integer) $second;
407
+
408
+ if ($second < 0) {
409
+ $minute += floor($second / 60);
410
+ $second = 60 - abs($second % 60);
411
+ if ($second == 60) {
412
+ $second = 0;
413
+ }
414
+ } elseif ($second >= 60) {
415
+ $minute += floor($second / 60);
416
+ $second = $second % 60;
417
+ }
418
+ if ($minute < 0) {
419
+ $hour += floor($minute / 60);
420
+ $minute = 60 - abs($minute % 60);
421
+ if ($minute == 60) {
422
+ $minute = 0;
423
+ }
424
+ } elseif ($minute >= 60) {
425
+ $hour += floor($minute / 60);
426
+ $minute = $minute % 60;
427
+ }
428
+
429
+ if ($hour > 23) {
430
+ $hour = $hour % 24;
431
+ } elseif ($hour < 0) {
432
+ return PHPExcel_Calculation_Functions::NaN();
433
+ }
434
+
435
+ // Execute function
436
+ switch (PHPExcel_Calculation_Functions::getReturnDateType()) {
437
+ case PHPExcel_Calculation_Functions::RETURNDATE_EXCEL:
438
+ $date = 0;
439
+ $calendar = PHPExcel_Shared_Date::getExcelCalendar();
440
+ if ($calendar != PHPExcel_Shared_Date::CALENDAR_WINDOWS_1900) {
441
+ $date = 1;
442
+ }
443
+ return (float) PHPExcel_Shared_Date::FormattedPHPToExcel($calendar, 1, $date, $hour, $minute, $second);
444
+ case PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC:
445
+ return (integer) PHPExcel_Shared_Date::ExcelToPHP(PHPExcel_Shared_Date::FormattedPHPToExcel(1970, 1, 1, $hour, $minute, $second)); // -2147468400; // -2147472000 + 3600
446
+ case PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT:
447
+ $dayAdjust = 0;
448
+ if ($hour < 0) {
449
+ $dayAdjust = floor($hour / 24);
450
+ $hour = 24 - abs($hour % 24);
451
+ if ($hour == 24) {
452
+ $hour = 0;
453
+ }
454
+ } elseif ($hour >= 24) {
455
+ $dayAdjust = floor($hour / 24);
456
+ $hour = $hour % 24;
457
+ }
458
+ $phpDateObject = new DateTime('1900-01-01 '.$hour.':'.$minute.':'.$second);
459
+ if ($dayAdjust != 0) {
460
+ $phpDateObject->modify($dayAdjust.' days');
461
+ }
462
+ return $phpDateObject;
463
+ }
464
+ }
465
+
466
+
467
+ /**
468
+ * DATEVALUE
469
+ *
470
+ * Returns a value that represents a particular date.
471
+ * Use DATEVALUE to convert a date represented by a text string to an Excel or PHP date/time stamp
472
+ * value.
473
+ *
474
+ * NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the date
475
+ * format of your regional settings. PHPExcel does not change cell formatting in this way.
476
+ *
477
+ * Excel Function:
478
+ * DATEVALUE(dateValue)
479
+ *
480
+ * @access public
481
+ * @category Date/Time Functions
482
+ * @param string $dateValue Text that represents a date in a Microsoft Excel date format.
483
+ * For example, "1/30/2008" or "30-Jan-2008" are text strings within
484
+ * quotation marks that represent dates. Using the default date
485
+ * system in Excel for Windows, date_text must represent a date from
486
+ * January 1, 1900, to December 31, 9999. Using the default date
487
+ * system in Excel for the Macintosh, date_text must represent a date
488
+ * from January 1, 1904, to December 31, 9999. DATEVALUE returns the
489
+ * #VALUE! error value if date_text is out of this range.
490
+ * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
491
+ * depending on the value of the ReturnDateType flag
492
+ */
493
+ public static function DATEVALUE($dateValue = 1)
494
+ {
495
+ $dateValue = trim(PHPExcel_Calculation_Functions::flattenSingleValue($dateValue), '"');
496
+ // Strip any ordinals because they're allowed in Excel (English only)
497
+ $dateValue = preg_replace('/(\d)(st|nd|rd|th)([ -\/])/Ui', '$1$3', $dateValue);
498
+ // Convert separators (/ . or space) to hyphens (should also handle dot used for ordinals in some countries, e.g. Denmark, Germany)
499
+ $dateValue = str_replace(array('/', '.', '-', ' '), array(' ', ' ', ' ', ' '), $dateValue);
500
+
501
+ $yearFound = false;
502
+ $t1 = explode(' ', $dateValue);
503
+ foreach ($t1 as &$t) {
504
+ if ((is_numeric($t)) && ($t > 31)) {
505
+ if ($yearFound) {
506
+ return PHPExcel_Calculation_Functions::VALUE();
507
+ } else {
508
+ if ($t < 100) {
509
+ $t += 1900;
510
+ }
511
+ $yearFound = true;
512
+ }
513
+ }
514
+ }
515
+ if ((count($t1) == 1) && (strpos($t, ':') != false)) {
516
+ // We've been fed a time value without any date
517
+ return 0.0;
518
+ } elseif (count($t1) == 2) {
519
+ // We only have two parts of the date: either day/month or month/year
520
+ if ($yearFound) {
521
+ array_unshift($t1, 1);
522
+ } else {
523
+ array_push($t1, date('Y'));
524
+ }
525
+ }
526
+ unset($t);
527
+ $dateValue = implode(' ', $t1);
528
+
529
+ $PHPDateArray = date_parse($dateValue);
530
+ if (($PHPDateArray === false) || ($PHPDateArray['error_count'] > 0)) {
531
+ $testVal1 = strtok($dateValue, '- ');
532
+ if ($testVal1 !== false) {
533
+ $testVal2 = strtok('- ');
534
+ if ($testVal2 !== false) {
535
+ $testVal3 = strtok('- ');
536
+ if ($testVal3 === false) {
537
+ $testVal3 = strftime('%Y');
538
+ }
539
+ } else {
540
+ return PHPExcel_Calculation_Functions::VALUE();
541
+ }
542
+ } else {
543
+ return PHPExcel_Calculation_Functions::VALUE();
544
+ }
545
+ $PHPDateArray = date_parse($testVal1.'-'.$testVal2.'-'.$testVal3);
546
+ if (($PHPDateArray === false) || ($PHPDateArray['error_count'] > 0)) {
547
+ $PHPDateArray = date_parse($testVal2.'-'.$testVal1.'-'.$testVal3);
548
+ if (($PHPDateArray === false) || ($PHPDateArray['error_count'] > 0)) {
549
+ return PHPExcel_Calculation_Functions::VALUE();
550
+ }
551
+ }
552
+ }
553
+
554
+ if (($PHPDateArray !== false) && ($PHPDateArray['error_count'] == 0)) {
555
+ // Execute function
556
+ if ($PHPDateArray['year'] == '') {
557
+ $PHPDateArray['year'] = strftime('%Y');
558
+ }
559
+ if ($PHPDateArray['year'] < 1900) {
560
+ return PHPExcel_Calculation_Functions::VALUE();
561
+ }
562
+ if ($PHPDateArray['month'] == '') {
563
+ $PHPDateArray['month'] = strftime('%m');
564
+ }
565
+ if ($PHPDateArray['day'] == '') {
566
+ $PHPDateArray['day'] = strftime('%d');
567
+ }
568
+ $excelDateValue = floor(
569
+ PHPExcel_Shared_Date::FormattedPHPToExcel(
570
+ $PHPDateArray['year'],
571
+ $PHPDateArray['month'],
572
+ $PHPDateArray['day'],
573
+ $PHPDateArray['hour'],
574
+ $PHPDateArray['minute'],
575
+ $PHPDateArray['second']
576
+ )
577
+ );
578
+
579
+ switch (PHPExcel_Calculation_Functions::getReturnDateType()) {
580
+ case PHPExcel_Calculation_Functions::RETURNDATE_EXCEL:
581
+ return (float) $excelDateValue;
582
+ case PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC:
583
+ return (integer) PHPExcel_Shared_Date::ExcelToPHP($excelDateValue);
584
+ case PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT:
585
+ return new DateTime($PHPDateArray['year'].'-'.$PHPDateArray['month'].'-'.$PHPDateArray['day'].' 00:00:00');
586
+ }
587
+ }
588
+ return PHPExcel_Calculation_Functions::VALUE();
589
+ }
590
+
591
+
592
+ /**
593
+ * TIMEVALUE
594
+ *
595
+ * Returns a value that represents a particular time.
596
+ * Use TIMEVALUE to convert a time represented by a text string to an Excel or PHP date/time stamp
597
+ * value.
598
+ *
599
+ * NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the time
600
+ * format of your regional settings. PHPExcel does not change cell formatting in this way.
601
+ *
602
+ * Excel Function:
603
+ * TIMEVALUE(timeValue)
604
+ *
605
+ * @access public
606
+ * @category Date/Time Functions
607
+ * @param string $timeValue A text string that represents a time in any one of the Microsoft
608
+ * Excel time formats; for example, "6:45 PM" and "18:45" text strings
609
+ * within quotation marks that represent time.
610
+ * Date information in time_text is ignored.
611
+ * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
612
+ * depending on the value of the ReturnDateType flag
613
+ */
614
+ public static function TIMEVALUE($timeValue)
615
+ {
616
+ $timeValue = trim(PHPExcel_Calculation_Functions::flattenSingleValue($timeValue), '"');
617
+ $timeValue = str_replace(array('/', '.'), array('-', '-'), $timeValue);
618
+
619
+ $PHPDateArray = date_parse($timeValue);
620
+ if (($PHPDateArray !== false) && ($PHPDateArray['error_count'] == 0)) {
621
+ if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) {
622
+ $excelDateValue = PHPExcel_Shared_Date::FormattedPHPToExcel(
623
+ $PHPDateArray['year'],
624
+ $PHPDateArray['month'],
625
+ $PHPDateArray['day'],
626
+ $PHPDateArray['hour'],
627
+ $PHPDateArray['minute'],
628
+ $PHPDateArray['second']
629
+ );
630
+ } else {
631
+ $excelDateValue = PHPExcel_Shared_Date::FormattedPHPToExcel(1900, 1, 1, $PHPDateArray['hour'], $PHPDateArray['minute'], $PHPDateArray['second']) - 1;
632
+ }
633
+
634
+ switch (PHPExcel_Calculation_Functions::getReturnDateType()) {
635
+ case PHPExcel_Calculation_Functions::RETURNDATE_EXCEL:
636
+ return (float) $excelDateValue;
637
+ case PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC:
638
+ return (integer) $phpDateValue = PHPExcel_Shared_Date::ExcelToPHP($excelDateValue+25569) - 3600;
639
+ case PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT:
640
+ return new DateTime('1900-01-01 '.$PHPDateArray['hour'].':'.$PHPDateArray['minute'].':'.$PHPDateArray['second']);
641
+ }
642
+ }
643
+ return PHPExcel_Calculation_Functions::VALUE();
644
+ }
645
+
646
+
647
+ /**
648
+ * DATEDIF
649
+ *
650
+ * @param mixed $startDate Excel date serial value, PHP date/time stamp, PHP DateTime object
651
+ * or a standard date string
652
+ * @param mixed $endDate Excel date serial value, PHP date/time stamp, PHP DateTime object
653
+ * or a standard date string
654
+ * @param string $unit
655
+ * @return integer Interval between the dates
656
+ */
657
+ public static function DATEDIF($startDate = 0, $endDate = 0, $unit = 'D')
658
+ {
659
+ $startDate = PHPExcel_Calculation_Functions::flattenSingleValue($startDate);
660
+ $endDate = PHPExcel_Calculation_Functions::flattenSingleValue($endDate);
661
+ $unit = strtoupper(PHPExcel_Calculation_Functions::flattenSingleValue($unit));
662
+
663
+ if (is_string($startDate = self::getDateValue($startDate))) {
664
+ return PHPExcel_Calculation_Functions::VALUE();
665
+ }
666
+ if (is_string($endDate = self::getDateValue($endDate))) {
667
+ return PHPExcel_Calculation_Functions::VALUE();
668
+ }
669
+
670
+ // Validate parameters
671
+ if ($startDate >= $endDate) {
672
+ return PHPExcel_Calculation_Functions::NaN();
673
+ }
674
+
675
+ // Execute function
676
+ $difference = $endDate - $startDate;
677
+
678
+ $PHPStartDateObject = PHPExcel_Shared_Date::ExcelToPHPObject($startDate);
679
+ $startDays = $PHPStartDateObject->format('j');
680
+ $startMonths = $PHPStartDateObject->format('n');
681
+ $startYears = $PHPStartDateObject->format('Y');
682
+
683
+ $PHPEndDateObject = PHPExcel_Shared_Date::ExcelToPHPObject($endDate);
684
+ $endDays = $PHPEndDateObject->format('j');
685
+ $endMonths = $PHPEndDateObject->format('n');
686
+ $endYears = $PHPEndDateObject->format('Y');
687
+
688
+ $retVal = PHPExcel_Calculation_Functions::NaN();
689
+ switch ($unit) {
690
+ case 'D':
691
+ $retVal = intval($difference);
692
+ break;
693
+ case 'M':
694
+ $retVal = intval($endMonths - $startMonths) + (intval($endYears - $startYears) * 12);
695
+ // We're only interested in full months
696
+ if ($endDays < $startDays) {
697
+ --$retVal;
698
+ }
699
+ break;
700
+ case 'Y':
701
+ $retVal = intval($endYears - $startYears);
702
+ // We're only interested in full months
703
+ if ($endMonths < $startMonths) {
704
+ --$retVal;
705
+ } elseif (($endMonths == $startMonths) && ($endDays < $startDays)) {
706
+ --$retVal;
707
+ }
708
+ break;
709
+ case 'MD':
710
+ if ($endDays < $startDays) {
711
+ $retVal = $endDays;
712
+ $PHPEndDateObject->modify('-'.$endDays.' days');
713
+ $adjustDays = $PHPEndDateObject->format('j');
714
+ if ($adjustDays > $startDays) {
715
+ $retVal += ($adjustDays - $startDays);
716
+ }
717
+ } else {
718
+ $retVal = $endDays - $startDays;
719
+ }
720
+ break;
721
+ case 'YM':
722
+ $retVal = intval($endMonths - $startMonths);
723
+ if ($retVal < 0) {
724
+ $retVal += 12;
725
+ }
726
+ // We're only interested in full months
727
+ if ($endDays < $startDays) {
728
+ --$retVal;
729
+ }
730
+ break;
731
+ case 'YD':
732
+ $retVal = intval($difference);
733
+ if ($endYears > $startYears) {
734
+ while ($endYears > $startYears) {
735
+ $PHPEndDateObject->modify('-1 year');
736
+ $endYears = $PHPEndDateObject->format('Y');
737
+ }
738
+ $retVal = $PHPEndDateObject->format('z') - $PHPStartDateObject->format('z');
739
+ if ($retVal < 0) {
740
+ $retVal += 365;
741
+ }
742
+ }
743
+ break;
744
+ default:
745
+ $retVal = PHPExcel_Calculation_Functions::NaN();
746
+ }
747
+ return $retVal;
748
+ }
749
+
750
+
751
+ /**
752
+ * DAYS360
753
+ *
754
+ * Returns the number of days between two dates based on a 360-day year (twelve 30-day months),
755
+ * which is used in some accounting calculations. Use this function to help compute payments if
756
+ * your accounting system is based on twelve 30-day months.
757
+ *
758
+ * Excel Function:
759
+ * DAYS360(startDate,endDate[,method])
760
+ *
761
+ * @access public
762
+ * @category Date/Time Functions
763
+ * @param mixed $startDate Excel date serial value (float), PHP date timestamp (integer),
764
+ * PHP DateTime object, or a standard date string
765
+ * @param mixed $endDate Excel date serial value (float), PHP date timestamp (integer),
766
+ * PHP DateTime object, or a standard date string
767
+ * @param boolean $method US or European Method
768
+ * FALSE or omitted: U.S. (NASD) method. If the starting date is
769
+ * the last day of a month, it becomes equal to the 30th of the
770
+ * same month. If the ending date is the last day of a month and
771
+ * the starting date is earlier than the 30th of a month, the
772
+ * ending date becomes equal to the 1st of the next month;
773
+ * otherwise the ending date becomes equal to the 30th of the
774
+ * same month.
775
+ * TRUE: European method. Starting dates and ending dates that
776
+ * occur on the 31st of a month become equal to the 30th of the
777
+ * same month.
778
+ * @return integer Number of days between start date and end date
779
+ */
780
+ public static function DAYS360($startDate = 0, $endDate = 0, $method = false)
781
+ {
782
+ $startDate = PHPExcel_Calculation_Functions::flattenSingleValue($startDate);
783
+ $endDate = PHPExcel_Calculation_Functions::flattenSingleValue($endDate);
784
+
785
+ if (is_string($startDate = self::getDateValue($startDate))) {
786
+ return PHPExcel_Calculation_Functions::VALUE();
787
+ }
788
+ if (is_string($endDate = self::getDateValue($endDate))) {
789
+ return PHPExcel_Calculation_Functions::VALUE();
790
+ }
791
+
792
+ if (!is_bool($method)) {
793
+ return PHPExcel_Calculation_Functions::VALUE();
794
+ }
795
+
796
+ // Execute function
797
+ $PHPStartDateObject = PHPExcel_Shared_Date::ExcelToPHPObject($startDate);
798
+ $startDay = $PHPStartDateObject->format('j');
799
+ $startMonth = $PHPStartDateObject->format('n');
800
+ $startYear = $PHPStartDateObject->format('Y');
801
+
802
+ $PHPEndDateObject = PHPExcel_Shared_Date::ExcelToPHPObject($endDate);
803
+ $endDay = $PHPEndDateObject->format('j');
804
+ $endMonth = $PHPEndDateObject->format('n');
805
+ $endYear = $PHPEndDateObject->format('Y');
806
+
807
+ return self::dateDiff360($startDay, $startMonth, $startYear, $endDay, $endMonth, $endYear, !$method);
808
+ }
809
+
810
+
811
+ /**
812
+ * YEARFRAC
813
+ *
814
+ * Calculates the fraction of the year represented by the number of whole days between two dates
815
+ * (the start_date and the end_date).
816
+ * Use the YEARFRAC worksheet function to identify the proportion of a whole year's benefits or
817
+ * obligations to assign to a specific term.
818
+ *
819
+ * Excel Function:
820
+ * YEARFRAC(startDate,endDate[,method])
821
+ *
822
+ * @access public
823
+ * @category Date/Time Functions
824
+ * @param mixed $startDate Excel date serial value (float), PHP date timestamp (integer),
825
+ * PHP DateTime object, or a standard date string
826
+ * @param mixed $endDate Excel date serial value (float), PHP date timestamp (integer),
827
+ * PHP DateTime object, or a standard date string
828
+ * @param integer $method Method used for the calculation
829
+ * 0 or omitted US (NASD) 30/360
830
+ * 1 Actual/actual
831
+ * 2 Actual/360
832
+ * 3 Actual/365
833
+ * 4 European 30/360
834
+ * @return float fraction of the year
835
+ */
836
+ public static function YEARFRAC($startDate = 0, $endDate = 0, $method = 0)
837
+ {
838
+ $startDate = PHPExcel_Calculation_Functions::flattenSingleValue($startDate);
839
+ $endDate = PHPExcel_Calculation_Functions::flattenSingleValue($endDate);
840
+ $method = PHPExcel_Calculation_Functions::flattenSingleValue($method);
841
+
842
+ if (is_string($startDate = self::getDateValue($startDate))) {
843
+ return PHPExcel_Calculation_Functions::VALUE();
844
+ }
845
+ if (is_string($endDate = self::getDateValue($endDate))) {
846
+ return PHPExcel_Calculation_Functions::VALUE();
847
+ }
848
+
849
+ if (((is_numeric($method)) && (!is_string($method))) || ($method == '')) {
850
+ switch ($method) {
851
+ case 0:
852
+ return self::DAYS360($startDate, $endDate) / 360;
853
+ case 1:
854
+ $days = self::DATEDIF($startDate, $endDate);
855
+ $startYear = self::YEAR($startDate);
856
+ $endYear = self::YEAR($endDate);
857
+ $years = $endYear - $startYear + 1;
858
+ $leapDays = 0;
859
+ if ($years == 1) {
860
+ if (self::isLeapYear($endYear)) {
861
+ $startMonth = self::MONTHOFYEAR($startDate);
862
+ $endMonth = self::MONTHOFYEAR($endDate);
863
+ $endDay = self::DAYOFMONTH($endDate);
864
+ if (($startMonth < 3) ||
865
+ (($endMonth * 100 + $endDay) >= (2 * 100 + 29))) {
866
+ $leapDays += 1;
867
+ }
868
+ }
869
+ } else {
870
+ for ($year = $startYear; $year <= $endYear; ++$year) {
871
+ if ($year == $startYear) {
872
+ $startMonth = self::MONTHOFYEAR($startDate);
873
+ $startDay = self::DAYOFMONTH($startDate);
874
+ if ($startMonth < 3) {
875
+ $leapDays += (self::isLeapYear($year)) ? 1 : 0;
876
+ }
877
+ } elseif ($year == $endYear) {
878
+ $endMonth = self::MONTHOFYEAR($endDate);
879
+ $endDay = self::DAYOFMONTH($endDate);
880
+ if (($endMonth * 100 + $endDay) >= (2 * 100 + 29)) {
881
+ $leapDays += (self::isLeapYear($year)) ? 1 : 0;
882
+ }
883
+ } else {
884
+ $leapDays += (self::isLeapYear($year)) ? 1 : 0;
885
+ }
886
+ }
887
+ if ($years == 2) {
888
+ if (($leapDays == 0) && (self::isLeapYear($startYear)) && ($days > 365)) {
889
+ $leapDays = 1;
890
+ } elseif ($days < 366) {
891
+ $years = 1;
892
+ }
893
+ }
894
+ $leapDays /= $years;
895
+ }
896
+ return $days / (365 + $leapDays);
897
+ case 2:
898
+ return self::DATEDIF($startDate, $endDate) / 360;
899
+ case 3:
900
+ return self::DATEDIF($startDate, $endDate) / 365;
901
+ case 4:
902
+ return self::DAYS360($startDate, $endDate, true) / 360;
903
+ }
904
+ }
905
+ return PHPExcel_Calculation_Functions::VALUE();
906
+ }
907
+
908
+
909
+ /**
910
+ * NETWORKDAYS
911
+ *
912
+ * Returns the number of whole working days between start_date and end_date. Working days
913
+ * exclude weekends and any dates identified in holidays.
914
+ * Use NETWORKDAYS to calculate employee benefits that accrue based on the number of days
915
+ * worked during a specific term.
916
+ *
917
+ * Excel Function:
918
+ * NETWORKDAYS(startDate,endDate[,holidays[,holiday[,...]]])
919
+ *
920
+ * @access public
921
+ * @category Date/Time Functions
922
+ * @param mixed $startDate Excel date serial value (float), PHP date timestamp (integer),
923
+ * PHP DateTime object, or a standard date string
924
+ * @param mixed $endDate Excel date serial value (float), PHP date timestamp (integer),
925
+ * PHP DateTime object, or a standard date string
926
+ * @param mixed $holidays,... Optional series of Excel date serial value (float), PHP date
927
+ * timestamp (integer), PHP DateTime object, or a standard date
928
+ * strings that will be excluded from the working calendar, such
929
+ * as state and federal holidays and floating holidays.
930
+ * @return integer Interval between the dates
931
+ */
932
+ public static function NETWORKDAYS($startDate, $endDate)
933
+ {
934
+ // Retrieve the mandatory start and end date that are referenced in the function definition
935
+ $startDate = PHPExcel_Calculation_Functions::flattenSingleValue($startDate);
936
+ $endDate = PHPExcel_Calculation_Functions::flattenSingleValue($endDate);
937
+ // Flush the mandatory start and end date that are referenced in the function definition, and get the optional days
938
+ $dateArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args());
939
+ array_shift($dateArgs);
940
+ array_shift($dateArgs);
941
+
942
+ // Validate the start and end dates
943
+ if (is_string($startDate = $sDate = self::getDateValue($startDate))) {
944
+ return PHPExcel_Calculation_Functions::VALUE();
945
+ }
946
+ $startDate = (float) floor($startDate);
947
+ if (is_string($endDate = $eDate = self::getDateValue($endDate))) {
948
+ return PHPExcel_Calculation_Functions::VALUE();
949
+ }
950
+ $endDate = (float) floor($endDate);
951
+
952
+ if ($sDate > $eDate) {
953
+ $startDate = $eDate;
954
+ $endDate = $sDate;
955
+ }
956
+
957
+ // Execute function
958
+ $startDoW = 6 - self::DAYOFWEEK($startDate, 2);
959
+ if ($startDoW < 0) {
960
+ $startDoW = 0;
961
+ }
962
+ $endDoW = self::DAYOFWEEK($endDate, 2);
963
+ if ($endDoW >= 6) {
964
+ $endDoW = 0;
965
+ }
966
+
967
+ $wholeWeekDays = floor(($endDate - $startDate) / 7) * 5;
968
+ $partWeekDays = $endDoW + $startDoW;
969
+ if ($partWeekDays > 5) {
970
+ $partWeekDays -= 5;
971
+ }
972
+
973
+ // Test any extra holiday parameters
974
+ $holidayCountedArray = array();
975
+ foreach ($dateArgs as $holidayDate) {
976
+ if (is_string($holidayDate = self::getDateValue($holidayDate))) {
977
+ return PHPExcel_Calculation_Functions::VALUE();
978
+ }
979
+ if (($holidayDate >= $startDate) && ($holidayDate <= $endDate)) {
980
+ if ((self::DAYOFWEEK($holidayDate, 2) < 6) && (!in_array($holidayDate, $holidayCountedArray))) {
981
+ --$partWeekDays;
982
+ $holidayCountedArray[] = $holidayDate;
983
+ }
984
+ }
985
+ }
986
+
987
+ if ($sDate > $eDate) {
988
+ return 0 - ($wholeWeekDays + $partWeekDays);
989
+ }
990
+ return $wholeWeekDays + $partWeekDays;
991
+ }
992
+
993
+
994
+ /**
995
+ * WORKDAY
996
+ *
997
+ * Returns the date that is the indicated number of working days before or after a date (the
998
+ * starting date). Working days exclude weekends and any dates identified as holidays.
999
+ * Use WORKDAY to exclude weekends or holidays when you calculate invoice due dates, expected
1000
+ * delivery times, or the number of days of work performed.
1001
+ *
1002
+ * Excel Function:
1003
+ * WORKDAY(startDate,endDays[,holidays[,holiday[,...]]])
1004
+ *
1005
+ * @access public
1006
+ * @category Date/Time Functions
1007
+ * @param mixed $startDate Excel date serial value (float), PHP date timestamp (integer),
1008
+ * PHP DateTime object, or a standard date string
1009
+ * @param integer $endDays The number of nonweekend and nonholiday days before or after
1010
+ * startDate. A positive value for days yields a future date; a
1011
+ * negative value yields a past date.
1012
+ * @param mixed $holidays,... Optional series of Excel date serial value (float), PHP date
1013
+ * timestamp (integer), PHP DateTime object, or a standard date
1014
+ * strings that will be excluded from the working calendar, such
1015
+ * as state and federal holidays and floating holidays.
1016
+ * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
1017
+ * depending on the value of the ReturnDateType flag
1018
+ */
1019
+ public static function WORKDAY($startDate, $endDays)
1020
+ {
1021
+ // Retrieve the mandatory start date and days that are referenced in the function definition
1022
+ $startDate = PHPExcel_Calculation_Functions::flattenSingleValue($startDate);
1023
+ $endDays = PHPExcel_Calculation_Functions::flattenSingleValue($endDays);
1024
+ // Flush the mandatory start date and days that are referenced in the function definition, and get the optional days
1025
+ $dateArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args());
1026
+ array_shift($dateArgs);
1027
+ array_shift($dateArgs);
1028
+
1029
+ if ((is_string($startDate = self::getDateValue($startDate))) || (!is_numeric($endDays))) {
1030
+ return PHPExcel_Calculation_Functions::VALUE();
1031
+ }
1032
+ $startDate = (float) floor($startDate);
1033
+ $endDays = (int) floor($endDays);
1034
+ // If endDays is 0, we always return startDate
1035
+ if ($endDays == 0) {
1036
+ return $startDate;
1037
+ }
1038
+
1039
+ $decrementing = ($endDays < 0) ? true : false;
1040
+
1041
+ // Adjust the start date if it falls over a weekend
1042
+
1043
+ $startDoW = self::DAYOFWEEK($startDate, 3);
1044
+ if (self::DAYOFWEEK($startDate, 3) >= 5) {
1045
+ $startDate += ($decrementing) ? -$startDoW + 4: 7 - $startDoW;
1046
+ ($decrementing) ? $endDays++ : $endDays--;
1047
+ }
1048
+
1049
+ // Add endDays
1050
+ $endDate = (float) $startDate + (intval($endDays / 5) * 7) + ($endDays % 5);
1051
+
1052
+ // Adjust the calculated end date if it falls over a weekend
1053
+ $endDoW = self::DAYOFWEEK($endDate, 3);
1054
+ if ($endDoW >= 5) {
1055
+ $endDate += ($decrementing) ? -$endDoW + 4: 7 - $endDoW;
1056
+ }
1057
+
1058
+ // Test any extra holiday parameters
1059
+ if (!empty($dateArgs)) {
1060
+ $holidayCountedArray = $holidayDates = array();
1061
+ foreach ($dateArgs as $holidayDate) {
1062
+ if (($holidayDate !== null) && (trim($holidayDate) > '')) {
1063
+ if (is_string($holidayDate = self::getDateValue($holidayDate))) {
1064
+ return PHPExcel_Calculation_Functions::VALUE();
1065
+ }
1066
+ if (self::DAYOFWEEK($holidayDate, 3) < 5) {
1067
+ $holidayDates[] = $holidayDate;
1068
+ }
1069
+ }
1070
+ }
1071
+ if ($decrementing) {
1072
+ rsort($holidayDates, SORT_NUMERIC);
1073
+ } else {
1074
+ sort($holidayDates, SORT_NUMERIC);
1075
+ }
1076
+ foreach ($holidayDates as $holidayDate) {
1077
+ if ($decrementing) {
1078
+ if (($holidayDate <= $startDate) && ($holidayDate >= $endDate)) {
1079
+ if (!in_array($holidayDate, $holidayCountedArray)) {
1080
+ --$endDate;
1081
+ $holidayCountedArray[] = $holidayDate;
1082
+ }
1083
+ }
1084
+ } else {
1085
+ if (($holidayDate >= $startDate) && ($holidayDate <= $endDate)) {
1086
+ if (!in_array($holidayDate, $holidayCountedArray)) {
1087
+ ++$endDate;
1088
+ $holidayCountedArray[] = $holidayDate;
1089
+ }
1090
+ }
1091
+ }
1092
+ // Adjust the calculated end date if it falls over a weekend
1093
+ $endDoW = self::DAYOFWEEK($endDate, 3);
1094
+ if ($endDoW >= 5) {
1095
+ $endDate += ($decrementing) ? -$endDoW + 4 : 7 - $endDoW;
1096
+ }
1097
+ }
1098
+ }
1099
+
1100
+ switch (PHPExcel_Calculation_Functions::getReturnDateType()) {
1101
+ case PHPExcel_Calculation_Functions::RETURNDATE_EXCEL:
1102
+ return (float) $endDate;
1103
+ case PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC:
1104
+ return (integer) PHPExcel_Shared_Date::ExcelToPHP($endDate);
1105
+ case PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT:
1106
+ return PHPExcel_Shared_Date::ExcelToPHPObject($endDate);
1107
+ }
1108
+ }
1109
+
1110
+
1111
+ /**
1112
+ * DAYOFMONTH
1113
+ *
1114
+ * Returns the day of the month, for a specified date. The day is given as an integer
1115
+ * ranging from 1 to 31.
1116
+ *
1117
+ * Excel Function:
1118
+ * DAY(dateValue)
1119
+ *
1120
+ * @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer),
1121
+ * PHP DateTime object, or a standard date string
1122
+ * @return int Day of the month
1123
+ */
1124
+ public static function DAYOFMONTH($dateValue = 1)
1125
+ {
1126
+ $dateValue = PHPExcel_Calculation_Functions::flattenSingleValue($dateValue);
1127
+
1128
+ if ($dateValue === null) {
1129
+ $dateValue = 1;
1130
+ } elseif (is_string($dateValue = self::getDateValue($dateValue))) {
1131
+ return PHPExcel_Calculation_Functions::VALUE();
1132
+ } elseif ($dateValue == 0.0) {
1133
+ return 0;
1134
+ } elseif ($dateValue < 0.0) {
1135
+ return PHPExcel_Calculation_Functions::NaN();
1136
+ }
1137
+
1138
+ // Execute function
1139
+ $PHPDateObject = PHPExcel_Shared_Date::ExcelToPHPObject($dateValue);
1140
+
1141
+ return (int) $PHPDateObject->format('j');
1142
+ }
1143
+
1144
+
1145
+ /**
1146
+ * DAYOFWEEK
1147
+ *
1148
+ * Returns the day of the week for a specified date. The day is given as an integer
1149
+ * ranging from 0 to 7 (dependent on the requested style).
1150
+ *
1151
+ * Excel Function:
1152
+ * WEEKDAY(dateValue[,style])
1153
+ *
1154
+ * @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer),
1155
+ * PHP DateTime object, or a standard date string
1156
+ * @param int $style A number that determines the type of return value
1157
+ * 1 or omitted Numbers 1 (Sunday) through 7 (Saturday).
1158
+ * 2 Numbers 1 (Monday) through 7 (Sunday).
1159
+ * 3 Numbers 0 (Monday) through 6 (Sunday).
1160
+ * @return int Day of the week value
1161
+ */
1162
+ public static function DAYOFWEEK($dateValue = 1, $style = 1)
1163
+ {
1164
+ $dateValue = PHPExcel_Calculation_Functions::flattenSingleValue($dateValue);
1165
+ $style = PHPExcel_Calculation_Functions::flattenSingleValue($style);
1166
+
1167
+ if (!is_numeric($style)) {
1168
+ return PHPExcel_Calculation_Functions::VALUE();
1169
+ } elseif (($style < 1) || ($style > 3)) {
1170
+ return PHPExcel_Calculation_Functions::NaN();
1171
+ }
1172
+ $style = floor($style);
1173
+
1174
+ if ($dateValue === null) {
1175
+ $dateValue = 1;
1176
+ } elseif (is_string($dateValue = self::getDateValue($dateValue))) {
1177
+ return PHPExcel_Calculation_Functions::VALUE();
1178
+ } elseif ($dateValue < 0.0) {
1179
+ return PHPExcel_Calculation_Functions::NaN();
1180
+ }
1181
+
1182
+ // Execute function
1183
+ $PHPDateObject = PHPExcel_Shared_Date::ExcelToPHPObject($dateValue);
1184
+ $DoW = $PHPDateObject->format('w');
1185
+
1186
+ $firstDay = 1;
1187
+ switch ($style) {
1188
+ case 1:
1189
+ ++$DoW;
1190
+ break;
1191
+ case 2:
1192
+ if ($DoW == 0) {
1193
+ $DoW = 7;
1194
+ }
1195
+ break;
1196
+ case 3:
1197
+ if ($DoW == 0) {
1198
+ $DoW = 7;
1199
+ }
1200
+ $firstDay = 0;
1201
+ --$DoW;
1202
+ break;
1203
+ }
1204
+ if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_EXCEL) {
1205
+ // Test for Excel's 1900 leap year, and introduce the error as required
1206
+ if (($PHPDateObject->format('Y') == 1900) && ($PHPDateObject->format('n') <= 2)) {
1207
+ --$DoW;
1208
+ if ($DoW < $firstDay) {
1209
+ $DoW += 7;
1210
+ }
1211
+ }
1212
+ }
1213
+
1214
+ return (int) $DoW;
1215
+ }
1216
+
1217
+
1218
+ /**
1219
+ * WEEKOFYEAR
1220
+ *
1221
+ * Returns the week of the year for a specified date.
1222
+ * The WEEKNUM function considers the week containing January 1 to be the first week of the year.
1223
+ * However, there is a European standard that defines the first week as the one with the majority
1224
+ * of days (four or more) falling in the new year. This means that for years in which there are
1225
+ * three days or less in the first week of January, the WEEKNUM function returns week numbers
1226
+ * that are incorrect according to the European standard.
1227
+ *
1228
+ * Excel Function:
1229
+ * WEEKNUM(dateValue[,style])
1230
+ *
1231
+ * @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer),
1232
+ * PHP DateTime object, or a standard date string
1233
+ * @param boolean $method Week begins on Sunday or Monday
1234
+ * 1 or omitted Week begins on Sunday.
1235
+ * 2 Week begins on Monday.
1236
+ * @return int Week Number
1237
+ */
1238
+ public static function WEEKOFYEAR($dateValue = 1, $method = 1)
1239
+ {
1240
+ $dateValue = PHPExcel_Calculation_Functions::flattenSingleValue($dateValue);
1241
+ $method = PHPExcel_Calculation_Functions::flattenSingleValue($method);
1242
+
1243
+ if (!is_numeric($method)) {
1244
+ return PHPExcel_Calculation_Functions::VALUE();
1245
+ } elseif (($method < 1) || ($method > 2)) {
1246
+ return PHPExcel_Calculation_Functions::NaN();
1247
+ }
1248
+ $method = floor($method);
1249
+
1250
+ if ($dateValue === null) {
1251
+ $dateValue = 1;
1252
+ } elseif (is_string($dateValue = self::getDateValue($dateValue))) {
1253
+ return PHPExcel_Calculation_Functions::VALUE();
1254
+ } elseif ($dateValue < 0.0) {
1255
+ return PHPExcel_Calculation_Functions::NaN();
1256
+ }
1257
+
1258
+ // Execute function
1259
+ $PHPDateObject = PHPExcel_Shared_Date::ExcelToPHPObject($dateValue);
1260
+ $dayOfYear = $PHPDateObject->format('z');
1261
+ $dow = $PHPDateObject->format('w');
1262
+ $PHPDateObject->modify('-' . $dayOfYear . ' days');
1263
+ $dow = $PHPDateObject->format('w');
1264
+ $daysInFirstWeek = 7 - (($dow + (2 - $method)) % 7);
1265
+ $dayOfYear -= $daysInFirstWeek;
1266
+ $weekOfYear = ceil($dayOfYear / 7) + 1;
1267
+
1268
+ return (int) $weekOfYear;
1269
+ }
1270
+
1271
+
1272
+ /**
1273
+ * MONTHOFYEAR
1274
+ *
1275
+ * Returns the month of a date represented by a serial number.
1276
+ * The month is given as an integer, ranging from 1 (January) to 12 (December).
1277
+ *
1278
+ * Excel Function:
1279
+ * MONTH(dateValue)
1280
+ *
1281
+ * @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer),
1282
+ * PHP DateTime object, or a standard date string
1283
+ * @return int Month of the year
1284
+ */
1285
+ public static function MONTHOFYEAR($dateValue = 1)
1286
+ {
1287
+ $dateValue = PHPExcel_Calculation_Functions::flattenSingleValue($dateValue);
1288
+
1289
+ if ($dateValue === null) {
1290
+ $dateValue = 1;
1291
+ } elseif (is_string($dateValue = self::getDateValue($dateValue))) {
1292
+ return PHPExcel_Calculation_Functions::VALUE();
1293
+ } elseif ($dateValue < 0.0) {
1294
+ return PHPExcel_Calculation_Functions::NaN();
1295
+ }
1296
+
1297
+ // Execute function
1298
+ $PHPDateObject = PHPExcel_Shared_Date::ExcelToPHPObject($dateValue);
1299
+
1300
+ return (int) $PHPDateObject->format('n');
1301
+ }
1302
+
1303
+
1304
+ /**
1305
+ * YEAR
1306
+ *
1307
+ * Returns the year corresponding to a date.
1308
+ * The year is returned as an integer in the range 1900-9999.
1309
+ *
1310
+ * Excel Function:
1311
+ * YEAR(dateValue)
1312
+ *
1313
+ * @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer),
1314
+ * PHP DateTime object, or a standard date string
1315
+ * @return int Year
1316
+ */
1317
+ public static function YEAR($dateValue = 1)
1318
+ {
1319
+ $dateValue = PHPExcel_Calculation_Functions::flattenSingleValue($dateValue);
1320
+
1321
+ if ($dateValue === null) {
1322
+ $dateValue = 1;
1323
+ } elseif (is_string($dateValue = self::getDateValue($dateValue))) {
1324
+ return PHPExcel_Calculation_Functions::VALUE();
1325
+ } elseif ($dateValue < 0.0) {
1326
+ return PHPExcel_Calculation_Functions::NaN();
1327
+ }
1328
+
1329
+ // Execute function
1330
+ $PHPDateObject = PHPExcel_Shared_Date::ExcelToPHPObject($dateValue);
1331
+
1332
+ return (int) $PHPDateObject->format('Y');
1333
+ }
1334
+
1335
+
1336
+ /**
1337
+ * HOUROFDAY
1338
+ *
1339
+ * Returns the hour of a time value.
1340
+ * The hour is given as an integer, ranging from 0 (12:00 A.M.) to 23 (11:00 P.M.).
1341
+ *
1342
+ * Excel Function:
1343
+ * HOUR(timeValue)
1344
+ *
1345
+ * @param mixed $timeValue Excel date serial value (float), PHP date timestamp (integer),
1346
+ * PHP DateTime object, or a standard time string
1347
+ * @return int Hour
1348
+ */
1349
+ public static function HOUROFDAY($timeValue = 0)
1350
+ {
1351
+ $timeValue = PHPExcel_Calculation_Functions::flattenSingleValue($timeValue);
1352
+
1353
+ if (!is_numeric($timeValue)) {
1354
+ if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC) {
1355
+ $testVal = strtok($timeValue, '/-: ');
1356
+ if (strlen($testVal) < strlen($timeValue)) {
1357
+ return PHPExcel_Calculation_Functions::VALUE();
1358
+ }
1359
+ }
1360
+ $timeValue = self::getTimeValue($timeValue);
1361
+ if (is_string($timeValue)) {
1362
+ return PHPExcel_Calculation_Functions::VALUE();
1363
+ }
1364
+ }
1365
+ // Execute function
1366
+ if ($timeValue >= 1) {
1367
+ $timeValue = fmod($timeValue, 1);
1368
+ } elseif ($timeValue < 0.0) {
1369
+ return PHPExcel_Calculation_Functions::NaN();
1370
+ }
1371
+ $timeValue = PHPExcel_Shared_Date::ExcelToPHP($timeValue);
1372
+
1373
+ return (int) gmdate('G', $timeValue);
1374
+ }
1375
+
1376
+
1377
+ /**
1378
+ * MINUTEOFHOUR
1379
+ *
1380
+ * Returns the minutes of a time value.
1381
+ * The minute is given as an integer, ranging from 0 to 59.
1382
+ *
1383
+ * Excel Function:
1384
+ * MINUTE(timeValue)
1385
+ *
1386
+ * @param mixed $timeValue Excel date serial value (float), PHP date timestamp (integer),
1387
+ * PHP DateTime object, or a standard time string
1388
+ * @return int Minute
1389
+ */
1390
+ public static function MINUTEOFHOUR($timeValue = 0)
1391
+ {
1392
+ $timeValue = $timeTester = PHPExcel_Calculation_Functions::flattenSingleValue($timeValue);
1393
+
1394
+ if (!is_numeric($timeValue)) {
1395
+ if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC) {
1396
+ $testVal = strtok($timeValue, '/-: ');
1397
+ if (strlen($testVal) < strlen($timeValue)) {
1398
+ return PHPExcel_Calculation_Functions::VALUE();
1399
+ }
1400
+ }
1401
+ $timeValue = self::getTimeValue($timeValue);
1402
+ if (is_string($timeValue)) {
1403
+ return PHPExcel_Calculation_Functions::VALUE();
1404
+ }
1405
+ }
1406
+ // Execute function
1407
+ if ($timeValue >= 1) {
1408
+ $timeValue = fmod($timeValue, 1);
1409
+ } elseif ($timeValue < 0.0) {
1410
+ return PHPExcel_Calculation_Functions::NaN();
1411
+ }
1412
+ $timeValue = PHPExcel_Shared_Date::ExcelToPHP($timeValue);
1413
+
1414
+ return (int) gmdate('i', $timeValue);
1415
+ }
1416
+
1417
+
1418
+ /**
1419
+ * SECONDOFMINUTE
1420
+ *
1421
+ * Returns the seconds of a time value.
1422
+ * The second is given as an integer in the range 0 (zero) to 59.
1423
+ *
1424
+ * Excel Function:
1425
+ * SECOND(timeValue)
1426
+ *
1427
+ * @param mixed $timeValue Excel date serial value (float), PHP date timestamp (integer),
1428
+ * PHP DateTime object, or a standard time string
1429
+ * @return int Second
1430
+ */
1431
+ public static function SECONDOFMINUTE($timeValue = 0)
1432
+ {
1433
+ $timeValue = PHPExcel_Calculation_Functions::flattenSingleValue($timeValue);
1434
+
1435
+ if (!is_numeric($timeValue)) {
1436
+ if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC) {
1437
+ $testVal = strtok($timeValue, '/-: ');
1438
+ if (strlen($testVal) < strlen($timeValue)) {
1439
+ return PHPExcel_Calculation_Functions::VALUE();
1440
+ }
1441
+ }
1442
+ $timeValue = self::getTimeValue($timeValue);
1443
+ if (is_string($timeValue)) {
1444
+ return PHPExcel_Calculation_Functions::VALUE();
1445
+ }
1446
+ }
1447
+ // Execute function
1448
+ if ($timeValue >= 1) {
1449
+ $timeValue = fmod($timeValue, 1);
1450
+ } elseif ($timeValue < 0.0) {
1451
+ return PHPExcel_Calculation_Functions::NaN();
1452
+ }
1453
+ $timeValue = PHPExcel_Shared_Date::ExcelToPHP($timeValue);
1454
+
1455
+ return (int) gmdate('s', $timeValue);
1456
+ }
1457
+
1458
+
1459
+ /**
1460
+ * EDATE
1461
+ *
1462
+ * Returns the serial number that represents the date that is the indicated number of months
1463
+ * before or after a specified date (the start_date).
1464
+ * Use EDATE to calculate maturity dates or due dates that fall on the same day of the month
1465
+ * as the date of issue.
1466
+ *
1467
+ * Excel Function:
1468
+ * EDATE(dateValue,adjustmentMonths)
1469
+ *
1470
+ * @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer),
1471
+ * PHP DateTime object, or a standard date string
1472
+ * @param int $adjustmentMonths The number of months before or after start_date.
1473
+ * A positive value for months yields a future date;
1474
+ * a negative value yields a past date.
1475
+ * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
1476
+ * depending on the value of the ReturnDateType flag
1477
+ */
1478
+ public static function EDATE($dateValue = 1, $adjustmentMonths = 0)
1479
+ {
1480
+ $dateValue = PHPExcel_Calculation_Functions::flattenSingleValue($dateValue);
1481
+ $adjustmentMonths = PHPExcel_Calculation_Functions::flattenSingleValue($adjustmentMonths);
1482
+
1483
+ if (!is_numeric($adjustmentMonths)) {
1484
+ return PHPExcel_Calculation_Functions::VALUE();
1485
+ }
1486
+ $adjustmentMonths = floor($adjustmentMonths);
1487
+
1488
+ if (is_string($dateValue = self::getDateValue($dateValue))) {
1489
+ return PHPExcel_Calculation_Functions::VALUE();
1490
+ }
1491
+
1492
+ // Execute function
1493
+ $PHPDateObject = self::adjustDateByMonths($dateValue, $adjustmentMonths);
1494
+
1495
+ switch (PHPExcel_Calculation_Functions::getReturnDateType()) {
1496
+ case PHPExcel_Calculation_Functions::RETURNDATE_EXCEL:
1497
+ return (float) PHPExcel_Shared_Date::PHPToExcel($PHPDateObject);
1498
+ case PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC:
1499
+ return (integer) PHPExcel_Shared_Date::ExcelToPHP(PHPExcel_Shared_Date::PHPToExcel($PHPDateObject));
1500
+ case PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT:
1501
+ return $PHPDateObject;
1502
+ }
1503
+ }
1504
+
1505
+
1506
+ /**
1507
+ * EOMONTH
1508
+ *
1509
+ * Returns the date value for the last day of the month that is the indicated number of months
1510
+ * before or after start_date.
1511
+ * Use EOMONTH to calculate maturity dates or due dates that fall on the last day of the month.
1512
+ *
1513
+ * Excel Function:
1514
+ * EOMONTH(dateValue,adjustmentMonths)
1515
+ *
1516
+ * @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer),
1517
+ * PHP DateTime object, or a standard date string
1518
+ * @param int $adjustmentMonths The number of months before or after start_date.
1519
+ * A positive value for months yields a future date;
1520
+ * a negative value yields a past date.
1521
+ * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
1522
+ * depending on the value of the ReturnDateType flag
1523
+ */
1524
+ public static function EOMONTH($dateValue = 1, $adjustmentMonths = 0)
1525
+ {
1526
+ $dateValue = PHPExcel_Calculation_Functions::flattenSingleValue($dateValue);
1527
+ $adjustmentMonths = PHPExcel_Calculation_Functions::flattenSingleValue($adjustmentMonths);
1528
+
1529
+ if (!is_numeric($adjustmentMonths)) {
1530
+ return PHPExcel_Calculation_Functions::VALUE();
1531
+ }
1532
+ $adjustmentMonths = floor($adjustmentMonths);
1533
+
1534
+ if (is_string($dateValue = self::getDateValue($dateValue))) {
1535
+ return PHPExcel_Calculation_Functions::VALUE();
1536
+ }
1537
+
1538
+ // Execute function
1539
+ $PHPDateObject = self::adjustDateByMonths($dateValue, $adjustmentMonths+1);
1540
+ $adjustDays = (int) $PHPDateObject->format('d');
1541
+ $adjustDaysString = '-' . $adjustDays . ' days';
1542
+ $PHPDateObject->modify($adjustDaysString);
1543
+
1544
+ switch (PHPExcel_Calculation_Functions::getReturnDateType()) {
1545
+ case PHPExcel_Calculation_Functions::RETURNDATE_EXCEL:
1546
+ return (float) PHPExcel_Shared_Date::PHPToExcel($PHPDateObject);
1547
+ case PHPExcel_Calculation_Functions::RETURNDATE_PHP_NUMERIC:
1548
+ return (integer) PHPExcel_Shared_Date::ExcelToPHP(PHPExcel_Shared_Date::PHPToExcel($PHPDateObject));
1549
+ case PHPExcel_Calculation_Functions::RETURNDATE_PHP_OBJECT:
1550
+ return $PHPDateObject;
1551
+ }
1552
+ }
1553
+ }
PHPExcel/Classes/PHPExcel/Calculation/Engineering.php CHANGED
@@ -1,2505 +1,2650 @@
1
- <?php
2
- /**
3
- * PHPExcel
4
- *
5
- * Copyright (c) 2006 - 2014 PHPExcel
6
- *
7
- * This library is free software; you can redistribute it and/or
8
- * modify it under the terms of the GNU Lesser General Public
9
- * License as published by the Free Software Foundation; either
10
- * version 2.1 of the License, or (at your option) any later version.
11
- *
12
- * This library is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
- * Lesser General Public License for more details.
16
- *
17
- * You should have received a copy of the GNU Lesser General Public
18
- * License along with this library; if not, write to the Free Software
19
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
- *
21
- * @category PHPExcel
22
- * @package PHPExcel_Calculation
23
- * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
24
- * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25
- * @version 1.8.0, 2014-03-02
26
- */
27
-
28
-
29
- /** PHPExcel root directory */
30
- if (!defined('PHPEXCEL_ROOT')) {
31
- /**
32
- * @ignore
33
- */
34
- define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
35
- require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
36
- }
37
-
38
-
39
- /** EULER */
40
- define('EULER', 2.71828182845904523536);
41
-
42
-
43
- /**
44
- * PHPExcel_Calculation_Engineering
45
- *
46
- * @category PHPExcel
47
- * @package PHPExcel_Calculation
48
- * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
49
- */
50
- class PHPExcel_Calculation_Engineering {
51
-
52
- /**
53
- * Details of the Units of measure that can be used in CONVERTUOM()
54
- *
55
- * @var mixed[]
56
- */
57
- private static $_conversionUnits = array( 'g' => array( 'Group' => 'Mass', 'Unit Name' => 'Gram', 'AllowPrefix' => True ),
58
- 'sg' => array( 'Group' => 'Mass', 'Unit Name' => 'Slug', 'AllowPrefix' => False ),
59
- 'lbm' => array( 'Group' => 'Mass', 'Unit Name' => 'Pound mass (avoirdupois)', 'AllowPrefix' => False ),
60
- 'u' => array( 'Group' => 'Mass', 'Unit Name' => 'U (atomic mass unit)', 'AllowPrefix' => True ),
61
- 'ozm' => array( 'Group' => 'Mass', 'Unit Name' => 'Ounce mass (avoirdupois)', 'AllowPrefix' => False ),
62
- 'm' => array( 'Group' => 'Distance', 'Unit Name' => 'Meter', 'AllowPrefix' => True ),
63
- 'mi' => array( 'Group' => 'Distance', 'Unit Name' => 'Statute mile', 'AllowPrefix' => False ),
64
- 'Nmi' => array( 'Group' => 'Distance', 'Unit Name' => 'Nautical mile', 'AllowPrefix' => False ),
65
- 'in' => array( 'Group' => 'Distance', 'Unit Name' => 'Inch', 'AllowPrefix' => False ),
66
- 'ft' => array( 'Group' => 'Distance', 'Unit Name' => 'Foot', 'AllowPrefix' => False ),
67
- 'yd' => array( 'Group' => 'Distance', 'Unit Name' => 'Yard', 'AllowPrefix' => False ),
68
- 'ang' => array( 'Group' => 'Distance', 'Unit Name' => 'Angstrom', 'AllowPrefix' => True ),
69
- 'Pica' => array( 'Group' => 'Distance', 'Unit Name' => 'Pica (1/72 in)', 'AllowPrefix' => False ),
70
- 'yr' => array( 'Group' => 'Time', 'Unit Name' => 'Year', 'AllowPrefix' => False ),
71
- 'day' => array( 'Group' => 'Time', 'Unit Name' => 'Day', 'AllowPrefix' => False ),
72
- 'hr' => array( 'Group' => 'Time', 'Unit Name' => 'Hour', 'AllowPrefix' => False ),
73
- 'mn' => array( 'Group' => 'Time', 'Unit Name' => 'Minute', 'AllowPrefix' => False ),
74
- 'sec' => array( 'Group' => 'Time', 'Unit Name' => 'Second', 'AllowPrefix' => True ),
75
- 'Pa' => array( 'Group' => 'Pressure', 'Unit Name' => 'Pascal', 'AllowPrefix' => True ),
76
- 'p' => array( 'Group' => 'Pressure', 'Unit Name' => 'Pascal', 'AllowPrefix' => True ),
77
- 'atm' => array( 'Group' => 'Pressure', 'Unit Name' => 'Atmosphere', 'AllowPrefix' => True ),
78
- 'at' => array( 'Group' => 'Pressure', 'Unit Name' => 'Atmosphere', 'AllowPrefix' => True ),
79
- 'mmHg' => array( 'Group' => 'Pressure', 'Unit Name' => 'mm of Mercury', 'AllowPrefix' => True ),
80
- 'N' => array( 'Group' => 'Force', 'Unit Name' => 'Newton', 'AllowPrefix' => True ),
81
- 'dyn' => array( 'Group' => 'Force', 'Unit Name' => 'Dyne', 'AllowPrefix' => True ),
82
- 'dy' => array( 'Group' => 'Force', 'Unit Name' => 'Dyne', 'AllowPrefix' => True ),
83
- 'lbf' => array( 'Group' => 'Force', 'Unit Name' => 'Pound force', 'AllowPrefix' => False ),
84
- 'J' => array( 'Group' => 'Energy', 'Unit Name' => 'Joule', 'AllowPrefix' => True ),
85
- 'e' => array( 'Group' => 'Energy', 'Unit Name' => 'Erg', 'AllowPrefix' => True ),
86
- 'c' => array( 'Group' => 'Energy', 'Unit Name' => 'Thermodynamic calorie', 'AllowPrefix' => True ),
87
- 'cal' => array( 'Group' => 'Energy', 'Unit Name' => 'IT calorie', 'AllowPrefix' => True ),
88
- 'eV' => array( 'Group' => 'Energy', 'Unit Name' => 'Electron volt', 'AllowPrefix' => True ),
89
- 'ev' => array( 'Group' => 'Energy', 'Unit Name' => 'Electron volt', 'AllowPrefix' => True ),
90
- 'HPh' => array( 'Group' => 'Energy', 'Unit Name' => 'Horsepower-hour', 'AllowPrefix' => False ),
91
- 'hh' => array( 'Group' => 'Energy', 'Unit Name' => 'Horsepower-hour', 'AllowPrefix' => False ),
92
- 'Wh' => array( 'Group' => 'Energy', 'Unit Name' => 'Watt-hour', 'AllowPrefix' => True ),
93
- 'wh' => array( 'Group' => 'Energy', 'Unit Name' => 'Watt-hour', 'AllowPrefix' => True ),
94
- 'flb' => array( 'Group' => 'Energy', 'Unit Name' => 'Foot-pound', 'AllowPrefix' => False ),
95
- 'BTU' => array( 'Group' => 'Energy', 'Unit Name' => 'BTU', 'AllowPrefix' => False ),
96
- 'btu' => array( 'Group' => 'Energy', 'Unit Name' => 'BTU', 'AllowPrefix' => False ),
97
- 'HP' => array( 'Group' => 'Power', 'Unit Name' => 'Horsepower', 'AllowPrefix' => False ),
98
- 'h' => array( 'Group' => 'Power', 'Unit Name' => 'Horsepower', 'AllowPrefix' => False ),
99
- 'W' => array( 'Group' => 'Power', 'Unit Name' => 'Watt', 'AllowPrefix' => True ),
100
- 'w' => array( 'Group' => 'Power', 'Unit Name' => 'Watt', 'AllowPrefix' => True ),
101
- 'T' => array( 'Group' => 'Magnetism', 'Unit Name' => 'Tesla', 'AllowPrefix' => True ),
102
- 'ga' => array( 'Group' => 'Magnetism', 'Unit Name' => 'Gauss', 'AllowPrefix' => True ),
103
- 'C' => array( 'Group' => 'Temperature', 'Unit Name' => 'Celsius', 'AllowPrefix' => False ),
104
- 'cel' => array( 'Group' => 'Temperature', 'Unit Name' => 'Celsius', 'AllowPrefix' => False ),
105
- 'F' => array( 'Group' => 'Temperature', 'Unit Name' => 'Fahrenheit', 'AllowPrefix' => False ),
106
- 'fah' => array( 'Group' => 'Temperature', 'Unit Name' => 'Fahrenheit', 'AllowPrefix' => False ),
107
- 'K' => array( 'Group' => 'Temperature', 'Unit Name' => 'Kelvin', 'AllowPrefix' => False ),
108
- 'kel' => array( 'Group' => 'Temperature', 'Unit Name' => 'Kelvin', 'AllowPrefix' => False ),
109
- 'tsp' => array( 'Group' => 'Liquid', 'Unit Name' => 'Teaspoon', 'AllowPrefix' => False ),
110
- 'tbs' => array( 'Group' => 'Liquid', 'Unit Name' => 'Tablespoon', 'AllowPrefix' => False ),
111
- 'oz' => array( 'Group' => 'Liquid', 'Unit Name' => 'Fluid Ounce', 'AllowPrefix' => False ),
112
- 'cup' => array( 'Group' => 'Liquid', 'Unit Name' => 'Cup', 'AllowPrefix' => False ),
113
- 'pt' => array( 'Group' => 'Liquid', 'Unit Name' => 'U.S. Pint', 'AllowPrefix' => False ),
114
- 'us_pt' => array( 'Group' => 'Liquid', 'Unit Name' => 'U.S. Pint', 'AllowPrefix' => False ),
115
- 'uk_pt' => array( 'Group' => 'Liquid', 'Unit Name' => 'U.K. Pint', 'AllowPrefix' => False ),
116
- 'qt' => array( 'Group' => 'Liquid', 'Unit Name' => 'Quart', 'AllowPrefix' => False ),
117
- 'gal' => array( 'Group' => 'Liquid', 'Unit Name' => 'Gallon', 'AllowPrefix' => False ),
118
- 'l' => array( 'Group' => 'Liquid', 'Unit Name' => 'Litre', 'AllowPrefix' => True ),
119
- 'lt' => array( 'Group' => 'Liquid', 'Unit Name' => 'Litre', 'AllowPrefix' => True )
120
- );
121
-
122
- /**
123
- * Details of the Multiplier prefixes that can be used with Units of Measure in CONVERTUOM()
124
- *
125
- * @var mixed[]
126
- */
127
- private static $_conversionMultipliers = array( 'Y' => array( 'multiplier' => 1E24, 'name' => 'yotta' ),
128
- 'Z' => array( 'multiplier' => 1E21, 'name' => 'zetta' ),
129
- 'E' => array( 'multiplier' => 1E18, 'name' => 'exa' ),
130
- 'P' => array( 'multiplier' => 1E15, 'name' => 'peta' ),
131
- 'T' => array( 'multiplier' => 1E12, 'name' => 'tera' ),
132
- 'G' => array( 'multiplier' => 1E9, 'name' => 'giga' ),
133
- 'M' => array( 'multiplier' => 1E6, 'name' => 'mega' ),
134
- 'k' => array( 'multiplier' => 1E3, 'name' => 'kilo' ),
135
- 'h' => array( 'multiplier' => 1E2, 'name' => 'hecto' ),
136
- 'e' => array( 'multiplier' => 1E1, 'name' => 'deka' ),
137
- 'd' => array( 'multiplier' => 1E-1, 'name' => 'deci' ),
138
- 'c' => array( 'multiplier' => 1E-2, 'name' => 'centi' ),
139
- 'm' => array( 'multiplier' => 1E-3, 'name' => 'milli' ),
140
- 'u' => array( 'multiplier' => 1E-6, 'name' => 'micro' ),
141
- 'n' => array( 'multiplier' => 1E-9, 'name' => 'nano' ),
142
- 'p' => array( 'multiplier' => 1E-12, 'name' => 'pico' ),
143
- 'f' => array( 'multiplier' => 1E-15, 'name' => 'femto' ),
144
- 'a' => array( 'multiplier' => 1E-18, 'name' => 'atto' ),
145
- 'z' => array( 'multiplier' => 1E-21, 'name' => 'zepto' ),
146
- 'y' => array( 'multiplier' => 1E-24, 'name' => 'yocto' )
147
- );
148
-
149
- /**
150
- * Details of the Units of measure conversion factors, organised by group
151
- *
152
- * @var mixed[]
153
- */
154
- private static $_unitConversions = array( 'Mass' => array( 'g' => array( 'g' => 1.0,
155
- 'sg' => 6.85220500053478E-05,
156
- 'lbm' => 2.20462291469134E-03,
157
- 'u' => 6.02217000000000E+23,
158
- 'ozm' => 3.52739718003627E-02
159
- ),
160
- 'sg' => array( 'g' => 1.45938424189287E+04,
161
- 'sg' => 1.0,
162
- 'lbm' => 3.21739194101647E+01,
163
- 'u' => 8.78866000000000E+27,
164
- 'ozm' => 5.14782785944229E+02
165
- ),
166
- 'lbm' => array( 'g' => 4.5359230974881148E+02,
167
- 'sg' => 3.10810749306493E-02,
168
- 'lbm' => 1.0,
169
- 'u' => 2.73161000000000E+26,
170
- 'ozm' => 1.60000023429410E+01
171
- ),
172
- 'u' => array( 'g' => 1.66053100460465E-24,
173
- 'sg' => 1.13782988532950E-28,
174
- 'lbm' => 3.66084470330684E-27,
175
- 'u' => 1.0,
176
- 'ozm' => 5.85735238300524E-26
177
- ),
178
- 'ozm' => array( 'g' => 2.83495152079732E+01,
179
- 'sg' => 1.94256689870811E-03,
180
- 'lbm' => 6.24999908478882E-02,
181
- 'u' => 1.70725600000000E+25,
182
- 'ozm' => 1.0
183
- )
184
- ),
185
- 'Distance' => array( 'm' => array( 'm' => 1.0,
186
- 'mi' => 6.21371192237334E-04,
187
- 'Nmi' => 5.39956803455724E-04,
188
- 'in' => 3.93700787401575E+01,
189
- 'ft' => 3.28083989501312E+00,
190
- 'yd' => 1.09361329797891E+00,
191
- 'ang' => 1.00000000000000E+10,
192
- 'Pica' => 2.83464566929116E+03
193
- ),
194
- 'mi' => array( 'm' => 1.60934400000000E+03,
195
- 'mi' => 1.0,
196
- 'Nmi' => 8.68976241900648E-01,
197
- 'in' => 6.33600000000000E+04,
198
- 'ft' => 5.28000000000000E+03,
199
- 'yd' => 1.76000000000000E+03,
200
- 'ang' => 1.60934400000000E+13,
201
- 'Pica' => 4.56191999999971E+06
202
- ),
203
- 'Nmi' => array( 'm' => 1.85200000000000E+03,
204
- 'mi' => 1.15077944802354E+00,
205
- 'Nmi' => 1.0,
206
- 'in' => 7.29133858267717E+04,
207
- 'ft' => 6.07611548556430E+03,
208
- 'yd' => 2.02537182785694E+03,
209
- 'ang' => 1.85200000000000E+13,
210
- 'Pica' => 5.24976377952723E+06
211
- ),
212
- 'in' => array( 'm' => 2.54000000000000E-02,
213
- 'mi' => 1.57828282828283E-05,
214
- 'Nmi' => 1.37149028077754E-05,
215
- 'in' => 1.0,
216
- 'ft' => 8.33333333333333E-02,
217
- 'yd' => 2.77777777686643E-02,
218
- 'ang' => 2.54000000000000E+08,
219
- 'Pica' => 7.19999999999955E+01
220
- ),
221
- 'ft' => array( 'm' => 3.04800000000000E-01,
222
- 'mi' => 1.89393939393939E-04,
223
- 'Nmi' => 1.64578833693305E-04,
224
- 'in' => 1.20000000000000E+01,
225
- 'ft' => 1.0,
226
- 'yd' => 3.33333333223972E-01,
227
- 'ang' => 3.04800000000000E+09,
228
- 'Pica' => 8.63999999999946E+02
229
- ),
230
- 'yd' => array( 'm' => 9.14400000300000E-01,
231
- 'mi' => 5.68181818368230E-04,
232
- 'Nmi' => 4.93736501241901E-04,
233
- 'in' => 3.60000000118110E+01,
234
- 'ft' => 3.00000000000000E+00,
235
- 'yd' => 1.0,
236
- 'ang' => 9.14400000300000E+09,
237
- 'Pica' => 2.59200000085023E+03
238
- ),
239
- 'ang' => array( 'm' => 1.00000000000000E-10,
240
- 'mi' => 6.21371192237334E-14,
241
- 'Nmi' => 5.39956803455724E-14,
242
- 'in' => 3.93700787401575E-09,
243
- 'ft' => 3.28083989501312E-10,
244
- 'yd' => 1.09361329797891E-10,
245
- 'ang' => 1.0,
246
- 'Pica' => 2.83464566929116E-07
247
- ),
248
- 'Pica' => array( 'm' => 3.52777777777800E-04,
249
- 'mi' => 2.19205948372629E-07,
250
- 'Nmi' => 1.90484761219114E-07,
251
- 'in' => 1.38888888888898E-02,
252
- 'ft' => 1.15740740740748E-03,
253
- 'yd' => 3.85802469009251E-04,
254
- 'ang' => 3.52777777777800E+06,
255
- 'Pica' => 1.0
256
- )
257
- ),
258
- 'Time' => array( 'yr' => array( 'yr' => 1.0,
259
- 'day' => 365.25,
260
- 'hr' => 8766.0,
261
- 'mn' => 525960.0,
262
- 'sec' => 31557600.0
263
- ),
264
- 'day' => array( 'yr' => 2.73785078713210E-03,
265
- 'day' => 1.0,
266
- 'hr' => 24.0,
267
- 'mn' => 1440.0,
268
- 'sec' => 86400.0
269
- ),
270
- 'hr' => array( 'yr' => 1.14077116130504E-04,
271
- 'day' => 4.16666666666667E-02,
272
- 'hr' => 1.0,
273
- 'mn' => 60.0,
274
- 'sec' => 3600.0
275
- ),
276
- 'mn' => array( 'yr' => 1.90128526884174E-06,
277
- 'day' => 6.94444444444444E-04,
278
- 'hr' => 1.66666666666667E-02,
279
- 'mn' => 1.0,
280
- 'sec' => 60.0
281
- ),
282
- 'sec' => array( 'yr' => 3.16880878140289E-08,
283
- 'day' => 1.15740740740741E-05,
284
- 'hr' => 2.77777777777778E-04,
285
- 'mn' => 1.66666666666667E-02,
286
- 'sec' => 1.0
287
- )
288
- ),
289
- 'Pressure' => array( 'Pa' => array( 'Pa' => 1.0,
290
- 'p' => 1.0,
291
- 'atm' => 9.86923299998193E-06,
292
- 'at' => 9.86923299998193E-06,
293
- 'mmHg' => 7.50061707998627E-03
294
- ),
295
- 'p' => array( 'Pa' => 1.0,
296
- 'p' => 1.0,
297
- 'atm' => 9.86923299998193E-06,
298
- 'at' => 9.86923299998193E-06,
299
- 'mmHg' => 7.50061707998627E-03
300
- ),
301
- 'atm' => array( 'Pa' => 1.01324996583000E+05,
302
- 'p' => 1.01324996583000E+05,
303
- 'atm' => 1.0,
304
- 'at' => 1.0,
305
- 'mmHg' => 760.0
306
- ),
307
- 'at' => array( 'Pa' => 1.01324996583000E+05,
308
- 'p' => 1.01324996583000E+05,
309
- 'atm' => 1.0,
310
- 'at' => 1.0,
311
- 'mmHg' => 760.0
312
- ),
313
- 'mmHg' => array( 'Pa' => 1.33322363925000E+02,
314
- 'p' => 1.33322363925000E+02,
315
- 'atm' => 1.31578947368421E-03,
316
- 'at' => 1.31578947368421E-03,
317
- 'mmHg' => 1.0
318
- )
319
- ),
320
- 'Force' => array( 'N' => array( 'N' => 1.0,
321
- 'dyn' => 1.0E+5,
322
- 'dy' => 1.0E+5,
323
- 'lbf' => 2.24808923655339E-01
324
- ),
325
- 'dyn' => array( 'N' => 1.0E-5,
326
- 'dyn' => 1.0,
327
- 'dy' => 1.0,
328
- 'lbf' => 2.24808923655339E-06
329
- ),
330
- 'dy' => array( 'N' => 1.0E-5,
331
- 'dyn' => 1.0,
332
- 'dy' => 1.0,
333
- 'lbf' => 2.24808923655339E-06
334
- ),
335
- 'lbf' => array( 'N' => 4.448222,
336
- 'dyn' => 4.448222E+5,
337
- 'dy' => 4.448222E+5,
338
- 'lbf' => 1.0
339
- )
340
- ),
341
- 'Energy' => array( 'J' => array( 'J' => 1.0,
342
- 'e' => 9.99999519343231E+06,
343
- 'c' => 2.39006249473467E-01,
344
- 'cal' => 2.38846190642017E-01,
345
- 'eV' => 6.24145700000000E+18,
346
- 'ev' => 6.24145700000000E+18,
347
- 'HPh' => 3.72506430801000E-07,
348
- 'hh' => 3.72506430801000E-07,
349
- 'Wh' => 2.77777916238711E-04,
350
- 'wh' => 2.77777916238711E-04,
351
- 'flb' => 2.37304222192651E+01,
352
- 'BTU' => 9.47815067349015E-04,
353
- 'btu' => 9.47815067349015E-04
354
- ),
355
- 'e' => array( 'J' => 1.00000048065700E-07,
356
- 'e' => 1.0,
357
- 'c' => 2.39006364353494E-08,
358
- 'cal' => 2.38846305445111E-08,
359
- 'eV' => 6.24146000000000E+11,
360
- 'ev' => 6.24146000000000E+11,
361
- 'HPh' => 3.72506609848824E-14,
362
- 'hh' => 3.72506609848824E-14,
363
- 'Wh' => 2.77778049754611E-11,
364
- 'wh' => 2.77778049754611E-11,
365
- 'flb' => 2.37304336254586E-06,
366
- 'BTU' => 9.47815522922962E-11,
367
- 'btu' => 9.47815522922962E-11
368
- ),
369
- 'c' => array( 'J' => 4.18399101363672E+00,
370
- 'e' => 4.18398900257312E+07,
371
- 'c' => 1.0,
372
- 'cal' => 9.99330315287563E-01,
373
- 'eV' => 2.61142000000000E+19,
374
- 'ev' => 2.61142000000000E+19,
375
- 'HPh' => 1.55856355899327E-06,
376
- 'hh' => 1.55856355899327E-06,
377
- 'Wh' => 1.16222030532950E-03,
378
- 'wh' => 1.16222030532950E-03,
379
- 'flb' => 9.92878733152102E+01,
380
- 'BTU' => 3.96564972437776E-03,
381
- 'btu' => 3.96564972437776E-03
382
- ),
383
- 'cal' => array( 'J' => 4.18679484613929E+00,
384
- 'e' => 4.18679283372801E+07,
385
- 'c' => 1.00067013349059E+00,
386
- 'cal' => 1.0,
387
- 'eV' => 2.61317000000000E+19,
388
- 'ev' => 2.61317000000000E+19,
389
- 'HPh' => 1.55960800463137E-06,
390
- 'hh' => 1.55960800463137E-06,
391
- 'Wh' => 1.16299914807955E-03,
392
- 'wh' => 1.16299914807955E-03,
393
- 'flb' => 9.93544094443283E+01,
394
- 'BTU' => 3.96830723907002E-03,
395
- 'btu' => 3.96830723907002E-03
396
- ),
397
- 'eV' => array( 'J' => 1.60219000146921E-19,
398
- 'e' => 1.60218923136574E-12,
399
- 'c' => 3.82933423195043E-20,
400
- 'cal' => 3.82676978535648E-20,
401
- 'eV' => 1.0,
402
- 'ev' => 1.0,
403
- 'HPh' => 5.96826078912344E-26,
404
- 'hh' => 5.96826078912344E-26,
405
- 'Wh' => 4.45053000026614E-23,
406
- 'wh' => 4.45053000026614E-23,
407
- 'flb' => 3.80206452103492E-18,
408
- 'BTU' => 1.51857982414846E-22,
409
- 'btu' => 1.51857982414846E-22
410
- ),
411
- 'ev' => array( 'J' => 1.60219000146921E-19,
412
- 'e' => 1.60218923136574E-12,
413
- 'c' => 3.82933423195043E-20,
414
- 'cal' => 3.82676978535648E-20,
415
- 'eV' => 1.0,
416
- 'ev' => 1.0,
417
- 'HPh' => 5.96826078912344E-26,
418
- 'hh' => 5.96826078912344E-26,
419
- 'Wh' => 4.45053000026614E-23,
420
- 'wh' => 4.45053000026614E-23,
421
- 'flb' => 3.80206452103492E-18,
422
- 'BTU' => 1.51857982414846E-22,
423
- 'btu' => 1.51857982414846E-22
424
- ),
425
- 'HPh' => array( 'J' => 2.68451741316170E+06,
426
- 'e' => 2.68451612283024E+13,
427
- 'c' => 6.41616438565991E+05,
428
- 'cal' => 6.41186757845835E+05,
429
- 'eV' => 1.67553000000000E+25,
430
- 'ev' => 1.67553000000000E+25,
431
- 'HPh' => 1.0,
432
- 'hh' => 1.0,
433
- 'Wh' => 7.45699653134593E+02,
434
- 'wh' => 7.45699653134593E+02,
435
- 'flb' => 6.37047316692964E+07,
436
- 'BTU' => 2.54442605275546E+03,
437
- 'btu' => 2.54442605275546E+03
438
- ),
439
- 'hh' => array( 'J' => 2.68451741316170E+06,
440
- 'e' => 2.68451612283024E+13,
441
- 'c' => 6.41616438565991E+05,
442
- 'cal' => 6.41186757845835E+05,
443
- 'eV' => 1.67553000000000E+25,
444
- 'ev' => 1.67553000000000E+25,
445
- 'HPh' => 1.0,
446
- 'hh' => 1.0,
447
- 'Wh' => 7.45699653134593E+02,
448
- 'wh' => 7.45699653134593E+02,
449
- 'flb' => 6.37047316692964E+07,
450
- 'BTU' => 2.54442605275546E+03,
451
- 'btu' => 2.54442605275546E+03
452
- ),
453
- 'Wh' => array( 'J' => 3.59999820554720E+03,
454
- 'e' => 3.59999647518369E+10,
455
- 'c' => 8.60422069219046E+02,
456
- 'cal' => 8.59845857713046E+02,
457
- 'eV' => 2.24692340000000E+22,
458
- 'ev' => 2.24692340000000E+22,
459
- 'HPh' => 1.34102248243839E-03,
460
- 'hh' => 1.34102248243839E-03,
461
- 'Wh' => 1.0,
462
- 'wh' => 1.0,
463
- 'flb' => 8.54294774062316E+04,
464
- 'BTU' => 3.41213254164705E+00,
465
- 'btu' => 3.41213254164705E+00
466
- ),
467
- 'wh' => array( 'J' => 3.59999820554720E+03,
468
- 'e' => 3.59999647518369E+10,
469
- 'c' => 8.60422069219046E+02,
470
- 'cal' => 8.59845857713046E+02,
471
- 'eV' => 2.24692340000000E+22,
472
- 'ev' => 2.24692340000000E+22,
473
- 'HPh' => 1.34102248243839E-03,
474
- 'hh' => 1.34102248243839E-03,
475
- 'Wh' => 1.0,
476
- 'wh' => 1.0,
477
- 'flb' => 8.54294774062316E+04,
478
- 'BTU' => 3.41213254164705E+00,
479
- 'btu' => 3.41213254164705E+00
480
- ),
481
- 'flb' => array( 'J' => 4.21400003236424E-02,
482
- 'e' => 4.21399800687660E+05,
483
- 'c' => 1.00717234301644E-02,
484
- 'cal' => 1.00649785509554E-02,
485
- 'eV' => 2.63015000000000E+17,
486
- 'ev' => 2.63015000000000E+17,
487
- 'HPh' => 1.56974211145130E-08,
488
- 'hh' => 1.56974211145130E-08,
489
- 'Wh' => 1.17055614802000E-05,
490
- 'wh' => 1.17055614802000E-05,
491
- 'flb' => 1.0,
492
- 'BTU' => 3.99409272448406E-05,
493
- 'btu' => 3.99409272448406E-05
494
- ),
495
- 'BTU' => array( 'J' => 1.05505813786749E+03,
496
- 'e' => 1.05505763074665E+10,
497
- 'c' => 2.52165488508168E+02,
498
- 'cal' => 2.51996617135510E+02,
499
- 'eV' => 6.58510000000000E+21,
500
- 'ev' => 6.58510000000000E+21,
501
- 'HPh' => 3.93015941224568E-04,
502
- 'hh' => 3.93015941224568E-04,
503
- 'Wh' => 2.93071851047526E-01,
504
- 'wh' => 2.93071851047526E-01,
505
- 'flb' => 2.50369750774671E+04,
506
- 'BTU' => 1.0,
507
- 'btu' => 1.0,
508
- ),
509
- 'btu' => array( 'J' => 1.05505813786749E+03,
510
- 'e' => 1.05505763074665E+10,
511
- 'c' => 2.52165488508168E+02,
512
- 'cal' => 2.51996617135510E+02,
513
- 'eV' => 6.58510000000000E+21,
514
- 'ev' => 6.58510000000000E+21,
515
- 'HPh' => 3.93015941224568E-04,
516
- 'hh' => 3.93015941224568E-04,
517
- 'Wh' => 2.93071851047526E-01,
518
- 'wh' => 2.93071851047526E-01,
519
- 'flb' => 2.50369750774671E+04,
520
- 'BTU' => 1.0,
521
- 'btu' => 1.0,
522
- )
523
- ),
524
- 'Power' => array( 'HP' => array( 'HP' => 1.0,
525
- 'h' => 1.0,
526
- 'W' => 7.45701000000000E+02,
527
- 'w' => 7.45701000000000E+02
528
- ),
529
- 'h' => array( 'HP' => 1.0,
530
- 'h' => 1.0,
531
- 'W' => 7.45701000000000E+02,
532
- 'w' => 7.45701000000000E+02
533
- ),
534
- 'W' => array( 'HP' => 1.34102006031908E-03,
535
- 'h' => 1.34102006031908E-03,
536
- 'W' => 1.0,
537
- 'w' => 1.0
538
- ),
539
- 'w' => array( 'HP' => 1.34102006031908E-03,
540
- 'h' => 1.34102006031908E-03,
541
- 'W' => 1.0,
542
- 'w' => 1.0
543
- )
544
- ),
545
- 'Magnetism' => array( 'T' => array( 'T' => 1.0,
546
- 'ga' => 10000.0
547
- ),
548
- 'ga' => array( 'T' => 0.0001,
549
- 'ga' => 1.0
550
- )
551
- ),
552
- 'Liquid' => array( 'tsp' => array( 'tsp' => 1.0,
553
- 'tbs' => 3.33333333333333E-01,
554
- 'oz' => 1.66666666666667E-01,
555
- 'cup' => 2.08333333333333E-02,
556
- 'pt' => 1.04166666666667E-02,
557
- 'us_pt' => 1.04166666666667E-02,
558
- 'uk_pt' => 8.67558516821960E-03,
559
- 'qt' => 5.20833333333333E-03,
560
- 'gal' => 1.30208333333333E-03,
561
- 'l' => 4.92999408400710E-03,
562
- 'lt' => 4.92999408400710E-03
563
- ),
564
- 'tbs' => array( 'tsp' => 3.00000000000000E+00,
565
- 'tbs' => 1.0,
566
- 'oz' => 5.00000000000000E-01,
567
- 'cup' => 6.25000000000000E-02,
568
- 'pt' => 3.12500000000000E-02,
569
- 'us_pt' => 3.12500000000000E-02,
570
- 'uk_pt' => 2.60267555046588E-02,
571
- 'qt' => 1.56250000000000E-02,
572
- 'gal' => 3.90625000000000E-03,
573
- 'l' => 1.47899822520213E-02,
574
- 'lt' => 1.47899822520213E-02
575
- ),
576
- 'oz' => array( 'tsp' => 6.00000000000000E+00,
577
- 'tbs' => 2.00000000000000E+00,
578
- 'oz' => 1.0,
579
- 'cup' => 1.25000000000000E-01,
580
- 'pt' => 6.25000000000000E-02,
581
- 'us_pt' => 6.25000000000000E-02,
582
- 'uk_pt' => 5.20535110093176E-02,
583
- 'qt' => 3.12500000000000E-02,
584
- 'gal' => 7.81250000000000E-03,
585
- 'l' => 2.95799645040426E-02,
586
- 'lt' => 2.95799645040426E-02
587
- ),
588
- 'cup' => array( 'tsp' => 4.80000000000000E+01,
589
- 'tbs' => 1.60000000000000E+01,
590
- 'oz' => 8.00000000000000E+00,
591
- 'cup' => 1.0,
592
- 'pt' => 5.00000000000000E-01,
593
- 'us_pt' => 5.00000000000000E-01,
594
- 'uk_pt' => 4.16428088074541E-01,
595
- 'qt' => 2.50000000000000E-01,
596
- 'gal' => 6.25000000000000E-02,
597
- 'l' => 2.36639716032341E-01,
598
- 'lt' => 2.36639716032341E-01
599
- ),
600
- 'pt' => array( 'tsp' => 9.60000000000000E+01,
601
- 'tbs' => 3.20000000000000E+01,
602
- 'oz' => 1.60000000000000E+01,
603
- 'cup' => 2.00000000000000E+00,
604
- 'pt' => 1.0,
605
- 'us_pt' => 1.0,
606
- 'uk_pt' => 8.32856176149081E-01,
607
- 'qt' => 5.00000000000000E-01,
608
- 'gal' => 1.25000000000000E-01,
609
- 'l' => 4.73279432064682E-01,
610
- 'lt' => 4.73279432064682E-01
611
- ),
612
- 'us_pt' => array( 'tsp' => 9.60000000000000E+01,
613
- 'tbs' => 3.20000000000000E+01,
614
- 'oz' => 1.60000000000000E+01,
615
- 'cup' => 2.00000000000000E+00,
616
- 'pt' => 1.0,
617
- 'us_pt' => 1.0,
618
- 'uk_pt' => 8.32856176149081E-01,
619
- 'qt' => 5.00000000000000E-01,
620
- 'gal' => 1.25000000000000E-01,
621
- 'l' => 4.73279432064682E-01,
622
- 'lt' => 4.73279432064682E-01
623
- ),
624
- 'uk_pt' => array( 'tsp' => 1.15266000000000E+02,
625
- 'tbs' => 3.84220000000000E+01,
626
- 'oz' => 1.92110000000000E+01,
627
- 'cup' => 2.40137500000000E+00,
628
- 'pt' => 1.20068750000000E+00,
629
- 'us_pt' => 1.20068750000000E+00,
630
- 'uk_pt' => 1.0,
631
- 'qt' => 6.00343750000000E-01,
632
- 'gal' => 1.50085937500000E-01,
633
- 'l' => 5.68260698087162E-01,
634
- 'lt' => 5.68260698087162E-01
635
- ),
636
- 'qt' => array( 'tsp' => 1.92000000000000E+02,
637
- 'tbs' => 6.40000000000000E+01,
638
- 'oz' => 3.20000000000000E+01,
639
- 'cup' => 4.00000000000000E+00,
640
- 'pt' => 2.00000000000000E+00,
641
- 'us_pt' => 2.00000000000000E+00,
642
- 'uk_pt' => 1.66571235229816E+00,
643
- 'qt' => 1.0,
644
- 'gal' => 2.50000000000000E-01,
645
- 'l' => 9.46558864129363E-01,
646
- 'lt' => 9.46558864129363E-01
647
- ),
648
- 'gal' => array( 'tsp' => 7.68000000000000E+02,
649
- 'tbs' => 2.56000000000000E+02,
650
- 'oz' => 1.28000000000000E+02,
651
- 'cup' => 1.60000000000000E+01,
652
- 'pt' => 8.00000000000000E+00,
653
- 'us_pt' => 8.00000000000000E+00,
654
- 'uk_pt' => 6.66284940919265E+00,
655
- 'qt' => 4.00000000000000E+00,
656
- 'gal' => 1.0,
657
- 'l' => 3.78623545651745E+00,
658
- 'lt' => 3.78623545651745E+00
659
- ),
660
- 'l' => array( 'tsp' => 2.02840000000000E+02,
661
- 'tbs' => 6.76133333333333E+01,
662
- 'oz' => 3.38066666666667E+01,
663
- 'cup' => 4.22583333333333E+00,
664
- 'pt' => 2.11291666666667E+00,
665
- 'us_pt' => 2.11291666666667E+00,
666
- 'uk_pt' => 1.75975569552166E+00,
667
- 'qt' => 1.05645833333333E+00,
668
- 'gal' => 2.64114583333333E-01,
669
- 'l' => 1.0,
670
- 'lt' => 1.0
671
- ),
672
- 'lt' => array( 'tsp' => 2.02840000000000E+02,
673
- 'tbs' => 6.76133333333333E+01,
674
- 'oz' => 3.38066666666667E+01,
675
- 'cup' => 4.22583333333333E+00,
676
- 'pt' => 2.11291666666667E+00,
677
- 'us_pt' => 2.11291666666667E+00,
678
- 'uk_pt' => 1.75975569552166E+00,
679
- 'qt' => 1.05645833333333E+00,
680
- 'gal' => 2.64114583333333E-01,
681
- 'l' => 1.0,
682
- 'lt' => 1.0
683
- )
684
- )
685
- );
686
-
687
-
688
- /**
689
- * _parseComplex
690
- *
691
- * Parses a complex number into its real and imaginary parts, and an I or J suffix
692
- *
693
- * @param string $complexNumber The complex number
694
- * @return string[] Indexed on "real", "imaginary" and "suffix"
695
- */
696
- public static function _parseComplex($complexNumber) {
697
- $workString = (string) $complexNumber;
698
-
699
- $realNumber = $imaginary = 0;
700
- // Extract the suffix, if there is one
701
- $suffix = substr($workString,-1);
702
- if (!is_numeric($suffix)) {
703
- $workString = substr($workString,0,-1);
704
- } else {
705
- $suffix = '';
706
- }
707
-
708
- // Split the input into its Real and Imaginary components
709
- $leadingSign = 0;
710
- if (strlen($workString) > 0) {
711
- $leadingSign = (($workString{0} == '+') || ($workString{0} == '-')) ? 1 : 0;
712
- }
713
- $power = '';
714
- $realNumber = strtok($workString, '+-');
715
- if (strtoupper(substr($realNumber,-1)) == 'E') {
716
- $power = strtok('+-');
717
- ++$leadingSign;
718
- }
719
-
720
- $realNumber = substr($workString,0,strlen($realNumber)+strlen($power)+$leadingSign);
721
-
722
- if ($suffix != '') {
723
- $imaginary = substr($workString,strlen($realNumber));
724
-
725
- if (($imaginary == '') && (($realNumber == '') || ($realNumber == '+') || ($realNumber == '-'))) {
726
- $imaginary = $realNumber.'1';
727
- $realNumber = '0';
728
- } else if ($imaginary == '') {
729
- $imaginary = $realNumber;
730
- $realNumber = '0';
731
- } elseif (($imaginary == '+') || ($imaginary == '-')) {
732
- $imaginary .= '1';
733
- }
734
- }
735
-
736
- return array( 'real' => $realNumber,
737
- 'imaginary' => $imaginary,
738
- 'suffix' => $suffix
739
- );
740
- } // function _parseComplex()
741
-
742
-
743
- /**
744
- * Cleans the leading characters in a complex number string
745
- *
746
- * @param string $complexNumber The complex number to clean
747
- * @return string The "cleaned" complex number
748
- */
749
- private static function _cleanComplex($complexNumber) {
750
- if ($complexNumber{0} == '+') $complexNumber = substr($complexNumber,1);
751
- if ($complexNumber{0} == '0') $complexNumber = substr($complexNumber,1);
752
- if ($complexNumber{0} == '.') $complexNumber = '0'.$complexNumber;
753
- if ($complexNumber{0} == '+') $complexNumber = substr($complexNumber,1);
754
- return $complexNumber;
755
- }
756
-
757
- /**
758
- * Formats a number base string value with leading zeroes
759
- *
760
- * @param string $xVal The "number" to pad
761
- * @param integer $places The length that we want to pad this value
762
- * @return string The padded "number"
763
- */
764
- private static function _nbrConversionFormat($xVal, $places) {
765
- if (!is_null($places)) {
766
- if (strlen($xVal) <= $places) {
767
- return substr(str_pad($xVal, $places, '0', STR_PAD_LEFT), -10);
768
- } else {
769
- return PHPExcel_Calculation_Functions::NaN();
770
- }
771
- }
772
-
773
- return substr($xVal, -10);
774
- } // function _nbrConversionFormat()
775
-
776
- /**
777
- * BESSELI
778
- *
779
- * Returns the modified Bessel function In(x), which is equivalent to the Bessel function evaluated
780
- * for purely imaginary arguments
781
- *
782
- * Excel Function:
783
- * BESSELI(x,ord)
784
- *
785
- * @access public
786
- * @category Engineering Functions
787
- * @param float $x The value at which to evaluate the function.
788
- * If x is nonnumeric, BESSELI returns the #VALUE! error value.
789
- * @param integer $ord The order of the Bessel function.
790
- * If ord is not an integer, it is truncated.
791
- * If $ord is nonnumeric, BESSELI returns the #VALUE! error value.
792
- * If $ord < 0, BESSELI returns the #NUM! error value.
793
- * @return float
794
- *
795
- */
796
- public static function BESSELI($x, $ord) {
797
- $x = (is_null($x)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($x);
798
- $ord = (is_null($ord)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($ord);
799
-
800
- if ((is_numeric($x)) && (is_numeric($ord))) {
801
- $ord = floor($ord);
802
- if ($ord < 0) {
803
- return PHPExcel_Calculation_Functions::NaN();
804
- }
805
-
806
- if (abs($x) <= 30) {
807
- $fResult = $fTerm = pow($x / 2, $ord) / PHPExcel_Calculation_MathTrig::FACT($ord);
808
- $ordK = 1;
809
- $fSqrX = ($x * $x) / 4;
810
- do {
811
- $fTerm *= $fSqrX;
812
- $fTerm /= ($ordK * ($ordK + $ord));
813
- $fResult += $fTerm;
814
- } while ((abs($fTerm) > 1e-12) && (++$ordK < 100));
815
- } else {
816
- $f_2_PI = 2 * M_PI;
817
-
818
- $fXAbs = abs($x);
819
- $fResult = exp($fXAbs) / sqrt($f_2_PI * $fXAbs);
820
- if (($ord & 1) && ($x < 0)) {
821
- $fResult = -$fResult;
822
- }
823
- }
824
- return (is_nan($fResult)) ? PHPExcel_Calculation_Functions::NaN() : $fResult;
825
- }
826
- return PHPExcel_Calculation_Functions::VALUE();
827
- } // function BESSELI()
828
-
829
-
830
- /**
831
- * BESSELJ
832
- *
833
- * Returns the Bessel function
834
- *
835
- * Excel Function:
836
- * BESSELJ(x,ord)
837
- *
838
- * @access public
839
- * @category Engineering Functions
840
- * @param float $x The value at which to evaluate the function.
841
- * If x is nonnumeric, BESSELJ returns the #VALUE! error value.
842
- * @param integer $ord The order of the Bessel function. If n is not an integer, it is truncated.
843
- * If $ord is nonnumeric, BESSELJ returns the #VALUE! error value.
844
- * If $ord < 0, BESSELJ returns the #NUM! error value.
845
- * @return float
846
- *
847
- */
848
- public static function BESSELJ($x, $ord) {
849
- $x = (is_null($x)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($x);
850
- $ord = (is_null($ord)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($ord);
851
-
852
- if ((is_numeric($x)) && (is_numeric($ord))) {
853
- $ord = floor($ord);
854
- if ($ord < 0) {
855
- return PHPExcel_Calculation_Functions::NaN();
856
- }
857
-
858
- $fResult = 0;
859
- if (abs($x) <= 30) {
860
- $fResult = $fTerm = pow($x / 2, $ord) / PHPExcel_Calculation_MathTrig::FACT($ord);
861
- $ordK = 1;
862
- $fSqrX = ($x * $x) / -4;
863
- do {
864
- $fTerm *= $fSqrX;
865
- $fTerm /= ($ordK * ($ordK + $ord));
866
- $fResult += $fTerm;
867
- } while ((abs($fTerm) > 1e-12) && (++$ordK < 100));
868
- } else {
869
- $f_PI_DIV_2 = M_PI / 2;
870
- $f_PI_DIV_4 = M_PI / 4;
871
-
872
- $fXAbs = abs($x);
873
- $fResult = sqrt(M_2DIVPI / $fXAbs) * cos($fXAbs - $ord * $f_PI_DIV_2 - $f_PI_DIV_4);
874
- if (($ord & 1) && ($x < 0)) {
875
- $fResult = -$fResult;
876
- }
877
- }
878
- return (is_nan($fResult)) ? PHPExcel_Calculation_Functions::NaN() : $fResult;
879
- }
880
- return PHPExcel_Calculation_Functions::VALUE();
881
- } // function BESSELJ()
882
-
883
-
884
- private static function _Besselk0($fNum) {
885
- if ($fNum <= 2) {
886
- $fNum2 = $fNum * 0.5;
887
- $y = ($fNum2 * $fNum2);
888
- $fRet = -log($fNum2) * self::BESSELI($fNum, 0) +
889
- (-0.57721566 + $y * (0.42278420 + $y * (0.23069756 + $y * (0.3488590e-1 + $y * (0.262698e-2 + $y *
890
- (0.10750e-3 + $y * 0.74e-5))))));
891
- } else {
892
- $y = 2 / $fNum;
893
- $fRet = exp(-$fNum) / sqrt($fNum) *
894
- (1.25331414 + $y * (-0.7832358e-1 + $y * (0.2189568e-1 + $y * (-0.1062446e-1 + $y *
895
- (0.587872e-2 + $y * (-0.251540e-2 + $y * 0.53208e-3))))));
896
- }
897
- return $fRet;
898
- } // function _Besselk0()
899
-
900
-
901
- private static function _Besselk1($fNum) {
902
- if ($fNum <= 2) {
903
- $fNum2 = $fNum * 0.5;
904
- $y = ($fNum2 * $fNum2);
905
- $fRet = log($fNum2) * self::BESSELI($fNum, 1) +
906
- (1 + $y * (0.15443144 + $y * (-0.67278579 + $y * (-0.18156897 + $y * (-0.1919402e-1 + $y *
907
- (-0.110404e-2 + $y * (-0.4686e-4))))))) / $fNum;
908
- } else {
909
- $y = 2 / $fNum;
910
- $fRet = exp(-$fNum) / sqrt($fNum) *
911
- (1.25331414 + $y * (0.23498619 + $y * (-0.3655620e-1 + $y * (0.1504268e-1 + $y * (-0.780353e-2 + $y *
912
- (0.325614e-2 + $y * (-0.68245e-3)))))));
913
- }
914
- return $fRet;
915
- } // function _Besselk1()
916
-
917
-
918
- /**
919
- * BESSELK
920
- *
921
- * Returns the modified Bessel function Kn(x), which is equivalent to the Bessel functions evaluated
922
- * for purely imaginary arguments.
923
- *
924
- * Excel Function:
925
- * BESSELK(x,ord)
926
- *
927
- * @access public
928
- * @category Engineering Functions
929
- * @param float $x The value at which to evaluate the function.
930
- * If x is nonnumeric, BESSELK returns the #VALUE! error value.
931
- * @param integer $ord The order of the Bessel function. If n is not an integer, it is truncated.
932
- * If $ord is nonnumeric, BESSELK returns the #VALUE! error value.
933
- * If $ord < 0, BESSELK returns the #NUM! error value.
934
- * @return float
935
- *
936
- */
937
- public static function BESSELK($x, $ord) {
938
- $x = (is_null($x)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($x);
939
- $ord = (is_null($ord)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($ord);
940
-
941
- if ((is_numeric($x)) && (is_numeric($ord))) {
942
- if (($ord < 0) || ($x == 0.0)) {
943
- return PHPExcel_Calculation_Functions::NaN();
944
- }
945
-
946
- switch(floor($ord)) {
947
- case 0 : return self::_Besselk0($x);
948
- break;
949
- case 1 : return self::_Besselk1($x);
950
- break;
951
- default : $fTox = 2 / $x;
952
- $fBkm = self::_Besselk0($x);
953
- $fBk = self::_Besselk1($x);
954
- for ($n = 1; $n < $ord; ++$n) {
955
- $fBkp = $fBkm + $n * $fTox * $fBk;
956
- $fBkm = $fBk;
957
- $fBk = $fBkp;
958
- }
959
- }
960
- return (is_nan($fBk)) ? PHPExcel_Calculation_Functions::NaN() : $fBk;
961
- }
962
- return PHPExcel_Calculation_Functions::VALUE();
963
- } // function BESSELK()
964
-
965
-
966
- private static function _Bessely0($fNum) {
967
- if ($fNum < 8.0) {
968
- $y = ($fNum * $fNum);
969
- $f1 = -2957821389.0 + $y * (7062834065.0 + $y * (-512359803.6 + $y * (10879881.29 + $y * (-86327.92757 + $y * 228.4622733))));
970
- $f2 = 40076544269.0 + $y * (745249964.8 + $y * (7189466.438 + $y * (47447.26470 + $y * (226.1030244 + $y))));
971
- $fRet = $f1 / $f2 + 0.636619772 * self::BESSELJ($fNum, 0) * log($fNum);
972
- } else {
973
- $z = 8.0 / $fNum;
974
- $y = ($z * $z);
975
- $xx = $fNum - 0.785398164;
976
- $f1 = 1 + $y * (-0.1098628627e-2 + $y * (0.2734510407e-4 + $y * (-0.2073370639e-5 + $y * 0.2093887211e-6)));
977
- $f2 = -0.1562499995e-1 + $y * (0.1430488765e-3 + $y * (-0.6911147651e-5 + $y * (0.7621095161e-6 + $y * (-0.934945152e-7))));
978
- $fRet = sqrt(0.636619772 / $fNum) * (sin($xx) * $f1 + $z * cos($xx) * $f2);
979
- }
980
- return $fRet;
981
- } // function _Bessely0()
982
-
983
-
984
- private static function _Bessely1($fNum) {
985
- if ($fNum < 8.0) {
986
- $y = ($fNum * $fNum);
987
- $f1 = $fNum * (-0.4900604943e13 + $y * (0.1275274390e13 + $y * (-0.5153438139e11 + $y * (0.7349264551e9 + $y *
988
- (-0.4237922726e7 + $y * 0.8511937935e4)))));
989
- $f2 = 0.2499580570e14 + $y * (0.4244419664e12 + $y * (0.3733650367e10 + $y * (0.2245904002e8 + $y *
990
- (0.1020426050e6 + $y * (0.3549632885e3 + $y)))));
991
- $fRet = $f1 / $f2 + 0.636619772 * ( self::BESSELJ($fNum, 1) * log($fNum) - 1 / $fNum);
992
- } else {
993
- $fRet = sqrt(0.636619772 / $fNum) * sin($fNum - 2.356194491);
994
- }
995
- return $fRet;
996
- } // function _Bessely1()
997
-
998
-
999
- /**
1000
- * BESSELY
1001
- *
1002
- * Returns the Bessel function, which is also called the Weber function or the Neumann function.
1003
- *
1004
- * Excel Function:
1005
- * BESSELY(x,ord)
1006
- *
1007
- * @access public
1008
- * @category Engineering Functions
1009
- * @param float $x The value at which to evaluate the function.
1010
- * If x is nonnumeric, BESSELK returns the #VALUE! error value.
1011
- * @param integer $ord The order of the Bessel function. If n is not an integer, it is truncated.
1012
- * If $ord is nonnumeric, BESSELK returns the #VALUE! error value.
1013
- * If $ord < 0, BESSELK returns the #NUM! error value.
1014
- *
1015
- * @return float
1016
- */
1017
- public static function BESSELY($x, $ord) {
1018
- $x = (is_null($x)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($x);
1019
- $ord = (is_null($ord)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($ord);
1020
-
1021
- if ((is_numeric($x)) && (is_numeric($ord))) {
1022
- if (($ord < 0) || ($x == 0.0)) {
1023
- return PHPExcel_Calculation_Functions::NaN();
1024
- }
1025
-
1026
- switch(floor($ord)) {
1027
- case 0 : return self::_Bessely0($x);
1028
- break;
1029
- case 1 : return self::_Bessely1($x);
1030
- break;
1031
- default: $fTox = 2 / $x;
1032
- $fBym = self::_Bessely0($x);
1033
- $fBy = self::_Bessely1($x);
1034
- for ($n = 1; $n < $ord; ++$n) {
1035
- $fByp = $n * $fTox * $fBy - $fBym;
1036
- $fBym = $fBy;
1037
- $fBy = $fByp;
1038
- }
1039
- }
1040
- return (is_nan($fBy)) ? PHPExcel_Calculation_Functions::NaN() : $fBy;
1041
- }
1042
- return PHPExcel_Calculation_Functions::VALUE();
1043
- } // function BESSELY()
1044
-
1045
-
1046
- /**
1047
- * BINTODEC
1048
- *
1049
- * Return a binary value as decimal.
1050
- *
1051
- * Excel Function:
1052
- * BIN2DEC(x)
1053
- *
1054
- * @access public
1055
- * @category Engineering Functions
1056
- * @param string $x The binary number (as a string) that you want to convert. The number
1057
- * cannot contain more than 10 characters (10 bits). The most significant
1058
- * bit of number is the sign bit. The remaining 9 bits are magnitude bits.
1059
- * Negative numbers are represented using two's-complement notation.
1060
- * If number is not a valid binary number, or if number contains more than
1061
- * 10 characters (10 bits), BIN2DEC returns the #NUM! error value.
1062
- * @return string
1063
- */
1064
- public static function BINTODEC($x) {
1065
- $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
1066
-
1067
- if (is_bool($x)) {
1068
- if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) {
1069
- $x = (int) $x;
1070
- } else {
1071
- return PHPExcel_Calculation_Functions::VALUE();
1072
- }
1073
- }
1074
- if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC) {
1075
- $x = floor($x);
1076
- }
1077
- $x = (string) $x;
1078
- if (strlen($x) > preg_match_all('/[01]/',$x,$out)) {
1079
- return PHPExcel_Calculation_Functions::NaN();
1080
- }
1081
- if (strlen($x) > 10) {
1082
- return PHPExcel_Calculation_Functions::NaN();
1083
- } elseif (strlen($x) == 10) {
1084
- // Two's Complement
1085
- $x = substr($x,-9);
1086
- return '-'.(512-bindec($x));
1087
- }
1088
- return bindec($x);
1089
- } // function BINTODEC()
1090
-
1091
-
1092
- /**
1093
- * BINTOHEX
1094
- *
1095
- * Return a binary value as hex.
1096
- *
1097
- * Excel Function:
1098
- * BIN2HEX(x[,places])
1099
- *
1100
- * @access public
1101
- * @category Engineering Functions
1102
- * @param string $x The binary number (as a string) that you want to convert. The number
1103
- * cannot contain more than 10 characters (10 bits). The most significant
1104
- * bit of number is the sign bit. The remaining 9 bits are magnitude bits.
1105
- * Negative numbers are represented using two's-complement notation.
1106
- * If number is not a valid binary number, or if number contains more than
1107
- * 10 characters (10 bits), BIN2HEX returns the #NUM! error value.
1108
- * @param integer $places The number of characters to use. If places is omitted, BIN2HEX uses the
1109
- * minimum number of characters necessary. Places is useful for padding the
1110
- * return value with leading 0s (zeros).
1111
- * If places is not an integer, it is truncated.
1112
- * If places is nonnumeric, BIN2HEX returns the #VALUE! error value.
1113
- * If places is negative, BIN2HEX returns the #NUM! error value.
1114
- * @return string
1115
- */
1116
- public static function BINTOHEX($x, $places=NULL) {
1117
- $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
1118
- $places = PHPExcel_Calculation_Functions::flattenSingleValue($places);
1119
-
1120
- if (is_bool($x)) {
1121
- if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) {
1122
- $x = (int) $x;
1123
- } else {
1124
- return PHPExcel_Calculation_Functions::VALUE();
1125
- }
1126
- }
1127
- if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC) {
1128
- $x = floor($x);
1129
- }
1130
- $x = (string) $x;
1131
- if (strlen($x) > preg_match_all('/[01]/',$x,$out)) {
1132
- return PHPExcel_Calculation_Functions::NaN();
1133
- }
1134
- if (strlen($x) > 10) {
1135
- return PHPExcel_Calculation_Functions::NaN();
1136
- } elseif (strlen($x) == 10) {
1137
- // Two's Complement
1138
- return str_repeat('F',8).substr(strtoupper(dechex(bindec(substr($x,-9)))),-2);
1139
- }
1140
- $hexVal = (string) strtoupper(dechex(bindec($x)));
1141
-
1142
- return self::_nbrConversionFormat($hexVal,$places);
1143
- } // function BINTOHEX()
1144
-
1145
-
1146
- /**
1147
- * BINTOOCT
1148
- *
1149
- * Return a binary value as octal.
1150
- *
1151
- * Excel Function:
1152
- * BIN2OCT(x[,places])
1153
- *
1154
- * @access public
1155
- * @category Engineering Functions
1156
- * @param string $x The binary number (as a string) that you want to convert. The number
1157
- * cannot contain more than 10 characters (10 bits). The most significant
1158
- * bit of number is the sign bit. The remaining 9 bits are magnitude bits.
1159
- * Negative numbers are represented using two's-complement notation.
1160
- * If number is not a valid binary number, or if number contains more than
1161
- * 10 characters (10 bits), BIN2OCT returns the #NUM! error value.
1162
- * @param integer $places The number of characters to use. If places is omitted, BIN2OCT uses the
1163
- * minimum number of characters necessary. Places is useful for padding the
1164
- * return value with leading 0s (zeros).
1165
- * If places is not an integer, it is truncated.
1166
- * If places is nonnumeric, BIN2OCT returns the #VALUE! error value.
1167
- * If places is negative, BIN2OCT returns the #NUM! error value.
1168
- * @return string
1169
- */
1170
- public static function BINTOOCT($x, $places=NULL) {
1171
- $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
1172
- $places = PHPExcel_Calculation_Functions::flattenSingleValue($places);
1173
-
1174
- if (is_bool($x)) {
1175
- if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) {
1176
- $x = (int) $x;
1177
- } else {
1178
- return PHPExcel_Calculation_Functions::VALUE();
1179
- }
1180
- }
1181
- if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC) {
1182
- $x = floor($x);
1183
- }
1184
- $x = (string) $x;
1185
- if (strlen($x) > preg_match_all('/[01]/',$x,$out)) {
1186
- return PHPExcel_Calculation_Functions::NaN();
1187
- }
1188
- if (strlen($x) > 10) {
1189
- return PHPExcel_Calculation_Functions::NaN();
1190
- } elseif (strlen($x) == 10) {
1191
- // Two's Complement
1192
- return str_repeat('7',7).substr(strtoupper(decoct(bindec(substr($x,-9)))),-3);
1193
- }
1194
- $octVal = (string) decoct(bindec($x));
1195
-
1196
- return self::_nbrConversionFormat($octVal,$places);
1197
- } // function BINTOOCT()
1198
-
1199
-
1200
- /**
1201
- * DECTOBIN
1202
- *
1203
- * Return a decimal value as binary.
1204
- *
1205
- * Excel Function:
1206
- * DEC2BIN(x[,places])
1207
- *
1208
- * @access public
1209
- * @category Engineering Functions
1210
- * @param string $x The decimal integer you want to convert. If number is negative,
1211
- * valid place values are ignored and DEC2BIN returns a 10-character
1212
- * (10-bit) binary number in which the most significant bit is the sign
1213
- * bit. The remaining 9 bits are magnitude bits. Negative numbers are
1214
- * represented using two's-complement notation.
1215
- * If number < -512 or if number > 511, DEC2BIN returns the #NUM! error
1216
- * value.
1217
- * If number is nonnumeric, DEC2BIN returns the #VALUE! error value.
1218
- * If DEC2BIN requires more than places characters, it returns the #NUM!
1219
- * error value.
1220
- * @param integer $places The number of characters to use. If places is omitted, DEC2BIN uses
1221
- * the minimum number of characters necessary. Places is useful for
1222
- * padding the return value with leading 0s (zeros).
1223
- * If places is not an integer, it is truncated.
1224
- * If places is nonnumeric, DEC2BIN returns the #VALUE! error value.
1225
- * If places is zero or negative, DEC2BIN returns the #NUM! error value.
1226
- * @return string
1227
- */
1228
- public static function DECTOBIN($x, $places=NULL) {
1229
- $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
1230
- $places = PHPExcel_Calculation_Functions::flattenSingleValue($places);
1231
-
1232
- if (is_bool($x)) {
1233
- if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) {
1234
- $x = (int) $x;
1235
- } else {
1236
- return PHPExcel_Calculation_Functions::VALUE();
1237
- }
1238
- }
1239
- $x = (string) $x;
1240
- if (strlen($x) > preg_match_all('/[-0123456789.]/',$x,$out)) {
1241
- return PHPExcel_Calculation_Functions::VALUE();
1242
- }
1243
- $x = (string) floor($x);
1244
- $r = decbin($x);
1245
- if (strlen($r) == 32) {
1246
- // Two's Complement
1247
- $r = substr($r,-10);
1248
- } elseif (strlen($r) > 11) {
1249
- return PHPExcel_Calculation_Functions::NaN();
1250
- }
1251
-
1252
- return self::_nbrConversionFormat($r,$places);
1253
- } // function DECTOBIN()
1254
-
1255
-
1256
- /**
1257
- * DECTOHEX
1258
- *
1259
- * Return a decimal value as hex.
1260
- *
1261
- * Excel Function:
1262
- * DEC2HEX(x[,places])
1263
- *
1264
- * @access public
1265
- * @category Engineering Functions
1266
- * @param string $x The decimal integer you want to convert. If number is negative,
1267
- * places is ignored and DEC2HEX returns a 10-character (40-bit)
1268
- * hexadecimal number in which the most significant bit is the sign
1269
- * bit. The remaining 39 bits are magnitude bits. Negative numbers
1270
- * are represented using two's-complement notation.
1271
- * If number < -549,755,813,888 or if number > 549,755,813,887,
1272
- * DEC2HEX returns the #NUM! error value.
1273
- * If number is nonnumeric, DEC2HEX returns the #VALUE! error value.
1274
- * If DEC2HEX requires more than places characters, it returns the
1275
- * #NUM! error value.
1276
- * @param integer $places The number of characters to use. If places is omitted, DEC2HEX uses
1277
- * the minimum number of characters necessary. Places is useful for
1278
- * padding the return value with leading 0s (zeros).
1279
- * If places is not an integer, it is truncated.
1280
- * If places is nonnumeric, DEC2HEX returns the #VALUE! error value.
1281
- * If places is zero or negative, DEC2HEX returns the #NUM! error value.
1282
- * @return string
1283
- */
1284
- public static function DECTOHEX($x, $places=null) {
1285
- $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
1286
- $places = PHPExcel_Calculation_Functions::flattenSingleValue($places);
1287
-
1288
- if (is_bool($x)) {
1289
- if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) {
1290
- $x = (int) $x;
1291
- } else {
1292
- return PHPExcel_Calculation_Functions::VALUE();
1293
- }
1294
- }
1295
- $x = (string) $x;
1296
- if (strlen($x) > preg_match_all('/[-0123456789.]/',$x,$out)) {
1297
- return PHPExcel_Calculation_Functions::VALUE();
1298
- }
1299
- $x = (string) floor($x);
1300
- $r = strtoupper(dechex($x));
1301
- if (strlen($r) == 8) {
1302
- // Two's Complement
1303
- $r = 'FF'.$r;
1304
- }
1305
-
1306
- return self::_nbrConversionFormat($r,$places);
1307
- } // function DECTOHEX()
1308
-
1309
-
1310
- /**
1311
- * DECTOOCT
1312
- *
1313
- * Return an decimal value as octal.
1314
- *
1315
- * Excel Function:
1316
- * DEC2OCT(x[,places])
1317
- *
1318
- * @access public
1319
- * @category Engineering Functions
1320
- * @param string $x The decimal integer you want to convert. If number is negative,
1321
- * places is ignored and DEC2OCT returns a 10-character (30-bit)
1322
- * octal number in which the most significant bit is the sign bit.
1323
- * The remaining 29 bits are magnitude bits. Negative numbers are
1324
- * represented using two's-complement notation.
1325
- * If number < -536,870,912 or if number > 536,870,911, DEC2OCT
1326
- * returns the #NUM! error value.
1327
- * If number is nonnumeric, DEC2OCT returns the #VALUE! error value.
1328
- * If DEC2OCT requires more than places characters, it returns the
1329
- * #NUM! error value.
1330
- * @param integer $places The number of characters to use. If places is omitted, DEC2OCT uses
1331
- * the minimum number of characters necessary. Places is useful for
1332
- * padding the return value with leading 0s (zeros).
1333
- * If places is not an integer, it is truncated.
1334
- * If places is nonnumeric, DEC2OCT returns the #VALUE! error value.
1335
- * If places is zero or negative, DEC2OCT returns the #NUM! error value.
1336
- * @return string
1337
- */
1338
- public static function DECTOOCT($x, $places=null) {
1339
- $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
1340
- $places = PHPExcel_Calculation_Functions::flattenSingleValue($places);
1341
-
1342
- if (is_bool($x)) {
1343
- if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) {
1344
- $x = (int) $x;
1345
- } else {
1346
- return PHPExcel_Calculation_Functions::VALUE();
1347
- }
1348
- }
1349
- $x = (string) $x;
1350
- if (strlen($x) > preg_match_all('/[-0123456789.]/',$x,$out)) {
1351
- return PHPExcel_Calculation_Functions::VALUE();
1352
- }
1353
- $x = (string) floor($x);
1354
- $r = decoct($x);
1355
- if (strlen($r) == 11) {
1356
- // Two's Complement
1357
- $r = substr($r,-10);
1358
- }
1359
-
1360
- return self::_nbrConversionFormat($r,$places);
1361
- } // function DECTOOCT()
1362
-
1363
-
1364
- /**
1365
- * HEXTOBIN
1366
- *
1367
- * Return a hex value as binary.
1368
- *
1369
- * Excel Function:
1370
- * HEX2BIN(x[,places])
1371
- *
1372
- * @access public
1373
- * @category Engineering Functions
1374
- * @param string $x the hexadecimal number you want to convert. Number cannot
1375
- * contain more than 10 characters. The most significant bit of
1376
- * number is the sign bit (40th bit from the right). The remaining
1377
- * 9 bits are magnitude bits. Negative numbers are represented
1378
- * using two's-complement notation.
1379
- * If number is negative, HEX2BIN ignores places and returns a
1380
- * 10-character binary number.
1381
- * If number is negative, it cannot be less than FFFFFFFE00, and
1382
- * if number is positive, it cannot be greater than 1FF.
1383
- * If number is not a valid hexadecimal number, HEX2BIN returns
1384
- * the #NUM! error value.
1385
- * If HEX2BIN requires more than places characters, it returns
1386
- * the #NUM! error value.
1387
- * @param integer $places The number of characters to use. If places is omitted,
1388
- * HEX2BIN uses the minimum number of characters necessary. Places
1389
- * is useful for padding the return value with leading 0s (zeros).
1390
- * If places is not an integer, it is truncated.
1391
- * If places is nonnumeric, HEX2BIN returns the #VALUE! error value.
1392
- * If places is negative, HEX2BIN returns the #NUM! error value.
1393
- * @return string
1394
- */
1395
- public static function HEXTOBIN($x, $places=null) {
1396
- $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
1397
- $places = PHPExcel_Calculation_Functions::flattenSingleValue($places);
1398
-
1399
- if (is_bool($x)) {
1400
- return PHPExcel_Calculation_Functions::VALUE();
1401
- }
1402
- $x = (string) $x;
1403
- if (strlen($x) > preg_match_all('/[0123456789ABCDEF]/',strtoupper($x),$out)) {
1404
- return PHPExcel_Calculation_Functions::NaN();
1405
- }
1406
- $binVal = decbin(hexdec($x));
1407
-
1408
- return substr(self::_nbrConversionFormat($binVal,$places),-10);
1409
- } // function HEXTOBIN()
1410
-
1411
-
1412
- /**
1413
- * HEXTODEC
1414
- *
1415
- * Return a hex value as decimal.
1416
- *
1417
- * Excel Function:
1418
- * HEX2DEC(x)
1419
- *
1420
- * @access public
1421
- * @category Engineering Functions
1422
- * @param string $x The hexadecimal number you want to convert. This number cannot
1423
- * contain more than 10 characters (40 bits). The most significant
1424
- * bit of number is the sign bit. The remaining 39 bits are magnitude
1425
- * bits. Negative numbers are represented using two's-complement
1426
- * notation.
1427
- * If number is not a valid hexadecimal number, HEX2DEC returns the
1428
- * #NUM! error value.
1429
- * @return string
1430
- */
1431
- public static function HEXTODEC($x) {
1432
- $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
1433
-
1434
- if (is_bool($x)) {
1435
- return PHPExcel_Calculation_Functions::VALUE();
1436
- }
1437
- $x = (string) $x;
1438
- if (strlen($x) > preg_match_all('/[0123456789ABCDEF]/',strtoupper($x),$out)) {
1439
- return PHPExcel_Calculation_Functions::NaN();
1440
- }
1441
- return hexdec($x);
1442
- } // function HEXTODEC()
1443
-
1444
-
1445
- /**
1446
- * HEXTOOCT
1447
- *
1448
- * Return a hex value as octal.
1449
- *
1450
- * Excel Function:
1451
- * HEX2OCT(x[,places])
1452
- *
1453
- * @access public
1454
- * @category Engineering Functions
1455
- * @param string $x The hexadecimal number you want to convert. Number cannot
1456
- * contain more than 10 characters. The most significant bit of
1457
- * number is the sign bit. The remaining 39 bits are magnitude
1458
- * bits. Negative numbers are represented using two's-complement
1459
- * notation.
1460
- * If number is negative, HEX2OCT ignores places and returns a
1461
- * 10-character octal number.
1462
- * If number is negative, it cannot be less than FFE0000000, and
1463
- * if number is positive, it cannot be greater than 1FFFFFFF.
1464
- * If number is not a valid hexadecimal number, HEX2OCT returns
1465
- * the #NUM! error value.
1466
- * If HEX2OCT requires more than places characters, it returns
1467
- * the #NUM! error value.
1468
- * @param integer $places The number of characters to use. If places is omitted, HEX2OCT
1469
- * uses the minimum number of characters necessary. Places is
1470
- * useful for padding the return value with leading 0s (zeros).
1471
- * If places is not an integer, it is truncated.
1472
- * If places is nonnumeric, HEX2OCT returns the #VALUE! error
1473
- * value.
1474
- * If places is negative, HEX2OCT returns the #NUM! error value.
1475
- * @return string
1476
- */
1477
- public static function HEXTOOCT($x, $places=null) {
1478
- $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
1479
- $places = PHPExcel_Calculation_Functions::flattenSingleValue($places);
1480
-
1481
- if (is_bool($x)) {
1482
- return PHPExcel_Calculation_Functions::VALUE();
1483
- }
1484
- $x = (string) $x;
1485
- if (strlen($x) > preg_match_all('/[0123456789ABCDEF]/',strtoupper($x),$out)) {
1486
- return PHPExcel_Calculation_Functions::NaN();
1487
- }
1488
- $octVal = decoct(hexdec($x));
1489
-
1490
- return self::_nbrConversionFormat($octVal,$places);
1491
- } // function HEXTOOCT()
1492
-
1493
-
1494
- /**
1495
- * OCTTOBIN
1496
- *
1497
- * Return an octal value as binary.
1498
- *
1499
- * Excel Function:
1500
- * OCT2BIN(x[,places])
1501
- *
1502
- * @access public
1503
- * @category Engineering Functions
1504
- * @param string $x The octal number you want to convert. Number may not
1505
- * contain more than 10 characters. The most significant
1506
- * bit of number is the sign bit. The remaining 29 bits
1507
- * are magnitude bits. Negative numbers are represented
1508
- * using two's-complement notation.
1509
- * If number is negative, OCT2BIN ignores places and returns
1510
- * a 10-character binary number.
1511
- * If number is negative, it cannot be less than 7777777000,
1512
- * and if number is positive, it cannot be greater than 777.
1513
- * If number is not a valid octal number, OCT2BIN returns
1514
- * the #NUM! error value.
1515
- * If OCT2BIN requires more than places characters, it
1516
- * returns the #NUM! error value.
1517
- * @param integer $places The number of characters to use. If places is omitted,
1518
- * OCT2BIN uses the minimum number of characters necessary.
1519
- * Places is useful for padding the return value with
1520
- * leading 0s (zeros).
1521
- * If places is not an integer, it is truncated.
1522
- * If places is nonnumeric, OCT2BIN returns the #VALUE!
1523
- * error value.
1524
- * If places is negative, OCT2BIN returns the #NUM! error
1525
- * value.
1526
- * @return string
1527
- */
1528
- public static function OCTTOBIN($x, $places=null) {
1529
- $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
1530
- $places = PHPExcel_Calculation_Functions::flattenSingleValue($places);
1531
-
1532
- if (is_bool($x)) {
1533
- return PHPExcel_Calculation_Functions::VALUE();
1534
- }
1535
- $x = (string) $x;
1536
- if (preg_match_all('/[01234567]/',$x,$out) != strlen($x)) {
1537
- return PHPExcel_Calculation_Functions::NaN();
1538
- }
1539
- $r = decbin(octdec($x));
1540
-
1541
- return self::_nbrConversionFormat($r,$places);
1542
- } // function OCTTOBIN()
1543
-
1544
-
1545
- /**
1546
- * OCTTODEC
1547
- *
1548
- * Return an octal value as decimal.
1549
- *
1550
- * Excel Function:
1551
- * OCT2DEC(x)
1552
- *
1553
- * @access public
1554
- * @category Engineering Functions
1555
- * @param string $x The octal number you want to convert. Number may not contain
1556
- * more than 10 octal characters (30 bits). The most significant
1557
- * bit of number is the sign bit. The remaining 29 bits are
1558
- * magnitude bits. Negative numbers are represented using
1559
- * two's-complement notation.
1560
- * If number is not a valid octal number, OCT2DEC returns the
1561
- * #NUM! error value.
1562
- * @return string
1563
- */
1564
- public static function OCTTODEC($x) {
1565
- $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
1566
-
1567
- if (is_bool($x)) {
1568
- return PHPExcel_Calculation_Functions::VALUE();
1569
- }
1570
- $x = (string) $x;
1571
- if (preg_match_all('/[01234567]/',$x,$out) != strlen($x)) {
1572
- return PHPExcel_Calculation_Functions::NaN();
1573
- }
1574
- return octdec($x);
1575
- } // function OCTTODEC()
1576
-
1577
-
1578
- /**
1579
- * OCTTOHEX
1580
- *
1581
- * Return an octal value as hex.
1582
- *
1583
- * Excel Function:
1584
- * OCT2HEX(x[,places])
1585
- *
1586
- * @access public
1587
- * @category Engineering Functions
1588
- * @param string $x The octal number you want to convert. Number may not contain
1589
- * more than 10 octal characters (30 bits). The most significant
1590
- * bit of number is the sign bit. The remaining 29 bits are
1591
- * magnitude bits. Negative numbers are represented using
1592
- * two's-complement notation.
1593
- * If number is negative, OCT2HEX ignores places and returns a
1594
- * 10-character hexadecimal number.
1595
- * If number is not a valid octal number, OCT2HEX returns the
1596
- * #NUM! error value.
1597
- * If OCT2HEX requires more than places characters, it returns
1598
- * the #NUM! error value.
1599
- * @param integer $places The number of characters to use. If places is omitted, OCT2HEX
1600
- * uses the minimum number of characters necessary. Places is useful
1601
- * for padding the return value with leading 0s (zeros).
1602
- * If places is not an integer, it is truncated.
1603
- * If places is nonnumeric, OCT2HEX returns the #VALUE! error value.
1604
- * If places is negative, OCT2HEX returns the #NUM! error value.
1605
- * @return string
1606
- */
1607
- public static function OCTTOHEX($x, $places=null) {
1608
- $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
1609
- $places = PHPExcel_Calculation_Functions::flattenSingleValue($places);
1610
-
1611
- if (is_bool($x)) {
1612
- return PHPExcel_Calculation_Functions::VALUE();
1613
- }
1614
- $x = (string) $x;
1615
- if (preg_match_all('/[01234567]/',$x,$out) != strlen($x)) {
1616
- return PHPExcel_Calculation_Functions::NaN();
1617
- }
1618
- $hexVal = strtoupper(dechex(octdec($x)));
1619
-
1620
- return self::_nbrConversionFormat($hexVal,$places);
1621
- } // function OCTTOHEX()
1622
-
1623
-
1624
- /**
1625
- * COMPLEX
1626
- *
1627
- * Converts real and imaginary coefficients into a complex number of the form x + yi or x + yj.
1628
- *
1629
- * Excel Function:
1630
- * COMPLEX(realNumber,imaginary[,places])
1631
- *
1632
- * @access public
1633
- * @category Engineering Functions
1634
- * @param float $realNumber The real coefficient of the complex number.
1635
- * @param float $imaginary The imaginary coefficient of the complex number.
1636
- * @param string $suffix The suffix for the imaginary component of the complex number.
1637
- * If omitted, the suffix is assumed to be "i".
1638
- * @return string
1639
- */
1640
- public static function COMPLEX($realNumber=0.0, $imaginary=0.0, $suffix='i') {
1641
- $realNumber = (is_null($realNumber)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($realNumber);
1642
- $imaginary = (is_null($imaginary)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($imaginary);
1643
- $suffix = (is_null($suffix)) ? 'i' : PHPExcel_Calculation_Functions::flattenSingleValue($suffix);
1644
-
1645
- if (((is_numeric($realNumber)) && (is_numeric($imaginary))) &&
1646
- (($suffix == 'i') || ($suffix == 'j') || ($suffix == ''))) {
1647
- $realNumber = (float) $realNumber;
1648
- $imaginary = (float) $imaginary;
1649
-
1650
- if ($suffix == '') $suffix = 'i';
1651
- if ($realNumber == 0.0) {
1652
- if ($imaginary == 0.0) {
1653
- return (string) '0';
1654
- } elseif ($imaginary == 1.0) {
1655
- return (string) $suffix;
1656
- } elseif ($imaginary == -1.0) {
1657
- return (string) '-'.$suffix;
1658
- }
1659
- return (string) $imaginary.$suffix;
1660
- } elseif ($imaginary == 0.0) {
1661
- return (string) $realNumber;
1662
- } elseif ($imaginary == 1.0) {
1663
- return (string) $realNumber.'+'.$suffix;
1664
- } elseif ($imaginary == -1.0) {
1665
- return (string) $realNumber.'-'.$suffix;
1666
- }
1667
- if ($imaginary > 0) { $imaginary = (string) '+'.$imaginary; }
1668
- return (string) $realNumber.$imaginary.$suffix;
1669
- }
1670
-
1671
- return PHPExcel_Calculation_Functions::VALUE();
1672
- } // function COMPLEX()
1673
-
1674
-
1675
- /**
1676
- * IMAGINARY
1677
- *
1678
- * Returns the imaginary coefficient of a complex number in x + yi or x + yj text format.
1679
- *
1680
- * Excel Function:
1681
- * IMAGINARY(complexNumber)
1682
- *
1683
- * @access public
1684
- * @category Engineering Functions
1685
- * @param string $complexNumber The complex number for which you want the imaginary
1686
- * coefficient.
1687
- * @return float
1688
- */
1689
- public static function IMAGINARY($complexNumber) {
1690
- $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
1691
-
1692
- $parsedComplex = self::_parseComplex($complexNumber);
1693
- return $parsedComplex['imaginary'];
1694
- } // function IMAGINARY()
1695
-
1696
-
1697
- /**
1698
- * IMREAL
1699
- *
1700
- * Returns the real coefficient of a complex number in x + yi or x + yj text format.
1701
- *
1702
- * Excel Function:
1703
- * IMREAL(complexNumber)
1704
- *
1705
- * @access public
1706
- * @category Engineering Functions
1707
- * @param string $complexNumber The complex number for which you want the real coefficient.
1708
- * @return float
1709
- */
1710
- public static function IMREAL($complexNumber) {
1711
- $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
1712
-
1713
- $parsedComplex = self::_parseComplex($complexNumber);
1714
- return $parsedComplex['real'];
1715
- } // function IMREAL()
1716
-
1717
-
1718
- /**
1719
- * IMABS
1720
- *
1721
- * Returns the absolute value (modulus) of a complex number in x + yi or x + yj text format.
1722
- *
1723
- * Excel Function:
1724
- * IMABS(complexNumber)
1725
- *
1726
- * @param string $complexNumber The complex number for which you want the absolute value.
1727
- * @return float
1728
- */
1729
- public static function IMABS($complexNumber) {
1730
- $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
1731
-
1732
- $parsedComplex = self::_parseComplex($complexNumber);
1733
-
1734
- return sqrt(($parsedComplex['real'] * $parsedComplex['real']) + ($parsedComplex['imaginary'] * $parsedComplex['imaginary']));
1735
- } // function IMABS()
1736
-
1737
-
1738
- /**
1739
- * IMARGUMENT
1740
- *
1741
- * Returns the argument theta of a complex number, i.e. the angle in radians from the real
1742
- * axis to the representation of the number in polar coordinates.
1743
- *
1744
- * Excel Function:
1745
- * IMARGUMENT(complexNumber)
1746
- *
1747
- * @param string $complexNumber The complex number for which you want the argument theta.
1748
- * @return float
1749
- */
1750
- public static function IMARGUMENT($complexNumber) {
1751
- $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
1752
-
1753
- $parsedComplex = self::_parseComplex($complexNumber);
1754
-
1755
- if ($parsedComplex['real'] == 0.0) {
1756
- if ($parsedComplex['imaginary'] == 0.0) {
1757
- return 0.0;
1758
- } elseif($parsedComplex['imaginary'] < 0.0) {
1759
- return M_PI / -2;
1760
- } else {
1761
- return M_PI / 2;
1762
- }
1763
- } elseif ($parsedComplex['real'] > 0.0) {
1764
- return atan($parsedComplex['imaginary'] / $parsedComplex['real']);
1765
- } elseif ($parsedComplex['imaginary'] < 0.0) {
1766
- return 0 - (M_PI - atan(abs($parsedComplex['imaginary']) / abs($parsedComplex['real'])));
1767
- } else {
1768
- return M_PI - atan($parsedComplex['imaginary'] / abs($parsedComplex['real']));
1769
- }
1770
- } // function IMARGUMENT()
1771
-
1772
-
1773
- /**
1774
- * IMCONJUGATE
1775
- *
1776
- * Returns the complex conjugate of a complex number in x + yi or x + yj text format.
1777
- *
1778
- * Excel Function:
1779
- * IMCONJUGATE(complexNumber)
1780
- *
1781
- * @param string $complexNumber The complex number for which you want the conjugate.
1782
- * @return string
1783
- */
1784
- public static function IMCONJUGATE($complexNumber) {
1785
- $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
1786
-
1787
- $parsedComplex = self::_parseComplex($complexNumber);
1788
-
1789
- if ($parsedComplex['imaginary'] == 0.0) {
1790
- return $parsedComplex['real'];
1791
- } else {
1792
- return self::_cleanComplex( self::COMPLEX( $parsedComplex['real'],
1793
- 0 - $parsedComplex['imaginary'],
1794
- $parsedComplex['suffix']
1795
- )
1796
- );
1797
- }
1798
- } // function IMCONJUGATE()
1799
-
1800
-
1801
- /**
1802
- * IMCOS
1803
- *
1804
- * Returns the cosine of a complex number in x + yi or x + yj text format.
1805
- *
1806
- * Excel Function:
1807
- * IMCOS(complexNumber)
1808
- *
1809
- * @param string $complexNumber The complex number for which you want the cosine.
1810
- * @return string|float
1811
- */
1812
- public static function IMCOS($complexNumber) {
1813
- $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
1814
-
1815
- $parsedComplex = self::_parseComplex($complexNumber);
1816
-
1817
- if ($parsedComplex['imaginary'] == 0.0) {
1818
- return cos($parsedComplex['real']);
1819
- } else {
1820
- return self::IMCONJUGATE(self::COMPLEX(cos($parsedComplex['real']) * cosh($parsedComplex['imaginary']),sin($parsedComplex['real']) * sinh($parsedComplex['imaginary']),$parsedComplex['suffix']));
1821
- }
1822
- } // function IMCOS()
1823
-
1824
-
1825
- /**
1826
- * IMSIN
1827
- *
1828
- * Returns the sine of a complex number in x + yi or x + yj text format.
1829
- *
1830
- * Excel Function:
1831
- * IMSIN(complexNumber)
1832
- *
1833
- * @param string $complexNumber The complex number for which you want the sine.
1834
- * @return string|float
1835
- */
1836
- public static function IMSIN($complexNumber) {
1837
- $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
1838
-
1839
- $parsedComplex = self::_parseComplex($complexNumber);
1840
-
1841
- if ($parsedComplex['imaginary'] == 0.0) {
1842
- return sin($parsedComplex['real']);
1843
- } else {
1844
- return self::COMPLEX(sin($parsedComplex['real']) * cosh($parsedComplex['imaginary']),cos($parsedComplex['real']) * sinh($parsedComplex['imaginary']),$parsedComplex['suffix']);
1845
- }
1846
- } // function IMSIN()
1847
-
1848
-
1849
- /**
1850
- * IMSQRT
1851
- *
1852
- * Returns the square root of a complex number in x + yi or x + yj text format.
1853
- *
1854
- * Excel Function:
1855
- * IMSQRT(complexNumber)
1856
- *
1857
- * @param string $complexNumber The complex number for which you want the square root.
1858
- * @return string
1859
- */
1860
- public static function IMSQRT($complexNumber) {
1861
- $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
1862
-
1863
- $parsedComplex = self::_parseComplex($complexNumber);
1864
-
1865
- $theta = self::IMARGUMENT($complexNumber);
1866
- $d1 = cos($theta / 2);
1867
- $d2 = sin($theta / 2);
1868
- $r = sqrt(sqrt(($parsedComplex['real'] * $parsedComplex['real']) + ($parsedComplex['imaginary'] * $parsedComplex['imaginary'])));
1869
-
1870
- if ($parsedComplex['suffix'] == '') {
1871
- return self::COMPLEX($d1 * $r,$d2 * $r);
1872
- } else {
1873
- return self::COMPLEX($d1 * $r,$d2 * $r,$parsedComplex['suffix']);
1874
- }
1875
- } // function IMSQRT()
1876
-
1877
-
1878
- /**
1879
- * IMLN
1880
- *
1881
- * Returns the natural logarithm of a complex number in x + yi or x + yj text format.
1882
- *
1883
- * Excel Function:
1884
- * IMLN(complexNumber)
1885
- *
1886
- * @param string $complexNumber The complex number for which you want the natural logarithm.
1887
- * @return string
1888
- */
1889
- public static function IMLN($complexNumber) {
1890
- $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
1891
-
1892
- $parsedComplex = self::_parseComplex($complexNumber);
1893
-
1894
- if (($parsedComplex['real'] == 0.0) && ($parsedComplex['imaginary'] == 0.0)) {
1895
- return PHPExcel_Calculation_Functions::NaN();
1896
- }
1897
-
1898
- $logR = log(sqrt(($parsedComplex['real'] * $parsedComplex['real']) + ($parsedComplex['imaginary'] * $parsedComplex['imaginary'])));
1899
- $t = self::IMARGUMENT($complexNumber);
1900
-
1901
- if ($parsedComplex['suffix'] == '') {
1902
- return self::COMPLEX($logR,$t);
1903
- } else {
1904
- return self::COMPLEX($logR,$t,$parsedComplex['suffix']);
1905
- }
1906
- } // function IMLN()
1907
-
1908
-
1909
- /**
1910
- * IMLOG10
1911
- *
1912
- * Returns the common logarithm (base 10) of a complex number in x + yi or x + yj text format.
1913
- *
1914
- * Excel Function:
1915
- * IMLOG10(complexNumber)
1916
- *
1917
- * @param string $complexNumber The complex number for which you want the common logarithm.
1918
- * @return string
1919
- */
1920
- public static function IMLOG10($complexNumber) {
1921
- $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
1922
-
1923
- $parsedComplex = self::_parseComplex($complexNumber);
1924
-
1925
- if (($parsedComplex['real'] == 0.0) && ($parsedComplex['imaginary'] == 0.0)) {
1926
- return PHPExcel_Calculation_Functions::NaN();
1927
- } elseif (($parsedComplex['real'] > 0.0) && ($parsedComplex['imaginary'] == 0.0)) {
1928
- return log10($parsedComplex['real']);
1929
- }
1930
-
1931
- return self::IMPRODUCT(log10(EULER),self::IMLN($complexNumber));
1932
- } // function IMLOG10()
1933
-
1934
-
1935
- /**
1936
- * IMLOG2
1937
- *
1938
- * Returns the base-2 logarithm of a complex number in x + yi or x + yj text format.
1939
- *
1940
- * Excel Function:
1941
- * IMLOG2(complexNumber)
1942
- *
1943
- * @param string $complexNumber The complex number for which you want the base-2 logarithm.
1944
- * @return string
1945
- */
1946
- public static function IMLOG2($complexNumber) {
1947
- $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
1948
-
1949
- $parsedComplex = self::_parseComplex($complexNumber);
1950
-
1951
- if (($parsedComplex['real'] == 0.0) && ($parsedComplex['imaginary'] == 0.0)) {
1952
- return PHPExcel_Calculation_Functions::NaN();
1953
- } elseif (($parsedComplex['real'] > 0.0) && ($parsedComplex['imaginary'] == 0.0)) {
1954
- return log($parsedComplex['real'],2);
1955
- }
1956
-
1957
- return self::IMPRODUCT(log(EULER,2),self::IMLN($complexNumber));
1958
- } // function IMLOG2()
1959
-
1960
-
1961
- /**
1962
- * IMEXP
1963
- *
1964
- * Returns the exponential of a complex number in x + yi or x + yj text format.
1965
- *
1966
- * Excel Function:
1967
- * IMEXP(complexNumber)
1968
- *
1969
- * @param string $complexNumber The complex number for which you want the exponential.
1970
- * @return string
1971
- */
1972
- public static function IMEXP($complexNumber) {
1973
- $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
1974
-
1975
- $parsedComplex = self::_parseComplex($complexNumber);
1976
-
1977
- if (($parsedComplex['real'] == 0.0) && ($parsedComplex['imaginary'] == 0.0)) {
1978
- return '1';
1979
- }
1980
-
1981
- $e = exp($parsedComplex['real']);
1982
- $eX = $e * cos($parsedComplex['imaginary']);
1983
- $eY = $e * sin($parsedComplex['imaginary']);
1984
-
1985
- if ($parsedComplex['suffix'] == '') {
1986
- return self::COMPLEX($eX,$eY);
1987
- } else {
1988
- return self::COMPLEX($eX,$eY,$parsedComplex['suffix']);
1989
- }
1990
- } // function IMEXP()
1991
-
1992
-
1993
- /**
1994
- * IMPOWER
1995
- *
1996
- * Returns a complex number in x + yi or x + yj text format raised to a power.
1997
- *
1998
- * Excel Function:
1999
- * IMPOWER(complexNumber,realNumber)
2000
- *
2001
- * @param string $complexNumber The complex number you want to raise to a power.
2002
- * @param float $realNumber The power to which you want to raise the complex number.
2003
- * @return string
2004
- */
2005
- public static function IMPOWER($complexNumber,$realNumber) {
2006
- $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
2007
- $realNumber = PHPExcel_Calculation_Functions::flattenSingleValue($realNumber);
2008
-
2009
- if (!is_numeric($realNumber)) {
2010
- return PHPExcel_Calculation_Functions::VALUE();
2011
- }
2012
-
2013
- $parsedComplex = self::_parseComplex($complexNumber);
2014
-
2015
- $r = sqrt(($parsedComplex['real'] * $parsedComplex['real']) + ($parsedComplex['imaginary'] * $parsedComplex['imaginary']));
2016
- $rPower = pow($r,$realNumber);
2017
- $theta = self::IMARGUMENT($complexNumber) * $realNumber;
2018
- if ($theta == 0) {
2019
- return 1;
2020
- } elseif ($parsedComplex['imaginary'] == 0.0) {
2021
- return self::COMPLEX($rPower * cos($theta),$rPower * sin($theta),$parsedComplex['suffix']);
2022
- } else {
2023
- return self::COMPLEX($rPower * cos($theta),$rPower * sin($theta),$parsedComplex['suffix']);
2024
- }
2025
- } // function IMPOWER()
2026
-
2027
-
2028
- /**
2029
- * IMDIV
2030
- *
2031
- * Returns the quotient of two complex numbers in x + yi or x + yj text format.
2032
- *
2033
- * Excel Function:
2034
- * IMDIV(complexDividend,complexDivisor)
2035
- *
2036
- * @param string $complexDividend The complex numerator or dividend.
2037
- * @param string $complexDivisor The complex denominator or divisor.
2038
- * @return string
2039
- */
2040
- public static function IMDIV($complexDividend,$complexDivisor) {
2041
- $complexDividend = PHPExcel_Calculation_Functions::flattenSingleValue($complexDividend);
2042
- $complexDivisor = PHPExcel_Calculation_Functions::flattenSingleValue($complexDivisor);
2043
-
2044
- $parsedComplexDividend = self::_parseComplex($complexDividend);
2045
- $parsedComplexDivisor = self::_parseComplex($complexDivisor);
2046
-
2047
- if (($parsedComplexDividend['suffix'] != '') && ($parsedComplexDivisor['suffix'] != '') &&
2048
- ($parsedComplexDividend['suffix'] != $parsedComplexDivisor['suffix'])) {
2049
- return PHPExcel_Calculation_Functions::NaN();
2050
- }
2051
- if (($parsedComplexDividend['suffix'] != '') && ($parsedComplexDivisor['suffix'] == '')) {
2052
- $parsedComplexDivisor['suffix'] = $parsedComplexDividend['suffix'];
2053
- }
2054
-
2055
- $d1 = ($parsedComplexDividend['real'] * $parsedComplexDivisor['real']) + ($parsedComplexDividend['imaginary'] * $parsedComplexDivisor['imaginary']);
2056
- $d2 = ($parsedComplexDividend['imaginary'] * $parsedComplexDivisor['real']) - ($parsedComplexDividend['real'] * $parsedComplexDivisor['imaginary']);
2057
- $d3 = ($parsedComplexDivisor['real'] * $parsedComplexDivisor['real']) + ($parsedComplexDivisor['imaginary'] * $parsedComplexDivisor['imaginary']);
2058
-
2059
- $r = $d1/$d3;
2060
- $i = $d2/$d3;
2061
-
2062
- if ($i > 0.0) {
2063
- return self::_cleanComplex($r.'+'.$i.$parsedComplexDivisor['suffix']);
2064
- } elseif ($i < 0.0) {
2065
- return self::_cleanComplex($r.$i.$parsedComplexDivisor['suffix']);
2066
- } else {
2067
- return $r;
2068
- }
2069
- } // function IMDIV()
2070
-
2071
-
2072
- /**
2073
- * IMSUB
2074
- *
2075
- * Returns the difference of two complex numbers in x + yi or x + yj text format.
2076
- *
2077
- * Excel Function:
2078
- * IMSUB(complexNumber1,complexNumber2)
2079
- *
2080
- * @param string $complexNumber1 The complex number from which to subtract complexNumber2.
2081
- * @param string $complexNumber2 The complex number to subtract from complexNumber1.
2082
- * @return string
2083
- */
2084
- public static function IMSUB($complexNumber1,$complexNumber2) {
2085
- $complexNumber1 = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber1);
2086
- $complexNumber2 = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber2);
2087
-
2088
- $parsedComplex1 = self::_parseComplex($complexNumber1);
2089
- $parsedComplex2 = self::_parseComplex($complexNumber2);
2090
-
2091
- if ((($parsedComplex1['suffix'] != '') && ($parsedComplex2['suffix'] != '')) &&
2092
- ($parsedComplex1['suffix'] != $parsedComplex2['suffix'])) {
2093
- return PHPExcel_Calculation_Functions::NaN();
2094
- } elseif (($parsedComplex1['suffix'] == '') && ($parsedComplex2['suffix'] != '')) {
2095
- $parsedComplex1['suffix'] = $parsedComplex2['suffix'];
2096
- }
2097
-
2098
- $d1 = $parsedComplex1['real'] - $parsedComplex2['real'];
2099
- $d2 = $parsedComplex1['imaginary'] - $parsedComplex2['imaginary'];
2100
-
2101
- return self::COMPLEX($d1,$d2,$parsedComplex1['suffix']);
2102
- } // function IMSUB()
2103
-
2104
-
2105
- /**
2106
- * IMSUM
2107
- *
2108
- * Returns the sum of two or more complex numbers in x + yi or x + yj text format.
2109
- *
2110
- * Excel Function:
2111
- * IMSUM(complexNumber[,complexNumber[,...]])
2112
- *
2113
- * @param string $complexNumber,... Series of complex numbers to add
2114
- * @return string
2115
- */
2116
- public static function IMSUM() {
2117
- // Return value
2118
- $returnValue = self::_parseComplex('0');
2119
- $activeSuffix = '';
2120
-
2121
- // Loop through the arguments
2122
- $aArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args());
2123
- foreach ($aArgs as $arg) {
2124
- $parsedComplex = self::_parseComplex($arg);
2125
-
2126
- if ($activeSuffix == '') {
2127
- $activeSuffix = $parsedComplex['suffix'];
2128
- } elseif (($parsedComplex['suffix'] != '') && ($activeSuffix != $parsedComplex['suffix'])) {
2129
- return PHPExcel_Calculation_Functions::VALUE();
2130
- }
2131
-
2132
- $returnValue['real'] += $parsedComplex['real'];
2133
- $returnValue['imaginary'] += $parsedComplex['imaginary'];
2134
- }
2135
-
2136
- if ($returnValue['imaginary'] == 0.0) { $activeSuffix = ''; }
2137
- return self::COMPLEX($returnValue['real'],$returnValue['imaginary'],$activeSuffix);
2138
- } // function IMSUM()
2139
-
2140
-
2141
- /**
2142
- * IMPRODUCT
2143
- *
2144
- * Returns the product of two or more complex numbers in x + yi or x + yj text format.
2145
- *
2146
- * Excel Function:
2147
- * IMPRODUCT(complexNumber[,complexNumber[,...]])
2148
- *
2149
- * @param string $complexNumber,... Series of complex numbers to multiply
2150
- * @return string
2151
- */
2152
- public static function IMPRODUCT() {
2153
- // Return value
2154
- $returnValue = self::_parseComplex('1');
2155
- $activeSuffix = '';
2156
-
2157
- // Loop through the arguments
2158
- $aArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args());
2159
- foreach ($aArgs as $arg) {
2160
- $parsedComplex = self::_parseComplex($arg);
2161
-
2162
- $workValue = $returnValue;
2163
- if (($parsedComplex['suffix'] != '') && ($activeSuffix == '')) {
2164
- $activeSuffix = $parsedComplex['suffix'];
2165
- } elseif (($parsedComplex['suffix'] != '') && ($activeSuffix != $parsedComplex['suffix'])) {
2166
- return PHPExcel_Calculation_Functions::NaN();
2167
- }
2168
- $returnValue['real'] = ($workValue['real'] * $parsedComplex['real']) - ($workValue['imaginary'] * $parsedComplex['imaginary']);
2169
- $returnValue['imaginary'] = ($workValue['real'] * $parsedComplex['imaginary']) + ($workValue['imaginary'] * $parsedComplex['real']);
2170
- }
2171
-
2172
- if ($returnValue['imaginary'] == 0.0) { $activeSuffix = ''; }
2173
- return self::COMPLEX($returnValue['real'],$returnValue['imaginary'],$activeSuffix);
2174
- } // function IMPRODUCT()
2175
-
2176
-
2177
- /**
2178
- * DELTA
2179
- *
2180
- * Tests whether two values are equal. Returns 1 if number1 = number2; returns 0 otherwise.
2181
- * Use this function to filter a set of values. For example, by summing several DELTA
2182
- * functions you calculate the count of equal pairs. This function is also known as the
2183
- * Kronecker Delta function.
2184
- *
2185
- * Excel Function:
2186
- * DELTA(a[,b])
2187
- *
2188
- * @param float $a The first number.
2189
- * @param float $b The second number. If omitted, b is assumed to be zero.
2190
- * @return int
2191
- */
2192
- public static function DELTA($a, $b=0) {
2193
- $a = PHPExcel_Calculation_Functions::flattenSingleValue($a);
2194
- $b = PHPExcel_Calculation_Functions::flattenSingleValue($b);
2195
-
2196
- return (int) ($a == $b);
2197
- } // function DELTA()
2198
-
2199
-
2200
- /**
2201
- * GESTEP
2202
- *
2203
- * Excel Function:
2204
- * GESTEP(number[,step])
2205
- *
2206
- * Returns 1 if number >= step; returns 0 (zero) otherwise
2207
- * Use this function to filter a set of values. For example, by summing several GESTEP
2208
- * functions you calculate the count of values that exceed a threshold.
2209
- *
2210
- * @param float $number The value to test against step.
2211
- * @param float $step The threshold value.
2212
- * If you omit a value for step, GESTEP uses zero.
2213
- * @return int
2214
- */
2215
- public static function GESTEP($number, $step=0) {
2216
- $number = PHPExcel_Calculation_Functions::flattenSingleValue($number);
2217
- $step = PHPExcel_Calculation_Functions::flattenSingleValue($step);
2218
-
2219
- return (int) ($number >= $step);
2220
- } // function GESTEP()
2221
-
2222
-
2223
- //
2224
- // Private method to calculate the erf value
2225
- //
2226
- private static $_two_sqrtpi = 1.128379167095512574;
2227
-
2228
- public static function _erfVal($x) {
2229
- if (abs($x) > 2.2) {
2230
- return 1 - self::_erfcVal($x);
2231
- }
2232
- $sum = $term = $x;
2233
- $xsqr = ($x * $x);
2234
- $j = 1;
2235
- do {
2236
- $term *= $xsqr / $j;
2237
- $sum -= $term / (2 * $j + 1);
2238
- ++$j;
2239
- $term *= $xsqr / $j;
2240
- $sum += $term / (2 * $j + 1);
2241
- ++$j;
2242
- if ($sum == 0.0) {
2243
- break;
2244
- }
2245
- } while (abs($term / $sum) > PRECISION);
2246
- return self::$_two_sqrtpi * $sum;
2247
- } // function _erfVal()
2248
-
2249
-
2250
- /**
2251
- * ERF
2252
- *
2253
- * Returns the error function integrated between the lower and upper bound arguments.
2254
- *
2255
- * Note: In Excel 2007 or earlier, if you input a negative value for the upper or lower bound arguments,
2256
- * the function would return a #NUM! error. However, in Excel 2010, the function algorithm was
2257
- * improved, so that it can now calculate the function for both positive and negative ranges.
2258
- * PHPExcel follows Excel 2010 behaviour, and accepts nagative arguments.
2259
- *
2260
- * Excel Function:
2261
- * ERF(lower[,upper])
2262
- *
2263
- * @param float $lower lower bound for integrating ERF
2264
- * @param float $upper upper bound for integrating ERF.
2265
- * If omitted, ERF integrates between zero and lower_limit
2266
- * @return float
2267
- */
2268
- public static function ERF($lower, $upper = NULL) {
2269
- $lower = PHPExcel_Calculation_Functions::flattenSingleValue($lower);
2270
- $upper = PHPExcel_Calculation_Functions::flattenSingleValue($upper);
2271
-
2272
- if (is_numeric($lower)) {
2273
- if (is_null($upper)) {
2274
- return self::_erfVal($lower);
2275
- }
2276
- if (is_numeric($upper)) {
2277
- return self::_erfVal($upper) - self::_erfVal($lower);
2278
- }
2279
- }
2280
- return PHPExcel_Calculation_Functions::VALUE();
2281
- } // function ERF()
2282
-
2283
-
2284
- //
2285
- // Private method to calculate the erfc value
2286
- //
2287
- private static $_one_sqrtpi = 0.564189583547756287;
2288
-
2289
- private static function _erfcVal($x) {
2290
- if (abs($x) < 2.2) {
2291
- return 1 - self::_erfVal($x);
2292
- }
2293
- if ($x < 0) {
2294
- return 2 - self::ERFC(-$x);
2295
- }
2296
- $a = $n = 1;
2297
- $b = $c = $x;
2298
- $d = ($x * $x) + 0.5;
2299
- $q1 = $q2 = $b / $d;
2300
- $t = 0;
2301
- do {
2302
- $t = $a * $n + $b * $x;
2303
- $a = $b;
2304
- $b = $t;
2305
- $t = $c * $n + $d * $x;
2306
- $c = $d;
2307
- $d = $t;
2308
- $n += 0.5;
2309
- $q1 = $q2;
2310
- $q2 = $b / $d;
2311
- } while ((abs($q1 - $q2) / $q2) > PRECISION);
2312
- return self::$_one_sqrtpi * exp(-$x * $x) * $q2;
2313
- } // function _erfcVal()
2314
-
2315
-
2316
- /**
2317
- * ERFC
2318
- *
2319
- * Returns the complementary ERF function integrated between x and infinity
2320
- *
2321
- * Note: In Excel 2007 or earlier, if you input a negative value for the lower bound argument,
2322
- * the function would return a #NUM! error. However, in Excel 2010, the function algorithm was
2323
- * improved, so that it can now calculate the function for both positive and negative x values.
2324
- * PHPExcel follows Excel 2010 behaviour, and accepts nagative arguments.
2325
- *
2326
- * Excel Function:
2327
- * ERFC(x)
2328
- *
2329
- * @param float $x The lower bound for integrating ERFC
2330
- * @return float
2331
- */
2332
- public static function ERFC($x) {
2333
- $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
2334
-
2335
- if (is_numeric($x)) {
2336
- return self::_erfcVal($x);
2337
- }
2338
- return PHPExcel_Calculation_Functions::VALUE();
2339
- } // function ERFC()
2340
-
2341
-
2342
- /**
2343
- * getConversionGroups
2344
- * Returns a list of the different conversion groups for UOM conversions
2345
- *
2346
- * @return array
2347
- */
2348
- public static function getConversionGroups() {
2349
- $conversionGroups = array();
2350
- foreach(self::$_conversionUnits as $conversionUnit) {
2351
- $conversionGroups[] = $conversionUnit['Group'];
2352
- }
2353
- return array_merge(array_unique($conversionGroups));
2354
- } // function getConversionGroups()
2355
-
2356
-
2357
- /**
2358
- * getConversionGroupUnits
2359
- * Returns an array of units of measure, for a specified conversion group, or for all groups
2360
- *
2361
- * @param string $group The group whose units of measure you want to retrieve
2362
- * @return array
2363
- */
2364
- public static function getConversionGroupUnits($group = NULL) {
2365
- $conversionGroups = array();
2366
- foreach(self::$_conversionUnits as $conversionUnit => $conversionGroup) {
2367
- if ((is_null($group)) || ($conversionGroup['Group'] == $group)) {
2368
- $conversionGroups[$conversionGroup['Group']][] = $conversionUnit;
2369
- }
2370
- }
2371
- return $conversionGroups;
2372
- } // function getConversionGroupUnits()
2373
-
2374
-
2375
- /**
2376
- * getConversionGroupUnitDetails
2377
- *
2378
- * @param string $group The group whose units of measure you want to retrieve
2379
- * @return array
2380
- */
2381
- public static function getConversionGroupUnitDetails($group = NULL) {
2382
- $conversionGroups = array();
2383
- foreach(self::$_conversionUnits as $conversionUnit => $conversionGroup) {
2384
- if ((is_null($group)) || ($conversionGroup['Group'] == $group)) {
2385
- $conversionGroups[$conversionGroup['Group']][] = array( 'unit' => $conversionUnit,
2386
- 'description' => $conversionGroup['Unit Name']
2387
- );
2388
- }
2389
- }
2390
- return $conversionGroups;
2391
- } // function getConversionGroupUnitDetails()
2392
-
2393
-
2394
- /**
2395
- * getConversionMultipliers
2396
- * Returns an array of the Multiplier prefixes that can be used with Units of Measure in CONVERTUOM()
2397
- *
2398
- * @return array of mixed
2399
- */
2400
- public static function getConversionMultipliers() {
2401
- return self::$_conversionMultipliers;
2402
- } // function getConversionGroups()
2403
-
2404
-
2405
- /**
2406
- * CONVERTUOM
2407
- *
2408
- * Converts a number from one measurement system to another.
2409
- * For example, CONVERT can translate a table of distances in miles to a table of distances
2410
- * in kilometers.
2411
- *
2412
- * Excel Function:
2413
- * CONVERT(value,fromUOM,toUOM)
2414
- *
2415
- * @param float $value The value in fromUOM to convert.
2416
- * @param string $fromUOM The units for value.
2417
- * @param string $toUOM The units for the result.
2418
- *
2419
- * @return float
2420
- */
2421
- public static function CONVERTUOM($value, $fromUOM, $toUOM) {
2422
- $value = PHPExcel_Calculation_Functions::flattenSingleValue($value);
2423
- $fromUOM = PHPExcel_Calculation_Functions::flattenSingleValue($fromUOM);
2424
- $toUOM = PHPExcel_Calculation_Functions::flattenSingleValue($toUOM);
2425
-
2426
- if (!is_numeric($value)) {
2427
- return PHPExcel_Calculation_Functions::VALUE();
2428
- }
2429
- $fromMultiplier = 1.0;
2430
- if (isset(self::$_conversionUnits[$fromUOM])) {
2431
- $unitGroup1 = self::$_conversionUnits[$fromUOM]['Group'];
2432
- } else {
2433
- $fromMultiplier = substr($fromUOM,0,1);
2434
- $fromUOM = substr($fromUOM,1);
2435
- if (isset(self::$_conversionMultipliers[$fromMultiplier])) {
2436
- $fromMultiplier = self::$_conversionMultipliers[$fromMultiplier]['multiplier'];
2437
- } else {
2438
- return PHPExcel_Calculation_Functions::NA();
2439
- }
2440
- if ((isset(self::$_conversionUnits[$fromUOM])) && (self::$_conversionUnits[$fromUOM]['AllowPrefix'])) {
2441
- $unitGroup1 = self::$_conversionUnits[$fromUOM]['Group'];
2442
- } else {
2443
- return PHPExcel_Calculation_Functions::NA();
2444
- }
2445
- }
2446
- $value *= $fromMultiplier;
2447
-
2448
- $toMultiplier = 1.0;
2449
- if (isset(self::$_conversionUnits[$toUOM])) {
2450
- $unitGroup2 = self::$_conversionUnits[$toUOM]['Group'];
2451
- } else {
2452
- $toMultiplier = substr($toUOM,0,1);
2453
- $toUOM = substr($toUOM,1);
2454
- if (isset(self::$_conversionMultipliers[$toMultiplier])) {
2455
- $toMultiplier = self::$_conversionMultipliers[$toMultiplier]['multiplier'];
2456
- } else {
2457
- return PHPExcel_Calculation_Functions::NA();
2458
- }
2459
- if ((isset(self::$_conversionUnits[$toUOM])) && (self::$_conversionUnits[$toUOM]['AllowPrefix'])) {
2460
- $unitGroup2 = self::$_conversionUnits[$toUOM]['Group'];
2461
- } else {
2462
- return PHPExcel_Calculation_Functions::NA();
2463
- }
2464
- }
2465
- if ($unitGroup1 != $unitGroup2) {
2466
- return PHPExcel_Calculation_Functions::NA();
2467
- }
2468
-
2469
- if (($fromUOM == $toUOM) && ($fromMultiplier == $toMultiplier)) {
2470
- // We've already factored $fromMultiplier into the value, so we need
2471
- // to reverse it again
2472
- return $value / $fromMultiplier;
2473
- } elseif ($unitGroup1 == 'Temperature') {
2474
- if (($fromUOM == 'F') || ($fromUOM == 'fah')) {
2475
- if (($toUOM == 'F') || ($toUOM == 'fah')) {
2476
- return $value;
2477
- } else {
2478
- $value = (($value - 32) / 1.8);
2479
- if (($toUOM == 'K') || ($toUOM == 'kel')) {
2480
- $value += 273.15;
2481
- }
2482
- return $value;
2483
- }
2484
- } elseif ((($fromUOM == 'K') || ($fromUOM == 'kel')) &&
2485
- (($toUOM == 'K') || ($toUOM == 'kel'))) {
2486
- return $value;
2487
- } elseif ((($fromUOM == 'C') || ($fromUOM == 'cel')) &&
2488
- (($toUOM == 'C') || ($toUOM == 'cel'))) {
2489
- return $value;
2490
- }
2491
- if (($toUOM == 'F') || ($toUOM == 'fah')) {
2492
- if (($fromUOM == 'K') || ($fromUOM == 'kel')) {
2493
- $value -= 273.15;
2494
- }
2495
- return ($value * 1.8) + 32;
2496
- }
2497
- if (($toUOM == 'C') || ($toUOM == 'cel')) {
2498
- return $value - 273.15;
2499
- }
2500
- return $value + 273.15;
2501
- }
2502
- return ($value * self::$_unitConversions[$unitGroup1][$fromUOM][$toUOM]) / $toMultiplier;
2503
- } // function CONVERTUOM()
2504
-
2505
- } // class PHPExcel_Calculation_Engineering
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /** PHPExcel root directory */
4
+ if (!defined('PHPEXCEL_ROOT')) {
5
+ /**
6
+ * @ignore
7
+ */
8
+ define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
9
+ require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
10
+ }
11
+
12
+ /** EULER */
13
+ define('EULER', 2.71828182845904523536);
14
+
15
+ /**
16
+ * PHPExcel_Calculation_Engineering
17
+ *
18
+ * Copyright (c) 2006 - 2015 PHPExcel
19
+ *
20
+ * This library is free software; you can redistribute it and/or
21
+ * modify it under the terms of the GNU Lesser General Public
22
+ * License as published by the Free Software Foundation; either
23
+ * version 2.1 of the License, or (at your option) any later version.
24
+ *
25
+ * This library is distributed in the hope that it will be useful,
26
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
27
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28
+ * Lesser General Public License for more details.
29
+ *
30
+ * You should have received a copy of the GNU Lesser General Public
31
+ * License along with this library; if not, write to the Free Software
32
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
33
+ *
34
+ * @category PHPExcel
35
+ * @package PHPExcel_Calculation
36
+ * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
37
+ * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
38
+ * @version ##VERSION##, ##DATE##
39
+ */
40
+ class PHPExcel_Calculation_Engineering
41
+ {
42
+ /**
43
+ * Details of the Units of measure that can be used in CONVERTUOM()
44
+ *
45
+ * @var mixed[]
46
+ */
47
+ private static $conversionUnits = array(
48
+ 'g' => array('Group' => 'Mass', 'Unit Name' => 'Gram', 'AllowPrefix' => true),
49
+ 'sg' => array('Group' => 'Mass', 'Unit Name' => 'Slug', 'AllowPrefix' => false),
50
+ 'lbm' => array('Group' => 'Mass', 'Unit Name' => 'Pound mass (avoirdupois)', 'AllowPrefix' => false),
51
+ 'u' => array('Group' => 'Mass', 'Unit Name' => 'U (atomic mass unit)', 'AllowPrefix' => true),
52
+ 'ozm' => array('Group' => 'Mass', 'Unit Name' => 'Ounce mass (avoirdupois)', 'AllowPrefix' => false),
53
+ 'm' => array('Group' => 'Distance', 'Unit Name' => 'Meter', 'AllowPrefix' => true),
54
+ 'mi' => array('Group' => 'Distance', 'Unit Name' => 'Statute mile', 'AllowPrefix' => false),
55
+ 'Nmi' => array('Group' => 'Distance', 'Unit Name' => 'Nautical mile', 'AllowPrefix' => false),
56
+ 'in' => array('Group' => 'Distance', 'Unit Name' => 'Inch', 'AllowPrefix' => false),
57
+ 'ft' => array('Group' => 'Distance', 'Unit Name' => 'Foot', 'AllowPrefix' => false),
58
+ 'yd' => array('Group' => 'Distance', 'Unit Name' => 'Yard', 'AllowPrefix' => false),
59
+ 'ang' => array('Group' => 'Distance', 'Unit Name' => 'Angstrom', 'AllowPrefix' => true),
60
+ 'Pica' => array('Group' => 'Distance', 'Unit Name' => 'Pica (1/72 in)', 'AllowPrefix' => false),
61
+ 'yr' => array('Group' => 'Time', 'Unit Name' => 'Year', 'AllowPrefix' => false),
62
+ 'day' => array('Group' => 'Time', 'Unit Name' => 'Day', 'AllowPrefix' => false),
63
+ 'hr' => array('Group' => 'Time', 'Unit Name' => 'Hour', 'AllowPrefix' => false),
64
+ 'mn' => array('Group' => 'Time', 'Unit Name' => 'Minute', 'AllowPrefix' => false),
65
+ 'sec' => array('Group' => 'Time', 'Unit Name' => 'Second', 'AllowPrefix' => true),
66
+ 'Pa' => array('Group' => 'Pressure', 'Unit Name' => 'Pascal', 'AllowPrefix' => true),
67
+ 'p' => array('Group' => 'Pressure', 'Unit Name' => 'Pascal', 'AllowPrefix' => true),
68
+ 'atm' => array('Group' => 'Pressure', 'Unit Name' => 'Atmosphere', 'AllowPrefix' => true),
69
+ 'at' => array('Group' => 'Pressure', 'Unit Name' => 'Atmosphere', 'AllowPrefix' => true),
70
+ 'mmHg' => array('Group' => 'Pressure', 'Unit Name' => 'mm of Mercury', 'AllowPrefix' => true),
71
+ 'N' => array('Group' => 'Force', 'Unit Name' => 'Newton', 'AllowPrefix' => true),
72
+ 'dyn' => array('Group' => 'Force', 'Unit Name' => 'Dyne', 'AllowPrefix' => true),
73
+ 'dy' => array('Group' => 'Force', 'Unit Name' => 'Dyne', 'AllowPrefix' => true),
74
+ 'lbf' => array('Group' => 'Force', 'Unit Name' => 'Pound force', 'AllowPrefix' => false),
75
+ 'J' => array('Group' => 'Energy', 'Unit Name' => 'Joule', 'AllowPrefix' => true),
76
+ 'e' => array('Group' => 'Energy', 'Unit Name' => 'Erg', 'AllowPrefix' => true),
77
+ 'c' => array('Group' => 'Energy', 'Unit Name' => 'Thermodynamic calorie', 'AllowPrefix' => true),
78
+ 'cal' => array('Group' => 'Energy', 'Unit Name' => 'IT calorie', 'AllowPrefix' => true),
79
+ 'eV' => array('Group' => 'Energy', 'Unit Name' => 'Electron volt', 'AllowPrefix' => true),
80
+ 'ev' => array('Group' => 'Energy', 'Unit Name' => 'Electron volt', 'AllowPrefix' => true),
81
+ 'HPh' => array('Group' => 'Energy', 'Unit Name' => 'Horsepower-hour', 'AllowPrefix' => false),
82
+ 'hh' => array('Group' => 'Energy', 'Unit Name' => 'Horsepower-hour', 'AllowPrefix' => false),
83
+ 'Wh' => array('Group' => 'Energy', 'Unit Name' => 'Watt-hour', 'AllowPrefix' => true),
84
+ 'wh' => array('Group' => 'Energy', 'Unit Name' => 'Watt-hour', 'AllowPrefix' => true),
85
+ 'flb' => array('Group' => 'Energy', 'Unit Name' => 'Foot-pound', 'AllowPrefix' => false),
86
+ 'BTU' => array('Group' => 'Energy', 'Unit Name' => 'BTU', 'AllowPrefix' => false),
87
+ 'btu' => array('Group' => 'Energy', 'Unit Name' => 'BTU', 'AllowPrefix' => false),
88
+ 'HP' => array('Group' => 'Power', 'Unit Name' => 'Horsepower', 'AllowPrefix' => false),
89
+ 'h' => array('Group' => 'Power', 'Unit Name' => 'Horsepower', 'AllowPrefix' => false),
90
+ 'W' => array('Group' => 'Power', 'Unit Name' => 'Watt', 'AllowPrefix' => true),
91
+ 'w' => array('Group' => 'Power', 'Unit Name' => 'Watt', 'AllowPrefix' => true),
92
+ 'T' => array('Group' => 'Magnetism', 'Unit Name' => 'Tesla', 'AllowPrefix' => true),
93
+ 'ga' => array('Group' => 'Magnetism', 'Unit Name' => 'Gauss', 'AllowPrefix' => true),
94
+ 'C' => array('Group' => 'Temperature', 'Unit Name' => 'Celsius', 'AllowPrefix' => false),
95
+ 'cel' => array('Group' => 'Temperature', 'Unit Name' => 'Celsius', 'AllowPrefix' => false),
96
+ 'F' => array('Group' => 'Temperature', 'Unit Name' => 'Fahrenheit', 'AllowPrefix' => false),
97
+ 'fah' => array('Group' => 'Temperature', 'Unit Name' => 'Fahrenheit', 'AllowPrefix' => false),
98
+ 'K' => array('Group' => 'Temperature', 'Unit Name' => 'Kelvin', 'AllowPrefix' => false),
99
+ 'kel' => array('Group' => 'Temperature', 'Unit Name' => 'Kelvin', 'AllowPrefix' => false),
100
+ 'tsp' => array('Group' => 'Liquid', 'Unit Name' => 'Teaspoon', 'AllowPrefix' => false),
101
+ 'tbs' => array('Group' => 'Liquid', 'Unit Name' => 'Tablespoon', 'AllowPrefix' => false),
102
+ 'oz' => array('Group' => 'Liquid', 'Unit Name' => 'Fluid Ounce', 'AllowPrefix' => false),
103
+ 'cup' => array('Group' => 'Liquid', 'Unit Name' => 'Cup', 'AllowPrefix' => false),
104
+ 'pt' => array('Group' => 'Liquid', 'Unit Name' => 'U.S. Pint', 'AllowPrefix' => false),
105
+ 'us_pt' => array('Group' => 'Liquid', 'Unit Name' => 'U.S. Pint', 'AllowPrefix' => false),
106
+ 'uk_pt' => array('Group' => 'Liquid', 'Unit Name' => 'U.K. Pint', 'AllowPrefix' => false),
107
+ 'qt' => array('Group' => 'Liquid', 'Unit Name' => 'Quart', 'AllowPrefix' => false),
108
+ 'gal' => array('Group' => 'Liquid', 'Unit Name' => 'Gallon', 'AllowPrefix' => false),
109
+ 'l' => array('Group' => 'Liquid', 'Unit Name' => 'Litre', 'AllowPrefix' => true),
110
+ 'lt' => array('Group' => 'Liquid', 'Unit Name' => 'Litre', 'AllowPrefix' => true),
111
+ );
112
+
113
+ /**
114
+ * Details of the Multiplier prefixes that can be used with Units of Measure in CONVERTUOM()
115
+ *
116
+ * @var mixed[]
117
+ */
118
+ private static $conversionMultipliers = array(
119
+ 'Y' => array('multiplier' => 1E24, 'name' => 'yotta'),
120
+ 'Z' => array('multiplier' => 1E21, 'name' => 'zetta'),
121
+ 'E' => array('multiplier' => 1E18, 'name' => 'exa'),
122
+ 'P' => array('multiplier' => 1E15, 'name' => 'peta'),
123
+ 'T' => array('multiplier' => 1E12, 'name' => 'tera'),
124
+ 'G' => array('multiplier' => 1E9, 'name' => 'giga'),
125
+ 'M' => array('multiplier' => 1E6, 'name' => 'mega'),
126
+ 'k' => array('multiplier' => 1E3, 'name' => 'kilo'),
127
+ 'h' => array('multiplier' => 1E2, 'name' => 'hecto'),
128
+ 'e' => array('multiplier' => 1E1, 'name' => 'deka'),
129
+ 'd' => array('multiplier' => 1E-1, 'name' => 'deci'),
130
+ 'c' => array('multiplier' => 1E-2, 'name' => 'centi'),
131
+ 'm' => array('multiplier' => 1E-3, 'name' => 'milli'),
132
+ 'u' => array('multiplier' => 1E-6, 'name' => 'micro'),
133
+ 'n' => array('multiplier' => 1E-9, 'name' => 'nano'),
134
+ 'p' => array('multiplier' => 1E-12, 'name' => 'pico'),
135
+ 'f' => array('multiplier' => 1E-15, 'name' => 'femto'),
136
+ 'a' => array('multiplier' => 1E-18, 'name' => 'atto'),
137
+ 'z' => array('multiplier' => 1E-21, 'name' => 'zepto'),
138
+ 'y' => array('multiplier' => 1E-24, 'name' => 'yocto'),
139
+ );
140
+
141
+ /**
142
+ * Details of the Units of measure conversion factors, organised by group
143
+ *
144
+ * @var mixed[]
145
+ */
146
+ private static $unitConversions = array(
147
+ 'Mass' => array(
148
+ 'g' => array(
149
+ 'g' => 1.0,
150
+ 'sg' => 6.85220500053478E-05,
151
+ 'lbm' => 2.20462291469134E-03,
152
+ 'u' => 6.02217000000000E+23,
153
+ 'ozm' => 3.52739718003627E-02,
154
+ ),
155
+ 'sg' => array(
156
+ 'g' => 1.45938424189287E+04,
157
+ 'sg' => 1.0,
158
+ 'lbm' => 3.21739194101647E+01,
159
+ 'u' => 8.78866000000000E+27,
160
+ 'ozm' => 5.14782785944229E+02,
161
+ ),
162
+ 'lbm' => array(
163
+ 'g' => 4.5359230974881148E+02,
164
+ 'sg' => 3.10810749306493E-02,
165
+ 'lbm' => 1.0,
166
+ 'u' => 2.73161000000000E+26,
167
+ 'ozm' => 1.60000023429410E+01,
168
+ ),
169
+ 'u' => array(
170
+ 'g' => 1.66053100460465E-24,
171
+ 'sg' => 1.13782988532950E-28,
172
+ 'lbm' => 3.66084470330684E-27,
173
+ 'u' => 1.0,
174
+ 'ozm' => 5.85735238300524E-26,
175
+ ),
176
+ 'ozm' => array(
177
+ 'g' => 2.83495152079732E+01,
178
+ 'sg' => 1.94256689870811E-03,
179
+ 'lbm' => 6.24999908478882E-02,
180
+ 'u' => 1.70725600000000E+25,
181
+ 'ozm' => 1.0,
182
+ ),
183
+ ),
184
+ 'Distance' => array(
185
+ 'm' => array(
186
+ 'm' => 1.0,
187
+ 'mi' => 6.21371192237334E-04,
188
+ 'Nmi' => 5.39956803455724E-04,
189
+ 'in' => 3.93700787401575E+01,
190
+ 'ft' => 3.28083989501312E+00,
191
+ 'yd' => 1.09361329797891E+00,
192
+ 'ang' => 1.00000000000000E+10,
193
+ 'Pica' => 2.83464566929116E+03,
194
+ ),
195
+ 'mi' => array(
196
+ 'm' => 1.60934400000000E+03,
197
+ 'mi' => 1.0,
198
+ 'Nmi' => 8.68976241900648E-01,
199
+ 'in' => 6.33600000000000E+04,
200
+ 'ft' => 5.28000000000000E+03,
201
+ 'yd' => 1.76000000000000E+03,
202
+ 'ang' => 1.60934400000000E+13,
203
+ 'Pica' => 4.56191999999971E+06,
204
+ ),
205
+ 'Nmi' => array(
206
+ 'm' => 1.85200000000000E+03,
207
+ 'mi' => 1.15077944802354E+00,
208
+ 'Nmi' => 1.0,
209
+ 'in' => 7.29133858267717E+04,
210
+ 'ft' => 6.07611548556430E+03,
211
+ 'yd' => 2.02537182785694E+03,
212
+ 'ang' => 1.85200000000000E+13,
213
+ 'Pica' => 5.24976377952723E+06,
214
+ ),
215
+ 'in' => array(
216
+ 'm' => 2.54000000000000E-02,
217
+ 'mi' => 1.57828282828283E-05,
218
+ 'Nmi' => 1.37149028077754E-05,
219
+ 'in' => 1.0,
220
+ 'ft' => 8.33333333333333E-02,
221
+ 'yd' => 2.77777777686643E-02,
222
+ 'ang' => 2.54000000000000E+08,
223
+ 'Pica' => 7.19999999999955E+01,
224
+ ),
225
+ 'ft' => array(
226
+ 'm' => 3.04800000000000E-01,
227
+ 'mi' => 1.89393939393939E-04,
228
+ 'Nmi' => 1.64578833693305E-04,
229
+ 'in' => 1.20000000000000E+01,
230
+ 'ft' => 1.0,
231
+ 'yd' => 3.33333333223972E-01,
232
+ 'ang' => 3.04800000000000E+09,
233
+ 'Pica' => 8.63999999999946E+02,
234
+ ),
235
+ 'yd' => array(
236
+ 'm' => 9.14400000300000E-01,
237
+ 'mi' => 5.68181818368230E-04,
238
+ 'Nmi' => 4.93736501241901E-04,
239
+ 'in' => 3.60000000118110E+01,
240
+ 'ft' => 3.00000000000000E+00,
241
+ 'yd' => 1.0,
242
+ 'ang' => 9.14400000300000E+09,
243
+ 'Pica' => 2.59200000085023E+03,
244
+ ),
245
+ 'ang' => array(
246
+ 'm' => 1.00000000000000E-10,
247
+ 'mi' => 6.21371192237334E-14,
248
+ 'Nmi' => 5.39956803455724E-14,
249
+ 'in' => 3.93700787401575E-09,
250
+ 'ft' => 3.28083989501312E-10,
251
+ 'yd' => 1.09361329797891E-10,
252
+ 'ang' => 1.0,
253
+ 'Pica' => 2.83464566929116E-07,
254
+ ),
255
+ 'Pica' => array(
256
+ 'm' => 3.52777777777800E-04,
257
+ 'mi' => 2.19205948372629E-07,
258
+ 'Nmi' => 1.90484761219114E-07,
259
+ 'in' => 1.38888888888898E-02,
260
+ 'ft' => 1.15740740740748E-03,
261
+ 'yd' => 3.85802469009251E-04,
262
+ 'ang' => 3.52777777777800E+06,
263
+ 'Pica' => 1.0,
264
+ ),
265
+ ),
266
+ 'Time' => array(
267
+ 'yr' => array(
268
+ 'yr' => 1.0,
269
+ 'day' => 365.25,
270
+ 'hr' => 8766.0,
271
+ 'mn' => 525960.0,
272
+ 'sec' => 31557600.0,
273
+ ),
274
+ 'day' => array(
275
+ 'yr' => 2.73785078713210E-03,
276
+ 'day' => 1.0,
277
+ 'hr' => 24.0,
278
+ 'mn' => 1440.0,
279
+ 'sec' => 86400.0,
280
+ ),
281
+ 'hr' => array(
282
+ 'yr' => 1.14077116130504E-04,
283
+ 'day' => 4.16666666666667E-02,
284
+ 'hr' => 1.0,
285
+ 'mn' => 60.0,
286
+ 'sec' => 3600.0,
287
+ ),
288
+ 'mn' => array(
289
+ 'yr' => 1.90128526884174E-06,
290
+ 'day' => 6.94444444444444E-04,
291
+ 'hr' => 1.66666666666667E-02,
292
+ 'mn' => 1.0,
293
+ 'sec' => 60.0,
294
+ ),
295
+ 'sec' => array(
296
+ 'yr' => 3.16880878140289E-08,
297
+ 'day' => 1.15740740740741E-05,
298
+ 'hr' => 2.77777777777778E-04,
299
+ 'mn' => 1.66666666666667E-02,
300
+ 'sec' => 1.0,
301
+ ),
302
+ ),
303
+ 'Pressure' => array(
304
+ 'Pa' => array(
305
+ 'Pa' => 1.0,
306
+ 'p' => 1.0,
307
+ 'atm' => 9.86923299998193E-06,
308
+ 'at' => 9.86923299998193E-06,
309
+ 'mmHg' => 7.50061707998627E-03,
310
+ ),
311
+ 'p' => array(
312
+ 'Pa' => 1.0,
313
+ 'p' => 1.0,
314
+ 'atm' => 9.86923299998193E-06,
315
+ 'at' => 9.86923299998193E-06,
316
+ 'mmHg' => 7.50061707998627E-03,
317
+ ),
318
+ 'atm' => array(
319
+ 'Pa' => 1.01324996583000E+05,
320
+ 'p' => 1.01324996583000E+05,
321
+ 'atm' => 1.0,
322
+ 'at' => 1.0,
323
+ 'mmHg' => 760.0,
324
+ ),
325
+ 'at' => array(
326
+ 'Pa' => 1.01324996583000E+05,
327
+ 'p' => 1.01324996583000E+05,
328
+ 'atm' => 1.0,
329
+ 'at' => 1.0,
330
+ 'mmHg' => 760.0,
331
+ ),
332
+ 'mmHg' => array(
333
+ 'Pa' => 1.33322363925000E+02,
334
+ 'p' => 1.33322363925000E+02,
335
+ 'atm' => 1.31578947368421E-03,
336
+ 'at' => 1.31578947368421E-03,
337
+ 'mmHg' => 1.0,
338
+ ),
339
+ ),
340
+ 'Force' => array(
341
+ 'N' => array(
342
+ 'N' => 1.0,
343
+ 'dyn' => 1.0E+5,
344
+ 'dy' => 1.0E+5,
345
+ 'lbf' => 2.24808923655339E-01,
346
+ ),
347
+ 'dyn' => array(
348
+ 'N' => 1.0E-5,
349
+ 'dyn' => 1.0,
350
+ 'dy' => 1.0,
351
+ 'lbf' => 2.24808923655339E-06,
352
+ ),
353
+ 'dy' => array(
354
+ 'N' => 1.0E-5,
355
+ 'dyn' => 1.0,
356
+ 'dy' => 1.0,
357
+ 'lbf' => 2.24808923655339E-06,
358
+ ),
359
+ 'lbf' => array(
360
+ 'N' => 4.448222,
361
+ 'dyn' => 4.448222E+5,
362
+ 'dy' => 4.448222E+5,
363
+ 'lbf' => 1.0,
364
+ ),
365
+ ),
366
+ 'Energy' => array(
367
+ 'J' => array(
368
+ 'J' => 1.0,
369
+ 'e' => 9.99999519343231E+06,
370
+ 'c' => 2.39006249473467E-01,
371
+ 'cal' => 2.38846190642017E-01,
372
+ 'eV' => 6.24145700000000E+18,
373
+ 'ev' => 6.24145700000000E+18,
374
+ 'HPh' => 3.72506430801000E-07,
375
+ 'hh' => 3.72506430801000E-07,
376
+ 'Wh' => 2.77777916238711E-04,
377
+ 'wh' => 2.77777916238711E-04,
378
+ 'flb' => 2.37304222192651E+01,
379
+ 'BTU' => 9.47815067349015E-04,
380
+ 'btu' => 9.47815067349015E-04,
381
+ ),
382
+ 'e' => array(
383
+ 'J' => 1.00000048065700E-07,
384
+ 'e' => 1.0,
385
+ 'c' => 2.39006364353494E-08,
386
+ 'cal' => 2.38846305445111E-08,
387
+ 'eV' => 6.24146000000000E+11,
388
+ 'ev' => 6.24146000000000E+11,
389
+ 'HPh' => 3.72506609848824E-14,
390
+ 'hh' => 3.72506609848824E-14,
391
+ 'Wh' => 2.77778049754611E-11,
392
+ 'wh' => 2.77778049754611E-11,
393
+ 'flb' => 2.37304336254586E-06,
394
+ 'BTU' => 9.47815522922962E-11,
395
+ 'btu' => 9.47815522922962E-11,
396
+ ),
397
+ 'c' => array(
398
+ 'J' => 4.18399101363672E+00,
399
+ 'e' => 4.18398900257312E+07,
400
+ 'c' => 1.0,
401
+ 'cal' => 9.99330315287563E-01,
402
+ 'eV' => 2.61142000000000E+19,
403
+ 'ev' => 2.61142000000000E+19,
404
+ 'HPh' => 1.55856355899327E-06,
405
+ 'hh' => 1.55856355899327E-06,
406
+ 'Wh' => 1.16222030532950E-03,
407
+ 'wh' => 1.16222030532950E-03,
408
+ 'flb' => 9.92878733152102E+01,
409
+ 'BTU' => 3.96564972437776E-03,
410
+ 'btu' => 3.96564972437776E-03,
411
+ ),
412
+ 'cal' => array(
413
+ 'J' => 4.18679484613929E+00,
414
+ 'e' => 4.18679283372801E+07,
415
+ 'c' => 1.00067013349059E+00,
416
+ 'cal' => 1.0,
417
+ 'eV' => 2.61317000000000E+19,
418
+ 'ev' => 2.61317000000000E+19,
419
+ 'HPh' => 1.55960800463137E-06,
420
+ 'hh' => 1.55960800463137E-06,
421
+ 'Wh' => 1.16299914807955E-03,
422
+ 'wh' => 1.16299914807955E-03,
423
+ 'flb' => 9.93544094443283E+01,
424
+ 'BTU' => 3.96830723907002E-03,
425
+ 'btu' => 3.96830723907002E-03,
426
+ ),
427
+ 'eV' => array(
428
+ 'J' => 1.60219000146921E-19,
429
+ 'e' => 1.60218923136574E-12,
430
+ 'c' => 3.82933423195043E-20,
431
+ 'cal' => 3.82676978535648E-20,
432
+ 'eV' => 1.0,
433
+ 'ev' => 1.0,
434
+ 'HPh' => 5.96826078912344E-26,
435
+ 'hh' => 5.96826078912344E-26,
436
+ 'Wh' => 4.45053000026614E-23,
437
+ 'wh' => 4.45053000026614E-23,
438
+ 'flb' => 3.80206452103492E-18,
439
+ 'BTU' => 1.51857982414846E-22,
440
+ 'btu' => 1.51857982414846E-22,
441
+ ),
442
+ 'ev' => array(
443
+ 'J' => 1.60219000146921E-19,
444
+ 'e' => 1.60218923136574E-12,
445
+ 'c' => 3.82933423195043E-20,
446
+ 'cal' => 3.82676978535648E-20,
447
+ 'eV' => 1.0,
448
+ 'ev' => 1.0,
449
+ 'HPh' => 5.96826078912344E-26,
450
+ 'hh' => 5.96826078912344E-26,
451
+ 'Wh' => 4.45053000026614E-23,
452
+ 'wh' => 4.45053000026614E-23,
453
+ 'flb' => 3.80206452103492E-18,
454
+ 'BTU' => 1.51857982414846E-22,
455
+ 'btu' => 1.51857982414846E-22,
456
+ ),
457
+ 'HPh' => array(
458
+ 'J' => 2.68451741316170E+06,
459
+ 'e' => 2.68451612283024E+13,
460
+ 'c' => 6.41616438565991E+05,
461
+ 'cal' => 6.41186757845835E+05,
462
+ 'eV' => 1.67553000000000E+25,
463
+ 'ev' => 1.67553000000000E+25,
464
+ 'HPh' => 1.0,
465
+ 'hh' => 1.0,
466
+ 'Wh' => 7.45699653134593E+02,
467
+ 'wh' => 7.45699653134593E+02,
468
+ 'flb' => 6.37047316692964E+07,
469
+ 'BTU' => 2.54442605275546E+03,
470
+ 'btu' => 2.54442605275546E+03,
471
+ ),
472
+ 'hh' => array(
473
+ 'J' => 2.68451741316170E+06,
474
+ 'e' => 2.68451612283024E+13,
475
+ 'c' => 6.41616438565991E+05,
476
+ 'cal' => 6.41186757845835E+05,
477
+ 'eV' => 1.67553000000000E+25,
478
+ 'ev' => 1.67553000000000E+25,
479
+ 'HPh' => 1.0,
480
+ 'hh' => 1.0,
481
+ 'Wh' => 7.45699653134593E+02,
482
+ 'wh' => 7.45699653134593E+02,
483
+ 'flb' => 6.37047316692964E+07,
484
+ 'BTU' => 2.54442605275546E+03,
485
+ 'btu' => 2.54442605275546E+03,
486
+ ),
487
+ 'Wh' => array(
488
+ 'J' => 3.59999820554720E+03,
489
+ 'e' => 3.59999647518369E+10,
490
+ 'c' => 8.60422069219046E+02,
491
+ 'cal' => 8.59845857713046E+02,
492
+ 'eV' => 2.24692340000000E+22,
493
+ 'ev' => 2.24692340000000E+22,
494
+ 'HPh' => 1.34102248243839E-03,
495
+ 'hh' => 1.34102248243839E-03,
496
+ 'Wh' => 1.0,
497
+ 'wh' => 1.0,
498
+ 'flb' => 8.54294774062316E+04,
499
+ 'BTU' => 3.41213254164705E+00,
500
+ 'btu' => 3.41213254164705E+00,
501
+ ),
502
+ 'wh' => array(
503
+ 'J' => 3.59999820554720E+03,
504
+ 'e' => 3.59999647518369E+10,
505
+ 'c' => 8.60422069219046E+02,
506
+ 'cal' => 8.59845857713046E+02,
507
+ 'eV' => 2.24692340000000E+22,
508
+ 'ev' => 2.24692340000000E+22,
509
+ 'HPh' => 1.34102248243839E-03,
510
+ 'hh' => 1.34102248243839E-03,
511
+ 'Wh' => 1.0,
512
+ 'wh' => 1.0,
513
+ 'flb' => 8.54294774062316E+04,
514
+ 'BTU' => 3.41213254164705E+00,
515
+ 'btu' => 3.41213254164705E+00,
516
+ ),
517
+ 'flb' => array(
518
+ 'J' => 4.21400003236424E-02,
519
+ 'e' => 4.21399800687660E+05,
520
+ 'c' => 1.00717234301644E-02,
521
+ 'cal' => 1.00649785509554E-02,
522
+ 'eV' => 2.63015000000000E+17,
523
+ 'ev' => 2.63015000000000E+17,
524
+ 'HPh' => 1.56974211145130E-08,
525
+ 'hh' => 1.56974211145130E-08,
526
+ 'Wh' => 1.17055614802000E-05,
527
+ 'wh' => 1.17055614802000E-05,
528
+ 'flb' => 1.0,
529
+ 'BTU' => 3.99409272448406E-05,
530
+ 'btu' => 3.99409272448406E-05,
531
+ ),
532
+ 'BTU' => array(
533
+ 'J' => 1.05505813786749E+03,
534
+ 'e' => 1.05505763074665E+10,
535
+ 'c' => 2.52165488508168E+02,
536
+ 'cal' => 2.51996617135510E+02,
537
+ 'eV' => 6.58510000000000E+21,
538
+ 'ev' => 6.58510000000000E+21,
539
+ 'HPh' => 3.93015941224568E-04,
540
+ 'hh' => 3.93015941224568E-04,
541
+ 'Wh' => 2.93071851047526E-01,
542
+ 'wh' => 2.93071851047526E-01,
543
+ 'flb' => 2.50369750774671E+04,
544
+ 'BTU' => 1.0,
545
+ 'btu' => 1.0,
546
+ ),
547
+ 'btu' => array(
548
+ 'J' => 1.05505813786749E+03,
549
+ 'e' => 1.05505763074665E+10,
550
+ 'c' => 2.52165488508168E+02,
551
+ 'cal' => 2.51996617135510E+02,
552
+ 'eV' => 6.58510000000000E+21,
553
+ 'ev' => 6.58510000000000E+21,
554
+ 'HPh' => 3.93015941224568E-04,
555
+ 'hh' => 3.93015941224568E-04,
556
+ 'Wh' => 2.93071851047526E-01,
557
+ 'wh' => 2.93071851047526E-01,
558
+ 'flb' => 2.50369750774671E+04,
559
+ 'BTU' => 1.0,
560
+ 'btu' => 1.0,
561
+ ),
562
+ ),
563
+ 'Power' => array(
564
+ 'HP' => array(
565
+ 'HP' => 1.0,
566
+ 'h' => 1.0,
567
+ 'W' => 7.45701000000000E+02,
568
+ 'w' => 7.45701000000000E+02,
569
+ ),
570
+ 'h' => array(
571
+ 'HP' => 1.0,
572
+ 'h' => 1.0,
573
+ 'W' => 7.45701000000000E+02,
574
+ 'w' => 7.45701000000000E+02,
575
+ ),
576
+ 'W' => array(
577
+ 'HP' => 1.34102006031908E-03,
578
+ 'h' => 1.34102006031908E-03,
579
+ 'W' => 1.0,
580
+ 'w' => 1.0,
581
+ ),
582
+ 'w' => array(
583
+ 'HP' => 1.34102006031908E-03,
584
+ 'h' => 1.34102006031908E-03,
585
+ 'W' => 1.0,
586
+ 'w' => 1.0,
587
+ ),
588
+ ),
589
+ 'Magnetism' => array(
590
+ 'T' => array(
591
+ 'T' => 1.0,
592
+ 'ga' => 10000.0,
593
+ ),
594
+ 'ga' => array(
595
+ 'T' => 0.0001,
596
+ 'ga' => 1.0,
597
+ ),
598
+ ),
599
+ 'Liquid' => array(
600
+ 'tsp' => array(
601
+ 'tsp' => 1.0,
602
+ 'tbs' => 3.33333333333333E-01,
603
+ 'oz' => 1.66666666666667E-01,
604
+ 'cup' => 2.08333333333333E-02,
605
+ 'pt' => 1.04166666666667E-02,
606
+ 'us_pt' => 1.04166666666667E-02,
607
+ 'uk_pt' => 8.67558516821960E-03,
608
+ 'qt' => 5.20833333333333E-03,
609
+ 'gal' => 1.30208333333333E-03,
610
+ 'l' => 4.92999408400710E-03,
611
+ 'lt' => 4.92999408400710E-03,
612
+ ),
613
+ 'tbs' => array(
614
+ 'tsp' => 3.00000000000000E+00,
615
+ 'tbs' => 1.0,
616
+ 'oz' => 5.00000000000000E-01,
617
+ 'cup' => 6.25000000000000E-02,
618
+ 'pt' => 3.12500000000000E-02,
619
+ 'us_pt' => 3.12500000000000E-02,
620
+ 'uk_pt' => 2.60267555046588E-02,
621
+ 'qt' => 1.56250000000000E-02,
622
+ 'gal' => 3.90625000000000E-03,
623
+ 'l' => 1.47899822520213E-02,
624
+ 'lt' => 1.47899822520213E-02,
625
+ ),
626
+ 'oz' => array(
627
+ 'tsp' => 6.00000000000000E+00,
628
+ 'tbs' => 2.00000000000000E+00,
629
+ 'oz' => 1.0,
630
+ 'cup' => 1.25000000000000E-01,
631
+ 'pt' => 6.25000000000000E-02,
632
+ 'us_pt' => 6.25000000000000E-02,
633
+ 'uk_pt' => 5.20535110093176E-02,
634
+ 'qt' => 3.12500000000000E-02,
635
+ 'gal' => 7.81250000000000E-03,
636
+ 'l' => 2.95799645040426E-02,
637
+ 'lt' => 2.95799645040426E-02,
638
+ ),
639
+ 'cup' => array(
640
+ 'tsp' => 4.80000000000000E+01,
641
+ 'tbs' => 1.60000000000000E+01,
642
+ 'oz' => 8.00000000000000E+00,
643
+ 'cup' => 1.0,
644
+ 'pt' => 5.00000000000000E-01,
645
+ 'us_pt' => 5.00000000000000E-01,
646
+ 'uk_pt' => 4.16428088074541E-01,
647
+ 'qt' => 2.50000000000000E-01,
648
+ 'gal' => 6.25000000000000E-02,
649
+ 'l' => 2.36639716032341E-01,
650
+ 'lt' => 2.36639716032341E-01,
651
+ ),
652
+ 'pt' => array(
653
+ 'tsp' => 9.60000000000000E+01,
654
+ 'tbs' => 3.20000000000000E+01,
655
+ 'oz' => 1.60000000000000E+01,
656
+ 'cup' => 2.00000000000000E+00,
657
+ 'pt' => 1.0,
658
+ 'us_pt' => 1.0,
659
+ 'uk_pt' => 8.32856176149081E-01,
660
+ 'qt' => 5.00000000000000E-01,
661
+ 'gal' => 1.25000000000000E-01,
662
+ 'l' => 4.73279432064682E-01,
663
+ 'lt' => 4.73279432064682E-01,
664
+ ),
665
+ 'us_pt' => array(
666
+ 'tsp' => 9.60000000000000E+01,
667
+ 'tbs' => 3.20000000000000E+01,
668
+ 'oz' => 1.60000000000000E+01,
669
+ 'cup' => 2.00000000000000E+00,
670
+ 'pt' => 1.0,
671
+ 'us_pt' => 1.0,
672
+ 'uk_pt' => 8.32856176149081E-01,
673
+ 'qt' => 5.00000000000000E-01,
674
+ 'gal' => 1.25000000000000E-01,
675
+ 'l' => 4.73279432064682E-01,
676
+ 'lt' => 4.73279432064682E-01,
677
+ ),
678
+ 'uk_pt' => array(
679
+ 'tsp' => 1.15266000000000E+02,
680
+ 'tbs' => 3.84220000000000E+01,
681
+ 'oz' => 1.92110000000000E+01,
682
+ 'cup' => 2.40137500000000E+00,
683
+ 'pt' => 1.20068750000000E+00,
684
+ 'us_pt' => 1.20068750000000E+00,
685
+ 'uk_pt' => 1.0,
686
+ 'qt' => 6.00343750000000E-01,
687
+ 'gal' => 1.50085937500000E-01,
688
+ 'l' => 5.68260698087162E-01,
689
+ 'lt' => 5.68260698087162E-01,
690
+ ),
691
+ 'qt' => array(
692
+ 'tsp' => 1.92000000000000E+02,
693
+ 'tbs' => 6.40000000000000E+01,
694
+ 'oz' => 3.20000000000000E+01,
695
+ 'cup' => 4.00000000000000E+00,
696
+ 'pt' => 2.00000000000000E+00,
697
+ 'us_pt' => 2.00000000000000E+00,
698
+ 'uk_pt' => 1.66571235229816E+00,
699
+ 'qt' => 1.0,
700
+ 'gal' => 2.50000000000000E-01,
701
+ 'l' => 9.46558864129363E-01,
702
+ 'lt' => 9.46558864129363E-01,
703
+ ),
704
+ 'gal' => array(
705
+ 'tsp' => 7.68000000000000E+02,
706
+ 'tbs' => 2.56000000000000E+02,
707
+ 'oz' => 1.28000000000000E+02,
708
+ 'cup' => 1.60000000000000E+01,
709
+ 'pt' => 8.00000000000000E+00,
710
+ 'us_pt' => 8.00000000000000E+00,
711
+ 'uk_pt' => 6.66284940919265E+00,
712
+ 'qt' => 4.00000000000000E+00,
713
+ 'gal' => 1.0,
714
+ 'l' => 3.78623545651745E+00,
715
+ 'lt' => 3.78623545651745E+00,
716
+ ),
717
+ 'l' => array(
718
+ 'tsp' => 2.02840000000000E+02,
719
+ 'tbs' => 6.76133333333333E+01,
720
+ 'oz' => 3.38066666666667E+01,
721
+ 'cup' => 4.22583333333333E+00,
722
+ 'pt' => 2.11291666666667E+00,
723
+ 'us_pt' => 2.11291666666667E+00,
724
+ 'uk_pt' => 1.75975569552166E+00,
725
+ 'qt' => 1.05645833333333E+00,
726
+ 'gal' => 2.64114583333333E-01,
727
+ 'l' => 1.0,
728
+ 'lt' => 1.0,
729
+ ),
730
+ 'lt' => array(
731
+ 'tsp' => 2.02840000000000E+02,
732
+ 'tbs' => 6.76133333333333E+01,
733
+ 'oz' => 3.38066666666667E+01,
734
+ 'cup' => 4.22583333333333E+00,
735
+ 'pt' => 2.11291666666667E+00,
736
+ 'us_pt' => 2.11291666666667E+00,
737
+ 'uk_pt' => 1.75975569552166E+00,
738
+ 'qt' => 1.05645833333333E+00,
739
+ 'gal' => 2.64114583333333E-01,
740
+ 'l' => 1.0,
741
+ 'lt' => 1.0,
742
+ ),
743
+ ),
744
+ );
745
+
746
+
747
+ /**
748
+ * parseComplex
749
+ *
750
+ * Parses a complex number into its real and imaginary parts, and an I or J suffix
751
+ *
752
+ * @param string $complexNumber The complex number
753
+ * @return string[] Indexed on "real", "imaginary" and "suffix"
754
+ */
755
+ public static function parseComplex($complexNumber)
756
+ {
757
+ $workString = (string) $complexNumber;
758
+
759
+ $realNumber = $imaginary = 0;
760
+ // Extract the suffix, if there is one
761
+ $suffix = substr($workString, -1);
762
+ if (!is_numeric($suffix)) {
763
+ $workString = substr($workString, 0, -1);
764
+ } else {
765
+ $suffix = '';
766
+ }
767
+
768
+ // Split the input into its Real and Imaginary components
769
+ $leadingSign = 0;
770
+ if (strlen($workString) > 0) {
771
+ $leadingSign = (($workString{0} == '+') || ($workString{0} == '-')) ? 1 : 0;
772
+ }
773
+ $power = '';
774
+ $realNumber = strtok($workString, '+-');
775
+ if (strtoupper(substr($realNumber, -1)) == 'E') {
776
+ $power = strtok('+-');
777
+ ++$leadingSign;
778
+ }
779
+
780
+ $realNumber = substr($workString, 0, strlen($realNumber)+strlen($power)+$leadingSign);
781
+
782
+ if ($suffix != '') {
783
+ $imaginary = substr($workString, strlen($realNumber));
784
+
785
+ if (($imaginary == '') && (($realNumber == '') || ($realNumber == '+') || ($realNumber == '-'))) {
786
+ $imaginary = $realNumber.'1';
787
+ $realNumber = '0';
788
+ } elseif ($imaginary == '') {
789
+ $imaginary = $realNumber;
790
+ $realNumber = '0';
791
+ } elseif (($imaginary == '+') || ($imaginary == '-')) {
792
+ $imaginary .= '1';
793
+ }
794
+ }
795
+
796
+ return array(
797
+ 'real' => $realNumber,
798
+ 'imaginary' => $imaginary,
799
+ 'suffix' => $suffix
800
+ );
801
+ }
802
+
803
+
804
+ /**
805
+ * Cleans the leading characters in a complex number string
806
+ *
807
+ * @param string $complexNumber The complex number to clean
808
+ * @return string The "cleaned" complex number
809
+ */
810
+ private static function cleanComplex($complexNumber)
811
+ {
812
+ if ($complexNumber{0} == '+') {
813
+ $complexNumber = substr($complexNumber, 1);
814
+ }
815
+ if ($complexNumber{0} == '0') {
816
+ $complexNumber = substr($complexNumber, 1);
817
+ }
818
+ if ($complexNumber{0} == '.') {
819
+ $complexNumber = '0'.$complexNumber;
820
+ }
821
+ if ($complexNumber{0} == '+') {
822
+ $complexNumber = substr($complexNumber, 1);
823
+ }
824
+ return $complexNumber;
825
+ }
826
+
827
+ /**
828
+ * Formats a number base string value with leading zeroes
829
+ *
830
+ * @param string $xVal The "number" to pad
831
+ * @param integer $places The length that we want to pad this value
832
+ * @return string The padded "number"
833
+ */
834
+ private static function nbrConversionFormat($xVal, $places)
835
+ {
836
+ if (!is_null($places)) {
837
+ if (strlen($xVal) <= $places) {
838
+ return substr(str_pad($xVal, $places, '0', STR_PAD_LEFT), -10);
839
+ } else {
840
+ return PHPExcel_Calculation_Functions::NaN();
841
+ }
842
+ }
843
+
844
+ return substr($xVal, -10);
845
+ }
846
+
847
+ /**
848
+ * BESSELI
849
+ *
850
+ * Returns the modified Bessel function In(x), which is equivalent to the Bessel function evaluated
851
+ * for purely imaginary arguments
852
+ *
853
+ * Excel Function:
854
+ * BESSELI(x,ord)
855
+ *
856
+ * @access public
857
+ * @category Engineering Functions
858
+ * @param float $x The value at which to evaluate the function.
859
+ * If x is nonnumeric, BESSELI returns the #VALUE! error value.
860
+ * @param integer $ord The order of the Bessel function.
861
+ * If ord is not an integer, it is truncated.
862
+ * If $ord is nonnumeric, BESSELI returns the #VALUE! error value.
863
+ * If $ord < 0, BESSELI returns the #NUM! error value.
864
+ * @return float
865
+ *
866
+ */
867
+ public static function BESSELI($x, $ord)
868
+ {
869
+ $x = (is_null($x)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($x);
870
+ $ord = (is_null($ord)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($ord);
871
+
872
+ if ((is_numeric($x)) && (is_numeric($ord))) {
873
+ $ord = floor($ord);
874
+ if ($ord < 0) {
875
+ return PHPExcel_Calculation_Functions::NaN();
876
+ }
877
+
878
+ if (abs($x) <= 30) {
879
+ $fResult = $fTerm = pow($x / 2, $ord) / PHPExcel_Calculation_MathTrig::FACT($ord);
880
+ $ordK = 1;
881
+ $fSqrX = ($x * $x) / 4;
882
+ do {
883
+ $fTerm *= $fSqrX;
884
+ $fTerm /= ($ordK * ($ordK + $ord));
885
+ $fResult += $fTerm;
886
+ } while ((abs($fTerm) > 1e-12) && (++$ordK < 100));
887
+ } else {
888
+ $f_2_PI = 2 * M_PI;
889
+
890
+ $fXAbs = abs($x);
891
+ $fResult = exp($fXAbs) / sqrt($f_2_PI * $fXAbs);
892
+ if (($ord & 1) && ($x < 0)) {
893
+ $fResult = -$fResult;
894
+ }
895
+ }
896
+ return (is_nan($fResult)) ? PHPExcel_Calculation_Functions::NaN() : $fResult;
897
+ }
898
+ return PHPExcel_Calculation_Functions::VALUE();
899
+ }
900
+
901
+
902
+ /**
903
+ * BESSELJ
904
+ *
905
+ * Returns the Bessel function
906
+ *
907
+ * Excel Function:
908
+ * BESSELJ(x,ord)
909
+ *
910
+ * @access public
911
+ * @category Engineering Functions
912
+ * @param float $x The value at which to evaluate the function.
913
+ * If x is nonnumeric, BESSELJ returns the #VALUE! error value.
914
+ * @param integer $ord The order of the Bessel function. If n is not an integer, it is truncated.
915
+ * If $ord is nonnumeric, BESSELJ returns the #VALUE! error value.
916
+ * If $ord < 0, BESSELJ returns the #NUM! error value.
917
+ * @return float
918
+ *
919
+ */
920
+ public static function BESSELJ($x, $ord)
921
+ {
922
+ $x = (is_null($x)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($x);
923
+ $ord = (is_null($ord)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($ord);
924
+
925
+ if ((is_numeric($x)) && (is_numeric($ord))) {
926
+ $ord = floor($ord);
927
+ if ($ord < 0) {
928
+ return PHPExcel_Calculation_Functions::NaN();
929
+ }
930
+
931
+ $fResult = 0;
932
+ if (abs($x) <= 30) {
933
+ $fResult = $fTerm = pow($x / 2, $ord) / PHPExcel_Calculation_MathTrig::FACT($ord);
934
+ $ordK = 1;
935
+ $fSqrX = ($x * $x) / -4;
936
+ do {
937
+ $fTerm *= $fSqrX;
938
+ $fTerm /= ($ordK * ($ordK + $ord));
939
+ $fResult += $fTerm;
940
+ } while ((abs($fTerm) > 1e-12) && (++$ordK < 100));
941
+ } else {
942
+ $f_PI_DIV_2 = M_PI / 2;
943
+ $f_PI_DIV_4 = M_PI / 4;
944
+
945
+ $fXAbs = abs($x);
946
+ $fResult = sqrt(M_2DIVPI / $fXAbs) * cos($fXAbs - $ord * $f_PI_DIV_2 - $f_PI_DIV_4);
947
+ if (($ord & 1) && ($x < 0)) {
948
+ $fResult = -$fResult;
949
+ }
950
+ }
951
+ return (is_nan($fResult)) ? PHPExcel_Calculation_Functions::NaN() : $fResult;
952
+ }
953
+ return PHPExcel_Calculation_Functions::VALUE();
954
+ }
955
+
956
+
957
+ private static function besselK0($fNum)
958
+ {
959
+ if ($fNum <= 2) {
960
+ $fNum2 = $fNum * 0.5;
961
+ $y = ($fNum2 * $fNum2);
962
+ $fRet = -log($fNum2) * self::BESSELI($fNum, 0) +
963
+ (-0.57721566 + $y * (0.42278420 + $y * (0.23069756 + $y * (0.3488590e-1 + $y * (0.262698e-2 + $y *
964
+ (0.10750e-3 + $y * 0.74e-5))))));
965
+ } else {
966
+ $y = 2 / $fNum;
967
+ $fRet = exp(-$fNum) / sqrt($fNum) *
968
+ (1.25331414 + $y * (-0.7832358e-1 + $y * (0.2189568e-1 + $y * (-0.1062446e-1 + $y *
969
+ (0.587872e-2 + $y * (-0.251540e-2 + $y * 0.53208e-3))))));
970
+ }
971
+ return $fRet;
972
+ }
973
+
974
+
975
+ private static function besselK1($fNum)
976
+ {
977
+ if ($fNum <= 2) {
978
+ $fNum2 = $fNum * 0.5;
979
+ $y = ($fNum2 * $fNum2);
980
+ $fRet = log($fNum2) * self::BESSELI($fNum, 1) +
981
+ (1 + $y * (0.15443144 + $y * (-0.67278579 + $y * (-0.18156897 + $y * (-0.1919402e-1 + $y *
982
+ (-0.110404e-2 + $y * (-0.4686e-4))))))) / $fNum;
983
+ } else {
984
+ $y = 2 / $fNum;
985
+ $fRet = exp(-$fNum) / sqrt($fNum) *
986
+ (1.25331414 + $y * (0.23498619 + $y * (-0.3655620e-1 + $y * (0.1504268e-1 + $y * (-0.780353e-2 + $y *
987
+ (0.325614e-2 + $y * (-0.68245e-3)))))));
988
+ }
989
+ return $fRet;
990
+ }
991
+
992
+
993
+ /**
994
+ * BESSELK
995
+ *
996
+ * Returns the modified Bessel function Kn(x), which is equivalent to the Bessel functions evaluated
997
+ * for purely imaginary arguments.
998
+ *
999
+ * Excel Function:
1000
+ * BESSELK(x,ord)
1001
+ *
1002
+ * @access public
1003
+ * @category Engineering Functions
1004
+ * @param float $x The value at which to evaluate the function.
1005
+ * If x is nonnumeric, BESSELK returns the #VALUE! error value.
1006
+ * @param integer $ord The order of the Bessel function. If n is not an integer, it is truncated.
1007
+ * If $ord is nonnumeric, BESSELK returns the #VALUE! error value.
1008
+ * If $ord < 0, BESSELK returns the #NUM! error value.
1009
+ * @return float
1010
+ *
1011
+ */
1012
+ public static function BESSELK($x, $ord)
1013
+ {
1014
+ $x = (is_null($x)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($x);
1015
+ $ord = (is_null($ord)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($ord);
1016
+
1017
+ if ((is_numeric($x)) && (is_numeric($ord))) {
1018
+ if (($ord < 0) || ($x == 0.0)) {
1019
+ return PHPExcel_Calculation_Functions::NaN();
1020
+ }
1021
+
1022
+ switch (floor($ord)) {
1023
+ case 0:
1024
+ return self::besselK0($x);
1025
+ case 1:
1026
+ return self::besselK1($x);
1027
+ default:
1028
+ $fTox = 2 / $x;
1029
+ $fBkm = self::besselK0($x);
1030
+ $fBk = self::besselK1($x);
1031
+ for ($n = 1; $n < $ord; ++$n) {
1032
+ $fBkp = $fBkm + $n * $fTox * $fBk;
1033
+ $fBkm = $fBk;
1034
+ $fBk = $fBkp;
1035
+ }
1036
+ }
1037
+ return (is_nan($fBk)) ? PHPExcel_Calculation_Functions::NaN() : $fBk;
1038
+ }
1039
+ return PHPExcel_Calculation_Functions::VALUE();
1040
+ }
1041
+
1042
+
1043
+ private static function besselY0($fNum)
1044
+ {
1045
+ if ($fNum < 8.0) {
1046
+ $y = ($fNum * $fNum);
1047
+ $f1 = -2957821389.0 + $y * (7062834065.0 + $y * (-512359803.6 + $y * (10879881.29 + $y * (-86327.92757 + $y * 228.4622733))));
1048
+ $f2 = 40076544269.0 + $y * (745249964.8 + $y * (7189466.438 + $y * (47447.26470 + $y * (226.1030244 + $y))));
1049
+ $fRet = $f1 / $f2 + 0.636619772 * self::BESSELJ($fNum, 0) * log($fNum);
1050
+ } else {
1051
+ $z = 8.0 / $fNum;
1052
+ $y = ($z * $z);
1053
+ $xx = $fNum - 0.785398164;
1054
+ $f1 = 1 + $y * (-0.1098628627e-2 + $y * (0.2734510407e-4 + $y * (-0.2073370639e-5 + $y * 0.2093887211e-6)));
1055
+ $f2 = -0.1562499995e-1 + $y * (0.1430488765e-3 + $y * (-0.6911147651e-5 + $y * (0.7621095161e-6 + $y * (-0.934945152e-7))));
1056
+ $fRet = sqrt(0.636619772 / $fNum) * (sin($xx) * $f1 + $z * cos($xx) * $f2);
1057
+ }
1058
+ return $fRet;
1059
+ }
1060
+
1061
+
1062
+ private static function besselY1($fNum)
1063
+ {
1064
+ if ($fNum < 8.0) {
1065
+ $y = ($fNum * $fNum);
1066
+ $f1 = $fNum * (-0.4900604943e13 + $y * (0.1275274390e13 + $y * (-0.5153438139e11 + $y * (0.7349264551e9 + $y *
1067
+ (-0.4237922726e7 + $y * 0.8511937935e4)))));
1068
+ $f2 = 0.2499580570e14 + $y * (0.4244419664e12 + $y * (0.3733650367e10 + $y * (0.2245904002e8 + $y *
1069
+ (0.1020426050e6 + $y * (0.3549632885e3 + $y)))));
1070
+ $fRet = $f1 / $f2 + 0.636619772 * ( self::BESSELJ($fNum, 1) * log($fNum) - 1 / $fNum);
1071
+ } else {
1072
+ $fRet = sqrt(0.636619772 / $fNum) * sin($fNum - 2.356194491);
1073
+ }
1074
+ return $fRet;
1075
+ }
1076
+
1077
+
1078
+ /**
1079
+ * BESSELY
1080
+ *
1081
+ * Returns the Bessel function, which is also called the Weber function or the Neumann function.
1082
+ *
1083
+ * Excel Function:
1084
+ * BESSELY(x,ord)
1085
+ *
1086
+ * @access public
1087
+ * @category Engineering Functions
1088
+ * @param float $x The value at which to evaluate the function.
1089
+ * If x is nonnumeric, BESSELK returns the #VALUE! error value.
1090
+ * @param integer $ord The order of the Bessel function. If n is not an integer, it is truncated.
1091
+ * If $ord is nonnumeric, BESSELK returns the #VALUE! error value.
1092
+ * If $ord < 0, BESSELK returns the #NUM! error value.
1093
+ *
1094
+ * @return float
1095
+ */
1096
+ public static function BESSELY($x, $ord)
1097
+ {
1098
+ $x = (is_null($x)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($x);
1099
+ $ord = (is_null($ord)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($ord);
1100
+
1101
+ if ((is_numeric($x)) && (is_numeric($ord))) {
1102
+ if (($ord < 0) || ($x == 0.0)) {
1103
+ return PHPExcel_Calculation_Functions::NaN();
1104
+ }
1105
+
1106
+ switch (floor($ord)) {
1107
+ case 0:
1108
+ return self::besselY0($x);
1109
+ case 1:
1110
+ return self::besselY1($x);
1111
+ default:
1112
+ $fTox = 2 / $x;
1113
+ $fBym = self::besselY0($x);
1114
+ $fBy = self::besselY1($x);
1115
+ for ($n = 1; $n < $ord; ++$n) {
1116
+ $fByp = $n * $fTox * $fBy - $fBym;
1117
+ $fBym = $fBy;
1118
+ $fBy = $fByp;
1119
+ }
1120
+ }
1121
+ return (is_nan($fBy)) ? PHPExcel_Calculation_Functions::NaN() : $fBy;
1122
+ }
1123
+ return PHPExcel_Calculation_Functions::VALUE();
1124
+ }
1125
+
1126
+
1127
+ /**
1128
+ * BINTODEC
1129
+ *
1130
+ * Return a binary value as decimal.
1131
+ *
1132
+ * Excel Function:
1133
+ * BIN2DEC(x)
1134
+ *
1135
+ * @access public
1136
+ * @category Engineering Functions
1137
+ * @param string $x The binary number (as a string) that you want to convert. The number
1138
+ * cannot contain more than 10 characters (10 bits). The most significant
1139
+ * bit of number is the sign bit. The remaining 9 bits are magnitude bits.
1140
+ * Negative numbers are represented using two's-complement notation.
1141
+ * If number is not a valid binary number, or if number contains more than
1142
+ * 10 characters (10 bits), BIN2DEC returns the #NUM! error value.
1143
+ * @return string
1144
+ */
1145
+ public static function BINTODEC($x)
1146
+ {
1147
+ $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
1148
+
1149
+ if (is_bool($x)) {
1150
+ if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) {
1151
+ $x = (int) $x;
1152
+ } else {
1153
+ return PHPExcel_Calculation_Functions::VALUE();
1154
+ }
1155
+ }
1156
+ if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC) {
1157
+ $x = floor($x);
1158
+ }
1159
+ $x = (string) $x;
1160
+ if (strlen($x) > preg_match_all('/[01]/', $x, $out)) {
1161
+ return PHPExcel_Calculation_Functions::NaN();
1162
+ }
1163
+ if (strlen($x) > 10) {
1164
+ return PHPExcel_Calculation_Functions::NaN();
1165
+ } elseif (strlen($x) == 10) {
1166
+ // Two's Complement
1167
+ $x = substr($x, -9);
1168
+ return '-'.(512-bindec($x));
1169
+ }
1170
+ return bindec($x);
1171
+ }
1172
+
1173
+
1174
+ /**
1175
+ * BINTOHEX
1176
+ *
1177
+ * Return a binary value as hex.
1178
+ *
1179
+ * Excel Function:
1180
+ * BIN2HEX(x[,places])
1181
+ *
1182
+ * @access public
1183
+ * @category Engineering Functions
1184
+ * @param string $x The binary number (as a string) that you want to convert. The number
1185
+ * cannot contain more than 10 characters (10 bits). The most significant
1186
+ * bit of number is the sign bit. The remaining 9 bits are magnitude bits.
1187
+ * Negative numbers are represented using two's-complement notation.
1188
+ * If number is not a valid binary number, or if number contains more than
1189
+ * 10 characters (10 bits), BIN2HEX returns the #NUM! error value.
1190
+ * @param integer $places The number of characters to use. If places is omitted, BIN2HEX uses the
1191
+ * minimum number of characters necessary. Places is useful for padding the
1192
+ * return value with leading 0s (zeros).
1193
+ * If places is not an integer, it is truncated.
1194
+ * If places is nonnumeric, BIN2HEX returns the #VALUE! error value.
1195
+ * If places is negative, BIN2HEX returns the #NUM! error value.
1196
+ * @return string
1197
+ */
1198
+ public static function BINTOHEX($x, $places = null)
1199
+ {
1200
+ $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
1201
+ $places = PHPExcel_Calculation_Functions::flattenSingleValue($places);
1202
+
1203
+ if (is_bool($x)) {
1204
+ if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) {
1205
+ $x = (int) $x;
1206
+ } else {
1207
+ return PHPExcel_Calculation_Functions::VALUE();
1208
+ }
1209
+ }
1210
+ if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC) {
1211
+ $x = floor($x);
1212
+ }
1213
+ $x = (string) $x;
1214
+ if (strlen($x) > preg_match_all('/[01]/', $x, $out)) {
1215
+ return PHPExcel_Calculation_Functions::NaN();
1216
+ }
1217
+ if (strlen($x) > 10) {
1218
+ return PHPExcel_Calculation_Functions::NaN();
1219
+ } elseif (strlen($x) == 10) {
1220
+ // Two's Complement
1221
+ return str_repeat('F', 8).substr(strtoupper(dechex(bindec(substr($x, -9)))), -2);
1222
+ }
1223
+ $hexVal = (string) strtoupper(dechex(bindec($x)));
1224
+
1225
+ return self::nbrConversionFormat($hexVal, $places);
1226
+ }
1227
+
1228
+
1229
+ /**
1230
+ * BINTOOCT
1231
+ *
1232
+ * Return a binary value as octal.
1233
+ *
1234
+ * Excel Function:
1235
+ * BIN2OCT(x[,places])
1236
+ *
1237
+ * @access public
1238
+ * @category Engineering Functions
1239
+ * @param string $x The binary number (as a string) that you want to convert. The number
1240
+ * cannot contain more than 10 characters (10 bits). The most significant
1241
+ * bit of number is the sign bit. The remaining 9 bits are magnitude bits.
1242
+ * Negative numbers are represented using two's-complement notation.
1243
+ * If number is not a valid binary number, or if number contains more than
1244
+ * 10 characters (10 bits), BIN2OCT returns the #NUM! error value.
1245
+ * @param integer $places The number of characters to use. If places is omitted, BIN2OCT uses the
1246
+ * minimum number of characters necessary. Places is useful for padding the
1247
+ * return value with leading 0s (zeros).
1248
+ * If places is not an integer, it is truncated.
1249
+ * If places is nonnumeric, BIN2OCT returns the #VALUE! error value.
1250
+ * If places is negative, BIN2OCT returns the #NUM! error value.
1251
+ * @return string
1252
+ */
1253
+ public static function BINTOOCT($x, $places = null)
1254
+ {
1255
+ $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
1256
+ $places = PHPExcel_Calculation_Functions::flattenSingleValue($places);
1257
+
1258
+ if (is_bool($x)) {
1259
+ if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) {
1260
+ $x = (int) $x;
1261
+ } else {
1262
+ return PHPExcel_Calculation_Functions::VALUE();
1263
+ }
1264
+ }
1265
+ if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC) {
1266
+ $x = floor($x);
1267
+ }
1268
+ $x = (string) $x;
1269
+ if (strlen($x) > preg_match_all('/[01]/', $x, $out)) {
1270
+ return PHPExcel_Calculation_Functions::NaN();
1271
+ }
1272
+ if (strlen($x) > 10) {
1273
+ return PHPExcel_Calculation_Functions::NaN();
1274
+ } elseif (strlen($x) == 10) {
1275
+ // Two's Complement
1276
+ return str_repeat('7', 7).substr(strtoupper(decoct(bindec(substr($x, -9)))), -3);
1277
+ }
1278
+ $octVal = (string) decoct(bindec($x));
1279
+
1280
+ return self::nbrConversionFormat($octVal, $places);
1281
+ }
1282
+
1283
+
1284
+ /**
1285
+ * DECTOBIN
1286
+ *
1287
+ * Return a decimal value as binary.
1288
+ *
1289
+ * Excel Function:
1290
+ * DEC2BIN(x[,places])
1291
+ *
1292
+ * @access public
1293
+ * @category Engineering Functions
1294
+ * @param string $x The decimal integer you want to convert. If number is negative,
1295
+ * valid place values are ignored and DEC2BIN returns a 10-character
1296
+ * (10-bit) binary number in which the most significant bit is the sign
1297
+ * bit. The remaining 9 bits are magnitude bits. Negative numbers are
1298
+ * represented using two's-complement notation.
1299
+ * If number < -512 or if number > 511, DEC2BIN returns the #NUM! error
1300
+ * value.
1301
+ * If number is nonnumeric, DEC2BIN returns the #VALUE! error value.
1302
+ * If DEC2BIN requires more than places characters, it returns the #NUM!
1303
+ * error value.
1304
+ * @param integer $places The number of characters to use. If places is omitted, DEC2BIN uses
1305
+ * the minimum number of characters necessary. Places is useful for
1306
+ * padding the return value with leading 0s (zeros).
1307
+ * If places is not an integer, it is truncated.
1308
+ * If places is nonnumeric, DEC2BIN returns the #VALUE! error value.
1309
+ * If places is zero or negative, DEC2BIN returns the #NUM! error value.
1310
+ * @return string
1311
+ */
1312
+ public static function DECTOBIN($x, $places = null)
1313
+ {
1314
+ $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
1315
+ $places = PHPExcel_Calculation_Functions::flattenSingleValue($places);
1316
+
1317
+ if (is_bool($x)) {
1318
+ if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) {
1319
+ $x = (int) $x;
1320
+ } else {
1321
+ return PHPExcel_Calculation_Functions::VALUE();
1322
+ }
1323
+ }
1324
+ $x = (string) $x;
1325
+ if (strlen($x) > preg_match_all('/[-0123456789.]/', $x, $out)) {
1326
+ return PHPExcel_Calculation_Functions::VALUE();
1327
+ }
1328
+ $x = (string) floor($x);
1329
+ $r = decbin($x);
1330
+ if (strlen($r) == 32) {
1331
+ // Two's Complement
1332
+ $r = substr($r, -10);
1333
+ } elseif (strlen($r) > 11) {
1334
+ return PHPExcel_Calculation_Functions::NaN();
1335
+ }
1336
+
1337
+ return self::nbrConversionFormat($r, $places);
1338
+ }
1339
+
1340
+
1341
+ /**
1342
+ * DECTOHEX
1343
+ *
1344
+ * Return a decimal value as hex.
1345
+ *
1346
+ * Excel Function:
1347
+ * DEC2HEX(x[,places])
1348
+ *
1349
+ * @access public
1350
+ * @category Engineering Functions
1351
+ * @param string $x The decimal integer you want to convert. If number is negative,
1352
+ * places is ignored and DEC2HEX returns a 10-character (40-bit)
1353
+ * hexadecimal number in which the most significant bit is the sign
1354
+ * bit. The remaining 39 bits are magnitude bits. Negative numbers
1355
+ * are represented using two's-complement notation.
1356
+ * If number < -549,755,813,888 or if number > 549,755,813,887,
1357
+ * DEC2HEX returns the #NUM! error value.
1358
+ * If number is nonnumeric, DEC2HEX returns the #VALUE! error value.
1359
+ * If DEC2HEX requires more than places characters, it returns the
1360
+ * #NUM! error value.
1361
+ * @param integer $places The number of characters to use. If places is omitted, DEC2HEX uses
1362
+ * the minimum number of characters necessary. Places is useful for
1363
+ * padding the return value with leading 0s (zeros).
1364
+ * If places is not an integer, it is truncated.
1365
+ * If places is nonnumeric, DEC2HEX returns the #VALUE! error value.
1366
+ * If places is zero or negative, DEC2HEX returns the #NUM! error value.
1367
+ * @return string
1368
+ */
1369
+ public static function DECTOHEX($x, $places = null)
1370
+ {
1371
+ $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
1372
+ $places = PHPExcel_Calculation_Functions::flattenSingleValue($places);
1373
+
1374
+ if (is_bool($x)) {
1375
+ if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) {
1376
+ $x = (int) $x;
1377
+ } else {
1378
+ return PHPExcel_Calculation_Functions::VALUE();
1379
+ }
1380
+ }
1381
+ $x = (string) $x;
1382
+ if (strlen($x) > preg_match_all('/[-0123456789.]/', $x, $out)) {
1383
+ return PHPExcel_Calculation_Functions::VALUE();
1384
+ }
1385
+ $x = (string) floor($x);
1386
+ $r = strtoupper(dechex($x));
1387
+ if (strlen($r) == 8) {
1388
+ // Two's Complement
1389
+ $r = 'FF'.$r;
1390
+ }
1391
+
1392
+ return self::nbrConversionFormat($r, $places);
1393
+ }
1394
+
1395
+
1396
+ /**
1397
+ * DECTOOCT
1398
+ *
1399
+ * Return an decimal value as octal.
1400
+ *
1401
+ * Excel Function:
1402
+ * DEC2OCT(x[,places])
1403
+ *
1404
+ * @access public
1405
+ * @category Engineering Functions
1406
+ * @param string $x The decimal integer you want to convert. If number is negative,
1407
+ * places is ignored and DEC2OCT returns a 10-character (30-bit)
1408
+ * octal number in which the most significant bit is the sign bit.
1409
+ * The remaining 29 bits are magnitude bits. Negative numbers are
1410
+ * represented using two's-complement notation.
1411
+ * If number < -536,870,912 or if number > 536,870,911, DEC2OCT
1412
+ * returns the #NUM! error value.
1413
+ * If number is nonnumeric, DEC2OCT returns the #VALUE! error value.
1414
+ * If DEC2OCT requires more than places characters, it returns the
1415
+ * #NUM! error value.
1416
+ * @param integer $places The number of characters to use. If places is omitted, DEC2OCT uses
1417
+ * the minimum number of characters necessary. Places is useful for
1418
+ * padding the return value with leading 0s (zeros).
1419
+ * If places is not an integer, it is truncated.
1420
+ * If places is nonnumeric, DEC2OCT returns the #VALUE! error value.
1421
+ * If places is zero or negative, DEC2OCT returns the #NUM! error value.
1422
+ * @return string
1423
+ */
1424
+ public static function DECTOOCT($x, $places = null)
1425
+ {
1426
+ $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
1427
+ $places = PHPExcel_Calculation_Functions::flattenSingleValue($places);
1428
+
1429
+ if (is_bool($x)) {
1430
+ if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) {
1431
+ $x = (int) $x;
1432
+ } else {
1433
+ return PHPExcel_Calculation_Functions::VALUE();
1434
+ }
1435
+ }
1436
+ $x = (string) $x;
1437
+ if (strlen($x) > preg_match_all('/[-0123456789.]/', $x, $out)) {
1438
+ return PHPExcel_Calculation_Functions::VALUE();
1439
+ }
1440
+ $x = (string) floor($x);
1441
+ $r = decoct($x);
1442
+ if (strlen($r) == 11) {
1443
+ // Two's Complement
1444
+ $r = substr($r, -10);
1445
+ }
1446
+
1447
+ return self::nbrConversionFormat($r, $places);
1448
+ }
1449
+
1450
+
1451
+ /**
1452
+ * HEXTOBIN
1453
+ *
1454
+ * Return a hex value as binary.
1455
+ *
1456
+ * Excel Function:
1457
+ * HEX2BIN(x[,places])
1458
+ *
1459
+ * @access public
1460
+ * @category Engineering Functions
1461
+ * @param string $x the hexadecimal number you want to convert. Number cannot
1462
+ * contain more than 10 characters. The most significant bit of
1463
+ * number is the sign bit (40th bit from the right). The remaining
1464
+ * 9 bits are magnitude bits. Negative numbers are represented
1465
+ * using two's-complement notation.
1466
+ * If number is negative, HEX2BIN ignores places and returns a
1467
+ * 10-character binary number.
1468
+ * If number is negative, it cannot be less than FFFFFFFE00, and
1469
+ * if number is positive, it cannot be greater than 1FF.
1470
+ * If number is not a valid hexadecimal number, HEX2BIN returns
1471
+ * the #NUM! error value.
1472
+ * If HEX2BIN requires more than places characters, it returns
1473
+ * the #NUM! error value.
1474
+ * @param integer $places The number of characters to use. If places is omitted,
1475
+ * HEX2BIN uses the minimum number of characters necessary. Places
1476
+ * is useful for padding the return value with leading 0s (zeros).
1477
+ * If places is not an integer, it is truncated.
1478
+ * If places is nonnumeric, HEX2BIN returns the #VALUE! error value.
1479
+ * If places is negative, HEX2BIN returns the #NUM! error value.
1480
+ * @return string
1481
+ */
1482
+ public static function HEXTOBIN($x, $places = null)
1483
+ {
1484
+ $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
1485
+ $places = PHPExcel_Calculation_Functions::flattenSingleValue($places);
1486
+
1487
+ if (is_bool($x)) {
1488
+ return PHPExcel_Calculation_Functions::VALUE();
1489
+ }
1490
+ $x = (string) $x;
1491
+ if (strlen($x) > preg_match_all('/[0123456789ABCDEF]/', strtoupper($x), $out)) {
1492
+ return PHPExcel_Calculation_Functions::NaN();
1493
+ }
1494
+ $binVal = decbin(hexdec($x));
1495
+
1496
+ return substr(self::nbrConversionFormat($binVal, $places), -10);
1497
+ }
1498
+
1499
+
1500
+ /**
1501
+ * HEXTODEC
1502
+ *
1503
+ * Return a hex value as decimal.
1504
+ *
1505
+ * Excel Function:
1506
+ * HEX2DEC(x)
1507
+ *
1508
+ * @access public
1509
+ * @category Engineering Functions
1510
+ * @param string $x The hexadecimal number you want to convert. This number cannot
1511
+ * contain more than 10 characters (40 bits). The most significant
1512
+ * bit of number is the sign bit. The remaining 39 bits are magnitude
1513
+ * bits. Negative numbers are represented using two's-complement
1514
+ * notation.
1515
+ * If number is not a valid hexadecimal number, HEX2DEC returns the
1516
+ * #NUM! error value.
1517
+ * @return string
1518
+ */
1519
+ public static function HEXTODEC($x)
1520
+ {
1521
+ $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
1522
+
1523
+ if (is_bool($x)) {
1524
+ return PHPExcel_Calculation_Functions::VALUE();
1525
+ }
1526
+ $x = (string) $x;
1527
+ if (strlen($x) > preg_match_all('/[0123456789ABCDEF]/', strtoupper($x), $out)) {
1528
+ return PHPExcel_Calculation_Functions::NaN();
1529
+ }
1530
+ return hexdec($x);
1531
+ }
1532
+
1533
+
1534
+ /**
1535
+ * HEXTOOCT
1536
+ *
1537
+ * Return a hex value as octal.
1538
+ *
1539
+ * Excel Function:
1540
+ * HEX2OCT(x[,places])
1541
+ *
1542
+ * @access public
1543
+ * @category Engineering Functions
1544
+ * @param string $x The hexadecimal number you want to convert. Number cannot
1545
+ * contain more than 10 characters. The most significant bit of
1546
+ * number is the sign bit. The remaining 39 bits are magnitude
1547
+ * bits. Negative numbers are represented using two's-complement
1548
+ * notation.
1549
+ * If number is negative, HEX2OCT ignores places and returns a
1550
+ * 10-character octal number.
1551
+ * If number is negative, it cannot be less than FFE0000000, and
1552
+ * if number is positive, it cannot be greater than 1FFFFFFF.
1553
+ * If number is not a valid hexadecimal number, HEX2OCT returns
1554
+ * the #NUM! error value.
1555
+ * If HEX2OCT requires more than places characters, it returns
1556
+ * the #NUM! error value.
1557
+ * @param integer $places The number of characters to use. If places is omitted, HEX2OCT
1558
+ * uses the minimum number of characters necessary. Places is
1559
+ * useful for padding the return value with leading 0s (zeros).
1560
+ * If places is not an integer, it is truncated.
1561
+ * If places is nonnumeric, HEX2OCT returns the #VALUE! error
1562
+ * value.
1563
+ * If places is negative, HEX2OCT returns the #NUM! error value.
1564
+ * @return string
1565
+ */
1566
+ public static function HEXTOOCT($x, $places = null)
1567
+ {
1568
+ $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
1569
+ $places = PHPExcel_Calculation_Functions::flattenSingleValue($places);
1570
+
1571
+ if (is_bool($x)) {
1572
+ return PHPExcel_Calculation_Functions::VALUE();
1573
+ }
1574
+ $x = (string) $x;
1575
+ if (strlen($x) > preg_match_all('/[0123456789ABCDEF]/', strtoupper($x), $out)) {
1576
+ return PHPExcel_Calculation_Functions::NaN();
1577
+ }
1578
+ $octVal = decoct(hexdec($x));
1579
+
1580
+ return self::nbrConversionFormat($octVal, $places);
1581
+ } // function HEXTOOCT()
1582
+
1583
+
1584
+ /**
1585
+ * OCTTOBIN
1586
+ *
1587
+ * Return an octal value as binary.
1588
+ *
1589
+ * Excel Function:
1590
+ * OCT2BIN(x[,places])
1591
+ *
1592
+ * @access public
1593
+ * @category Engineering Functions
1594
+ * @param string $x The octal number you want to convert. Number may not
1595
+ * contain more than 10 characters. The most significant
1596
+ * bit of number is the sign bit. The remaining 29 bits
1597
+ * are magnitude bits. Negative numbers are represented
1598
+ * using two's-complement notation.
1599
+ * If number is negative, OCT2BIN ignores places and returns
1600
+ * a 10-character binary number.
1601
+ * If number is negative, it cannot be less than 7777777000,
1602
+ * and if number is positive, it cannot be greater than 777.
1603
+ * If number is not a valid octal number, OCT2BIN returns
1604
+ * the #NUM! error value.
1605
+ * If OCT2BIN requires more than places characters, it
1606
+ * returns the #NUM! error value.
1607
+ * @param integer $places The number of characters to use. If places is omitted,
1608
+ * OCT2BIN uses the minimum number of characters necessary.
1609
+ * Places is useful for padding the return value with
1610
+ * leading 0s (zeros).
1611
+ * If places is not an integer, it is truncated.
1612
+ * If places is nonnumeric, OCT2BIN returns the #VALUE!
1613
+ * error value.
1614
+ * If places is negative, OCT2BIN returns the #NUM! error
1615
+ * value.
1616
+ * @return string
1617
+ */
1618
+ public static function OCTTOBIN($x, $places = null)
1619
+ {
1620
+ $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
1621
+ $places = PHPExcel_Calculation_Functions::flattenSingleValue($places);
1622
+
1623
+ if (is_bool($x)) {
1624
+ return PHPExcel_Calculation_Functions::VALUE();
1625
+ }
1626
+ $x = (string) $x;
1627
+ if (preg_match_all('/[01234567]/', $x, $out) != strlen($x)) {
1628
+ return PHPExcel_Calculation_Functions::NaN();
1629
+ }
1630
+ $r = decbin(octdec($x));
1631
+
1632
+ return self::nbrConversionFormat($r, $places);
1633
+ }
1634
+
1635
+
1636
+ /**
1637
+ * OCTTODEC
1638
+ *
1639
+ * Return an octal value as decimal.
1640
+ *
1641
+ * Excel Function:
1642
+ * OCT2DEC(x)
1643
+ *
1644
+ * @access public
1645
+ * @category Engineering Functions
1646
+ * @param string $x The octal number you want to convert. Number may not contain
1647
+ * more than 10 octal characters (30 bits). The most significant
1648
+ * bit of number is the sign bit. The remaining 29 bits are
1649
+ * magnitude bits. Negative numbers are represented using
1650
+ * two's-complement notation.
1651
+ * If number is not a valid octal number, OCT2DEC returns the
1652
+ * #NUM! error value.
1653
+ * @return string
1654
+ */
1655
+ public static function OCTTODEC($x)
1656
+ {
1657
+ $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
1658
+
1659
+ if (is_bool($x)) {
1660
+ return PHPExcel_Calculation_Functions::VALUE();
1661
+ }
1662
+ $x = (string) $x;
1663
+ if (preg_match_all('/[01234567]/', $x, $out) != strlen($x)) {
1664
+ return PHPExcel_Calculation_Functions::NaN();
1665
+ }
1666
+ return octdec($x);
1667
+ }
1668
+
1669
+
1670
+ /**
1671
+ * OCTTOHEX
1672
+ *
1673
+ * Return an octal value as hex.
1674
+ *
1675
+ * Excel Function:
1676
+ * OCT2HEX(x[,places])
1677
+ *
1678
+ * @access public
1679
+ * @category Engineering Functions
1680
+ * @param string $x The octal number you want to convert. Number may not contain
1681
+ * more than 10 octal characters (30 bits). The most significant
1682
+ * bit of number is the sign bit. The remaining 29 bits are
1683
+ * magnitude bits. Negative numbers are represented using
1684
+ * two's-complement notation.
1685
+ * If number is negative, OCT2HEX ignores places and returns a
1686
+ * 10-character hexadecimal number.
1687
+ * If number is not a valid octal number, OCT2HEX returns the
1688
+ * #NUM! error value.
1689
+ * If OCT2HEX requires more than places characters, it returns
1690
+ * the #NUM! error value.
1691
+ * @param integer $places The number of characters to use. If places is omitted, OCT2HEX
1692
+ * uses the minimum number of characters necessary. Places is useful
1693
+ * for padding the return value with leading 0s (zeros).
1694
+ * If places is not an integer, it is truncated.
1695
+ * If places is nonnumeric, OCT2HEX returns the #VALUE! error value.
1696
+ * If places is negative, OCT2HEX returns the #NUM! error value.
1697
+ * @return string
1698
+ */
1699
+ public static function OCTTOHEX($x, $places = null)
1700
+ {
1701
+ $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
1702
+ $places = PHPExcel_Calculation_Functions::flattenSingleValue($places);
1703
+
1704
+ if (is_bool($x)) {
1705
+ return PHPExcel_Calculation_Functions::VALUE();
1706
+ }
1707
+ $x = (string) $x;
1708
+ if (preg_match_all('/[01234567]/', $x, $out) != strlen($x)) {
1709
+ return PHPExcel_Calculation_Functions::NaN();
1710
+ }
1711
+ $hexVal = strtoupper(dechex(octdec($x)));
1712
+
1713
+ return self::nbrConversionFormat($hexVal, $places);
1714
+ }
1715
+
1716
+
1717
+ /**
1718
+ * COMPLEX
1719
+ *
1720
+ * Converts real and imaginary coefficients into a complex number of the form x + yi or x + yj.
1721
+ *
1722
+ * Excel Function:
1723
+ * COMPLEX(realNumber,imaginary[,places])
1724
+ *
1725
+ * @access public
1726
+ * @category Engineering Functions
1727
+ * @param float $realNumber The real coefficient of the complex number.
1728
+ * @param float $imaginary The imaginary coefficient of the complex number.
1729
+ * @param string $suffix The suffix for the imaginary component of the complex number.
1730
+ * If omitted, the suffix is assumed to be "i".
1731
+ * @return string
1732
+ */
1733
+ public static function COMPLEX($realNumber = 0.0, $imaginary = 0.0, $suffix = 'i')
1734
+ {
1735
+ $realNumber = (is_null($realNumber)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($realNumber);
1736
+ $imaginary = (is_null($imaginary)) ? 0.0 : PHPExcel_Calculation_Functions::flattenSingleValue($imaginary);
1737
+ $suffix = (is_null($suffix)) ? 'i' : PHPExcel_Calculation_Functions::flattenSingleValue($suffix);
1738
+
1739
+ if (((is_numeric($realNumber)) && (is_numeric($imaginary))) &&
1740
+ (($suffix == 'i') || ($suffix == 'j') || ($suffix == ''))) {
1741
+ $realNumber = (float) $realNumber;
1742
+ $imaginary = (float) $imaginary;
1743
+
1744
+ if ($suffix == '') {
1745
+ $suffix = 'i';
1746
+ }
1747
+ if ($realNumber == 0.0) {
1748
+ if ($imaginary == 0.0) {
1749
+ return (string) '0';
1750
+ } elseif ($imaginary == 1.0) {
1751
+ return (string) $suffix;
1752
+ } elseif ($imaginary == -1.0) {
1753
+ return (string) '-'.$suffix;
1754
+ }
1755
+ return (string) $imaginary.$suffix;
1756
+ } elseif ($imaginary == 0.0) {
1757
+ return (string) $realNumber;
1758
+ } elseif ($imaginary == 1.0) {
1759
+ return (string) $realNumber.'+'.$suffix;
1760
+ } elseif ($imaginary == -1.0) {
1761
+ return (string) $realNumber.'-'.$suffix;
1762
+ }
1763
+ if ($imaginary > 0) {
1764
+ $imaginary = (string) '+'.$imaginary;
1765
+ }
1766
+ return (string) $realNumber.$imaginary.$suffix;
1767
+ }
1768
+
1769
+ return PHPExcel_Calculation_Functions::VALUE();
1770
+ }
1771
+
1772
+
1773
+ /**
1774
+ * IMAGINARY
1775
+ *
1776
+ * Returns the imaginary coefficient of a complex number in x + yi or x + yj text format.
1777
+ *
1778
+ * Excel Function:
1779
+ * IMAGINARY(complexNumber)
1780
+ *
1781
+ * @access public
1782
+ * @category Engineering Functions
1783
+ * @param string $complexNumber The complex number for which you want the imaginary
1784
+ * coefficient.
1785
+ * @return float
1786
+ */
1787
+ public static function IMAGINARY($complexNumber)
1788
+ {
1789
+ $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
1790
+
1791
+ $parsedComplex = self::parseComplex($complexNumber);
1792
+ return $parsedComplex['imaginary'];
1793
+ }
1794
+
1795
+
1796
+ /**
1797
+ * IMREAL
1798
+ *
1799
+ * Returns the real coefficient of a complex number in x + yi or x + yj text format.
1800
+ *
1801
+ * Excel Function:
1802
+ * IMREAL(complexNumber)
1803
+ *
1804
+ * @access public
1805
+ * @category Engineering Functions
1806
+ * @param string $complexNumber The complex number for which you want the real coefficient.
1807
+ * @return float
1808
+ */
1809
+ public static function IMREAL($complexNumber)
1810
+ {
1811
+ $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
1812
+
1813
+ $parsedComplex = self::parseComplex($complexNumber);
1814
+ return $parsedComplex['real'];
1815
+ }
1816
+
1817
+
1818
+ /**
1819
+ * IMABS
1820
+ *
1821
+ * Returns the absolute value (modulus) of a complex number in x + yi or x + yj text format.
1822
+ *
1823
+ * Excel Function:
1824
+ * IMABS(complexNumber)
1825
+ *
1826
+ * @param string $complexNumber The complex number for which you want the absolute value.
1827
+ * @return float
1828
+ */
1829
+ public static function IMABS($complexNumber)
1830
+ {
1831
+ $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
1832
+
1833
+ $parsedComplex = self::parseComplex($complexNumber);
1834
+
1835
+ return sqrt(
1836
+ ($parsedComplex['real'] * $parsedComplex['real']) +
1837
+ ($parsedComplex['imaginary'] * $parsedComplex['imaginary'])
1838
+ );
1839
+ }
1840
+
1841
+
1842
+ /**
1843
+ * IMARGUMENT
1844
+ *
1845
+ * Returns the argument theta of a complex number, i.e. the angle in radians from the real
1846
+ * axis to the representation of the number in polar coordinates.
1847
+ *
1848
+ * Excel Function:
1849
+ * IMARGUMENT(complexNumber)
1850
+ *
1851
+ * @param string $complexNumber The complex number for which you want the argument theta.
1852
+ * @return float
1853
+ */
1854
+ public static function IMARGUMENT($complexNumber)
1855
+ {
1856
+ $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
1857
+
1858
+ $parsedComplex = self::parseComplex($complexNumber);
1859
+
1860
+ if ($parsedComplex['real'] == 0.0) {
1861
+ if ($parsedComplex['imaginary'] == 0.0) {
1862
+ return 0.0;
1863
+ } elseif ($parsedComplex['imaginary'] < 0.0) {
1864
+ return M_PI / -2;
1865
+ } else {
1866
+ return M_PI / 2;
1867
+ }
1868
+ } elseif ($parsedComplex['real'] > 0.0) {
1869
+ return atan($parsedComplex['imaginary'] / $parsedComplex['real']);
1870
+ } elseif ($parsedComplex['imaginary'] < 0.0) {
1871
+ return 0 - (M_PI - atan(abs($parsedComplex['imaginary']) / abs($parsedComplex['real'])));
1872
+ } else {
1873
+ return M_PI - atan($parsedComplex['imaginary'] / abs($parsedComplex['real']));
1874
+ }
1875
+ }
1876
+
1877
+
1878
+ /**
1879
+ * IMCONJUGATE
1880
+ *
1881
+ * Returns the complex conjugate of a complex number in x + yi or x + yj text format.
1882
+ *
1883
+ * Excel Function:
1884
+ * IMCONJUGATE(complexNumber)
1885
+ *
1886
+ * @param string $complexNumber The complex number for which you want the conjugate.
1887
+ * @return string
1888
+ */
1889
+ public static function IMCONJUGATE($complexNumber)
1890
+ {
1891
+ $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
1892
+
1893
+ $parsedComplex = self::parseComplex($complexNumber);
1894
+
1895
+ if ($parsedComplex['imaginary'] == 0.0) {
1896
+ return $parsedComplex['real'];
1897
+ } else {
1898
+ return self::cleanComplex(
1899
+ self::COMPLEX(
1900
+ $parsedComplex['real'],
1901
+ 0 - $parsedComplex['imaginary'],
1902
+ $parsedComplex['suffix']
1903
+ )
1904
+ );
1905
+ }
1906
+ }
1907
+
1908
+
1909
+ /**
1910
+ * IMCOS
1911
+ *
1912
+ * Returns the cosine of a complex number in x + yi or x + yj text format.
1913
+ *
1914
+ * Excel Function:
1915
+ * IMCOS(complexNumber)
1916
+ *
1917
+ * @param string $complexNumber The complex number for which you want the cosine.
1918
+ * @return string|float
1919
+ */
1920
+ public static function IMCOS($complexNumber)
1921
+ {
1922
+ $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
1923
+
1924
+ $parsedComplex = self::parseComplex($complexNumber);
1925
+
1926
+ if ($parsedComplex['imaginary'] == 0.0) {
1927
+ return cos($parsedComplex['real']);
1928
+ } else {
1929
+ return self::IMCONJUGATE(
1930
+ self::COMPLEX(
1931
+ cos($parsedComplex['real']) * cosh($parsedComplex['imaginary']),
1932
+ sin($parsedComplex['real']) * sinh($parsedComplex['imaginary']),
1933
+ $parsedComplex['suffix']
1934
+ )
1935
+ );
1936
+ }
1937
+ }
1938
+
1939
+
1940
+ /**
1941
+ * IMSIN
1942
+ *
1943
+ * Returns the sine of a complex number in x + yi or x + yj text format.
1944
+ *
1945
+ * Excel Function:
1946
+ * IMSIN(complexNumber)
1947
+ *
1948
+ * @param string $complexNumber The complex number for which you want the sine.
1949
+ * @return string|float
1950
+ */
1951
+ public static function IMSIN($complexNumber)
1952
+ {
1953
+ $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
1954
+
1955
+ $parsedComplex = self::parseComplex($complexNumber);
1956
+
1957
+ if ($parsedComplex['imaginary'] == 0.0) {
1958
+ return sin($parsedComplex['real']);
1959
+ } else {
1960
+ return self::COMPLEX(
1961
+ sin($parsedComplex['real']) * cosh($parsedComplex['imaginary']),
1962
+ cos($parsedComplex['real']) * sinh($parsedComplex['imaginary']),
1963
+ $parsedComplex['suffix']
1964
+ );
1965
+ }
1966
+ }
1967
+
1968
+
1969
+ /**
1970
+ * IMSQRT
1971
+ *
1972
+ * Returns the square root of a complex number in x + yi or x + yj text format.
1973
+ *
1974
+ * Excel Function:
1975
+ * IMSQRT(complexNumber)
1976
+ *
1977
+ * @param string $complexNumber The complex number for which you want the square root.
1978
+ * @return string
1979
+ */
1980
+ public static function IMSQRT($complexNumber)
1981
+ {
1982
+ $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
1983
+
1984
+ $parsedComplex = self::parseComplex($complexNumber);
1985
+
1986
+ $theta = self::IMARGUMENT($complexNumber);
1987
+ $d1 = cos($theta / 2);
1988
+ $d2 = sin($theta / 2);
1989
+ $r = sqrt(sqrt(($parsedComplex['real'] * $parsedComplex['real']) + ($parsedComplex['imaginary'] * $parsedComplex['imaginary'])));
1990
+
1991
+ if ($parsedComplex['suffix'] == '') {
1992
+ return self::COMPLEX($d1 * $r, $d2 * $r);
1993
+ } else {
1994
+ return self::COMPLEX($d1 * $r, $d2 * $r, $parsedComplex['suffix']);
1995
+ }
1996
+ }
1997
+
1998
+
1999
+ /**
2000
+ * IMLN
2001
+ *
2002
+ * Returns the natural logarithm of a complex number in x + yi or x + yj text format.
2003
+ *
2004
+ * Excel Function:
2005
+ * IMLN(complexNumber)
2006
+ *
2007
+ * @param string $complexNumber The complex number for which you want the natural logarithm.
2008
+ * @return string
2009
+ */
2010
+ public static function IMLN($complexNumber)
2011
+ {
2012
+ $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
2013
+
2014
+ $parsedComplex = self::parseComplex($complexNumber);
2015
+
2016
+ if (($parsedComplex['real'] == 0.0) && ($parsedComplex['imaginary'] == 0.0)) {
2017
+ return PHPExcel_Calculation_Functions::NaN();
2018
+ }
2019
+
2020
+ $logR = log(sqrt(($parsedComplex['real'] * $parsedComplex['real']) + ($parsedComplex['imaginary'] * $parsedComplex['imaginary'])));
2021
+ $t = self::IMARGUMENT($complexNumber);
2022
+
2023
+ if ($parsedComplex['suffix'] == '') {
2024
+ return self::COMPLEX($logR, $t);
2025
+ } else {
2026
+ return self::COMPLEX($logR, $t, $parsedComplex['suffix']);
2027
+ }
2028
+ }
2029
+
2030
+
2031
+ /**
2032
+ * IMLOG10
2033
+ *
2034
+ * Returns the common logarithm (base 10) of a complex number in x + yi or x + yj text format.
2035
+ *
2036
+ * Excel Function:
2037
+ * IMLOG10(complexNumber)
2038
+ *
2039
+ * @param string $complexNumber The complex number for which you want the common logarithm.
2040
+ * @return string
2041
+ */
2042
+ public static function IMLOG10($complexNumber)
2043
+ {
2044
+ $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
2045
+
2046
+ $parsedComplex = self::parseComplex($complexNumber);
2047
+
2048
+ if (($parsedComplex['real'] == 0.0) && ($parsedComplex['imaginary'] == 0.0)) {
2049
+ return PHPExcel_Calculation_Functions::NaN();
2050
+ } elseif (($parsedComplex['real'] > 0.0) && ($parsedComplex['imaginary'] == 0.0)) {
2051
+ return log10($parsedComplex['real']);
2052
+ }
2053
+
2054
+ return self::IMPRODUCT(log10(EULER), self::IMLN($complexNumber));
2055
+ }
2056
+
2057
+
2058
+ /**
2059
+ * IMLOG2
2060
+ *
2061
+ * Returns the base-2 logarithm of a complex number in x + yi or x + yj text format.
2062
+ *
2063
+ * Excel Function:
2064
+ * IMLOG2(complexNumber)
2065
+ *
2066
+ * @param string $complexNumber The complex number for which you want the base-2 logarithm.
2067
+ * @return string
2068
+ */
2069
+ public static function IMLOG2($complexNumber)
2070
+ {
2071
+ $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
2072
+
2073
+ $parsedComplex = self::parseComplex($complexNumber);
2074
+
2075
+ if (($parsedComplex['real'] == 0.0) && ($parsedComplex['imaginary'] == 0.0)) {
2076
+ return PHPExcel_Calculation_Functions::NaN();
2077
+ } elseif (($parsedComplex['real'] > 0.0) && ($parsedComplex['imaginary'] == 0.0)) {
2078
+ return log($parsedComplex['real'], 2);
2079
+ }
2080
+
2081
+ return self::IMPRODUCT(log(EULER, 2), self::IMLN($complexNumber));
2082
+ }
2083
+
2084
+
2085
+ /**
2086
+ * IMEXP
2087
+ *
2088
+ * Returns the exponential of a complex number in x + yi or x + yj text format.
2089
+ *
2090
+ * Excel Function:
2091
+ * IMEXP(complexNumber)
2092
+ *
2093
+ * @param string $complexNumber The complex number for which you want the exponential.
2094
+ * @return string
2095
+ */
2096
+ public static function IMEXP($complexNumber)
2097
+ {
2098
+ $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
2099
+
2100
+ $parsedComplex = self::parseComplex($complexNumber);
2101
+
2102
+ if (($parsedComplex['real'] == 0.0) && ($parsedComplex['imaginary'] == 0.0)) {
2103
+ return '1';
2104
+ }
2105
+
2106
+ $e = exp($parsedComplex['real']);
2107
+ $eX = $e * cos($parsedComplex['imaginary']);
2108
+ $eY = $e * sin($parsedComplex['imaginary']);
2109
+
2110
+ if ($parsedComplex['suffix'] == '') {
2111
+ return self::COMPLEX($eX, $eY);
2112
+ } else {
2113
+ return self::COMPLEX($eX, $eY, $parsedComplex['suffix']);
2114
+ }
2115
+ }
2116
+
2117
+
2118
+ /**
2119
+ * IMPOWER
2120
+ *
2121
+ * Returns a complex number in x + yi or x + yj text format raised to a power.
2122
+ *
2123
+ * Excel Function:
2124
+ * IMPOWER(complexNumber,realNumber)
2125
+ *
2126
+ * @param string $complexNumber The complex number you want to raise to a power.
2127
+ * @param float $realNumber The power to which you want to raise the complex number.
2128
+ * @return string
2129
+ */
2130
+ public static function IMPOWER($complexNumber, $realNumber)
2131
+ {
2132
+ $complexNumber = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber);
2133
+ $realNumber = PHPExcel_Calculation_Functions::flattenSingleValue($realNumber);
2134
+
2135
+ if (!is_numeric($realNumber)) {
2136
+ return PHPExcel_Calculation_Functions::VALUE();
2137
+ }
2138
+
2139
+ $parsedComplex = self::parseComplex($complexNumber);
2140
+
2141
+ $r = sqrt(($parsedComplex['real'] * $parsedComplex['real']) + ($parsedComplex['imaginary'] * $parsedComplex['imaginary']));
2142
+ $rPower = pow($r, $realNumber);
2143
+ $theta = self::IMARGUMENT($complexNumber) * $realNumber;
2144
+ if ($theta == 0) {
2145
+ return 1;
2146
+ } elseif ($parsedComplex['imaginary'] == 0.0) {
2147
+ return self::COMPLEX($rPower * cos($theta), $rPower * sin($theta), $parsedComplex['suffix']);
2148
+ } else {
2149
+ return self::COMPLEX($rPower * cos($theta), $rPower * sin($theta), $parsedComplex['suffix']);
2150
+ }
2151
+ }
2152
+
2153
+
2154
+ /**
2155
+ * IMDIV
2156
+ *
2157
+ * Returns the quotient of two complex numbers in x + yi or x + yj text format.
2158
+ *
2159
+ * Excel Function:
2160
+ * IMDIV(complexDividend,complexDivisor)
2161
+ *
2162
+ * @param string $complexDividend The complex numerator or dividend.
2163
+ * @param string $complexDivisor The complex denominator or divisor.
2164
+ * @return string
2165
+ */
2166
+ public static function IMDIV($complexDividend, $complexDivisor)
2167
+ {
2168
+ $complexDividend = PHPExcel_Calculation_Functions::flattenSingleValue($complexDividend);
2169
+ $complexDivisor = PHPExcel_Calculation_Functions::flattenSingleValue($complexDivisor);
2170
+
2171
+ $parsedComplexDividend = self::parseComplex($complexDividend);
2172
+ $parsedComplexDivisor = self::parseComplex($complexDivisor);
2173
+
2174
+ if (($parsedComplexDividend['suffix'] != '') && ($parsedComplexDivisor['suffix'] != '') &&
2175
+ ($parsedComplexDividend['suffix'] != $parsedComplexDivisor['suffix'])) {
2176
+ return PHPExcel_Calculation_Functions::NaN();
2177
+ }
2178
+ if (($parsedComplexDividend['suffix'] != '') && ($parsedComplexDivisor['suffix'] == '')) {
2179
+ $parsedComplexDivisor['suffix'] = $parsedComplexDividend['suffix'];
2180
+ }
2181
+
2182
+ $d1 = ($parsedComplexDividend['real'] * $parsedComplexDivisor['real']) + ($parsedComplexDividend['imaginary'] * $parsedComplexDivisor['imaginary']);
2183
+ $d2 = ($parsedComplexDividend['imaginary'] * $parsedComplexDivisor['real']) - ($parsedComplexDividend['real'] * $parsedComplexDivisor['imaginary']);
2184
+ $d3 = ($parsedComplexDivisor['real'] * $parsedComplexDivisor['real']) + ($parsedComplexDivisor['imaginary'] * $parsedComplexDivisor['imaginary']);
2185
+
2186
+ $r = $d1 / $d3;
2187
+ $i = $d2 / $d3;
2188
+
2189
+ if ($i > 0.0) {
2190
+ return self::cleanComplex($r.'+'.$i.$parsedComplexDivisor['suffix']);
2191
+ } elseif ($i < 0.0) {
2192
+ return self::cleanComplex($r.$i.$parsedComplexDivisor['suffix']);
2193
+ } else {
2194
+ return $r;
2195
+ }
2196
+ }
2197
+
2198
+
2199
+ /**
2200
+ * IMSUB
2201
+ *
2202
+ * Returns the difference of two complex numbers in x + yi or x + yj text format.
2203
+ *
2204
+ * Excel Function:
2205
+ * IMSUB(complexNumber1,complexNumber2)
2206
+ *
2207
+ * @param string $complexNumber1 The complex number from which to subtract complexNumber2.
2208
+ * @param string $complexNumber2 The complex number to subtract from complexNumber1.
2209
+ * @return string
2210
+ */
2211
+ public static function IMSUB($complexNumber1, $complexNumber2)
2212
+ {
2213
+ $complexNumber1 = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber1);
2214
+ $complexNumber2 = PHPExcel_Calculation_Functions::flattenSingleValue($complexNumber2);
2215
+
2216
+ $parsedComplex1 = self::parseComplex($complexNumber1);
2217
+ $parsedComplex2 = self::parseComplex($complexNumber2);
2218
+
2219
+ if ((($parsedComplex1['suffix'] != '') && ($parsedComplex2['suffix'] != '')) &&
2220
+ ($parsedComplex1['suffix'] != $parsedComplex2['suffix'])) {
2221
+ return PHPExcel_Calculation_Functions::NaN();
2222
+ } elseif (($parsedComplex1['suffix'] == '') && ($parsedComplex2['suffix'] != '')) {
2223
+ $parsedComplex1['suffix'] = $parsedComplex2['suffix'];
2224
+ }
2225
+
2226
+ $d1 = $parsedComplex1['real'] - $parsedComplex2['real'];
2227
+ $d2 = $parsedComplex1['imaginary'] - $parsedComplex2['imaginary'];
2228
+
2229
+ return self::COMPLEX($d1, $d2, $parsedComplex1['suffix']);
2230
+ }
2231
+
2232
+
2233
+ /**
2234
+ * IMSUM
2235
+ *
2236
+ * Returns the sum of two or more complex numbers in x + yi or x + yj text format.
2237
+ *
2238
+ * Excel Function:
2239
+ * IMSUM(complexNumber[,complexNumber[,...]])
2240
+ *
2241
+ * @param string $complexNumber,... Series of complex numbers to add
2242
+ * @return string
2243
+ */
2244
+ public static function IMSUM()
2245
+ {
2246
+ // Return value
2247
+ $returnValue = self::parseComplex('0');
2248
+ $activeSuffix = '';
2249
+
2250
+ // Loop through the arguments
2251
+ $aArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args());
2252
+ foreach ($aArgs as $arg) {
2253
+ $parsedComplex = self::parseComplex($arg);
2254
+
2255
+ if ($activeSuffix == '') {
2256
+ $activeSuffix = $parsedComplex['suffix'];
2257
+ } elseif (($parsedComplex['suffix'] != '') && ($activeSuffix != $parsedComplex['suffix'])) {
2258
+ return PHPExcel_Calculation_Functions::VALUE();
2259
+ }
2260
+
2261
+ $returnValue['real'] += $parsedComplex['real'];
2262
+ $returnValue['imaginary'] += $parsedComplex['imaginary'];
2263
+ }
2264
+
2265
+ if ($returnValue['imaginary'] == 0.0) {
2266
+ $activeSuffix = '';
2267
+ }
2268
+ return self::COMPLEX($returnValue['real'], $returnValue['imaginary'], $activeSuffix);
2269
+ }
2270
+
2271
+
2272
+ /**
2273
+ * IMPRODUCT
2274
+ *
2275
+ * Returns the product of two or more complex numbers in x + yi or x + yj text format.
2276
+ *
2277
+ * Excel Function:
2278
+ * IMPRODUCT(complexNumber[,complexNumber[,...]])
2279
+ *
2280
+ * @param string $complexNumber,... Series of complex numbers to multiply
2281
+ * @return string
2282
+ */
2283
+ public static function IMPRODUCT()
2284
+ {
2285
+ // Return value
2286
+ $returnValue = self::parseComplex('1');
2287
+ $activeSuffix = '';
2288
+
2289
+ // Loop through the arguments
2290
+ $aArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args());
2291
+ foreach ($aArgs as $arg) {
2292
+ $parsedComplex = self::parseComplex($arg);
2293
+
2294
+ $workValue = $returnValue;
2295
+ if (($parsedComplex['suffix'] != '') && ($activeSuffix == '')) {
2296
+ $activeSuffix = $parsedComplex['suffix'];
2297
+ } elseif (($parsedComplex['suffix'] != '') && ($activeSuffix != $parsedComplex['suffix'])) {
2298
+ return PHPExcel_Calculation_Functions::NaN();
2299
+ }
2300
+ $returnValue['real'] = ($workValue['real'] * $parsedComplex['real']) - ($workValue['imaginary'] * $parsedComplex['imaginary']);
2301
+ $returnValue['imaginary'] = ($workValue['real'] * $parsedComplex['imaginary']) + ($workValue['imaginary'] * $parsedComplex['real']);
2302
+ }
2303
+
2304
+ if ($returnValue['imaginary'] == 0.0) {
2305
+ $activeSuffix = '';
2306
+ }
2307
+ return self::COMPLEX($returnValue['real'], $returnValue['imaginary'], $activeSuffix);
2308
+ }
2309
+
2310
+
2311
+ /**
2312
+ * DELTA
2313
+ *
2314
+ * Tests whether two values are equal. Returns 1 if number1 = number2; returns 0 otherwise.
2315
+ * Use this function to filter a set of values. For example, by summing several DELTA
2316
+ * functions you calculate the count of equal pairs. This function is also known as the
2317
+ * Kronecker Delta function.
2318
+ *
2319
+ * Excel Function:
2320
+ * DELTA(a[,b])
2321
+ *
2322
+ * @param float $a The first number.
2323
+ * @param float $b The second number. If omitted, b is assumed to be zero.
2324
+ * @return int
2325
+ */
2326
+ public static function DELTA($a, $b = 0)
2327
+ {
2328
+ $a = PHPExcel_Calculation_Functions::flattenSingleValue($a);
2329
+ $b = PHPExcel_Calculation_Functions::flattenSingleValue($b);
2330
+
2331
+ return (int) ($a == $b);
2332
+ }
2333
+
2334
+
2335
+ /**
2336
+ * GESTEP
2337
+ *
2338
+ * Excel Function:
2339
+ * GESTEP(number[,step])
2340
+ *
2341
+ * Returns 1 if number >= step; returns 0 (zero) otherwise
2342
+ * Use this function to filter a set of values. For example, by summing several GESTEP
2343
+ * functions you calculate the count of values that exceed a threshold.
2344
+ *
2345
+ * @param float $number The value to test against step.
2346
+ * @param float $step The threshold value.
2347
+ * If you omit a value for step, GESTEP uses zero.
2348
+ * @return int
2349
+ */
2350
+ public static function GESTEP($number, $step = 0)
2351
+ {
2352
+ $number = PHPExcel_Calculation_Functions::flattenSingleValue($number);
2353
+ $step = PHPExcel_Calculation_Functions::flattenSingleValue($step);
2354
+
2355
+ return (int) ($number >= $step);
2356
+ }
2357
+
2358
+
2359
+ //
2360
+ // Private method to calculate the erf value
2361
+ //
2362
+ private static $twoSqrtPi = 1.128379167095512574;
2363
+
2364
+ public static function erfVal($x)
2365
+ {
2366
+ if (abs($x) > 2.2) {
2367
+ return 1 - self::erfcVal($x);
2368
+ }
2369
+ $sum = $term = $x;
2370
+ $xsqr = ($x * $x);
2371
+ $j = 1;
2372
+ do {
2373
+ $term *= $xsqr / $j;
2374
+ $sum -= $term / (2 * $j + 1);
2375
+ ++$j;
2376
+ $term *= $xsqr / $j;
2377
+ $sum += $term / (2 * $j + 1);
2378
+ ++$j;
2379
+ if ($sum == 0.0) {
2380
+ break;
2381
+ }
2382
+ } while (abs($term / $sum) > PRECISION);
2383
+ return self::$twoSqrtPi * $sum;
2384
+ }
2385
+
2386
+
2387
+ /**
2388
+ * ERF
2389
+ *
2390
+ * Returns the error function integrated between the lower and upper bound arguments.
2391
+ *
2392
+ * Note: In Excel 2007 or earlier, if you input a negative value for the upper or lower bound arguments,
2393
+ * the function would return a #NUM! error. However, in Excel 2010, the function algorithm was
2394
+ * improved, so that it can now calculate the function for both positive and negative ranges.
2395
+ * PHPExcel follows Excel 2010 behaviour, and accepts nagative arguments.
2396
+ *
2397
+ * Excel Function:
2398
+ * ERF(lower[,upper])
2399
+ *
2400
+ * @param float $lower lower bound for integrating ERF
2401
+ * @param float $upper upper bound for integrating ERF.
2402
+ * If omitted, ERF integrates between zero and lower_limit
2403
+ * @return float
2404
+ */
2405
+ public static function ERF($lower, $upper = null)
2406
+ {
2407
+ $lower = PHPExcel_Calculation_Functions::flattenSingleValue($lower);
2408
+ $upper = PHPExcel_Calculation_Functions::flattenSingleValue($upper);
2409
+
2410
+ if (is_numeric($lower)) {
2411
+ if (is_null($upper)) {
2412
+ return self::erfVal($lower);
2413
+ }
2414
+ if (is_numeric($upper)) {
2415
+ return self::erfVal($upper) - self::erfVal($lower);
2416
+ }
2417
+ }
2418
+ return PHPExcel_Calculation_Functions::VALUE();
2419
+ }
2420
+
2421
+
2422
+ //
2423
+ // Private method to calculate the erfc value
2424
+ //
2425
+ private static $oneSqrtPi = 0.564189583547756287;
2426
+
2427
+ private static function erfcVal($x)
2428
+ {
2429
+ if (abs($x) < 2.2) {
2430
+ return 1 - self::erfVal($x);
2431
+ }
2432
+ if ($x < 0) {
2433
+ return 2 - self::ERFC(-$x);
2434
+ }
2435
+ $a = $n = 1;
2436
+ $b = $c = $x;
2437
+ $d = ($x * $x) + 0.5;
2438
+ $q1 = $q2 = $b / $d;
2439
+ $t = 0;
2440
+ do {
2441
+ $t = $a * $n + $b * $x;
2442
+ $a = $b;
2443
+ $b = $t;
2444
+ $t = $c * $n + $d * $x;
2445
+ $c = $d;
2446
+ $d = $t;
2447
+ $n += 0.5;
2448
+ $q1 = $q2;
2449
+ $q2 = $b / $d;
2450
+ } while ((abs($q1 - $q2) / $q2) > PRECISION);
2451
+ return self::$oneSqrtPi * exp(-$x * $x) * $q2;
2452
+ }
2453
+
2454
+
2455
+ /**
2456
+ * ERFC
2457
+ *
2458
+ * Returns the complementary ERF function integrated between x and infinity
2459
+ *
2460
+ * Note: In Excel 2007 or earlier, if you input a negative value for the lower bound argument,
2461
+ * the function would return a #NUM! error. However, in Excel 2010, the function algorithm was
2462
+ * improved, so that it can now calculate the function for both positive and negative x values.
2463
+ * PHPExcel follows Excel 2010 behaviour, and accepts nagative arguments.
2464
+ *
2465
+ * Excel Function:
2466
+ * ERFC(x)
2467
+ *
2468
+ * @param float $x The lower bound for integrating ERFC
2469
+ * @return float
2470
+ */
2471
+ public static function ERFC($x)
2472
+ {
2473
+ $x = PHPExcel_Calculation_Functions::flattenSingleValue($x);
2474
+
2475
+ if (is_numeric($x)) {
2476
+ return self::erfcVal($x);
2477
+ }
2478
+ return PHPExcel_Calculation_Functions::VALUE();
2479
+ }
2480
+
2481
+
2482
+ /**
2483
+ * getConversionGroups
2484
+ * Returns a list of the different conversion groups for UOM conversions
2485
+ *
2486
+ * @return array
2487
+ */
2488
+ public static function getConversionGroups()
2489
+ {
2490
+ $conversionGroups = array();
2491
+ foreach (self::$conversionUnits as $conversionUnit) {
2492
+ $conversionGroups[] = $conversionUnit['Group'];
2493
+ }
2494
+ return array_merge(array_unique($conversionGroups));
2495
+ }
2496
+
2497
+
2498
+ /**
2499
+ * getConversionGroupUnits
2500
+ * Returns an array of units of measure, for a specified conversion group, or for all groups
2501
+ *
2502
+ * @param string $group The group whose units of measure you want to retrieve
2503
+ * @return array
2504
+ */
2505
+ public static function getConversionGroupUnits($group = null)
2506
+ {
2507
+ $conversionGroups = array();
2508
+ foreach (self::$conversionUnits as $conversionUnit => $conversionGroup) {
2509
+ if ((is_null($group)) || ($conversionGroup['Group'] == $group)) {
2510
+ $conversionGroups[$conversionGroup['Group']][] = $conversionUnit;
2511
+ }
2512
+ }
2513
+ return $conversionGroups;
2514
+ }
2515
+
2516
+
2517
+ /**
2518
+ * getConversionGroupUnitDetails
2519
+ *
2520
+ * @param string $group The group whose units of measure you want to retrieve
2521
+ * @return array
2522
+ */
2523
+ public static function getConversionGroupUnitDetails($group = null)
2524
+ {
2525
+ $conversionGroups = array();
2526
+ foreach (self::$conversionUnits as $conversionUnit => $conversionGroup) {
2527
+ if ((is_null($group)) || ($conversionGroup['Group'] == $group)) {
2528
+ $conversionGroups[$conversionGroup['Group']][] = array(
2529
+ 'unit' => $conversionUnit,
2530
+ 'description' => $conversionGroup['Unit Name']
2531
+ );
2532
+ }
2533
+ }
2534
+ return $conversionGroups;
2535
+ }
2536
+
2537
+
2538
+ /**
2539
+ * getConversionMultipliers
2540
+ * Returns an array of the Multiplier prefixes that can be used with Units of Measure in CONVERTUOM()
2541
+ *
2542
+ * @return array of mixed
2543
+ */
2544
+ public static function getConversionMultipliers()
2545
+ {
2546
+ return self::$conversionMultipliers;
2547
+ }
2548
+
2549
+
2550
+ /**
2551
+ * CONVERTUOM
2552
+ *
2553
+ * Converts a number from one measurement system to another.
2554
+ * For example, CONVERT can translate a table of distances in miles to a table of distances
2555
+ * in kilometers.
2556
+ *
2557
+ * Excel Function:
2558
+ * CONVERT(value,fromUOM,toUOM)
2559
+ *
2560
+ * @param float $value The value in fromUOM to convert.
2561
+ * @param string $fromUOM The units for value.
2562
+ * @param string $toUOM The units for the result.
2563
+ *
2564
+ * @return float
2565
+ */
2566
+ public static function CONVERTUOM($value, $fromUOM, $toUOM)
2567
+ {
2568
+ $value = PHPExcel_Calculation_Functions::flattenSingleValue($value);
2569
+ $fromUOM = PHPExcel_Calculation_Functions::flattenSingleValue($fromUOM);
2570
+ $toUOM = PHPExcel_Calculation_Functions::flattenSingleValue($toUOM);
2571
+
2572
+ if (!is_numeric($value)) {
2573
+ return PHPExcel_Calculation_Functions::VALUE();
2574
+ }
2575
+ $fromMultiplier = 1.0;
2576
+ if (isset(self::$conversionUnits[$fromUOM])) {
2577
+ $unitGroup1 = self::$conversionUnits[$fromUOM]['Group'];
2578
+ } else {
2579
+ $fromMultiplier = substr($fromUOM, 0, 1);
2580
+ $fromUOM = substr($fromUOM, 1);
2581
+ if (isset(self::$conversionMultipliers[$fromMultiplier])) {
2582
+ $fromMultiplier = self::$conversionMultipliers[$fromMultiplier]['multiplier'];
2583
+ } else {
2584
+ return PHPExcel_Calculation_Functions::NA();
2585
+ }
2586
+ if ((isset(self::$conversionUnits[$fromUOM])) && (self::$conversionUnits[$fromUOM]['AllowPrefix'])) {
2587
+ $unitGroup1 = self::$conversionUnits[$fromUOM]['Group'];
2588
+ } else {
2589
+ return PHPExcel_Calculation_Functions::NA();
2590
+ }
2591
+ }
2592
+ $value *= $fromMultiplier;
2593
+
2594
+ $toMultiplier = 1.0;
2595
+ if (isset(self::$conversionUnits[$toUOM])) {
2596
+ $unitGroup2 = self::$conversionUnits[$toUOM]['Group'];
2597
+ } else {
2598
+ $toMultiplier = substr($toUOM, 0, 1);
2599
+ $toUOM = substr($toUOM, 1);
2600
+ if (isset(self::$conversionMultipliers[$toMultiplier])) {
2601
+ $toMultiplier = self::$conversionMultipliers[$toMultiplier]['multiplier'];
2602
+ } else {
2603
+ return PHPExcel_Calculation_Functions::NA();
2604
+ }
2605
+ if ((isset(self::$conversionUnits[$toUOM])) && (self::$conversionUnits[$toUOM]['AllowPrefix'])) {
2606
+ $unitGroup2 = self::$conversionUnits[$toUOM]['Group'];
2607
+ } else {
2608
+ return PHPExcel_Calculation_Functions::NA();
2609
+ }
2610
+ }
2611
+ if ($unitGroup1 != $unitGroup2) {
2612
+ return PHPExcel_Calculation_Functions::NA();
2613
+ }
2614
+
2615
+ if (($fromUOM == $toUOM) && ($fromMultiplier == $toMultiplier)) {
2616
+ // We've already factored $fromMultiplier into the value, so we need
2617
+ // to reverse it again
2618
+ return $value / $fromMultiplier;
2619
+ } elseif ($unitGroup1 == 'Temperature') {
2620
+ if (($fromUOM == 'F') || ($fromUOM == 'fah')) {
2621
+ if (($toUOM == 'F') || ($toUOM == 'fah')) {
2622
+ return $value;
2623
+ } else {
2624
+ $value = (($value - 32) / 1.8);
2625
+ if (($toUOM == 'K') || ($toUOM == 'kel')) {
2626
+ $value += 273.15;
2627
+ }
2628
+ return $value;
2629
+ }
2630
+ } elseif ((($fromUOM == 'K') || ($fromUOM == 'kel')) &&
2631
+ (($toUOM == 'K') || ($toUOM == 'kel'))) {
2632
+ return $value;
2633
+ } elseif ((($fromUOM == 'C') || ($fromUOM == 'cel')) &&
2634
+ (($toUOM == 'C') || ($toUOM == 'cel'))) {
2635
+ return $value;
2636
+ }
2637
+ if (($toUOM == 'F') || ($toUOM == 'fah')) {
2638
+ if (($fromUOM == 'K') || ($fromUOM == 'kel')) {
2639
+ $value -= 273.15;
2640
+ }
2641
+ return ($value * 1.8) + 32;
2642
+ }
2643
+ if (($toUOM == 'C') || ($toUOM == 'cel')) {
2644
+ return $value - 273.15;
2645
+ }
2646
+ return $value + 273.15;
2647
+ }
2648
+ return ($value * self::$unitConversions[$unitGroup1][$fromUOM][$toUOM]) / $toMultiplier;
2649
+ }
2650
+ }
PHPExcel/Classes/PHPExcel/Calculation/Exception.php CHANGED
@@ -1,52 +1,46 @@
1
- <?php
2
- /**
3
- * PHPExcel
4
- *
5
- * Copyright (c) 2006 - 2014 PHPExcel
6
- *
7
- * This library is free software; you can redistribute it and/or
8
- * modify it under the terms of the GNU Lesser General Public
9
- * License as published by the Free Software Foundation; either
10
- * version 2.1 of the License, or (at your option) any later version.
11
- *
12
- * This library is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
- * Lesser General Public License for more details.
16
- *
17
- * You should have received a copy of the GNU Lesser General Public
18
- * License along with this library; if not, write to the Free Software
19
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
- *
21
- * @category PHPExcel
22
- * @package PHPExcel_Calculation
23
- * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
24
- * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25
- * @version 1.8.0, 2014-03-02
26
- */
27
-
28
-
29
- /**
30
- * PHPExcel_Calculation_Exception
31
- *
32
- * @category PHPExcel
33
- * @package PHPExcel_Calculation
34
- * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
35
- */
36
- class PHPExcel_Calculation_Exception extends PHPExcel_Exception {
37
- /**
38
- * Error handler callback
39
- *
40
- * @param mixed $code
41
- * @param mixed $string
42
- * @param mixed $file
43
- * @param mixed $line
44
- * @param mixed $context
45
- */
46
- public static function errorHandlerCallback($code, $string, $file, $line, $context) {
47
- $e = new self($string, $code);
48
- $e->line = $line;
49
- $e->file = $file;
50
- throw $e;
51
- }
52
- }
1
+ <?php
2
+
3
+ /**
4
+ * PHPExcel_Calculation_Exception
5
+ *
6
+ * Copyright (c) 2006 - 2015 PHPExcel
7
+ *
8
+ * This library is free software; you can redistribute it and/or
9
+ * modify it under the terms of the GNU Lesser General Public
10
+ * License as published by the Free Software Foundation; either
11
+ * version 2.1 of the License, or (at your option) any later version.
12
+ *
13
+ * This library is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
+ * Lesser General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU Lesser General Public
19
+ * License along with this library; if not, write to the Free Software
20
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
+ *
22
+ * @category PHPExcel
23
+ * @package PHPExcel_Calculation
24
+ * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
25
+ * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
26
+ * @version ##VERSION##, ##DATE##
27
+ */
28
+ class PHPExcel_Calculation_Exception extends PHPExcel_Exception
29
+ {
30
+ /**
31
+ * Error handler callback
32
+ *
33
+ * @param mixed $code
34
+ * @param mixed $string
35
+ * @param mixed $file
36
+ * @param mixed $line
37
+ * @param mixed $context
38
+ */
39
+ public static function errorHandlerCallback($code, $string, $file, $line, $context)
40
+ {
41
+ $e = new self($string, $code);
42
+ $e->line = $line;
43
+ $e->file = $file;
44
+ throw $e;
45
+ }
46
+ }
 
 
 
 
 
 
PHPExcel/Classes/PHPExcel/Calculation/ExceptionHandler.php CHANGED
@@ -1,49 +1,45 @@
1
- <?php
2
- /**
3
- * PHPExcel
4
- *
5
- * Copyright (c) 2006 - 2014 PHPExcel
6
- *
7
- * This library is free software; you can redistribute it and/or
8
- * modify it under the terms of the GNU Lesser General Public
9
- * License as published by the Free Software Foundation; either
10
- * version 2.1 of the License, or (at your option) any later version.
11
- *
12
- * This library is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
- * Lesser General Public License for more details.
16
- *
17
- * You should have received a copy of the GNU Lesser General Public
18
- * License along with this library; if not, write to the Free Software
19
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
- *
21
- * @category PHPExcel
22
- * @package PHPExcel_Calculation
23
- * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
24
- * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25
- * @version 1.8.0, 2014-03-02
26
- */
27
-
28
- /**
29
- * PHPExcel_Calculation_ExceptionHandler
30
- *
31
- * @category PHPExcel
32
- * @package PHPExcel_Calculation
33
- * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
34
- */
35
- class PHPExcel_Calculation_ExceptionHandler {
36
- /**
37
- * Register errorhandler
38
- */
39
- public function __construct() {
40
- set_error_handler(array('PHPExcel_Calculation_Exception', 'errorHandlerCallback'), E_ALL);
41
- }
42
-
43
- /**
44
- * Unregister errorhandler
45
- */
46
- public function __destruct() {
47
- restore_error_handler();
48
- }
49
- }
1
+ <?php
2
+
3
+ /**
4
+ * PHPExcel_Calculation_ExceptionHandler
5
+ *
6
+ * Copyright (c) 2006 - 2015 PHPExcel
7
+ *
8
+ * This library is free software; you can redistribute it and/or
9
+ * modify it under the terms of the GNU Lesser General Public
10
+ * License as published by the Free Software Foundation; either
11
+ * version 2.1 of the License, or (at your option) any later version.
12
+ *
13
+ * This library is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
+ * Lesser General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU Lesser General Public
19
+ * License along with this library; if not, write to the Free Software
20
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
+ *
22
+ * @category PHPExcel
23
+ * @package PHPExcel_Calculation
24
+ * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
25
+ * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
26
+ * @version ##VERSION##, ##DATE##
27
+ */
28
+ class PHPExcel_Calculation_ExceptionHandler
29
+ {
30
+ /**
31
+ * Register errorhandler
32
+ */
33
+ public function __construct()
34
+ {
35
+ set_error_handler(array('PHPExcel_Calculation_Exception', 'errorHandlerCallback'), E_ALL);
36
+ }
37
+
38
+ /**
39
+ * Unregister errorhandler
40
+ */
41
+ public function __destruct()
42
+ {
43
+ restore_error_handler();
44
+ }
45
+ }
 
 
 
 
PHPExcel/Classes/PHPExcel/Calculation/Financial.php CHANGED
@@ -1,2292 +1,2359 @@
1
- <?php
2
- /**
3
- * PHPExcel
4
- *
5
- * Copyright (c) 2006 - 2014 PHPExcel
6
- *
7
- * This library is free software; you can redistribute it and/or
8
- * modify it under the terms of the GNU Lesser General Public
9
- * License as published by the Free Software Foundation; either
10
- * version 2.1 of the License, or (at your option) any later version.
11
- *
12
- * This library is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
- * Lesser General Public License for more details.
16
- *
17
- * You should have received a copy of the GNU Lesser General Public
18
- * License along with this library; if not, write to the Free Software
19
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
- *
21
- * @category PHPExcel
22
- * @package PHPExcel_Calculation
23
- * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
24
- * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25
- * @version 1.8.0, 2014-03-02
26
- */
27
-
28
-
29
- /** PHPExcel root directory */
30
- if (!defined('PHPEXCEL_ROOT')) {
31
- /**
32
- * @ignore
33
- */
34
- define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
35
- require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
36
- }
37
-
38
-
39
- /** FINANCIAL_MAX_ITERATIONS */
40
- define('FINANCIAL_MAX_ITERATIONS', 128);
41
-
42
- /** FINANCIAL_PRECISION */
43
- define('FINANCIAL_PRECISION', 1.0e-08);
44
-
45
-
46
- /**
47
- * PHPExcel_Calculation_Financial
48
- *
49
- * @category PHPExcel
50
- * @package PHPExcel_Calculation
51
- * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
52
- */
53
- class PHPExcel_Calculation_Financial {
54
-
55
- /**
56
- * _lastDayOfMonth
57
- *
58
- * Returns a boolean TRUE/FALSE indicating if this date is the last date of the month
59
- *
60
- * @param DateTime $testDate The date for testing
61
- * @return boolean
62
- */
63
- private static function _lastDayOfMonth($testDate)
64
- {
65
- return ($testDate->format('d') == $testDate->format('t'));
66
- } // function _lastDayOfMonth()
67
-
68
-
69
- /**
70
- * _firstDayOfMonth
71
- *
72
- * Returns a boolean TRUE/FALSE indicating if this date is the first date of the month
73
- *
74
- * @param DateTime $testDate The date for testing
75
- * @return boolean
76
- */
77
- private static function _firstDayOfMonth($testDate)
78
- {
79
- return ($testDate->format('d') == 1);
80
- } // function _firstDayOfMonth()
81
-
82
-
83
- private static function _coupFirstPeriodDate($settlement, $maturity, $frequency, $next)
84
- {
85
- $months = 12 / $frequency;
86
-
87
- $result = PHPExcel_Shared_Date::ExcelToPHPObject($maturity);
88
- $eom = self::_lastDayOfMonth($result);
89
-
90
- while ($settlement < PHPExcel_Shared_Date::PHPToExcel($result)) {
91
- $result->modify('-'.$months.' months');
92
- }
93
- if ($next) {
94
- $result->modify('+'.$months.' months');
95
- }
96
-
97
- if ($eom) {
98
- $result->modify('-1 day');
99
- }
100
-
101
- return PHPExcel_Shared_Date::PHPToExcel($result);
102
- } // function _coupFirstPeriodDate()
103
-
104
-
105
- private static function _validFrequency($frequency)
106
- {
107
- if (($frequency == 1) || ($frequency == 2) || ($frequency == 4)) {
108
- return true;
109
- }
110
- if ((PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC) &&
111
- (($frequency == 6) || ($frequency == 12))) {
112
- return true;
113
- }
114
- return false;
115
- } // function _validFrequency()
116
-
117
-
118
- /**
119
- * _daysPerYear
120
- *
121
- * Returns the number of days in a specified year, as defined by the "basis" value
122
- *
123
- * @param integer $year The year against which we're testing
124
- * @param integer $basis The type of day count:
125
- * 0 or omitted US (NASD) 360
126
- * 1 Actual (365 or 366 in a leap year)
127
- * 2 360
128
- * 3 365
129
- * 4 European 360
130
- * @return integer
131
- */
132
- private static function _daysPerYear($year, $basis=0)
133
- {
134
- switch ($basis) {
135
- case 0 :
136
- case 2 :
137
- case 4 :
138
- $daysPerYear = 360;
139
- break;
140
- case 3 :
141
- $daysPerYear = 365;
142
- break;
143
- case 1 :
144
- $daysPerYear = (PHPExcel_Calculation_DateTime::_isLeapYear($year)) ? 366 : 365;
145
- break;
146
- default :
147
- return PHPExcel_Calculation_Functions::NaN();
148
- }
149
- return $daysPerYear;
150
- } // function _daysPerYear()
151
-
152
-
153
- private static function _interestAndPrincipal($rate=0, $per=0, $nper=0, $pv=0, $fv=0, $type=0)
154
- {
155
- $pmt = self::PMT($rate, $nper, $pv, $fv, $type);
156
- $capital = $pv;
157
- for ($i = 1; $i<= $per; ++$i) {
158
- $interest = ($type && $i == 1) ? 0 : -$capital * $rate;
159
- $principal = $pmt - $interest;
160
- $capital += $principal;
161
- }
162
- return array($interest, $principal);
163
- } // function _interestAndPrincipal()
164
-
165
-
166
- /**
167
- * ACCRINT
168
- *
169
- * Returns the accrued interest for a security that pays periodic interest.
170
- *
171
- * Excel Function:
172
- * ACCRINT(issue,firstinterest,settlement,rate,par,frequency[,basis])
173
- *
174
- * @access public
175
- * @category Financial Functions
176
- * @param mixed $issue The security's issue date.
177
- * @param mixed $firstinterest The security's first interest date.
178
- * @param mixed $settlement The security's settlement date.
179
- * The security settlement date is the date after the issue date
180
- * when the security is traded to the buyer.
181
- * @param float $rate The security's annual coupon rate.
182
- * @param float $par The security's par value.
183
- * If you omit par, ACCRINT uses $1,000.
184
- * @param integer $frequency the number of coupon payments per year.
185
- * Valid frequency values are:
186
- * 1 Annual
187
- * 2 Semi-Annual
188
- * 4 Quarterly
189
- * If working in Gnumeric Mode, the following frequency options are
190
- * also available
191
- * 6 Bimonthly
192
- * 12 Monthly
193
- * @param integer $basis The type of day count to use.
194
- * 0 or omitted US (NASD) 30/360
195
- * 1 Actual/actual
196
- * 2 Actual/360
197
- * 3 Actual/365
198
- * 4 European 30/360
199
- * @return float
200
- */
201
- public static function ACCRINT($issue, $firstinterest, $settlement, $rate, $par=1000, $frequency=1, $basis=0)
202
- {
203
- $issue = PHPExcel_Calculation_Functions::flattenSingleValue($issue);
204
- $firstinterest = PHPExcel_Calculation_Functions::flattenSingleValue($firstinterest);
205
- $settlement = PHPExcel_Calculation_Functions::flattenSingleValue($settlement);
206
- $rate = PHPExcel_Calculation_Functions::flattenSingleValue($rate);
207
- $par = (is_null($par)) ? 1000 : PHPExcel_Calculation_Functions::flattenSingleValue($par);
208
- $frequency = (is_null($frequency)) ? 1 : PHPExcel_Calculation_Functions::flattenSingleValue($frequency);
209
- $basis = (is_null($basis)) ? 0 : PHPExcel_Calculation_Functions::flattenSingleValue($basis);
210
-
211
- // Validate
212
- if ((is_numeric($rate)) && (is_numeric($par))) {
213
- $rate = (float) $rate;
214
- $par = (float) $par;
215
- if (($rate <= 0) || ($par <= 0)) {
216
- return PHPExcel_Calculation_Functions::NaN();
217
- }
218
- $daysBetweenIssueAndSettlement = PHPExcel_Calculation_DateTime::YEARFRAC($issue, $settlement, $basis);
219
- if (!is_numeric($daysBetweenIssueAndSettlement)) {
220
- // return date error
221
- return $daysBetweenIssueAndSettlement;
222
- }
223
-
224
- return $par * $rate * $daysBetweenIssueAndSettlement;
225
- }
226
- return PHPExcel_Calculation_Functions::VALUE();
227
- } // function ACCRINT()
228
-
229
-
230
- /**
231
- * ACCRINTM
232
- *
233
- * Returns the accrued interest for a security that pays interest at ma