【发布时间】:2019-01-18 21:11:37
【问题描述】:
我正在使用 PHPword 来生成 word 文档。我想生成多个文档,以便使用模板。我在控制器中尝试了这段代码:
$templateProcessor = new TemplateProcessor('resources/Sample_07_TemplateCloneRow.docx');
$templateProcessor->setValue('Name', 'John Doe');
$templateProcessor->setValue(array('City', 'Street'), array('Detroit', '12th Street'));
并显示以下错误:
copy(resources/Sample_07_TemplateCloneRow.docx): failed to open stream: No such
file or directory
在:
// Template file cloning
if (false === copy($documentTemplate, $this->tempDocumentFilename)) {
throw new CopyFileException($documentTemplate, $this->tempDocumentFilename);
}
模板处理器的默认目录是什么?或者我们必须手动提供位置。请帮忙!
PHP 版本:7.0 拉拉维尔 5.5 PHPWord 版本:0.14
【问题讨论】:
-
这个控制器文件相对于
resources文件夹在哪里?你确定你的路径正确吗?也许快速__DIR__ . '/resources/Sample....是要走的路? -
控制器文件在 App\Http\Controllers 中。和资源文件夹在 Vendor\phpoffice\phpword\samples\resources.
-
资源文件夹在哪里?
-
Resources 文件夹位于 Vendor\phpoffice\phpword\samples\resources 中。如何在控制器和 Sample_07_TemplateCloneRow.docx 文件之间链接??
-
我认为这是您需要的路径...
__DIR__ . '/../../../Vendor/phpoffice/phpword/samples/resources/yourfilehere'