Subversion Repositories eFlore/Applications.cel

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2390 jpm 1
<?php
2
/**
3
 * PHPExcel
4
 *
5
 * Copyright (c) 2006 - 2013 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_Writer_Excel2007
23
 * @copyright  Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
24
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt	LGPL
25
 * @version    ##VERSION##, ##DATE##
26
 */
27
 
28
 
29
/**
30
 * PHPExcel_Writer_Excel2007_Style
31
 *
32
 * @category   PHPExcel
33
 * @package    PHPExcel_Writer_Excel2007
34
 * @copyright  Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
35
 */
36
class PHPExcel_Writer_Excel2007_Style extends PHPExcel_Writer_Excel2007_WriterPart
37
{
38
	/**
39
	 * Write styles to XML format
40
	 *
41
	 * @param 	PHPExcel	$pPHPExcel
42
	 * @return 	string 		XML Output
43
	 * @throws 	PHPExcel_Writer_Exception
44
	 */
45
	public function writeStyles(PHPExcel $pPHPExcel = null)
46
	{
47
		// Create XML writer
48
		$objWriter = null;
49
		if ($this->getParentWriter()->getUseDiskCaching()) {
50
			$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
51
		} else {
52
			$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY);
53
		}
54
 
55
		// XML header
56
		$objWriter->startDocument('1.0','UTF-8','yes');
57
 
58
		// styleSheet
59
		$objWriter->startElement('styleSheet');
60
		$objWriter->writeAttribute('xml:space', 'preserve');
61
		$objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/spreadsheetml/2006/main');
62
 
63
			// numFmts
64
			$objWriter->startElement('numFmts');
65
			$objWriter->writeAttribute('count', $this->getParentWriter()->getNumFmtHashTable()->count());
66
 
67
				// numFmt
68
				for ($i = 0; $i < $this->getParentWriter()->getNumFmtHashTable()->count(); ++$i) {
69
					$this->_writeNumFmt($objWriter, $this->getParentWriter()->getNumFmtHashTable()->getByIndex($i), $i);
70
				}
71
 
72
			$objWriter->endElement();
73
 
74
			// fonts
75
			$objWriter->startElement('fonts');
76
			$objWriter->writeAttribute('count', $this->getParentWriter()->getFontHashTable()->count());
77
 
78
				// font
79
				for ($i = 0; $i < $this->getParentWriter()->getFontHashTable()->count(); ++$i) {
80
					$this->_writeFont($objWriter, $this->getParentWriter()->getFontHashTable()->getByIndex($i));
81
				}
82
 
83
			$objWriter->endElement();
84
 
85
			// fills
86
			$objWriter->startElement('fills');
87
			$objWriter->writeAttribute('count', $this->getParentWriter()->getFillHashTable()->count());
88
 
89
				// fill
90
				for ($i = 0; $i < $this->getParentWriter()->getFillHashTable()->count(); ++$i) {
91
					$this->_writeFill($objWriter, $this->getParentWriter()->getFillHashTable()->getByIndex($i));
92
				}
93
 
94
			$objWriter->endElement();
95
 
96
			// borders
97
			$objWriter->startElement('borders');
98
			$objWriter->writeAttribute('count', $this->getParentWriter()->getBordersHashTable()->count());
99
 
100
				// border
101
				for ($i = 0; $i < $this->getParentWriter()->getBordersHashTable()->count(); ++$i) {
102
					$this->_writeBorder($objWriter, $this->getParentWriter()->getBordersHashTable()->getByIndex($i));
103
				}
104
 
105
			$objWriter->endElement();
106
 
107
			// cellStyleXfs
108
			$objWriter->startElement('cellStyleXfs');
109
			$objWriter->writeAttribute('count', 1);
110
 
111
				// xf
112
				$objWriter->startElement('xf');
113
					$objWriter->writeAttribute('numFmtId', 	0);
114
					$objWriter->writeAttribute('fontId', 	0);
115
					$objWriter->writeAttribute('fillId', 	0);
116
					$objWriter->writeAttribute('borderId',	0);
117
				$objWriter->endElement();
118
 
119
			$objWriter->endElement();
120
 
121
			// cellXfs
122
			$objWriter->startElement('cellXfs');
123
			$objWriter->writeAttribute('count', count($pPHPExcel->getCellXfCollection()));
124
 
125
				// xf
126
				foreach ($pPHPExcel->getCellXfCollection() as $cellXf) {
127
					$this->_writeCellStyleXf($objWriter, $cellXf, $pPHPExcel);
128
				}
129
 
130
			$objWriter->endElement();
131
 
132
			// cellStyles
133
			$objWriter->startElement('cellStyles');
134
			$objWriter->writeAttribute('count', 1);
135
 
136
				// cellStyle
137
				$objWriter->startElement('cellStyle');
138
					$objWriter->writeAttribute('name', 		'Normal');
139
					$objWriter->writeAttribute('xfId', 		0);
140
					$objWriter->writeAttribute('builtinId',	0);
141
				$objWriter->endElement();
142
 
143
			$objWriter->endElement();
144
 
145
			// dxfs
146
			$objWriter->startElement('dxfs');
147
			$objWriter->writeAttribute('count', $this->getParentWriter()->getStylesConditionalHashTable()->count());
148
 
149
				// dxf
150
				for ($i = 0; $i < $this->getParentWriter()->getStylesConditionalHashTable()->count(); ++$i) {
151
					$this->_writeCellStyleDxf($objWriter, $this->getParentWriter()->getStylesConditionalHashTable()->getByIndex($i)->getStyle());
152
				}
153
 
154
			$objWriter->endElement();
155
 
156
			// tableStyles
157
			$objWriter->startElement('tableStyles');
158
			$objWriter->writeAttribute('defaultTableStyle', 'TableStyleMedium9');
159
			$objWriter->writeAttribute('defaultPivotStyle', 'PivotTableStyle1');
160
			$objWriter->endElement();
161
 
162
		$objWriter->endElement();
163
 
164
		// Return
165
		return $objWriter->getData();
166
	}
