phpword使用报错 ZipArchive::locateName(): Invalid or uninitialized Zip object
一开始使用doc格式的word作为模板
vendor('phpoffice.phpword'); $templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor(ROOT_PATH.'public/template/zjscbs_template.doc'); $year = date('Y'); $templateProcessor->setValue('project',$project['name']); //保存文件 $templateProcessor->saveAs(ROOT_PATH."public/uploads/zjscbs/zjscbs_template_{$project['id']}.doc"); |
报错如下
[ error ] [2]ZipArchive::locateName(): Invalid or uninitialized Zip object[/www/wwwroot/oa.dsbbk.cn/vendor/phpoffice/phpword/src/PhpWord/Shared/ZipArchive.php:115] [ error ] [2]ZipArchive::locateName(): Invalid or uninitialized Zip object[/www/wwwroot/oa.dsbbk.cn/vendor/phpoffice/phpword/src/PhpWord/Shared/ZipArchive.php:115] [ error ] [2]ZipArchive::getFromName(): Invalid or uninitialized Zip object[/www/wwwroot/oa.dsbbk.cn/vendor/phpoffice/phpword/src/PhpWord/Shared/ZipArchive.php:201]
修改为docx格式的作为模板
一开始使用doc格式的word作为模板
vendor('phpoffice.phpword'); $templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor(ROOT_PATH.'public/template/zjscbs_template.docx'); $year = date('Y'); $templateProcessor->setValue('project',$project['name']); //保存文件 $templateProcessor->saveAs(ROOT_PATH."public/uploads/zjscbs/zjscbs_template_{$project['id']}.docx"); |