phpWord - 无法在部分中添加 PreserveText
phpWord - Cannot add PreserveText in Section
没有很多 phpWord 经验,遇到以下错误:
Fatal error: Uncaught exception 'BadMethodCallException' with message 'Cannot add PreserveText in Section.'
使用以下行时会发生:
$phpWord = \PhpOffice\PhpWord\IOFactory::load($document_location . $document_name . '.docx');
文档肯定存在,我也可以保存文档和readfile。
如有任何见解,我们将不胜感激。
我有同样的问题(也问过 here),对我来说,在我从中删除所有 mail merge fields
后加载文档工作正常。也许这也适合你
为了在文件中添加到方法 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.");
没有很多 phpWord 经验,遇到以下错误:
Fatal error: Uncaught exception 'BadMethodCallException' with message 'Cannot add PreserveText in Section.'
使用以下行时会发生:
$phpWord = \PhpOffice\PhpWord\IOFactory::load($document_location . $document_name . '.docx');
文档肯定存在,我也可以保存文档和readfile。
如有任何见解,我们将不胜感激。
我有同样的问题(也问过 here),对我来说,在我从中删除所有 mail merge fields
后加载文档工作正常。也许这也适合你
为了在文件中添加到方法 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.");