111 public function __construct($isSupervisor =
false, $isConditional =
false)
114 $this->_isSupervisor = $isSupervisor;
117 $this->_conditionalStyles = array();
127 $this->_font->bindParent($this);
128 $this->_fill->bindParent($this);
129 $this->_borders->bindParent($this);
130 $this->_alignment->bindParent($this);
131 $this->_numberFormat->bindParent($this);
132 $this->_protection->bindParent($this);
147 if ($activeSheet->cellExists($selectedCell)) {
148 $xfIndex = $activeSheet->getCell($selectedCell)->getXfIndex();
153 return $this->_parent->getCellXfByIndex($xfIndex);
174 return array(
'quotePrefix' => $array);
219 if (is_array($pStyles)) {
220 if ($this->_isSupervisor) {
225 $pRange = strtoupper($pRange);
228 if (strpos($pRange,
':') ===
false) {
232 list($rangeA, $rangeB) = explode(
':', $pRange);
244 if ($rangeStart[0] > $rangeEnd[0] && $rangeStart[1] > $rangeEnd[1]) {
246 $rangeStart = $rangeEnd;
252 if ($pAdvanced && isset($pStyles[
'borders'])) {
256 if (isset($pStyles[
'borders'][
'allborders'])) {
257 foreach (array(
'outline',
'inside') as $component) {
258 if (!isset($pStyles[
'borders'][$component])) {
259 $pStyles[
'borders'][$component] = $pStyles[
'borders'][
'allborders'];
262 unset($pStyles[
'borders'][
'allborders']);
267 if (isset($pStyles[
'borders'][
'outline'])) {
268 foreach (array(
'top',
'right',
'bottom',
'left') as $component) {
269 if (!isset($pStyles[
'borders'][$component])) {
270 $pStyles[
'borders'][$component] = $pStyles[
'borders'][
'outline'];
273 unset($pStyles[
'borders'][
'outline']);
278 if (isset($pStyles[
'borders'][
'inside'])) {
279 foreach (array(
'vertical',
'horizontal') as $component) {
280 if (!isset($pStyles[
'borders'][$component])) {
281 $pStyles[
'borders'][$component] = $pStyles[
'borders'][
'inside'];
284 unset($pStyles[
'borders'][
'inside']);
288 $xMax = min($rangeEnd[0] - $rangeStart[0] + 1, 3);
289 $yMax = min($rangeEnd[1] - $rangeStart[1] + 1, 3);
292 for (
$x = 1;
$x <= $xMax; ++
$x) {
294 $colStart = (
$x == 3) ?
299 $colEnd = (
$x == 1) ?
303 for (
$y = 1;
$y <= $yMax; ++
$y) {
329 $rowStart = (
$y == 3) ?
330 $rangeEnd[1] : $rangeStart[1] +
$y - 1;
333 $rowEnd = (
$y == 1) ?
334 $rangeStart[1] : $rangeEnd[1] - $yMax +
$y;
337 $range = $colStart . $rowStart .
':' . $colEnd . $rowEnd;
340 $regionStyles = $pStyles;
341 unset($regionStyles[
'borders'][
'inside']);
344 $innerEdges = array_diff( array(
'top',
'right',
'bottom',
'left'), $edges );
347 foreach ($innerEdges as $innerEdge) {
348 switch ($innerEdge) {
352 if (isset($pStyles[
'borders'][
'horizontal'])) {
353 $regionStyles[
'borders'][$innerEdge] = $pStyles[
'borders'][
'horizontal'];
355 unset($regionStyles[
'borders'][$innerEdge]);
361 if (isset($pStyles[
'borders'][
'vertical'])) {
362 $regionStyles[
'borders'][$innerEdge] = $pStyles[
'borders'][
'vertical'];
364 unset($regionStyles[
'borders'][$innerEdge]);
371 $this->
getActiveSheet()->getStyle($range)->applyFromArray($regionStyles,
false);
380 if (preg_match(
'/^[A-Z]+1:[A-Z]+1048576$/', $pRange)) {
381 $selectionType =
'COLUMN';
382 }
else if (preg_match(
'/^A[0-9]+:XFD[0-9]+$/', $pRange)) {
383 $selectionType =
'ROW';
385 $selectionType =
'CELL';
389 switch ($selectionType) {
391 $oldXfIndexes = array();
392 for ($col = $rangeStart[0]; $col <= $rangeEnd[0]; ++$col) {
393 $oldXfIndexes[$this->
getActiveSheet()->getColumnDimensionByColumn($col)->getXfIndex()] =
true;
398 $oldXfIndexes = array();
399 for (
$row = $rangeStart[1];
$row <= $rangeEnd[1]; ++
$row) {
401 $oldXfIndexes[0] =
true;
409 $oldXfIndexes = array();
410 for ($col = $rangeStart[0]; $col <= $rangeEnd[0]; ++$col) {
411 for (
$row = $rangeStart[1];
$row <= $rangeEnd[1]; ++
$row) {
412 $oldXfIndexes[$this->
getActiveSheet()->getCellByColumnAndRow($col,
$row)->getXfIndex()] =
true;
420 foreach ($oldXfIndexes as $oldXfIndex => $dummy) {
421 $style = $workbook->getCellXfByIndex($oldXfIndex);
423 $newStyle->applyFromArray($pStyles);
425 if ($existingStyle = $workbook->getCellXfByHashCode($newStyle->getHashCode())) {
427 $newXfIndexes[$oldXfIndex] = $existingStyle->getIndex();
430 $workbook->addCellXf($newStyle);
431 $newXfIndexes[$oldXfIndex] = $newStyle->getIndex();
436 switch ($selectionType) {
438 for ($col = $rangeStart[0]; $col <= $rangeEnd[0]; ++$col) {
439 $columnDimension = $this->
getActiveSheet()->getColumnDimensionByColumn($col);
440 $oldXfIndex = $columnDimension->getXfIndex();
441 $columnDimension->setXfIndex($newXfIndexes[$oldXfIndex]);
446 for (
$row = $rangeStart[1];
$row <= $rangeEnd[1]; ++
$row) {
448 $oldXfIndex = $rowDimension->getXfIndex() ===
null ?
449 0 : $rowDimension->getXfIndex();
450 $rowDimension->setXfIndex($newXfIndexes[$oldXfIndex]);
455 for ($col = $rangeStart[0]; $col <= $rangeEnd[0]; ++$col) {
456 for (
$row = $rangeStart[1];
$row <= $rangeEnd[1]; ++
$row) {
458 $oldXfIndex = $cell->getXfIndex();
459 $cell->setXfIndex($newXfIndexes[$oldXfIndex]);
467 if (array_key_exists(
'fill', $pStyles)) {
468 $this->
getFill()->applyFromArray($pStyles[
'fill']);
470 if (array_key_exists(
'font', $pStyles)) {
471 $this->
getFont()->applyFromArray($pStyles[
'font']);
473 if (array_key_exists(
'borders', $pStyles)) {
474 $this->
getBorders()->applyFromArray($pStyles[
'borders']);
476 if (array_key_exists(
'alignment', $pStyles)) {
477 $this->
getAlignment()->applyFromArray($pStyles[
'alignment']);
479 if (array_key_exists(
'numberformat', $pStyles)) {
482 if (array_key_exists(
'protection', $pStyles)) {
483 $this->
getProtection()->applyFromArray($pStyles[
'protection']);
485 if (array_key_exists(
'quotePrefix', $pStyles)) {
486 $this->_quotePrefix = $pStyles[
'quotePrefix'];
523 $this->_font = $font;
575 if (is_array($pValue)) {
598 if ($this->_isSupervisor) {
614 if ($this->_isSupervisor) {
615 $styleArray = array(
'quotePrefix' => $pValue);
618 $this->_quotePrefix = (boolean) $pValue;
630 $hashConditionals =
'';
631 foreach ($this->_conditionalStyles as $conditional) {
632 $hashConditionals .= $conditional->getHashCode();
636 $this->_fill->getHashCode()
637 . $this->_font->getHashCode()
638 . $this->_borders->getHashCode()
639 . $this->_alignment->getHashCode()
640 . $this->_numberFormat->getHashCode()
642 . $this->_protection->getHashCode()
643 . ($this->_quotePrefix ?
't' :
'f')
665 $this->_index = $pValue;
An exception for terminatinating execution or to throw for unit testing.
static stringFromColumnIndex($pColumnIndex=0)
String from columnindex.
static coordinateFromString($pCoordinateString='A1')
Coordinate from string.
static columnIndexFromString($pString='A')
Column index from string.
getActiveSheet()
Get the currently active sheet.
getActiveCell()
Get the currently active cell coordinate in currently active sheet.
getSelectedCells()
Get the currently active cell coordinate in currently active sheet.
setConditionalStyles($pValue=null)
Set Conditional Styles.
applyFromArray($pStyles=null, $pAdvanced=true)
Apply styles from array.
setIndex($pValue)
Set own index in style collection.
getNumberFormat()
Get Number Format.
getSharedComponent()
Get the shared style component for the currently active cell in currently active sheet.
getQuotePrefix()
Get quote prefix.
setFont(PHPExcel_Style_Font $font)
Set font.
getConditionalStyles()
Get Conditional Styles.
getHashCode()
Get hash code.
__construct($isSupervisor=false, $isConditional=false)
Create a new PHPExcel_Style.
getProtection()
Get Protection.
getIndex()
Get own index in style collection.
setQuotePrefix($pValue)
Set quote prefix.
getAlignment()
Get Alignment.
getStyleArray($array)
Build style array from subcomponents.