For God so loved the world, that He gave His only begotten Son, that all who believe in Him should not perish but have everlasting life
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

204 lines
8.3 KiB

  1. <?php
  2. /**
  3. * PHPExcel
  4. *
  5. * Copyright (c) 2006 - 2015 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 - 2015 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. date_default_timezone_set('Europe/London');
  32. define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
  33. /** Include PHPExcel */
  34. require_once dirname(__FILE__) . '/../Classes/PHPExcel.php';
  35. // Create new PHPExcel object
  36. echo date('H:i:s') , " Create new PHPExcel object" , EOL;
  37. $objPHPExcel = new PHPExcel();
  38. // Set document properties
  39. echo date('H:i:s') , " Set document properties" , EOL;
  40. $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
  41. ->setLastModifiedBy("Maarten Balliauw")
  42. ->setTitle("Office 2007 XLSX Test Document")
  43. ->setSubject("Office 2007 XLSX Test Document")
  44. ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
  45. ->setKeywords("office 2007 openxml php")
  46. ->setCategory("Test result file");
  47. // Set default font
  48. echo date('H:i:s') , " Set default font" , EOL;
  49. $objPHPExcel->getDefaultStyle()->getFont()->setName('Arial')
  50. ->setSize(10);
  51. // Add some data, resembling some different data types
  52. echo date('H:i:s') , " Add some data" , EOL;
  53. $objPHPExcel->getActiveSheet()->setCellValue('A1', 'String')
  54. ->setCellValue('B1', 'Simple')
  55. ->setCellValue('C1', 'PHPExcel');
  56. $objPHPExcel->getActiveSheet()->setCellValue('A2', 'String')
  57. ->setCellValue('B2', 'Symbols')
  58. ->setCellValue('C2', '!+&=()~§±æþ');
  59. $objPHPExcel->getActiveSheet()->setCellValue('A3', 'String')
  60. ->setCellValue('B3', 'UTF-8')
  61. ->setCellValue('C3', 'Создать MS Excel Книги из PHP скриптов');
  62. $objPHPExcel->getActiveSheet()->setCellValue('A4', 'Number')
  63. ->setCellValue('B4', 'Integer')
  64. ->setCellValue('C4', 12);
  65. $objPHPExcel->getActiveSheet()->setCellValue('A5', 'Number')
  66. ->setCellValue('B5', 'Float')
  67. ->setCellValue('C5', 34.56);
  68. $objPHPExcel->getActiveSheet()->setCellValue('A6', 'Number')
  69. ->setCellValue('B6', 'Negative')
  70. ->setCellValue('C6', -7.89);
  71. $objPHPExcel->getActiveSheet()->setCellValue('A7', 'Boolean')
  72. ->setCellValue('B7', 'True')
  73. ->setCellValue('C7', true);
  74. $objPHPExcel->getActiveSheet()->setCellValue('A8', 'Boolean')
  75. ->setCellValue('B8', 'False')
  76. ->setCellValue('C8', false);
  77. $dateTimeNow = time();
  78. $objPHPExcel->getActiveSheet()->setCellValue('A9', 'Date/Time')
  79. ->setCellValue('B9', 'Date')
  80. ->setCellValue('C9', PHPExcel_Shared_Date::PHPToExcel( $dateTimeNow ));
  81. $objPHPExcel->getActiveSheet()->getStyle('C9')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDD2);
  82. $objPHPExcel->getActiveSheet()->setCellValue('A10', 'Date/Time')
  83. ->setCellValue('B10', 'Time')
  84. ->setCellValue('C10', PHPExcel_Shared_Date::PHPToExcel( $dateTimeNow ));
  85. $objPHPExcel->getActiveSheet()->getStyle('C10')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME4);
  86. $objPHPExcel->getActiveSheet()->setCellValue('A11', 'Date/Time')
  87. ->setCellValue('B11', 'Date and Time')
  88. ->setCellValue('C11', PHPExcel_Shared_Date::PHPToExcel( $dateTimeNow ));
  89. $objPHPExcel->getActiveSheet()->getStyle('C11')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_DATETIME);
  90. $objPHPExcel->getActiveSheet()->setCellValue('A12', 'NULL')
  91. ->setCellValue('C12', NULL);
  92. $objRichText = new PHPExcel_RichText();
  93. $objRichText->createText('你好 ');
  94. $objPayable = $objRichText->createTextRun('你 好 吗?');
  95. $objPayable->getFont()->setBold(true);
  96. $objPayable->getFont()->setItalic(true);
  97. $objPayable->getFont()->setColor( new PHPExcel_Style_Color( PHPExcel_Style_Color::COLOR_DARKGREEN ) );
  98. $objRichText->createText(', unless specified otherwise on the invoice.');
  99. $objPHPExcel->getActiveSheet()->setCellValue('A13', 'Rich Text')
  100. ->setCellValue('C13', $objRichText);
  101. $objRichText2 = new PHPExcel_RichText();
  102. $objRichText2->createText("black text\n");
  103. $objRed = $objRichText2->createTextRun("red text");
  104. $objRed->getFont()->setColor( new PHPExcel_Style_Color(PHPExcel_Style_Color::COLOR_RED ) );
  105. $objPHPExcel->getActiveSheet()->getCell("C14")->setValue($objRichText2);
  106. $objPHPExcel->getActiveSheet()->getStyle("C14")->getAlignment()->setWrapText(true);
  107. $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setAutoSize(true);
  108. $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setAutoSize(true);
  109. $objRichText3 = new PHPExcel_RichText();
  110. $objRichText3->createText("Hello ");
  111. $objUnderlined = $objRichText3->createTextRun("underlined");
  112. $objUnderlined->getFont()->setUnderline(true);
  113. $objRichText3->createText(' World.');
  114. $objPHPExcel->getActiveSheet()
  115. ->getCell("C15")
  116. ->setValue($objRichText3);
  117. $objPHPExcel->getActiveSheet()->setCellValue('A17', 'Hyperlink');
  118. $objPHPExcel->getActiveSheet()->setCellValue('C17', 'www.phpexcel.net');
  119. $objPHPExcel->getActiveSheet()->getCell('C17')->getHyperlink()->setUrl('http://www.phpexcel.net');
  120. $objPHPExcel->getActiveSheet()->getCell('C17')->getHyperlink()->setTooltip('Navigate to website');
  121. $objPHPExcel->getActiveSheet()->setCellValue('C18', '=HYPERLINK("mailto:[email protected]","[email protected]")');
  122. // Rename worksheet
  123. echo date('H:i:s') , " Rename worksheet" , EOL;
  124. $objPHPExcel->getActiveSheet()->setTitle('Datatypes');
  125. // Set active sheet index to the first sheet, so Excel opens this as the first sheet
  126. $objPHPExcel->setActiveSheetIndex(0);
  127. // Save Excel 2007 file
  128. echo date('H:i:s') , " Write to Excel2007 format" , EOL;
  129. $callStartTime = microtime(true);
  130. $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
  131. $objWriter->save(str_replace('.php', '.xlsx', __FILE__));
  132. $callEndTime = microtime(true);
  133. $callTime = $callEndTime - $callStartTime;
  134. echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL;
  135. echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL;
  136. // Echo memory usage
  137. echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL;
  138. echo date('H:i:s') , " Reload workbook from saved file" , EOL;
  139. $callStartTime = microtime(true);
  140. $objPHPExcel = PHPExcel_IOFactory::load(str_replace('.php', '.xlsx', __FILE__));
  141. $callEndTime = microtime(true);
  142. $callTime = $callEndTime - $callStartTime;
  143. echo 'Call time to reload Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL;
  144. // Echo memory usage
  145. echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL;
  146. var_dump($objPHPExcel->getActiveSheet()->toArray());
  147. // Echo memory peak usage
  148. echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL;
  149. // Echo done
  150. echo date('H:i:s') , " Done testing file" , EOL;
  151. echo 'File has been created in ' , getcwd() , EOL;