forked from real-chocopanda/PHPExcel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Worksheet.php
2583 lines (2283 loc) · 66 KB
/
Worksheet.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* PHPExcel
*
* Copyright (c) 2006 - 2011 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel_Worksheet
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE##
*/
/**
* PHPExcel_Worksheet
*
* @category PHPExcel
* @package PHPExcel_Worksheet
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Worksheet implements PHPExcel_IComparable
{
/* Break types */
const BREAK_NONE = 0;
const BREAK_ROW = 1;
const BREAK_COLUMN = 2;
/* Sheet state */
const SHEETSTATE_VISIBLE = 'visible';
const SHEETSTATE_HIDDEN = 'hidden';
const SHEETSTATE_VERYHIDDEN = 'veryHidden';
/**
* Invalid characters in sheet title
*
* @var array
*/
private static $_invalidCharacters = array('*', ':', '/', '\\', '?', '[', ']');
/**
* Parent spreadsheet
*
* @var PHPExcel
*/
private $_parent;
/**
* Cacheable collection of cells
*
* @var PHPExcel_CachedObjectStorage_xxx
*/
private $_cellCollection = null;
/**
* Collection of row dimensions
*
* @var PHPExcel_Worksheet_RowDimension[]
*/
private $_rowDimensions = array();
/**
* Default row dimension
*
* @var PHPExcel_Worksheet_RowDimension
*/
private $_defaultRowDimension = null;
/**
* Collection of column dimensions
*
* @var PHPExcel_Worksheet_ColumnDimension[]
*/
private $_columnDimensions = array();
/**
* Default column dimension
*
* @var PHPExcel_Worksheet_ColumnDimension
*/
private $_defaultColumnDimension = null;
/**
* Collection of drawings
*
* @var PHPExcel_Worksheet_BaseDrawing[]
*/
private $_drawingCollection = null;
/**
* Worksheet title
*
* @var string
*/
private $_title;
/**
* Sheet state
*
* @var string
*/
private $_sheetState;
/**
* Page setup
*
* @var PHPExcel_Worksheet_PageSetup
*/
private $_pageSetup;
/**
* Page margins
*
* @var PHPExcel_Worksheet_PageMargins
*/
private $_pageMargins;
/**
* Page header/footer
*
* @var PHPExcel_Worksheet_HeaderFooter
*/
private $_headerFooter;
/**
* Sheet view
*
* @var PHPExcel_Worksheet_SheetView
*/
private $_sheetView;
/**
* Protection
*
* @var PHPExcel_Worksheet_Protection
*/
private $_protection;
/**
* Collection of styles
*
* @var PHPExcel_Style[]
*/
private $_styles = array();
/**
* Conditional styles. Indexed by cell coordinate, e.g. 'A1'
*
* @var array
*/
private $_conditionalStylesCollection = array();
/**
* Is the current cell collection sorted already?
*
* @var boolean
*/
private $_cellCollectionIsSorted = false;
/**
* Collection of breaks
*
* @var array
*/
private $_breaks = array();
/**
* Collection of merged cell ranges
*
* @var array
*/
private $_mergeCells = array();
/**
* Collection of protected cell ranges
*
* @var array
*/
private $_protectedCells = array();
/**
* Autofilter Range
*
* @var string
*/
private $_autoFilter = '';
/**
* Freeze pane
*
* @var string
*/
private $_freezePane = '';
/**
* Show gridlines?
*
* @var boolean
*/
private $_showGridlines = true;
/**
* Print gridlines?
*
* @var boolean
*/
private $_printGridlines = false;
/**
* Show row and column headers?
*
* @var boolean
*/
private $_showRowColHeaders = true;
/**
* Show summary below? (Row/Column outline)
*
* @var boolean
*/
private $_showSummaryBelow = true;
/**
* Show summary right? (Row/Column outline)
*
* @var boolean
*/
private $_showSummaryRight = true;
/**
* Collection of comments
*
* @var PHPExcel_Comment[]
*/
private $_comments = array();
/**
* Active cell. (Only one!)
*
* @var string
*/
private $_activeCell = 'A1';
/**
* Selected cells
*
* @var string
*/
private $_selectedCells = 'A1';
/**
* Cached highest column
*
* @var string
*/
private $_cachedHighestColumn = 'A';
/**
* Cached highest row
*
* @var int
*/
private $_cachedHighestRow = 1;
/**
* Right-to-left?
*
* @var boolean
*/
private $_rightToLeft = false;
/**
* Hyperlinks. Indexed by cell coordinate, e.g. 'A1'
*
* @var array
*/
private $_hyperlinkCollection = array();
/**
* Data validation objects. Indexed by cell coordinate, e.g. 'A1'
*
* @var array
*/
private $_dataValidationCollection = array();
/**
* Tab color
*
* @var PHPExcel_Style_Color
*/
private $_tabColor;
/**
* Dirty flag
*
* @var boolean
*/
private $_dirty = true;
/**
* Hash
*
* @var string
*/
private $_hash = null;
/**
* Create a new worksheet
*
* @param PHPExcel $pParent
* @param string $pTitle
*/
public function __construct(PHPExcel $pParent = null, $pTitle = 'Worksheet')
{
// Set parent and title
$this->_parent = $pParent;
$this->setTitle($pTitle);
$this->setSheetState(PHPExcel_Worksheet::SHEETSTATE_VISIBLE);
$this->_cellCollection = PHPExcel_CachedObjectStorageFactory::getInstance($this);
// Set page setup
$this->_pageSetup = new PHPExcel_Worksheet_PageSetup();
// Set page margins
$this->_pageMargins = new PHPExcel_Worksheet_PageMargins();
// Set page header/footer
$this->_headerFooter = new PHPExcel_Worksheet_HeaderFooter();
// Set sheet view
$this->_sheetView = new PHPExcel_Worksheet_SheetView();
// Drawing collection
$this->_drawingCollection = new ArrayObject();
// Protection
$this->_protection = new PHPExcel_Worksheet_Protection();
// Default row dimension
$this->_defaultRowDimension = new PHPExcel_Worksheet_RowDimension(null);
// Default column dimension
$this->_defaultColumnDimension = new PHPExcel_Worksheet_ColumnDimension(null);
}
public function disconnectCells() {
$this->_cellCollection->unsetWorksheetCells();
$this->_cellCollection = null;
// detach ourself from the workbook, so that it can then delete this worksheet successfully
$this->_parent = null;
}
/**
* Return the cache controller for the cell collection
*
* @return PHPExcel_CachedObjectStorage_xxx
*/
public function getCellCacheController() {
return $this->_cellCollection;
} // function getCellCacheController()
/**
* Get array of invalid characters for sheet title
*
* @return array
*/
public static function getInvalidCharacters()
{
return self::$_invalidCharacters;
}
/**
* Check sheet title for valid Excel syntax
*
* @param string $pValue The string to check
* @return string The valid string
* @throws Exception
*/
private static function _checkSheetTitle($pValue)
{
// Some of the printable ASCII characters are invalid: * : / \ ? [ ]
if (str_replace(self::$_invalidCharacters, '', $pValue) !== $pValue) {
throw new Exception('Invalid character found in sheet title');
}
// Maximum 31 characters allowed for sheet title
if (PHPExcel_Shared_String::CountCharacters($pValue) > 31) {
throw new Exception('Maximum 31 characters allowed in sheet title.');
}
return $pValue;
}
/**
* Get collection of cells
*
* @param boolean $pSorted Also sort the cell collection?
* @return PHPExcel_Cell[]
*/
public function getCellCollection($pSorted = true)
{
if ($pSorted) {
// Re-order cell collection
return $this->sortCellCollection();
}
if (!is_null($this->_cellCollection)) {
return $this->_cellCollection->getCellList();
}
return array();
}
/**
* Sort collection of cells
*
* @return PHPExcel_Worksheet
*/
public function sortCellCollection()
{
if (!is_null($this->_cellCollection)) {
return $this->_cellCollection->getSortedCellList();
}
return array();
}
/**
* Get collection of row dimensions
*
* @return PHPExcel_Worksheet_RowDimension[]
*/
public function getRowDimensions()
{
return $this->_rowDimensions;
}
/**
* Get default row dimension
*
* @return PHPExcel_Worksheet_RowDimension
*/
public function getDefaultRowDimension()
{
return $this->_defaultRowDimension;
}
/**
* Get collection of column dimensions
*
* @return PHPExcel_Worksheet_ColumnDimension[]
*/
public function getColumnDimensions()
{
return $this->_columnDimensions;
}
/**
* Get default column dimension
*
* @return PHPExcel_Worksheet_ColumnDimension
*/
public function getDefaultColumnDimension()
{
return $this->_defaultColumnDimension;
}
/**
* Get collection of drawings
*
* @return PHPExcel_Worksheet_BaseDrawing[]
*/
public function getDrawingCollection()
{
return $this->_drawingCollection;
}
/**
* Refresh column dimensions
*
* @return PHPExcel_Worksheet
*/
public function refreshColumnDimensions()
{
$currentColumnDimensions = $this->getColumnDimensions();
$newColumnDimensions = array();
foreach ($currentColumnDimensions as $objColumnDimension) {
$newColumnDimensions[$objColumnDimension->getColumnIndex()] = $objColumnDimension;
}
$this->_columnDimensions = $newColumnDimensions;
return $this;
}
/**
* Refresh row dimensions
*
* @return PHPExcel_Worksheet
*/
public function refreshRowDimensions()
{
$currentRowDimensions = $this->getRowDimensions();
$newRowDimensions = array();
foreach ($currentRowDimensions as $objRowDimension) {
$newRowDimensions[$objRowDimension->getRowIndex()] = $objRowDimension;
}
$this->_rowDimensions = $newRowDimensions;
return $this;
}
/**
* Calculate worksheet dimension
*
* @return string String containing the dimension of this worksheet
*/
public function calculateWorksheetDimension()
{
// Return
return 'A1' . ':' . $this->getHighestColumn() . $this->getHighestRow();
}
/**
* Calculate widths for auto-size columns
*
* @param boolean $calculateMergeCells Calculate merge cell width
* @return PHPExcel_Worksheet;
*/
public function calculateColumnWidths($calculateMergeCells = false)
{
// initialize $autoSizes array
$autoSizes = array();
foreach ($this->getColumnDimensions() as $colDimension) {
if ($colDimension->getAutoSize()) {
$autoSizes[$colDimension->getColumnIndex()] = -1;
}
}
// There is only something to do if there are some auto-size columns
if (!empty($autoSizes)) {
// build list of cells references that participate in a merge
$isMergeCell = array();
foreach ($this->getMergeCells() as $cells) {
foreach (PHPExcel_Cell::extractAllCellReferencesInRange($cells) as $cellReference) {
$isMergeCell[$cellReference] = true;
}
}
// loop through all cells in the worksheet
foreach ($this->getCellCollection(false) as $cellID) {
$cell = $this->getCell($cellID);
if (isset($autoSizes[$cell->getColumn()])) {
// Determine width if cell does not participate in a merge
if (!isset($isMergeCell[$cell->getCoordinate()])) {
// Calculated value
$cellValue = $cell->getCalculatedValue();
// To formatted string
$cellValue = PHPExcel_Style_NumberFormat::toFormattedString($cellValue, $this->getParent()->getCellXfByIndex($cell->getXfIndex())->getNumberFormat()->getFormatCode());
$autoSizes[$cell->getColumn()] = max(
(float)$autoSizes[$cell->getColumn()],
(float)PHPExcel_Shared_Font::calculateColumnWidth(
$this->getParent()->getCellXfByIndex($cell->getXfIndex())->getFont(),
$cellValue,
$this->getParent()->getCellXfByIndex($cell->getXfIndex())->getAlignment()->getTextRotation(),
$this->getDefaultStyle()->getFont()
)
);
}
}
}
// adjust column widths
foreach ($autoSizes as $columnIndex => $width) {
if ($width == -1) $width = $this->getDefaultColumnDimension()->getWidth();
$this->getColumnDimension($columnIndex)->setWidth($width);
}
}
return $this;
}
/**
* Get parent
*
* @return PHPExcel
*/
public function getParent() {
return $this->_parent;
}
/**
* Re-bind parent
*
* @param PHPExcel $parent
* @return PHPExcel_Worksheet
*/
public function rebindParent(PHPExcel $parent) {
$namedRanges = $this->_parent->getNamedRanges();
foreach ($namedRanges as $namedRange) {
$parent->addNamedRange($namedRange);
}
$this->_parent->removeSheetByIndex(
$this->_parent->getIndex($this)
);
$this->_parent = $parent;
return $this;
}
/**
* Get title
*
* @return string
*/
public function getTitle()
{
return $this->_title;
}
/**
* Set title
*
* @param string $pValue String containing the dimension of this worksheet
* @return PHPExcel_Worksheet
*/
public function setTitle($pValue = 'Worksheet')
{
// Is this a 'rename' or not?
if ($this->getTitle() == $pValue) {
return $this;
}
// Syntax check
self::_checkSheetTitle($pValue);
// Old title
$oldTitle = $this->getTitle();
// Is there already such sheet name?
if ($this->getParent()->getSheetByName($pValue)) {
// Use name, but append with lowest possible integer
if (PHPExcel_Shared_String::CountCharacters($pValue) > 29) {
$pValue = PHPExcel_Shared_String::Substring($pValue,0,29);
}
$i = 1;
while ($this->getParent()->getSheetByName($pValue . ' ' . $i)) {
++$i;
if ($i == 10) {
if (PHPExcel_Shared_String::CountCharacters($pValue) > 28) {
$pValue = PHPExcel_Shared_String::Substring($pValue,0,28);
}
} elseif ($i == 100) {
if (PHPExcel_Shared_String::CountCharacters($pValue) > 27) {
$pValue = PHPExcel_Shared_String::Substring($pValue,0,27);
}
}
}
$altTitle = $pValue . ' ' . $i;
return $this->setTitle($altTitle);
}
// Set title
$this->_title = $pValue;
$this->_dirty = true;
// New title
$newTitle = $this->getTitle();
PHPExcel_ReferenceHelper::getInstance()->updateNamedFormulas($this->getParent(), $oldTitle, $newTitle);
return $this;
}
/**
* Get sheet state
*
* @return string Sheet state (visible, hidden, veryHidden)
*/
public function getSheetState() {
return $this->_sheetState;
}
/**
* Set sheet state
*
* @param string $value Sheet state (visible, hidden, veryHidden)
* @return PHPExcel_Worksheet
*/
public function setSheetState($value = PHPExcel_Worksheet::SHEETSTATE_VISIBLE) {
$this->_sheetState = $value;
return $this;
}
/**
* Get page setup
*
* @return PHPExcel_Worksheet_PageSetup
*/
public function getPageSetup()
{
return $this->_pageSetup;
}
/**
* Set page setup
*
* @param PHPExcel_Worksheet_PageSetup $pValue
* @return PHPExcel_Worksheet
*/
public function setPageSetup(PHPExcel_Worksheet_PageSetup $pValue)
{
$this->_pageSetup = $pValue;
return $this;
}
/**
* Get page margins
*
* @return PHPExcel_Worksheet_PageMargins
*/
public function getPageMargins()
{
return $this->_pageMargins;
}
/**
* Set page margins
*
* @param PHPExcel_Worksheet_PageMargins $pValue
* @return PHPExcel_Worksheet
*/
public function setPageMargins(PHPExcel_Worksheet_PageMargins $pValue)
{
$this->_pageMargins = $pValue;
return $this;
}
/**
* Get page header/footer
*
* @return PHPExcel_Worksheet_HeaderFooter
*/
public function getHeaderFooter()
{
return $this->_headerFooter;
}
/**
* Set page header/footer
*
* @param PHPExcel_Worksheet_HeaderFooter $pValue
* @return PHPExcel_Worksheet
*/
public function setHeaderFooter(PHPExcel_Worksheet_HeaderFooter $pValue)
{
$this->_headerFooter = $pValue;
return $this;
}
/**
* Get sheet view
*
* @return PHPExcel_Worksheet_HeaderFooter
*/
public function getSheetView()
{
return $this->_sheetView;
}
/**
* Set sheet view
*
* @param PHPExcel_Worksheet_SheetView $pValue
* @return PHPExcel_Worksheet
*/
public function setSheetView(PHPExcel_Worksheet_SheetView $pValue)
{
$this->_sheetView = $pValue;
return $this;
}
/**
* Get Protection
*
* @return PHPExcel_Worksheet_Protection
*/
public function getProtection()
{
return $this->_protection;
}
/**
* Set Protection
*
* @param PHPExcel_Worksheet_Protection $pValue
* @return PHPExcel_Worksheet
*/
public function setProtection(PHPExcel_Worksheet_Protection $pValue)
{
$this->_protection = $pValue;
$this->_dirty = true;
return $this;
}
/**
* Get highest worksheet column
*
* @return string Highest column name
*/
public function getHighestColumn()
{
return $this->_cachedHighestColumn;
}
/**
* Get highest worksheet row
*
* @return int Highest row number
*/
public function getHighestRow()
{
return $this->_cachedHighestRow;
}
/**
* Set a cell value
*
* @param string $pCoordinate Coordinate of the cell
* @param mixed $pValue Value of the cell
* @param bool $returnCell Return the worksheet (false, default) or the cell (true)
* @return PHPExcel_Worksheet|PHPExcel_Cell Depending on the last parameter being specified
*/
public function setCellValue($pCoordinate = 'A1', $pValue = null, $returnCell = false)
{
$cell = $this->getCell($pCoordinate);
$cell->setValue($pValue);
if ($returnCell) {
return $cell;
}
return $this;
}
/**
* Set a cell value by using numeric cell coordinates
*
* @param string $pColumn Numeric column coordinate of the cell
* @param string $pRow Numeric row coordinate of the cell
* @param mixed $pValue Value of the cell
* @param bool $returnCell Return the worksheet (false, default) or the cell (true)
* @return PHPExcel_Worksheet|PHPExcel_Cell Depending on the last parameter being specified
*/
public function setCellValueByColumnAndRow($pColumn = 0, $pRow = 1, $pValue = null, $returnCell = false)
{
$cell = $this->getCell(PHPExcel_Cell::stringFromColumnIndex($pColumn) . $pRow);
$cell->setValue($pValue);
if ($returnCell) {
return $cell;
}
return $this;
}
/**
* Set a cell value
*
* @param string $pCoordinate Coordinate of the cell
* @param mixed $pValue Value of the cell
* @param string $pDataType Explicit data type
* @return PHPExcel_Worksheet
*/
public function setCellValueExplicit($pCoordinate = 'A1', $pValue = null, $pDataType = PHPExcel_Cell_DataType::TYPE_STRING)
{
// Set value
$this->getCell($pCoordinate)->setValueExplicit($pValue, $pDataType);
return $this;
}
/**
* Set a cell value by using numeric cell coordinates
*
* @param string $pColumn Numeric column coordinate of the cell
* @param string $pRow Numeric row coordinate of the cell
* @param mixed $pValue Value of the cell
* @param string $pDataType Explicit data type
* @return PHPExcel_Worksheet
*/
public function setCellValueExplicitByColumnAndRow($pColumn = 0, $pRow = 1, $pValue = null, $pDataType = PHPExcel_Cell_DataType::TYPE_STRING)
{
return $this->getCell(PHPExcel_Cell::stringFromColumnIndex($pColumn) . $pRow)->setValueExplicit($pValue, $pDataType);
}
/**
* Get cell at a specific coordinate
*
* @param string $pCoordinate Coordinate of the cell
* @throws Exception
* @return PHPExcel_Cell Cell that was found
*/
public function getCell($pCoordinate = 'A1')
{
// Check cell collection
if ($this->_cellCollection->isDataSet($pCoordinate)) {
return $this->_cellCollection->getCacheData($pCoordinate);
}
// Worksheet reference?
if (strpos($pCoordinate, '!') !== false) {
$worksheetReference = PHPExcel_Worksheet::extractSheetTitle($pCoordinate, true);
return $this->getParent()->getSheetByName($worksheetReference[0])->getCell($worksheetReference[1]);
}
// Named range?
if ((!preg_match('/^'.PHPExcel_Calculation::CALCULATION_REGEXP_CELLREF.'$/i', $pCoordinate, $matches)) &&
(preg_match('/^'.PHPExcel_Calculation::CALCULATION_REGEXP_NAMEDRANGE.'$/i', $pCoordinate, $matches))) {
$namedRange = PHPExcel_NamedRange::resolveRange($pCoordinate, $this);
if (!is_null($namedRange)) {
$pCoordinate = $namedRange->getRange();
return $namedRange->getWorksheet()->getCell($pCoordinate);
}
}
// Uppercase coordinate
$pCoordinate = strtoupper($pCoordinate);
if (strpos($pCoordinate,':') !== false || strpos($pCoordinate,',') !== false) {
throw new Exception('Cell coordinate can not be a range of cells.');
} elseif (strpos($pCoordinate,'$') !== false) {
throw new Exception('Cell coordinate must not be absolute.');
} else {
// Create new cell object
// Coordinates
$aCoordinates = PHPExcel_Cell::coordinateFromString($pCoordinate);
$cell = $this->_cellCollection->addCacheData($pCoordinate,new PHPExcel_Cell($aCoordinates[0], $aCoordinates[1], null, PHPExcel_Cell_DataType::TYPE_NULL, $this));
$this->_cellCollectionIsSorted = false;
if (PHPExcel_Cell::columnIndexFromString($this->_cachedHighestColumn) < PHPExcel_Cell::columnIndexFromString($aCoordinates[0]))
$this->_cachedHighestColumn = $aCoordinates[0];
$this->_cachedHighestRow = max($this->_cachedHighestRow,$aCoordinates[1]);
// Cell needs appropriate xfIndex
$rowDimensions = $this->getRowDimensions();
$columnDimensions = $this->getColumnDimensions();
if ( isset($rowDimensions[$aCoordinates[1]]) && $rowDimensions[$aCoordinates[1]]->getXfIndex() !== null ) {
// then there is a row dimension with explicit style, assign it to the cell
$cell->setXfIndex($rowDimensions[$aCoordinates[1]]->getXfIndex());
} else if ( isset($columnDimensions[$aCoordinates[0]]) ) {
// then there is a column dimension, assign it to the cell
$cell->setXfIndex($columnDimensions[$aCoordinates[0]]->getXfIndex());
} else {
// set to default index
$cell->setXfIndex(0);
}
return $cell;
}
}
/**
* Get cell at a specific coordinate by using numeric cell coordinates
*
* @param string $pColumn Numeric column coordinate of the cell
* @param string $pRow Numeric row coordinate of the cell
* @return PHPExcel_Cell Cell that was found
*/
public function getCellByColumnAndRow($pColumn = 0, $pRow = 1)
{
$columnLetter = PHPExcel_Cell::stringFromColumnIndex($pColumn);
$coordinate = $columnLetter . $pRow;
if (!$this->_cellCollection->isDataSet($coordinate)) {