diff --git a/src/Spout/Reader/ODS/Helper/CellValueFormatter.php b/src/Spout/Reader/ODS/Helper/CellValueFormatter.php index bd21576..3eb1918 100644 --- a/src/Spout/Reader/ODS/Helper/CellValueFormatter.php +++ b/src/Spout/Reader/ODS/Helper/CellValueFormatter.php @@ -23,6 +23,7 @@ class CellValueFormatter /** Definition of XML nodes names used to parse data */ const XML_NODE_P = 'p'; const XML_NODE_S = 'text:s'; + const XML_NODE_A = 'text:a'; /** Definition of XML attribute used to parse data */ const XML_ATTRIBUTE_TYPE = 'office:value-type'; @@ -98,6 +99,8 @@ class CellValueFormatter $spaceAttribute = $childNode->getAttribute(self::XML_ATTRIBUTE_C); $numSpaces = (!empty($spaceAttribute)) ? intval($spaceAttribute) : 1; $currentPValue .= str_repeat(' ', $numSpaces); + } else if ($childNode->nodeName === self::XML_NODE_A) { + $currentPValue .= $childNode->nodeValue; } } diff --git a/tests/Spout/Reader/ODS/ReaderTest.php b/tests/Spout/Reader/ODS/ReaderTest.php index 8683459..4c95fd9 100644 --- a/tests/Spout/Reader/ODS/ReaderTest.php +++ b/tests/Spout/Reader/ODS/ReaderTest.php @@ -436,6 +436,23 @@ class ReaderTest extends \PHPUnit_Framework_TestCase $this->assertEquals($expectedRows, $allRows, 'Cell values should not be trimmed'); } + /** + * https://github.com/box/spout/issues/218 + * @return void + */ + public function testReaderShouldReadTextInHyperlinks() + { + $allRows = $this->getAllRowsForFile('sheet_with_hyperlinks.ods'); + + $expectedRows = [ + ['email', 'text'], + ['1@example.com', 'text'], + ['2@example.com', 'text and https://github.com/box/spout/issues/218 and text'], + ]; + + $this->assertEquals($expectedRows, $allRows, 'Text in hyperlinks should be read'); + } + /** * @param string $fileName * @return array All the read rows the given file diff --git a/tests/resources/ods/sheet_with_hyperlinks.ods b/tests/resources/ods/sheet_with_hyperlinks.ods new file mode 100644 index 0000000..7246db5 Binary files /dev/null and b/tests/resources/ods/sheet_with_hyperlinks.ods differ