Write an arrangement in word from laravel using php word?

1

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 using TemplateProcessor, the problem that I present is when I want to write a dynamic array in the word template, that contains the values of a query to the bd. the arrangement is: nombreacti1 ['futbol', '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 variable activities as follows:

I would like that array to be inserted as a list in that part of the document, but doing so in this way throws me an error (Array to string conversion) and the damaged download document.

    
asked by Ándres Felipe Patiño 30.04.2018 в 19:44
source

1 answer

1

Using the information provided by Malberez, make the following solution, here attached if someone serves:

$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 hago el implode con el salto de linea de word usando el arreglo 
$var=implode(" </w:t><w:br/><w:t> ",$nombreacti1);

// Creating the new document...
$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('algo',$var);


$TemplateProcessor->saveAs('cot1.docx');
return response()->download('cot1.docx');
    
answered by 30.04.2018 / 22:01
source