Adding support for <text:s> inside <text:span> (fixes #666)

This commit is contained in:
Daniele De Nobili 2019-07-10 14:15:24 +02:00
parent 6c4086cf97
commit 24f81cc219

View File

@ -96,21 +96,7 @@ class CellValueFormatter
$pNodes = $node->getElementsByTagName(self::XML_NODE_P);
foreach ($pNodes as $pNode) {
$currentPValue = '';
foreach ($pNode->childNodes as $childNode) {
if ($childNode instanceof \DOMText) {
$currentPValue .= $childNode->nodeValue;
} elseif ($childNode->nodeName === self::XML_NODE_S) {
$spaceAttribute = $childNode->getAttribute(self::XML_ATTRIBUTE_C);
$numSpaces = (!empty($spaceAttribute)) ? (int) $spaceAttribute : 1;
$currentPValue .= str_repeat(' ', $numSpaces);
} elseif ($childNode->nodeName === self::XML_NODE_A || $childNode->nodeName === self::XML_NODE_SPAN) {
$currentPValue .= $childNode->nodeValue;
}
}
$pNodeValues[] = $currentPValue;
$pNodeValues[] = $this->extractTextFromNode($pNode);
}
$escapedCellValue = implode("\n", $pNodeValues);
@ -119,6 +105,29 @@ class CellValueFormatter
return $cellValue;
}
/**
* @param \DOMNode $pNode
* @return string
*/
protected function extractTextFromNode($pNode)
{
$currentPValue = '';
foreach ($pNode->childNodes as $childNode) {
if ($childNode instanceof \DOMText) {
$currentPValue .= $childNode->nodeValue;
} elseif ($childNode->nodeName === self::XML_NODE_S) {
$spaceAttribute = $childNode->getAttribute(self::XML_ATTRIBUTE_C);
$numSpaces = (!empty($spaceAttribute)) ? (int) $spaceAttribute : 1;
$currentPValue .= str_repeat(' ', $numSpaces);
} elseif ($childNode->nodeName === self::XML_NODE_A || $childNode->nodeName === self::XML_NODE_SPAN) {
$currentPValue .= $this->extractTextFromNode($childNode);
}
}
return $currentPValue;
}
/**
* Returns the cell Numeric value from the given node.
*