Hi,
Is it possible to insert a comment in an existing .docx file on a specified fragment?
Hi,
Is it possible to insert a comment in an existing .docx file on a specified fragment?
Hello,
You can generate the comment and use DOCXPath (https://www.phpdocx.com/documentation/introduction/docxpath) to insert it, for example:
<?php
require_once 'classes/CreateDocx.php';
$docx = new CreateDocxFromTemplate('SimpleExample.docx');
$comment = new WordFragment($docx, 'document');
$comment->addComment(
array(
'textDocument' => 'comment',
'textComment' => 'The comment we want to insert.',
'initials' => 'PT',
'author' => 'PHPDocX Team',
'date' => '10 September 2000'
)
);
$referenceNode = array(
'type' => 'paragraph',
'occurrence' => 2,
);
$docx->insertWordFragment($comment, $referenceNode, 'inlineAfter');
$docx->createDocx('output');
at specific positions. Please note that insertWordFragment allows working with existing tags, so it can add the comment after any MS Word tag (in body (document), header, and footer targets), but it doesn't allow applying the comment to an existing string.
Regards.