Update Readme.MD for improving the first introduction

This commit is contained in:
Progi1984 2014-03-25 13:11:52 +01:00
parent e6466f0ee5
commit db2460fc49
1 changed files with 66 additions and 0 deletions

View File

@ -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');
```