Skip to content

Commit 2830286

Browse files
committed
Handle special XML characters also for formula
1 parent a9ddee3 commit 2830286

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/XlsxFastEditorCell.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,17 @@ public function writeFormula(string $value): void
307307
throw new XlsxFastEditorXmlException("Internal error accessing cell {$this->name()}!");
308308
}
309309
try {
310-
$f = $dom->createElement('f', $value);
311-
if (!($f instanceof \DOMElement)) {
310+
// First, we create an empty element t
311+
$f = $dom->createElement('f');
312+
if ($f === false) {
312313
throw new XlsxFastEditorXmlException("Error creating DOMElement of formula for cell {$this->name()}!");
313314
}
315+
// Add content as a text node
316+
$textNode = $dom->createTextNode($value);
317+
if ($textNode === false) {
318+
throw new XlsxFastEditorXmlException("Error creating text node of formula for cell {$this->name()}!");
319+
}
320+
$f->appendChild($textNode);
314321
} catch (\DOMException $dex) {
315322
throw new XlsxFastEditorXmlException("Error creating formula for cell {$this->name()}!", $dex->code, $dex);
316323
}

0 commit comments

Comments
 (0)