1 | <?php |
||
11 | abstract class StyleHelperAbstract implements StyleHelperInterface |
||
12 | { |
||
13 | /** @var array [SERIALIZED_STYLE] => [STYLE_ID] mapping table, keeping track of the registered styles */ |
||
14 | protected $serializedStyleToStyleIdMappingTable = []; |
||
15 | |||
16 | /** @var array [STYLE_ID] => [STYLE] mapping table, keeping track of the registered styles */ |
||
17 | protected $styleIdToStyleMappingTable = []; |
||
18 | |||
19 | /** |
||
20 | * @param \Box\Spout\Writer\Style\Style $defaultStyle |
||
21 | */ |
||
22 | 98 | public function __construct($defaultStyle) |
|
27 | |||
28 | /** |
||
29 | * Registers the given style as a used style. |
||
30 | * Duplicate styles won't be registered more than once. |
||
31 | * |
||
32 | * @param \Box\Spout\Writer\Style\Style $style The style to be registered |
||
33 | * @return \Box\Spout\Writer\Style\Style The registered style, updated with an internal ID. |
||
34 | */ |
||
35 | 98 | public function registerStyle($style) |
|
49 | |||
50 | /** |
||
51 | * Returns whether the given style has already been registered. |
||
52 | * |
||
53 | * @param \Box\Spout\Writer\Style\Style $style |
||
54 | * @return bool |
||
55 | */ |
||
56 | 98 | protected function hasStyleAlreadyBeenRegistered($style) |
|
63 | |||
64 | /** |
||
65 | * Returns the registered style associated to the given serialization. |
||
66 | * |
||
67 | * @param string $serializedStyle The serialized style from which the actual style should be fetched from |
||
68 | * @return \Box\Spout\Writer\Style\Style |
||
69 | */ |
||
70 | 98 | protected function getStyleFromSerializedStyle($serializedStyle) |
|
75 | |||
76 | /** |
||
77 | * @return \Box\Spout\Writer\Style\Style[] List of registered styles |
||
78 | */ |
||
79 | 70 | protected function getRegisteredStyles() |
|
83 | |||
84 | /** |
||
85 | * Returns the default style |
||
86 | * |
||
87 | * @return \Box\Spout\Writer\Style\Style Default style |
||
88 | */ |
||
89 | 34 | protected function getDefaultStyle() |
|
94 | |||
95 | /** |
||
96 | * Apply additional styles if the given row needs it. |
||
97 | * Typically, set "wrap text" if a cell contains a new line. |
||
98 | * |
||
99 | * @param \Box\Spout\Writer\Style\Style $style The original style |
||
100 | * @param array $dataRow The row the style will be applied to |
||
101 | * @return \Box\Spout\Writer\Style\Style The updated style |
||
102 | */ |
||
103 | 68 | public function applyExtraStylesIfNeeded($style, $dataRow) |
|
108 | |||
109 | /** |
||
110 | * Set the "wrap text" option if a cell of the given row contains a new line. |
||
111 | * |
||
112 | * @NOTE: There is a bug on the Mac version of Excel (2011 and below) where new lines |
||
113 | * are ignored even when the "wrap text" option is set. This only occurs with |
||
114 | * inline strings (shared strings do work fine). |
||
115 | * A workaround would be to encode "\n" as "_x000D_" but it does not work |
||
116 | * on the Windows version of Excel... |
||
117 | * |
||
118 | * @param \Box\Spout\Writer\Style\Style $style The original style |
||
119 | * @param array $dataRow The row the style will be applied to |
||
120 | * @return \Box\Spout\Writer\Style\Style The eventually updated style |
||
121 | */ |
||
122 | 68 | protected function applyWrapTextIfCellContainsNewLine($style, $dataRow) |
|
138 | } |
||
139 |