116 $this->_isSupervisor = $isSupervisor;
119 $this->_conditionalStyles = array();
129 $this->_font->bindParent($this);
130 $this->_fill->bindParent($this);
131 $this->_borders->bindParent($this);
132 $this->_alignment->bindParent($this);
133 $this->_numberFormat->bindParent($this);
134 $this->_protection->bindParent($this);
146 $this->_parent = $parent;
171 if ($activeSheet->cellExists($selectedCell)) {
172 $xfIndex = $activeSheet->getCell($selectedCell)->getXfIndex();
177 return $this->_parent->getCellXfByIndex($xfIndex);
187 return $this->_parent->getActiveSheet();
198 return $this->_parent->getActiveSheet()->getSelectedCells();
209 return $this->_parent->getActiveSheet()->getActiveCell();
262 if (is_array($pStyles)) {
263 if ($this->_isSupervisor) {
268 $pRange = strtoupper($pRange);
271 if (strpos($pRange,
':') ===
false) {
275 list($rangeA, $rangeB) = explode(
':', $pRange);
287 if ($rangeStart[0] > $rangeEnd[0] && $rangeStart[1] > $rangeEnd[1]) {
289 $rangeStart = $rangeEnd;
295 if ($pAdvanced && isset($pStyles[
'borders'])) {
299 if (isset($pStyles[
'borders'][
'allborders'])) {
300 foreach (array(
'outline',
'inside') as $component) {
301 if (!isset($pStyles[
'borders'][$component])) {
302 $pStyles[
'borders'][$component] = $pStyles[
'borders'][
'allborders'];
305 unset($pStyles[
'borders'][
'allborders']);
310 if (isset($pStyles[
'borders'][
'outline'])) {
311 foreach (array(
'top',
'right',
'bottom',
'left') as $component) {
312 if (!isset($pStyles[
'borders'][$component])) {
313 $pStyles[
'borders'][$component] = $pStyles[
'borders'][
'outline'];
316 unset($pStyles[
'borders'][
'outline']);
321 if (isset($pStyles[
'borders'][
'inside'])) {
322 foreach (array(
'vertical',
'horizontal') as $component) {
323 if (!isset($pStyles[
'borders'][$component])) {
324 $pStyles[
'borders'][$component] = $pStyles[
'borders'][
'inside'];
327 unset($pStyles[
'borders'][
'inside']);
331 $xMax = min($rangeEnd[0] - $rangeStart[0] + 1, 3);
332 $yMax = min($rangeEnd[1] - $rangeStart[1] + 1, 3);
335 for (
$x = 1;
$x <= $xMax; ++
$x) {
337 $colStart = (
$x == 3) ?
342 $colEnd = (
$x == 1) ?
346 for (
$y = 1;
$y <= $yMax; ++
$y) {
372 $rowStart = (
$y == 3) ?
373 $rangeEnd[1] : $rangeStart[1] +
$y - 1;
376 $rowEnd = (
$y == 1) ?
377 $rangeStart[1] : $rangeEnd[1] - $yMax +
$y;
380 $range = $colStart . $rowStart .
':' . $colEnd . $rowEnd;
383 $regionStyles = $pStyles;
384 unset($regionStyles[
'borders'][
'inside']);
387 $innerEdges = array_diff( array(
'top',
'right',
'bottom',
'left'), $edges );
390 foreach ($innerEdges as $innerEdge) {
391 switch ($innerEdge) {
395 if (isset($pStyles[
'borders'][
'horizontal'])) {
396 $regionStyles[
'borders'][$innerEdge] = $pStyles[
'borders'][
'horizontal'];
398 unset($regionStyles[
'borders'][$innerEdge]);
404 if (isset($pStyles[
'borders'][
'vertical'])) {
405 $regionStyles[
'borders'][$innerEdge] = $pStyles[
'borders'][
'vertical'];
407 unset($regionStyles[
'borders'][$innerEdge]);
414 $this->
getActiveSheet()->getStyle($range)->applyFromArray($regionStyles,
false);
423 if (preg_match(
'/^[A-Z]+1:[A-Z]+1048576$/', $pRange)) {
424 $selectionType =
'COLUMN';
425 }
else if (preg_match(
'/^A[0-9]+:XFD[0-9]+$/', $pRange)) {
426 $selectionType =
'ROW';
428 $selectionType =
'CELL';
432 switch ($selectionType) {
434 $oldXfIndexes = array();
435 for ($col = $rangeStart[0]; $col <= $rangeEnd[0]; ++$col) {
436 $oldXfIndexes[$this->
getActiveSheet()->getColumnDimensionByColumn($col)->getXfIndex()] =
true;
441 $oldXfIndexes = array();
442 for (
$row = $rangeStart[1];
$row <= $rangeEnd[1]; ++
$row) {
444 $oldXfIndexes[0] =
true;
452 $oldXfIndexes = array();
453 for ($col = $rangeStart[0]; $col <= $rangeEnd[0]; ++$col) {
454 for (
$row = $rangeStart[1];
$row <= $rangeEnd[1]; ++
$row) {
455 $oldXfIndexes[$this->
getActiveSheet()->getCellByColumnAndRow($col,
$row)->getXfIndex()] =
true;
463 foreach ($oldXfIndexes as $oldXfIndex => $dummy) {
464 $style = $workbook->getCellXfByIndex($oldXfIndex);
465 $newStyle = clone $style;
466 $newStyle->applyFromArray($pStyles);
468 if ($existingStyle = $workbook->getCellXfByHashCode($newStyle->getHashCode())) {
470 $newXfIndexes[$oldXfIndex] = $existingStyle->getIndex();
473 $workbook->addCellXf($newStyle);
474 $newXfIndexes[$oldXfIndex] = $newStyle->getIndex();
479 switch ($selectionType) {
481 for ($col = $rangeStart[0]; $col <= $rangeEnd[0]; ++$col) {
482 $columnDimension = $this->
getActiveSheet()->getColumnDimensionByColumn($col);
483 $oldXfIndex = $columnDimension->getXfIndex();
484 $columnDimension->setXfIndex($newXfIndexes[$oldXfIndex]);
489 for (
$row = $rangeStart[1];
$row <= $rangeEnd[1]; ++
$row) {
491 $oldXfIndex = $rowDimension->getXfIndex() === null ?
492 0 : $rowDimension->getXfIndex();
493 $rowDimension->setXfIndex($newXfIndexes[$oldXfIndex]);
498 for ($col = $rangeStart[0]; $col <= $rangeEnd[0]; ++$col) {
499 for (
$row = $rangeStart[1];
$row <= $rangeEnd[1]; ++
$row) {
501 $oldXfIndex = $cell->getXfIndex();
502 $cell->setXfIndex($newXfIndexes[$oldXfIndex]);
510 if (array_key_exists(
'fill', $pStyles)) {
511 $this->
getFill()->applyFromArray($pStyles[
'fill']);
513 if (array_key_exists(
'font', $pStyles)) {
514 $this->
getFont()->applyFromArray($pStyles[
'font']);
516 if (array_key_exists(
'borders', $pStyles)) {
517 $this->
getBorders()->applyFromArray($pStyles[
'borders']);
519 if (array_key_exists(
'alignment', $pStyles)) {
520 $this->
getAlignment()->applyFromArray($pStyles[
'alignment']);
522 if (array_key_exists(
'numberformat', $pStyles)) {
525 if (array_key_exists(
'protection', $pStyles)) {
526 $this->
getProtection()->applyFromArray($pStyles[
'protection']);
530 throw new Exception(
"Invalid style array passed.");
561 $this->_font = $font;
608 if (is_array($pValue)) {
629 $hashConditionals =
'';
630 foreach ($this->_conditionalStyles as $conditional) {
631 $hashConditionals .= $conditional->getHashCode();
635 $this->_fill->getHashCode()
636 . $this->_font->getHashCode()
637 . $this->_borders->getHashCode()
638 . $this->_alignment->getHashCode()
639 . $this->_numberFormat->getHashCode()
641 . $this->_protection->getHashCode()
663 $this->_index = $pValue;
670 $vars = get_object_vars($this);
671 foreach ($vars as $key => $value) {
672 if ((is_object($value)) && ($key !=
'_parent')) {
673 $this->$key = clone $value;
675 $this->$key = $value;