Sample 39 TrackChanges

19:30:05 Create new PhpWord object
19:30:05 Write to Word2007 format
19:30:06 Write to ODText format
19:30:06 Write to RTF format
19:30:06 Write to HTML format
19:30:06 Write to PDF format ... NOT DONE!
19:30:06 Write to EPub3 format
19:30:06 Done writing file(s)
19:30:06 Peak memory usage: 2 MB

 

Results: docx odt rtf html epub


<?php


use PhpOffice\PhpWord\Element\TrackChange;

include_once 
'Sample_Header.php';

// New Word Document
echo date('H:i:s') , ' Create new PhpWord object' , EOL;
$phpWord = new PhpOffice\PhpWord\PhpWord();

// New portrait section
$section = $phpWord->addSection();
$textRun = $section->addTextRun();

$text = $textRun->addText('Hello World! Time to ');

$text = $textRun->addText('wake ', ['bold' => true]);
$text->setChangeInfo(TrackChange::INSERTED, 'Fred', time() - 1800);

$text = $textRun->addText('up');
$text->setTrackChange(new TrackChange(TrackChange::INSERTED, 'Fred'));

$text = $textRun->addText('go to sleep');
$text->setChangeInfo(TrackChange::DELETED, 'Barney', new DateTime('@' . (time() - 3600)));

// Save file
echo write($phpWord, basename(__FILE__, '.php'), $writers);
if (!
CLI) {
    include_once 
'Sample_Footer.php';
}