PHPExcel_Writer_Excel2007
[ class tree: PHPExcel_Writer_Excel2007 ] [ index: PHPExcel_Writer_Excel2007 ] [ all elements ]

Source for file DocProps.php

Documentation is available at DocProps.php

  1. <?php
  2. /**
  3.  * PHPExcel
  4.  *
  5.  * Copyright (c) 2006 - 2011 PHPExcel
  6.  *
  7.  * This library is free software; you can redistribute it and/or
  8.  * modify it under the terms of the GNU Lesser General Public
  9.  * License as published by the Free Software Foundation; either
  10.  * version 2.1 of the License, or (at your option) any later version.
  11.  *
  12.  * This library is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.  * Lesser General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU Lesser General Public
  18.  * License along with this library; if not, write to the Free Software
  19.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  20.  *
  21.  * @category   PHPExcel
  22.  * @package    PHPExcel_Writer_Excel2007
  23.  * @copyright  Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
  24.  * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
  25.  * @version    1.7.6, 2011-02-27
  26.  */
  27.  
  28.  
  29. /**
  30.  * PHPExcel_Writer_Excel2007_DocProps
  31.  *
  32.  * @category   PHPExcel
  33.  * @package    PHPExcel_Writer_Excel2007
  34.  * @copyright  Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
  35.  */
  36. {
  37. /**
  38.      * Write docProps/app.xml to XML format
  39.      *
  40.      * @param     PHPExcel    $pPHPExcel 
  41.      * @return     string         XML Output
  42.      * @throws     Exception
  43.      */
  44.     public function writeDocPropsApp(PHPExcel $pPHPExcel null)
  45.     {
  46.         // Create XML writer
  47.         $objWriter null;
  48.         if ($this->getParentWriter()->getUseDiskCaching()) {
  49.             $objWriter new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK$this->getParentWriter()->getDiskCachingDirectory());
  50.         else {
  51.             $objWriter new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY);
  52.         }
  53.  
  54.         // XML header
  55.         $objWriter->startDocument('1.0','UTF-8','yes');
  56.  
  57.         // Properties
  58.         $objWriter->startElement('Properties');
  59.             $objWriter->writeAttribute('xmlns''http://schemas.openxmlformats.org/officeDocument/2006/extended-properties');
  60.             $objWriter->writeAttribute('xmlns:vt''http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes');
  61.  
  62.             // Application
  63.             $objWriter->writeElement('Application',     'Microsoft Excel');
  64.  
  65.             // DocSecurity
  66.             $objWriter->writeElement('DocSecurity',     '0');
  67.  
  68.             // ScaleCrop
  69.             $objWriter->writeElement('ScaleCrop',         'false');
  70.  
  71.             // HeadingPairs
  72.             $objWriter->startElement('HeadingPairs');
  73.  
  74.                 // Vector
  75.                 $objWriter->startElement('vt:vector');
  76.                     $objWriter->writeAttribute('size',         '2');
  77.                     $objWriter->writeAttribute('baseType',     'variant');
  78.  
  79.                     // Variant
  80.                     $objWriter->startElement('vt:variant');
  81.                         $objWriter->writeElement('vt:lpstr',     'Worksheets');
  82.                     $objWriter->endElement();
  83.  
  84.                     // Variant
  85.                     $objWriter->startElement('vt:variant');
  86.                         $objWriter->writeElement('vt:i4',         $pPHPExcel->getSheetCount());
  87.                     $objWriter->endElement();
  88.  
  89.                 $objWriter->endElement();
  90.  
  91.             $objWriter->endElement();
  92.  
  93.             // TitlesOfParts
  94.             $objWriter->startElement('TitlesOfParts');
  95.  
  96.                 // Vector
  97.                 $objWriter->startElement('vt:vector');
  98.                     $objWriter->writeAttribute('size',         $pPHPExcel->getSheetCount());
  99.                     $objWriter->writeAttribute('baseType',    'lpstr');
  100.  
  101.                     $sheetCount $pPHPExcel->getSheetCount();
  102.                     for ($i 0$i $sheetCount++$i{
  103.                         $objWriter->writeElement('vt:lpstr'$pPHPExcel->getSheet($i)->getTitle());
  104.                     }
  105.  
  106.                 $objWriter->endElement();
  107.  
  108.             $objWriter->endElement();
  109.  
  110.             // Company
  111.             $objWriter->writeElement('Company',             $pPHPExcel->getProperties()->getCompany());
  112.  
  113.             // Company
  114.             $objWriter->writeElement('Manager',             $pPHPExcel->getProperties()->getManager());
  115.  
  116.             // LinksUpToDate
  117.             $objWriter->writeElement('LinksUpToDate',         'false');
  118.  
  119.             // SharedDoc
  120.             $objWriter->writeElement('SharedDoc',             'false');
  121.  
  122.             // HyperlinksChanged
  123.             $objWriter->writeElement('HyperlinksChanged',     'false');
  124.  
  125.             // AppVersion
  126.             $objWriter->writeElement('AppVersion',             '12.0000');
  127.  
  128.         $objWriter->endElement();
  129.  
  130.         // Return
  131.         return $objWriter->getData();
  132.     }
  133.  
  134.     /**
  135.      * Write docProps/core.xml to XML format
  136.      *
  137.      * @param     PHPExcel    $pPHPExcel 
  138.      * @return     string         XML Output
  139.      * @throws     Exception
  140.      */
  141.     public function writeDocPropsCore(PHPExcel $pPHPExcel null)
  142.     {
  143.         // Create XML writer
  144.         $objWriter null;
  145.         if ($this->getParentWriter()->getUseDiskCaching()) {
  146.             $objWriter new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK$this->getParentWriter()->getDiskCachingDirectory());
  147.         else {
  148.             $objWriter new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY);
  149.         }
  150.  
  151.         // XML header
  152.         $objWriter->startDocument('1.0','UTF-8','yes');
  153.  
  154.         // cp:coreProperties
  155.         $objWriter->startElement('cp:coreProperties');
  156.             $objWriter->writeAttribute('xmlns:cp''http://schemas.openxmlformats.org/package/2006/metadata/core-properties');
  157.             $objWriter->writeAttribute('xmlns:dc''http://purl.org/dc/elements/1.1/');
  158.             $objWriter->writeAttribute('xmlns:dcterms''http://purl.org/dc/terms/');
  159.             $objWriter->writeAttribute('xmlns:dcmitype''http://purl.org/dc/dcmitype/');
  160.             $objWriter->writeAttribute('xmlns:xsi''http://www.w3.org/2001/XMLSchema-instance');
  161.  
  162.             // dc:creator
  163.             $objWriter->writeElement('dc:creator',            $pPHPExcel->getProperties()->getCreator());
  164.  
  165.             // cp:lastModifiedBy
  166.             $objWriter->writeElement('cp:lastModifiedBy',     $pPHPExcel->getProperties()->getLastModifiedBy());
  167.  
  168.             // dcterms:created
  169.             $objWriter->startElement('dcterms:created');
  170.                 $objWriter->writeAttribute('xsi:type''dcterms:W3CDTF');
  171.                 $objWriter->writeRawData(date(DATE_W3C,     $pPHPExcel->getProperties()->getCreated()));
  172.             $objWriter->endElement();
  173.  
  174.             // dcterms:modified
  175.             $objWriter->startElement('dcterms:modified');
  176.                 $objWriter->writeAttribute('xsi:type''dcterms:W3CDTF');
  177.                 $objWriter->writeRawData(date(DATE_W3C,     $pPHPExcel->getProperties()->getModified()));
  178.             $objWriter->endElement();
  179.  
  180.             // dc:title
  181.             $objWriter->writeElement('dc:title',             $pPHPExcel->getProperties()->getTitle());
  182.  
  183.             // dc:description
  184.             $objWriter->writeElement('dc:description',         $pPHPExcel->getProperties()->getDescription());
  185.  
  186.             // dc:subject
  187.             $objWriter->writeElement('dc:subject',             $pPHPExcel->getProperties()->getSubject());
  188.  
  189.             // cp:keywords
  190.             $objWriter->writeElement('cp:keywords',         $pPHPExcel->getProperties()->getKeywords());
  191.  
  192.             // cp:category
  193.             $objWriter->writeElement('cp:category',         $pPHPExcel->getProperties()->getCategory());
  194.  
  195.         $objWriter->endElement();
  196.  
  197.         // Return
  198.         return $objWriter->getData();
  199.     }
  200.  
  201.     /**
  202.      * Write docProps/custom.xml to XML format
  203.      *
  204.      * @param     PHPExcel    $pPHPExcel 
  205.      * @return     string         XML Output
  206.      * @throws     Exception
  207.      */
  208.     public function writeDocPropsCustom(PHPExcel $pPHPExcel null)
  209.     {
  210.         $customPropertyList $pPHPExcel->getProperties()->getCustomProperties();
  211.         if (count($customPropertyList== 0{
  212.             return;
  213.         }
  214.  
  215.         // Create XML writer
  216.         $objWriter null;
  217.         if ($this->getParentWriter()->getUseDiskCaching()) {
  218.             $objWriter new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK$this->getParentWriter()->getDiskCachingDirectory());
  219.         else {
  220.             $objWriter new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY);
  221.         }
  222.  
  223.         // XML header
  224.         $objWriter->startDocument('1.0','UTF-8','yes');
  225.  
  226.         // cp:coreProperties
  227.         $objWriter->startElement('Properties');
  228.             $objWriter->writeAttribute('xmlns''http://schemas.openxmlformats.org/officeDocument/2006/custom-properties');
  229.             $objWriter->writeAttribute('xmlns:vt''http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes');
  230.  
  231.  
  232.             foreach($customPropertyList as $key => $customProperty{
  233.                 $propertyValue $pPHPExcel->getProperties()->getCustomPropertyValue($customProperty);
  234.                 $propertyType $pPHPExcel->getProperties()->getCustomPropertyType($customProperty);
  235.  
  236.                 $objWriter->startElement('property');
  237.                     $objWriter->writeAttribute('fmtid',     '{D5CDD505-2E9C-101B-9397-08002B2CF9AE}');
  238.                     $objWriter->writeAttribute('pid',         $key+2);
  239.                     $objWriter->writeAttribute('name',         $customProperty);
  240.  
  241.                     switch($propertyType{
  242.                         case 'i' :
  243.                             $objWriter->writeElement('vt:i4',         $propertyValue);
  244.                             break;
  245.                         case 'f' :
  246.                             $objWriter->writeElement('vt:r8',         $propertyValue);
  247.                             break;
  248.                         case 'b' :
  249.                             $objWriter->writeElement('vt:bool',     ($propertyValue'true' 'false');
  250.                             break;
  251.                         case 'd' :
  252.                             $objWriter->startElement('vt:filetime');
  253.                                 $objWriter->writeRawData(date(DATE_W3C$propertyValue));
  254.                             $objWriter->endElement();
  255.                             break;
  256.                         default :
  257.                             $objWriter->writeElement('vt:lpwstr',     $propertyValue);
  258.                             break;
  259.                     }
  260.  
  261.                 $objWriter->endElement();
  262.             }
  263.  
  264.  
  265.         $objWriter->endElement();
  266.  
  267.         // Return
  268.         return $objWriter->getData();
  269.     }
  270.  
  271. }

Documentation generated on Sun, 27 Feb 2011 16:30:12 -0800 by phpDocumentor 1.4.3