Subversion Repositories eFlore/Applications.cel

Rev

Rev 2388 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2388 jpm 1
<?php
2
/**
3
 * PHPExcel
4
 *
5
 * Copyright (c) 2006 - 2013 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_Worksheet
23
 * @copyright  Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
24
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
25
 * @version    ##VERSION##, ##DATE##
26
 */
27
 
28
 
29
/**
30
 * PHPExcel_Worksheet
31
 *
32
 * @category   PHPExcel
33
 * @package    PHPExcel_Worksheet
34
 * @copyright  Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
35
 */
36
class PHPExcel_Worksheet implements PHPExcel_IComparable
37
{
38
    /* Break types */
39
    const BREAK_NONE   = 0;
40
    const BREAK_ROW    = 1;
41
    const BREAK_COLUMN = 2;
42
 
43
    /* Sheet state */
44
    const SHEETSTATE_VISIBLE    = 'visible';
45
    const SHEETSTATE_HIDDEN     = 'hidden';
46
    const SHEETSTATE_VERYHIDDEN = 'veryHidden';
47
 
48
    /**
49
     * Invalid characters in sheet title
50
     *
51
     * @var array
52
     */
53
    private static $_invalidCharacters = array('*', ':', '/', '\\', '?', '[', ']');
54
 
55
    /**
56
     * Parent spreadsheet
57
     *
58
     * @var PHPExcel
59
     */
60
    private $_parent;
61
 
62
    /**
63
     * Cacheable collection of cells
64
     *
65
     * @var PHPExcel_CachedObjectStorage_xxx
66
     */
67
    private $_cellCollection = null;
68
 
69
    /**
70
     * Collection of row dimensions
71
     *
72
     * @var PHPExcel_Worksheet_RowDimension[]
73
     */
74
    private $_rowDimensions = array();
75
 
76
    /**
77
     * Default row dimension
78
     *
79
     * @var PHPExcel_Worksheet_RowDimension
80
     */
81
    private $_defaultRowDimension = null;
82
 
83
    /**
84
     * Collection of column dimensions
85
     *
86
     * @var PHPExcel_Worksheet_ColumnDimension[]
87
     */
88
    private $_columnDimensions = array();
89
 
90
    /**
91
     * Default column dimension
92
     *
93
     * @var PHPExcel_Worksheet_ColumnDimension
94
     */
95
    private $_defaultColumnDimension = null;
96
 
97
    /**
98
     * Collection of drawings
99
     *
100
     * @var PHPExcel_Worksheet_BaseDrawing[]
101
     */
102
    private $_drawingCollection = null;
103
 
104
    /**
105
     * Collection of Chart objects
106
     *
107
     * @var PHPExcel_Chart[]
108
     */
109
    private $_chartCollection = array();
110
 
111
    /**
112
     * Worksheet title
113
     *
114
     * @var string
115
     */
116
    private $_title;
117
 
118
    /**
119
     * Sheet state
120
     *
121
     * @var string
122
     */
123
    private $_sheetState;
124
 
125
    /**
126
     * Page setup
127
     *
128
     * @var PHPExcel_Worksheet_PageSetup
129
     */
130
    private $_pageSetup;
131
 
132
    /**
133
     * Page margins
134
     *
135
     * @var PHPExcel_Worksheet_PageMargins
136
     */
137
    private $_pageMargins;
138
 
139
    /**
140
     * Page header/footer
141
     *
142
     * @var PHPExcel_Worksheet_HeaderFooter
143
     */
144
    private $_headerFooter;
145
 
146
    /**
147
     * Sheet view
148
     *
149
     * @var PHPExcel_Worksheet_SheetView
150
     */
151
    private $_sheetView;
152
 
153
    /**
154
     * Protection
155
     *
156
     * @var PHPExcel_Worksheet_Protection
157
     */
158
    private $_protection;
159
 
160
    /**
161
     * Collection of styles
162
     *
163
     * @var PHPExcel_Style[]
164
     */
165
    private $_styles = array();
166
 
167
    /**
168
     * Conditional styles. Indexed by cell coordinate, e.g. 'A1'
169
     *
170
     * @var array
171
     */
172
    private $_conditionalStylesCollection = array();
173
 
174
    /**
175
     * Is the current cell collection sorted already?
176
     *
177
     * @var boolean
178
     */
179
    private $_cellCollectionIsSorted = false;
180
 
181
    /**
182
     * Collection of breaks
183
     *
184
     * @var array
185
     */
186
    private $_breaks = array();
187
 
188
    /**
189
     * Collection of merged cell ranges
190
     *
191
     * @var array
192
     */
193
    private $_mergeCells = array();
194
 
195
    /**
196
     * Collection of protected cell ranges
197
     *
198
     * @var array
199
     */
200
    private $_protectedCells = array();
201
 
202
    /**
203
     * Autofilter Range and selection
204
     *
205
     * @var PHPExcel_Worksheet_AutoFilter
206
     */
207
    private $_autoFilter = NULL;
208
 
209
    /**
210
     * Freeze pane
211
     *
212
     * @var string
213
     */
214
    private $_freezePane = '';
215
 
216
    /**
217
     * Show gridlines?
218
     *
219
     * @var boolean
220
     */
221
    private $_showGridlines = true;
222
 
223
    /**
224
    * Print gridlines?
225
    *
226
    * @var boolean
227
    */
228
    private $_printGridlines = false;
229
 
230
    /**
231
    * Show row and column headers?
232
    *
233
    * @var boolean
234
    */
235
    private $_showRowColHeaders = true;
236
 
237
    /**
238
     * Show summary below? (Row/Column outline)
239
     *
240
     * @var boolean
241
     */
242
    private $_showSummaryBelow = true;
243
 
244
    /**
245
     * Show summary right? (Row/Column outline)
246
     *
247
     * @var boolean
248
     */
249
    private $_showSummaryRight = true;
250
 
251
    /**
252
     * Collection of comments
253
     *
254
     * @var PHPExcel_Comment[]
255
     */
256
    private $_comments = array();
257
 
258
    /**
259
     * Active cell. (Only one!)
260
     *
261
     * @var string
262
     */
263
    private $_activeCell = 'A1';
264
 
265
    /**
266
     * Selected cells
267
     *
268
     * @var string
269
     */
270
    private $_selectedCells = 'A1';
271
 
272
    /**
273
     * Cached highest column
274
     *
275
     * @var string
276
     */
277
    private $_cachedHighestColumn = 'A';
278
 
279
    /**
280
     * Cached highest row
281
     *
282
     * @var int
283
     */
284
    private $_cachedHighestRow = 1;
285
 
286
    /**
287
     * Right-to-left?
288
     *
289
     * @var boolean
290
     */
291
    private $_rightToLeft = false;
292
 
293
    /**
294
     * Hyperlinks. Indexed by cell coordinate, e.g. 'A1'
295
     *
296
     * @var array
297
     */
298
    private $_hyperlinkCollection = array();
299
 
300
    /**
301
     * Data validation objects. Indexed by cell coordinate, e.g. 'A1'
302
     *
303
     * @var array
304
     */
305
    private $_dataValidationCollection = array();
306
 
307
    /**
308
     * Tab color
309
     *
310
     * @var PHPExcel_Style_Color
311
     */
312
    private $_tabColor;
313
 
314
    /**
315
     * Dirty flag
316
     *
317
     * @var boolean
318
     */
319
    private $_dirty    = true;
320
 
321
    /**
322
     * Hash
323
     *
324
     * @var string
325
     */
326
    private $_hash    = null;
327
 
328
    /**
329
     * Create a new worksheet
330
     *
331
     * @param PHPExcel        $pParent
332
     * @param string        $pTitle
333
     */
334
    public function __construct(PHPExcel $pParent = null, $pTitle = 'Worksheet')
335
    {
336
        // Set parent and title
337
        $this->_parent = $pParent;
338
        $this->setTitle($pTitle, FALSE);
339
        $this->setSheetState(PHPExcel_Worksheet::SHEETSTATE_VISIBLE);
340
 
341
        $this->_cellCollection        = PHPExcel_CachedObjectStorageFactory::getInstance($this);
342
 
343
        // Set page setup
344
        $this->_pageSetup            = new PHPExcel_Worksheet_PageSetup();
345
 
346
        // Set page margins
347
        $this->_pageMargins         = new PHPExcel_Worksheet_PageMargins();
348
 
349
        // Set page header/footer
350
        $this->_headerFooter        = new PHPExcel_Worksheet_HeaderFooter();
351
 
352
        // Set sheet view
353
        $this->_sheetView            = new PHPExcel_Worksheet_SheetView();
354
 
355
        // Drawing collection
356
        $this->_drawingCollection    = new ArrayObject();
357
 
358
        // Chart collection
359
        $this->_chartCollection     = new ArrayObject();
360
 
361
        // Protection
362
        $this->_protection            = new PHPExcel_Worksheet_Protection();
363
 
364
        // Default row dimension
365
        $this->_defaultRowDimension = new PHPExcel_Worksheet_RowDimension(NULL);
366
 
367
        // Default column dimension
368
        $this->_defaultColumnDimension    = new PHPExcel_Worksheet_ColumnDimension(NULL);
369
 
370
        $this->_autoFilter            = new PHPExcel_Worksheet_AutoFilter(NULL, $this);
371
    }
372
 
373
 
374
    /**
375
     * Disconnect all cells from this PHPExcel_Worksheet object,
376
     *    typically so that the worksheet object can be unset
377
     *
378
     */
379
	public function disconnectCells() {
380
    	if ( $this->_cellCollection !== NULL){
381
            $this->_cellCollection->unsetWorksheetCells();
382
            $this->_cellCollection = NULL;
383
    	}
384
        //    detach ourself from the workbook, so that it can then delete this worksheet successfully
385
        $this->_parent = null;
386
    }
387
 
388
    /**
389
     * Code to execute when this worksheet is unset()
390
     *
391
     */
392
	function __destruct() {
393
		PHPExcel_Calculation::getInstance($this->_parent)
394
		    ->clearCalculationCacheForWorksheet($this->_title);
395
 
396
		$this->disconnectCells();
397
	}
398
 
399
   /**
400
     * Return the cache controller for the cell collection
401
     *
402
     * @return PHPExcel_CachedObjectStorage_xxx
403
     */
404
	public function getCellCacheController() {
405
        return $this->_cellCollection;
406
    }    //    function getCellCacheController()
407
 
408
 
409
    /**
410
     * Get array of invalid characters for sheet title
411
     *
412
     * @return array
413
     */
414
    public static function getInvalidCharacters()
415
    {
416
        return self::$_invalidCharacters;
417
    }
418
 
419
    /**
420
     * Check sheet title for valid Excel syntax
421
     *
422
     * @param string $pValue The string to check
423
     * @return string The valid string
424
     * @throws PHPExcel_Exception
425
     */
426
    private static function _checkSheetTitle($pValue)
427
    {
428
        // Some of the printable ASCII characters are invalid:  * : / \ ? [ ]
429
        if (str_replace(self::$_invalidCharacters, '', $pValue) !== $pValue) {
430
            throw new PHPExcel_Exception('Invalid character found in sheet title');
431
        }
432
 
433
        // Maximum 31 characters allowed for sheet title
434
        if (PHPExcel_Shared_String::CountCharacters($pValue) > 31) {
435
            throw new PHPExcel_Exception('Maximum 31 characters allowed in sheet title.');
436
        }
437
 
438
        return $pValue;
439
    }
440
 
441
    /**
442
     * Get collection of cells
443
     *
444
     * @param boolean $pSorted Also sort the cell collection?
445
     * @return PHPExcel_Cell[]
446
     */
447
    public function getCellCollection($pSorted = true)
448
    {
449
        if ($pSorted) {
450
            // Re-order cell collection
451
            return $this->sortCellCollection();
452
        }
453
        if ($this->_cellCollection !== NULL) {
454
            return $this->_cellCollection->getCellList();
455
        }
456
        return array();
457
    }
458
 
459
    /**
460
     * Sort collection of cells
461
     *
462
     * @return PHPExcel_Worksheet
463
     */
464
    public function sortCellCollection()
465
    {
466
        if ($this->_cellCollection !== NULL) {
467
            return $this->_cellCollection->getSortedCellList();
468
        }
469
        return array();
470
    }
471
 
472
    /**
473
     * Get collection of row dimensions
474
     *
475
     * @return PHPExcel_Worksheet_RowDimension[]
476
     */
477
    public function getRowDimensions()
478
    {
479
        return $this->_rowDimensions;
480
    }
481
 
482
    /**
483
     * Get default row dimension
484
     *
485
     * @return PHPExcel_Worksheet_RowDimension
486
     */
487
    public function getDefaultRowDimension()
488
    {
489
        return $this->_defaultRowDimension;
490
    }
491
 
492
    /**
493
     * Get collection of column dimensions
494
     *
495
     * @return PHPExcel_Worksheet_ColumnDimension[]
496
     */
497
    public function getColumnDimensions()
498
    {
499
        return $this->_columnDimensions;
500
    }
501
 
502
    /**
503
     * Get default column dimension
504
     *
505
     * @return PHPExcel_Worksheet_ColumnDimension
506
     */
507
    public function getDefaultColumnDimension()
508
    {
509
        return $this->_defaultColumnDimension;
510
    }
511
 
512
    /**
513
     * Get collection of drawings
514
     *
515
     * @return PHPExcel_Worksheet_BaseDrawing[]
516
     */
517
    public function getDrawingCollection()
518
    {
519
        return $this->_drawingCollection;
520
    }
521
 
522
    /**
523
     * Get collection of charts
524
     *
525
     * @return PHPExcel_Chart[]
526
     */
527
    public function getChartCollection()
528
    {
529
        return $this->_chartCollection;
530
    }
531
 
532
    /**
533
     * Add chart
534
     *
535
     * @param PHPExcel_Chart $pChart
536
     * @param int|null $iChartIndex Index where chart should go (0,1,..., or null for last)
537
     * @return PHPExcel_Chart
538
     */
539
    public function addChart(PHPExcel_Chart $pChart = null, $iChartIndex = null)
540
    {
541
        $pChart->setWorksheet($this);
542
        if (is_null($iChartIndex)) {
543
            $this->_chartCollection[] = $pChart;
544
        } else {
545
            // Insert the chart at the requested index
546
            array_splice($this->_chartCollection, $iChartIndex, 0, array($pChart));
547
        }
548
 
549
        return $pChart;
550
    }
551
 
552
    /**
553
     * Return the count of charts on this worksheet
554
     *
555
     * @return int        The number of charts
556
     */
557
    public function getChartCount()
558
    {
559
        return count($this->_chartCollection);
560
    }
561
 
562
    /**
563
     * Get a chart by its index position
564
     *
565
     * @param string $index Chart index position
566
     * @return false|PHPExcel_Chart
567
     * @throws PHPExcel_Exception
568
     */
569
    public function getChartByIndex($index = null)
570
    {
571
        $chartCount = count($this->_chartCollection);
572
        if ($chartCount == 0) {
573
            return false;
574
        }
575
        if (is_null($index)) {
576
            $index = --$chartCount;
577
        }
578
        if (!isset($this->_chartCollection[$index])) {
579
            return false;
580
        }
581
 
582
        return $this->_chartCollection[$index];
583
    }
584
 
585
    /**
586
     * Return an array of the names of charts on this worksheet
587
     *
588
     * @return string[] The names of charts
589
     * @throws PHPExcel_Exception
590
     */
591
    public function getChartNames()
592
    {
593
        $chartNames = array();
594
        foreach($this->_chartCollection as $chart) {
595
            $chartNames[] = $chart->getName();
596
        }
597
        return $chartNames;
598
    }
599
 
600
    /**
601
     * Get a chart by name
602
     *
603
     * @param string $chartName Chart name
604
     * @return false|PHPExcel_Chart
605
     * @throws PHPExcel_Exception
606
     */
607
    public function getChartByName($chartName = '')
608
    {
609
        $chartCount = count($this->_chartCollection);
610
        if ($chartCount == 0) {
611
            return false;
612
        }
613
        foreach($this->_chartCollection as $index => $chart) {
614
            if ($chart->getName() == $chartName) {
615
                return $this->_chartCollection[$index];
616
            }
617
        }
618
        return false;
619
    }
620
 
621
    /**
622
     * Refresh column dimensions
623
     *
624
     * @return PHPExcel_Worksheet
625
     */
626
    public function refreshColumnDimensions()
627
    {
628
        $currentColumnDimensions = $this->getColumnDimensions();
629
        $newColumnDimensions = array();
630
 
631
        foreach ($currentColumnDimensions as $objColumnDimension) {
632
            $newColumnDimensions[$objColumnDimension->getColumnIndex()] = $objColumnDimension;
633
        }
634
 
635
        $this->_columnDimensions = $newColumnDimensions;
636
 
637
        return $this;
638
    }
639
 
640
    /**
641
     * Refresh row dimensions
642
     *
643
     * @return PHPExcel_Worksheet
644
     */
645
    public function refreshRowDimensions()
646
    {
647
        $currentRowDimensions = $this->getRowDimensions();
648
        $newRowDimensions = array();
649
 
650
        foreach ($currentRowDimensions as $objRowDimension) {
651
            $newRowDimensions[$objRowDimension->getRowIndex()] = $objRowDimension;
652
        }
653
 
654
        $this->_rowDimensions = $newRowDimensions;
655
 
656
        return $this;
657
    }
658
 
659
    /**
660
     * Calculate worksheet dimension
661
     *
662
     * @return string  String containing the dimension of this worksheet
663
     */
664
    public function calculateWorksheetDimension()
665
    {
666
        // Return
667
        return 'A1' . ':' .  $this->getHighestColumn() . $this->getHighestRow();
668
    }
669
 
670
    /**
671
     * Calculate worksheet data dimension
672
     *
673
     * @return string  String containing the dimension of this worksheet that actually contain data
674
     */
675
    public function calculateWorksheetDataDimension()
676
    {
677
        // Return
678
        return 'A1' . ':' .  $this->getHighestDataColumn() . $this->getHighestDataRow();
679
    }
680
 
681
    /**
682
     * Calculate widths for auto-size columns
683
     *
684
     * @param  boolean  $calculateMergeCells  Calculate merge cell width
685
     * @return PHPExcel_Worksheet;
686
     */
687
    public function calculateColumnWidths($calculateMergeCells = false)
688
    {
689
        // initialize $autoSizes array
690
        $autoSizes = array();
691
        foreach ($this->getColumnDimensions() as $colDimension) {
692
            if ($colDimension->getAutoSize()) {
693
                $autoSizes[$colDimension->getColumnIndex()] = -1;
694
            }
695
        }
696
 
697
        // There is only something to do if there are some auto-size columns
698
        if (!empty($autoSizes)) {
699
 
700
            // build list of cells references that participate in a merge
701
            $isMergeCell = array();
702
            foreach ($this->getMergeCells() as $cells) {
703
                foreach (PHPExcel_Cell::extractAllCellReferencesInRange($cells) as $cellReference) {
704
                    $isMergeCell[$cellReference] = true;
705
                }
706
            }
707
 
708
            // loop through all cells in the worksheet
709
            foreach ($this->getCellCollection(false) as $cellID) {
710
                $cell = $this->getCell($cellID);
711
				if (isset($autoSizes[$this->_cellCollection->getCurrentColumn()])) {
712
                    // Determine width if cell does not participate in a merge
713
					if (!isset($isMergeCell[$this->_cellCollection->getCurrentAddress()])) {
714
                        // Calculated value
715
                        // To formatted string
716
						$cellValue = PHPExcel_Style_NumberFormat::toFormattedString(
717
							$cell->getCalculatedValue(),
718
							$this->getParent()->getCellXfByIndex($cell->getXfIndex())->getNumberFormat()->getFormatCode()
719
						);
720
 
721
						$autoSizes[$this->_cellCollection->getCurrentColumn()] = max(
722
							(float) $autoSizes[$this->_cellCollection->getCurrentColumn()],
723
                            (float)PHPExcel_Shared_Font::calculateColumnWidth(
724
								$this->getParent()->getCellXfByIndex($cell->getXfIndex())->getFont(),
725
                                $cellValue,
726
								$this->getParent()->getCellXfByIndex($cell->getXfIndex())->getAlignment()->getTextRotation(),
727
                                $this->getDefaultStyle()->getFont()
728
                            )
729
                        );
730
                    }
731
                }
732
            }
733
 
734
            // adjust column widths
735
            foreach ($autoSizes as $columnIndex => $width) {
736
                if ($width == -1) $width = $this->getDefaultColumnDimension()->getWidth();
737
                $this->getColumnDimension($columnIndex)->setWidth($width);
738
            }
739
        }
740
 
741
        return $this;
742
    }
743
 
744
    /**
745
     * Get parent
746
     *
747
     * @return PHPExcel
748
     */
749
	public function getParent() {
750
        return $this->_parent;
751
    }
752
 
753
    /**
754
     * Re-bind parent
755
     *
756
     * @param PHPExcel $parent
757
     * @return PHPExcel_Worksheet
758
     */
759
	public function rebindParent(PHPExcel $parent) {
760
        $namedRanges = $this->_parent->getNamedRanges();
761
        foreach ($namedRanges as $namedRange) {
762
            $parent->addNamedRange($namedRange);
763
        }
764
 
765
        $this->_parent->removeSheetByIndex(
766
            $this->_parent->getIndex($this)
767
        );
768
        $this->_parent = $parent;
769
 
770
        return $this;
771
    }
772
 
773
    /**
774
     * Get title
775
     *
776
     * @return string
777
     */
778
    public function getTitle()
779
    {
780
        return $this->_title;
781
    }
782
 
783
    /**
784
     * Set title
785
     *
786
     * @param string $pValue String containing the dimension of this worksheet
787
     * @param string $updateFormulaCellReferences boolean Flag indicating whether cell references in formulae should
788
     *        	be updated to reflect the new sheet name.
789
     *          This should be left as the default true, unless you are
790
     *          certain that no formula cells on any worksheet contain
791
     *          references to this worksheet
792
     * @return PHPExcel_Worksheet
793
     */
794
    public function setTitle($pValue = 'Worksheet', $updateFormulaCellReferences = true)
795
    {
796
        // Is this a 'rename' or not?
797
        if ($this->getTitle() == $pValue) {
798
            return $this;
799
        }
800
 
801
        // Syntax check
802
        self::_checkSheetTitle($pValue);
803
 
804
        // Old title
805
        $oldTitle = $this->getTitle();
806
 
807
        if ($this->_parent) {
808
            // Is there already such sheet name?
809
			if ($this->_parent->sheetNameExists($pValue)) {
810
                // Use name, but append with lowest possible integer
811
 
812
                if (PHPExcel_Shared_String::CountCharacters($pValue) > 29) {
813
                    $pValue = PHPExcel_Shared_String::Substring($pValue,0,29);
814
                }
815
                $i = 1;
816
				while ($this->_parent->sheetNameExists($pValue . ' ' . $i)) {
817
                    ++$i;
818
                    if ($i == 10) {
819
                        if (PHPExcel_Shared_String::CountCharacters($pValue) > 28) {
820
                            $pValue = PHPExcel_Shared_String::Substring($pValue,0,28);
821
                        }
822
                    } elseif ($i == 100) {
823
                        if (PHPExcel_Shared_String::CountCharacters($pValue) > 27) {
824
                            $pValue = PHPExcel_Shared_String::Substring($pValue,0,27);
825
                        }
826
                    }
827
                }
828
 
829
                $altTitle = $pValue . ' ' . $i;
830
                return $this->setTitle($altTitle,$updateFormulaCellReferences);
831
            }
832
        }
833
 
834
        // Set title
835
        $this->_title = $pValue;
836
        $this->_dirty = true;
837
 
838
        if ($this->_parent) {
839
            // New title
840
            $newTitle = $this->getTitle();
841
			PHPExcel_Calculation::getInstance($this->_parent)
842
			    ->renameCalculationCacheForWorksheet($oldTitle, $newTitle);
843
            if ($updateFormulaCellReferences)
844
				PHPExcel_ReferenceHelper::getInstance()->updateNamedFormulas($this->_parent, $oldTitle, $newTitle);
845
        }
846
 
847
        return $this;
848
    }
849
 
850
    /**
851
     * Get sheet state
852
     *
853
     * @return string Sheet state (visible, hidden, veryHidden)
854
     */
855
	public function getSheetState() {
856
        return $this->_sheetState;
857
    }
858
 
859
    /**
860
     * Set sheet state
861
     *
862
     * @param string $value Sheet state (visible, hidden, veryHidden)
863
     * @return PHPExcel_Worksheet
864
     */
865
	public function setSheetState($value = PHPExcel_Worksheet::SHEETSTATE_VISIBLE) {
866
        $this->_sheetState = $value;
867
        return $this;
868
    }
869
 
870
    /**
871
     * Get page setup
872
     *
873
     * @return PHPExcel_Worksheet_PageSetup
874
     */
875
    public function getPageSetup()
876
    {
877
        return $this->_pageSetup;
878
    }
879
 
880
    /**
881
     * Set page setup
882
     *
883
     * @param PHPExcel_Worksheet_PageSetup    $pValue
884
     * @return PHPExcel_Worksheet
885
     */
886
    public function setPageSetup(PHPExcel_Worksheet_PageSetup $pValue)
887
    {
888
        $this->_pageSetup = $pValue;
889
        return $this;
890
    }
891
 
892
    /**
893
     * Get page margins
894
     *
895
     * @return PHPExcel_Worksheet_PageMargins
896
     */
897
    public function getPageMargins()
898
    {
899
        return $this->_pageMargins;
900
    }
901
 
902
    /**
903
     * Set page margins
904
     *
905
     * @param PHPExcel_Worksheet_PageMargins    $pValue
906
     * @return PHPExcel_Worksheet
907
     */
908
    public function setPageMargins(PHPExcel_Worksheet_PageMargins $pValue)
909
    {
910
        $this->_pageMargins = $pValue;
911
        return $this;
912
    }
913
 
914
    /**
915
     * Get page header/footer
916
     *
917
     * @return PHPExcel_Worksheet_HeaderFooter
918
     */
919
    public function getHeaderFooter()
920
    {
921
        return $this->_headerFooter;
922
    }
923
 
924
    /**
925
     * Set page header/footer
926
     *
927
     * @param PHPExcel_Worksheet_HeaderFooter    $pValue
928
     * @return PHPExcel_Worksheet
929
     */
930
    public function setHeaderFooter(PHPExcel_Worksheet_HeaderFooter $pValue)
931
    {
932
        $this->_headerFooter = $pValue;
933
        return $this;
934
    }
935
 
936
    /**
937
     * Get sheet view
938
     *
939
     * @return PHPExcel_Worksheet_SheetView
940
     */
941
    public function getSheetView()
942
    {
943
        return $this->_sheetView;
944
    }
945
 
946
    /**
947
     * Set sheet view
948
     *
949
     * @param PHPExcel_Worksheet_SheetView    $pValue
950
     * @return PHPExcel_Worksheet
951
     */
952
    public function setSheetView(PHPExcel_Worksheet_SheetView $pValue)
953
    {
954
        $this->_sheetView = $pValue;
955
        return $this;
956
    }
957
 
958
    /**
959
     * Get Protection
960
     *
961
     * @return PHPExcel_Worksheet_Protection
962
     */
963
    public function getProtection()
964
    {
965
        return $this->_protection;
966
    }
967
 
968
    /**
969
     * Set Protection
970
     *
971
     * @param PHPExcel_Worksheet_Protection    $pValue
972
     * @return PHPExcel_Worksheet
973
     */
974
    public function setProtection(PHPExcel_Worksheet_Protection $pValue)
975
    {
976
        $this->_protection = $pValue;
977
        $this->_dirty = true;
978
 
979
        return $this;
980
    }
981
 
982
    /**
983
     * Get highest worksheet column
984
     *
985
     * @return string Highest column name
986
     */
987
    public function getHighestColumn()
988
    {
989
        return $this->_cachedHighestColumn;
990
    }
991
 
992
    /**
993
     * Get highest worksheet column that contains data
994
     *
995
     * @return string Highest column name that contains data
996
     */
997
    public function getHighestDataColumn()
998
    {
999
        return $this->_cellCollection->getHighestColumn();
1000
    }
1001
 
1002
    /**
1003
     * Get highest worksheet row
1004
     *
1005
     * @return int Highest row number
1006
     */
1007
    public function getHighestRow()
1008
    {
1009
        return $this->_cachedHighestRow;
1010
    }
1011
 
1012
    /**
1013
     * Get highest worksheet row that contains data
1014
     *
1015
     * @return string Highest row number that contains data
1016
     */
1017
    public function getHighestDataRow()
1018
    {
1019
        return $this->_cellCollection->getHighestRow();
1020
    }
1021
 
1022
    /**
1023
     * Get highest worksheet column and highest row that have cell records
1024
     *
1025
     * @return array Highest column name and highest row number
1026
     */
1027
    public function getHighestRowAndColumn()
1028
    {
1029
        return $this->_cellCollection->getHighestRowAndColumn();
1030
    }
1031
 
1032
    /**
1033
     * Set a cell value
1034
     *
1035
     * @param string $pCoordinate Coordinate of the cell
1036
     * @param mixed $pValue Value of the cell
1037
     * @param bool $returnCell   Return the worksheet (false, default) or the cell (true)
1038
     * @return PHPExcel_Worksheet|PHPExcel_Cell    Depending on the last parameter being specified
1039
     */
1040
    public function setCellValue($pCoordinate = 'A1', $pValue = null, $returnCell = false)
1041
    {
1042
        $cell = $this->getCell($pCoordinate)->setValue($pValue);
1043
        return ($returnCell) ? $cell : $this;
1044
    }
1045
 
1046
    /**
1047
     * Set a cell value by using numeric cell coordinates
1048
     *
1049
     * @param string $pColumn Numeric column coordinate of the cell (A = 0)
1050
     * @param string $pRow Numeric row coordinate of the cell
1051
     * @param mixed $pValue Value of the cell
1052
     * @param bool $returnCell Return the worksheet (false, default) or the cell (true)
1053
     * @return PHPExcel_Worksheet|PHPExcel_Cell    Depending on the last parameter being specified
1054
     */
1055
    public function setCellValueByColumnAndRow($pColumn = 0, $pRow = 1, $pValue = null, $returnCell = false)
1056
    {
1057
        $cell = $this->getCell(PHPExcel_Cell::stringFromColumnIndex($pColumn) . $pRow)->setValue($pValue);
1058
        return ($returnCell) ? $cell : $this;
1059
    }
1060
 
1061
    /**
1062
     * Set a cell value
1063
     *
1064
     * @param string $pCoordinate Coordinate of the cell
1065
     * @param mixed  $pValue Value of the cell
1066
     * @param string $pDataType Explicit data type
1067
     * @param bool $returnCell Return the worksheet (false, default) or the cell (true)
1068
     * @return PHPExcel_Worksheet|PHPExcel_Cell    Depending on the last parameter being specified
1069
     */
1070
    public function setCellValueExplicit($pCoordinate = 'A1', $pValue = null, $pDataType = PHPExcel_Cell_DataType::TYPE_STRING, $returnCell = false)
1071
    {
1072
        // Set value
1073
        $cell = $this->getCell($pCoordinate)->setValueExplicit($pValue, $pDataType);
1074
        return ($returnCell) ? $cell : $this;
1075
    }
1076
 
1077
    /**
1078
     * Set a cell value by using numeric cell coordinates
1079
     *
1080
     * @param string $pColumn Numeric column coordinate of the cell
1081
     * @param string $pRow Numeric row coordinate of the cell
1082
     * @param mixed $pValue Value of the cell
1083
     * @param string $pDataType Explicit data type
1084
     * @param bool $returnCell Return the worksheet (false, default) or the cell (true)
1085
     * @return PHPExcel_Worksheet|PHPExcel_Cell    Depending on the last parameter being specified
1086
     */
1087
    public function setCellValueExplicitByColumnAndRow($pColumn = 0, $pRow = 1, $pValue = null, $pDataType = PHPExcel_Cell_DataType::TYPE_STRING, $returnCell = false)
1088
    {
1089
        $cell = $this->getCell(PHPExcel_Cell::stringFromColumnIndex($pColumn) . $pRow)->setValueExplicit($pValue, $pDataType);
1090
        return ($returnCell) ? $cell : $this;
1091
    }
1092
 
1093
    /**
1094
     * Get cell at a specific coordinate
1095
     *
1096
     * @param string $pCoordinate    Coordinate of the cell
1097
     * @throws PHPExcel_Exception
1098
     * @return PHPExcel_Cell Cell that was found
1099
     */
1100
    public function getCell($pCoordinate = 'A1')
1101
    {
1102
        // Check cell collection
1103
        if ($this->_cellCollection->isDataSet($pCoordinate)) {
1104
            return $this->_cellCollection->getCacheData($pCoordinate);
1105
        }
1106
 
1107
        // Worksheet reference?
1108
        if (strpos($pCoordinate, '!') !== false) {
1109
            $worksheetReference = PHPExcel_Worksheet::extractSheetTitle($pCoordinate, true);
1110
			return $this->_parent->getSheetByName($worksheetReference[0])->getCell($worksheetReference[1]);
1111
        }
1112
 
1113
        // Named range?
1114
        if ((!preg_match('/^'.PHPExcel_Calculation::CALCULATION_REGEXP_CELLREF.'$/i', $pCoordinate, $matches)) &&
1115
            (preg_match('/^'.PHPExcel_Calculation::CALCULATION_REGEXP_NAMEDRANGE.'$/i', $pCoordinate, $matches))) {
1116
            $namedRange = PHPExcel_NamedRange::resolveRange($pCoordinate, $this);
1117
            if ($namedRange !== NULL) {
1118
                $pCoordinate = $namedRange->getRange();
1119
                return $namedRange->getWorksheet()->getCell($pCoordinate);
1120
            }
1121
        }
1122
 
1123
        // Uppercase coordinate
1124
        $pCoordinate = strtoupper($pCoordinate);
1125
 
1126
        if (strpos($pCoordinate,':') !== false || strpos($pCoordinate,',') !== false) {
1127
            throw new PHPExcel_Exception('Cell coordinate can not be a range of cells.');
1128
        } elseif (strpos($pCoordinate,'$') !== false) {
1129
            throw new PHPExcel_Exception('Cell coordinate must not be absolute.');
1130
        } else {
1131
            // Create new cell object
1132
 
1133
            // Coordinates
1134
            $aCoordinates = PHPExcel_Cell::coordinateFromString($pCoordinate);
1135
 
1136
			$cell = $this->_cellCollection->addCacheData($pCoordinate,new PHPExcel_Cell(NULL, PHPExcel_Cell_DataType::TYPE_NULL, $this));
1137
            $this->_cellCollectionIsSorted = false;
1138
 
1139
            if (PHPExcel_Cell::columnIndexFromString($this->_cachedHighestColumn) < PHPExcel_Cell::columnIndexFromString($aCoordinates[0]))
1140
                $this->_cachedHighestColumn = $aCoordinates[0];
1141
 
1142
            $this->_cachedHighestRow = max($this->_cachedHighestRow,$aCoordinates[1]);
1143
 
1144
            // Cell needs appropriate xfIndex
1145
            $rowDimensions    = $this->getRowDimensions();
1146
            $columnDimensions = $this->getColumnDimensions();
1147
 
1148
            if ( isset($rowDimensions[$aCoordinates[1]]) && $rowDimensions[$aCoordinates[1]]->getXfIndex() !== null ) {
1149
                // then there is a row dimension with explicit style, assign it to the cell
1150
                $cell->setXfIndex($rowDimensions[$aCoordinates[1]]->getXfIndex());
1151
            } else if ( isset($columnDimensions[$aCoordinates[0]]) ) {
1152
                // then there is a column dimension, assign it to the cell
1153
                $cell->setXfIndex($columnDimensions[$aCoordinates[0]]->getXfIndex());
1154
            } else {
1155
                // set to default index
1156
                $cell->setXfIndex(0);
1157
            }
1158
 
1159
            return $cell;
1160
        }
1161
    }
1162
 
1163
    /**
1164
     * Get cell at a specific coordinate by using numeric cell coordinates
1165
     *
1166
     * @param  string $pColumn Numeric column coordinate of the cell
1167
     * @param string $pRow Numeric row coordinate of the cell
1168
     * @return PHPExcel_Cell Cell that was found
1169
     */
1170
    public function getCellByColumnAndRow($pColumn = 0, $pRow = 1)
1171
    {
1172
        $columnLetter = PHPExcel_Cell::stringFromColumnIndex($pColumn);
1173
        $coordinate = $columnLetter . $pRow;
1174
 
1175
        if (!$this->_cellCollection->isDataSet($coordinate)) {
1176
            $cell = $this->_cellCollection->addCacheData($coordinate, new PHPExcel_Cell(NULL, PHPExcel_Cell_DataType::TYPE_NULL, $this));
1177
            $this->_cellCollectionIsSorted = false;
1178
 
1179
            if (PHPExcel_Cell::columnIndexFromString($this->_cachedHighestColumn) < $pColumn)
1180
                $this->_cachedHighestColumn = $columnLetter;
1181
 
1182
            $this->_cachedHighestRow = max($this->_cachedHighestRow,$pRow);
1183
 
1184
            return $cell;
1185
        }
1186
 
1187
        return $this->_cellCollection->getCacheData($coordinate);
1188
    }
1189
 
1190
    /**
1191
     * Cell at a specific coordinate exists?
1192
     *
1193
     * @param string $pCoordinate  Coordinate of the cell
1194
     * @throws PHPExcel_Exception
1195
     * @return boolean
1196
     */
1197
    public function cellExists($pCoordinate = 'A1')
1198
    {
1199
        // Worksheet reference?
1200
        if (strpos($pCoordinate, '!') !== false) {
1201
            $worksheetReference = PHPExcel_Worksheet::extractSheetTitle($pCoordinate, true);
1202
			return $this->_parent->getSheetByName($worksheetReference[0])->cellExists($worksheetReference[1]);
1203
        }
1204
 
1205
        // Named range?
1206
        if ((!preg_match('/^'.PHPExcel_Calculation::CALCULATION_REGEXP_CELLREF.'$/i', $pCoordinate, $matches)) &&
1207
            (preg_match('/^'.PHPExcel_Calculation::CALCULATION_REGEXP_NAMEDRANGE.'$/i', $pCoordinate, $matches))) {
1208
            $namedRange = PHPExcel_NamedRange::resolveRange($pCoordinate, $this);
1209
            if ($namedRange !== NULL) {
1210
                $pCoordinate = $namedRange->getRange();
1211
                if ($this->getHashCode() != $namedRange->getWorksheet()->getHashCode()) {
1212
                    if (!$namedRange->getLocalOnly()) {
1213
                        return $namedRange->getWorksheet()->cellExists($pCoordinate);
1214
                    } else {
1215
                        throw new PHPExcel_Exception('Named range ' . $namedRange->getName() . ' is not accessible from within sheet ' . $this->getTitle());
1216
                    }
1217
                }
1218
            }
1219
            else { return false; }
1220
        }
1221
 
1222
        // Uppercase coordinate
1223
        $pCoordinate = strtoupper($pCoordinate);
1224
 
1225
        if (strpos($pCoordinate,':') !== false || strpos($pCoordinate,',') !== false) {
1226
            throw new PHPExcel_Exception('Cell coordinate can not be a range of cells.');
1227
        } elseif (strpos($pCoordinate,'$') !== false) {
1228
            throw new PHPExcel_Exception('Cell coordinate must not be absolute.');
1229
        } else {
1230
            // Coordinates
1231
            $aCoordinates = PHPExcel_Cell::coordinateFromString($pCoordinate);
1232
 
1233
            // Cell exists?
1234
            return $this->_cellCollection->isDataSet($pCoordinate);
1235
        }
1236
    }
1237
 
1238
    /**
1239
     * Cell at a specific coordinate by using numeric cell coordinates exists?
1240
     *
1241
     * @param string $pColumn Numeric column coordinate of the cell
1242
     * @param string $pRow Numeric row coordinate of the cell
1243
     * @return boolean
1244
     */
1245
    public function cellExistsByColumnAndRow($pColumn = 0, $pRow = 1)
1246
    {
1247
        return $this->cellExists(PHPExcel_Cell::stringFromColumnIndex($pColumn) . $pRow);
1248
    }
1249
 
1250
    /**
1251
     * Get row dimension at a specific row
1252
     *
1253
     * @param int $pRow Numeric index of the row
1254
     * @return PHPExcel_Worksheet_RowDimension
1255
     */
1256
    public function getRowDimension($pRow = 1)
1257
    {
1258
        // Found
1259
        $found = null;
1260
 
1261
        // Get row dimension
1262
        if (!isset($this->_rowDimensions[$pRow])) {
1263
            $this->_rowDimensions[$pRow] = new PHPExcel_Worksheet_RowDimension($pRow);
1264
 
1265
            $this->_cachedHighestRow = max($this->_cachedHighestRow,$pRow);
1266
        }
1267
        return $this->_rowDimensions[$pRow];
1268
    }
1269
 
1270
    /**
1271
     * Get column dimension at a specific column
1272
     *
1273
     * @param string $pColumn String index of the column
1274
     * @return PHPExcel_Worksheet_ColumnDimension
1275
     */
1276
    public function getColumnDimension($pColumn = 'A')
1277
    {
1278
        // Uppercase coordinate
1279
        $pColumn = strtoupper($pColumn);
1280
 
1281
        // Fetch dimensions
1282
        if (!isset($this->_columnDimensions[$pColumn])) {
1283
            $this->_columnDimensions[$pColumn] = new PHPExcel_Worksheet_ColumnDimension($pColumn);
1284
 
1285
            if (PHPExcel_Cell::columnIndexFromString($this->_cachedHighestColumn) < PHPExcel_Cell::columnIndexFromString($pColumn))
1286
                $this->_cachedHighestColumn = $pColumn;
1287
        }
1288
        return $this->_columnDimensions[$pColumn];
1289
    }
1290
 
1291
    /**
1292
     * Get column dimension at a specific column by using numeric cell coordinates
1293
     *
1294
     * @param string $pColumn Numeric column coordinate of the cell
1295
     * @return PHPExcel_Worksheet_ColumnDimension
1296
     */
1297
    public function getColumnDimensionByColumn($pColumn = 0)
1298
    {
1299
        return $this->getColumnDimension(PHPExcel_Cell::stringFromColumnIndex($pColumn));
1300
    }
1301
 
1302
    /**
1303
     * Get styles
1304
     *
1305
     * @return PHPExcel_Style[]
1306
     */
1307
    public function getStyles()
1308
    {
1309
        return $this->_styles;
1310
    }
1311
 
1312
    /**
1313
     * Get default style of workbook.
1314
     *
1315
     * @deprecated
1316
     * @return PHPExcel_Style
1317
     * @throws PHPExcel_Exception
1318
     */
1319
    public function getDefaultStyle()
1320
    {
1321
        return $this->_parent->getDefaultStyle();
1322
    }
1323
 
1324
    /**
1325
     * Set default style - should only be used by PHPExcel_IReader implementations!
1326
     *
1327
     * @deprecated
1328
     * @param PHPExcel_Style $pValue
1329
     * @throws PHPExcel_Exception
1330
     * @return PHPExcel_Worksheet
1331
     */
1332
    public function setDefaultStyle(PHPExcel_Style $pValue)
1333
    {
1334
        $this->_parent->getDefaultStyle()->applyFromArray(array(
1335
            'font' => array(
1336
                'name' => $pValue->getFont()->getName(),
1337
                'size' => $pValue->getFont()->getSize(),
1338
            ),
1339
        ));
1340
        return $this;
1341
    }
1342
 
1343
    /**
1344
     * Get style for cell
1345
     *
1346
     * @param string $pCellCoordinate Cell coordinate to get style for
1347
     * @return PHPExcel_Style
1348
     * @throws PHPExcel_Exception
1349
     */
1350
    public function getStyle($pCellCoordinate = 'A1')
1351
    {
1352
        // set this sheet as active
1353
        $this->_parent->setActiveSheetIndex($this->_parent->getIndex($this));
1354
 
1355
        // set cell coordinate as active
1356
        $this->setSelectedCells($pCellCoordinate);
1357
 
1358
        return $this->_parent->getCellXfSupervisor();
1359
    }
1360
 
1361
    /**
1362
     * Get conditional styles for a cell
1363
     *
1364
     * @param string $pCoordinate
1365
     * @return PHPExcel_Style_Conditional[]
1366
     */
1367
    public function getConditionalStyles($pCoordinate = 'A1')
1368
    {
1369
        if (!isset($this->_conditionalStylesCollection[$pCoordinate])) {
1370
            $this->_conditionalStylesCollection[$pCoordinate] = array();
1371
        }
1372
        return $this->_conditionalStylesCollection[$pCoordinate];
1373
    }
1374
 
1375
    /**
1376
     * Do conditional styles exist for this cell?
1377
     *
1378
     * @param string $pCoordinate
1379
     * @return boolean
1380
     */
1381
    public function conditionalStylesExists($pCoordinate = 'A1')
1382
    {
1383
        if (isset($this->_conditionalStylesCollection[$pCoordinate])) {
1384
            return true;
1385
        }
1386
        return false;
1387
    }
1388
 
1389
    /**
1390
     * Removes conditional styles for a cell
1391
     *
1392
     * @param string $pCoordinate
1393
     * @return PHPExcel_Worksheet
1394
     */
1395
    public function removeConditionalStyles($pCoordinate = 'A1')
1396
    {
1397
        unset($this->_conditionalStylesCollection[$pCoordinate]);
1398
        return $this;
1399
    }
1400
 
1401
    /**
1402
     * Get collection of conditional styles
1403
     *
1404
     * @return array
1405
     */
1406
    public function getConditionalStylesCollection()
1407
    {
1408
        return $this->_conditionalStylesCollection;
1409
    }
1410
 
1411
    /**
1412
     * Set conditional styles
1413
     *
1414
     * @param $pCoordinate string E.g. 'A1'
1415
     * @param $pValue PHPExcel_Style_Conditional[]
1416
     * @return PHPExcel_Worksheet
1417
     */
1418
    public function setConditionalStyles($pCoordinate = 'A1', $pValue)
1419
    {
1420
        $this->_conditionalStylesCollection[$pCoordinate] = $pValue;
1421
        return $this;
1422
    }
1423
 
1424
    /**
1425
     * Get style for cell by using numeric cell coordinates
1426
     *
1427
     * @param int $pColumn  Numeric column coordinate of the cell
1428
     * @param int $pRow Numeric row coordinate of the cell
1429
     * @return PHPExcel_Style
1430
     */
1431
    public function getStyleByColumnAndRow($pColumn = 0, $pRow = 1)
1432
    {
1433
        return $this->getStyle(PHPExcel_Cell::stringFromColumnIndex($pColumn) . $pRow);
1434
    }
1435
 
1436
    /**
1437
     * Set shared cell style to a range of cells
1438
     *
1439
     * Please note that this will overwrite existing cell styles for cells in range!
1440
     *
1441
     * @deprecated
1442
     * @param PHPExcel_Style $pSharedCellStyle Cell style to share
1443
     * @param string $pRange Range of cells (i.e. "A1:B10"), or just one cell (i.e. "A1")
1444
     * @throws PHPExcel_Exception
1445
     * @return PHPExcel_Worksheet
1446
     */
1447
    public function setSharedStyle(PHPExcel_Style $pSharedCellStyle = null, $pRange = '')
1448
    {
1449
        $this->duplicateStyle($pSharedCellStyle, $pRange);
1450
        return $this;
1451
    }
1452
 
1453
    /**
1454
     * Duplicate cell style to a range of cells
1455
     *
1456
     * Please note that this will overwrite existing cell styles for cells in range!
1457
     *
1458
     * @param PHPExcel_Style $pCellStyle Cell style to duplicate
1459
     * @param string $pRange Range of cells (i.e. "A1:B10"), or just one cell (i.e. "A1")
1460
     * @throws PHPExcel_Exception
1461
     * @return PHPExcel_Worksheet
1462
     */
1463
    public function duplicateStyle(PHPExcel_Style $pCellStyle = null, $pRange = '')
1464
    {
1465
        // make sure we have a real style and not supervisor
1466
        $style = $pCellStyle->getIsSupervisor() ? $pCellStyle->getSharedComponent() : $pCellStyle;
1467
 
1468
        // Add the style to the workbook if necessary
1469
        $workbook = $this->_parent;
1470
        if ($this->_parent->cellXfExists($pCellStyle)) {
1471
            // there is already this cell Xf in our collection
1472
            $xfIndex = $pCellStyle->getIndex();
1473
        } else {
1474
            // we don't have such a cell Xf, need to add
1475
            $workbook->addCellXf($pCellStyle);
1476
            $xfIndex = $pCellStyle->getIndex();
1477
        }
1478
 
1479
        // Uppercase coordinate
1480
        $pRange = strtoupper($pRange);
1481
 
1482
        // Is it a cell range or a single cell?
1483
        $rangeA    = '';
1484
        $rangeB    = '';
1485
        if (strpos($pRange, ':') === false) {
1486
            $rangeA = $pRange;
1487
            $rangeB = $pRange;
1488
        } else {
1489
            list($rangeA, $rangeB) = explode(':', $pRange);
1490
        }
1491
 
1492
        // Calculate range outer borders
1493
        $rangeStart = PHPExcel_Cell::coordinateFromString($rangeA);
1494
        $rangeEnd    = PHPExcel_Cell::coordinateFromString($rangeB);
1495
 
1496
        // Translate column into index
1497
        $rangeStart[0]    = PHPExcel_Cell::columnIndexFromString($rangeStart[0]) - 1;
1498
        $rangeEnd[0]    = PHPExcel_Cell::columnIndexFromString($rangeEnd[0]) - 1;
1499
 
1500
        // Make sure we can loop upwards on rows and columns
1501
        if ($rangeStart[0] > $rangeEnd[0] && $rangeStart[1] > $rangeEnd[1]) {
1502
            $tmp = $rangeStart;
1503
            $rangeStart = $rangeEnd;
1504
            $rangeEnd = $tmp;
1505
        }
1506
 
1507
        // Loop through cells and apply styles
1508
        for ($col = $rangeStart[0]; $col <= $rangeEnd[0]; ++$col) {
1509
            for ($row = $rangeStart[1]; $row <= $rangeEnd[1]; ++$row) {
1510
                $this->getCell(PHPExcel_Cell::stringFromColumnIndex($col) . $row)->setXfIndex($xfIndex);
1511
            }
1512
        }
1513
 
1514
        return $this;
1515
    }
1516
 
1517
    /**
1518
     * Duplicate conditional style to a range of cells
1519
     *
1520
     * Please note that this will overwrite existing cell styles for cells in range!
1521
     *
1522
	 * @param	array of PHPExcel_Style_Conditional	$pCellStyle	Cell style to duplicate
1523
     * @param string $pRange Range of cells (i.e. "A1:B10"), or just one cell (i.e. "A1")
1524
     * @throws PHPExcel_Exception
1525
     * @return PHPExcel_Worksheet
1526
     */
1527
    public function duplicateConditionalStyle(array $pCellStyle = null, $pRange = '')
1528
    {
1529
        foreach($pCellStyle as $cellStyle) {
1530
            if (!($cellStyle instanceof PHPExcel_Style_Conditional)) {
1531
                throw new PHPExcel_Exception('Style is not a conditional style');
1532
            }
1533
        }
1534
 
1535
        // Uppercase coordinate
1536
        $pRange = strtoupper($pRange);
1537
 
1538
        // Is it a cell range or a single cell?
1539
        $rangeA    = '';
1540
        $rangeB    = '';
1541
        if (strpos($pRange, ':') === false) {
1542
            $rangeA = $pRange;
1543
            $rangeB = $pRange;
1544
        } else {
1545
            list($rangeA, $rangeB) = explode(':', $pRange);
1546
        }
1547
 
1548
        // Calculate range outer borders
1549
        $rangeStart = PHPExcel_Cell::coordinateFromString($rangeA);
1550
        $rangeEnd    = PHPExcel_Cell::coordinateFromString($rangeB);
1551
 
1552
        // Translate column into index
1553
        $rangeStart[0]    = PHPExcel_Cell::columnIndexFromString($rangeStart[0]) - 1;
1554
        $rangeEnd[0]    = PHPExcel_Cell::columnIndexFromString($rangeEnd[0]) - 1;
1555
 
1556
        // Make sure we can loop upwards on rows and columns
1557
        if ($rangeStart[0] > $rangeEnd[0] && $rangeStart[1] > $rangeEnd[1]) {
1558
            $tmp = $rangeStart;
1559
            $rangeStart = $rangeEnd;
1560
            $rangeEnd = $tmp;
1561
        }
1562
 
1563
        // Loop through cells and apply styles
1564
        for ($col = $rangeStart[0]; $col <= $rangeEnd[0]; ++$col) {
1565
            for ($row = $rangeStart[1]; $row <= $rangeEnd[1]; ++$row) {
1566
                $this->setConditionalStyles(PHPExcel_Cell::stringFromColumnIndex($col) . $row, $pCellStyle);
1567
            }
1568
        }
1569
 
1570
        return $this;
1571
    }
1572
 
1573
    /**
1574
     * Duplicate cell style array to a range of cells
1575
     *
1576
     * Please note that this will overwrite existing cell styles for cells in range,
1577
     * if they are in the styles array. For example, if you decide to set a range of
1578
     * cells to font bold, only include font bold in the styles array.
1579
     *
1580
     * @deprecated
1581
     * @param array $pStyles Array containing style information
1582
     * @param string $pRange Range of cells (i.e. "A1:B10"), or just one cell (i.e. "A1")
1583
     * @param boolean $pAdvanced Advanced mode for setting borders.
1584
     * @throws PHPExcel_Exception
1585
     * @return PHPExcel_Worksheet
1586
     */
1587
    public function duplicateStyleArray($pStyles = null, $pRange = '', $pAdvanced = true)
1588
    {
1589
        $this->getStyle($pRange)->applyFromArray($pStyles, $pAdvanced);
1590
        return $this;
1591
    }
1592
 
1593
    /**
1594
     * Set break on a cell
1595
     *
1596
     * @param string $pCell Cell coordinate (e.g. A1)
1597
     * @param int $pBreak Break type (type of PHPExcel_Worksheet::BREAK_*)
1598
     * @throws PHPExcel_Exception
1599
     * @return PHPExcel_Worksheet
1600
     */
1601
    public function setBreak($pCell = 'A1', $pBreak = PHPExcel_Worksheet::BREAK_NONE)
1602
    {
1603
        // Uppercase coordinate
1604
        $pCell = strtoupper($pCell);
1605
 
1606
        if ($pCell != '') {
1607
        	if ($pBreak == PHPExcel_Worksheet::BREAK_NONE) {
1608
        		if (isset($this->_breaks[$pCell])) {
1609
	            	unset($this->_breaks[$pCell]);
1610
        		}
1611
        	} else {
1612
	            $this->_breaks[$pCell] = $pBreak;
1613
	        }
1614
        } else {
1615
            throw new PHPExcel_Exception('No cell coordinate specified.');
1616
        }
1617
 
1618
        return $this;
1619
    }
1620
 
1621
    /**
1622
     * Set break on a cell by using numeric cell coordinates
1623
     *
1624
     * @param integer $pColumn Numeric column coordinate of the cell
1625
     * @param integer $pRow Numeric row coordinate of the cell
1626
     * @param  integer $pBreak Break type (type of PHPExcel_Worksheet::BREAK_*)
1627
     * @return PHPExcel_Worksheet
1628
     */
1629
    public function setBreakByColumnAndRow($pColumn = 0, $pRow = 1, $pBreak = PHPExcel_Worksheet::BREAK_NONE)
1630
    {
1631
        return $this->setBreak(PHPExcel_Cell::stringFromColumnIndex($pColumn) . $pRow, $pBreak);
1632
    }
1633
 
1634
    /**
1635
     * Get breaks
1636
     *
1637
     * @return array[]
1638
     */
1639
    public function getBreaks()
1640
    {
1641
        return $this->_breaks;
1642
    }
1643
 
1644
    /**
1645
     * Set merge on a cell range
1646
     *
1647
     * @param string $pRange  Cell range (e.g. A1:E1)
1648
     * @throws PHPExcel_Exception
1649
     * @return PHPExcel_Worksheet
1650
     */
1651
    public function mergeCells($pRange = 'A1:A1')
1652
    {
1653
        // Uppercase coordinate
1654
        $pRange = strtoupper($pRange);
1655
 
1656
        if (strpos($pRange,':') !== false) {
1657
            $this->_mergeCells[$pRange] = $pRange;
1658
 
1659
            // make sure cells are created
1660
 
1661
            // get the cells in the range
1662
            $aReferences = PHPExcel_Cell::extractAllCellReferencesInRange($pRange);
1663
 
1664
            // create upper left cell if it does not already exist
1665
            $upperLeft = $aReferences[0];
1666
            if (!$this->cellExists($upperLeft)) {
1667
                $this->getCell($upperLeft)->setValueExplicit(null, PHPExcel_Cell_DataType::TYPE_NULL);
1668
            }
1669
 
1670
            // create or blank out the rest of the cells in the range
1671
            $count = count($aReferences);
1672
            for ($i = 1; $i < $count; $i++) {
1673
                $this->getCell($aReferences[$i])->setValueExplicit(null, PHPExcel_Cell_DataType::TYPE_NULL);
1674
            }
1675
 
1676
        } else {
1677
            throw new PHPExcel_Exception('Merge must be set on a range of cells.');
1678
        }
1679
 
1680
        return $this;
1681
    }
1682
 
1683
    /**
1684
     * Set merge on a cell range by using numeric cell coordinates
1685
     *
1686
     * @param int $pColumn1    Numeric column coordinate of the first cell
1687
     * @param int $pRow1        Numeric row coordinate of the first cell
1688
     * @param int $pColumn2    Numeric column coordinate of the last cell
1689
     * @param int $pRow2        Numeric row coordinate of the last cell
1690
     * @throws    PHPExcel_Exception
1691
     * @return PHPExcel_Worksheet
1692
     */
1693
    public function mergeCellsByColumnAndRow($pColumn1 = 0, $pRow1 = 1, $pColumn2 = 0, $pRow2 = 1)
1694
    {
1695
        $cellRange = PHPExcel_Cell::stringFromColumnIndex($pColumn1) . $pRow1 . ':' . PHPExcel_Cell::stringFromColumnIndex($pColumn2) . $pRow2;
1696
        return $this->mergeCells($cellRange);
1697
    }
1698
 
1699
    /**
1700
     * Remove merge on a cell range
1701
     *
1702
     * @param    string            $pRange        Cell range (e.g. A1:E1)
1703
     * @throws    PHPExcel_Exception
1704
     * @return PHPExcel_Worksheet
1705
     */
1706
    public function unmergeCells($pRange = 'A1:A1')
1707
    {
1708
        // Uppercase coordinate
1709
        $pRange = strtoupper($pRange);
1710
 
1711
        if (strpos($pRange,':') !== false) {
1712
            if (isset($this->_mergeCells[$pRange])) {
1713
                unset($this->_mergeCells[$pRange]);
1714
            } else {
1715
                throw new PHPExcel_Exception('Cell range ' . $pRange . ' not known as merged.');
1716
            }
1717
        } else {
1718
            throw new PHPExcel_Exception('Merge can only be removed from a range of cells.');
1719
        }
1720
 
1721
        return $this;
1722
    }
1723
 
1724
    /**
1725
     * Remove merge on a cell range by using numeric cell coordinates
1726
     *
1727
     * @param int $pColumn1    Numeric column coordinate of the first cell
1728
     * @param int $pRow1        Numeric row coordinate of the first cell
1729
     * @param int $pColumn2    Numeric column coordinate of the last cell
1730
     * @param int $pRow2        Numeric row coordinate of the last cell
1731
     * @throws    PHPExcel_Exception
1732
     * @return PHPExcel_Worksheet
1733
     */
1734
    public function unmergeCellsByColumnAndRow($pColumn1 = 0, $pRow1 = 1, $pColumn2 = 0, $pRow2 = 1)
1735
    {
1736
        $cellRange = PHPExcel_Cell::stringFromColumnIndex($pColumn1) . $pRow1 . ':' . PHPExcel_Cell::stringFromColumnIndex($pColumn2) . $pRow2;
1737
        return $this->unmergeCells($cellRange);
1738
    }
1739
 
1740
    /**
1741
     * Get merge cells array.
1742
     *
1743
     * @return array[]
1744
     */
1745
    public function getMergeCells()
1746
    {
1747
        return $this->_mergeCells;
1748
    }
1749
 
1750
    /**
1751
     * Set merge cells array for the entire sheet. Use instead mergeCells() to merge
1752
     * a single cell range.
1753
     *
1754
     * @param array
1755
     */
1756
    public function setMergeCells($pValue = array())
1757
    {
1758
        $this->_mergeCells = $pValue;
1759
 
1760
        return $this;
1761
    }
1762
 
1763
    /**
1764
     * Set protection on a cell range
1765
     *
1766
     * @param    string            $pRange                Cell (e.g. A1) or cell range (e.g. A1:E1)
1767
     * @param    string            $pPassword            Password to unlock the protection
1768
     * @param    boolean        $pAlreadyHashed    If the password has already been hashed, set this to true
1769
     * @throws    PHPExcel_Exception
1770
     * @return PHPExcel_Worksheet
1771
     */
1772
    public function protectCells($pRange = 'A1', $pPassword = '', $pAlreadyHashed = false)
1773
    {
1774
        // Uppercase coordinate
1775
        $pRange = strtoupper($pRange);
1776
 
1777
        if (!$pAlreadyHashed) {
1778
            $pPassword = PHPExcel_Shared_PasswordHasher::hashPassword($pPassword);
1779
        }
1780
        $this->_protectedCells[$pRange] = $pPassword;
1781
 
1782
        return $this;
1783
    }
1784
 
1785
    /**
1786
     * Set protection on a cell range by using numeric cell coordinates
1787
     *
1788
     * @param int  $pColumn1            Numeric column coordinate of the first cell
1789
     * @param int  $pRow1                Numeric row coordinate of the first cell
1790
     * @param int  $pColumn2            Numeric column coordinate of the last cell
1791
     * @param int  $pRow2                Numeric row coordinate of the last cell
1792
     * @param string $pPassword            Password to unlock the protection
1793
     * @param    boolean $pAlreadyHashed    If the password has already been hashed, set this to true
1794
     * @throws    PHPExcel_Exception
1795
     * @return PHPExcel_Worksheet
1796
     */
1797
    public function protectCellsByColumnAndRow($pColumn1 = 0, $pRow1 = 1, $pColumn2 = 0, $pRow2 = 1, $pPassword = '', $pAlreadyHashed = false)
1798
    {
1799
        $cellRange = PHPExcel_Cell::stringFromColumnIndex($pColumn1) . $pRow1 . ':' . PHPExcel_Cell::stringFromColumnIndex($pColumn2) . $pRow2;
1800
        return $this->protectCells($cellRange, $pPassword, $pAlreadyHashed);
1801
    }
1802
 
1803
    /**
1804
     * Remove protection on a cell range
1805
     *
1806
     * @param    string            $pRange        Cell (e.g. A1) or cell range (e.g. A1:E1)
1807
     * @throws    PHPExcel_Exception
1808
     * @return PHPExcel_Worksheet
1809
     */
1810
    public function unprotectCells($pRange = 'A1')
1811
    {
1812
        // Uppercase coordinate
1813
        $pRange = strtoupper($pRange);
1814
 
1815
        if (isset($this->_protectedCells[$pRange])) {
1816
            unset($this->_protectedCells[$pRange]);
1817
        } else {
1818
            throw new PHPExcel_Exception('Cell range ' . $pRange . ' not known as protected.');
1819
        }
1820
        return $this;
1821
    }
1822
 
1823
    /**
1824
     * Remove protection on a cell range by using numeric cell coordinates
1825
     *
1826
     * @param int  $pColumn1            Numeric column coordinate of the first cell
1827
     * @param int  $pRow1                Numeric row coordinate of the first cell
1828
     * @param int  $pColumn2            Numeric column coordinate of the last cell
1829
     * @param int $pRow2                Numeric row coordinate of the last cell
1830
     * @param string $pPassword            Password to unlock the protection
1831
     * @param    boolean $pAlreadyHashed    If the password has already been hashed, set this to true
1832
     * @throws    PHPExcel_Exception
1833
     * @return PHPExcel_Worksheet
1834
     */
1835
    public function unprotectCellsByColumnAndRow($pColumn1 = 0, $pRow1 = 1, $pColumn2 = 0, $pRow2 = 1, $pPassword = '', $pAlreadyHashed = false)
1836
    {
1837
        $cellRange = PHPExcel_Cell::stringFromColumnIndex($pColumn1) . $pRow1 . ':' . PHPExcel_Cell::stringFromColumnIndex($pColumn2) . $pRow2;
1838
        return $this->unprotectCells($cellRange, $pPassword, $pAlreadyHashed);
1839
    }
1840
 
1841
    /**
1842
     * Get protected cells
1843
     *
1844
     * @return array[]
1845
     */
1846
    public function getProtectedCells()
1847
    {
1848
        return $this->_protectedCells;
1849
    }
1850
 
1851
    /**
1852
     *    Get Autofilter
1853
     *
1854
     *    @return PHPExcel_Worksheet_AutoFilter
1855
     */
1856
    public function getAutoFilter()
1857
    {
1858
        return $this->_autoFilter;
1859
    }
1860
 
1861
    /**
1862
     *    Set AutoFilter
1863
     *
1864
     *    @param    PHPExcel_Worksheet_AutoFilter|string   $pValue
1865
     *            A simple string containing a Cell range like 'A1:E10' is permitted for backward compatibility
1866
     *    @throws    PHPExcel_Exception
1867
     *    @return PHPExcel_Worksheet
1868
     */
1869
    public function setAutoFilter($pValue)
1870
    {
1871
        if (is_string($pValue)) {
1872
            $this->_autoFilter->setRange($pValue);
1873
        } elseif(is_object($pValue) && ($pValue instanceof PHPExcel_Worksheet_AutoFilter)) {
1874
            $this->_autoFilter = $pValue;
1875
        }
1876
        return $this;
1877
    }
1878
 
1879
    /**
1880
     *    Set Autofilter Range by using numeric cell coordinates
1881
     *
1882
     *    @param  integer  $pColumn1    Numeric column coordinate of the first cell
1883
     *    @param  integer  $pRow1       Numeric row coordinate of the first cell
1884
     *    @param  integer  $pColumn2    Numeric column coordinate of the second cell
1885
     *    @param  integer  $pRow2       Numeric row coordinate of the second cell
1886
     *    @throws    PHPExcel_Exception
1887
     *    @return PHPExcel_Worksheet
1888
     */
1889
    public function setAutoFilterByColumnAndRow($pColumn1 = 0, $pRow1 = 1, $pColumn2 = 0, $pRow2 = 1)
1890
    {
1891
        return $this->setAutoFilter(
1892
            PHPExcel_Cell::stringFromColumnIndex($pColumn1) . $pRow1
1893
            . ':' .
1894
            PHPExcel_Cell::stringFromColumnIndex($pColumn2) . $pRow2
1895
        );
1896
    }
1897
 
1898
    /**
1899
     * Remove autofilter
1900
     *
1901
     * @return PHPExcel_Worksheet
1902
     */
1903
    public function removeAutoFilter()
1904
    {
1905
        $this->_autoFilter->setRange(NULL);
1906
        return $this;
1907
    }
1908
 
1909
    /**
1910
     * Get Freeze Pane
1911
     *
1912
     * @return string
1913
     */
1914
    public function getFreezePane()
1915
    {
1916
        return $this->_freezePane;
1917
    }
1918
 
1919
    /**
1920
     * Freeze Pane
1921
     *
1922
     * @param    string        $pCell        Cell (i.e. A2)
1923
     *                                    Examples:
1924
     *                                        A2 will freeze the rows above cell A2 (i.e row 1)
1925
     *                                        B1 will freeze the columns to the left of cell B1 (i.e column A)
1926
     *                                        B2 will freeze the rows above and to the left of cell A2
1927
     *                                            (i.e row 1 and column A)
1928
     * @throws    PHPExcel_Exception
1929
     * @return PHPExcel_Worksheet
1930
     */
1931
    public function freezePane($pCell = '')
1932
    {
1933
        // Uppercase coordinate
1934
        $pCell = strtoupper($pCell);
1935
 
1936
        if (strpos($pCell,':') === false && strpos($pCell,',') === false) {
1937
            $this->_freezePane = $pCell;
1938
        } else {
1939
            throw new PHPExcel_Exception('Freeze pane can not be set on a range of cells.');
1940
        }
1941
        return $this;
1942
    }
1943
 
1944
    /**
1945
     * Freeze Pane by using numeric cell coordinates
1946
     *
1947
     * @param int $pColumn    Numeric column coordinate of the cell
1948
     * @param int $pRow        Numeric row coordinate of the cell
1949
     * @throws    PHPExcel_Exception
1950
     * @return PHPExcel_Worksheet
1951
     */
1952
    public function freezePaneByColumnAndRow($pColumn = 0, $pRow = 1)
1953
    {
1954
        return $this->freezePane(PHPExcel_Cell::stringFromColumnIndex($pColumn) . $pRow);
1955
    }
1956
 
1957
    /**
1958
     * Unfreeze Pane
1959
     *
1960
     * @return PHPExcel_Worksheet
1961
     */
1962
    public function unfreezePane()
1963
    {
1964
        return $this->freezePane('');
1965
    }
1966
 
1967
    /**
1968
     * Insert a new row, updating all possible related data
1969
     *
1970
     * @param int $pBefore    Insert before this one
1971
     * @param int $pNumRows    Number of rows to insert
1972
     * @throws    PHPExcel_Exception
1973
     * @return PHPExcel_Worksheet
1974
     */
1975
    public function insertNewRowBefore($pBefore = 1, $pNumRows = 1) {
1976
        if ($pBefore >= 1) {
1977
            $objReferenceHelper = PHPExcel_ReferenceHelper::getInstance();
1978
            $objReferenceHelper->insertNewBefore('A' . $pBefore, 0, $pNumRows, $this);
1979
        } else {
1980
            throw new PHPExcel_Exception("Rows can only be inserted before at least row 1.");
1981
        }
1982
        return $this;
1983
    }
1984
 
1985
    /**
1986
     * Insert a new column, updating all possible related data
1987
     *
1988
     * @param int $pBefore    Insert before this one
1989
     * @param int $pNumCols    Number of columns to insert
1990
     * @throws    PHPExcel_Exception
1991
     * @return PHPExcel_Worksheet
1992
     */
1993
    public function insertNewColumnBefore($pBefore = 'A', $pNumCols = 1) {
1994
        if (!is_numeric($pBefore)) {
1995
            $objReferenceHelper = PHPExcel_ReferenceHelper::getInstance();
1996
            $objReferenceHelper->insertNewBefore($pBefore . '1', $pNumCols, 0, $this);
1997
        } else {
1998
            throw new PHPExcel_Exception("Column references should not be numeric.");
1999
        }
2000
        return $this;
2001
    }
2002
 
2003
    /**
2004
     * Insert a new column, updating all possible related data
2005
     *
2006
     * @param int $pBefore    Insert before this one (numeric column coordinate of the cell)
2007
     * @param int $pNumCols    Number of columns to insert
2008
     * @throws    PHPExcel_Exception
2009
     * @return PHPExcel_Worksheet
2010
     */
2011
    public function insertNewColumnBeforeByIndex($pBefore = 0, $pNumCols = 1) {
2012
        if ($pBefore >= 0) {
2013
            return $this->insertNewColumnBefore(PHPExcel_Cell::stringFromColumnIndex($pBefore), $pNumCols);
2014
        } else {
2015
            throw new PHPExcel_Exception("Columns can only be inserted before at least column A (0).");
2016
        }
2017
    }
2018
 
2019
    /**
2020
     * Delete a row, updating all possible related data
2021
     *
2022
     * @param int $pRow        Remove starting with this one
2023
     * @param int $pNumRows    Number of rows to remove
2024
     * @throws    PHPExcel_Exception
2025
     * @return PHPExcel_Worksheet
2026
     */
2027
    public function removeRow($pRow = 1, $pNumRows = 1) {
2028
        if ($pRow >= 1) {
2029
            $objReferenceHelper = PHPExcel_ReferenceHelper::getInstance();
2030
            $objReferenceHelper->insertNewBefore('A' . ($pRow + $pNumRows), 0, -$pNumRows, $this);
2031
        } else {
2032
            throw new PHPExcel_Exception("Rows to be deleted should at least start from row 1.");
2033
        }
2034
        return $this;
2035
    }
2036
 
2037
    /**
2038
     * Remove a column, updating all possible related data
2039
     *
2040
     * @param int $pColumn    Remove starting with this one
2041
     * @param int $pNumCols    Number of columns to remove
2042
     * @throws    PHPExcel_Exception
2043
     * @return PHPExcel_Worksheet
2044
     */
2045
    public function removeColumn($pColumn = 'A', $pNumCols = 1) {
2046
        if (!is_numeric($pColumn)) {
2047
            $pColumn = PHPExcel_Cell::stringFromColumnIndex(PHPExcel_Cell::columnIndexFromString($pColumn) - 1 + $pNumCols);
2048
            $objReferenceHelper = PHPExcel_ReferenceHelper::getInstance();
2049
            $objReferenceHelper->insertNewBefore($pColumn . '1', -$pNumCols, 0, $this);
2050
        } else {
2051
            throw new PHPExcel_Exception("Column references should not be numeric.");
2052
        }
2053
        return $this;
2054
    }
2055
 
2056
    /**
2057
     * Remove a column, updating all possible related data
2058
     *
2059
     * @param int $pColumn    Remove starting with this one (numeric column coordinate of the cell)
2060
     * @param int $pNumCols    Number of columns to remove
2061
     * @throws    PHPExcel_Exception
2062
     * @return PHPExcel_Worksheet
2063
     */
2064
    public function removeColumnByIndex($pColumn = 0, $pNumCols = 1) {
2065
        if ($pColumn >= 0) {
2066
            return $this->removeColumn(PHPExcel_Cell::stringFromColumnIndex($pColumn), $pNumCols);
2067
        } else {
2068
            throw new PHPExcel_Exception("Columns to be deleted should at least start from column 0");
2069
        }
2070
    }
2071
 
2072
    /**
2073
     * Show gridlines?
2074
     *
2075
     * @return boolean
2076
     */
2077
    public function getShowGridlines() {
2078
        return $this->_showGridlines;
2079
    }
2080
 
2081
    /**
2082
     * Set show gridlines
2083
     *
2084
     * @param boolean $pValue    Show gridlines (true/false)
2085
     * @return PHPExcel_Worksheet
2086
     */
2087
    public function setShowGridlines($pValue = false) {
2088
        $this->_showGridlines = $pValue;
2089
        return $this;
2090
    }
2091
 
2092
    /**
2093
    * Print gridlines?
2094
    *
2095
    * @return boolean
2096
    */
2097
    public function getPrintGridlines() {
2098
        return $this->_printGridlines;
2099
    }
2100
 
2101
    /**
2102
    * Set print gridlines
2103
    *
2104
    * @param boolean $pValue Print gridlines (true/false)
2105
    * @return PHPExcel_Worksheet
2106
    */
2107
    public function setPrintGridlines($pValue = false) {
2108
        $this->_printGridlines = $pValue;
2109
        return $this;
2110
    }
2111
 
2112
    /**
2113
    * Show row and column headers?
2114
    *
2115
    * @return boolean
2116
    */
2117
    public function getShowRowColHeaders() {
2118
        return $this->_showRowColHeaders;
2119
    }
2120
 
2121
    /**
2122
    * Set show row and column headers
2123
    *
2124
    * @param boolean $pValue Show row and column headers (true/false)
2125
    * @return PHPExcel_Worksheet
2126
    */
2127
    public function setShowRowColHeaders($pValue = false) {
2128
        $this->_showRowColHeaders = $pValue;
2129
        return $this;
2130
    }
2131
 
2132
    /**
2133
     * Show summary below? (Row/Column outlining)
2134
     *
2135
     * @return boolean
2136
     */
2137
    public function getShowSummaryBelow() {
2138
        return $this->_showSummaryBelow;
2139
    }
2140
 
2141
    /**
2142
     * Set show summary below
2143
     *
2144
     * @param boolean $pValue    Show summary below (true/false)
2145
     * @return PHPExcel_Worksheet
2146
     */
2147
    public function setShowSummaryBelow($pValue = true) {
2148
        $this->_showSummaryBelow = $pValue;
2149
        return $this;
2150
    }
2151
 
2152
    /**
2153
     * Show summary right? (Row/Column outlining)
2154
     *
2155
     * @return boolean
2156
     */
2157
    public function getShowSummaryRight() {
2158
        return $this->_showSummaryRight;
2159
    }
2160
 
2161
    /**
2162
     * Set show summary right
2163
     *
2164
     * @param boolean $pValue    Show summary right (true/false)
2165
     * @return PHPExcel_Worksheet
2166
     */
2167
    public function setShowSummaryRight($pValue = true) {
2168
        $this->_showSummaryRight = $pValue;
2169
        return $this;
2170
    }
2171
 
2172
    /**
2173
     * Get comments
2174
     *
2175
     * @return PHPExcel_Comment[]
2176
     */
2177
    public function getComments()
2178
    {
2179
        return $this->_comments;
2180
    }
2181
 
2182
    /**
2183
     * Set comments array for the entire sheet.
2184
     *
2185
	 * @param array of PHPExcel_Comment
2186
     * @return PHPExcel_Worksheet
2187
     */
2188
    public function setComments($pValue = array())
2189
    {
2190
        $this->_comments = $pValue;
2191
 
2192
        return $this;
2193
    }
2194
 
2195
    /**
2196
     * Get comment for cell
2197
     *
2198
     * @param string $pCellCoordinate    Cell coordinate to get comment for
2199
     * @return PHPExcel_Comment
2200
     * @throws PHPExcel_Exception
2201
     */
2202
    public function getComment($pCellCoordinate = 'A1')
2203
    {
2204
        // Uppercase coordinate
2205
        $pCellCoordinate = strtoupper($pCellCoordinate);
2206
 
2207
        if (strpos($pCellCoordinate,':') !== false || strpos($pCellCoordinate,',') !== false) {
2208
            throw new PHPExcel_Exception('Cell coordinate string can not be a range of cells.');
2209
        } else if (strpos($pCellCoordinate,'$') !== false) {
2210
            throw new PHPExcel_Exception('Cell coordinate string must not be absolute.');
2211
        } else if ($pCellCoordinate == '') {
2212
            throw new PHPExcel_Exception('Cell coordinate can not be zero-length string.');
2213
        } else {
2214
            // Check if we already have a comment for this cell.
2215
            // If not, create a new comment.
2216
            if (isset($this->_comments[$pCellCoordinate])) {
2217
                return $this->_comments[$pCellCoordinate];
2218
            } else {
2219
                $newComment = new PHPExcel_Comment();
2220
                $this->_comments[$pCellCoordinate] = $newComment;
2221
                return $newComment;
2222
            }
2223
        }
2224
    }
2225
 
2226
    /**
2227
     * Get comment for cell by using numeric cell coordinates
2228
     *
2229
     * @param int $pColumn    Numeric column coordinate of the cell
2230
     * @param int $pRow        Numeric row coordinate of the cell
2231
     * @return PHPExcel_Comment
2232
     */
2233
    public function getCommentByColumnAndRow($pColumn = 0, $pRow = 1)
2234
    {
2235
        return $this->getComment(PHPExcel_Cell::stringFromColumnIndex($pColumn) . $pRow);
2236
    }
2237
 
2238
    /**
2239
     * Get selected cell
2240
     *
2241
     * @deprecated
2242
     * @return string
2243
     */
2244
    public function getSelectedCell()
2245
    {
2246
        return $this->getSelectedCells();
2247
    }
2248
 
2249
    /**
2250
     * Get active cell
2251
     *
2252
     * @return string Example: 'A1'
2253
     */
2254
    public function getActiveCell()
2255
    {
2256
        return $this->_activeCell;
2257
    }
2258
 
2259
    /**
2260
     * Get selected cells
2261
     *
2262
     * @return string
2263
     */
2264
    public function getSelectedCells()
2265
    {
2266
        return $this->_selectedCells;
2267
    }
2268
 
2269
    /**
2270
     * Selected cell
2271
     *
2272
     * @param    string        $pCoordinate    Cell (i.e. A1)
2273
     * @return PHPExcel_Worksheet
2274
     */
2275
    public function setSelectedCell($pCoordinate = 'A1')
2276
    {
2277
        return $this->setSelectedCells($pCoordinate);
2278
    }
2279
 
2280
    /**
2281
     * Select a range of cells.
2282
     *
2283
     * @param    string        $pCoordinate    Cell range, examples: 'A1', 'B2:G5', 'A:C', '3:6'
2284
     * @throws    PHPExcel_Exception
2285
     * @return PHPExcel_Worksheet
2286
     */
2287
    public function setSelectedCells($pCoordinate = 'A1')
2288
    {
2289
        // Uppercase coordinate
2290
        $pCoordinate = strtoupper($pCoordinate);
2291
 
2292
        // Convert 'A' to 'A:A'
2293
        $pCoordinate = preg_replace('/^([A-Z]+)$/', '${1}:${1}', $pCoordinate);
2294
 
2295
        // Convert '1' to '1:1'
2296
        $pCoordinate = preg_replace('/^([0-9]+)$/', '${1}:${1}', $pCoordinate);
2297
 
2298
        // Convert 'A:C' to 'A1:C1048576'
2299
        $pCoordinate = preg_replace('/^([A-Z]+):([A-Z]+)$/', '${1}1:${2}1048576', $pCoordinate);
2300
 
2301
        // Convert '1:3' to 'A1:XFD3'
2302
        $pCoordinate = preg_replace('/^([0-9]+):([0-9]+)$/', 'A${1}:XFD${2}', $pCoordinate);
2303
 
2304
        if (strpos($pCoordinate,':') !== false || strpos($pCoordinate,',') !== false) {
2305
            list($first, ) = PHPExcel_Cell::splitRange($pCoordinate);
2306
            $this->_activeCell = $first[0];
2307
        } else {
2308
            $this->_activeCell = $pCoordinate;
2309
        }
2310
        $this->_selectedCells = $pCoordinate;
2311
        return $this;
2312
    }
2313
 
2314
    /**
2315
     * Selected cell by using numeric cell coordinates
2316
     *
2317
     * @param int $pColumn Numeric column coordinate of the cell
2318
     * @param int $pRow Numeric row coordinate of the cell
2319
     * @throws PHPExcel_Exception
2320
     * @return PHPExcel_Worksheet
2321
     */
2322
    public function setSelectedCellByColumnAndRow($pColumn = 0, $pRow = 1)
2323
    {
2324
        return $this->setSelectedCells(PHPExcel_Cell::stringFromColumnIndex($pColumn) . $pRow);
2325
    }
2326
 
2327
    /**
2328
     * Get right-to-left
2329
     *
2330
     * @return boolean
2331
     */
2332
    public function getRightToLeft() {
2333
        return $this->_rightToLeft;
2334
    }
2335
 
2336
    /**
2337
     * Set right-to-left
2338
     *
2339
     * @param boolean $value    Right-to-left true/false
2340
     * @return PHPExcel_Worksheet
2341
     */
2342
    public function setRightToLeft($value = false) {
2343
        $this->_rightToLeft = $value;
2344
        return $this;
2345
    }
2346
 
2347
    /**
2348
     * Fill worksheet from values in array
2349
     *
2350
     * @param array $source Source array
2351
     * @param mixed $nullValue Value in source array that stands for blank cell
2352
     * @param string $startCell Insert array starting from this cell address as the top left coordinate
2353
     * @param boolean $strictNullComparison Apply strict comparison when testing for null values in the array
2354
     * @throws PHPExcel_Exception
2355
     * @return PHPExcel_Worksheet
2356
     */
2357
    public function fromArray($source = null, $nullValue = null, $startCell = 'A1', $strictNullComparison = false) {
2358
        if (is_array($source)) {
2359
            //    Convert a 1-D array to 2-D (for ease of looping)
2360
            if (!is_array(end($source))) {
2361
                $source = array($source);
2362
            }
2363
 
2364
            // start coordinate
2365
            list ($startColumn, $startRow) = PHPExcel_Cell::coordinateFromString($startCell);
2366
 
2367
            // Loop through $source
2368
            foreach ($source as $rowData) {
2369
                $currentColumn = $startColumn;
2370
                foreach($rowData as $cellValue) {
2371
                    if ($strictNullComparison) {
2372
                        if ($cellValue !== $nullValue) {
2373
                            // Set cell value
2374
                            $this->getCell($currentColumn . $startRow)->setValue($cellValue);
2375
                        }
2376
                    } else {
2377
                        if ($cellValue != $nullValue) {
2378
                            // Set cell value
2379
                            $this->getCell($currentColumn . $startRow)->setValue($cellValue);
2380
                        }
2381
                    }
2382
                    ++$currentColumn;
2383
                }
2384
                ++$startRow;
2385
            }
2386
        } else {
2387
            throw new PHPExcel_Exception("Parameter \$source should be an array.");
2388
        }
2389
        return $this;
2390
    }
2391
 
2392
    /**
2393
     * Create array from a range of cells
2394
     *
2395
     * @param string $pRange Range of cells (i.e. "A1:B10"), or just one cell (i.e. "A1")
2396
     * @param mixed $nullValue Value returned in the array entry if a cell doesn't exist
2397
     * @param boolean $calculateFormulas Should formulas be calculated?
2398
     * @param boolean $formatData Should formatting be applied to cell values?
2399
     * @param boolean $returnCellRef False - Return a simple array of rows and columns indexed by number counting from zero
2400
     *                               True - Return rows and columns indexed by their actual row and column IDs
2401
     * @return array
2402
     */
2403
	public function rangeToArray($pRange = 'A1', $nullValue = null, $calculateFormulas = true, $formatData = true, $returnCellRef = false) {
2404
        // Returnvalue
2405
        $returnValue = array();
2406
        //    Identify the range that we need to extract from the worksheet
2407
        list($rangeStart, $rangeEnd) = PHPExcel_Cell::rangeBoundaries($pRange);
2408
        $minCol = PHPExcel_Cell::stringFromColumnIndex($rangeStart[0] -1);
2409
        $minRow = $rangeStart[1];
2410
        $maxCol = PHPExcel_Cell::stringFromColumnIndex($rangeEnd[0] -1);
2411
        $maxRow = $rangeEnd[1];
2412
 
2413
        $maxCol++;
2414
        // Loop through rows
2415
        $r = -1;
2416
        for ($row = $minRow; $row <= $maxRow; ++$row) {
2417
            $rRef = ($returnCellRef) ? $row : ++$r;
2418
            $c = -1;
2419
            // Loop through columns in the current row
2420
            for ($col = $minCol; $col != $maxCol; ++$col) {
2421
                $cRef = ($returnCellRef) ? $col : ++$c;
2422
                //    Using getCell() will create a new cell if it doesn't already exist. We don't want that to happen
2423
                //        so we test and retrieve directly against _cellCollection
2424
                if ($this->_cellCollection->isDataSet($col.$row)) {
2425
                    // Cell exists
2426
                    $cell = $this->_cellCollection->getCacheData($col.$row);
2427
                    if ($cell->getValue() !== null) {
2428
                        if ($cell->getValue() instanceof PHPExcel_RichText) {
2429
                            $returnValue[$rRef][$cRef] = $cell->getValue()->getPlainText();
2430
                        } else {
2431
                            if ($calculateFormulas) {
2432
                                $returnValue[$rRef][$cRef] = $cell->getCalculatedValue();
2433
                            } else {
2434
                                $returnValue[$rRef][$cRef] = $cell->getValue();
2435
                            }
2436
                        }
2437
 
2438
                        if ($formatData) {
2439
                            $style = $this->_parent->getCellXfByIndex($cell->getXfIndex());
2440
                            $returnValue[$rRef][$cRef] = PHPExcel_Style_NumberFormat::toFormattedString(
2441
                            	$returnValue[$rRef][$cRef],
2442
								($style->getNumberFormat()) ?
2443
									$style->getNumberFormat()->getFormatCode() :
2444
									PHPExcel_Style_NumberFormat::FORMAT_GENERAL
2445
                            );
2446
                        }
2447
                    } else {
2448
                        // Cell holds a NULL
2449
                        $returnValue[$rRef][$cRef] = $nullValue;
2450
                    }
2451
                } else {
2452
                    // Cell doesn't exist
2453
                    $returnValue[$rRef][$cRef] = $nullValue;
2454
                }
2455
            }
2456
        }
2457
 
2458
        // Return
2459
        return $returnValue;
2460
    }
2461
 
2462
 
2463
    /**
2464
     * Create array from a range of cells
2465
     *
2466
     * @param  string $pNamedRange Name of the Named Range
2467
     * @param  mixed  $nullValue Value returned in the array entry if a cell doesn't exist
2468
     * @param  boolean $calculateFormulas  Should formulas be calculated?
2469
     * @param  boolean $formatData  Should formatting be applied to cell values?
2470
     * @param  boolean $returnCellRef False - Return a simple array of rows and columns indexed by number counting from zero
2471
     *                                True - Return rows and columns indexed by their actual row and column IDs
2472
     * @return array
2473
     * @throws PHPExcel_Exception
2474
     */
2475
	public function namedRangeToArray($pNamedRange = '', $nullValue = null, $calculateFormulas = true, $formatData = true, $returnCellRef = false) {
2476
        $namedRange = PHPExcel_NamedRange::resolveRange($pNamedRange, $this);
2477
        if ($namedRange !== NULL) {
2478
            $pWorkSheet = $namedRange->getWorksheet();
2479
            $pCellRange = $namedRange->getRange();
2480
 
2481
			return $pWorkSheet->rangeToArray(	$pCellRange,
2482
												$nullValue, $calculateFormulas, $formatData, $returnCellRef);
2483
        }
2484
 
2485
        throw new PHPExcel_Exception('Named Range '.$pNamedRange.' does not exist.');
2486
    }
2487
 
2488
 
2489
    /**
2490
     * Create array from worksheet
2491
     *
2492
     * @param mixed $nullValue Value returned in the array entry if a cell doesn't exist
2493
     * @param boolean $calculateFormulas Should formulas be calculated?
2494
     * @param boolean $formatData  Should formatting be applied to cell values?
2495
     * @param boolean $returnCellRef False - Return a simple array of rows and columns indexed by number counting from zero
2496
     *                               True - Return rows and columns indexed by their actual row and column IDs
2497
     * @return array
2498
     */
2499
	public function toArray($nullValue = null, $calculateFormulas = true, $formatData = true, $returnCellRef = false) {
2500
        // Garbage collect...
2501
        $this->garbageCollect();
2502
 
2503
        //    Identify the range that we need to extract from the worksheet
2504
        $maxCol = $this->getHighestColumn();
2505
        $maxRow = $this->getHighestRow();
2506
        // Return
2507
		return $this->rangeToArray(	'A1:'.$maxCol.$maxRow,
2508
									$nullValue, $calculateFormulas, $formatData, $returnCellRef);
2509
    }
2510
 
2511
    /**
2512
     * Get row iterator
2513
     *
2514
     * @param  integer                           $startRow    The row number at which to start iterating
2515
     * @return PHPExcel_Worksheet_RowIterator
2516
     */
2517
	public function getRowIterator($startRow = 1) {
2518
        return new PHPExcel_Worksheet_RowIterator($this,$startRow);
2519
    }
2520
 
2521
    /**
2522
     * Run PHPExcel garabage collector.
2523
     *
2524
     * @return PHPExcel_Worksheet
2525
     */
2526
	public function garbageCollect() {
2527
        // Flush cache
2528
        $this->_cellCollection->getCacheData('A1');
2529
        // Build a reference table from images
2530
//        $imageCoordinates = array();
2531
//        $iterator = $this->getDrawingCollection()->getIterator();
2532
//        while ($iterator->valid()) {
2533
//            $imageCoordinates[$iterator->current()->getCoordinates()] = true;
2534
//
2535
//            $iterator->next();
2536
//        }
2537
//
2538
        // Lookup highest column and highest row if cells are cleaned
2539
        $colRow = $this->_cellCollection->getHighestRowAndColumn();
2540
        $highestRow = $colRow['row'];
2541
        $highestColumn = PHPExcel_Cell::columnIndexFromString($colRow['column']);
2542
 
2543
        // Loop through column dimensions
2544
        foreach ($this->_columnDimensions as $dimension) {
2545
            $highestColumn = max($highestColumn,PHPExcel_Cell::columnIndexFromString($dimension->getColumnIndex()));
2546
        }
2547
 
2548
        // Loop through row dimensions
2549
        foreach ($this->_rowDimensions as $dimension) {
2550
            $highestRow = max($highestRow,$dimension->getRowIndex());
2551
        }
2552
 
2553
        // Cache values
2554
        if ($highestColumn < 0) {
2555
            $this->_cachedHighestColumn = 'A';
2556
        } else {
2557
            $this->_cachedHighestColumn = PHPExcel_Cell::stringFromColumnIndex(--$highestColumn);
2558
        }
2559
        $this->_cachedHighestRow = $highestRow;
2560
 
2561
        // Return
2562
        return $this;
2563
    }
2564
 
2565
    /**
2566
     * Get hash code
2567
     *
2568
     * @return string    Hash code
2569
     */
2570
	public function getHashCode() {
2571
        if ($this->_dirty) {
2572
            $this->_hash = md5( $this->_title .
2573
                                $this->_autoFilter .
2574
                                ($this->_protection->isProtectionEnabled() ? 't' : 'f') .
2575
                                __CLASS__
2576
                              );
2577
            $this->_dirty = false;
2578
        }
2579
        return $this->_hash;
2580
    }
2581
 
2582
    /**
2583
     * Extract worksheet title from range.
2584
     *
2585
     * Example: extractSheetTitle("testSheet!A1") ==> 'A1'
2586
     * Example: extractSheetTitle("'testSheet 1'!A1", true) ==> array('testSheet 1', 'A1');
2587
     *
2588
     * @param string $pRange    Range to extract title from
2589
     * @param bool $returnRange    Return range? (see example)
2590
     * @return mixed
2591
     */
2592
	public static function extractSheetTitle($pRange, $returnRange = false) {
2593
        // Sheet title included?
2594
        if (($sep = strpos($pRange, '!')) === false) {
2595
            return '';
2596
        }
2597
 
2598
        if ($returnRange) {
2599
            return array( trim(substr($pRange, 0, $sep),"'"),
2600
                          substr($pRange, $sep + 1)
2601
                        );
2602
        }
2603
 
2604
        return substr($pRange, $sep + 1);
2605
    }
2606
 
2607
    /**
2608
     * Get hyperlink
2609
     *
2610
     * @param string $pCellCoordinate    Cell coordinate to get hyperlink for
2611
     */
2612
    public function getHyperlink($pCellCoordinate = 'A1')
2613
    {
2614
        // return hyperlink if we already have one
2615
        if (isset($this->_hyperlinkCollection[$pCellCoordinate])) {
2616
            return $this->_hyperlinkCollection[$pCellCoordinate];
2617
        }
2618
 
2619
        // else create hyperlink
2620
        $this->_hyperlinkCollection[$pCellCoordinate] = new PHPExcel_Cell_Hyperlink();
2621
        return $this->_hyperlinkCollection[$pCellCoordinate];
2622
    }
2623
 
2624
    /**
2625
     * Set hyperlnk
2626
     *
2627
     * @param string $pCellCoordinate    Cell coordinate to insert hyperlink
2628
     * @param    PHPExcel_Cell_Hyperlink    $pHyperlink
2629
     * @return PHPExcel_Worksheet
2630
     */
2631
    public function setHyperlink($pCellCoordinate = 'A1', PHPExcel_Cell_Hyperlink $pHyperlink = null)
2632
    {
2633
        if ($pHyperlink === null) {
2634
            unset($this->_hyperlinkCollection[$pCellCoordinate]);
2635
        } else {
2636
            $this->_hyperlinkCollection[$pCellCoordinate] = $pHyperlink;
2637
        }
2638
        return $this;
2639
    }
2640
 
2641
    /**
2642
     * Hyperlink at a specific coordinate exists?
2643
     *
2644
     * @param string $pCoordinate
2645
     * @return boolean
2646
     */
2647
    public function hyperlinkExists($pCoordinate = 'A1')
2648
    {
2649
        return isset($this->_hyperlinkCollection[$pCoordinate]);
2650
    }
2651
 
2652
    /**
2653
     * Get collection of hyperlinks
2654
     *
2655
     * @return PHPExcel_Cell_Hyperlink[]
2656
     */
2657
    public function getHyperlinkCollection()
2658
    {
2659
        return $this->_hyperlinkCollection;
2660
    }
2661
 
2662
    /**
2663
     * Get data validation
2664
     *
2665
     * @param string $pCellCoordinate Cell coordinate to get data validation for
2666
     */
2667
    public function getDataValidation($pCellCoordinate = 'A1')
2668
    {
2669
        // return data validation if we already have one
2670
        if (isset($this->_dataValidationCollection[$pCellCoordinate])) {
2671
            return $this->_dataValidationCollection[$pCellCoordinate];
2672
        }
2673
 
2674
        // else create data validation
2675
        $this->_dataValidationCollection[$pCellCoordinate] = new PHPExcel_Cell_DataValidation();
2676
        return $this->_dataValidationCollection[$pCellCoordinate];
2677
    }
2678
 
2679
    /**
2680
     * Set data validation
2681
     *
2682
     * @param string $pCellCoordinate    Cell coordinate to insert data validation
2683
     * @param    PHPExcel_Cell_DataValidation    $pDataValidation
2684
     * @return PHPExcel_Worksheet
2685
     */
2686
    public function setDataValidation($pCellCoordinate = 'A1', PHPExcel_Cell_DataValidation $pDataValidation = null)
2687
    {
2688
        if ($pDataValidation === null) {
2689
            unset($this->_dataValidationCollection[$pCellCoordinate]);
2690
        } else {
2691
            $this->_dataValidationCollection[$pCellCoordinate] = $pDataValidation;
2692
        }
2693
        return $this;
2694
    }
2695
 
2696
    /**
2697
     * Data validation at a specific coordinate exists?
2698
     *
2699
     * @param string $pCoordinate
2700
     * @return boolean
2701
     */
2702
    public function dataValidationExists($pCoordinate = 'A1')
2703
    {
2704
        return isset($this->_dataValidationCollection[$pCoordinate]);
2705
    }
2706
 
2707
    /**
2708
     * Get collection of data validations
2709
     *
2710
     * @return PHPExcel_Cell_DataValidation[]
2711
     */
2712
    public function getDataValidationCollection()
2713
    {
2714
        return $this->_dataValidationCollection;
2715
    }
2716
 
2717
    /**
2718
     * Accepts a range, returning it as a range that falls within the current highest row and column of the worksheet
2719
     *
2720
     * @param string $range
2721
     * @return string Adjusted range value
2722
     */
2723
	public function shrinkRangeToFit($range) {
2724
        $maxCol = $this->getHighestColumn();
2725
        $maxRow = $this->getHighestRow();
2726
        $maxCol = PHPExcel_Cell::columnIndexFromString($maxCol);
2727
 
2728
        $rangeBlocks = explode(' ',$range);
2729
        foreach ($rangeBlocks as &$rangeSet) {
2730
            $rangeBoundaries = PHPExcel_Cell::getRangeBoundaries($rangeSet);
2731
 
2732
            if (PHPExcel_Cell::columnIndexFromString($rangeBoundaries[0][0]) > $maxCol) { $rangeBoundaries[0][0] = PHPExcel_Cell::stringFromColumnIndex($maxCol); }
2733
            if ($rangeBoundaries[0][1] > $maxRow) { $rangeBoundaries[0][1] = $maxRow; }
2734
            if (PHPExcel_Cell::columnIndexFromString($rangeBoundaries[1][0]) > $maxCol) { $rangeBoundaries[1][0] = PHPExcel_Cell::stringFromColumnIndex($maxCol); }
2735
            if ($rangeBoundaries[1][1] > $maxRow) { $rangeBoundaries[1][1] = $maxRow; }
2736
            $rangeSet = $rangeBoundaries[0][0].$rangeBoundaries[0][1].':'.$rangeBoundaries[1][0].$rangeBoundaries[1][1];
2737
        }
2738
        unset($rangeSet);
2739
        $stRange = implode(' ',$rangeBlocks);
2740
 
2741
        return $stRange;
2742
    }
2743
 
2744
    /**
2745
     * Get tab color
2746
     *
2747
     * @return PHPExcel_Style_Color
2748
     */
2749
    public function getTabColor()
2750
    {
2751
        if ($this->_tabColor === NULL)
2752
            $this->_tabColor = new PHPExcel_Style_Color();
2753
 
2754
        return $this->_tabColor;
2755
    }
2756
 
2757
    /**
2758
     * Reset tab color
2759
     *
2760
     * @return PHPExcel_Worksheet
2761
     */
2762
    public function resetTabColor()
2763
    {
2764
        $this->_tabColor = null;
2765
        unset($this->_tabColor);
2766
 
2767
        return $this;
2768
    }
2769
 
2770
    /**
2771
     * Tab color set?
2772
     *
2773
     * @return boolean
2774
     */
2775
    public function isTabColorSet()
2776
    {
2777
        return ($this->_tabColor !== NULL);
2778
    }
2779
 
2780
    /**
2781
     * Copy worksheet (!= clone!)
2782
     *
2783
     * @return PHPExcel_Worksheet
2784
     */
2785
	public function copy() {
2786
        $copied = clone $this;
2787
 
2788
        return $copied;
2789
    }
2790
 
2791
    /**
2792
     * Implement PHP __clone to create a deep clone, not just a shallow copy.
2793
     */
2794
	public function __clone() {
2795
        foreach ($this as $key => $val) {
2796
            if ($key == '_parent') {
2797
                continue;
2798
            }
2799
 
2800
            if (is_object($val) || (is_array($val))) {
2801
                if ($key == '_cellCollection') {
2802
                    $newCollection = clone $this->_cellCollection;
2803
                    $newCollection->copyCellCollection($this);
2804
                    $this->_cellCollection = $newCollection;
2805
                } elseif ($key == '_drawingCollection') {
2806
                    $newCollection = clone $this->_drawingCollection;
2807
                    $this->_drawingCollection = $newCollection;
2808
                } elseif (($key == '_autoFilter') && ($this->_autoFilter instanceof PHPExcel_Worksheet_AutoFilter)) {
2809
                    $newAutoFilter = clone $this->_autoFilter;
2810
                    $this->_autoFilter = $newAutoFilter;
2811
                    $this->_autoFilter->setParent($this);
2812
                } else {
2813
                    $this->{$key} = unserialize(serialize($val));
2814
                }
2815
            }
2816
        }
2817
    }
2818
}