167
 
168
	/**
169
	 * Write Fill
170
	 *
171
	 * @param 	PHPExcel_Shared_XMLWriter 	$objWriter 		XML Writer
172
	 * @param 	PHPExcel_Style_Fill			$pFill			Fill style
173
	 * @throws 	PHPExcel_Writer_Exception
174
	 */
175
	private function _writeFill(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Style_Fill $pFill = null)
176
	{
177
		// Check if this is a pattern type or gradient type
178
		if ($pFill->getFillType() === PHPExcel_Style_Fill::FILL_GRADIENT_LINEAR ||
179
			$pFill->getFillType() === PHPExcel_Style_Fill::FILL_GRADIENT_PATH) {
180
			// Gradient fill
181
			$this->_writeGradientFill($objWriter, $pFill);
182
		} elseif($pFill->getFillType() !== NULL) {
183
			// Pattern fill
184
			$this->_writePatternFill($objWriter, $pFill);
185
		}
186
	}
187
 
188
	/**
189
	 * Write Gradient Fill
190
	 *
191
	 * @param 	PHPExcel_Shared_XMLWriter 	$objWriter 		XML Writer
192
	 * @param 	PHPExcel_Style_Fill			$pFill			Fill style
193
	 * @throws 	PHPExcel_Writer_Exception
194
	 */
195
	private function _writeGradientFill(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Style_Fill $pFill = null)
