|
1 | 1 | # PHPWord - OpenXML - Read, Write and Create Word documents in PHP
|
| 2 | + |
2 | 3 | PHPWord is a library written in PHP that create word documents.
|
3 |
| -No Windows operating system is needed for usage because the result are docx files (Office Open XML) that can be opened by all major office software. |
| 4 | +No Windows operating system is needed for usage because the result are docx files (Office Open XML) that can be |
| 5 | +opened by all major office software. |
4 | 6 |
|
5 | 7 | ## Want to contribute?
|
6 | 8 | Fork us!
|
7 | 9 |
|
| 10 | +## Requirements |
| 11 | + |
| 12 | +* PHP version 5.2.0 or higher |
| 13 | + |
8 | 14 | ## License
|
9 |
| -PHPWord is licensed under [LGPL (GNU LESSER GENERAL PUBLIC LICENSE)](https://github.com/PHPOffice/PHPWord/blob/master/license.md) |
| 15 | +PHPWord is licensed under [LGPL (GNU LESSER GENERAL PUBLIC LICENSE)](https://github.com/PHPOffice/PHPWord/blob/master/license.md) |
| 16 | + |
| 17 | +## Installation |
| 18 | + |
| 19 | +It is recommended that you install the PHPWord library [through composer](http://getcomposer.org/). To do so, add |
| 20 | +the following lines to your ``composer.json``. |
| 21 | + |
| 22 | +```json |
| 23 | +{ |
| 24 | + "require": { |
| 25 | + "phpoffice/phpword": "dev-master" |
| 26 | + } |
| 27 | +} |
| 28 | +``` |
| 29 | + |
| 30 | +## Usage |
| 31 | + |
| 32 | +The following is a basic example of the PHPWord library. |
| 33 | + |
| 34 | +```php |
| 35 | +// Create a new PHPWord Object |
| 36 | +$PHPWord = new PHPWord(); |
| 37 | + |
| 38 | +// Every element you want to append to the word document is placed in a section. So you need a section: |
| 39 | +$section = $PHPWord->createSection(); |
| 40 | + |
| 41 | +// After creating a section, you can append elements: |
| 42 | +$section->addText('Hello world!'); |
| 43 | + |
| 44 | +// You can directly style your text by giving the addText function an array: |
| 45 | +$section->addText('Hello world! I am formatted.', array('name'=>'Tahoma', 'size'=>16, 'bold'=>true)); |
| 46 | + |
| 47 | +// If you often need the same style again you can create a user defined style to the word document |
| 48 | +// and give the addText function the name of the style: |
| 49 | +$PHPWord->addFontStyle('myOwnStyle', array('name'=>'Verdana', 'size'=>14, 'color'=>'1B2232')); |
| 50 | +$section->addText('Hello world! I am formatted by a user defined style', 'myOwnStyle'); |
| 51 | + |
| 52 | +// You can also putthe appended element to local object an call functions like this: |
| 53 | +$myTextElement = $section->addText('Hello World!'); |
| 54 | +$myTextElement->setBold(); |
| 55 | +$myTextElement->setName('Verdana'); |
| 56 | +$myTextElement->setSize(22); |
| 57 | + |
| 58 | +// At least write the document to webspace: |
| 59 | +$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); |
| 60 | +$objWriter->save('helloWorld.docx'); |
| 61 | +``` |
0 commit comments