|
1 |
| -#  |
2 |
| - |
3 |
| -[](https://travis-ci.org/PHPOffice/PHPWord) |
4 |
| -[](https://packagist.org/packages/phpoffice/phpword) |
5 |
| -[](https://packagist.org/packages/phpoffice/phpword) |
6 |
| -[](https://packagist.org/packages/phpoffice/phpword) |
7 |
| -[](https://packagist.org/packages/phpoffice/phpword) |
8 |
| - |
9 |
| - |
10 |
| -PHPWord is a library written in pure PHP that provides a set of classes to write to and read from different document file formats. The current version of PHPWord supports Microsoft [Office Open XML](http://en.wikipedia.org/wiki/Office_Open_XML) (OOXML or OpenXML), OASIS [Open Document Format for Office Applications](http://en.wikipedia.org/wiki/OpenDocument) (OpenDocument or ODF), and [Rich Text Format](http://en.wikipedia.org/wiki/Rich_Text_Format) (RTF). |
11 |
| - |
12 |
| -With PHPWord, you can create DOCX, ODT, or RTF documents dynamically using your PHP 5.3+ scripts. Below are some of the things that you can do with PHPWord library: |
13 |
| - |
14 |
| -* Set document properties, e.g. title, subject, and creator. |
15 |
| -* Create document sections with different settings, e.g. portrait/landscape, page size, and page numbering |
16 |
| -* Create header and footer for each sections |
17 |
| -* Set default font type, font size, and paragraph style |
18 |
| -* Use UTF-8 and East Asia fonts/characters |
19 |
| -* Define custom font styles (e.g. bold, italic, color) and paragraph styles (e.g. centered, multicolumns, spacing) either as named style or inline in text |
20 |
| -* Insert paragraphs, either as a simple text or complex one (a text run) that contains other elements |
21 |
| -* Insert titles (headers) and table of contents |
22 |
| -* Insert text breaks and page breaks |
23 |
| -* Insert and format images, either local, remote, or as page watermarks |
24 |
| -* Insert binary OLE Objects such as Excel or Visio |
25 |
| -* Insert and format table with customized properties for each rows (e.g. repeat as header row) and cells (e.g. background color, rowspan, colspan) |
26 |
| -* Insert list items as bulleted, numbered, or multilevel |
27 |
| -* Insert hyperlinks |
28 |
| -* Create document from templates |
29 |
| -* Use XSL 1.0 style sheets to transform main document part of OOXML template |
30 |
| -* ... and many more features on progress |
31 |
| - |
32 |
| -__Want to contribute?__ [Fork us](https://github.com/PHPOffice/PHPWord/fork) or [submit](https://github.com/PHPOffice/PHPWord/issues) your bug reports or feature requests to us. |
33 |
| - |
34 |
| -## Requirements |
35 |
| -* PHP 5.3+ |
36 |
| -* PHP [Zip](http://php.net/manual/en/book.zip.php) extension |
37 |
| -* PHP [XML Parser](http://www.php.net/manual/en/xml.installation.php) extension |
38 |
| - |
39 |
| -### Optional PHP extensions |
40 |
| -* PHP [GD](http://php.net/manual/en/book.image.php) extension |
41 |
| -* PHP [XMLWriter](http://php.net/manual/en/book.xmlwriter.php) extension |
42 |
| -* PHP [XSL](http://php.net/manual/en/book.xsl.php) extension |
43 |
| - |
44 |
| -## Installation |
45 |
| - |
46 |
| -It is recommended that you install the PHPWord library [through composer](http://getcomposer.org/). To do so, add |
47 |
| -the following lines to your ``composer.json``. |
48 |
| - |
49 |
| -```json |
50 |
| -{ |
51 |
| - "require": { |
52 |
| - "phpoffice/phpword": "dev-master" |
53 |
| - } |
54 |
| -} |
55 |
| -``` |
56 |
| - |
57 |
| -Alternatively, you can download the latest release from the [releases page](https://github.com/PHPOffice/PHPWord/releases). |
58 |
| -In this case, you will have to register the autoloader. |
59 |
| - |
60 |
| -```php |
61 |
| -require_once 'path/to/PhpWord/src/PhpWord/Autoloader.php'; |
62 |
| -PhpOffice\PhpWord\Autoloader::register(); |
63 |
| -``` |
64 |
| - |
65 |
| -## Basic usage |
66 |
| - |
67 |
| -The following is a basic example of the PHPWord library. More examples are provided in the [samples folder](samples/). |
68 |
| - |
69 |
| -```php |
70 |
| -$phpWord = new \PhpOffice\PhpWord\PhpWord(); |
71 |
| - |
72 |
| -// Every element you want to append to the word document is placed in a section. |
73 |
| -// To create a basic section: |
74 |
| -$section = $phpWord->createSection(); |
75 |
| - |
76 |
| -// After creating a section, you can append elements: |
77 |
| -$section->addText('Hello world!'); |
78 |
| - |
79 |
| -// You can directly style your text by giving the addText function an array: |
80 |
| -$section->addText('Hello world! I am formatted.', |
81 |
| - array('name'=>'Tahoma', 'size'=>16, 'bold'=>true)); |
82 |
| - |
83 |
| -// If you often need the same style again you can create a user defined style |
84 |
| -// to the word document and give the addText function the name of the style: |
85 |
| -$phpWord->addFontStyle('myOwnStyle', |
86 |
| - array('name'=>'Verdana', 'size'=>14, 'color'=>'1B2232')); |
87 |
| -$section->addText('Hello world! I am formatted by a user defined style', |
88 |
| - 'myOwnStyle'); |
89 |
| - |
90 |
| -// You can also put the appended element to local object like this: |
91 |
| -$fontStyle = new \PhpOffice\PhpWord\Style\Font(); |
92 |
| -$fontStyle->setBold(true); |
93 |
| -$fontStyle->setName('Verdana'); |
94 |
| -$fontStyle->setSize(22); |
95 |
| -$myTextElement = $section->addText('Hello World!'); |
96 |
| -$myTextElement->setFontStyle($fontStyle); |
97 |
| - |
98 |
| -// Finally, write the document: |
99 |
| -$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007'); |
100 |
| -$objWriter->save('helloWorld.docx'); |
101 |
| - |
102 |
| -$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'ODText'); |
103 |
| -$objWriter->save('helloWorld.odt'); |
104 |
| - |
105 |
| -$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'RTF'); |
106 |
| -$objWriter->save('helloWorld.rtf'); |
107 |
| -``` |
108 |
| - |
109 |
| -## Documentation |
110 |
| - |
111 |
| -__Want to know more?__ Read the full documentation of PHPWord on [Read The Docs](http://phpword.readthedocs.org/). |
| 1 | +#  |
| 2 | + |
| 3 | +[](https://travis-ci.org/PHPOffice/PHPWord) |
| 4 | +[](https://packagist.org/packages/phpoffice/phpword) |
| 5 | +[](https://packagist.org/packages/phpoffice/phpword) |
| 6 | +[](https://packagist.org/packages/phpoffice/phpword) |
| 7 | +[](https://packagist.org/packages/phpoffice/phpword) |
| 8 | + |
| 9 | + |
| 10 | +PHPWord is a library written in pure PHP that provides a set of classes to write to and read from different document file formats. The current version of PHPWord supports Microsoft [Office Open XML](http://en.wikipedia.org/wiki/Office_Open_XML) (OOXML or OpenXML), OASIS [Open Document Format for Office Applications](http://en.wikipedia.org/wiki/OpenDocument) (OpenDocument or ODF), and [Rich Text Format](http://en.wikipedia.org/wiki/Rich_Text_Format) (RTF). |
| 11 | + |
| 12 | +With PHPWord, you can create DOCX, ODT, or RTF documents dynamically using your PHP 5.3+ scripts. Below are some of the things that you can do with PHPWord library: |
| 13 | + |
| 14 | +* Set document properties, e.g. title, subject, and creator. |
| 15 | +* Create document sections with different settings, e.g. portrait/landscape, page size, and page numbering |
| 16 | +* Create header and footer for each sections |
| 17 | +* Set default font type, font size, and paragraph style |
| 18 | +* Use UTF-8 and East Asia fonts/characters |
| 19 | +* Define custom font styles (e.g. bold, italic, color) and paragraph styles (e.g. centered, multicolumns, spacing) either as named style or inline in text |
| 20 | +* Insert paragraphs, either as a simple text or complex one (a text run) that contains other elements |
| 21 | +* Insert titles (headers) and table of contents |
| 22 | +* Insert text breaks and page breaks |
| 23 | +* Insert and format images, either local, remote, or as page watermarks |
| 24 | +* Insert binary OLE Objects such as Excel or Visio |
| 25 | +* Insert and format table with customized properties for each rows (e.g. repeat as header row) and cells (e.g. background color, rowspan, colspan) |
| 26 | +* Insert list items as bulleted, numbered, or multilevel |
| 27 | +* Insert hyperlinks |
| 28 | +* Insert footnotes and endnotes |
| 29 | +* Create document from templates |
| 30 | +* Use XSL 1.0 style sheets to transform main document part of OOXML template |
| 31 | +* ... and many more features on progress |
| 32 | + |
| 33 | +__Want to contribute?__ [Fork us](https://github.com/PHPOffice/PHPWord/fork) or [submit](https://github.com/PHPOffice/PHPWord/issues) your bug reports or feature requests to us. |
| 34 | + |
| 35 | +## Requirements |
| 36 | +* PHP 5.3+ |
| 37 | +* PHP [Zip](http://php.net/manual/en/book.zip.php) extension |
| 38 | +* PHP [XML Parser](http://www.php.net/manual/en/xml.installation.php) extension |
| 39 | + |
| 40 | +### Optional PHP extensions |
| 41 | +* PHP [GD](http://php.net/manual/en/book.image.php) extension |
| 42 | +* PHP [XMLWriter](http://php.net/manual/en/book.xmlwriter.php) extension |
| 43 | +* PHP [XSL](http://php.net/manual/en/book.xsl.php) extension |
| 44 | + |
| 45 | +## Installation |
| 46 | + |
| 47 | +It is recommended that you install the PHPWord library [through composer](http://getcomposer.org/). To do so, add |
| 48 | +the following lines to your ``composer.json``. |
| 49 | + |
| 50 | +```json |
| 51 | +{ |
| 52 | + "require": { |
| 53 | + "phpoffice/phpword": "dev-master" |
| 54 | + } |
| 55 | +} |
| 56 | +``` |
| 57 | + |
| 58 | +Alternatively, you can download the latest release from the [releases page](https://github.com/PHPOffice/PHPWord/releases). |
| 59 | +In this case, you will have to register the autoloader. |
| 60 | + |
| 61 | +```php |
| 62 | +require_once 'path/to/PhpWord/src/PhpWord/Autoloader.php'; |
| 63 | +\PhpOffice\PhpWord\Autoloader::register(); |
| 64 | +``` |
| 65 | + |
| 66 | +## Basic usage |
| 67 | + |
| 68 | +The following is a basic example of the PHPWord library. More examples are provided in the [samples folder](samples/). |
| 69 | + |
| 70 | +```php |
| 71 | +$phpWord = new \PhpOffice\PhpWord\PhpWord(); |
| 72 | + |
| 73 | +// Every element you want to append to the word document is placed in a section. |
| 74 | +// To create a basic section: |
| 75 | +$section = $phpWord->addSection(); |
| 76 | + |
| 77 | +// After creating a section, you can append elements: |
| 78 | +$section->addText('Hello world!'); |
| 79 | + |
| 80 | +// You can directly style your text by giving the addText function an array: |
| 81 | +$section->addText('Hello world! I am formatted.', |
| 82 | + array('name'=>'Tahoma', 'size'=>16, 'bold'=>true)); |
| 83 | + |
| 84 | +// If you often need the same style again you can create a user defined style |
| 85 | +// to the word document and give the addText function the name of the style: |
| 86 | +$phpWord->addFontStyle('myOwnStyle', |
| 87 | + array('name'=>'Verdana', 'size'=>14, 'color'=>'1B2232')); |
| 88 | +$section->addText('Hello world! I am formatted by a user defined style', |
| 89 | + 'myOwnStyle'); |
| 90 | + |
| 91 | +// You can also put the appended element to local object like this: |
| 92 | +$fontStyle = new \PhpOffice\PhpWord\Style\Font(); |
| 93 | +$fontStyle->setBold(true); |
| 94 | +$fontStyle->setName('Verdana'); |
| 95 | +$fontStyle->setSize(22); |
| 96 | +$myTextElement = $section->addText('Hello World!'); |
| 97 | +$myTextElement->setFontStyle($fontStyle); |
| 98 | + |
| 99 | +// Finally, write the document: |
| 100 | +$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007'); |
| 101 | +$objWriter->save('helloWorld.docx'); |
| 102 | + |
| 103 | +$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'ODText'); |
| 104 | +$objWriter->save('helloWorld.odt'); |
| 105 | + |
| 106 | +$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'RTF'); |
| 107 | +$objWriter->save('helloWorld.rtf'); |
| 108 | +``` |
| 109 | + |
| 110 | +## Documentation |
| 111 | + |
| 112 | +__Want to know more?__ Read the full documentation of PHPWord on [Read The Docs](http://phpword.readthedocs.org/). |
0 commit comments