Write docProps/app.xml to XML format

@param     PHPExcel    $pPHPExcel
@return     string         XML Output
@throws     PHPExcel_Writer_Exception
323624
public function writeDocPropsApp(PHPExcel $pPHPExcel = null)
    {
        // Create XML writer
        $objWriter = null;
        if ($this->getParentWriter()->getUseDiskCaching()) {
            $objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
        } else {
            $objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY);
        }

        // XML header
        $objWriter->startDocument('1.0', 'UTF-8', 'yes');

        // Properties
        $objWriter->startElement('Properties');
        $objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/officeDocument/2006/extended-properties');
        $objWriter->writeAttribute('xmlns:vt', 'http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes');

        // Application
        $objWriter->writeElement('Application', 'Microsoft Excel');

        // DocSecurity
        $objWriter->writeElement('DocSecurity', '0');

        // ScaleCrop
        $objWriter->writeElement('ScaleCrop', 'false');

        // HeadingPairs
        $objWriter->startElement('HeadingPairs');

        // Vector
        $objWriter->startElement('vt:vector');
        $objWriter->writeAttribute('size', '2');
        $objWriter->writeAttribute('baseType', 'variant');

        // Variant
        $objWriter->startElement('vt:variant');
        $objWriter->writeElement('vt:lpstr', 'Worksheets');
        $objWriter->endElement();

        // Variant
        $objWriter->startElement('vt:variant');
        $objWriter->writeElement('vt:i4', $pPHPExcel->getSheetCount());
        $objWriter->endElement();

        $objWriter->endElement();

        $objWriter->endElement();

        // TitlesOfParts
        $objWriter->startElement('TitlesOfParts');

        // Vector
        $objWriter->startElement('vt:vector');
        $objWriter->writeAttribute('size', $pPHPExcel->getSheetCount());
        $objWriter->writeAttribute('baseType', 'lpstr');

        $sheetCount = $pPHPExcel->getSheetCount();
        for ($i = 0; $i < $sheetCount; ++$i) {
            $objWriter->writeElement('vt:lpstr', $pPHPExcel->getSheet($i)->getTitle());
        }

        $objWriter->endElement();

        $objWriter->endElement();

        // Company
        $objWriter->writeElement('Company', $pPHPExcel->getProperties()->getCompany());

        // Company
        $objWriter->writeElement('Manager', $pPHPExcel->getProperties()->getManager());

        // LinksUpToDate
        $objWriter->writeElement('LinksUpToDate', 'false');

        // SharedDoc
        $objWriter->writeElement('SharedDoc', 'false');

        // HyperlinksChanged
        $objWriter->writeElement('HyperlinksChanged', 'false');

        // AppVersion
        $objWriter->writeElement('AppVersion', '12.0000');

        $objWriter->endElement();

        // Return
        return $objWriter->getData();
    }
1229324
public function createWorkbookFile($worksheets)
    {
        $workbookXmlFileContents = <<<EOD
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
    <sheets>
EOD;

        /** @noinspection PhpUnnecessaryFullyQualifiedNameInspection */
        $escaper = \Box\Spout\Common\Escaper\XLSX::getInstance();

        /** @var Worksheet $worksheet */
        foreach ($worksheets as $worksheet) {
            $worksheetName = $worksheet->getExternalSheet()->getName();
            $worksheetId = $worksheet->getId();
            $workbookXmlFileContents .= '<sheet name="' . $escaper->escape($worksheetName) . '" sheetId="' . $worksheetId . '" r:id="rIdSheet' . $worksheetId . '"/>';
        }

        $workbookXmlFileContents .= <<<EOD
    </sheets>
</workbook>
EOD;

        $this->createFileWithContents($this->xlFolder, self::WORKBOOK_XML_FILE_NAME, $workbookXmlFileContents);

        return $this;
    }
318448
public function writeRibbonRelationships(PHPExcel $pPHPExcel = null)
    {
        // Create XML writer
        $objWriter = null;
        if ($this->getParentWriter()->getUseDiskCaching()) {
            $objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
        } else {
            $objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY);
        }

        // XML header
        $objWriter->startDocument('1.0', 'UTF-8', 'yes');

        // Relationships
        $objWriter->startElement('Relationships');
        $objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships');
        $localRels = $pPHPExcel->getRibbonBinObjects('names');
        if (is_array($localRels)) {
            foreach ($localRels as $aId => $aTarget) {
                $objWriter->startElement('Relationship');
                $objWriter->writeAttribute('Id', $aId);
                $objWriter->writeAttribute('Type', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image');
                $objWriter->writeAttribute('Target', $aTarget);
                $objWriter->endElement();
            }
        }
        $objWriter->endElement();

        return $objWriter->getData();
    }
786158
public function writeStyles(PHPExcel $pPHPExcel = null)
	{
		// Create XML writer
		$objWriter = null;
		if ($this->getParentWriter()->getUseDiskCaching()) {
			$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
		} else {
			$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY);
		}

		// XML header
		$objWriter->startDocument('1.0','UTF-8','yes');

		// styleSheet
		$objWriter->startElement('styleSheet');
		$objWriter->writeAttribute('xml:space', 'preserve');
		$objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/spreadsheetml/2006/main');

			// numFmts
			$objWriter->startElement('numFmts');
			$objWriter->writeAttribute('count', $this->getParentWriter()->getNumFmtHashTable()->count());

				// numFmt
				for ($i = 0; $i < $this->getParentWriter()->getNumFmtHashTable()->count(); ++$i) {
					$this->_writeNumFmt($objWriter, $this->getParentWriter()->getNumFmtHashTable()->getByIndex($i), $i);
				}

			$objWriter->endElement();

			// fonts
			$objWriter->startElement('fonts');
			$objWriter->writeAttribute('count', $this->getParentWriter()->getFontHashTable()->count());

				// font
				for ($i = 0; $i < $this->getParentWriter()->getFontHashTable()->count(); ++$i) {
					$this->_writeFont($objWriter, $this->getParentWriter()->getFontHashTable()->getByIndex($i));
				}

			$objWriter->endElement();

			// fills
			$objWriter->startElement('fills');
			$objWriter->writeAttribute('count', $this->getParentWriter()->getFillHashTable()->count());

				// fill
				for ($i = 0; $i < $this->getParentWriter()->getFillHashTable()->count(); ++$i) {
					$this->_writeFill($objWriter, $this->getParentWriter()->getFillHashTable()->getByIndex($i));
				}

			$objWriter->endElement();

			// borders
			$objWriter->startElement('borders');
			$objWriter->writeAttribute('count', $this->getParentWriter()->getBordersHashTable()->count());

				// border
				for ($i = 0; $i < $this->getParentWriter()->getBordersHashTable()->count(); ++$i) {
					$this->_writeBorder($objWriter, $this->getParentWriter()->getBordersHashTable()->getByIndex($i));
				}

			$objWriter->endElement();

			// cellStyleXfs
			$objWriter->startElement('cellStyleXfs');
			$objWriter->writeAttribute('count', 1);

				// xf
				$objWriter->startElement('xf');
					$objWriter->writeAttribute('numFmtId', 	0);
					$objWriter->writeAttribute('fontId', 	0);
					$objWriter->writeAttribute('fillId', 	0);
					$objWriter->writeAttribute('borderId',	0);
				$objWriter->endElement();

			$objWriter->endElement();

			// cellXfs
			$objWriter->startElement('cellXfs');
			$objWriter->writeAttribute('count', count($pPHPExcel->getCellXfCollection()));

				// xf
				foreach ($pPHPExcel->getCellXfCollection() as $cellXf) {
					$this->_writeCellStyleXf($objWriter, $cellXf, $pPHPExcel);
				}

			$objWriter->endElement();

			// cellStyles
			$objWriter->startElement('cellStyles');
			$objWriter->writeAttribute('count', 1);

				// cellStyle
				$objWriter->startElement('cellStyle');
					$objWriter->writeAttribute('name', 		'Normal');
					$objWriter->writeAttribute('xfId', 		0);
					$objWriter->writeAttribute('builtinId',	0);
				$objWriter->endElement();

			$objWriter->endElement();

			// dxfs
			$objWriter->startElement('dxfs');
			$objWriter->writeAttribute('count', $this->getParentWriter()->getStylesConditionalHashTable()->count());

				// dxf
				for ($i = 0; $i < $this->getParentWriter()->getStylesConditionalHashTable()->count(); ++$i) {
					$this->_writeCellStyleDxf($objWriter, $this->getParentWriter()->getStylesConditionalHashTable()->getByIndex($i)->getStyle());
				}

			$objWriter->endElement();

			// tableStyles
			$objWriter->startElement('tableStyles');
			$objWriter->writeAttribute('defaultTableStyle', 'TableStyleMedium9');
			$objWriter->writeAttribute('defaultPivotStyle', 'PivotTableStyle1');
			$objWriter->endElement();

		$objWriter->endElement();

		// Return
		return $objWriter->getData();
	}
603591
public function output($filename = 'excel.xls', $excelWriterType = 'Excel2007')
    {
        if (!$this->phpexcel instanceof \PHPExcel) {
            throw new HtmlPhpExcelException('You must run process() first to create a phpexcel instance');
        }

        header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
        header('Content-Disposition: attachment;filename="'.$filename.'"');
        header('Cache-Control: max-age=1');

        $writer = \PHPExcel_IOFactory::createWriter($this->phpexcel, $excelWriterType);
        $writer->save('php://output');
    }
