gh-17 Update examples for namespace changes

This commit is contained in:
MarkBaker 2016-08-17 00:06:51 +01:00
parent 5c03e85531
commit e87ec8505d
11 changed files with 344 additions and 493 deletions

View File

@ -1,8 +1,8 @@
<?php <?php
/** /**
* PHPExcel * PhpSpreadsheet
* *
* Copyright (c) 2006 - 2015 PHPExcel * Copyright (c) 2006 - 2016 PhpSpreadsheet
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -18,9 +18,8 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* @category PHPExcel * @category PhpSpreadsheet
* @package PHPExcel * @copyright Copyright (c) 2006 - 2016 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet)
* @copyright Copyright (c) 2006 - 2015 PHPExcel (https://github.com/PHPOffice/PhpSpreadsheet)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE## * @version ##VERSION##, ##DATE##
*/ */
@ -34,15 +33,15 @@ date_default_timezone_set('Europe/London');
if (PHP_SAPI == 'cli') if (PHP_SAPI == 'cli')
die('This example should only be run from a Web Browser'); die('This example should only be run from a Web Browser');
/** Include PHPExcel */ /** Include PhpSpreadsheet */
require_once dirname(__FILE__) . '/../src/Bootstrap.php'; require_once dirname(__FILE__) . '/../src/Bootstrap.php';
// Create new PHPExcel object // Create new PhpSpreadsheet object
$objPHPExcel = new \PHPExcel\Spreadsheet(); $objPhpSpreadsheet = new \PhpSpreadsheet\Spreadsheet();
// Set document properties // Set document properties
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw") $objPhpSpreadsheet->getProperties()->setCreator("Maarten Balliauw")
->setLastModifiedBy("Maarten Balliauw") ->setLastModifiedBy("Maarten Balliauw")
->setTitle("Office 2007 XLSX Test Document") ->setTitle("Office 2007 XLSX Test Document")
->setSubject("Office 2007 XLSX Test Document") ->setSubject("Office 2007 XLSX Test Document")
@ -52,23 +51,23 @@ $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
// Add some data // Add some data
$objPHPExcel->setActiveSheetIndex(0) $objPhpSpreadsheet->setActiveSheetIndex(0)
->setCellValue('A1', 'Hello') ->setCellValue('A1', 'Hello')
->setCellValue('B2', 'world!') ->setCellValue('B2', 'world!')
->setCellValue('C1', 'Hello') ->setCellValue('C1', 'Hello')
->setCellValue('D2', 'world!'); ->setCellValue('D2', 'world!');
// Miscellaneous glyphs, UTF-8 // Miscellaneous glyphs, UTF-8
$objPHPExcel->setActiveSheetIndex(0) $objPhpSpreadsheet->setActiveSheetIndex(0)
->setCellValue('A4', 'Miscellaneous glyphs') ->setCellValue('A4', 'Miscellaneous glyphs')
->setCellValue('A5', 'éàèùâêîôûëïüÿäöüç'); ->setCellValue('A5', 'éàèùâêîôûëïüÿäöüç');
// Rename worksheet // Rename worksheet
$objPHPExcel->getActiveSheet()->setTitle('Simple'); $objPhpSpreadsheet->getActiveSheet()->setTitle('Simple');
// Set active sheet index to the first sheet, so Excel opens this as the first sheet // Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0); $objPhpSpreadsheet->setActiveSheetIndex(0);
// Redirect output to a clients web browser (OpenDocument) // Redirect output to a clients web browser (OpenDocument)
@ -84,6 +83,6 @@ header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1 header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
header ('Pragma: public'); // HTTP/1.0 header ('Pragma: public'); // HTTP/1.0
$objWriter = \PHPExcel\IOFactory::createWriter($objPHPExcel, 'OpenDocument'); $objWriter = \PhpSpreadsheet\IOFactory::createWriter($objPhpSpreadsheet, 'OpenDocument');
$objWriter->save('php://output'); $objWriter->save('php://output');
exit; exit;

View File

@ -1,8 +1,8 @@
<?php <?php
/** /**
* PHPExcel * PhpSpreadsheet
* *
* Copyright (c) 2006 - 2015 PHPExcel * Copyright (c) 2006 - 2016 PhpSpreadsheet
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -18,9 +18,8 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* @category PHPExcel * @category PhpSpreadsheet
* @package PHPExcel * @copyright Copyright (c) 2006 - 2016 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet)
* @copyright Copyright (c) 2006 - 2015 PHPExcel (https://github.com/PHPOffice/PhpSpreadsheet)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE## * @version ##VERSION##, ##DATE##
*/ */
@ -34,26 +33,26 @@ date_default_timezone_set('Europe/London');
if (PHP_SAPI == 'cli') if (PHP_SAPI == 'cli')
die('This example should only be run from a Web Browser'); die('This example should only be run from a Web Browser');
/** Include PHPExcel */ /** Include PhpSpreadsheet */
require_once dirname(__FILE__) . '/../src/Bootstrap.php'; require_once dirname(__FILE__) . '/../src/Bootstrap.php';
// Change these values to select the Rendering library that you wish to use // Change these values to select the Rendering library that you wish to use
// and its directory location on your server // and its directory location on your server
//$rendererName = PHPExcel\Settings::PDF_RENDERER_TCPDF; //$rendererName = PhpSpreadsheet\Settings::PDF_RENDERER_TCPDF;
$rendererName = PHPExcel\Settings::PDF_RENDERER_MPDF; $rendererName = PhpSpreadsheet\Settings::PDF_RENDERER_MPDF;
//$rendererName = PHPExcel\Settings::PDF_RENDERER_DOMPDF; //$rendererName = PhpSpreadsheet\Settings::PDF_RENDERER_DOMPDF;
//$rendererLibrary = 'tcPDF5.9'; //$rendererLibrary = 'tcPDF5.9';
$rendererLibrary = 'mPDF5.4'; $rendererLibrary = 'mPDF5.4';
//$rendererLibrary = 'domPDF0.6.0beta3'; //$rendererLibrary = 'domPDF0.6.0beta3';
$rendererLibraryPath = dirname(__FILE__).'/../../../libraries/PDF/' . $rendererLibrary; $rendererLibraryPath = dirname(__FILE__).'/../../../libraries/PDF/' . $rendererLibrary;
// Create new PHPExcel object // Create new PhpSpreadsheet object
$objPHPExcel = new \PHPExcel\Spreadsheet(); $objPhpSpreadsheet = new \PhpSpreadsheet\Spreadsheet();
// Set document properties // Set document properties
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw") $objPhpSpreadsheet->getProperties()->setCreator("Maarten Balliauw")
->setLastModifiedBy("Maarten Balliauw") ->setLastModifiedBy("Maarten Balliauw")
->setTitle("PDF Test Document") ->setTitle("PDF Test Document")
->setSubject("PDF Test Document") ->setSubject("PDF Test Document")
@ -63,26 +62,26 @@ $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
// Add some data // Add some data
$objPHPExcel->setActiveSheetIndex(0) $objPhpSpreadsheet->setActiveSheetIndex(0)
->setCellValue('A1', 'Hello') ->setCellValue('A1', 'Hello')
->setCellValue('B2', 'world!') ->setCellValue('B2', 'world!')
->setCellValue('C1', 'Hello') ->setCellValue('C1', 'Hello')
->setCellValue('D2', 'world!'); ->setCellValue('D2', 'world!');
// Miscellaneous glyphs, UTF-8 // Miscellaneous glyphs, UTF-8
$objPHPExcel->setActiveSheetIndex(0) $objPhpSpreadsheet->setActiveSheetIndex(0)
->setCellValue('A4', 'Miscellaneous glyphs') ->setCellValue('A4', 'Miscellaneous glyphs')
->setCellValue('A5', 'éàèùâêîôûëïüÿäöüç'); ->setCellValue('A5', 'éàèùâêîôûëïüÿäöüç');
// Rename worksheet // Rename worksheet
$objPHPExcel->getActiveSheet()->setTitle('Simple'); $objPhpSpreadsheet->getActiveSheet()->setTitle('Simple');
$objPHPExcel->getActiveSheet()->setShowGridLines(false); $objPhpSpreadsheet->getActiveSheet()->setShowGridLines(false);
// Set active sheet index to the first sheet, so Excel opens this as the first sheet // Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0); $objPhpSpreadsheet->setActiveSheetIndex(0);
if (!PHPExcel\Settings::setPdfRenderer( if (!PhpSpreadsheet\Settings::setPdfRenderer(
$rendererName, $rendererName,
$rendererLibraryPath $rendererLibraryPath
)) { )) {
@ -99,6 +98,6 @@ header('Content-Type: application/pdf');
header('Content-Disposition: attachment;filename="01simple.pdf"'); header('Content-Disposition: attachment;filename="01simple.pdf"');
header('Cache-Control: max-age=0'); header('Cache-Control: max-age=0');
$objWriter = \PHPExcel\IOFactory::createWriter($objPHPExcel, 'PDF'); $objWriter = \PhpSpreadsheet\IOFactory::createWriter($objPhpSpreadsheet, 'PDF');
$objWriter->save('php://output'); $objWriter->save('php://output');
exit; exit;

View File

@ -1,8 +1,8 @@
<?php <?php
/** /**
* PHPExcel * PhpSpreadsheet
* *
* Copyright (c) 2006 - 2015 PHPExcel * Copyright (c) 2006 - 2016 PhpSpreadsheet
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -18,9 +18,8 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* @category PHPExcel * @category PhpSpreadsheet
* @package PHPExcel * @copyright Copyright (c) 2006 - 2016 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet)
* @copyright Copyright (c) 2006 - 2015 PHPExcel (https://github.com/PHPOffice/PhpSpreadsheet)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE## * @version ##VERSION##, ##DATE##
*/ */
@ -34,15 +33,15 @@ date_default_timezone_set('Europe/London');
if (PHP_SAPI == 'cli') if (PHP_SAPI == 'cli')
die('This example should only be run from a Web Browser'); die('This example should only be run from a Web Browser');
/** Include PHPExcel */ /** Include PhpSpreadsheet */
require_once dirname(__FILE__) . '/../src/Bootstrap.php'; require_once dirname(__FILE__) . '/../src/Bootstrap.php';
// Create new PHPExcel object // Create new PhpSpreadsheet object
$objPHPExcel = new \PHPExcel\Spreadsheet(); $objPhpSpreadsheet = new \PhpSpreadsheet\Spreadsheet();
// Set document properties // Set document properties
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw") $objPhpSpreadsheet->getProperties()->setCreator("Maarten Balliauw")
->setLastModifiedBy("Maarten Balliauw") ->setLastModifiedBy("Maarten Balliauw")
->setTitle("Office 2007 XLSX Test Document") ->setTitle("Office 2007 XLSX Test Document")
->setSubject("Office 2007 XLSX Test Document") ->setSubject("Office 2007 XLSX Test Document")
@ -52,23 +51,23 @@ $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
// Add some data // Add some data
$objPHPExcel->setActiveSheetIndex(0) $objPhpSpreadsheet->setActiveSheetIndex(0)
->setCellValue('A1', 'Hello') ->setCellValue('A1', 'Hello')
->setCellValue('B2', 'world!') ->setCellValue('B2', 'world!')
->setCellValue('C1', 'Hello') ->setCellValue('C1', 'Hello')
->setCellValue('D2', 'world!'); ->setCellValue('D2', 'world!');
// Miscellaneous glyphs, UTF-8 // Miscellaneous glyphs, UTF-8
$objPHPExcel->setActiveSheetIndex(0) $objPhpSpreadsheet->setActiveSheetIndex(0)
->setCellValue('A4', 'Miscellaneous glyphs') ->setCellValue('A4', 'Miscellaneous glyphs')
->setCellValue('A5', 'éàèùâêîôûëïüÿäöüç'); ->setCellValue('A5', 'éàèùâêîôûëïüÿäöüç');
// Rename worksheet // Rename worksheet
$objPHPExcel->getActiveSheet()->setTitle('Simple'); $objPhpSpreadsheet->getActiveSheet()->setTitle('Simple');
// Set active sheet index to the first sheet, so Excel opens this as the first sheet // Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0); $objPhpSpreadsheet->setActiveSheetIndex(0);
// Redirect output to a clients web browser (Excel5) // Redirect output to a clients web browser (Excel5)
@ -84,6 +83,6 @@ header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1 header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
header ('Pragma: public'); // HTTP/1.0 header ('Pragma: public'); // HTTP/1.0
$objWriter = \PHPExcel\IOFactory::createWriter($objPHPExcel, 'Excel5'); $objWriter = \PhpSpreadsheet\IOFactory::createWriter($objPhpSpreadsheet, 'Excel5');
$objWriter->save('php://output'); $objWriter->save('php://output');
exit; exit;

View File

@ -1,8 +1,8 @@
<?php <?php
/** /**
* PHPExcel * PhpSpreadsheet
* *
* Copyright (c) 2006 - 2015 PHPExcel * Copyright (c) 2006 - 2016 PhpSpreadsheet
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -18,9 +18,8 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* @category PHPExcel * @category PhpSpreadsheet
* @package PHPExcel * @copyright Copyright (c) 2006 - 2016 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet)
* @copyright Copyright (c) 2006 - 2015 PHPExcel (https://github.com/PHPOffice/PhpSpreadsheet)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE## * @version ##VERSION##, ##DATE##
*/ */
@ -34,15 +33,15 @@ date_default_timezone_set('Europe/London');
if (PHP_SAPI == 'cli') if (PHP_SAPI == 'cli')
die('This example should only be run from a Web Browser'); die('This example should only be run from a Web Browser');
/** Include PHPExcel */ /** Include PhpSpreadsheet */
require_once dirname(__FILE__) . '/../src/Bootstrap.php'; require_once dirname(__FILE__) . '/../src/Bootstrap.php';
// Create new PHPExcel object // Create new PhpSpreadsheet object
$objPHPExcel = new \PHPExcel\Spreadsheet(); $objPhpSpreadsheet = new \PhpSpreadsheet\Spreadsheet();
// Set document properties // Set document properties
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw") $objPhpSpreadsheet->getProperties()->setCreator("Maarten Balliauw")
->setLastModifiedBy("Maarten Balliauw") ->setLastModifiedBy("Maarten Balliauw")
->setTitle("Office 2007 XLSX Test Document") ->setTitle("Office 2007 XLSX Test Document")
->setSubject("Office 2007 XLSX Test Document") ->setSubject("Office 2007 XLSX Test Document")
@ -52,23 +51,23 @@ $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
// Add some data // Add some data
$objPHPExcel->setActiveSheetIndex(0) $objPhpSpreadsheet->setActiveSheetIndex(0)
->setCellValue('A1', 'Hello') ->setCellValue('A1', 'Hello')
->setCellValue('B2', 'world!') ->setCellValue('B2', 'world!')
->setCellValue('C1', 'Hello') ->setCellValue('C1', 'Hello')
->setCellValue('D2', 'world!'); ->setCellValue('D2', 'world!');
// Miscellaneous glyphs, UTF-8 // Miscellaneous glyphs, UTF-8
$objPHPExcel->setActiveSheetIndex(0) $objPhpSpreadsheet->setActiveSheetIndex(0)
->setCellValue('A4', 'Miscellaneous glyphs') ->setCellValue('A4', 'Miscellaneous glyphs')
->setCellValue('A5', 'éàèùâêîôûëïüÿäöüç'); ->setCellValue('A5', 'éàèùâêîôûëïüÿäöüç');
// Rename worksheet // Rename worksheet
$objPHPExcel->getActiveSheet()->setTitle('Simple'); $objPhpSpreadsheet->getActiveSheet()->setTitle('Simple');
// Set active sheet index to the first sheet, so Excel opens this as the first sheet // Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0); $objPhpSpreadsheet->setActiveSheetIndex(0);
// Redirect output to a clients web browser (Excel2007) // Redirect output to a clients web browser (Excel2007)
@ -84,6 +83,6 @@ header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1 header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
header ('Pragma: public'); // HTTP/1.0 header ('Pragma: public'); // HTTP/1.0
$objWriter = \PHPExcel\IOFactory::createWriter($objPHPExcel, 'Excel2007'); $objWriter = \PhpSpreadsheet\IOFactory::createWriter($objPhpSpreadsheet, 'Excel2007');
$objWriter->save('php://output'); $objWriter->save('php://output');
exit; exit;

View File

@ -1,8 +1,8 @@
<?php <?php
/** /**
* PHPExcel * PhpSpreadsheet
* *
* Copyright (c) 2006 - 2015 PHPExcel * Copyright (c) 2006 - 2016 PhpSpreadsheet
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -18,9 +18,8 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* @category PHPExcel * @category PhpSpreadsheet
* @package PHPExcel * @copyright Copyright (c) 2006 - 2016 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet)
* @copyright Copyright (c) 2006 - 2015 PHPExcel (https://github.com/PHPOffice/PhpSpreadsheet)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE## * @version ##VERSION##, ##DATE##
*/ */
@ -33,81 +32,81 @@ date_default_timezone_set('Europe/London');
define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />'); define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
/** Include PHPExcel */ /** Include PhpSpreadsheet */
require_once dirname(__FILE__) . '/../src/Bootstrap.php'; require_once dirname(__FILE__) . '/../src/Bootstrap.php';
// Create new PHPExcel object // Create new Spreadsheet object
echo date('H:i:s') , " Create new PHPExcel object" , EOL; echo date('H:i:s') , " Create new Spreadsheet object" , EOL;
$objPHPExcel = new \PHPExcel\Spreadsheet(); $objPhpSpreadsheet = new \PhpSpreadsheet\Spreadsheet();
// Set document properties // Set document properties
echo date('H:i:s') , " Set document properties" , EOL; echo date('H:i:s') , " Set document properties" , EOL;
$objPHPExcel->getProperties() $objPhpSpreadsheet->getProperties()
->setCreator("Maarten Balliauw") ->setCreator("Maarten Balliauw")
->setLastModifiedBy("Maarten Balliauw") ->setLastModifiedBy("Maarten Balliauw")
->setTitle("PHPExcel Test Document") ->setTitle("PhpSpreadsheet Test Document")
->setSubject("PHPExcel Test Document") ->setSubject("PhpSpreadsheet Test Document")
->setDescription("Test document for PHPExcel, generated using PHP classes.") ->setDescription("Test document for PhpSpreadsheet, generated using PHP classes.")
->setKeywords("office PHPExcel php") ->setKeywords("office PhpSpreadsheet php")
->setCategory("Test result file"); ->setCategory("Test result file");
// Add some data // Add some data
echo date('H:i:s') , " Add some data" , EOL; echo date('H:i:s') , " Add some data" , EOL;
$objPHPExcel->setActiveSheetIndex(0) $objPhpSpreadsheet->setActiveSheetIndex(0)
->setCellValue('A1', 'Hello') ->setCellValue('A1', 'Hello')
->setCellValue('B2', 'world!') ->setCellValue('B2', 'world!')
->setCellValue('C1', 'Hello') ->setCellValue('C1', 'Hello')
->setCellValue('D2', 'world!'); ->setCellValue('D2', 'world!');
// Miscellaneous glyphs, UTF-8 // Miscellaneous glyphs, UTF-8
$objPHPExcel->setActiveSheetIndex(0) $objPhpSpreadsheet->setActiveSheetIndex(0)
->setCellValue('A4', 'Miscellaneous glyphs') ->setCellValue('A4', 'Miscellaneous glyphs')
->setCellValue('A5', 'éàèùâêîôûëïüÿäöüç'); ->setCellValue('A5', 'éàèùâêîôûëïüÿäöüç');
$objPHPExcel->getActiveSheet() $objPhpSpreadsheet->getActiveSheet()
->setCellValue('A8',"Hello\nWorld"); ->setCellValue('A8',"Hello\nWorld");
$objPHPExcel->getActiveSheet() $objPhpSpreadsheet->getActiveSheet()
->getRowDimension(8) ->getRowDimension(8)
->setRowHeight(-1); ->setRowHeight(-1);
$objPHPExcel->getActiveSheet() $objPhpSpreadsheet->getActiveSheet()
->getStyle('A8') ->getStyle('A8')
->getAlignment() ->getAlignment()
->setWrapText(true); ->setWrapText(true);
$value = "-ValueA\n-Value B\n-Value C"; $value = "-ValueA\n-Value B\n-Value C";
$objPHPExcel->getActiveSheet() $objPhpSpreadsheet->getActiveSheet()
->setCellValue('A10', $value); ->setCellValue('A10', $value);
$objPHPExcel->getActiveSheet() $objPhpSpreadsheet->getActiveSheet()
->getRowDimension(10) ->getRowDimension(10)
->setRowHeight(-1); ->setRowHeight(-1);
$objPHPExcel->getActiveSheet() $objPhpSpreadsheet->getActiveSheet()
->getStyle('A10') ->getStyle('A10')
->getAlignment() ->getAlignment()
->setWrapText(true); ->setWrapText(true);
$objPHPExcel->getActiveSheet() $objPhpSpreadsheet->getActiveSheet()
->getStyle('A10') ->getStyle('A10')
->setQuotePrefix(true); ->setQuotePrefix(true);
// Rename worksheet // Rename worksheet
echo date('H:i:s') , " Rename worksheet" , EOL; echo date('H:i:s') , " Rename worksheet" , EOL;
$objPHPExcel->getActiveSheet() $objPhpSpreadsheet->getActiveSheet()
->setTitle('Simple'); ->setTitle('Simple');
// Set active sheet index to the first sheet, so Excel opens this as the first sheet // Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0); $objPhpSpreadsheet->setActiveSheetIndex(0);
// Save Excel 2007 file // Save Excel 2007 file
echo date('H:i:s') , " Write to Excel2007 format" , EOL; echo date('H:i:s') , " Write to Excel2007 format" , EOL;
$callStartTime = microtime(true); $callStartTime = microtime(true);
$objWriter = \PHPExcel\IOFactory::createWriter($objPHPExcel, 'Excel2007'); $objWriter = \PhpSpreadsheet\IOFactory::createWriter($objPhpSpreadsheet, 'Excel2007');
$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); $objWriter->save(str_replace('.php', '.xlsx', __FILE__));
$callEndTime = microtime(true); $callEndTime = microtime(true);
$callTime = $callEndTime - $callStartTime; $callTime = $callEndTime - $callStartTime;
@ -122,7 +121,7 @@ echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024
echo date('H:i:s') , " Write to Excel5 format" , EOL; echo date('H:i:s') , " Write to Excel5 format" , EOL;
$callStartTime = microtime(true); $callStartTime = microtime(true);
$objWriter = \PHPExcel\IOFactory::createWriter($objPHPExcel, 'Excel5'); $objWriter = \PhpSpreadsheet\IOFactory::createWriter($objPhpSpreadsheet, 'Excel5');
$objWriter->save(str_replace('.php', '.xls', __FILE__)); $objWriter->save(str_replace('.php', '.xls', __FILE__));
$callEndTime = microtime(true); $callEndTime = microtime(true);
$callTime = $callEndTime - $callStartTime; $callTime = $callEndTime - $callStartTime;

View File

@ -1,8 +1,8 @@
<?php <?php
/** /**
* PHPExcel * PhpSpreadsheet
* *
* Copyright (c) 2006 - 2015 PHPExcel * Copyright (c) 2006 - 2016 PhpSpreadsheet
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -18,9 +18,8 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* @category PHPExcel * @category PhpSpreadsheet
* @package PHPExcel * @copyright Copyright (c) 2006 - 2016 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet)
* @copyright Copyright (c) 2006 - 2015 PHPExcel (https://github.com/PHPOffice/PhpSpreadsheet)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE## * @version ##VERSION##, ##DATE##
*/ */
@ -33,51 +32,51 @@ date_default_timezone_set('Europe/London');
define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />'); define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
/** Include PHPExcel */ /** Include PhpSpreadsheet */
require_once dirname(__FILE__) . '/../src/Bootstrap.php'; require_once dirname(__FILE__) . '/../src/Bootstrap.php';
// Create new PHPExcel object // Create new PhpSpreadsheet object
echo date('H:i:s') , " Create new PHPExcel object" , EOL; echo date('H:i:s') , " Create new PhpSpreadsheet object" , EOL;
$objPHPExcel = new \PHPExcel\Spreadsheet(); $objPhpSpreadsheet = new \PhpSpreadsheet\Spreadsheet();
// Set document properties // Set document properties
echo date('H:i:s') , " Set document properties" , EOL; echo date('H:i:s') , " Set document properties" , EOL;
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw") $objPhpSpreadsheet->getProperties()->setCreator("Maarten Balliauw")
->setLastModifiedBy("Maarten Balliauw") ->setLastModifiedBy("Maarten Balliauw")
->setTitle("PHPExcel Test Document") ->setTitle("PhpSpreadsheet Test Document")
->setSubject("PHPExcel Test Document") ->setSubject("PhpSpreadsheet Test Document")
->setDescription("Test document for PHPExcel, generated using PHP classes.") ->setDescription("Test document for PhpSpreadsheet, generated using PHP classes.")
->setKeywords("office PHPExcel php") ->setKeywords("office PhpSpreadsheet php")
->setCategory("Test result file"); ->setCategory("Test result file");
// Add some data // Add some data
echo date('H:i:s') , " Add some data" , EOL; echo date('H:i:s') , " Add some data" , EOL;
$objPHPExcel->setActiveSheetIndex(0) $objPhpSpreadsheet->setActiveSheetIndex(0)
->setCellValue('A1', 'Hello') ->setCellValue('A1', 'Hello')
->setCellValue('B2', 'world!') ->setCellValue('B2', 'world!')
->setCellValue('C1', 'Hello') ->setCellValue('C1', 'Hello')
->setCellValue('D2', 'world!'); ->setCellValue('D2', 'world!');
// Miscellaneous glyphs, UTF-8 // Miscellaneous glyphs, UTF-8
$objPHPExcel->setActiveSheetIndex(0) $objPhpSpreadsheet->setActiveSheetIndex(0)
->setCellValue('A4', 'Miscellaneous glyphs') ->setCellValue('A4', 'Miscellaneous glyphs')
->setCellValue('A5', 'éàèùâêîôûëïüÿäöüç'); ->setCellValue('A5', 'éàèùâêîôûëïüÿäöüç');
$objPHPExcel->getActiveSheet()->setCellValue('A8',"Hello\nWorld"); $objPhpSpreadsheet->getActiveSheet()->setCellValue('A8',"Hello\nWorld");
$objPHPExcel->getActiveSheet()->getRowDimension(8)->setRowHeight(-1); $objPhpSpreadsheet->getActiveSheet()->getRowDimension(8)->setRowHeight(-1);
$objPHPExcel->getActiveSheet()->getStyle('A8')->getAlignment()->setWrapText(true); $objPhpSpreadsheet->getActiveSheet()->getStyle('A8')->getAlignment()->setWrapText(true);
// Rename worksheet // Rename worksheet
echo date('H:i:s') , " Rename worksheet" , EOL; echo date('H:i:s') , " Rename worksheet" , EOL;
$objPHPExcel->getActiveSheet()->setTitle('Simple'); $objPhpSpreadsheet->getActiveSheet()->setTitle('Simple');
// Set active sheet index to the first sheet, so Excel opens this as the first sheet // Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0); $objPhpSpreadsheet->setActiveSheetIndex(0);
// Save Excel 2007 file // Save Excel 2007 file
@ -85,9 +84,9 @@ echo date('H:i:s') , " Write to Excel2007 format" , EOL;
$callStartTime = microtime(true); $callStartTime = microtime(true);
// Use PCLZip rather than ZipArchive to create the Excel2007 OfficeOpenXML file // Use PCLZip rather than ZipArchive to create the Excel2007 OfficeOpenXML file
PHPExcel\Settings::setZipClass(PHPExcel\Settings::PCLZIP); PhpSpreadsheet\Settings::setZipClass(PhpSpreadsheet\Settings::PCLZIP);
$objWriter = \PHPExcel\IOFactory::createWriter($objPHPExcel, 'Excel2007'); $objWriter = \PhpSpreadsheet\IOFactory::createWriter($objPhpSpreadsheet, 'Excel2007');
$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); $objWriter->save(str_replace('.php', '.xlsx', __FILE__));
$callEndTime = microtime(true); $callEndTime = microtime(true);
$callTime = $callEndTime - $callStartTime; $callTime = $callEndTime - $callStartTime;

View File

@ -1,183 +0,0 @@
<?php
/**
* PHPExcel
*
* Copyright (c) 2006 - 2015 PHPExcel
*
* 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
*
* @category PHPExcel
* @package PHPExcel
* @copyright Copyright (c) 2006 - 2015 PHPExcel (https://github.com/PHPOffice/PhpSpreadsheet)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE##
*/
/** Error reporting */
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
date_default_timezone_set('Europe/London');
define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
/** Include PHPExcel */
require_once dirname(__FILE__) . '/../src/Bootstrap.php';
// Create new PHPExcel object
echo date('H:i:s') , " Create new PHPExcel object" , EOL;
$objPHPExcel = new \PHPExcel\Spreadsheet();
// Set document properties
echo date('H:i:s') , " Set document properties" , EOL;
$objPHPExcel->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");
// Set default font
echo date('H:i:s') , " Set default font" , EOL;
$objPHPExcel->getDefaultStyle()->getFont()->setName('Arial')
->setSize(10);
// Add some data, resembling some different data types
echo date('H:i:s') , " Add some data" , EOL;
$objPHPExcel->getActiveSheet()->setCellValue('A1', 'String')
->setCellValue('B1', 'Simple')
->setCellValue('C1', 'PHPExcel');
$objPHPExcel->getActiveSheet()->setCellValue('A2', 'String')
->setCellValue('B2', 'Symbols')
->setCellValue('C2', '!+&=()~§±æþ');
$objPHPExcel->getActiveSheet()->setCellValue('A3', 'String')
->setCellValue('B3', 'UTF-8')
->setCellValue('C3', 'Создать MS Excel Книги из PHP скриптов');
$objPHPExcel->getActiveSheet()->setCellValue('A4', 'Number')
->setCellValue('B4', 'Integer')
->setCellValue('C4', 12);
$objPHPExcel->getActiveSheet()->setCellValue('A5', 'Number')
->setCellValue('B5', 'Float')
->setCellValue('C5', 34.56);
$objPHPExcel->getActiveSheet()->setCellValue('A6', 'Number')
->setCellValue('B6', 'Negative')
->setCellValue('C6', -7.89);
$objPHPExcel->getActiveSheet()->setCellValue('A7', 'Boolean')
->setCellValue('B7', 'True')
->setCellValue('C7', true);
$objPHPExcel->getActiveSheet()->setCellValue('A8', 'Boolean')
->setCellValue('B8', 'False')
->setCellValue('C8', false);
$dateTimeNow = time();
$objPHPExcel->getActiveSheet()->setCellValue('A9', 'Date/Time')
->setCellValue('B9', 'Date')
->setCellValue('C9', \PHPExcel\Shared\Date::PHPToExcel( $dateTimeNow ));
$objPHPExcel->getActiveSheet()->getStyle('C9')->getNumberFormat()->setFormatCode(\PHPExcel\Style\NumberFormat::FORMAT_DATE_YYYYMMDD2);
$objPHPExcel->getActiveSheet()->setCellValue('A10', 'Date/Time')
->setCellValue('B10', 'Time')
->setCellValue('C10', \PHPExcel\Shared\Date::PHPToExcel( $dateTimeNow ));
$objPHPExcel->getActiveSheet()->getStyle('C10')->getNumberFormat()->setFormatCode(\PHPExcel\Style\NumberFormat::FORMAT_DATE_TIME4);
$objPHPExcel->getActiveSheet()->setCellValue('A11', 'Date/Time')
->setCellValue('B11', 'Date and Time')
->setCellValue('C11', \PHPExcel\Shared\Date::PHPToExcel( $dateTimeNow ));
$objPHPExcel->getActiveSheet()->getStyle('C11')->getNumberFormat()->setFormatCode(\PHPExcel\Style\NumberFormat::FORMAT_DATE_DATETIME);
$objPHPExcel->getActiveSheet()->setCellValue('A12', 'NULL')
->setCellValue('C12', NULL);
$objRichText = new \PHPExcel\RichText();
$objRichText->createText('你好 ');
$objPayable = $objRichText->createTextRun('你 好 吗?');
$objPayable->getFont()->setBold(true);
$objPayable->getFont()->setItalic(true);
$objPayable->getFont()->setColor(new \PHPExcel\Style\Color(\PHPExcel\Style\Color::COLOR_DARKGREEN));
$objRichText->createText(', unless specified otherwise on the invoice.');
$objPHPExcel->getActiveSheet()->setCellValue('A13', 'Rich Text')
->setCellValue('C13', $objRichText);
$objRichText2 = new \PHPExcel\RichText();
$objRichText2->createText("black text\n");
$objRed = $objRichText2->createTextRun("red text");
$objRed->getFont()->setColor(new \PHPExcel\Style\Color(\PHPExcel\Style\Color::COLOR_RED ));
$objPHPExcel->getActiveSheet()->getCell("C14")->setValue($objRichText2);
$objPHPExcel->getActiveSheet()->getStyle("C14")->getAlignment()->setWrapText(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setAutoSize(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setAutoSize(true);
// Rename worksheet
echo date('H:i:s') , " Rename worksheet" , EOL;
$objPHPExcel->getActiveSheet()->setTitle('Datatypes');
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);
// Save Excel 95 file
echo date('H:i:s') , " Write to Excel5 format" , EOL;
$callStartTime = microtime(true);
$objWriter = \PHPExcel\IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save(str_replace('.php', '.xls', __FILE__));
echo date('H:i:s') , " File written to " , str_replace('.php', '.xls', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL;
$callEndTime = microtime(true);
$callTime = $callEndTime - $callStartTime;
echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL;
echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL;
// Echo memory usage
echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL;
echo date('H:i:s') , " Reload workbook from saved file" , EOL;
$callStartTime = microtime(true);
$objPHPExcel = \PHPExcel\IOFactory::load(str_replace('.php', '.xls', __FILE__));
$callEndTime = microtime(true);
$callTime = $callEndTime - $callStartTime;
echo 'Call time to reload Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL;
// Echo memory usage
echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL;
var_dump($objPHPExcel->getActiveSheet()->toArray());
// Echo memory peak usage
echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL;
// Echo done
echo date('H:i:s') , " Done testing file" , EOL;
echo 'File has been created in ' , getcwd() , EOL;

View File

@ -1,8 +1,8 @@
<?php <?php
/** /**
* PHPExcel * PhpSpreadsheet
* *
* Copyright (c) 2006 - 2015 PHPExcel * Copyright (c) 2006 - 2016 PhpSpreadsheet
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -18,9 +18,8 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* @category PHPExcel * @category PhpSpreadsheet
* @package PHPExcel * @copyright Copyright (c) 2006 - 2016 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet)
* @copyright Copyright (c) 2006 - 2015 PHPExcel (https://github.com/PHPOffice/PhpSpreadsheet)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE## * @version ##VERSION##, ##DATE##
*/ */
@ -33,17 +32,17 @@ date_default_timezone_set('Europe/London');
define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />'); define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
/** Include PHPExcel */ /** Include PhpSpreadsheet */
require_once dirname(__FILE__) . '/../src/Bootstrap.php'; require_once dirname(__FILE__) . '/../src/Bootstrap.php';
// Create new PHPExcel object // Create new PhpSpreadsheet object
echo date('H:i:s') , " Create new PHPExcel object" , EOL; echo date('H:i:s') , " Create new PhpSpreadsheet object" , EOL;
$objPHPExcel = new \PHPExcel\Spreadsheet(); $objPhpSpreadsheet = new \PhpSpreadsheet\Spreadsheet();
// Set document properties // Set document properties
echo date('H:i:s') , " Set document properties" , EOL; echo date('H:i:s') , " Set document properties" , EOL;
$objPHPExcel->getProperties() $objPhpSpreadsheet->getProperties()
->setCreator("Maarten Balliauw") ->setCreator("Maarten Balliauw")
->setLastModifiedBy("Maarten Balliauw") ->setLastModifiedBy("Maarten Balliauw")
->setTitle("Office 2007 XLSX Test Document") ->setTitle("Office 2007 XLSX Test Document")
@ -54,144 +53,149 @@ $objPHPExcel->getProperties()
// Set default font // Set default font
echo date('H:i:s') , " Set default font" , EOL; echo date('H:i:s') , " Set default font" , EOL;
$objPHPExcel->getDefaultStyle() $objPhpSpreadsheet->getDefaultStyle()
->getFont() ->getFont()
->setName('Arial') ->setName('Arial')
->setSize(10); ->setSize(10);
// Add some data, resembling some different data types // Add some data, resembling some different data types
echo date('H:i:s') , " Add some data" , EOL; echo date('H:i:s') , " Add some data" , EOL;
$objPHPExcel->getActiveSheet() $objPhpSpreadsheet->getActiveSheet()
->setCellValue('A1', 'String') ->setCellValue('A1', 'String')
->setCellValue('B1', 'Simple') ->setCellValue('B1', 'Simple')
->setCellValue('C1', 'PHPExcel'); ->setCellValue('C1', 'PhpSpreadsheet');
$objPHPExcel->getActiveSheet() $objPhpSpreadsheet->getActiveSheet()
->setCellValue('A2', 'String') ->setCellValue('A2', 'String')
->setCellValue('B2', 'Symbols') ->setCellValue('B2', 'Symbols')
->setCellValue('C2', '!+&=()~§±æþ'); ->setCellValue('C2', '!+&=()~§±æþ');
$objPHPExcel->getActiveSheet() $objPhpSpreadsheet->getActiveSheet()
->setCellValue('A3', 'String') ->setCellValue('A3', 'String')
->setCellValue('B3', 'UTF-8') ->setCellValue('B3', 'UTF-8')
->setCellValue('C3', 'Создать MS Excel Книги из PHP скриптов'); ->setCellValue('C3', 'Создать MS Excel Книги из PHP скриптов');
$objPHPExcel->getActiveSheet() $objPhpSpreadsheet->getActiveSheet()
->setCellValue('A4', 'Number') ->setCellValue('A4', 'Number')
->setCellValue('B4', 'Integer') ->setCellValue('B4', 'Integer')
->setCellValue('C4', 12); ->setCellValue('C4', 12);
$objPHPExcel->getActiveSheet() $objPhpSpreadsheet->getActiveSheet()
->setCellValue('A5', 'Number') ->setCellValue('A5', 'Number')
->setCellValue('B5', 'Float') ->setCellValue('B5', 'Float')
->setCellValue('C5', 34.56); ->setCellValue('C5', 34.56);
$objPHPExcel->getActiveSheet() $objPhpSpreadsheet->getActiveSheet()
->setCellValue('A6', 'Number') ->setCellValue('A6', 'Number')
->setCellValue('B6', 'Negative') ->setCellValue('B6', 'Negative')
->setCellValue('C6', -7.89); ->setCellValue('C6', -7.89);
$objPHPExcel->getActiveSheet() $objPhpSpreadsheet->getActiveSheet()
->setCellValue('A7', 'Boolean') ->setCellValue('A7', 'Boolean')
->setCellValue('B7', 'True') ->setCellValue('B7', 'True')
->setCellValue('C7', true); ->setCellValue('C7', true);
$objPHPExcel->getActiveSheet() $objPhpSpreadsheet->getActiveSheet()
->setCellValue('A8', 'Boolean') ->setCellValue('A8', 'Boolean')
->setCellValue('B8', 'False') ->setCellValue('B8', 'False')
->setCellValue('C8', false); ->setCellValue('C8', false);
$dateTimeNow = time(); $dateTimeNow = time();
$objPHPExcel->getActiveSheet() $objPhpSpreadsheet->getActiveSheet()
->setCellValue('A9', 'Date/Time') ->setCellValue('A9', 'Date/Time')
->setCellValue('B9', 'Date') ->setCellValue('B9', 'Date')
->setCellValue('C9', \PHPExcel\Shared\Date::PHPToExcel( $dateTimeNow )); ->setCellValue('C9', \PhpSpreadsheet\Shared\Date::PHPToExcel( $dateTimeNow ));
$objPHPExcel->getActiveSheet() $objPhpSpreadsheet->getActiveSheet()
->getStyle('C9') ->getStyle('C9')
->getNumberFormat() ->getNumberFormat()
->setFormatCode(\PHPExcel\Style\NumberFormat::FORMAT_DATE_YYYYMMDD2); ->setFormatCode(\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_YYYYMMDD2);
$objPHPExcel->getActiveSheet() $objPhpSpreadsheet->getActiveSheet()
->setCellValue('A10', 'Date/Time') ->setCellValue('A10', 'Date/Time')
->setCellValue('B10', 'Time') ->setCellValue('B10', 'Time')
->setCellValue('C10', \PHPExcel\Shared\Date::PHPToExcel( $dateTimeNow )); ->setCellValue('C10', \PhpSpreadsheet\Shared\Date::PHPToExcel( $dateTimeNow ));
$objPHPExcel->getActiveSheet() $objPhpSpreadsheet->getActiveSheet()
->getStyle('C10') ->getStyle('C10')
->getNumberFormat() ->getNumberFormat()
->setFormatCode(\PHPExcel\Style\NumberFormat::FORMAT_DATE_TIME4); ->setFormatCode(\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_TIME4);
$objPHPExcel->getActiveSheet() $objPhpSpreadsheet->getActiveSheet()
->setCellValue('A11', 'Date/Time') ->setCellValue('A11', 'Date/Time')
->setCellValue('B11', 'Date and Time') ->setCellValue('B11', 'Date and Time')
->setCellValue('C11', \PHPExcel\Shared\Date::PHPToExcel( $dateTimeNow )); ->setCellValue('C11', \PhpSpreadsheet\Shared\Date::PHPToExcel( $dateTimeNow ));
$objPHPExcel->getActiveSheet() $objPhpSpreadsheet->getActiveSheet()
->getStyle('C11') ->getStyle('C11')
->getNumberFormat() ->getNumberFormat()
->setFormatCode(\PHPExcel\Style\NumberFormat::FORMAT_DATE_DATETIME); ->setFormatCode(\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_DATETIME);
$objPHPExcel->getActiveSheet() $objPhpSpreadsheet->getActiveSheet()
->setCellValue('A12', 'NULL') ->setCellValue('A12', 'NULL')
->setCellValue('C12', NULL); ->setCellValue('C12', NULL);
$objRichText = new \PHPExcel\RichText(); $objRichText = new \PhpSpreadsheet\RichText();
$objRichText->createText('你好 '); $objRichText->createText('你好 ');
$objPayable = $objRichText->createTextRun('你 好 吗?'); $objPayable = $objRichText->createTextRun('你 好 吗?');
$objPayable->getFont()->setBold(true); $objPayable->getFont()->setBold(true);
$objPayable->getFont()->setItalic(true); $objPayable->getFont()->setItalic(true);
$objPayable->getFont()->setColor( new \PHPExcel\Style\Color( \PHPExcel\Style\Color::COLOR_DARKGREEN ) ); $objPayable->getFont()->setColor( new \PhpSpreadsheet\Style\Color( \PhpSpreadsheet\Style\Color::COLOR_DARKGREEN ) );
$objRichText->createText(', unless specified otherwise on the invoice.'); $objRichText->createText(', unless specified otherwise on the invoice.');
$objPHPExcel->getActiveSheet() $objPhpSpreadsheet->getActiveSheet()
->setCellValue('A13', 'Rich Text') ->setCellValue('A13', 'Rich Text')
->setCellValue('C13', $objRichText); ->setCellValue('C13', $objRichText);
$objRichText2 = new \PHPExcel\RichText(); $objRichText2 = new \PhpSpreadsheet\RichText();
$objRichText2->createText("black text\n"); $objRichText2->createText("black text\n");
$objRed = $objRichText2->createTextRun("red text"); $objRed = $objRichText2->createTextRun("red text");
$objRed->getFont()->setColor( new \PHPExcel\Style\Color(\PHPExcel\Style\Color::COLOR_RED ) ); $objRed->getFont()->setColor( new \PhpSpreadsheet\Style\Color(\PhpSpreadsheet\Style\Color::COLOR_RED ) );
$objPHPExcel->getActiveSheet() $objPhpSpreadsheet->getActiveSheet()
->getCell("C14") ->getCell("C14")
->setValue($objRichText2); ->setValue($objRichText2);
$objPHPExcel->getActiveSheet() $objPhpSpreadsheet->getActiveSheet()
->getStyle("C14") ->getStyle("C14")
->getAlignment()->setWrapText(true); ->getAlignment()->setWrapText(true);
$objPHPExcel->getActiveSheet()->setCellValue('A17', 'Hyperlink'); $objPhpSpreadsheet->getActiveSheet()->setCellValue('A17', 'Hyperlink');
$objPHPExcel->getActiveSheet()->setCellValue('C17', 'www.phpexcel.net'); $objPhpSpreadsheet->getActiveSheet()
$objPHPExcel->getActiveSheet()->getCell('C17')->getHyperlink()->setUrl('http://www.phpexcel.net'); ->setCellValue('C17', 'PhpSpreadsheet Web Site');
$objPHPExcel->getActiveSheet()->getCell('C17')->getHyperlink()->setTooltip('Navigate to website'); $objPhpSpreadsheet->getActiveSheet()
->getCell('C17')
->getHyperlink()
->setUrl('https://github.com/PHPOffice/PhpSpreadsheet')
->setTooltip('Navigate to PhpSpreadsheet website');
$objPHPExcel->getActiveSheet()->setCellValue('C18', '=HYPERLINK("mailto:abc@def.com","abc@def.com")'); $objPhpSpreadsheet->getActiveSheet()
->setCellValue('C18', '=HYPERLINK("mailto:abc@def.com","abc@def.com")');
$objPHPExcel->getActiveSheet() $objPhpSpreadsheet->getActiveSheet()
->getColumnDimension('B') ->getColumnDimension('B')
->setAutoSize(true); ->setAutoSize(true);
$objPHPExcel->getActiveSheet() $objPhpSpreadsheet->getActiveSheet()
->getColumnDimension('C') ->getColumnDimension('C')
->setAutoSize(true); ->setAutoSize(true);
// Rename worksheet // Rename worksheet
echo date('H:i:s') , " Rename worksheet" , EOL; echo date('H:i:s') , " Rename worksheet" , EOL;
$objPHPExcel->getActiveSheet()->setTitle('Datatypes'); $objPhpSpreadsheet->getActiveSheet()->setTitle('Datatypes');
// Set active sheet index to the first sheet, so Excel opens this as the first sheet // Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0); $objPhpSpreadsheet->setActiveSheetIndex(0);
// Save Excel 2007 file // Save Excel 2007 file
echo date('H:i:s') , " Write to Excel2007 format" , EOL; echo date('H:i:s') , " Write to Excel2007 format" , EOL;
$callStartTime = microtime(true); $callStartTime = microtime(true);
$objWriter = \PHPExcel\IOFactory::createWriter($objPHPExcel, 'Excel2007'); $objWriter = \PhpSpreadsheet\IOFactory::createWriter($objPhpSpreadsheet, 'Excel2007');
$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); $objWriter->save(str_replace('.php', '.xlsx', __FILE__));
$callEndTime = microtime(true); $callEndTime = microtime(true);
$callTime = $callEndTime - $callStartTime; $callTime = $callEndTime - $callStartTime;
@ -202,24 +206,24 @@ echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds"
echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL;
echo date('H:i:s') , " Reload workbook from saved file" , EOL; // Save Excel 5 file
echo date('H:i:s') , " Write to Excel5 format" , EOL;
$callStartTime = microtime(true); $callStartTime = microtime(true);
$objPHPExcel = \PHPExcel\IOFactory::load(str_replace('.php', '.xlsx', __FILE__)); $objWriter = \PhpSpreadsheet\IOFactory::createWriter($objPhpSpreadsheet, 'Excel5');
$objWriter->save(str_replace('.php', '.xls', __FILE__));
$callEndTime = microtime(true); $callEndTime = microtime(true);
$callTime = $callEndTime - $callStartTime; $callTime = $callEndTime - $callStartTime;
echo 'Call time to reload Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL;
echo date('H:i:s') , " File written to " , str_replace('.php', '.xls', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL;
echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL;
// Echo memory usage // Echo memory usage
echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL; echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL;
var_dump($objPHPExcel->getActiveSheet()->toArray());
// Echo memory peak usage // Echo memory peak usage
echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL; echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL;
// Echo done // Echo done
echo date('H:i:s') , " Done testing file" , EOL; echo date('H:i:s') , " Done testing file" , EOL;
echo 'File has been created in ' , getcwd() , EOL; echo 'Files have been created in ' , getcwd() , EOL;

View File

@ -1,8 +1,8 @@
<?php <?php
/** /**
* PHPExcel * PhpSpreadsheet
* *
* Copyright (c) 2006 - 2015 PHPExcel * Copyright (c) 2006 - 2015 PhpSpreadsheet
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -18,9 +18,9 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* @category PHPExcel * @category PhpSpreadsheet
* @package PHPExcel * @package PhpSpreadsheet
* @copyright Copyright (c) 2006 - 2015 PHPExcel (https://github.com/PHPOffice/PhpSpreadsheet) * @copyright Copyright (c) 2006 - 2015 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE## * @version ##VERSION##, ##DATE##
*/ */
@ -33,17 +33,17 @@ date_default_timezone_set('Europe/London');
define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />'); define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
/** Include PHPExcel */ /** Include PhpSpreadsheet */
require_once dirname(__FILE__) . '/../src/Bootstrap.php'; require_once dirname(__FILE__) . '/../src/Bootstrap.php';
// Create new PHPExcel object // Create new PhpSpreadsheet object
echo date('H:i:s') , " Create new PHPExcel object" , EOL; echo date('H:i:s') , " Create new PhpSpreadsheet object" , EOL;
$objPHPExcel = new \PHPExcel\Spreadsheet(); $objPhpSpreadsheet = new \PhpSpreadsheet\Spreadsheet();
// Set document properties // Set document properties
echo date('H:i:s') , " Set document properties" , EOL; echo date('H:i:s') , " Set document properties" , EOL;
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw") $objPhpSpreadsheet->getProperties()->setCreator("Maarten Balliauw")
->setLastModifiedBy("Maarten Balliauw") ->setLastModifiedBy("Maarten Balliauw")
->setTitle("Office 2007 XLSX Test Document") ->setTitle("Office 2007 XLSX Test Document")
->setSubject("Office 2007 XLSX Test Document") ->setSubject("Office 2007 XLSX Test Document")
@ -54,62 +54,88 @@ $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
// Add some data, we will use some formulas here // Add some data, we will use some formulas here
echo date('H:i:s') , " Add some data" , EOL; echo date('H:i:s') , " Add some data" , EOL;
$objPHPExcel->getActiveSheet()->setCellValue('A5', 'Sum:'); $objPhpSpreadsheet->getActiveSheet()
->setCellValue('A5', 'Sum:');
$objPHPExcel->getActiveSheet()->setCellValue('B1', 'Range #1') $objPhpSpreadsheet->getActiveSheet()->setCellValue('B1', 'Range #1')
->setCellValue('B2', 3) ->setCellValue('B2', 3)
->setCellValue('B3', 7) ->setCellValue('B3', 7)
->setCellValue('B4', 13) ->setCellValue('B4', 13)
->setCellValue('B5', '=SUM(B2:B4)'); ->setCellValue('B5', '=SUM(B2:B4)');
echo date('H:i:s') , " Sum of Range #1 is " , echo date('H:i:s') , " Sum of Range #1 is " ,
$objPHPExcel->getActiveSheet()->getCell('B5')->getCalculatedValue() , EOL; $objPhpSpreadsheet->getActiveSheet()
->getCell('B5')
->getCalculatedValue() , EOL;
$objPHPExcel->getActiveSheet()->setCellValue('C1', 'Range #2') $objPhpSpreadsheet->getActiveSheet()->setCellValue('C1', 'Range #2')
->setCellValue('C2', 5) ->setCellValue('C2', 5)
->setCellValue('C3', 11) ->setCellValue('C3', 11)
->setCellValue('C4', 17) ->setCellValue('C4', 17)
->setCellValue('C5', '=SUM(C2:C4)'); ->setCellValue('C5', '=SUM(C2:C4)');
echo date('H:i:s') , " Sum of Range #2 is " , echo date('H:i:s') , " Sum of Range #2 is " ,
$objPHPExcel->getActiveSheet()->getCell('C5')->getCalculatedValue() , EOL; $objPhpSpreadsheet->getActiveSheet()
->getCell('C5')
->getCalculatedValue() , EOL;
$objPHPExcel->getActiveSheet()->setCellValue('A7', 'Total of both ranges:'); $objPhpSpreadsheet->getActiveSheet()
$objPHPExcel->getActiveSheet()->setCellValue('B7', '=SUM(B5:C5)'); ->setCellValue('A7', 'Total of both ranges:');
$objPhpSpreadsheet->getActiveSheet()
->setCellValue('B7', '=SUM(B5:C5)');
echo date('H:i:s') , " Sum of both Ranges is " , echo date('H:i:s') , " Sum of both Ranges is " ,
$objPHPExcel->getActiveSheet()->getCell('B7')->getCalculatedValue() , EOL; $objPhpSpreadsheet->getActiveSheet()
->getCell('B7')
->getCalculatedValue() , EOL;
$objPHPExcel->getActiveSheet()->setCellValue('A8', 'Minimum of both ranges:'); $objPhpSpreadsheet->getActiveSheet()
$objPHPExcel->getActiveSheet()->setCellValue('B8', '=MIN(B2:C4)'); ->setCellValue('A8', 'Minimum of both ranges:');
$objPhpSpreadsheet->getActiveSheet()
->setCellValue('B8', '=MIN(B2:C4)');
echo date('H:i:s') , " Minimum value in either Range is " , echo date('H:i:s') , " Minimum value in either Range is " ,
$objPHPExcel->getActiveSheet()->getCell('B8')->getCalculatedValue() , EOL; $objPhpSpreadsheet->getActiveSheet()
->getCell('B8')
->getCalculatedValue() , EOL;
$objPHPExcel->getActiveSheet()->setCellValue('A9', 'Maximum of both ranges:'); $objPhpSpreadsheet->getActiveSheet()
$objPHPExcel->getActiveSheet()->setCellValue('B9', '=MAX(B2:C4)'); ->setCellValue('A9', 'Maximum of both ranges:');
$objPhpSpreadsheet->getActiveSheet()
->setCellValue('B9', '=MAX(B2:C4)');
echo date('H:i:s') , " Maximum value in either Range is " , echo date('H:i:s') , " Maximum value in either Range is " ,
$objPHPExcel->getActiveSheet()->getCell('B9')->getCalculatedValue() , EOL; $objPhpSpreadsheet->getActiveSheet()
->getCell('B9')
->getCalculatedValue() , EOL;
$objPHPExcel->getActiveSheet()->setCellValue('A10', 'Average of both ranges:'); $objPhpSpreadsheet->getActiveSheet()
$objPHPExcel->getActiveSheet()->setCellValue('B10', '=AVERAGE(B2:C4)'); ->setCellValue('A10', 'Average of both ranges:');
$objPhpSpreadsheet->getActiveSheet()
->setCellValue('B10', '=AVERAGE(B2:C4)');
echo date('H:i:s') , " Average value of both Ranges is " , echo date('H:i:s') , " Average value of both Ranges is " ,
$objPHPExcel->getActiveSheet()->getCell('B10')->getCalculatedValue() , EOL; $objPhpSpreadsheet->getActiveSheet()
->getCell('B10')->getCalculatedValue() , EOL;
$objPhpSpreadsheet->getActiveSheet()
->getColumnDimension('A')
->setAutoSize(true);
// Rename worksheet // Rename worksheet
echo date('H:i:s') , " Rename worksheet" , EOL; echo date('H:i:s') , " Rename worksheet" , EOL;
$objPHPExcel->getActiveSheet()->setTitle('Formulas'); $objPhpSpreadsheet->getActiveSheet()
->setTitle('Formulas');
// Set active sheet index to the first sheet, so Excel opens this as the first sheet // Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0); $objPhpSpreadsheet->setActiveSheetIndex(0);
// Save Excel 2007 file // Save Excel 2007 file
echo date('H:i:s') , " Write to Excel2007 format" , EOL; echo date('H:i:s') , " Write to Excel2007 format" , EOL;
$callStartTime = microtime(true); $callStartTime = microtime(true);
$objWriter = \PHPExcel\IOFactory::createWriter($objPHPExcel, 'Excel2007'); $objWriter = \PhpSpreadsheet\IOFactory::createWriter($objPhpSpreadsheet, 'Excel2007');
// //
// If we set Pre Calculated Formulas to true then PHPExcel will calculate all formulae in the // If we set Pre Calculated Formulas to true then PhpSpreadsheet will calculate all formulae in the
// workbook before saving. This adds time and memory overhead, and can cause some problems with formulae // workbook before saving. This adds time and memory overhead, and can cause some problems with formulae
// using functions or features (such as array formulae) that aren't yet supported by the calculation engine // using functions or features (such as array formulae) that aren't yet supported by the calculation engine
// If the value is false (the default) for the Excel2007 Writer, then MS Excel (or the application used to // If the value is false (the default) for the Excel2007 Writer, then MS Excel (or the application used to
@ -130,7 +156,7 @@ echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024
echo date('H:i:s') , " Write to Excel5 format" , EOL; echo date('H:i:s') , " Write to Excel5 format" , EOL;
$callStartTime = microtime(true); $callStartTime = microtime(true);
$objWriter = \PHPExcel\IOFactory::createWriter($objPHPExcel, 'Excel5'); $objWriter = \PhpSpreadsheet\IOFactory::createWriter($objPhpSpreadsheet, 'Excel5');
$objWriter->save(str_replace('.php', '.xls', __FILE__)); $objWriter->save(str_replace('.php', '.xls', __FILE__));
$callEndTime = microtime(true); $callEndTime = microtime(true);
$callTime = $callEndTime - $callStartTime; $callTime = $callEndTime - $callStartTime;

View File

@ -1,8 +1,8 @@
<?php <?php
/** /**
* PHPExcel * PhpSpreadsheet
* *
* Copyright (c) 2006 - 2015 PHPExcel * Copyright (c) 2006 - 2015 PhpSpreadsheet
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -18,9 +18,9 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* *
* @category PHPExcel * @category PhpSpreadsheet
* @package PHPExcel * @package PhpSpreadsheet
* @copyright Copyright (c) 2006 - 2015 PHPExcel (https://github.com/PHPOffice/PhpSpreadsheet) * @copyright Copyright (c) 2006 - 2015 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE## * @version ##VERSION##, ##DATE##
*/ */
@ -34,17 +34,17 @@ define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
date_default_timezone_set('Europe/London'); date_default_timezone_set('Europe/London');
/** Include PHPExcel */ /** Include PhpSpreadsheet */
require_once dirname(__FILE__) . '/../src/Bootstrap.php'; require_once dirname(__FILE__) . '/../src/Bootstrap.php';
// Create new PHPExcel object // Create new PhpSpreadsheet object
echo date('H:i:s') , " Create new PHPExcel object" , EOL; echo date('H:i:s') , " Create new PhpSpreadsheet object" , EOL;
$objPHPExcel = new \PHPExcel\Spreadsheet(); $objPhpSpreadsheet = new \PhpSpreadsheet\Spreadsheet();
// Set document properties // Set document properties
echo date('H:i:s') , " Set document properties" , EOL; echo date('H:i:s') , " Set document properties" , EOL;
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw") $objPhpSpreadsheet->getProperties()->setCreator("Maarten Balliauw")
->setLastModifiedBy("Maarten Balliauw") ->setLastModifiedBy("Maarten Balliauw")
->setTitle("Office 2007 XLSX Test Document") ->setTitle("Office 2007 XLSX Test Document")
->setSubject("Office 2007 XLSX Test Document") ->setSubject("Office 2007 XLSX Test Document")
@ -56,42 +56,52 @@ $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
// Add some data, we will use printing features // Add some data, we will use printing features
echo date('H:i:s') , " Add some data" , EOL; echo date('H:i:s') , " Add some data" , EOL;
for ($i = 1; $i < 200; $i++) { for ($i = 1; $i < 200; $i++) {
$objPHPExcel->getActiveSheet()->setCellValue('A' . $i, $i); $objPhpSpreadsheet->getActiveSheet()->setCellValue('A' . $i, $i);
$objPHPExcel->getActiveSheet()->setCellValue('B' . $i, 'Test value'); $objPhpSpreadsheet->getActiveSheet()->setCellValue('B' . $i, 'Test value');
} }
// Set header and footer. When no different headers for odd/even are used, odd header is assumed. // Set header and footer. When no different headers for odd/even are used, odd header is assumed.
echo date('H:i:s') , " Set header/footer" , EOL; echo date('H:i:s') , " Set header/footer" , EOL;
$objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddHeader('&L&G&C&HPlease treat this document as confidential!'); $objPhpSpreadsheet->getActiveSheet()
$objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddFooter('&L&B' . $objPHPExcel->getProperties()->getTitle() . '&RPage &P of &N'); ->getHeaderFooter()
->setOddHeader('&L&G&C&HPlease treat this document as confidential!');
$objPhpSpreadsheet->getActiveSheet()
->getHeaderFooter()
->setOddFooter('&L&B' . $objPhpSpreadsheet->getProperties()->getTitle() . '&RPage &P of &N');
// Add a drawing to the header // Add a drawing to the header
echo date('H:i:s') , " Add a drawing to the header" , EOL; echo date('H:i:s') , " Add a drawing to the header" , EOL;
$objDrawing = new \PHPExcel\Worksheet\HeaderFooterDrawing(); $objDrawing = new \PhpSpreadsheet\Worksheet\HeaderFooterDrawing();
$objDrawing->setName('PHPExcel logo'); $objDrawing->setName('PhpSpreadsheet logo');
$objDrawing->setPath('./images/phpexcel_logo.gif'); $objDrawing->setPath('./images/PhpSpreadsheet_logo.gif');
$objDrawing->setHeight(36); $objDrawing->setHeight(36);
$objPHPExcel->getActiveSheet()->getHeaderFooter()->addImage($objDrawing, \PHPExcel\Worksheet\HeaderFooter::IMAGE_HEADER_LEFT); $objPhpSpreadsheet->getActiveSheet()
->getHeaderFooter()
->addImage($objDrawing, \PhpSpreadsheet\Worksheet\HeaderFooter::IMAGE_HEADER_LEFT);
// Set page orientation and size // Set page orientation and size
echo date('H:i:s') , " Set page orientation and size" , EOL; echo date('H:i:s') , " Set page orientation and size" , EOL;
$objPHPExcel->getActiveSheet()->getPageSetup()->setOrientation(\PHPExcel\Worksheet\PageSetup::ORIENTATION_LANDSCAPE); $objPhpSpreadsheet->getActiveSheet()
$objPHPExcel->getActiveSheet()->getPageSetup()->setPaperSize(\PHPExcel\Worksheet\PageSetup::PAPERSIZE_A4); ->getPageSetup()
->setOrientation(\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_LANDSCAPE);
$objPhpSpreadsheet->getActiveSheet()
->getPageSetup()
->setPaperSize(\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_A4);
// Rename worksheet // Rename worksheet
echo date('H:i:s') , " Rename worksheet" , EOL; echo date('H:i:s') , " Rename worksheet" , EOL;
$objPHPExcel->getActiveSheet()->setTitle('Printing'); $objPhpSpreadsheet->getActiveSheet()->setTitle('Printing');
// Set active sheet index to the first sheet, so Excel opens this as the first sheet // Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0); $objPhpSpreadsheet->setActiveSheetIndex(0);
// Save Excel 2007 file // Save Excel 2007 file
echo date('H:i:s') , " Write to Excel2007 format" , EOL; echo date('H:i:s') , " Write to Excel2007 format" , EOL;
$callStartTime = microtime(true); $callStartTime = microtime(true);
$objWriter = \PHPExcel\IOFactory::createWriter($objPHPExcel, 'Excel2007'); $objWriter = \PhpSpreadsheet\IOFactory::createWriter($objPhpSpreadsheet, 'Excel2007');
$objWriter->save(str_replace('.php', '.xlsx', __FILE__)); $objWriter->save(str_replace('.php', '.xlsx', __FILE__));
$callEndTime = microtime(true); $callEndTime = microtime(true);
$callTime = $callEndTime - $callStartTime; $callTime = $callEndTime - $callStartTime;
@ -106,7 +116,7 @@ echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024
echo date('H:i:s') , " Write to Excel5 format" , EOL; echo date('H:i:s') , " Write to Excel5 format" , EOL;
$callStartTime = microtime(true); $callStartTime = microtime(true);
$objWriter = \PHPExcel\IOFactory::createWriter($objPHPExcel, 'Excel5'); $objWriter = \PhpSpreadsheet\IOFactory::createWriter($objPhpSpreadsheet, 'Excel5');
$objWriter->save(str_replace('.php', '.xls', __FILE__)); $objWriter->save(str_replace('.php', '.xls', __FILE__));
$callEndTime = microtime(true); $callEndTime = microtime(true);
$callTime = $callEndTime - $callStartTime; $callTime = $callEndTime - $callStartTime;

View File

Before

Width:  |  Height:  |  Size: 6.0 KiB

After

Width:  |  Height:  |  Size: 6.0 KiB