@@ -214,64 +214,143 @@ public function getContentXmlAutomaticStylesSectionContent($numWorksheets)
214214 */
215215 protected function getStyleSectionContent ($ style )
216216 {
217- $ defaultStyle = $ this ->getDefaultStyle ();
218217 $ styleIndex = $ style ->getId () + 1 ; // 1-based
219218
220219 $ content = '<style:style style:data-style-name="N0" style:family="table-cell" style:name="ce ' . $ styleIndex . '" style:parent-style-name="Default"> ' ;
221220
221+ $ content .= $ this ->getTextPropertiesSectionContent ($ style );
222+ $ content .= $ this ->getTableCellPropertiesSectionContent ($ style );
223+
224+ $ content .= '</style:style> ' ;
225+
226+ return $ content ;
227+ }
228+
229+ /**
230+ * Returns the contents of the "<style:text-properties>" section, inside "<style:style>" section
231+ *
232+ * @param \Box\Spout\Writer\Style\Style $style
233+ * @return string
234+ */
235+ private function getTextPropertiesSectionContent ($ style )
236+ {
237+ $ content = '' ;
238+
222239 if ($ style ->shouldApplyFont ()) {
223- $ content .= '<style:text-properties ' ;
224-
225- $ fontColor = $ style ->getFontColor ();
226- if ($ fontColor !== $ defaultStyle ->getFontColor ()) {
227- $ content .= ' fo:color="# ' . $ fontColor . '" ' ;
228- }
229-
230- $ fontName = $ style ->getFontName ();
231- if ($ fontName !== $ defaultStyle ->getFontName ()) {
232- $ content .= ' style:font-name=" ' . $ fontName . '" style:font-name-asian=" ' . $ fontName . '" style:font-name-complex=" ' . $ fontName . '" ' ;
233- }
234-
235- $ fontSize = $ style ->getFontSize ();
236- if ($ fontSize !== $ defaultStyle ->getFontSize ()) {
237- $ content .= ' fo:font-size=" ' . $ fontSize . 'pt" style:font-size-asian=" ' . $ fontSize . 'pt" style:font-size-complex=" ' . $ fontSize . 'pt" ' ;
238- }
239-
240- if ($ style ->isFontBold ()) {
241- $ content .= ' fo:font-weight="bold" style:font-weight-asian="bold" style:font-weight-complex="bold" ' ;
242- }
243- if ($ style ->isFontItalic ()) {
244- $ content .= ' fo:font-style="italic" style:font-style-asian="italic" style:font-style-complex="italic" ' ;
245- }
246- if ($ style ->isFontUnderline ()) {
247- $ content .= ' style:text-underline-style="solid" style:text-underline-type="single" ' ;
248- }
249- if ($ style ->isFontStrikethrough ()) {
250- $ content .= ' style:text-line-through-style="solid" ' ;
251- }
252-
253- $ content .= '/> ' ;
240+ $ content .= $ this ->getFontSectionContent ($ style );
241+ }
242+
243+ return $ content ;
244+ }
245+
246+ /**
247+ * Returns the contents of the "<style:text-properties>" section, inside "<style:style>" section
248+ *
249+ * @param \Box\Spout\Writer\Style\Style $style
250+ * @return string
251+ */
252+ private function getFontSectionContent ($ style )
253+ {
254+ $ defaultStyle = $ this ->getDefaultStyle ();
255+
256+ $ content = '<style:text-properties ' ;
257+
258+ $ fontColor = $ style ->getFontColor ();
259+ if ($ fontColor !== $ defaultStyle ->getFontColor ()) {
260+ $ content .= ' fo:color="# ' . $ fontColor . '" ' ;
254261 }
255262
263+ $ fontName = $ style ->getFontName ();
264+ if ($ fontName !== $ defaultStyle ->getFontName ()) {
265+ $ content .= ' style:font-name=" ' . $ fontName . '" style:font-name-asian=" ' . $ fontName . '" style:font-name-complex=" ' . $ fontName . '" ' ;
266+ }
267+
268+ $ fontSize = $ style ->getFontSize ();
269+ if ($ fontSize !== $ defaultStyle ->getFontSize ()) {
270+ $ content .= ' fo:font-size=" ' . $ fontSize . 'pt" style:font-size-asian=" ' . $ fontSize . 'pt" style:font-size-complex=" ' . $ fontSize . 'pt" ' ;
271+ }
272+
273+ if ($ style ->isFontBold ()) {
274+ $ content .= ' fo:font-weight="bold" style:font-weight-asian="bold" style:font-weight-complex="bold" ' ;
275+ }
276+ if ($ style ->isFontItalic ()) {
277+ $ content .= ' fo:font-style="italic" style:font-style-asian="italic" style:font-style-complex="italic" ' ;
278+ }
279+ if ($ style ->isFontUnderline ()) {
280+ $ content .= ' style:text-underline-style="solid" style:text-underline-type="single" ' ;
281+ }
282+ if ($ style ->isFontStrikethrough ()) {
283+ $ content .= ' style:text-line-through-style="solid" ' ;
284+ }
285+
286+ $ content .= '/> ' ;
287+
288+ return $ content ;
289+ }
290+
291+ /**
292+ * Returns the contents of the "<style:table-cell-properties>" section, inside "<style:style>" section
293+ *
294+ * @param \Box\Spout\Writer\Style\Style $style
295+ * @return string
296+ */
297+ private function getTableCellPropertiesSectionContent ($ style )
298+ {
299+ $ content = '' ;
300+
256301 if ($ style ->shouldWrapText ()) {
257- $ content .= ' <style:table-cell-properties fo:wrap-option="wrap" style:vertical-align="automatic"/> ' ;
302+ $ content .= $ this -> getWrapTextXMLContent () ;
258303 }
259304
260305 if ($ style ->shouldApplyBorder ()) {
261- $ borderProperty = '<style:table-cell-properties %s /> ' ;
262- $ borders = array_map (function (BorderPart $ borderPart ) {
263- return BorderHelper::serializeBorderPart ($ borderPart );
264- }, $ style ->getBorder ()->getParts ());
265- $ content .= sprintf ($ borderProperty , implode (' ' , $ borders ));
306+ $ content .= $ this ->getBorderXMLContent ($ style );
266307 }
267308
268309 if ($ style ->shouldApplyBackgroundColor ()) {
269- $ content .= sprintf ('
270- <style:table-cell-properties fo:background-color="#%s"/> ' , $ style ->getBackgroundColor ());
310+ $ content .= $ this ->getBackgroundColorXMLContent ($ style );
271311 }
272312
273- $ content .= '</style:style> ' ;
274-
275313 return $ content ;
276314 }
315+
316+ /**
317+ * Returns the contents of the wrap text definition for the "<style:table-cell-properties>" section
318+ *
319+ * @return string
320+ */
321+ private function getWrapTextXMLContent ()
322+ {
323+ return '<style:table-cell-properties fo:wrap-option="wrap" style:vertical-align="automatic"/> ' ;
324+ }
325+
326+ /**
327+ * Returns the contents of the borders definition for the "<style:table-cell-properties>" section
328+ *
329+ * @param \Box\Spout\Writer\Style\Style $style
330+ * @return string
331+ */
332+ private function getBorderXMLContent ($ style )
333+ {
334+ $ borderProperty = '<style:table-cell-properties %s /> ' ;
335+
336+ $ borders = array_map (function (BorderPart $ borderPart ) {
337+ return BorderHelper::serializeBorderPart ($ borderPart );
338+ }, $ style ->getBorder ()->getParts ());
339+
340+ return sprintf ($ borderProperty , implode (' ' , $ borders ));
341+ }
342+
343+ /**
344+ * Returns the contents of the background color definition for the "<style:table-cell-properties>" section
345+ *
346+ * @param \Box\Spout\Writer\Style\Style $style
347+ * @return string
348+ */
349+ private function getBackgroundColorXMLContent ($ style )
350+ {
351+ return sprintf (
352+ '<style:table-cell-properties fo:background-color="#%s"/> ' ,
353+ $ style ->getBackgroundColor ()
354+ );
355+ }
277356}
0 commit comments