[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/phpexcel/PHPExcel/Writer/Excel2007/ -> DocProps.php (source)

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


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1