首页 > 解决方案 > phpoffice 或任何可以向 word 文档添加注释的 phpWord 库?

问题描述

是否有任何 PHP Word 文档库可以让我自动添加评论,例如下面的这个示例,

在此处输入图像描述

其中在文档右侧可以看到注释,

我试过 PHPOffice 但它似乎没有任何评论功能,

$phpWord = new \PhpOffice\PhpWord\PhpWord();
        $phpWord->setDefaultFontSize(10);
        $phpWord->setDefaultFontName('Calibri');
        $phpWord->setDefaultParagraphStyle(
            array(
            'spaceAfter' => \PhpOffice\PhpWord\Shared\Converter::pointToTwip(0))
        );

$metaDataSection = $phpWord->addSection();
        $metaDataSection->addText(
            "Legal Name: "Sample Legal Name ",  
            array('bold' => true)
        );
$metaDataSection-> like addComment() functionality

标签: phpphpwordphpoffice

解决方案


在 PHPWord 源代码上有一个这样做的例子。

该示例的一个片段是:

// 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);

文档中也有一些信息。


推荐阅读