XLSX Reader should add a space between text nodes (#229)
When a cell contains multiple text nodes, the cell value is currently obtained by concatenating the value of each text node. Instead, values should still be concatenated but a space should be added in between.
This commit is contained in:
parent
a24e794177
commit
2c80b1f23a
@ -100,11 +100,16 @@ class SharedStringsHelper
|
|||||||
// removes nodes that should not be read, like the pronunciation of the Kanji characters
|
// removes nodes that should not be read, like the pronunciation of the Kanji characters
|
||||||
$cleanNode = $this->removeSuperfluousTextNodes($node);
|
$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');
|
$textNodes = $cleanNode->xpath('//ns:t');
|
||||||
|
|
||||||
$textValue = '';
|
$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)) {
|
if ($this->shouldPreserveWhitespace($textNode)) {
|
||||||
$textValue .= $textNode->__toString();
|
$textValue .= $textNode->__toString();
|
||||||
} else {
|
} else {
|
||||||
@ -200,6 +205,8 @@ class SharedStringsHelper
|
|||||||
{
|
{
|
||||||
$tagsToRemove = [
|
$tagsToRemove = [
|
||||||
'rPh', // Pronunciation of the text
|
'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) {
|
foreach ($tagsToRemove as $tagToRemove) {
|
||||||
|
@ -82,6 +82,22 @@ class SharedStringsHelperTest extends \PHPUnit_Framework_TestCase
|
|||||||
$sharedStringsHelper->cleanup();
|
$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
|
* @return void
|
||||||
*/
|
*/
|
||||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user