|
4 | 4 | // New Word Document
|
5 | 5 | echo date('H:i:s') , ' Create new PhpWord object' , EOL;
|
6 | 6 | $phpWord = new \PhpOffice\PhpWord\PhpWord();
|
7 |
| -$phpWord->addFontStyle('rStyle', array('bold' => true, 'italic' => true, 'size' => 16, 'allCaps' => true, 'doubleStrikethrough' => true)); |
8 |
| -$phpWord->addParagraphStyle('pStyle', array('alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER, 'spaceAfter' => 100)); |
| 7 | + |
| 8 | +$fontStyleName = 'rStyle'; |
| 9 | +$phpWord->addFontStyle($fontStyleName, array('bold' => true, 'italic' => true, 'size' => 16, 'allCaps' => true, 'doubleStrikethrough' => true)); |
| 10 | + |
| 11 | +$paragraphStyleName = 'pStyle'; |
| 12 | +$phpWord->addParagraphStyle($paragraphStyleName, array('alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER, 'spaceAfter' => 100)); |
| 13 | + |
9 | 14 | $phpWord->addTitleStyle(1, array('bold' => true), array('spaceAfter' => 240));
|
10 | 15 |
|
11 | 16 | // New portrait section
|
12 | 17 | $section = $phpWord->addSection();
|
13 | 18 |
|
14 | 19 | // Simple text
|
15 |
| -$section->addTitle(htmlspecialchars('Welcome to PhpWord', ENT_COMPAT, 'UTF-8'), 1); |
16 |
| -$section->addText(htmlspecialchars('Hello World!', ENT_COMPAT, 'UTF-8')); |
| 20 | +$section->addTitle('Welcome to PhpWord', 1); |
| 21 | +$section->addText('Hello World!'); |
17 | 22 |
|
18 | 23 | // Two text break
|
19 | 24 | $section->addTextBreak(2);
|
20 | 25 |
|
21 |
| -// Defined style |
22 |
| -$section->addText(htmlspecialchars('I am styled by a font style definition.', ENT_COMPAT, 'UTF-8'), 'rStyle'); |
23 |
| -$section->addText(htmlspecialchars('I am styled by a paragraph style definition.', ENT_COMPAT, 'UTF-8'), null, 'pStyle'); |
24 |
| -$section->addText(htmlspecialchars('I am styled by both font and paragraph style.', ENT_COMPAT, 'UTF-8'), 'rStyle', 'pStyle'); |
| 26 | +// Define styles |
| 27 | +$section->addText('I am styled by a font style definition.', $fontStyleName); |
| 28 | +$section->addText('I am styled by a paragraph style definition.', null, $paragraphStyleName); |
| 29 | +$section->addText('I am styled by both font and paragraph style.', $fontStyleName, $paragraphStyleName); |
25 | 30 |
|
26 | 31 | $section->addTextBreak();
|
27 | 32 |
|
|
30 | 35 | $fontStyle['size'] = 20;
|
31 | 36 |
|
32 | 37 | $textrun = $section->addTextRun();
|
33 |
| -$textrun->addText(htmlspecialchars('I am inline styled ', ENT_COMPAT, 'UTF-8'), $fontStyle); |
34 |
| -$textrun->addText(htmlspecialchars('with ', ENT_COMPAT, 'UTF-8')); |
35 |
| -$textrun->addText(htmlspecialchars('color', ENT_COMPAT, 'UTF-8'), array('color' => '996699')); |
36 |
| -$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8')); |
37 |
| -$textrun->addText(htmlspecialchars('bold', ENT_COMPAT, 'UTF-8'), array('bold' => true)); |
38 |
| -$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8')); |
39 |
| -$textrun->addText(htmlspecialchars('italic', ENT_COMPAT, 'UTF-8'), array('italic' => true)); |
40 |
| -$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8')); |
41 |
| -$textrun->addText(htmlspecialchars('underline', ENT_COMPAT, 'UTF-8'), array('underline' => 'dash')); |
42 |
| -$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8')); |
43 |
| -$textrun->addText(htmlspecialchars('strikethrough', ENT_COMPAT, 'UTF-8'), array('strikethrough' => true)); |
44 |
| -$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8')); |
45 |
| -$textrun->addText(htmlspecialchars('doubleStrikethrough', ENT_COMPAT, 'UTF-8'), array('doubleStrikethrough' => true)); |
46 |
| -$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8')); |
47 |
| -$textrun->addText(htmlspecialchars('superScript', ENT_COMPAT, 'UTF-8'), array('superScript' => true)); |
48 |
| -$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8')); |
49 |
| -$textrun->addText(htmlspecialchars('subScript', ENT_COMPAT, 'UTF-8'), array('subScript' => true)); |
50 |
| -$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8')); |
51 |
| -$textrun->addText(htmlspecialchars('smallCaps', ENT_COMPAT, 'UTF-8'), array('smallCaps' => true)); |
52 |
| -$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8')); |
53 |
| -$textrun->addText(htmlspecialchars('allCaps', ENT_COMPAT, 'UTF-8'), array('allCaps' => true)); |
54 |
| -$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8')); |
55 |
| -$textrun->addText(htmlspecialchars('fgColor', ENT_COMPAT, 'UTF-8'), array('fgColor' => 'yellow')); |
56 |
| -$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8')); |
57 |
| -$textrun->addText(htmlspecialchars('scale', ENT_COMPAT, 'UTF-8'), array('scale' => 200)); |
58 |
| -$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8')); |
59 |
| -$textrun->addText(htmlspecialchars('spacing', ENT_COMPAT, 'UTF-8'), array('spacing' => 120)); |
60 |
| -$textrun->addText(htmlspecialchars(', ', ENT_COMPAT, 'UTF-8')); |
61 |
| -$textrun->addText(htmlspecialchars('kerning', ENT_COMPAT, 'UTF-8'), array('kerning' => 10)); |
62 |
| -$textrun->addText(htmlspecialchars('. ', ENT_COMPAT, 'UTF-8')); |
| 38 | +$textrun->addText('I am inline styled ', $fontStyle); |
| 39 | +$textrun->addText('with '); |
| 40 | +$textrun->addText('color', array('color' => '996699')); |
| 41 | +$textrun->addText(', '); |
| 42 | +$textrun->addText('bold', array('bold' => true)); |
| 43 | +$textrun->addText(', '); |
| 44 | +$textrun->addText('italic', array('italic' => true)); |
| 45 | +$textrun->addText(', '); |
| 46 | +$textrun->addText('underline', array('underline' => 'dash')); |
| 47 | +$textrun->addText(', '); |
| 48 | +$textrun->addText('strikethrough', array('strikethrough' => true)); |
| 49 | +$textrun->addText(', '); |
| 50 | +$textrun->addText('doubleStrikethrough', array('doubleStrikethrough' => true)); |
| 51 | +$textrun->addText(', '); |
| 52 | +$textrun->addText('superScript', array('superScript' => true)); |
| 53 | +$textrun->addText(', '); |
| 54 | +$textrun->addText('subScript', array('subScript' => true)); |
| 55 | +$textrun->addText(', '); |
| 56 | +$textrun->addText('smallCaps', array('smallCaps' => true)); |
| 57 | +$textrun->addText(', '); |
| 58 | +$textrun->addText('allCaps', array('allCaps' => true)); |
| 59 | +$textrun->addText(', '); |
| 60 | +$textrun->addText('fgColor', array('fgColor' => 'yellow')); |
| 61 | +$textrun->addText(', '); |
| 62 | +$textrun->addText('scale', array('scale' => 200)); |
| 63 | +$textrun->addText(', '); |
| 64 | +$textrun->addText('spacing', array('spacing' => 120)); |
| 65 | +$textrun->addText(', '); |
| 66 | +$textrun->addText('kerning', array('kerning' => 10)); |
| 67 | +$textrun->addText('. '); |
63 | 68 |
|
64 | 69 | // Link
|
65 |
| -$section->addLink('https://github.com/PHPOffice/PHPWord', htmlspecialchars('PHPWord on GitHub', ENT_COMPAT, 'UTF-8')); |
| 70 | +$section->addLink('https://github.com/PHPOffice/PHPWord', 'PHPWord on GitHub'); |
66 | 71 | $section->addTextBreak();
|
67 | 72 |
|
68 | 73 | // Image
|
|
0 commit comments