@@ -6,12 +6,13 @@ General usage
6
6
Basic example
7
7
-------------
8
8
9
- The following is a basic example of the PHPWord library. More examples
9
+ The following is a basic example of the PhpWord library. More examples
10
10
are provided in the `samples folder <https://github.com/PHPOffice/PHPWord/tree/master/samples/ >`__.
11
11
12
12
.. code-block :: php
13
13
14
- require_once '../src/PhpWord/PhpWord.php';
14
+ require_once 'src/PhpWord/Autoloader.php';
15
+ PhpOffice\PhpWord\Autoloader::register();
15
16
16
17
$phpWord = new \PhpOffice\PhpWord\PhpWord();
17
18
@@ -34,17 +35,23 @@ are provided in the `samples folder <https://github.com/PHPOffice/PHPWord/tree/m
34
35
'myOwnStyle');
35
36
36
37
// You can also put the appended element to local object like this:
37
- $fontStyle = new PHPWord_Style_Font ();
38
+ $fontStyle = new \PhpOffice\PhpWord\Style\Font ();
38
39
$fontStyle->setBold(true);
39
40
$fontStyle->setName('Verdana');
40
41
$fontStyle->setSize(22);
41
42
$myTextElement = $section->addText('Hello World!');
42
43
$myTextElement->setFontStyle($fontStyle);
43
44
44
45
// Finally, write the document:
45
- $objWriter = PHPWord_IOFactory ::createWriter($phpWord, 'Word2007');
46
+ $objWriter = \PhpOffice\PhpWord\IOFactory ::createWriter($phpWord, 'Word2007');
46
47
$objWriter->save('helloWorld.docx');
47
48
49
+ $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'ODText');
50
+ $objWriter->save('helloWorld.odt');
51
+
52
+ $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'RTF');
53
+ $objWriter->save('helloWorld.rtf');
54
+
48
55
Default font
49
56
------------
50
57
@@ -82,19 +89,19 @@ Measurement units
82
89
The base length unit in Open Office XML is twip. Twip means "TWentieth
83
90
of an Inch Point", i.e. 1 twip = 1/1440 inch.
84
91
85
- You can use PHPWord helper functions to convert inches, centimeters, or
92
+ You can use PhpWord helper functions to convert inches, centimeters, or
86
93
points to twips.
87
94
88
95
.. code-block :: php
89
96
90
97
// Paragraph with 6 points space after
91
98
$phpWord->addParagraphStyle('My Style', array(
92
- 'spaceAfter' => PHPWord_Shared_Font ::pointSizeToTwips(6))
99
+ 'spaceAfter' => \PhpOffice\PhpWord\Shared\Font ::pointSizeToTwips(6))
93
100
);
94
101
95
102
$section = $phpWord->createSection();
96
103
$sectionStyle = $section->getSettings();
97
104
// half inch left margin
98
- $sectionStyle->setMarginLeft(PHPWord_Shared_Font ::inchSizeToTwips(.5));
105
+ $sectionStyle->setMarginLeft(\PhpOffice\PhpWord\Shared\Font ::inchSizeToTwips(.5));
99
106
// 2 cm right margin
100
- $sectionStyle->setMarginRight(PHPWord_Shared_Font ::centimeterSizeToTwips(2));
107
+ $sectionStyle->setMarginRight(\PhpOffice\PhpWord\Shared\Font ::centimeterSizeToTwips(2));
0 commit comments