PageRenderTime 74ms CodeModel.GetById 19ms app.highlight 47ms RepoModel.GetById 1ms app.codeStats 1ms

/branches/v1.6.2/Classes/PHPExcel/Writer/HTML.php

#
PHP | 742 lines | 370 code | 99 blank | 273 comment | 68 complexity | dad51a8844e8c1bbd7ce91ab4c43b6b5 MD5 | raw file
  1<?php
  2/**
  3 * PHPExcel
  4 *
  5 * Copyright (c) 2006 - 2008 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
 23 * @copyright  Copyright (c) 2006 - 2008 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/** PHPExcel_IWriter */
 30require_once 'PHPExcel/Writer/IWriter.php';
 31
 32/** PHPExcel_Cell */
 33require_once 'PHPExcel/Cell.php';
 34
 35/** PHPExcel_RichText */
 36require_once 'PHPExcel/RichText.php';
 37
 38/** PHPExcel_Shared_Drawing */
 39require_once 'PHPExcel/Shared/Drawing.php';
 40
 41/** PHPExcel_Shared_String */
 42require_once 'PHPExcel/Shared/String.php';
 43
 44/** PHPExcel_HashTable */
 45require_once 'PHPExcel/HashTable.php';
 46
 47
 48/**
 49 * PHPExcel_Writer_HTML
 50 *
 51 * @category   PHPExcel
 52 * @package    PHPExcel_Writer
 53 * @copyright  Copyright (c) 2006 - 2008 PHPExcel (http://www.codeplex.com/PHPExcel)
 54 */
 55class PHPExcel_Writer_HTML implements PHPExcel_Writer_IWriter {
 56	/**
 57	 * PHPExcel object
 58	 *
 59	 * @var PHPExcel
 60	 */
 61	private $_phpExcel;
 62	
 63	/**
 64	 * Sheet index to write
 65	 * 
 66	 * @var int
 67	 */
 68	private $_sheetIndex;
 69	
 70	/**
 71	 * Pre-calculate formulas
 72	 *
 73	 * @var boolean
 74	 */
 75	private $_preCalculateFormulas = true;
 76	
 77	/**
 78	 * Images root
 79	 *
 80	 * @var string
 81	 */
 82	private $_imagesRoot = '.';
 83	
 84	/**
 85	 * Create a new PHPExcel_Writer_HTML
 86	 *
 87	 * @param 	PHPExcel	$phpExcel	PHPExcel object
 88	 */
 89	public function __construct(PHPExcel $phpExcel) {
 90		$this->_phpExcel = $phpExcel;
 91		$this->_sheetIndex = 0;
 92		$this->_imagesRoot = '.';
 93	}
 94	
 95	/**
 96	 * Save PHPExcel to file
 97	 *
 98	 * @param 	string 		$pFileName
 99	 * @throws 	Exception
100	 */	
101	public function save($pFilename = null) {
102		// Open file
103		$fileHandle = fopen($pFilename, 'w');
104		if ($fileHandle === false) {
105			throw new Exception("Could not open file $pFilename for writing.");
106		}
107		
108		// Fetch sheets
109		$sheets = array();
110		if (is_null($this->_sheetIndex)) {
111			$sheets = $this->_phpExcel->getAllSheets();
112		} else {
113			$sheets[] = $this->_phpExcel->getSheet($this->_sheetIndex);
114		}
115		
116		// Write headers
117		$this->_writeHTMLHeader($fileHandle);
118		$this->_writeStyles($fileHandle, $sheets);
119		
120		// Loop all sheets
121		foreach ($sheets as $sheet) {
122			// Calculate hash code
123			$hashCode = $sheet->getHashCode();
124				
125			// Get cell collection
126			$cellCollection = $sheet->getCellCollection();
127			
128			// Write header
129			$this->_writeTableHeader($fileHandle, $hashCode);
130			
131	    	// Get worksheet dimension
132	    	$dimension = explode(':', $sheet->calculateWorksheetDimension());
133	    	$dimension[0] = PHPExcel_Cell::coordinateFromString($dimension[0]);
134	    	$dimension[0][0] = PHPExcel_Cell::columnIndexFromString($dimension[0][0]) - 1;
135	    	$dimension[1] = PHPExcel_Cell::coordinateFromString($dimension[1]);
136	    	$dimension[1][0] = PHPExcel_Cell::columnIndexFromString($dimension[1][0]) - 1;
137	
138	    	// Loop trough cells
139	    	$rowData = null;
140	    	for ($row = $dimension[0][1]; $row <= $dimension[1][1]; $row++) {
141				// Start a new row
142				$rowData = array();
143							
144				// Loop trough columns
145	    		for ($column = $dimension[0][0]; $column <= $dimension[1][0]; $column++) {
146	    			// Cell exists?
147	    			if ($sheet->cellExistsByColumnAndRow($column, $row)) {
148	    				$rowData[$column] = $sheet->getCellByColumnAndRow($column, $row);
149	    			} else {
150	    				$rowData[$column] = '';
151	    			}
152	    		}
153	
154	    		// Write row
155				$this->_writeRow($fileHandle, $sheet, $rowData, $row - 1);
156	    	}
157				
158			// Write footer
159			$this->_writeTableFooter($fileHandle);
160		}
161		
162		// Write footer
163		$this->_writeHTMLFooter($fileHandle);
164		
165		
166		// Close file
167		fclose($fileHandle);
168	}
169 	
170	/**
171	 * Map VAlign
172	 */	
173	private function _mapVAlign($vAlign) {
174		switch ($vAlign) {
175			case PHPExcel_Style_Alignment::VERTICAL_BOTTOM: return 'bottom';
176			case PHPExcel_Style_Alignment::VERTICAL_TOP: return 'top';
177			case PHPExcel_Style_Alignment::VERTICAL_CENTER:
178			case PHPExcel_Style_Alignment::VERTICAL_JUSTIFY: return 'middle';
179			default: return ' baseline';
180		}
181	}
182	
183	/**
184	 * Map HAlign
185	 */	
186	private function _mapHAlign($hAlign) {
187		switch ($hAlign) {
188			case PHPExcel_Style_Alignment::HORIZONTAL_GENERAL:
189			case PHPExcel_Style_Alignment::HORIZONTAL_LEFT: return 'left';
190			case PHPExcel_Style_Alignment::HORIZONTAL_RIGHT: return 'right';
191			case PHPExcel_Style_Alignment::HORIZONTAL_CENTER: return 'center';
192			case PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY: return 'justify';
193			default: return ' baseline';
194		}
195	}
196	
197	/**
198	 * Map border style
199	 */	
200	private function _mapBorderStyle($borderStyle) {
201		switch ($borderStyle) {
202			case PHPExcel_Style_Border::BORDER_NONE: return '0px';
203			case PHPExcel_Style_Border::BORDER_DASHED: return '1px dashed';
204			case PHPExcel_Style_Border::BORDER_DOTTED: return '1px dotted';
205			case PHPExcel_Style_Border::BORDER_THICK: return '2px solid';
206			default: return '1px solid'; // map others to thin
207		}
208	}
209	
210	/**
211	 * Get sheet index
212	 * 
213	 * @return int
214	 */
215	public function getSheetIndex() {
216		return $this->_sheetIndex;
217	}
218	
219	/**
220	 * Set sheet index
221	 * 
222	 * @param	int		$pValue		Sheet index
223	 */
224	public function setSheetIndex($pValue = 0) {
225		$this->_sheetIndex = $pValue;
226	}
227	
228	/**
229	 * Write all sheets (resets sheetIndex to NULL)
230	 */
231	public function writeAllSheets() {
232		$this->_sheetIndex = null;
233	}
234	
235	/**
236	 * Write HTML header to file
237	 * 
238	 * @param	mixed	$pFileHandle	PHP filehandle
239	 * @throws	Exception
240	 */
241	private function _writeHTMLHeader($pFileHandle = null) {
242		if (!is_null($pFileHandle)) {
243			// Construct HTML
244			$html = '';
245			$html .= '<!-- Generated by PHPExcel - http://www.phpexcel.net -->' . "\r\n";
246			$html .= '<html>' . "\r\n";
247			$html .= '  <head>' . "\r\n";
248			$html .= '    <title>' . $this->_phpExcel->getProperties()->getTitle() . '</title>' . "\r\n";
249			$html .= '  </head>' . "\r\n";
250			$html .= '' . "\r\n";
251			$html .= '  <body>' . "\r\n";
252
253			// Write to file
254			fwrite($pFileHandle, $html);
255		} else {
256			throw new Exception("Invalid parameters passed.");
257		}
258	}
259
260	/**
261	 * Write images to file
262	 * 
263	 * @param	mixed				$pFileHandle	PHP filehandle
264	 * @param	PHPExcel_Worksheet 	$pSheet			PHPExcel_Worksheet
265	 * @param	string				$coordinates	Cell coordinates
266	 * @throws	Exception
267	 */
268	private function _writeImageInCell($pFileHandle = null, PHPExcel_Worksheet $pSheet, $coordinates) {
269		if (!is_null($pFileHandle)) {
270			// Construct HTML
271			$html = '';
272
273			// Write images
274			foreach ($pSheet->getDrawingCollection() as $drawing) {
275				if ($drawing instanceof PHPExcel_Worksheet_BaseDrawing) {
276					if ($drawing->getCoordinates() == $coordinates) {
277						$filename = $drawing->getPath();
278						
279						// Strip off eventual '.'
280						if (substr($filename, 0, 1) == '.') {
281							$filename = substr($filename, 1);
282						}
283						
284						// Prepend images root
285						$filename = $this->getImagesRoot() . $filename;
286
287						$html .= "\r\n";
288						$html .= '        <img  style="position: relative; left: ' . $drawing->getOffsetX() . 'px; top: ' . $drawing->getOffsetY() . 'px; width: ' . $drawing->getWidth() . 'px; height: ' . $drawing->getHeight() . 'px;" src="' . $filename . '" border="0">' . "\r\n";
289					}
290				}
291			}
292
293			// Write to file
294			fwrite($pFileHandle, $html);
295		} else {
296			throw new Exception("Invalid parameters passed.");
297		}
298	}
299	
300	/**
301	 * Write styles to file
302	 * 
303	 * @param	mixed					$pFileHandle	PHP filehandle
304	 * @param	PHPExcel_Worksheet[] 	$pSheets		Array of PHPExcel_Worksheet
305	 * @throws	Exception
306	 */
307	private function _writeStyles($pFileHandle = null, $pSheets) {
308		if (!is_null($pFileHandle) && is_array($pSheets)) {
309			// Construct HTML
310			$html = '';
311			
312			// Start styles
313			$html .= '    <style>' . "\r\n";
314			$html .= '    <!--' . "\r\n";
315			$html .= '      html {' . "\r\n";
316			$html .= '        font-family: Calibri, Arial, Helvetica, Sans Serif;' . "\r\n";
317			$html .= '        font-size: 10pt;' . "\r\n";
318			$html .= '        background-color: white;' . "\r\n";
319			$html .= '      }' . "\r\n";
320			
321			// Write styles per sheet
322			foreach ($pSheets as $sheet) {
323				// Calculate hash code
324				$hashCode = $sheet->getHashCode();
325				
326				// Write styles
327				$html .= '      table.sheet' . $hashCode . ', table.sheet' . $hashCode . ' td {' . "\r\n";
328				if ($sheet->getShowGridlines()) {
329					$html .= '        border: 1px dotted black;' . "\r\n";
330				}
331				$html .= '        page-break-after: always;' . "\r\n";
332				$html .= '      }' . "\r\n";				
333			
334				// Calculate column widths
335				$sheet->calculateColumnWidths();
336				foreach ($sheet->getColumnDimensions() as $columnDimension) {
337					$column = PHPExcel_Cell::columnIndexFromString($columnDimension->getColumnIndex()) - 1;
338					
339					$html .= '      table.sheet' . $hashCode . ' td.column' . $column  . ' {' . "\r\n";
340					$html .= '        width: ' . PHPExcel_Shared_Drawing::cellDimensionToPixels($columnDimension->getWidth()) . 'px;' . "\r\n";
341					if ($columnDimension->getVisible() === false) {
342						$html .= '        display: none;' . "\r\n";
343						$html .= '        visibility: hidden;' . "\r\n";
344					}
345					$html .= '      }' . "\r\n";
346				}
347			
348				// Calculate row heights
349				foreach ($sheet->getRowDimensions() as $rowDimension) {
350					$html .= '      table.sheet' . $hashCode . ' tr.row' . ($rowDimension->getRowIndex() - 1)  . ' {' . "\r\n";
351					// height is disproportionately large
352					$px_height = round( PHPExcel_Shared_Drawing::cellDimensionToPixels($rowDimension->getRowHeight()) /12 );
353					$html .= '        height: ' . $px_height . 'px;' . "\r\n";
354					if ($rowDimension->getVisible() === false) {
355						$html .= '        display: none;' . "\r\n";
356						$html .= '        visibility: hidden;' . "\r\n";
357					}
358					$html .= '      }' . "\r\n";
359				}
360			
361				// Calculate cell style hashes
362				$cellStyleHashes = new PHPExcel_HashTable();
363				$cellStyleHashes->addFromSource( $sheet->getStyles() );
364				for ($i = 0; $i < $cellStyleHashes->count(); $i++) {
365					$html .= $this->_createCSSStyle( $cellStyleHashes->getByIndex($i) );
366				}
367			}
368			
369			// End styles
370			$html .= '    -->' . "\r\n";
371			$html .= '    </style>' . "\r\n";
372
373			// Write to file
374			fwrite($pFileHandle, $html);
375		} else {
376			throw new Exception("Invalid parameters passed.");
377		}
378	}
379	
380	/**
381	 * Create CSS style
382	 * 
383	 * @param	PHPExcel_Style 		$pStyle			PHPExcel_Style
384	 * @return	string
385	 */
386	private function _createCSSStyle(PHPExcel_Style $pStyle) {
387		// Construct HTML
388		$html = '';
389			
390		// Create CSS
391		$html .= '      .style' . $pStyle->getHashCode() . ' {' . "\r\n";
392		$html .= $this->_createCSSStyleAlignment($pStyle->getAlignment());
393		$html .= $this->_createCSSStyleFont($pStyle->getFont());
394		$html .= $this->_createCSSStyleBorders($pStyle->getBorders());
395		$html .= $this->_createCSSStyleFill($pStyle->getFill());
396		$html .= '      }' . "\r\n";
397
398		// Return
399		return $html;
400	}
401	
402	/**
403	 * Create CSS style (PHPExcel_Style_Alignment)
404	 * 
405	 * @param	PHPExcel_Style_Alignment 		$pStyle			PHPExcel_Style_Alignment
406	 * @return	string
407	 */
408	private function _createCSSStyleAlignment(PHPExcel_Style_Alignment $pStyle) {
409		// Construct HTML
410		$html = '';
411			
412		// Create CSS
413		$html .= '        vertical-align: ' 	. $this->_mapVAlign($pStyle->getVertical()) . ';' . "\r\n";
414		$html .= '        text-align: ' 		. $this->_mapHAlign($pStyle->getHorizontal()) . ';' . "\r\n";
415		
416		// Return
417		return $html;
418	}
419	
420	/**
421	 * Create CSS style (PHPExcel_Style_Font)
422	 * 
423	 * @param	PHPExcel_Style_Font 		$pStyle			PHPExcel_Style_Font
424	 * @return	string
425	 */
426	private function _createCSSStyleFont(PHPExcel_Style_Font $pStyle) {
427		// Construct HTML
428		$html = '';
429			
430		// Create CSS
431		if ($pStyle->getBold()) {
432			$html .= '        font-weight: bold;' . "\r\n";
433		}
434		if ($pStyle->getUnderline() != PHPExcel_Style_Font::UNDERLINE_NONE && $pStyle->getStriketrough()) {
435			$html .= '        text-decoration: underline line-through;' . "\r\n";
436		} else if ($pStyle->getUnderline() != PHPExcel_Style_Font::UNDERLINE_NONE) {
437			$html .= '        text-decoration: underline;' . "\r\n";
438		} else if ($pStyle->getStriketrough()) {
439			$html .= '        text-decoration: line-through;' . "\r\n";
440		}
441		if ($pStyle->getItalic()) {
442			$html .= '        font-style: italic;' . "\r\n";
443		}
444				
445		$html .= '        color: ' 				. '#' . $pStyle->getColor()->getRGB() . ';' . "\r\n";
446		$html .= '        font-family: ' 		. $pStyle->getName() . ';' . "\r\n";
447		$html .= '        font-size: ' 			. $pStyle->getSize() . 'pt;' . "\r\n";
448	
449		// Return
450		return $html;
451	}
452	
453	/**
454	 * Create CSS style (PHPExcel_Style_Borders)
455	 * 
456	 * @param	PHPExcel_Style_Borders 		$pStyle			PHPExcel_Style_Borders
457	 * @return	string
458	 */
459	private function _createCSSStyleBorders(PHPExcel_Style_Borders $pStyle) {
460		// Construct HTML
461		$html = '';
462			
463		// Create CSS	
464		$html .= '        border-bottom: ' 		. $this->_createCSSStyleBorder($pStyle->getBottom()) . ';' . "\r\n";
465		$html .= '        border-top: ' 		. $this->_createCSSStyleBorder($pStyle->getTop()) . ';' . "\r\n";
466		$html .= '        border-left: ' 		. $this->_createCSSStyleBorder($pStyle->getLeft()) . ';' . "\r\n";
467		$html .= '        border-right: ' 		. $this->_createCSSStyleBorder($pStyle->getRight()) . ';' . "\r\n";
468
469		// Return
470		return $html;
471	}
472	
473	/**
474	 * Create CSS style (PHPExcel_Style_Border)
475	 * 
476	 * @param	PHPExcel_Style_Border		$pStyle			PHPExcel_Style_Border
477	 * @return	string
478	 */
479	private function _createCSSStyleBorder(PHPExcel_Style_Border $pStyle) {
480		// Construct HTML
481		$html = '';
482			
483		// Create CSS
484		$html .= $this->_mapBorderStyle($pStyle->getBorderStyle()) . ' #' . $pStyle->getColor()->getRGB();
485		
486		// Return
487		return $html;
488	}
489	
490	/**
491	 * Create CSS style (PHPExcel_Style_Fill)
492	 * 
493	 * @param	PHPExcel_Style_Fill		$pStyle			PHPExcel_Style_Fill
494	 * @return	string
495	 */
496	private function _createCSSStyleFill(PHPExcel_Style_Fill $pStyle) {
497		// Construct HTML
498		$html = '';
499			
500		// Create CSS
501		$html .= '        background-color: ' 	. '#' . $pStyle->getStartColor()->getRGB() . ';' . "\r\n";
502
503		// Return
504		return $html;
505	}
506	
507	/**
508	 * Write HTML footer to file
509	 * 
510	 * @param	mixed	$pFileHandle	PHP filehandle
511	 * @throws	Exception
512	 */
513	private function _writeHTMLFooter($pFileHandle = null) {
514		if (!is_null($pFileHandle)) {
515			// Construct HTML
516			$html = '';
517			$html .= '  </body>' . "\r\n";
518			$html .= '</html>' . "\r\n";			
519
520			// Write to file
521			fwrite($pFileHandle, $html);
522		} else {
523			throw new Exception("Invalid parameters passed.");
524		}
525	}
526
527	/**
528	 * Write table header to file
529	 * 
530	 * @param	mixed	$pFileHandle	PHP filehandle
531	 * @param 	string	$pIdentifier	Identifier for the table
532	 * @throws	Exception
533	 */
534	private function _writeTableHeader($pFileHandle = null, $pIdentifier = '') {
535		if (!is_null($pFileHandle)) {
536			// Construct HTML
537			$html = '';
538			$html .= '    <table border="0" cellpadding="0" cellspacing="0" class="sheet' . $pIdentifier . '">' . "\r\n";
539
540			// Write to file
541			fwrite($pFileHandle, $html);
542		} else {
543			throw new Exception("Invalid parameters passed.");
544		}
545	}
546	
547	/**
548	 * Write table footer to file
549	 * 
550	 * @param	mixed	$pFileHandle	PHP filehandle
551	 * @throws	Exception
552	 */
553	private function _writeTableFooter($pFileHandle = null) {
554		if (!is_null($pFileHandle)) {
555			// Construct HTML
556			$html = '';
557			$html .= '    </table>' . "\r\n";		
558
559			// Write to file
560			fwrite($pFileHandle, $html);
561		} else {
562			throw new Exception("Invalid parameters passed.");
563		}
564	}
565	
566	/**
567	 * Write row to HTML file
568	 * 
569	 * @param	mixed				$pFileHandle	PHP filehandle
570	 * @param	PHPExcel_Worksheet 	$pSheet			PHPExcel_Worksheet
571	 * @param	array				$pValues		Array containing cells in a row
572	 * @param	int					$pRow			Row number
573	 * @throws	Exception
574	 */
575	private function _writeRow($pFileHandle = null, PHPExcel_Worksheet $pSheet, $pValues = null, $pRow = 0) {
576		if (!is_null($pFileHandle) && is_array($pValues)) {	
577			// Write row start
578			fwrite($pFileHandle, '        <tr class="row' . $pRow . '">' . "\r\n");
579			
580			// Write cells
581			$colNum = 0;
582			foreach ($pValues as $cell) {
583				$cellData = '&nbsp;';
584				$cssClass = 'column' . $colNum;
585				$colSpan = 1;
586				$rowSpan = 1;
587				$writeCell = true;	// Write cell
588				
589				// PHPExcel_Cell
590				if ($cell instanceof PHPExcel_Cell) {
591					// Value
592					if ($cell->getValue() instanceof PHPExcel_RichText) {
593						// Loop trough rich text elements
594						$elements = $cell->getValue()->getRichTextElements();
595						foreach ($elements as $element) {
596							// Rich text start?
597							if ($element instanceof PHPExcel_RichText_Run) {
598								$cellData .= '<span style="' . 
599									str_replace("\r\n", '',
600										$this->_createCSSStyleFont($element->getFont())
601									) . '">';
602							}
603							
604							// Decode UTF8 data
605							$cellText = $element->getText();
606							if (PHPExcel_Shared_String::IsUTF8($cellText)) {
607								$cellData .= utf8_decode($cellText);
608							}
609							
610							if ($element instanceof PHPExcel_RichText_Run) {
611								$cellData .= '</span>';
612							}
613						}
614					} else {
615						if ($this->_preCalculateFormulas) {
616							$cellData = PHPExcel_Style_NumberFormat::toFormattedString(
617								$cell->getCalculatedValue(),
618								$pSheet->getstyle( $cell->getCoordinate() )->getNumberFormat()->getFormatCode()
619							);
620						} else {
621							$cellData = PHPExcel_Style_NumberFormat::ToFormattedString(
622								$cell->getValue(),
623								$pSheet->getstyle( $cell->getCoordinate() )->getNumberFormat()->getFormatCode()
624							);
625						}
626
627						// Decode UTF8 data
628						if (PHPExcel_Shared_String::IsUTF8($cellData)) {
629							$cellData = utf8_decode($cellData);
630						}
631					}
632					
633					// Check value
634					if ($cellData == '') {
635						$cellData = '&nbsp;';
636					}
637					
638					// Extend CSS class?
639					if (array_key_exists($cell->getCoordinate(), $pSheet->getStyles())) {
640						$cssClass .= ' style' . $pSheet->getStyle($cell->getCoordinate())->getHashCode();
641					}
642				} else {
643					$cell = new PHPExcel_Cell(
644						PHPExcel_Cell::stringFromColumnIndex($colNum),
645						($pRow + 1),
646						'',
647						null,
648						null
649					);
650				}
651				
652				// Hyperlink?
653				if ($cell->hasHyperlink() && !$cell->getHyperlink()->isInternal()) {
654					$cellData = '<a href="' . $cell->getHyperlink()->getUrl() . '" title="' . $cell->getHyperlink()->getTooltip() . '">' . $cellData . '</a>';
655				}
656				
657				// Column/rowspan
658				foreach ($pSheet->getMergeCells() as $cells) {
659					if ($cell->isInRange($cells)) {
660						list($first, ) = PHPExcel_Cell::splitRange($cells);
661						
662						if ($first == $cell->getCoordinate()) {
663							list($colSpan, $rowSpan) = PHPExcel_Cell::rangeDimension($cells);
664						} else {
665							$writeCell = false;
666						}
667							
668						break;
669					}
670				}
671				
672				// Write
673				if ($writeCell) {
674					// Column start
675					fwrite($pFileHandle, '          <td');
676							fwrite($pFileHandle, ' class="' . $cssClass . '"');
677						if ($colSpan > 1) {
678							fwrite($pFileHandle, ' colspan="' . $colSpan . '"');
679						}
680						if ($rowSpan > 1) {
681							fwrite($pFileHandle, ' rowspan="' . $rowSpan . '"');
682						}
683					fwrite($pFileHandle, '>');
684					
685					// Image?
686					$this->_writeImageInCell($pFileHandle, $pSheet, $cell->getCoordinate());
687
688					// Cell data
689					fwrite($pFileHandle, $cellData);
690					
691					// Column end
692					fwrite($pFileHandle, '</td>' . "\r\n");
693				}
694				
695				// Next column
696				$colNum++;
697			}
698			
699			// Write row end
700			fwrite($pFileHandle, '        </tr>' . "\r\n");
701		} else {
702			throw new Exception("Invalid parameters passed.");
703		}
704	}
705	
706
707    /**
708     * Get Pre-Calculate Formulas
709     *
710     * @return boolean
711     */
712    public function getPreCalculateFormulas() {
713    	return $this->_preCalculateFormulas;
714    }
715    
716    /**
717     * Set Pre-Calculate Formulas
718     *
719     * @param boolean $pValue	Pre-Calculate Formulas?
720     */
721    public function setPreCalculateFormulas($pValue = true) {
722    	$this->_preCalculateFormulas = $pValue;
723    }
724    
725    /**
726     * Get images root
727     *
728     * @return string
729     */
730    public function getImagesRoot() {
731    	return $this->_imagesRoot;
732    }
733    
734    /**
735     * Set images root
736     *
737     * @param string $pValue
738     */
739    public function setImagesRoot($pValue = '.') {
740    	$this->_imagesRoot = $pValue;
741    }
742}