|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* PHPExcel |
|
4
|
|
|
* |
|
5
|
|
|
* Copyright (c) 2006 - 2012 PHPExcel |
|
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 PHPExcel |
|
22
|
|
|
* @package PHPExcel_Reader |
|
23
|
|
|
* @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel) |
|
24
|
|
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
|
25
|
|
|
* @version 1.7.7, 2012-05-19 |
|
26
|
|
|
*/ |
|
27
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
/** PHPExcel root directory */ |
|
30
|
|
View Code Duplication |
if (!defined('PHPEXCEL_ROOT')) { |
|
31
|
|
|
/** |
|
32
|
|
|
* @ignore |
|
33
|
|
|
*/ |
|
34
|
|
|
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../'); |
|
35
|
|
|
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php'); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* PHPExcel_Reader_Excel2007 |
|
40
|
|
|
* |
|
41
|
|
|
* @category PHPExcel |
|
42
|
|
|
* @package PHPExcel_Reader |
|
43
|
|
|
* @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel) |
|
44
|
|
|
*/ |
|
45
|
|
|
class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader |
|
46
|
|
|
{ |
|
47
|
|
|
/** |
|
48
|
|
|
* Read data only? |
|
49
|
|
|
* Identifies whether the Reader should only read data values for cells, and ignore any formatting information; |
|
50
|
|
|
* or whether it should read both data and formatting |
|
51
|
|
|
* |
|
52
|
|
|
* @var boolean |
|
53
|
|
|
*/ |
|
54
|
|
|
private $_readDataOnly = false; |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Read charts that are defined in the workbook? |
|
58
|
|
|
* Identifies whether the Reader should read the definitions for any charts that exist in the workbook; |
|
59
|
|
|
* |
|
60
|
|
|
* @var boolean |
|
61
|
|
|
*/ |
|
62
|
|
|
private $_includeCharts = false; |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Restrict which sheets should be loaded? |
|
66
|
|
|
* This property holds an array of worksheet names to be loaded. If null, then all worksheets will be loaded. |
|
67
|
|
|
* |
|
68
|
|
|
* @var array of string |
|
69
|
|
|
*/ |
|
70
|
|
|
private $_loadSheetsOnly = null; |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* PHPExcel_Reader_IReadFilter instance |
|
74
|
|
|
* |
|
75
|
|
|
* @var PHPExcel_Reader_IReadFilter |
|
76
|
|
|
*/ |
|
77
|
|
|
private $_readFilter = null; |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* PHPExcel_ReferenceHelper instance |
|
81
|
|
|
* |
|
82
|
|
|
* @var PHPExcel_ReferenceHelper |
|
83
|
|
|
*/ |
|
84
|
|
|
private $_referenceHelper = null; |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* PHPExcel_Reader_Excel2007_Theme instance |
|
88
|
|
|
* |
|
89
|
|
|
* @var PHPExcel_Reader_Excel2007_Theme |
|
90
|
|
|
*/ |
|
91
|
|
|
private static $_theme = null; |
|
92
|
|
|
|
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Create a new PHPExcel_Reader_Excel2007 instance |
|
96
|
|
|
*/ |
|
97
|
|
|
public function __construct() { |
|
98
|
|
|
$this->_readFilter = new PHPExcel_Reader_DefaultReadFilter(); |
|
99
|
|
|
$this->_referenceHelper = PHPExcel_ReferenceHelper::getInstance(); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Read data only? |
|
105
|
|
|
* If this is true, then the Reader will only read data values for cells, it will not read any formatting information. |
|
106
|
|
|
* If false (the default) it will read data and formatting. |
|
107
|
|
|
* |
|
108
|
|
|
* @return boolean |
|
109
|
|
|
*/ |
|
110
|
|
|
public function getReadDataOnly() { |
|
111
|
|
|
return $this->_readDataOnly; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* Set read data only |
|
117
|
|
|
* Set to true, to advise the Reader only to read data values for cells, and to ignore any formatting information. |
|
118
|
|
|
* Set to false (the default) to advise the Reader to read both data and formatting for cells. |
|
119
|
|
|
* |
|
120
|
|
|
* @param boolean $pValue |
|
121
|
|
|
* |
|
122
|
|
|
* @return PHPExcel_Reader_Excel2007 |
|
123
|
|
|
*/ |
|
124
|
|
|
public function setReadDataOnly($pValue = false) { |
|
125
|
|
|
$this->_readDataOnly = $pValue; |
|
126
|
|
|
return $this; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* Read charts in workbook? |
|
132
|
|
|
* If this is true, then the Reader will include any charts that exist in the workbook. |
|
133
|
|
|
* Note that a ReadDataOnly value of false overrides, and charts won't be read regardless of the IncludeCharts value. |
|
134
|
|
|
* If false (the default) it will ignore any charts defined in the workbook file. |
|
135
|
|
|
* |
|
136
|
|
|
* @return boolean |
|
137
|
|
|
*/ |
|
138
|
|
|
public function getIncludeCharts() { |
|
139
|
|
|
return $this->_includeCharts; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* Set read charts in workbook |
|
145
|
|
|
* Set to true, to advise the Reader to include any charts that exist in the workbook. |
|
146
|
|
|
* Note that a ReadDataOnly value of false overrides, and charts won't be read regardless of the IncludeCharts value. |
|
147
|
|
|
* Set to false (the default) to discard charts. |
|
148
|
|
|
* |
|
149
|
|
|
* @param boolean $pValue |
|
150
|
|
|
* |
|
151
|
|
|
* @return PHPExcel_Reader_Excel2007 |
|
152
|
|
|
*/ |
|
153
|
|
|
public function setIncludeCharts($pValue = false) { |
|
154
|
|
|
$this->_includeCharts = (boolean) $pValue; |
|
155
|
|
|
return $this; |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* Get which sheets to load |
|
161
|
|
|
* Returns either an array of worksheet names (the list of worksheets that should be loaded), or a null |
|
162
|
|
|
* indicating that all worksheets in the workbook should be loaded. |
|
163
|
|
|
* |
|
164
|
|
|
* @return mixed |
|
165
|
|
|
*/ |
|
166
|
|
|
public function getLoadSheetsOnly() |
|
167
|
|
|
{ |
|
168
|
|
|
return $this->_loadSheetsOnly; |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* Set which sheets to load |
|
174
|
|
|
* |
|
175
|
|
|
* @param mixed $value |
|
176
|
|
|
* This should be either an array of worksheet names to be loaded, or a string containing a single worksheet name. |
|
177
|
|
|
* If NULL, then it tells the Reader to read all worksheets in the workbook |
|
178
|
|
|
* |
|
179
|
|
|
* @return PHPExcel_Reader_Excel2007 |
|
180
|
|
|
*/ |
|
181
|
|
|
public function setLoadSheetsOnly($value = null) |
|
182
|
|
|
{ |
|
183
|
|
|
$this->_loadSheetsOnly = is_array($value) ? |
|
184
|
|
|
$value : array($value); |
|
185
|
|
|
return $this; |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
|
|
189
|
|
|
/** |
|
190
|
|
|
* Set all sheets to load |
|
191
|
|
|
* Tells the Reader to load all worksheets from the workbook. |
|
192
|
|
|
* |
|
193
|
|
|
* @return PHPExcel_Reader_Excel2007 |
|
194
|
|
|
*/ |
|
195
|
|
|
public function setLoadAllSheets() |
|
196
|
|
|
{ |
|
197
|
|
|
$this->_loadSheetsOnly = null; |
|
|
|
|
|
|
198
|
|
|
return $this; |
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
|
|
|
|
202
|
|
|
/** |
|
203
|
|
|
* Read filter |
|
204
|
|
|
* |
|
205
|
|
|
* @return PHPExcel_Reader_IReadFilter |
|
206
|
|
|
*/ |
|
207
|
|
|
public function getReadFilter() { |
|
208
|
|
|
return $this->_readFilter; |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
|
|
212
|
|
|
/** |
|
213
|
|
|
* Set read filter |
|
214
|
|
|
* |
|
215
|
|
|
* @param PHPExcel_Reader_IReadFilter $pValue |
|
216
|
|
|
* @return PHPExcel_Reader_Excel2007 |
|
217
|
|
|
*/ |
|
218
|
|
|
public function setReadFilter(PHPExcel_Reader_IReadFilter $pValue) { |
|
219
|
|
|
$this->_readFilter = $pValue; |
|
220
|
|
|
return $this; |
|
221
|
|
|
} |
|
222
|
|
|
|
|
223
|
|
|
|
|
224
|
|
|
/** |
|
225
|
|
|
* Can the current PHPExcel_Reader_IReader read the file? |
|
226
|
|
|
* |
|
227
|
|
|
* @param string $pFileName |
|
|
|
|
|
|
228
|
|
|
* @return boolean |
|
229
|
|
|
* @throws Exception |
|
230
|
|
|
*/ |
|
231
|
|
|
public function canRead($pFilename) |
|
232
|
|
|
{ |
|
233
|
|
|
// Check if file exists |
|
234
|
|
|
if (!file_exists($pFilename)) { |
|
235
|
|
|
throw new Exception("Could not open " . $pFilename . " for reading! File does not exist."); |
|
236
|
|
|
} |
|
237
|
|
|
|
|
238
|
|
|
// Check if zip class exists |
|
239
|
|
|
if (!class_exists('ZipArchive')) { |
|
240
|
|
|
throw new Exception("ZipArchive library is not enabled"); |
|
241
|
|
|
} |
|
242
|
|
|
|
|
243
|
|
|
$xl = false; |
|
244
|
|
|
// Load file |
|
245
|
|
|
$zip = new ZipArchive; |
|
246
|
|
|
if ($zip->open($pFilename) === true) { |
|
247
|
|
|
// check if it is an OOXML archive |
|
248
|
|
|
$rels = simplexml_load_string($this->_getFromZipArchive($zip, "_rels/.rels")); |
|
249
|
|
|
if ($rels !== false) { |
|
250
|
|
|
foreach ($rels->Relationship as $rel) { |
|
251
|
|
|
switch ($rel["Type"]) { |
|
252
|
|
|
case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument": |
|
253
|
|
|
if (basename($rel["Target"]) == 'workbook.xml') { |
|
254
|
|
|
$xl = true; |
|
255
|
|
|
} |
|
256
|
|
|
break; |
|
257
|
|
|
|
|
258
|
|
|
} |
|
259
|
|
|
} |
|
260
|
|
|
} |
|
261
|
|
|
$zip->close(); |
|
262
|
|
|
} |
|
263
|
|
|
|
|
264
|
|
|
return $xl; |
|
265
|
|
|
} |
|
266
|
|
|
|
|
267
|
|
|
|
|
268
|
|
|
/** |
|
269
|
|
|
* Return worksheet info (Name, Last Column Letter, Last Column Index, Total Rows, Total Columns) |
|
270
|
|
|
* |
|
271
|
|
|
* @param string $pFilename |
|
272
|
|
|
* @throws Exception |
|
273
|
|
|
*/ |
|
274
|
|
|
public function listWorksheetInfo($pFilename) |
|
275
|
|
|
{ |
|
276
|
|
|
// Check if file exists |
|
277
|
|
|
if (!file_exists($pFilename)) { |
|
278
|
|
|
throw new Exception("Could not open " . $pFilename . " for reading! File does not exist."); |
|
279
|
|
|
} |
|
280
|
|
|
|
|
281
|
|
|
$worksheetInfo = array(); |
|
282
|
|
|
|
|
283
|
|
|
$zip = new ZipArchive; |
|
284
|
|
|
$zip->open($pFilename); |
|
285
|
|
|
|
|
286
|
|
|
$rels = simplexml_load_string($this->_getFromZipArchive($zip, "_rels/.rels")); //~ http://schemas.openxmlformats.org/package/2006/relationships"); |
|
287
|
|
|
foreach ($rels->Relationship as $rel) { |
|
288
|
|
|
if ($rel["Type"] == "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument") { |
|
289
|
|
|
$dir = dirname($rel["Target"]); |
|
290
|
|
|
$relsWorkbook = simplexml_load_string($this->_getFromZipArchive($zip, "$dir/_rels/" . basename($rel["Target"]) . ".rels")); //~ http://schemas.openxmlformats.org/package/2006/relationships"); |
|
291
|
|
|
$relsWorkbook->registerXPathNamespace("rel", "http://schemas.openxmlformats.org/package/2006/relationships"); |
|
292
|
|
|
|
|
293
|
|
|
$worksheets = array(); |
|
294
|
|
View Code Duplication |
foreach ($relsWorkbook->Relationship as $ele) { |
|
295
|
|
|
if ($ele["Type"] == "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet") { |
|
296
|
|
|
$worksheets[(string) $ele["Id"]] = $ele["Target"]; |
|
297
|
|
|
} |
|
298
|
|
|
} |
|
299
|
|
|
|
|
300
|
|
|
$xmlWorkbook = simplexml_load_string($this->_getFromZipArchive($zip, "{$rel['Target']}")); //~ http://schemas.openxmlformats.org/spreadsheetml/2006/main"); |
|
301
|
|
|
if ($xmlWorkbook->sheets) { |
|
302
|
|
|
$dir = dirname($rel["Target"]); |
|
303
|
|
|
foreach ($xmlWorkbook->sheets->sheet as $eleSheet) { |
|
304
|
|
|
$tmpInfo = array(); |
|
305
|
|
|
$tmpInfo['worksheetName'] = (string) $eleSheet["name"]; |
|
306
|
|
|
$tmpInfo['lastColumnLetter'] = 'A'; |
|
307
|
|
|
$tmpInfo['lastColumnIndex'] = 0; |
|
308
|
|
|
$tmpInfo['totalRows'] = 0; |
|
309
|
|
|
$tmpInfo['totalColumns'] = 0; |
|
310
|
|
|
|
|
311
|
|
|
$fileWorksheet = $worksheets[(string) self::array_item($eleSheet->attributes("http://schemas.openxmlformats.org/officeDocument/2006/relationships"), "id")]; |
|
312
|
|
|
$xmlSheet = simplexml_load_string($this->_getFromZipArchive($zip, "$dir/$fileWorksheet")); //~ http://schemas.openxmlformats.org/spreadsheetml/2006/main"); |
|
313
|
|
|
if ($xmlSheet && $xmlSheet->sheetData && $xmlSheet->sheetData->row) { |
|
314
|
|
|
foreach ($xmlSheet->sheetData->row as $row) { |
|
315
|
|
|
foreach ($row->c as $c) { |
|
316
|
|
|
$r = (string) $c["r"]; |
|
317
|
|
|
$coordinates = PHPExcel_Cell::coordinateFromString($r); |
|
318
|
|
|
|
|
319
|
|
|
$rowIndex = $coordinates[1]; |
|
320
|
|
|
$columnIndex = PHPExcel_Cell::columnIndexFromString($coordinates[0]) - 1; |
|
321
|
|
|
|
|
322
|
|
|
$tmpInfo['totalRows'] = max($tmpInfo['totalRows'], $rowIndex); |
|
323
|
|
|
$tmpInfo['lastColumnIndex'] = max($tmpInfo['lastColumnIndex'], $columnIndex); |
|
324
|
|
|
} |
|
325
|
|
|
} |
|
326
|
|
|
} |
|
327
|
|
|
|
|
328
|
|
|
$tmpInfo['lastColumnLetter'] = PHPExcel_Cell::stringFromColumnIndex($tmpInfo['lastColumnIndex']); |
|
329
|
|
|
$tmpInfo['totalColumns'] = $tmpInfo['lastColumnIndex'] + 1; |
|
330
|
|
|
|
|
331
|
|
|
$worksheetInfo[] = $tmpInfo; |
|
332
|
|
|
} |
|
333
|
|
|
} |
|
334
|
|
|
} |
|
335
|
|
|
} |
|
336
|
|
|
|
|
337
|
|
|
$zip->close(); |
|
338
|
|
|
|
|
339
|
|
|
return $worksheetInfo; |
|
340
|
|
|
} |
|
341
|
|
|
|
|
342
|
|
|
|
|
343
|
|
|
private static function _castToBool($c) { |
|
344
|
|
|
// echo 'Initial Cast to Boolean<br />'; |
|
345
|
|
|
$value = isset($c->v) ? (string) $c->v : null; |
|
346
|
|
|
if ($value == '0') { |
|
347
|
|
|
return false; |
|
348
|
|
|
} elseif ($value == '1') { |
|
349
|
|
|
return true; |
|
350
|
|
|
} else { |
|
351
|
|
|
return (bool)$c->v; |
|
352
|
|
|
} |
|
353
|
|
|
return $value; |
|
|
|
|
|
|
354
|
|
|
} // function _castToBool() |
|
355
|
|
|
|
|
356
|
|
|
|
|
357
|
|
|
private static function _castToError($c) { |
|
358
|
|
|
// echo 'Initial Cast to Error<br />'; |
|
359
|
|
|
return isset($c->v) ? (string) $c->v : null;; |
|
360
|
|
|
} // function _castToError() |
|
361
|
|
|
|
|
362
|
|
|
|
|
363
|
|
|
private static function _castToString($c) { |
|
364
|
|
|
// echo 'Initial Cast to String<br />'; |
|
365
|
|
|
return isset($c->v) ? (string) $c->v : null;; |
|
366
|
|
|
} // function _castToString() |
|
367
|
|
|
|
|
368
|
|
|
|
|
369
|
|
|
private function _castToFormula($c,$r,&$cellDataType,&$value,&$calculatedValue,&$sharedFormulas,$castBaseType) { |
|
370
|
|
|
// echo '<font color="darkgreen">Formula</font><br />'; |
|
371
|
|
|
// echo '$c->f is '.$c->f.'<br />'; |
|
372
|
|
|
$cellDataType = 'f'; |
|
373
|
|
|
$value = "={$c->f}"; |
|
374
|
|
|
$calculatedValue = self::$castBaseType($c); |
|
375
|
|
|
|
|
376
|
|
|
// Shared formula? |
|
377
|
|
|
if (isset($c->f['t']) && strtolower((string)$c->f['t']) == 'shared') { |
|
378
|
|
|
// echo '<font color="darkgreen">SHARED FORMULA</font><br />'; |
|
379
|
|
|
$instance = (string)$c->f['si']; |
|
380
|
|
|
|
|
381
|
|
|
// echo 'Instance ID = '.$instance.'<br />'; |
|
382
|
|
|
// |
|
383
|
|
|
// echo 'Shared Formula Array:<pre>'; |
|
384
|
|
|
// print_r($sharedFormulas); |
|
385
|
|
|
// echo '</pre>'; |
|
386
|
|
|
if (!isset($sharedFormulas[(string)$c->f['si']])) { |
|
387
|
|
|
// echo '<font color="darkgreen">SETTING NEW SHARED FORMULA</font><br />'; |
|
388
|
|
|
// echo 'Master is '.$r.'<br />'; |
|
389
|
|
|
// echo 'Formula is '.$value.'<br />'; |
|
390
|
|
|
$sharedFormulas[$instance] = array( 'master' => $r, |
|
391
|
|
|
'formula' => $value |
|
392
|
|
|
); |
|
393
|
|
|
// echo 'New Shared Formula Array:<pre>'; |
|
394
|
|
|
// print_r($sharedFormulas); |
|
395
|
|
|
// echo '</pre>'; |
|
396
|
|
|
} else { |
|
397
|
|
|
// echo '<font color="darkgreen">GETTING SHARED FORMULA</font><br />'; |
|
398
|
|
|
// echo 'Master is '.$sharedFormulas[$instance]['master'].'<br />'; |
|
399
|
|
|
// echo 'Formula is '.$sharedFormulas[$instance]['formula'].'<br />'; |
|
400
|
|
|
$master = PHPExcel_Cell::coordinateFromString($sharedFormulas[$instance]['master']); |
|
401
|
|
|
$current = PHPExcel_Cell::coordinateFromString($r); |
|
402
|
|
|
|
|
403
|
|
|
$difference = array(0, 0); |
|
404
|
|
|
$difference[0] = PHPExcel_Cell::columnIndexFromString($current[0]) - PHPExcel_Cell::columnIndexFromString($master[0]); |
|
405
|
|
|
$difference[1] = $current[1] - $master[1]; |
|
406
|
|
|
|
|
407
|
|
|
$value = $this->_referenceHelper->updateFormulaReferences( $sharedFormulas[$instance]['formula'], |
|
408
|
|
|
'A1', |
|
409
|
|
|
$difference[0], |
|
410
|
|
|
$difference[1] |
|
411
|
|
|
); |
|
412
|
|
|
// echo 'Adjusted Formula is '.$value.'<br />'; |
|
413
|
|
|
} |
|
414
|
|
|
} |
|
415
|
|
|
} |
|
416
|
|
|
|
|
417
|
|
|
|
|
418
|
|
|
public function _getFromZipArchive(ZipArchive $archive, $fileName = '') |
|
419
|
|
|
{ |
|
420
|
|
|
// Root-relative paths |
|
421
|
|
|
if (strpos($fileName, '//') !== false) |
|
422
|
|
|
{ |
|
423
|
|
|
$fileName = substr($fileName, strpos($fileName, '//') + 1); |
|
424
|
|
|
} |
|
425
|
|
|
$fileName = PHPExcel_Shared_File::realpath($fileName); |
|
426
|
|
|
|
|
427
|
|
|
// Apache POI fixes |
|
428
|
|
|
$contents = $archive->getFromName($fileName); |
|
429
|
|
|
if ($contents === false) |
|
430
|
|
|
{ |
|
431
|
|
|
$contents = $archive->getFromName(substr($fileName, 1)); |
|
432
|
|
|
} |
|
433
|
|
|
|
|
434
|
|
|
return $contents; |
|
435
|
|
|
} |
|
436
|
|
|
|
|
437
|
|
|
|
|
438
|
|
|
/** |
|
439
|
|
|
* Reads names of the worksheets from a file, without parsing the whole file to a PHPExcel object |
|
440
|
|
|
* |
|
441
|
|
|
* @param string $pFilename |
|
442
|
|
|
* @throws Exception |
|
443
|
|
|
*/ |
|
444
|
|
|
public function listWorksheetNames($pFilename) |
|
445
|
|
|
{ |
|
446
|
|
|
// Check if file exists |
|
447
|
|
|
if (!file_exists($pFilename)) { |
|
448
|
|
|
throw new Exception("Could not open " . $pFilename . " for reading! File does not exist."); |
|
449
|
|
|
} |
|
450
|
|
|
|
|
451
|
|
|
$worksheetNames = array(); |
|
452
|
|
|
|
|
453
|
|
|
$zip = new ZipArchive; |
|
454
|
|
|
$zip->open($pFilename); |
|
455
|
|
|
|
|
456
|
|
|
$rels = simplexml_load_string($this->_getFromZipArchive($zip, "_rels/.rels")); //~ http://schemas.openxmlformats.org/package/2006/relationships"); |
|
457
|
|
|
foreach ($rels->Relationship as $rel) { |
|
458
|
|
|
switch ($rel["Type"]) { |
|
459
|
|
|
case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument": |
|
460
|
|
|
$xmlWorkbook = simplexml_load_string($this->_getFromZipArchive($zip, "{$rel['Target']}")); //~ http://schemas.openxmlformats.org/spreadsheetml/2006/main"); |
|
461
|
|
|
|
|
462
|
|
|
if ($xmlWorkbook->sheets) { |
|
463
|
|
|
foreach ($xmlWorkbook->sheets->sheet as $eleSheet) { |
|
464
|
|
|
// Check if sheet should be skipped |
|
465
|
|
|
$worksheetNames[] = (string) $eleSheet["name"]; |
|
466
|
|
|
} |
|
467
|
|
|
} |
|
468
|
|
|
} |
|
469
|
|
|
} |
|
470
|
|
|
|
|
471
|
|
|
$zip->close(); |
|
472
|
|
|
|
|
473
|
|
|
return $worksheetNames; |
|
474
|
|
|
} |
|
475
|
|
|
|
|
476
|
|
|
|
|
477
|
|
|
/** |
|
478
|
|
|
* Loads PHPExcel from file |
|
479
|
|
|
* |
|
480
|
|
|
* @param string $pFilename |
|
481
|
|
|
* @throws Exception |
|
482
|
|
|
*/ |
|
483
|
|
|
public function load($pFilename) |
|
484
|
|
|
{ |
|
485
|
|
|
// Check if file exists |
|
486
|
|
|
if (!file_exists($pFilename)) { |
|
487
|
|
|
throw new Exception("Could not open " . $pFilename . " for reading! File does not exist."); |
|
488
|
|
|
} |
|
489
|
|
|
|
|
490
|
|
|
// Initialisations |
|
491
|
|
|
$excel = new PHPExcel; |
|
492
|
|
|
$excel->removeSheetByIndex(0); |
|
493
|
|
|
if (!$this->_readDataOnly) { |
|
494
|
|
|
$excel->removeCellStyleXfByIndex(0); // remove the default style |
|
495
|
|
|
$excel->removeCellXfByIndex(0); // remove the default style |
|
496
|
|
|
} |
|
497
|
|
|
$zip = new ZipArchive; |
|
498
|
|
|
$zip->open($pFilename); |
|
499
|
|
|
|
|
500
|
|
|
// Read the theme first, because we need the colour scheme when reading the styles |
|
501
|
|
|
$wbRels = simplexml_load_string($this->_getFromZipArchive($zip, "xl/_rels/workbook.xml.rels")); //~ http://schemas.openxmlformats.org/package/2006/relationships"); |
|
502
|
|
|
foreach ($wbRels->Relationship as $rel) { |
|
503
|
|
|
switch ($rel["Type"]) { |
|
504
|
|
|
case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme": |
|
505
|
|
|
$themeOrderArray = array('lt1','dk1','lt2','dk2'); |
|
506
|
|
|
$themeOrderAdditional = count($themeOrderArray); |
|
507
|
|
|
|
|
508
|
|
|
$xmlTheme = simplexml_load_string($this->_getFromZipArchive($zip, "xl/{$rel['Target']}")); |
|
509
|
|
|
if (is_object($xmlTheme)) { |
|
510
|
|
|
$xmlThemeName = $xmlTheme->attributes(); |
|
511
|
|
|
$xmlTheme = $xmlTheme->children("http://schemas.openxmlformats.org/drawingml/2006/main"); |
|
512
|
|
|
$themeName = (string)$xmlThemeName['name']; |
|
513
|
|
|
|
|
514
|
|
|
$colourScheme = $xmlTheme->themeElements->clrScheme->attributes(); |
|
515
|
|
|
$colourSchemeName = (string)$colourScheme['name']; |
|
516
|
|
|
$colourScheme = $xmlTheme->themeElements->clrScheme->children("http://schemas.openxmlformats.org/drawingml/2006/main"); |
|
517
|
|
|
|
|
518
|
|
|
$themeColours = array(); |
|
519
|
|
|
foreach ($colourScheme as $k => $xmlColour) { |
|
520
|
|
|
$themePos = array_search($k,$themeOrderArray); |
|
521
|
|
|
if ($themePos === false) { |
|
522
|
|
|
$themePos = $themeOrderAdditional++; |
|
523
|
|
|
} |
|
524
|
|
|
if (isset($xmlColour->sysClr)) { |
|
525
|
|
|
$xmlColourData = $xmlColour->sysClr->attributes(); |
|
526
|
|
|
$themeColours[$themePos] = $xmlColourData['lastClr']; |
|
527
|
|
|
} elseif (isset($xmlColour->srgbClr)) { |
|
528
|
|
|
$xmlColourData = $xmlColour->srgbClr->attributes(); |
|
529
|
|
|
$themeColours[$themePos] = $xmlColourData['val']; |
|
530
|
|
|
} |
|
531
|
|
|
} |
|
532
|
|
|
self::$_theme = new PHPExcel_Reader_Excel2007_Theme($themeName,$colourSchemeName,$themeColours); |
|
533
|
|
|
} |
|
534
|
|
|
break; |
|
535
|
|
|
} |
|
536
|
|
|
} |
|
537
|
|
|
|
|
538
|
|
|
$rels = simplexml_load_string($this->_getFromZipArchive($zip, "_rels/.rels")); //~ http://schemas.openxmlformats.org/package/2006/relationships"); |
|
539
|
|
|
foreach ($rels->Relationship as $rel) { |
|
540
|
|
|
switch ($rel["Type"]) { |
|
541
|
|
|
case "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties": |
|
542
|
|
|
$xmlCore = simplexml_load_string($this->_getFromZipArchive($zip, "{$rel['Target']}")); |
|
543
|
|
|
if (is_object($xmlCore)) { |
|
544
|
|
|
$xmlCore->registerXPathNamespace("dc", "http://purl.org/dc/elements/1.1/"); |
|
545
|
|
|
$xmlCore->registerXPathNamespace("dcterms", "http://purl.org/dc/terms/"); |
|
546
|
|
|
$xmlCore->registerXPathNamespace("cp", "http://schemas.openxmlformats.org/package/2006/metadata/core-properties"); |
|
547
|
|
|
$docProps = $excel->getProperties(); |
|
548
|
|
|
$docProps->setCreator((string) self::array_item($xmlCore->xpath("dc:creator"))); |
|
549
|
|
|
$docProps->setLastModifiedBy((string) self::array_item($xmlCore->xpath("cp:lastModifiedBy"))); |
|
550
|
|
|
$docProps->setCreated(strtotime(self::array_item($xmlCore->xpath("dcterms:created")))); //! respect xsi:type |
|
551
|
|
|
$docProps->setModified(strtotime(self::array_item($xmlCore->xpath("dcterms:modified")))); //! respect xsi:type |
|
552
|
|
|
$docProps->setTitle((string) self::array_item($xmlCore->xpath("dc:title"))); |
|
553
|
|
|
$docProps->setDescription((string) self::array_item($xmlCore->xpath("dc:description"))); |
|
554
|
|
|
$docProps->setSubject((string) self::array_item($xmlCore->xpath("dc:subject"))); |
|
555
|
|
|
$docProps->setKeywords((string) self::array_item($xmlCore->xpath("cp:keywords"))); |
|
556
|
|
|
$docProps->setCategory((string) self::array_item($xmlCore->xpath("cp:category"))); |
|
557
|
|
|
} |
|
558
|
|
|
break; |
|
559
|
|
|
|
|
560
|
|
|
case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties": |
|
561
|
|
|
$xmlCore = simplexml_load_string($this->_getFromZipArchive($zip, "{$rel['Target']}")); |
|
562
|
|
|
if (is_object($xmlCore)) { |
|
563
|
|
|
$docProps = $excel->getProperties(); |
|
564
|
|
|
if (isset($xmlCore->Company)) |
|
565
|
|
|
$docProps->setCompany((string) $xmlCore->Company); |
|
566
|
|
|
if (isset($xmlCore->Manager)) |
|
567
|
|
|
$docProps->setManager((string) $xmlCore->Manager); |
|
568
|
|
|
} |
|
569
|
|
|
break; |
|
570
|
|
|
|
|
571
|
|
|
case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties": |
|
572
|
|
|
$xmlCore = simplexml_load_string($this->_getFromZipArchive($zip, "{$rel['Target']}")); |
|
573
|
|
|
if (is_object($xmlCore)) { |
|
574
|
|
|
$docProps = $excel->getProperties(); |
|
575
|
|
|
foreach ($xmlCore as $xmlProperty) { |
|
576
|
|
|
$cellDataOfficeAttributes = $xmlProperty->attributes(); |
|
577
|
|
|
if (isset($cellDataOfficeAttributes['name'])) { |
|
578
|
|
|
$propertyName = (string) $cellDataOfficeAttributes['name']; |
|
579
|
|
|
$cellDataOfficeChildren = $xmlProperty->children('http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes'); |
|
580
|
|
|
$attributeType = $cellDataOfficeChildren->getName(); |
|
581
|
|
|
$attributeValue = (string) $cellDataOfficeChildren->{$attributeType}; |
|
582
|
|
|
$attributeValue = PHPExcel_DocumentProperties::convertProperty($attributeValue,$attributeType); |
|
583
|
|
|
$attributeType = PHPExcel_DocumentProperties::convertPropertyType($attributeType); |
|
584
|
|
|
$docProps->setCustomProperty($propertyName,$attributeValue,$attributeType); |
|
585
|
|
|
} |
|
586
|
|
|
} |
|
587
|
|
|
} |
|
588
|
|
|
break; |
|
589
|
|
|
|
|
590
|
|
|
case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument": |
|
591
|
|
|
$dir = dirname($rel["Target"]); |
|
592
|
|
|
$relsWorkbook = simplexml_load_string($this->_getFromZipArchive($zip, "$dir/_rels/" . basename($rel["Target"]) . ".rels")); //~ http://schemas.openxmlformats.org/package/2006/relationships"); |
|
593
|
|
|
$relsWorkbook->registerXPathNamespace("rel", "http://schemas.openxmlformats.org/package/2006/relationships"); |
|
594
|
|
|
|
|
595
|
|
|
$sharedStrings = array(); |
|
596
|
|
|
$xpath = self::array_item($relsWorkbook->xpath("rel:Relationship[@Type='http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings']")); |
|
597
|
|
|
$xmlStrings = simplexml_load_string($this->_getFromZipArchive($zip, "$dir/$xpath[Target]")); //~ http://schemas.openxmlformats.org/spreadsheetml/2006/main"); |
|
598
|
|
|
if (isset($xmlStrings) && isset($xmlStrings->si)) { |
|
599
|
|
|
foreach ($xmlStrings->si as $val) { |
|
600
|
|
|
if (isset($val->t)) { |
|
601
|
|
|
$sharedStrings[] = PHPExcel_Shared_String::ControlCharacterOOXML2PHP( (string) $val->t ); |
|
602
|
|
|
} elseif (isset($val->r)) { |
|
603
|
|
|
$sharedStrings[] = $this->_parseRichText($val); |
|
604
|
|
|
} |
|
605
|
|
|
} |
|
606
|
|
|
} |
|
607
|
|
|
|
|
608
|
|
|
$worksheets = array(); |
|
609
|
|
View Code Duplication |
foreach ($relsWorkbook->Relationship as $ele) { |
|
610
|
|
|
if ($ele["Type"] == "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet") { |
|
611
|
|
|
$worksheets[(string) $ele["Id"]] = $ele["Target"]; |
|
612
|
|
|
} |
|
613
|
|
|
} |
|
614
|
|
|
|
|
615
|
|
|
$styles = array(); |
|
616
|
|
|
$cellStyles = array(); |
|
617
|
|
|
$xpath = self::array_item($relsWorkbook->xpath("rel:Relationship[@Type='http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles']")); |
|
618
|
|
|
$xmlStyles = simplexml_load_string($this->_getFromZipArchive($zip, "$dir/$xpath[Target]")); //~ http://schemas.openxmlformats.org/spreadsheetml/2006/main"); |
|
619
|
|
|
$numFmts = null; |
|
620
|
|
|
if ($xmlStyles && $xmlStyles->numFmts[0]) { |
|
621
|
|
|
$numFmts = $xmlStyles->numFmts[0]; |
|
622
|
|
|
} |
|
623
|
|
|
if (isset($numFmts) && ($numFmts !== NULL)) { |
|
624
|
|
|
$numFmts->registerXPathNamespace("sml", "http://schemas.openxmlformats.org/spreadsheetml/2006/main"); |
|
625
|
|
|
} |
|
626
|
|
|
if (!$this->_readDataOnly && $xmlStyles) { |
|
627
|
|
View Code Duplication |
foreach ($xmlStyles->cellXfs->xf as $xf) { |
|
628
|
|
|
$numFmt = PHPExcel_Style_NumberFormat::FORMAT_GENERAL; |
|
629
|
|
|
|
|
630
|
|
|
if ($xf["numFmtId"]) { |
|
631
|
|
|
if (isset($numFmts)) { |
|
632
|
|
|
$tmpNumFmt = self::array_item($numFmts->xpath("sml:numFmt[@numFmtId=$xf[numFmtId]]")); |
|
633
|
|
|
|
|
634
|
|
|
if (isset($tmpNumFmt["formatCode"])) { |
|
635
|
|
|
$numFmt = (string) $tmpNumFmt["formatCode"]; |
|
636
|
|
|
} |
|
637
|
|
|
} |
|
638
|
|
|
|
|
639
|
|
|
if ((int)$xf["numFmtId"] < 164) { |
|
640
|
|
|
$numFmt = PHPExcel_Style_NumberFormat::builtInFormatCode((int)$xf["numFmtId"]); |
|
641
|
|
|
} |
|
642
|
|
|
} |
|
643
|
|
|
//$numFmt = str_replace('mm', 'i', $numFmt); |
|
644
|
|
|
//$numFmt = str_replace('h', 'H', $numFmt); |
|
645
|
|
|
|
|
646
|
|
|
$style = (object) array( |
|
647
|
|
|
"numFmt" => $numFmt, |
|
648
|
|
|
"font" => $xmlStyles->fonts->font[intval($xf["fontId"])], |
|
649
|
|
|
"fill" => $xmlStyles->fills->fill[intval($xf["fillId"])], |
|
650
|
|
|
"border" => $xmlStyles->borders->border[intval($xf["borderId"])], |
|
651
|
|
|
"alignment" => $xf->alignment, |
|
652
|
|
|
"protection" => $xf->protection, |
|
653
|
|
|
); |
|
654
|
|
|
$styles[] = $style; |
|
655
|
|
|
|
|
656
|
|
|
// add style to cellXf collection |
|
657
|
|
|
$objStyle = new PHPExcel_Style; |
|
658
|
|
|
self::_readStyle($objStyle, $style); |
|
659
|
|
|
$excel->addCellXf($objStyle); |
|
660
|
|
|
} |
|
661
|
|
|
|
|
662
|
|
View Code Duplication |
foreach ($xmlStyles->cellStyleXfs->xf as $xf) { |
|
663
|
|
|
$numFmt = PHPExcel_Style_NumberFormat::FORMAT_GENERAL; |
|
664
|
|
|
if ($numFmts && $xf["numFmtId"]) { |
|
665
|
|
|
$tmpNumFmt = self::array_item($numFmts->xpath("sml:numFmt[@numFmtId=$xf[numFmtId]]")); |
|
666
|
|
|
if (isset($tmpNumFmt["formatCode"])) { |
|
667
|
|
|
$numFmt = (string) $tmpNumFmt["formatCode"]; |
|
668
|
|
|
} else if ((int)$xf["numFmtId"] < 165) { |
|
669
|
|
|
$numFmt = PHPExcel_Style_NumberFormat::builtInFormatCode((int)$xf["numFmtId"]); |
|
670
|
|
|
} |
|
671
|
|
|
} |
|
672
|
|
|
|
|
673
|
|
|
$cellStyle = (object) array( |
|
674
|
|
|
"numFmt" => $numFmt, |
|
675
|
|
|
"font" => $xmlStyles->fonts->font[intval($xf["fontId"])], |
|
676
|
|
|
"fill" => $xmlStyles->fills->fill[intval($xf["fillId"])], |
|
677
|
|
|
"border" => $xmlStyles->borders->border[intval($xf["borderId"])], |
|
678
|
|
|
"alignment" => $xf->alignment, |
|
679
|
|
|
"protection" => $xf->protection, |
|
680
|
|
|
); |
|
681
|
|
|
$cellStyles[] = $cellStyle; |
|
682
|
|
|
|
|
683
|
|
|
// add style to cellStyleXf collection |
|
684
|
|
|
$objStyle = new PHPExcel_Style; |
|
685
|
|
|
self::_readStyle($objStyle, $cellStyle); |
|
686
|
|
|
$excel->addCellStyleXf($objStyle); |
|
687
|
|
|
} |
|
688
|
|
|
} |
|
689
|
|
|
|
|
690
|
|
|
$dxfs = array(); |
|
691
|
|
|
if (!$this->_readDataOnly && $xmlStyles) { |
|
692
|
|
|
if ($xmlStyles->dxfs) { |
|
693
|
|
|
foreach ($xmlStyles->dxfs->dxf as $dxf) { |
|
694
|
|
|
$style = new PHPExcel_Style; |
|
695
|
|
|
self::_readStyle($style, $dxf); |
|
696
|
|
|
$dxfs[] = $style; |
|
697
|
|
|
} |
|
698
|
|
|
} |
|
699
|
|
|
|
|
700
|
|
|
if ($xmlStyles->cellStyles) |
|
701
|
|
|
{ |
|
702
|
|
|
foreach ($xmlStyles->cellStyles->cellStyle as $cellStyle) { |
|
703
|
|
|
if (intval($cellStyle['builtinId']) == 0) { |
|
704
|
|
|
if (isset($cellStyles[intval($cellStyle['xfId'])])) { |
|
705
|
|
|
// Set default style |
|
706
|
|
|
$style = new PHPExcel_Style; |
|
707
|
|
|
self::_readStyle($style, $cellStyles[intval($cellStyle['xfId'])]); |
|
708
|
|
|
|
|
709
|
|
|
// normal style, currently not using it for anything |
|
710
|
|
|
} |
|
711
|
|
|
} |
|
712
|
|
|
} |
|
713
|
|
|
} |
|
714
|
|
|
} |
|
715
|
|
|
|
|
716
|
|
|
$xmlWorkbook = simplexml_load_string($this->_getFromZipArchive($zip, "{$rel['Target']}")); //~ http://schemas.openxmlformats.org/spreadsheetml/2006/main"); |
|
717
|
|
|
|
|
718
|
|
|
// Set base date |
|
719
|
|
|
if ($xmlWorkbook->workbookPr) { |
|
720
|
|
|
PHPExcel_Shared_Date::setExcelCalendar(PHPExcel_Shared_Date::CALENDAR_WINDOWS_1900); |
|
721
|
|
|
if (isset($xmlWorkbook->workbookPr['date1904'])) { |
|
722
|
|
|
$date1904 = (string)$xmlWorkbook->workbookPr['date1904']; |
|
723
|
|
|
if ($date1904 == "true" || $date1904 == "1") { |
|
724
|
|
|
PHPExcel_Shared_Date::setExcelCalendar(PHPExcel_Shared_Date::CALENDAR_MAC_1904); |
|
725
|
|
|
} |
|
726
|
|
|
} |
|
727
|
|
|
} |
|
728
|
|
|
|
|
729
|
|
|
$sheetId = 0; // keep track of new sheet id in final workbook |
|
730
|
|
|
$oldSheetId = -1; // keep track of old sheet id in final workbook |
|
731
|
|
|
$countSkippedSheets = 0; // keep track of number of skipped sheets |
|
732
|
|
|
$mapSheetId = array(); // mapping of sheet ids from old to new |
|
733
|
|
|
|
|
734
|
|
|
|
|
735
|
|
|
$charts = $chartDetails = array(); |
|
736
|
|
|
|
|
737
|
|
|
if ($xmlWorkbook->sheets) { |
|
738
|
|
|
foreach ($xmlWorkbook->sheets->sheet as $eleSheet) { |
|
739
|
|
|
++$oldSheetId; |
|
740
|
|
|
|
|
741
|
|
|
// Check if sheet should be skipped |
|
742
|
|
|
if (isset($this->_loadSheetsOnly) && !in_array((string) $eleSheet["name"], $this->_loadSheetsOnly)) { |
|
743
|
|
|
++$countSkippedSheets; |
|
744
|
|
|
$mapSheetId[$oldSheetId] = null; |
|
745
|
|
|
continue; |
|
746
|
|
|
} |
|
747
|
|
|
|
|
748
|
|
|
// Map old sheet id in original workbook to new sheet id. |
|
749
|
|
|
// They will differ if loadSheetsOnly() is being used |
|
750
|
|
|
$mapSheetId[$oldSheetId] = $oldSheetId - $countSkippedSheets; |
|
751
|
|
|
|
|
752
|
|
|
// Load sheet |
|
753
|
|
|
$docSheet = $excel->createSheet(); |
|
754
|
|
|
// Use false for $updateFormulaCellReferences to prevent adjustment of worksheet |
|
755
|
|
|
// references in formula cells... during the load, all formulae should be correct, |
|
756
|
|
|
// and we're simply bringing the worksheet name in line with the formula, not the |
|
757
|
|
|
// reverse |
|
758
|
|
|
$docSheet->setTitle((string) $eleSheet["name"],false); |
|
759
|
|
|
$fileWorksheet = $worksheets[(string) self::array_item($eleSheet->attributes("http://schemas.openxmlformats.org/officeDocument/2006/relationships"), "id")]; |
|
760
|
|
|
$xmlSheet = simplexml_load_string($this->_getFromZipArchive($zip, "$dir/$fileWorksheet")); //~ http://schemas.openxmlformats.org/spreadsheetml/2006/main"); |
|
761
|
|
|
|
|
762
|
|
|
$sharedFormulas = array(); |
|
763
|
|
|
|
|
764
|
|
|
if (isset($eleSheet["state"]) && (string) $eleSheet["state"] != '') { |
|
765
|
|
|
$docSheet->setSheetState( (string) $eleSheet["state"] ); |
|
766
|
|
|
} |
|
767
|
|
|
|
|
768
|
|
|
if (isset($xmlSheet->sheetViews) && isset($xmlSheet->sheetViews->sheetView)) { |
|
769
|
|
View Code Duplication |
if (isset($xmlSheet->sheetViews->sheetView['zoomScale'])) { |
|
770
|
|
|
$docSheet->getSheetView()->setZoomScale( intval($xmlSheet->sheetViews->sheetView['zoomScale']) ); |
|
771
|
|
|
} |
|
772
|
|
|
|
|
773
|
|
View Code Duplication |
if (isset($xmlSheet->sheetViews->sheetView['zoomScaleNormal'])) { |
|
774
|
|
|
$docSheet->getSheetView()->setZoomScaleNormal( intval($xmlSheet->sheetViews->sheetView['zoomScaleNormal']) ); |
|
775
|
|
|
} |
|
776
|
|
|
|
|
777
|
|
|
if (isset($xmlSheet->sheetViews->sheetView['showGridLines'])) { |
|
778
|
|
|
$docSheet->setShowGridLines((string)$xmlSheet->sheetViews->sheetView['showGridLines'] ? true : false); |
|
779
|
|
|
} |
|
780
|
|
|
|
|
781
|
|
|
if (isset($xmlSheet->sheetViews->sheetView['showRowColHeaders'])) { |
|
782
|
|
|
$docSheet->setShowRowColHeaders((string)$xmlSheet->sheetViews->sheetView['showRowColHeaders'] ? true : false); |
|
783
|
|
|
} |
|
784
|
|
|
|
|
785
|
|
|
if (isset($xmlSheet->sheetViews->sheetView['rightToLeft'])) { |
|
786
|
|
|
$docSheet->setRightToLeft((string)$xmlSheet->sheetViews->sheetView['rightToLeft'] ? true : false); |
|
787
|
|
|
} |
|
788
|
|
|
|
|
789
|
|
|
if (isset($xmlSheet->sheetViews->sheetView->pane)) { |
|
790
|
|
|
if (isset($xmlSheet->sheetViews->sheetView->pane['topLeftCell'])) { |
|
791
|
|
|
$docSheet->freezePane( (string)$xmlSheet->sheetViews->sheetView->pane['topLeftCell'] ); |
|
792
|
|
|
} else { |
|
793
|
|
|
$xSplit = 0; |
|
794
|
|
|
$ySplit = 0; |
|
795
|
|
|
|
|
796
|
|
View Code Duplication |
if (isset($xmlSheet->sheetViews->sheetView->pane['xSplit'])) { |
|
797
|
|
|
$xSplit = 1 + intval($xmlSheet->sheetViews->sheetView->pane['xSplit']); |
|
798
|
|
|
} |
|
799
|
|
|
|
|
800
|
|
View Code Duplication |
if (isset($xmlSheet->sheetViews->sheetView->pane['ySplit'])) { |
|
801
|
|
|
$ySplit = 1 + intval($xmlSheet->sheetViews->sheetView->pane['ySplit']); |
|
802
|
|
|
} |
|
803
|
|
|
|
|
804
|
|
|
$docSheet->freezePaneByColumnAndRow($xSplit, $ySplit); |
|
805
|
|
|
} |
|
806
|
|
|
} |
|
807
|
|
|
|
|
808
|
|
|
if (isset($xmlSheet->sheetViews->sheetView->selection)) { |
|
809
|
|
|
if (isset($xmlSheet->sheetViews->sheetView->selection['sqref'])) { |
|
810
|
|
|
$sqref = (string)$xmlSheet->sheetViews->sheetView->selection['sqref']; |
|
811
|
|
|
$sqref = explode(' ', $sqref); |
|
812
|
|
|
$sqref = $sqref[0]; |
|
813
|
|
|
$docSheet->setSelectedCells($sqref); |
|
814
|
|
|
} |
|
815
|
|
|
} |
|
816
|
|
|
|
|
817
|
|
|
} |
|
818
|
|
|
|
|
819
|
|
|
if (isset($xmlSheet->sheetPr) && isset($xmlSheet->sheetPr->tabColor)) { |
|
820
|
|
|
if (isset($xmlSheet->sheetPr->tabColor['rgb'])) { |
|
821
|
|
|
$docSheet->getTabColor()->setARGB( (string)$xmlSheet->sheetPr->tabColor['rgb'] ); |
|
822
|
|
|
} |
|
823
|
|
|
} |
|
824
|
|
|
|
|
825
|
|
|
if (isset($xmlSheet->sheetPr) && isset($xmlSheet->sheetPr->outlinePr)) { |
|
826
|
|
View Code Duplication |
if (isset($xmlSheet->sheetPr->outlinePr['summaryRight']) && $xmlSheet->sheetPr->outlinePr['summaryRight'] == false) { |
|
827
|
|
|
$docSheet->setShowSummaryRight(false); |
|
828
|
|
|
} else { |
|
829
|
|
|
$docSheet->setShowSummaryRight(true); |
|
830
|
|
|
} |
|
831
|
|
|
|
|
832
|
|
View Code Duplication |
if (isset($xmlSheet->sheetPr->outlinePr['summaryBelow']) && $xmlSheet->sheetPr->outlinePr['summaryBelow'] == false) { |
|
833
|
|
|
$docSheet->setShowSummaryBelow(false); |
|
834
|
|
|
} else { |
|
835
|
|
|
$docSheet->setShowSummaryBelow(true); |
|
836
|
|
|
} |
|
837
|
|
|
} |
|
838
|
|
|
|
|
839
|
|
|
if (isset($xmlSheet->sheetPr) && isset($xmlSheet->sheetPr->pageSetUpPr)) { |
|
840
|
|
|
if (isset($xmlSheet->sheetPr->pageSetUpPr['fitToPage']) && $xmlSheet->sheetPr->pageSetUpPr['fitToPage'] == false) { |
|
841
|
|
|
$docSheet->getPageSetup()->setFitToPage(false); |
|
842
|
|
|
} else { |
|
843
|
|
|
$docSheet->getPageSetup()->setFitToPage(true); |
|
844
|
|
|
} |
|
845
|
|
|
} |
|
846
|
|
|
|
|
847
|
|
|
if (isset($xmlSheet->sheetFormatPr)) { |
|
848
|
|
|
if (isset($xmlSheet->sheetFormatPr['customHeight']) && ((string)$xmlSheet->sheetFormatPr['customHeight'] == '1' || strtolower((string)$xmlSheet->sheetFormatPr['customHeight']) == 'true') && isset($xmlSheet->sheetFormatPr['defaultRowHeight'])) { |
|
849
|
|
|
$docSheet->getDefaultRowDimension()->setRowHeight( (float)$xmlSheet->sheetFormatPr['defaultRowHeight'] ); |
|
850
|
|
|
} |
|
851
|
|
|
if (isset($xmlSheet->sheetFormatPr['defaultColWidth'])) { |
|
852
|
|
|
$docSheet->getDefaultColumnDimension()->setWidth( (float)$xmlSheet->sheetFormatPr['defaultColWidth'] ); |
|
853
|
|
|
} |
|
854
|
|
|
} |
|
855
|
|
|
|
|
856
|
|
|
if (isset($xmlSheet->cols) && !$this->_readDataOnly) { |
|
857
|
|
|
foreach ($xmlSheet->cols->col as $col) { |
|
858
|
|
|
for ($i = intval($col["min"]) - 1; $i < intval($col["max"]); ++$i) { |
|
859
|
|
|
if ($col["style"] && !$this->_readDataOnly) { |
|
860
|
|
|
$docSheet->getColumnDimension(PHPExcel_Cell::stringFromColumnIndex($i))->setXfIndex(intval($col["style"])); |
|
861
|
|
|
} |
|
862
|
|
|
if ($col["bestFit"]) { |
|
|
|
|
|
|
863
|
|
|
//$docSheet->getColumnDimension(PHPExcel_Cell::stringFromColumnIndex($i))->setAutoSize(true); |
|
864
|
|
|
} |
|
865
|
|
|
if ($col["hidden"]) { |
|
866
|
|
|
$docSheet->getColumnDimension(PHPExcel_Cell::stringFromColumnIndex($i))->setVisible(false); |
|
867
|
|
|
} |
|
868
|
|
|
if ($col["collapsed"]) { |
|
869
|
|
|
$docSheet->getColumnDimension(PHPExcel_Cell::stringFromColumnIndex($i))->setCollapsed(true); |
|
870
|
|
|
} |
|
871
|
|
|
if ($col["outlineLevel"] > 0) { |
|
872
|
|
|
$docSheet->getColumnDimension(PHPExcel_Cell::stringFromColumnIndex($i))->setOutlineLevel(intval($col["outlineLevel"])); |
|
873
|
|
|
} |
|
874
|
|
|
$docSheet->getColumnDimension(PHPExcel_Cell::stringFromColumnIndex($i))->setWidth(floatval($col["width"])); |
|
875
|
|
|
|
|
876
|
|
|
if (intval($col["max"]) == 16384) { |
|
877
|
|
|
break; |
|
878
|
|
|
} |
|
879
|
|
|
} |
|
880
|
|
|
} |
|
881
|
|
|
} |
|
882
|
|
|
|
|
883
|
|
|
if (isset($xmlSheet->printOptions) && !$this->_readDataOnly) { |
|
884
|
|
|
if ($xmlSheet->printOptions['gridLinesSet'] == 'true' && $xmlSheet->printOptions['gridLinesSet'] == '1') { |
|
885
|
|
|
$docSheet->setShowGridlines(true); |
|
886
|
|
|
} |
|
887
|
|
|
|
|
888
|
|
|
if ($xmlSheet->printOptions['gridLines'] == 'true' || $xmlSheet->printOptions['gridLines'] == '1') { |
|
889
|
|
|
$docSheet->setPrintGridlines(true); |
|
890
|
|
|
} |
|
891
|
|
|
|
|
892
|
|
|
if ($xmlSheet->printOptions['horizontalCentered']) { |
|
893
|
|
|
$docSheet->getPageSetup()->setHorizontalCentered(true); |
|
894
|
|
|
} |
|
895
|
|
|
if ($xmlSheet->printOptions['verticalCentered']) { |
|
896
|
|
|
$docSheet->getPageSetup()->setVerticalCentered(true); |
|
897
|
|
|
} |
|
898
|
|
|
} |
|
899
|
|
|
|
|
900
|
|
|
if ($xmlSheet && $xmlSheet->sheetData && $xmlSheet->sheetData->row) { |
|
901
|
|
|
foreach ($xmlSheet->sheetData->row as $row) { |
|
902
|
|
|
if ($row["ht"] && !$this->_readDataOnly) { |
|
903
|
|
|
$docSheet->getRowDimension(intval($row["r"]))->setRowHeight(floatval($row["ht"])); |
|
904
|
|
|
} |
|
905
|
|
|
if ($row["hidden"] && !$this->_readDataOnly) { |
|
906
|
|
|
$docSheet->getRowDimension(intval($row["r"]))->setVisible(false); |
|
907
|
|
|
} |
|
908
|
|
|
if ($row["collapsed"]) { |
|
909
|
|
|
$docSheet->getRowDimension(intval($row["r"]))->setCollapsed(true); |
|
910
|
|
|
} |
|
911
|
|
|
if ($row["outlineLevel"] > 0) { |
|
912
|
|
|
$docSheet->getRowDimension(intval($row["r"]))->setOutlineLevel(intval($row["outlineLevel"])); |
|
913
|
|
|
} |
|
914
|
|
View Code Duplication |
if ($row["s"] && !$this->_readDataOnly) { |
|
915
|
|
|
$docSheet->getRowDimension(intval($row["r"]))->setXfIndex(intval($row["s"])); |
|
916
|
|
|
} |
|
917
|
|
|
|
|
918
|
|
|
foreach ($row->c as $c) { |
|
919
|
|
|
$r = (string) $c["r"]; |
|
920
|
|
|
$cellDataType = (string) $c["t"]; |
|
921
|
|
|
$value = null; |
|
922
|
|
|
$calculatedValue = null; |
|
923
|
|
|
|
|
924
|
|
|
// Read cell? |
|
925
|
|
|
if ($this->getReadFilter() !== NULL) { |
|
926
|
|
|
$coordinates = PHPExcel_Cell::coordinateFromString($r); |
|
927
|
|
|
|
|
928
|
|
|
if (!$this->getReadFilter()->readCell($coordinates[0], $coordinates[1], $docSheet->getTitle())) { |
|
929
|
|
|
continue; |
|
930
|
|
|
} |
|
931
|
|
|
} |
|
932
|
|
|
|
|
933
|
|
|
// echo '<b>Reading cell '.$coordinates[0].$coordinates[1].'</b><br />'; |
|
934
|
|
|
// print_r($c); |
|
935
|
|
|
// echo '<br />'; |
|
936
|
|
|
// echo 'Cell Data Type is '.$cellDataType.': '; |
|
937
|
|
|
// |
|
938
|
|
|
// Read cell! |
|
939
|
|
|
switch ($cellDataType) { |
|
940
|
|
|
case "s": |
|
941
|
|
|
// echo 'String<br />'; |
|
942
|
|
|
if ((string)$c->v != '') { |
|
943
|
|
|
$value = $sharedStrings[intval($c->v)]; |
|
944
|
|
|
|
|
945
|
|
|
if ($value instanceof PHPExcel_RichText) { |
|
946
|
|
|
$value = clone $value; |
|
947
|
|
|
} |
|
948
|
|
|
} else { |
|
949
|
|
|
$value = ''; |
|
950
|
|
|
} |
|
951
|
|
|
|
|
952
|
|
|
break; |
|
953
|
|
|
case "b": |
|
954
|
|
|
// echo 'Boolean<br />'; |
|
955
|
|
|
if (!isset($c->f)) { |
|
956
|
|
|
$value = self::_castToBool($c); |
|
957
|
|
|
} else { |
|
958
|
|
|
// Formula |
|
959
|
|
|
$this->_castToFormula($c,$r,$cellDataType,$value,$calculatedValue,$sharedFormulas,'_castToBool'); |
|
960
|
|
|
if (isset($c->f['t'])) { |
|
961
|
|
|
$att = array(); |
|
962
|
|
|
$att = $c->f; |
|
963
|
|
|
$docSheet->getCell($r)->setFormulaAttributes($att); |
|
964
|
|
|
} |
|
965
|
|
|
// echo '$calculatedValue = '.$calculatedValue.'<br />'; |
|
966
|
|
|
} |
|
967
|
|
|
break; |
|
968
|
|
|
case "inlineStr": |
|
969
|
|
|
// echo 'Inline String<br />'; |
|
970
|
|
|
$value = $this->_parseRichText($c->is); |
|
971
|
|
|
|
|
972
|
|
|
break; |
|
973
|
|
|
case "e": |
|
974
|
|
|
// echo 'Error<br />'; |
|
975
|
|
View Code Duplication |
if (!isset($c->f)) { |
|
976
|
|
|
$value = self::_castToError($c); |
|
977
|
|
|
} else { |
|
978
|
|
|
// Formula |
|
979
|
|
|
$this->_castToFormula($c,$r,$cellDataType,$value,$calculatedValue,$sharedFormulas,'_castToError'); |
|
980
|
|
|
// echo '$calculatedValue = '.$calculatedValue.'<br />'; |
|
981
|
|
|
} |
|
982
|
|
|
|
|
983
|
|
|
break; |
|
984
|
|
|
|
|
985
|
|
|
default: |
|
986
|
|
|
// echo 'Default<br />'; |
|
987
|
|
View Code Duplication |
if (!isset($c->f)) { |
|
988
|
|
|
// echo 'Not a Formula<br />'; |
|
989
|
|
|
$value = self::_castToString($c); |
|
990
|
|
|
} else { |
|
991
|
|
|
// echo 'Treat as Formula<br />'; |
|
992
|
|
|
// Formula |
|
993
|
|
|
$this->_castToFormula($c,$r,$cellDataType,$value,$calculatedValue,$sharedFormulas,'_castToString'); |
|
994
|
|
|
// echo '$calculatedValue = '.$calculatedValue.'<br />'; |
|
995
|
|
|
} |
|
996
|
|
|
|
|
997
|
|
|
break; |
|
998
|
|
|
} |
|
999
|
|
|
// echo 'Value is '.$value.'<br />'; |
|
1000
|
|
|
|
|
1001
|
|
|
// Check for numeric values |
|
1002
|
|
|
if (is_numeric($value) && $cellDataType != 's') { |
|
1003
|
|
|
if ($value == (int)$value) $value = (int)$value; |
|
1004
|
|
|
elseif ($value == (float)$value) $value = (float)$value; |
|
1005
|
|
|
elseif ($value == (double)$value) $value = (double)$value; |
|
1006
|
|
|
} |
|
1007
|
|
|
|
|
1008
|
|
|
// Rich text? |
|
1009
|
|
|
if ($value instanceof PHPExcel_RichText && $this->_readDataOnly) { |
|
1010
|
|
|
$value = $value->getPlainText(); |
|
1011
|
|
|
} |
|
1012
|
|
|
|
|
1013
|
|
|
$cell = $docSheet->getCell($r); |
|
1014
|
|
|
// Assign value |
|
1015
|
|
|
if ($cellDataType != '') { |
|
1016
|
|
|
$cell->setValueExplicit($value, $cellDataType); |
|
1017
|
|
|
} else { |
|
1018
|
|
|
$cell->setValue($value); |
|
1019
|
|
|
} |
|
1020
|
|
|
if ($calculatedValue !== NULL) { |
|
1021
|
|
|
$cell->setCalculatedValue($calculatedValue); |
|
1022
|
|
|
} |
|
1023
|
|
|
|
|
1024
|
|
|
// Style information? |
|
1025
|
|
View Code Duplication |
if ($c["s"] && !$this->_readDataOnly) { |
|
1026
|
|
|
// no style index means 0, it seems |
|
1027
|
|
|
$cell->setXfIndex(isset($styles[intval($c["s"])]) ? |
|
1028
|
|
|
intval($c["s"]) : 0); |
|
1029
|
|
|
} |
|
1030
|
|
|
} |
|
1031
|
|
|
} |
|
1032
|
|
|
} |
|
1033
|
|
|
|
|
1034
|
|
|
$conditionals = array(); |
|
1035
|
|
|
if (!$this->_readDataOnly && $xmlSheet && $xmlSheet->conditionalFormatting) { |
|
1036
|
|
|
foreach ($xmlSheet->conditionalFormatting as $conditional) { |
|
1037
|
|
|
foreach ($conditional->cfRule as $cfRule) { |
|
1038
|
|
|
if ( |
|
1039
|
|
|
( |
|
1040
|
|
|
(string)$cfRule["type"] == PHPExcel_Style_Conditional::CONDITION_NONE || |
|
1041
|
|
|
(string)$cfRule["type"] == PHPExcel_Style_Conditional::CONDITION_CELLIS || |
|
1042
|
|
|
(string)$cfRule["type"] == PHPExcel_Style_Conditional::CONDITION_CONTAINSTEXT || |
|
1043
|
|
|
(string)$cfRule["type"] == PHPExcel_Style_Conditional::CONDITION_EXPRESSION |
|
1044
|
|
|
) && isset($dxfs[intval($cfRule["dxfId"])]) |
|
1045
|
|
|
) { |
|
1046
|
|
|
$conditionals[(string) $conditional["sqref"]][intval($cfRule["priority"])] = $cfRule; |
|
1047
|
|
|
} |
|
1048
|
|
|
} |
|
1049
|
|
|
} |
|
1050
|
|
|
|
|
1051
|
|
|
foreach ($conditionals as $ref => $cfRules) { |
|
1052
|
|
|
ksort($cfRules); |
|
1053
|
|
|
$conditionalStyles = array(); |
|
1054
|
|
|
foreach ($cfRules as $cfRule) { |
|
1055
|
|
|
$objConditional = new PHPExcel_Style_Conditional(); |
|
1056
|
|
|
$objConditional->setConditionType((string)$cfRule["type"]); |
|
1057
|
|
|
$objConditional->setOperatorType((string)$cfRule["operator"]); |
|
1058
|
|
|
|
|
1059
|
|
|
if ((string)$cfRule["text"] != '') { |
|
1060
|
|
|
$objConditional->setText((string)$cfRule["text"]); |
|
1061
|
|
|
} |
|
1062
|
|
|
|
|
1063
|
|
|
if (count($cfRule->formula) > 1) { |
|
1064
|
|
|
foreach ($cfRule->formula as $formula) { |
|
1065
|
|
|
$objConditional->addCondition((string)$formula); |
|
1066
|
|
|
} |
|
1067
|
|
|
} else { |
|
1068
|
|
|
$objConditional->addCondition((string)$cfRule->formula); |
|
1069
|
|
|
} |
|
1070
|
|
|
$objConditional->setStyle(clone $dxfs[intval($cfRule["dxfId"])]); |
|
1071
|
|
|
$conditionalStyles[] = $objConditional; |
|
1072
|
|
|
} |
|
1073
|
|
|
|
|
1074
|
|
|
// Extract all cell references in $ref |
|
1075
|
|
|
$aReferences = PHPExcel_Cell::extractAllCellReferencesInRange($ref); |
|
1076
|
|
|
foreach ($aReferences as $reference) { |
|
1077
|
|
|
$docSheet->getStyle($reference)->setConditionalStyles($conditionalStyles); |
|
1078
|
|
|
} |
|
1079
|
|
|
} |
|
1080
|
|
|
} |
|
1081
|
|
|
|
|
1082
|
|
|
$aKeys = array("sheet", "objects", "scenarios", "formatCells", "formatColumns", "formatRows", "insertColumns", "insertRows", "insertHyperlinks", "deleteColumns", "deleteRows", "selectLockedCells", "sort", "autoFilter", "pivotTables", "selectUnlockedCells"); |
|
1083
|
|
|
if (!$this->_readDataOnly && $xmlSheet && $xmlSheet->sheetProtection) { |
|
1084
|
|
|
foreach ($aKeys as $key) { |
|
1085
|
|
|
$method = "set" . ucfirst($key); |
|
1086
|
|
|
$docSheet->getProtection()->$method($xmlSheet->sheetProtection[$key] == "true"); |
|
1087
|
|
|
} |
|
1088
|
|
|
} |
|
1089
|
|
|
|
|
1090
|
|
|
if (!$this->_readDataOnly && $xmlSheet && $xmlSheet->sheetProtection) { |
|
1091
|
|
|
$docSheet->getProtection()->setPassword((string) $xmlSheet->sheetProtection["password"], true); |
|
1092
|
|
|
if ($xmlSheet->protectedRanges->protectedRange) { |
|
1093
|
|
|
foreach ($xmlSheet->protectedRanges->protectedRange as $protectedRange) { |
|
1094
|
|
|
$docSheet->protectCells((string) $protectedRange["sqref"], (string) $protectedRange["password"], true); |
|
1095
|
|
|
} |
|
1096
|
|
|
} |
|
1097
|
|
|
} |
|
1098
|
|
|
|
|
1099
|
|
|
if ($xmlSheet && $xmlSheet->autoFilter && !$this->_readDataOnly) { |
|
1100
|
|
|
$docSheet->setAutoFilter((string) $xmlSheet->autoFilter["ref"]); |
|
1101
|
|
|
} |
|
1102
|
|
|
|
|
1103
|
|
|
if ($xmlSheet && $xmlSheet->mergeCells && $xmlSheet->mergeCells->mergeCell && !$this->_readDataOnly) { |
|
1104
|
|
|
foreach ($xmlSheet->mergeCells->mergeCell as $mergeCell) { |
|
1105
|
|
|
$docSheet->mergeCells((string) $mergeCell["ref"]); |
|
1106
|
|
|
} |
|
1107
|
|
|
} |
|
1108
|
|
|
|
|
1109
|
|
|
if ($xmlSheet && $xmlSheet->pageMargins && !$this->_readDataOnly) { |
|
1110
|
|
|
$docPageMargins = $docSheet->getPageMargins(); |
|
1111
|
|
|
$docPageMargins->setLeft(floatval($xmlSheet->pageMargins["left"])); |
|
1112
|
|
|
$docPageMargins->setRight(floatval($xmlSheet->pageMargins["right"])); |
|
1113
|
|
|
$docPageMargins->setTop(floatval($xmlSheet->pageMargins["top"])); |
|
1114
|
|
|
$docPageMargins->setBottom(floatval($xmlSheet->pageMargins["bottom"])); |
|
1115
|
|
|
$docPageMargins->setHeader(floatval($xmlSheet->pageMargins["header"])); |
|
1116
|
|
|
$docPageMargins->setFooter(floatval($xmlSheet->pageMargins["footer"])); |
|
1117
|
|
|
} |
|
1118
|
|
|
|
|
1119
|
|
|
if ($xmlSheet && $xmlSheet->pageSetup && !$this->_readDataOnly) { |
|
1120
|
|
|
$docPageSetup = $docSheet->getPageSetup(); |
|
1121
|
|
|
|
|
1122
|
|
|
if (isset($xmlSheet->pageSetup["orientation"])) { |
|
1123
|
|
|
$docPageSetup->setOrientation((string) $xmlSheet->pageSetup["orientation"]); |
|
1124
|
|
|
} |
|
1125
|
|
|
if (isset($xmlSheet->pageSetup["paperSize"])) { |
|
1126
|
|
|
$docPageSetup->setPaperSize(intval($xmlSheet->pageSetup["paperSize"])); |
|
1127
|
|
|
} |
|
1128
|
|
|
if (isset($xmlSheet->pageSetup["scale"])) { |
|
1129
|
|
|
$docPageSetup->setScale(intval($xmlSheet->pageSetup["scale"]), false); |
|
1130
|
|
|
} |
|
1131
|
|
View Code Duplication |
if (isset($xmlSheet->pageSetup["fitToHeight"]) && intval($xmlSheet->pageSetup["fitToHeight"]) >= 0) { |
|
1132
|
|
|
$docPageSetup->setFitToHeight(intval($xmlSheet->pageSetup["fitToHeight"]), false); |
|
1133
|
|
|
} |
|
1134
|
|
View Code Duplication |
if (isset($xmlSheet->pageSetup["fitToWidth"]) && intval($xmlSheet->pageSetup["fitToWidth"]) >= 0) { |
|
1135
|
|
|
$docPageSetup->setFitToWidth(intval($xmlSheet->pageSetup["fitToWidth"]), false); |
|
1136
|
|
|
} |
|
1137
|
|
|
if (isset($xmlSheet->pageSetup["firstPageNumber"]) && isset($xmlSheet->pageSetup["useFirstPageNumber"]) && |
|
1138
|
|
|
((string)$xmlSheet->pageSetup["useFirstPageNumber"] == 'true' || (string)$xmlSheet->pageSetup["useFirstPageNumber"] == '1')) { |
|
1139
|
|
|
$docPageSetup->setFirstPageNumber(intval($xmlSheet->pageSetup["firstPageNumber"])); |
|
1140
|
|
|
} |
|
1141
|
|
|
} |
|
1142
|
|
|
|
|
1143
|
|
|
if ($xmlSheet && $xmlSheet->headerFooter && !$this->_readDataOnly) { |
|
1144
|
|
|
$docHeaderFooter = $docSheet->getHeaderFooter(); |
|
1145
|
|
|
|
|
1146
|
|
View Code Duplication |
if (isset($xmlSheet->headerFooter["differentOddEven"]) && |
|
1147
|
|
|
((string)$xmlSheet->headerFooter["differentOddEven"] == 'true' || (string)$xmlSheet->headerFooter["differentOddEven"] == '1')) { |
|
1148
|
|
|
$docHeaderFooter->setDifferentOddEven(true); |
|
1149
|
|
|
} else { |
|
1150
|
|
|
$docHeaderFooter->setDifferentOddEven(false); |
|
1151
|
|
|
} |
|
1152
|
|
View Code Duplication |
if (isset($xmlSheet->headerFooter["differentFirst"]) && |
|
1153
|
|
|
((string)$xmlSheet->headerFooter["differentFirst"] == 'true' || (string)$xmlSheet->headerFooter["differentFirst"] == '1')) { |
|
1154
|
|
|
$docHeaderFooter->setDifferentFirst(true); |
|
1155
|
|
|
} else { |
|
1156
|
|
|
$docHeaderFooter->setDifferentFirst(false); |
|
1157
|
|
|
} |
|
1158
|
|
View Code Duplication |
if (isset($xmlSheet->headerFooter["scaleWithDoc"]) && |
|
1159
|
|
|
((string)$xmlSheet->headerFooter["scaleWithDoc"] == 'false' || (string)$xmlSheet->headerFooter["scaleWithDoc"] == '0')) { |
|
1160
|
|
|
$docHeaderFooter->setScaleWithDocument(false); |
|
1161
|
|
|
} else { |
|
1162
|
|
|
$docHeaderFooter->setScaleWithDocument(true); |
|
1163
|
|
|
} |
|
1164
|
|
View Code Duplication |
if (isset($xmlSheet->headerFooter["alignWithMargins"]) && |
|
1165
|
|
|
((string)$xmlSheet->headerFooter["alignWithMargins"] == 'false' || (string)$xmlSheet->headerFooter["alignWithMargins"] == '0')) { |
|
1166
|
|
|
$docHeaderFooter->setAlignWithMargins(false); |
|
1167
|
|
|
} else { |
|
1168
|
|
|
$docHeaderFooter->setAlignWithMargins(true); |
|
1169
|
|
|
} |
|
1170
|
|
|
|
|
1171
|
|
|
$docHeaderFooter->setOddHeader((string) $xmlSheet->headerFooter->oddHeader); |
|
1172
|
|
|
$docHeaderFooter->setOddFooter((string) $xmlSheet->headerFooter->oddFooter); |
|
1173
|
|
|
$docHeaderFooter->setEvenHeader((string) $xmlSheet->headerFooter->evenHeader); |
|
1174
|
|
|
$docHeaderFooter->setEvenFooter((string) $xmlSheet->headerFooter->evenFooter); |
|
1175
|
|
|
$docHeaderFooter->setFirstHeader((string) $xmlSheet->headerFooter->firstHeader); |
|
1176
|
|
|
$docHeaderFooter->setFirstFooter((string) $xmlSheet->headerFooter->firstFooter); |
|
1177
|
|
|
} |
|
1178
|
|
|
|
|
1179
|
|
|
if ($xmlSheet && $xmlSheet->rowBreaks && $xmlSheet->rowBreaks->brk && !$this->_readDataOnly) { |
|
1180
|
|
|
foreach ($xmlSheet->rowBreaks->brk as $brk) { |
|
1181
|
|
|
if ($brk["man"]) { |
|
1182
|
|
|
$docSheet->setBreak("A$brk[id]", PHPExcel_Worksheet::BREAK_ROW); |
|
1183
|
|
|
} |
|
1184
|
|
|
} |
|
1185
|
|
|
} |
|
1186
|
|
|
if ($xmlSheet && $xmlSheet->colBreaks && $xmlSheet->colBreaks->brk && !$this->_readDataOnly) { |
|
1187
|
|
|
foreach ($xmlSheet->colBreaks->brk as $brk) { |
|
1188
|
|
|
if ($brk["man"]) { |
|
1189
|
|
|
$docSheet->setBreak(PHPExcel_Cell::stringFromColumnIndex($brk["id"]) . "1", PHPExcel_Worksheet::BREAK_COLUMN); |
|
1190
|
|
|
} |
|
1191
|
|
|
} |
|
1192
|
|
|
} |
|
1193
|
|
|
|
|
1194
|
|
|
if ($xmlSheet && $xmlSheet->dataValidations && !$this->_readDataOnly) { |
|
1195
|
|
|
foreach ($xmlSheet->dataValidations->dataValidation as $dataValidation) { |
|
1196
|
|
|
// Uppercase coordinate |
|
1197
|
|
|
$range = strtoupper($dataValidation["sqref"]); |
|
1198
|
|
|
$rangeSet = explode(' ',$range); |
|
1199
|
|
|
foreach($rangeSet as $range) { |
|
1200
|
|
|
$stRange = $docSheet->shrinkRangeToFit($range); |
|
1201
|
|
|
|
|
1202
|
|
|
// Extract all cell references in $range |
|
1203
|
|
|
$aReferences = PHPExcel_Cell::extractAllCellReferencesInRange($stRange); |
|
1204
|
|
|
foreach ($aReferences as $reference) { |
|
1205
|
|
|
// Create validation |
|
1206
|
|
|
$docValidation = $docSheet->getCell($reference)->getDataValidation(); |
|
1207
|
|
|
$docValidation->setType((string) $dataValidation["type"]); |
|
1208
|
|
|
$docValidation->setErrorStyle((string) $dataValidation["errorStyle"]); |
|
1209
|
|
|
$docValidation->setOperator((string) $dataValidation["operator"]); |
|
1210
|
|
|
$docValidation->setAllowBlank($dataValidation["allowBlank"] != 0); |
|
1211
|
|
|
$docValidation->setShowDropDown($dataValidation["showDropDown"] == 0); |
|
1212
|
|
|
$docValidation->setShowInputMessage($dataValidation["showInputMessage"] != 0); |
|
1213
|
|
|
$docValidation->setShowErrorMessage($dataValidation["showErrorMessage"] != 0); |
|
1214
|
|
|
$docValidation->setErrorTitle((string) $dataValidation["errorTitle"]); |
|
1215
|
|
|
$docValidation->setError((string) $dataValidation["error"]); |
|
1216
|
|
|
$docValidation->setPromptTitle((string) $dataValidation["promptTitle"]); |
|
1217
|
|
|
$docValidation->setPrompt((string) $dataValidation["prompt"]); |
|
1218
|
|
|
$docValidation->setFormula1((string) $dataValidation->formula1); |
|
1219
|
|
|
$docValidation->setFormula2((string) $dataValidation->formula2); |
|
1220
|
|
|
} |
|
1221
|
|
|
} |
|
1222
|
|
|
} |
|
1223
|
|
|
} |
|
1224
|
|
|
|
|
1225
|
|
|
// Add hyperlinks |
|
1226
|
|
|
$hyperlinks = array(); |
|
1227
|
|
|
if (!$this->_readDataOnly) { |
|
1228
|
|
|
// Locate hyperlink relations |
|
1229
|
|
|
if ($zip->locateName(dirname("$dir/$fileWorksheet") . "/_rels/" . basename($fileWorksheet) . ".rels")) { |
|
1230
|
|
|
$relsWorksheet = simplexml_load_string($this->_getFromZipArchive($zip, dirname("$dir/$fileWorksheet") . "/_rels/" . basename($fileWorksheet) . ".rels") ); //~ http://schemas.openxmlformats.org/package/2006/relationships"); |
|
1231
|
|
|
foreach ($relsWorksheet->Relationship as $ele) { |
|
1232
|
|
|
if ($ele["Type"] == "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink") { |
|
1233
|
|
|
$hyperlinks[(string)$ele["Id"]] = (string)$ele["Target"]; |
|
1234
|
|
|
} |
|
1235
|
|
|
} |
|
1236
|
|
|
} |
|
1237
|
|
|
|
|
1238
|
|
|
// Loop through hyperlinks |
|
1239
|
|
|
if ($xmlSheet && $xmlSheet->hyperlinks) { |
|
1240
|
|
|
foreach ($xmlSheet->hyperlinks->hyperlink as $hyperlink) { |
|
1241
|
|
|
// Link url |
|
1242
|
|
|
$linkRel = $hyperlink->attributes('http://schemas.openxmlformats.org/officeDocument/2006/relationships'); |
|
1243
|
|
|
|
|
1244
|
|
|
foreach (PHPExcel_Cell::extractAllCellReferencesInRange($hyperlink['ref']) as $cellReference) { |
|
1245
|
|
|
$cell = $docSheet->getCell( $cellReference ); |
|
1246
|
|
|
if (isset($linkRel['id'])) { |
|
1247
|
|
|
$cell->getHyperlink()->setUrl( $hyperlinks[ (string)$linkRel['id'] ] ); |
|
1248
|
|
|
} |
|
1249
|
|
|
if (isset($hyperlink['location'])) { |
|
1250
|
|
|
$cell->getHyperlink()->setUrl( 'sheet://' . (string)$hyperlink['location'] ); |
|
1251
|
|
|
} |
|
1252
|
|
|
|
|
1253
|
|
|
// Tooltip |
|
1254
|
|
|
if (isset($hyperlink['tooltip'])) { |
|
1255
|
|
|
$cell->getHyperlink()->setTooltip( (string)$hyperlink['tooltip'] ); |
|
1256
|
|
|
} |
|
1257
|
|
|
} |
|
1258
|
|
|
} |
|
1259
|
|
|
} |
|
1260
|
|
|
} |
|
1261
|
|
|
|
|
1262
|
|
|
// Add comments |
|
1263
|
|
|
$comments = array(); |
|
1264
|
|
|
$vmlComments = array(); |
|
1265
|
|
|
if (!$this->_readDataOnly) { |
|
1266
|
|
|
// Locate comment relations |
|
1267
|
|
|
if ($zip->locateName(dirname("$dir/$fileWorksheet") . "/_rels/" . basename($fileWorksheet) . ".rels")) { |
|
1268
|
|
|
$relsWorksheet = simplexml_load_string($this->_getFromZipArchive($zip, dirname("$dir/$fileWorksheet") . "/_rels/" . basename($fileWorksheet) . ".rels") ); //~ http://schemas.openxmlformats.org/package/2006/relationships"); |
|
1269
|
|
|
foreach ($relsWorksheet->Relationship as $ele) { |
|
1270
|
|
|
if ($ele["Type"] == "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments") { |
|
1271
|
|
|
$comments[(string)$ele["Id"]] = (string)$ele["Target"]; |
|
1272
|
|
|
} |
|
1273
|
|
|
if ($ele["Type"] == "http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing") { |
|
1274
|
|
|
$vmlComments[(string)$ele["Id"]] = (string)$ele["Target"]; |
|
1275
|
|
|
} |
|
1276
|
|
|
} |
|
1277
|
|
|
} |
|
1278
|
|
|
|
|
1279
|
|
|
// Loop through comments |
|
1280
|
|
|
foreach ($comments as $relName => $relPath) { |
|
1281
|
|
|
// Load comments file |
|
1282
|
|
|
$relPath = PHPExcel_Shared_File::realpath(dirname("$dir/$fileWorksheet") . "/" . $relPath); |
|
1283
|
|
|
$commentsFile = simplexml_load_string($this->_getFromZipArchive($zip, $relPath) ); |
|
1284
|
|
|
|
|
1285
|
|
|
// Utility variables |
|
1286
|
|
|
$authors = array(); |
|
1287
|
|
|
|
|
1288
|
|
|
// Loop through authors |
|
1289
|
|
|
foreach ($commentsFile->authors->author as $author) { |
|
1290
|
|
|
$authors[] = (string)$author; |
|
1291
|
|
|
} |
|
1292
|
|
|
|
|
1293
|
|
|
// Loop through contents |
|
1294
|
|
|
foreach ($commentsFile->commentList->comment as $comment) { |
|
1295
|
|
|
$docSheet->getComment( (string)$comment['ref'] )->setAuthor( $authors[(string)$comment['authorId']] ); |
|
1296
|
|
|
$docSheet->getComment( (string)$comment['ref'] )->setText( $this->_parseRichText($comment->text) ); |
|
1297
|
|
|
} |
|
1298
|
|
|
} |
|
1299
|
|
|
|
|
1300
|
|
|
// Loop through VML comments |
|
1301
|
|
|
foreach ($vmlComments as $relName => $relPath) { |
|
1302
|
|
|
// Load VML comments file |
|
1303
|
|
|
$relPath = PHPExcel_Shared_File::realpath(dirname("$dir/$fileWorksheet") . "/" . $relPath); |
|
1304
|
|
|
$vmlCommentsFile = simplexml_load_string( $this->_getFromZipArchive($zip, $relPath) ); |
|
1305
|
|
|
$vmlCommentsFile->registerXPathNamespace('v', 'urn:schemas-microsoft-com:vml'); |
|
1306
|
|
|
|
|
1307
|
|
|
$shapes = $vmlCommentsFile->xpath('//v:shape'); |
|
1308
|
|
|
foreach ($shapes as $shape) { |
|
1309
|
|
|
$shape->registerXPathNamespace('v', 'urn:schemas-microsoft-com:vml'); |
|
1310
|
|
|
|
|
1311
|
|
|
if (isset($shape['style'])) { |
|
1312
|
|
|
$style = (string)$shape['style']; |
|
1313
|
|
|
$fillColor = strtoupper( substr( (string)$shape['fillcolor'], 1 ) ); |
|
1314
|
|
|
$column = null; |
|
1315
|
|
|
$row = null; |
|
1316
|
|
|
|
|
1317
|
|
|
$clientData = $shape->xpath('.//x:ClientData'); |
|
1318
|
|
|
if (is_array($clientData) && !empty($clientData)) { |
|
1319
|
|
|
$clientData = $clientData[0]; |
|
1320
|
|
|
|
|
1321
|
|
|
if ( isset($clientData['ObjectType']) && (string)$clientData['ObjectType'] == 'Note' ) { |
|
1322
|
|
|
$temp = $clientData->xpath('.//x:Row'); |
|
1323
|
|
|
if (is_array($temp)) $row = $temp[0]; |
|
1324
|
|
|
|
|
1325
|
|
|
$temp = $clientData->xpath('.//x:Column'); |
|
1326
|
|
|
if (is_array($temp)) $column = $temp[0]; |
|
1327
|
|
|
} |
|
1328
|
|
|
} |
|
1329
|
|
|
|
|
1330
|
|
|
if (($column !== NULL) && ($row !== NULL)) { |
|
1331
|
|
|
// Set comment properties |
|
1332
|
|
|
$comment = $docSheet->getCommentByColumnAndRow((string) $column, $row + 1); |
|
1333
|
|
|
$comment->getFillColor()->setRGB( $fillColor ); |
|
1334
|
|
|
|
|
1335
|
|
|
// Parse style |
|
1336
|
|
|
$styleArray = explode(';', str_replace(' ', '', $style)); |
|
1337
|
|
|
foreach ($styleArray as $stylePair) { |
|
1338
|
|
|
$stylePair = explode(':', $stylePair); |
|
1339
|
|
|
|
|
1340
|
|
|
if ($stylePair[0] == 'margin-left') $comment->setMarginLeft($stylePair[1]); |
|
1341
|
|
|
if ($stylePair[0] == 'margin-top') $comment->setMarginTop($stylePair[1]); |
|
1342
|
|
|
if ($stylePair[0] == 'width') $comment->setWidth($stylePair[1]); |
|
1343
|
|
|
if ($stylePair[0] == 'height') $comment->setHeight($stylePair[1]); |
|
1344
|
|
|
if ($stylePair[0] == 'visibility') $comment->setVisible( $stylePair[1] == 'visible' ); |
|
1345
|
|
|
|
|
1346
|
|
|
} |
|
1347
|
|
|
} |
|
1348
|
|
|
} |
|
1349
|
|
|
} |
|
1350
|
|
|
} |
|
1351
|
|
|
|
|
1352
|
|
|
// Header/footer images |
|
1353
|
|
|
if ($xmlSheet && $xmlSheet->legacyDrawingHF && !$this->_readDataOnly) { |
|
1354
|
|
|
if ($zip->locateName(dirname("$dir/$fileWorksheet") . "/_rels/" . basename($fileWorksheet) . ".rels")) { |
|
1355
|
|
|
$relsWorksheet = simplexml_load_string($this->_getFromZipArchive($zip, dirname("$dir/$fileWorksheet") . "/_rels/" . basename($fileWorksheet) . ".rels") ); //~ http://schemas.openxmlformats.org/package/2006/relationships"); |
|
1356
|
|
|
$vmlRelationship = ''; |
|
1357
|
|
|
|
|
1358
|
|
|
foreach ($relsWorksheet->Relationship as $ele) { |
|
1359
|
|
|
if ($ele["Type"] == "http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing") { |
|
1360
|
|
|
$vmlRelationship = self::dir_add("$dir/$fileWorksheet", $ele["Target"]); |
|
1361
|
|
|
} |
|
1362
|
|
|
} |
|
1363
|
|
|
|
|
1364
|
|
|
if ($vmlRelationship != '') { |
|
1365
|
|
|
// Fetch linked images |
|
1366
|
|
|
$relsVML = simplexml_load_string($this->_getFromZipArchive($zip, dirname($vmlRelationship) . '/_rels/' . basename($vmlRelationship) . '.rels' )); //~ http://schemas.openxmlformats.org/package/2006/relationships"); |
|
1367
|
|
|
$drawings = array(); |
|
1368
|
|
View Code Duplication |
foreach ($relsVML->Relationship as $ele) { |
|
1369
|
|
|
if ($ele["Type"] == "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image") { |
|
1370
|
|
|
$drawings[(string) $ele["Id"]] = self::dir_add($vmlRelationship, $ele["Target"]); |
|
1371
|
|
|
} |
|
1372
|
|
|
} |
|
1373
|
|
|
|
|
1374
|
|
|
// Fetch VML document |
|
1375
|
|
|
$vmlDrawing = simplexml_load_string($this->_getFromZipArchive($zip, $vmlRelationship)); |
|
1376
|
|
|
$vmlDrawing->registerXPathNamespace('v', 'urn:schemas-microsoft-com:vml'); |
|
1377
|
|
|
|
|
1378
|
|
|
$hfImages = array(); |
|
1379
|
|
|
|
|
1380
|
|
|
$shapes = $vmlDrawing->xpath('//v:shape'); |
|
1381
|
|
|
foreach ($shapes as $shape) { |
|
1382
|
|
|
$shape->registerXPathNamespace('v', 'urn:schemas-microsoft-com:vml'); |
|
1383
|
|
|
$imageData = $shape->xpath('//v:imagedata'); |
|
1384
|
|
|
$imageData = $imageData[0]; |
|
1385
|
|
|
|
|
1386
|
|
|
$imageData = $imageData->attributes('urn:schemas-microsoft-com:office:office'); |
|
1387
|
|
|
$style = self::toCSSArray( (string)$shape['style'] ); |
|
1388
|
|
|
|
|
1389
|
|
|
$hfImages[ (string)$shape['id'] ] = new PHPExcel_Worksheet_HeaderFooterDrawing(); |
|
1390
|
|
|
if (isset($imageData['title'])) { |
|
1391
|
|
|
$hfImages[ (string)$shape['id'] ]->setName( (string)$imageData['title'] ); |
|
1392
|
|
|
} |
|
1393
|
|
|
|
|
1394
|
|
|
$hfImages[ (string)$shape['id'] ]->setPath("zip://$pFilename#" . $drawings[(string)$imageData['relid']], false); |
|
1395
|
|
|
$hfImages[ (string)$shape['id'] ]->setResizeProportional(false); |
|
1396
|
|
|
$hfImages[ (string)$shape['id'] ]->setWidth($style['width']); |
|
1397
|
|
|
$hfImages[ (string)$shape['id'] ]->setHeight($style['height']); |
|
1398
|
|
|
$hfImages[ (string)$shape['id'] ]->setOffsetX($style['margin-left']); |
|
1399
|
|
|
$hfImages[ (string)$shape['id'] ]->setOffsetY($style['margin-top']); |
|
1400
|
|
|
$hfImages[ (string)$shape['id'] ]->setResizeProportional(true); |
|
1401
|
|
|
} |
|
1402
|
|
|
|
|
1403
|
|
|
$docSheet->getHeaderFooter()->setImages($hfImages); |
|
1404
|
|
|
} |
|
1405
|
|
|
} |
|
1406
|
|
|
} |
|
1407
|
|
|
|
|
1408
|
|
|
} |
|
1409
|
|
|
|
|
1410
|
|
|
// TODO: Make sure drawings and graph are loaded differently! |
|
1411
|
|
|
if ($zip->locateName(dirname("$dir/$fileWorksheet") . "/_rels/" . basename($fileWorksheet) . ".rels")) { |
|
1412
|
|
|
$relsWorksheet = simplexml_load_string($this->_getFromZipArchive($zip, dirname("$dir/$fileWorksheet") . "/_rels/" . basename($fileWorksheet) . ".rels") ); //~ http://schemas.openxmlformats.org/package/2006/relationships"); |
|
1413
|
|
|
$drawings = array(); |
|
1414
|
|
View Code Duplication |
foreach ($relsWorksheet->Relationship as $ele) { |
|
1415
|
|
|
if ($ele["Type"] == "http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing") { |
|
1416
|
|
|
$drawings[(string) $ele["Id"]] = self::dir_add("$dir/$fileWorksheet", $ele["Target"]); |
|
1417
|
|
|
} |
|
1418
|
|
|
} |
|
1419
|
|
|
if ($xmlSheet->drawing && !$this->_readDataOnly) { |
|
1420
|
|
|
foreach ($xmlSheet->drawing as $drawing) { |
|
1421
|
|
|
$fileDrawing = $drawings[(string) self::array_item($drawing->attributes("http://schemas.openxmlformats.org/officeDocument/2006/relationships"), "id")]; |
|
1422
|
|
|
$relsDrawing = simplexml_load_string($this->_getFromZipArchive($zip, dirname($fileDrawing) . "/_rels/" . basename($fileDrawing) . ".rels") ); //~ http://schemas.openxmlformats.org/package/2006/relationships"); |
|
1423
|
|
|
$images = array(); |
|
1424
|
|
|
|
|
1425
|
|
|
if ($relsDrawing && $relsDrawing->Relationship) { |
|
1426
|
|
|
foreach ($relsDrawing->Relationship as $ele) { |
|
1427
|
|
|
if ($ele["Type"] == "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image") { |
|
1428
|
|
|
$images[(string) $ele["Id"]] = self::dir_add($fileDrawing, $ele["Target"]); |
|
1429
|
|
|
} elseif ($ele["Type"] == "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart") { |
|
1430
|
|
|
if ($this->_includeCharts) { |
|
1431
|
|
|
$charts[self::dir_add($fileDrawing, $ele["Target"])] = array('id' => (string) $ele["Id"], |
|
1432
|
|
|
'sheet' => $docSheet->getTitle() |
|
1433
|
|
|
); |
|
1434
|
|
|
} |
|
1435
|
|
|
} |
|
1436
|
|
|
} |
|
1437
|
|
|
} |
|
1438
|
|
|
$xmlDrawing = simplexml_load_string($this->_getFromZipArchive($zip, $fileDrawing))->children("http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing"); |
|
1439
|
|
|
|
|
1440
|
|
|
if ($xmlDrawing->oneCellAnchor) { |
|
1441
|
|
|
foreach ($xmlDrawing->oneCellAnchor as $oneCellAnchor) { |
|
1442
|
|
|
if ($oneCellAnchor->pic->blipFill) { |
|
1443
|
|
|
$blip = $oneCellAnchor->pic->blipFill->children("http://schemas.openxmlformats.org/drawingml/2006/main")->blip; |
|
1444
|
|
|
$xfrm = $oneCellAnchor->pic->spPr->children("http://schemas.openxmlformats.org/drawingml/2006/main")->xfrm; |
|
1445
|
|
|
$outerShdw = $oneCellAnchor->pic->spPr->children("http://schemas.openxmlformats.org/drawingml/2006/main")->effectLst->outerShdw; |
|
1446
|
|
|
$objDrawing = new PHPExcel_Worksheet_Drawing; |
|
1447
|
|
|
$objDrawing->setName((string) self::array_item($oneCellAnchor->pic->nvPicPr->cNvPr->attributes(), "name")); |
|
1448
|
|
|
$objDrawing->setDescription((string) self::array_item($oneCellAnchor->pic->nvPicPr->cNvPr->attributes(), "descr")); |
|
1449
|
|
|
$objDrawing->setPath("zip://$pFilename#" . $images[(string) self::array_item($blip->attributes("http://schemas.openxmlformats.org/officeDocument/2006/relationships"), "embed")], false); |
|
1450
|
|
|
$objDrawing->setCoordinates(PHPExcel_Cell::stringFromColumnIndex((string) $oneCellAnchor->from->col) . ($oneCellAnchor->from->row + 1)); |
|
1451
|
|
|
$objDrawing->setOffsetX(PHPExcel_Shared_Drawing::EMUToPixels($oneCellAnchor->from->colOff)); |
|
1452
|
|
|
$objDrawing->setOffsetY(PHPExcel_Shared_Drawing::EMUToPixels($oneCellAnchor->from->rowOff)); |
|
1453
|
|
|
$objDrawing->setResizeProportional(false); |
|
1454
|
|
|
$objDrawing->setWidth(PHPExcel_Shared_Drawing::EMUToPixels(self::array_item($oneCellAnchor->ext->attributes(), "cx"))); |
|
1455
|
|
|
$objDrawing->setHeight(PHPExcel_Shared_Drawing::EMUToPixels(self::array_item($oneCellAnchor->ext->attributes(), "cy"))); |
|
1456
|
|
|
if ($xfrm) { |
|
1457
|
|
|
$objDrawing->setRotation(PHPExcel_Shared_Drawing::angleToDegrees(self::array_item($xfrm->attributes(), "rot"))); |
|
1458
|
|
|
} |
|
1459
|
|
View Code Duplication |
if ($outerShdw) { |
|
1460
|
|
|
$shadow = $objDrawing->getShadow(); |
|
1461
|
|
|
$shadow->setVisible(true); |
|
1462
|
|
|
$shadow->setBlurRadius(PHPExcel_Shared_Drawing::EMUTopixels(self::array_item($outerShdw->attributes(), "blurRad"))); |
|
1463
|
|
|
$shadow->setDistance(PHPExcel_Shared_Drawing::EMUTopixels(self::array_item($outerShdw->attributes(), "dist"))); |
|
1464
|
|
|
$shadow->setDirection(PHPExcel_Shared_Drawing::angleToDegrees(self::array_item($outerShdw->attributes(), "dir"))); |
|
1465
|
|
|
$shadow->setAlignment((string) self::array_item($outerShdw->attributes(), "algn")); |
|
1466
|
|
|
$shadow->getColor()->setRGB(self::array_item($outerShdw->srgbClr->attributes(), "val")); |
|
1467
|
|
|
$shadow->setAlpha(self::array_item($outerShdw->srgbClr->alpha->attributes(), "val") / 1000); |
|
1468
|
|
|
} |
|
1469
|
|
|
$objDrawing->setWorksheet($docSheet); |
|
1470
|
|
|
} else { |
|
1471
|
|
|
$coordinates = PHPExcel_Cell::stringFromColumnIndex((string) $oneCellAnchor->from->col) . ($oneCellAnchor->from->row + 1); |
|
1472
|
|
|
$offsetX = PHPExcel_Shared_Drawing::EMUToPixels($oneCellAnchor->from->colOff); |
|
1473
|
|
|
$offsetY = PHPExcel_Shared_Drawing::EMUToPixels($oneCellAnchor->from->rowOff); |
|
1474
|
|
|
$width = PHPExcel_Shared_Drawing::EMUToPixels(self::array_item($oneCellAnchor->ext->attributes(), "cx")); |
|
1475
|
|
|
$height = PHPExcel_Shared_Drawing::EMUToPixels(self::array_item($oneCellAnchor->ext->attributes(), "cy")); |
|
1476
|
|
|
} |
|
1477
|
|
|
} |
|
1478
|
|
|
} |
|
1479
|
|
|
if ($xmlDrawing->twoCellAnchor) { |
|
1480
|
|
|
foreach ($xmlDrawing->twoCellAnchor as $twoCellAnchor) { |
|
1481
|
|
|
if ($twoCellAnchor->pic->blipFill) { |
|
1482
|
|
|
$blip = $twoCellAnchor->pic->blipFill->children("http://schemas.openxmlformats.org/drawingml/2006/main")->blip; |
|
1483
|
|
|
$xfrm = $twoCellAnchor->pic->spPr->children("http://schemas.openxmlformats.org/drawingml/2006/main")->xfrm; |
|
1484
|
|
|
$outerShdw = $twoCellAnchor->pic->spPr->children("http://schemas.openxmlformats.org/drawingml/2006/main")->effectLst->outerShdw; |
|
1485
|
|
|
$objDrawing = new PHPExcel_Worksheet_Drawing; |
|
1486
|
|
|
$objDrawing->setName((string) self::array_item($twoCellAnchor->pic->nvPicPr->cNvPr->attributes(), "name")); |
|
1487
|
|
|
$objDrawing->setDescription((string) self::array_item($twoCellAnchor->pic->nvPicPr->cNvPr->attributes(), "descr")); |
|
1488
|
|
|
$objDrawing->setPath("zip://$pFilename#" . $images[(string) self::array_item($blip->attributes("http://schemas.openxmlformats.org/officeDocument/2006/relationships"), "embed")], false); |
|
1489
|
|
|
$objDrawing->setCoordinates(PHPExcel_Cell::stringFromColumnIndex((string) $twoCellAnchor->from->col) . ($twoCellAnchor->from->row + 1)); |
|
1490
|
|
|
$objDrawing->setOffsetX(PHPExcel_Shared_Drawing::EMUToPixels($twoCellAnchor->from->colOff)); |
|
1491
|
|
|
$objDrawing->setOffsetY(PHPExcel_Shared_Drawing::EMUToPixels($twoCellAnchor->from->rowOff)); |
|
1492
|
|
|
$objDrawing->setResizeProportional(false); |
|
1493
|
|
|
|
|
1494
|
|
|
$objDrawing->setWidth(PHPExcel_Shared_Drawing::EMUToPixels(self::array_item($xfrm->ext->attributes(), "cx"))); |
|
1495
|
|
|
$objDrawing->setHeight(PHPExcel_Shared_Drawing::EMUToPixels(self::array_item($xfrm->ext->attributes(), "cy"))); |
|
1496
|
|
|
|
|
1497
|
|
|
if ($xfrm) { |
|
1498
|
|
|
$objDrawing->setRotation(PHPExcel_Shared_Drawing::angleToDegrees(self::array_item($xfrm->attributes(), "rot"))); |
|
1499
|
|
|
} |
|
1500
|
|
View Code Duplication |
if ($outerShdw) { |
|
1501
|
|
|
$shadow = $objDrawing->getShadow(); |
|
1502
|
|
|
$shadow->setVisible(true); |
|
1503
|
|
|
$shadow->setBlurRadius(PHPExcel_Shared_Drawing::EMUTopixels(self::array_item($outerShdw->attributes(), "blurRad"))); |
|
1504
|
|
|
$shadow->setDistance(PHPExcel_Shared_Drawing::EMUTopixels(self::array_item($outerShdw->attributes(), "dist"))); |
|
1505
|
|
|
$shadow->setDirection(PHPExcel_Shared_Drawing::angleToDegrees(self::array_item($outerShdw->attributes(), "dir"))); |
|
1506
|
|
|
$shadow->setAlignment((string) self::array_item($outerShdw->attributes(), "algn")); |
|
1507
|
|
|
$shadow->getColor()->setRGB(self::array_item($outerShdw->srgbClr->attributes(), "val")); |
|
1508
|
|
|
$shadow->setAlpha(self::array_item($outerShdw->srgbClr->alpha->attributes(), "val") / 1000); |
|
1509
|
|
|
} |
|
1510
|
|
|
$objDrawing->setWorksheet($docSheet); |
|
1511
|
|
|
} elseif($this->_includeCharts) { |
|
1512
|
|
|
$fromCoordinate = PHPExcel_Cell::stringFromColumnIndex((string) $twoCellAnchor->from->col) . ($twoCellAnchor->from->row + 1); |
|
1513
|
|
|
$fromOffsetX = PHPExcel_Shared_Drawing::EMUToPixels($twoCellAnchor->from->colOff); |
|
1514
|
|
|
$fromOffsetY = PHPExcel_Shared_Drawing::EMUToPixels($twoCellAnchor->from->rowOff); |
|
1515
|
|
|
$toCoordinate = PHPExcel_Cell::stringFromColumnIndex((string) $twoCellAnchor->to->col) . ($twoCellAnchor->to->row + 1); |
|
1516
|
|
|
$toOffsetX = PHPExcel_Shared_Drawing::EMUToPixels($twoCellAnchor->to->colOff); |
|
1517
|
|
|
$toOffsetY = PHPExcel_Shared_Drawing::EMUToPixels($twoCellAnchor->to->rowOff); |
|
1518
|
|
|
$graphic = $twoCellAnchor->graphicFrame->children("http://schemas.openxmlformats.org/drawingml/2006/main")->graphic; |
|
1519
|
|
|
$chartRef = $graphic->graphicData->children("http://schemas.openxmlformats.org/drawingml/2006/chart")->chart; |
|
1520
|
|
|
$thisChart = (string) $chartRef->attributes("http://schemas.openxmlformats.org/officeDocument/2006/relationships"); |
|
1521
|
|
|
|
|
1522
|
|
|
$chartDetails[$docSheet->getTitle().'!'.$thisChart] = |
|
1523
|
|
|
array( 'fromCoordinate' => $fromCoordinate, |
|
1524
|
|
|
'fromOffsetX' => $fromOffsetX, |
|
1525
|
|
|
'fromOffsetY' => $fromOffsetY, |
|
1526
|
|
|
'toCoordinate' => $toCoordinate, |
|
1527
|
|
|
'toOffsetX' => $toOffsetX, |
|
1528
|
|
|
'toOffsetY' => $toOffsetY, |
|
1529
|
|
|
'worksheetTitle' => $docSheet->getTitle() |
|
1530
|
|
|
); |
|
1531
|
|
|
} |
|
1532
|
|
|
} |
|
1533
|
|
|
} |
|
1534
|
|
|
|
|
1535
|
|
|
} |
|
1536
|
|
|
} |
|
1537
|
|
|
} |
|
1538
|
|
|
|
|
1539
|
|
|
// Loop through definedNames |
|
1540
|
|
|
if ($xmlWorkbook->definedNames) { |
|
1541
|
|
|
foreach ($xmlWorkbook->definedNames->definedName as $definedName) { |
|
1542
|
|
|
// Extract range |
|
1543
|
|
|
$extractedRange = (string)$definedName; |
|
1544
|
|
|
$extractedRange = preg_replace('/\'(\w+)\'\!/', '', $extractedRange); |
|
1545
|
|
|
if (($spos = strpos($extractedRange,'!')) !== false) { |
|
1546
|
|
|
$extractedRange = substr($extractedRange,0,$spos).str_replace('$', '', substr($extractedRange,$spos)); |
|
1547
|
|
|
} else { |
|
1548
|
|
|
$extractedRange = str_replace('$', '', $extractedRange); |
|
1549
|
|
|
} |
|
1550
|
|
|
|
|
1551
|
|
|
// Valid range? |
|
1552
|
|
|
if (stripos((string)$definedName, '#REF!') !== false || $extractedRange == '') { |
|
1553
|
|
|
continue; |
|
1554
|
|
|
} |
|
1555
|
|
|
|
|
1556
|
|
|
// Some definedNames are only applicable if we are on the same sheet... |
|
1557
|
|
|
if ((string)$definedName['localSheetId'] != '' && (string)$definedName['localSheetId'] == $sheetId) { |
|
1558
|
|
|
// Switch on type |
|
1559
|
|
|
switch ((string)$definedName['name']) { |
|
1560
|
|
|
|
|
1561
|
|
|
case '_xlnm._FilterDatabase': |
|
1562
|
|
|
$docSheet->setAutoFilter($extractedRange); |
|
1563
|
|
|
break; |
|
1564
|
|
|
|
|
1565
|
|
|
case '_xlnm.Print_Titles': |
|
1566
|
|
|
// Split $extractedRange |
|
1567
|
|
|
$extractedRange = explode(',', $extractedRange); |
|
1568
|
|
|
|
|
1569
|
|
|
// Set print titles |
|
1570
|
|
|
foreach ($extractedRange as $range) { |
|
1571
|
|
|
$matches = array(); |
|
1572
|
|
|
|
|
1573
|
|
|
// check for repeating columns, e g. 'A:A' or 'A:D' |
|
1574
|
|
|
if (preg_match('/^([A-Z]+)\:([A-Z]+)$/', $range, $matches)) { |
|
1575
|
|
|
$docSheet->getPageSetup()->setColumnsToRepeatAtLeft(array($matches[1], $matches[2])); |
|
1576
|
|
|
} |
|
1577
|
|
|
// check for repeating rows, e.g. '1:1' or '1:5' |
|
1578
|
|
|
elseif (preg_match('/^(\d+)\:(\d+)$/', $range, $matches)) { |
|
1579
|
|
|
$docSheet->getPageSetup()->setRowsToRepeatAtTop(array($matches[1], $matches[2])); |
|
1580
|
|
|
} |
|
1581
|
|
|
} |
|
1582
|
|
|
break; |
|
1583
|
|
|
|
|
1584
|
|
|
case '_xlnm.Print_Area': |
|
1585
|
|
|
$rangeSets = explode(',', $extractedRange); // FIXME: what if sheetname contains comma? |
|
1586
|
|
|
$newRangeSets = array(); |
|
1587
|
|
|
foreach($rangeSets as $rangeSet) { |
|
1588
|
|
|
$range = explode('!', $rangeSet); // FIXME: what if sheetname contains exclamation mark? |
|
1589
|
|
|
$rangeSet = isset($range[1]) ? $range[1] : $range[0]; |
|
1590
|
|
|
$newRangeSets[] = str_replace('$', '', $rangeSet); |
|
1591
|
|
|
} |
|
1592
|
|
|
$docSheet->getPageSetup()->setPrintArea(implode(',',$newRangeSets)); |
|
1593
|
|
|
break; |
|
1594
|
|
|
|
|
1595
|
|
|
default: |
|
1596
|
|
|
break; |
|
1597
|
|
|
} |
|
1598
|
|
|
} |
|
1599
|
|
|
} |
|
1600
|
|
|
} |
|
1601
|
|
|
|
|
1602
|
|
|
// Next sheet id |
|
1603
|
|
|
++$sheetId; |
|
1604
|
|
|
} |
|
1605
|
|
|
|
|
1606
|
|
|
// Loop through definedNames |
|
1607
|
|
|
if ($xmlWorkbook->definedNames) { |
|
1608
|
|
|
foreach ($xmlWorkbook->definedNames->definedName as $definedName) { |
|
1609
|
|
|
// Extract range |
|
1610
|
|
|
$extractedRange = (string)$definedName; |
|
1611
|
|
|
$extractedRange = preg_replace('/\'(\w+)\'\!/', '', $extractedRange); |
|
1612
|
|
|
if (($spos = strpos($extractedRange,'!')) !== false) { |
|
1613
|
|
|
$extractedRange = substr($extractedRange,0,$spos).str_replace('$', '', substr($extractedRange,$spos)); |
|
1614
|
|
|
} else { |
|
1615
|
|
|
$extractedRange = str_replace('$', '', $extractedRange); |
|
1616
|
|
|
} |
|
1617
|
|
|
|
|
1618
|
|
|
// Valid range? |
|
1619
|
|
|
if (stripos((string)$definedName, '#REF!') !== false || $extractedRange == '') { |
|
1620
|
|
|
continue; |
|
1621
|
|
|
} |
|
1622
|
|
|
|
|
1623
|
|
|
// Some definedNames are only applicable if we are on the same sheet... |
|
1624
|
|
|
if ((string)$definedName['localSheetId'] != '') { |
|
1625
|
|
|
// Local defined name |
|
1626
|
|
|
// Switch on type |
|
1627
|
|
|
switch ((string)$definedName['name']) { |
|
1628
|
|
|
|
|
1629
|
|
|
case '_xlnm._FilterDatabase': |
|
1630
|
|
|
case '_xlnm.Print_Titles': |
|
1631
|
|
|
case '_xlnm.Print_Area': |
|
1632
|
|
|
break; |
|
1633
|
|
|
|
|
1634
|
|
|
default: |
|
1635
|
|
|
$range = explode('!', (string)$definedName); |
|
1636
|
|
|
if (count($range) == 2) { |
|
1637
|
|
|
$range[0] = str_replace("''", "'", $range[0]); |
|
1638
|
|
|
$range[0] = str_replace("'", "", $range[0]); |
|
1639
|
|
|
if ($worksheet = $docSheet->getParent()->getSheetByName($range[0])) { |
|
1640
|
|
|
$extractedRange = str_replace('$', '', $range[1]); |
|
1641
|
|
|
$scope = $docSheet->getParent()->getSheet((string)$definedName['localSheetId']); |
|
|
|
|
|
|
1642
|
|
|
|
|
1643
|
|
|
$excel->addNamedRange( new PHPExcel_NamedRange((string)$definedName['name'], $worksheet, $extractedRange, true, $scope) ); |
|
1644
|
|
|
} |
|
1645
|
|
|
} |
|
1646
|
|
|
break; |
|
1647
|
|
|
} |
|
1648
|
|
|
} else if (!isset($definedName['localSheetId'])) { |
|
1649
|
|
|
// "Global" definedNames |
|
1650
|
|
|
$locatedSheet = null; |
|
1651
|
|
|
$extractedSheetName = ''; |
|
1652
|
|
|
if (strpos( (string)$definedName, '!' ) !== false) { |
|
1653
|
|
|
// Extract sheet name |
|
1654
|
|
|
$extractedSheetName = PHPExcel_Worksheet::extractSheetTitle( (string)$definedName, true ); |
|
1655
|
|
|
$extractedSheetName = $extractedSheetName[0]; |
|
1656
|
|
|
|
|
1657
|
|
|
// Locate sheet |
|
1658
|
|
|
$locatedSheet = $excel->getSheetByName($extractedSheetName); |
|
1659
|
|
|
|
|
1660
|
|
|
// Modify range |
|
1661
|
|
|
$range = explode('!', $extractedRange); |
|
1662
|
|
|
$extractedRange = isset($range[1]) ? $range[1] : $range[0]; |
|
1663
|
|
|
} |
|
1664
|
|
|
|
|
1665
|
|
|
if ($locatedSheet !== NULL) { |
|
1666
|
|
|
$excel->addNamedRange( new PHPExcel_NamedRange((string)$definedName['name'], $locatedSheet, $extractedRange, false) ); |
|
1667
|
|
|
} |
|
1668
|
|
|
} |
|
1669
|
|
|
} |
|
1670
|
|
|
} |
|
1671
|
|
|
} |
|
1672
|
|
|
|
|
1673
|
|
|
if (!$this->_readDataOnly) { |
|
1674
|
|
|
// active sheet index |
|
1675
|
|
|
$activeTab = intval($xmlWorkbook->bookViews->workbookView["activeTab"]); // refers to old sheet index |
|
1676
|
|
|
|
|
1677
|
|
|
// keep active sheet index if sheet is still loaded, else first sheet is set as the active |
|
1678
|
|
|
if (isset($mapSheetId[$activeTab]) && $mapSheetId[$activeTab] !== null) { |
|
1679
|
|
|
$excel->setActiveSheetIndex($mapSheetId[$activeTab]); |
|
1680
|
|
|
} else { |
|
1681
|
|
|
if ($excel->getSheetCount() == 0) { |
|
1682
|
|
|
$excel->createSheet(); |
|
1683
|
|
|
} |
|
1684
|
|
|
$excel->setActiveSheetIndex(0); |
|
1685
|
|
|
} |
|
1686
|
|
|
} |
|
1687
|
|
|
break; |
|
1688
|
|
|
} |
|
1689
|
|
|
|
|
1690
|
|
|
} |
|
1691
|
|
|
|
|
1692
|
|
|
|
|
1693
|
|
|
if (!$this->_readDataOnly) { |
|
1694
|
|
|
$contentTypes = simplexml_load_string($this->_getFromZipArchive($zip, "[Content_Types].xml")); |
|
1695
|
|
|
foreach ($contentTypes->Override as $contentType) { |
|
1696
|
|
|
switch ($contentType["ContentType"]) { |
|
1697
|
|
|
case "application/vnd.openxmlformats-officedocument.drawingml.chart+xml": |
|
1698
|
|
|
if ($this->_includeCharts) { |
|
1699
|
|
|
$chartEntryRef = ltrim($contentType['PartName'],'/'); |
|
1700
|
|
|
$chartElements = simplexml_load_string($this->_getFromZipArchive($zip, $chartEntryRef)); |
|
1701
|
|
|
$objChart = PHPExcel_Reader_Excel2007_Chart::readChart($chartElements,basename($chartEntryRef,'.xml')); |
|
1702
|
|
|
|
|
1703
|
|
|
// echo 'Chart ',$chartEntryRef,'<br />'; |
|
1704
|
|
|
// var_dump($charts[$chartEntryRef]); |
|
1705
|
|
|
// |
|
1706
|
|
|
if (isset($charts[$chartEntryRef])) { |
|
1707
|
|
|
$chartPositionRef = $charts[$chartEntryRef]['sheet'].'!'.$charts[$chartEntryRef]['id']; |
|
1708
|
|
|
// echo 'Position Ref ',$chartPositionRef,'<br />'; |
|
1709
|
|
|
if (isset($chartDetails[$chartPositionRef])) { |
|
1710
|
|
|
// var_dump($chartDetails[$chartPositionRef]); |
|
1711
|
|
|
|
|
1712
|
|
|
$excel->getSheetByName($charts[$chartEntryRef]['sheet'])->addChart($objChart); |
|
1713
|
|
|
$objChart->setWorksheet($excel->getSheetByName($charts[$chartEntryRef]['sheet'])); |
|
1714
|
|
|
$objChart->setTopLeftPosition( $chartDetails[$chartPositionRef]['fromCoordinate'], |
|
1715
|
|
|
$chartDetails[$chartPositionRef]['fromOffsetX'], |
|
1716
|
|
|
$chartDetails[$chartPositionRef]['fromOffsetY'] |
|
1717
|
|
|
); |
|
1718
|
|
|
$objChart->setBottomRightPosition( $chartDetails[$chartPositionRef]['toCoordinate'], |
|
1719
|
|
|
$chartDetails[$chartPositionRef]['toOffsetX'], |
|
1720
|
|
|
$chartDetails[$chartPositionRef]['toOffsetY'] |
|
1721
|
|
|
); |
|
1722
|
|
|
} |
|
1723
|
|
|
} |
|
1724
|
|
|
} |
|
1725
|
|
|
} |
|
1726
|
|
|
} |
|
1727
|
|
|
} |
|
1728
|
|
|
|
|
1729
|
|
|
$zip->close(); |
|
1730
|
|
|
|
|
1731
|
|
|
return $excel; |
|
1732
|
|
|
} |
|
1733
|
|
|
|
|
1734
|
|
|
|
|
1735
|
|
|
private static function _readColor($color, $background=false) { |
|
1736
|
|
|
if (isset($color["rgb"])) { |
|
1737
|
|
|
return (string)$color["rgb"]; |
|
1738
|
|
|
} else if (isset($color["indexed"])) { |
|
1739
|
|
|
return PHPExcel_Style_Color::indexedColor($color["indexed"]-7,$background)->getARGB(); |
|
1740
|
|
|
} else if (isset($color["theme"])) { |
|
1741
|
|
|
if (self::$_theme !== NULL) { |
|
1742
|
|
|
$returnColour = self::$_theme->getColourByIndex((int)$color["theme"]); |
|
1743
|
|
|
if (isset($color["tint"])) { |
|
1744
|
|
|
$tintAdjust = (float) $color["tint"]; |
|
1745
|
|
|
$returnColour = PHPExcel_Style_Color::changeBrightness($returnColour, $tintAdjust); |
|
1746
|
|
|
} |
|
1747
|
|
|
return 'FF'.$returnColour; |
|
1748
|
|
|
} |
|
1749
|
|
|
} |
|
1750
|
|
|
|
|
1751
|
|
|
if ($background) { |
|
1752
|
|
|
return 'FFFFFFFF'; |
|
1753
|
|
|
} |
|
1754
|
|
|
return 'FF000000'; |
|
1755
|
|
|
} |
|
1756
|
|
|
|
|
1757
|
|
|
|
|
1758
|
|
|
private static function _readStyle($docStyle, $style) { |
|
1759
|
|
|
// format code |
|
1760
|
|
|
if (isset($style->numFmt)) { |
|
1761
|
|
|
$docStyle->getNumberFormat()->setFormatCode($style->numFmt); |
|
1762
|
|
|
} |
|
1763
|
|
|
|
|
1764
|
|
|
// font |
|
1765
|
|
|
if (isset($style->font)) { |
|
1766
|
|
|
$docStyle->getFont()->setName((string) $style->font->name["val"]); |
|
1767
|
|
|
$docStyle->getFont()->setSize((string) $style->font->sz["val"]); |
|
1768
|
|
View Code Duplication |
if (isset($style->font->b)) { |
|
1769
|
|
|
$docStyle->getFont()->setBold(!isset($style->font->b["val"]) || $style->font->b["val"] == 'true' || $style->font->b["val"] == '1'); |
|
1770
|
|
|
} |
|
1771
|
|
View Code Duplication |
if (isset($style->font->i)) { |
|
1772
|
|
|
$docStyle->getFont()->setItalic(!isset($style->font->i["val"]) || $style->font->i["val"] == 'true' || $style->font->i["val"] == '1'); |
|
1773
|
|
|
} |
|
1774
|
|
View Code Duplication |
if (isset($style->font->strike)) { |
|
1775
|
|
|
$docStyle->getFont()->setStrikethrough(!isset($style->font->strike["val"]) || $style->font->strike["val"] == 'true' || $style->font->strike["val"] == '1'); |
|
1776
|
|
|
} |
|
1777
|
|
|
$docStyle->getFont()->getColor()->setARGB(self::_readColor($style->font->color)); |
|
1778
|
|
|
|
|
1779
|
|
View Code Duplication |
if (isset($style->font->u) && !isset($style->font->u["val"])) { |
|
1780
|
|
|
$docStyle->getFont()->setUnderline(PHPExcel_Style_Font::UNDERLINE_SINGLE); |
|
1781
|
|
|
} else if (isset($style->font->u) && isset($style->font->u["val"])) { |
|
1782
|
|
|
$docStyle->getFont()->setUnderline((string)$style->font->u["val"]); |
|
1783
|
|
|
} |
|
1784
|
|
|
|
|
1785
|
|
View Code Duplication |
if (isset($style->font->vertAlign) && isset($style->font->vertAlign["val"])) { |
|
1786
|
|
|
$vertAlign = strtolower((string)$style->font->vertAlign["val"]); |
|
1787
|
|
|
if ($vertAlign == 'superscript') { |
|
1788
|
|
|
$docStyle->getFont()->setSuperScript(true); |
|
1789
|
|
|
} |
|
1790
|
|
|
if ($vertAlign == 'subscript') { |
|
1791
|
|
|
$docStyle->getFont()->setSubScript(true); |
|
1792
|
|
|
} |
|
1793
|
|
|
} |
|
1794
|
|
|
} |
|
1795
|
|
|
|
|
1796
|
|
|
// fill |
|
1797
|
|
|
if (isset($style->fill)) { |
|
1798
|
|
|
if ($style->fill->gradientFill) { |
|
1799
|
|
|
$gradientFill = $style->fill->gradientFill[0]; |
|
1800
|
|
|
if(!empty($gradientFill["type"])) { |
|
1801
|
|
|
$docStyle->getFill()->setFillType((string) $gradientFill["type"]); |
|
1802
|
|
|
} |
|
1803
|
|
|
$docStyle->getFill()->setRotation(floatval($gradientFill["degree"])); |
|
1804
|
|
|
$gradientFill->registerXPathNamespace("sml", "http://schemas.openxmlformats.org/spreadsheetml/2006/main"); |
|
1805
|
|
|
$docStyle->getFill()->getStartColor()->setARGB(self::_readColor( self::array_item($gradientFill->xpath("sml:stop[@position=0]"))->color) ); |
|
1806
|
|
|
$docStyle->getFill()->getEndColor()->setARGB(self::_readColor( self::array_item($gradientFill->xpath("sml:stop[@position=1]"))->color) ); |
|
1807
|
|
|
} elseif ($style->fill->patternFill) { |
|
1808
|
|
|
$patternType = (string)$style->fill->patternFill["patternType"] != '' ? (string)$style->fill->patternFill["patternType"] : 'solid'; |
|
1809
|
|
|
$docStyle->getFill()->setFillType($patternType); |
|
1810
|
|
|
if ($style->fill->patternFill->fgColor) { |
|
1811
|
|
|
$docStyle->getFill()->getStartColor()->setARGB(self::_readColor($style->fill->patternFill->fgColor,true)); |
|
1812
|
|
|
} else { |
|
1813
|
|
|
$docStyle->getFill()->getStartColor()->setARGB('FF000000'); |
|
1814
|
|
|
} |
|
1815
|
|
|
if ($style->fill->patternFill->bgColor) { |
|
1816
|
|
|
$docStyle->getFill()->getEndColor()->setARGB(self::_readColor($style->fill->patternFill->bgColor,true)); |
|
1817
|
|
|
} |
|
1818
|
|
|
} |
|
1819
|
|
|
} |
|
1820
|
|
|
|
|
1821
|
|
|
// border |
|
1822
|
|
|
if (isset($style->border)) { |
|
1823
|
|
|
$diagonalUp = false; |
|
1824
|
|
|
$diagonalDown = false; |
|
1825
|
|
|
if ($style->border["diagonalUp"] == 'true' || $style->border["diagonalUp"] == 1) { |
|
1826
|
|
|
$diagonalUp = true; |
|
1827
|
|
|
} |
|
1828
|
|
|
if ($style->border["diagonalDown"] == 'true' || $style->border["diagonalDown"] == 1) { |
|
1829
|
|
|
$diagonalDown = true; |
|
1830
|
|
|
} |
|
1831
|
|
View Code Duplication |
if ($diagonalUp == false && $diagonalDown == false) { |
|
|
|
|
|
|
1832
|
|
|
$docStyle->getBorders()->setDiagonalDirection(PHPExcel_Style_Borders::DIAGONAL_NONE); |
|
1833
|
|
|
} elseif ($diagonalUp == true && $diagonalDown == false) { |
|
|
|
|
|
|
1834
|
|
|
$docStyle->getBorders()->setDiagonalDirection(PHPExcel_Style_Borders::DIAGONAL_UP); |
|
1835
|
|
|
} elseif ($diagonalUp == false && $diagonalDown == true) { |
|
|
|
|
|
|
1836
|
|
|
$docStyle->getBorders()->setDiagonalDirection(PHPExcel_Style_Borders::DIAGONAL_DOWN); |
|
1837
|
|
|
} elseif ($diagonalUp == true && $diagonalDown == true) { |
|
|
|
|
|
|
1838
|
|
|
$docStyle->getBorders()->setDiagonalDirection(PHPExcel_Style_Borders::DIAGONAL_BOTH); |
|
1839
|
|
|
} |
|
1840
|
|
|
self::_readBorder($docStyle->getBorders()->getLeft(), $style->border->left); |
|
1841
|
|
|
self::_readBorder($docStyle->getBorders()->getRight(), $style->border->right); |
|
1842
|
|
|
self::_readBorder($docStyle->getBorders()->getTop(), $style->border->top); |
|
1843
|
|
|
self::_readBorder($docStyle->getBorders()->getBottom(), $style->border->bottom); |
|
1844
|
|
|
self::_readBorder($docStyle->getBorders()->getDiagonal(), $style->border->diagonal); |
|
1845
|
|
|
} |
|
1846
|
|
|
|
|
1847
|
|
|
// alignment |
|
1848
|
|
|
if (isset($style->alignment)) { |
|
1849
|
|
|
$docStyle->getAlignment()->setHorizontal((string) $style->alignment["horizontal"]); |
|
1850
|
|
|
$docStyle->getAlignment()->setVertical((string) $style->alignment["vertical"]); |
|
1851
|
|
|
|
|
1852
|
|
|
$textRotation = 0; |
|
1853
|
|
|
if ((int)$style->alignment["textRotation"] <= 90) { |
|
1854
|
|
|
$textRotation = (int)$style->alignment["textRotation"]; |
|
1855
|
|
|
} else if ((int)$style->alignment["textRotation"] > 90) { |
|
1856
|
|
|
$textRotation = 90 - (int)$style->alignment["textRotation"]; |
|
1857
|
|
|
} |
|
1858
|
|
|
|
|
1859
|
|
|
$docStyle->getAlignment()->setTextRotation(intval($textRotation)); |
|
1860
|
|
|
$docStyle->getAlignment()->setWrapText( (string)$style->alignment["wrapText"] == "true" || (string)$style->alignment["wrapText"] == "1" ); |
|
1861
|
|
|
$docStyle->getAlignment()->setShrinkToFit( (string)$style->alignment["shrinkToFit"] == "true" || (string)$style->alignment["shrinkToFit"] == "1" ); |
|
1862
|
|
|
$docStyle->getAlignment()->setIndent( intval((string)$style->alignment["indent"]) > 0 ? intval((string)$style->alignment["indent"]) : 0 ); |
|
1863
|
|
|
} |
|
1864
|
|
|
|
|
1865
|
|
|
// protection |
|
1866
|
|
|
if (isset($style->protection)) { |
|
1867
|
|
|
if (isset($style->protection['locked'])) { |
|
1868
|
|
|
if ((string)$style->protection['locked'] == 'true') { |
|
1869
|
|
|
$docStyle->getProtection()->setLocked(PHPExcel_Style_Protection::PROTECTION_PROTECTED); |
|
1870
|
|
|
} else { |
|
1871
|
|
|
$docStyle->getProtection()->setLocked(PHPExcel_Style_Protection::PROTECTION_UNPROTECTED); |
|
1872
|
|
|
} |
|
1873
|
|
|
} |
|
1874
|
|
|
|
|
1875
|
|
|
if (isset($style->protection['hidden'])) { |
|
1876
|
|
|
if ((string)$style->protection['hidden'] == 'true') { |
|
1877
|
|
|
$docStyle->getProtection()->setHidden(PHPExcel_Style_Protection::PROTECTION_PROTECTED); |
|
1878
|
|
|
} else { |
|
1879
|
|
|
$docStyle->getProtection()->setHidden(PHPExcel_Style_Protection::PROTECTION_UNPROTECTED); |
|
1880
|
|
|
} |
|
1881
|
|
|
} |
|
1882
|
|
|
} |
|
1883
|
|
|
} |
|
1884
|
|
|
|
|
1885
|
|
|
|
|
1886
|
|
|
private static function _readBorder($docBorder, $eleBorder) { |
|
1887
|
|
|
if (isset($eleBorder["style"])) { |
|
1888
|
|
|
$docBorder->setBorderStyle((string) $eleBorder["style"]); |
|
1889
|
|
|
} |
|
1890
|
|
|
if (isset($eleBorder->color)) { |
|
1891
|
|
|
$docBorder->getColor()->setARGB(self::_readColor($eleBorder->color)); |
|
1892
|
|
|
} |
|
1893
|
|
|
} |
|
1894
|
|
|
|
|
1895
|
|
|
|
|
1896
|
|
|
private function _parseRichText($is = null) { |
|
1897
|
|
|
$value = new PHPExcel_RichText(); |
|
1898
|
|
|
|
|
1899
|
|
|
if (isset($is->t)) { |
|
1900
|
|
|
$value->createText( PHPExcel_Shared_String::ControlCharacterOOXML2PHP( (string) $is->t ) ); |
|
1901
|
|
|
} else { |
|
1902
|
|
|
foreach ($is->r as $run) { |
|
1903
|
|
|
if (!isset($run->rPr)) { |
|
1904
|
|
|
$objText = $value->createText( PHPExcel_Shared_String::ControlCharacterOOXML2PHP( (string) $run->t ) ); |
|
1905
|
|
|
|
|
1906
|
|
|
} else { |
|
1907
|
|
|
$objText = $value->createTextRun( PHPExcel_Shared_String::ControlCharacterOOXML2PHP( (string) $run->t ) ); |
|
1908
|
|
|
|
|
1909
|
|
View Code Duplication |
if (isset($run->rPr->rFont["val"])) { |
|
1910
|
|
|
$objText->getFont()->setName((string) $run->rPr->rFont["val"]); |
|
1911
|
|
|
} |
|
1912
|
|
|
|
|
1913
|
|
|
if (isset($run->rPr->sz["val"])) { |
|
1914
|
|
|
$objText->getFont()->setSize((string) $run->rPr->sz["val"]); |
|
1915
|
|
|
} |
|
1916
|
|
|
|
|
1917
|
|
|
if (isset($run->rPr->color)) { |
|
1918
|
|
|
$objText->getFont()->setColor( new PHPExcel_Style_Color( self::_readColor($run->rPr->color) ) ); |
|
1919
|
|
|
} |
|
1920
|
|
|
|
|
1921
|
|
View Code Duplication |
if ( (isset($run->rPr->b["val"]) && ((string) $run->rPr->b["val"] == 'true' || (string) $run->rPr->b["val"] == '1')) |
|
1922
|
|
|
|| (isset($run->rPr->b) && !isset($run->rPr->b["val"])) ) { |
|
1923
|
|
|
$objText->getFont()->setBold(true); |
|
1924
|
|
|
} |
|
1925
|
|
|
|
|
1926
|
|
View Code Duplication |
if ( (isset($run->rPr->i["val"]) && ((string) $run->rPr->i["val"] == 'true' || (string) $run->rPr->i["val"] == '1')) |
|
1927
|
|
|
|| (isset($run->rPr->i) && !isset($run->rPr->i["val"])) ) { |
|
1928
|
|
|
$objText->getFont()->setItalic(true); |
|
1929
|
|
|
} |
|
1930
|
|
|
|
|
1931
|
|
View Code Duplication |
if (isset($run->rPr->vertAlign) && isset($run->rPr->vertAlign["val"])) { |
|
1932
|
|
|
$vertAlign = strtolower((string)$run->rPr->vertAlign["val"]); |
|
1933
|
|
|
if ($vertAlign == 'superscript') { |
|
1934
|
|
|
$objText->getFont()->setSuperScript(true); |
|
1935
|
|
|
} |
|
1936
|
|
|
if ($vertAlign == 'subscript') { |
|
1937
|
|
|
$objText->getFont()->setSubScript(true); |
|
1938
|
|
|
} |
|
1939
|
|
|
} |
|
1940
|
|
|
|
|
1941
|
|
View Code Duplication |
if (isset($run->rPr->u) && !isset($run->rPr->u["val"])) { |
|
1942
|
|
|
$objText->getFont()->setUnderline(PHPExcel_Style_Font::UNDERLINE_SINGLE); |
|
1943
|
|
|
} else if (isset($run->rPr->u) && isset($run->rPr->u["val"])) { |
|
1944
|
|
|
$objText->getFont()->setUnderline((string)$run->rPr->u["val"]); |
|
1945
|
|
|
} |
|
1946
|
|
|
|
|
1947
|
|
View Code Duplication |
if ( (isset($run->rPr->strike["val"]) && ((string) $run->rPr->strike["val"] == 'true' || (string) $run->rPr->strike["val"] == '1')) |
|
1948
|
|
|
|| (isset($run->rPr->strike) && !isset($run->rPr->strike["val"])) ) { |
|
1949
|
|
|
$objText->getFont()->setStrikethrough(true); |
|
1950
|
|
|
} |
|
1951
|
|
|
} |
|
1952
|
|
|
} |
|
1953
|
|
|
} |
|
1954
|
|
|
|
|
1955
|
|
|
return $value; |
|
1956
|
|
|
} |
|
1957
|
|
|
|
|
1958
|
|
|
|
|
1959
|
|
|
private static function array_item($array, $key = 0) { |
|
1960
|
|
|
return (isset($array[$key]) ? $array[$key] : null); |
|
1961
|
|
|
} |
|
1962
|
|
|
|
|
1963
|
|
|
|
|
1964
|
|
|
private static function dir_add($base, $add) { |
|
1965
|
|
|
return preg_replace('~[^/]+/\.\./~', '', dirname($base) . "/$add"); |
|
1966
|
|
|
} |
|
1967
|
|
|
|
|
1968
|
|
|
|
|
1969
|
|
|
private static function toCSSArray($style) { |
|
1970
|
|
|
$style = str_replace(array("\r","\n"), "", $style); |
|
1971
|
|
|
|
|
1972
|
|
|
$temp = explode(';', $style); |
|
1973
|
|
|
$style = array(); |
|
1974
|
|
|
foreach ($temp as $item) { |
|
1975
|
|
|
$item = explode(':', $item); |
|
1976
|
|
|
|
|
1977
|
|
|
if (strpos($item[1], 'px') !== false) { |
|
1978
|
|
|
$item[1] = str_replace('px', '', $item[1]); |
|
1979
|
|
|
} |
|
1980
|
|
View Code Duplication |
if (strpos($item[1], 'pt') !== false) { |
|
1981
|
|
|
$item[1] = str_replace('pt', '', $item[1]); |
|
1982
|
|
|
$item[1] = PHPExcel_Shared_Font::fontSizeToPixels($item[1]); |
|
1983
|
|
|
} |
|
1984
|
|
View Code Duplication |
if (strpos($item[1], 'in') !== false) { |
|
1985
|
|
|
$item[1] = str_replace('in', '', $item[1]); |
|
1986
|
|
|
$item[1] = PHPExcel_Shared_Font::inchSizeToPixels($item[1]); |
|
1987
|
|
|
} |
|
1988
|
|
View Code Duplication |
if (strpos($item[1], 'cm') !== false) { |
|
1989
|
|
|
$item[1] = str_replace('cm', '', $item[1]); |
|
1990
|
|
|
$item[1] = PHPExcel_Shared_Font::centimeterSizeToPixels($item[1]); |
|
1991
|
|
|
} |
|
1992
|
|
|
|
|
1993
|
|
|
$style[$item[0]] = $item[1]; |
|
1994
|
|
|
} |
|
1995
|
|
|
|
|
1996
|
|
|
return $style; |
|
1997
|
|
|
} |
|
1998
|
|
|
} |
|
1999
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..