1356093
private function writeDefinedNames(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel $pPHPExcel = null)
    {
        // Write defined names
        $objWriter->startElement('definedNames');

        // Named ranges
        if (count($pPHPExcel->getNamedRanges()) > 0) {
            // Named ranges
            $this->writeNamedRanges($objWriter, $pPHPExcel);
        }

        // Other defined names
        $sheetCount = $pPHPExcel->getSheetCount();
        for ($i = 0; $i < $sheetCount; ++$i) {
            // definedName for autoFilter
            $this->writeDefinedNameForAutofilter($objWriter, $pPHPExcel->getSheet($i), $i);

            // definedName for Print_Titles
            $this->writeDefinedNameForPrintTitles($objWriter, $pPHPExcel->getSheet($i), $i);

            // definedName for Print_Area
            $this->writeDefinedNameForPrintArea($objWriter, $pPHPExcel->getSheet($i), $i);
        }

        $objWriter->endElement();
    }
377565
private function _writePageMargins(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null)
	{
		// pageMargins
		$objWriter->startElement('pageMargins');
		$objWriter->writeAttribute('left',		PHPExcel_Shared_String::FormatNumber($pSheet->getPageMargins()->getLeft()));
		$objWriter->writeAttribute('right',		PHPExcel_Shared_String::FormatNumber($pSheet->getPageMargins()->getRight()));
		$objWriter->writeAttribute('top',		PHPExcel_Shared_String::FormatNumber($pSheet->getPageMargins()->getTop()));
		$objWriter->writeAttribute('bottom',	PHPExcel_Shared_String::FormatNumber($pSheet->getPageMargins()->getBottom()));
		$objWriter->writeAttribute('header',	PHPExcel_Shared_String::FormatNumber($pSheet->getPageMargins()->getHeader()));
		$objWriter->writeAttribute('footer',	PHPExcel_Shared_String::FormatNumber($pSheet->getPageMargins()->getFooter()));
		$objWriter->endElement();
	}
713163
public function allNumberFormats(PHPExcel $pPHPExcel = null)
    {
        // Get an array of unique number formats
        $aNumFmts = array();
        $aStyles = $this->allStyles($pPHPExcel);

        foreach ($aStyles as $style) {
            if ($style->getNumberFormat()->getBuiltInFormatCode() === false && !array_key_exists($style->getNumberFormat()->getHashCode(), $aNumFmts)) {
                $aNumFmts[ $style->getNumberFormat()->getHashCode() ] = $style->getNumberFormat();
            }
        }

        return $aNumFmts;
    }
1273254
private function _writeSheetFormatPr(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null)
	{
		// sheetFormatPr
		$objWriter->startElement('sheetFormatPr');

			// Default row height
			if ($pSheet->getDefaultRowDimension()->getRowHeight() >= 0) {
				$objWriter->writeAttribute('customHeight',		'true');
				$objWriter->writeAttribute('defaultRowHeight',	PHPExcel_Shared_String::FormatNumber($pSheet->getDefaultRowDimension()->getRowHeight()));
			} else {
				$objWriter->writeAttribute('defaultRowHeight', '14.4');
			}

			// Set Zero Height row
			if ((string)$pSheet->getDefaultRowDimension()->getzeroHeight()  == '1' ||
				strtolower((string)$pSheet->getDefaultRowDimension()->getzeroHeight()) == 'true' ) {
				$objWriter->writeAttribute('zeroHeight', '1');
			}

			// Default column width
			if ($pSheet->getDefaultColumnDimension()->getWidth() >= 0) {
				$objWriter->writeAttribute('defaultColWidth', PHPExcel_Shared_String::FormatNumber($pSheet->getDefaultColumnDimension()->getWidth()));
			}

			// Outline level - row
			$outlineLevelRow = 0;
			foreach ($pSheet->getRowDimensions() as $dimension) {
				if ($dimension->getOutlineLevel() > $outlineLevelRow) {
					$outlineLevelRow = $dimension->getOutlineLevel();
				}
			}
			$objWriter->writeAttribute('outlineLevelRow',	(int)$outlineLevelRow);

			// Outline level - column
			$outlineLevelCol = 0;
			foreach ($pSheet->getColumnDimensions() as $dimension) {
				if ($dimension->getOutlineLevel() > $outlineLevelCol) {
					$outlineLevelCol = $dimension->getOutlineLevel();
				}
			}
			$objWriter->writeAttribute('outlineLevelCol',	(int)$outlineLevelCol);

		$objWriter->endElement();
	}
