@@ -33,3 +33,69 @@ __Want to contribute?__ [Fork us](https://github.com/PHPOffice/PHPWord/fork) or
33
33
34
34
__ Want to know more?__ Read the full documentation of PHPWord on [ Read The Docs] ( http://phpword.readthedocs.org/en/develop/ ) .
35
35
36
+ ## Requirements
37
+ * PHP 5.3+
38
+ * PHP [ Zip] ( http://php.net/manual/en/book.zip.php ) extension
39
+ * PHP [ XML Parser] ( http://www.php.net/manual/en/xml.installation.php ) extension
40
+
41
+ ### Optional PHP extensions
42
+ * PHP [ GD] ( http://php.net/manual/en/book.image.php ) extension
43
+ * PHP [ XMLWriter] ( http://php.net/manual/en/book.xmlwriter.php ) extension
44
+ * PHP [ XSL] ( http://php.net/manual/en/book.xsl.php ) extension
45
+
46
+ ## Installation
47
+
48
+ It is recommended that you install the PHPWord library [ through composer] ( http://getcomposer.org/ ) . To do so, add
49
+ the following lines to your `` composer.json `` .
50
+
51
+ ``` json
52
+ {
53
+ "require" : {
54
+ "phpoffice/phpword" : " dev-master"
55
+ }
56
+ }
57
+ ```
58
+
59
+ ## Basic usage
60
+
61
+ The following is a basic example of the PHPWord library. More examples are provided in the [ samples folder] ( samples/ ) .
62
+
63
+ ``` php
64
+ $PHPWord = new PHPWord();
65
+
66
+ // Every element you want to append to the word document is placed in a section.
67
+ // To create a basic section:
68
+ $section = $PHPWord->createSection();
69
+
70
+ // After creating a section, you can append elements:
71
+ $section->addText('Hello world!');
72
+
73
+ // You can directly style your text by giving the addText function an array:
74
+ $section->addText('Hello world! I am formatted.',
75
+ array('name'=>'Tahoma', 'size'=>16, 'bold'=>true));
76
+
77
+ // If you often need the same style again you can create a user defined style
78
+ // to the word document and give the addText function the name of the style:
79
+ $PHPWord->addFontStyle('myOwnStyle',
80
+ array('name'=>'Verdana', 'size'=>14, 'color'=>'1B2232'));
81
+ $section->addText('Hello world! I am formatted by a user defined style',
82
+ 'myOwnStyle');
83
+
84
+ // You can also put the appended element to local object like this:
85
+ $fontStyle = new PHPWord_Style_Font();
86
+ $fontStyle->setBold(true);
87
+ $fontStyle->setName('Verdana');
88
+ $fontStyle->setSize(22);
89
+ $myTextElement = $section->addText('Hello World!');
90
+ $myTextElement->setFontStyle($fontStyle);
91
+
92
+ // Finally, write the document:
93
+ $objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
94
+ $objWriter->save('helloWorld.docx');
95
+
96
+ $objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'ODText');
97
+ $objWriter->save('helloWorld.odt');
98
+
99
+ $objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'RTF');
100
+ $objWriter->save('helloWorld.rtf');
101
+ ```
0 commit comments