forked from PHPOffice/PHPWord
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for comments (PHPOffice#1067)
Just a writer for now, reader to be done
- Loading branch information
Showing
23 changed files
with
726 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ Thumbs.db | |
Desktop.ini | ||
.idea | ||
_build | ||
/build | ||
phpunit.xml | ||
composer.lock | ||
composer.phar | ||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
include_once 'Sample_Header.php'; | ||
|
||
// New Word Document | ||
echo date('H:i:s') , ' Create new PhpWord object' , EOL; | ||
$phpWord = new \PhpOffice\PhpWord\PhpWord(); | ||
|
||
// A comment | ||
$comment = new \PhpOffice\PhpWord\Element\Comment('Authors name', new \DateTime(), 'my_initials'); | ||
$comment->addText('Test', array('bold' => true)); | ||
$phpWord->addComment($comment); | ||
|
||
$section = $phpWord->addSection(); | ||
|
||
$textrun = $section->addTextRun(); | ||
$textrun->addText('This '); | ||
$text = $textrun->addText('is'); | ||
$text->setCommentRangeStart($comment); | ||
$textrun->addText(' a test'); | ||
|
||
$section->addTextBreak(2); | ||
|
||
// Let's create a comment that we will link to a start element and an end element | ||
$commentWithStartAndEnd = new \PhpOffice\PhpWord\Element\Comment('Foo Bar', new \DateTime(), ''); | ||
$commentWithStartAndEnd->addText('A comment with a start and an end'); | ||
$phpWord->addComment($commentWithStartAndEnd); | ||
|
||
$textrunWithEnd = $section->addTextRun(); | ||
$textrunWithEnd->addText('This '); | ||
$textToStartOn = $textrunWithEnd->addText('is', array('bold' => true)); | ||
$textToStartOn->setCommentRangeStart($commentWithStartAndEnd); | ||
$textrunWithEnd->addText(' another', array('italic' => true)); | ||
$textToEndOn = $textrunWithEnd->addText(' test'); | ||
$textToEndOn->setCommentRangeEnd($commentWithStartAndEnd); | ||
|
||
$section->addTextBreak(2); | ||
|
||
// Let's add a comment on an image | ||
$commentOnImage = new \PhpOffice\PhpWord\Element\Comment('Mr Smart', new \DateTime(), ''); | ||
$imageComment = $commentOnImage->addTextRun(); | ||
$imageComment->addText('Hey, Mars does look '); | ||
$imageComment->addText('red', array('color' => 'FF0000')); | ||
$phpWord->addComment($commentOnImage); | ||
$image = $section->addImage('resources/_mars.jpg'); | ||
$image->setCommentRangeStart($commentOnImage); | ||
|
||
$section->addTextBreak(2); | ||
|
||
// We can also do things the other way round, link the comment to the element | ||
$anotherText = $section->addText("another text"); | ||
|
||
$comment1 = new \PhpOffice\PhpWord\Element\Comment('Authors name', new \DateTime(), 'my_initials'); | ||
$comment1->addText('Test', array('bold' => true)); | ||
$comment1->setStartElement($anotherText); | ||
$comment1->setEndElement($anotherText); | ||
$phpWord->addComment($comment1); | ||
|
||
|
||
// Save file | ||
echo write($phpWord, basename(__FILE__, '.php'), $writers); | ||
if (!CLI) { | ||
include_once 'Sample_Footer.php'; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
/** | ||
* This file is part of PHPWord - A pure PHP library for reading and writing | ||
* word processing documents. | ||
* | ||
* PHPWord is free software distributed under the terms of the GNU Lesser | ||
* General Public License version 3 as published by the Free Software Foundation. | ||
* | ||
* For the full copyright and license information, please read the LICENSE | ||
* file that was distributed with this source code. For the full list of | ||
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. | ||
* | ||
* @link https://github.com/PHPOffice/PHPWord | ||
* @copyright 2010-2016 PHPWord contributors | ||
* @license http:https://www.gnu.org/licenses/lgpl.txt LGPL version 3 | ||
*/ | ||
|
||
namespace PhpOffice\PhpWord\Collection; | ||
|
||
/** | ||
* Comments collection | ||
* | ||
* @since 0.12.0 | ||
*/ | ||
class Comments extends AbstractCollection | ||
{ | ||
} |
This file contains 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
This file contains 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
Oops, something went wrong.