phpWord - 无法在Section中添加PreserveText

时间:2015-10-11 21:44:20

标签: php phpword

没有很多使用phpWord的经验并遇到以下错误:

  

致命错误:未捕获的异常'BadMethodCallException',消息'无法在Section中添加PreserveText。'

使用以下行时发生了这种情况:

$phpWord = \PhpOffice\PhpWord\IOFactory::load($document_location . $document_name . '.docx'); 

文档肯定存在,我也可以保存文档和readfile。

非常感谢任何见解。

2 个答案:

答案 0 :(得分:2)

我遇到了同样的问题(也问过here),并且在我从中删除了所有mail merge fields之后加载文档。也许这对你也有用

答案 1 :(得分:1)

在部分中使用保留文本添加到文件中的方法checkValidity()     PhpOffice/PhpWord/Element/AbstractContainer.php新规则。

例如:

第214行

'PreserveText' => array('Header', 'Footer', 'Cell')Section添加到数组

第224行中的

'PreserveText' => array(array('Cell'), array('Header', 'Footer'))也为子容器添加Section

现在,你应该写

$section->addPreserveText("Total {PAGE} pages.");