[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 3 namespace Box\Spout\Writer\XLSX\Helper; 4 5 use Box\Spout\Writer\Common\Helper\AbstractStyleHelper; 6 use Box\Spout\Writer\Style\Color; 7 8 /** 9 * Class StyleHelper 10 * This class provides helper functions to manage styles 11 * 12 * @package Box\Spout\Writer\XLSX\Helper 13 */ 14 class StyleHelper extends AbstractStyleHelper 15 { 16 /** 17 * Returns the content of the "styles.xml" file, given a list of styles. 18 * 19 * @return string 20 */ 21 public function getStylesXMLFileContent() 22 { 23 $content = <<<EOD 24 <?xml version="1.0" encoding="UTF-8" standalone="yes"?> 25 <styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"> 26 EOD; 27 28 $content .= $this->getFontsSectionContent(); 29 $content .= $this->getFillsSectionContent(); 30 $content .= $this->getBordersSectionContent(); 31 $content .= $this->getCellStyleXfsSectionContent(); 32 $content .= $this->getCellXfsSectionContent(); 33 $content .= $this->getCellStylesSectionContent(); 34 35 $content .= <<<EOD 36 </styleSheet> 37 EOD; 38 39 return $content; 40 } 41 42 /** 43 * Returns the content of the "<fonts>" section. 44 * 45 * @return string 46 */ 47 protected function getFontsSectionContent() 48 { 49 $content = '<fonts count="' . count($this->styleIdToStyleMappingTable) . '">'; 50 51 /** @var \Box\Spout\Writer\Style\Style $style */ 52 foreach ($this->getRegisteredStyles() as $style) { 53 $content .= '<font>'; 54 55 $content .= '<sz val="' . $style->getFontSize() . '"/>'; 56 $content .= '<color rgb="' . Color::toARGB($style->getFontColor()) . '"/>'; 57 $content .= '<name val="' . $style->getFontName() . '"/>'; 58 59 if ($style->isFontBold()) { 60 $content .= '<b/>'; 61 } 62 if ($style->isFontItalic()) { 63 $content .= '<i/>'; 64 } 65 if ($style->isFontUnderline()) { 66 $content .= '<u/>'; 67 } 68 if ($style->isFontStrikethrough()) { 69 $content .= '<strike/>'; 70 } 71 72 $content .= '</font>'; 73 } 74 75 $content .= '</fonts>'; 76 77 return $content; 78 } 79 80 /** 81 * Returns the content of the "<fills>" section. 82 * 83 * @return string 84 */ 85 protected function getFillsSectionContent() 86 { 87 return <<<EOD 88 <fills count="1"> 89 <fill> 90 <patternFill patternType="none"/> 91 </fill> 92 </fills> 93 EOD; 94 } 95 96 /** 97 * Returns the content of the "<borders>" section. 98 * 99 * @return string 100 */ 101 protected function getBordersSectionContent() 102 { 103 return <<<EOD 104 <borders count="1"> 105 <border> 106 <left/> 107 <right/> 108 <top/> 109 <bottom/> 110 <diagonal/> 111 </border> 112 </borders> 113 EOD; 114 } 115 116 /** 117 * Returns the content of the "<cellStyleXfs>" section. 118 * 119 * @return string 120 */ 121 protected function getCellStyleXfsSectionContent() 122 { 123 return <<<EOD 124 <cellStyleXfs count="1"> 125 <xf borderId="0" fillId="0" fontId="0" numFmtId="0"/> 126 </cellStyleXfs> 127 EOD; 128 } 129 130 /** 131 * Returns the content of the "<cellXfs>" section. 132 * 133 * @return string 134 */ 135 protected function getCellXfsSectionContent() 136 { 137 $registeredStyles = $this->getRegisteredStyles(); 138 139 $content = '<cellXfs count="' . count($registeredStyles) . '">'; 140 141 foreach ($registeredStyles as $style) { 142 $content .= '<xf numFmtId="0" fontId="' . $style->getId() . '" fillId="0" borderId="0" xfId="0"'; 143 144 if ($style->shouldApplyFont()) { 145 $content .= ' applyFont="1"'; 146 } 147 148 if ($style->shouldWrapText()) { 149 $content .= ' applyAlignment="1">'; 150 $content .= '<alignment wrapText="1"/>'; 151 $content .= '</xf>'; 152 } else { 153 $content .= '/>'; 154 } 155 } 156 157 $content .= '</cellXfs>'; 158 159 return $content; 160 } 161 162 /** 163 * Returns the content of the "<cellStyles>" section. 164 * 165 * @return string 166 */ 167 protected function getCellStylesSectionContent() 168 { 169 return <<<EOD 170 <cellStyles count="1"> 171 <cellStyle builtinId="0" name="Normal" xfId="0"/> 172 </cellStyles> 173 EOD; 174 } 175 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |