2010-08-26 19:14:53 +00:00
|
|
|
|
<?php
|
|
|
|
|
/**
|
2016-08-16 23:06:51 +00:00
|
|
|
|
* PhpSpreadsheet
|
2010-08-26 19:14:53 +00:00
|
|
|
|
*
|
2016-08-16 23:06:51 +00:00
|
|
|
|
* Copyright (c) 2006 - 2016 PhpSpreadsheet
|
2010-08-26 19:14:53 +00:00
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
*
|
2016-08-16 23:06:51 +00:00
|
|
|
|
* @category PhpSpreadsheet
|
|
|
|
|
* @copyright Copyright (c) 2006 - 2016 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet)
|
|
|
|
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
2010-08-26 19:14:53 +00:00
|
|
|
|
* @version ##VERSION##, ##DATE##
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/** Error reporting */
|
|
|
|
|
error_reporting(E_ALL);
|
2012-08-05 17:54:20 +00:00
|
|
|
|
ini_set('display_errors', TRUE);
|
|
|
|
|
ini_set('display_startup_errors', TRUE);
|
2010-08-26 19:14:53 +00:00
|
|
|
|
date_default_timezone_set('Europe/London');
|
|
|
|
|
|
2012-08-05 17:54:20 +00:00
|
|
|
|
if (PHP_SAPI == 'cli')
|
|
|
|
|
die('This example should only be run from a Web Browser');
|
|
|
|
|
|
2016-08-16 23:06:51 +00:00
|
|
|
|
/** Include PhpSpreadsheet */
|
2016-03-22 13:25:49 +00:00
|
|
|
|
require_once dirname(__FILE__) . '/../src/Bootstrap.php';
|
2010-08-26 19:14:53 +00:00
|
|
|
|
|
|
|
|
|
|
2016-08-16 23:06:51 +00:00
|
|
|
|
// Create new PhpSpreadsheet object
|
|
|
|
|
$objPhpSpreadsheet = new \PhpSpreadsheet\Spreadsheet();
|
2010-08-26 19:14:53 +00:00
|
|
|
|
|
2012-02-12 23:03:57 +00:00
|
|
|
|
// Set document properties
|
2016-08-16 23:06:51 +00:00
|
|
|
|
$objPhpSpreadsheet->getProperties()->setCreator("Maarten Balliauw")
|
|
|
|
|
->setLastModifiedBy("Maarten Balliauw")
|
|
|
|
|
->setTitle("Office 2007 XLSX Test Document")
|
|
|
|
|
->setSubject("Office 2007 XLSX Test Document")
|
|
|
|
|
->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
|
|
|
|
|
->setKeywords("office 2007 openxml php")
|
|
|
|
|
->setCategory("Test result file");
|
2010-08-26 19:14:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Add some data
|
2016-08-16 23:06:51 +00:00
|
|
|
|
$objPhpSpreadsheet->setActiveSheetIndex(0)
|
|
|
|
|
->setCellValue('A1', 'Hello')
|
|
|
|
|
->setCellValue('B2', 'world!')
|
|
|
|
|
->setCellValue('C1', 'Hello')
|
|
|
|
|
->setCellValue('D2', 'world!');
|
2010-08-26 19:14:53 +00:00
|
|
|
|
|
|
|
|
|
// Miscellaneous glyphs, UTF-8
|
2016-08-16 23:06:51 +00:00
|
|
|
|
$objPhpSpreadsheet->setActiveSheetIndex(0)
|
|
|
|
|
->setCellValue('A4', 'Miscellaneous glyphs')
|
|
|
|
|
->setCellValue('A5', 'éàèùâêîôûëïüÿäöüç');
|
2010-08-26 19:14:53 +00:00
|
|
|
|
|
2012-02-12 23:03:57 +00:00
|
|
|
|
// Rename worksheet
|
2016-08-16 23:06:51 +00:00
|
|
|
|
$objPhpSpreadsheet->getActiveSheet()->setTitle('Simple');
|
2010-08-26 19:14:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
|
2016-08-16 23:06:51 +00:00
|
|
|
|
$objPhpSpreadsheet->setActiveSheetIndex(0);
|
2010-08-26 19:14:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Redirect output to a client’s web browser (Excel2007)
|
|
|
|
|
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
|
|
|
|
header('Content-Disposition: attachment;filename="01simple.xlsx"');
|
|
|
|
|
header('Cache-Control: max-age=0');
|
2014-02-09 15:27:36 +00:00
|
|
|
|
// If you're serving to IE 9, then the following may be needed
|
|
|
|
|
header('Cache-Control: max-age=1');
|
|
|
|
|
|
|
|
|
|
// If you're serving to IE over SSL, then the following may be needed
|
|
|
|
|
header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
|
|
|
|
|
header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
|
|
|
|
|
header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
|
|
|
|
|
header ('Pragma: public'); // HTTP/1.0
|
2010-08-26 19:14:53 +00:00
|
|
|
|
|
2016-08-16 23:06:51 +00:00
|
|
|
|
$objWriter = \PhpSpreadsheet\IOFactory::createWriter($objPhpSpreadsheet, 'Excel2007');
|
2010-08-26 19:14:53 +00:00
|
|
|
|
$objWriter->save('php://output');
|
|
|
|
|
exit;
|