This project is read-only.


  • PHP 5.2.x or newer
  • PHP Extension ZipArchive
  • PHP Extension xmllib
  • For opening by PHPWord created files in Microsoft Office < 2007 you need the "Microsoft Office Compatibility Pack". You can get it here for free: Microsoft Office Compability Pack

Installation and configuration

Installation and configuration is very easy:
  • Extract the ZIP-Archive
  • Copy the source files to your webserver
  • If your PHPWord working directory isn't your PHP include path you can set the PHPWord base path. To set the PHPWord base path open the PHPWord.php inside the root folder and edit the value of PHPWORD_BASE_PATH constant.

Basic example

// Include the PHPWord.php, all other classes were loaded by an autoloader
require_once 'PHPWord.php';

// Create a new PHPWord Object
$PHPWord = new PHPWord();

// Every element you want to append to the word document is placed in a section. So you need a section:
$section = $PHPWord->createSection();

// After creating a section, you can append elements:
$section->addText('Hello world!');

// You can directly style your text by giving the addText function an array:
$section->addText('Hello world! I am formatted.', array('name'=>'Tahoma', 'size'=>16, 'bold'=>true));

// If you often need the same style again you can create a user defined style to the word document
// and give the addText function the name of the style:
$PHPWord->addFontStyle('myOwnStyle', array('name'=>'Verdana', 'size'=>14, 'color'=>'1B2232'));
$section->addText('Hello world! I am formatted by a user defined style', 'myOwnStyle');

// You can also putthe appended element to local object an call functions like this:
$myTextElement = $section->addText('Hello World!');

// At least write the document to webspace:
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');


You can download examples and a full documentation of PHPWord here

Font Style changes between 0.6.1 and 0.6.2:

With the release 0.6.2 the paragraph properties has been moved into a separate Class!
So, every text element now has two style properties: FONT and PARAGRAPH. See the following example for more information:

// OLD release, 0.6.1:
$styleFont = array('bold'=>true, 'size'=>16, 'name'=>'Calibri', 'align'=>'center', 'spaceAfter'=>100);
$section->addText('Hello World', $styleFont);

// NEW release, 0.6.2:
$styleFont = array('bold'=>true, 'size'=>16, 'name'=>'Calibri');
$styleParagraph = array('align'=>'center', 'spaceAfter'=>100);
$section->addText('Hello World', $styleFont, $styleParagraph);

Last edited Jul 25, 2010 at 8:56 PM by raw_venture_ad, version 18


vesalio Feb 6 at 6:22 AM 
how can i set an image in a certain position

biplabd Feb 25, 2016 at 3:25 AM 
I used the example of Template.php to replace some value. I have used ${variable} for some reason it not replacing the value but your example works ok if use new variable get problem

vancent Aug 20, 2015 at 3:39 AM 
some parts of the functions are missing, but it is still great job!!

bayuforest Jun 1, 2015 at 9:38 AM 
how to insert new line on a cell table? I've tried this: $table->addCell(4000)->addText($nama." <br /> ".$nip);
but code above doesn't give me a line break.

ozaarm Oct 21, 2014 at 3:07 PM 
Re: the styling, setBold(), setSize() may have disappeared, but this from /Examples/Text.php worked :

$PHPWord->addFontStyle('myStyle1', array('bold'=>true, 'italic'=>true, 'size'=>16));
$section->addText('Hello text with the new stylish style !','myStyle1');

ozaarm Oct 21, 2014 at 2:50 PM 
same as fallphenix Aug 1 at 2:00 PM, with the example code around setBold and setSize, commented out and it worked.

PHP Fatal error: Call to undefined method PHPWord_Section_Text::setBold()
PHP Fatal error: Call to undefined method PHPWord_Section_Text::setSize()

Pratiksha2211 Aug 6, 2014 at 7:23 AM 
Its work good but sometime i have problem with some special characters like &,$ etc.. and is there any way to read and write doc file ??

fallphenix Aug 1, 2014 at 1:00 PM 
error over :
$myTextElement = $section->addText('Hello World!');

private '_text' => string 'Hello World!' (length=12)
private '_styleFont' => null
private '_styleParagraph' => null

setter setBold(),..; are undifined

yangbai May 24, 2014 at 1:51 PM 

rahmuna Feb 26, 2014 at 9:43 AM 
i can not open the file in webpage

hake12308 Dec 18, 2013 at 3:19 AM 
hi,can it make the part of word document protected? the name in the word office is limited to edit.

JackStone Nov 25, 2013 at 8:51 PM 
Is there just a simple find-and-replace function? I want to be able to go into an existing section and replace the text there.

hervehant Aug 19, 2013 at 12:58 PM 
I wonder how two columns in a word document in php from PHPWord

kishore1587 Mar 13, 2013 at 4:36 PM 
Hi i m new for this
please let me know
How to add table in word file using this PHP word?

huanga Oct 9, 2012 at 6:31 PM 
docx uses a very special unit for calculating width and height, etc. It took me a long time to search for it. In case you need to set a length too read this first:

djodjo Oct 2, 2012 at 8:51 AM 
Is it possible to open a doc file, change properties (title, tags, subject, ...) and save the file ?

papyloup Jul 9, 2012 at 1:54 PM 
any possibilité to read a docx file with bookmarks or position of cursor ?

sreevathsanr Jun 22, 2012 at 7:36 PM 
hey.. i want to create a msword 2003 file. i am doubtful whether it supports, if so, can u help me pls.. Thanks in Advance

danivu May 21, 2012 at 2:10 PM 
great tool, but some problem with utf-8 characters

Maybe could be done same as is done odtPHP for OpenOffice, use formated document template and fill with data. This is ismplest and easiest way to create document,
each client can have his own style without changing the source code

caashie Jan 23, 2012 at 1:51 PM 
need help with utf-8 support...

onekit Jul 20, 2011 at 9:06 AM 
I have found the reason why Cyrillic didn't displayed correct. The library in Section.php do utf8_encode() twice. English letters don't care about double utf8_encode(), but russian letters turns to abracadabra-language. So, remark all of utf8_encode() functions in Section.php and all work done. Need not to encode to utf8 without checking if it already in utf8. If source already in UTF-8, then we'll needn't to encode it.

onekit Jul 18, 2011 at 8:47 AM 
Problem with UTF-8, can't write Cyrillic.

hardikhardik May 18, 2011 at 2:06 PM 
Its great....Is there any possibilities to read docx document?

lagrandeours May 4, 2011 at 12:35 AM 
it's work great ... But : i have some problems with with utf-8 characters, do you have any idea how to solve this matter ...

panuwat27 Mar 7, 2011 at 5:50 PM