~automne-team/automne/trunk

« back to all changes in this revision

Viewing changes to automne/phpMyAdmin/libraries/PHPExcel/PHPExcel/Cell.php

  • Committer: sebastien-pauchet
  • Date: 2012-02-15 16:47:40 UTC
  • mfrom: (363.2.105 4.2)
  • Revision ID: seb@automne-cms.org-20120215164740-xrk26iafkvztwv6s
Merge stable branch 4.2.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
/**
3
 
 * PHPExcel
4
 
 *
5
 
 * Copyright (c) 2006 - 2010 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 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
24
 
 * @license             http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt   LGPL
25
 
 * @version             1.7.4, 2010-08-26
26
 
 */
27
 
 
28
 
 
29
 
/**
30
 
 * PHPExcel_Cell
31
 
 *
32
 
 * @category   PHPExcel
33
 
 * @package     PHPExcel_Cell
34
 
 * @copyright  Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
35
 
 */
36
 
class PHPExcel_Cell
37
 
{
38
 
        /**
39
 
         * Value binder to use
40
 
         *
41
 
         * @var PHPExcel_Cell_IValueBinder
42
 
         */
43
 
        private static $_valueBinder = null;
44
 
 
45
 
        /**
46
 
         * Column of the cell
47
 
         *
48
 
         * @var string
49
 
         */
50
 
        private $_column;
51
 
 
52
 
        /**
53
 
         * Row of the cell
54
 
         *
55
 
         * @var int
56
 
         */
57
 
        private $_row;
58
 
 
59
 
        /**
60
 
         * Value of the cell
61
 
         *
62
 
         * @var mixed
63
 
         */
64
 
        private $_value;
65
 
 
66
 
        /**
67
 
         * Calculated value of the cell (used for caching)
68
 
         *
69
 
         * @var mixed
70
 
         */
71
 
        private $_calculatedValue = null;
72
 
 
73
 
        /**
74
 
         * Type of the cell data
75
 
         *
76
 
         * @var string
77
 
         */
78
 
        private $_dataType;
79
 
 
80
 
        /**
81
 
         * Parent worksheet
82
 
         *
83
 
         * @var PHPExcel_Worksheet
84
 
         */
85
 
        private $_parent;
86
 
 
87
 
        /**
88
 
         * Index to cellXf
89
 
         *
90
 
         * @var int
91
 
         */
92
 
        private $_xfIndex;
93
 
 
94
 
        /**
95
 
         * Attributes of the formula
96
 
         *
97
 
         *
98
 
         */
99
 
        private $_formulaAttributes;
100
 
 
101
 
 
102
 
        /**
103
 
         * Send notification to the cache controller
104
 
         * @return void
105
 
         **/
106
 
        public function notifyCacheController() {
107
 
                $this->_parent->getCellCacheController()->updateCacheData($this);
108
 
                return $this;
109
 
        }
110
 
 
111
 
        public function detach() {
112
 
                $this->_parent = null;
113
 
        }
114
 
 
115
 
        public function attach($parent) {
116
 
                $this->_parent = $parent;
117
 
        }
118
 
 
119
 
 
120
 
        /**
121
 
         * Create a new Cell
122
 
         *
123
 
         * @param       string                          $pColumn
124
 
         * @param       int                             $pRow
125
 
         * @param       mixed                           $pValue
126
 
         * @param       string                          $pDataType
127
 
         * @param       PHPExcel_Worksheet      $pSheet
128
 
         * @throws      Exception
129
 
         */
130
 
        public function __construct($pColumn = 'A', $pRow = 1, $pValue = null, $pDataType = null, PHPExcel_Worksheet $pSheet = null)
131
 
        {
132
 
                // Initialise cell coordinate
133
 
                $this->_column = strtoupper($pColumn);
134
 
                $this->_row = $pRow;
135
 
 
136
 
                // Initialise cell value
137
 
                $this->_value = $pValue;
138
 
 
139
 
                // Set worksheet
140
 
                $this->_parent = $pSheet;
141
 
 
142
 
                // Set datatype?
143
 
                if (!is_null($pDataType)) {
144
 
                        $this->_dataType = $pDataType;
145
 
                } else {
146
 
                        if (!self::getValueBinder()->bindValue($this, $pValue)) {
147
 
                                throw new Exception("Value could not be bound to cell.");
148
 
                        }
149
 
                }
150
 
 
151
 
                // set default index to cellXf
152
 
                $this->_xfIndex = 0;
153
 
        }
154
 
 
155
 
        /**
156
 
         * Get cell coordinate column
157
 
         *
158
 
         * @return string
159
 
         */
160
 
        public function getColumn()
161
 
        {
162
 
                return $this->_column;
163
 
        }
164
 
 
165
 
        /**
166
 
         * Get cell coordinate row
167
 
         *
168
 
         * @return int
169
 
         */
170
 
        public function getRow()
171
 
        {
172
 
                return $this->_row;
173
 
        }
174
 
 
175
 
        /**
176
 
         * Get cell coordinate
177
 
         *
178
 
         * @return string
179
 
         */
180
 
        public function getCoordinate()
181
 
        {
182
 
                return $this->_column . $this->_row;
183
 
        }
184
 
 
185
 
        /**
186
 
         * Get cell value
187
 
         *
188
 
         * @return mixed
189
 
         */
190
 
        public function getValue()
191
 
        {
192
 
                return $this->_value;
193
 
        }
194
 
 
195
 
        /**
196
 
         * Set cell value
197
 
         *
198
 
         * This clears the cell formula.
199
 
         *
200
 
         * @param mixed $pValue                                 Value
201
 
         * @return PHPExcel_Cell
202
 
         */
203
 
        public function setValue($pValue = null)
204
 
        {
205
 
                if (!self::getValueBinder()->bindValue($this, $pValue)) {
206
 
                        throw new Exception("Value could not be bound to cell.");
207
 
                }
208
 
                return $this;
209
 
        }
210
 
 
211
 
        /**
212
 
         * Set cell value (with explicit data type given)
213
 
         *
214
 
         * @param mixed $pValue                 Value
215
 
         * @param string        $pDataType              Explicit data type
216
 
         * @return PHPExcel_Cell
217
 
         * @throws Exception
218
 
         */
219
 
        public function setValueExplicit($pValue = null, $pDataType = PHPExcel_Cell_DataType::TYPE_STRING)
220
 
        {
221
 
                // set the value according to data type
222
 
                switch ($pDataType) {
223
 
                        case PHPExcel_Cell_DataType::TYPE_STRING:
224
 
                        case PHPExcel_Cell_DataType::TYPE_NULL:
225
 
                        case PHPExcel_Cell_DataType::TYPE_INLINE:
226
 
                                $this->_value = PHPExcel_Cell_DataType::checkString($pValue);
227
 
                                break;
228
 
 
229
 
                        case PHPExcel_Cell_DataType::TYPE_NUMERIC:
230
 
                                $this->_value = (float)$pValue;
231
 
                                break;
232
 
 
233
 
                        case PHPExcel_Cell_DataType::TYPE_FORMULA:
234
 
                                $this->_value = (string)$pValue;
235
 
                                break;
236
 
 
237
 
                        case PHPExcel_Cell_DataType::TYPE_BOOL:
238
 
                                $this->_value = (bool)$pValue;
239
 
                                break;
240
 
 
241
 
                        case PHPExcel_Cell_DataType::TYPE_ERROR:
242
 
                                $this->_value = PHPExcel_Cell_DataType::checkErrorCode($pValue);
243
 
                                break;
244
 
 
245
 
                        default:
246
 
                                throw new Exception('Invalid datatype: ' . $pDataType);
247
 
                                break;
248
 
                }
249
 
 
250
 
                // set the datatype
251
 
                $this->_dataType = $pDataType;
252
 
 
253
 
                return $this->notifyCacheController();
254
 
        }
255
 
 
256
 
        /**
257
 
         * Get calculated cell value
258
 
         *
259
 
         * @return mixed
260
 
         */
261
 
        public function getCalculatedValue($resetLog=true)
262
 
        {
263
 
//              echo 'Cell '.$this->getCoordinate().' value is a '.$this->_dataType.' with a value of '.$this->getValue().'<br />';
264
 
                if ($this->_dataType == PHPExcel_Cell_DataType::TYPE_FORMULA) {
265
 
                        try {
266
 
//                              echo 'Cell value for '.$this->getCoordinate().' is a formula: Calculating value<br />';
267
 
                                $result = PHPExcel_Calculation::getInstance()->calculateCellValue($this,$resetLog);
268
 
//                              echo $this->getCoordinate().' calculation result is '.$result.'<br />';
269
 
                        } catch ( Exception $ex ) {
270
 
//                              echo 'Calculation Exception: '.$ex->getMessage().'<br />';
271
 
                                $result = '#N/A';
272
 
                                throw(new Exception($this->getParent()->getTitle().'!'.$this->getCoordinate().' -> '.$ex->getMessage()));
273
 
                        }
274
 
 
275
 
                        if ($result === '#Not Yet Implemented') {
276
 
//                              echo 'Returning fallback value of '.$this->_calculatedValue.' for cell '.$this->getCoordinate().'<br />';
277
 
                                return $this->_calculatedValue; // Fallback if calculation engine does not support the formula.
278
 
                        }
279
 
//                      echo 'Returning calculated value of '.$result.' for cell '.$this->getCoordinate().'<br />';
280
 
                        return $result;
281
 
                }
282
 
 
283
 
                if (is_null($this->_value)) {
284
 
//                      echo 'Cell '.$this->getCoordinate().' has no value, formula or otherwise<br />';
285
 
                        return null;
286
 
                }
287
 
//              echo 'Cell value for '.$this->getCoordinate().' is not a formula: Returning data value of '.$this->_value.'<br />';
288
 
                return $this->_value;
289
 
        }
290
 
 
291
 
        /**
292
 
         * Set calculated value (used for caching)
293
 
         *
294
 
         * @param mixed $pValue Value
295
 
         * @return PHPExcel_Cell
296
 
         */
297
 
        public function setCalculatedValue($pValue = null)
298
 
        {
299
 
                if (!is_null($pValue)) {
300
 
                        $this->_calculatedValue = $pValue;
301
 
                }
302
 
 
303
 
                return $this->notifyCacheController();
304
 
        }
305
 
 
306
 
        /**
307
 
         * Get old calculated value (cached)
308
 
         *
309
 
         * @return mixed
310
 
         */
311
 
        public function getOldCalculatedValue()
312
 
        {
313
 
                return $this->_calculatedValue;
314
 
        }
315
 
 
316
 
        /**
317
 
         * Get cell data type
318
 
         *
319
 
         * @return string
320
 
         */
321
 
        public function getDataType()
322
 
        {
323
 
                return $this->_dataType;
324
 
        }
325
 
 
326
 
        /**
327
 
         * Set cell data type
328
 
         *
329
 
         * @param string $pDataType
330
 
         * @return PHPExcel_Cell
331
 
         */
332
 
        public function setDataType($pDataType = PHPExcel_Cell_DataType::TYPE_STRING)
333
 
        {
334
 
                $this->_dataType = $pDataType;
335
 
 
336
 
                return $this->notifyCacheController();
337
 
        }
338
 
 
339
 
        /**
340
 
         * Has Data validation?
341
 
         *
342
 
         * @return boolean
343
 
         */
344
 
        public function hasDataValidation()
345
 
        {
346
 
                if (!isset($this->_parent)) {
347
 
                        throw new Exception('Cannot check for data validation when cell is not bound to a worksheet');
348
 
                }
349
 
 
350
 
                return $this->_parent->dataValidationExists($this->getCoordinate());
351
 
        }
352
 
 
353
 
        /**
354
 
         * Get Data validation
355
 
         *
356
 
         * @return PHPExcel_Cell_DataValidation
357
 
         */
358
 
        public function getDataValidation()
359
 
        {
360
 
                if (!isset($this->_parent)) {
361
 
                        throw new Exception('Cannot get data validation for cell that is not bound to a worksheet');
362
 
                }
363
 
 
364
 
                return $this->_parent->getDataValidation($this->getCoordinate());
365
 
        }
366
 
 
367
 
        /**
368
 
         * Set Data validation
369
 
         *
370
 
         * @param       PHPExcel_Cell_DataValidation    $pDataValidation
371
 
         * @throws      Exception
372
 
         * @return PHPExcel_Cell
373
 
         */
374
 
        public function setDataValidation(PHPExcel_Cell_DataValidation $pDataValidation = null)
375
 
        {
376
 
                if (!isset($this->_parent)) {
377
 
                        throw new Exception('Cannot set data validation for cell that is not bound to a worksheet');
378
 
                }
379
 
 
380
 
                $this->_parent->setDataValidation($this->getCoordinate(), $pDataValidation);
381
 
 
382
 
                return $this->notifyCacheController();
383
 
        }
384
 
 
385
 
        /**
386
 
         * Has Hyperlink
387
 
         *
388
 
         * @return boolean
389
 
         */
390
 
        public function hasHyperlink()
391
 
        {
392
 
                if (!isset($this->_parent)) {
393
 
                        throw new Exception('Cannot check for hyperlink when cell is not bound to a worksheet');
394
 
                }
395
 
 
396
 
                return $this->_parent->hyperlinkExists($this->getCoordinate());
397
 
        }
398
 
 
399
 
        /**
400
 
         * Get Hyperlink
401
 
         *
402
 
         * @throws Exception
403
 
         * @return PHPExcel_Cell_Hyperlink
404
 
         */
405
 
        public function getHyperlink()
406
 
        {
407
 
                if (!isset($this->_parent)) {
408
 
                        throw new Exception('Cannot get hyperlink for cell that is not bound to a worksheet');
409
 
                }
410
 
 
411
 
                return $this->_parent->getHyperlink($this->getCoordinate());
412
 
        }
413
 
 
414
 
        /**
415
 
         * Set Hyperlink
416
 
         *
417
 
         * @param       PHPExcel_Cell_Hyperlink $pHyperlink
418
 
         * @throws      Exception
419
 
         * @return PHPExcel_Cell
420
 
         */
421
 
        public function setHyperlink(PHPExcel_Cell_Hyperlink $pHyperlink = null)
422
 
        {
423
 
                if (!isset($this->_parent)) {
424
 
                        throw new Exception('Cannot set hyperlink for cell that is not bound to a worksheet');
425
 
                }
426
 
 
427
 
                $this->_parent->setHyperlink($this->getCoordinate(), $pHyperlink);
428
 
 
429
 
                return $this->notifyCacheController();
430
 
        }
431
 
 
432
 
        /**
433
 
         * Get parent
434
 
         *
435
 
         * @return PHPExcel_Worksheet
436
 
         */
437
 
        public function getParent() {
438
 
                return $this->_parent;
439
 
        }
440
 
 
441
 
        /**
442
 
         * Re-bind parent
443
 
         *
444
 
         * @param PHPExcel_Worksheet $parent
445
 
         * @return PHPExcel_Cell
446
 
         */
447
 
        public function rebindParent(PHPExcel_Worksheet $parent) {
448
 
                $this->_parent = $parent;
449
 
 
450
 
                return $this->notifyCacheController();
451
 
        }
452
 
 
453
 
        /**
454
 
         * Is cell in a specific range?
455
 
         *
456
 
         * @param       string  $pRange         Cell range (e.g. A1:A1)
457
 
         * @return      boolean
458
 
         */
459
 
        public function isInRange($pRange = 'A1:A1')
460
 
        {
461
 
                list($rangeStart,$rangeEnd) = PHPExcel_Cell::rangeBoundaries($pRange);
462
 
 
463
 
                // Translate properties
464
 
                $myColumn       = PHPExcel_Cell::columnIndexFromString($this->getColumn()) - 1;
465
 
                $myRow          = $this->getRow();
466
 
 
467
 
                // Verify if cell is in range
468
 
                return (($rangeStart[0] <= $myColumn) && ($rangeEnd[0] >= $myColumn) &&
469
 
                                ($rangeStart[1] <= $myRow) && ($rangeEnd[1] >= $myRow)
470
 
                           );
471
 
        }
472
 
 
473
 
        /**
474
 
         * Coordinate from string
475
 
         *
476
 
         * @param       string  $pCoordinateString
477
 
         * @return      array   Array containing column and row (indexes 0 and 1)
478
 
         * @throws      Exception
479
 
         */
480
 
        public static function coordinateFromString($pCoordinateString = 'A1')
481
 
        {
482
 
                if (strpos($pCoordinateString,':') !== false) {
483
 
                        throw new Exception('Cell coordinate string can not be a range of cells.');
484
 
                } else if ($pCoordinateString == '') {
485
 
                        throw new Exception('Cell coordinate can not be zero-length string.');
486
 
                } else if (preg_match("/([$]?[A-Z]+)([$]?\d+)/", $pCoordinateString, $matches)) {
487
 
                        list(, $column, $row) = $matches;
488
 
                        return array($column, $row);
489
 
                } else {
490
 
                        throw new Exception('Invalid cell coordinate.');
491
 
                }
492
 
        }
493
 
 
494
 
        /**
495
 
         * Make string coordinate absolute
496
 
         *
497
 
         * @param       string  $pCoordinateString
498
 
         * @return      string  Absolute coordinate
499
 
         * @throws      Exception
500
 
         */
501
 
        public static function absoluteCoordinate($pCoordinateString = 'A1')
502
 
        {
503
 
                if (strpos($pCoordinateString,':') === false && strpos($pCoordinateString,',') === false) {
504
 
                        // Create absolute coordinate
505
 
                        list($column, $row) = PHPExcel_Cell::coordinateFromString($pCoordinateString);
506
 
                        return '$' . $column . '$' . $row;
507
 
                } else {
508
 
                        throw new Exception("Coordinate string should not be a cell range.");
509
 
                }
510
 
        }
511
 
 
512
 
        /**
513
 
         * Split range into coordinate strings
514
 
         *
515
 
         * @param       string  $pRange
516
 
         * @return      array   Array containg one or more arrays containing one or two coordinate strings
517
 
         */
518
 
        public static function splitRange($pRange = 'A1:A1')
519
 
        {
520
 
                $exploded = explode(',', $pRange);
521
 
                for ($i = 0; $i < count($exploded); ++$i) {
522
 
                        $exploded[$i] = explode(':', $exploded[$i]);
523
 
                }
524
 
                return $exploded;
525
 
        }
526
 
 
527
 
        /**
528
 
         * Build range from coordinate strings
529
 
         *
530
 
         * @param       array   $pRange Array containg one or more arrays containing one or two coordinate strings
531
 
         * @return  string      String representation of $pRange
532
 
         * @throws      Exception
533
 
         */
534
 
        public static function buildRange($pRange)
535
 
        {
536
 
                // Verify range
537
 
                if (!is_array($pRange) || count($pRange) == 0 || !is_array($pRange[0])) {
538
 
                        throw new Exception('Range does not contain any information.');
539
 
                }
540
 
 
541
 
                // Build range
542
 
                $imploded = array();
543
 
                for ($i = 0; $i < count($pRange); ++$i) {
544
 
                        $pRange[$i] = implode(':', $pRange[$i]);
545
 
                }
546
 
                $imploded = implode(',', $pRange);
547
 
 
548
 
                return $imploded;
549
 
        }
550
 
 
551
 
        /**
552
 
         * Calculate range boundaries
553
 
         *
554
 
         * @param       string  $pRange         Cell range (e.g. A1:A1)
555
 
         * @return      array   Range coordinates (Start Cell, End Cell) where Start Cell and End Cell are arrays (Column Number, Row Number)
556
 
         */
557
 
        public static function rangeBoundaries($pRange = 'A1:A1')
558
 
        {
559
 
                // Uppercase coordinate
560
 
                $pRange = strtoupper($pRange);
561
 
 
562
 
                // Extract range
563
 
                if (strpos($pRange, ':') === false) {
564
 
                        $rangeA = $rangeB = $pRange;
565
 
                } else {
566
 
                        list($rangeA, $rangeB) = explode(':', $pRange);
567
 
                }
568
 
 
569
 
                // Calculate range outer borders
570
 
                $rangeStart = PHPExcel_Cell::coordinateFromString($rangeA);
571
 
                $rangeEnd       = PHPExcel_Cell::coordinateFromString($rangeB);
572
 
 
573
 
                // Translate column into index
574
 
                $rangeStart[0]  = PHPExcel_Cell::columnIndexFromString($rangeStart[0]);
575
 
                $rangeEnd[0]    = PHPExcel_Cell::columnIndexFromString($rangeEnd[0]);
576
 
 
577
 
                return array($rangeStart, $rangeEnd);
578
 
        }
579
 
 
580
 
        /**
581
 
         * Calculate range dimension
582
 
         *
583
 
         * @param       string  $pRange         Cell range (e.g. A1:A1)
584
 
         * @return      array   Range dimension (width, height)
585
 
         */
586
 
        public static function rangeDimension($pRange = 'A1:A1')
587
 
        {
588
 
                // Calculate range outer borders
589
 
                list($rangeStart,$rangeEnd) = PHPExcel_Cell::rangeBoundaries($pRange);
590
 
 
591
 
                return array( ($rangeEnd[0] - $rangeStart[0] + 1), ($rangeEnd[1] - $rangeStart[1] + 1) );
592
 
        }
593
 
 
594
 
        /**
595
 
         * Calculate range boundaries
596
 
         *
597
 
         * @param       string  $pRange         Cell range (e.g. A1:A1)
598
 
         * @return      array   Range boundaries (staring Column, starting Row, Final Column, Final Row)
599
 
         */
600
 
        public static function getRangeBoundaries($pRange = 'A1:A1')
601
 
        {
602
 
                // Uppercase coordinate
603
 
                $pRange = strtoupper($pRange);
604
 
 
605
 
                // Extract range
606
 
                if (strpos($pRange, ':') === false) {
607
 
                        $rangeA = $pRange;
608
 
                        $rangeB = $pRange;
609
 
                } else {
610
 
                        list($rangeA, $rangeB) = explode(':', $pRange);
611
 
                }
612
 
 
613
 
                return array( self::coordinateFromString($rangeA), self::coordinateFromString($rangeB));
614
 
        }
615
 
 
616
 
        /**
617
 
         * Column index from string
618
 
         *
619
 
         * @param       string $pString
620
 
         * @return      int Column index (base 1 !!!)
621
 
         * @throws      Exception
622
 
         */
623
 
        public static function columnIndexFromString($pString = 'A')
624
 
        {
625
 
                static $lookup = array(
626
 
                        'A' => 1, 'B' => 2, 'C' => 3, 'D' => 4, 'E' => 5, 'F' => 6, 'G' => 7, 'H' => 8, 'I' => 9, 'J' => 10, 'K' => 11, 'L' => 12, 'M' => 13,
627
 
                        'N' => 14, 'O' => 15, 'P' => 16, 'Q' => 17, 'R' => 18, 'S' => 19, 'T' => 20, 'U' => 21, 'V' => 22, 'W' => 23, 'X' => 24, 'Y' => 25, 'Z' => 26
628
 
                );
629
 
 
630
 
                if (isset($lookup[$pString]))
631
 
                        return $lookup[$pString];
632
 
 
633
 
                // Convert to uppercase
634
 
                $pString = strtoupper($pString);
635
 
 
636
 
                $strLen = strlen($pString);
637
 
                // Convert column to integer
638
 
                if ($strLen == 1) {
639
 
                        return (ord($pString{0}) - 64);
640
 
                } elseif ($strLen == 2) {
641
 
                        return $result = ((1 + (ord($pString{0}) - 65)) * 26) + (ord($pString{1}) - 64);
642
 
                } elseif ($strLen == 3) {
643
 
                        return ((1 + (ord($pString{0}) - 65)) * 676) + ((1 + (ord($pString{1}) - 65)) * 26) + (ord($pString{2}) - 64);
644
 
                } else {
645
 
                        throw new Exception("Column string index can not be " . ($strLen != 0 ? "longer than 3 characters" : "empty") . ".");
646
 
                }
647
 
        }
648
 
 
649
 
        /**
650
 
         * String from columnindex
651
 
         *
652
 
         * @param int $pColumnIndex Column index (base 0 !!!)
653
 
         * @return string
654
 
         */
655
 
        public static function stringFromColumnIndex($pColumnIndex = 0)
656
 
        {
657
 
                // Determine column string
658
 
                if ($pColumnIndex < 26) {
659
 
                        return chr(65 + $pColumnIndex);
660
 
                }
661
 
                return PHPExcel_Cell::stringFromColumnIndex((int)($pColumnIndex / 26) -1).chr(65 + $pColumnIndex%26) ;
662
 
        }
663
 
 
664
 
        /**
665
 
         * Extract all cell references in range
666
 
         *
667
 
         * @param       string  $pRange         Range (e.g. A1 or A1:A10 or A1:A10 A100:A1000)
668
 
         * @return      array   Array containing single cell references
669
 
         */
670
 
        public static function extractAllCellReferencesInRange($pRange = 'A1') {
671
 
                // Returnvalue
672
 
                $returnValue = array();
673
 
 
674
 
                // Explode spaces
675
 
                $aExplodeSpaces = explode(' ', str_replace('$', '', strtoupper($pRange)));
676
 
                foreach ($aExplodeSpaces as $explodedSpaces) {
677
 
                        // Single cell?
678
 
                        if (strpos($explodedSpaces,':') === false && strpos($explodedSpaces,',') === false) {
679
 
                                $col = 'A';
680
 
                                $row = 1;
681
 
                                list($col, $row) = PHPExcel_Cell::coordinateFromString($explodedSpaces);
682
 
 
683
 
                                if (strlen($col) <= 2) {
684
 
                                        $returnValue[] = $explodedSpaces;
685
 
                                }
686
 
 
687
 
                                continue;
688
 
                        }
689
 
 
690
 
                        // Range...
691
 
                        $range = PHPExcel_Cell::splitRange($explodedSpaces);
692
 
                        for ($i = 0; $i < count($range); ++$i) {
693
 
                                // Single cell?
694
 
                                if (count($range[$i]) == 1) {
695
 
                                        $col = 'A';
696
 
                                        $row = 1;
697
 
                                        list($col, $row) = PHPExcel_Cell::coordinateFromString($range[$i]);
698
 
 
699
 
                                        if (strlen($col) <= 2) {
700
 
                                                $returnValue[] = $explodedSpaces;
701
 
                                        }
702
 
                                }
703
 
 
704
 
                                // Range...
705
 
                                $rangeStart             = $rangeEnd             = '';
706
 
                                $startingCol    = $startingRow  = $endingCol    = $endingRow    = 0;
707
 
 
708
 
                                list($rangeStart, $rangeEnd)            = $range[$i];
709
 
                                list($startingCol, $startingRow)        = PHPExcel_Cell::coordinateFromString($rangeStart);
710
 
                                list($endingCol, $endingRow)            = PHPExcel_Cell::coordinateFromString($rangeEnd);
711
 
 
712
 
                                // Conversions...
713
 
                                $startingCol    = PHPExcel_Cell::columnIndexFromString($startingCol);
714
 
                                $endingCol              = PHPExcel_Cell::columnIndexFromString($endingCol);
715
 
 
716
 
                                // Current data
717
 
                                $currentCol     = --$startingCol;
718
 
                                $currentRow     = $startingRow;
719
 
 
720
 
                                // Loop cells
721
 
                                while ($currentCol < $endingCol) {
722
 
                                        $loopColumn = PHPExcel_Cell::stringFromColumnIndex($currentCol);
723
 
                                        while ($currentRow <= $endingRow) {
724
 
                                                $returnValue[] = $loopColumn.$currentRow;
725
 
                                                ++$currentRow;
726
 
                                        }
727
 
                                        ++$currentCol;
728
 
                                        $currentRow = $startingRow;
729
 
                                }
730
 
                        }
731
 
                }
732
 
 
733
 
                // Return value
734
 
                return $returnValue;
735
 
        }
736
 
 
737
 
        /**
738
 
         * Compare 2 cells
739
 
         *
740
 
         * @param       PHPExcel_Cell   $a      Cell a
741
 
         * @param       PHPExcel_Cell   $a      Cell b
742
 
         * @return      int             Result of comparison (always -1 or 1, never zero!)
743
 
         */
744
 
        public static function compareCells(PHPExcel_Cell $a, PHPExcel_Cell $b)
745
 
        {
746
 
                if ($a->_row < $b->_row) {
747
 
                        return -1;
748
 
                } elseif ($a->_row > $b->_row) {
749
 
                        return 1;
750
 
                } elseif (PHPExcel_Cell::columnIndexFromString($a->_column) < PHPExcel_Cell::columnIndexFromString($b->_column)) {
751
 
                        return -1;
752
 
                } else {
753
 
                        return 1;
754
 
                }
755
 
        }
756
 
 
757
 
        /**
758
 
         * Get value binder to use
759
 
         *
760
 
         * @return PHPExcel_Cell_IValueBinder
761
 
         */
762
 
        public static function getValueBinder() {
763
 
                if (is_null(self::$_valueBinder)) {
764
 
                        self::$_valueBinder = new PHPExcel_Cell_DefaultValueBinder();
765
 
                }
766
 
 
767
 
                return self::$_valueBinder;
768
 
        }
769
 
 
770
 
        /**
771
 
         * Set value binder to use
772
 
         *
773
 
         * @param PHPExcel_Cell_IValueBinder $binder
774
 
         * @throws Exception
775
 
         */
776
 
        public static function setValueBinder(PHPExcel_Cell_IValueBinder $binder = null) {
777
 
                if (is_null($binder)) {
778
 
                        throw new Exception("A PHPExcel_Cell_IValueBinder is required for PHPExcel to function correctly.");
779
 
                }
780
 
 
781
 
                self::$_valueBinder = $binder;
782
 
        }
783
 
 
784
 
        /**
785
 
         * Implement PHP __clone to create a deep clone, not just a shallow copy.
786
 
         */
787
 
        public function __clone() {
788
 
                $vars = get_object_vars($this);
789
 
                foreach ($vars as $key => $value) {
790
 
                        if ((is_object($value)) && ($key != '_parent')) {
791
 
                                $this->$key = clone $value;
792
 
                        } else {
793
 
                                $this->$key = $value;
794
 
                        }
795
 
                }
796
 
        }
797
 
 
798
 
        /**
799
 
         * Get index to cellXf
800
 
         *
801
 
         * @return int
802
 
         */
803
 
        public function getXfIndex()
804
 
        {
805
 
                return $this->_xfIndex;
806
 
        }
807
 
 
808
 
        /**
809
 
         * Set index to cellXf
810
 
         *
811
 
         * @param int $pValue
812
 
         * @return PHPExcel_Cell
813
 
         */
814
 
        public function setXfIndex($pValue = 0)
815
 
        {
816
 
                $this->_xfIndex = $pValue;
817
 
 
818
 
                return $this->notifyCacheController();
819
 
        }
820
 
 
821
 
 
822
 
        public function setFormulaAttributes($pAttributes)
823
 
        {
824
 
                $this->_formulaAttributes = $pAttributes;
825
 
                return $this;
826
 
        }
827
 
 
828
 
        public function getFormulaAttributes()
829
 
        {
830
 
                return $this->_formulaAttributes;
831
 
        }
832
 
 
833
 
}
834