196
	{
197
		// fill
198
		$objWriter->startElement('fill');
199
 
200
			// gradientFill
201
			$objWriter->startElement('gradientFill');
202
				$objWriter->writeAttribute('type', 		$pFill->getFillType());
203
				$objWriter->writeAttribute('degree', 	$pFill->getRotation());
204
 
205
				// stop
206
				$objWriter->startElement('stop');
207
				$objWriter->writeAttribute('position', '0');
208
 
209
					// color
210
					$objWriter->startElement('color');
211
					$objWriter->writeAttribute('rgb', $pFill->getStartColor()->getARGB());
212
					$objWriter->endElement();
213
 
214
				$objWriter->endElement();
215
 
216
				// stop
217
				$objWriter->startElement('stop');
218
				$objWriter->writeAttribute('position', '1');
219
 
220
					// color
221
					$objWriter->startElement('color');
222
					$objWriter->writeAttribute('rgb', $pFill->getEndColor()->getARGB());
223
					$objWriter->endElement();
224
 
225
				$objWriter->endElement();
226
 
227
			$objWriter->endElement();
228
 
229
		$objWriter->endElement();
230
	}
231
 
232
	/**
233
	 * Write Pattern Fill
234
	 *
235
	 * @param 	PHPExcel_Shared_XMLWriter			$objWriter 		XML Writer
236
	 * @param 	PHPExcel_Style_Fill					$pFill			Fill style
237
	 * @throws 	PHPExcel_Writer_Exception
238
	 */
239
	private function _writePatternFill(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Style_Fill $pFill = null)
240
	{
241
		// fill
242
		$objWriter->startElement('fill');
243
 
244
			// patternFill
245
			$objWriter->startElement('patternFill');
246
				$objWriter->writeAttribute('patternType', $pFill->getFillType());
247
 
248
				if ($pFill->getFillType() !== PHPExcel_Style_Fill::FILL_NONE) {
249
					// fgColor
250
					if ($pFill->getStartColor()->getARGB()) {
251
						$objWriter->startElement('fgColor');
252
						$objWriter->writeAttribute('rgb', $pFill->getStartColor()->getARGB());
253
						$objWriter->endElement();
254
					}
255
				}
256
				if ($pFill->getFillType() !== PHPExcel_Style_Fill::FILL_NONE) {
257
					// bgColor
258
					if ($pFill->getEndColor()->getARGB()) {
259
						$objWriter->startElement('bgColor');
260
						$objWriter->writeAttribute('rgb', $pFill->getEndColor()->getARGB());
261
						$objWriter->endElement();
262
					}
263
				}
264
 
265
			$objWriter->endElement();
266
 
267
		$objWriter->endElement();
268
	}
269
 
270
	/**
271
	 * Write Font
272
	 *
273
	 * @param 	PHPExcel_Shared_XMLWriter		$objWriter 		XML Writer
274
	 * @param 	PHPExcel_Style_Font				$pFont			Font style
275
	 * @throws 	PHPExcel_Writer_Exception
276
	 */
277
	private function _writeFont(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Style_Font $pFont = null)
278
	{
279
		// font
280
		$objWriter->startElement('font');
281
			//	Weird! The order of these elements actually makes a difference when opening Excel2007
282
			//		files in Excel2003 with the compatibility pack. It's not documented behaviour,
283
			//		and makes for a real WTF!
284
 
285
			// Bold. We explicitly write this element also when false (like MS Office Excel 2007 does
286
			// for conditional formatting). Otherwise it will apparently not be picked up in conditional
287
			// formatting style dialog
288
			if ($pFont->getBold() !== NULL) {
289
				$objWriter->startElement('b');
290
					$objWriter->writeAttribute('val', $pFont->getBold() ? '1' : '0');
291
				$objWriter->endElement();
292
			}
293
 
294
			// Italic
295
			if ($pFont->getItalic() !== NULL) {
296
				$objWriter->startElement('i');
297
					$objWriter->writeAttribute('val', $pFont->getItalic() ? '1' : '0');
298
				$objWriter->endElement();
299
			}
300
 
301
			// Strikethrough
302
			if ($pFont->getStrikethrough() !== NULL) {
303
				$objWriter->startElement('strike');
304
				$objWriter->writeAttribute('val', $pFont->getStrikethrough() ? '1' : '0');
305
				$objWriter->endElement();
306
			}
307
 
308
			// Underline
309
			if ($pFont->getUnderline() !== NULL) {
310
				$objWriter->startElement('u');
311
				$objWriter->writeAttribute('val', $pFont->getUnderline());
312
				$objWriter->endElement();
313
			}
314
 
315
			// Superscript / subscript
316
			if ($pFont->getSuperScript() === TRUE || $pFont->getSubScript() === TRUE) {
317
				$objWriter->startElement('vertAlign');
318
				if ($pFont->getSuperScript() === TRUE) {
319
					$objWriter->writeAttribute('val', 'superscript');
320
				} else if ($pFont->getSubScript() === TRUE) {
321
					$objWriter->writeAttribute('val', 'subscript');
322
				}
323
				$objWriter->endElement();
324
			}
325
 
326
			// Size
327
			if ($pFont->getSize() !== NULL) {
328
				$objWriter->startElement('sz');
329
					$objWriter->writeAttribute('val', $pFont->getSize());
330
				$objWriter->endElement();
331
			}
332
 
333
			// Foreground color
334
			if ($pFont->getColor()->getARGB() !== NULL) {
335
				$objWriter->startElement('color');
336
				$objWriter->writeAttribute('rgb', $pFont->getColor()->getARGB());
337
				$objWriter->endElement();
338
			}
339
 
340
			// Name
341
			if ($pFont->getName() !== NULL) {
342
				$objWriter->startElement('name');
343
					$objWriter->writeAttribute('val', $pFont->getName());
344
				$objWriter->endElement();
345
			}
346
 
347
		$objWriter->endElement();
348
	}
349
 
350
	/**
351
	 * Write Border
352
	 *
353
	 * @param 	PHPExcel_Shared_XMLWriter			$objWriter 		XML Writer
354
	 * @param 	PHPExcel_Style_Borders				$pBorders		Borders style
355
	 * @throws 	PHPExcel_Writer_Exception
356
	 */
357
	private function _writeBorder(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Style_Borders $pBorders = null)
358
	{
359
		// Write border
360
		$objWriter->startElement('border');
361
			// Diagonal?
362
			switch ($pBorders->getDiagonalDirection()) {
363
				case PHPExcel_Style_Borders::DIAGONAL_UP:
364
					$objWriter->writeAttribute('diagonalUp', 	'true');
365
					$objWriter->writeAttribute('diagonalDown', 	'false');
366
					break;
367
				case PHPExcel_Style_Borders::DIAGONAL_DOWN:
368
					$objWriter->writeAttribute('diagonalUp', 	'false');
369
					$objWriter->writeAttribute('diagonalDown', 	'true');
370
					break;
371
				case PHPExcel_Style_Borders::DIAGONAL_BOTH:
372
					$objWriter->writeAttribute('diagonalUp', 	'true');
373
					$objWriter->writeAttribute('diagonalDown', 	'true');
374
					break;
375
			}
376
 
377
			// BorderPr
378
			$this->_writeBorderPr($objWriter, 'left',		$pBorders->getLeft());
379
			$this->_writeBorderPr($objWriter, 'right',		$pBorders->getRight());
380
			$this->_writeBorderPr($objWriter, 'top',		$pBorders->getTop());
381
			$this->_writeBorderPr($objWriter, 'bottom',		$pBorders->getBottom());
382
			$this->_writeBorderPr($objWriter, 'diagonal',	$pBorders->getDiagonal());
383
		$objWriter->endElement();
384
	}
385
 
386
	/**
387
	 * Write Cell Style Xf
388
	 *
389
	 * @param 	PHPExcel_Shared_XMLWriter			$objWriter 		XML Writer
390
	 * @param 	PHPExcel_Style						$pStyle			Style
391
	 * @param 	PHPExcel							$pPHPExcel		Workbook
392
	 * @throws 	PHPExcel_Writer_Exception
393
	 */
394
	private function _writeCellStyleXf(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Style $pStyle = null, PHPExcel $pPHPExcel = null)
