Няма описание

26utf8.php 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. // Change these values to select the PDF Rendering library that you wish to use
  36. // and its directory location on your server
  37. //$rendererName = PHPExcel_Settings::PDF_RENDERER_TCPDF;
  38. //$rendererName = PHPExcel_Settings::PDF_RENDERER_MPDF;
  39. $rendererName = PHPExcel_Settings::PDF_RENDERER_DOMPDF;
  40. //$rendererLibrary = 'tcPDF5.9';
  41. //$rendererLibrary = 'mPDF5.4';
  42. $rendererLibrary = 'domPDF0.6.0beta3';
  43. $rendererLibraryPath = '/php/libraries/PDF/' . $rendererLibrary;
  44. // Read from Excel2007 (.xlsx) template
  45. echo date('H:i:s') , " Load Excel2007 template file" , EOL;
  46. $objReader = PHPExcel_IOFactory::createReader('Excel2007');
  47. $objPHPExcel = $objReader->load("templates/26template.xlsx");
  48. /** at this point, we could do some manipulations with the template, but we skip this step */
  49. // Export to Excel2007 (.xlsx)
  50. echo date('H:i:s') , " Write to Excel5 format" , EOL;
  51. $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
  52. $objWriter->save(str_replace('.php', '.xlsx', __FILE__));
  53. echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL;
  54. // Export to Excel5 (.xls)
  55. echo date('H:i:s') , " Write to Excel5 format" , EOL;
  56. $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  57. $objWriter->save(str_replace('.php', '.xls', __FILE__));
  58. echo date('H:i:s') , " File written to " , str_replace('.php', '.xls', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL;
  59. // Export to HTML (.html)
  60. echo date('H:i:s') , " Write to HTML format" , EOL;
  61. $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'HTML');
  62. $objWriter->save(str_replace('.php', '.htm', __FILE__));
  63. echo date('H:i:s') , " File written to " , str_replace('.php', '.htm', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL;
  64. // Export to PDF (.pdf)
  65. echo date('H:i:s') , " Write to PDF format" , EOL;
  66. try {
  67. if (!PHPExcel_Settings::setPdfRenderer(
  68. $rendererName,
  69. $rendererLibraryPath
  70. )) {
  71. echo (
  72. 'NOTICE: Please set the $rendererName and $rendererLibraryPath values' .
  73. EOL .
  74. 'at the top of this script as appropriate for your directory structure' .
  75. EOL
  76. );
  77. } else {
  78. $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'PDF');
  79. $objWriter->save(str_replace('.php', '.pdf', __FILE__));
  80. echo date('H:i:s') , " File written to " , str_replace('.php', '.pdf', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL;
  81. }
  82. } catch (Exception $e) {
  83. echo date('H:i:s') , ' EXCEPTION: ', $e->getMessage() , EOL;
  84. }
  85. // Remove first two rows with field headers before exporting to CSV
  86. echo date('H:i:s') , " Removing first two heading rows for CSV export" , EOL;
  87. $objWorksheet = $objPHPExcel->getActiveSheet();
  88. $objWorksheet->removeRow(1, 2);
  89. // Export to CSV (.csv)
  90. echo date('H:i:s') , " Write to CSV format" , EOL;
  91. $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'CSV');
  92. $objWriter->save(str_replace('.php', '.csv', __FILE__));
  93. echo date('H:i:s') , " File written to " , str_replace('.php', '.csv', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL;
  94. // Export to CSV with BOM (.csv)
  95. echo date('H:i:s') , " Write to CSV format (with BOM)" , EOL;
  96. $objWriter->setUseBOM(true);
  97. $objWriter->save(str_replace('.php', '-bom.csv', __FILE__));
  98. echo date('H:i:s') , " File written to " , str_replace('.php', '-bom.csv', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL;
  99. // Echo memory peak usage
  100. echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL;
  101. // Echo done
  102. echo date('H:i:s') , " Done writing files" , EOL;
  103. echo 'Files have been created in ' , getcwd() , EOL;