报错信息:
PHP Warning 'yii\base\ErrorException' with message 'DOMDocument::loadXML(): Namespace prefix m on oMath is not defined in Entity, line: 1'
in /projectname/vendor/phpoffice/math/src/Math/Reader/OfficeMathML.php:39
解决方法:修改文件
/vendor/phpoffice/phpword/src/PhpWord/Reader/Word2007/AbstractPart.php
将代码
// Formula
$xmlReader->registerNamespace('m', 'http://schemas.openxmlformats.org/officeDocument/2006/math');
if ($xmlReader->elementExists('m:oMath', $domNode)) {
$mathElement = $xmlReader->getElement('m:oMath', $domNode);
$mathXML = $mathElement->ownerDocument->saveXML($mathElement);
if (is_string($mathXML)) {
$reader = new OfficeMathML();
$math = $reader->read($mathXML);
$parent->addFormula($math);
}
return;
}
修改为
// Formula
$xmlReader->registerNamespace('m', 'http://schemas.openxmlformats.org/officeDocument/2006/math');
if ($xmlReader->elementExists('m:oMath', $domNode)) {
$mathElement = $xmlReader->getElement('m:oMath', $domNode);
$mathXML = $mathElement->ownerDocument->saveXML($mathElement);
if (is_string($mathXML)) {
try{
$reader = new OfficeMathML();
$math = $reader->read($mathXML);
$parent->addFormula($math);
}catch(\Exception $ex){
//do nothing...
}
}
return;
}