phpWord - Cannot add PreserveText in Section

杀马特。学长 韩版系。学妹 提交于 2019-12-06 07:12:11

问题


Not got a lot of experience with phpWord and coming across the following error:

Fatal error: Uncaught exception 'BadMethodCallException' with message 'Cannot add PreserveText in Section.'

Its happening when using the below line:

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

The document definitely exists and I can save the document and readfile as well.

Any insight would be greatly appreciated.


回答1:


I had the same Problem (also asked here) and for me loading the document worked after I removed all mail merge fields from it. Maybe this works for you, too




回答2:


For using preserve text in Section add to method checkValidity() in file PhpOffice/PhpWord/Element/AbstractContainer.php new rules.

For example :

in line 214: 'PreserveText' => array('Header', 'Footer', 'Cell') add Section to array

in line 224: 'PreserveText' => array(array('Cell'), array('Header', 'Footer')) add Section too for sub containers.

Now, you should write

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


来源:https://stackoverflow.com/questions/33070424/phpword-cannot-add-preservetext-in-section

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!