395
	{
396
		// xf
397
		$objWriter->startElement('xf');
398
			$objWriter->writeAttribute('xfId', 0);
399
			$objWriter->writeAttribute('fontId', 			(int)$this->getParentWriter()->getFontHashTable()->getIndexForHashCode($pStyle->getFont()->getHashCode()));
400
 
401
			if ($pStyle->getNumberFormat()->getBuiltInFormatCode() === false) {
402
				$objWriter->writeAttribute('numFmtId', 			(int)($this->getParentWriter()->getNumFmtHashTable()->getIndexForHashCode($pStyle->getNumberFormat()->getHashCode()) + 164)   );
403
			} else {
404
				$objWriter->writeAttribute('numFmtId', 			(int)$pStyle->getNumberFormat()->getBuiltInFormatCode());
405
			}
406
 
407
			$objWriter->writeAttribute('fillId', 			(int)$this->getParentWriter()->getFillHashTable()->getIndexForHashCode($pStyle->getFill()->getHashCode()));
408
			$objWriter->writeAttribute('borderId', 			(int)$this->getParentWriter()->getBordersHashTable()->getIndexForHashCode($pStyle->getBorders()->getHashCode()));
409
 
410
			// Apply styles?
411
			$objWriter->writeAttribute('applyFont', 		($pPHPExcel->getDefaultStyle()->getFont()->getHashCode() != $pStyle->getFont()->getHashCode()) ? '1' : '0');
412
			$objWriter->writeAttribute('applyNumberFormat', ($pPHPExcel->getDefaultStyle()->getNumberFormat()->getHashCode() != $pStyle->getNumberFormat()->getHashCode()) ? '1' : '0');
413
			$objWriter->writeAttribute('applyFill', 		($pPHPExcel->getDefaultStyle()->getFill()->getHashCode() != $pStyle->getFill()->getHashCode()) ? '1' : '0');
414
			$objWriter->writeAttribute('applyBorder', 		($pPHPExcel->getDefaultStyle()->getBorders()->getHashCode() != $pStyle->getBorders()->getHashCode()) ? '1' : '0');
415
			$objWriter->writeAttribute('applyAlignment',	($pPHPExcel->getDefaultStyle()->getAlignment()->getHashCode() != $pStyle->getAlignment()->getHashCode()) ? '1' : '0');
416
			if ($pStyle->getProtection()->getLocked() != PHPExcel_Style_Protection::PROTECTION_INHERIT || $pStyle->getProtection()->getHidden() != PHPExcel_Style_Protection::PROTECTION_INHERIT) {
417
				$objWriter->writeAttribute('applyProtection', 'true');
418
			}
419
 
420
			// alignment
421
			$objWriter->startElement('alignment');
422
				$objWriter->writeAttribute('horizontal', 	$pStyle->getAlignment()->getHorizontal());
423
				$objWriter->writeAttribute('vertical', 		$pStyle->getAlignment()->getVertical());
424
 
425
				$textRotation = 0;
426
				if ($pStyle->getAlignment()->getTextRotation() >= 0) {
427
					$textRotation = $pStyle->getAlignment()->getTextRotation();
428
				} else if ($pStyle->getAlignment()->getTextRotation() < 0) {
429
					$textRotation = 90 - $pStyle->getAlignment()->getTextRotation();
430
				}
431
				$objWriter->writeAttribute('textRotation', 	$textRotation);
432
 
433
				$objWriter->writeAttribute('wrapText', 		($pStyle->getAlignment()->getWrapText() ? 'true' : 'false'));
434
				$objWriter->writeAttribute('shrinkToFit', 	($pStyle->getAlignment()->getShrinkToFit() ? 'true' : 'false'));
435
 
436
				if ($pStyle->getAlignment()->getIndent() > 0) {
437
					$objWriter->writeAttribute('indent', 	$pStyle->getAlignment()->getIndent());
438
				}
439
			$objWriter->endElement();
440
 
441
			// protection
442
			if ($pStyle->getProtection()->getLocked() != PHPExcel_Style_Protection::PROTECTION_INHERIT || $pStyle->getProtection()->getHidden() != PHPExcel_Style_Protection::PROTECTION_INHERIT) {
443
				$objWriter->startElement('protection');
444
					if ($pStyle->getProtection()->getLocked() != PHPExcel_Style_Protection::PROTECTION_INHERIT) {
445
						$objWriter->writeAttribute('locked', 		($pStyle->getProtection()->getLocked() == PHPExcel_Style_Protection::PROTECTION_PROTECTED ? 'true' : 'false'));
446
					}
447
					if ($pStyle->getProtection()->getHidden() != PHPExcel_Style_Protection::PROTECTION_INHERIT) {
448
						$objWriter->writeAttribute('hidden', 		($pStyle->getProtection()->getHidden() == PHPExcel_Style_Protection::PROTECTION_PROTECTED ? 'true' : 'false'));
449
					}
450
				$objWriter->endElement();
451
			}
452
 
453
		$objWriter->endElement();
454
	}
