Skip to content

Instantly share code, notes, and snippets.

@ko-sasaki
Last active March 5, 2018 02:24
Show Gist options
  • Save ko-sasaki/f90b38d105e42df3c4e3bff5953f5147 to your computer and use it in GitHub Desktop.
Save ko-sasaki/f90b38d105e42df3c4e3bff5953f5147 to your computer and use it in GitHub Desktop.
php-office-word-comments-sample
<?php
require_once __DIR__.'/../vendor/autoload.php';
$word = new PhpOffice\PhpWord\PhpWord();
$section = $word->addSection();
$section->addText('"Learn from yesterday, live for today, hope for tomorrow. '
. 'The important thing is not to stop questioning." '
. '(Albert Einstein)');
$section->addText('"Great achievement is usually born of great sacrifice, '
. 'and is never the result of selfishness." ');
$comment = new PhpOffice\PhpWord\Element\Comment('Authors name', new DateTime(), 'my initials');
$comment->addText('Test',array('bold' => true));
$textrun = $section->addTextRun();
$textrun->addText('This ');
$text = $textrun->addText('is');
// link the comment to the text you just created
$text->setCommentRangeStart($comment);
$objWriter = PhpOffice\PhpWord\IOFactory::createWriter($word, 'Word2007');
$objWriter->save('helloWorld.docx');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment