PHP Word - 添加轨道修订
PHP Word - Add Track Revisions
我是一个Japanese.So可能我的英语太差了,抱歉
我要
我想通过 PHP WORD 添加 "Track Revisions" 到 *.docx。
但是我找不到怎么做。
1、通过PHPWORD添加一些文档。
2,通过PHP WORD对文档添加一些Track Revisions。
3、通过docx文件输出文档。
4、用Microsoft Word打开文件,可以看到带有Track Revisions的文件。
我的代码
我写了这段代码,但是我做不到。
<?php
require_once 'vendor/autoload.php';
$phpword = new PhpOffice\PhpWord\PhpWord();
$phpword->getSettings()->setTrackRevisions(true);
$section = $phpword->addSection();
$section->addText('some text');
// output
$objWriter = PhpOffice\PhpWord\IOFactory::createWriter($phpword, 'Word2007');
$objWriter->save('helloWorld.docx');
// ===========================================
// read file
$reader = PhpOffice\PhpWord\IOFactory::load("helloWorld.docx", 'Word2007');
$trackChangesView = new PhpOffice\PhpWord\ComplexType\TrackChangesView();
$section2 = $reader->addSection();
$trackChangesView->setComments('history');
$sugoiyatsu = $section2->addTextRun();
$sugoiyatsu->addText('some some text');
$writer = PhpOffice\PhpWord\IOFactory::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 PhpOffice\PhpWord\Element\TrackChange;
$phpword = new PhpOffice\PhpWord\PhpWord();
$section = $phpword->addSection();
$textRun = $section->addTextRun();
$text = $textRun->addText('I am TEXT');
$text->setChangeInfo(TrackChange::INSERTED, 'nnahito', time() - 1800);
我是一个Japanese.So可能我的英语太差了,抱歉
我要
我想通过 PHP WORD 添加 "Track Revisions" 到 *.docx。 但是我找不到怎么做。
1、通过PHPWORD添加一些文档。 2,通过PHP WORD对文档添加一些Track Revisions。 3、通过docx文件输出文档。 4、用Microsoft Word打开文件,可以看到带有Track Revisions的文件。
我的代码
我写了这段代码,但是我做不到。
<?php
require_once 'vendor/autoload.php';
$phpword = new PhpOffice\PhpWord\PhpWord();
$phpword->getSettings()->setTrackRevisions(true);
$section = $phpword->addSection();
$section->addText('some text');
// output
$objWriter = PhpOffice\PhpWord\IOFactory::createWriter($phpword, 'Word2007');
$objWriter->save('helloWorld.docx');
// ===========================================
// read file
$reader = PhpOffice\PhpWord\IOFactory::load("helloWorld.docx", 'Word2007');
$trackChangesView = new PhpOffice\PhpWord\ComplexType\TrackChangesView();
$section2 = $reader->addSection();
$trackChangesView->setComments('history');
$sugoiyatsu = $section2->addTextRun();
$sugoiyatsu->addText('some some text');
$writer = PhpOffice\PhpWord\IOFactory::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 PhpOffice\PhpWord\Element\TrackChange;
$phpword = new PhpOffice\PhpWord\PhpWord();
$section = $phpword->addSection();
$textRun = $section->addTextRun();
$text = $textRun->addText('I am TEXT');
$text->setChangeInfo(TrackChange::INSERTED, 'nnahito', time() - 1800);