Esempio n. 1
0
 /**
  * Write relationships to XML format
  *
  * @param \PHPExcel\SpreadSheet $pPHPExcel
  * @return string  XML Output
  * @throws     \PHPExcel\Writer\Exception
  */
 public function writeRelationships(\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');
     $customPropertyList = $pPHPExcel->getProperties()->getCustomProperties();
     if (!empty($customPropertyList)) {
         // Relationship docProps/app.xml
         $this->writeRelationship($objWriter, 4, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties', 'docProps/custom.xml');
     }
     // Relationship docProps/app.xml
     $this->writeRelationship($objWriter, 3, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties', 'docProps/app.xml');
     // Relationship docProps/core.xml
     $this->writeRelationship($objWriter, 2, 'http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties', 'docProps/core.xml');
     // Relationship xl/workbook.xml
     $this->writeRelationship($objWriter, 1, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument', 'xl/workbook.xml');
     // a custom UI in workbook ?
     if ($pPHPExcel->hasRibbon()) {
         $this->writeRelationShip($objWriter, 5, 'http://schemas.microsoft.com/office/2006/relationships/ui/extensibility', $pPHPExcel->getRibbonXMLData('target'));
     }
     $objWriter->endElement();
     return $objWriter->getData();
 }
Esempio n. 2
0
 /**
  * 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();
 }