diff --git a/src/Spout/Reader/XLSX/Helper/SharedStringsHelper.php b/src/Spout/Reader/XLSX/Helper/SharedStringsHelper.php index 6aafb52..1ba4e6a 100644 --- a/src/Spout/Reader/XLSX/Helper/SharedStringsHelper.php +++ b/src/Spout/Reader/XLSX/Helper/SharedStringsHelper.php @@ -100,11 +100,16 @@ class SharedStringsHelper // removes nodes that should not be read, like the pronunciation of the Kanji characters $cleanNode = $this->removeSuperfluousTextNodes($node); - // find all text nodes 't'; there can be multiple if the cell contains formatting + // find all text nodes "t"; there can be multiple if the cell contains formatting $textNodes = $cleanNode->xpath('//ns:t'); $textValue = ''; - foreach ($textNodes as $textNode) { + foreach ($textNodes as $nodeIndex => $textNode) { + if ($nodeIndex !== 0) { + // add a space between each "t" node + $textValue .= ' '; + } + if ($this->shouldPreserveWhitespace($textNode)) { $textValue .= $textNode->__toString(); } else { @@ -200,6 +205,8 @@ class SharedStringsHelper { $tagsToRemove = [ 'rPh', // Pronunciation of the text + 'pPr', // Paragraph Properties / Previous Paragraph Properties + 'rPr', // Run Properties for the Paragraph Mark / Previous Run Properties for the Paragraph Mark ]; foreach ($tagsToRemove as $tagToRemove) { diff --git a/tests/Spout/Reader/XLSX/Helper/SharedStringsHelperTest.php b/tests/Spout/Reader/XLSX/Helper/SharedStringsHelperTest.php index a72d19a..31f9c71 100644 --- a/tests/Spout/Reader/XLSX/Helper/SharedStringsHelperTest.php +++ b/tests/Spout/Reader/XLSX/Helper/SharedStringsHelperTest.php @@ -82,6 +82,22 @@ class SharedStringsHelperTest extends \PHPUnit_Framework_TestCase $sharedStringsHelper->cleanup(); } + /** + * @return void + */ + public function testGetStringAtIndexShouldWorkWithStringsContainingTextAndHyperlinkInSameCell() + { + $resourcePath = $this->getResourcePath('one_sheet_with_shared_strings_containing_text_and_hyperlink_in_same_cell.xlsx'); + $sharedStringsHelper = new SharedStringsHelper($resourcePath); + + $sharedStringsHelper->extractSharedStrings(); + + $sharedString = $sharedStringsHelper->getStringAtIndex(0); + $this->assertEquals('go to https://github.com please', $sharedString); + + $sharedStringsHelper->cleanup(); + } + /** * @return void */ diff --git a/tests/resources/xlsx/one_sheet_with_shared_strings_containing_text_and_hyperlink_in_same_cell.xlsx b/tests/resources/xlsx/one_sheet_with_shared_strings_containing_text_and_hyperlink_in_same_cell.xlsx new file mode 100644 index 0000000..08527df Binary files /dev/null and b/tests/resources/xlsx/one_sheet_with_shared_strings_containing_text_and_hyperlink_in_same_cell.xlsx differ