diff --git a/src/Spout/Reader/ODS/Helper/CellValueFormatter.php b/src/Spout/Reader/ODS/Helper/CellValueFormatter.php index 50209ec..9d7a27b 100644 --- a/src/Spout/Reader/ODS/Helper/CellValueFormatter.php +++ b/src/Spout/Reader/ODS/Helper/CellValueFormatter.php @@ -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. *