11documentsecurity.php 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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
  42. echo date('H:i:s') . " Add some data\n";
  43. $objPHPExcel->setActiveSheetIndex(0);
  44. $objPHPExcel->getActiveSheet()->setCellValue('A1', 'Hello');
  45. $objPHPExcel->getActiveSheet()->setCellValue('B2', 'world!');
  46. $objPHPExcel->getActiveSheet()->setCellValue('C1', 'Hello');
  47. $objPHPExcel->getActiveSheet()->setCellValue('D2', 'world!');
  48. // Rename sheet
  49. echo date('H:i:s') . " Rename sheet\n";
  50. $objPHPExcel->getActiveSheet()->setTitle('Simple');
  51. // Set document security
  52. echo date('H:i:s') . " Set document security\n";
  53. $objPHPExcel->getSecurity()->setLockWindows(true);
  54. $objPHPExcel->getSecurity()->setLockStructure(true);
  55. $objPHPExcel->getSecurity()->setWorkbookPassword("PHPExcel");
  56. // Set sheet security
  57. echo date('H:i:s') . " Set sheet security\n";
  58. $objPHPExcel->getActiveSheet()->getProtection()->setPassword('PHPExcel');
  59. $objPHPExcel->getActiveSheet()->getProtection()->setSheet(true); // This should be enabled in order to enable any of the following!
  60. $objPHPExcel->getActiveSheet()->getProtection()->setSort(true);
  61. $objPHPExcel->getActiveSheet()->getProtection()->setInsertRows(true);
  62. $objPHPExcel->getActiveSheet()->getProtection()->setFormatCells(true);
  63. // Set active sheet index to the first sheet, so Excel opens this as the first sheet
  64. $objPHPExcel->setActiveSheetIndex(0);
  65. // Save Excel 2007 file
  66. echo date('H:i:s') . " Write to Excel2007 format\n";
  67. $objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
  68. $objWriter->save(str_replace('.php', '.xlsx', __FILE__));
  69. // Echo memory peak usage
  70. echo date('H:i:s') . " Peak memory usage: " . (memory_get_peak_usage(true) / 1024 / 1024) . " MB\r\n";
  71. // Echo done
  72. echo date('H:i:s') . " Done writing file.\r\n";