Make global usage of `use` instead of FQCN

Closes #78
Closes #147
This commit is contained in:
Zharikov Viktor 2017-05-18 00:02:17 +02:00 committed by Adrien Crivelli
parent 77199c9877
commit 07455d24f6
No known key found for this signature in database
GPG Key ID: B182FD79DC6DE92E
294 changed files with 3915 additions and 2974 deletions

View File

@ -1,6 +1,8 @@
#!/usr/bin/env php #!/usr/bin/env php
<?php <?php
use PhpOffice\PhpSpreadsheet\Helper\Migrator;
require_once __DIR__ . '/../src/Bootstrap.php'; require_once __DIR__ . '/../src/Bootstrap.php';
$migrator = new \PhpOffice\PhpSpreadsheet\Helper\Migrator(); $migrator = new Migrator();
$migrator->migrate(); $migrator->migrate();

View File

@ -1,5 +1,7 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
error_reporting(E_ALL); error_reporting(E_ALL);
set_time_limit(0); set_time_limit(0);
@ -22,7 +24,7 @@ date_default_timezone_set('Europe/London');
require_once __DIR__ . '/../../../../src/Bootstrap.php'; require_once __DIR__ . '/../../../../src/Bootstrap.php';
// Create new PhpSpreadsheet object // Create new PhpSpreadsheet object
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet(); $worksheet = $spreadsheet->getActiveSheet();
// Add some data // Add some data

View File

@ -1,5 +1,7 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
error_reporting(E_ALL); error_reporting(E_ALL);
set_time_limit(0); set_time_limit(0);
@ -22,7 +24,7 @@ date_default_timezone_set('Europe/London');
require_once __DIR__ . '/../../../../src/Bootstrap.php'; require_once __DIR__ . '/../../../../src/Bootstrap.php';
// Create new PhpSpreadsheet object // Create new PhpSpreadsheet object
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet(); $worksheet = $spreadsheet->getActiveSheet();
// Add some data // Add some data

View File

@ -1,5 +1,7 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
error_reporting(E_ALL); error_reporting(E_ALL);
set_time_limit(0); set_time_limit(0);
@ -22,7 +24,7 @@ date_default_timezone_set('Europe/London');
require_once __DIR__ . '/../../../../src/Bootstrap.php'; require_once __DIR__ . '/../../../../src/Bootstrap.php';
// Create new PhpSpreadsheet object // Create new PhpSpreadsheet object
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet(); $worksheet = $spreadsheet->getActiveSheet();
// Add some data // Add some data

View File

@ -1,5 +1,7 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
error_reporting(E_ALL); error_reporting(E_ALL);
set_time_limit(0); set_time_limit(0);
@ -22,7 +24,7 @@ date_default_timezone_set('Europe/London');
require_once __DIR__ . '/../../../../src/Bootstrap.php'; require_once __DIR__ . '/../../../../src/Bootstrap.php';
// Create new PhpSpreadsheet object // Create new PhpSpreadsheet object
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet(); $worksheet = $spreadsheet->getActiveSheet();
// Add some data // Add some data

View File

@ -1,5 +1,7 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
error_reporting(E_ALL); error_reporting(E_ALL);
set_time_limit(0); set_time_limit(0);
@ -22,7 +24,7 @@ date_default_timezone_set('Europe/London');
require_once __DIR__ . '/../../../../src/Bootstrap.php'; require_once __DIR__ . '/../../../../src/Bootstrap.php';
// Create new PhpSpreadsheet object // Create new PhpSpreadsheet object
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet(); $worksheet = $spreadsheet->getActiveSheet();
// Add some data // Add some data

View File

@ -1,5 +1,7 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
error_reporting(E_ALL); error_reporting(E_ALL);
set_time_limit(0); set_time_limit(0);
@ -22,7 +24,7 @@ date_default_timezone_set('Europe/London');
require_once __DIR__ . '/../../../../src/Bootstrap.php'; require_once __DIR__ . '/../../../../src/Bootstrap.php';
// Create new PhpSpreadsheet object // Create new PhpSpreadsheet object
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet(); $worksheet = $spreadsheet->getActiveSheet();
// Add some data // Add some data

View File

@ -1,5 +1,7 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
error_reporting(E_ALL); error_reporting(E_ALL);
set_time_limit(0); set_time_limit(0);
@ -22,7 +24,7 @@ date_default_timezone_set('Europe/London');
require_once __DIR__ . '/../../../../src/Bootstrap.php'; require_once __DIR__ . '/../../../../src/Bootstrap.php';
// Create new PhpSpreadsheet object // Create new PhpSpreadsheet object
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet(); $worksheet = $spreadsheet->getActiveSheet();
// Add some data // Add some data

View File

@ -1,5 +1,7 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
error_reporting(E_ALL); error_reporting(E_ALL);
set_time_limit(0); set_time_limit(0);
@ -22,7 +24,7 @@ date_default_timezone_set('Europe/London');
require_once __DIR__ . '/../../../../src/Bootstrap.php'; require_once __DIR__ . '/../../../../src/Bootstrap.php';
// Create new PhpSpreadsheet object // Create new PhpSpreadsheet object
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet(); $worksheet = $spreadsheet->getActiveSheet();
// Add some data // Add some data

View File

@ -1,5 +1,7 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
error_reporting(E_ALL); error_reporting(E_ALL);
set_time_limit(0); set_time_limit(0);
@ -22,7 +24,7 @@ date_default_timezone_set('Europe/London');
require_once __DIR__ . '/../../../../src/Bootstrap.php'; require_once __DIR__ . '/../../../../src/Bootstrap.php';
// Create new PhpSpreadsheet object // Create new PhpSpreadsheet object
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet(); $worksheet = $spreadsheet->getActiveSheet();
// Add some data // Add some data

View File

@ -1,5 +1,7 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
error_reporting(E_ALL); error_reporting(E_ALL);
set_time_limit(0); set_time_limit(0);
@ -22,7 +24,7 @@ date_default_timezone_set('Europe/London');
require_once __DIR__ . '/../../../../src/Bootstrap.php'; require_once __DIR__ . '/../../../../src/Bootstrap.php';
// Create new PhpSpreadsheet object // Create new PhpSpreadsheet object
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet(); $worksheet = $spreadsheet->getActiveSheet();
// Add some data // Add some data

View File

@ -1,5 +1,7 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
error_reporting(E_ALL); error_reporting(E_ALL);
set_time_limit(0); set_time_limit(0);
@ -22,7 +24,7 @@ date_default_timezone_set('Europe/London');
require_once __DIR__ . '/../../../../src/Bootstrap.php'; require_once __DIR__ . '/../../../../src/Bootstrap.php';
// Create new PhpSpreadsheet object // Create new PhpSpreadsheet object
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet(); $worksheet = $spreadsheet->getActiveSheet();
// Add some data // Add some data

View File

@ -1,5 +1,7 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
error_reporting(E_ALL); error_reporting(E_ALL);
set_time_limit(0); set_time_limit(0);
@ -22,7 +24,7 @@ date_default_timezone_set('Europe/London');
require_once __DIR__ . '/../../../../src/Bootstrap.php'; require_once __DIR__ . '/../../../../src/Bootstrap.php';
// Create new PhpSpreadsheet object // Create new PhpSpreadsheet object
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet(); $worksheet = $spreadsheet->getActiveSheet();
// Add some data // Add some data

View File

@ -1,5 +1,7 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
error_reporting(E_ALL); error_reporting(E_ALL);
set_time_limit(0); set_time_limit(0);
@ -22,7 +24,7 @@ date_default_timezone_set('Europe/London');
require_once __DIR__ . '/../../../../src/Bootstrap.php'; require_once __DIR__ . '/../../../../src/Bootstrap.php';
// Create new PhpSpreadsheet object // Create new PhpSpreadsheet object
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet(); $worksheet = $spreadsheet->getActiveSheet();
// Add some data // Add some data

View File

@ -1,5 +1,7 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
error_reporting(E_ALL); error_reporting(E_ALL);
set_time_limit(0); set_time_limit(0);
@ -22,7 +24,7 @@ date_default_timezone_set('Europe/London');
require_once __DIR__ . '/../../../../src/Bootstrap.php'; require_once __DIR__ . '/../../../../src/Bootstrap.php';
// Create new PhpSpreadsheet object // Create new PhpSpreadsheet object
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet(); $worksheet = $spreadsheet->getActiveSheet();
// Add some data // Add some data

View File

@ -1,5 +1,7 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\IOFactory;
error_reporting(E_ALL); error_reporting(E_ALL);
set_time_limit(0); set_time_limit(0);
@ -16,14 +18,14 @@ date_default_timezone_set('Europe/London');
<body> <body>
<h1>PhpSpreadsheet Reader Example #01</h1> <h1>PhpSpreadsheet Reader Example #01</h1>
<h2>Simple File Reader using \PhpOffice\PhpSpreadsheet\IOFactory::load()</h2> <h2>Simple File Reader using IOFactory::load()</h2>
<?php <?php
require_once __DIR__ . '/../../../src/Bootstrap.php'; require_once __DIR__ . '/../../../src/Bootstrap.php';
$inputFileName = './sampleData/example1.xls'; $inputFileName = './sampleData/example1.xls';
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory to identify the format<br />'; echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory to identify the format<br />';
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($inputFileName); $spreadsheet = IOFactory::load($inputFileName);
echo '<hr />'; echo '<hr />';

View File

@ -1,5 +1,7 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Reader\Xls;
error_reporting(E_ALL); error_reporting(E_ALL);
set_time_limit(0); set_time_limit(0);
@ -24,7 +26,7 @@ require_once __DIR__ . '/../../../src/Bootstrap.php';
$inputFileName = './sampleData/example1.xls'; $inputFileName = './sampleData/example1.xls';
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using \PhpOffice\PhpSpreadsheet\Reader\Xls<br />'; echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using \PhpOffice\PhpSpreadsheet\Reader\Xls<br />';
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xls(); $reader = new Xls();
// $reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx(); // $reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
// $reader = new \PhpOffice\PhpSpreadsheet\Reader\Xml(); // $reader = new \PhpOffice\PhpSpreadsheet\Reader\Xml();
// $reader = new \PhpOffice\PhpSpreadsheet\Reader\Ods(); // $reader = new \PhpOffice\PhpSpreadsheet\Reader\Ods();

View File

@ -1,5 +1,7 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\IOFactory;
error_reporting(E_ALL); error_reporting(E_ALL);
set_time_limit(0); set_time_limit(0);
@ -16,7 +18,7 @@ date_default_timezone_set('Europe/London');
<body> <body>
<h1>PhpSpreadsheet Reader Example #03</h1> <h1>PhpSpreadsheet Reader Example #03</h1>
<h2>Simple File Reader using the \PhpOffice\PhpSpreadsheet\IOFactory to Return a Reader</h2> <h2>Simple File Reader using the IOFactory to Return a Reader</h2>
<?php <?php
require_once __DIR__ . '/../../../src/Bootstrap.php'; require_once __DIR__ . '/../../../src/Bootstrap.php';
@ -31,7 +33,7 @@ $inputFileType = 'Xls';
$inputFileName = './sampleData/example1.xls'; $inputFileName = './sampleData/example1.xls';
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />'; echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); $reader = IOFactory::createReader($inputFileType);
$spreadsheet = $reader->load($inputFileName); $spreadsheet = $reader->load($inputFileName);
echo '<hr />'; echo '<hr />';

View File

@ -1,5 +1,7 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\IOFactory;
error_reporting(E_ALL); error_reporting(E_ALL);
set_time_limit(0); set_time_limit(0);
@ -16,18 +18,18 @@ date_default_timezone_set('Europe/London');
<body> <body>
<h1>PhpSpreadsheet Reader Example #04</h1> <h1>PhpSpreadsheet Reader Example #04</h1>
<h2>Simple File Reader using the \PhpOffice\PhpSpreadsheet\IOFactory to Identify a Reader to Use</h2> <h2>Simple File Reader using the IOFactory to Identify a Reader to Use</h2>
<?php <?php
require_once __DIR__ . '/../../../src/Bootstrap.php'; require_once __DIR__ . '/../../../src/Bootstrap.php';
$inputFileName = './sampleData/example1.xls'; $inputFileName = './sampleData/example1.xls';
$inputFileType = \PhpOffice\PhpSpreadsheet\IOFactory::identify($inputFileName); $inputFileType = IOFactory::identify($inputFileName);
echo 'File ',pathinfo($inputFileName, PATHINFO_BASENAME),' has been identified as an ',$inputFileType,' file<br />'; echo 'File ',pathinfo($inputFileName, PATHINFO_BASENAME),' has been identified as an ',$inputFileType,' file<br />';
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with the identified reader type<br />'; echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with the identified reader type<br />';
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); $reader = IOFactory::createReader($inputFileType);
$spreadsheet = $reader->load($inputFileName); $spreadsheet = $reader->load($inputFileName);
echo '<hr />'; echo '<hr />';

View File

@ -1,5 +1,7 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\IOFactory;
error_reporting(E_ALL); error_reporting(E_ALL);
set_time_limit(0); set_time_limit(0);
@ -29,7 +31,7 @@ $inputFileType = 'Xls';
$inputFileName = './sampleData/example1.xls'; $inputFileName = './sampleData/example1.xls';
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />'; echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); $reader = IOFactory::createReader($inputFileType);
echo 'Turning Formatting off for Load<br />'; echo 'Turning Formatting off for Load<br />';
$reader->setReadDataOnly(true); $reader->setReadDataOnly(true);
$spreadsheet = $reader->load($inputFileName); $spreadsheet = $reader->load($inputFileName);

View File

@ -1,5 +1,7 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\IOFactory;
error_reporting(E_ALL); error_reporting(E_ALL);
set_time_limit(0); set_time_limit(0);
@ -29,7 +31,7 @@ $inputFileType = 'Xls';
$inputFileName = './sampleData/example1.xls'; $inputFileName = './sampleData/example1.xls';
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />'; echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); $reader = IOFactory::createReader($inputFileType);
echo 'Loading all WorkSheets<br />'; echo 'Loading all WorkSheets<br />';
$reader->setLoadAllSheets(); $reader->setLoadAllSheets();
$spreadsheet = $reader->load($inputFileName); $spreadsheet = $reader->load($inputFileName);

View File

@ -1,5 +1,7 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\IOFactory;
error_reporting(E_ALL); error_reporting(E_ALL);
set_time_limit(0); set_time_limit(0);
@ -30,7 +32,7 @@ $inputFileName = './sampleData/example1.xls';
$sheetname = 'Data Sheet #2'; $sheetname = 'Data Sheet #2';
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />'; echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); $reader = IOFactory::createReader($inputFileType);
echo 'Loading Sheet "',$sheetname,'" only<br />'; echo 'Loading Sheet "',$sheetname,'" only<br />';
$reader->setLoadSheetsOnly($sheetname); $reader->setLoadSheetsOnly($sheetname);
$spreadsheet = $reader->load($inputFileName); $spreadsheet = $reader->load($inputFileName);

View File

@ -1,5 +1,7 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\IOFactory;
error_reporting(E_ALL); error_reporting(E_ALL);
set_time_limit(0); set_time_limit(0);
@ -30,7 +32,7 @@ $inputFileName = './sampleData/example1.xls';
$sheetnames = ['Data Sheet #1', 'Data Sheet #3']; $sheetnames = ['Data Sheet #1', 'Data Sheet #3'];
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />'; echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); $reader = IOFactory::createReader($inputFileType);
echo 'Loading Sheet',((count($sheetnames) == 1) ? '' : 's'),' "',implode('" and "', $sheetnames),'" only<br />'; echo 'Loading Sheet',((count($sheetnames) == 1) ? '' : 's'),' "',implode('" and "', $sheetnames),'" only<br />';
$reader->setLoadSheetsOnly($sheetnames); $reader->setLoadSheetsOnly($sheetnames);
$spreadsheet = $reader->load($inputFileName); $spreadsheet = $reader->load($inputFileName);

View File

@ -1,5 +1,8 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Reader\IReadFilter;
error_reporting(E_ALL); error_reporting(E_ALL);
set_time_limit(0); set_time_limit(0);
@ -29,7 +32,7 @@ $inputFileType = 'Xls';
$inputFileName = './sampleData/example1.xls'; $inputFileName = './sampleData/example1.xls';
$sheetname = 'Data Sheet #3'; $sheetname = 'Data Sheet #3';
class MyReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter class MyReadFilter implements IReadFilter
{ {
public function readCell($column, $row, $worksheetName = '') public function readCell($column, $row, $worksheetName = '')
{ {
@ -47,7 +50,7 @@ class MyReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter
$filterSubset = new MyReadFilter(); $filterSubset = new MyReadFilter();
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />'; echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); $reader = IOFactory::createReader($inputFileType);
echo 'Loading Sheet "',$sheetname,'" only<br />'; echo 'Loading Sheet "',$sheetname,'" only<br />';
$reader->setLoadSheetsOnly($sheetname); $reader->setLoadSheetsOnly($sheetname);
echo 'Loading Sheet using filter<br />'; echo 'Loading Sheet using filter<br />';

View File

@ -1,5 +1,8 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Reader\IReadFilter;
error_reporting(E_ALL); error_reporting(E_ALL);
set_time_limit(0); set_time_limit(0);
@ -29,7 +32,7 @@ $inputFileType = 'Xls';
$inputFileName = './sampleData/example1.xls'; $inputFileName = './sampleData/example1.xls';
$sheetname = 'Data Sheet #3'; $sheetname = 'Data Sheet #3';
class MyReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter class MyReadFilter implements IReadFilter
{ {
private $_startRow = 0; private $_startRow = 0;
@ -59,7 +62,7 @@ class MyReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter
$filterSubset = new MyReadFilter(9, 15, range('G', 'K')); $filterSubset = new MyReadFilter(9, 15, range('G', 'K'));
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />'; echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); $reader = IOFactory::createReader($inputFileType);
echo 'Loading Sheet "',$sheetname,'" only<br />'; echo 'Loading Sheet "',$sheetname,'" only<br />';
$reader->setLoadSheetsOnly($sheetname); $reader->setLoadSheetsOnly($sheetname);
echo 'Loading Sheet using configurable filter<br />'; echo 'Loading Sheet using configurable filter<br />';

View File

@ -1,5 +1,8 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Reader\IReadFilter;
error_reporting(E_ALL); error_reporting(E_ALL);
set_time_limit(0); set_time_limit(0);
@ -28,8 +31,8 @@ $inputFileType = 'Xls';
// $inputFileType = 'Gnumeric'; // $inputFileType = 'Gnumeric';
$inputFileName = './sampleData/example2.xls'; $inputFileName = './sampleData/example2.xls';
/** Define a Read Filter class implementing \PhpOffice\PhpSpreadsheet\Reader\IReadFilter */ /** Define a Read Filter class implementing IReadFilter */
class chunkReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter class chunkReadFilter implements IReadFilter
{ {
private $_startRow = 0; private $_startRow = 0;
@ -60,7 +63,7 @@ class chunkReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />'; echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
/* Create a new Reader of the type defined in $inputFileType **/ /* Create a new Reader of the type defined in $inputFileType **/
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); $reader = IOFactory::createReader($inputFileType);
echo '<hr />'; echo '<hr />';

View File

@ -1,5 +1,8 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Reader\IReadFilter;
error_reporting(E_ALL); error_reporting(E_ALL);
set_time_limit(0); set_time_limit(0);
@ -28,8 +31,8 @@ $inputFileType = 'Xls';
// $inputFileType = 'Gnumeric'; // $inputFileType = 'Gnumeric';
$inputFileName = './sampleData/example2.xls'; $inputFileName = './sampleData/example2.xls';
/** Define a Read Filter class implementing \PhpOffice\PhpSpreadsheet\Reader\IReadFilter */ /** Define a Read Filter class implementing IReadFilter */
class chunkReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter class chunkReadFilter implements IReadFilter
{ {
private $_startRow = 0; private $_startRow = 0;
@ -60,7 +63,7 @@ class chunkReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />'; echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
/* Create a new Reader of the type defined in $inputFileType **/ /* Create a new Reader of the type defined in $inputFileType **/
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); $reader = IOFactory::createReader($inputFileType);
echo '<hr />'; echo '<hr />';

View File

@ -1,5 +1,7 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\IOFactory;
error_reporting(E_ALL); error_reporting(E_ALL);
set_time_limit(0); set_time_limit(0);
@ -24,7 +26,7 @@ require_once __DIR__ . '/../../../src/Bootstrap.php';
$inputFileType = 'Csv'; $inputFileType = 'Csv';
$inputFileNames = ['./sampleData/example1.csv', './sampleData/example2.csv']; $inputFileNames = ['./sampleData/example1.csv', './sampleData/example2.csv'];
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); $reader = IOFactory::createReader($inputFileType);
$inputFileName = array_shift($inputFileNames); $inputFileName = array_shift($inputFileNames);
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' into WorkSheet #1 using IOFactory with a defined reader type of ',$inputFileType,'<br />'; echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' into WorkSheet #1 using IOFactory with a defined reader type of ',$inputFileType,'<br />';
$spreadsheet = $reader->load($inputFileName); $spreadsheet = $reader->load($inputFileName);

View File

@ -1,5 +1,9 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Reader\IReadFilter;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
error_reporting(E_ALL); error_reporting(E_ALL);
set_time_limit(0); set_time_limit(0);
@ -24,8 +28,8 @@ require_once __DIR__ . '/../../../src/Bootstrap.php';
$inputFileType = 'Csv'; $inputFileType = 'Csv';
$inputFileName = './sampleData/example2.csv'; $inputFileName = './sampleData/example2.csv';
/** Define a Read Filter class implementing \PhpOffice\PhpSpreadsheet\Reader\IReadFilter */ /** Define a Read Filter class implementing IReadFilter */
class chunkReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter class chunkReadFilter implements IReadFilter
{ {
private $_startRow = 0; private $_startRow = 0;
@ -56,7 +60,7 @@ class chunkReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />'; echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
/* Create a new Reader of the type defined in $inputFileType **/ /* Create a new Reader of the type defined in $inputFileType **/
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); $reader = IOFactory::createReader($inputFileType);
echo '<hr />'; echo '<hr />';
@ -71,7 +75,7 @@ $reader->setReadFilter($chunkFilter)
->setContiguous(true); ->setContiguous(true);
/* Instantiate a new PhpSpreadsheet object manually **/ /* Instantiate a new PhpSpreadsheet object manually **/
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $spreadsheet = new Spreadsheet();
/* Set a sheet index **/ /* Set a sheet index **/
$sheet = 0; $sheet = 0;

View File

@ -1,5 +1,8 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Cell;
use PhpOffice\PhpSpreadsheet\IOFactory;
error_reporting(E_ALL); error_reporting(E_ALL);
set_time_limit(0); set_time_limit(0);
@ -21,12 +24,12 @@ date_default_timezone_set('Europe/London');
require_once __DIR__ . '/../../../src/Bootstrap.php'; require_once __DIR__ . '/../../../src/Bootstrap.php';
\PhpOffice\PhpSpreadsheet\Cell::setValueBinder(new \PhpOffice\PhpSpreadsheet\Cell\AdvancedValueBinder()); Cell::setValueBinder(new Cell\AdvancedValueBinder());
$inputFileType = 'Csv'; $inputFileType = 'Csv';
$inputFileName = './sampleData/example1.tsv'; $inputFileName = './sampleData/example1.tsv';
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); $reader = IOFactory::createReader($inputFileType);
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' into WorkSheet #1 using IOFactory with a defined reader type of ',$inputFileType,'<br />'; echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' into WorkSheet #1 using IOFactory with a defined reader type of ',$inputFileType,'<br />';
$reader->setDelimiter("\t"); $reader->setDelimiter("\t");
$spreadsheet = $reader->load($inputFileName); $spreadsheet = $reader->load($inputFileName);

View File

@ -1,5 +1,8 @@
<?php <?php
use InvalidArgumentException;
use PhpOffice\PhpSpreadsheet\IOFactory;
error_reporting(E_ALL); error_reporting(E_ALL);
set_time_limit(0); set_time_limit(0);
@ -24,8 +27,8 @@ require_once __DIR__ . '/../../../src/Bootstrap.php';
$inputFileName = './sampleData/example_1.xls'; $inputFileName = './sampleData/example_1.xls';
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory to identify the format<br />'; echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory to identify the format<br />';
try { try {
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($inputFileName); $spreadsheet = IOFactory::load($inputFileName);
} catch (\InvalidArgumentException $e) { } catch (InvalidArgumentException $e) {
die('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' . $e->getMessage()); die('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' . $e->getMessage());
} }

View File

@ -1,5 +1,7 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\IOFactory;
error_reporting(E_ALL); error_reporting(E_ALL);
set_time_limit(0); set_time_limit(0);
@ -29,7 +31,7 @@ $inputFileType = 'Xls';
$inputFileName = './sampleData/example1.xls'; $inputFileName = './sampleData/example1.xls';
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />'; echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); $reader = IOFactory::createReader($inputFileType);
/* Read the list of Worksheet Names from the Workbook file **/ /* Read the list of Worksheet Names from the Workbook file **/
echo 'Read the list of Worksheets in the WorkBook<br />'; echo 'Read the list of Worksheets in the WorkBook<br />';

View File

@ -1,5 +1,7 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\IOFactory;
error_reporting(E_ALL); error_reporting(E_ALL);
set_time_limit(0); set_time_limit(0);
@ -30,7 +32,7 @@ $inputFileName = './sampleData/example1.xls';
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' information using IOFactory with a defined reader type of ',$inputFileType,'<br />'; echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' information using IOFactory with a defined reader type of ',$inputFileType,'<br />';
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); $reader = IOFactory::createReader($inputFileType);
$worksheetNames = $reader->listWorksheetNames($inputFileName); $worksheetNames = $reader->listWorksheetNames($inputFileName);
echo '<h3>Worksheet Names</h3>'; echo '<h3>Worksheet Names</h3>';

View File

@ -1,5 +1,7 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\IOFactory;
error_reporting(E_ALL); error_reporting(E_ALL);
set_time_limit(0); set_time_limit(0);
@ -30,7 +32,7 @@ $inputFileName = './sampleData/example1.xls';
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' information using IOFactory with a defined reader type of ',$inputFileType,'<br />'; echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' information using IOFactory with a defined reader type of ',$inputFileType,'<br />';
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); $reader = IOFactory::createReader($inputFileType);
$worksheetData = $reader->listWorksheetInfo($inputFileName); $worksheetData = $reader->listWorksheetInfo($inputFileName);
echo '<h3>Worksheet Information</h3>'; echo '<h3>Worksheet Information</h3>';

View File

@ -1,5 +1,7 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\IOFactory;
error_reporting(E_ALL); error_reporting(E_ALL);
set_time_limit(0); set_time_limit(0);
@ -25,7 +27,7 @@ $inputFileType = 'Xls';
$inputFileName = './sampleData/example1.xls'; $inputFileName = './sampleData/example1.xls';
/* Create a new Reader of the type defined in $inputFileType **/ /* Create a new Reader of the type defined in $inputFileType **/
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); $reader = IOFactory::createReader($inputFileType);
/* Load $inputFileName to a PhpSpreadsheet Object **/ /* Load $inputFileName to a PhpSpreadsheet Object **/
$spreadsheet = $reader->load($inputFileName); $spreadsheet = $reader->load($inputFileName);

View File

@ -1,5 +1,7 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\IOFactory;
error_reporting(E_ALL); error_reporting(E_ALL);
set_time_limit(0); set_time_limit(0);
@ -25,7 +27,7 @@ $inputFileType = 'Xlsx';
$inputFileName = './sampleData/example1.xlsx'; $inputFileName = './sampleData/example1.xlsx';
/* Create a new Reader of the type defined in $inputFileType **/ /* Create a new Reader of the type defined in $inputFileType **/
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); $reader = IOFactory::createReader($inputFileType);
/* Load $inputFileName to a PhpSpreadsheet Object **/ /* Load $inputFileName to a PhpSpreadsheet Object **/
$spreadsheet = $reader->load($inputFileName); $spreadsheet = $reader->load($inputFileName);

View File

@ -1,5 +1,7 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\IOFactory;
error_reporting(E_ALL); error_reporting(E_ALL);
set_time_limit(0); set_time_limit(0);
@ -25,7 +27,7 @@ $inputFileType = 'Xlsx';
$inputFileName = './sampleData/example1.xlsx'; $inputFileName = './sampleData/example1.xlsx';
/* Create a new Reader of the type defined in $inputFileType **/ /* Create a new Reader of the type defined in $inputFileType **/
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); $reader = IOFactory::createReader($inputFileType);
/* Load $inputFileName to a PhpSpreadsheet Object **/ /* Load $inputFileName to a PhpSpreadsheet Object **/
$spreadsheet = $reader->load($inputFileName); $spreadsheet = $reader->load($inputFileName);

View File

@ -1,5 +1,7 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\IOFactory;
error_reporting(E_ALL); error_reporting(E_ALL);
set_time_limit(0); set_time_limit(0);
@ -25,7 +27,7 @@ $inputFileType = 'Xls';
$inputFileName = './sampleData/example2.xls'; $inputFileName = './sampleData/example2.xls';
/* Create a new Reader of the type defined in $inputFileType **/ /* Create a new Reader of the type defined in $inputFileType **/
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); $reader = IOFactory::createReader($inputFileType);
/* Load $inputFileName to a PhpSpreadsheet Object **/ /* Load $inputFileName to a PhpSpreadsheet Object **/
$spreadsheet = $reader->load($inputFileName); $spreadsheet = $reader->load($inputFileName);

View File

@ -1,10 +1,12 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.php';
// Create new Spreadsheet object $spreadsheet = new Spreadsheet();
$helper->log('Create new Spreadsheet object'); $helper->log('Create new Spreadsheet object');
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $spreadsheet = new Spreadsheet();
// Set document properties // Set document properties
$helper->log('Set document properties'); $helper->log('Set document properties');

View File

@ -1,8 +1,12 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Helper\Sample;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require_once __DIR__ . '/../src/Bootstrap.php'; require_once __DIR__ . '/../src/Bootstrap.php';
$helper = new \PhpOffice\PhpSpreadsheet\Helper\Sample(); $helper = new Sample();
if ($helper->isCli()) { if ($helper->isCli()) {
echo 'This example should only be run from a Web Browser' . PHP_EOL; echo 'This example should only be run from a Web Browser' . PHP_EOL;
@ -10,7 +14,7 @@ if ($helper->isCli()) {
} }
// Create new Spreadsheet object // Create new Spreadsheet object
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $spreadsheet = new Spreadsheet();
// Set document properties // Set document properties
$spreadsheet->getProperties()->setCreator('Maarten Balliauw') $spreadsheet->getProperties()->setCreator('Maarten Balliauw')
@ -52,6 +56,6 @@ header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modifie
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
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Ods'); $writer = IOFactory::createWriter($spreadsheet, 'Ods');
$writer->save('php://output'); $writer->save('php://output');
exit; exit;

View File

@ -1,8 +1,13 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Helper\Sample;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Settings;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require_once __DIR__ . '/../src/Bootstrap.php'; require_once __DIR__ . '/../src/Bootstrap.php';
$helper = new \PhpOffice\PhpSpreadsheet\Helper\Sample(); $helper = new Sample();
if ($helper->isCli()) { if ($helper->isCli()) {
echo 'This example should only be run from a Web Browser' . PHP_EOL; echo 'This example should only be run from a Web Browser' . PHP_EOL;
@ -12,11 +17,11 @@ if ($helper->isCli()) {
// 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 = \PhpOffice\PhpSpreadsheet\Settings::PDF_RENDERER_TCPDF; //$rendererName = \PhpOffice\PhpSpreadsheet\Settings::PDF_RENDERER_TCPDF;
$rendererName = \PhpOffice\PhpSpreadsheet\Settings::PDF_RENDERER_MPDF; $rendererName = Settings::PDF_RENDERER_MPDF;
//$rendererName = \PhpOffice\PhpSpreadsheet\Settings::PDF_RENDERER_DOMPDF; //$rendererName = \PhpOffice\PhpSpreadsheet\Settings::PDF_RENDERER_DOMPDF;
// Create new Spreadsheet object // Create new Spreadsheet object
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $spreadsheet = new Spreadsheet();
// Set document properties // Set document properties
$spreadsheet->getProperties()->setCreator('Maarten Balliauw') $spreadsheet->getProperties()->setCreator('Maarten Balliauw')
@ -46,13 +51,13 @@ $spreadsheet->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
$spreadsheet->setActiveSheetIndex(0); $spreadsheet->setActiveSheetIndex(0);
\PhpOffice\PhpSpreadsheet\Settings::setPdfRendererName($rendererName); Settings::setPdfRendererName($rendererName);
// Redirect output to a clients web browser (PDF) // Redirect output to a clients web browser (PDF)
header('Content-Type: application/pdf'); 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');
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Pdf'); $writer = IOFactory::createWriter($spreadsheet, 'Pdf');
$writer->save('php://output'); $writer->save('php://output');
exit; exit;

View File

@ -1,8 +1,12 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Helper\Sample;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require_once __DIR__ . '/../src/Bootstrap.php'; require_once __DIR__ . '/../src/Bootstrap.php';
$helper = new \PhpOffice\PhpSpreadsheet\Helper\Sample(); $helper = new Sample();
if ($helper->isCli()) { if ($helper->isCli()) {
echo 'This example should only be run from a Web Browser' . PHP_EOL; echo 'This example should only be run from a Web Browser' . PHP_EOL;
@ -10,7 +14,7 @@ if ($helper->isCli()) {
} }
// Create new Spreadsheet object // Create new Spreadsheet object
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $spreadsheet = new Spreadsheet();
// Set document properties // Set document properties
$spreadsheet->getProperties()->setCreator('Maarten Balliauw') $spreadsheet->getProperties()->setCreator('Maarten Balliauw')
@ -52,6 +56,6 @@ header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modifie
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
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xls'); $writer = IOFactory::createWriter($spreadsheet, 'Xls');
$writer->save('php://output'); $writer->save('php://output');
exit; exit;

View File

@ -1,15 +1,19 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Helper\Sample;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require_once __DIR__ . '/../src/Bootstrap.php'; require_once __DIR__ . '/../src/Bootstrap.php';
$helper = new \PhpOffice\PhpSpreadsheet\Helper\Sample(); $helper = new Sample();
if ($helper->isCli()) { if ($helper->isCli()) {
echo 'This example should only be run from a Web Browser' . PHP_EOL; echo 'This example should only be run from a Web Browser' . PHP_EOL;
return; return;
} }
// Create new Spreadsheet object // Create new Spreadsheet object
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $spreadsheet = new Spreadsheet();
// Set document properties // Set document properties
$spreadsheet->getProperties()->setCreator('Maarten Balliauw') $spreadsheet->getProperties()->setCreator('Maarten Balliauw')
@ -51,6 +55,6 @@ header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modifie
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
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx'); $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->save('php://output'); $writer->save('php://output');
exit; exit;

View File

@ -1,10 +1,16 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\RichText;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Style\Color;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.php';
// Create new Spreadsheet object // Create new Spreadsheet object
$helper->log('Create new Spreadsheet object'); $helper->log('Create new Spreadsheet object');
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $spreadsheet = new Spreadsheet();
// Set document properties // Set document properties
$helper->log('Set document properties'); $helper->log('Set document properties');
@ -70,41 +76,41 @@ $dateTimeNow = time();
$spreadsheet->getActiveSheet() $spreadsheet->getActiveSheet()
->setCellValue('A9', 'Date/Time') ->setCellValue('A9', 'Date/Time')
->setCellValue('B9', 'Date') ->setCellValue('B9', 'Date')
->setCellValue('C9', \PhpOffice\PhpSpreadsheet\Shared\Date::PHPToExcel($dateTimeNow)); ->setCellValue('C9', Date::PHPToExcel($dateTimeNow));
$spreadsheet->getActiveSheet() $spreadsheet->getActiveSheet()
->getStyle('C9') ->getStyle('C9')
->getNumberFormat() ->getNumberFormat()
->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_YYYYMMDD2); ->setFormatCode(NumberFormat::FORMAT_DATE_YYYYMMDD2);
$spreadsheet->getActiveSheet() $spreadsheet->getActiveSheet()
->setCellValue('A10', 'Date/Time') ->setCellValue('A10', 'Date/Time')
->setCellValue('B10', 'Time') ->setCellValue('B10', 'Time')
->setCellValue('C10', \PhpOffice\PhpSpreadsheet\Shared\Date::PHPToExcel($dateTimeNow)); ->setCellValue('C10', Date::PHPToExcel($dateTimeNow));
$spreadsheet->getActiveSheet() $spreadsheet->getActiveSheet()
->getStyle('C10') ->getStyle('C10')
->getNumberFormat() ->getNumberFormat()
->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_TIME4); ->setFormatCode(NumberFormat::FORMAT_DATE_TIME4);
$spreadsheet->getActiveSheet() $spreadsheet->getActiveSheet()
->setCellValue('A11', 'Date/Time') ->setCellValue('A11', 'Date/Time')
->setCellValue('B11', 'Date and Time') ->setCellValue('B11', 'Date and Time')
->setCellValue('C11', \PhpOffice\PhpSpreadsheet\Shared\Date::PHPToExcel($dateTimeNow)); ->setCellValue('C11', Date::PHPToExcel($dateTimeNow));
$spreadsheet->getActiveSheet() $spreadsheet->getActiveSheet()
->getStyle('C11') ->getStyle('C11')
->getNumberFormat() ->getNumberFormat()
->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_DATETIME); ->setFormatCode(NumberFormat::FORMAT_DATE_DATETIME);
$spreadsheet->getActiveSheet() $spreadsheet->getActiveSheet()
->setCellValue('A12', 'NULL') ->setCellValue('A12', 'NULL')
->setCellValue('C12', null); ->setCellValue('C12', null);
$richText = new \PhpOffice\PhpSpreadsheet\RichText(); $richText = new RichText();
$richText->createText('你好 '); $richText->createText('你好 ');
$payable = $richText->createTextRun('你 好 吗?'); $payable = $richText->createTextRun('你 好 吗?');
$payable->getFont()->setBold(true); $payable->getFont()->setBold(true);
$payable->getFont()->setItalic(true); $payable->getFont()->setItalic(true);
$payable->getFont()->setColor(new \PhpOffice\PhpSpreadsheet\Style\Color(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_DARKGREEN)); $payable->getFont()->setColor(new Color(Color::COLOR_DARKGREEN));
$richText->createText(', unless specified otherwise on the invoice.'); $richText->createText(', unless specified otherwise on the invoice.');
@ -112,11 +118,11 @@ $spreadsheet->getActiveSheet()
->setCellValue('A13', 'Rich Text') ->setCellValue('A13', 'Rich Text')
->setCellValue('C13', $richText); ->setCellValue('C13', $richText);
$richText2 = new \PhpOffice\PhpSpreadsheet\RichText(); $richText2 = new RichText();
$richText2->createText("black text\n"); $richText2->createText("black text\n");
$red = $richText2->createTextRun('red text'); $red = $richText2->createTextRun('red text');
$red->getFont()->setColor(new \PhpOffice\PhpSpreadsheet\Style\Color(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_RED)); $red->getFont()->setColor(new Color(Color::COLOR_RED));
$spreadsheet->getActiveSheet() $spreadsheet->getActiveSheet()
->getCell('C14') ->getCell('C14')

View File

@ -1,10 +1,12 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.php';
// Create new Spreadsheet object // Create new Spreadsheet object
$helper->log('Create new Spreadsheet object'); $helper->log('Create new Spreadsheet object');
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $spreadsheet = new Spreadsheet();
// Set document properties // Set document properties
$helper->log('Set document properties'); $helper->log('Set document properties');

View File

@ -1,10 +1,15 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Worksheet\HeaderFooter;
use PhpOffice\PhpSpreadsheet\Worksheet\HeaderFooterDrawing;
use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.php';
// Create new Spreadsheet object // Create new Spreadsheet object
$helper->log('Create new Spreadsheet object'); $helper->log('Create new Spreadsheet object');
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $spreadsheet = new Spreadsheet();
// Set document properties // Set document properties
$helper->log('Set document properties'); $helper->log('Set document properties');
@ -34,22 +39,22 @@ $spreadsheet->getActiveSheet()
// Add a drawing to the header // Add a drawing to the header
$helper->log('Add a drawing to the header'); $helper->log('Add a drawing to the header');
$drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\HeaderFooterDrawing(); $drawing = new HeaderFooterDrawing();
$drawing->setName('PhpSpreadsheet logo'); $drawing->setName('PhpSpreadsheet logo');
$drawing->setPath(__DIR__ . '/images/PhpSpreadsheet_logo.png'); $drawing->setPath(__DIR__ . '/images/PhpSpreadsheet_logo.png');
$drawing->setHeight(36); $drawing->setHeight(36);
$spreadsheet->getActiveSheet() $spreadsheet->getActiveSheet()
->getHeaderFooter() ->getHeaderFooter()
->addImage($drawing, \PhpOffice\PhpSpreadsheet\Worksheet\HeaderFooter::IMAGE_HEADER_LEFT); ->addImage($drawing, HeaderFooter::IMAGE_HEADER_LEFT);
// Set page orientation and size // Set page orientation and size
$helper->log('Set page orientation and size'); $helper->log('Set page orientation and size');
$spreadsheet->getActiveSheet() $spreadsheet->getActiveSheet()
->getPageSetup() ->getPageSetup()
->setOrientation(\PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_LANDSCAPE); ->setOrientation(PageSetup::ORIENTATION_LANDSCAPE);
$spreadsheet->getActiveSheet() $spreadsheet->getActiveSheet()
->getPageSetup() ->getPageSetup()
->setPaperSize(\PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_A4); ->setPaperSize(PageSetup::PAPERSIZE_A4);
// Rename worksheet // Rename worksheet
$helper->log('Rename worksheet'); $helper->log('Rename worksheet');

View File

@ -1,15 +1,18 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.php';
// Create temporary file that will be read // Create temporary file that will be read
$sampleSpreadsheet = require __DIR__ . '/templates/sampleSpreadsheet.php'; $sampleSpreadsheet = require __DIR__ . '/templates/sampleSpreadsheet.php';
$filename = $helper->getTemporaryFilename(); $filename = $helper->getTemporaryFilename();
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($sampleSpreadsheet); $writer = new Xlsx($sampleSpreadsheet);
$writer->save($filename); $writer->save($filename);
$callStartTime = microtime(true); $callStartTime = microtime(true);
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($filename); $spreadsheet = IOFactory::load($filename);
$helper->logRead('Xlsx', $filename, $callStartTime); $helper->logRead('Xlsx', $filename, $callStartTime);
// Save // Save

View File

@ -1,10 +1,16 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Style\Color;
use PhpOffice\PhpSpreadsheet\Style\Conditional;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.php';
// Create new Spreadsheet object // Create new Spreadsheet object
$helper->log('Create new Spreadsheet object'); $helper->log('Create new Spreadsheet object');
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $spreadsheet = new Spreadsheet();
// Set document properties // Set document properties
$helper->log('Set document properties'); $helper->log('Set document properties');
@ -47,30 +53,30 @@ $spreadsheet->getActiveSheet()->getColumnDimension('B')->setWidth(12);
// Add conditional formatting // Add conditional formatting
$helper->log('Add conditional formatting'); $helper->log('Add conditional formatting');
$conditional1 = new \PhpOffice\PhpSpreadsheet\Style\Conditional(); $conditional1 = new Conditional();
$conditional1->setConditionType(\PhpOffice\PhpSpreadsheet\Style\Conditional::CONDITION_CELLIS) $conditional1->setConditionType(Conditional::CONDITION_CELLIS)
->setOperatorType(\PhpOffice\PhpSpreadsheet\Style\Conditional::OPERATOR_BETWEEN) ->setOperatorType(Conditional::OPERATOR_BETWEEN)
->addCondition('200') ->addCondition('200')
->addCondition('400'); ->addCondition('400');
$conditional1->getStyle()->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_YELLOW); $conditional1->getStyle()->getFont()->getColor()->setARGB(Color::COLOR_YELLOW);
$conditional1->getStyle()->getFont()->setBold(true); $conditional1->getStyle()->getFont()->setBold(true);
$conditional1->getStyle()->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE); $conditional1->getStyle()->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
$conditional2 = new \PhpOffice\PhpSpreadsheet\Style\Conditional(); $conditional2 = new Conditional();
$conditional2->setConditionType(\PhpOffice\PhpSpreadsheet\Style\Conditional::CONDITION_CELLIS) $conditional2->setConditionType(Conditional::CONDITION_CELLIS)
->setOperatorType(\PhpOffice\PhpSpreadsheet\Style\Conditional::OPERATOR_LESSTHAN) ->setOperatorType(Conditional::OPERATOR_LESSTHAN)
->addCondition('0'); ->addCondition('0');
$conditional2->getStyle()->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_RED); $conditional2->getStyle()->getFont()->getColor()->setARGB(Color::COLOR_RED);
$conditional2->getStyle()->getFont()->setItalic(true); $conditional2->getStyle()->getFont()->setItalic(true);
$conditional2->getStyle()->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE); $conditional2->getStyle()->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
$conditional3 = new \PhpOffice\PhpSpreadsheet\Style\Conditional(); $conditional3 = new Conditional();
$conditional3->setConditionType(\PhpOffice\PhpSpreadsheet\Style\Conditional::CONDITION_CELLIS) $conditional3->setConditionType(Conditional::CONDITION_CELLIS)
->setOperatorType(\PhpOffice\PhpSpreadsheet\Style\Conditional::OPERATOR_GREATERTHANOREQUAL) ->setOperatorType(Conditional::OPERATOR_GREATERTHANOREQUAL)
->addCondition('0'); ->addCondition('0');
$conditional3->getStyle()->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_GREEN); $conditional3->getStyle()->getFont()->getColor()->setARGB(Color::COLOR_GREEN);
$conditional3->getStyle()->getFont()->setItalic(true); $conditional3->getStyle()->getFont()->setItalic(true);
$conditional3->getStyle()->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE); $conditional3->getStyle()->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
$conditionalStyles = $spreadsheet->getActiveSheet()->getStyle('B2')->getConditionalStyles(); $conditionalStyles = $spreadsheet->getActiveSheet()->getStyle('B2')->getConditionalStyles();
array_push($conditionalStyles, $conditional1); array_push($conditionalStyles, $conditional1);
@ -98,8 +104,8 @@ $spreadsheet->getActiveSheet()->getHeaderFooter()->setOddFooter('&L&B' . $spread
// Set page orientation and size // Set page orientation and size
$helper->log('Set page orientation and size'); $helper->log('Set page orientation and size');
$spreadsheet->getActiveSheet()->getPageSetup()->setOrientation(\PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_PORTRAIT); $spreadsheet->getActiveSheet()->getPageSetup()->setOrientation(PageSetup::ORIENTATION_PORTRAIT);
$spreadsheet->getActiveSheet()->getPageSetup()->setPaperSize(\PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_A4); $spreadsheet->getActiveSheet()->getPageSetup()->setPaperSize(PageSetup::PAPERSIZE_A4);
// Rename worksheet // Rename worksheet
$helper->log('Rename worksheet'); $helper->log('Rename worksheet');

View File

@ -1,10 +1,15 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Style\Color;
use PhpOffice\PhpSpreadsheet\Style\Conditional;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.php';
// Create new Spreadsheet object // Create new Spreadsheet object
$helper->log('Create new Spreadsheet object'); $helper->log('Create new Spreadsheet object');
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $spreadsheet = new Spreadsheet();
// Set document properties // Set document properties
$helper->log('Set document properties'); $helper->log('Set document properties');
@ -32,22 +37,22 @@ $spreadsheet->getActiveSheet()
$spreadsheet->getActiveSheet()->getStyle('A1:A8') $spreadsheet->getActiveSheet()->getStyle('A1:A8')
->getNumberFormat() ->getNumberFormat()
->setFormatCode( ->setFormatCode(
\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_PERCENTAGE_00 NumberFormat::FORMAT_PERCENTAGE_00
); );
// Add conditional formatting // Add conditional formatting
$helper->log('Add conditional formatting'); $helper->log('Add conditional formatting');
$conditional1 = new \PhpOffice\PhpSpreadsheet\Style\Conditional(); $conditional1 = new Conditional();
$conditional1->setConditionType(\PhpOffice\PhpSpreadsheet\Style\Conditional::CONDITION_CELLIS) $conditional1->setConditionType(Conditional::CONDITION_CELLIS)
->setOperatorType(\PhpOffice\PhpSpreadsheet\Style\Conditional::OPERATOR_LESSTHAN) ->setOperatorType(Conditional::OPERATOR_LESSTHAN)
->addCondition('0'); ->addCondition('0');
$conditional1->getStyle()->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_RED); $conditional1->getStyle()->getFont()->getColor()->setARGB(Color::COLOR_RED);
$conditional3 = new \PhpOffice\PhpSpreadsheet\Style\Conditional(); $conditional3 = new Conditional();
$conditional3->setConditionType(\PhpOffice\PhpSpreadsheet\Style\Conditional::CONDITION_CELLIS) $conditional3->setConditionType(Conditional::CONDITION_CELLIS)
->setOperatorType(\PhpOffice\PhpSpreadsheet\Style\Conditional::OPERATOR_GREATERTHANOREQUAL) ->setOperatorType(Conditional::OPERATOR_GREATERTHANOREQUAL)
->addCondition('1'); ->addCondition('1');
$conditional3->getStyle()->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_GREEN); $conditional3->getStyle()->getFont()->getColor()->setARGB(Color::COLOR_GREEN);
$conditionalStyles = $spreadsheet->getActiveSheet()->getStyle('A1')->getConditionalStyles(); $conditionalStyles = $spreadsheet->getActiveSheet()->getStyle('A1')->getConditionalStyles();
array_push($conditionalStyles, $conditional1); array_push($conditionalStyles, $conditional1);

