03formulas.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 some formulas here
  42. echo date('H:i:s') . " Add some data\n";
  43. $objPHPExcel->getActiveSheet()->setCellValue('A5', 'Sum:');
  44. $objPHPExcel->getActiveSheet()->setCellValue('B1', 'Range 1');
  45. $objPHPExcel->getActiveSheet()->setCellValue('B2', 2);
  46. $objPHPExcel->getActiveSheet()->setCellValue('B3', 8);
  47. $objPHPExcel->getActiveSheet()->setCellValue('B4', 10);
  48. $objPHPExcel->getActiveSheet()->setCellValue('B5', '=SUM(B2:B4)');
  49. $objPHPExcel->getActiveSheet()->setCellValue('C1', 'Range 2');
  50. $objPHPExcel->getActiveSheet()->setCellValue('C2', 3);
  51. $objPHPExcel->getActiveSheet()->setCellValue('C3', 9);
  52. $objPHPExcel->getActiveSheet()->setCellValue('C4', 11);
  53. $objPHPExcel->getActiveSheet()->setCellValue('C5', '=SUM(C2:C4)');
  54. $objPHPExcel->getActiveSheet()->setCellValue('A7', 'Total of both ranges:');
  55. $objPHPExcel->getActiveSheet()->setCellValue('B7', '=SUM(B5:C5)');
  56. $objPHPExcel->getActiveSheet()->setCellValue('A8', 'Minimum of both ranges:');
  57. $objPHPExcel->getActiveSheet()->setCellValue('B8', '=MIN(B2:C5)');
  58. // Rename sheet
  59. echo date('H:i:s') . " Rename sheet\n";
  60. $objPHPExcel->getActiveSheet()->setTitle('Formulas');
  61. // Set active sheet index to the first sheet, so Excel opens this as the first sheet
  62. $objPHPExcel->setActiveSheetIndex(0);
  63. // Save Excel 2007 file
  64. echo date('H:i:s') . " Write to Excel2007 format\n";
  65. $objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
  66. $objWriter->save(str_replace('.php', '.xlsx', __FILE__));
  67. // Echo memory peak usage
  68. echo date('H:i:s') . " Peak memory usage: " . (memory_get_peak_usage(true) / 1024 / 1024) . " MB\r\n";
  69. // Echo done
  70. echo date('H:i:s') . " Done writing file.\r\n";