How to Create Docx Files using php
How to create Docx Files using php. Yes, we need to create word Documents in certain places. So this article may help you to create your Docx file using php. Let’s start with working steps,
Just download the PHPWord extension from phpword.codeplex.com and extract from zip and copy it to your working location.
Now, create a php file by including the phpword.php main file.
<?php require_once('PHPWord.php'); // provide the exact path here. ?>
Now, we are going to use the phpword functions by extending the phpword and creating our own object.
$kv_phpword = new PHPWord();
Followed by we need to create the sections,
$kv_main_section = $kv_phpword->createSection();
Now, you can add texts, styles, image, and etc.
$kv_main_section->addText('Hi, welcome to Kvcodes Blog!');
Now, you can add text styles with the text,
$section->addText('Formated text.', array('name'=>'Arial', 'size'=>18, 'bold'=>true));
Also, you can add images with the help of following code.
$kv_main_section->addImage('logo.png', array('width'=>360, 'height'=>210, 'align'=>'center'));
and finally, you need to save the document, with the help of following code,
$kvcodes = PHPWord_IOFactory::createWriter($kv_phpword, 'Word2007'); $kvcodes->save('kvcodes-test-doc.docx');