View File

@ -1,10 +1,13 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Worksheet;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.php';
// Create new Spreadsheet object // Create new Spreadsheet object
$helper->log('Create new Spreadsheet object'); $helper->log('Create new Spreadsheet object');
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $spreadsheet = new Spreadsheet();
// Set document properties // Set document properties
$helper->log('Set document properties'); $helper->log('Set document properties');
@ -36,7 +39,7 @@ for ($i = 2; $i <= 50; ++$i) {
// Add page breaks every 10 rows // Add page breaks every 10 rows
if ($i % 10 == 0) { if ($i % 10 == 0) {
// Add a page break // Add a page break
$spreadsheet->getActiveSheet()->setBreak('A' . $i, \PhpOffice\PhpSpreadsheet\Worksheet::BREAK_ROW); $spreadsheet->getActiveSheet()->setBreak('A' . $i, Worksheet::BREAK_ROW);
} }
} }

View File

@ -1,10 +1,12 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.php';
// Create new Spreadsheet object // Create new Spreadsheet object
$helper->log('Create new Spreadsheet object'); $helper->log('Create new Spreadsheet object');
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $spreadsheet = new Spreadsheet();
// Set document properties // Set document properties
$helper->log('Set document properties'); $helper->log('Set document properties');

View File

@ -1,10 +1,16 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Shared\Date;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column;
use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.php';
// Create new Spreadsheet object // Create new Spreadsheet object
$helper->log('Create new Spreadsheet object'); $helper->log('Create new Spreadsheet object');
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $spreadsheet = new Spreadsheet();
// Set document properties // Set document properties
$helper->log('Set document properties'); $helper->log('Set document properties');
@ -48,7 +54,7 @@ foreach ($years as $year) {
foreach ($countries as $country) { foreach ($countries as $country) {
$endDays = date('t', mktime(0, 0, 0, $period, 1, $year)); $endDays = date('t', mktime(0, 0, 0, $period, 1, $year));
for ($i = 1; $i <= $endDays; ++$i) { for ($i = 1; $i <= $endDays; ++$i) {
$eDate = \PhpOffice\PhpSpreadsheet\Shared\Date::formattedPHPToExcel( $eDate = Date::formattedPHPToExcel(
$year, $year,
$period, $period,
$i $i
@ -86,8 +92,8 @@ $spreadsheet->getActiveSheet()->getStyle('A1:F1')->getFont()->setBold(true);
$spreadsheet->getActiveSheet()->getStyle('A1:F1')->getAlignment()->setWrapText(true); $spreadsheet->getActiveSheet()->getStyle('A1:F1')->getAlignment()->setWrapText(true);
$spreadsheet->getActiveSheet()->getColumnDimension('C')->setWidth(12.5); $spreadsheet->getActiveSheet()->getColumnDimension('C')->setWidth(12.5);
$spreadsheet->getActiveSheet()->getColumnDimension('D')->setWidth(10.5); $spreadsheet->getActiveSheet()->getColumnDimension('D')->setWidth(10.5);
$spreadsheet->getActiveSheet()->getStyle('D2:D' . $row)->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_YYYYMMDD2); $spreadsheet->getActiveSheet()->getStyle('D2:D' . $row)->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_DATE_YYYYMMDD2);
$spreadsheet->getActiveSheet()->getStyle('E2:F' . $row)->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_CURRENCY_USD_SIMPLE); $spreadsheet->getActiveSheet()->getStyle('E2:F' . $row)->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_CURRENCY_USD_SIMPLE);
$spreadsheet->getActiveSheet()->getColumnDimension('F')->setWidth(14); $spreadsheet->getActiveSheet()->getColumnDimension('F')->setWidth(14);
$spreadsheet->getActiveSheet()->freezePane('A2'); $spreadsheet->getActiveSheet()->freezePane('A2');
@ -104,45 +110,45 @@ $helper->log('Set active filters');
// Filter the Country column on a filter value of countries beginning with the letter U (or Japan) // Filter the Country column on a filter value of countries beginning with the letter U (or Japan)
// We use * as a wildcard, so specify as U* and using a wildcard requires customFilter // We use * as a wildcard, so specify as U* and using a wildcard requires customFilter
$autoFilter->getColumn('C') $autoFilter->getColumn('C')
->setFilterType(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column::AUTOFILTER_FILTERTYPE_CUSTOMFILTER) ->setFilterType(Column::AUTOFILTER_FILTERTYPE_CUSTOMFILTER)
->createRule() ->createRule()
->setRule( ->setRule(
\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_COLUMN_RULE_EQUAL, Rule::AUTOFILTER_COLUMN_RULE_EQUAL,
'u*' 'u*'
) )
->setRuleType(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_RULETYPE_CUSTOMFILTER); ->setRuleType(Rule::AUTOFILTER_RULETYPE_CUSTOMFILTER);
$autoFilter->getColumn('C') $autoFilter->getColumn('C')
->createRule() ->createRule()
->setRule( ->setRule(
\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_COLUMN_RULE_EQUAL, Rule::AUTOFILTER_COLUMN_RULE_EQUAL,
'japan' 'japan'
) )
->setRuleType(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_RULETYPE_CUSTOMFILTER); ->setRuleType(Rule::AUTOFILTER_RULETYPE_CUSTOMFILTER);
// Filter the Date column on a filter value of the first day of every period of the current year // Filter the Date column on a filter value of the first day of every period of the current year
// We us a dateGroup ruletype for this, although it is still a standard filter // We us a dateGroup ruletype for this, although it is still a standard filter
foreach ($periods as $period) { foreach ($periods as $period) {
$endDate = date('t', mktime(0, 0, 0, $period, 1, $currentYear)); $endDate = date('t', mktime(0, 0, 0, $period, 1, $currentYear));
$autoFilter->getColumn('D') $autoFilter->getColumn('D')
->setFilterType(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column::AUTOFILTER_FILTERTYPE_FILTER) ->setFilterType(Column::AUTOFILTER_FILTERTYPE_FILTER)
->createRule() ->createRule()
->setRule( ->setRule(
\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_COLUMN_RULE_EQUAL, Rule::AUTOFILTER_COLUMN_RULE_EQUAL,
[ [
'year' => $currentYear, 'year' => $currentYear,
'month' => $period, 'month' => $period,
'day' => $endDate, 'day' => $endDate,
] ]
) )
->setRuleType(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_RULETYPE_DATEGROUP); ->setRuleType(Rule::AUTOFILTER_RULETYPE_DATEGROUP);
} }
// Display only sales values that are blank // Display only sales values that are blank
// Standard filter, operator equals, and value of NULL // Standard filter, operator equals, and value of NULL
$autoFilter->getColumn('E') $autoFilter->getColumn('E')
->setFilterType(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column::AUTOFILTER_FILTERTYPE_FILTER) ->setFilterType(Column::AUTOFILTER_FILTERTYPE_FILTER)
->createRule() ->createRule()
->setRule( ->setRule(
\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_COLUMN_RULE_EQUAL, Rule::AUTOFILTER_COLUMN_RULE_EQUAL,
'' ''
); );

View File

@ -1,10 +1,16 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Shared\Date;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column;
use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.php';
// Create new Spreadsheet object // Create new Spreadsheet object
$helper->log('Create new Spreadsheet object'); $helper->log('Create new Spreadsheet object');
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $spreadsheet = new Spreadsheet();
// Set document properties // Set document properties
$helper->log('Set document properties'); $helper->log('Set document properties');
@ -48,7 +54,7 @@ foreach ($years as $year) {
foreach ($countries as $country) { foreach ($countries as $country) {
$endDays = date('t', mktime(0, 0, 0, $period, 1, $year)); $endDays = date('t', mktime(0, 0, 0, $period, 1, $year));
for ($i = 1; $i <= $endDays; ++$i) { for ($i = 1; $i <= $endDays; ++$i) {
$eDate = \PhpOffice\PhpSpreadsheet\Shared\Date::formattedPHPToExcel( $eDate = Date::formattedPHPToExcel(
$year, $year,
$period, $period,
$i $i
@ -86,8 +92,8 @@ $spreadsheet->getActiveSheet()->getStyle('A1:F1')->getFont()->setBold(true);
$spreadsheet->getActiveSheet()->getStyle('A1:F1')->getAlignment()->setWrapText(true); $spreadsheet->getActiveSheet()->getStyle('A1:F1')->getAlignment()->setWrapText(true);
$spreadsheet->getActiveSheet()->getColumnDimension('C')->setWidth(12.5); $spreadsheet->getActiveSheet()->getColumnDimension('C')->setWidth(12.5);
$spreadsheet->getActiveSheet()->getColumnDimension('D')->setWidth(10.5); $spreadsheet->getActiveSheet()->getColumnDimension('D')->setWidth(10.5);
$spreadsheet->getActiveSheet()->getStyle('D2:D' . $row)->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_YYYYMMDD2); $spreadsheet->getActiveSheet()->getStyle('D2:D' . $row)->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_DATE_YYYYMMDD2);
$spreadsheet->getActiveSheet()->getStyle('E2:F' . $row)->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_CURRENCY_USD_SIMPLE); $spreadsheet->getActiveSheet()->getStyle('E2:F' . $row)->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_CURRENCY_USD_SIMPLE);
$spreadsheet->getActiveSheet()->getColumnDimension('F')->setWidth(14); $spreadsheet->getActiveSheet()->getColumnDimension('F')->setWidth(14);
$spreadsheet->getActiveSheet()->freezePane('A2'); $spreadsheet->getActiveSheet()->freezePane('A2');
@ -104,39 +110,39 @@ $helper->log('Set active filters');
// Filter the Country column on a filter value of Germany // Filter the Country column on a filter value of Germany
// As it's just a simple value filter, we can use FILTERTYPE_FILTER // As it's just a simple value filter, we can use FILTERTYPE_FILTER
$autoFilter->getColumn('C') $autoFilter->getColumn('C')
->setFilterType(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column::AUTOFILTER_FILTERTYPE_FILTER) ->setFilterType(Column::AUTOFILTER_FILTERTYPE_FILTER)
->createRule() ->createRule()
->setRule( ->setRule(
\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_COLUMN_RULE_EQUAL, Rule::AUTOFILTER_COLUMN_RULE_EQUAL,
'Germany' 'Germany'
); );
// Filter the Date column on a filter value of the year to date // Filter the Date column on a filter value of the year to date
$autoFilter->getColumn('D') $autoFilter->getColumn('D')
->setFilterType(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column::AUTOFILTER_FILTERTYPE_DYNAMICFILTER) ->setFilterType(Column::AUTOFILTER_FILTERTYPE_DYNAMICFILTER)
->createRule() ->createRule()
->setRule( ->setRule(
\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_COLUMN_RULE_EQUAL, Rule::AUTOFILTER_COLUMN_RULE_EQUAL,
null, null,
\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_RULETYPE_DYNAMIC_YEARTODATE Rule::AUTOFILTER_RULETYPE_DYNAMIC_YEARTODATE
) )
->setRuleType(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_RULETYPE_DYNAMICFILTER); ->setRuleType(Rule::AUTOFILTER_RULETYPE_DYNAMICFILTER);
// Display only sales values that are between 400 and 600 // Display only sales values that are between 400 and 600
$autoFilter->getColumn('E') $autoFilter->getColumn('E')
->setFilterType(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column::AUTOFILTER_FILTERTYPE_CUSTOMFILTER) ->setFilterType(Column::AUTOFILTER_FILTERTYPE_CUSTOMFILTER)
->createRule() ->createRule()
->setRule( ->setRule(
\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_COLUMN_RULE_GREATERTHANOREQUAL, Rule::AUTOFILTER_COLUMN_RULE_GREATERTHANOREQUAL,
400 400
) )
->setRuleType(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_RULETYPE_CUSTOMFILTER); ->setRuleType(Rule::AUTOFILTER_RULETYPE_CUSTOMFILTER);
$autoFilter->getColumn('E') $autoFilter->getColumn('E')
->setJoin(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column::AUTOFILTER_COLUMN_JOIN_AND) ->setJoin(Column::AUTOFILTER_COLUMN_JOIN_AND)
->createRule() ->createRule()
->setRule( ->setRule(
\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_COLUMN_RULE_LESSTHANOREQUAL, Rule::AUTOFILTER_COLUMN_RULE_LESSTHANOREQUAL,
600 600
) )
->setRuleType(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_RULETYPE_CUSTOMFILTER); ->setRuleType(Rule::AUTOFILTER_RULETYPE_CUSTOMFILTER);
// Save // Save
$helper->write($spreadsheet, __FILE__); $helper->write($spreadsheet, __FILE__);

View File

@ -1,10 +1,16 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Shared\Date;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column;
use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.php';
// Create new Spreadsheet object // Create new Spreadsheet object
$helper->log('Create new Spreadsheet object'); $helper->log('Create new Spreadsheet object');
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $spreadsheet = new Spreadsheet();
// Set document properties // Set document properties
$helper->log('Set document properties'); $helper->log('Set document properties');
@ -48,7 +54,7 @@ foreach ($years as $year) {
foreach ($countries as $country) { foreach ($countries as $country) {
$endDays = date('t', mktime(0, 0, 0, $period, 1, $year)); $endDays = date('t', mktime(0, 0, 0, $period, 1, $year));
for ($i = 1; $i <= $endDays; ++$i) { for ($i = 1; $i <= $endDays; ++$i) {
$eDate = \PhpOffice\PhpSpreadsheet\Shared\Date::formattedPHPToExcel( $eDate = Date::formattedPHPToExcel(
$year, $year,
$period, $period,
$i $i
@ -86,8 +92,8 @@ $spreadsheet->getActiveSheet()->getStyle('A1:F1')->getFont()->setBold(true);
$spreadsheet->getActiveSheet()->getStyle('A1:F1')->getAlignment()->setWrapText(true); $spreadsheet->getActiveSheet()->getStyle('A1:F1')->getAlignment()->setWrapText(true);
$spreadsheet->getActiveSheet()->getColumnDimension('C')->setWidth(12.5); $spreadsheet->getActiveSheet()->getColumnDimension('C')->setWidth(12.5);
$spreadsheet->getActiveSheet()->getColumnDimension('D')->setWidth(10.5); $spreadsheet->getActiveSheet()->getColumnDimension('D')->setWidth(10.5);
$spreadsheet->getActiveSheet()->getStyle('D2:D' . $row)->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_YYYYMMDD2); $spreadsheet->getActiveSheet()->getStyle('D2:D' . $row)->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_DATE_YYYYMMDD2);
$spreadsheet->getActiveSheet()->getStyle('E2:F' . $row)->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_CURRENCY_USD_SIMPLE); $spreadsheet->getActiveSheet()->getStyle('E2:F' . $row)->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_CURRENCY_USD_SIMPLE);
$spreadsheet->getActiveSheet()->getColumnDimension('F')->setWidth(14); $spreadsheet->getActiveSheet()->getColumnDimension('F')->setWidth(14);
$spreadsheet->getActiveSheet()->freezePane('A2'); $spreadsheet->getActiveSheet()->freezePane('A2');
@ -104,45 +110,45 @@ $helper->log('Set active filters');
// Filter the Country column on a filter value of countries beginning with the letter U (or Japan) // Filter the Country column on a filter value of countries beginning with the letter U (or Japan)
// We use * as a wildcard, so specify as U* and using a wildcard requires customFilter // We use * as a wildcard, so specify as U* and using a wildcard requires customFilter
$autoFilter->getColumn('C') $autoFilter->getColumn('C')
->setFilterType(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column::AUTOFILTER_FILTERTYPE_CUSTOMFILTER) ->setFilterType(Column::AUTOFILTER_FILTERTYPE_CUSTOMFILTER)
->createRule() ->createRule()
->setRule( ->setRule(
\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_COLUMN_RULE_EQUAL, Rule::AUTOFILTER_COLUMN_RULE_EQUAL,
'u*' 'u*'
) )
->setRuleType(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_RULETYPE_CUSTOMFILTER); ->setRuleType(Rule::AUTOFILTER_RULETYPE_CUSTOMFILTER);
$autoFilter->getColumn('C') $autoFilter->getColumn('C')
->createRule() ->createRule()
->setRule( ->setRule(
\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_COLUMN_RULE_EQUAL, Rule::AUTOFILTER_COLUMN_RULE_EQUAL,
'japan' 'japan'
) )
->setRuleType(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_RULETYPE_CUSTOMFILTER); ->setRuleType(Rule::AUTOFILTER_RULETYPE_CUSTOMFILTER);
// Filter the Date column on a filter value of the first day of every period of the current year // Filter the Date column on a filter value of the first day of every period of the current year
// We us a dateGroup ruletype for this, although it is still a standard filter // We us a dateGroup ruletype for this, although it is still a standard filter
foreach ($periods as $period) { foreach ($periods as $period) {
$endDate = date('t', mktime(0, 0, 0, $period, 1, $currentYear)); $endDate = date('t', mktime(0, 0, 0, $period, 1, $currentYear));
$autoFilter->getColumn('D') $autoFilter->getColumn('D')
->setFilterType(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column::AUTOFILTER_FILTERTYPE_FILTER) ->setFilterType(Column::AUTOFILTER_FILTERTYPE_FILTER)
->createRule() ->createRule()
->setRule( ->setRule(
\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_COLUMN_RULE_EQUAL, Rule::AUTOFILTER_COLUMN_RULE_EQUAL,
[ [
'year' => $currentYear, 'year' => $currentYear,
'month' => $period, 'month' => $period,
'day' => $endDate, 'day' => $endDate,
] ]
) )
->setRuleType(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_RULETYPE_DATEGROUP); ->setRuleType(Rule::AUTOFILTER_RULETYPE_DATEGROUP);
} }
// Display only sales values that are blank // Display only sales values that are blank
// Standard filter, operator equals, and value of NULL // Standard filter, operator equals, and value of NULL
$autoFilter->getColumn('E') $autoFilter->getColumn('E')
->setFilterType(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column::AUTOFILTER_FILTERTYPE_FILTER) ->setFilterType(Column::AUTOFILTER_FILTERTYPE_FILTER)
->createRule() ->createRule()
->setRule( ->setRule(
\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_COLUMN_RULE_EQUAL, Rule::AUTOFILTER_COLUMN_RULE_EQUAL,
'' ''
); );

View File

@ -1,10 +1,12 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.php';
// Create new Spreadsheet object // Create new Spreadsheet object
$helper->log('Create new Spreadsheet object'); $helper->log('Create new Spreadsheet object');
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $spreadsheet = new Spreadsheet();
// Set document properties // Set document properties
$helper->log('Set document properties'); $helper->log('Set document properties');

View File

@ -1,10 +1,13 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Style\Protection;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.php';
// Create new Spreadsheet object // Create new Spreadsheet object
$helper->log('Create new Spreadsheet object'); $helper->log('Create new Spreadsheet object');
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $spreadsheet = new Spreadsheet();
// Set document properties // Set document properties
$helper->log('Set document properties'); $helper->log('Set document properties');
@ -37,7 +40,7 @@ $spreadsheet->getActiveSheet()->getProtection()->setSheet(true);
$spreadsheet->getActiveSheet() $spreadsheet->getActiveSheet()
->getStyle('A2:B2') ->getStyle('A2:B2')
->getProtection()->setLocked( ->getProtection()->setLocked(
\PhpOffice\PhpSpreadsheet\Style\Protection::PROTECTION_UNPROTECTED Protection::PROTECTION_UNPROTECTED
); );
// Save // Save

View File

@ -1,17 +1,20 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Calculation;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
mt_srand(1234567890); mt_srand(1234567890);
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.php';
// List functions // List functions
$helper->log('List implemented functions'); $helper->log('List implemented functions');
$calc = \PhpOffice\PhpSpreadsheet\Calculation::getInstance(); $calc = Calculation::getInstance();
print_r($calc->getImplementedFunctionNames()); print_r($calc->getImplementedFunctionNames());
// Create new Spreadsheet object // Create new Spreadsheet object
$helper->log('Create new Spreadsheet object'); $helper->log('Create new Spreadsheet object');
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $spreadsheet = new Spreadsheet();
// Add some data, we will use some formulas here // Add some data, we will use some formulas here
$helper->log('Add some data and formulas'); $helper->log('Add some data and formulas');

View File

@ -1,10 +1,13 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Calculation;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.php';
// Create new Spreadsheet object // Create new Spreadsheet object
$helper->log('Create new Spreadsheet object'); $helper->log('Create new Spreadsheet object');
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $spreadsheet = new Spreadsheet();
// Add some data, we will use some formulas here // Add some data, we will use some formulas here
$helper->log('Add some data and formulas'); $helper->log('Add some data and formulas');
@ -13,7 +16,7 @@ $spreadsheet->getActiveSheet()->setCellValue('A1', '=B1')
->setCellValue('B1', '=A1+1') ->setCellValue('B1', '=A1+1')
->setCellValue('B2', '=A2'); ->setCellValue('B2', '=A2');
\PhpOffice\PhpSpreadsheet\Calculation::getInstance($spreadsheet)->cyclicFormulaCount = 100; Calculation::getInstance($spreadsheet)->cyclicFormulaCount = 100;
// Calculated data // Calculated data
$helper->log('Calculated data'); $helper->log('Calculated data');

View File

@ -1,10 +1,12 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\IOFactory;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.php';
$spreadsheet = require __DIR__ . '/templates/sampleSpreadsheet.php'; $spreadsheet = require __DIR__ . '/templates/sampleSpreadsheet.php';
$filename = $helper->getFilename(__FILE__, 'xls'); $filename = $helper->getFilename(__FILE__, 'xls');
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xls'); $writer = IOFactory::createWriter($spreadsheet, 'Xls');
$callStartTime = microtime(true); $callStartTime = microtime(true);
$writer->save($filename); $writer->save($filename);

View File

@ -1,10 +1,13 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Cell\DataValidation;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.php';
// Create new Spreadsheet object // Create new Spreadsheet object
$helper->log('Create new Spreadsheet object'); $helper->log('Create new Spreadsheet object');
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $spreadsheet = new Spreadsheet();
// Set document properties // Set document properties
$helper->log('Set document properties'); $helper->log('Set document properties');
@ -35,8 +38,8 @@ $spreadsheet->getActiveSheet()->setCellValue('A1', 'Cell B3 and B5 contain data
// Set data validation // Set data validation
$helper->log('Set data validation'); $helper->log('Set data validation');
$validation = $spreadsheet->getActiveSheet()->getCell('B3')->getDataValidation(); $validation = $spreadsheet->getActiveSheet()->getCell('B3')->getDataValidation();
$validation->setType(\PhpOffice\PhpSpreadsheet\Cell\DataValidation::TYPE_WHOLE); $validation->setType(DataValidation::TYPE_WHOLE);
$validation->setErrorStyle(\PhpOffice\PhpSpreadsheet\Cell\DataValidation::STYLE_STOP); $validation->setErrorStyle(DataValidation::STYLE_STOP);
$validation->setAllowBlank(true); $validation->setAllowBlank(true);
$validation->setShowInputMessage(true); $validation->setShowInputMessage(true);
$validation->setShowErrorMessage(true); $validation->setShowErrorMessage(true);
@ -48,8 +51,8 @@ $validation->setFormula1(10);
$validation->setFormula2(20); $validation->setFormula2(20);
$validation = $spreadsheet->getActiveSheet()->getCell('B5')->getDataValidation(); $validation = $spreadsheet->getActiveSheet()->getCell('B5')->getDataValidation();
$validation->setType(\PhpOffice\PhpSpreadsheet\Cell\DataValidation::TYPE_LIST); $validation->setType(DataValidation::TYPE_LIST);
$validation->setErrorStyle(\PhpOffice\PhpSpreadsheet\Cell\DataValidation::STYLE_INFORMATION); $validation->setErrorStyle(DataValidation::STYLE_INFORMATION);
$validation->setAllowBlank(false); $validation->setAllowBlank(false);
$validation->setShowInputMessage(true); $validation->setShowInputMessage(true);
$validation->setShowErrorMessage(true); $validation->setShowErrorMessage(true);
@ -61,8 +64,8 @@ $validation->setPrompt('Please pick a value from the drop-down list.');
$validation->setFormula1('"Item A,Item B,Item C"'); // Make sure to put the list items between " and " if your list is simply a comma-separated list of values !!! $validation->setFormula1('"Item A,Item B,Item C"'); // Make sure to put the list items between " and " if your list is simply a comma-separated list of values !!!
$validation = $spreadsheet->getActiveSheet()->getCell('B7')->getDataValidation(); $validation = $spreadsheet->getActiveSheet()->getCell('B7')->getDataValidation();
$validation->setType(\PhpOffice\PhpSpreadsheet\Cell\DataValidation::TYPE_LIST); $validation->setType(DataValidation::TYPE_LIST);
$validation->setErrorStyle(\PhpOffice\PhpSpreadsheet\Cell\DataValidation::STYLE_INFORMATION); $validation->setErrorStyle(DataValidation::STYLE_INFORMATION);
$validation->setAllowBlank(false); $validation->setAllowBlank(false);
$validation->setShowInputMessage(true); $validation->setShowInputMessage(true);
$validation->setShowErrorMessage(true); $validation->setShowErrorMessage(true);

View File

@ -1,10 +1,12 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\IOFactory;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.php';
$spreadsheet = require __DIR__ . '/templates/sampleSpreadsheet.php'; $spreadsheet = require __DIR__ . '/templates/sampleSpreadsheet.php';
$helper->log('Write to CSV format'); $helper->log('Write to CSV format');
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Csv')->setDelimiter(',') $writer = IOFactory::createWriter($spreadsheet, 'Csv')->setDelimiter(',')
->setEnclosure('"') ->setEnclosure('"')
->setSheetIndex(0); ->setSheetIndex(0);
@ -15,7 +17,7 @@ $helper->logWrite($writer, $filename, $callStartTime);
$helper->log('Read from CSV format'); $helper->log('Read from CSV format');
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Csv')->setDelimiter(',') $reader = IOFactory::createReader('Csv')->setDelimiter(',')
->setEnclosure('"') ->setEnclosure('"')
->setSheetIndex(0); ->setSheetIndex(0);
@ -28,7 +30,7 @@ $helper->write($spreadsheetFromCSV, __FILE__, ['Xlsx']);
// Write CSV // Write CSV
$filenameCSV = $helper->getFilename(__FILE__, 'csv'); $filenameCSV = $helper->getFilename(__FILE__, 'csv');
$writerCSV = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheetFromCSV, 'Csv'); $writerCSV = IOFactory::createWriter($spreadsheetFromCSV, 'Csv');
$writerCSV->setExcelCompatibility(true); $writerCSV->setExcelCompatibility(true);
$callStartTime = microtime(true); $callStartTime = microtime(true);

View File

@ -1,10 +1,12 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\IOFactory;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.php';
$spreadsheet = require __DIR__ . '/templates/sampleSpreadsheet.php'; $spreadsheet = require __DIR__ . '/templates/sampleSpreadsheet.php';
$filename = $helper->getFilename(__FILE__, 'html'); $filename = $helper->getFilename(__FILE__, 'html');
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Html'); $writer = IOFactory::createWriter($spreadsheet, 'Html');
$callStartTime = microtime(true); $callStartTime = microtime(true);
$writer->save($filename); $writer->save($filename);

View File

@ -1,16 +1,18 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Calculation;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.php';
// List functions // List functions
$helper->log('List implemented functions'); $helper->log('List implemented functions');
$calc = \PhpOffice\PhpSpreadsheet\Calculation::getInstance(); $calc = Calculation::getInstance();
print_r($calc->getImplementedFunctionNames()); print_r($calc->getImplementedFunctionNames());
// Create new Spreadsheet object // Create new Spreadsheet object
$helper->log('Create new Spreadsheet object'); $helper->log('Create new Spreadsheet object');
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $spreadsheet = new Spreadsheet();
// Add some data, we will use some formulas here // Add some data, we will use some formulas here
$helper->log('Add some data'); $helper->log('Add some data');

View File

@ -1,10 +1,13 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\NamedRange;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.php';
// Create new Spreadsheet object // Create new Spreadsheet object
$helper->log('Create new Spreadsheet object'); $helper->log('Create new Spreadsheet object');
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $spreadsheet = new Spreadsheet();
// Set document properties // Set document properties
$helper->log('Set document properties'); $helper->log('Set document properties');
@ -28,8 +31,8 @@ $spreadsheet->getActiveSheet()->setCellValue('A1', 'Firstname:')
// Define named ranges // Define named ranges
$helper->log('Define named ranges'); $helper->log('Define named ranges');
$spreadsheet->addNamedRange(new \PhpOffice\PhpSpreadsheet\NamedRange('PersonName', $spreadsheet->getActiveSheet(), 'B1')); $spreadsheet->addNamedRange(new NamedRange('PersonName', $spreadsheet->getActiveSheet(), 'B1'));
$spreadsheet->addNamedRange(new \PhpOffice\PhpSpreadsheet\NamedRange('PersonLN', $spreadsheet->getActiveSheet(), 'B2')); $spreadsheet->addNamedRange(new NamedRange('PersonLN', $spreadsheet->getActiveSheet(), 'B2'));
// Rename named ranges // Rename named ranges
$helper->log('Rename named ranges'); $helper->log('Rename named ranges');

View File

@ -1,10 +1,12 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\IOFactory;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.php';
$filename = __DIR__ . '/templates/Excel2003XMLTest.xml'; $filename = __DIR__ . '/templates/Excel2003XMLTest.xml';
$callStartTime = microtime(true); $callStartTime = microtime(true);
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($filename); $spreadsheet = IOFactory::load($filename);
$helper->logRead('Xml', $filename, $callStartTime); $helper->logRead('Xml', $filename, $callStartTime);
// Save // Save

View File

@ -1,10 +1,12 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\IOFactory;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.php';
$filename = __DIR__ . '/templates/GnumericTest.gnumeric'; $filename = __DIR__ . '/templates/GnumericTest.gnumeric';
$callStartTime = microtime(true); $callStartTime = microtime(true);
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($filename); $spreadsheet = IOFactory::load($filename);
$helper->logRead('Gnumeric', $filename, $callStartTime); $helper->logRead('Gnumeric', $filename, $callStartTime);
// Save // Save

View File

@ -1,10 +1,12 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\IOFactory;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.php';
$filename = __DIR__ . '/templates/OOCalcTest.ods'; $filename = __DIR__ . '/templates/OOCalcTest.ods';
$callStartTime = microtime(true); $callStartTime = microtime(true);
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($filename); $spreadsheet = IOFactory::load($filename);
$helper->logRead('Ods', $filename, $callStartTime); $helper->logRead('Ods', $filename, $callStartTime);
// Save // Save

View File

@ -1,10 +1,12 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\IOFactory;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.php';
$filename = __DIR__ . '/templates/SylkTest.slk'; $filename = __DIR__ . '/templates/SylkTest.slk';
$callStartTime = microtime(true); $callStartTime = microtime(true);
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($filename); $spreadsheet = IOFactory::load($filename);
$helper->logRead('Slk', $filename, $callStartTime); $helper->logRead('Slk', $filename, $callStartTime);
// Save // Save

View File

@ -1,19 +1,21 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\IOFactory;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.php';
$spreadsheet = require __DIR__ . '/templates/sampleSpreadsheet.php'; $spreadsheet = require __DIR__ . '/templates/sampleSpreadsheet.php';
// Write temporary file // Write temporary file
$filename = $helper->getTemporaryFilename('xls'); $filename = $helper->getTemporaryFilename('xls');
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xls'); $writer = IOFactory::createWriter($spreadsheet, 'Xls');
$callStartTime = microtime(true); $callStartTime = microtime(true);
$writer->save($filename); $writer->save($filename);
$helper->logWrite($writer, $filename, $callStartTime); $helper->logWrite($writer, $filename, $callStartTime);
// Read Xls file // Read Xls file
$callStartTime = microtime(true); $callStartTime = microtime(true);
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($filename); $spreadsheet = IOFactory::load($filename);
$helper->logRead('Xls', $filename, $callStartTime); $helper->logRead('Xls', $filename, $callStartTime);
// Save // Save

View File

@ -1,5 +1,8 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Settings;
use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.php';
$spreadsheet = require __DIR__ . '/templates/sampleSpreadsheet.php'; $spreadsheet = require __DIR__ . '/templates/sampleSpreadsheet.php';
@ -7,11 +10,11 @@ $helper->log('Hide grid lines');
$spreadsheet->getActiveSheet()->setShowGridLines(false); $spreadsheet->getActiveSheet()->setShowGridLines(false);
$helper->log('Set orientation to landscape'); $helper->log('Set orientation to landscape');
$spreadsheet->getActiveSheet()->getPageSetup()->setOrientation(\PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_LANDSCAPE); $spreadsheet->getActiveSheet()->getPageSetup()->setOrientation(PageSetup::ORIENTATION_LANDSCAPE);
$rendererName = \PhpOffice\PhpSpreadsheet\Settings::PDF_RENDERER_DOMPDF; $rendererName = Settings::PDF_RENDERER_DOMPDF;
$helper->log("Write to PDF format using {$rendererName}"); $helper->log("Write to PDF format using {$rendererName}");
\PhpOffice\PhpSpreadsheet\Settings::setPdfRendererName($rendererName); Settings::setPdfRendererName($rendererName);
// Save // Save
$helper->write($spreadsheet, __FILE__, ['Pdf']); $helper->write($spreadsheet, __FILE__, ['Pdf']);

View File

@ -1,5 +1,8 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Settings;
use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.php';
$spreadsheet = require __DIR__ . '/templates/sampleSpreadsheet.php'; $spreadsheet = require __DIR__ . '/templates/sampleSpreadsheet.php';
@ -7,11 +10,11 @@ $helper->log('Hide grid lines');
$spreadsheet->getActiveSheet()->setShowGridLines(false); $spreadsheet->getActiveSheet()->setShowGridLines(false);
$helper->log('Set orientation to landscape'); $helper->log('Set orientation to landscape');
$spreadsheet->getActiveSheet()->getPageSetup()->setOrientation(\PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_LANDSCAPE); $spreadsheet->getActiveSheet()->getPageSetup()->setOrientation(PageSetup::ORIENTATION_LANDSCAPE);
$rendererName = \PhpOffice\PhpSpreadsheet\Settings::PDF_RENDERER_TCPDF; $rendererName = Settings::PDF_RENDERER_TCPDF;
$helper->log("Write to PDF format using {$rendererName}"); $helper->log("Write to PDF format using {$rendererName}");
\PhpOffice\PhpSpreadsheet\Settings::setPdfRendererName($rendererName); Settings::setPdfRendererName($rendererName);
// Save // Save
$helper->write($spreadsheet, __FILE__, ['Pdf']); $helper->write($spreadsheet, __FILE__, ['Pdf']);

View File

@ -1,5 +1,8 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Settings;
use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.php';
$spreadsheet = require __DIR__ . '/templates/sampleSpreadsheet.php'; $spreadsheet = require __DIR__ . '/templates/sampleSpreadsheet.php';
@ -7,11 +10,11 @@ $helper->log('Hide grid lines');
$spreadsheet->getActiveSheet()->setShowGridLines(false); $spreadsheet->getActiveSheet()->setShowGridLines(false);
$helper->log('Set orientation to landscape'); $helper->log('Set orientation to landscape');
$spreadsheet->getActiveSheet()->getPageSetup()->setOrientation(\PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_LANDSCAPE); $spreadsheet->getActiveSheet()->getPageSetup()->setOrientation(PageSetup::ORIENTATION_LANDSCAPE);
$rendererName = \PhpOffice\PhpSpreadsheet\Settings::PDF_RENDERER_MPDF; $rendererName = Settings::PDF_RENDERER_MPDF;
$helper->log("Write to PDF format using {$rendererName}"); $helper->log("Write to PDF format using {$rendererName}");
\PhpOffice\PhpSpreadsheet\Settings::setPdfRendererName($rendererName); Settings::setPdfRendererName($rendererName);
// Save // Save
$helper->write($spreadsheet, __FILE__, ['Pdf']); $helper->write($spreadsheet, __FILE__, ['Pdf']);

View File

@ -1,10 +1,14 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Style\Border;
use PhpOffice\PhpSpreadsheet\Style\Fill;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.php';
// Create new Spreadsheet object // Create new Spreadsheet object
$helper->log('Create new Spreadsheet object'); $helper->log('Create new Spreadsheet object');
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $spreadsheet = new Spreadsheet();
// Set document properties // Set document properties
$helper->log('Set document properties'); $helper->log('Set document properties');
@ -22,19 +26,19 @@ $spreadsheet->setActiveSheetIndex(0);
$spreadsheet->getActiveSheet()->getStyle('A1:T100')->applyFromArray( $spreadsheet->getActiveSheet()->getStyle('A1:T100')->applyFromArray(
['fill' => [ ['fill' => [
'type' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID, 'type' => Fill::FILL_SOLID,
'color' => ['argb' => 'FFCCFFCC'], 'color' => ['argb' => 'FFCCFFCC'],
], ],
'borders' => [ 'borders' => [
'bottom' => ['style' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN], 'bottom' => ['style' => Border::BORDER_THIN],
'right' => ['style' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUM], 'right' => ['style' => Border::BORDER_MEDIUM],
], ],
] ]
); );
$spreadsheet->getActiveSheet()->getStyle('C5:R95')->applyFromArray( $spreadsheet->getActiveSheet()->getStyle('C5:R95')->applyFromArray(
['fill' => [ ['fill' => [
'type' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID, 'type' => Fill::FILL_SOLID,
'color' => ['argb' => 'FFFFFF00'], 'color' => ['argb' => 'FFFFFF00'],
], ],
] ]

View File

@ -1,10 +1,15 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Style;
use PhpOffice\PhpSpreadsheet\Style\Border;
use PhpOffice\PhpSpreadsheet\Style\Fill;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.php';
// Create new Spreadsheet object // Create new Spreadsheet object
$helper->log('Create new Spreadsheet object'); $helper->log('Create new Spreadsheet object');
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $spreadsheet = new Spreadsheet();
// Set document properties // Set document properties
$helper->log('Set document properties'); $helper->log('Set document properties');
@ -20,29 +25,29 @@ $spreadsheet->getProperties()->setCreator('Maarten Balliauw')
$helper->log('Add some data'); $helper->log('Add some data');
$spreadsheet->setActiveSheetIndex(0); $spreadsheet->setActiveSheetIndex(0);
$sharedStyle1 = new \PhpOffice\PhpSpreadsheet\Style(); $sharedStyle1 = new Style();
$sharedStyle2 = new \PhpOffice\PhpSpreadsheet\Style(); $sharedStyle2 = new Style();
$sharedStyle1->applyFromArray( $sharedStyle1->applyFromArray(
['fill' => [ ['fill' => [
'type' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID, 'type' => Fill::FILL_SOLID,
'color' => ['argb' => 'FFCCFFCC'], 'color' => ['argb' => 'FFCCFFCC'],
], ],
'borders' => [ 'borders' => [
'bottom' => ['style' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN], 'bottom' => ['style' => Border::BORDER_THIN],
'right' => ['style' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUM], 'right' => ['style' => Border::BORDER_MEDIUM],
], ],
] ]
); );
$sharedStyle2->applyFromArray( $sharedStyle2->applyFromArray(
['fill' => [ ['fill' => [
'type' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID, 'type' => Fill::FILL_SOLID,
'color' => ['argb' => 'FFFFFF00'], 'color' => ['argb' => 'FFFFFF00'],
], ],
'borders' => [ 'borders' => [
'bottom' => ['style' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN], 'bottom' => ['style' => Border::BORDER_THIN],
'right' => ['style' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUM], 'right' => ['style' => Border::BORDER_MEDIUM],
], ],
] ]
); );

View File

@ -2,17 +2,20 @@
namespace PhpOffice\PhpSpreadsheet; namespace PhpOffice\PhpSpreadsheet;
use PhpOffice\PhpSpreadsheet\Reader\IReadFilter;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.php';
// Write temporary file // Write temporary file
$largeSpreadsheet = require __DIR__ . '/templates/largeSpreadsheet.php'; $largeSpreadsheet = require __DIR__ . '/templates/largeSpreadsheet.php';
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($largeSpreadsheet); $writer = new Xlsx($largeSpreadsheet);
$filename = $helper->getTemporaryFilename(); $filename = $helper->getTemporaryFilename();
$callStartTime = microtime(true); $callStartTime = microtime(true);
$writer->save($filename); $writer->save($filename);
$helper->logWrite($writer, $filename, $callStartTime); $helper->logWrite($writer, $filename, $callStartTime);
class MyReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter class MyReadFilter implements IReadFilter
{ {
public function readCell($column, $row, $worksheetName = '') public function readCell($column, $row, $worksheetName = '')
{ {
@ -26,7 +29,7 @@ class MyReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter
} }
$helper->log('Load from Xlsx file'); $helper->log('Load from Xlsx file');
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xlsx'); $reader = IOFactory::createReader('Xlsx');
$reader->setReadFilter(new MyReadFilter()); $reader->setReadFilter(new MyReadFilter());
$callStartTime = microtime(true); $callStartTime = microtime(true);
$spreadsheet = $reader->load($filename); $spreadsheet = $reader->load($filename);

View File

@ -1,10 +1,13 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.php';
// Create new Spreadsheet object // Create new Spreadsheet object
$helper->log('Create new Spreadsheet object'); $helper->log('Create new Spreadsheet object');
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $spreadsheet = new Spreadsheet();
// Set document properties // Set document properties
$helper->log('Set document properties'); $helper->log('Set document properties');
@ -24,12 +27,12 @@ imagestring($gdImage, 1, 5, 5, 'Created with PhpSpreadsheet', $textColor);
// Add a drawing to the worksheet // Add a drawing to the worksheet
$helper->log('Add a drawing to the worksheet'); $helper->log('Add a drawing to the worksheet');
$drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing(); $drawing = new MemoryDrawing();
$drawing->setName('Sample image'); $drawing->setName('Sample image');
$drawing->setDescription('Sample image'); $drawing->setDescription('Sample image');
$drawing->setImageResource($gdImage); $drawing->setImageResource($gdImage);
$drawing->setRenderingFunction(\PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing::RENDERING_JPEG); $drawing->setRenderingFunction(MemoryDrawing::RENDERING_JPEG);
$drawing->setMimeType(\PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing::MIMETYPE_DEFAULT); $drawing->setMimeType(MemoryDrawing::MIMETYPE_DEFAULT);
$drawing->setHeight(36); $drawing->setHeight(36);
$drawing->setWorksheet($spreadsheet->getActiveSheet()); $drawing->setWorksheet($spreadsheet->getActiveSheet());

View File

@ -1,16 +1,19 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Settings;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.php';
// Change these values to select the PDF Rendering library that you wish to use // Change these values to select the PDF Rendering library that you wish to use
// and its directory location on your server // and its directory location on your server
//$rendererName = \PhpOffice\PhpSpreadsheet\Settings::PDF_RENDERER_TCPDF; //$rendererName = \PhpOffice\PhpSpreadsheet\Settings::PDF_RENDERER_TCPDF;
//$rendererName = \PhpOffice\PhpSpreadsheet\Settings::PDF_RENDERER_MPDF; //$rendererName = \PhpOffice\PhpSpreadsheet\Settings::PDF_RENDERER_MPDF;
$rendererName = \PhpOffice\PhpSpreadsheet\Settings::PDF_RENDERER_DOMPDF; $rendererName = Settings::PDF_RENDERER_DOMPDF;
// Read from Xlsx (.xlsx) template // Read from Xlsx (.xlsx) template
$helper->log('Load Xlsx template file'); $helper->log('Load Xlsx template file');
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xlsx'); $reader = IOFactory::createReader('Xlsx');
$spreadsheet = $reader->load(__DIR__ . '/templates/26template.xlsx'); $spreadsheet = $reader->load(__DIR__ . '/templates/26template.xlsx');
/* at this point, we could do some manipulations with the template, but we skip this step */ /* at this point, we could do some manipulations with the template, but we skip this step */
@ -18,7 +21,7 @@ $helper->write($spreadsheet, __FILE__, ['Xlsx', 'Xls', 'Html']);
// Export to PDF (.pdf) // Export to PDF (.pdf)
$helper->log('Write to PDF format'); $helper->log('Write to PDF format');
\PhpOffice\PhpSpreadsheet\Settings::setPdfRendererName($rendererName); Settings::setPdfRendererName($rendererName);
$helper->write($spreadsheet, __FILE__, ['Pdf']); $helper->write($spreadsheet, __FILE__, ['Pdf']);
// Remove first two rows with field headers before exporting to CSV // Remove first two rows with field headers before exporting to CSV
@ -28,7 +31,7 @@ $worksheet->removeRow(1, 2);
// Export to CSV (.csv) // Export to CSV (.csv)
$helper->log('Write to CSV format'); $helper->log('Write to CSV format');
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Csv'); $writer = IOFactory::createWriter($spreadsheet, 'Csv');
$filename = $helper->getFilename(__FILE__, 'csv'); $filename = $helper->getFilename(__FILE__, 'csv');
$callStartTime = microtime(true); $callStartTime = microtime(true);
$writer->save($filename); $writer->save($filename);

View File

@ -1,10 +1,12 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\IOFactory;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.php';
// Read from Xls (.xls) template // Read from Xls (.xls) template
$helper->log('Load Xlsx template file'); $helper->log('Load Xlsx template file');
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xls'); $reader = IOFactory::createReader('Xls');
$spreadsheet = $reader->load(__DIR__ . '/templates/27template.xls'); $spreadsheet = $reader->load(__DIR__ . '/templates/27template.xls');
// Save // Save

View File

@ -1,16 +1,19 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.php';
$sampleSpreadsheet = require __DIR__ . '/templates/sampleSpreadsheet.php'; $sampleSpreadsheet = require __DIR__ . '/templates/sampleSpreadsheet.php';
$filename = $helper->getTemporaryFilename(); $filename = $helper->getTemporaryFilename();
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($sampleSpreadsheet); $writer = new Xlsx($sampleSpreadsheet);
$callStartTime = microtime(true); $callStartTime = microtime(true);
$writer->save($filename); $writer->save($filename);
$helper->logWrite($writer, $filename, $callStartTime); $helper->logWrite($writer, $filename, $callStartTime);
$callStartTime = microtime(true); $callStartTime = microtime(true);
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xlsx'); $reader = IOFactory::createReader('Xlsx');
$spreadsheet = $reader->load($filename); $spreadsheet = $reader->load($filename);
$helper->logRead('Xlsx', $filename, $callStartTime); $helper->logRead('Xlsx', $filename, $callStartTime);
$helper->log('Iterate worksheets'); $helper->log('Iterate worksheets');

View File

@ -1,5 +1,7 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Cell;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.php';
@ -9,11 +11,11 @@ date_default_timezone_set('UTC');
// Set value binder // Set value binder
$helper->log('Set value binder'); $helper->log('Set value binder');
\PhpOffice\PhpSpreadsheet\Cell::setValueBinder(new \PhpOffice\PhpSpreadsheet\Cell\AdvancedValueBinder()); Cell::setValueBinder(new Cell\AdvancedValueBinder());
// Create new Spreadsheet object // Create new Spreadsheet object
$helper->log('Create new Spreadsheet object'); $helper->log('Create new Spreadsheet object');
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $spreadsheet = new Spreadsheet();
// Set document properties // Set document properties
$helper->log('Set document properties'); $helper->log('Set document properties');

View File

@ -1,9 +1,12 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Shared\Date;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.php';
$helper->log('Load from Xls template'); $helper->log('Load from Xls template');
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xls'); $reader = IOFactory::createReader('Xls');
$spreadsheet = $reader->load(__DIR__ . '/templates/30template.xls'); $spreadsheet = $reader->load(__DIR__ . '/templates/30template.xls');
$helper->log('Add new data to the template'); $helper->log('Add new data to the template');
@ -21,7 +24,7 @@ $data = [['title' => 'Excel for dummies',
], ],
]; ];
$spreadsheet->getActiveSheet()->setCellValue('D1', \PhpOffice\PhpSpreadsheet\Shared\Date::PHPToExcel(time())); $spreadsheet->getActiveSheet()->setCellValue('D1', Date::PHPToExcel(time()));
$baseRow = 5; $baseRow = 5;
foreach ($data as $r => $dataRow) { foreach ($data as $r => $dataRow) {

View File

@ -1,11 +1,14 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Document\Properties;
use PhpOffice\PhpSpreadsheet\IOFactory;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.php';
$inputFileType = 'Xlsx'; $inputFileType = 'Xlsx';
$inputFileName = __DIR__ . '/templates/31docproperties.xlsx'; $inputFileName = __DIR__ . '/templates/31docproperties.xlsx';
$spreadsheetReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); $spreadsheetReader = IOFactory::createReader($inputFileType);
$callStartTime = microtime(true); $callStartTime = microtime(true);
$spreadsheet = $spreadsheetReader->load($inputFileName); $spreadsheet = $spreadsheetReader->load($inputFileName);
$helper->logRead($inputFileType, $inputFileName, $callStartTime); $helper->logRead($inputFileType, $inputFileName, $callStartTime);
@ -18,7 +21,7 @@ $spreadsheet->getProperties()->setTitle('Office 2007 XLSX Test Document')
// Save Excel 2007 file // Save Excel 2007 file
$filename = $helper->getFilename(__FILE__); $filename = $helper->getFilename(__FILE__);
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx'); $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
$callStartTime = microtime(true); $callStartTime = microtime(true);
$writer->save($filename); $writer->save($filename);
$helper->logWrite($writer, $filename, $callStartTime); $helper->logWrite($writer, $filename, $callStartTime);
@ -28,7 +31,7 @@ $helper->logEndingNotes();
// Reread File // Reread File
$helper->log('Reread Xlsx file'); $helper->log('Reread Xlsx file');
$spreadsheetRead = \PhpOffice\PhpSpreadsheet\IOFactory::load($filename); $spreadsheetRead = IOFactory::load($filename);
// Set properties // Set properties
$helper->log('Get properties'); $helper->log('Get properties');
@ -53,9 +56,9 @@ $customProperties = $spreadsheet->getProperties()->getCustomProperties();
foreach ($customProperties as $customProperty) { foreach ($customProperties as $customProperty) {
$propertyValue = $spreadsheet->getProperties()->getCustomPropertyValue($customProperty); $propertyValue = $spreadsheet->getProperties()->getCustomPropertyValue($customProperty);
$propertyType = $spreadsheet->getProperties()->getCustomPropertyType($customProperty); $propertyType = $spreadsheet->getProperties()->getCustomPropertyType($customProperty);
if ($propertyType == \PhpOffice\PhpSpreadsheet\Document\Properties::PROPERTY_TYPE_DATE) { if ($propertyType == Properties::PROPERTY_TYPE_DATE) {
$formattedValue = date('d-M-Y H:i:s', $propertyValue); $formattedValue = date('d-M-Y H:i:s', $propertyValue);
} elseif ($propertyType == \PhpOffice\PhpSpreadsheet\Document\Properties::PROPERTY_TYPE_BOOLEAN) { } elseif ($propertyType == Properties::PROPERTY_TYPE_BOOLEAN) {
$formattedValue = $propertyValue ? 'TRUE' : 'FALSE'; $formattedValue = $propertyValue ? 'TRUE' : 'FALSE';
} else { } else {
$formattedValue = $propertyValue; $formattedValue = $propertyValue;

View File

@ -1,11 +1,14 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Document\Properties;
use PhpOffice\PhpSpreadsheet\IOFactory;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.php';
$inputFileType = 'Xls'; $inputFileType = 'Xls';
$inputFileName = __DIR__ . '/templates/31docproperties.xls'; $inputFileName = __DIR__ . '/templates/31docproperties.xls';
$spreadsheetReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); $spreadsheetReader = IOFactory::createReader($inputFileType);
$callStartTime = microtime(true); $callStartTime = microtime(true);
$spreadsheet = $spreadsheetReader->load($inputFileName); $spreadsheet = $spreadsheetReader->load($inputFileName);
$helper->logRead($inputFileType, $inputFileName, $callStartTime); $helper->logRead($inputFileType, $inputFileName, $callStartTime);
@ -18,7 +21,7 @@ $spreadsheet->getProperties()->setTitle('Office 95 XLS Test Document')
// Save Excel 95 file // Save Excel 95 file
$filename = $helper->getFilename(__FILE__, 'xls'); $filename = $helper->getFilename(__FILE__, 'xls');
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xls'); $writer = IOFactory::createWriter($spreadsheet, 'Xls');
$callStartTime = microtime(true); $callStartTime = microtime(true);
$writer->save($filename); $writer->save($filename);
$helper->logWrite($writer, $filename, $callStartTime); $helper->logWrite($writer, $filename, $callStartTime);
@ -28,7 +31,7 @@ $helper->logEndingNotes();
// Reread File // Reread File
$helper->log('Reread Xls file'); $helper->log('Reread Xls file');
$spreadsheetRead = \PhpOffice\PhpSpreadsheet\IOFactory::load($filename); $spreadsheetRead = IOFactory::load($filename);
// Set properties // Set properties
$helper->log('Get properties'); $helper->log('Get properties');
@ -53,9 +56,9 @@ $customProperties = $spreadsheet->getProperties()->getCustomProperties();
foreach ($customProperties as $customProperty) { foreach ($customProperties as $customProperty) {
$propertyValue = $spreadsheet->getProperties()->getCustomPropertyValue($customProperty); $propertyValue = $spreadsheet->getProperties()->getCustomPropertyValue($customProperty);
$propertyType = $spreadsheet->getProperties()->getCustomPropertyType($customProperty); $propertyType = $spreadsheet->getProperties()->getCustomPropertyType($customProperty);
if ($propertyType == \PhpOffice\PhpSpreadsheet\Document\Properties::PROPERTY_TYPE_DATE) { if ($propertyType == Properties::PROPERTY_TYPE_DATE) {
$formattedValue = date('d-M-Y H:i:s', $propertyValue); $formattedValue = date('d-M-Y H:i:s', $propertyValue);
} elseif ($propertyType == \PhpOffice\PhpSpreadsheet\Document\Properties::PROPERTY_TYPE_BOOLEAN) { } elseif ($propertyType == Properties::PROPERTY_TYPE_BOOLEAN) {
$formattedValue = $propertyValue ? 'TRUE' : 'FALSE'; $formattedValue = $propertyValue ? 'TRUE' : 'FALSE';
} else { } else {
$formattedValue = $propertyValue; $formattedValue = $propertyValue;

View File

@ -1,5 +1,7 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\IOFactory;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.php';
$inputFileType = 'Xlsx'; $inputFileType = 'Xlsx';
@ -20,7 +22,7 @@ foreach ($inputFileNames as $inputFileName) {
$helper->log('File ' . $inputFileNameShort . ' does not exist'); $helper->log('File ' . $inputFileNameShort . ' does not exist');
continue; continue;
} }
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); $reader = IOFactory::createReader($inputFileType);
$reader->setIncludeCharts(true); $reader->setIncludeCharts(true);
$callStartTime = microtime(true); $callStartTime = microtime(true);
$spreadsheet = $reader->load($inputFileName); $spreadsheet = $reader->load($inputFileName);
@ -69,7 +71,7 @@ foreach ($inputFileNames as $inputFileName) {
} }
$outputFileName = $helper->getFilename($inputFileName); $outputFileName = $helper->getFilename($inputFileName);
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx'); $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->setIncludeCharts(true); $writer->setIncludeCharts(true);
$callStartTime = microtime(true); $callStartTime = microtime(true);
$writer->save($outputFileName); $writer->save($outputFileName);

View File

@ -1,14 +1,17 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Settings;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.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 = \PhpOffice\PhpSpreadsheet\Settings::CHART_RENDERER_JPGRAPH; $rendererName = Settings::CHART_RENDERER_JPGRAPH;
$rendererLibrary = 'jpgraph3.5.0b1/src/'; $rendererLibrary = 'jpgraph3.5.0b1/src/';
$rendererLibraryPath = '/php/libraries/Charts/' . $rendererLibrary; $rendererLibraryPath = '/php/libraries/Charts/' . $rendererLibrary;
if (!\PhpOffice\PhpSpreadsheet\Settings::setChartRenderer($rendererName, $rendererLibraryPath)) { if (!Settings::setChartRenderer($rendererName, $rendererLibraryPath)) {
$helper->log('NOTICE: Please set the $rendererName and $rendererLibraryPath values at the top of this script as appropriate for your directory structure'); $helper->log('NOTICE: Please set the $rendererName and $rendererLibraryPath values at the top of this script as appropriate for your directory structure');
return; return;
@ -35,7 +38,7 @@ foreach ($inputFileNames as $inputFileName) {
$helper->log("Load Test from $inputFileType file " . $inputFileNameShort); $helper->log("Load Test from $inputFileType file " . $inputFileNameShort);
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); $reader = IOFactory::createReader($inputFileType);
$reader->setIncludeCharts(true); $reader->setIncludeCharts(true);
$spreadsheet = $reader->load($inputFileName); $spreadsheet = $reader->load($inputFileName);
@ -83,7 +86,7 @@ foreach ($inputFileNames as $inputFileName) {
// Save // Save
$filename = $helper->getFilename($inputFileName); $filename = $helper->getFilename($inputFileName);
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Html'); $writer = IOFactory::createWriter($spreadsheet, 'Html');
$writer->setIncludeCharts(true); $writer->setIncludeCharts(true);
$callStartTime = microtime(true); $callStartTime = microtime(true);
$writer->save($filename); $writer->save($filename);

View File

@ -1,22 +1,25 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Settings;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.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
// for PDF files, and its directory location on your server // for PDF files, and its directory location on your server
//$rendererName = \PhpOffice\PhpSpreadsheet\Settings::PDF_RENDERER_TCPDF; //$rendererName = \PhpOffice\PhpSpreadsheet\Settings::PDF_RENDERER_TCPDF;
$rendererName = \PhpOffice\PhpSpreadsheet\Settings::PDF_RENDERER_MPDF; $rendererName = Settings::PDF_RENDERER_MPDF;
//$rendererName = \PhpOffice\PhpSpreadsheet\Settings::PDF_RENDERER_DOMPDF; //$rendererName = \PhpOffice\PhpSpreadsheet\Settings::PDF_RENDERER_DOMPDF;
\PhpOffice\PhpSpreadsheet\Settings::setPdfRendererName($rendererName); Settings::setPdfRendererName($rendererName);
// 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
// for Chart images, and its directory location on your server // for Chart images, and its directory location on your server
$rendererName = \PhpOffice\PhpSpreadsheet\Settings::CHART_RENDERER_JPGRAPH; $rendererName = Settings::CHART_RENDERER_JPGRAPH;
$rendererLibrary = 'jpgraph3.5.0b1/src/'; $rendererLibrary = 'jpgraph3.5.0b1/src/';
$rendererLibraryPath = '/php/libraries/Charts/' . $rendererLibrary; $rendererLibraryPath = '/php/libraries/Charts/' . $rendererLibrary;
if (!\PhpOffice\PhpSpreadsheet\Settings::setChartRenderer($rendererName, $rendererLibraryPath)) { if (!Settings::setChartRenderer($rendererName, $rendererLibraryPath)) {
$helper->log('NOTICE: Please set the $rendererName and $rendererLibraryPath values at the top of this script as appropriate for your directory structure'); $helper->log('NOTICE: Please set the $rendererName and $rendererLibraryPath values at the top of this script as appropriate for your directory structure');
return; return;
@ -43,7 +46,7 @@ foreach ($inputFileNames as $inputFileName) {
$helper->log("Load Test from $inputFileType file " . $inputFileNameShort); $helper->log("Load Test from $inputFileType file " . $inputFileNameShort);
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); $reader = IOFactory::createReader($inputFileType);
$reader->setIncludeCharts(true); $reader->setIncludeCharts(true);
$spreadsheet = $reader->load($inputFileName); $spreadsheet = $reader->load($inputFileName);
@ -91,7 +94,7 @@ foreach ($inputFileNames as $inputFileName) {
// Save // Save
$filename = $helper->getFilename($inputFileName); $filename = $helper->getFilename($inputFileName);
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Pdf'); $writer = IOFactory::createWriter($spreadsheet, 'Pdf');
$writer->setIncludeCharts(true); $writer->setIncludeCharts(true);
$callStartTime = microtime(true); $callStartTime = microtime(true);
$writer->save($filename); $writer->save($filename);

View File

@ -1,9 +1,17 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Chart;
use PhpOffice\PhpSpreadsheet\Chart\DataSeries;
use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues;
use PhpOffice\PhpSpreadsheet\Chart\Legend;
use PhpOffice\PhpSpreadsheet\Chart\PlotArea;
use PhpOffice\PhpSpreadsheet\Chart\Title;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.php';
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet(); $worksheet = $spreadsheet->getActiveSheet();
$worksheet->fromArray( $worksheet->fromArray(
[ [
@ -23,9 +31,9 @@ $worksheet->fromArray(
// Data values // Data values
// Data Marker // Data Marker
$dataSeriesLabels = [ $dataSeriesLabels = [
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$B$1', null, 1), // 2010 new DataSeriesValues('String', 'Worksheet!$B$1', null, 1), // 2010
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$C$1', null, 1), // 2011 new DataSeriesValues('String', 'Worksheet!$C$1', null, 1), // 2011
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$D$1', null, 1), // 2012 new DataSeriesValues('String', 'Worksheet!$D$1', null, 1), // 2012
]; ];
// Set the X-Axis Labels // Set the X-Axis Labels
// Datatype // Datatype
@ -35,7 +43,7 @@ $dataSeriesLabels = [
// Data values // Data values
// Data Marker // Data Marker
$xAxisTickValues = [ $xAxisTickValues = [
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4 new DataSeriesValues('String', 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4
]; ];
// Set the Data values for each data series we want to plot // Set the Data values for each data series we want to plot
// Datatype // Datatype
@ -45,15 +53,15 @@ $xAxisTickValues = [
// Data values // Data values
// Data Marker // Data Marker
$dataSeriesValues = [ $dataSeriesValues = [
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$B$2:$B$5', null, 4), new DataSeriesValues('Number', 'Worksheet!$B$2:$B$5', null, 4),
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', null, 4), new DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', null, 4),
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$D$2:$D$5', null, 4), new DataSeriesValues('Number', 'Worksheet!$D$2:$D$5', null, 4),
]; ];
// Build the dataseries // Build the dataseries
$series = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries( $series = new DataSeries(
\PhpOffice\PhpSpreadsheet\Chart\DataSeries::TYPE_AREACHART, // plotType DataSeries::TYPE_AREACHART, // plotType
\PhpOffice\PhpSpreadsheet\Chart\DataSeries::GROUPING_PERCENT_STACKED, // plotGrouping DataSeries::GROUPING_PERCENT_STACKED, // plotGrouping
range(0, count($dataSeriesValues) - 1), // plotOrder range(0, count($dataSeriesValues) - 1), // plotOrder
$dataSeriesLabels, // plotLabel $dataSeriesLabels, // plotLabel
$xAxisTickValues, // plotCategory $xAxisTickValues, // plotCategory
@ -61,15 +69,15 @@ $series = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries(
); );
// Set the series in the plot area // Set the series in the plot area
$plotArea = new \PhpOffice\PhpSpreadsheet\Chart\PlotArea(null, [$series]); $plotArea = new PlotArea(null, [$series]);
// Set the chart legend // Set the chart legend
$legend = new \PhpOffice\PhpSpreadsheet\Chart\Legend(\PhpOffice\PhpSpreadsheet\Chart\Legend::POSITION_TOPRIGHT, null, false); $legend = new Legend(Legend::POSITION_TOPRIGHT, null, false);
$title = new \PhpOffice\PhpSpreadsheet\Chart\Title('Test %age-Stacked Area Chart'); $title = new Title('Test %age-Stacked Area Chart');
$yAxisLabel = new \PhpOffice\PhpSpreadsheet\Chart\Title('Value ($k)'); $yAxisLabel = new Title('Value ($k)');
// Create the chart // Create the chart
$chart = new \PhpOffice\PhpSpreadsheet\Chart( $chart = new Chart(
'chart1', // name 'chart1', // name
$title, // title $title, // title
$legend, // legend $legend, // legend
@ -89,7 +97,7 @@ $worksheet->addChart($chart);
// Save Excel 2007 file // Save Excel 2007 file
$filename = $helper->getFilename(__FILE__); $filename = $helper->getFilename(__FILE__);
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx'); $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->setIncludeCharts(true); $writer->setIncludeCharts(true);
$callStartTime = microtime(true); $callStartTime = microtime(true);
$writer->save($filename); $writer->save($filename);

View File

@ -1,5 +1,6 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\IOFactory;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.php';
@ -7,7 +8,7 @@ $spreadsheet = require __DIR__ . '/templates/chartSpreadsheet.php';
// Save Excel 2007 file // Save Excel 2007 file
$filename = $helper->getFilename(__FILE__); $filename = $helper->getFilename(__FILE__);
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx'); $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->setIncludeCharts(true); $writer->setIncludeCharts(true);
$callStartTime = microtime(true); $callStartTime = microtime(true);
$writer->save($filename); $writer->save($filename);

View File

@ -1,9 +1,17 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Chart;
use PhpOffice\PhpSpreadsheet\Chart\DataSeries;
use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues;
use PhpOffice\PhpSpreadsheet\Chart\Legend;
use PhpOffice\PhpSpreadsheet\Chart\PlotArea;
use PhpOffice\PhpSpreadsheet\Chart\Title;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.php';
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet(); $worksheet = $spreadsheet->getActiveSheet();
$worksheet->fromArray( $worksheet->fromArray(
[ [
@ -23,9 +31,9 @@ $worksheet->fromArray(
// Data values // Data values
// Data Marker // Data Marker
$dataSeriesLabels = [ $dataSeriesLabels = [
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$B$1', null, 1), // 2010 new DataSeriesValues('String', 'Worksheet!$B$1', null, 1), // 2010
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$C$1', null, 1), // 2011 new DataSeriesValues('String', 'Worksheet!$C$1', null, 1), // 2011
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$D$1', null, 1), // 2012 new DataSeriesValues('String', 'Worksheet!$D$1', null, 1), // 2012
]; ];
// Set the X-Axis Labels // Set the X-Axis Labels
// Datatype // Datatype
@ -35,7 +43,7 @@ $dataSeriesLabels = [
// Data values // Data values
// Data Marker // Data Marker
$xAxisTickValues = [ $xAxisTickValues = [
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4 new DataSeriesValues('String', 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4
]; ];
// Set the Data values for each data series we want to plot // Set the Data values for each data series we want to plot
// Datatype // Datatype
@ -45,15 +53,15 @@ $xAxisTickValues = [
// Data values // Data values
// Data Marker // Data Marker
$dataSeriesValues = [ $dataSeriesValues = [
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$B$2:$B$5', null, 4), new DataSeriesValues('Number', 'Worksheet!$B$2:$B$5', null, 4),
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', null, 4), new DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', null, 4),
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$D$2:$D$5', null, 4), new DataSeriesValues('Number', 'Worksheet!$D$2:$D$5', null, 4),
]; ];
// Build the dataseries // Build the dataseries
$series = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries( $series = new DataSeries(
\PhpOffice\PhpSpreadsheet\Chart\DataSeries::TYPE_BARCHART, // plotType DataSeries::TYPE_BARCHART, // plotType
\PhpOffice\PhpSpreadsheet\Chart\DataSeries::GROUPING_STACKED, // plotGrouping DataSeries::GROUPING_STACKED, // plotGrouping
range(0, count($dataSeriesValues) - 1), // plotOrder range(0, count($dataSeriesValues) - 1), // plotOrder
$dataSeriesLabels, // plotLabel $dataSeriesLabels, // plotLabel
$xAxisTickValues, // plotCategory $xAxisTickValues, // plotCategory
@ -61,18 +69,18 @@ $series = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries(
); );
// Set additional dataseries parameters // Set additional dataseries parameters
// Make it a horizontal bar rather than a vertical column graph // Make it a horizontal bar rather than a vertical column graph
$series->setPlotDirection(\PhpOffice\PhpSpreadsheet\Chart\DataSeries::DIRECTION_BAR); $series->setPlotDirection(DataSeries::DIRECTION_BAR);
// Set the series in the plot area // Set the series in the plot area
$plotArea = new \PhpOffice\PhpSpreadsheet\Chart\PlotArea(null, [$series]); $plotArea = new PlotArea(null, [$series]);
// Set the chart legend // Set the chart legend
$legend = new \PhpOffice\PhpSpreadsheet\Chart\Legend(\PhpOffice\PhpSpreadsheet\Chart\Legend::POSITION_RIGHT, null, false); $legend = new Legend(Legend::POSITION_RIGHT, null, false);
$title = new \PhpOffice\PhpSpreadsheet\Chart\Title('Test Chart'); $title = new Title('Test Chart');
$yAxisLabel = new \PhpOffice\PhpSpreadsheet\Chart\Title('Value ($k)'); $yAxisLabel = new Title('Value ($k)');
// Create the chart // Create the chart
$chart = new \PhpOffice\PhpSpreadsheet\Chart( $chart = new Chart(
'chart1', // name 'chart1', // name
$title, // title $title, // title
$legend, // legend $legend, // legend
@ -92,7 +100,7 @@ $worksheet->addChart($chart);
// Save Excel 2007 file // Save Excel 2007 file
$filename = $helper->getFilename(__FILE__); $filename = $helper->getFilename(__FILE__);
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx'); $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->setIncludeCharts(true); $writer->setIncludeCharts(true);
$callStartTime = microtime(true); $callStartTime = microtime(true);
$writer->save($filename); $writer->save($filename);

View File

@ -1,9 +1,17 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Chart;
use PhpOffice\PhpSpreadsheet\Chart\DataSeries;
use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues;
use PhpOffice\PhpSpreadsheet\Chart\Legend;
use PhpOffice\PhpSpreadsheet\Chart\PlotArea;
use PhpOffice\PhpSpreadsheet\Chart\Title;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.php';
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet(); $worksheet = $spreadsheet->getActiveSheet();
$worksheet->fromArray( $worksheet->fromArray(
[ [
@ -23,9 +31,9 @@ $worksheet->fromArray(
// Data values // Data values
// Data Marker // Data Marker
$dataSeriesLabels = [ $dataSeriesLabels = [
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$B$1', null, 1), // 2010 new DataSeriesValues('String', 'Worksheet!$B$1', null, 1), // 2010
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$C$1', null, 1), // 2011 new DataSeriesValues('String', 'Worksheet!$C$1', null, 1), // 2011
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$D$1', null, 1), // 2012 new DataSeriesValues('String', 'Worksheet!$D$1', null, 1), // 2012
]; ];
// Set the X-Axis Labels // Set the X-Axis Labels
// Datatype // Datatype
@ -35,7 +43,7 @@ $dataSeriesLabels = [
// Data values // Data values
// Data Marker // Data Marker
$xAxisTickValues = [ $xAxisTickValues = [
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4 new DataSeriesValues('String', 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4
]; ];
// Set the Data values for each data series we want to plot // Set the Data values for each data series we want to plot
// Datatype // Datatype
@ -45,15 +53,15 @@ $xAxisTickValues = [
// Data values // Data values
// Data Marker // Data Marker
$dataSeriesValues = [ $dataSeriesValues = [
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$B$2:$B$5', null, 4), new DataSeriesValues('Number', 'Worksheet!$B$2:$B$5', null, 4),
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', null, 4), new DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', null, 4),
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$D$2:$D$5', null, 4), new DataSeriesValues('Number', 'Worksheet!$D$2:$D$5', null, 4),
]; ];
// Build the dataseries // Build the dataseries
$series = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries( $series = new DataSeries(
\PhpOffice\PhpSpreadsheet\Chart\DataSeries::TYPE_BARCHART, // plotType DataSeries::TYPE_BARCHART, // plotType
\PhpOffice\PhpSpreadsheet\Chart\DataSeries::GROUPING_STANDARD, // plotGrouping DataSeries::GROUPING_STANDARD, // plotGrouping
range(0, count($dataSeriesValues) - 1), // plotOrder range(0, count($dataSeriesValues) - 1), // plotOrder
$dataSeriesLabels, // plotLabel $dataSeriesLabels, // plotLabel
$xAxisTickValues, // plotCategory $xAxisTickValues, // plotCategory
@ -61,18 +69,18 @@ $series = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries(
); );
// Set additional dataseries parameters // Set additional dataseries parameters
// Make it a vertical column rather than a horizontal bar graph // Make it a vertical column rather than a horizontal bar graph
$series->setPlotDirection(\PhpOffice\PhpSpreadsheet\Chart\DataSeries::DIRECTION_COL); $series->setPlotDirection(DataSeries::DIRECTION_COL);
// Set the series in the plot area // Set the series in the plot area
$plotArea = new \PhpOffice\PhpSpreadsheet\Chart\PlotArea(null, [$series]); $plotArea = new PlotArea(null, [$series]);
// Set the chart legend // Set the chart legend
$legend = new \PhpOffice\PhpSpreadsheet\Chart\Legend(\PhpOffice\PhpSpreadsheet\Chart\Legend::POSITION_RIGHT, null, false); $legend = new Legend(Legend::POSITION_RIGHT, null, false);
$title = new \PhpOffice\PhpSpreadsheet\Chart\Title('Test Column Chart'); $title = new Title('Test Column Chart');
$yAxisLabel = new \PhpOffice\PhpSpreadsheet\Chart\Title('Value ($k)'); $yAxisLabel = new Title('Value ($k)');
// Create the chart // Create the chart
$chart = new \PhpOffice\PhpSpreadsheet\Chart( $chart = new Chart(
'chart1', // name 'chart1', // name
$title, // title $title, // title
$legend, // legend $legend, // legend
@ -92,7 +100,7 @@ $worksheet->addChart($chart);
// Save Excel 2007 file // Save Excel 2007 file
$filename = $helper->getFilename(__FILE__); $filename = $helper->getFilename(__FILE__);
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx'); $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->setIncludeCharts(true); $writer->setIncludeCharts(true);
$callStartTime = microtime(true); $callStartTime = microtime(true);
$writer->save($filename); $writer->save($filename);

View File

@ -1,9 +1,17 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Chart;
use PhpOffice\PhpSpreadsheet\Chart\DataSeries;
use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues;
use PhpOffice\PhpSpreadsheet\Chart\Legend;
use PhpOffice\PhpSpreadsheet\Chart\PlotArea;
use PhpOffice\PhpSpreadsheet\Chart\Title;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.php';
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet(); $worksheet = $spreadsheet->getActiveSheet();
$worksheet->fromArray( $worksheet->fromArray(
[ [
@ -31,9 +39,9 @@ $worksheet->fromArray(
// Data values // Data values
// Data Marker // Data Marker
$dataSeriesLabels = [ $dataSeriesLabels = [
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$C$1', null, 1), // 'Budget' new DataSeriesValues('String', 'Worksheet!$C$1', null, 1), // 'Budget'
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$D$1', null, 1), // 'Forecast' new DataSeriesValues('String', 'Worksheet!$D$1', null, 1), // 'Forecast'
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$E$1', null, 1), // 'Actual' new DataSeriesValues('String', 'Worksheet!$E$1', null, 1), // 'Actual'
]; ];
// Set the X-Axis Labels // Set the X-Axis Labels
// Datatype // Datatype
@ -43,7 +51,7 @@ $dataSeriesLabels = [
// Data values // Data values
// Data Marker // Data Marker
$xAxisTickValues = [ $xAxisTickValues = [
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$A$2:$B$13', null, 12), // Q1 to Q4 for 2010 to 2012 new DataSeriesValues('String', 'Worksheet!$A$2:$B$13', null, 12), // Q1 to Q4 for 2010 to 2012
]; ];
// Set the Data values for each data series we want to plot // Set the Data values for each data series we want to plot
// Datatype // Datatype
@ -53,15 +61,15 @@ $xAxisTickValues = [
// Data values // Data values
// Data Marker // Data Marker
$dataSeriesValues = [ $dataSeriesValues = [
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$C$2:$C$13', null, 12), new DataSeriesValues('Number', 'Worksheet!$C$2:$C$13', null, 12),
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$D$2:$D$13', null, 12), new DataSeriesValues('Number', 'Worksheet!$D$2:$D$13', null, 12),
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$E$2:$E$13', null, 12), new DataSeriesValues('Number', 'Worksheet!$E$2:$E$13', null, 12),
]; ];
// Build the dataseries // Build the dataseries
$series = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries( $series = new DataSeries(
\PhpOffice\PhpSpreadsheet\Chart\DataSeries::TYPE_BARCHART, // plotType DataSeries::TYPE_BARCHART, // plotType
\PhpOffice\PhpSpreadsheet\Chart\DataSeries::GROUPING_CLUSTERED, // plotGrouping DataSeries::GROUPING_CLUSTERED, // plotGrouping
range(0, count($dataSeriesValues) - 1), // plotOrder range(0, count($dataSeriesValues) - 1), // plotOrder
$dataSeriesLabels, // plotLabel $dataSeriesLabels, // plotLabel
$xAxisTickValues, // plotCategory $xAxisTickValues, // plotCategory
@ -69,19 +77,19 @@ $series = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries(
); );
// Set additional dataseries parameters // Set additional dataseries parameters
// Make it a vertical column rather than a horizontal bar graph // Make it a vertical column rather than a horizontal bar graph
$series->setPlotDirection(\PhpOffice\PhpSpreadsheet\Chart\DataSeries::DIRECTION_COL); $series->setPlotDirection(DataSeries::DIRECTION_COL);
// Set the series in the plot area // Set the series in the plot area
$plotArea = new \PhpOffice\PhpSpreadsheet\Chart\PlotArea(null, [$series]); $plotArea = new PlotArea(null, [$series]);
// Set the chart legend // Set the chart legend
$legend = new \PhpOffice\PhpSpreadsheet\Chart\Legend(\PhpOffice\PhpSpreadsheet\Chart\Legend::POSITION_BOTTOM, null, false); $legend = new Legend(Legend::POSITION_BOTTOM, null, false);
$title = new \PhpOffice\PhpSpreadsheet\Chart\Title('Test Grouped Column Chart'); $title = new Title('Test Grouped Column Chart');
$xAxisLabel = new \PhpOffice\PhpSpreadsheet\Chart\Title('Financial Period'); $xAxisLabel = new Title('Financial Period');
$yAxisLabel = new \PhpOffice\PhpSpreadsheet\Chart\Title('Value ($k)'); $yAxisLabel = new Title('Value ($k)');
// Create the chart // Create the chart
$chart = new \PhpOffice\PhpSpreadsheet\Chart( $chart = new Chart(
'chart1', // name 'chart1', // name
$title, // title $title, // title
$legend, // legend $legend, // legend
@ -101,7 +109,7 @@ $worksheet->addChart($chart);
// Save Excel 2007 file // Save Excel 2007 file
$filename = $helper->getFilename(__FILE__); $filename = $helper->getFilename(__FILE__);
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx'); $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->setIncludeCharts(true); $writer->setIncludeCharts(true);
$callStartTime = microtime(true); $callStartTime = microtime(true);
$writer->save($filename); $writer->save($filename);

View File

@ -1,9 +1,17 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Chart;
use PhpOffice\PhpSpreadsheet\Chart\DataSeries;
use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues;
use PhpOffice\PhpSpreadsheet\Chart\Legend;
use PhpOffice\PhpSpreadsheet\Chart\PlotArea;
use PhpOffice\PhpSpreadsheet\Chart\Title;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.php';
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet(); $worksheet = $spreadsheet->getActiveSheet();
$worksheet->fromArray( $worksheet->fromArray(
[ [
@ -31,13 +39,13 @@ $worksheet->fromArray(
// Data values // Data values
// Data Marker // Data Marker
$dataSeriesLabels1 = [ $dataSeriesLabels1 = [
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$B$1', null, 1), // Temperature new DataSeriesValues('String', 'Worksheet!$B$1', null, 1), // Temperature
]; ];
$dataSeriesLabels2 = [ $dataSeriesLabels2 = [
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$C$1', null, 1), // Rainfall new DataSeriesValues('String', 'Worksheet!$C$1', null, 1), // Rainfall
]; ];
$dataSeriesLabels3 = [ $dataSeriesLabels3 = [
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$D$1', null, 1), // Humidity new DataSeriesValues('String', 'Worksheet!$D$1', null, 1), // Humidity
]; ];
// Set the X-Axis Labels // Set the X-Axis Labels
@ -48,7 +56,7 @@ $dataSeriesLabels3 = [
// Data values // Data values
// Data Marker // Data Marker
$xAxisTickValues = [ $xAxisTickValues = [
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$A$2:$A$13', null, 12), // Jan to Dec new DataSeriesValues('String', 'Worksheet!$A$2:$A$13', null, 12), // Jan to Dec
]; ];
// Set the Data values for each data series we want to plot // Set the Data values for each data series we want to plot
@ -59,13 +67,13 @@ $xAxisTickValues = [
// Data values // Data values
// Data Marker // Data Marker
$dataSeriesValues1 = [ $dataSeriesValues1 = [
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$B$2:$B$13', null, 12), new DataSeriesValues('Number', 'Worksheet!$B$2:$B$13', null, 12),
]; ];
// Build the dataseries // Build the dataseries
$series1 = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries( $series1 = new DataSeries(
\PhpOffice\PhpSpreadsheet\Chart\DataSeries::TYPE_BARCHART, // plotType DataSeries::TYPE_BARCHART, // plotType
\PhpOffice\PhpSpreadsheet\Chart\DataSeries::GROUPING_CLUSTERED, // plotGrouping DataSeries::GROUPING_CLUSTERED, // plotGrouping
range(0, count($dataSeriesValues1) - 1), // plotOrder range(0, count($dataSeriesValues1) - 1), // plotOrder
$dataSeriesLabels1, // plotLabel $dataSeriesLabels1, // plotLabel
$xAxisTickValues, // plotCategory $xAxisTickValues, // plotCategory
@ -73,7 +81,7 @@ $series1 = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries(
); );
// Set additional dataseries parameters // Set additional dataseries parameters
// Make it a vertical column rather than a horizontal bar graph // Make it a vertical column rather than a horizontal bar graph
$series1->setPlotDirection(\PhpOffice\PhpSpreadsheet\Chart\DataSeries::DIRECTION_COL); $series1->setPlotDirection(DataSeries::DIRECTION_COL);
// Set the Data values for each data series we want to plot // Set the Data values for each data series we want to plot
// Datatype // Datatype
@ -83,13 +91,13 @@ $series1->setPlotDirection(\PhpOffice\PhpSpreadsheet\Chart\DataSeries::DIRECTION
// Data values // Data values
// Data Marker // Data Marker
$dataSeriesValues2 = [ $dataSeriesValues2 = [
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$C$2:$C$13', null, 12), new DataSeriesValues('Number', 'Worksheet!$C$2:$C$13', null, 12),
]; ];
// Build the dataseries // Build the dataseries
$series2 = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries( $series2 = new DataSeries(
\PhpOffice\PhpSpreadsheet\Chart\DataSeries::TYPE_LINECHART, // plotType DataSeries::TYPE_LINECHART, // plotType
\PhpOffice\PhpSpreadsheet\Chart\DataSeries::GROUPING_STANDARD, // plotGrouping DataSeries::GROUPING_STANDARD, // plotGrouping
range(0, count($dataSeriesValues2) - 1), // plotOrder range(0, count($dataSeriesValues2) - 1), // plotOrder
$dataSeriesLabels2, // plotLabel $dataSeriesLabels2, // plotLabel
null, // plotCategory null, // plotCategory
@ -104,13 +112,13 @@ $series2 = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries(
// Data values // Data values
// Data Marker // Data Marker
$dataSeriesValues3 = [ $dataSeriesValues3 = [
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$D$2:$D$13', null, 12), new DataSeriesValues('Number', 'Worksheet!$D$2:$D$13', null, 12),
]; ];
// Build the dataseries // Build the dataseries
$series3 = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries( $series3 = new DataSeries(
\PhpOffice\PhpSpreadsheet\Chart\DataSeries::TYPE_AREACHART, // plotType DataSeries::TYPE_AREACHART, // plotType
\PhpOffice\PhpSpreadsheet\Chart\DataSeries::GROUPING_STANDARD, // plotGrouping DataSeries::GROUPING_STANDARD, // plotGrouping
range(0, count($dataSeriesValues2) - 1), // plotOrder range(0, count($dataSeriesValues2) - 1), // plotOrder
$dataSeriesLabels3, // plotLabel $dataSeriesLabels3, // plotLabel
null, // plotCategory null, // plotCategory
@ -118,14 +126,14 @@ $series3 = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries(
); );
// Set the series in the plot area // Set the series in the plot area
$plotArea = new \PhpOffice\PhpSpreadsheet\Chart\PlotArea(null, [$series1, $series2, $series3]); $plotArea = new PlotArea(null, [$series1, $series2, $series3]);
// Set the chart legend // Set the chart legend
$legend = new \PhpOffice\PhpSpreadsheet\Chart\Legend(\PhpOffice\PhpSpreadsheet\Chart\Legend::POSITION_RIGHT, null, false); $legend = new Legend(Legend::POSITION_RIGHT, null, false);
$title = new \PhpOffice\PhpSpreadsheet\Chart\Title('Average Weather Chart for Crete'); $title = new Title('Average Weather Chart for Crete');
// Create the chart // Create the chart
$chart = new \PhpOffice\PhpSpreadsheet\Chart( $chart = new Chart(
'chart1', // name 'chart1', // name
$title, // title $title, // title
$legend, // legend $legend, // legend
@ -145,7 +153,7 @@ $worksheet->addChart($chart);
// Save Excel 2007 file // Save Excel 2007 file
$filename = $helper->getFilename(__FILE__); $filename = $helper->getFilename(__FILE__);
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx'); $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->setIncludeCharts(true); $writer->setIncludeCharts(true);
$callStartTime = microtime(true); $callStartTime = microtime(true);
$writer->save($filename); $writer->save($filename);

View File

@ -1,9 +1,17 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Chart;
use PhpOffice\PhpSpreadsheet\Chart\DataSeries;
use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues;
use PhpOffice\PhpSpreadsheet\Chart\Legend;
use PhpOffice\PhpSpreadsheet\Chart\PlotArea;
use PhpOffice\PhpSpreadsheet\Chart\Title;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.php';
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet(); $worksheet = $spreadsheet->getActiveSheet();
$worksheet->fromArray( $worksheet->fromArray(
[ [
@ -23,9 +31,9 @@ $worksheet->fromArray(
// Data values // Data values
// Data Marker // Data Marker
$dataSeriesLabels = [ $dataSeriesLabels = [
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$B$1', null, 1), // 2010 new DataSeriesValues('String', 'Worksheet!$B$1', null, 1), // 2010
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$C$1', null, 1), // 2011 new DataSeriesValues('String', 'Worksheet!$C$1', null, 1), // 2011
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$D$1', null, 1), // 2012 new DataSeriesValues('String', 'Worksheet!$D$1', null, 1), // 2012
]; ];
// Set the X-Axis Labels // Set the X-Axis Labels
// Datatype // Datatype
@ -35,7 +43,7 @@ $dataSeriesLabels = [
// Data values // Data values
// Data Marker // Data Marker
$xAxisTickValues = [ $xAxisTickValues = [
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4 new DataSeriesValues('String', 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4
]; ];
// Set the Data values for each data series we want to plot // Set the Data values for each data series we want to plot
// Datatype // Datatype
@ -45,15 +53,15 @@ $xAxisTickValues = [
// Data values // Data values
// Data Marker // Data Marker
$dataSeriesValues = [ $dataSeriesValues = [
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$B$2:$B$5', null, 4), new DataSeriesValues('Number', 'Worksheet!$B$2:$B$5', null, 4),
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', null, 4), new DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', null, 4),
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$D$2:$D$5', null, 4), new DataSeriesValues('Number', 'Worksheet!$D$2:$D$5', null, 4),
]; ];
// Build the dataseries // Build the dataseries
$series = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries( $series = new DataSeries(
\PhpOffice\PhpSpreadsheet\Chart\DataSeries::TYPE_LINECHART, // plotType DataSeries::TYPE_LINECHART, // plotType
\PhpOffice\PhpSpreadsheet\Chart\DataSeries::GROUPING_STACKED, // plotGrouping DataSeries::GROUPING_STACKED, // plotGrouping
range(0, count($dataSeriesValues) - 1), // plotOrder range(0, count($dataSeriesValues) - 1), // plotOrder
$dataSeriesLabels, // plotLabel $dataSeriesLabels, // plotLabel
$xAxisTickValues, // plotCategory $xAxisTickValues, // plotCategory
@ -61,15 +69,15 @@ $series = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries(
); );
// Set the series in the plot area // Set the series in the plot area
$plotArea = new \PhpOffice\PhpSpreadsheet\Chart\PlotArea(null, [$series]); $plotArea = new PlotArea(null, [$series]);
// Set the chart legend // Set the chart legend
$legend = new \PhpOffice\PhpSpreadsheet\Chart\Legend(\PhpOffice\PhpSpreadsheet\Chart\Legend::POSITION_TOPRIGHT, null, false); $legend = new Legend(Legend::POSITION_TOPRIGHT, null, false);
$title = new \PhpOffice\PhpSpreadsheet\Chart\Title('Test Stacked Line Chart'); $title = new Title('Test Stacked Line Chart');
$yAxisLabel = new \PhpOffice\PhpSpreadsheet\Chart\Title('Value ($k)'); $yAxisLabel = new Title('Value ($k)');
// Create the chart // Create the chart
$chart = new \PhpOffice\PhpSpreadsheet\Chart( $chart = new Chart(
'chart1', // name 'chart1', // name
$title, // title $title, // title
$legend, // legend $legend, // legend
@ -89,7 +97,7 @@ $worksheet->addChart($chart);
// Save Excel 2007 file // Save Excel 2007 file
$filename = $helper->getFilename(__FILE__); $filename = $helper->getFilename(__FILE__);
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx'); $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->setIncludeCharts(true); $writer->setIncludeCharts(true);
$callStartTime = microtime(true); $callStartTime = microtime(true);
$writer->save($filename); $writer->save($filename);

View File

@ -1,9 +1,17 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Chart;
use PhpOffice\PhpSpreadsheet\Chart\DataSeries;
use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues;
use PhpOffice\PhpSpreadsheet\Chart\Legend;
use PhpOffice\PhpSpreadsheet\Chart\PlotArea;
use PhpOffice\PhpSpreadsheet\Chart\Title;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.php';
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet(); $worksheet = $spreadsheet->getActiveSheet();
$worksheet->fromArray( $worksheet->fromArray(
[ [
@ -23,9 +31,9 @@ $worksheet->fromArray(
// Data values // Data values
// Data Marker // Data Marker
$dataSeriesLabels1 = [ $dataSeriesLabels1 = [
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$B$1', null, 1), // 2010 new DataSeriesValues('String', 'Worksheet!$B$1', null, 1), // 2010
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$C$1', null, 1), // 2011 new DataSeriesValues('String', 'Worksheet!$C$1', null, 1), // 2011
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$D$1', null, 1), // 2012 new DataSeriesValues('String', 'Worksheet!$D$1', null, 1), // 2012
]; ];
// Set the X-Axis Labels // Set the X-Axis Labels
// Datatype // Datatype
@ -35,7 +43,7 @@ $dataSeriesLabels1 = [
// Data values // Data values
// Data Marker // Data Marker
$xAxisTickValues1 = [ $xAxisTickValues1 = [
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4 new DataSeriesValues('String', 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4
]; ];
// Set the Data values for each data series we want to plot // Set the Data values for each data series we want to plot
// Datatype // Datatype
@ -45,15 +53,15 @@ $xAxisTickValues1 = [
// Data values // Data values
// Data Marker // Data Marker
$dataSeriesValues1 = [ $dataSeriesValues1 = [
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$B$2:$B$5', null, 4), new DataSeriesValues('Number', 'Worksheet!$B$2:$B$5', null, 4),
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', null, 4), new DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', null, 4),
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$D$2:$D$5', null, 4), new DataSeriesValues('Number', 'Worksheet!$D$2:$D$5', null, 4),
]; ];
// Build the dataseries // Build the dataseries
$series1 = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries( $series1 = new DataSeries(
\PhpOffice\PhpSpreadsheet\Chart\DataSeries::TYPE_AREACHART, // plotType DataSeries::TYPE_AREACHART, // plotType
\PhpOffice\PhpSpreadsheet\Chart\DataSeries::GROUPING_PERCENT_STACKED, // plotGrouping DataSeries::GROUPING_PERCENT_STACKED, // plotGrouping
range(0, count($dataSeriesValues1) - 1), // plotOrder range(0, count($dataSeriesValues1) - 1), // plotOrder
$dataSeriesLabels1, // plotLabel $dataSeriesLabels1, // plotLabel
$xAxisTickValues1, // plotCategory $xAxisTickValues1, // plotCategory
@ -61,15 +69,15 @@ $series1 = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries(
); );
// Set the series in the plot area // Set the series in the plot area
$plotArea1 = new \PhpOffice\PhpSpreadsheet\Chart\PlotArea(null, [$series1]); $plotArea1 = new PlotArea(null, [$series1]);
// Set the chart legend // Set the chart legend
$legend1 = new \PhpOffice\PhpSpreadsheet\Chart\Legend(\PhpOffice\PhpSpreadsheet\Chart\Legend::POSITION_TOPRIGHT, null, false); $legend1 = new Legend(Legend::POSITION_TOPRIGHT, null, false);
$title1 = new \PhpOffice\PhpSpreadsheet\Chart\Title('Test %age-Stacked Area Chart'); $title1 = new Title('Test %age-Stacked Area Chart');
$yAxisLabel1 = new \PhpOffice\PhpSpreadsheet\Chart\Title('Value ($k)'); $yAxisLabel1 = new Title('Value ($k)');
// Create the chart // Create the chart
$chart1 = new \PhpOffice\PhpSpreadsheet\Chart( $chart1 = new Chart(
'chart1', // name 'chart1', // name
$title1, // title $title1, // title
$legend1, // legend $legend1, // legend
@ -95,9 +103,9 @@ $worksheet->addChart($chart1);
// Data values // Data values
// Data Marker // Data Marker
$dataSeriesLabels2 = [ $dataSeriesLabels2 = [
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$B$1', null, 1), // 2010 new DataSeriesValues('String', 'Worksheet!$B$1', null, 1), // 2010
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$C$1', null, 1), // 2011 new DataSeriesValues('String', 'Worksheet!$C$1', null, 1), // 2011
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$D$1', null, 1), // 2012 new DataSeriesValues('String', 'Worksheet!$D$1', null, 1), // 2012
]; ];
// Set the X-Axis Labels // Set the X-Axis Labels
// Datatype // Datatype
@ -107,7 +115,7 @@ $dataSeriesLabels2 = [
// Data values // Data values
// Data Marker // Data Marker
$xAxisTickValues2 = [ $xAxisTickValues2 = [
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4 new DataSeriesValues('String', 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4
]; ];
// Set the Data values for each data series we want to plot // Set the Data values for each data series we want to plot
// Datatype // Datatype
@ -117,15 +125,15 @@ $xAxisTickValues2 = [
// Data values // Data values
// Data Marker // Data Marker
$dataSeriesValues2 = [ $dataSeriesValues2 = [
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$B$2:$B$5', null, 4), new DataSeriesValues('Number', 'Worksheet!$B$2:$B$5', null, 4),
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', null, 4), new DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', null, 4),
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$D$2:$D$5', null, 4), new DataSeriesValues('Number', 'Worksheet!$D$2:$D$5', null, 4),
]; ];
// Build the dataseries // Build the dataseries
$series2 = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries( $series2 = new DataSeries(
\PhpOffice\PhpSpreadsheet\Chart\DataSeries::TYPE_BARCHART, // plotType DataSeries::TYPE_BARCHART, // plotType
\PhpOffice\PhpSpreadsheet\Chart\DataSeries::GROUPING_STANDARD, // plotGrouping DataSeries::GROUPING_STANDARD, // plotGrouping
range(0, count($dataSeriesValues2) - 1), // plotOrder range(0, count($dataSeriesValues2) - 1), // plotOrder
$dataSeriesLabels2, // plotLabel $dataSeriesLabels2, // plotLabel
$xAxisTickValues2, // plotCategory $xAxisTickValues2, // plotCategory
@ -133,18 +141,18 @@ $series2 = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries(
); );
// Set additional dataseries parameters // Set additional dataseries parameters
// Make it a vertical column rather than a horizontal bar graph // Make it a vertical column rather than a horizontal bar graph
$series2->setPlotDirection(\PhpOffice\PhpSpreadsheet\Chart\DataSeries::DIRECTION_COL); $series2->setPlotDirection(DataSeries::DIRECTION_COL);
// Set the series in the plot area // Set the series in the plot area
$plotArea2 = new \PhpOffice\PhpSpreadsheet\Chart\PlotArea(null, [$series2]); $plotArea2 = new PlotArea(null, [$series2]);
// Set the chart legend // Set the chart legend
$legend2 = new \PhpOffice\PhpSpreadsheet\Chart\Legend(\PhpOffice\PhpSpreadsheet\Chart\Legend::POSITION_RIGHT, null, false); $legend2 = new Legend(Legend::POSITION_RIGHT, null, false);
$title2 = new \PhpOffice\PhpSpreadsheet\Chart\Title('Test Column Chart'); $title2 = new Title('Test Column Chart');
$yAxisLabel2 = new \PhpOffice\PhpSpreadsheet\Chart\Title('Value ($k)'); $yAxisLabel2 = new Title('Value ($k)');
// Create the chart // Create the chart
$chart2 = new \PhpOffice\PhpSpreadsheet\Chart( $chart2 = new Chart(
'chart2', // name 'chart2', // name
$title2, // title $title2, // title
$legend2, // legend $legend2, // legend
@ -164,7 +172,7 @@ $worksheet->addChart($chart2);
// Save Excel 2007 file // Save Excel 2007 file
$filename = $helper->getFilename(__FILE__); $filename = $helper->getFilename(__FILE__);
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx'); $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->setIncludeCharts(true); $writer->setIncludeCharts(true);
$callStartTime = microtime(true); $callStartTime = microtime(true);
$writer->save($filename); $writer->save($filename);

View File

@ -1,9 +1,17 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Chart;
use PhpOffice\PhpSpreadsheet\Chart\DataSeries;
use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues;
use PhpOffice\PhpSpreadsheet\Chart\Legend;
use PhpOffice\PhpSpreadsheet\Chart\PlotArea;
use PhpOffice\PhpSpreadsheet\Chart\Title;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.php';
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet(); $worksheet = $spreadsheet->getActiveSheet();
$worksheet->fromArray( $worksheet->fromArray(
[ [
@ -23,7 +31,7 @@ $worksheet->fromArray(
// Data values // Data values
// Data Marker // Data Marker
$dataSeriesLabels1 = [ $dataSeriesLabels1 = [
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$C$1', null, 1), // 2011 new DataSeriesValues('String', 'Worksheet!$C$1', null, 1), // 2011
]; ];
// Set the X-Axis Labels // Set the X-Axis Labels
// Datatype // Datatype
@ -33,7 +41,7 @@ $dataSeriesLabels1 = [
// Data values // Data values
// Data Marker // Data Marker
$xAxisTickValues1 = [ $xAxisTickValues1 = [
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4 new DataSeriesValues('String', 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4
]; ];
// Set the Data values for each data series we want to plot // Set the Data values for each data series we want to plot
// Datatype // Datatype
@ -43,12 +51,12 @@ $xAxisTickValues1 = [
// Data values // Data values
// Data Marker // Data Marker
$dataSeriesValues1 = [ $dataSeriesValues1 = [
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', null, 4), new DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', null, 4),
]; ];
// Build the dataseries // Build the dataseries
$series1 = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries( $series1 = new DataSeries(
\PhpOffice\PhpSpreadsheet\Chart\DataSeries::TYPE_PIECHART, // plotType DataSeries::TYPE_PIECHART, // plotType
null, // plotGrouping (Pie charts don't have any grouping) null, // plotGrouping (Pie charts don't have any grouping)
range(0, count($dataSeriesValues1) - 1), // plotOrder range(0, count($dataSeriesValues1) - 1), // plotOrder
$dataSeriesLabels1, // plotLabel $dataSeriesLabels1, // plotLabel
@ -57,19 +65,19 @@ $series1 = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries(
); );
// Set up a layout object for the Pie chart // Set up a layout object for the Pie chart
$layout1 = new \PhpOffice\PhpSpreadsheet\Chart\Layout(); $layout1 = new Chart\Layout();
$layout1->setShowVal(true); $layout1->setShowVal(true);
$layout1->setShowPercent(true); $layout1->setShowPercent(true);
// Set the series in the plot area // Set the series in the plot area
$plotArea1 = new \PhpOffice\PhpSpreadsheet\Chart\PlotArea($layout1, [$series1]); $plotArea1 = new PlotArea($layout1, [$series1]);
// Set the chart legend // Set the chart legend
$legend1 = new \PhpOffice\PhpSpreadsheet\Chart\Legend(\PhpOffice\PhpSpreadsheet\Chart\Legend::POSITION_RIGHT, null, false); $legend1 = new Legend(Legend::POSITION_RIGHT, null, false);
$title1 = new \PhpOffice\PhpSpreadsheet\Chart\Title('Test Pie Chart'); $title1 = new Title('Test Pie Chart');
// Create the chart // Create the chart
$chart1 = new \PhpOffice\PhpSpreadsheet\Chart( $chart1 = new Chart(
'chart1', // name 'chart1', // name
$title1, // title $title1, // title
$legend1, // legend $legend1, // legend
@ -95,7 +103,7 @@ $worksheet->addChart($chart1);
// Data values // Data values
// Data Marker // Data Marker
$dataSeriesLabels2 = [ $dataSeriesLabels2 = [
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$C$1', null, 1), // 2011 new DataSeriesValues('String', 'Worksheet!$C$1', null, 1), // 2011
]; ];
// Set the X-Axis Labels // Set the X-Axis Labels
// Datatype // Datatype
@ -105,7 +113,7 @@ $dataSeriesLabels2 = [
// Data values // Data values
// Data Marker // Data Marker
$xAxisTickValues2 = [ $xAxisTickValues2 = [
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4 new DataSeriesValues('String', 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4
]; ];
// Set the Data values for each data series we want to plot // Set the Data values for each data series we want to plot
// Datatype // Datatype
@ -115,12 +123,12 @@ $xAxisTickValues2 = [
// Data values // Data values
// Data Marker // Data Marker
$dataSeriesValues2 = [ $dataSeriesValues2 = [
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', null, 4), new DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', null, 4),
]; ];
// Build the dataseries // Build the dataseries
$series2 = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries( $series2 = new DataSeries(
\PhpOffice\PhpSpreadsheet\Chart\DataSeries::TYPE_DONUTCHART, // plotType DataSeries::TYPE_DONUTCHART, // plotType
null, // plotGrouping (Donut charts don't have any grouping) null, // plotGrouping (Donut charts don't have any grouping)
range(0, count($dataSeriesValues2) - 1), // plotOrder range(0, count($dataSeriesValues2) - 1), // plotOrder
$dataSeriesLabels2, // plotLabel $dataSeriesLabels2, // plotLabel
@ -129,17 +137,17 @@ $series2 = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries(
); );
// Set up a layout object for the Pie chart // Set up a layout object for the Pie chart
$layout2 = new \PhpOffice\PhpSpreadsheet\Chart\Layout(); $layout2 = new Chart\Layout();
$layout2->setShowVal(true); $layout2->setShowVal(true);
$layout2->setShowCatName(true); $layout2->setShowCatName(true);
// Set the series in the plot area // Set the series in the plot area
$plotArea2 = new \PhpOffice\PhpSpreadsheet\Chart\PlotArea($layout2, [$series2]); $plotArea2 = new PlotArea($layout2, [$series2]);
$title2 = new \PhpOffice\PhpSpreadsheet\Chart\Title('Test Donut Chart'); $title2 = new Title('Test Donut Chart');
// Create the chart // Create the chart
$chart2 = new \PhpOffice\PhpSpreadsheet\Chart( $chart2 = new Chart(
'chart2', // name 'chart2', // name
$title2, // title $title2, // title
null, // legend null, // legend
@ -159,7 +167,7 @@ $worksheet->addChart($chart2);
// Save Excel 2007 file // Save Excel 2007 file
$filename = $helper->getFilename(__FILE__); $filename = $helper->getFilename(__FILE__);
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx'); $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->setIncludeCharts(true); $writer->setIncludeCharts(true);
$callStartTime = microtime(true); $callStartTime = microtime(true);
$writer->save($filename); $writer->save($filename);

View File

@ -1,9 +1,17 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Chart;
use PhpOffice\PhpSpreadsheet\Chart\DataSeries;
use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues;
use PhpOffice\PhpSpreadsheet\Chart\Legend;
use PhpOffice\PhpSpreadsheet\Chart\PlotArea;
use PhpOffice\PhpSpreadsheet\Chart\Title;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.php';
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet(); $worksheet = $spreadsheet->getActiveSheet();
$worksheet->fromArray( $worksheet->fromArray(
[ [
@ -31,8 +39,8 @@ $worksheet->fromArray(
// Data values // Data values
// Data Marker // Data Marker
$dataSeriesLabels = [ $dataSeriesLabels = [
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$C$1', null, 1), // 2011 new DataSeriesValues('String', 'Worksheet!$C$1', null, 1), // 2011
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$D$1', null, 1), // 2012 new DataSeriesValues('String', 'Worksheet!$D$1', null, 1), // 2012
]; ];
// Set the X-Axis Labels // Set the X-Axis Labels
// Datatype // Datatype
@ -42,8 +50,8 @@ $dataSeriesLabels = [
// Data values // Data values
// Data Marker // Data Marker
$xAxisTickValues = [ $xAxisTickValues = [
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$A$2:$A$13', null, 12), // Jan to Dec new DataSeriesValues('String', 'Worksheet!$A$2:$A$13', null, 12), // Jan to Dec
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$A$2:$A$13', null, 12), // Jan to Dec new DataSeriesValues('String', 'Worksheet!$A$2:$A$13', null, 12), // Jan to Dec
]; ];
// Set the Data values for each data series we want to plot // Set the Data values for each data series we want to plot
// Datatype // Datatype
@ -53,13 +61,13 @@ $xAxisTickValues = [
// Data values // Data values
// Data Marker // Data Marker
$dataSeriesValues = [ $dataSeriesValues = [
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$C$2:$C$13', null, 12), new DataSeriesValues('Number', 'Worksheet!$C$2:$C$13', null, 12),
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$D$2:$D$13', null, 12), new DataSeriesValues('Number', 'Worksheet!$D$2:$D$13', null, 12),
]; ];
// Build the dataseries // Build the dataseries
$series = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries( $series = new DataSeries(
\PhpOffice\PhpSpreadsheet\Chart\DataSeries::TYPE_RADARCHART, // plotType DataSeries::TYPE_RADARCHART, // plotType
null, // plotGrouping (Radar charts don't have any grouping) null, // plotGrouping (Radar charts don't have any grouping)
range(0, count($dataSeriesValues) - 1), // plotOrder range(0, count($dataSeriesValues) - 1), // plotOrder
$dataSeriesLabels, // plotLabel $dataSeriesLabels, // plotLabel
@ -67,21 +75,21 @@ $series = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries(
$dataSeriesValues, // plotValues $dataSeriesValues, // plotValues
null, // plotDirection null, // plotDirection
null, // smooth line null, // smooth line
\PhpOffice\PhpSpreadsheet\Chart\DataSeries::STYLE_MARKER // plotStyle DataSeries::STYLE_MARKER // plotStyle
); );
// Set up a layout object for the Pie chart // Set up a layout object for the Pie chart
$layout = new \PhpOffice\PhpSpreadsheet\Chart\Layout(); $layout = new Chart\Layout();
// Set the series in the plot area // Set the series in the plot area
$plotArea = new \PhpOffice\PhpSpreadsheet\Chart\PlotArea($layout, [$series]); $plotArea = new PlotArea($layout, [$series]);
// Set the chart legend // Set the chart legend
$legend = new \PhpOffice\PhpSpreadsheet\Chart\Legend(\PhpOffice\PhpSpreadsheet\Chart\Legend::POSITION_RIGHT, null, false); $legend = new Legend(Legend::POSITION_RIGHT, null, false);
$title = new \PhpOffice\PhpSpreadsheet\Chart\Title('Test Radar Chart'); $title = new Title('Test Radar Chart');
// Create the chart // Create the chart
$chart = new \PhpOffice\PhpSpreadsheet\Chart( $chart = new Chart(
'chart1', // name 'chart1', // name
$title, // title $title, // title
$legend, // legend $legend, // legend
@ -101,7 +109,7 @@ $worksheet->addChart($chart);
// Save Excel 2007 file // Save Excel 2007 file
$filename = $helper->getFilename(__FILE__); $filename = $helper->getFilename(__FILE__);
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx'); $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->setIncludeCharts(true); $writer->setIncludeCharts(true);
$callStartTime = microtime(true); $callStartTime = microtime(true);
$writer->save($filename); $writer->save($filename);

View File

@ -1,9 +1,17 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Chart;
use PhpOffice\PhpSpreadsheet\Chart\DataSeries;
use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues;
use PhpOffice\PhpSpreadsheet\Chart\Legend;
use PhpOffice\PhpSpreadsheet\Chart\PlotArea;
use PhpOffice\PhpSpreadsheet\Chart\Title;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.php';
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet(); $worksheet = $spreadsheet->getActiveSheet();
$worksheet->fromArray( $worksheet->fromArray(
[ [
@ -23,13 +31,13 @@ $worksheet->fromArray(
// Data values // Data values
// Data Marker // Data Marker
$dataSeriesLabels = [ $dataSeriesLabels = [
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$B$1', null, 1), // 2010 new DataSeriesValues('String', 'Worksheet!$B$1', null, 1), // 2010
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$C$1', null, 1), // 2011 new DataSeriesValues('String', 'Worksheet!$C$1', null, 1), // 2011
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$D$1', null, 1), // 2012 new DataSeriesValues('String', 'Worksheet!$D$1', null, 1), // 2012
]; ];
// Set the X-Axis Labels // Set the X-Axis Labels
$xAxisTickValues = [ $xAxisTickValues = [
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4 new DataSeriesValues('String', 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4
]; ];
// Set the Data values for each data series we want to plot // Set the Data values for each data series we want to plot
// Datatype // Datatype
@ -39,14 +47,14 @@ $xAxisTickValues = [
// Data values // Data values
// Data Marker // Data Marker
$dataSeriesValues = [ $dataSeriesValues = [
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$B$2:$B$5', null, 4), new DataSeriesValues('Number', 'Worksheet!$B$2:$B$5', null, 4),
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', null, 4), new DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', null, 4),
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$D$2:$D$5', null, 4), new DataSeriesValues('Number', 'Worksheet!$D$2:$D$5', null, 4),
]; ];
// Build the dataseries // Build the dataseries
$series = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries( $series = new DataSeries(
\PhpOffice\PhpSpreadsheet\Chart\DataSeries::TYPE_SCATTERCHART, // plotType DataSeries::TYPE_SCATTERCHART, // plotType
null, // plotGrouping (Scatter charts don't have any grouping) null, // plotGrouping (Scatter charts don't have any grouping)
range(0, count($dataSeriesValues) - 1), // plotOrder range(0, count($dataSeriesValues) - 1), // plotOrder
$dataSeriesLabels, // plotLabel $dataSeriesLabels, // plotLabel
@ -54,19 +62,19 @@ $series = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries(
$dataSeriesValues, // plotValues $dataSeriesValues, // plotValues
null, // plotDirection null, // plotDirection
null, // smooth line null, // smooth line
\PhpOffice\PhpSpreadsheet\Chart\DataSeries::STYLE_LINEMARKER // plotStyle DataSeries::STYLE_LINEMARKER // plotStyle
); );
// Set the series in the plot area // Set the series in the plot area
$plotArea = new \PhpOffice\PhpSpreadsheet\Chart\PlotArea(null, [$series]); $plotArea = new PlotArea(null, [$series]);
// Set the chart legend // Set the chart legend
$legend = new \PhpOffice\PhpSpreadsheet\Chart\Legend(\PhpOffice\PhpSpreadsheet\Chart\Legend::POSITION_TOPRIGHT, null, false); $legend = new Legend(Legend::POSITION_TOPRIGHT, null, false);
$title = new \PhpOffice\PhpSpreadsheet\Chart\Title('Test Scatter Chart'); $title = new Title('Test Scatter Chart');
$yAxisLabel = new \PhpOffice\PhpSpreadsheet\Chart\Title('Value ($k)'); $yAxisLabel = new Title('Value ($k)');
// Create the chart // Create the chart
$chart = new \PhpOffice\PhpSpreadsheet\Chart( $chart = new Chart(
'chart1', // name 'chart1', // name
$title, // title $title, // title
$legend, // legend $legend, // legend
@ -86,7 +94,7 @@ $worksheet->addChart($chart);
// Save Excel 2007 file // Save Excel 2007 file
$filename = $helper->getFilename(__FILE__); $filename = $helper->getFilename(__FILE__);
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx'); $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->setIncludeCharts(true); $writer->setIncludeCharts(true);
$callStartTime = microtime(true); $callStartTime = microtime(true);
$writer->save($filename); $writer->save($filename);

View File

@ -1,9 +1,18 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Chart;
use PhpOffice\PhpSpreadsheet\Chart\DataSeries;
use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues;
use PhpOffice\PhpSpreadsheet\Chart\Legend;
use PhpOffice\PhpSpreadsheet\Chart\PlotArea;
use PhpOffice\PhpSpreadsheet\Chart\Title;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.php';
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet(); $worksheet = $spreadsheet->getActiveSheet();
$worksheet->fromArray( $worksheet->fromArray(
[ [
@ -18,7 +27,7 @@ $worksheet->fromArray(
'A1', 'A1',
true true
); );
$worksheet->getStyle('B2:E6')->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_NUMBER_00); $worksheet->getStyle('B2:E6')->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_NUMBER_00);
// Set the Labels for each data series we want to plot // Set the Labels for each data series we want to plot
// Datatype // Datatype
@ -28,10 +37,10 @@ $worksheet->getStyle('B2:E6')->getNumberFormat()->setFormatCode(\PhpOffice\PhpSp
// Data values // Data values
// Data Marker // Data Marker
$dataSeriesLabels = [ $dataSeriesLabels = [
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$B$1', null, 1), //Max / Open new DataSeriesValues('String', 'Worksheet!$B$1', null, 1), //Max / Open
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$C$1', null, 1), //Min / Close new DataSeriesValues('String', 'Worksheet!$C$1', null, 1), //Min / Close
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$D$1', null, 1), //Min Threshold / Min new DataSeriesValues('String', 'Worksheet!$D$1', null, 1), //Min Threshold / Min
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$E$1', null, 1), //Max Threshold / Max new DataSeriesValues('String', 'Worksheet!$E$1', null, 1), //Max Threshold / Max
]; ];
// Set the X-Axis Labels // Set the X-Axis Labels
// Datatype // Datatype
@ -41,7 +50,7 @@ $dataSeriesLabels = [
// Data values // Data values
// Data Marker // Data Marker
$xAxisTickValues = [ $xAxisTickValues = [
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('String', 'Worksheet!$A$2:$A$6', null, 5), // Counts new DataSeriesValues('String', 'Worksheet!$A$2:$A$6', null, 5), // Counts
]; ];
// Set the Data values for each data series we want to plot // Set the Data values for each data series we want to plot
// Datatype // Datatype
@ -51,15 +60,15 @@ $xAxisTickValues = [
// Data values // Data values
// Data Marker // Data Marker
$dataSeriesValues = [ $dataSeriesValues = [
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$B$2:$B$6', null, 5), new DataSeriesValues('Number', 'Worksheet!$B$2:$B$6', null, 5),
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$C$2:$C$6', null, 5), new DataSeriesValues('Number', 'Worksheet!$C$2:$C$6', null, 5),
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$D$2:$D$6', null, 5), new DataSeriesValues('Number', 'Worksheet!$D$2:$D$6', null, 5),
new \PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues('Number', 'Worksheet!$E$2:$E$6', null, 5), new DataSeriesValues('Number', 'Worksheet!$E$2:$E$6', null, 5),
]; ];
// Build the dataseries // Build the dataseries
$series = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries( $series = new DataSeries(
\PhpOffice\PhpSpreadsheet\Chart\DataSeries::TYPE_STOCKCHART, // plotType DataSeries::TYPE_STOCKCHART, // plotType
null, // plotGrouping - if we set this to not null, then xlsx throws error null, // plotGrouping - if we set this to not null, then xlsx throws error
range(0, count($dataSeriesValues) - 1), // plotOrder range(0, count($dataSeriesValues) - 1), // plotOrder
$dataSeriesLabels, // plotLabel $dataSeriesLabels, // plotLabel
@ -68,16 +77,16 @@ $series = new \PhpOffice\PhpSpreadsheet\Chart\DataSeries(
); );
// Set the series in the plot area // Set the series in the plot area
$plotArea = new \PhpOffice\PhpSpreadsheet\Chart\PlotArea(null, [$series]); $plotArea = new PlotArea(null, [$series]);
// Set the chart legend // Set the chart legend
$legend = new \PhpOffice\PhpSpreadsheet\Chart\Legend(\PhpOffice\PhpSpreadsheet\Chart\Legend::POSITION_RIGHT, null, false); $legend = new Legend(Legend::POSITION_RIGHT, null, false);
$title = new \PhpOffice\PhpSpreadsheet\Chart\Title('Test Stock Chart'); $title = new Title('Test Stock Chart');
$xAxisLabel = new \PhpOffice\PhpSpreadsheet\Chart\Title('Counts'); $xAxisLabel = new Title('Counts');
$yAxisLabel = new \PhpOffice\PhpSpreadsheet\Chart\Title('Values'); $yAxisLabel = new Title('Values');
// Create the chart // Create the chart
$chart = new \PhpOffice\PhpSpreadsheet\Chart( $chart = new Chart(
'stock-chart', // name 'stock-chart', // name
$title, // title $title, // title
$legend, // legend $legend, // legend
@ -97,7 +106,7 @@ $worksheet->addChart($chart);
// Save Excel 2007 file // Save Excel 2007 file
$filename = $helper->getFilename(__FILE__); $filename = $helper->getFilename(__FILE__);
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx'); $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->setIncludeCharts(true); $writer->setIncludeCharts(true);
$callStartTime = microtime(true); $callStartTime = microtime(true);
$writer->save($filename); $writer->save($filename);

View File

@ -1,16 +1,18 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.php';
// Create temporary file that will be read // Create temporary file that will be read
$sampleSpreadsheet = require __DIR__ . '/templates/chartSpreadsheet.php'; $sampleSpreadsheet = require __DIR__ . '/templates/chartSpreadsheet.php';
$filename = $helper->getTemporaryFilename(); $filename = $helper->getTemporaryFilename();
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($sampleSpreadsheet); $writer = new Xlsx($sampleSpreadsheet);
$writer->save($filename); $writer->save($filename);
$helper->log('Load from Xlsx file'); $helper->log('Load from Xlsx file');
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xlsx'); $reader = IOFactory::createReader('Xlsx');
$reader->setIncludeCharts(true); $reader->setIncludeCharts(true);
$spreadsheet = $reader->load($filename); $spreadsheet = $reader->load($filename);
@ -29,7 +31,7 @@ $worksheet->fromArray(
// Save Excel 2007 file // Save Excel 2007 file
$filename = $helper->getFilename(__FILE__); $filename = $helper->getFilename(__FILE__);
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx'); $writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->setIncludeCharts(true); $writer->setIncludeCharts(true);
$callStartTime = microtime(true); $callStartTime = microtime(true);
$writer->save($filename); $writer->save($filename);

View File

@ -1,14 +1,17 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Settings;
require __DIR__ . '/Header.php'; require __DIR__ . '/Header.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 = \PhpOffice\PhpSpreadsheet\Settings::CHART_RENDERER_JPGRAPH; $rendererName = Settings::CHART_RENDERER_JPGRAPH;
$rendererLibrary = 'jpgraph3.5.0b1/src/'; $rendererLibrary = 'jpgraph3.5.0b1/src/';
$rendererLibraryPath = '/php/libraries/Charts/' . $rendererLibrary; $rendererLibraryPath = '/php/libraries/Charts/' . $rendererLibrary;
if (!\PhpOffice\PhpSpreadsheet\Settings::setChartRenderer($rendererName, $rendererLibraryPath)) { if (!Settings::setChartRenderer($rendererName, $rendererLibraryPath)) {
$helper->log('NOTICE: Please set the $rendererName and $rendererLibraryPath values at the top of this script as appropriate for your directory structure'); $helper->log('NOTICE: Please set the $rendererName and $rendererLibraryPath values at the top of this script as appropriate for your directory structure');
return; return;
@ -35,7 +38,7 @@ foreach ($inputFileNames as $inputFileName) {
$helper->log("Load Test from $inputFileType file ", $inputFileNameShort); $helper->log("Load Test from $inputFileType file ", $inputFileNameShort);
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); $reader = IOFactory::createReader($inputFileType);
$reader->setIncludeCharts(true); $reader->setIncludeCharts(true);
$spreadsheet = $reader->load($inputFileName); $spreadsheet = $reader->load($inputFileName);

Some files were not shown because too many files have changed in this diff Show More