forked from PHPOffice/PHPWord
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Sample_14_ListItem.php
95 lines (81 loc) · 5 KB
/
Sample_14_ListItem.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
include_once 'Sample_Header.php';
// New Word document
echo date('H:i:s'), ' Create new PhpWord object', EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// Begin code
$section = $phpWord->addSection();
// Style definition
$phpWord->addFontStyle('myOwnStyle', array('color' => 'FF0000'));
$phpWord->addParagraphStyle('P-Style', array('spaceAfter' => 95));
$phpWord->addNumberingStyle(
'multilevel',
array(
'type' => 'multilevel',
'levels' => array(
array('format' => 'decimal', 'text' => '%1.', 'left' => 360, 'hanging' => 360, 'tabPos' => 360),
array('format' => 'upperLetter', 'text' => '%2.', 'left' => 720, 'hanging' => 360, 'tabPos' => 720),
),
)
);
$predefinedMultilevel = array('listType' => \PhpOffice\PhpWord\Style\ListItem::TYPE_NUMBER_NESTED);
// Lists
$section->addText(htmlspecialchars('Multilevel list.', ENT_COMPAT, 'UTF-8'));
$section->addListItem(htmlspecialchars('List Item I', ENT_COMPAT, 'UTF-8'), 0, null, 'multilevel');
$section->addListItem(htmlspecialchars('List Item I.a', ENT_COMPAT, 'UTF-8'), 1, null, 'multilevel');
$section->addListItem(htmlspecialchars('List Item I.b', ENT_COMPAT, 'UTF-8'), 1, null, 'multilevel');
$section->addListItem(htmlspecialchars('List Item II', ENT_COMPAT, 'UTF-8'), 0, null, 'multilevel');
$section->addListItem(htmlspecialchars('List Item II.a', ENT_COMPAT, 'UTF-8'), 1, null, 'multilevel');
$section->addListItem(htmlspecialchars('List Item III', ENT_COMPAT, 'UTF-8'), 0, null, 'multilevel');
$section->addTextBreak(2);
$section->addText(htmlspecialchars('Basic simple bulleted list.', ENT_COMPAT, 'UTF-8'));
$section->addListItem(htmlspecialchars('List Item 1', ENT_COMPAT, 'UTF-8'));
$section->addListItem(htmlspecialchars('List Item 2', ENT_COMPAT, 'UTF-8'));
$section->addListItem(htmlspecialchars('List Item 3', ENT_COMPAT, 'UTF-8'));
$section->addTextBreak(2);
$section->addText(htmlspecialchars('Continue from multilevel list above.', ENT_COMPAT, 'UTF-8'));
$section->addListItem(htmlspecialchars('List Item IV', ENT_COMPAT, 'UTF-8'), 0, null, 'multilevel');
$section->addListItem(htmlspecialchars('List Item IV.a', ENT_COMPAT, 'UTF-8'), 1, null, 'multilevel');
$section->addTextBreak(2);
$section->addText(htmlspecialchars('Multilevel predefined list.', ENT_COMPAT, 'UTF-8'));
$section->addListItem(htmlspecialchars('List Item 1', ENT_COMPAT, 'UTF-8'), 0, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
$section->addListItem(htmlspecialchars('List Item 2', ENT_COMPAT, 'UTF-8'), 0, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
$section->addListItem(htmlspecialchars('List Item 3', ENT_COMPAT, 'UTF-8'), 1, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
$section->addListItem(htmlspecialchars('List Item 4', ENT_COMPAT, 'UTF-8'), 1, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
$section->addListItem(htmlspecialchars('List Item 5', ENT_COMPAT, 'UTF-8'), 2, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
$section->addListItem(htmlspecialchars('List Item 6', ENT_COMPAT, 'UTF-8'), 1, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
$section->addListItem(htmlspecialchars('List Item 7', ENT_COMPAT, 'UTF-8'), 0, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
$section->addTextBreak(2);
$section->addText(htmlspecialchars('List with inline formatting.', ENT_COMPAT, 'UTF-8'));
$listItemRun = $section->addListItemRun();
$listItemRun->addText(htmlspecialchars('List item 1', ENT_COMPAT, 'UTF-8'));
$listItemRun->addText(htmlspecialchars(' in bold', ENT_COMPAT, 'UTF-8'), array('bold' => true));
$listItemRun = $section->addListItemRun();
$listItemRun->addText(htmlspecialchars('List item 2', ENT_COMPAT, 'UTF-8'));
$listItemRun->addText(htmlspecialchars(' in italic', ENT_COMPAT, 'UTF-8'), array('italic' => true));
$listItemRun = $section->addListItemRun();
$listItemRun->addText(htmlspecialchars('List item 3', ENT_COMPAT, 'UTF-8'));
$listItemRun->addText(htmlspecialchars(' underlined', ENT_COMPAT, 'UTF-8'), array('underline' => 'dash'));
$section->addTextBreak(2);
// Numbered heading
$phpWord->addNumberingStyle(
'headingNumbering',
array('type' => 'multilevel',
'levels' => array(
array('pStyle' => 'Heading1', 'format' => 'decimal', 'text' => '%1'),
array('pStyle' => 'Heading2', 'format' => 'decimal', 'text' => '%1.%2'),
array('pStyle' => 'Heading3', 'format' => 'decimal', 'text' => '%1.%2.%3'),
),
)
);
$phpWord->addTitleStyle(1, array('size' => 16), array('numStyle' => 'headingNumbering', 'numLevel' => 0));
$phpWord->addTitleStyle(2, array('size' => 14), array('numStyle' => 'headingNumbering', 'numLevel' => 1));
$phpWord->addTitleStyle(3, array('size' => 12), array('numStyle' => 'headingNumbering', 'numLevel' => 2));
$section->addTitle(htmlspecialchars('Heading 1', ENT_COMPAT, 'UTF-8'), 1);
$section->addTitle(htmlspecialchars('Heading 2', ENT_COMPAT, 'UTF-8'), 2);
$section->addTitle(htmlspecialchars('Heading 3', ENT_COMPAT, 'UTF-8'), 3);
// Save file
echo write($phpWord, basename(__FILE__, '.php'), $writers);
if (!CLI) {
include_once 'Sample_Footer.php';
}