简体   繁体   English

PHP单词不能替换文档中的文本

[英]PHP word not replace text in doc

I am trying to make a replacement in a .docx document 我正在尝试在.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');
}

This code replace in { } , but not replace for %% 此代码替换为{ } ,但不能替换为%%

According to the documentation page about Template processing the { } brackets are indeed the default, and looking at the code for the setValue function no way seems to be built-in to use a different prefix and suffix. 根据有关模板处理的文档页面,{}括号确实是默认值,并且看一下setValue函数的代码 ,似乎没有内置方法可以使用不同的前缀和后缀。

This issue shows one possible way, but it requires modifying the source of the PHPWord package itself. 问题显示了一种可能的方法,但是它需要修改PHPWord包本身的源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM