@@ -50,29 +50,33 @@ The following is a basic example of the PHPWord library.
50
50
``` php
51
51
$PHPWord = new PHPWord();
52
52
53
- // Every element you want to append to the word document is placed in a section. So you need a section:
53
+ // Every element you want to append to the word document is placed in a section.
54
+ // To create a basic section:
54
55
$section = $PHPWord->createSection();
55
56
56
57
// After creating a section, you can append elements:
57
58
$section->addText('Hello world!');
58
59
59
60
// You can directly style your text by giving the addText function an array:
60
- $section->addText('Hello world! I am formatted.', array('name'=>'Tahoma', 'size'=>16, 'bold'=>true));
61
+ $section->addText('Hello world! I am formatted.',
62
+ array('name'=>'Tahoma', 'size'=>16, 'bold'=>true));
61
63
62
- // If you often need the same style again you can create a user defined style to the word document
63
- // and give the addText function the name of the style:
64
- $PHPWord->addFontStyle('myOwnStyle', array('name'=>'Verdana', 'size'=>14, 'color'=>'1B2232'));
65
- $section->addText('Hello world! I am formatted by a user defined style', 'myOwnStyle');
64
+ // If you often need the same style again you can create a user defined style
65
+ // to the word document and give the addText function the name of the style:
66
+ $PHPWord->addFontStyle('myOwnStyle',
67
+ array('name'=>'Verdana', 'size'=>14, 'color'=>'1B2232'));
68
+ $section->addText('Hello world! I am formatted by a user defined style',
69
+ 'myOwnStyle');
66
70
67
- // You can also putthe appended element to local object an call functions like this:
71
+ // You can also put the appended element to local object like this:
68
72
$fontStyle = new PHPWord_Style_Font();
69
73
$fontStyle->setBold(true);
70
74
$fontStyle->setName('Verdana');
71
75
$fontStyle->setSize(22);
72
76
$myTextElement = $section->addText('Hello World!');
73
77
$myTextElement->setFontStyle($fontStyle);
74
78
75
- // At least write the document to webspace :
79
+ // Finally, write the document:
76
80
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
77
81
$objWriter->save('helloWorld.docx');
78
82
```
0 commit comments