Last active
March 5, 2018 02:24
-
-
Save ko-sasaki/f90b38d105e42df3c4e3bff5953f5147 to your computer and use it in GitHub Desktop.
php-office-word-comments-sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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