155601
public function loadIntoExisting($pFilename, PHPExcel $objPHPExcel)
	{
		// Check if file exists
		if (!file_exists($pFilename)) {
			throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist.");
		}

		$timezoneObj = new DateTimeZone('Europe/London');
		$GMT = new DateTimeZone('UTC');

		$zip = new ZipArchive;
		if (!$zip->open($pFilename)) {
			throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! Error opening file.");
		}

//		echo '<h1>Meta Information</h1>';
		$xml = simplexml_load_string($zip->getFromName("meta.xml"));
		$namespacesMeta = $xml->getNamespaces(true);
//		echo '<pre>';
//		print_r($namespacesMeta);
//		echo '</pre><hr />';

		$docProps = $objPHPExcel->getProperties();
		$officeProperty = $xml->children($namespacesMeta['office']);
		foreach($officeProperty as $officePropertyData) {
			$officePropertyDC = array();
			if (isset($namespacesMeta['dc'])) {
				$officePropertyDC = $officePropertyData->children($namespacesMeta['dc']);
			}
			foreach($officePropertyDC as $propertyName => $propertyValue) {
				switch ($propertyName) {
					case 'title' :
							$docProps->setTitle($propertyValue);
							break;
					case 'subject' :
							$docProps->setSubject($propertyValue);
							break;
					case 'creator' :
							$docProps->setCreator($propertyValue);
							$docProps->setLastModifiedBy($propertyValue);
							break;
					case 'date' :
							$creationDate = strtotime($propertyValue);
							$docProps->setCreated($creationDate);
							$docProps->setModified($creationDate);
							break;
					case 'description' :
							$docProps->setDescription($propertyValue);
							break;
				}
			}
			$officePropertyMeta = array();
			if (isset($namespacesMeta['dc'])) {
				$officePropertyMeta = $officePropertyData->children($namespacesMeta['meta']);
			}
			foreach($officePropertyMeta as $propertyName => $propertyValue) {
				$propertyValueAttributes = $propertyValue->attributes($namespacesMeta['meta']);
				switch ($propertyName) {
					case 'initial-creator' :
							$docProps->setCreator($propertyValue);
							break;
					case 'keyword' :
							$docProps->setKeywords($propertyValue);
							break;
					case 'creation-date' :
							$creationDate = strtotime($propertyValue);
							$docProps->setCreated($creationDate);
							break;
					case 'user-defined' :
							$propertyValueType = PHPExcel_DocumentProperties::PROPERTY_TYPE_STRING;
							foreach ($propertyValueAttributes as $key => $value) {
								if ($key == 'name') {
									$propertyValueName = (string) $value;
								} elseif($key == 'value-type') {
									switch ($value) {
										case 'date'	:
											$propertyValue = PHPExcel_DocumentProperties::convertProperty($propertyValue,'date');
											$propertyValueType = PHPExcel_DocumentProperties::PROPERTY_TYPE_DATE;
											break;
										case 'boolean'	:
											$propertyValue = PHPExcel_DocumentProperties::convertProperty($propertyValue,'bool');
											$propertyValueType = PHPExcel_DocumentProperties::PROPERTY_TYPE_BOOLEAN;
											break;
										case 'float'	:
											$propertyValue = PHPExcel_DocumentProperties::convertProperty($propertyValue,'r4');
											$propertyValueType = PHPExcel_DocumentProperties::PROPERTY_TYPE_FLOAT;
											break;
										default :
											$propertyValueType = PHPExcel_DocumentProperties::PROPERTY_TYPE_STRING;
									}
								}
							}
							$docProps->setCustomProperty($propertyValueName,$propertyValue,$propertyValueType);
							break;
				}
			}
		}


//		echo '<h1>Workbook Content</h1>';
		$xml = simplexml_load_string($zip->getFromName("content.xml"));
		$namespacesContent = $xml->getNamespaces(true);
//		echo '<pre>';
//		print_r($namespacesContent);
//		echo '</pre><hr />';

		$workbook = $xml->children($namespacesContent['office']);
		foreach($workbook->body->spreadsheet as $workbookData) {
			$workbookData = $workbookData->children($namespacesContent['table']);
			$worksheetID = 0;
			foreach($workbookData->table as $worksheetDataSet) {
				$worksheetData = $worksheetDataSet->children($namespacesContent['table']);
//				print_r($worksheetData);
//				echo '<br />';
				$worksheetDataAttributes = $worksheetDataSet->attributes($namespacesContent['table']);
//				print_r($worksheetDataAttributes);
//				echo '<br />';
				if ((isset($this->_loadSheetsOnly)) && (isset($worksheetDataAttributes['name'])) &&
					(!in_array($worksheetDataAttributes['name'], $this->_loadSheetsOnly))) {
					continue;
				}

//				echo '<h2>Worksheet '.$worksheetDataAttributes['name'].'</h2>';
				// Create new Worksheet
				$objPHPExcel->createSheet();
				$objPHPExcel->setActiveSheetIndex($worksheetID);
				if (isset($worksheetDataAttributes['name'])) {
					$worksheetName = (string) $worksheetDataAttributes['name'];
					//	Use false for $updateFormulaCellReferences to prevent adjustment of worksheet references in
					//		formula cells... during the load, all formulae should be correct, and we're simply
					//		bringing the worksheet name in line with the formula, not the reverse
					$objPHPExcel->getActiveSheet()->setTitle($worksheetName,false);
				}

				$rowID = 1;
				foreach($worksheetData as $key => $rowData) {
//					echo '<b>'.$key.'</b><br />';
					switch ($key) {
						case 'table-header-rows':
							foreach ($rowData as $key=>$cellData) {
								$rowData = $cellData;
								break;
							}
						case 'table-row' :
							$rowDataTableAttributes = $rowData->attributes($namespacesContent['table']);
							$rowRepeats = (isset($rowDataTableAttributes['number-rows-repeated'])) ?
									$rowDataTableAttributes['number-rows-repeated'] : 1;
							$columnID = 'A';
							foreach($rowData as $key => $cellData) {
								if ($this->getReadFilter() !== NULL) {
									if (!$this->getReadFilter()->readCell($columnID, $rowID, $worksheetName)) {
										continue;
									}
								}

//								echo '<b>'.$columnID.$rowID.'</b><br />';
								$cellDataText = (isset($namespacesContent['text'])) ?
									$cellData->children($namespacesContent['text']) :
									'';
								$cellDataOffice = $cellData->children($namespacesContent['office']);
								$cellDataOfficeAttributes = $cellData->attributes($namespacesContent['office']);
								$cellDataTableAttributes = $cellData->attributes($namespacesContent['table']);

//								echo 'Office Attributes: ';
//								print_r($cellDataOfficeAttributes);
//								echo '<br />Table Attributes: ';
//								print_r($cellDataTableAttributes);
//								echo '<br />Cell Data Text';
//								print_r($cellDataText);
//								echo '<br />';
//
								$type = $formatting = $hyperlink = null;
								$hasCalculatedValue = false;
								$cellDataFormula = '';
								if (isset($cellDataTableAttributes['formula'])) {
									$cellDataFormula = $cellDataTableAttributes['formula'];
									$hasCalculatedValue = true;
								}

								if (isset($cellDataOffice->annotation)) {
//									echo 'Cell has comment<br />';
									$annotationText = $cellDataOffice->annotation->children($namespacesContent['text']);
									$textArray = array();
									foreach($annotationText as $t) {
										foreach($t->span as $text) {
											$textArray[] = (string)$text;
										}
									}
									$text = implode("\n",$textArray);
//									echo $text,'<br />';
									$objPHPExcel->getActiveSheet()->getComment( $columnID.$rowID )
//																	->setAuthor( $author )
																	->setText($this->_parseRichText($text) );
								}

									if (isset($cellDataText->p)) {
									// Consolidate if there are multiple p records (maybe with spans as well)
									$dataArray = array();
									// Text can have multiple text:p and within those, multiple text:span.
									// text:p newlines, but text:span does not.
									// Also, here we assume there is no text data is span fields are specified, since
									// we have no way of knowing proper positioning anyway.
									foreach ($cellDataText->p as $pData) {
										if (isset($pData->span)) {
											// span sections do not newline, so we just create one large string here
											$spanSection = "";
											foreach ($pData->span as $spanData) {
												$spanSection .= $spanData;
											}
											array_push($dataArray, $spanSection);
										} else {
											array_push($dataArray, $pData);
										}
									}
									$allCellDataText = implode($dataArray, "\n");

//									echo 'Value Type is '.$cellDataOfficeAttributes['value-type'].'<br />';
									switch ($cellDataOfficeAttributes['value-type']) {
 										case 'string' :
												$type = PHPExcel_Cell_DataType::TYPE_STRING;
												$dataValue = $allCellDataText;
												if (isset($dataValue->a)) {
													$dataValue = $dataValue->a;
													$cellXLinkAttributes = $dataValue->attributes($namespacesContent['xlink']);
													$hyperlink = $cellXLinkAttributes['href'];
												}
												break;
										case 'boolean' :
												$type = PHPExcel_Cell_DataType::TYPE_BOOL;
												$dataValue = ($allCellDataText == 'TRUE') ? True : False;
												break;
										case 'percentage' :
												$type = PHPExcel_Cell_DataType::TYPE_NUMERIC;
												$dataValue = (float) $cellDataOfficeAttributes['value'];
												if (floor($dataValue) == $dataValue) {
													$dataValue = (integer) $dataValue;
												}
												$formatting = PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE_00;
												break;
										case 'currency' :
												$type = PHPExcel_Cell_DataType::TYPE_NUMERIC;
												$dataValue = (float) $cellDataOfficeAttributes['value'];
												if (floor($dataValue) == $dataValue) {
													$dataValue = (integer) $dataValue;
												}
												$formatting = PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_USD_SIMPLE;
												break;
										case 'float' :
												$type = PHPExcel_Cell_DataType::TYPE_NUMERIC;
												$dataValue = (float) $cellDataOfficeAttributes['value'];
												if (floor($dataValue) == $dataValue) {
													if ($dataValue = (integer) $dataValue)
														$dataValue = (integer) $dataValue;
													else
														$dataValue = (float) $dataValue;
												}
												break;
										case 'date' :
												$type = PHPExcel_Cell_DataType::TYPE_NUMERIC;
											    $dateObj = new DateTime($cellDataOfficeAttributes['date-value'], $GMT);
												$dateObj->setTimeZone($timezoneObj);
												list($year,$month,$day,$hour,$minute,$second) = explode(' ',$dateObj->format('Y m d H i s'));
												$dataValue = PHPExcel_Shared_Date::FormattedPHPToExcel($year,$month,$day,$hour,$minute,$second);
												if ($dataValue != floor($dataValue)) {
													$formatting = PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX15.' '.PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME4;
												} else {
													$formatting = PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX15;
												}
												break;
										case 'time' :
												$type = PHPExcel_Cell_DataType::TYPE_NUMERIC;
												$dataValue = PHPExcel_Shared_Date::PHPToExcel(strtotime('01-01-1970 '.implode(':',sscanf($cellDataOfficeAttributes['time-value'],'PT%dH%dM%dS'))));
												$formatting = PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME4;
												break;
									}
//									echo 'Data value is '.$dataValue.'<br />';
//									if ($hyperlink !== NULL) {
//										echo 'Hyperlink is '.$hyperlink.'<br />';
//									}
								} else {
									$type = PHPExcel_Cell_DataType::TYPE_NULL;
									$dataValue = NULL;
								}

								if ($hasCalculatedValue) {
									$type = PHPExcel_Cell_DataType::TYPE_FORMULA;
//									echo 'Formula: '.$cellDataFormula.'<br />';
									$cellDataFormula = substr($cellDataFormula,strpos($cellDataFormula,':=')+1);
									$temp = explode('"',$cellDataFormula);
									$tKey = false;
									foreach($temp as &$value) {
										//	Only replace in alternate array entries (i.e. non-quoted blocks)
										if ($tKey = !$tKey) {
											$value = preg_replace('/\[\.(.*):\.(.*)\]/Ui','$1:$2',$value);
											$value = preg_replace('/\[\.(.*)\]/Ui','$1',$value);
											$value = PHPExcel_Calculation::_translateSeparator(';',',',$value,$inBraces);
										}
									}
									unset($value);
									//	Then rebuild the formula string
									$cellDataFormula = implode('"',$temp);
//									echo 'Adjusted Formula: '.$cellDataFormula.'<br />';
								}

								$colRepeats = (isset($cellDataTableAttributes['number-columns-repeated'])) ?
									$cellDataTableAttributes['number-columns-repeated'] : 1;
								if ($type !== NULL) {
									for ($i = 0; $i < $colRepeats; ++$i) {
										if ($i > 0) {
											++$columnID;
										}
										if ($type !== PHPExcel_Cell_DataType::TYPE_NULL) {
											for ($rowAdjust = 0; $rowAdjust < $rowRepeats; ++$rowAdjust) {
												$rID = $rowID + $rowAdjust;
												$objPHPExcel->getActiveSheet()->getCell($columnID.$rID)->setValueExplicit((($hasCalculatedValue) ? $cellDataFormula : $dataValue),$type);
												if ($hasCalculatedValue) {
//													echo 'Forumla result is '.$dataValue.'<br />';
													$objPHPExcel->getActiveSheet()->getCell($columnID.$rID)->setCalculatedValue($dataValue);
												}
												if ($formatting !== NULL) {
													$objPHPExcel->getActiveSheet()->getStyle($columnID.$rID)->getNumberFormat()->setFormatCode($formatting);
												} else {
													$objPHPExcel->getActiveSheet()->getStyle($columnID.$rID)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_GENERAL);
												}
												if ($hyperlink !== NULL) {
													$objPHPExcel->getActiveSheet()->getCell($columnID.$rID)->getHyperlink()->setUrl($hyperlink);
												}
											}
										}
									}
								}

								//	Merged cells
								if ((isset($cellDataTableAttributes['number-columns-spanned'])) || (isset($cellDataTableAttributes['number-rows-spanned']))) {
									if (($type !== PHPExcel_Cell_DataType::TYPE_NULL) || (!$this->_readDataOnly)) {
										$columnTo = $columnID;
										if (isset($cellDataTableAttributes['number-columns-spanned'])) {
											$columnTo = PHPExcel_Cell::stringFromColumnIndex(PHPExcel_Cell::columnIndexFromString($columnID) + $cellDataTableAttributes['number-columns-spanned'] -2);
										}
										$rowTo = $rowID;
										if (isset($cellDataTableAttributes['number-rows-spanned'])) {
											$rowTo = $rowTo + $cellDataTableAttributes['number-rows-spanned'] - 1;
										}
										$cellRange = $columnID.$rowID.':'.$columnTo.$rowTo;
										$objPHPExcel->getActiveSheet()->mergeCells($cellRange);
									}
								}

								++$columnID;
							}
							$rowID += $rowRepeats;
							break;
					}
				}
				++$worksheetID;
			}
		}

		// Return
		return $objPHPExcel;
	}
