No Description

31docproperties_write.php 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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
  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. /** Error reporting */
  28. error_reporting(E_ALL);
  29. ini_set('display_errors', TRUE);
  30. ini_set('display_startup_errors', TRUE);
  31. define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
  32. date_default_timezone_set('Europe/London');
  33. /** Include PHPExcel */
  34. require_once dirname(__FILE__) . '/../Classes/PHPExcel.php';
  35. $inputFileType = 'Excel2007';
  36. $inputFileName = 'templates/31docproperties.xlsx';
  37. echo date('H:i:s') , " Load Tests from $inputFileType file" , EOL;
  38. $callStartTime = microtime(true);
  39. $objPHPExcelReader = PHPExcel_IOFactory::createReader($inputFileType);
  40. $objPHPExcel = $objPHPExcelReader->load($inputFileName);
  41. $callEndTime = microtime(true);
  42. $callTime = $callEndTime - $callStartTime;
  43. echo 'Call time to read Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL;
  44. // Echo memory usage
  45. echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL;
  46. echo date('H:i:s') , " Adjust properties" , EOL;
  47. $objPHPExcel->getProperties()->setTitle("Office 2007 XLSX Test Document")
  48. ->setSubject("Office 2007 XLSX Test Document")
  49. ->setDescription("Test XLSX document, generated using PHPExcel")
  50. ->setKeywords("office 2007 openxml php");
  51. // Save Excel 2007 file
  52. echo date('H:i:s') , " Write to Excel2007 format" , EOL;
  53. $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
  54. $objWriter->save(str_replace('.php', '.xlsx', __FILE__));
  55. echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL;
  56. // Echo memory peak usage
  57. echo date('H:i:s') , " Peak memory usage: " . (memory_get_peak_usage(true) / 1024 / 1024) . " MB" , EOL;
  58. echo EOL;
  59. // Reread File
  60. echo date('H:i:s') , " Reread Excel2007 file" , EOL;
  61. $objPHPExcelRead = PHPExcel_IOFactory::load(str_replace('.php', '.xlsx', __FILE__));
  62. // Set properties
  63. echo date('H:i:s') , " Get properties" , EOL;
  64. echo 'Core Properties:' , EOL;
  65. echo ' Created by - ' , $objPHPExcel->getProperties()->getCreator() , EOL;
  66. echo ' Created on - ' , date('d-M-Y',$objPHPExcel->getProperties()->getCreated()) , ' at ' ,
  67. date('H:i:s',$objPHPExcel->getProperties()->getCreated()) , EOL;
  68. echo ' Last Modified by - ' , $objPHPExcel->getProperties()->getLastModifiedBy() , EOL;
  69. echo ' Last Modified on - ' , date('d-M-Y',$objPHPExcel->getProperties()->getModified()) , ' at ' ,
  70. date('H:i:s',$objPHPExcel->getProperties()->getModified()) , EOL;
  71. echo ' Title - ' , $objPHPExcel->getProperties()->getTitle() , EOL;
  72. echo ' Subject - ' , $objPHPExcel->getProperties()->getSubject() , EOL;
  73. echo ' Description - ' , $objPHPExcel->getProperties()->getDescription() , EOL;
  74. echo ' Keywords: - ' , $objPHPExcel->getProperties()->getKeywords() , EOL;
  75. echo 'Extended (Application) Properties:' , EOL;
  76. echo ' Category - ' , $objPHPExcel->getProperties()->getCategory() , EOL;
  77. echo ' Company - ' , $objPHPExcel->getProperties()->getCompany() , EOL;
  78. echo ' Manager - ' , $objPHPExcel->getProperties()->getManager() , EOL;
  79. echo 'Custom Properties:' , EOL;
  80. $customProperties = $objPHPExcel->getProperties()->getCustomProperties();
  81. foreach($customProperties as $customProperty) {
  82. $propertyValue = $objPHPExcel->getProperties()->getCustomPropertyValue($customProperty);
  83. $propertyType = $objPHPExcel->getProperties()->getCustomPropertyType($customProperty);
  84. echo ' ' , $customProperty , ' - (' , $propertyType , ') - ';
  85. if ($propertyType == PHPExcel_DocumentProperties::PROPERTY_TYPE_DATE) {
  86. echo date('d-M-Y H:i:s',$propertyValue) , EOL;
  87. } elseif ($propertyType == PHPExcel_DocumentProperties::PROPERTY_TYPE_BOOLEAN) {
  88. echo (($propertyValue) ? 'TRUE' : 'FALSE') , EOL;
  89. } else {
  90. echo $propertyValue , EOL;
  91. }
  92. }
  93. // Echo memory peak usage
  94. echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) . " MB" , EOL;