Differences Between: [Versions 400 and 402] [Versions 400 and 403]
1 <?php 2 3 namespace PhpOffice\PhpSpreadsheet\Reader\Xml; 4 5 use SimpleXMLElement; 6 7 class Style 8 { 9 /** 10 * Formats. 11 * 12 * @var array 13 */ 14 protected $styles = []; 15 16 public function parseStyles(SimpleXMLElement $xml, array $namespaces): array 17 { 18 if (!isset($xml->Styles)) { 19 return []; 20 } 21 22 $alignmentStyleParser = new Style\Alignment(); 23 $borderStyleParser = new Style\Border(); 24 $fontStyleParser = new Style\Font(); 25 $fillStyleParser = new Style\Fill(); 26 $numberFormatStyleParser = new Style\NumberFormat(); 27 28 foreach ($xml->Styles[0] as $style) { 29 $style_ss = self::getAttributes($style, $namespaces['ss']); 30 $styleID = (string) $style_ss['ID']; 31 $this->styles[$styleID] = $this->styles['Default'] ?? []; 32 33 $alignment = $border = $font = $fill = $numberFormat = []; 34 35 foreach ($style as $styleType => $styleDatax) { 36 $styleData = $styleDatax ?? new SimpleXMLElement('<xml></xml>'); 37 $styleAttributes = $styleData->attributes($namespaces['ss']); 38 39 switch ($styleType) { 40 case 'Alignment': 41 if ($styleAttributes) { 42 $alignment = $alignmentStyleParser->parseStyle($styleAttributes); 43 } 44 45 break; 46 case 'Borders': 47 $border = $borderStyleParser->parseStyle($styleData, $namespaces); 48 49 break; 50 case 'Font': 51 if ($styleAttributes) { 52 $font = $fontStyleParser->parseStyle($styleAttributes); 53 } 54 55 break; 56 case 'Interior': 57 if ($styleAttributes) { 58 $fill = $fillStyleParser->parseStyle($styleAttributes); 59 } 60 61 break; 62 case 'NumberFormat': 63 if ($styleAttributes) { 64 $numberFormat = $numberFormatStyleParser->parseStyle($styleAttributes); 65 } 66 67 break; 68 } 69 } 70 71 $this->styles[$styleID] = array_merge($alignment, $border, $font, $fill, $numberFormat); 72 } 73 74 return $this->styles; 75 } 76 77 protected static function getAttributes(?SimpleXMLElement $simple, string $node): SimpleXMLElement 78 { 79 return ($simple === null) 80 ? new SimpleXMLElement('<xml></xml>') 81 : ($simple->attributes($node) ?? new SimpleXMLElement('<xml></xml>')); 82 } 83 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body