332671
public function setHyperlink(PHPExcel_Cell_Hyperlink $pHyperlink = NULL)
	{
		if (!isset($this->_parent)) {
			throw new PHPExcel_Exception('Cannot set hyperlink for cell that is not bound to a worksheet');
		}

		$this->getWorksheet()->setHyperlink($this->getCoordinate(), $pHyperlink);

		return $this->notifyCacheController();
	}
838392
public function writeWorkbook(PHPExcel $pPHPExcel = null, $recalcRequired = FALSE)
	{
		// Create XML writer
		$objWriter = null;
		if ($this->getParentWriter()->getUseDiskCaching()) {
			$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
		} else {
			$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY);
		}

		// XML header
		$objWriter->startDocument('1.0','UTF-8','yes');

		// workbook
		$objWriter->startElement('workbook');
		$objWriter->writeAttribute('xml:space', 'preserve');
		$objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/spreadsheetml/2006/main');
		$objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');

			// fileVersion
			$this->_writeFileVersion($objWriter);

			// workbookPr
			$this->_writeWorkbookPr($objWriter);

			// workbookProtection
			$this->_writeWorkbookProtection($objWriter, $pPHPExcel);

			// bookViews
			if ($this->getParentWriter()->getOffice2003Compatibility() === false) {
				$this->_writeBookViews($objWriter, $pPHPExcel);
			}

			// sheets
			$this->_writeSheets($objWriter, $pPHPExcel);

			// definedNames
			$this->_writeDefinedNames($objWriter, $pPHPExcel);

			// calcPr
			$this->_writeCalcPr($objWriter,$recalcRequired);

		$objWriter->endElement();

		// Return
		return $objWriter->getData();
	}
