1
+ <?php
2
+ /**
3
+ * PHPWord
4
+ *
5
+ * Copyright (c) 2011 PHPWord
6
+ *
7
+ * This library is free software; you can redistribute it and/or
8
+ * modify it under the terms of the GNU Lesser General Public
9
+ * License as published by the Free Software Foundation; either
10
+ * version 2.1 of the License, or (at your option) any later version.
11
+ *
12
+ * This library is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
+ * Lesser General Public License for more details.
16
+ *
17
+ * You should have received a copy of the GNU Lesser General Public
18
+ * License along with this library; if not, write to the Free Software
19
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
+ *
21
+ * @category PHPWord
22
+ * @package PHPWord
23
+ * @copyright Copyright (c) 010 PHPWord
24
+ * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25
+ * @version Beta 0.6.3, 08.07.2011
26
+ */
27
+
28
+ /** PHPWORD_BASE_PATH */
29
+ if (!defined ('PHPWORD_BASE_PATH ' )) {
30
+ define ('PHPWORD_BASE_PATH ' , dirname (__FILE__ ) . '/ ' );
31
+ require PHPWORD_BASE_PATH . 'PHPWord/Autoloader.php ' ;
32
+ PHPWord_Autoloader::Register ();
33
+ }
34
+
35
+
36
+ /**
37
+ * PHPWord
38
+ *
39
+ * @category PHPWord
40
+ * @package PHPWord
41
+ * @copyright Copyright (c) 2011 PHPWord
42
+ */
43
+ class PHPWord {
44
+
45
+ /**
46
+ * Document properties
47
+ *
48
+ * @var PHPWord_DocumentProperties
49
+ */
50
+ private $ _properties ;
51
+
52
+ /**
53
+ * Default Font Name
54
+ *
55
+ * @var string
56
+ */
57
+ private $ _defaultFontName ;
58
+
59
+ /**
60
+ * Default Font Size
61
+ *
62
+ * @var int
63
+ */
64
+ private $ _defaultFontSize ;
65
+
66
+ /**
67
+ * Collection of section elements
68
+ *
69
+ * @var array
70
+ */
71
+ private $ _sectionCollection = array ();
72
+
73
+
74
+ /**
75
+ * Create a new PHPWord Document
76
+ */
77
+ public function __construct () {
78
+ $ this ->_properties = new PHPWord_DocumentProperties ();
79
+ $ this ->_defaultFontName = 'Arial ' ;
80
+ $ this ->_defaultFontSize = 20 ;
81
+ }
82
+
83
+ /**
84
+ * Get properties
85
+ * @return PHPWord_DocumentProperties
86
+ */
87
+ public function getProperties () {
88
+ return $ this ->_properties ;
89
+ }
90
+
91
+ /**
92
+ * Set properties
93
+ *
94
+ * @param PHPWord_DocumentProperties $value
95
+ * @return PHPWord
96
+ */
97
+ public function setProperties (PHPWord_DocumentProperties $ value ) {
98
+ $ this ->_properties = $ value ;
99
+ return $ this ;
100
+ }
101
+
102
+ /**
103
+ * Create a new Section
104
+ *
105
+ * @param PHPWord_Section_Settings $settings
106
+ * @return PHPWord_Section
107
+ */
108
+ public function createSection ($ settings = null ) {
109
+ $ sectionCount = $ this ->_countSections () + 1 ;
110
+
111
+ $ section = new PHPWord_Section ($ sectionCount , $ settings );
112
+ $ this ->_sectionCollection [] = $ section ;
113
+ return $ section ;
114
+ }
115
+
116
+ /**
117
+ * Get default Font name
118
+ * @return string
119
+ */
120
+ public function getDefaultFontName () {
121
+ return $ this ->_defaultFontName ;
122
+ }
123
+
124
+ /**
125
+ * Set default Font name
126
+ * @param string $pValue
127
+ */
128
+ public function setDefaultFontName ($ pValue ) {
129
+ $ this ->_defaultFontName = $ pValue ;
130
+ }
131
+
132
+ /**
133
+ * Get default Font size
134
+ * @return string
135
+ */
136
+ public function getDefaultFontSize () {
137
+ return $ this ->_defaultFontSize ;
138
+ }
139
+
140
+ /**
141
+ * Set default Font size
142
+ * @param int $pValue
143
+ */
144
+ public function setDefaultFontSize ($ pValue ) {
145
+ $ pValue = $ pValue * 2 ;
146
+ $ this ->_defaultFontSize = $ pValue ;
147
+ }
148
+
149
+ /**
150
+ * Adds a paragraph style definition to styles.xml
151
+ *
152
+ * @param $styleName string
153
+ * @param $styles array
154
+ */
155
+ public function addParagraphStyle ($ styleName , $ styles ) {
156
+ PHPWord_Style::addParagraphStyle ($ styleName , $ styles );
157
+ }
158
+
159
+ /**
160
+ * Adds a font style definition to styles.xml
161
+ *
162
+ * @param $styleName string
163
+ * @param $styles array
164
+ */
165
+ public function addFontStyle ($ styleName , $ styleFont , $ styleParagraph = null ) {
166
+ PHPWord_Style::addFontStyle ($ styleName , $ styleFont , $ styleParagraph );
167
+ }
168
+
169
+ /**
170
+ * Adds a table style definition to styles.xml
171
+ *
172
+ * @param $styleName string
173
+ * @param $styles array
174
+ */
175
+ public function addTableStyle ($ styleName , $ styleTable , $ styleFirstRow = null ) {
176
+ PHPWord_Style::addTableStyle ($ styleName , $ styleTable , $ styleFirstRow );
177
+ }
178
+
179
+ /**
180
+ * Adds a heading style definition to styles.xml
181
+ *
182
+ * @param $titleCount int
183
+ * @param $styles array
184
+ */
185
+ public function addTitleStyle ($ titleCount , $ styleFont , $ styleParagraph = null ) {
186
+ PHPWord_Style::addTitleStyle ($ titleCount , $ styleFont , $ styleParagraph );
187
+ }
188
+
189
+ /**
190
+ * Adds a hyperlink style to styles.xml
191
+ *
192
+ * @param $styleName string
193
+ * @param $styles array
194
+ */
195
+ public function addLinkStyle ($ styleName , $ styles ) {
196
+ PHPWord_Style::addLinkStyle ($ styleName , $ styles );
197
+ }
198
+
199
+ /**
200
+ * Get sections
201
+ * @return PHPWord_Section[]
202
+ */
203
+ public function getSections () {
204
+ return $ this ->_sectionCollection ;
205
+ }
206
+
207
+ /**
208
+ * Get section count
209
+ * @return int
210
+ */
211
+ private function _countSections () {
212
+ return count ($ this ->_sectionCollection );
213
+ }
214
+
215
+ /**
216
+ * Load a Template File
217
+ *
218
+ * @param string $strFilename
219
+ * @return PHPWord_Template
220
+ */
221
+ public function loadTemplate ($ strFilename ) {
222
+ if (file_exists ($ strFilename )) {
223
+ $ template = new PHPWord_Template ($ strFilename );
224
+ return $ template ;
225
+ } else {
226
+ trigger_error ('Template file ' .$ strFilename .' not found. ' , E_USER_ERROR );
227
+ }
228
+ }
229
+ }
0 commit comments