1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpSpreadsheet\Style\ConditionalFormatting; |
4
|
|
|
|
5
|
|
|
use PhpOffice\PhpSpreadsheet\Style\Border; |
6
|
|
|
use PhpOffice\PhpSpreadsheet\Style\Borders; |
7
|
|
|
use PhpOffice\PhpSpreadsheet\Style\Fill; |
8
|
|
|
use PhpOffice\PhpSpreadsheet\Style\Font; |
9
|
|
|
use PhpOffice\PhpSpreadsheet\Style\Style; |
10
|
|
|
|
11
|
|
|
class StyleMerger |
12
|
|
|
{ |
13
|
|
|
protected Style $baseStyle; |
14
|
|
|
|
15
|
4 |
|
public function __construct(Style $baseStyle) |
16
|
|
|
{ |
17
|
4 |
|
$this->baseStyle = $baseStyle; |
18
|
|
|
} |
19
|
|
|
|
20
|
4 |
|
public function getStyle(): Style |
21
|
|
|
{ |
22
|
4 |
|
return $this->baseStyle; |
23
|
|
|
} |
24
|
|
|
|
25
|
3 |
|
public function mergeStyle(Style $style): void |
26
|
|
|
{ |
27
|
3 |
|
if ($style->getNumberFormat()->getFormatCode() !== null) { |
|
|
|
|
28
|
|
|
$this->baseStyle->getNumberFormat()->setFormatCode($style->getNumberFormat()->getFormatCode()); |
29
|
|
|
} |
30
|
|
|
$this->mergeFontStyle($this->baseStyle->getFont(), $style->getFont()); |
31
|
3 |
|
$this->mergeFillStyle($this->baseStyle->getFill(), $style->getFill()); |
32
|
3 |
|
$this->mergeBordersStyle($this->baseStyle->getBorders(), $style->getBorders()); |
33
|
|
|
} |
34
|
|
|
|
35
|
3 |
|
protected function mergeFontStyle(Font $baseFontStyle, Font $fontStyle): void |
36
|
3 |
|
{ |
37
|
|
|
if ($fontStyle->getBold() !== null) { |
38
|
|
|
$baseFontStyle->setBold($fontStyle->getBold()); |
39
|
3 |
|
} |
40
|
3 |
|
if ($fontStyle->getItalic() !== null) { |
41
|
|
|
$baseFontStyle->setItalic($fontStyle->getItalic()); |
42
|
|
|
} |
43
|
|
|
if ($fontStyle->getStrikethrough() !== null) { |
44
|
3 |
|
$baseFontStyle->setStrikethrough($fontStyle->getStrikethrough()); |
45
|
|
|
} |
46
|
3 |
|
if ($fontStyle->getUnderline() !== null) { |
47
|
|
|
$baseFontStyle->setUnderline($fontStyle->getUnderline()); |
48
|
|
|
} |
49
|
|
|
if ($fontStyle->getColor()->getARGB() !== null) { |
50
|
3 |
|
$baseFontStyle->setColor($fontStyle->getColor()); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
3 |
|
protected function mergeFillStyle(Fill $baseFillStyle, Fill $fillStyle): void |
55
|
|
|
{ |
56
|
|
|
if ($fillStyle->getFillType() !== null) { |
57
|
|
|
$baseFillStyle->setFillType($fillStyle->getFillType()); |
58
|
3 |
|
} |
59
|
|
|
$baseFillStyle->setRotation($fillStyle->getRotation()); |
60
|
|
|
if ($fillStyle->getStartColor()->getARGB() !== null) { |
61
|
|
|
$baseFillStyle->setStartColor($fillStyle->getStartColor()); |
62
|
3 |
|
} |
63
|
|
|
if ($fillStyle->getEndColor()->getARGB() !== null) { |
64
|
|
|
$baseFillStyle->setEndColor($fillStyle->getEndColor()); |
65
|
|
|
} |
66
|
|
|
} |
67
|
3 |
|
|
68
|
|
|
protected function mergeBordersStyle(Borders $baseBordersStyle, Borders $bordersStyle): void |
69
|
3 |
|
{ |
70
|
3 |
|
$this->mergeBorderStyle($baseBordersStyle->getTop(), $bordersStyle->getTop()); |
71
|
|
|
$this->mergeBorderStyle($baseBordersStyle->getBottom(), $bordersStyle->getBottom()); |
72
|
|
|
$this->mergeBorderStyle($baseBordersStyle->getLeft(), $bordersStyle->getLeft()); |
73
|
|
|
$this->mergeBorderStyle($baseBordersStyle->getRight(), $bordersStyle->getRight()); |
74
|
3 |
|
} |
75
|
|
|
|
76
|
|
|
protected function mergeBorderStyle(Border $baseBorderStyle, Border $borderStyle): void |
77
|
3 |
|
{ |
78
|
3 |
|
$baseBorderStyle->setBorderStyle($borderStyle->getBorderStyle()); |
79
|
|
|
if ($borderStyle->getColor()->getARGB() !== null) { |
80
|
|
|
$baseBorderStyle->setColor($borderStyle->getColor()); |
81
|
3 |
|
} |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|