Phpword example

IS there simple example how to use phpword ?

Hi @Abdennour_Amriou

You can do a lot of things with the library. What do you need specifically? Did you try something?

Hi gbillot3
I try to use phpword with a specific template
when I Try I get this message : Class ‘PHPWord’ not found
so if there is an example It will help me so much
thank’s

I used composer to link the library. I used to create docs inserting data in Word templates defined by the user. This is the code example

This line include the prj library

sc_include_library(“prj”, “composer”, “/vendor/autoload.php”);

$template=’…/_lib/file/doc/plantillas/’. $plantilla;
$wbloque=0;
$wreg=’’;
$wcant_fichas=count($fichas);
$templateWord = new \PhpOffice\PhpWord\TemplateProcessor($template);
$allVariables = $templateWord->getVariables();
//Lookup for fields in the database
//Replace vars
$templateWord->setValue(‘idficha’.$wreg, $wfichanum);
$templateWord->setValue(‘proyecto’.$wreg, $wproyecto);
$templateWord->setValue(‘nombre_encomienda’.$wreg, $wnombre_encomienda);
$templateWord->setValue(‘simbolo_moneda’.$wreg, $wsimbolo_moneda);
$templateWord->setValue(‘monto_contrato’.$wreg, $wmonto_contrato);

$path="…/_lib/file/documentos/";
$wdocs .= $path . “Ficha Nro $wfichanum- $wproyecto.docx” . ‘,’; //"’".
$wdocu= $path . “Ficha Nro $wfichanum- $wproyecto.docx”;
$templateWord->saveAs($wdocu);

1 Like

Hi, interesting topic I had asked some years ago.
When you say “I used composer to link the library” is something very technical. I’m not a programmer and it’s not obvious. Why to use the library inside SC doesn’t work ?
Thanks

What is composer?
Introduction - Composer (getcomposer.org)

(5) Scriptcase - Instalando composer en Scriptcase - YouTube

2 Likes

Thanks !
I will see if I’ll be able to implement that .