455
 
456
	/**
457
	 * Write Cell Style Dxf
458
	 *
459
	 * @param 	PHPExcel_Shared_XMLWriter 		$objWriter 		XML Writer
460
	 * @param 	PHPExcel_Style					$pStyle			Style
461
	 * @throws 	PHPExcel_Writer_Exception
462
	 */
463
	private function _writeCellStyleDxf(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Style $pStyle = null)
464
	{
465
		// dxf
466
		$objWriter->startElement('dxf');
467
 
468
			// font
469
			$this->_writeFont($objWriter, $pStyle->getFont());
470
 
471
			// numFmt
472
			$this->_writeNumFmt($objWriter, $pStyle->getNumberFormat());
473
 
474
			// fill
475
			$this->_writeFill($objWriter, $pStyle->getFill());
476
 
477
			// alignment
478
			$objWriter->startElement('alignment');
479
				if ($pStyle->getAlignment()->getHorizontal() !== NULL) {
480
					$objWriter->writeAttribute('horizontal', $pStyle->getAlignment()->getHorizontal());
481
				}
482
				if ($pStyle->getAlignment()->getVertical() !== NULL) {
483
					$objWriter->writeAttribute('vertical', $pStyle->getAlignment()->getVertical());
484
				}
485
 
486
				if ($pStyle->getAlignment()->getTextRotation() !== NULL) {
487
					$textRotation = 0;
488
					if ($pStyle->getAlignment()->getTextRotation() >= 0) {
489
						$textRotation = $pStyle->getAlignment()->getTextRotation();
490
					} else if ($pStyle->getAlignment()->getTextRotation() < 0) {
491
						$textRotation = 90 - $pStyle->getAlignment()->getTextRotation();
492
					}
493
					$objWriter->writeAttribute('textRotation', 	$textRotation);
494
				}
495
			$objWriter->endElement();
496
 
497
			// border
498
			$this->_writeBorder($objWriter, $pStyle->getBorders());
499
 
500
			// protection
501
			if (($pStyle->getProtection()->getLocked() !== NULL) ||
502
				($pStyle->getProtection()->getHidden() !== NULL)) {
503
				if ($pStyle->getProtection()->getLocked() !== PHPExcel_Style_Protection::PROTECTION_INHERIT ||
504
					$pStyle->getProtection()->getHidden() !== PHPExcel_Style_Protection::PROTECTION_INHERIT) {
505
					$objWriter->startElement('protection');
506
						if (($pStyle->getProtection()->getLocked() !== NULL) &&
507
							($pStyle->getProtection()->getLocked() !== PHPExcel_Style_Protection::PROTECTION_INHERIT)) {
508
							$objWriter->writeAttribute('locked', ($pStyle->getProtection()->getLocked() == PHPExcel_Style_Protection::PROTECTION_PROTECTED ? 'true' : 'false'));
509
						}
510
						if (($pStyle->getProtection()->getHidden() !== NULL) &&
511
							($pStyle->getProtection()->getHidden() !== PHPExcel_Style_Protection::PROTECTION_INHERIT)) {
512
							$objWriter->writeAttribute('hidden', ($pStyle->getProtection()->getHidden() == PHPExcel_Style_Protection::PROTECTION_PROTECTED ? 'true' : 'false'));
513
						}
514
					$objWriter->endElement();
515
				}
516
			}
517
 
518
		$objWriter->endElement();
519
	}
