Phpword: Find and Replace with PHPWord

Created on 24 Jul 2017  路  1Comment  路  Source: PHPOffice/PHPWord

hi is there a method to find a specific string and replace it using PHPWord ?

Most helpful comment

yes, the method is called setValue
e.g

$templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor($fileName);
$templateProcessor->setValue('year', date('Y'));
$templateProcessor->saveAs($newFileName);

year has to be mentioned like
${year} in your Word Doc.

I hope this helps

You should refer to the documentation in regards to queries like this. If you find a bug, you should report it here.

>All comments

yes, the method is called setValue
e.g

$templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor($fileName);
$templateProcessor->setValue('year', date('Y'));
$templateProcessor->saveAs($newFileName);

year has to be mentioned like
${year} in your Word Doc.

I hope this helps

You should refer to the documentation in regards to queries like this. If you find a bug, you should report it here.

Was this page helpful?
0 / 5 - 0 ratings