PHPOffice / PHPWord

A pure PHP library for reading and writing word processing documents
https://phpoffice.github.io/PHPWord/
Other
7.22k stars 2.69k forks source link

how to get docx comments #2525

Open nujiakk opened 9 months ago

nujiakk commented 9 months ago

How do I directly retrieve comments information from a DOCX document?

Akashpaila commented 9 months ago

2525

You can use the PHP word library to retreive the commented information in the DOCX or else you can also use DOM document to access the commented information

Try this DOM Document method Load the DOCX file as the xml $xml = file_get_contents("path to your docx"); $dom = new DOMDocument(); $dom->loadXML($xml, LIBXML_PARSEHUGE);

$xpath = new DOMXPath($dom); $comments = $xpath->query("//w:comment");

foreach ($comments as $comment) { $author = $comment->getElementsByTagName("w:author")->item(0)->nodeValue; $date = $comment->getElementsByTagName("w:date")->item(0)->nodeValue; $text = $comment->getElementsByTagName("w:t")->item(0)->nodeValue; }