/** * Generate doc and download. * * @param int $id * @return \Illuminate\Http\Response */ public function download($id) { $poder = Poder::findOrFail($id); $phpWord = new PhpWord(); $template = public_path() . "/download/poderespecial.docx"; $file = public_path() . "/download/" . $poder->id . "-" . $poder->poderante . ".docx"; $download = $phpWord->loadTemplate($template); $d_fecha = new DateTime($poder->fecha); $s_fecha = new DateTime($poder->fecha_siniestro); $download->setValue('dia_fecha', $d_fecha->format("d")); $download->setValue('mes_fecha', getMes($d_fecha->format("m"))); $download->setValue('ano_fecha', trim(valorEnLetras((int) $d_fecha->format("Y")))); $download->setValue('poderante', strtoupper($poder->poderante)); $download->setValue('dni', $poder->dni); $download->setValue('direccion', strtoupper($poder->direccion)); $download->setValue('localidad', $poder->localidad); $download->setValue('demandado', strtoupper($poder->demandado)); $download->setValue('aseguradora', strtoupper($poder->aseguradora)); $download->setValue('fecha_siniestro', $s_fecha->format("d") . "." . $s_fecha->format("m") . "." . $s_fecha->format("Y")); $download->setValue('dominio_siniestro', $poder->dominio_siniestro); $download->setValue('direccion_siniestro', strtoupper($poder->direccion_siniestro)); $download->setValue('localidad', $poder->localidad); $download->saveAs($file); $headers = array('Content-Type: application/docx'); return response()->download($file, $poder->id . "-" . $poder->poderante . ".docx", $headers); }
/** * Test load template exception * * @expectedException \PhpOffice\PhpWord\Exception\Exception */ public function testLoadTemplateException() { $templateFqfn = join(DIRECTORY_SEPARATOR, array(PHPWORD_TESTS_BASE_DIR, 'PhpWord', 'Tests', '_files', 'templates', 'blanks.docx')); $phpWord = new PhpWord(); $phpWord->loadTemplate($templateFqfn); }
/** * Generate doc and download. * * @param int $id * @return \Illuminate\Http\Response */ public function download($id) { $document = Document::findOrFail($id); $phpWord = new PhpWord(); $template = public_path() . "/download/template.docx"; $file = public_path() . "/download/result.docx"; $download = $phpWord->loadTemplate($template); $download->setValue('COMPANY', $document->company); $download->setValue('OWNER', $document->owner); $download->saveAs($file); $headers = array('Content-Type: application/docx'); return response()->download($file, 'result.docx', $headers); }