Descargar plantilla ya creada en word con phpword |
Saludos comunidad, necesito ayuda con la librería phpword.
Necesito poder descargar una plantilla de word ya creada con la librería de phpword. Esta es mi función que esta en el controlador: public function word(){ $phpWord = new \PhpOffice\PhpWord\PhpWord(); $section = $phpWord->addSection(); $section->addText('"Learn from yesterday, live for today, hope for tomorrow. ' . 'The important thing is not to stop questioning." ' . '(Albert Einstein)'); $section->addText('Great achievement is usually born of great sacrifice, ' . 'and is never the result of selfishness. (Napoleon Hill)', array('name' => 'Tahoma', 'size' => 10)); $fontStyleName = 'oneUserDefinedStyle'; $phpWord->addFontStyle($fontStyleName, array('name' => 'Tahoma', 'size' => 10, 'color' => '1B2232', 'bold' => true)); $section->addText('"The greatest accomplishment is not in never falling, ' . 'but in rising again after you fall." ' . '(Vince Lombardi)', $fontStyleName); $fontStyle = new \PhpOffice\PhpWord\Style\Font(); $fontStyle->setBold(true); $fontStyle->setName('Tahoma'); $fontStyle->setSize(13); $myTextElement = $section->addText('"Believe you can and you\'re halfway there." (Theodor Roosevelt)'); $myTextElement->setFontStyle($fontStyle); $file = 'HelloWorld.docx'; header("Content-Description: File Transfer"); header('Content-Disposition: attachment; filename="' . $file . '"'); header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document'); header('Content-Transfer-Encoding: binary'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Expires: 0'); $xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007'); $xmlWriter->save("php://output"); }
someto a su consideración el siguiente ejemplo:
PHP Code: <?php NOTA: funciona para versiones menores a CodeIgniter-3.1.6 NOTA 2: si alguien sabe como aplicarlo a versiones superiores a 3.1.5 favor de compartir sintaxis. |
Welcome Guest, Not a member yet? Register Sign In |