I'm trying to replace some content into a docx file but even if the saveAs
works properly I dont see any modification in the new document.
Here is my code :
require 'vendor/autoload.php';
use PhpOffice\PhpWord\TemplateProcessor;
use Mpdf\Mpdf;
// Chemin du fichier Word d'origine
$inputDocx = 'Attestation_CLUE_modele V1 .docx';
// Chemin du fichier Word modifié
$outputDocx = 'Attestation_CLUE_modele V1MODA.docx';
// Instancier le TemplateProcessor
$templateProcessor = new TemplateProcessor($inputDocx);
// Remplacer le texte avec des guillemets français
$templateProcessor->setValues(['NOM', 'TEST DU NOM']);
var_dump($templateProcessor);
// Sauvegarder le document Word modifié
$templateProcessor->saveAs($outputDocx);
and here is what I'm trying to replace :
Yet nothing change, at first I was trying with the full version of what I want to change :
$templateProcessor->setValues(['«NOM»', 'TEST DU NOM']);
But without success and even without the «»
that could maybe have caused some encoding issue (maybe), nothing changed
Use the
setValue
method to replace each placeholder individually