S
S
Semen2021-06-08 15:27:00
Yii
Semen, 2021-06-08 15:27:00

How to generate docx document from template in yii2?

I use the phpWord v0.18.2 library.
I'm trying to apply a Word template to display a report.
Created a temp.docx document with a substitution variable - ${Name}
Code:
$path_templ = Yii::getAlias('@web').'/templates/temp.docx';
$phpWord = new TemplateProcessor($path_templ);
$phpWord->setValue('Name', 'Me');
$path_file = Yii::getAlias('@web').'/reports/report.docx';
$phpWord->saveAs($path_file);

Error execution result:
Declaration of PhpOffice\PhpWord\TemplateProcessor::save() should be compatible with PhpOffice\PhpWord\PhpWord::save($filename, $format = 'Word2007', $download = false)

I can't figure out what the TemplateProcessor declaration means must be compatible with PhpWord. There are no $format and $download parameters in the TemplateProcessor::save() method.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question