/** * Write relationships for additional objects of custom UI (ribbon) * * @param \PHPExcel\SpreadSheet $pPHPExcel * @return string XML Output * @throws \PHPExcel\Writer\Exception */ public function writeRibbonRelationships(\PHPExcel\SpreadSheet $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(); }
/** * Write workbook relationships to XML format * * @param \PHPExcel\SpreadSheet $pPHPExcel * @return string XML Output * @throws \PHPExcel\Writer\Exception */ public function writeWorkbookRelationships(\PHPExcel\SpreadSheet $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'); // Relationship styles.xml $this->writeRelationship($objWriter, 1, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles', 'styles.xml'); // Relationship theme/theme1.xml $this->writeRelationship($objWriter, 2, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme', 'theme/theme1.xml'); // Relationship sharedStrings.xml $this->writeRelationship($objWriter, 3, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings', 'sharedStrings.xml'); // Relationships with sheets $sheetCount = $pPHPExcel->getSheetCount(); for ($i = 0; $i < $sheetCount; ++$i) { $this->writeRelationship($objWriter, $i + 1 + 3, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet', 'worksheets/sheet' . ($i + 1) . '.xml'); } // Relationships for vbaProject if needed // id : just after the last sheet if ($pPHPExcel->hasMacros()) { $this->writeRelationShip($objWriter, $i + 1 + 3, 'http://schemas.microsoft.com/office/2006/relationships/vbaProject', 'vbaProject.bin'); ++$i; //increment i if needed for an another relation } $objWriter->endElement(); return $objWriter->getData(); }
/** * Write named ranges * * @param \PHPExcel\Shared\XMLWriter $objWriter XML Writer * @param \PHPExcel\SpreadSheet $pPHPExcel * @throws \PHPExcel\Writer\Exception */ private function writeNamedRanges(\PHPExcel\Shared\XMLWriter $objWriter, \PHPExcel\SpreadSheet $pPHPExcel) { // Loop named ranges $namedRanges = $pPHPExcel->getNamedRanges(); foreach ($namedRanges as $namedRange) { $this->writeDefinedNameForNamedRange($objWriter, $namedRange); } }
/** * Get an array of all drawings * * @param PHPExcel $pPHPExcel * @return \PHPExcel\Worksheet\Drawing[] All drawings in PHPExcel * @throws \PHPExcel\Writer\Exception */ public function allDrawings(\PHPExcel\SpreadSheet $pPHPExcel = null) { // Get an array of all drawings $aDrawings = array(); // Loop through PHPExcel $sheetCount = $pPHPExcel->getSheetCount(); for ($i = 0; $i < $sheetCount; ++$i) { // Loop through images and add to array $iterator = $pPHPExcel->getSheet($i)->getDrawingCollection()->getIterator(); while ($iterator->valid()) { $aDrawings[] = $iterator->current(); $iterator->next(); } } return $aDrawings; }
/** * Get an array of all conditional styles * * @param \PHPExcel\SpreadSheet $pPHPExcel * @return \PHPExcel\Style\Conditional[] All conditional styles in PHPExcel * @throws \PHPExcel\Writer\Exception */ public function allConditionalStyles(\PHPExcel\SpreadSheet $pPHPExcel = null) { // Get an array of all styles $aStyles = array(); $sheetCount = $pPHPExcel->getSheetCount(); for ($i = 0; $i < $sheetCount; ++$i) { foreach ($pPHPExcel->getSheet($i)->getConditionalStylesCollection() as $conditionalStyles) { foreach ($conditionalStyles as $conditionalStyle) { $aStyles[] = $conditionalStyle; } } } return $aStyles; }
/** * Write docProps/custom.xml to XML format * * @param \PHPExcel\SpreadSheet $pPHPExcel * @return string XML Output * @throws \PHPExcel\Writer\Exception */ public function writeDocPropsCustom(\PHPExcel\SpreadSheet $pPHPExcel = null) { $customPropertyList = $pPHPExcel->getProperties()->getCustomProperties(); if (empty($customPropertyList)) { return; } // 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'); // cp:coreProperties $objWriter->startElement('Properties'); $objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/officeDocument/2006/custom-properties'); $objWriter->writeAttribute('xmlns:vt', 'http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes'); foreach ($customPropertyList as $key => $customProperty) { $propertyValue = $pPHPExcel->getProperties()->getCustomPropertyValue($customProperty); $propertyType = $pPHPExcel->getProperties()->getCustomPropertyType($customProperty); $objWriter->startElement('property'); $objWriter->writeAttribute('fmtid', '{D5CDD505-2E9C-101B-9397-08002B2CF9AE}'); $objWriter->writeAttribute('pid', $key + 2); $objWriter->writeAttribute('name', $customProperty); switch ($propertyType) { case 'i': $objWriter->writeElement('vt:i4', $propertyValue); break; case 'f': $objWriter->writeElement('vt:r8', $propertyValue); break; case 'b': $objWriter->writeElement('vt:bool', $propertyValue ? 'true' : 'false'); break; case 'd': $objWriter->startElement('vt:filetime'); $objWriter->writeRawData(date(DATE_W3C, $propertyValue)); $objWriter->endElement(); break; default: $objWriter->writeElement('vt:lpwstr', $propertyValue); break; } $objWriter->endElement(); } $objWriter->endElement(); return $objWriter->getData(); }