From 77de693c9f6b98e631ea9cd441bb83ab7acaa45a Mon Sep 17 00:00:00 2001 From: Mark Baker Date: Tue, 7 Sep 2010 12:04:00 +0000 Subject: [PATCH] Minor fixes to reading standard/extended properties, and reading custom properties for the Excel2003XML Reader git-svn-id: https://phpexcel.svn.codeplex.com/svn/trunk@60519 2327b42d-5241-43d6-9e2a-de5ac946f064 --- Classes/PHPExcel/Reader/Excel2003XML.php | 55 +++++++++++++++--- .../Functionality Cross-Reference.xls | Bin 35328 -> 35840 bytes 2 files changed, 46 insertions(+), 9 deletions(-) diff --git a/Classes/PHPExcel/Reader/Excel2003XML.php b/Classes/PHPExcel/Reader/Excel2003XML.php index f78579d4..70e52902 100644 --- a/Classes/PHPExcel/Reader/Excel2003XML.php +++ b/Classes/PHPExcel/Reader/Excel2003XML.php @@ -272,6 +272,11 @@ class PHPExcel_Reader_Excel2003XML implements PHPExcel_Reader_IReader return $pixels; } + + private static function _hex2str($hex) { + return chr(hexdec($hex[1])); + } + /** * Loads PHPExcel from file into PHPExcel instance * @@ -307,6 +312,9 @@ class PHPExcel_Reader_Excel2003XML implements PHPExcel_Reader_IReader PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY ); + $timezoneObj = new DateTimeZone('Europe/London'); + $GMT = new DateTimeZone('UTC'); + // Check if file exists if (!file_exists($pFilename)) { @@ -315,14 +323,7 @@ class PHPExcel_Reader_Excel2003XML implements PHPExcel_Reader_IReader $xml = simplexml_load_file($pFilename); $namespaces = $xml->getNamespaces(true); -// echo '
';
-//		print_r($namespaces);
-//		echo '

'; -// -// echo '
';
-//		print_r($xml);
-//		echo '

'; -// + $docProps = $objPHPExcel->getProperties(); foreach($xml->DocumentProperties[0] as $propertyName => $propertyValue) { switch ($propertyName) { @@ -342,12 +343,19 @@ class PHPExcel_Reader_Excel2003XML implements PHPExcel_Reader_IReader case 'LastAuthor' : $docProps->setLastModifiedBy($propertyValue); break; + case 'LastSaved' : + $lastSaveDate = strtotime($propertyValue); + $docProps->setModified($lastSaveDate); + break; case 'Company' : $docProps->setCompany($propertyValue); break; case 'Category' : $docProps->setCategory($propertyValue); break; + case 'Manager' : + $docProps->setManager($propertyValue); + break; case 'Keywords' : $docProps->setKeywords($propertyValue); break; @@ -356,7 +364,36 @@ class PHPExcel_Reader_Excel2003XML implements PHPExcel_Reader_IReader break; } } - + if (isset($xml->CustomDocumentProperties)) { + foreach($xml->CustomDocumentProperties[0] as $propertyName => $propertyValue) { + $propertyAttributes = $propertyValue->attributes($namespaces['dt']); + $propertyName = preg_replace_callback('/_x([0-9a-z]{4})_/','PHPExcel_Reader_Excel2003XML::_hex2str',$propertyName); + $propertyType = PHPExcel_DocumentProperties::PROPERTY_TYPE_UNKNOWN; + switch((string) $propertyAttributes) { + case 'string' : + $propertyType = PHPExcel_DocumentProperties::PROPERTY_TYPE_STRING; + $propertyValue = trim($propertyValue); + break; + case 'boolean' : + $propertyType = PHPExcel_DocumentProperties::PROPERTY_TYPE_BOOLEAN; + $propertyValue = (bool) $propertyValue; + break; + case 'integer' : + $propertyType = PHPExcel_DocumentProperties::PROPERTY_TYPE_INTEGER; + $propertyValue = intval($propertyValue); + break; + case 'float' : + $propertyType = PHPExcel_DocumentProperties::PROPERTY_TYPE_FLOAT; + $propertyValue = floatval($propertyValue); + break; + case 'dateTime.tz' : + $propertyType = PHPExcel_DocumentProperties::PROPERTY_TYPE_DATE; + $propertyValue = strtotime(trim($propertyValue)); + break; + } + $docProps->setCustomProperty($propertyName,$propertyValue,$propertyType); + } + } foreach($xml->Styles[0] as $style) { $style_ss = $style->attributes($namespaces['ss']); diff --git a/Documentation/Functionality Cross-Reference.xls b/Documentation/Functionality Cross-Reference.xls index a37229b0832b8b45a640119ff0fc2f54933bc0b5..fecb98eef6edcaddc829cd620256551c7e7604ef 100644 GIT binary patch delta 909 zcma)4OGs2v82--j&h5@+oVkuO<28$ND$)o{C#VeaHAD=Snl+9sB1gw0G)EmJ1<^&C zJr?F^;i96Vr6F;kRfGjakQ<>z6i9AE60D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