1007304
private function _writeHyperlinks(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null)
	{
		// Hyperlink collection
		$hyperlinkCollection = $pSheet->getHyperlinkCollection();

		// Relation ID
		$relationId = 1;

		// Write hyperlinks?
		if (!empty($hyperlinkCollection)) {
			$objWriter->startElement('hyperlinks');

			foreach ($hyperlinkCollection as $coordinate => $hyperlink) {
				$objWriter->startElement('hyperlink');

				$objWriter->writeAttribute('ref', $coordinate);
				if (!$hyperlink->isInternal()) {
					$objWriter->writeAttribute('r:id',	'rId_hyperlink_' . $relationId);
					++$relationId;
				} else {
					$objWriter->writeAttribute('location',	str_replace('sheet://', '', $hyperlink->getUrl()));
				}

				if ($hyperlink->getTooltip() != '') {
					$objWriter->writeAttribute('tooltip', $hyperlink->getTooltip());
				}

				$objWriter->endElement();
			}

			$objWriter->endElement();
		}
	}
1350727
private function _writeProtectedRanges(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null)
	{
		if (count($pSheet->getProtectedCells()) > 0) {
			// protectedRanges
			$objWriter->startElement('protectedRanges');

				// Loop protectedRanges
				foreach ($pSheet->getProtectedCells() as $protectedCell => $passwordHash) {
					// protectedRange
					$objWriter->startElement('protectedRange');
					$objWriter->writeAttribute('name',		'p' . md5($protectedCell));
					$objWriter->writeAttribute('sqref',	$protectedCell);
					if (!empty($passwordHash)) {
						$objWriter->writeAttribute('password',	$passwordHash);
					}
					$objWriter->endElement();
				}

			$objWriter->endElement();
		}
	}
