Nenhuma Descrição

01simple-download-xlsx.php 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. date_default_timezone_set('Europe/London');
  32. if (PHP_SAPI == 'cli')
  33. die('This example should only be run from a Web Browser');
  34. /** Include PHPExcel */
  35. require_once dirname(__FILE__) . '/../Classes/PHPExcel.php';
  36. // Create new PHPExcel object
  37. $objPHPExcel = new PHPExcel();
  38. // Set document properties
  39. $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
  40. ->setLastModifiedBy("Maarten Balliauw")
  41. ->setTitle("Office 2007 XLSX Test Document")
  42. ->setSubject("Office 2007 XLSX Test Document")
  43. ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
  44. ->setKeywords("office 2007 openxml php")
  45. ->setCategory("Test result file");
  46. // Add some data
  47. $objPHPExcel->setActiveSheetIndex(0)
  48. ->setCellValue('A1', 'Hello')
  49. ->setCellValue('B2', 'world!')
  50. ->setCellValue('C1', 'Hello')
  51. ->setCellValue('D2', 'world!');
  52. // Miscellaneous glyphs, UTF-8
  53. $objPHPExcel->setActiveSheetIndex(0)
  54. ->setCellValue('A4', 'Miscellaneous glyphs')
  55. ->setCellValue('A5', 'éàèùâêîôûëïüÿäöüç');
  56. // Rename worksheet
  57. $objPHPExcel->getActiveSheet()->setTitle('Simple');
  58. // Set active sheet index to the first sheet, so Excel opens this as the first sheet
  59. $objPHPExcel->setActiveSheetIndex(0);
  60. // Redirect output to a client’s web browser (Excel2007)
  61. header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  62. header('Content-Disposition: attachment;filename="01simple.xlsx"');
  63. header('Cache-Control: max-age=0');
  64. // If you're serving to IE 9, then the following may be needed
  65. header('Cache-Control: max-age=1');
  66. // If you're serving to IE over SSL, then the following may be needed
  67. header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  68. header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
  69. header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
  70. header ('Pragma: public'); // HTTP/1.0
  71. $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
  72. $objWriter->save('php://output');
  73. exit;