使用 docx 在 phpoffice 中捕获异常


catch exceptions in phpoffice with docx

如何捕获此异常(或phpoffice中的任何异常)

https://github.com/PHPOffice/PHPWord/tree/master/src/PhpWord

require_once 'Ini::get('path/class').'/third-party/phpword/Autoloader.php';
'PhpOffice'PhpWord'Autoloader::register();
'PhpOffice'PhpWord'Settings::setPdfRendererPath('Ini::get('path/class').'/third-party/tcpdf');
'PhpOffice'PhpWord'Settings::setPdfRendererName('TCPDF');
try{
    $word = 'PhpOffice'PhpWord'IOFactory::load($file_dst);
    $writer = 'PhpOffice'PhpWord'IOFactory::createWriter($word, 'PDF');
}
catch('PhpOffice'PhpWord'BadMethodCallException $e){
}

错误

    PHP Fatal error:  Uncaught exception 'BadMethodCallException' with message 'Cannot add PreserveText in Cell.' in /var/www/dyntest.dk/class/third-party/phpword/Element/AbstractContainer.php:276
这是一个

基本的PHP异常(PHP核心的一部分,而不是PHPOffice),你应该像这样捕获它:

try{
    $word = 'PhpOffice'PhpWord'IOFactory::load($file_dst);
    $writer = 'PhpOffice'PhpWord'IOFactory::createWriter($word, 'PDF');
}
catch('BadMethodCallException $e){
}
相关文章: