29 if (isset(
$xml->DocumentProperties[0])) {
30 $docProps = $this->spreadsheet->getProperties();
32 foreach (
$xml->DocumentProperties[0] as $propertyName => $propertyValue) {
33 $propertyValue = (string) $propertyValue;
42 if (isset(
$xml->CustomDocumentProperties)) {
43 $docProps = $this->spreadsheet->getProperties();
45 foreach (
$xml->CustomDocumentProperties[0] as $propertyName => $propertyValue) {
47 $propertyName = preg_replace_callback(
'/_x([0-9a-f]{4})_/i', [$this,
'hex2str'], $propertyName);
55 DocumentProperties $docProps,
61 $docProps->setTitle($stringValue);
65 $docProps->setSubject($stringValue);
69 $docProps->setCreator($stringValue);
73 $docProps->setCreated($stringValue);
77 $docProps->setLastModifiedBy($stringValue);
81 $docProps->setModified($stringValue);
85 $docProps->setCompany($stringValue);
89 $docProps->setCategory($stringValue);
93 $docProps->setManager($stringValue);
97 $docProps->setKeywords($stringValue);
101 $docProps->setDescription($stringValue);
108 DocumentProperties $docProps,
109 string $propertyName,
110 ?SimpleXMLElement $propertyValue,
111 SimpleXMLElement $propertyAttributes
113 $propertyType = DocumentProperties::PROPERTY_TYPE_UNKNOWN;
115 switch ((
string) $propertyAttributes) {
117 $propertyType = DocumentProperties::PROPERTY_TYPE_STRING;
118 $propertyValue = trim((
string) $propertyValue);
122 $propertyType = DocumentProperties::PROPERTY_TYPE_BOOLEAN;
123 $propertyValue = (bool) $propertyValue;
127 $propertyType = DocumentProperties::PROPERTY_TYPE_INTEGER;
128 $propertyValue = (int) $propertyValue;
132 $propertyType = DocumentProperties::PROPERTY_TYPE_FLOAT;
133 $propertyValue = (float) $propertyValue;
137 $propertyType = DocumentProperties::PROPERTY_TYPE_DATE;
138 $propertyValue = trim((
string) $propertyValue);
143 $docProps->setCustomProperty($propertyName, $propertyValue, $propertyType);
146 protected function hex2str(array $hex): string
148 return mb_chr((
int) hexdec($hex[1]),
'UTF-8');
151 private static function getAttributes(?SimpleXMLElement $simple,
string $node): SimpleXMLElement
153 return ($simple ===
null)
154 ?
new SimpleXMLElement(
'<xml></xml>')
155 : ($simple->attributes($node) ??
new SimpleXMLElement(
'<xml></xml>'));
An exception for terminatinating execution or to throw for unit testing.
processStandardProperty(DocumentProperties $docProps, string $propertyName, string $stringValue)
processCustomProperty(DocumentProperties $docProps, string $propertyName, ?SimpleXMLElement $propertyValue, SimpleXMLElement $propertyAttributes)
static getAttributes(?SimpleXMLElement $simple, string $node)
readProperties(SimpleXMLElement $xml, array $namespaces)
readStandardProperties(SimpleXMLElement $xml)
__construct(Spreadsheet $spreadsheet)
readCustomProperties(SimpleXMLElement $xml, array $namespaces)