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']);
$docProps = $objPHPExcel->getProperties();
// Document Properties are held differently, depending on the version of Gnumeric
if (isset($namespacesMeta['office'])) {
$officeXML = $xml->children($namespacesMeta['office']);
$officeDocXML = $officeXML->{'document-meta'};
$officeDocMetaXML = $officeDocXML->meta;
$docProps = $objPHPExcel->getProperties();
foreach($officeDocMetaXML as $officePropertyData) {
$officePropertyDC = array();
@ -306,10 +307,12 @@ class PHPExcel_Reader_Gnumeric implements PHPExcel_Reader_IReader
break;
case 'initial-creator' :
$docProps->setCreator(trim($propertyValue));
$docProps->setLastModifiedBy(trim($propertyValue));
break;
case 'creation-date' :
$creationDate = strtotime(trim($propertyValue));
$docProps->setCreated($creationDate);
$docProps->setModified($creationDate);
break;
case 'user-defined' :
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;
foreach($gnmXML->Sheets->Sheet as $sheet) {
@ -757,8 +790,10 @@ class PHPExcel_Reader_Gnumeric implements PHPExcel_Reader_IReader
private static function _parseBorderAttributes($borderAttributes) {
$styleArray = array();
if (isset($borderAttributes["Color"])) {
$RGB = self::_parseGnumericColour($borderAttributes["Color"]);
$styleArray['color']['rgb'] = $RGB;
}
switch ($borderAttributes["Style"]) {
case '0' :
@ -808,7 +843,6 @@ class PHPExcel_Reader_Gnumeric implements PHPExcel_Reader_IReader
}
private static function _parseGnumericColour($gnmColour) {
// echo 'Gnumeric Colour: ',$gnmColour,'<br />';
list($gnmR,$gnmG,$gnmB) = explode(':',$gnmColour);
$gnmR = substr(str_pad($gnmR,4,'0',STR_PAD_RIGHT),0,2);
$gnmG = substr(str_pad($gnmG,4,'0',STR_PAD_RIGHT),0,2);