没有很多使用phpWord的经验并遇到以下错误:
致命错误:未捕获的异常'BadMethodCallException',消息'无法在Section中添加PreserveText。'
使用以下行时发生了这种情况:
$phpWord = \PhpOffice\PhpWord\IOFactory::load($document_location . $document_name . '.docx');
文档肯定存在,我也可以保存文档和readfile。
非常感谢任何见解。
答案 0 :(得分:2)
我遇到了同样的问题(也问过here),并且在我从中删除了所有mail merge fields
之后加载文档。也许这对你也有用
答案 1 :(得分:1)
在部分中使用保留文本添加到文件中的方法checkValidity()
PhpOffice/PhpWord/Element/AbstractContainer.php
新规则。
例如:
第214行:'PreserveText' => array('Header', 'Footer', 'Cell')
将Section
添加到数组
:'PreserveText' => array(array('Cell'), array('Header', 'Footer'))
也为子容器添加Section
。
现在,你应该写
$section->addPreserveText("Total {PAGE} pages.");