PHP word 未替换文档中的文本
PHP word not replace text in doc
我正在尝试在 .docx 文档中进行替换
public function replace($seach, $replace)
{
$file = base_path() . '/public/templates/test.docx';
$phpword = new \PhpOffice\PhpWord\TemplateProcessor($file);
$phpword->setValue('%name%', 'Santosh');
$phpword->setValue('{lastname}', 'Achari');
$phpword->setValue('{name}', 'Achari');
$phpword->setValue('{officeAddress}', 'Yahoo');
$phpword->saveAs('edited.docx');
}
此代码在 { }
中替换,但不替换 %%
根据有关 Template processing the { } brackets are indeed the default, and looking at the code 的 setValue
函数的文档页面,似乎没有办法内置使用不同的前缀和后缀。
这个issue展示了一种可能的方法,但是它需要修改PHPWord包本身的源代码。
我正在尝试在 .docx 文档中进行替换
public function replace($seach, $replace)
{
$file = base_path() . '/public/templates/test.docx';
$phpword = new \PhpOffice\PhpWord\TemplateProcessor($file);
$phpword->setValue('%name%', 'Santosh');
$phpword->setValue('{lastname}', 'Achari');
$phpword->setValue('{name}', 'Achari');
$phpword->setValue('{officeAddress}', 'Yahoo');
$phpword->saveAs('edited.docx');
}
此代码在 { }
中替换,但不替换 %%
根据有关 Template processing the { } brackets are indeed the default, and looking at the code 的 setValue
函数的文档页面,似乎没有办法内置使用不同的前缀和后缀。
这个issue展示了一种可能的方法,但是它需要修改PHPWord包本身的源代码。