See Release Notes
Long Term Support Release
Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401] [Versions 401 and 402] [Versions 401 and 403]
1 <?php 2 3 namespace PhpOffice\PhpSpreadsheet\Reader\Ods; 4 5 use PhpOffice\PhpSpreadsheet\Document\Properties as DocumentProperties; 6 use PhpOffice\PhpSpreadsheet\Spreadsheet; 7 use SimpleXMLElement; 8 9 class Properties 10 { 11 private $spreadsheet; 12 13 public function __construct(Spreadsheet $spreadsheet) 14 { 15 $this->spreadsheet = $spreadsheet; 16 } 17 18 public function load(SimpleXMLElement $xml, $namespacesMeta): void 19 { 20 $docProps = $this->spreadsheet->getProperties(); 21 $officeProperty = $xml->children($namespacesMeta['office']); 22 foreach ($officeProperty as $officePropertyData) { 23 // @var \SimpleXMLElement $officePropertyData 24 if (isset($namespacesMeta['dc'])) { 25 $officePropertiesDC = $officePropertyData->children($namespacesMeta['dc']); 26 $this->setCoreProperties($docProps, $officePropertiesDC); 27 } 28 29 $officePropertyMeta = null; 30 if (isset($namespacesMeta['dc'])) { 31 $officePropertyMeta = $officePropertyData->children($namespacesMeta['meta']); 32 } 33 $officePropertyMeta = $officePropertyMeta ?? []; 34 foreach ($officePropertyMeta as $propertyName => $propertyValue) { 35 $this->setMetaProperties($namespacesMeta, $propertyValue, $propertyName, $docProps); 36 } 37 } 38 } 39 40 private function setCoreProperties(DocumentProperties $docProps, SimpleXMLElement $officePropertyDC): void 41 { 42 foreach ($officePropertyDC as $propertyName => $propertyValue) { 43 $propertyValue = (string) $propertyValue; 44 switch ($propertyName) { 45 case 'title': 46 $docProps->setTitle($propertyValue); 47 48 break; 49 case 'subject': 50 $docProps->setSubject($propertyValue); 51 52 break; 53 case 'creator': 54 $docProps->setCreator($propertyValue); 55 $docProps->setLastModifiedBy($propertyValue); 56 57 break; 58 case 'date': 59 $docProps->setModified($propertyValue); 60 61 break; 62 case 'description': 63 $docProps->setDescription($propertyValue); 64 65 break; 66 } 67 } 68 } 69 70 private function setMetaProperties( 71 $namespacesMeta, 72 SimpleXMLElement $propertyValue, 73 $propertyName, 74 DocumentProperties $docProps 75 ): void { 76 $propertyValueAttributes = $propertyValue->attributes($namespacesMeta['meta']); 77 $propertyValue = (string) $propertyValue; 78 switch ($propertyName) { 79 case 'initial-creator': 80 $docProps->setCreator($propertyValue); 81 82 break; 83 case 'keyword': 84 $docProps->setKeywords($propertyValue); 85 86 break; 87 case 'creation-date': 88 $docProps->setCreated($propertyValue); 89 90 break; 91 case 'user-defined': 92 $this->setUserDefinedProperty($propertyValueAttributes, $propertyValue, $docProps); 93 94 break; 95 } 96 } 97 98 private function setUserDefinedProperty($propertyValueAttributes, $propertyValue, DocumentProperties $docProps): void 99 { 100 $propertyValueName = ''; 101 $propertyValueType = DocumentProperties::PROPERTY_TYPE_STRING; 102 foreach ($propertyValueAttributes as $key => $value) { 103 if ($key == 'name') { 104 $propertyValueName = (string) $value; 105 } elseif ($key == 'value-type') { 106 switch ($value) { 107 case 'date': 108 $propertyValue = DocumentProperties::convertProperty($propertyValue, 'date'); 109 $propertyValueType = DocumentProperties::PROPERTY_TYPE_DATE; 110 111 break; 112 case 'boolean': 113 $propertyValue = DocumentProperties::convertProperty($propertyValue, 'bool'); 114 $propertyValueType = DocumentProperties::PROPERTY_TYPE_BOOLEAN; 115 116 break; 117 case 'float': 118 $propertyValue = DocumentProperties::convertProperty($propertyValue, 'r4'); 119 $propertyValueType = DocumentProperties::PROPERTY_TYPE_FLOAT; 120 121 break; 122 default: 123 $propertyValueType = DocumentProperties::PROPERTY_TYPE_STRING; 124 } 125 } 126 } 127 128 $docProps->setCustomProperty($propertyValueName, $propertyValue, $propertyValueType); 129 } 130 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body