Esempio n. 1
0
 /**
  * Write comments to XML format
  *
  * @param     \PHPExcel\Worksheet                $pWorksheet
  * @return string                          XML Output
  * @throws     \PHPExcel\Writer\Exception
  */
 public function writeComments(\PHPExcel\Worksheet $pWorksheet = 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');
     // Comments cache
     $comments = $pWorksheet->getComments();
     // Authors cache
     $authors = array();
     $authorId = 0;
     foreach ($comments as $comment) {
         if (!isset($authors[$comment->getAuthor()])) {
             $authors[$comment->getAuthor()] = $authorId++;
         }
     }
     // comments
     $objWriter->startElement('comments');
     $objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/spreadsheetml/2006/main');
     // Loop through authors
     $objWriter->startElement('authors');
     foreach ($authors as $author => $index) {
         $objWriter->writeElement('author', $author);
     }
     $objWriter->endElement();
     // Loop through comments
     $objWriter->startElement('commentList');
     foreach ($comments as $key => $value) {
         $this->writeComment($objWriter, $key, $value, $authors);
     }
     $objWriter->endElement();
     $objWriter->endElement();
     // Return
     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();
 }