forked from tristanbes/PHPWord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PHPWord.php
executable file
·230 lines (205 loc) · 5.29 KB
/
PHPWord.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
<?php
/**
* PHPWord
*
* Copyright (c) 2011 PHPWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPWord
* @package PHPWord
* @copyright Copyright (c) 010 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version Beta 0.6.3, 08.07.2011
*/
/** PHPWORD_BASE_PATH */
if(!defined('PHPWORD_BASE_PATH')) {
define('PHPWORD_BASE_PATH', dirname(__FILE__) . '/');
require PHPWORD_BASE_PATH . 'PHPWord/Autoloader.php';
PHPWord_Autoloader::Register();
}
/**
* PHPWord
*
* @category PHPWord
* @package PHPWord
* @copyright Copyright (c) 2011 PHPWord
*/
class PHPWord {
/**
* Document properties
*
* @var PHPWord_DocumentProperties
*/
private $_properties;
/**
* Default Font Name
*
* @var string
*/
private $_defaultFontName;
/**
* Default Font Size
*
* @var int
*/
private $_defaultFontSize;
/**
* Collection of section elements
*
* @var array
*/
private $_sectionCollection = array();
/**
* Create a new PHPWord Document
*/
public function __construct() {
$this->_properties = new PHPWord_DocumentProperties();
$this->_defaultFontName = 'Arial';
$this->_defaultFontSize = 20;
}
/**
* Get properties
* @return PHPWord_DocumentProperties
*/
public function getProperties() {
return $this->_properties;
}
/**
* Set properties
*
* @param PHPWord_DocumentProperties $value
* @return PHPWord
*/
public function setProperties(PHPWord_DocumentProperties $value) {
$this->_properties = $value;
return $this;
}
/**
* Create a new Section
*
* @param PHPWord_Section_Settings $settings
* @return PHPWord_Section
*/
public function createSection($settings = null) {
$sectionCount = $this->_countSections() + 1;
$section = new PHPWord_Section($sectionCount, $settings);
$this->_sectionCollection[] = $section;
return $section;
}
/**
* Get default Font name
* @return string
*/
public function getDefaultFontName() {
return $this->_defaultFontName;
}
/**
* Set default Font name
* @param string $pValue
*/
public function setDefaultFontName($pValue) {
$this->_defaultFontName = $pValue;
}
/**
* Get default Font size
* @return string
*/
public function getDefaultFontSize() {
return $this->_defaultFontSize;
}
/**
* Set default Font size
* @param int $pValue
*/
public function setDefaultFontSize($pValue) {
$pValue = $pValue * 2;
$this->_defaultFontSize = $pValue;
}
/**
* Adds a paragraph style definition to styles.xml
*
* @param $styleName string
* @param $styles array
*/
public function addParagraphStyle($styleName, $styles) {
PHPWord_Style::addParagraphStyle($styleName, $styles);
}
/**
* Adds a font style definition to styles.xml
*
* @param $styleName string
* @param $styles array
*/
public function addFontStyle($styleName, $styleFont, $styleParagraph = null) {
PHPWord_Style::addFontStyle($styleName, $styleFont, $styleParagraph);
}
/**
* Adds a table style definition to styles.xml
*
* @param $styleName string
* @param $styles array
*/
public function addTableStyle($styleName, $styleTable, $styleFirstRow = null) {
PHPWord_Style::addTableStyle($styleName, $styleTable, $styleFirstRow);
}
/**
* Adds a heading style definition to styles.xml
*
* @param $titleCount int
* @param $styles array
*/
public function addTitleStyle($titleCount, $styleFont, $styleParagraph = null) {
PHPWord_Style::addTitleStyle($titleCount, $styleFont, $styleParagraph);
}
/**
* Adds a hyperlink style to styles.xml
*
* @param $styleName string
* @param $styles array
*/
public function addLinkStyle($styleName, $styles) {
PHPWord_Style::addLinkStyle($styleName, $styles);
}
/**
* Get sections
* @return PHPWord_Section[]
*/
public function getSections() {
return $this->_sectionCollection;
}
/**
* Get section count
* @return int
*/
private function _countSections() {
return count($this->_sectionCollection);
}
/**
* Load a Template File
*
* @param string $strFilename
* @return PHPWord_Template
*/
public function loadTemplate($strFilename) {
if(file_exists($strFilename)) {
$template = new PHPWord_Template($strFilename);
return $template;
} else {
trigger_error('Template file '.$strFilename.' not found.', E_ERROR);
}
}
}
?>