~ubuntu-branches/ubuntu/lucid/phpmyadmin/lucid

« back to all changes in this revision

Viewing changes to libraries/PHPExcel/PHPExcel/Writer/Excel2007/Style.php

  • Committer: Bazaar Package Importer
  • Author(s): Michal Čihař
  • Date: 2010-03-08 15:25:00 UTC
  • mfrom: (1.2.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20100308152500-6e8hmuqc5co39de5
Tags: 4:3.3.0-1
* New upstream version.
* Rediff debian/patches.
* Fix permissions on mediawiki export extension.

Show diffs side-by-side

added added

removed removed

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