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

Support comments in docx documents #1059

Closed
wants to merge 31 commits into from

Conversation

troosan
Copy link
Contributor

@troosan troosan commented May 15, 2017

This will allow you to add comments in your generated documents.
To try it out, run the Sample_37_Comments.php

This will generate the following

image

'github_troosan/fix_for_different_even_odd_headers' into develop

Conflicts:
	tests/PhpWord/SettingsTest.php
	tests/PhpWord/Writer/Word2007/Part/SettingsTest.php
@troosan troosan closed this May 18, 2017
*
* @var Comment
*/
protected $commentStart;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be part of AbstractElement? Seems it should be part of Comment to me. Or is it because comments should be attached to an element? If so, maybe the attribute name could be clarified just a bit more? 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rvanlaak Indeed, the Comment starts at an element and ends at another one.

The node in the generated XML is named 'w:commentRangeStart and 'w:commentRangeEnd, maybe I could rename it to match this closer.

On the Comment itself, I'm keeping a reference back to the Element on which it starts/ends
private $startElement;
private $endElement;

@troosan
Copy link
Contributor Author

troosan commented May 25, 2017

I messed up the merge on this branch. I'm deleting this branch and pushing to a new one.

@troosan troosan closed this May 25, 2017
@troosan troosan deleted the support_comments branch May 25, 2017 20:51
@hrydi
Copy link

hrydi commented May 9, 2018

i have trouble for using this feature (comment), i have couples of comments and want to attach it to single text. but always outputing one comment instead (i'm using loop for this).
can you help me ?

<?php
#.....
$purchaserName = $cell->addText("Purchaser Name");
$users = ['kampret'=>'Nice work!!', 'wakwauuu'=>'Awesome !!', 'oase'=>'Good Job!!'];
foreach($users as $user => $msg){
    $cmnt = new \PhpOffice\PhpWord\Element\Comment($user, new \DateTime());
    $cmnt->addText($msg, array('bold' => true));
    $cmnt->setStartElement($purchaserName);
    $cmnt->setEndElement($purchaserName);
    $phpWord->addComment($cmnt);
}

and sorry for my bad english 😄 .
this library is awesome btw, thank you.

@troosan
Copy link
Contributor Author

troosan commented May 11, 2018

@hrydi I'm afraid I had not foreseen to add multiple comments on a same text element. Which is indeed wrong :-(
I'll see what I can do about that, but it could take some time!

@hrydi
Copy link

hrydi commented May 14, 2018

@troosan thanks for the reply,
I will wait for the updated 😄
while waiting, I will test in my local of course hehehe

@cambraca
Copy link
Contributor

cambraca commented Mar 6, 2023

@troosan hey hey, has there been any update on multiple comments? (it's hard to google this, the word "comment" pops up everywhere on the web!)

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants