Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

497
Vistas
Why does PHPword setvalue not replacing text in word Doc?

I am trying to edit word document using php (PHPword library). However, I am not sure why it is not working. The script did not throw any error.

My Code:

    <?php 
    require 'vendor/autoload.php';
    
    // $phpword = new \PhpOffice\PhpWord\PhpWord();
    $templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor('test.docx');
    // $templateProcessor->setValues(array('firstname' => 'John', 'lastname' => 'Doe'));
    $templateProcessor->setValue('firstname', 'John');
    $templateProcessor->setValue('lastname', 'Doe');
    
    // var_dump($templateProcessor->setValues(array('firstname' => 'John', 'lastname' => 'Doe')));
    var_dump($templateProcessor->setValue('lastname', 'Doe'))
    ?>

My word Doc: word doc

Output: Output

I have no idea why it is not working. can you please help me ? Thank you

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

The setValue() method will set the value but not return it to var_dump it.

Instead you can add:

$pathToSave = 'path/to/save/file.ext';
$templateProcessor->saveAs($pathToSave);

and check the output in the generated document.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda