Subversion Repositories eFlore/Applications.cel

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2388 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_Worksheet
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_Worksheet extends PHPExcel_Writer_Excel2007_WriterPart
37
{
38
	/**
39
	 * Write worksheet to XML format
40
	 *
41
	 * @param	PHPExcel_Worksheet		$pSheet
42
	 * @param	string[]				$pStringTable
43
	 * @param	boolean					$includeCharts	Flag indicating if we should write charts
44
	 * @return	string					XML Output
45
	 * @throws	PHPExcel_Writer_Exception
46
	 */
47
	public function writeWorksheet($pSheet = null, $pStringTable = null, $includeCharts = FALSE)
48
	{
49
		if (!is_null($pSheet)) {
50
			// Create XML writer
51
			$objWriter = null;
52
			if ($this->getParentWriter()->getUseDiskCaching()) {
53
				$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
54
			} else {
55
				$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY);
56
			}
57
 
58
			// XML header
59
			$objWriter->startDocument('1.0','UTF-8','yes');
60
 
61
			// Worksheet
62
			$objWriter->startElement('worksheet');
63
			$objWriter->writeAttribute('xml:space', 'preserve');
64
			$objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/spreadsheetml/2006/main');
65
			$objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
66
 
67
				// sheetPr
68
				$this->_writeSheetPr($objWriter, $pSheet);
69
 
70
				// Dimension
71
				$this->_writeDimension($objWriter, $pSheet);
72
 
73
				// sheetViews
74
				$this->_writeSheetViews($objWriter, $pSheet);
75
 
76
				// sheetFormatPr
77
				$this->_writeSheetFormatPr($objWriter, $pSheet);
78
 
79
				// cols
80
				$this->_writeCols($objWriter, $pSheet);
81
 
82
				// sheetData
83
				$this->_writeSheetData($objWriter, $pSheet, $pStringTable);
84
 
85
				// sheetProtection
86
				$this->_writeSheetProtection($objWriter, $pSheet);
87
 
88
				// protectedRanges
89
				$this->_writeProtectedRanges($objWriter, $pSheet);
90
 
91
				// autoFilter
92
				$this->_writeAutoFilter($objWriter, $pSheet);
93
 
94
				// mergeCells
95
				$this->_writeMergeCells($objWriter, $pSheet);
96
 
97
				// conditionalFormatting
98
				$this->_writeConditionalFormatting($objWriter, $pSheet);
99
 
100
				// dataValidations
101
				$this->_writeDataValidations($objWriter, $pSheet);
102
 
103
				// hyperlinks
104
				$this->_writeHyperlinks($objWriter, $pSheet);
105
 
106
				// Print options
107
				$this->_writePrintOptions($objWriter, $pSheet);
108
 
109
				// Page margins
110
				$this->_writePageMargins($objWriter, $pSheet);
111
 
112
				// Page setup
113
				$this->_writePageSetup($objWriter, $pSheet);
114
 
115
				// Header / footer
116
				$this->_writeHeaderFooter($objWriter, $pSheet);
117
 
118
				// Breaks
119
				$this->_writeBreaks($objWriter, $pSheet);
120
 
121
				// Drawings and/or Charts
122
				$this->_writeDrawings($objWriter, $pSheet, $includeCharts);
123
 
124
				// LegacyDrawing
125
				$this->_writeLegacyDrawing($objWriter, $pSheet);
126
 
127
				// LegacyDrawingHF
128
				$this->_writeLegacyDrawingHF($objWriter, $pSheet);
129
 
130
			$objWriter->endElement();
131
 
132
			// Return
133
			return $objWriter->getData();
134
		} else {
135
			throw new PHPExcel_Writer_Exception("Invalid PHPExcel_Worksheet object passed.");
136
		}
137
	}
138
 
139
	/**
140
	 * Write SheetPr
141
	 *
142
	 * @param	PHPExcel_Shared_XMLWriter		$objWriter		XML Writer
143
	 * @param	PHPExcel_Worksheet				$pSheet			Worksheet
144
	 * @throws	PHPExcel_Writer_Exception
145
	 */
146
	private function _writeSheetPr(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null)
147
	{
148
		// sheetPr
149
		$objWriter->startElement('sheetPr');
150
		//$objWriter->writeAttribute('codeName',		$pSheet->getTitle());
151
			$autoFilterRange = $pSheet->getAutoFilter()->getRange();
152
			if (!empty($autoFilterRange)) {
153
				$objWriter->writeAttribute('filterMode', 1);
154
				$pSheet->getAutoFilter()->showHideRows();
155
			}
156
 
157
			// tabColor
158
			if ($pSheet->isTabColorSet()) {
159
				$objWriter->startElement('tabColor');
160
				$objWriter->writeAttribute('rgb',	$pSheet->getTabColor()->getARGB());
161
				$objWriter->endElement();
162
			}
163
 
164
			// outlinePr
165
			$objWriter->startElement('outlinePr');
166
			$objWriter->writeAttribute('summaryBelow',	($pSheet->getShowSummaryBelow() ? '1' : '0'));
167
			$objWriter->writeAttribute('summaryRight',	($pSheet->getShowSummaryRight() ? '1' : '0'));
168
			$objWriter->endElement();
169
 
170
			// pageSetUpPr
171
			if ($pSheet->getPageSetup()->getFitToPage()) {
172
				$objWriter->startElement('pageSetUpPr');
173
				$objWriter->writeAttribute('fitToPage',	'1');
174
				$objWriter->endElement();
175
			}
176
 
177
		$objWriter->endElement();
178
	}
179
 
180
	/**
181
	 * Write Dimension
182
	 *
183
	 * @param	PHPExcel_Shared_XMLWriter	$objWriter		XML Writer
184
	 * @param	PHPExcel_Worksheet			$pSheet			Worksheet
185
	 * @throws	PHPExcel_Writer_Exception
186
	 */
187
	private function _writeDimension(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null)
188
	{
189
		// dimension
190
		$objWriter->startElement('dimension');
191
		$objWriter->writeAttribute('ref', $pSheet->calculateWorksheetDimension());
192
		$objWriter->endElement();
193
	}
194
 
195
	/**
196
	 * Write SheetViews
197
	 *
198
	 * @param	PHPExcel_Shared_XMLWriter			$objWriter		XML Writer
199
	 * @param	PHPExcel_Worksheet					$pSheet			Worksheet
200
	 * @throws	PHPExcel_Writer_Exception
201
	 */
202
	private function _writeSheetViews(PHPExcel_Shared_XMLWriter $objWriter = NULL, PHPExcel_Worksheet $pSheet = NULL)
203
	{
204
		// sheetViews
205
		$objWriter->startElement('sheetViews');
206
 
207
			// Sheet selected?
208
			$sheetSelected = false;
209
			if ($this->getParentWriter()->getPHPExcel()->getIndex($pSheet) == $this->getParentWriter()->getPHPExcel()->getActiveSheetIndex())
210
				$sheetSelected = true;
211
 
212
 
213
			// sheetView
214
			$objWriter->startElement('sheetView');
215
			$objWriter->writeAttribute('tabSelected',		$sheetSelected ? '1' : '0');
216
			$objWriter->writeAttribute('workbookViewId',	'0');
217
 
218
				// Zoom scales
219
				if ($pSheet->getSheetView()->getZoomScale() != 100) {
220
					$objWriter->writeAttribute('zoomScale',	$pSheet->getSheetView()->getZoomScale());
221
				}
222
				if ($pSheet->getSheetView()->getZoomScaleNormal() != 100) {
223
					$objWriter->writeAttribute('zoomScaleNormal',	$pSheet->getSheetView()->getZoomScaleNormal());
224
				}
225
 
226
				// View Layout Type
227
				if ($pSheet->getSheetView()->getView() !== PHPExcel_Worksheet_SheetView::SHEETVIEW_NORMAL) {
228
					$objWriter->writeAttribute('view',	$pSheet->getSheetView()->getView());
229
				}
230
 
231
				// Gridlines
232
				if ($pSheet->getShowGridlines()) {
233
					$objWriter->writeAttribute('showGridLines',	'true');
234
				} else {
235
					$objWriter->writeAttribute('showGridLines',	'false');
236
				}
237
 
238
				// Row and column headers
239
				if ($pSheet->getShowRowColHeaders()) {
240
					$objWriter->writeAttribute('showRowColHeaders', '1');
241
				} else {
242
					$objWriter->writeAttribute('showRowColHeaders', '0');
243
				}
244
 
245
				// Right-to-left
246
				if ($pSheet->getRightToLeft()) {
247
					$objWriter->writeAttribute('rightToLeft',	'true');
248
				}
249
 
250
				$activeCell = $pSheet->getActiveCell();
251
 
252
				// Pane
253
				$pane = '';
254
				$topLeftCell = $pSheet->getFreezePane();
255
				if (($topLeftCell != '') && ($topLeftCell != 'A1')) {
256
					$activeCell = $topLeftCell;
257
					// Calculate freeze coordinates
258
					$xSplit = $ySplit = 0;
259
 
260
					list($xSplit, $ySplit) = PHPExcel_Cell::coordinateFromString($topLeftCell);
261
					$xSplit = PHPExcel_Cell::columnIndexFromString($xSplit);
262
 
263
					// pane
264
					$pane = 'topRight';
265
					$objWriter->startElement('pane');
266
					if ($xSplit > 1)
267
						$objWriter->writeAttribute('xSplit',	$xSplit - 1);
268
					if ($ySplit > 1) {
269
						$objWriter->writeAttribute('ySplit',	$ySplit - 1);
270
						$pane = ($xSplit > 1) ? 'bottomRight' : 'bottomLeft';
271
					}
272
					$objWriter->writeAttribute('topLeftCell',	$topLeftCell);
273
					$objWriter->writeAttribute('activePane',	$pane);
274
					$objWriter->writeAttribute('state',		'frozen');
275
					$objWriter->endElement();
276
 
277
					if (($xSplit > 1) && ($ySplit > 1)) {
278
						//	Write additional selections if more than two panes (ie both an X and a Y split)
279
						$objWriter->startElement('selection');	$objWriter->writeAttribute('pane', 'topRight');		$objWriter->endElement();
280
						$objWriter->startElement('selection');	$objWriter->writeAttribute('pane', 'bottomLeft');	$objWriter->endElement();
281
					}
282
				}
283
 
284
				// Selection
285
//				if ($pane != '') {
286
					//	Only need to write selection element if we have a split pane
287
					//		We cheat a little by over-riding the active cell selection, setting it to the split cell
288
					$objWriter->startElement('selection');
289
					if ($pane != '') {
290
						$objWriter->writeAttribute('pane', $pane);
291
					}
292
					$objWriter->writeAttribute('activeCell', $activeCell);
293
					$objWriter->writeAttribute('sqref', $activeCell);
294
					$objWriter->endElement();
295
//				}
296
 
297
			$objWriter->endElement();
298
 
299
		$objWriter->endElement();
300
	}
301
 
302
	/**
303
	 * Write SheetFormatPr
304
	 *
305
	 * @param	PHPExcel_Shared_XMLWriter $objWriter		XML Writer
306
	 * @param	PHPExcel_Worksheet		  $pSheet			Worksheet
307
	 * @throws	PHPExcel_Writer_Exception
308
	 */
309
	private function _writeSheetFormatPr(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null)
310
	{
311
		// sheetFormatPr
312
		$objWriter->startElement('sheetFormatPr');
313
 
314
			// Default row height
315
			if ($pSheet->getDefaultRowDimension()->getRowHeight() >= 0) {
316
				$objWriter->writeAttribute('customHeight',		'true');
317
				$objWriter->writeAttribute('defaultRowHeight',	PHPExcel_Shared_String::FormatNumber($pSheet->getDefaultRowDimension()->getRowHeight()));
318
			} else {
319
				$objWriter->writeAttribute('defaultRowHeight', '14.4');
320
			}
321
 
322
			// Set Zero Height row
323
			if ((string)$pSheet->getDefaultRowDimension()->getzeroHeight()  == '1' ||
324
				strtolower((string)$pSheet->getDefaultRowDimension()->getzeroHeight()) == 'true' ) {
325
				$objWriter->writeAttribute('zeroHeight', '1');
326
			}
327
 
328
			// Default column width
329
			if ($pSheet->getDefaultColumnDimension()->getWidth() >= 0) {
330
				$objWriter->writeAttribute('defaultColWidth', PHPExcel_Shared_String::FormatNumber($pSheet->getDefaultColumnDimension()->getWidth()));
331
			}
332
 
333
			// Outline level - row
334
			$outlineLevelRow = 0;
335
			foreach ($pSheet->getRowDimensions() as $dimension) {
336
				if ($dimension->getOutlineLevel() > $outlineLevelRow) {
337
					$outlineLevelRow = $dimension->getOutlineLevel();
338
				}
339
			}
340
			$objWriter->writeAttribute('outlineLevelRow',	(int)$outlineLevelRow);
341
 
342
			// Outline level - column
343
			$outlineLevelCol = 0;
344
			foreach ($pSheet->getColumnDimensions() as $dimension) {
345
				if ($dimension->getOutlineLevel() > $outlineLevelCol) {
346
					$outlineLevelCol = $dimension->getOutlineLevel();
347
				}
348
			}
349
			$objWriter->writeAttribute('outlineLevelCol',	(int)$outlineLevelCol);
350
 
351
		$objWriter->endElement();
352
	}
353
 
354
	/**
355
	 * Write Cols
356
	 *
357
	 * @param	PHPExcel_Shared_XMLWriter			$objWriter		XML Writer
358
	 * @param	PHPExcel_Worksheet					$pSheet			Worksheet
359
	 * @throws	PHPExcel_Writer_Exception
360
	 */
361
	private function _writeCols(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null)
362
	{
363
		// cols
364
		if (count($pSheet->getColumnDimensions()) > 0)  {
365
			$objWriter->startElement('cols');
366
 
367
				$pSheet->calculateColumnWidths();
368
 
369
				// Loop through column dimensions
370
				foreach ($pSheet->getColumnDimensions() as $colDimension) {
371
					// col
372
					$objWriter->startElement('col');
373
					$objWriter->writeAttribute('min',	PHPExcel_Cell::columnIndexFromString($colDimension->getColumnIndex()));
374
					$objWriter->writeAttribute('max',	PHPExcel_Cell::columnIndexFromString($colDimension->getColumnIndex()));
375
 
376
					if ($colDimension->getWidth() < 0) {
377
						// No width set, apply default of 10
378
						$objWriter->writeAttribute('width',		'9.10');
379
					} else {
380
						// Width set
381
						$objWriter->writeAttribute('width',		PHPExcel_Shared_String::FormatNumber($colDimension->getWidth()));
382
					}
383
 
384
					// Column visibility
385
					if ($colDimension->getVisible() == false) {
386
						$objWriter->writeAttribute('hidden',		'true');
387
					}
388
 
389
					// Auto size?
390
					if ($colDimension->getAutoSize()) {
391
						$objWriter->writeAttribute('bestFit',		'true');
392
					}
393
 
394
					// Custom width?
395
					if ($colDimension->getWidth() != $pSheet->getDefaultColumnDimension()->getWidth()) {
396
						$objWriter->writeAttribute('customWidth',	'true');
397
					}
398
 
399
					// Collapsed
400
					if ($colDimension->getCollapsed() == true) {
401
						$objWriter->writeAttribute('collapsed',		'true');
402
					}
403
 
404
					// Outline level
405
					if ($colDimension->getOutlineLevel() > 0) {
406
						$objWriter->writeAttribute('outlineLevel',	$colDimension->getOutlineLevel());
407
					}
408
 
409
					// Style
410
					$objWriter->writeAttribute('style', $colDimension->getXfIndex());
411
 
412
					$objWriter->endElement();
413
				}
414
 
415
			$objWriter->endElement();
416
		}
417
	}
418
 
419
	/**
420
	 * Write SheetProtection
421
	 *
422
	 * @param	PHPExcel_Shared_XMLWriter			$objWriter		XML Writer
423
	 * @param	PHPExcel_Worksheet					$pSheet			Worksheet
424
	 * @throws	PHPExcel_Writer_Exception
425
	 */
426
	private function _writeSheetProtection(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null)
427
	{
428
		// sheetProtection
429
		$objWriter->startElement('sheetProtection');
430
 
431
		if ($pSheet->getProtection()->getPassword() != '') {
432
			$objWriter->writeAttribute('password',				$pSheet->getProtection()->getPassword());
433
		}
434
 
435
		$objWriter->writeAttribute('sheet',					($pSheet->getProtection()->getSheet()				? 'true' : 'false'));
436
		$objWriter->writeAttribute('objects',				($pSheet->getProtection()->getObjects()				? 'true' : 'false'));
437
		$objWriter->writeAttribute('scenarios',				($pSheet->getProtection()->getScenarios()			? 'true' : 'false'));
438
		$objWriter->writeAttribute('formatCells',			($pSheet->getProtection()->getFormatCells()			? 'true' : 'false'));
439
		$objWriter->writeAttribute('formatColumns',			($pSheet->getProtection()->getFormatColumns()		? 'true' : 'false'));
440
		$objWriter->writeAttribute('formatRows',			($pSheet->getProtection()->getFormatRows()			? 'true' : 'false'));
441
		$objWriter->writeAttribute('insertColumns',			($pSheet->getProtection()->getInsertColumns()		? 'true' : 'false'));
442
		$objWriter->writeAttribute('insertRows',			($pSheet->getProtection()->getInsertRows()			? 'true' : 'false'));
443
		$objWriter->writeAttribute('insertHyperlinks',		($pSheet->getProtection()->getInsertHyperlinks()	? 'true' : 'false'));
444
		$objWriter->writeAttribute('deleteColumns',			($pSheet->getProtection()->getDeleteColumns()		? 'true' : 'false'));
445
		$objWriter->writeAttribute('deleteRows',			($pSheet->getProtection()->getDeleteRows()			? 'true' : 'false'));
446
		$objWriter->writeAttribute('selectLockedCells',		($pSheet->getProtection()->getSelectLockedCells()	? 'true' : 'false'));
447
		$objWriter->writeAttribute('sort',					($pSheet->getProtection()->getSort()				? 'true' : 'false'));
448
		$objWriter->writeAttribute('autoFilter',			($pSheet->getProtection()->getAutoFilter()			? 'true' : 'false'));
449
		$objWriter->writeAttribute('pivotTables',			($pSheet->getProtection()->getPivotTables()			? 'true' : 'false'));
450
		$objWriter->writeAttribute('selectUnlockedCells',	($pSheet->getProtection()->getSelectUnlockedCells()	? 'true' : 'false'));
451
		$objWriter->endElement();
452
	}
453
 
454
	/**
455
	 * Write ConditionalFormatting
456
	 *
457
	 * @param	PHPExcel_Shared_XMLWriter			$objWriter		XML Writer
458
	 * @param	PHPExcel_Worksheet					$pSheet			Worksheet
459
	 * @throws	PHPExcel_Writer_Exception
460
	 */
461
	private function _writeConditionalFormatting(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null)
462
	{
463
		// Conditional id
464
		$id = 1;
465
 
466
		// Loop through styles in the current worksheet
467
		foreach ($pSheet->getConditionalStylesCollection() as $cellCoordinate => $conditionalStyles) {
468
			foreach ($conditionalStyles as $conditional) {
469
				// WHY was this again?
470
				// if ($this->getParentWriter()->getStylesConditionalHashTable()->getIndexForHashCode( $conditional->getHashCode() ) == '') {
471
				//	continue;
472
				// }
473
				if ($conditional->getConditionType() != PHPExcel_Style_Conditional::CONDITION_NONE) {
474
					// conditionalFormatting
475
					$objWriter->startElement('conditionalFormatting');
476
					$objWriter->writeAttribute('sqref',	$cellCoordinate);
477
 
478
						// cfRule
479
						$objWriter->startElement('cfRule');
480
						$objWriter->writeAttribute('type',		$conditional->getConditionType());
481
						$objWriter->writeAttribute('dxfId',		$this->getParentWriter()->getStylesConditionalHashTable()->getIndexForHashCode( $conditional->getHashCode() ));
482
						$objWriter->writeAttribute('priority',	$id++);
483
 
484
						if (($conditional->getConditionType() == PHPExcel_Style_Conditional::CONDITION_CELLIS
485
								||
486
							 $conditional->getConditionType() == PHPExcel_Style_Conditional::CONDITION_CONTAINSTEXT)
487
							&& $conditional->getOperatorType() != PHPExcel_Style_Conditional::OPERATOR_NONE) {
488
							$objWriter->writeAttribute('operator',	$conditional->getOperatorType());
489
						}
490
 
491
						if ($conditional->getConditionType() == PHPExcel_Style_Conditional::CONDITION_CONTAINSTEXT
492
							&& !is_null($conditional->getText())) {
493
							$objWriter->writeAttribute('text',	$conditional->getText());
494
						}
495
 
496
						if ($conditional->getConditionType() == PHPExcel_Style_Conditional::CONDITION_CONTAINSTEXT
497
							&& $conditional->getOperatorType() == PHPExcel_Style_Conditional::OPERATOR_CONTAINSTEXT
498
							&& !is_null($conditional->getText())) {
499
							$objWriter->writeElement('formula',	'NOT(ISERROR(SEARCH("' . $conditional->getText() . '",' . $cellCoordinate . ')))');
500
						} else if ($conditional->getConditionType() == PHPExcel_Style_Conditional::CONDITION_CONTAINSTEXT
501
							&& $conditional->getOperatorType() == PHPExcel_Style_Conditional::OPERATOR_BEGINSWITH
502
							&& !is_null($conditional->getText())) {
503
							$objWriter->writeElement('formula',	'LEFT(' . $cellCoordinate . ',' . strlen($conditional->getText()) . ')="' . $conditional->getText() . '"');
504
						} else if ($conditional->getConditionType() == PHPExcel_Style_Conditional::CONDITION_CONTAINSTEXT
505
							&& $conditional->getOperatorType() == PHPExcel_Style_Conditional::OPERATOR_ENDSWITH
506
							&& !is_null($conditional->getText())) {
507
							$objWriter->writeElement('formula',	'RIGHT(' . $cellCoordinate . ',' . strlen($conditional->getText()) . ')="' . $conditional->getText() . '"');
508
						} else if ($conditional->getConditionType() == PHPExcel_Style_Conditional::CONDITION_CONTAINSTEXT
509
							&& $conditional->getOperatorType() == PHPExcel_Style_Conditional::OPERATOR_NOTCONTAINS
510
							&& !is_null($conditional->getText())) {
511
							$objWriter->writeElement('formula',	'ISERROR(SEARCH("' . $conditional->getText() . '",' . $cellCoordinate . '))');
512
						} else if ($conditional->getConditionType() == PHPExcel_Style_Conditional::CONDITION_CELLIS
513
							|| $conditional->getConditionType() == PHPExcel_Style_Conditional::CONDITION_CONTAINSTEXT
514
							|| $conditional->getConditionType() == PHPExcel_Style_Conditional::CONDITION_EXPRESSION) {
515
							foreach ($conditional->getConditions() as $formula) {
516
								// Formula
517
								$objWriter->writeElement('formula',	$formula);
518
							}
519
						}
520
 
521
						$objWriter->endElement();
522
 
523
					$objWriter->endElement();
524
				}
525
			}
526
		}
527
	}
528
 
529
	/**
530
	 * Write DataValidations
531
	 *
532
	 * @param	PHPExcel_Shared_XMLWriter			$objWriter		XML Writer
533
	 * @param	PHPExcel_Worksheet					$pSheet			Worksheet
534
	 * @throws	PHPExcel_Writer_Exception
535
	 */
536
	private function _writeDataValidations(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null)
537
	{
538
		// Datavalidation collection
539
		$dataValidationCollection = $pSheet->getDataValidationCollection();
540
 
541
		// Write data validations?
542
		if (!empty($dataValidationCollection)) {
543
			$objWriter->startElement('dataValidations');
544
			$objWriter->writeAttribute('count', count($dataValidationCollection));
545
 
546
			foreach ($dataValidationCollection as $coordinate => $dv) {
547
				$objWriter->startElement('dataValidation');
548
 
549
				if ($dv->getType() != '') {
550
					$objWriter->writeAttribute('type', $dv->getType());
551
				}
552
 
553
				if ($dv->getErrorStyle() != '') {
554
					$objWriter->writeAttribute('errorStyle', $dv->getErrorStyle());
555
				}
556
 
557
				if ($dv->getOperator() != '') {
558
					$objWriter->writeAttribute('operator', $dv->getOperator());
559
				}
560
 
561
				$objWriter->writeAttribute('allowBlank',		($dv->getAllowBlank()		? '1'  : '0'));
562
				$objWriter->writeAttribute('showDropDown',		(!$dv->getShowDropDown()	? '1'  : '0'));
563
				$objWriter->writeAttribute('showInputMessage',	($dv->getShowInputMessage()	? '1'  : '0'));
564
				$objWriter->writeAttribute('showErrorMessage',	($dv->getShowErrorMessage()	? '1'  : '0'));
565
 
566
				if ($dv->getErrorTitle() !== '') {
567
					$objWriter->writeAttribute('errorTitle', $dv->getErrorTitle());
568
				}
569
				if ($dv->getError() !== '') {
570
					$objWriter->writeAttribute('error', $dv->getError());
571
				}
572
				if ($dv->getPromptTitle() !== '') {
573
					$objWriter->writeAttribute('promptTitle', $dv->getPromptTitle());
574
				}
575
				if ($dv->getPrompt() !== '') {
576
					$objWriter->writeAttribute('prompt', $dv->getPrompt());
577
				}
578
 
579
				$objWriter->writeAttribute('sqref', $coordinate);
580
 
581
				if ($dv->getFormula1() !== '') {
582
					$objWriter->writeElement('formula1', $dv->getFormula1());
583
				}
584
				if ($dv->getFormula2() !== '') {
585
					$objWriter->writeElement('formula2', $dv->getFormula2());
586
				}
587
 
588
				$objWriter->endElement();
589
			}
590
 
591
			$objWriter->endElement();
592
		}
593
	}
594
 
595
	/**
596
	 * Write Hyperlinks
597
	 *
598
	 * @param	PHPExcel_Shared_XMLWriter			$objWriter		XML Writer
599
	 * @param	PHPExcel_Worksheet					$pSheet			Worksheet
600
	 * @throws	PHPExcel_Writer_Exception
601
	 */
602
	private function _writeHyperlinks(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null)
603
	{
604
		// Hyperlink collection
605
		$hyperlinkCollection = $pSheet->getHyperlinkCollection();
606
 
607
		// Relation ID
608
		$relationId = 1;
609
 
610
		// Write hyperlinks?
611
		if (!empty($hyperlinkCollection)) {
612
			$objWriter->startElement('hyperlinks');
613
 
614
			foreach ($hyperlinkCollection as $coordinate => $hyperlink) {
615
				$objWriter->startElement('hyperlink');
616
 
617
				$objWriter->writeAttribute('ref', $coordinate);
618
				if (!$hyperlink->isInternal()) {
619
					$objWriter->writeAttribute('r:id',	'rId_hyperlink_' . $relationId);
620
					++$relationId;
621
				} else {
622
					$objWriter->writeAttribute('location',	str_replace('sheet://', '', $hyperlink->getUrl()));
623
				}
624
 
625
				if ($hyperlink->getTooltip() != '') {
626
					$objWriter->writeAttribute('tooltip', $hyperlink->getTooltip());
627
				}
628
 
629
				$objWriter->endElement();
630
			}
631
 
632
			$objWriter->endElement();
633
		}
634
	}
635
 
636
	/**
637
	 * Write ProtectedRanges
638
	 *
639
	 * @param	PHPExcel_Shared_XMLWriter			$objWriter		XML Writer
640
	 * @param	PHPExcel_Worksheet					$pSheet			Worksheet
641
	 * @throws	PHPExcel_Writer_Exception
642
	 */
643
	private function _writeProtectedRanges(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null)
644
	{
645
		if (count($pSheet->getProtectedCells()) > 0) {
646
			// protectedRanges
647
			$objWriter->startElement('protectedRanges');
648
 
649
				// Loop protectedRanges
650
				foreach ($pSheet->getProtectedCells() as $protectedCell => $passwordHash) {
651
					// protectedRange
652
					$objWriter->startElement('protectedRange');
653
					$objWriter->writeAttribute('name',		'p' . md5($protectedCell));
654
					$objWriter->writeAttribute('sqref',	$protectedCell);
655
					if (!empty($passwordHash)) {
656
						$objWriter->writeAttribute('password',	$passwordHash);
657
					}
658
					$objWriter->endElement();
659
				}
660
 
661
			$objWriter->endElement();
662
		}
663
	}
664
 
665
	/**
666
	 * Write MergeCells
667
	 *
668
	 * @param	PHPExcel_Shared_XMLWriter			$objWriter		XML Writer
669
	 * @param	PHPExcel_Worksheet					$pSheet			Worksheet
670
	 * @throws	PHPExcel_Writer_Exception
671
	 */
672
	private function _writeMergeCells(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null)
673
	{
674
		if (count($pSheet->getMergeCells()) > 0) {
675
			// mergeCells
676
			$objWriter->startElement('mergeCells');
677
 
678
				// Loop mergeCells
679
				foreach ($pSheet->getMergeCells() as $mergeCell) {
680
					// mergeCell
681
					$objWriter->startElement('mergeCell');
682
					$objWriter->writeAttribute('ref', $mergeCell);
683
					$objWriter->endElement();
684
				}
685
 
686
			$objWriter->endElement();
687
		}
688
	}
689
 
690
	/**
691
	 * Write PrintOptions
692
	 *
693
	 * @param	PHPExcel_Shared_XMLWriter			$objWriter		XML Writer
694
	 * @param	PHPExcel_Worksheet					$pSheet			Worksheet
695
	 * @throws	PHPExcel_Writer_Exception
696
	 */
697
	private function _writePrintOptions(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null)
698
	{
699
		// printOptions
700
		$objWriter->startElement('printOptions');
701
 
702
		$objWriter->writeAttribute('gridLines',	($pSheet->getPrintGridlines() ? 'true': 'false'));
703
		$objWriter->writeAttribute('gridLinesSet',	'true');
704
 
705
		if ($pSheet->getPageSetup()->getHorizontalCentered()) {
706
			$objWriter->writeAttribute('horizontalCentered', 'true');
707
		}
708
 
709
		if ($pSheet->getPageSetup()->getVerticalCentered()) {
710
			$objWriter->writeAttribute('verticalCentered', 'true');
711
		}
712
 
713
		$objWriter->endElement();
714
	}
715
 
716
	/**
717
	 * Write PageMargins
718
	 *
719
	 * @param	PHPExcel_Shared_XMLWriter				$objWriter		XML Writer
720
	 * @param	PHPExcel_Worksheet						$pSheet			Worksheet
721
	 * @throws	PHPExcel_Writer_Exception
722
	 */
723
	private function _writePageMargins(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null)
724
	{
725
		// pageMargins
726
		$objWriter->startElement('pageMargins');
727
		$objWriter->writeAttribute('left',		PHPExcel_Shared_String::FormatNumber($pSheet->getPageMargins()->getLeft()));
728
		$objWriter->writeAttribute('right',		PHPExcel_Shared_String::FormatNumber($pSheet->getPageMargins()->getRight()));
729
		$objWriter->writeAttribute('top',		PHPExcel_Shared_String::FormatNumber($pSheet->getPageMargins()->getTop()));
730
		$objWriter->writeAttribute('bottom',	PHPExcel_Shared_String::FormatNumber($pSheet->getPageMargins()->getBottom()));
731
		$objWriter->writeAttribute('header',	PHPExcel_Shared_String::FormatNumber($pSheet->getPageMargins()->getHeader()));
732
		$objWriter->writeAttribute('footer',	PHPExcel_Shared_String::FormatNumber($pSheet->getPageMargins()->getFooter()));
733
		$objWriter->endElement();
734
	}
735
 
736
	/**
737
	 * Write AutoFilter
738
	 *
739
	 * @param	PHPExcel_Shared_XMLWriter				$objWriter		XML Writer
740
	 * @param	PHPExcel_Worksheet						$pSheet			Worksheet
741
	 * @throws	PHPExcel_Writer_Exception
742
	 */
743
	private function _writeAutoFilter(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null)
744
	{
745
		$autoFilterRange = $pSheet->getAutoFilter()->getRange();
746
		if (!empty($autoFilterRange)) {
747
			// autoFilter
748
			$objWriter->startElement('autoFilter');
749
 
750
			// Strip any worksheet reference from the filter coordinates
751
			$range = PHPExcel_Cell::splitRange($autoFilterRange);
752
			$range = $range[0];
753
			//	Strip any worksheet ref
754
			if (strpos($range[0],'!') !== false) {
755
				list($ws,$range[0]) = explode('!',$range[0]);
756
			}
757
			$range = implode(':', $range);
758
 
759
			$objWriter->writeAttribute('ref',	str_replace('$','',$range));
760
 
761
			$columns = $pSheet->getAutoFilter()->getColumns();
762
			if (count($columns > 0)) {
763
				foreach($columns as $columnID => $column) {
764
					$rules = $column->getRules();
765
					if (count($rules > 0)) {
766
						$objWriter->startElement('filterColumn');
767
							$objWriter->writeAttribute('colId',	$pSheet->getAutoFilter()->getColumnOffset($columnID));
768
 
769
							$objWriter->startElement( $column->getFilterType());
770
								if ($column->getJoin() == PHPExcel_Worksheet_AutoFilter_Column::AUTOFILTER_COLUMN_JOIN_AND) {
771
									$objWriter->writeAttribute('and',	1);
772
								}
773
 
774
								foreach ($rules as $rule) {
775
									if (($column->getFilterType() === PHPExcel_Worksheet_AutoFilter_Column::AUTOFILTER_FILTERTYPE_FILTER) &&
776
										($rule->getOperator() === PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_COLUMN_RULE_EQUAL) &&
777
										($rule->getValue() === '')) {
778
										//	Filter rule for Blanks
779
										$objWriter->writeAttribute('blank',	1);
780
									} elseif($rule->getRuleType() === PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DYNAMICFILTER) {
781
										//	Dynamic Filter Rule
782
										$objWriter->writeAttribute('type', $rule->getGrouping());
783
										$val = $column->getAttribute('val');
784
										if ($val !== NULL) {
785
											$objWriter->writeAttribute('val', $val);
786
										}
787
										$maxVal = $column->getAttribute('maxVal');
788
										if ($maxVal !== NULL) {
789
											$objWriter->writeAttribute('maxVal', $maxVal);
790
										}
791
									} elseif($rule->getRuleType() === PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_TOPTENFILTER) {
792
										//	Top 10 Filter Rule
793
										$objWriter->writeAttribute('val',	$rule->getValue());
794
										$objWriter->writeAttribute('percent',	(($rule->getOperator() === PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_COLUMN_RULE_TOPTEN_PERCENT) ? '1' : '0'));
795
										$objWriter->writeAttribute('top',	(($rule->getGrouping() === PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_COLUMN_RULE_TOPTEN_TOP) ? '1': '0'));
796
									} else {
797
										//	Filter, DateGroupItem or CustomFilter
798
										$objWriter->startElement($rule->getRuleType());
799
 
800
											if ($rule->getOperator() !== PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_COLUMN_RULE_EQUAL) {
801
												$objWriter->writeAttribute('operator',	$rule->getOperator());
802
											}
803
											if ($rule->getRuleType() === PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_DATEGROUP) {
804
												// Date Group filters
805
												foreach($rule->getValue() as $key => $value) {
806
													if ($value > '') $objWriter->writeAttribute($key,	$value);
807
												}
808
												$objWriter->writeAttribute('dateTimeGrouping',	$rule->getGrouping());
809
											} else {
810
												$objWriter->writeAttribute('val',	$rule->getValue());
811
											}
812
 
813
										$objWriter->endElement();
814
									}
815
								}
816
 
817
							$objWriter->endElement();
818
 
819
						$objWriter->endElement();
820
					}
821
				}
822
			}
823
 
824
			$objWriter->endElement();
825
		}
826
	}
827
 
828
	/**
829
	 * Write PageSetup
830
	 *
831
	 * @param	PHPExcel_Shared_XMLWriter			$objWriter		XML Writer
832
	 * @param	PHPExcel_Worksheet					$pSheet			Worksheet
833
	 * @throws	PHPExcel_Writer_Exception
834
	 */
835
	private function _writePageSetup(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null)
836
	{
837
		// pageSetup
838
		$objWriter->startElement('pageSetup');
839
		$objWriter->writeAttribute('paperSize',		$pSheet->getPageSetup()->getPaperSize());
840
		$objWriter->writeAttribute('orientation',	$pSheet->getPageSetup()->getOrientation());
841
 
842
		if (!is_null($pSheet->getPageSetup()->getScale())) {
843
			$objWriter->writeAttribute('scale',				 $pSheet->getPageSetup()->getScale());
844
		}
845
		if (!is_null($pSheet->getPageSetup()->getFitToHeight())) {
846
			$objWriter->writeAttribute('fitToHeight',		 $pSheet->getPageSetup()->getFitToHeight());
847
		} else {
848
			$objWriter->writeAttribute('fitToHeight',		 '0');
849
		}
850
		if (!is_null($pSheet->getPageSetup()->getFitToWidth())) {
851
			$objWriter->writeAttribute('fitToWidth',		 $pSheet->getPageSetup()->getFitToWidth());
852
		} else {
853
			$objWriter->writeAttribute('fitToWidth',		 '0');
854
		}
855
		if (!is_null($pSheet->getPageSetup()->getFirstPageNumber())) {
856
			$objWriter->writeAttribute('firstPageNumber',	$pSheet->getPageSetup()->getFirstPageNumber());
857
			$objWriter->writeAttribute('useFirstPageNumber', '1');
858
		}
859
 
860
		$objWriter->endElement();
861
	}
862
 
863
	/**
864
	 * Write Header / Footer
865
	 *
866
	 * @param	PHPExcel_Shared_XMLWriter		$objWriter		XML Writer
867
	 * @param	PHPExcel_Worksheet				$pSheet			Worksheet
868
	 * @throws	PHPExcel_Writer_Exception
869
	 */
870
	private function _writeHeaderFooter(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null)
871
	{
872
		// headerFooter
873
		$objWriter->startElement('headerFooter');
874
		$objWriter->writeAttribute('differentOddEven',	($pSheet->getHeaderFooter()->getDifferentOddEven() ? 'true' : 'false'));
875
		$objWriter->writeAttribute('differentFirst',	($pSheet->getHeaderFooter()->getDifferentFirst() ? 'true' : 'false'));
876
		$objWriter->writeAttribute('scaleWithDoc',		($pSheet->getHeaderFooter()->getScaleWithDocument() ? 'true' : 'false'));
877
		$objWriter->writeAttribute('alignWithMargins',	($pSheet->getHeaderFooter()->getAlignWithMargins() ? 'true' : 'false'));
878
 
879
			$objWriter->writeElement('oddHeader',		$pSheet->getHeaderFooter()->getOddHeader());
880
			$objWriter->writeElement('oddFooter',		$pSheet->getHeaderFooter()->getOddFooter());
881
			$objWriter->writeElement('evenHeader',		$pSheet->getHeaderFooter()->getEvenHeader());
882
			$objWriter->writeElement('evenFooter',		$pSheet->getHeaderFooter()->getEvenFooter());
883
			$objWriter->writeElement('firstHeader',	$pSheet->getHeaderFooter()->getFirstHeader());
884
			$objWriter->writeElement('firstFooter',	$pSheet->getHeaderFooter()->getFirstFooter());
885
		$objWriter->endElement();
886
	}
887
 
888
	/**
889
	 * Write Breaks
890
	 *
891
	 * @param	PHPExcel_Shared_XMLWriter		$objWriter		XML Writer
892
	 * @param	PHPExcel_Worksheet				$pSheet			Worksheet
893
	 * @throws	PHPExcel_Writer_Exception
894
	 */
895
	private function _writeBreaks(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null)
896
	{
897
		// Get row and column breaks
898
		$aRowBreaks = array();
899
		$aColumnBreaks = array();
900
		foreach ($pSheet->getBreaks() as $cell => $breakType) {
901
			if ($breakType == PHPExcel_Worksheet::BREAK_ROW) {
902
				$aRowBreaks[] = $cell;
903
			} else if ($breakType == PHPExcel_Worksheet::BREAK_COLUMN) {
904
				$aColumnBreaks[] = $cell;
905
			}
906
		}
907
 
908
		// rowBreaks
909
		if (!empty($aRowBreaks)) {
910
			$objWriter->startElement('rowBreaks');
911
			$objWriter->writeAttribute('count',			count($aRowBreaks));
912
			$objWriter->writeAttribute('manualBreakCount',	count($aRowBreaks));
913
 
914
				foreach ($aRowBreaks as $cell) {
915
					$coords = PHPExcel_Cell::coordinateFromString($cell);
916
 
917
					$objWriter->startElement('brk');
918
					$objWriter->writeAttribute('id',	$coords[1]);
919
					$objWriter->writeAttribute('man',	'1');
920
					$objWriter->endElement();
921
				}
922
 
923
			$objWriter->endElement();
924
		}
925
 
926
		// Second, write column breaks
927
		if (!empty($aColumnBreaks)) {
928
			$objWriter->startElement('colBreaks');
929
			$objWriter->writeAttribute('count',			count($aColumnBreaks));
930
			$objWriter->writeAttribute('manualBreakCount',	count($aColumnBreaks));
931
 
932
				foreach ($aColumnBreaks as $cell) {
933
					$coords = PHPExcel_Cell::coordinateFromString($cell);
934
 
935
					$objWriter->startElement('brk');
936
					$objWriter->writeAttribute('id',	PHPExcel_Cell::columnIndexFromString($coords[0]) - 1);
937
					$objWriter->writeAttribute('man',	'1');
938
					$objWriter->endElement();
939
				}
940
 
941
			$objWriter->endElement();
942
		}
943
	}
944
 
945
	/**
946
	 * Write SheetData
947
	 *
948
	 * @param	PHPExcel_Shared_XMLWriter		$objWriter		XML Writer
949
	 * @param	PHPExcel_Worksheet				$pSheet			Worksheet
950
	 * @param	string[]						$pStringTable	String table
951
	 * @throws	PHPExcel_Writer_Exception
952
	 */
953
	private function _writeSheetData(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null, $pStringTable = null)
954
	{
955
		if (is_array($pStringTable)) {
956
			// Flipped stringtable, for faster index searching
957
			$aFlippedStringTable = $this->getParentWriter()->getWriterPart('stringtable')->flipStringTable($pStringTable);
958
 
959
			// sheetData
960
			$objWriter->startElement('sheetData');
961
 
962
				// Get column count
963
				$colCount = PHPExcel_Cell::columnIndexFromString($pSheet->getHighestColumn());
964
 
965
				// Highest row number
966
				$highestRow = $pSheet->getHighestRow();
967
 
968
				// Loop through cells
969
				$cellsByRow = array();
970
				foreach ($pSheet->getCellCollection() as $cellID) {
971
					$cellAddress = PHPExcel_Cell::coordinateFromString($cellID);
972
					$cellsByRow[$cellAddress[1]][] = $cellID;
973
				}
974
 
975
				$currentRow = 0;
976
				while($currentRow++ < $highestRow) {
977
					// Get row dimension
978
					$rowDimension = $pSheet->getRowDimension($currentRow);
979
 
980
					// Write current row?
981
					$writeCurrentRow =	isset($cellsByRow[$currentRow]) ||
982
										$rowDimension->getRowHeight() >= 0 ||
983
										$rowDimension->getVisible() == false ||
984
										$rowDimension->getCollapsed() == true ||
985
										$rowDimension->getOutlineLevel() > 0 ||
986
										$rowDimension->getXfIndex() !== null;
987
 
988
					if ($writeCurrentRow) {
989
						// Start a new row
990
						$objWriter->startElement('row');
991
						$objWriter->writeAttribute('r',	$currentRow);
992
						$objWriter->writeAttribute('spans',	'1:' . $colCount);
993
 
994
						// Row dimensions
995
						if ($rowDimension->getRowHeight() >= 0) {
996
							$objWriter->writeAttribute('customHeight',	'1');
997
							$objWriter->writeAttribute('ht',			PHPExcel_Shared_String::FormatNumber($rowDimension->getRowHeight()));
998
						}
999
 
1000
						// Row visibility
1001
						if ($rowDimension->getVisible() == false) {
1002
							$objWriter->writeAttribute('hidden',		'true');
1003
						}
1004
 
1005
						// Collapsed
1006
						if ($rowDimension->getCollapsed() == true) {
1007
							$objWriter->writeAttribute('collapsed',		'true');
1008
						}
1009
 
1010
						// Outline level
1011
						if ($rowDimension->getOutlineLevel() > 0) {
1012
							$objWriter->writeAttribute('outlineLevel',	$rowDimension->getOutlineLevel());
1013
						}
1014
 
1015
						// Style
1016
						if ($rowDimension->getXfIndex() !== null) {
1017
							$objWriter->writeAttribute('s',	$rowDimension->getXfIndex());
1018
							$objWriter->writeAttribute('customFormat', '1');
1019
						}
1020
 
1021
						// Write cells
1022
						if (isset($cellsByRow[$currentRow])) {
1023
							foreach($cellsByRow[$currentRow] as $cellAddress) {
1024
								// Write cell
1025
								$this->_writeCell($objWriter, $pSheet, $cellAddress, $pStringTable, $aFlippedStringTable);
1026
							}
1027
						}
1028
 
1029
						// End row
1030
						$objWriter->endElement();
1031
					}
1032
				}
1033
 
1034
			$objWriter->endElement();
1035
		} else {
1036
			throw new PHPExcel_Writer_Exception("Invalid parameters passed.");
1037
		}
1038
	}
1039
 
1040
	/**
1041
	 * Write Cell
1042
	 *
1043
	 * @param	PHPExcel_Shared_XMLWriter	$objWriter				XML Writer
1044
	 * @param	PHPExcel_Worksheet			$pSheet					Worksheet
1045
	 * @param	PHPExcel_Cell				$pCellAddress			Cell Address
1046
	 * @param	string[]					$pStringTable			String table
1047
	 * @param	string[]					$pFlippedStringTable	String table (flipped), for faster index searching
1048
	 * @throws	PHPExcel_Writer_Exception
1049
	 */
1050
	private function _writeCell(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null, $pCellAddress = null, $pStringTable = null, $pFlippedStringTable = null)
1051
	{
1052
		if (is_array($pStringTable) && is_array($pFlippedStringTable)) {
1053
			// Cell
1054
			$pCell = $pSheet->getCell($pCellAddress);
1055
			$objWriter->startElement('c');
1056
			$objWriter->writeAttribute('r', $pCellAddress);
1057
 
1058
			// Sheet styles
1059
			if ($pCell->getXfIndex() != '') {
1060
				$objWriter->writeAttribute('s', $pCell->getXfIndex());
1061
			}
1062
 
1063
			// If cell value is supplied, write cell value
1064
			$cellValue = $pCell->getValue();
1065
			if (is_object($cellValue) || $cellValue !== '') {
1066
				// Map type
1067
				$mappedType = $pCell->getDataType();
1068
 
1069
				// Write data type depending on its type
1070
				switch (strtolower($mappedType)) {
1071
					case 'inlinestr':	// Inline string
1072
					case 's':			// String
1073
					case 'b':			// Boolean
1074
						$objWriter->writeAttribute('t', $mappedType);
1075
						break;
1076
					case 'f':			// Formula
1077
						$calculatedValue = ($this->getParentWriter()->getPreCalculateFormulas()) ?
1078
						    $pCell->getCalculatedValue() :
1079
						    $cellValue;
1080
						if (is_string($calculatedValue)) {
1081
							$objWriter->writeAttribute('t', 'str');
1082
						}
1083
						break;
1084
					case 'e':			// Error
1085
						$objWriter->writeAttribute('t', $mappedType);
1086
				}
1087
 
1088
				// Write data depending on its type
1089
				switch (strtolower($mappedType)) {
1090
					case 'inlinestr':	// Inline string
1091
						if (! $cellValue instanceof PHPExcel_RichText) {
1092
							$objWriter->writeElement('t', PHPExcel_Shared_String::ControlCharacterPHP2OOXML( htmlspecialchars($cellValue) ) );
1093
						} else if ($cellValue instanceof PHPExcel_RichText) {
1094
							$objWriter->startElement('is');
1095
							$this->getParentWriter()->getWriterPart('stringtable')->writeRichText($objWriter, $cellValue);
1096
							$objWriter->endElement();
1097
						}
1098
 
1099
						break;
1100
					case 's':			// String
1101
						if (! $cellValue instanceof PHPExcel_RichText) {
1102
							if (isset($pFlippedStringTable[$cellValue])) {
1103
								$objWriter->writeElement('v', $pFlippedStringTable[$cellValue]);
1104
							}
1105
						} else if ($cellValue instanceof PHPExcel_RichText) {
1106
							$objWriter->writeElement('v', $pFlippedStringTable[$cellValue->getHashCode()]);
1107
						}
1108
 
1109
						break;
1110
					case 'f':			// Formula
1111
						$attributes = $pCell->getFormulaAttributes();
1112
						if($attributes['t'] == 'array') {
1113
							$objWriter->startElement('f');
1114
							$objWriter->writeAttribute('t', 'array');
1115
							$objWriter->writeAttribute('ref', $pCellAddress);
1116
							$objWriter->writeAttribute('aca', '1');
1117
							$objWriter->writeAttribute('ca', '1');
1118
							$objWriter->text(substr($cellValue, 1));
1119
							$objWriter->endElement();
1120
						} else {
1121
							$objWriter->writeElement('f', substr($cellValue, 1));
1122
						}
1123
						if ($this->getParentWriter()->getOffice2003Compatibility() === false) {
1124
							if ($this->getParentWriter()->getPreCalculateFormulas()) {
1125
//								$calculatedValue = $pCell->getCalculatedValue();
1126
								if (!is_array($calculatedValue) && substr($calculatedValue, 0, 1) != '#') {
1127
									$objWriter->writeElement('v', PHPExcel_Shared_String::FormatNumber($calculatedValue));
1128
								} else {
1129
									$objWriter->writeElement('v', '0');
1130
								}
1131
							} else {
1132
								$objWriter->writeElement('v', '0');
1133
							}
1134
						}
1135
						break;
1136
					case 'n':			// Numeric
1137
						// force point as decimal separator in case current locale uses comma
1138
						$objWriter->writeElement('v', str_replace(',', '.', $cellValue));
1139
						break;
1140
					case 'b':			// Boolean
1141
						$objWriter->writeElement('v', ($cellValue ? '1' : '0'));
1142
						break;
1143
					case 'e':			// Error
1144
						if (substr($cellValue, 0, 1) == '=') {
1145
							$objWriter->writeElement('f', substr($cellValue, 1));
1146
							$objWriter->writeElement('v', substr($cellValue, 1));
1147
						} else {
1148
							$objWriter->writeElement('v', $cellValue);
1149
						}
1150
 
1151
						break;
1152
				}
1153
			}
1154
 
1155
			$objWriter->endElement();
1156
		} else {
1157
			throw new PHPExcel_Writer_Exception("Invalid parameters passed.");
1158
		}
1159
	}
1160
 
1161
	/**
1162
	 * Write Drawings
1163
	 *
1164
	 * @param	PHPExcel_Shared_XMLWriter	$objWriter		XML Writer
1165
	 * @param	PHPExcel_Worksheet			$pSheet			Worksheet
1166
	 * @param	boolean						$includeCharts	Flag indicating if we should include drawing details for charts
1167
	 * @throws	PHPExcel_Writer_Exception
1168
	 */
1169
	private function _writeDrawings(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null, $includeCharts = FALSE)
1170
	{
1171
		$chartCount = ($includeCharts) ? $pSheet->getChartCollection()->count() : 0;
1172
		// If sheet contains drawings, add the relationships
1173
		if (($pSheet->getDrawingCollection()->count() > 0) ||
1174
			($chartCount > 0)) {
1175
			$objWriter->startElement('drawing');
1176
			$objWriter->writeAttribute('r:id', 'rId1');
1177
			$objWriter->endElement();
1178
		}
1179
	}
1180
 
1181
	/**
1182
	 * Write LegacyDrawing
1183
	 *
1184
	 * @param	PHPExcel_Shared_XMLWriter		$objWriter		XML Writer
1185
	 * @param	PHPExcel_Worksheet				$pSheet			Worksheet
1186
	 * @throws	PHPExcel_Writer_Exception
1187
	 */
1188
	private function _writeLegacyDrawing(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null)
1189
	{
1190
		// If sheet contains comments, add the relationships
1191
		if (count($pSheet->getComments()) > 0) {
1192
			$objWriter->startElement('legacyDrawing');
1193
			$objWriter->writeAttribute('r:id', 'rId_comments_vml1');
1194
			$objWriter->endElement();
1195
		}
1196
	}
1197
 
1198
	/**
1199
	 * Write LegacyDrawingHF
1200
	 *
1201
	 * @param	PHPExcel_Shared_XMLWriter		$objWriter		XML Writer
1202
	 * @param	PHPExcel_Worksheet				$pSheet			Worksheet
1203
	 * @throws	PHPExcel_Writer_Exception
1204
	 */
1205
	private function _writeLegacyDrawingHF(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null)
1206
	{
1207
		// If sheet contains images, add the relationships
1208
		if (count($pSheet->getHeaderFooter()->getImages()) > 0) {
1209
			$objWriter->startElement('legacyDrawingHF');
1210
			$objWriter->writeAttribute('r:id', 'rId_headerfooter_vml1');
1211
			$objWriter->endElement();
1212
		}
1213
	}
1214
}