c73fcf4f5719ec328b99d8f3ad0f76dccf8e6e67.svn-base 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. <?php
  2. /**
  3. * PHPExcel
  4. *
  5. * Copyright (c) 2006 - 2014 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 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
  24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  25. * @version ##VERSION##, ##DATE##
  26. */
  27. /**
  28. * PHPExcel_Writer_Excel2007_DocProps
  29. *
  30. * @category PHPExcel
  31. * @package PHPExcel_Writer_Excel2007
  32. * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
  33. */
  34. class PHPExcel_Writer_Excel2007_DocProps extends PHPExcel_Writer_Excel2007_WriterPart
  35. {
  36. /**
  37. * Write docProps/app.xml to XML format
  38. *
  39. * @param PHPExcel $pPHPExcel
  40. * @return string XML Output
  41. * @throws PHPExcel_Writer_Exception
  42. */
  43. public function writeDocPropsApp(PHPExcel $pPHPExcel = null)
  44. {
  45. // Create XML writer
  46. $objWriter = null;
  47. if ($this->getParentWriter()->getUseDiskCaching()) {
  48. $objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
  49. } else {
  50. $objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY);
  51. }
  52. // XML header
  53. $objWriter->startDocument('1.0','UTF-8','yes');
  54. // Properties
  55. $objWriter->startElement('Properties');
  56. $objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/officeDocument/2006/extended-properties');
  57. $objWriter->writeAttribute('xmlns:vt', 'http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes');
  58. // Application
  59. $objWriter->writeElement('Application', 'Microsoft Excel');
  60. // DocSecurity
  61. $objWriter->writeElement('DocSecurity', '0');
  62. // ScaleCrop
  63. $objWriter->writeElement('ScaleCrop', 'false');
  64. // HeadingPairs
  65. $objWriter->startElement('HeadingPairs');
  66. // Vector
  67. $objWriter->startElement('vt:vector');
  68. $objWriter->writeAttribute('size', '2');
  69. $objWriter->writeAttribute('baseType', 'variant');
  70. // Variant
  71. $objWriter->startElement('vt:variant');
  72. $objWriter->writeElement('vt:lpstr', 'Worksheets');
  73. $objWriter->endElement();
  74. // Variant
  75. $objWriter->startElement('vt:variant');
  76. $objWriter->writeElement('vt:i4', $pPHPExcel->getSheetCount());
  77. $objWriter->endElement();
  78. $objWriter->endElement();
  79. $objWriter->endElement();
  80. // TitlesOfParts
  81. $objWriter->startElement('TitlesOfParts');
  82. // Vector
  83. $objWriter->startElement('vt:vector');
  84. $objWriter->writeAttribute('size', $pPHPExcel->getSheetCount());
  85. $objWriter->writeAttribute('baseType', 'lpstr');
  86. $sheetCount = $pPHPExcel->getSheetCount();
  87. for ($i = 0; $i < $sheetCount; ++$i) {
  88. $objWriter->writeElement('vt:lpstr', $pPHPExcel->getSheet($i)->getTitle());
  89. }
  90. $objWriter->endElement();
  91. $objWriter->endElement();
  92. // Company
  93. $objWriter->writeElement('Company', $pPHPExcel->getProperties()->getCompany());
  94. // Company
  95. $objWriter->writeElement('Manager', $pPHPExcel->getProperties()->getManager());
  96. // LinksUpToDate
  97. $objWriter->writeElement('LinksUpToDate', 'false');
  98. // SharedDoc
  99. $objWriter->writeElement('SharedDoc', 'false');
  100. // HyperlinksChanged
  101. $objWriter->writeElement('HyperlinksChanged', 'false');
  102. // AppVersion
  103. $objWriter->writeElement('AppVersion', '12.0000');
  104. $objWriter->endElement();
  105. // Return
  106. return $objWriter->getData();
  107. }
  108. /**
  109. * Write docProps/core.xml to XML format
  110. *
  111. * @param PHPExcel $pPHPExcel
  112. * @return string XML Output
  113. * @throws PHPExcel_Writer_Exception
  114. */
  115. public function writeDocPropsCore(PHPExcel $pPHPExcel = null)
  116. {
  117. // Create XML writer
  118. $objWriter = null;
  119. if ($this->getParentWriter()->getUseDiskCaching()) {
  120. $objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
  121. } else {
  122. $objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY);
  123. }
  124. // XML header
  125. $objWriter->startDocument('1.0','UTF-8','yes');
  126. // cp:coreProperties
  127. $objWriter->startElement('cp:coreProperties');
  128. $objWriter->writeAttribute('xmlns:cp', 'http://schemas.openxmlformats.org/package/2006/metadata/core-properties');
  129. $objWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
  130. $objWriter->writeAttribute('xmlns:dcterms', 'http://purl.org/dc/terms/');
  131. $objWriter->writeAttribute('xmlns:dcmitype', 'http://purl.org/dc/dcmitype/');
  132. $objWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
  133. // dc:creator
  134. $objWriter->writeElement('dc:creator', $pPHPExcel->getProperties()->getCreator());
  135. // cp:lastModifiedBy
  136. $objWriter->writeElement('cp:lastModifiedBy', $pPHPExcel->getProperties()->getLastModifiedBy());
  137. // dcterms:created
  138. $objWriter->startElement('dcterms:created');
  139. $objWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF');
  140. $objWriter->writeRawData(date(DATE_W3C, $pPHPExcel->getProperties()->getCreated()));
  141. $objWriter->endElement();
  142. // dcterms:modified
  143. $objWriter->startElement('dcterms:modified');
  144. $objWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF');
  145. $objWriter->writeRawData(date(DATE_W3C, $pPHPExcel->getProperties()->getModified()));
  146. $objWriter->endElement();
  147. // dc:title
  148. $objWriter->writeElement('dc:title', $pPHPExcel->getProperties()->getTitle());
  149. // dc:description
  150. $objWriter->writeElement('dc:description', $pPHPExcel->getProperties()->getDescription());
  151. // dc:subject
  152. $objWriter->writeElement('dc:subject', $pPHPExcel->getProperties()->getSubject());
  153. // cp:keywords
  154. $objWriter->writeElement('cp:keywords', $pPHPExcel->getProperties()->getKeywords());
  155. // cp:category
  156. $objWriter->writeElement('cp:category', $pPHPExcel->getProperties()->getCategory());
  157. $objWriter->endElement();
  158. // Return
  159. return $objWriter->getData();
  160. }
  161. /**
  162. * Write docProps/custom.xml to XML format
  163. *
  164. * @param PHPExcel $pPHPExcel
  165. * @return string XML Output
  166. * @throws PHPExcel_Writer_Exception
  167. */
  168. public function writeDocPropsCustom(PHPExcel $pPHPExcel = null)
  169. {
  170. $customPropertyList = $pPHPExcel->getProperties()->getCustomProperties();
  171. if (empty($customPropertyList)) {
  172. return;
  173. }
  174. // Create XML writer
  175. $objWriter = null;
  176. if ($this->getParentWriter()->getUseDiskCaching()) {
  177. $objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
  178. } else {
  179. $objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY);
  180. }
  181. // XML header
  182. $objWriter->startDocument('1.0','UTF-8','yes');
  183. // cp:coreProperties
  184. $objWriter->startElement('Properties');
  185. $objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/officeDocument/2006/custom-properties');
  186. $objWriter->writeAttribute('xmlns:vt', 'http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes');
  187. foreach($customPropertyList as $key => $customProperty) {
  188. $propertyValue = $pPHPExcel->getProperties()->getCustomPropertyValue($customProperty);
  189. $propertyType = $pPHPExcel->getProperties()->getCustomPropertyType($customProperty);
  190. $objWriter->startElement('property');
  191. $objWriter->writeAttribute('fmtid', '{D5CDD505-2E9C-101B-9397-08002B2CF9AE}');
  192. $objWriter->writeAttribute('pid', $key+2);
  193. $objWriter->writeAttribute('name', $customProperty);
  194. switch($propertyType) {
  195. case 'i' :
  196. $objWriter->writeElement('vt:i4', $propertyValue);
  197. break;
  198. case 'f' :
  199. $objWriter->writeElement('vt:r8', $propertyValue);
  200. break;
  201. case 'b' :
  202. $objWriter->writeElement('vt:bool', ($propertyValue) ? 'true' : 'false');
  203. break;
  204. case 'd' :
  205. $objWriter->startElement('vt:filetime');
  206. $objWriter->writeRawData(date(DATE_W3C, $propertyValue));
  207. $objWriter->endElement();
  208. break;
  209. default :
  210. $objWriter->writeElement('vt:lpwstr', $propertyValue);
  211. break;
  212. }
  213. $objWriter->endElement();
  214. }
  215. $objWriter->endElement();
  216. // Return
  217. return $objWriter->getData();
  218. }
  219. }