520
 
521
	/**
522
	 * Write BorderPr
523
	 *
524
	 * @param 	PHPExcel_Shared_XMLWriter		$objWriter 		XML Writer
525
	 * @param 	string							$pName			Element name
526
	 * @param 	PHPExcel_Style_Border			$pBorder		Border style
527
	 * @throws 	PHPExcel_Writer_Exception
528
	 */
529
	private function _writeBorderPr(PHPExcel_Shared_XMLWriter $objWriter = null, $pName = 'left', PHPExcel_Style_Border $pBorder = null)
530
	{
531
		// Write BorderPr
532
		if ($pBorder->getBorderStyle() != PHPExcel_Style_Border::BORDER_NONE) {
533
			$objWriter->startElement($pName);
534
			$objWriter->writeAttribute('style', 	$pBorder->getBorderStyle());
535
 
536
				// color
537
				$objWriter->startElement('color');
538
				$objWriter->writeAttribute('rgb', 	$pBorder->getColor()->getARGB());
539
				$objWriter->endElement();
540
 
541
			$objWriter->endElement();
542
		}
543
	}
544
 
545
	/**
546
	 * Write NumberFormat
547
	 *
548
	 * @param 	PHPExcel_Shared_XMLWriter			$objWriter 		XML Writer
549
	 * @param 	PHPExcel_Style_NumberFormat			$pNumberFormat	Number Format
550
	 * @param 	int									$pId			Number Format identifier
551
	 * @throws 	PHPExcel_Writer_Exception
552
	 */
553
	private function _writeNumFmt(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Style_NumberFormat $pNumberFormat = null, $pId = 0)
554
	{
555
		// Translate formatcode
556
		$formatCode = $pNumberFormat->getFormatCode();
557
 
558
		// numFmt
559
		if ($formatCode !== NULL) {
560
			$objWriter->startElement('numFmt');
561
				$objWriter->writeAttribute('numFmtId', ($pId + 164));
562
				$objWriter->writeAttribute('formatCode', $formatCode);
563
			$objWriter->endElement();
564
		}
565
	}
566
 
567
	/**
568
	 * Get an array of all styles
569
	 *
570
	 * @param 	PHPExcel				$pPHPExcel
571
	 * @return 	PHPExcel_Style[]		All styles in PHPExcel
572
	 * @throws 	PHPExcel_Writer_Exception
573
	 */
574
	public function allStyles(PHPExcel $pPHPExcel = null)
575
	{
576
		$aStyles = $pPHPExcel->getCellXfCollection();
577
 
578
		return $aStyles;
579
	}
580
 
581
	/**
582
	 * Get an array of all conditional styles
583
	 *
584
	 * @param 	PHPExcel							$pPHPExcel
585
	 * @return 	PHPExcel_Style_Conditional[]		All conditional styles in PHPExcel
586
	 * @throws 	PHPExcel_Writer_Exception
587
	 */
588
	public function allConditionalStyles(PHPExcel $pPHPExcel = null)
589
	{
590
		// Get an array of all styles
591
		$aStyles		= array();
592
 
593
		$sheetCount = $pPHPExcel->getSheetCount();
594
		for ($i = 0; $i < $sheetCount; ++$i) {
595
			foreach ($pPHPExcel->getSheet($i)->getConditionalStylesCollection() as $conditionalStyles) {
596
				foreach ($conditionalStyles as $conditionalStyle) {
597
					$aStyles[] = $conditionalStyle;
598
				}
599
			}
600
		}
601
 
602
		return $aStyles;
603
	}
604
 