159004
private function writeCells(PHPExcel_Shared_XMLWriter $objWriter, PHPExcel_Worksheet_Row $row)
    {
        $number_cols_repeated = self::NUMBER_COLS_REPEATED_MAX;
        $prev_column = -1;
        $cells = $row->getCellIterator();
        while ($cells->valid()) {
            $cell = $cells->current();
            $column = PHPExcel_Cell::columnIndexFromString($cell->getColumn()) - 1;

            $this->writeCellSpan($objWriter, $column, $prev_column);
            $objWriter->startElement('table:table-cell');

            switch ($cell->getDataType()) {
                case PHPExcel_Cell_DataType::TYPE_BOOL:
                    $objWriter->writeAttribute('office:value-type', 'boolean');
                    $objWriter->writeAttribute('office:value', $cell->getValue());
                    $objWriter->writeElement('text:p', $cell->getValue());
                    break;

                case PHPExcel_Cell_DataType::TYPE_ERROR:
                    throw new PHPExcel_Writer_Exception('Writing of error not implemented yet.');
                    break;

                case PHPExcel_Cell_DataType::TYPE_FORMULA:
                    try {
                        $formula_value = $cell->getCalculatedValue();
                    } catch (Exception $e) {
                        $formula_value = $cell->getValue();
                    }
                    $objWriter->writeAttribute('table:formula', 'of:' . $cell->getValue());
                    if (is_numeric($formula_value)) {
                        $objWriter->writeAttribute('office:value-type', 'float');
                    } else {
                        $objWriter->writeAttribute('office:value-type', 'string');
                    }
                    $objWriter->writeAttribute('office:value', $formula_value);
                    $objWriter->writeElement('text:p', $formula_value);
                    break;

                case PHPExcel_Cell_DataType::TYPE_INLINE:
                    throw new PHPExcel_Writer_Exception('Writing of inline not implemented yet.');
                    break;

                case PHPExcel_Cell_DataType::TYPE_NUMERIC:
                    $objWriter->writeAttribute('office:value-type', 'float');
                    $objWriter->writeAttribute('office:value', $cell->getValue());
                    $objWriter->writeElement('text:p', $cell->getValue());
                    break;

                case PHPExcel_Cell_DataType::TYPE_STRING:
                    $objWriter->writeAttribute('office:value-type', 'string');
                    $objWriter->writeElement('text:p', $cell->getValue());
                    break;
            }
            PHPExcel_Writer_OpenDocument_Cell_Comment::write($objWriter, $cell);
            $objWriter->endElement();
            $prev_column = $column;
            $cells->next();
        }
        $number_cols_repeated = $number_cols_repeated - $prev_column - 1;
        if ($number_cols_repeated > 0) {
            if ($number_cols_repeated > 1) {
                $objWriter->startElement('table:table-cell');
                $objWriter->writeAttribute('table:number-columns-repeated', $number_cols_repeated);
                $objWriter->endElement();
            } else {
                $objWriter->writeElement('table:table-cell');
            }
        }
    }
