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:
parent
33ba87e908
commit
324fbd6ce8
|
@ -258,73 +258,106 @@ class PHPExcel_Reader_Gnumeric implements PHPExcel_Reader_IReader
|
||||||
//
|
//
|
||||||
$gnmXML = $xml->children($namespacesMeta['gnm']);
|
$gnmXML = $xml->children($namespacesMeta['gnm']);
|
||||||
|
|
||||||
$officeXML = $xml->children($namespacesMeta['office']);
|
|
||||||
$officeDocXML = $officeXML->{'document-meta'};
|
|
||||||
$officeDocMetaXML = $officeDocXML->meta;
|
|
||||||
|
|
||||||
$docProps = $objPHPExcel->getProperties();
|
$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;
|
||||||
|
|
||||||
foreach($officeDocMetaXML as $officePropertyData) {
|
foreach($officeDocMetaXML as $officePropertyData) {
|
||||||
|
|
||||||
$officePropertyDC = array();
|
$officePropertyDC = array();
|
||||||
if (isset($namespacesMeta['dc'])) {
|
if (isset($namespacesMeta['dc'])) {
|
||||||
$officePropertyDC = $officePropertyData->children($namespacesMeta['dc']);
|
$officePropertyDC = $officePropertyData->children($namespacesMeta['dc']);
|
||||||
}
|
}
|
||||||
foreach($officePropertyDC as $propertyName => $propertyValue) {
|
foreach($officePropertyDC as $propertyName => $propertyValue) {
|
||||||
$propertyValue = (string) $propertyValue;
|
$propertyValue = (string) $propertyValue;
|
||||||
switch ($propertyName) {
|
switch ($propertyName) {
|
||||||
case 'title' :
|
case 'title' :
|
||||||
$docProps->setTitle(trim($propertyValue));
|
$docProps->setTitle(trim($propertyValue));
|
||||||
break;
|
break;
|
||||||
case 'subject' :
|
case 'subject' :
|
||||||
$docProps->setSubject(trim($propertyValue));
|
$docProps->setSubject(trim($propertyValue));
|
||||||
break;
|
break;
|
||||||
case 'creator' :
|
case 'creator' :
|
||||||
$docProps->setCreator(trim($propertyValue));
|
$docProps->setCreator(trim($propertyValue));
|
||||||
$docProps->setLastModifiedBy(trim($propertyValue));
|
$docProps->setLastModifiedBy(trim($propertyValue));
|
||||||
break;
|
break;
|
||||||
case 'date' :
|
case 'date' :
|
||||||
$creationDate = strtotime(trim($propertyValue));
|
$creationDate = strtotime(trim($propertyValue));
|
||||||
$docProps->setCreated($creationDate);
|
$docProps->setCreated($creationDate);
|
||||||
$docProps->setModified($creationDate);
|
$docProps->setModified($creationDate);
|
||||||
break;
|
break;
|
||||||
case 'description' :
|
case 'description' :
|
||||||
$docProps->setDescription(trim($propertyValue));
|
$docProps->setDescription(trim($propertyValue));
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$officePropertyMeta = array();
|
||||||
|
if (isset($namespacesMeta['meta'])) {
|
||||||
|
$officePropertyMeta = $officePropertyData->children($namespacesMeta['meta']);
|
||||||
|
}
|
||||||
|
foreach($officePropertyMeta as $propertyName => $propertyValue) {
|
||||||
|
$attributes = $propertyValue->attributes($namespacesMeta['meta']);
|
||||||
|
$propertyValue = (string) $propertyValue;
|
||||||
|
switch ($propertyName) {
|
||||||
|
case 'keyword' :
|
||||||
|
$docProps->setKeywords(trim($propertyValue));
|
||||||
|
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']);
|
||||||
|
switch ($attrName) {
|
||||||
|
case 'publisher' :
|
||||||
|
$docProps->setCompany(trim($propertyValue));
|
||||||
|
break;
|
||||||
|
case 'category' :
|
||||||
|
$docProps->setCategory(trim($propertyValue));
|
||||||
|
break;
|
||||||
|
case 'manager' :
|
||||||
|
$docProps->setManager(trim($propertyValue));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$officePropertyMeta = array();
|
} elseif (isset($gnmXML->Summary)) {
|
||||||
if (isset($namespacesMeta['meta'])) {
|
foreach($gnmXML->Summary->Item as $summaryItem) {
|
||||||
$officePropertyMeta = $officePropertyData->children($namespacesMeta['meta']);
|
$propertyName = $summaryItem->name;
|
||||||
}
|
$propertyValue = $summaryItem->{'val-string'};
|
||||||
foreach($officePropertyMeta as $propertyName => $propertyValue) {
|
|
||||||
$attributes = $propertyValue->attributes($namespacesMeta['meta']);
|
|
||||||
$propertyValue = (string) $propertyValue;
|
|
||||||
switch ($propertyName) {
|
switch ($propertyName) {
|
||||||
case 'keyword' :
|
case 'title' :
|
||||||
$docProps->setKeywords(trim($propertyValue));
|
$docProps->setTitle(trim($propertyValue));
|
||||||
break;
|
break;
|
||||||
case 'initial-creator' :
|
case 'comments' :
|
||||||
$docProps->setCreator(trim($propertyValue));
|
$docProps->setDescription(trim($propertyValue));
|
||||||
break;
|
break;
|
||||||
case 'creation-date' :
|
case 'keywords' :
|
||||||
$creationDate = strtotime(trim($propertyValue));
|
$docProps->setKeywords(trim($propertyValue));
|
||||||
$docProps->setCreated($creationDate);
|
break;
|
||||||
break;
|
case 'category' :
|
||||||
case 'user-defined' :
|
$docProps->setCategory(trim($propertyValue));
|
||||||
list(,$attrName) = explode(':',$attributes['name']);
|
break;
|
||||||
switch ($attrName) {
|
case 'manager' :
|
||||||
case 'publisher' :
|
$docProps->setManager(trim($propertyValue));
|
||||||
$docProps->setCompany(trim($propertyValue));
|
break;
|
||||||
break;
|
case 'author' :
|
||||||
case 'category' :
|
$docProps->setCreator(trim($propertyValue));
|
||||||
$docProps->setCategory(trim($propertyValue));
|
$docProps->setLastModifiedBy(trim($propertyValue));
|
||||||
break;
|
break;
|
||||||
case 'manager' :
|
case 'company' :
|
||||||
$docProps->setManager(trim($propertyValue));
|
$docProps->setCompany(trim($propertyValue));
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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();
|
||||||
|
|
||||||
$RGB = self::_parseGnumericColour($borderAttributes["Color"]);
|
if (isset($borderAttributes["Color"])) {
|
||||||
$styleArray['color']['rgb'] = $RGB;
|
$RGB = self::_parseGnumericColour($borderAttributes["Color"]);
|
||||||
|
$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);
|
||||||
|
|
Loading…
Reference in New Issue