04printing.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * PHPExcel
  4. *
  5. * Copyright (C) 2006 - 2008 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 - 2008 PHPExcel (http://www.codeplex.com/PHPExcel)
  24. * @license http://www.gnu.org/licenses/lgpl.txt LGPL
  25. * @version 1.6.0, 2008-02-14
  26. */
  27. /* Modified by Bertrand Zuchuat */
  28. require_once 'symfony.inc.php';
  29. // Create new PHPExcel object
  30. echo date('H:i:s') . " Create new PHPExcel object\n";
  31. $objPHPExcel = new sfPhpExcel();
  32. // Set properties
  33. echo date('H:i:s') . " Set properties\n";
  34. $objPHPExcel->getProperties()->setCreator("Maarten Balliauw");
  35. $objPHPExcel->getProperties()->setLastModifiedBy("Maarten Balliauw");
  36. $objPHPExcel->getProperties()->setTitle("Office 2007 XLSX Test Document");
  37. $objPHPExcel->getProperties()->setSubject("Office 2007 XLSX Test Document");
  38. $objPHPExcel->getProperties()->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.");
  39. $objPHPExcel->getProperties()->setKeywords("office 2007 openxml php");
  40. $objPHPExcel->getProperties()->setCategory("Test result file");
  41. // Add some data, we will use printing features
  42. echo date('H:i:s') . " Add some data\n";
  43. for ($i = 1; $i < 200; $i++) {
  44. $objPHPExcel->getActiveSheet()->setCellValue('A' . $i, $i);
  45. $objPHPExcel->getActiveSheet()->setCellValue('B' . $i, 'Test value');
  46. }
  47. // Set header and footer. When no different headers for odd/even are used, odd header is assumed.
  48. echo date('H:i:s') . " Set header/footer\n";
  49. $objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddHeader('&C&HPlease treat this document as confidential!');
  50. $objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddFooter('&L&B' . $objPHPExcel->getProperties()->getTitle() . '&RPage &P of &N');
  51. // Set page orientation and size
  52. echo date('H:i:s') . " Set page orientation and size\n";
  53. $objPHPExcel->getActiveSheet()->getPageSetup()->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE);
  54. $objPHPExcel->getActiveSheet()->getPageSetup()->setPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4);
  55. // Rename sheet
  56. echo date('H:i:s') . " Rename sheet\n";
  57. $objPHPExcel->getActiveSheet()->setTitle('Printing');
  58. // Set active sheet index to the first sheet, so Excel opens this as the first sheet
  59. $objPHPExcel->setActiveSheetIndex(0);
  60. // Save Excel 2007 file
  61. echo date('H:i:s') . " Write to Excel2007 format\n";
  62. $objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
  63. $objWriter->save(str_replace('.php', '.xlsx', __FILE__));
  64. // Echo memory peak usage
  65. echo date('H:i:s') . " Peak memory usage: " . (memory_get_peak_usage(true) / 1024 / 1024) . " MB\r\n";
  66. // Echo done
  67. echo date('H:i:s') . " Done writing file.\r\n";