ahm*_*utt 5 php phpword yii2 yii2-advanced-app
我在使用 PHPWord 扩展时遇到了一个问题 我正在尝试使用 Yii2 和 PHPWord 从 template.docx 文件生成 cv.docx 文件。
这是我的模板文件中要替换的内容:
${EXPERIENCES}
${/EXPERIENCES}
Run Code Online (Sandbox Code Playgroud)
这是我的 php 文件中的代码
Settings::setZipClass(Settings::PCLZIP);
$template_document= 'template.docx';
$templateProcessor = new TemplateProcessor($template_document);
$workExperiences = [
[
'company' => 'PiRails - TechHub Connect',
'title' => 'Junior PHP-Laravel Developer',
'started_at' => 'June 2016',
'ended_at' => 'Dec 2016',
],
[
'company' => 'FreeLancer',
'title' => 'PHP, Asp.Net Full stack Developer',
'started_at' => 'Jan 2015',
'ended_at' => '',
],
[
'company' => 'FreeLancer',
'title' => 'PHP, Asp.Net Full stack Developer',
'started_at' => 'Jan 2015',
'ended_at' => '',
],
];
$phpWord = new PhpWord();
$section = $phpWord->addSection();
$table = $section->addTable();
$row = $table->addRow();
$row->addCell('title');
$row->addCell('Company');
$row->addCell('started_at');
$row->addCell('ended_at');
$templateProcessor->replaceBlock('EXPERIENCES', $table);
$templateProcessor->saveAs('cv'.'.docx');
Run Code Online (Sandbox Code Playgroud)
这是我在输出文件中得到的内容:
${经历} ${/经历}
现在我尝试在一堆链接上找到解决方案,其中一些如下:https: //github.com/PHPOffice/PHPWord/issues/341 https://github.com/PHPOffice/PHPWord/issues/683 https ://www.bountysource.com/issues/3942663-deleteblock-replaceblock-doesn-t-work-properly
最后一个链接说明了我的文本在文件 xml 中的错误放置,但对我来说也不是这种情况。
任何帮助表示赞赏。祝好运。