From db2460fc49687aa883c8265ba54b418d28d6ac8e Mon Sep 17 00:00:00 2001 From: Progi1984 Date: Tue, 25 Mar 2014 13:11:52 +0100 Subject: [PATCH] Update Readme.MD for improving the first introduction --- README.md | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/README.md b/README.md index d796dba3..6317dd13 100755 --- a/README.md +++ b/README.md @@ -33,3 +33,69 @@ __Want to contribute?__ [Fork us](https://github.com/PHPOffice/PHPWord/fork) or __Want to know more?__ Read the full documentation of PHPWord on [Read The Docs](http://phpword.readthedocs.org/en/develop/). +## Requirements +* PHP 5.3+ +* PHP [Zip](http://php.net/manual/en/book.zip.php) extension +* PHP [XML Parser](http://www.php.net/manual/en/xml.installation.php) extension + +### Optional PHP extensions +* PHP [GD](http://php.net/manual/en/book.image.php) extension +* PHP [XMLWriter](http://php.net/manual/en/book.xmlwriter.php) extension +* PHP [XSL](http://php.net/manual/en/book.xsl.php) extension + +## Installation + +It is recommended that you install the PHPWord library [through composer](http://getcomposer.org/). To do so, add +the following lines to your ``composer.json``. + +```json +{ + "require": { + "phpoffice/phpword": "dev-master" + } +} +``` + +## Basic usage + +The following is a basic example of the PHPWord library. More examples are provided in the [samples folder](samples/). + +```php +$PHPWord = new PHPWord(); + +// Every element you want to append to the word document is placed in a section. +// To create a basic 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 put the appended element to local object like this: +$fontStyle = new PHPWord_Style_Font(); +$fontStyle->setBold(true); +$fontStyle->setName('Verdana'); +$fontStyle->setSize(22); +$myTextElement = $section->addText('Hello World!'); +$myTextElement->setFontStyle($fontStyle); + +// Finally, write the document: +$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); +$objWriter->save('helloWorld.docx'); + +$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'ODText'); +$objWriter->save('helloWorld.odt'); + +$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'RTF'); +$objWriter->save('helloWorld.rtf'); +```