Handle variations in Gnumeric XML dependent on the version

git-svn-id: https://phpexcel.svn.codeplex.com/svn/trunk@60560 2327b42d-5241-43d6-9e2a-de5ac946f064
This commit is contained in:
Mark Baker 2010-09-08 12:06:08 +00:00
parent 33ba87e908
commit 324fbd6ce8
1 changed files with 98 additions and 64 deletions

View File

@ -258,12 +258,13 @@ class PHPExcel_Reader_Gnumeric implements PHPExcel_Reader_IReader
// //
$gnmXML = $xml->children($namespacesMeta['gnm']); $gnmXML = $xml->children($namespacesMeta['gnm']);
$docProps = $objPHPExcel->getProperties();
// Document Properties are held differently, depending on the version of Gnumeric
if (isset($namespacesMeta['office'])) {
$officeXML = $xml->children($namespacesMeta['office']); $officeXML = $xml->children($namespacesMeta['office']);
$officeDocXML = $officeXML->{'document-meta'}; $officeDocXML = $officeXML->{'document-meta'};
$officeDocMetaXML = $officeDocXML->meta; $officeDocMetaXML = $officeDocXML->meta;
$docProps = $objPHPExcel->getProperties();
foreach($officeDocMetaXML as $officePropertyData) { foreach($officeDocMetaXML as $officePropertyData) {
$officePropertyDC = array(); $officePropertyDC = array();
@ -306,10 +307,12 @@ class PHPExcel_Reader_Gnumeric implements PHPExcel_Reader_IReader
break; break;
case 'initial-creator' : case 'initial-creator' :
$docProps->setCreator(trim($propertyValue)); $docProps->setCreator(trim($propertyValue));
$docProps->setLastModifiedBy(trim($propertyValue));
break; break;
case 'creation-date' : case 'creation-date' :
$creationDate = strtotime(trim($propertyValue)); $creationDate = strtotime(trim($propertyValue));
$docProps->setCreated($creationDate); $docProps->setCreated($creationDate);
$docProps->setModified($creationDate);
break; break;
case 'user-defined' : case 'user-defined' :
list(,$attrName) = explode(':',$attributes['name']); list(,$attrName) = explode(':',$attributes['name']);
@ -328,6 +331,36 @@ class PHPExcel_Reader_Gnumeric implements PHPExcel_Reader_IReader
} }
} }
} }
} elseif (isset($gnmXML->Summary)) {
foreach($gnmXML->Summary->Item as $summaryItem) {
$propertyName = $summaryItem->name;
$propertyValue = $summaryItem->{'val-string'};
switch ($propertyName) {
case 'title' :
$docProps->setTitle(trim($propertyValue));
break;
case 'comments' :
$docProps->setDescription(trim($propertyValue));
break;
case 'keywords' :
$docProps->setKeywords(trim($propertyValue));
break;
case 'category' :
$docProps->setCategory(trim($propertyValue));
break;
case 'manager' :
$docProps->setManager(trim($propertyValue));
break;
case 'author' :
$docProps->setCreator(trim($propertyValue));
$docProps->setLastModifiedBy(trim($propertyValue));
break;
case 'company' :
$docProps->setCompany(trim($propertyValue));
break;
}
}
}
$worksheetID = 0; $worksheetID = 0;
foreach($gnmXML->Sheets->Sheet as $sheet) { foreach($gnmXML->Sheets->Sheet as $sheet) {
@ -757,8 +790,10 @@ class PHPExcel_Reader_Gnumeric implements PHPExcel_Reader_IReader
private static function _parseBorderAttributes($borderAttributes) { private static function _parseBorderAttributes($borderAttributes) {
$styleArray = array(); $styleArray = array();
if (isset($borderAttributes["Color"])) {
$RGB = self::_parseGnumericColour($borderAttributes["Color"]); $RGB = self::_parseGnumericColour($borderAttributes["Color"]);
$styleArray['color']['rgb'] = $RGB; $styleArray['color']['rgb'] = $RGB;
}
switch ($borderAttributes["Style"]) { switch ($borderAttributes["Style"]) {
case '0' : case '0' :
@ -808,7 +843,6 @@ class PHPExcel_Reader_Gnumeric implements PHPExcel_Reader_IReader
} }
private static function _parseGnumericColour($gnmColour) { private static function _parseGnumericColour($gnmColour) {
// echo 'Gnumeric Colour: ',$gnmColour,'<br />';
list($gnmR,$gnmG,$gnmB) = explode(':',$gnmColour); list($gnmR,$gnmG,$gnmB) = explode(':',$gnmColour);
$gnmR = substr(str_pad($gnmR,4,'0',STR_PAD_RIGHT),0,2); $gnmR = substr(str_pad($gnmR,4,'0',STR_PAD_RIGHT),0,2);
$gnmG = substr(str_pad($gnmG,4,'0',STR_PAD_RIGHT),0,2); $gnmG = substr(str_pad($gnmG,4,'0',STR_PAD_RIGHT),0,2);