PHPWord icon indicating copy to clipboard operation
PHPWord copied to clipboard

how to parse docx file "w:sym" tag?

Open longware opened this issue 5 months ago • 2 comments

By default, the phpword does not process w:sym tags but you can fix it!

phpoffice\phpword\src\PhpWord\Reader\Word2007\AbstractPart.php protected function readRunChild()

`

} elseif ($node->nodeName == 'w:br') {
        $parent->addTextBreak();
    } elseif ($node->nodeName == 'w:tab') {
        $parent->addText("\t");
    } elseif ($node->nodeName == 'w:sym') { // parse here
        $font = $xmlReader->getAttribute('w:font', $node);
        $char = $xmlReader->getAttribute('w:char', $node);
        $textContent = "[".$font.",".$char."]";  // or you can make a map array here
        $parent->addText($textContent, $fontStyle, $paragraphStyle);
    } elseif ($node->nodeName == 'mc:AlternateContent') { 

`

in my project, the result output is: XXXX [Wingdings 2,00A3]
YYYY [Wingdings 2,0052]

I hope to be useful to you~~

longware avatar Jul 21 '25 19:07 longware

@longware Have you got a simple file with symbols ?

Progi1984 avatar Jul 26 '25 11:07 Progi1984

Docx sym tag test file.docx

@Progi1984 HERE IS A TEST FILE

longware avatar Jul 26 '25 16:07 longware