Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding two comments to same text only shows one #2109

Open
rodrigoq opened this issue Jun 28, 2021 · 0 comments · May be fixed by #2112
Open

Adding two comments to same text only shows one #2109

rodrigoq opened this issue Jun 28, 2021 · 0 comments · May be fixed by #2112

Comments

@rodrigoq
Copy link

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

1 participant