9
9
10
10
namespace PhpOffice \PhpWord \Style ;
11
11
12
- use PhpOffice \PhpWord \Shared \ String ;
12
+ use PhpOffice \PhpWord \Style \ Shading ;
13
13
14
14
/**
15
15
* Table cell style
@@ -33,13 +33,6 @@ class Cell extends Border
33
33
*/
34
34
private $ textDirection ;
35
35
36
- /**
37
- * Background-Color
38
- *
39
- * @var string
40
- */
41
- private $ bgColor ;
42
-
43
36
/**
44
37
* Border Default Color
45
38
*
@@ -64,14 +57,20 @@ class Cell extends Border
64
57
*/
65
58
private $ vMerge = null ;
66
59
60
+ /**
61
+ * Shading
62
+ *
63
+ * @var \PhpOffice\PhpWord\Style\Shading
64
+ */
65
+ private $ shading ;
66
+
67
67
/**
68
68
* Create a new Cell Style
69
69
*/
70
70
public function __construct ()
71
71
{
72
72
$ this ->valign = null ;
73
73
$ this ->textDirection = null ;
74
- $ this ->bgColor = null ;
75
74
$ this ->borderTopSize = null ;
76
75
$ this ->borderTopColor = null ;
77
76
$ this ->borderLeftSize = null ;
@@ -83,24 +82,6 @@ public function __construct()
83
82
$ this ->defaultBorderColor = '000000 ' ;
84
83
}
85
84
86
- /**
87
- * Set style value
88
- *
89
- * @param string $key
90
- * @param mixed $value
91
- */
92
- public function setStyleValue ($ key , $ value )
93
- {
94
- $ key = String::removeUnderscorePrefix ($ key );
95
- if ($ key == 'borderSize ' ) {
96
- $ this ->setBorderSize ($ value );
97
- } elseif ($ key == 'borderColor ' ) {
98
- $ this ->setBorderColor ($ value );
99
- } else {
100
- $ this ->$ key = $ value ;
101
- }
102
- }
103
-
104
85
/**
105
86
* Get vertical align
106
87
*/
@@ -138,21 +119,26 @@ public function setTextDirection($pValue = null)
138
119
}
139
120
140
121
/**
141
- * Get background color
122
+ * Get background
123
+ *
124
+ * @return string
142
125
*/
143
126
public function getBgColor ()
144
127
{
145
- return $ this ->bgColor ;
128
+ if (!is_null ($ this ->shading )) {
129
+ return $ this ->shading ->getFill ();
130
+ }
146
131
}
147
132
148
133
/**
149
- * Set background color
134
+ * Set background
150
135
*
151
- * @param string $pValue
136
+ * @param string $value
137
+ * @return \PhpOffice\PhpWord\Style\Table
152
138
*/
153
- public function setBgColor ($ pValue = null )
139
+ public function setBgColor ($ value = null )
154
140
{
155
- $ this ->bgColor = $ pValue ;
141
+ $ this ->setShading ( array ( ' fill ' => $ value )) ;
156
142
}
157
143
158
144
/**
@@ -198,4 +184,34 @@ public function getVMerge()
198
184
{
199
185
return $ this ->vMerge ;
200
186
}
187
+
188
+ /**
189
+ * Get shading
190
+ *
191
+ * @return \PhpOffice\PhpWord\Style\Shading
192
+ */
193
+ public function getShading ()
194
+ {
195
+ return $ this ->shading ;
196
+ }
197
+
198
+ /**
199
+ * Set shading
200
+ *
201
+ * @param array $value
202
+ * @return self
203
+ */
204
+ public function setShading ($ value = null )
205
+ {
206
+ if (is_array ($ value )) {
207
+ if (!$ this ->shading instanceof Shading) {
208
+ $ this ->shading = new Shading ();
209
+ }
210
+ $ this ->shading ->setStyleByArray ($ value );
211
+ } else {
212
+ $ this ->shading = null ;
213
+ }
214
+
215
+ return $ this ;
216
+ }
201
217
}
0 commit comments