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.

122 lines
4.8 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. 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;