605
	/**
606
	 * Get an array of all fills
607
	 *
608
	 * @param 	PHPExcel						$pPHPExcel
609
	 * @return 	PHPExcel_Style_Fill[]		All fills in PHPExcel
610
	 * @throws 	PHPExcel_Writer_Exception
611
	 */
612
	public function allFills(PHPExcel $pPHPExcel = null)
613
	{
614
		// Get an array of unique fills
615
		$aFills 	= array();
616
 
617
		// Two first fills are predefined
618
		$fill0 = new PHPExcel_Style_Fill();
619
		$fill0->setFillType(PHPExcel_Style_Fill::FILL_NONE);
620
		$aFills[] = $fill0;
621
 
622
		$fill1 = new PHPExcel_Style_Fill();
623
		$fill1->setFillType(PHPExcel_Style_Fill::FILL_PATTERN_GRAY125);
624
		$aFills[] = $fill1;
625
		// The remaining fills
626
		$aStyles 	= $this->allStyles($pPHPExcel);
627
		foreach ($aStyles as $style) {
628
			if (!array_key_exists($style->getFill()->getHashCode(), $aFills)) {
629
				$aFills[ $style->getFill()->getHashCode() ] = $style->getFill();
630
			}
631
		}
632
 
633
		return $aFills;
634
	}
635
 
636
	/**
637
	 * Get an array of all fonts
638
	 *
639
	 * @param 	PHPExcel						$pPHPExcel
640
	 * @return 	PHPExcel_Style_Font[]		All fonts in PHPExcel
641
	 * @throws 	PHPExcel_Writer_Exception
642
	 */
643
	public function allFonts(PHPExcel $pPHPExcel = null)
644
	{
645
		// Get an array of unique fonts
646
		$aFonts 	= array();
647
		$aStyles 	= $this->allStyles($pPHPExcel);
648
 
649
		foreach ($aStyles as $style) {
650
			if (!array_key_exists($style->getFont()->getHashCode(), $aFonts)) {
651
				$aFonts[ $style->getFont()->getHashCode() ] = $style->getFont();
652
			}
653
		}
654
 
655
		return $aFonts;
656
	}
657
 
658
	/**
659
	 * Get an array of all borders
660
	 *
661
	 * @param 	PHPExcel						$pPHPExcel
662
	 * @return 	PHPExcel_Style_Borders[]		All borders in PHPExcel
663
	 * @throws 	PHPExcel_Writer_Exception
664
	 */
665
	public function allBorders(PHPExcel $pPHPExcel = null)
666
	{
667
		// Get an array of unique borders
668
		$aBorders 	= array();
669
		$aStyles 	= $this->allStyles($pPHPExcel);
670
 
671
		foreach ($aStyles as $style) {
672
			if (!array_key_exists($style->getBorders()->getHashCode(), $aBorders)) {
673
				$aBorders[ $style->getBorders()->getHashCode() ] = $style->getBorders();
674
			}
675
		}
676
 
677
		return $aBorders;
678
	}
679
 
680
	/**
681
	 * Get an array of all number formats
682
	 *
683
	 * @param 	PHPExcel								$pPHPExcel
684
	 * @return 	PHPExcel_Style_NumberFormat[]		All number formats in PHPExcel
685
	 * @throws 	PHPExcel_Writer_Exception
686
	 */
687
	public function allNumberFormats(PHPExcel $pPHPExcel = null)
688
	{
689
		// Get an array of unique number formats
690
		$aNumFmts 	= array();
691
		$aStyles 	= $this->allStyles($pPHPExcel);
692
 
693
		foreach ($aStyles as $style) {
694
			if ($style->getNumberFormat()->getBuiltInFormatCode() === false && !array_key_exists($style->getNumberFormat()->getHashCode(), $aNumFmts)) {
695
				$aNumFmts[ $style->getNumberFormat()->getHashCode() ] = $style->getNumberFormat();
696
			}
697
		}
698
 
699
		return $aNumFmts;
700
	}
701
}