Skip to content

Commit cc54b29

Browse files
authored
Merge pull request #1 from alexandrainst/super-formated-shared-strings
Support formatted shared strings
2 parents b485bef + 3ac04b9 commit cc54b29

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

src/XlsxFastEditor.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -753,13 +753,16 @@ public function _getSharedString(int $stringNumber): ?string
753753
$stringNumber++; // Base 1
754754

755755
$xpath = $this->getXPathFromPath(self::SHARED_STRINGS_PATH);
756-
$ts = $xpath->query("/o:sst/o:si[$stringNumber][1]/o:t[1]");
756+
$ts = $xpath->query("/o:sst/o:si[$stringNumber]//o:t");
757757
if ($ts !== false && $ts->length > 0) {
758-
$t = $ts[0];
759-
if (!($t instanceof \DOMElement)) {
760-
throw new XlsxFastEditorXmlException("Error querying XML shared string {$stringNumber}!");
758+
$text = '';
759+
foreach ($ts as $t) {
760+
if (!($t instanceof \DOMElement)) {
761+
throw new XlsxFastEditorXmlException("Error querying XML shared string {$stringNumber}!");
762+
}
763+
$text .= $t->nodeValue;
761764
}
762-
return $t->nodeValue;
765+
return $text;
763766
}
764767
return null;
765768
}

tests/test.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
assert($xlsxFastEditor->readFloat($sheet1, 'e5') === null);
3434
assert($xlsxFastEditor->readInt($sheet1, 'c3') === -5);
3535
assert($xlsxFastEditor->readInt($sheet1, 'F6') === null);
36+
assert($xlsxFastEditor->readString($sheet1, 'B3') === 'déjà-vu');
3637
assert($xlsxFastEditor->readString($sheet1, 'b4') === 'naïveté');
3738
assert($xlsxFastEditor->readString($sheet1, 'F7') === null);
3839
assert($xlsxFastEditor->readHyperlink($sheet1, 'B4') === 'https://example.net/');

tests/test.xlsx

91 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)