30 if (!defined(
'PHPEXCEL_ROOT')) {
34 define(
'PHPEXCEL_ROOT', dirname(__FILE__) .
'/../');
38 require_once PHPEXCEL_ROOT .
'PHPExcel/Style/Color.php';
41 require_once PHPEXCEL_ROOT .
'PHPExcel/Style/Font.php';
44 require_once PHPEXCEL_ROOT .
'PHPExcel/Style/Fill.php';
47 require_once PHPEXCEL_ROOT .
'PHPExcel/Style/Borders.php';
50 require_once PHPEXCEL_ROOT .
'PHPExcel/Style/Alignment.php';
53 require_once PHPEXCEL_ROOT .
'PHPExcel/Style/NumberFormat.php';
56 require_once PHPEXCEL_ROOT .
'PHPExcel/Style/Conditional.php';
59 require_once PHPEXCEL_ROOT .
'PHPExcel/Style/Protection.php';
62 require_once PHPEXCEL_ROOT .
'PHPExcel/IComparable.php';
151 $this->_isSupervisor = $isSupervisor;
154 $this->_conditionalStyles = array();
164 $this->_font->bindParent($this);
165 $this->_fill->bindParent($this);
166 $this->_borders->bindParent($this);
167 $this->_alignment->bindParent($this);
168 $this->_numberFormat->bindParent($this);
169 $this->_protection->bindParent($this);
181 $this->_parent = $parent;
206 if ($activeSheet->cellExists($selectedCell)) {
207 $cell = $activeSheet->getCell($selectedCell);
208 $xfIndex = $cell->getXfIndex();
213 $activeStyle = $this->_parent->getCellXfByIndex($xfIndex);
224 return $this->_parent->getActiveSheet();
235 return $this->_parent->getActiveSheet()->getXSelectedCells();
246 return $this->_parent->getActiveSheet()->getXActiveCell();
299 if (is_array($pStyles)) {
300 if ($this->_isSupervisor) {
304 if (is_array($pStyles)) {
306 $pRange = strtoupper($pRange);
311 if (strpos($pRange,
':') ===
false) {
315 list($rangeA, $rangeB) = explode(
':', $pRange);
327 if ($rangeStart[0] > $rangeEnd[0] && $rangeStart[1] > $rangeEnd[1]) {
329 $rangeStart = $rangeEnd;
334 if ($pAdvanced && isset($pStyles[
'borders'])) {
338 if (isset($pStyles[
'borders'][
'allborders'])) {
339 foreach (array(
'outline',
'inside') as $component) {
340 if (!isset($pStyles[
'borders'][$component])) {
341 $pStyles[
'borders'][$component] = $pStyles[
'borders'][
'allborders'];
344 unset($pStyles[
'borders'][
'allborders']);
349 if (isset($pStyles[
'borders'][
'outline'])) {
350 foreach (array(
'top',
'right',
'bottom',
'left') as $component) {
351 if (!isset($pStyles[
'borders'][$component])) {
352 $pStyles[
'borders'][$component] = $pStyles[
'borders'][
'outline'];
355 unset($pStyles[
'borders'][
'outline']);
360 if (isset($pStyles[
'borders'][
'inside'])) {
361 foreach (array(
'vertical',
'horizontal') as $component) {
362 if (!isset($pStyles[
'borders'][$component])) {
363 $pStyles[
'borders'][$component] = $pStyles[
'borders'][
'inside'];
366 unset($pStyles[
'borders'][
'inside']);
370 $xMax = min($rangeEnd[0] - $rangeStart[0] + 1, 3);
371 $yMax = min($rangeEnd[1] - $rangeStart[1] + 1, 3);
374 for (
$x = 1;
$x <= $xMax; ++
$x) {
376 $colStart = (
$x == 3) ?
381 $colEnd = (
$x == 1) ?
385 for (
$y = 1;
$y <= $yMax; ++
$y) {
411 $rowStart = (
$y == 3) ?
412 $rangeEnd[1] : $rangeStart[1] +
$y - 1;
415 $rowEnd = (
$y == 1) ?
416 $rangeStart[1] : $rangeEnd[1] - $yMax +
$y;
419 $range = $colStart . $rowStart .
':' . $colEnd . $rowEnd;
422 $regionStyles = $pStyles;
423 unset($regionStyles[
'borders'][
'inside']);
426 $innerEdges = array_diff( array(
'top',
'right',
'bottom',
'left'), $edges );
429 foreach ($innerEdges as $innerEdge) {
430 switch ($innerEdge) {
434 if (isset($pStyles[
'borders'][
'horizontal'])) {
435 $regionStyles[
'borders'][$innerEdge] = $pStyles[
'borders'][
'horizontal'];
437 unset($regionStyles[
'borders'][$innerEdge]);
443 if (isset($pStyles[
'borders'][
'vertical'])) {
444 $regionStyles[
'borders'][$innerEdge] = $pStyles[
'borders'][
'vertical'];
446 unset($regionStyles[
'borders'][$innerEdge]);
453 $this->
getActiveSheet()->getStyle($range)->applyFromArray($regionStyles,
false);
462 $oldXfIndexes = array();
463 for ($col = $rangeStart[0]; $col <= $rangeEnd[0]; ++$col) {
464 for (
$row = $rangeStart[1];
$row <= $rangeEnd[1]; ++
$row) {
465 $oldXfIndexes[$this->
getActiveSheet()->getCellByColumnAndRow($col,
$row)->getXfIndex()] =
true;
471 foreach ($oldXfIndexes as $oldXfIndex => $dummy) {
472 $style = $workbook->getCellXfByIndex($oldXfIndex);
473 $newStyle = clone $style;
474 $newStyle->applyFromArray($pStyles);
476 if ($existingStyle = $workbook->getCellXfByHashCode($newStyle->getHashCode())) {
478 $newXfIndexes[$oldXfIndex] = $existingStyle->getIndex();
481 $workbook->addCellXf($newStyle);
482 $newXfIndexes[$oldXfIndex] = $newStyle->getIndex();
487 for ($col = $rangeStart[0]; $col <= $rangeEnd[0]; ++$col) {
488 for (
$row = $rangeStart[1];
$row <= $rangeEnd[1]; ++
$row) {
490 $oldXfIndex = $cell->getXfIndex();
491 $cell->setXfIndex($newXfIndexes[$oldXfIndex]);
496 throw new Exception(
"Invalid style array passed.");
500 if (array_key_exists(
'fill', $pStyles)) {
501 $this->
getFill()->applyFromArray($pStyles[
'fill']);
503 if (array_key_exists(
'font', $pStyles)) {
504 $this->
getFont()->applyFromArray($pStyles[
'font']);
506 if (array_key_exists(
'borders', $pStyles)) {
507 $this->
getBorders()->applyFromArray($pStyles[
'borders']);
509 if (array_key_exists(
'alignment', $pStyles)) {
510 $this->
getAlignment()->applyFromArray($pStyles[
'alignment']);
512 if (array_key_exists(
'numberformat', $pStyles)) {
515 if (array_key_exists(
'protection', $pStyles)) {
516 $this->
getProtection()->applyFromArray($pStyles[
'protection']);
520 throw new Exception(
"Invalid style array passed.");
551 $this->_font = $font;
598 if (is_array($pValue)) {
600 $this->
getActiveSheet()->setConditionalStyles($cellReference, $pValue);
621 $hashConditionals =
'';
622 foreach ($this->_conditionalStyles as $conditional) {
623 $hashConditionals .= $conditional->getHashCode();
666 $this->_hashIndex = $value;
686 $this->_index = $pValue;
693 $vars = get_object_vars($this);
694 foreach ($vars as
$key => $value) {
695 if (is_object($value)) {
696 $this->
$key = clone $value;
698 $this->
$key = $value;