PHP Word - 添加轨道修订



我是 Japanese.So 也许我的英语太差了,对不起。

我要

我想将"跟踪修订"添加到 *.docx 通过 PHP WORD。但是我找不到该怎么做。

1,通过PHP WORD添加一些文档。2,通过PHP WORD为文档添加一些跟踪修订。3,通过docx文件输出文档。4,通过Microsoft Word打开文件,我们可以看到带有"跟踪修订"的文档。

我的代码

我写了这段代码,但我做不到。

<?php
require_once 'vendor/autoload.php';
$phpword = new PhpOfficePhpWordPhpWord();
$phpword->getSettings()->setTrackRevisions(true);
$section = $phpword->addSection();
$section->addText('some text');

// output
$objWriter = PhpOfficePhpWordIOFactory::createWriter($phpword, 'Word2007');
$objWriter->save('helloWorld.docx');

// ===========================================
// read file
$reader = PhpOfficePhpWordIOFactory::load("helloWorld.docx", 'Word2007');
$trackChangesView = new PhpOfficePhpWordComplexTypeTrackChangesView();
$section2 = $reader->addSection();
$trackChangesView->setComments('history');
$sugoiyatsu = $section2->addTextRun();
$sugoiyatsu->addText('some some text');
$writer = PhpOfficePhpWordIOFactory::createWriter($reader, 'Word2007');
$writer->save("sample.docx");

我该怎么办?如果你知道如何做到这一点,请告诉我该怎么做。

谢谢。

附言

我找到了这本手册,https://media.readthedocs.org/pdf/phpword/develop/phpword.pdf 和 28 页。

他们说Track changes can be set on text elements. There are 2 ways to set the change information on an element. Either by calling the setChangeInfo(), or by setting the TrackChange instance on the element with setTrackChange()..

但是,我的IDE(IntelliJ(没有找到setChangeInfo方法和setTrackChange方法...X(

我找到了我该怎么做。使用 PHP Word v0.14.0 无法将跟踪修订添加到 docx。

(1(我必须使用开发分支的代码。

composer require phpoffice/phpword:dev-develop composer update

(2( 使用此代码

<?php
require_once 'vendor/autoload.php';
use PhpOfficePhpWordElementTrackChange;
$phpword = new PhpOfficePhpWordPhpWord();
$section = $phpword->addSection();
$textRun = $section->addTextRun();
$text = $textRun->addText('I am TEXT');
$text->setChangeInfo(TrackChange::INSERTED, 'nnahito', time() - 1800);

书目https://nnahito.com/articles/31

最新更新