I am using the php word library in my project with laravel, it works correctly, what I do is use a word template and add values to it using TemplateProcessor, the problem I present is when I want to write a dynamic array in the word template, which contains the values of a query to the db. the array is: activename1['soccer','swimming','baseball'].
I am trying it in the following way, I attach the code:
$sqlclientes="SELECT * FROM datos_clientes";
$datos_clientes = DB::select($sqlclientes);
foreach ($datos_clientes as $datos_cli) {
$nombre_cli=$datos_cli->nombre_cli;
$empresa_cli=$datos_cli->empresa_cli;
$correo_cli=$datos_cli->correo_cli;
$ciudad_cli=$datos_cli->ciudad_cli;
$direccion_cli=$datos_cli->direccion_cli;
$fecha_cli=$datos_cli->fecha_cli;
$objetivo_ =$datos_cli->objetivo_;
$referencia_= $datos_cli->referencia_;
}
//Aqui creamos el word con texto de prueba
// Abriendo la plantilla
$TemplateProcessor= new TemplateProcessor(Storage_path('Estudio_Conexion.docx'));
$TemplateProcessor->setValue('nombre_cliente',$nombre_cli);
$TemplateProcessor->setValue('nombre_empresa',$empresa_cli);
$TemplateProcessor->setValue('Correo',$correo_cli);
$TemplateProcessor->setValue('direccion',$direccion_cli);
$TemplateProcessor->setValue('fecha',$fecha_cli);
$TemplateProcessor->setValue('referencia',$referencia_);
$TemplateProcessor->setValue('objetivo',$objetivo_);
$TemplateProcessor->setValue('actividades',$nombreacti1);
$TemplateProcessor->saveAs('cot1.docx');
return response()->download('cot1.docx');
In the word I assign the activities variable as follows:
I would like that array to be inserted as a list in that part of the document, but doing it this way gives me an error(Array to string conversion) and the document downloads corrupted.