908238
public function writeStringTable($pStringTable = null)
	{
		if ($pStringTable !== NULL) {
			// Create XML writer
			$objWriter = null;
			if ($this->getParentWriter()->getUseDiskCaching()) {
				$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
			} else {
				$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY);
			}

			// XML header
			$objWriter->startDocument('1.0','UTF-8','yes');

			// String table
			$objWriter->startElement('sst');
			$objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/spreadsheetml/2006/main');
			$objWriter->writeAttribute('uniqueCount', count($pStringTable));

				// Loop through string table
				foreach ($pStringTable as $textElement) {
					$objWriter->startElement('si');

						if (! $textElement instanceof PHPExcel_RichText) {
							$textToWrite = PHPExcel_Shared_String::ControlCharacterPHP2OOXML( $textElement );
							$objWriter->startElement('t');
							if ($textToWrite !== trim($textToWrite)) {
								$objWriter->writeAttribute('xml:space', 'preserve');
							}
							$objWriter->writeRawData($textToWrite);
							$objWriter->endElement();
						} else if ($textElement instanceof PHPExcel_RichText) {
							$this->writeRichText($objWriter, $textElement);
						}

                    $objWriter->endElement();
				}

			$objWriter->endElement();

			// Return
			return $objWriter->getData();
		} else {
			throw new PHPExcel_Writer_Exception("Invalid string table array passed.");
		}
	}
100031
private function writeLegacyDrawingHF(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null)
    {
        // If sheet contains images, add the relationships
        if (count($pSheet->getHeaderFooter()->getImages()) > 0) {
            $objWriter->startElement('legacyDrawingHF');
            $objWriter->writeAttribute('r:id', 'rId_headerfooter_vml1');
            $objWriter->endElement();
        }
    }