90 $this->font->bindParent($this);
91 $this->fill->bindParent($this);
92 $this->borders->bindParent($this);
93 $this->alignment->bindParent($this);
94 $this->numberFormat->bindParent($this);
95 $this->protection->bindParent($this);
110 if ($activeSheet->cellExists($selectedCell)) {
111 $xfIndex = $activeSheet->getCell($selectedCell)->getXfIndex();
116 return $this->
parent->getCellXfByIndex($xfIndex);
138 return [
'quotePrefix' => $array];
188 if ($this->isSupervisor) {
192 $pRange = strtoupper($pRange);
195 if (strpos($pRange,
':') ===
false) {
199 [$rangeA, $rangeB] = explode(
':', $pRange);
208 $columnStart = $rangeStart[0];
209 $columnEnd = $rangeEnd[0];
212 if ($rangeStartIndexes[0] > $rangeEndIndexes[0] && $rangeStartIndexes[1] > $rangeEndIndexes[1]) {
213 $tmp = $rangeStartIndexes;
214 $rangeStartIndexes = $rangeEndIndexes;
215 $rangeEndIndexes = $tmp;
219 if ($pAdvanced && isset($pStyles[
'borders'])) {
222 if (isset($pStyles[
'borders'][
'allBorders'])) {
223 foreach ([
'outline',
'inside'] as $component) {
224 if (!isset($pStyles[
'borders'][$component])) {
225 $pStyles[
'borders'][$component] = $pStyles[
'borders'][
'allBorders'];
228 unset($pStyles[
'borders'][
'allBorders']);
232 if (isset($pStyles[
'borders'][
'outline'])) {
233 foreach ([
'top',
'right',
'bottom',
'left'] as $component) {
234 if (!isset($pStyles[
'borders'][$component])) {
235 $pStyles[
'borders'][$component] = $pStyles[
'borders'][
'outline'];
238 unset($pStyles[
'borders'][
'outline']);
242 if (isset($pStyles[
'borders'][
'inside'])) {
243 foreach ([
'vertical',
'horizontal'] as $component) {
244 if (!isset($pStyles[
'borders'][$component])) {
245 $pStyles[
'borders'][$component] = $pStyles[
'borders'][
'inside'];
248 unset($pStyles[
'borders'][
'inside']);
251 $xMax = min($rangeEndIndexes[0] - $rangeStartIndexes[0] + 1, 3);
252 $yMax = min($rangeEndIndexes[1] - $rangeStartIndexes[1] + 1, 3);
255 for (
$x = 1;
$x <= $xMax; ++
$x) {
257 $colStart = (
$x == 3) ?
261 $colEnd = (
$x == 1) ?
265 for (
$y = 1;
$y <= $yMax; ++
$y) {
286 $rowStart = (
$y == 3) ?
287 $rangeEndIndexes[1] : $rangeStartIndexes[1] +
$y - 1;
290 $rowEnd = (
$y == 1) ?
291 $rangeStartIndexes[1] : $rangeEndIndexes[1] - $yMax +
$y;
294 $range = $colStart . $rowStart .
':' . $colEnd . $rowEnd;
297 $regionStyles = $pStyles;
298 unset($regionStyles[
'borders'][
'inside']);
301 $innerEdges = array_diff([
'top',
'right',
'bottom',
'left'], $edges);
304 foreach ($innerEdges as $innerEdge) {
305 switch ($innerEdge) {
309 if (isset($pStyles[
'borders'][
'horizontal'])) {
310 $regionStyles[
'borders'][$innerEdge] = $pStyles[
'borders'][
'horizontal'];
312 unset($regionStyles[
'borders'][$innerEdge]);
319 if (isset($pStyles[
'borders'][
'vertical'])) {
320 $regionStyles[
'borders'][$innerEdge] = $pStyles[
'borders'][
'vertical'];
322 unset($regionStyles[
'borders'][$innerEdge]);
330 $this->
getActiveSheet()->getStyle($range)->applyFromArray($regionStyles,
false);
342 if (preg_match(
'/^[A-Z]+1:[A-Z]+1048576$/', $pRange)) {
343 $selectionType =
'COLUMN';
344 } elseif (preg_match(
'/^A\d+:XFD\d+$/', $pRange)) {
345 $selectionType =
'ROW';
347 $selectionType =
'CELL';
351 $oldXfIndexes = $this->
getOldXfIndexes($selectionType, $rangeStartIndexes, $rangeEndIndexes, $columnStart, $columnEnd, $pStyles);
356 foreach ($oldXfIndexes as $oldXfIndex => $dummy) {
357 $style = $workbook->getCellXfByIndex($oldXfIndex);
359 $newStyle->applyFromArray($pStyles);
361 if ($existingStyle = $workbook->getCellXfByHashCode($newStyle->getHashCode())) {
363 $newXfIndexes[$oldXfIndex] = $existingStyle->getIndex();
366 $workbook->addCellXf($newStyle);
367 $newXfIndexes[$oldXfIndex] = $newStyle->getIndex();
372 switch ($selectionType) {
374 for ($col = $rangeStartIndexes[0]; $col <= $rangeEndIndexes[0]; ++$col) {
375 $columnDimension = $this->
getActiveSheet()->getColumnDimensionByColumn($col);
376 $oldXfIndex = $columnDimension->getXfIndex();
377 $columnDimension->setXfIndex($newXfIndexes[$oldXfIndex]);
382 for (
$row = $rangeStartIndexes[1];
$row <= $rangeEndIndexes[1]; ++
$row) {
385 $oldXfIndex = $rowDimension->getXfIndex() ?? 0;
386 $rowDimension->setXfIndex($newXfIndexes[$oldXfIndex]);
391 for ($col = $rangeStartIndexes[0]; $col <= $rangeEndIndexes[0]; ++$col) {
392 for (
$row = $rangeStartIndexes[1];
$row <= $rangeEndIndexes[1]; ++
$row) {
394 $oldXfIndex = $cell->getXfIndex();
395 $cell->setXfIndex($newXfIndexes[$oldXfIndex]);
403 if (isset($pStyles[
'fill'])) {
404 $this->
getFill()->applyFromArray($pStyles[
'fill']);
406 if (isset($pStyles[
'font'])) {
407 $this->
getFont()->applyFromArray($pStyles[
'font']);
409 if (isset($pStyles[
'borders'])) {
410 $this->
getBorders()->applyFromArray($pStyles[
'borders']);
412 if (isset($pStyles[
'alignment'])) {
413 $this->
getAlignment()->applyFromArray($pStyles[
'alignment']);
415 if (isset($pStyles[
'numberFormat'])) {
418 if (isset($pStyles[
'protection'])) {
419 $this->
getProtection()->applyFromArray($pStyles[
'protection']);
421 if (isset($pStyles[
'quotePrefix'])) {
422 $this->quotePrefix = $pStyles[
'quotePrefix'];
429 private function getOldXfIndexes(
string $selectionType, array $rangeStart, array $rangeEnd,
string $columnStart,
string $columnEnd, array $pStyles): array
432 switch ($selectionType) {
434 for ($col = $rangeStart[0]; $col <= $rangeEnd[0]; ++$col) {
435 $oldXfIndexes[$this->
getActiveSheet()->getColumnDimensionByColumn($col)->getXfIndex()] =
true;
437 foreach ($this->
getActiveSheet()->getColumnIterator($columnStart, $columnEnd) as $columnIterator) {
438 $cellIterator = $columnIterator->getCellIterator();
439 $cellIterator->setIterateOnlyExistingCells(
true);
440 foreach ($cellIterator as $columnCell) {
441 if ($columnCell !== null) {
442 $columnCell->getStyle()->applyFromArray($pStyles);
449 for (
$row = $rangeStart[1];
$row <= $rangeEnd[1]; ++
$row) {
451 $oldXfIndexes[0] =
true;
456 foreach ($this->
getActiveSheet()->getRowIterator((
int) $rangeStart[1], (
int) $rangeEnd[1]) as $rowIterator) {
457 $cellIterator = $rowIterator->getCellIterator();
458 $cellIterator->setIterateOnlyExistingCells(
true);
459 foreach ($cellIterator as $rowCell) {
460 if ($rowCell !== null) {
461 $rowCell->getStyle()->applyFromArray($pStyles);
468 for ($col = $rangeStart[0]; $col <= $rangeEnd[0]; ++$col) {
469 for (
$row = $rangeStart[1];
$row <= $rangeEnd[1]; ++
$row) {
470 $oldXfIndexes[$this->
getActiveSheet()->getCellByColumnAndRow($col,
$row)->getXfIndex()] =
true;
477 return $oldXfIndexes;
583 if ($this->isSupervisor) {
602 if ($this->isSupervisor) {
603 $styleArray = [
'quotePrefix' => $pValue];
606 $this->quotePrefix = (bool) $pValue;
620 $this->fill->getHashCode() .
621 $this->font->getHashCode() .
622 $this->borders->getHashCode() .
623 $this->alignment->getHashCode() .
624 $this->numberFormat->getHashCode() .
625 $this->protection->getHashCode() .
626 ($this->quotePrefix ?
't' :
'f') .
648 $this->index = $pValue;
662 return $exportedArray;
setConditionalStyles(array $pValue)
Set Conditional Styles.
getStyleArray($array)
Build style array from subcomponents.
setQuotePrefix($pValue)
Set quote prefix.
setIndex($pValue)
Set own index in style collection.
getActiveCell()
Get the currently active cell coordinate in currently active sheet.
applyFromArray(array $pStyles, $pAdvanced=true)
Apply styles from array.
getIndex()
Get own index in style collection.
getSelectedCells()
Get the currently active cell coordinate in currently active sheet.
getQuotePrefix()
Get quote prefix.
getProtection()
Get Protection.
getAlignment()
Get Alignment.
static indexesFromString(string $coordinates)
Get indexes from a string coordinates.
getOldXfIndexes(string $selectionType, array $rangeStart, array $rangeEnd, string $columnStart, string $columnEnd, array $pStyles)
getNumberFormat()
Get Number Format.
getHashCode()
Get hash code.
static coordinateFromString($pCoordinateString)
Coordinate from string.
getActiveSheet()
Get the currently active sheet.
setFont(Font $font)
Set font.
__construct($isSupervisor=false, $isConditional=false)
Create a new Style.
getSharedComponent()
Get the shared style component for the currently active cell in currently active sheet.
static stringFromColumnIndex($columnIndex)
String from column index.
exportArray2(array &$exportedArray, string $index, $objOrValue)
Populate array from exportArray1.
getConditionalStyles()
Get Conditional Styles.