-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Closed
Milestone
Description
Describe the Bug
Adding two comments to the same text object only shows one in Word.
Steps to Reproduce
<?php
require __DIR__ . '/vendor/autoload.php';
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
$comment1 = new \PhpOffice\PhpWord\Element\Comment('Author', new \DateTime());
$comment1->addText('Comment1');
$phpWord->addComment($comment1);
$comment2 = new \PhpOffice\PhpWord\Element\Comment('Author', new \DateTime());
$comment2->addText('Comment2');
$phpWord->addComment($comment2);
$start = $section->addText('Hello');
$start->setCommentRangeStart($comment1);
$start->setCommentRangeStart($comment2);
$writer = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord);
$writer->save(__DIR__ . '/out.docx');
The generated xml has no id for the first comment and only references the second one, weirdly Word shows the first one.
comments.xml
<w:comment w:id="" w:author="Author" w:date="2021-06-28T12:51:44-03:00">
<w:p>
<w:pPr/>
<w:r>
<w:rPr/>
<w:t xml:space="preserve">Comment1</w:t>
</w:r>
</w:p>
</w:comment>
<w:comment w:id="2f939d" w:author="Author" w:date="2021-06-28T12:51:44-03:00">
<w:p>
<w:pPr/>
<w:r>
<w:rPr/>
<w:t xml:space="preserve">Comment2</w:t>
</w:r>
</w:p>
</w:comment>
</w:comments>
document.xml
<w:p>
<w:pPr/>
<w:commentRangeStart w:id="2f939d"/>
<w:r>
<w:rPr/>
<w:t xml:space="preserve">Hola</w:t>
</w:r>
<w:commentRangeEnd w:id="2f939d"/>
<w:r>
<w:commentReference w:id="2f939d"/>
</w:r>
</w:p>
Expected Behavior
Show both comments.
Something like this on document.xml
<w:p>
<w:pPr/>
<w:commentRangeStart w:id="[id comment1]"/>
<w:commentRangeStart w:id="[id comment2]"/>
<w:r>
<w:rPr/>
<w:t xml:space="preserve">Hola</w:t>
</w:r>
<w:commentRangeEnd w:id="[id comment1]"/>
<w:r>
<w:commentReference w:id="[[id comment1]"/>
</w:r>
<w:commentRangeEnd w:id="[id comment2]"/>
<w:r>
<w:commentReference w:id="[[id comment2]"/>
</w:r>
</w:p>
Current Behavior
Shows only one comment (Comment1).
Context
- PHP Version: 7.3.22
- PHPWord Version: 0.18.2 and current last dev branch.