|
1 |
| -# PHPWord |
2 |
| - |
3 |
| -[](https://travis-ci.org/PHPOffice/PHPWord) |
4 |
| -[](https://packagist.org/packages/phpoffice/phpword) [](https://packagist.org/packages/phpoffice/phpword) [](https://packagist.org/packages/phpoffice/phpword) [](https://packagist.org/packages/phpoffice/phpword) |
5 |
| - |
6 |
| -__OpenXML - Read, Write and Create Word documents in PHP.__ |
7 |
| - |
8 |
| -PHPWord is a library written in PHP that create word documents. |
9 |
| - |
10 |
| -No Windows operating system is needed for usage because the result are docx files (Office Open XML) that can be |
11 |
| -opened by all major office software. |
12 |
| - |
13 |
| -__Want to contribute?__ Fork us! |
14 |
| - |
15 |
| -## Requirements |
16 |
| - |
17 |
| -* PHP version 5.3.0 or higher |
18 |
| - |
19 |
| -## Installation |
20 |
| - |
21 |
| -It is recommended that you install the PHPWord library [through composer](http://getcomposer.org/). To do so, add |
22 |
| -the following lines to your ``composer.json``. |
23 |
| - |
24 |
| -```json |
25 |
| -{ |
26 |
| - "require": { |
27 |
| - "phpoffice/phpword": "dev-master" |
28 |
| - } |
29 |
| -} |
30 |
| -``` |
31 |
| - |
32 |
| -## Documentation |
33 |
| - |
34 |
| -### Table of contents |
35 |
| - |
36 |
| -1. [Basic usage](#basic-usage) |
37 |
| -2. [Sections](#sections) |
38 |
| - * [Change Section Page Numbering](#sections-page-numbering) |
39 |
| -3. [Tables](#tables) |
40 |
| - * [Cell Style](#tables-cell-style) |
41 |
| -4. [Images](#images) |
42 |
| - |
43 |
| -<a name="basic-usage"></a> |
44 |
| -#### Basic usage |
45 |
| - |
46 |
| -The following is a basic example of the PHPWord library. |
47 |
| - |
48 |
| -```php |
49 |
| -$PHPWord = new PHPWord(); |
50 |
| - |
51 |
| -// Every element you want to append to the word document is placed in a section. So you need a section: |
52 |
| -$section = $PHPWord->createSection(); |
53 |
| - |
54 |
| -// After creating a section, you can append elements: |
55 |
| -$section->addText('Hello world!'); |
56 |
| - |
57 |
| -// You can directly style your text by giving the addText function an array: |
58 |
| -$section->addText('Hello world! I am formatted.', array('name'=>'Tahoma', 'size'=>16, 'bold'=>true)); |
59 |
| - |
60 |
| -// If you often need the same style again you can create a user defined style to the word document |
61 |
| -// and give the addText function the name of the style: |
62 |
| -$PHPWord->addFontStyle('myOwnStyle', array('name'=>'Verdana', 'size'=>14, 'color'=>'1B2232')); |
63 |
| -$section->addText('Hello world! I am formatted by a user defined style', 'myOwnStyle'); |
64 |
| - |
65 |
| -// You can also putthe appended element to local object an call functions like this: |
66 |
| -$myTextElement = $section->addText('Hello World!'); |
67 |
| -$myTextElement->setBold(); |
68 |
| -$myTextElement->setName('Verdana'); |
69 |
| -$myTextElement->setSize(22); |
70 |
| - |
71 |
| -// At least write the document to webspace: |
72 |
| -$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); |
73 |
| -$objWriter->save('helloWorld.docx'); |
74 |
| -``` |
75 |
| - |
76 |
| -<a name="sections"></a> |
77 |
| -#### Sections |
78 |
| - |
79 |
| -<a name="sections-page-numbering"></a> |
80 |
| -##### Change Section Page Numbering |
81 |
| - |
82 |
| -You can change a section page numbering. |
83 |
| - |
84 |
| -```php |
85 |
| -$section = $PHPWord->createSection(); |
86 |
| -$section->getSettings()->setPageNumberingStart(1); |
87 |
| -``` |
88 |
| - |
89 |
| -<a name="tables"></a> |
90 |
| -#### Tables |
91 |
| - |
92 |
| -The following illustrates how to create a table. |
93 |
| - |
94 |
| -```php |
95 |
| -$table = $section->addTable(); |
96 |
| -$table->addRow(); |
97 |
| -$table->addCell(); |
98 |
| -``` |
99 |
| - |
100 |
| -<a name="tables-cell-style"></a> |
101 |
| -##### Cell Style |
102 |
| - |
103 |
| -###### Cell Span |
104 |
| - |
105 |
| -You can span a cell on multiple columms. |
106 |
| - |
107 |
| -```php |
108 |
| -$cell = $table->addCell(200); |
109 |
| -$cell->getStyle()->setGridSpan(5); |
110 |
| -``` |
111 |
| - |
112 |
| -<a name="images"></a> |
113 |
| -#### Images |
114 |
| - |
115 |
| -You can add images easily using the following example. |
116 |
| - |
117 |
| -```php |
118 |
| -$section = $PHPWord->createSection(); |
119 |
| -$section->addImage('mars.jpg'); |
120 |
| -``` |
121 |
| - |
122 |
| -Images settings include: |
123 |
| -* ``width`` width in pixels |
124 |
| -* ``height`` height in pixels |
125 |
| -* ``align`` image alignment, _left_, _right_ or _center_ |
126 |
| -* ``marginTop`` top margin in inches, can be negative |
127 |
| -* ``marginLeft`` left margin in inches, can be negative |
128 |
| -* ``wrappingStyle`` can be _inline_, _square_, _tight_, _behind_, _infront_ |
129 |
| - |
130 |
| -To add an image with settings, consider the following example. |
131 |
| - |
132 |
| -```php |
133 |
| -$section->addImage( |
134 |
| - 'mars.jpg', |
135 |
| - array( |
136 |
| - 'width' => 100, |
137 |
| - 'height' => 100, |
138 |
| - 'marginTop' => -1, |
139 |
| - 'marginLeft' => -1, |
140 |
| - 'wrappingStyle' => 'behind' |
141 |
| - ) |
142 |
| -); |
143 |
| - ``` |
| 1 | +# PHPWord |
| 2 | + |
| 3 | +[](https://travis-ci.org/PHPOffice/PHPWord) |
| 4 | +[](https://packagist.org/packages/phpoffice/phpword) [](https://packagist.org/packages/phpoffice/phpword) [](https://packagist.org/packages/phpoffice/phpword) [](https://packagist.org/packages/phpoffice/phpword) |
| 5 | + |
| 6 | +__OpenXML - Read, Write and Create Word documents in PHP.__ |
| 7 | + |
| 8 | +PHPWord is a library written in PHP that create word documents. |
| 9 | + |
| 10 | +No Windows operating system is needed for usage because the result are docx files (Office Open XML) that can be |
| 11 | +opened by all major office software. |
| 12 | + |
| 13 | +__Want to contribute?__ Fork us! |
| 14 | + |
| 15 | +## Requirements |
| 16 | + |
| 17 | +* PHP version 5.3.0 or higher |
| 18 | + |
| 19 | +## Installation |
| 20 | + |
| 21 | +It is recommended that you install the PHPWord library [through composer](http://getcomposer.org/). To do so, add |
| 22 | +the following lines to your ``composer.json``. |
| 23 | + |
| 24 | +```json |
| 25 | +{ |
| 26 | + "require": { |
| 27 | + "phpoffice/phpword": "dev-master" |
| 28 | + } |
| 29 | +} |
| 30 | +``` |
| 31 | + |
| 32 | +## Documentation |
| 33 | + |
| 34 | +### Table of contents |
| 35 | + |
| 36 | +1. [Basic usage](#basic-usage) |
| 37 | +2. [Sections](#sections) |
| 38 | + * [Change Section Page Numbering](#sections-page-numbering) |
| 39 | +3. [Tables](#tables) |
| 40 | + * [Cell Style](#tables-cell-style) |
| 41 | +4. [Images](#images) |
| 42 | + |
| 43 | +<a name="basic-usage"></a> |
| 44 | +#### Basic usage |
| 45 | + |
| 46 | +The following is a basic example of the PHPWord library. |
| 47 | + |
| 48 | +```php |
| 49 | +$PHPWord = new PHPWord(); |
| 50 | + |
| 51 | +// Every element you want to append to the word document is placed in a section. So you need a section: |
| 52 | +$section = $PHPWord->createSection(); |
| 53 | + |
| 54 | +// After creating a section, you can append elements: |
| 55 | +$section->addText('Hello world!'); |
| 56 | + |
| 57 | +// You can directly style your text by giving the addText function an array: |
| 58 | +$section->addText('Hello world! I am formatted.', array('name'=>'Tahoma', 'size'=>16, 'bold'=>true)); |
| 59 | + |
| 60 | +// If you often need the same style again you can create a user defined style to the word document |
| 61 | +// and give the addText function the name of the style: |
| 62 | +$PHPWord->addFontStyle('myOwnStyle', array('name'=>'Verdana', 'size'=>14, 'color'=>'1B2232')); |
| 63 | +$section->addText('Hello world! I am formatted by a user defined style', 'myOwnStyle'); |
| 64 | + |
| 65 | +// You can also putthe appended element to local object an call functions like this: |
| 66 | +$myTextElement = $section->addText('Hello World!'); |
| 67 | +$myTextElement->setBold(); |
| 68 | +$myTextElement->setName('Verdana'); |
| 69 | +$myTextElement->setSize(22); |
| 70 | + |
| 71 | +// At least write the document to webspace: |
| 72 | +$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); |
| 73 | +$objWriter->save('helloWorld.docx'); |
| 74 | +``` |
| 75 | + |
| 76 | +<a name="sections"></a> |
| 77 | +#### Sections |
| 78 | + |
| 79 | +<a name="sections-page-numbering"></a> |
| 80 | +##### Change Section Page Numbering |
| 81 | + |
| 82 | +You can change a section page numbering. |
| 83 | + |
| 84 | +```php |
| 85 | +$section = $PHPWord->createSection(); |
| 86 | +$section->getSettings()->setPageNumberingStart(1); |
| 87 | +``` |
| 88 | + |
| 89 | +<a name="tables"></a> |
| 90 | +#### Tables |
| 91 | + |
| 92 | +The following illustrates how to create a table. |
| 93 | + |
| 94 | +```php |
| 95 | +$table = $section->addTable(); |
| 96 | +$table->addRow(); |
| 97 | +$table->addCell(); |
| 98 | +``` |
| 99 | + |
| 100 | +<a name="tables-cell-style"></a> |
| 101 | +##### Cell Style |
| 102 | + |
| 103 | +###### Cell Span |
| 104 | + |
| 105 | +You can span a cell on multiple columms. |
| 106 | + |
| 107 | +```php |
| 108 | +$cell = $table->addCell(200); |
| 109 | +$cell->getStyle()->setGridSpan(5); |
| 110 | +``` |
| 111 | + |
| 112 | +<a name="images"></a> |
| 113 | +#### Images |
| 114 | + |
| 115 | +You can add images easily using the following example. |
| 116 | + |
| 117 | +```php |
| 118 | +$section = $PHPWord->createSection(); |
| 119 | +$section->addImage('mars.jpg'); |
| 120 | +``` |
| 121 | + |
| 122 | +Images settings include: |
| 123 | +* ``width`` width in pixels |
| 124 | +* ``height`` height in pixels |
| 125 | +* ``align`` image alignment, _left_, _right_ or _center_ |
| 126 | +* ``marginTop`` top margin in inches, can be negative |
| 127 | +* ``marginLeft`` left margin in inches, can be negative |
| 128 | +* ``wrappingStyle`` can be _inline_, _square_, _tight_, _behind_, _infront_ |
| 129 | + |
| 130 | +To add an image with settings, consider the following example. |
| 131 | + |
| 132 | +```php |
| 133 | +$section->addImage( |
| 134 | + 'mars.jpg', |
| 135 | + array( |
| 136 | + 'width' => 100, |
| 137 | + 'height' => 100, |
| 138 | + 'marginTop' => -1, |
| 139 | + 'marginLeft' => -1, |
| 140 | + 'wrappingStyle' => 'behind' |
| 141 | + ) |
| 142 | +); |
| 143 | + ``` |
0 commit comments