2d3e57c6 by Marty Penner

Promoting r256 to live. refs #1185

1 parent 77239666
Showing 424 changed files with 4921 additions and 0 deletions
1 <?php
2 namespace Tz\Wordpress\Tools\ExcelWriter;
3 /**
4 * PHPExcel
5 *
6 * Copyright (c) 2006 - 2011 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
24 * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
25 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
26 * @version 1.7.6, 2011-02-27
27 */
28
29 PHPExcel_Autoloader::Register();
30 PHPExcel_Shared_ZipStreamWrapper::register();
31 // check mbstring.func_overload
32 if (ini_get('mbstring.func_overload') & 2) {
33 throw new Exception('Multibyte function overloading in PHP must be disabled for string functions (2).');
34 }
35 PHPExcel_Shared_String::buildCharacterSets();
36
37
38 class PHPExcel_Autoloader
39 {
40 public static function Register() {
41 return spl_autoload_register(array(__NAMESPACE__ . '\\' . 'PHPExcel_Autoloader', 'Load'));
42 } // function Register()
43
44
45 public static function Load($pObjectName){
46 if ((class_exists($pObjectName)) || (strpos($pObjectName, 'PHPExcel') === False)) {
47 return false;
48 }
49
50 if (false !== strpos($pObjectName, '\\')) {
51 $pObjectName = str_ireplace('\\', DIRECTORY_SEPARATOR, array_pop(explode('\\', $pObjectName)));
52 }
53 // var_dump($pObjectName);
54 $pObjectFilePath = PHPEXCEL_ROOT.
55 str_replace('_',DIRECTORY_SEPARATOR,$pObjectName).
56 '.php';
57
58 if ((file_exists($pObjectFilePath) === false) || (is_readable($pObjectFilePath) === false)) {
59 return false;
60 }
61
62 require_once $pObjectFilePath;
63 } // function Load()
64
65 }
...\ No newline at end of file ...\ No newline at end of file
1 <?php
2 /**
3 * PHPExcel
4 *
5 * Copyright (c) 2006 - 2011 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 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
24 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25 * @version 1.7.6, 2011-02-27
26 */
27
28
29 /**
30 * PHPExcel_CachedObjectStorage_APC
31 *
32 * @category PHPExcel
33 * @package PHPExcel_CachedObjectStorage
34 * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
35 */
36 class PHPExcel_CachedObjectStorage_APC extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {
37
38 private $_cachePrefix = null;
39
40 private $_cacheTime = 600;
41
42
43 private function _storeData() {
44 $this->_currentObject->detach();
45
46 if (!apc_store($this->_cachePrefix.$this->_currentObjectID.'.cache',serialize($this->_currentObject),$this->_cacheTime)) {
47 $this->__destruct();
48 throw new Exception('Failed to store cell '.$cellID.' in APC');
49 }
50 $this->_currentObjectID = $this->_currentObject = null;
51 } // function _storeData()
52
53
54 /**
55 * Add or Update a cell in cache identified by coordinate address
56 *
57 * @param string $pCoord Coordinate address of the cell to update
58 * @param PHPExcel_Cell $cell Cell to update
59 * @return void
60 * @throws Exception
61 */
62 public function addCacheData($pCoord, PHPExcel_Cell $cell) {
63 if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) {
64 $this->_storeData();
65 }
66 $this->_cellCache[$pCoord] = true;
67
68 $this->_currentObjectID = $pCoord;
69 $this->_currentObject = $cell;
70
71 return $cell;
72 } // function addCacheData()
73
74
75 /**
76 * Is a value set in the current PHPExcel_CachedObjectStorage_ICache for an indexed cell?
77 *
78 * @param string $pCoord Coordinate address of the cell to check
79 * @return void
80 * @return boolean
81 */
82 public function isDataSet($pCoord) {
83 // Check if the requested entry is the current object, or exists in the cache
84 if (parent::isDataSet($pCoord)) {
85 if ($this->_currentObjectID == $pCoord) {
86 return true;
87 }
88 // Check if the requested entry still exists in apc
89 $success = apc_fetch($this->_cachePrefix.$pCoord.'.cache');
90 if ($success === false) {
91 // Entry no longer exists in APC, so clear it from the cache array
92 parent::deleteCacheData($pCoord);
93 throw new Exception('Cell entry '.$cellID.' no longer exists in APC');
94 }
95 return true;
96 }
97 return false;
98 } // function isDataSet()
99
100
101 /**
102 * Get cell at a specific coordinate
103 *
104 * @param string $pCoord Coordinate of the cell
105 * @throws Exception
106 * @return PHPExcel_Cell Cell that was found, or null if not found
107 */
108 public function getCacheData($pCoord) {
109 if ($pCoord === $this->_currentObjectID) {
110 return $this->_currentObject;
111 }
112 $this->_storeData();
113
114 // Check if the entry that has been requested actually exists
115 if (parent::isDataSet($pCoord)) {
116 $obj = apc_fetch($this->_cachePrefix.$pCoord.'.cache');
117 if ($obj === false) {
118 // Entry no longer exists in APC, so clear it from the cache array
119 parent::deleteCacheData($pCoord);
120 throw new Exception('Cell entry '.$cellID.' no longer exists in APC');
121 }
122 } else {
123 // Return null if requested entry doesn't exist in cache
124 return null;
125 }
126
127 // Set current entry to the requested entry
128 $this->_currentObjectID = $pCoord;
129 $this->_currentObject = unserialize($obj);
130 // Re-attach the parent worksheet
131 $this->_currentObject->attach($this->_parent);
132
133 // Return requested entry
134 return $this->_currentObject;
135 } // function getCacheData()
136
137
138 /**
139 * Delete a cell in cache identified by coordinate address
140 *
141 * @param string $pCoord Coordinate address of the cell to delete
142 * @throws Exception
143 */
144 public function deleteCacheData($pCoord) {
145 // Delete the entry from APC
146 apc_delete($this->_cachePrefix.$pCoord.'.cache');
147
148 // Delete the entry from our cell address array
149 parent::deleteCacheData($pCoord);
150 } // function deleteCacheData()
151
152
153 /**
154 * Clone the cell collection
155 *
156 * @return void
157 */
158 public function copyCellCollection(PHPExcel_Worksheet $parent) {
159 parent::copyCellCollection($parent);
160 // Get a new id for the new file name
161 $baseUnique = $this->_getUniqueID();
162 $newCachePrefix = substr(md5($baseUnique),0,8).'.';
163 $cacheList = $this->getCellList();
164 foreach($cacheList as $cellID) {
165 if ($cellID != $this->_currentObjectID) {
166 $obj = apc_fetch($this->_cachePrefix.$cellID.'.cache');
167 if ($obj === false) {
168 // Entry no longer exists in APC, so clear it from the cache array
169 parent::deleteCacheData($cellID);
170 throw new Exception('Cell entry '.$cellID.' no longer exists in APC');
171 }
172 if (!apc_store($newCachePrefix.$cellID.'.cache',$obj,$this->_cacheTime)) {
173 $this->__destruct();
174 throw new Exception('Failed to store cell '.$cellID.' in APC');
175 }
176 }
177 }
178 $this->_cachePrefix = $newCachePrefix;
179 } // function copyCellCollection()
180
181
182 public function unsetWorksheetCells() {
183 if(!is_null($this->_currentObject)) {
184 $this->_currentObject->detach();
185 $this->_currentObject = $this->_currentObjectID = null;
186 }
187
188 // Flush the APC cache
189 $this->__destruct();
190
191 $this->_cellCache = array();
192
193 // detach ourself from the worksheet, so that it can then delete this object successfully
194 $this->_parent = null;
195 } // function unsetWorksheetCells()
196
197
198 public function __construct(PHPExcel_Worksheet $parent, $arguments) {
199 $cacheTime = (isset($arguments['cacheTime'])) ? $arguments['cacheTime'] : 600;
200
201 if (is_null($this->_cachePrefix)) {
202 $baseUnique = $this->_getUniqueID();
203 $this->_cachePrefix = substr(md5($baseUnique),0,8).'.';
204 $this->_cacheTime = $cacheTime;
205
206 parent::__construct($parent);
207 }
208 } // function __construct()
209
210
211 public function __destruct() {
212 $cacheList = $this->getCellList();
213 foreach($cacheList as $cellID) {
214 apc_delete($this->_cachePrefix.$cellID.'.cache');
215 }
216 } // function __destruct()
217
218 }
1 <?php
2 /**
3 * PHPExcel
4 *
5 * Copyright (c) 2006 - 2011 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 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
24 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25 * @version 1.7.6, 2011-02-27
26 */
27
28
29 /**
30 * PHPExcel_CachedObjectStorage_CacheBase
31 *
32 * @category PHPExcel
33 * @package PHPExcel_CachedObjectStorage
34 * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
35 */
36 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 * An array of cells or cell pointers for the worksheet cells held in this cache,
62 * and indexed by their coordinate address within the worksheet
63 *
64 * @var array of mixed
65 */
66 protected $_cellCache = array();
67
68
69 public function __construct(Tz\Wordpress\Tools\ExcelWriter\PHPExcel_Worksheet $parent) {
70 // Set our parent worksheet.
71 // This is maintained within the cache controller to facilitate re-attaching it to PHPExcel_Cell objects when
72 // they are woken from a serialized state
73 $this->_parent = $parent;
74 } // function __construct()
75
76
77 /**
78 * Is a value set in the current PHPExcel_CachedObjectStorage_ICache for an indexed cell?
79 *
80 * @param string $pCoord Coordinate address of the cell to check
81 * @return void
82 * @return boolean
83 */
84 public function isDataSet($pCoord) {
85 if ($pCoord === $this->_currentObjectID) {
86 return true;
87 }
88 // Check if the requested entry exists in the cache
89 return isset($this->_cellCache[$pCoord]);
90 } // function isDataSet()
91
92
93 /**
94 * Add or Update a cell in cache
95 *
96 * @param PHPExcel_Cell $cell Cell to update
97 * @return void
98 * @throws Exception
99 */
100 public function updateCacheData(Tz\Wordpress\Tools\ExcelWriter\PHPExcel_Cell $cell) {
101 return $this->addCacheData($cell->getCoordinate(),$cell);
102 } // function updateCacheData()
103
104
105 /**
106 * Delete a cell in cache identified by coordinate address
107 *
108 * @param string $pCoord Coordinate address of the cell to delete
109 * @throws Exception
110 */
111 public function deleteCacheData($pCoord) {
112 if ($pCoord === $this->_currentObjectID) {
113 $this->_currentObject->detach();
114 $this->_currentObjectID = $this->_currentObject = null;
115 }
116
117 if (is_object($this->_cellCache[$pCoord])) {
118 $this->_cellCache[$pCoord]->detach();
119 unset($this->_cellCache[$pCoord]);
120 }
121 } // function deleteCacheData()
122
123
124 /**
125 * Get a list of all cell addresses currently held in cache
126 *
127 * @return array of string
128 */
129 public function getCellList() {
130 return array_keys($this->_cellCache);
131 } // function getCellList()
132
133
134 /**
135 * Sort the list of all cell addresses currently held in cache by row and column
136 *
137 * @return void
138 */
139 public function getSortedCellList() {
140 $sortKeys = array();
141 foreach (array_keys($this->_cellCache) as $coord) {
142 list($column,$row) = sscanf($coord,'%[A-Z]%d');
143 $sortKeys[sprintf('%09d%3s',$row,$column)] = $coord;
144 }
145 ksort($sortKeys);
146
147 return array_values($sortKeys);
148 } // function sortCellList()
149
150
151 protected function _getUniqueID() {
152 if (function_exists('posix_getpid')) {
153 $baseUnique = posix_getpid();
154 } else {
155 $baseUnique = mt_rand();
156 }
157 return uniqid($baseUnique,true);
158 }
159
160 /**
161 * Clone the cell collection
162 *
163 * @return void
164 */
165 public function copyCellCollection(PHPExcel_Worksheet $parent) {
166 $this->_parent = $parent;
167 if ((!is_null($this->_currentObject)) && (is_object($this->_currentObject))) {
168 $this->_currentObject->attach($parent);
169 }
170 } // function copyCellCollection()
171
172 }
1 <?php
2 /**
3 * PHPExcel
4 *
5 * Copyright (c) 2006 - 2011 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 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
24 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25 * @version 1.7.6, 2011-02-27
26 */
27
28
29 /**
30 * PHPExcel_CachedObjectStorage_DiscISAM
31 *
32 * @category PHPExcel
33 * @package PHPExcel_CachedObjectStorage
34 * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
35 */
36 class PHPExcel_CachedObjectStorage_DiscISAM extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {
37
38 private $_fileName = null;
39 private $_fileHandle = null;
40
41
42 private function _storeData() {
43 $this->_currentObject->detach();
44
45 fseek($this->_fileHandle,0,SEEK_END);
46 $offset = ftell($this->_fileHandle);
47 fwrite($this->_fileHandle, serialize($this->_currentObject));
48 $this->_cellCache[$this->_currentObjectID] = array('ptr' => $offset,
49 'sz' => ftell($this->_fileHandle) - $offset
50 );
51 $this->_currentObjectID = $this->_currentObject = null;
52 } // function _storeData()
53
54
55 /**
56 * Add or Update a cell in cache identified by coordinate address
57 *
58 * @param string $pCoord Coordinate address of the cell to update
59 * @param PHPExcel_Cell $cell Cell to update
60 * @return void
61 * @throws Exception
62 */
63 public function addCacheData($pCoord, PHPExcel_Cell $cell) {
64 if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) {
65 $this->_storeData();
66 }
67
68 $this->_currentObjectID = $pCoord;
69 $this->_currentObject = $cell;
70
71 return $cell;
72 } // function addCacheData()
73
74
75 /**
76 * Get cell at a specific coordinate
77 *
78 * @param string $pCoord Coordinate of the cell
79 * @throws Exception
80 * @return PHPExcel_Cell Cell that was found, or null if not found
81 */
82 public function getCacheData($pCoord) {
83 if ($pCoord === $this->_currentObjectID) {
84 return $this->_currentObject;
85 }
86 $this->_storeData();
87
88 // Check if the entry that has been requested actually exists
89 if (!isset($this->_cellCache[$pCoord])) {
90 // Return null if requested entry doesn't exist in cache
91 return null;
92 }
93
94 // Set current entry to the requested entry
95 $this->_currentObjectID = $pCoord;
96 fseek($this->_fileHandle,$this->_cellCache[$pCoord]['ptr']);
97 $this->_currentObject = unserialize(fread($this->_fileHandle,$this->_cellCache[$pCoord]['sz']));
98 // Re-attach the parent worksheet
99 $this->_currentObject->attach($this->_parent);
100
101 // Return requested entry
102 return $this->_currentObject;
103 } // function getCacheData()
104
105
106 /**
107 * Clone the cell collection
108 *
109 * @return void
110 */
111 public function copyCellCollection(PHPExcel_Worksheet $parent) {
112 parent::copyCellCollection($parent);
113 // Get a new id for the new file name
114 $baseUnique = $this->_getUniqueID();
115 $newFileName = PHPExcel_Shared_File::sys_get_temp_dir().'/PHPExcel.'.$baseUnique.'.cache';
116 // Copy the existing cell cache file
117 copy ($this->_fileName,$newFileName);
118 $this->_fileName = $newFileName;
119 // Open the copied cell cache file
120 $this->_fileHandle = fopen($this->_fileName,'a+');
121 } // function copyCellCollection()
122
123
124 public function unsetWorksheetCells() {
125 if(!is_null($this->_currentObject)) {
126 $this->_currentObject->detach();
127 $this->_currentObject = $this->_currentObjectID = null;
128 }
129 $this->_cellCache = array();
130
131 // detach ourself from the worksheet, so that it can then delete this object successfully
132 $this->_parent = null;
133
134 // Close down the temporary cache file
135 $this->__destruct();
136 } // function unsetWorksheetCells()
137
138
139 public function __construct(PHPExcel_Worksheet $parent) {
140 parent::__construct($parent);
141 if (is_null($this->_fileHandle)) {
142 $baseUnique = $this->_getUniqueID();
143 $this->_fileName = PHPExcel_Shared_File::sys_get_temp_dir().'/PHPExcel.'.$baseUnique.'.cache';
144 $this->_fileHandle = fopen($this->_fileName,'a+');
145 }
146 } // function __construct()
147
148
149 public function __destruct() {
150 if (!is_null($this->_fileHandle)) {
151 fclose($this->_fileHandle);
152 unlink($this->_fileName);
153 }
154 $this->_fileHandle = null;
155 } // function __destruct()
156
157 }
1 <?php
2 /**
3 * PHPExcel
4 *
5 * Copyright (c) 2006 - 2011 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 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
24 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25 * @version 1.7.6, 2011-02-27
26 */
27
28
29 /**
30 * PHPExcel_CachedObjectStorage_ICache
31 *
32 * @category PHPExcel
33 * @package PHPExcel_CachedObjectStorage
34 * @copyright Copyright (c) 2006 - 2011 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 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 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 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 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 void
79 * @return boolean
80 */
81 public function isDataSet($pCoord);
82
83 /**
84 * Get a list of all cell addresses currently held in cache
85 *
86 * @return array of string
87 */
88 public function getCellList();
89
90 /**
91 * Get the list of all cell addresses currently held in cache sorted by column and row
92 *
93 * @return void
94 */
95 public function getSortedCellList();
96
97 /**
98 * Clone the cell collection
99 *
100 * @return void
101 */
102 public function copyCellCollection(PHPExcel_Worksheet $parent);
103
104 }
1 <?php
2 /**
3 * PHPExcel
4 *
5 * Copyright (c) 2006 - 2011 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 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
24 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25 * @version 1.7.6, 2011-02-27
26 */
27
28
29 /**
30 * PHPExcel_CachedObjectStorage_Memcache
31 *
32 * @category PHPExcel
33 * @package PHPExcel_CachedObjectStorage
34 * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
35 */
36 class PHPExcel_CachedObjectStorage_Memcache extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {
37
38 private $_cachePrefix = null;
39
40 private $_cacheTime = 600;
41
42 private $_memcache = null;
43
44
45 private function _storeData() {
46 $this->_currentObject->detach();
47
48 $obj = serialize($this->_currentObject);
49 if (!$this->_memcache->replace($this->_cachePrefix.$this->_currentObjectID.'.cache',$obj,NULL,$this->_cacheTime)) {
50 if (!$this->_memcache->add($this->_cachePrefix.$this->_currentObjectID.'.cache',$obj,NULL,$this->_cacheTime)) {
51 $this->__destruct();
52 throw new Exception('Failed to store cell '.$cellID.' in MemCache');
53 }
54 }
55 $this->_currentObjectID = $this->_currentObject = null;
56 } // function _storeData()
57
58
59 /**
60 * Add or Update a cell in cache identified by coordinate address
61 *
62 * @param string $pCoord Coordinate address of the cell to update
63 * @param PHPExcel_Cell $cell Cell to update
64 * @return void
65 * @throws Exception
66 */
67 public function addCacheData($pCoord, PHPExcel_Cell $cell) {
68 if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) {
69 $this->_storeData();
70 }
71 $this->_cellCache[$pCoord] = true;
72
73 $this->_currentObjectID = $pCoord;
74 $this->_currentObject = $cell;
75
76 return $cell;
77 } // function addCacheData()
78
79
80 /**
81 * Is a value set in the current PHPExcel_CachedObjectStorage_ICache for an indexed cell?
82 *
83 * @param string $pCoord Coordinate address of the cell to check
84 * @return void
85 * @return boolean
86 */
87 public function isDataSet($pCoord) {
88 // Check if the requested entry is the current object, or exists in the cache
89 if (parent::isDataSet($pCoord)) {
90 if ($this->_currentObjectID == $pCoord) {
91 return true;
92 }
93 // Check if the requested entry still exists in Memcache
94 $success = $this->_memcache->get($this->_cachePrefix.$pCoord.'.cache');
95 if ($success === false) {
96 // Entry no longer exists in Memcache, so clear it from the cache array
97 parent::deleteCacheData($pCoord);
98 throw new Exception('Cell entry '.$cellID.' no longer exists in MemCache');
99 }
100 return true;
101 }
102 return false;
103 } // function isDataSet()
104
105
106 /**
107 * Get cell at a specific coordinate
108 *
109 * @param string $pCoord Coordinate of the cell
110 * @throws Exception
111 * @return PHPExcel_Cell Cell that was found, or null if not found
112 */
113 public function getCacheData($pCoord) {
114 if ($pCoord === $this->_currentObjectID) {
115 return $this->_currentObject;
116 }
117 $this->_storeData();
118
119 // Check if the entry that has been requested actually exists
120 if (parent::isDataSet($pCoord)) {
121 $obj = $this->_memcache->get($this->_cachePrefix.$pCoord.'.cache');
122 if ($obj === false) {
123 // Entry no longer exists in Memcache, so clear it from the cache array
124 parent::deleteCacheData($pCoord);
125 throw new Exception('Cell entry '.$cellID.' no longer exists in MemCache');
126 }
127 } else {
128 // Return null if requested entry doesn't exist in cache
129 return null;
130 }
131
132 // Set current entry to the requested entry
133 $this->_currentObjectID = $pCoord;
134 $this->_currentObject = unserialize($obj);
135 // Re-attach the parent worksheet
136 $this->_currentObject->attach($this->_parent);
137
138 // Return requested entry
139 return $this->_currentObject;
140 } // function getCacheData()
141
142
143 /**
144 * Delete a cell in cache identified by coordinate address
145 *
146 * @param string $pCoord Coordinate address of the cell to delete
147 * @throws Exception
148 */
149 public function deleteCacheData($pCoord) {
150 // Delete the entry from Memcache
151 $this->_memcache->delete($this->_cachePrefix.$pCoord.'.cache');
152
153 // Delete the entry from our cell address array
154 parent::deleteCacheData($pCoord);
155 } // function deleteCacheData()
156
157
158 /**
159 * Clone the cell collection
160 *
161 * @return void
162 */
163 public function copyCellCollection(PHPExcel_Worksheet $parent) {
164 parent::copyCellCollection($parent);
165 // Get a new id for the new file name
166 $baseUnique = $this->_getUniqueID();
167 $newCachePrefix = substr(md5($baseUnique),0,8).'.';
168 $cacheList = $this->getCellList();
169 foreach($cacheList as $cellID) {
170 if ($cellID != $this->_currentObjectID) {
171 $obj = $this->_memcache->get($this->_cachePrefix.$cellID.'.cache');
172 if ($obj === false) {
173 // Entry no longer exists in Memcache, so clear it from the cache array
174 parent::deleteCacheData($cellID);
175 throw new Exception('Cell entry '.$cellID.' no longer exists in MemCache');
176 }
177 if (!$this->_memcache->add($newCachePrefix.$cellID.'.cache',$obj,NULL,$this->_cacheTime)) {
178 $this->__destruct();
179 throw new Exception('Failed to store cell '.$cellID.' in MemCache');
180 }
181 }
182 }
183 $this->_cachePrefix = $newCachePrefix;
184 } // function copyCellCollection()
185
186
187 public function unsetWorksheetCells() {
188 if(!is_null($this->_currentObject)) {
189 $this->_currentObject->detach();
190 $this->_currentObject = $this->_currentObjectID = null;
191 }
192
193 // Flush the Memcache cache
194 $this->__destruct();
195
196 $this->_cellCache = array();
197
198 // detach ourself from the worksheet, so that it can then delete this object successfully
199 $this->_parent = null;
200 } // function unsetWorksheetCells()
201
202
203 public function __construct(PHPExcel_Worksheet $parent, $arguments) {
204 $memcacheServer = (isset($arguments['memcacheServer'])) ? $arguments['memcacheServer'] : 'localhost';
205 $memcachePort = (isset($arguments['memcachePort'])) ? $arguments['memcachePort'] : 11211;
206 $cacheTime = (isset($arguments['cacheTime'])) ? $arguments['cacheTime'] : 600;
207
208 if (is_null($this->_cachePrefix)) {
209 $baseUnique = $this->_getUniqueID();
210 $this->_cachePrefix = substr(md5($baseUnique),0,8).'.';
211
212 // Set a new Memcache object and connect to the Memcache server
213 $this->_memcache = new Memcache();
214 if (!$this->_memcache->addServer($memcacheServer, $memcachePort, false, 50, 5, 5, true, array($this, 'failureCallback'))) {
215 throw new Exception('Could not connect to MemCache server at '.$memcacheServer.':'.$memcachePort);
216 }
217 $this->_cacheTime = $cacheTime;
218
219 parent::__construct($parent);
220 }
221 } // function __construct()
222
223
224 public function failureCallback($host, $port) {
225 throw new Exception('memcache '.$host.':'.$port.' failed');
226 }
227
228
229 public function __destruct() {
230 $cacheList = $this->getCellList();
231 foreach($cacheList as $cellID) {
232 $this->_memcache->delete($this->_cachePrefix.$cellID.'.cache');
233 }
234 } // function __destruct()
235
236 }
1 <?php
2 /**
3 * PHPExcel
4 *
5 * Copyright (c) 2006 - 2011 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 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
24 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25 * @version 1.7.6, 2011-02-27
26 */
27
28
29 /**
30 * PHPExcel_CachedObjectStorage_Memory
31 *
32 * @category PHPExcel
33 * @package PHPExcel_CachedObjectStorage
34 * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
35 */
36 class PHPExcel_CachedObjectStorage_Memory extends PHPExcel_CachedObjectStorage_CacheBase implements 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 Exception
45 */
46 public function addCacheData($pCoord, Tz\Wordpress\Tools\ExcelWriter\PHPExcel_Cell $cell) {
47 $this->_cellCache[$pCoord] = $cell;
48 return $cell;
49 } // function addCacheData()
50
51
52 /**
53 * Get cell at a specific coordinate
54 *
55 * @param string $pCoord Coordinate of the cell
56 * @throws Exception
57 * @return PHPExcel_Cell Cell that was found, or null if not found
58 */
59 public function getCacheData($pCoord) {
60 // Check if the entry that has been requested actually exists
61 if (!isset($this->_cellCache[$pCoord])) {
62 // Return null if requested entry doesn't exist in cache
63 return null;
64 }
65
66 // Return requested entry
67 return $this->_cellCache[$pCoord];
68 } // function getCacheData()
69
70
71 public function copyCellCollection(PHPExcel_Worksheet $parent) {
72 parent::copyCellCollection($parent);
73
74 $newCollection = array();
75 foreach($this->_cellCache as $k => &$cell) {
76 $newCollection[$k] = clone $cell;
77 $newCollection[$k]->attach($parent);
78 }
79
80 $this->_cellCache = $newCollection;
81 }
82
83
84 public function unsetWorksheetCells() {
85 // Because cells are all stored as intact objects in memory, we need to detach each one from the parent
86 foreach($this->_cellCache as $k => &$cell) {
87 $cell->detach();
88 $this->_cellCache[$k] = null;
89 }
90 unset($cell);
91
92 $this->_cellCache = array();
93
94 // detach ourself from the worksheet, so that it can then delete this object successfully
95 $this->_parent = null;
96 } // function unsetWorksheetCells()
97
98 }
1 <?php
2 /**
3 * PHPExcel
4 *
5 * Copyright (c) 2006 - 2011 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 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
24 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25 * @version 1.7.6, 2011-02-27
26 */
27
28
29 /**
30 * PHPExcel_CachedObjectStorage_MemoryGZip
31 *
32 * @category PHPExcel
33 * @package PHPExcel_CachedObjectStorage
34 * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
35 */
36 class PHPExcel_CachedObjectStorage_MemoryGZip extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {
37
38 private function _storeData() {
39 $this->_currentObject->detach();
40
41 $this->_cellCache[$this->_currentObjectID] = gzdeflate(serialize($this->_currentObject));
42 $this->_currentObjectID = $this->_currentObject = null;
43 } // function _storeData()
44
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 void
52 * @throws Exception
53 */
54 public function addCacheData($pCoord, PHPExcel_Cell $cell) {
55 if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) {
56 $this->_storeData();
57 }
58
59 $this->_currentObjectID = $pCoord;
60 $this->_currentObject = $cell;
61
62 return $cell;
63 } // function addCacheData()
64
65
66 /**
67 * Get cell at a specific coordinate
68 *
69 * @param string $pCoord Coordinate of the cell
70 * @throws Exception
71 * @return PHPExcel_Cell Cell that was found, or null if not found
72 */
73 public function getCacheData($pCoord) {
74 if ($pCoord === $this->_currentObjectID) {
75 return $this->_currentObject;
76 }
77 $this->_storeData();
78
79 // Check if the entry that has been requested actually exists
80 if (!isset($this->_cellCache[$pCoord])) {
81 // Return null if requested entry doesn't exist in cache
82 return null;
83 }
84
85 // Set current entry to the requested entry
86 $this->_currentObjectID = $pCoord;
87 $this->_currentObject = unserialize(gzinflate($this->_cellCache[$pCoord]));
88 // Re-attach the parent worksheet
89 $this->_currentObject->attach($this->_parent);
90
91 // Return requested entry
92 return $this->_currentObject;
93 } // function getCacheData()
94
95
96 public function unsetWorksheetCells() {
97 if(!is_null($this->_currentObject)) {
98 $this->_currentObject->detach();
99 $this->_currentObject = $this->_currentObjectID = null;
100 }
101 $this->_cellCache = array();
102
103 // detach ourself from the worksheet, so that it can then delete this object successfully
104 $this->_parent = null;
105 } // function unsetWorksheetCells()
106
107 }
1 <?php
2 /**
3 * PHPExcel
4 *
5 * Copyright (c) 2006 - 2011 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 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
24 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25 * @version 1.7.6, 2011-02-27
26 */
27
28
29 /**
30 * PHPExcel_CachedObjectStorage_MemorySerialized
31 *
32 * @category PHPExcel
33 * @package PHPExcel_CachedObjectStorage
34 * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
35 */
36 class PHPExcel_CachedObjectStorage_MemorySerialized extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {
37
38 private function _storeData() {
39 $this->_currentObject->detach();
40
41 $this->_cellCache[$this->_currentObjectID] = serialize($this->_currentObject);
42 $this->_currentObjectID = $this->_currentObject = null;
43 } // function _storeData()
44
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 void
52 * @throws Exception
53 */
54 public function addCacheData($pCoord, PHPExcel_Cell $cell) {
55 if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) {
56 $this->_storeData();
57 }
58
59 $this->_currentObjectID = $pCoord;
60 $this->_currentObject = $cell;
61
62 return $cell;
63 } // function addCacheData()
64
65
66 /**
67 * Get cell at a specific coordinate
68 *
69 * @param string $pCoord Coordinate of the cell
70 * @throws Exception
71 * @return PHPExcel_Cell Cell that was found, or null if not found
72 */
73 public function getCacheData($pCoord) {
74 if ($pCoord === $this->_currentObjectID) {
75 return $this->_currentObject;
76 }
77 $this->_storeData();
78
79 // Check if the entry that has been requested actually exists
80 if (!isset($this->_cellCache[$pCoord])) {
81 // Return null if requested entry doesn't exist in cache
82 return null;
83 }
84
85 // Set current entry to the requested entry
86 $this->_currentObjectID = $pCoord;
87 $this->_currentObject = unserialize($this->_cellCache[$pCoord]);
88 // Re-attach the parent worksheet
89 $this->_currentObject->attach($this->_parent);
90
91 // Return requested entry
92 return $this->_currentObject;
93 } // function getCacheData()
94
95
96 public function unsetWorksheetCells() {
97 if(!is_null($this->_currentObject)) {
98 $this->_currentObject->detach();
99 $this->_currentObject = $this->_currentObjectID = null;
100 }
101 $this->_cellCache = array();
102
103 // detach ourself from the worksheet, so that it can then delete this object successfully
104 $this->_parent = null;
105 } // function unsetWorksheetCells()
106
107 }
1 <?php
2 /**
3 * PHPExcel
4 *
5 * Copyright (c) 2006 - 2011 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 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
24 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25 * @version 1.7.6, 2011-02-27
26 */
27
28
29 /**
30 * PHPExcel_CachedObjectStorage_PHPTemp
31 *
32 * @category PHPExcel
33 * @package PHPExcel_CachedObjectStorage
34 * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
35 */
36 class PHPExcel_CachedObjectStorage_PHPTemp extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {
37
38 private $_fileHandle = null;
39
40
41 private $_memoryCacheSize = null;
42
43 private function _storeData() {
44 $this->_currentObject->detach();
45
46 fseek($this->_fileHandle,0,SEEK_END);
47 $offset = ftell($this->_fileHandle);
48 fwrite($this->_fileHandle, serialize($this->_currentObject));
49 $this->_cellCache[$this->_currentObjectID] = array('ptr' => $offset,
50 'sz' => ftell($this->_fileHandle) - $offset
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 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
72 return $cell;
73 } // function addCacheData()
74
75
76 /**
77 * Get cell at a specific coordinate
78 *
79 * @param string $pCoord Coordinate of the cell
80 * @throws Exception
81 * @return PHPExcel_Cell Cell that was found, or null if not found
82 */
83 public function getCacheData($pCoord) {
84 if ($pCoord === $this->_currentObjectID) {
85 return $this->_currentObject;
86 }
87 $this->_storeData();
88
89 // Check if the entry that has been requested actually exists
90 if (!isset($this->_cellCache[$pCoord])) {
91 // Return null if requested entry doesn't exist in cache
92 return null;
93 }
94
95 // Set current entry to the requested entry
96 $this->_currentObjectID = $pCoord;
97 fseek($this->_fileHandle,$this->_cellCache[$pCoord]['ptr']);
98 $this->_currentObject = unserialize(fread($this->_fileHandle,$this->_cellCache[$pCoord]['sz']));
99 // Re-attach the parent worksheet
100 $this->_currentObject->attach($this->_parent);
101
102 // Return requested entry
103 return $this->_currentObject;
104 } // function getCacheData()
105
106
107 /**
108 * Clone the cell collection
109 *
110 * @return void
111 */
112 public function copyCellCollection(PHPExcel_Worksheet $parent) {
113 parent::copyCellCollection($parent);
114 // Open a new stream for the cell cache data
115 $newFileHandle = fopen('php://temp/maxmemory:'.$this->_memoryCacheSize,'a+');
116 // Copy the existing cell cache data to the new stream
117 fseek($this->_fileHandle,0);
118 while (!feof($this->_fileHandle)) {
119 fwrite($newFileHandle,fread($this->_fileHandle, 1024));
120 }
121 $this->_fileHandle = $newFileHandle;
122 } // function copyCellCollection()
123
124
125 public function unsetWorksheetCells() {
126 if(!is_null($this->_currentObject)) {
127 $this->_currentObject->detach();
128 $this->_currentObject = $this->_currentObjectID = null;
129 }
130 $this->_cellCache = array();
131
132 // detach ourself from the worksheet, so that it can then delete this object successfully
133 $this->_parent = null;
134
135 // Close down the php://temp file
136 $this->__destruct();
137 } // function unsetWorksheetCells()
138
139
140 public function __construct(PHPExcel_Worksheet $parent, $memoryCacheSize = '1MB') {
141 $this->_memoryCacheSize = (isset($arguments['memoryCacheSize'])) ? $arguments['memoryCacheSize'] : '1MB';
142
143 parent::__construct($parent);
144 if (is_null($this->_fileHandle)) {
145 $this->_fileHandle = fopen('php://temp/maxmemory:'.$this->_memoryCacheSize,'a+');
146 }
147 } // function __construct()
148
149
150 public function __destruct() {
151 if (!is_null($this->_fileHandle)) {
152 fclose($this->_fileHandle);
153 }
154 $this->_fileHandle = null;
155 } // function __destruct()
156
157 }
1 <?php
2 /**
3 * PHPExcel
4 *
5 * Copyright (c) 2006 - 2011 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 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
24 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25 * @version 1.7.6, 2011-02-27
26 */
27
28
29 /**
30 * PHPExcel_CachedObjectStorage_Wincache
31 *
32 * @category PHPExcel
33 * @package PHPExcel_CachedObjectStorage
34 * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
35 */
36 class PHPExcel_CachedObjectStorage_Wincache extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache {
37
38 private $_cachePrefix = null;
39
40 private $_cacheTime = 600;
41
42
43 private function _storeData() {
44 $this->_currentObject->detach();
45
46 $obj = serialize($this->_currentObject);
47 if (wincache_ucache_exists($this->_cachePrefix.$this->_currentObjectID.'.cache')) {
48 if (!wincache_ucache_set($this->_cachePrefix.$this->_currentObjectID.'.cache', $obj, $this->_cacheTime)) {
49 $this->__destruct();
50 throw new Exception('Failed to store cell '.$cellID.' in WinCache');
51 }
52 } else {
53 if (!wincache_ucache_add($this->_cachePrefix.$this->_currentObjectID.'.cache', $obj, $this->_cacheTime)) {
54 $this->__destruct();
55 throw new Exception('Failed to store cell '.$cellID.' in WinCache');
56 }
57 }
58
59 $this->_currentObjectID = $this->_currentObject = null;
60 } // function _storeData()
61
62
63 /**
64 * Add or Update a cell in cache identified by coordinate address
65 *
66 * @param string $pCoord Coordinate address of the cell to update
67 * @param PHPExcel_Cell $cell Cell to update
68 * @return void
69 * @throws Exception
70 */
71 public function addCacheData($pCoord, PHPExcel_Cell $cell) {
72 if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) {
73 $this->_storeData();
74 }
75 $this->_cellCache[$pCoord] = true;
76
77 $this->_currentObjectID = $pCoord;
78 $this->_currentObject = $cell;
79
80 return $cell;
81 } // function addCacheData()
82
83
84 /**
85 * Is a value set in the current PHPExcel_CachedObjectStorage_ICache for an indexed cell?
86 *
87 * @param string $pCoord Coordinate address of the cell to check
88 * @return void
89 * @return boolean
90 */
91 public function isDataSet($pCoord) {
92 // Check if the requested entry is the current object, or exists in the cache
93 if (parent::isDataSet($pCoord)) {
94 if ($this->_currentObjectID == $pCoord) {
95 return true;
96 }
97 // Check if the requested entry still exists in cache
98 $success = wincache_ucache_exists($this->_cachePrefix.$pCoord.'.cache');
99 if ($success === false) {
100 // Entry no longer exists in Wincache, so clear it from the cache array
101 parent::deleteCacheData($pCoord);
102 throw new Exception('Cell entry '.$cellID.' no longer exists in WinCache');
103 }
104 return true;
105 }
106 return false;
107 } // function isDataSet()
108
109
110 /**
111 * Get cell at a specific coordinate
112 *
113 * @param string $pCoord Coordinate of the cell
114 * @throws Exception
115 * @return PHPExcel_Cell Cell that was found, or null if not found
116 */
117 public function getCacheData($pCoord) {
118 if ($pCoord === $this->_currentObjectID) {
119 return $this->_currentObject;
120 }
121 $this->_storeData();
122
123 // Check if the entry that has been requested actually exists
124 $obj = null;
125 if (parent::isDataSet($pCoord)) {
126 $success = false;
127 $obj = wincache_ucache_get($this->_cachePrefix.$pCoord.'.cache', $success);
128 if ($success === false) {
129 // Entry no longer exists in WinCache, so clear it from the cache array
130 parent::deleteCacheData($pCoord);
131 throw new Exception('Cell entry '.$cellID.' no longer exists in WinCache');
132 }
133 } else {
134 // Return null if requested entry doesn't exist in cache
135 return null;
136 }
137
138 // Set current entry to the requested entry
139 $this->_currentObjectID = $pCoord;
140 $this->_currentObject = unserialize($obj);
141 // Re-attach the parent worksheet
142 $this->_currentObject->attach($this->_parent);
143
144 // Return requested entry
145 return $this->_currentObject;
146 } // function getCacheData()
147
148
149 /**
150 * Delete a cell in cache identified by coordinate address
151 *
152 * @param string $pCoord Coordinate address of the cell to delete
153 * @throws Exception
154 */
155 public function deleteCacheData($pCoord) {
156 // Delete the entry from Wincache
157 wincache_ucache_delete($this->_cachePrefix.$pCoord.'.cache');
158
159 // Delete the entry from our cell address array
160 parent::deleteCacheData($pCoord);
161 } // function deleteCacheData()
162
163
164 /**
165 * Clone the cell collection
166 *
167 * @return void
168 */
169 public function copyCellCollection(PHPExcel_Worksheet $parent) {
170 parent::copyCellCollection($parent);
171 // Get a new id for the new file name
172 $baseUnique = $this->_getUniqueID();
173 $newCachePrefix = substr(md5($baseUnique),0,8).'.';
174 $cacheList = $this->getCellList();
175 foreach($cacheList as $cellID) {
176 if ($cellID != $this->_currentObjectID) {
177 $success = false;
178 $obj = wincache_ucache_get($this->_cachePrefix.$cellID.'.cache', $success);
179 if ($success === false) {
180 // Entry no longer exists in WinCache, so clear it from the cache array
181 parent::deleteCacheData($cellID);
182 throw new Exception('Cell entry '.$cellID.' no longer exists in Wincache');
183 }
184 if (!wincache_ucache_add($newCachePrefix.$cellID.'.cache', $obj, $this->_cacheTime)) {
185 $this->__destruct();
186 throw new Exception('Failed to store cell '.$cellID.' in Wincache');
187 }
188 }
189 }
190 $this->_cachePrefix = $newCachePrefix;
191 } // function copyCellCollection()
192
193
194 public function unsetWorksheetCells() {
195 if(!is_null($this->_currentObject)) {
196 $this->_currentObject->detach();
197 $this->_currentObject = $this->_currentObjectID = null;
198 }
199
200 // Flush the WinCache cache
201 $this->__destruct();
202
203 $this->_cellCache = array();
204
205 // detach ourself from the worksheet, so that it can then delete this object successfully
206 $this->_parent = null;
207 } // function unsetWorksheetCells()
208
209
210 public function __construct(PHPExcel_Worksheet $parent, $arguments) {
211 $cacheTime = (isset($arguments['cacheTime'])) ? $arguments['cacheTime'] : 600;
212
213 if (is_null($this->_cachePrefix)) {
214 $baseUnique = $this->_getUniqueID();
215 $this->_cachePrefix = substr(md5($baseUnique),0,8).'.';
216 $this->_cacheTime = $cacheTime;
217
218 parent::__construct($parent);
219 }
220 } // function __construct()
221
222
223 public function __destruct() {
224 $cacheList = $this->getCellList();
225 foreach($cacheList as $cellID) {
226 wincache_ucache_delete($this->_cachePrefix.$cellID.'.cache');
227 }
228 } // function __destruct()
229
230 }
1 <?php
2 namespace Tz\Wordpress\Tools\ExcelWriter;
3
4 class PHPExcel_CachedObjectStorageFactory {
5 const cache_in_memory = 'Memory';
6 const cache_in_memory_gzip = 'MemoryGZip';
7 const cache_in_memory_serialized = 'MemorySerialized';
8 const cache_to_discISAM = 'DiscISAM';
9 const cache_to_apc = 'APC';
10 const cache_to_memcache = 'Memcache';
11 const cache_to_phpTemp = 'PHPTemp';
12 const cache_to_wincache = 'Wincache';
13
14
15 private static $_cacheStorageMethod = null;
16
17 private static $_cacheStorageClass = null;
18
19
20 private static $_storageMethods = array(
21 self::cache_in_memory,
22 self::cache_in_memory_gzip,
23 self::cache_in_memory_serialized,
24 self::cache_to_phpTemp,
25 self::cache_to_discISAM,
26 self::cache_to_apc,
27 self::cache_to_memcache,
28 self::cache_to_wincache,
29 );
30
31
32 private static $_storageMethodDefaultParameters = array(
33 self::cache_in_memory => array(
34 ),
35 self::cache_in_memory_gzip => array(
36 ),
37 self::cache_in_memory_serialized => array(
38 ),
39 self::cache_to_phpTemp => array( 'memoryCacheSize' => '1MB'
40 ),
41 self::cache_to_discISAM => array(
42 ),
43 self::cache_to_apc => array( 'cacheTime' => 600
44 ),
45 self::cache_to_memcache => array( 'memcacheServer' => 'localhost',
46 'memcachePort' => 11211,
47 'cacheTime' => 600
48 ),
49 self::cache_to_wincache => array( 'cacheTime' => 600
50 )
51 );
52
53
54 private static $_storageMethodParameters = array();
55
56
57 public static function getCacheStorageMethod() {
58 if (!is_null(self::$_cacheStorageMethod)) {
59 return self::$_cacheStorageMethod;
60 }
61 return null;
62 } // function getCacheStorageMethod()
63
64
65 public static function getCacheStorageClass() {
66 if (!is_null(self::$_cacheStorageClass)) {
67 return self::$_cacheStorageClass;
68 }
69 return null;
70 } // function getCacheStorageClass()
71
72
73 public static function getCacheStorageMethods() {
74 return self::$_storageMethods;
75 } // function getCacheStorageMethods()
76
77
78 public static function initialize($method = self::cache_in_memory, $arguments = array()) {
79 if (!in_array($method,self::$_storageMethods)) {
80 return false;
81 }
82
83 switch($method) {
84 case self::cache_to_apc :
85 if (!function_exists('apc_store')) {
86 return false;
87 }
88 if (apc_sma_info() === false) {
89 return false;
90 }
91 break;
92 case self::cache_to_memcache :
93 if (!function_exists('memcache_add')) {
94 return false;
95 }
96 break;
97 case self::cache_to_wincache :
98 if (!function_exists('wincache_ucache_add')) {
99 return false;
100 }
101 break;
102 }
103
104 self::$_storageMethodParameters[$method] = self::$_storageMethodDefaultParameters[$method];
105 foreach($arguments as $k => $v) {
106 if (isset(self::$_storageMethodParameters[$method][$k])) {
107 self::$_storageMethodParameters[$method][$k] = $v;
108 }
109 }
110
111 if (is_null(self::$_cacheStorageMethod)) {
112 self::$_cacheStorageClass = 'PHPExcel_CachedObjectStorage_'.$method;
113 self::$_cacheStorageMethod = $method;
114 }
115 return true;
116 } // function initialize()
117
118
119 public static function getInstance(PHPExcel_Worksheet $parent) {
120 if (is_null(self::$_cacheStorageMethod)) {
121 self::initialize();
122 }
123
124 $instance = new self::$_cacheStorageClass($parent,self::$_storageMethodParameters[self::$_cacheStorageMethod]);
125 if (!is_null($instance)) {
126 return $instance;
127 }
128
129 return false;
130 } // function getInstance()
131
132 }
...\ No newline at end of file ...\ No newline at end of file
This diff could not be displayed because it is too large.
1 <?php
2 /**
3 * PHPExcel
4 *
5 * Copyright (c) 2006 - 2011 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 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
24 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25 * @version 1.7.6, 2011-02-27
26 */
27
28
29 /**
30 * PHPExcel_Calculation_Exception
31 *
32 * @category PHPExcel
33 * @package PHPExcel_Calculation
34 * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
35 */
36 class PHPExcel_Calculation_Exception extends 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 * PHPExcel
4 *
5 * Copyright (c) 2006 - 2011 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 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
24 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25 * @version 1.7.6, 2011-02-27
26 */
27
28 /**
29 * PHPExcel_Calculation_ExceptionHandler
30 *
31 * @category PHPExcel
32 * @package PHPExcel_Calculation
33 * @copyright Copyright (c) 2006 - 2011 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 * PHPExcel
4 *
5 * Copyright (c) 2006 - 2011 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 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
24 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25 * @version 1.7.6, 2011-02-27
26 */
27
28
29 /*
30 PARTLY BASED ON:
31 Copyright (c) 2007 E. W. Bachtal, Inc.
32
33 Permission is hereby granted, free of charge, to any person obtaining a copy of this software
34 and associated documentation files (the "Software"), to deal in the Software without restriction,
35 including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
36 and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
37 subject to the following conditions:
38
39 The above copyright notice and this permission notice shall be included in all copies or substantial
40 portions of the Software.
41
42 The software is provided "as is", without warranty of any kind, express or implied, including but not
43 limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In
44 no event shall the authors or copyright holders be liable for any claim, damages or other liability,
45 whether in an action of contract, tort or otherwise, arising from, out of or in connection with the
46 software or the use or other dealings in the software.
47
48 http://ewbi.blogs.com/develops/2007/03/excel_formula_p.html
49 http://ewbi.blogs.com/develops/2004/12/excel_formula_p.html
50 */
51
52
53 /**
54 * PHPExcel_Calculation_FormulaToken
55 *
56 * @category PHPExcel
57 * @package PHPExcel_Calculation
58 * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
59 */
60 class PHPExcel_Calculation_FormulaToken {
61 /* Token types */
62 const TOKEN_TYPE_NOOP = 'Noop';
63 const TOKEN_TYPE_OPERAND = 'Operand';
64 const TOKEN_TYPE_FUNCTION = 'Function';
65 const TOKEN_TYPE_SUBEXPRESSION = 'Subexpression';
66 const TOKEN_TYPE_ARGUMENT = 'Argument';
67 const TOKEN_TYPE_OPERATORPREFIX = 'OperatorPrefix';
68 const TOKEN_TYPE_OPERATORINFIX = 'OperatorInfix';
69 const TOKEN_TYPE_OPERATORPOSTFIX = 'OperatorPostfix';
70 const TOKEN_TYPE_WHITESPACE = 'Whitespace';
71 const TOKEN_TYPE_UNKNOWN = 'Unknown';
72
73 /* Token subtypes */
74 const TOKEN_SUBTYPE_NOTHING = 'Nothing';
75 const TOKEN_SUBTYPE_START = 'Start';
76 const TOKEN_SUBTYPE_STOP = 'Stop';
77 const TOKEN_SUBTYPE_TEXT = 'Text';
78 const TOKEN_SUBTYPE_NUMBER = 'Number';
79 const TOKEN_SUBTYPE_LOGICAL = 'Logical';
80 const TOKEN_SUBTYPE_ERROR = 'Error';
81 const TOKEN_SUBTYPE_RANGE = 'Range';
82 const TOKEN_SUBTYPE_MATH = 'Math';
83 const TOKEN_SUBTYPE_CONCATENATION = 'Concatenation';
84 const TOKEN_SUBTYPE_INTERSECTION = 'Intersection';
85 const TOKEN_SUBTYPE_UNION = 'Union';
86
87 /**
88 * Value
89 *
90 * @var string
91 */
92 private $_value;
93
94 /**
95 * Token Type (represented by TOKEN_TYPE_*)
96 *
97 * @var string
98 */
99 private $_tokenType;
100
101 /**
102 * Token SubType (represented by TOKEN_SUBTYPE_*)
103 *
104 * @var string
105 */
106 private $_tokenSubType;
107
108 /**
109 * Create a new PHPExcel_Calculation_FormulaToken
110 *
111 * @param string $pValue
112 * @param string $pTokenType Token type (represented by TOKEN_TYPE_*)
113 * @param string $pTokenSubType Token Subtype (represented by TOKEN_SUBTYPE_*)
114 */
115 public function __construct($pValue, $pTokenType = PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_UNKNOWN, $pTokenSubType = PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_NOTHING)
116 {
117 // Initialise values
118 $this->_value = $pValue;
119 $this->_tokenType = $pTokenType;
120 $this->_tokenSubType = $pTokenSubType;
121 }
122
123 /**
124 * Get Value
125 *
126 * @return string
127 */
128 public function getValue() {
129 return $this->_value;
130 }
131
132 /**
133 * Set Value
134 *
135 * @param string $value
136 */
137 public function setValue($value) {
138 $this->_value = $value;
139 }
140
141 /**
142 * Get Token Type (represented by TOKEN_TYPE_*)
143 *
144 * @return string
145 */
146 public function getTokenType() {
147 return $this->_tokenType;
148 }
149
150 /**
151 * Set Token Type
152 *
153 * @param string $value
154 */
155 public function setTokenType($value = PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_UNKNOWN) {
156 $this->_tokenType = $value;
157 }
158
159 /**
160 * Get Token SubType (represented by TOKEN_SUBTYPE_*)
161 *
162 * @return string
163 */
164 public function getTokenSubType() {
165 return $this->_tokenSubType;
166 }
167
168 /**
169 * Set Token SubType
170 *
171 * @param string $value
172 */
173 public function setTokenSubType($value = PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_NOTHING) {
174 $this->_tokenSubType = $value;
175 }
176 }
1 <?php
2 namespace Tz\Wordpress\Tools\ExcelWriter;
3 /**
4 * PHPExcel
5 *
6 * Copyright (c) 2006 - 2011 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 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
25 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
26 * @version 1.7.6, 2011-02-27
27 */
28
29
30 /**
31 * PHPExcel_Calculation_Function
32 *
33 * @category PHPExcel
34 * @package PHPExcel_Calculation
35 * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
36 */
37 class PHPExcel_Calculation_Function {
38 /* Function categories */
39 const CATEGORY_CUBE = 'Cube';
40 const CATEGORY_DATABASE = 'Database';
41 const CATEGORY_DATE_AND_TIME = 'Date and Time';
42 const CATEGORY_ENGINEERING = 'Engineering';
43 const CATEGORY_FINANCIAL = 'Financial';
44 const CATEGORY_INFORMATION = 'Information';
45 const CATEGORY_LOGICAL = 'Logical';
46 const CATEGORY_LOOKUP_AND_REFERENCE = 'Lookup and Reference';
47 const CATEGORY_MATH_AND_TRIG = 'Math and Trig';
48 const CATEGORY_STATISTICAL = 'Statistical';
49 const CATEGORY_TEXT_AND_DATA = 'Text and Data';
50
51 /**
52 * Category (represented by CATEGORY_*)
53 *
54 * @var string
55 */
56 private $_category;
57
58 /**
59 * Excel name
60 *
61 * @var string
62 */
63 private $_excelName;
64
65 /**
66 * PHPExcel name
67 *
68 * @var string
69 */
70 private $_phpExcelName;
71
72 /**
73 * Create a new PHPExcel_Calculation_Function
74 *
75 * @param string $pCategory Category (represented by CATEGORY_*)
76 * @param string $pExcelName Excel function name
77 * @param string $pPHPExcelName PHPExcel function mapping
78 * @throws Exception
79 */
80 public function __construct($pCategory = null, $pExcelName = null, $pPHPExcelName = null)
81 {
82 if (!is_null($pCategory) && !is_null($pExcelName) && !is_null($pPHPExcelName)) {
83 // Initialise values
84 $this->_category = $pCategory;
85 $this->_excelName = $pExcelName;
86 $this->_phpExcelName = $pPHPExcelName;
87 } else {
88 throw new Exception("Invalid parameters passed.");
89 }
90 }
91
92 /**
93 * Get Category (represented by CATEGORY_*)
94 *
95 * @return string
96 */
97 public function getCategory() {
98 return $this->_category;
99 }
100
101 /**
102 * Set Category (represented by CATEGORY_*)
103 *
104 * @param string $value
105 * @throws Exception
106 */
107 public function setCategory($value = null) {
108 if (!is_null($value)) {
109 $this->_category = $value;
110 } else {
111 throw new Exception("Invalid parameter passed.");
112 }
113 }
114
115 /**
116 * Get Excel name
117 *
118 * @return string
119 */
120 public function getExcelName() {
121 return $this->_excelName;
122 }
123
124 /**
125 * Set Excel name
126 *
127 * @param string $value
128 */
129 public function setExcelName($value) {
130 $this->_excelName = $value;
131 }
132
133 /**
134 * Get PHPExcel name
135 *
136 * @return string
137 */
138 public function getPHPExcelName() {
139 return $this->_phpExcelName;
140 }
141
142 /**
143 * Set PHPExcel name
144 *
145 * @param string $value
146 */
147 public function setPHPExcelName($value) {
148 $this->_phpExcelName = $value;
149 }
150 }
1 <?php
2 /**
3 * PHPExcel
4 *
5 * Copyright (c) 2006 - 2011 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 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
24 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25 * @version 1.7.6, 2011-02-27
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_Logical
41 *
42 * @category PHPExcel
43 * @package PHPExcel_Calculation
44 * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
45 */
46 class PHPExcel_Calculation_Logical {
47
48 /**
49 * TRUE
50 *
51 * Returns the boolean TRUE.
52 *
53 * Excel Function:
54 * =TRUE()
55 *
56 * @access public
57 * @category Logical Functions
58 * @return boolean True
59 */
60 public static function TRUE() {
61 return true;
62 } // function TRUE()
63
64
65 /**
66 * FALSE
67 *
68 * Returns the boolean FALSE.
69 *
70 * Excel Function:
71 * =FALSE()
72 *
73 * @access public
74 * @category Logical Functions
75 * @return boolean False
76 */
77 public static function FALSE() {
78 return false;
79 } // function FALSE()
80
81
82 /**
83 * LOGICAL_AND
84 *
85 * Returns boolean TRUE if all its arguments are TRUE; returns FALSE if one or more argument is FALSE.
86 *
87 * Excel Function:
88 * =AND(logical1[,logical2[, ...]])
89 *
90 * The arguments must evaluate to logical values such as TRUE or FALSE, or the arguments must be arrays
91 * or references that contain logical values.
92 *
93 * Boolean arguments are treated as True or False as appropriate
94 * Integer or floating point arguments are treated as True, except for 0 or 0.0 which are False
95 * If any argument value is a string, or a Null, the function returns a #VALUE! error, unless the string holds
96 * the value TRUE or FALSE, in which case it is evaluated as the corresponding boolean value
97 *
98 * @access public
99 * @category Logical Functions
100 * @param mixed $arg,... Data values
101 * @return boolean The logical AND of the arguments.
102 */
103 public static function LOGICAL_AND() {
104 // Return value
105 $returnValue = True;
106
107 // Loop through the arguments
108 $aArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args());
109 $argCount = 0;
110 foreach ($aArgs as $arg) {
111 // Is it a boolean value?
112 if (is_bool($arg)) {
113 $returnValue = $returnValue && $arg;
114 } elseif ((is_numeric($arg)) && (!is_string($arg))) {
115 $returnValue = $returnValue && ($arg != 0);
116 } elseif (is_string($arg)) {
117 $arg = strtoupper($arg);
118 if (($arg == 'TRUE') || ($arg == PHPExcel_Calculation::getTRUE())) {
119 $arg = true;
120 } elseif (($arg == 'FALSE') || ($arg == PHPExcel_Calculation::getFALSE())) {
121 $arg = false;
122 } else {
123 return PHPExcel_Calculation_Functions::VALUE();
124 }
125 $returnValue = $returnValue && ($arg != 0);
126 }
127 ++$argCount;
128 }
129
130 // Return
131 if ($argCount == 0) {
132 return PHPExcel_Calculation_Functions::VALUE();
133 }
134 return $returnValue;
135 } // function LOGICAL_AND()
136
137
138 /**
139 * LOGICAL_OR
140 *
141 * Returns boolean TRUE if any argument is TRUE; returns FALSE if all arguments are FALSE.
142 *
143 * Excel Function:
144 * =OR(logical1[,logical2[, ...]])
145 *
146 * The arguments must evaluate to logical values such as TRUE or FALSE, or the arguments must be arrays
147 * or references that contain logical values.
148 *
149 * Boolean arguments are treated as True or False as appropriate
150 * Integer or floating point arguments are treated as True, except for 0 or 0.0 which are False
151 * If any argument value is a string, or a Null, the function returns a #VALUE! error, unless the string holds
152 * the value TRUE or FALSE, in which case it is evaluated as the corresponding boolean value
153 *
154 * @access public
155 * @category Logical Functions
156 * @param mixed $arg,... Data values
157 * @return boolean The logical OR of the arguments.
158 */
159 public static function LOGICAL_OR() {
160 // Return value
161 $returnValue = False;
162
163 // Loop through the arguments
164 $aArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args());
165 $argCount = 0;
166 foreach ($aArgs as $arg) {
167 // Is it a boolean value?
168 if (is_bool($arg)) {
169 $returnValue = $returnValue || $arg;
170 } elseif ((is_numeric($arg)) && (!is_string($arg))) {
171 $returnValue = $returnValue || ($arg != 0);
172 } elseif (is_string($arg)) {
173 $arg = strtoupper($arg);
174 if (($arg == 'TRUE') || ($arg == PHPExcel_Calculation::getTRUE())) {
175 $arg = true;
176 } elseif (($arg == 'FALSE') || ($arg == PHPExcel_Calculation::getFALSE())) {
177 $arg = false;
178 } else {
179 return PHPExcel_Calculation_Functions::VALUE();
180 }
181 $returnValue = $returnValue || ($arg != 0);
182 }
183 ++$argCount;
184 }
185
186 // Return
187 if ($argCount == 0) {
188 return PHPExcel_Calculation_Functions::VALUE();
189 }
190 return $returnValue;
191 } // function LOGICAL_OR()
192
193
194 /**
195 * NOT
196 *
197 * Returns the boolean inverse of the argument.
198 *
199 * Excel Function:
200 * =NOT(logical)
201 *
202 * The argument must evaluate to a logical value such as TRUE or FALSE
203 *
204 * Boolean arguments are treated as True or False as appropriate
205 * Integer or floating point arguments are treated as True, except for 0 or 0.0 which are False
206 * If any argument value is a string, or a Null, the function returns a #VALUE! error, unless the string holds
207 * the value TRUE or FALSE, in which case it is evaluated as the corresponding boolean value
208 *
209 * @access public
210 * @category Logical Functions
211 * @param mixed $logical A value or expression that can be evaluated to TRUE or FALSE
212 * @return boolean The boolean inverse of the argument.
213 */
214 public static function NOT($logical) {
215 $logical = PHPExcel_Calculation_Functions::flattenSingleValue($logical);
216 if (is_string($logical)) {
217 $logical = strtoupper($logical);
218 if (($logical == 'TRUE') || ($logical == PHPExcel_Calculation::getTRUE())) {
219 return false;
220 } elseif (($logical == 'FALSE') || ($logical == PHPExcel_Calculation::getFALSE())) {
221 return true;
222 } else {
223 return PHPExcel_Calculation_Functions::VALUE();
224 }
225 }
226
227 return !$logical;
228 } // function NOT()
229
230 /**
231 * STATEMENT_IF
232 *
233 * Returns one value if a condition you specify evaluates to TRUE and another value if it evaluates to FALSE.
234 *
235 * Excel Function:
236 * =IF(condition[,returnIfTrue[,returnIfFalse]])
237 *
238 * Condition is any value or expression that can be evaluated to TRUE or FALSE.
239 * For example, A10=100 is a logical expression; if the value in cell A10 is equal to 100,
240 * the expression evaluates to TRUE. Otherwise, the expression evaluates to FALSE.
241 * This argument can use any comparison calculation operator.
242 * ReturnIfTrue is the value that is returned if condition evaluates to TRUE.
243 * For example, if this argument is the text string "Within budget" and the condition argument evaluates to TRUE,
244 * then the IF function returns the text "Within budget"
245 * If condition is TRUE and ReturnIfTrue is blank, this argument returns 0 (zero). To display the word TRUE, use
246 * the logical value TRUE for this argument.
247 * ReturnIfTrue can be another formula.
248 * ReturnIfFalse is the value that is returned if condition evaluates to FALSE.
249 * For example, if this argument is the text string "Over budget" and the condition argument evaluates to FALSE,
250 * then the IF function returns the text "Over budget".
251 * If condition is FALSE and ReturnIfFalse is omitted, then the logical value FALSE is returned.
252 * If condition is FALSE and ReturnIfFalse is blank, then the value 0 (zero) is returned.
253 * ReturnIfFalse can be another formula.
254 *
255 * @access public
256 * @category Logical Functions
257 * @param mixed $condition Condition to evaluate
258 * @param mixed $returnIfTrue Value to return when condition is true
259 * @param mixed $returnIfFalse Optional value to return when condition is false
260 * @return mixed The value of returnIfTrue or returnIfFalse determined by condition
261 */
262 public static function STATEMENT_IF($condition = true, $returnIfTrue = 0, $returnIfFalse = False) {
263 $condition = (is_null($condition)) ? True : (boolean) PHPExcel_Calculation_Functions::flattenSingleValue($condition);
264 $returnIfTrue = (is_null($returnIfTrue)) ? 0 : PHPExcel_Calculation_Functions::flattenSingleValue($returnIfTrue);
265 $returnIfFalse = (is_null($returnIfFalse)) ? False : PHPExcel_Calculation_Functions::flattenSingleValue($returnIfFalse);
266
267 return ($condition ? $returnIfTrue : $returnIfFalse);
268 } // function STATEMENT_IF()
269
270
271 /**
272 * IFERROR
273 *
274 * Excel Function:
275 * =IFERROR(testValue,errorpart)
276 *
277 * @access public
278 * @category Logical Functions
279 * @param mixed $testValue Value to check, is also the value returned when no error
280 * @param mixed $errorpart Value to return when testValue is an error condition
281 * @return mixed The value of errorpart or testValue determined by error condition
282 */
283 public static function IFERROR($testValue = '', $errorpart = '') {
284 $testValue = (is_null($testValue)) ? '' : PHPExcel_Calculation_Functions::flattenSingleValue($testValue);
285 $errorpart = (is_null($errorpart)) ? '' : PHPExcel_Calculation_Functions::flattenSingleValue($errorpart);
286
287 return self::STATEMENT_IF(PHPExcel_Calculation_Functions::IS_ERROR($testValue), $errorpart, $testValue);
288 } // function IFERROR()
289
290 } // class PHPExcel_Calculation_Logical
This diff could not be displayed because it is too large.
1 ABS
2 ACCRINT
3 ACCRINTM
4 ACOS
5 ACOSH
6 ADDRESS
7 AMORDEGRC
8 AMORLINC
9 AND
10 AREAS
11 ASC
12 ASIN
13 ASINH
14 ATAN
15 ATAN2
16 ATANH
17 AVEDEV
18 AVERAGE
19 AVERAGEA
20 AVERAGEIF
21 AVERAGEIFS
22 BAHTTEXT
23 BESSELI
24 BESSELJ
25 BESSELK
26 BESSELY
27 BETADIST
28 BETAINV
29 BIN2DEC
30 BIN2HEX
31 BIN2OCT
32 BINOMDIST
33 CEILING
34 CELL
35 CHAR
36 CHIDIST
37 CHIINV
38 CHITEST
39 CHOOSE
40 CLEAN
41 CODE
42 COLUMN
43 COLUMNS
44 COMBIN
45 COMPLEX
46 CONCATENATE
47 CONFIDENCE
48 CONVERT
49 CORREL
50 COS
51 COSH
52 COUNT
53 COUNTA
54 COUNTBLANK
55 COUNTIF
56 COUNTIFS
57 COUPDAYBS
58 COUPDAYBS
59 COUPDAYSNC
60 COUPNCD
61 COUPNUM
62 COUPPCD
63 COVAR
64 CRITBINOM
65 CUBEKPIMEMBER
66 CUBEMEMBER
67 CUBEMEMBERPROPERTY
68 CUBERANKEDMEMBER
69 CUBESET
70 CUBESETCOUNT
71 CUBEVALUE
72 CUMIPMT
73 CUMPRINC
74 DATE
75 DATEDIF
76 DATEVALUE
77 DAVERAGE
78 DAY
79 DAYS360
80 DB
81 DCOUNT
82 DCOUNTA
83 DDB
84 DEC2BIN
85 DEC2HEX
86 DEC2OCT
87 DEGREES
88 DELTA
89 DEVSQ
90 DGET
91 DISC
92 DMAX
93 DMIN
94 DOLLAR
95 DOLLARDE
96 DOLLARFR
97 DPRODUCT
98 DSTDEV
99 DSTDEVP
100 DSUM
101 DURATION
102 DVAR
103 DVARP
104 EDATE
105 EFFECT
106 EOMONTH
107 ERF
108 ERFC
109 ERROR.TYPE
110 EVEN
111 EXACT
112 EXP
113 EXPONDIST
114 FACT
115 FACTDOUBLE
116 FALSE
117 FDIST
118 FIND
119 FINDB
120 FINV
121 FISHER
122 FISHERINV
123 FIXED
124 FLOOR
125 FORECAST
126 FREQUENCY
127 FTEST
128 FV
129 FVSCHEDULE
130 GAMAMDIST
131 GAMMAINV
132 GAMMALN
133 GCD
134 GEOMEAN
135 GESTEP
136 GETPIVOTDATA
137 GROWTH
138 HARMEAN
139 HEX2BIN
140 HEX2OCT
141 HLOOKUP
142 HOUR
143 HYPERLINK
144 HYPGEOMDIST
145 IF
146 IFERROR
147 IMABS
148 IMAGINARY
149 IMARGUMENT
150 IMCONJUGATE
151 IMCOS
152 IMEXP
153 IMLN
154 IMLOG10
155 IMLOG2
156 IMPOWER
157 IMPRODUCT
158 IMREAL
159 IMSIN
160 IMSQRT
161 IMSUB
162 IMSUM
163 INDEX
164 INDIRECT
165 INFO
166 INT
167 INTERCEPT
168 INTRATE
169 IPMT
170 IRR
171 ISBLANK
172 ISERR
173 ISERROR
174 ISEVEN
175 ISLOGICAL
176 ISNA
177 ISNONTEXT
178 ISNUMBER
179 ISODD
180 ISPMT
181 ISREF
182 ISTEXT
183 JIS
184 KURT
185 LARGE
186 LCM
187 LEFT
188 LEFTB
189 LEN
190 LENB
191 LINEST
192 LN
193 LOG
194 LOG10
195 LOGEST
196 LOGINV
197 LOGNORMDIST
198 LOOKUP
199 LOWER
200 MATCH
201 MAX
202 MAXA
203 MDETERM
204 MDURATION
205 MEDIAN
206 MID
207 MIDB
208 MIN
209 MINA
210 MINUTE
211 MINVERSE
212 MIRR
213 MMULT
214 MOD
215 MODE
216 MONTH
217 MROUND
218 MULTINOMIAL
219 N
220 NA
221 NEGBINOMDIST
222 NETWORKDAYS
223 NOMINAL
224 NORMDIST
225 NORMINV
226 NORMSDIST
227 NORMSINV
228 NOT
229 NOW
230 NPER
231 NPV
232 OCT2BIN
233 OCT2DEC
234 OCT2HEX
235 ODD
236 ODDFPRICE
237 ODDFYIELD
238 ODDLPRICE
239 ODDLYIELD
240 OFFSET
241 OR
242 PEARSON
243 PERCENTILE
244 PERCENTRANK
245 PERMUT
246 PHONETIC
247 PI
248 PMT
249 POISSON
250 POWER
251 PPMT
252 PRICE
253 PRICEDISC
254 PRICEMAT
255 PROB
256 PRODUCT
257 PROPER
258 PV
259 QUARTILE
260 QUOTIENT
261 RADIANS
262 RAND
263 RANDBETWEEN
264 RANK
265 RATE
266 RECEIVED
267 REPLACE
268 REPLACEB
269 REPT
270 RIGHT
271 RIGHTB
272 ROMAN
273 ROUND
274 ROUNDDOWN
275 ROUNDUP
276 ROW
277 ROWS
278 RSQ
279 RTD
280 SEARCH
281 SEARCHB
282 SECOND
283 SERIESSUM
284 SIGN
285 SIN
286 SINH
287 SKEW
288 SLN
289 SLOPE
290 SMALL
291 SQRT
292 SQRTPI
293 STANDARDIZE
294 STDEV
295 STDEVA
296 STDEVP
297 STDEVPA
298 STEYX
299 SUBSTITUTE
300 SUBTOTAL
301 SUM
302 SUMIF
303 SUMIFS
304 SUMPRODUCT
305 SUMSQ
306 SUMX2MY2
307 SUMX2PY2
308 SUMXMY2
309 SYD
310 T
311 TAN
312 TANH
313 TBILLEQ
314 TBILLPRICE
315 TBILLYIELD
316 TDIST
317 TEXT
318 TIME
319 TIMEVALUE
320 TINV
321 TODAY
322 TRANSPOSE
323 TREND
324 TRIM
325 TRIMMEAN
326 TRUE
327 TRUNC
328 TTEST
329 TYPE
330 UPPER
331 USDOLLAR
332 VALUE
333 VAR
334 VARA
335 VARP
336 VARPA
337 VDB
338 VERSION
339 VLOOKUP
340 WEEKDAY
341 WEEKNUM
342 WEIBULL
343 WORKDAY
344 XIRR
345 XNPV
346 YEAR
347 YEARFRAC
348 YIELD
349 YIELDDISC
350 YIELDMAT
351 ZTEST
1 <?php
2 /**
3 * PHPExcel
4 *
5 * Copyright (c) 2006 - 2011 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_Cell
23 * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
24 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25 * @version 1.7.6, 2011-02-27
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_Cell_AdvancedValueBinder
41 *
42 * @category PHPExcel
43 * @package PHPExcel_Cell
44 * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
45 */
46 class PHPExcel_Cell_AdvancedValueBinder extends PHPExcel_Cell_DefaultValueBinder implements PHPExcel_Cell_IValueBinder
47 {
48 /**
49 * Bind value to a cell
50 *
51 * @param PHPExcel_Cell $cell Cell to bind value to
52 * @param mixed $value Value to bind in cell
53 * @return boolean
54 */
55 public function bindValue(PHPExcel_Cell $cell, $value = null)
56 {
57 // sanitize UTF-8 strings
58 if (is_string($value)) {
59 $value = PHPExcel_Shared_String::SanitizeUTF8($value);
60 }
61
62 // Find out data type
63 $dataType = parent::dataTypeForValue($value);
64
65 // Style logic - strings
66 if ($dataType === PHPExcel_Cell_DataType::TYPE_STRING && !$value instanceof PHPExcel_RichText) {
67 // Test for booleans using locale-setting
68 if ($value == PHPExcel_Calculation::getTRUE()) {
69 $cell->setValueExplicit( True, PHPExcel_Cell_DataType::TYPE_BOOL);
70 return true;
71 } elseif($value == PHPExcel_Calculation::getFALSE()) {
72 $cell->setValueExplicit( False, PHPExcel_Cell_DataType::TYPE_BOOL);
73 return true;
74 }
75
76 // Check for number in scientific format
77 if (preg_match('/^'.PHPExcel_Calculation::CALCULATION_REGEXP_NUMBER.'$/', $value)) {
78 $cell->setValueExplicit( (float) $value, PHPExcel_Cell_DataType::TYPE_NUMERIC);
79 return true;
80 }
81
82 // Check for percentage
83 if (preg_match('/^\-?[0-9]*\.?[0-9]*\s?\%$/', $value)) {
84 // Convert value to number
85 $cell->setValueExplicit( (float)str_replace('%', '', $value) / 100, PHPExcel_Cell_DataType::TYPE_NUMERIC);
86 // Set style
87 $cell->getParent()->getStyle( $cell->getCoordinate() )->getNumberFormat()->setFormatCode( PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE );
88 return true;
89 }
90
91 // Check for time without seconds e.g. '9:45', '09:45'
92 if (preg_match('/^(\d|[0-1]\d|2[0-3]):[0-5]\d$/', $value)) {
93 list($h, $m) = explode(':', $value);
94 $days = $h / 24 + $m / 1440;
95 // Convert value to number
96 $cell->setValueExplicit($days, PHPExcel_Cell_DataType::TYPE_NUMERIC);
97 // Set style
98 $cell->getParent()->getStyle( $cell->getCoordinate() )->getNumberFormat()->setFormatCode( PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME3 );
99 return true;
100 }
101
102 // Check for time with seconds '9:45:59', '09:45:59'
103 if (preg_match('/^(\d|[0-1]\d|2[0-3]):[0-5]\d:[0-5]\d$/', $value)) {
104 list($h, $m, $s) = explode(':', $value);
105 $days = $h / 24 + $m / 1440 + $s / 86400;
106 // Convert value to number
107 $cell->setValueExplicit($days, PHPExcel_Cell_DataType::TYPE_NUMERIC);
108 // Set style
109 $cell->getParent()->getStyle( $cell->getCoordinate() )->getNumberFormat()->setFormatCode( PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME4 );
110 return true;
111 }
112
113 // Check for datetime, e.g. '2008-12-31', '2008-12-31 15:59', '2008-12-31 15:59:10'
114 if (($d = PHPExcel_Shared_Date::stringToExcel($value)) !== false) {
115 // Convert value to number
116 $cell->setValueExplicit($d, PHPExcel_Cell_DataType::TYPE_NUMERIC);
117 // Determine style. Either there is a time part or not. Look for ':'
118 if (strpos($value, ':') !== false) {
119 $formatCode = 'yyyy-mm-dd h:mm';
120 } else {
121 $formatCode = 'yyyy-mm-dd';
122 }
123 $cell->getParent()->getStyle( $cell->getCoordinate() )->getNumberFormat()->setFormatCode($formatCode);
124 return true;
125 }
126
127 // Check for newline character "\n"
128 if (strpos($value, "\n") !== false) {
129 $value = PHPExcel_Shared_String::SanitizeUTF8($value);
130 $cell->setValueExplicit($value, PHPExcel_Cell_DataType::TYPE_STRING);
131 // Set style
132 $cell->getParent()->getStyle( $cell->getCoordinate() )->getAlignment()->setWrapText(true);
133 return true;
134 }
135 }
136
137 // Not bound yet? Use parent...
138 return parent::bindValue($cell, $value);
139 }
140 }
1 <?php
2 namespace Tz\Wordpress\Tools\ExcelWriter;
3 /**
4 * PHPExcel
5 *
6 * Copyright (c) 2006 - 2011 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_Cell
24 * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
25 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
26 * @version 1.7.6, 2011-02-27
27 */
28
29
30 /**
31 * PHPExcel_Cell_DataType
32 *
33 * @category PHPExcel
34 * @package PHPExcel_Cell
35 * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
36 */
37 class PHPExcel_Cell_DataType
38 {
39 /* Data types */
40 const TYPE_STRING2 = 'str';
41 const TYPE_STRING = 's';
42 const TYPE_FORMULA = 'f';
43 const TYPE_NUMERIC = 'n';
44 const TYPE_BOOL = 'b';
45 const TYPE_NULL = 's';
46 const TYPE_INLINE = 'inlineStr';
47 const TYPE_ERROR = 'e';
48
49 /**
50 * List of error codes
51 *
52 * @var array
53 */
54 private static $_errorCodes = array('#NULL!' => 0, '#DIV/0!' => 1, '#VALUE!' => 2, '#REF!' => 3, '#NAME?' => 4, '#NUM!' => 5, '#N/A' => 6);
55
56 /**
57 * Get list of error codes
58 *
59 * @return array
60 */
61 public static function getErrorCodes() {
62 return self::$_errorCodes;
63 }
64
65 /**
66 * DataType for value
67 *
68 * @deprecated Replaced by PHPExcel_Cell_IValueBinder infrastructure
69 * @param mixed $pValue
70 * @return int
71 */
72 public static function dataTypeForValue($pValue = null) {
73 return PHPExcel_Cell_DefaultValueBinder::dataTypeForValue($pValue);
74 }
75
76 /**
77 * Check a string that it satisfies Excel requirements
78 *
79 * @param mixed Value to sanitize to an Excel string
80 * @return mixed Sanitized value
81 */
82 public static function checkString($pValue = null)
83 {
84 if ($pValue instanceof PHPExcel_RichText) {
85 // TODO: Sanitize Rich-Text string (max. character count is 32,767)
86 return $pValue;
87 }
88
89 // string must never be longer than 32,767 characters, truncate if necessary
90 $pValue = PHPExcel_Shared_String::Substring($pValue, 0, 32767);
91
92 // we require that newline is represented as "\n" in core, not as "\r\n" or "\r"
93 $pValue = str_replace(array("\r\n", "\r"), "\n", $pValue);
94
95 return $pValue;
96 }
97
98 /**
99 * Check a value that it is a valid error code
100 *
101 * @param mixed Value to sanitize to an Excel error code
102 * @return string Sanitized value
103 */
104 public static function checkErrorCode($pValue = null)
105 {
106 $pValue = (string)$pValue;
107
108 if ( !array_key_exists($pValue, self::$_errorCodes) ) {
109 $pValue = '#NULL!';
110 }
111
112 return $pValue;
113 }
114
115 }
1 <?php
2 /**
3 * PHPExcel
4 *
5 * Copyright (c) 2006 - 2011 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_Cell
23 * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
24 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25 * @version 1.7.6, 2011-02-27
26 */
27
28
29 /**
30 * PHPExcel_Cell_DataValidation
31 *
32 * @category PHPExcel
33 * @package PHPExcel_Cell
34 * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
35 */
36 class PHPExcel_Cell_DataValidation
37 {
38 /* Data validation types */
39 const TYPE_NONE = 'none';
40 const TYPE_CUSTOM = 'custom';
41 const TYPE_DATE = 'date';
42 const TYPE_DECIMAL = 'decimal';
43 const TYPE_LIST = 'list';
44 const TYPE_TEXTLENGTH = 'textLength';
45 const TYPE_TIME = 'time';
46 const TYPE_WHOLE = 'whole';
47
48 /* Data validation error styles */
49 const STYLE_STOP = 'stop';
50 const STYLE_WARNING = 'warning';
51 const STYLE_INFORMATION = 'information';
52
53 /* Data validation operators */
54 const OPERATOR_BETWEEN = 'between';
55 const OPERATOR_EQUAL = 'equal';
56 const OPERATOR_GREATERTHAN = 'greaterThan';
57 const OPERATOR_GREATERTHANOREQUAL = 'greaterThanOrEqual';
58 const OPERATOR_LESSTHAN = 'lessThan';
59 const OPERATOR_LESSTHANOREQUAL = 'lessThanOrEqual';
60 const OPERATOR_NOTBETWEEN = 'notBetween';
61 const OPERATOR_NOTEQUAL = 'notEqual';
62
63 /**
64 * Formula 1
65 *
66 * @var string
67 */
68 private $_formula1;
69
70 /**
71 * Formula 2
72 *
73 * @var string
74 */
75 private $_formula2;
76
77 /**
78 * Type
79 *
80 * @var string
81 */
82 private $_type = PHPExcel_Cell_DataValidation::TYPE_NONE;
83
84 /**
85 * Error style
86 *
87 * @var string
88 */
89 private $_errorStyle = PHPExcel_Cell_DataValidation::STYLE_STOP;
90
91 /**
92 * Operator
93 *
94 * @var string
95 */
96 private $_operator;
97
98 /**
99 * Allow Blank
100 *
101 * @var boolean
102 */
103 private $_allowBlank;
104
105 /**
106 * Show DropDown
107 *
108 * @var boolean
109 */
110 private $_showDropDown;
111
112 /**
113 * Show InputMessage
114 *
115 * @var boolean
116 */
117 private $_showInputMessage;
118
119 /**
120 * Show ErrorMessage
121 *
122 * @var boolean
123 */
124 private $_showErrorMessage;
125
126 /**
127 * Error title
128 *
129 * @var string
130 */
131 private $_errorTitle;
132
133 /**
134 * Error
135 *
136 * @var string
137 */
138 private $_error;
139
140 /**
141 * Prompt title
142 *
143 * @var string
144 */
145 private $_promptTitle;
146
147 /**
148 * Prompt
149 *
150 * @var string
151 */
152 private $_prompt;
153
154 /**
155 * Create a new PHPExcel_Cell_DataValidation
156 *
157 * @throws Exception
158 */
159 public function __construct()
160 {
161 // Initialise member variables
162 $this->_formula1 = '';
163 $this->_formula2 = '';
164 $this->_type = PHPExcel_Cell_DataValidation::TYPE_NONE;
165 $this->_errorStyle = PHPExcel_Cell_DataValidation::STYLE_STOP;
166 $this->_operator = '';
167 $this->_allowBlank = false;
168 $this->_showDropDown = false;
169 $this->_showInputMessage = false;
170 $this->_showErrorMessage = false;
171 $this->_errorTitle = '';
172 $this->_error = '';
173 $this->_promptTitle = '';
174 $this->_prompt = '';
175 }
176
177 /**
178 * Get Formula 1
179 *
180 * @return string
181 */
182 public function getFormula1() {
183 return $this->_formula1;
184 }
185
186 /**
187 * Set Formula 1
188 *
189 * @param string $value
190 * @return PHPExcel_Cell_DataValidation
191 */
192 public function setFormula1($value = '') {
193 $this->_formula1 = $value;
194 return $this;
195 }
196
197 /**
198 * Get Formula 2
199 *
200 * @return string
201 */
202 public function getFormula2() {
203 return $this->_formula2;
204 }
205
206 /**
207 * Set Formula 2
208 *
209 * @param string $value
210 * @return PHPExcel_Cell_DataValidation
211 */
212 public function setFormula2($value = '') {
213 $this->_formula2 = $value;
214 return $this;
215 }
216
217 /**
218 * Get Type
219 *
220 * @return string
221 */
222 public function getType() {
223 return $this->_type;
224 }
225
226 /**
227 * Set Type
228 *
229 * @param string $value
230 * @return PHPExcel_Cell_DataValidation
231 */
232 public function setType($value = PHPExcel_Cell_DataValidation::TYPE_NONE) {
233 $this->_type = $value;
234 return $this;
235 }
236
237 /**
238 * Get Error style
239 *
240 * @return string
241 */
242 public function getErrorStyle() {
243 return $this->_errorStyle;
244 }
245
246 /**
247 * Set Error style
248 *
249 * @param string $value
250 * @return PHPExcel_Cell_DataValidation
251 */
252 public function setErrorStyle($value = PHPExcel_Cell_DataValidation::STYLE_STOP) {
253 $this->_errorStyle = $value;
254 return $this;
255 }
256
257 /**
258 * Get Operator
259 *
260 * @return string
261 */
262 public function getOperator() {
263 return $this->_operator;
264 }
265
266 /**
267 * Set Operator
268 *
269 * @param string $value
270 * @return PHPExcel_Cell_DataValidation
271 */
272 public function setOperator($value = '') {
273 $this->_operator = $value;
274 return $this;
275 }
276
277 /**
278 * Get Allow Blank
279 *
280 * @return boolean
281 */
282 public function getAllowBlank() {
283 return $this->_allowBlank;
284 }
285
286 /**
287 * Set Allow Blank
288 *
289 * @param boolean $value
290 * @return PHPExcel_Cell_DataValidation
291 */
292 public function setAllowBlank($value = false) {
293 $this->_allowBlank = $value;
294 return $this;
295 }
296
297 /**
298 * Get Show DropDown
299 *
300 * @return boolean
301 */
302 public function getShowDropDown() {
303 return $this->_showDropDown;
304 }
305
306 /**
307 * Set Show DropDown
308 *
309 * @param boolean $value
310 * @return PHPExcel_Cell_DataValidation
311 */
312 public function setShowDropDown($value = false) {
313 $this->_showDropDown = $value;
314 return $this;
315 }
316
317 /**
318 * Get Show InputMessage
319 *
320 * @return boolean
321 */
322 public function getShowInputMessage() {
323 return $this->_showInputMessage;
324 }
325
326 /**
327 * Set Show InputMessage
328 *
329 * @param boolean $value
330 * @return PHPExcel_Cell_DataValidation
331 */
332 public function setShowInputMessage($value = false) {
333 $this->_showInputMessage = $value;
334 return $this;
335 }
336
337 /**
338 * Get Show ErrorMessage
339 *
340 * @return boolean
341 */
342 public function getShowErrorMessage() {
343 return $this->_showErrorMessage;
344 }
345
346 /**
347 * Set Show ErrorMessage
348 *
349 * @param boolean $value
350 * @return PHPExcel_Cell_DataValidation
351 */
352 public function setShowErrorMessage($value = false) {
353 $this->_showErrorMessage = $value;
354 return $this;
355 }
356
357 /**
358 * Get Error title
359 *
360 * @return string
361 */
362 public function getErrorTitle() {
363 return $this->_errorTitle;
364 }
365
366 /**
367 * Set Error title
368 *
369 * @param string $value
370 * @return PHPExcel_Cell_DataValidation
371 */
372 public function setErrorTitle($value = '') {
373 $this->_errorTitle = $value;
374 return $this;
375 }
376
377 /**
378 * Get Error
379 *
380 * @return string
381 */
382 public function getError() {
383 return $this->_error;
384 }
385
386 /**
387 * Set Error
388 *
389 * @param string $value
390 * @return PHPExcel_Cell_DataValidation
391 */
392 public function setError($value = '') {
393 $this->_error = $value;
394 return $this;
395 }
396
397 /**
398 * Get Prompt title
399 *
400 * @return string
401 */
402 public function getPromptTitle() {
403 return $this->_promptTitle;
404 }
405
406 /**
407 * Set Prompt title
408 *
409 * @param string $value
410 * @return PHPExcel_Cell_DataValidation
411 */
412 public function setPromptTitle($value = '') {
413 $this->_promptTitle = $value;
414 return $this;
415 }
416
417 /**
418 * Get Prompt
419 *
420 * @return string
421 */
422 public function getPrompt() {
423 return $this->_prompt;
424 }
425
426 /**
427 * Set Prompt
428 *
429 * @param string $value
430 * @return PHPExcel_Cell_DataValidation
431 */
432 public function setPrompt($value = '') {
433 $this->_prompt = $value;
434 return $this;
435 }
436
437 /**
438 * Get hash code
439 *
440 * @return string Hash code
441 */
442 public function getHashCode() {
443 return md5(
444 $this->_formula1
445 . $this->_formula2
446 . $this->_type = PHPExcel_Cell_DataValidation::TYPE_NONE
447 . $this->_errorStyle = PHPExcel_Cell_DataValidation::STYLE_STOP
448 . $this->_operator
449 . ($this->_allowBlank ? 't' : 'f')
450 . ($this->_showDropDown ? 't' : 'f')
451 . ($this->_showInputMessage ? 't' : 'f')
452 . ($this->_showErrorMessage ? 't' : 'f')
453 . $this->_errorTitle
454 . $this->_error
455 . $this->_promptTitle
456 . $this->_prompt
457 . __CLASS__
458 );
459 }
460
461 /**
462 * Implement PHP __clone to create a deep clone, not just a shallow copy.
463 */
464 public function __clone() {
465 $vars = get_object_vars($this);
466 foreach ($vars as $key => $value) {
467 if (is_object($value)) {
468 $this->$key = clone $value;
469 } else {
470 $this->$key = $value;
471 }
472 }
473 }
474 }
1 <?php
2 namespace Tz\Wordpress\Tools\ExcelWriter;
3 /**
4 * PHPExcel
5 *
6 * Copyright (c) 2006 - 2011 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_Cell
24 * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
25 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
26 * @version 1.7.6, 2011-02-27
27 */
28
29
30 /** PHPExcel root directory */
31 if (!defined('PHPEXCEL_ROOT')) {
32 /**
33 * @ignore
34 */
35 define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
36 require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
37 }
38
39
40 /**
41 * PHPExcel_Cell_DefaultValueBinder
42 *
43 * @category PHPExcel
44 * @package PHPExcel_Cell
45 * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
46 */
47 class PHPExcel_Cell_DefaultValueBinder implements PHPExcel_Cell_IValueBinder
48 {
49 /**
50 * Bind value to a cell
51 *
52 * @param PHPExcel_Cell $cell Cell to bind value to
53 * @param mixed $value Value to bind in cell
54 * @return boolean
55 */
56 public function bindValue(PHPExcel_Cell $cell, $value = null)
57 {
58 // sanitize UTF-8 strings
59 if (is_string($value)) {
60 $value = PHPExcel_Shared_String::SanitizeUTF8($value);
61 }
62
63 // Set value explicit
64 $cell->setValueExplicit( $value, PHPExcel_Cell_DataType::dataTypeForValue($value) );
65
66 // Done!
67 return true;
68 }
69
70 /**
71 * DataType for value
72 *
73 * @param mixed $pValue
74 * @return int
75 */
76 public static function dataTypeForValue($pValue = null) {
77 // Match the value against a few data types
78 if (is_null($pValue)) {
79 return PHPExcel_Cell_DataType::TYPE_NULL;
80
81 } elseif ($pValue === '') {
82 return PHPExcel_Cell_DataType::TYPE_STRING;
83
84 } elseif ($pValue instanceof PHPExcel_RichText) {
85 return PHPExcel_Cell_DataType::TYPE_STRING;
86
87 } elseif ($pValue{0} === '=' && strlen($pValue) > 1) {
88 return PHPExcel_Cell_DataType::TYPE_FORMULA;
89
90 } elseif (is_bool($pValue)) {
91 return PHPExcel_Cell_DataType::TYPE_BOOL;
92
93 } elseif (is_float($pValue) || is_int($pValue)) {
94 return PHPExcel_Cell_DataType::TYPE_NUMERIC;
95
96 } elseif (preg_match('/^\-?([0-9]+\\.?[0-9]*|[0-9]*\\.?[0-9]+)$/', $pValue)) {
97 return PHPExcel_Cell_DataType::TYPE_NUMERIC;
98
99 } elseif (is_string($pValue) && array_key_exists($pValue, PHPExcel_Cell_DataType::getErrorCodes())) {
100 return PHPExcel_Cell_DataType::TYPE_ERROR;
101
102 } else {
103 return PHPExcel_Cell_DataType::TYPE_STRING;
104
105 }
106 }
107 }
1 <?php
2 /**
3 * PHPExcel
4 *
5 * Copyright (c) 2006 - 2011 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_Cell
23 * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
24 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25 * @version 1.7.6, 2011-02-27
26 */
27
28
29 /**
30 * PHPExcel_Cell_Hyperlink
31 *
32 * @category PHPExcel
33 * @package PHPExcel_Cell
34 * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
35 */
36 class PHPExcel_Cell_Hyperlink
37 {
38 /**
39 * URL to link the cell to
40 *
41 * @var string
42 */
43 private $_url;
44
45 /**
46 * Tooltip to display on the hyperlink
47 *
48 * @var string
49 */
50 private $_tooltip;
51
52 /**
53 * Create a new PHPExcel_Cell_Hyperlink
54 *
55 * @param string $pUrl Url to link the cell to
56 * @param string $pTooltip Tooltip to display on the hyperlink
57 * @throws Exception
58 */
59 public function __construct($pUrl = '', $pTooltip = '')
60 {
61 // Initialise member variables
62 $this->_url = $pUrl;
63 $this->_tooltip = $pTooltip;
64 }
65
66 /**
67 * Get URL
68 *
69 * @return string
70 */
71 public function getUrl() {
72 return $this->_url;
73 }
74
75 /**
76 * Set URL
77 *
78 * @param string $value
79 * @return PHPExcel_Cell_Hyperlink
80 */
81 public function setUrl($value = '') {
82 $this->_url = $value;
83 return $this;
84 }
85
86 /**
87 * Get tooltip
88 *
89 * @return string
90 */
91 public function getTooltip() {
92 return $this->_tooltip;
93 }
94
95 /**
96 * Set tooltip
97 *
98 * @param string $value
99 * @return PHPExcel_Cell_Hyperlink
100 */
101 public function setTooltip($value = '') {
102 $this->_tooltip = $value;
103 return $this;
104 }
105
106 /**
107 * Is this hyperlink internal? (to another sheet)
108 *
109 * @return boolean
110 */
111 public function isInternal() {
112 return strpos($this->_url, 'sheet://') !== false;
113 }
114
115 /**
116 * Get hash code
117 *
118 * @return string Hash code
119 */
120 public function getHashCode() {
121 return md5(
122 $this->_url
123 . $this->_tooltip
124 . __CLASS__
125 );
126 }
127 }
1 <?php
2 namespace Tz\Wordpress\Tools\ExcelWriter;
3 /**
4 * PHPExcel
5 *
6 * Copyright (c) 2006 - 2011 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_Cell
24 * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
25 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
26 * @version 1.7.6, 2011-02-27
27 */
28
29
30 /**
31 * PHPExcel_Cell_IValueBinder
32 *
33 * @category PHPExcel
34 * @package PHPExcel_Cell
35 * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
36 */
37 interface PHPExcel_Cell_IValueBinder
38 {
39 /**
40 * Bind value to a cell
41 *
42 * @param PHPExcel_Cell $cell Cell to bind value to
43 * @param mixed $value Value to bind in cell
44 * @return boolean
45 */
46 public function bindValue(PHPExcel_Cell $cell, $value = null);
47 }
1 <?php
2 /**
3 * PHPExcel
4 *
5 * Copyright (c) 2006 - 2011 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 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
24 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25 * @version 1.7.6, 2011-02-27
26 */
27
28
29 /**
30 * PHPExcel_Comment
31 *
32 * @category PHPExcel
33 * @package PHPExcel
34 * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
35 */
36 class PHPExcel_Comment implements PHPExcel_IComparable
37 {
38 /**
39 * Author
40 *
41 * @var string
42 */
43 private $_author;
44
45 /**
46 * Rich text comment
47 *
48 * @var PHPExcel_RichText
49 */
50 private $_text;
51
52 /**
53 * Comment width (CSS style, i.e. XXpx or YYpt)
54 *
55 * @var string
56 */
57 private $_width = '96pt';
58
59 /**
60 * Left margin (CSS style, i.e. XXpx or YYpt)
61 *
62 * @var string
63 */
64 private $_marginLeft = '59.25pt';
65
66 /**
67 * Top margin (CSS style, i.e. XXpx or YYpt)
68 *
69 * @var string
70 */
71 private $_marginTop = '1.5pt';
72
73 /**
74 * Visible
75 *
76 * @var boolean
77 */
78 private $_visible = false;
79
80 /**
81 * Comment height (CSS style, i.e. XXpx or YYpt)
82 *
83 * @var string
84 */
85 private $_height = '55.5pt';
86
87 /**
88 * Comment fill color
89 *
90 * @var PHPExcel_Style_Color
91 */
92 private $_fillColor;
93
94 /**
95 * Alignment
96 *
97 * @var string
98 */
99 private $_alignment;
100
101 /**
102 * Create a new PHPExcel_Comment
103 *
104 * @throws Exception
105 */
106 public function __construct()
107 {
108 // Initialise variables
109 $this->_author = 'Author';
110 $this->_text = new PHPExcel_RichText();
111 $this->_fillColor = new PHPExcel_Style_Color('FFFFFFE1');
112 $this->_alignment = PHPExcel_Style_Alignment::HORIZONTAL_GENERAL;
113 }
114
115 /**
116 * Get Author
117 *
118 * @return string
119 */
120 public function getAuthor() {
121 return $this->_author;
122 }
123
124 /**
125 * Set Author
126 *
127 * @param string $pValue
128 * @return PHPExcel_Comment
129 */
130 public function setAuthor($pValue = '') {
131 $this->_author = $pValue;
132 return $this;
133 }
134
135 /**
136 * Get Rich text comment
137 *
138 * @return PHPExcel_RichText
139 */
140 public function getText() {
141 return $this->_text;
142 }
143
144 /**
145 * Set Rich text comment
146 *
147 * @param PHPExcel_RichText $pValue
148 * @return PHPExcel_Comment
149 */
150 public function setText(PHPExcel_RichText $pValue) {
151 $this->_text = $pValue;
152 return $this;
153 }
154
155 /**
156 * Get comment width (CSS style, i.e. XXpx or YYpt)
157 *
158 * @return string
159 */
160 public function getWidth() {
161 return $this->_width;
162 }
163
164 /**
165 * Set comment width (CSS style, i.e. XXpx or YYpt)
166 *
167 * @param string $value
168 * @return PHPExcel_Comment
169 */
170 public function setWidth($value = '96pt') {
171 $this->_width = $value;
172 return $this;
173 }
174
175 /**
176 * Get comment height (CSS style, i.e. XXpx or YYpt)
177 *
178 * @return string
179 */
180 public function getHeight() {
181 return $this->_height;
182 }
183
184 /**
185 * Set comment height (CSS style, i.e. XXpx or YYpt)
186 *
187 * @param string $value
188 * @return PHPExcel_Comment
189 */
190 public function setHeight($value = '55.5pt') {
191 $this->_height = $value;
192 return $this;
193 }
194
195 /**
196 * Get left margin (CSS style, i.e. XXpx or YYpt)
197 *
198 * @return string
199 */
200 public function getMarginLeft() {
201 return $this->_marginLeft;
202 }
203
204 /**
205 * Set left margin (CSS style, i.e. XXpx or YYpt)
206 *
207 * @param string $value
208 * @return PHPExcel_Comment
209 */
210 public function setMarginLeft($value = '59.25pt') {
211 $this->_marginLeft = $value;
212 return $this;
213 }
214
215 /**
216 * Get top margin (CSS style, i.e. XXpx or YYpt)
217 *
218 * @return string
219 */
220 public function getMarginTop() {
221 return $this->_marginTop;
222 }
223
224 /**
225 * Set top margin (CSS style, i.e. XXpx or YYpt)
226 *
227 * @param string $value
228 * @return PHPExcel_Comment
229 */
230 public function setMarginTop($value = '1.5pt') {
231 $this->_marginTop = $value;
232 return $this;
233 }
234
235 /**
236 * Is the comment visible by default?
237 *
238 * @return boolean
239 */
240 public function getVisible() {
241 return $this->_visible;
242 }
243
244 /**
245 * Set comment default visibility
246 *
247 * @param boolean $value
248 * @return PHPExcel_Comment
249 */
250 public function setVisible($value = false) {
251 $this->_visible = $value;
252 return $this;
253 }
254
255 /**
256 * Get fill color
257 *
258 * @return PHPExcel_Style_Color
259 */
260 public function getFillColor() {
261 return $this->_fillColor;
262 }
263
264 /**
265 * Set Alignment
266 *
267 * @param string $pValue
268 * @return PHPExcel_Comment
269 */
270 public function setAlignment($pValue = PHPExcel_Style_Alignment::HORIZONTAL_GENERAL) {
271 $this->_alignment = $pValue;
272 return $this;
273 }
274
275 /**
276 * Get Alignment
277 *
278 * @return string
279 */
280 public function getAlignment() {
281 return $this->_alignment;
282 }
283
284 /**
285 * Get hash code
286 *
287 * @return string Hash code
288 */
289 public function getHashCode() {
290 return md5(
291 $this->_author
292 . $this->_text->getHashCode()
293 . $this->_width
294 . $this->_height
295 . $this->_marginLeft
296 . $this->_marginTop
297 . ($this->_visible ? 1 : 0)
298 . $this->_fillColor->getHashCode()
299 . $this->_alignment
300 . __CLASS__
301 );
302 }
303
304 /**
305 * Implement PHP __clone to create a deep clone, not just a shallow copy.
306 */
307 public function __clone() {
308 $vars = get_object_vars($this);
309 foreach ($vars as $key => $value) {
310 if (is_object($value)) {
311 $this->$key = clone $value;
312 } else {
313 $this->$key = $value;
314 }
315 }
316 }
317 }
1 <?php
2 namespace Tz\Wordpress\Tools\ExcelWriter;
3 /**
4 * PHPExcel
5 *
6 * Copyright (c) 2006 - 2011 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
24 * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
25 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
26 * @version 1.7.6, 2011-02-27
27 */
28
29
30 /**
31 * PHPExcel_DocumentSecurity
32 *
33 * @category PHPExcel
34 * @package PHPExcel
35 * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
36 */
37 class PHPExcel_DocumentSecurity
38 {
39 /**
40 * LockRevision
41 *
42 * @var boolean
43 */
44 private $_lockRevision;
45
46 /**
47 * LockStructure
48 *
49 * @var boolean
50 */
51 private $_lockStructure;
52
53 /**
54 * LockWindows
55 *
56 * @var boolean
57 */
58 private $_lockWindows;
59
60 /**
61 * RevisionsPassword
62 *
63 * @var string
64 */
65 private $_revisionsPassword;
66
67 /**
68 * WorkbookPassword
69 *
70 * @var string
71 */
72 private $_workbookPassword;
73
74 /**
75 * Create a new PHPExcel_DocumentSecurity
76 */
77 public function __construct()
78 {
79 // Initialise values
80 $this->_lockRevision = false;
81 $this->_lockStructure = false;
82 $this->_lockWindows = false;
83 $this->_revisionsPassword = '';
84 $this->_workbookPassword = '';
85 }
86
87 /**
88 * Is some sort of dcument security enabled?
89 *
90 * @return boolean
91 */
92 function isSecurityEnabled() {
93 return $this->_lockRevision ||
94 $this->_lockStructure ||
95 $this->_lockWindows;
96 }
97
98 /**
99 * Get LockRevision
100 *
101 * @return boolean
102 */
103 function getLockRevision() {
104 return $this->_lockRevision;
105 }
106
107 /**
108 * Set LockRevision
109 *
110 * @param boolean $pValue
111 * @return PHPExcel_DocumentSecurity
112 */
113 function setLockRevision($pValue = false) {
114 $this->_lockRevision = $pValue;
115 return $this;
116 }
117
118 /**
119 * Get LockStructure
120 *
121 * @return boolean
122 */
123 function getLockStructure() {
124 return $this->_lockStructure;
125 }
126
127 /**
128 * Set LockStructure
129 *
130 * @param boolean $pValue
131 * @return PHPExcel_DocumentSecurity
132 */
133 function setLockStructure($pValue = false) {
134 $this->_lockStructure = $pValue;
135 return $this;
136 }
137
138 /**
139 * Get LockWindows
140 *
141 * @return boolean
142 */
143 function getLockWindows() {
144 return $this->_lockWindows;
145 }
146
147 /**
148 * Set LockWindows
149 *
150 * @param boolean $pValue
151 * @return PHPExcel_DocumentSecurity
152 */
153 function setLockWindows($pValue = false) {
154 $this->_lockWindows = $pValue;
155 return $this;
156 }
157
158 /**
159 * Get RevisionsPassword (hashed)
160 *
161 * @return string
162 */
163 function getRevisionsPassword() {
164 return $this->_revisionsPassword;
165 }
166
167 /**
168 * Set RevisionsPassword
169 *
170 * @param string $pValue
171 * @param boolean $pAlreadyHashed If the password has already been hashed, set this to true
172 * @return PHPExcel_DocumentSecurity
173 */
174 function setRevisionsPassword($pValue = '', $pAlreadyHashed = false) {
175 if (!$pAlreadyHashed) {
176 $pValue = PHPExcel_Shared_PasswordHasher::hashPassword($pValue);
177 }
178 $this->_revisionsPassword = $pValue;
179 return $this;
180 }
181
182 /**
183 * Get WorkbookPassword (hashed)
184 *
185 * @return string
186 */
187 function getWorkbookPassword() {
188 return $this->_workbookPassword;
189 }
190
191 /**
192 * Set WorkbookPassword
193 *
194 * @param string $pValue
195 * @param boolean $pAlreadyHashed If the password has already been hashed, set this to true
196 * @return PHPExcel_DocumentSecurity
197 */
198 function setWorkbookPassword($pValue = '', $pAlreadyHashed = false) {
199 if (!$pAlreadyHashed) {
200 $pValue = PHPExcel_Shared_PasswordHasher::hashPassword($pValue);
201 }
202 $this->_workbookPassword = $pValue;
203 return $this;
204 }
205
206 /**
207 * Implement PHP __clone to create a deep clone, not just a shallow copy.
208 */
209 public function __clone() {
210 $vars = get_object_vars($this);
211 foreach ($vars as $key => $value) {
212 if (is_object($value)) {
213 $this->$key = clone $value;
214 } else {
215 $this->$key = $value;
216 }
217 }
218 }
219 }
1 <?php
2 /**
3 * PHPExcel
4 *
5 * Copyright (c) 2006 - 2011 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 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
24 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25 * @version 1.7.6, 2011-02-27
26 */
27
28
29 /**
30 * PHPExcel_HashTable
31 *
32 * @category PHPExcel
33 * @package PHPExcel
34 * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
35 */
36 class PHPExcel_HashTable
37 {
38 /**
39 * HashTable elements
40 *
41 * @var array
42 */
43 public $_items = array();
44
45 /**
46 * HashTable key map
47 *
48 * @var array
49 */
50 public $_keyMap = array();
51
52 /**
53 * Create a new PHPExcel_HashTable
54 *
55 * @param PHPExcel_IComparable[] $pSource Optional source array to create HashTable from
56 * @throws Exception
57 */
58 public function __construct($pSource = null)
59 {
60 if (!is_null($pSource)) {
61 // Create HashTable
62 $this->addFromSource($pSource);
63 }
64 }
65
66 /**
67 * Add HashTable items from source
68 *
69 * @param PHPExcel_IComparable[] $pSource Source array to create HashTable from
70 * @throws Exception
71 */
72 public function addFromSource($pSource = null) {
73 // Check if an array was passed
74 if ($pSource == null) {
75 return;
76 } else if (!is_array($pSource)) {
77 throw new Exception('Invalid array parameter passed.');
78 }
79
80 foreach ($pSource as $item) {
81 $this->add($item);
82 }
83 }
84
85 /**
86 * Add HashTable item
87 *
88 * @param PHPExcel_IComparable $pSource Item to add
89 * @throws Exception
90 */
91 public function add(PHPExcel_IComparable $pSource = null) {
92 $hash = $pSource->getHashCode();
93 if (!isset($this->_items[$hash])) {
94 $this->_items[$hash] = $pSource;
95 $this->_keyMap[count($this->_items) - 1] = $hash;
96 }
97 }
98
99 /**
100 * Remove HashTable item
101 *
102 * @param PHPExcel_IComparable $pSource Item to remove
103 * @throws Exception
104 */
105 public function remove(PHPExcel_IComparable $pSource = null) {
106 $hash = $pSource->getHashCode();
107 if (isset($this->_items[$hash])) {
108 unset($this->_items[$hash]);
109
110 $deleteKey = -1;
111 foreach ($this->_keyMap as $key => $value) {
112 if ($deleteKey >= 0) {
113 $this->_keyMap[$key - 1] = $value;
114 }
115
116 if ($value == $hash) {
117 $deleteKey = $key;
118 }
119 }
120 unset($this->_keyMap[count($this->_keyMap) - 1]);
121 }
122 }
123
124 /**
125 * Clear HashTable
126 *
127 */
128 public function clear() {
129 $this->_items = array();
130 $this->_keyMap = array();
131 }
132
133 /**
134 * Count
135 *
136 * @return int
137 */
138 public function count() {
139 return count($this->_items);
140 }
141
142 /**
143 * Get index for hash code
144 *
145 * @param string $pHashCode
146 * @return int Index
147 */
148 public function getIndexForHashCode($pHashCode = '') {
149 return array_search($pHashCode, $this->_keyMap);
150 }
151
152 /**
153 * Get by index
154 *
155 * @param int $pIndex
156 * @return PHPExcel_IComparable
157 *
158 */
159 public function getByIndex($pIndex = 0) {
160 if (isset($this->_keyMap[$pIndex])) {
161 return $this->getByHashCode( $this->_keyMap[$pIndex] );
162 }
163
164 return null;
165 }
166
167 /**
168 * Get by hashcode
169 *
170 * @param string $pHashCode
171 * @return PHPExcel_IComparable
172 *
173 */
174 public function getByHashCode($pHashCode = '') {
175 if (isset($this->_items[$pHashCode])) {
176 return $this->_items[$pHashCode];
177 }
178
179 return null;
180 }
181
182 /**
183 * HashTable to array
184 *
185 * @return PHPExcel_IComparable[]
186 */
187 public function toArray() {
188 return $this->_items;
189 }
190
191 /**
192 * Implement PHP __clone to create a deep clone, not just a shallow copy.
193 */
194 public function __clone() {
195 $vars = get_object_vars($this);
196 foreach ($vars as $key => $value) {
197 if (is_object($value)) {
198 $this->$key = clone $value;
199 }
200 }
201 }
202 }
1 <?php
2 namespace Tz\Wordpress\Tools\ExcelWriter;
3 /**
4 * PHPExcel
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 *
20 * @category PHPExcel
21 * @package PHPExcel
22 * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
23 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
24 * @version 1.7.6, 2011-02-27
25 */
26
27
28 /**
29 * PHPExcel_IComparable
30 *
31 * @category PHPExcel
32 * @package PHPExcel
33 * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
34 */
35 interface PHPExcel_IComparable
36 {
37 /**
38 * Get hash code
39 *
40 * @return string Hash code
41 */
42 public function getHashCode();
43
44 }
1 <?php
2 namespace Tz\Wordpress\Tools\ExcelWriter;
3 /**
4 * PHPExcel
5 *
6 * Copyright (c) 2006 - 2011 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
24 * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
25 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
26 * @version 1.7.6, 2011-02-27
27 */
28
29
30 /** PHPExcel root directory */
31 if (!defined('PHPEXCEL_ROOT')) {
32 /**
33 * @ignore
34 */
35 define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../');
36 require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
37 }
38
39 /**
40 * PHPExcel_IOFactory
41 *
42 * @category PHPExcel
43 * @package PHPExcel
44 * @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
45 */
46 class PHPExcel_IOFactory
47 {
48 /**
49 * Search locations
50 *
51 * @var array
52 * @access private
53 * @static
54 */
55 private static $_searchLocations = array(
56 array( 'type' => 'IWriter', 'path' => 'PHPExcel/Writer/{0}.php', 'class' => 'PHPExcel_Writer_{0}' ),
57 array( 'type' => 'IReader', 'path' => 'PHPExcel/Reader/{0}.php', 'class' => 'PHPExcel_Reader_{0}' )
58 );
59
60 /**
61 * Autoresolve classes
62 *
63 * @var array
64 * @access private
65 * @static
66 */
67 private static $_autoResolveClasses = array(
68 'Excel2007',
69 'Excel5',
70 'Excel2003XML',
71 'OOCalc',
72 'SYLK',
73 'Gnumeric',
74 'CSV',
75 );
76
77 /**
78 * Private constructor for PHPExcel_IOFactory
79 */
80 private function __construct() { }
81
82 /**
83 * Get search locations
84 *
85 * @static
86 * @access public
87 * @return array
88 */
89 public static function getSearchLocations() {
90 return self::$_searchLocations;
91 } // function getSearchLocations()
92
93 /**
94 * Set search locations
95 *
96 * @static
97 * @access public
98 * @param array $value
99 * @throws Exception
100 */
101 public static function setSearchLocations($value) {
102 if (is_array($value)) {
103 self::$_searchLocations = $value;
104 } else {
105 throw new Exception('Invalid parameter passed.');
106 }
107 } // function setSearchLocations()
108
109 /**
110 * Add search location
111 *
112 * @static
113 * @access public
114 * @param string $type Example: IWriter
115 * @param string $location Example: PHPExcel/Writer/{0}.php
116 * @param string $classname Example: PHPExcel_Writer_{0}
117 */
118 public static function addSearchLocation($type = '', $location = '', $classname = '') {
119 self::$_searchLocations[] = array( 'type' => $type, 'path' => $location, 'class' => $classname );
120 } // function addSearchLocation()
121
122 /**
123 * Create PHPExcel_Writer_IWriter
124 *
125 * @static
126 * @access public
127 * @param PHPExcel $phpExcel
128 * @param string $writerType Example: Excel2007
129 * @return PHPExcel_Writer_IWriter
130 * @throws Exception
131 */
132 public static function createWriter(PHPExcel $phpExcel, $writerType = '') {
133 // Search type
134 $searchType = 'IWriter';
135
136 // Include class
137 foreach (self::$_searchLocations as $searchLocation) {
138 if ($searchLocation['type'] == $searchType) {
139 $className = str_replace('{0}', $writerType, $searchLocation['class']);
140 $classFile = str_replace('{0}', $writerType, $searchLocation['path']);
141
142 if ($className == 'PHPExcel_Writer_Excel5') {
143 $className = __NAMESPACE__ . '\\' . $className;
144 }
145 $instance = new $className($phpExcel);
146 if (!is_null($instance)) {
147 return $instance;
148 }
149 }
150 }
151
152 // Nothing found...
153 throw new Exception("No $searchType found for type $writerType");
154 } // function createWriter()
155
156 /**
157 * Create PHPExcel_Reader_IReader
158 *
159 * @static
160 * @access public
161 * @param string $readerType Example: Excel2007
162 * @return PHPExcel_Reader_IReader
163 * @throws Exception
164 */
165 public static function createReader($readerType = '') {
166 // Search type
167 $searchType = 'IReader';
168
169 // Include class
170 foreach (self::$_searchLocations as $searchLocation) {
171 if ($searchLocation['type'] == $searchType) {
172 $className = str_replace('{0}', $readerType, $searchLocation['class']);
173 $classFile = str_replace('{0}', $readerType, $searchLocation['path']);
174
175 $instance = new $className();
176 if (!is_null($instance)) {
177 return $instance;
178 }
179 }
180 }
181
182 // Nothing found...
183 throw new Exception("No $searchType found for type $readerType");
184 } // function createReader()
185
186 /**
187 * Loads PHPExcel from file using automatic PHPExcel_Reader_IReader resolution
188 *
189 * @static
190 * @access public
191 * @param string $pFileName
192 * @return PHPExcel
193 * @throws Exception
194 */
195 public static function load($pFilename) {
196 $reader = self::createReaderForFile($pFilename);
197 return $reader->load($pFilename);
198 } // function load()
199
200 /**
201 * Identify file type using automatic PHPExcel_Reader_IReader resolution
202 *
203 * @static
204 * @access public
205 * @param string $pFileName
206 * @return string
207 * @throws Exception
208 */
209 public static function identify($pFilename) {
210 $reader = self::createReaderForFile($pFilename);
211 $className = get_class($reader);
212 $classType = explode('_',$className);
213 unset($reader);
214 return array_pop($classType);
215 } // function identify()
216
217 /**
218 * Create PHPExcel_Reader_IReader for file using automatic PHPExcel_Reader_IReader resolution
219 *
220 * @static
221 * @access public
222 * @param string $pFileName
223 * @return PHPExcel_Reader_IReader
224 * @throws Exception
225 */
226 public static function createReaderForFile($pFilename) {
227
228 // First, lucky guess by inspecting file extension
229 $pathinfo = pathinfo($pFilename);
230
231 if (isset($pathinfo['extension'])) {
232 switch (strtolower($pathinfo['extension'])) {
233 case 'xlsx':
234 $reader = self::createReader('Excel2007');
235 break;
236 case 'xls':
237 $reader = self::createReader('Excel5');
238 break;
239 case 'ods':
240 $reader = self::createReader('OOCalc');
241 break;
242 case 'slk':
243 $reader = self::createReader('SYLK');
244 break;
245 case 'xml':
246 $reader = self::createReader('Excel2003XML');
247 break;
248 case 'gnumeric':
249 $reader = self::createReader('Gnumeric');
250 break;
251 case 'csv':
252 // Do nothing
253 // We must not try to use CSV reader since it loads
254 // all files including Excel files etc.
255 break;
256 default:
257 break;
258 }
259
260 // Let's see if we are lucky
261 if (isset($reader) && $reader->canRead($pFilename)) {
262 return $reader;
263 }
264
265 }
266
267 // If we reach here then "lucky guess" didn't give any result
268
269 // Try loading using self::$_autoResolveClasses
270 foreach (self::$_autoResolveClasses as $autoResolveClass) {
271 $reader = self::createReader($autoResolveClass);
272 if ($reader->canRead($pFilename)) {
273 return $reader;
274 }
275 }
276
277 } // function createReaderForFile()
278 }
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
No preview for this file type
No preview for this file type
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.