コード例 #1
0
ファイル: DocProps.php プロジェクト: kameshwariv/testexample
 /**
  * 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();
 }
コード例 #2
0
 /**
  * Write string table to XML format
  *
  * @param     string[]     $pStringTable
  * @return string  XML Output
  * @throws     \PHPExcel\Writer\Exception
  */
 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\StringHelper::controlCharacterPHP2OOXML($textElement);
                 $objWriter->startElement('t');
                 if ($textToWrite !== trim($textToWrite)) {
                     $objWriter->writeAttribute('xml:space', 'preserve');
                 }
                 $objWriter->writeRawData($textToWrite);
                 $objWriter->endElement();
             } elseif ($textElement instanceof \PHPExcel\RichText) {
                 $this->writeRichText($objWriter, $textElement);
             }
             $objWriter->endElement();
         }
         $objWriter->endElement();
         return $objWriter->getData();
     } else {
         throw new \PHPExcel\Writer\Exception("Invalid string table array passed.");
     }
 }