Update basic example

This commit is contained in:
Ivan Lanin 2014-06-08 22:38:50 +07:00
parent 6839ee41dd
commit 1ec0589c55
4 changed files with 23 additions and 14 deletions

View File

@ -67,11 +67,14 @@ require_once 'path/to/PhpWord/src/PhpWord/Autoloader.php';
\PhpOffice\PhpWord\Autoloader::register();
```
## Usages
## Getting started
The following is a basic example of the PHPWord library. More examples are provided in the [samples folder](samples/).
The following is a basic usage example of the PHPWord library.
```php
require_once 'src/PhpWord/Autoloader.php';
\PhpOffice\PhpWord\Autoloader::register();
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// Every element you want to append to the word document is placed in a section.
@ -93,10 +96,11 @@ $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 \PhpOffice\PhpWord\Style\Font();
$fontStyle->setBold(true);
$fontStyle->setName('Verdana');
$fontStyle->setSize(22);
$fontStyle = array(
'name' => 'Verdana',
'size' => 22,
'bold' => true,
);
$myTextElement = $section->addText('Hello World!');
$myTextElement->setFontStyle($fontStyle);
@ -106,6 +110,8 @@ $phpWord->save('helloWorld.odt', 'ODText');
$phpWord->save('helloWorld.rtf', 'RTF');
```
More examples are provided in the [samples folder](samples/). You can also read the [Developers' Documentation](http://phpword.readthedocs.org/) and the [API Documentation](http://phpoffice.github.io/PHPWord/docs/develop/) for more detail.
## Known issues
- GH-238: PHPWord uses temporary folder with `sys_get_temp_dir()` extensively. The default setting on some systems (especially Windows) do not give appropriate read/write permission to this folder. Run `samples/index.php` either by CLI or by web browsers to check if you have this requirement fulfilled.

View File

@ -36,10 +36,11 @@ folder <https://github.com/PHPOffice/PHPWord/tree/master/samples/>`__.
'myOwnStyle');
// You can also put the appended element to local object like this:
$fontStyle = new \PhpOffice\PhpWord\Style\Font();
$fontStyle->setBold(true);
$fontStyle->setName('Verdana');
$fontStyle->setSize(22);
$fontStyle = array(
'name' => 'Verdana',
'size' => 22,
'bold' => true,
);
$myTextElement = $section->addText('Hello World!');
$myTextElement->setFontStyle($fontStyle);

View File

@ -231,10 +231,11 @@ $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 \PhpOffice\PhpWord\Style\Font();
$fontStyle->setBold(true);
$fontStyle->setName('Verdana');
$fontStyle->setSize(22);
$fontStyle = array(
'name' => 'Verdana',
'size' => 22,
'bold' => true,
);
$myTextElement = $section->addText('Hello World!');
$myTextElement->setFontStyle($fontStyle);

View File

@ -280,6 +280,7 @@ class PhpWord
'PDF' => 'application/pdf',
);
/** @var \PhpOffice\PhpWord\Writer\WriterInterface $writer */
$writer = IOFactory::createWriter($this, $format);
if ($download === true) {