Merge all examples together

Closes #17
This commit is contained in:
Adrien Crivelli 2017-10-01 17:48:59 +09:00
parent 29208e9d99
commit 50a0ec58af
No known key found for this signature in database
GPG Key ID: B182FD79DC6DE92E
174 changed files with 1878 additions and 2830 deletions

View File

@ -25,7 +25,7 @@
"scripts": { "scripts": {
"check": [ "check": [
"php-cs-fixer fix --ansi --dry-run --diff", "php-cs-fixer fix --ansi --dry-run --diff",
"phpcs --report-width=200 --report-summary --report-full samples/ src/ tests/ --standard=PSR2 -n", "phpcs --report-width=200 --report-summary --report-full samples/ src/ tests/ --ignore=samples/Header.php --standard=PSR2 -n",
"phpunit --color=always" "phpunit --color=always"
] ]
}, },

View File

@ -1,78 +0,0 @@
<?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
error_reporting(E_ALL);
set_time_limit(0);
date_default_timezone_set('Europe/London');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PhpSpreadsheet Calculation Examples</title>
</head>
<body>
<h1>DAVERAGE</h1>
<h2>Returns the average of selected database entries.</h2>
<?php
require_once __DIR__ . '/../../../../src/Bootstrap.php';
// Create new PhpSpreadsheet object
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
// Add some data
$database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'],
['Apple', 18, 20, 14, 105.00],
['Pear', 12, 12, 10, 96.00],
['Cherry', 13, 14, 9, 105.00],
['Apple', 14, 15, 10, 75.00],
['Pear', 9, 8, 8, 76.80],
['Apple', 8, 9, 6, 45.00],
];
$criteria = [['Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height'],
['="=Apple"', '>10', null, null, null, '<16'],
['="=Pear"', null, null, null, null, null],
];
$worksheet->fromArray($criteria, null, 'A1');
$worksheet->fromArray($database, null, 'A4');
$worksheet->setCellValue('A12', 'The Average yield of Apple trees over 10\' in height');
$worksheet->setCellValue('B12', '=DAVERAGE(A4:E10,"Yield",A1:B2)');
$worksheet->setCellValue('A13', 'The Average age of all Apple and Pear trees in the orchard');
$worksheet->setCellValue('B13', '=DAVERAGE(A4:E10,3,A1:A3)');
echo '<hr />';
echo '<h4>Database</h4>';
$databaseData = $worksheet->rangeToArray('A4:E10', null, true, true, true);
var_dump($databaseData);
echo '<hr />';
// Test the formulae
echo '<h4>Criteria</h4>';
$criteriaData = $worksheet->rangeToArray('A1:B2', null, true, true, true);
var_dump($criteriaData);
echo $worksheet->getCell('A12')->getValue() . '<br />';
echo 'DAVERAGE() Result is ' . $worksheet->getCell('B12')->getCalculatedValue() . '<br /><br />';
echo '<h4>Criteria</h4>';
$criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true);
var_dump($criteriaData);
echo $worksheet->getCell('A13')->getValue() . '<br />';
echo 'DAVERAGE() Result is ' . $worksheet->getCell('B13')->getCalculatedValue();
?>
<body>
</html>

View File

@ -1,78 +0,0 @@
<?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
error_reporting(E_ALL);
set_time_limit(0);
date_default_timezone_set('Europe/London');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PhpSpreadsheet Calculation Examples</title>
</head>
<body>
<h1>DCOUNT</h1>
<h2>Counts the cells that contain numbers in a database.</h2>
<?php
require_once __DIR__ . '/../../../../src/Bootstrap.php';
// Create new PhpSpreadsheet object
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
// Add some data
$database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'],
['Apple', 18, 20, 14, 105.00],
['Pear', 12, 12, 10, 96.00],
['Cherry', 13, 14, 9, 105.00],
['Apple', 14, 15, 10, 75.00],
['Pear', 9, 8, 8, 76.80],
['Apple', 8, 9, 6, 45.00],
];
$criteria = [['Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height'],
['="=Apple"', '>10', null, null, null, '<16'],
['="=Pear"', null, null, null, null, null],
];
$worksheet->fromArray($criteria, null, 'A1');
$worksheet->fromArray($database, null, 'A4');
$worksheet->setCellValue('A12', 'The Number of Apple trees over 10\' in height');
$worksheet->setCellValue('B12', '=DCOUNT(A4:E10,"Yield",A1:B2)');
$worksheet->setCellValue('A13', 'The Number of Apple and Pear trees in the orchard');
$worksheet->setCellValue('B13', '=DCOUNT(A4:E10,3,A1:A3)');
echo '<hr />';
echo '<h4>Database</h4>';
$databaseData = $worksheet->rangeToArray('A4:E10', null, true, true, true);
var_dump($databaseData);
echo '<hr />';
// Test the formulae
echo '<h4>Criteria</h4>';
$criteriaData = $worksheet->rangeToArray('A1:B2', null, true, true, true);
var_dump($criteriaData);
echo $worksheet->getCell('A12')->getValue() . '<br />';
echo 'DCOUNT() Result is ' . $worksheet->getCell('B12')->getCalculatedValue() . '<br /><br />';
echo '<h4>Criteria</h4>';
$criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true);
var_dump($criteriaData);
echo $worksheet->getCell('A13')->getValue() . '<br />';
echo 'DCOUNT() Result is ' . $worksheet->getCell('B13')->getCalculatedValue();
?>
<body>
</html>

View File

@ -1,74 +0,0 @@
<?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
error_reporting(E_ALL);
set_time_limit(0);
date_default_timezone_set('Europe/London');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PhpSpreadsheet Calculation Examples</title>
</head>
<body>
<h1>DGET</h1>
<h2>Extracts a single value from a column of a list or database that matches conditions that you specify.</h2>
<?php
require_once __DIR__ . '/../../../../src/Bootstrap.php';
// Create new PhpSpreadsheet object
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
// Add some data
$database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'],
['Apple', 18, 20, 14, 105.00],
['Pear', 12, 12, 10, 96.00],
['Cherry', 13, 14, 9, 105.00],
['Apple', 14, 15, 10, 75.00],
['Pear', 9, 8, 8, 76.80],
['Apple', 8, 9, 6, 45.00],
];
$criteria = [['Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height'],
['="=Apple"', '>10', null, null, null, '<16'],
['="=Pear"', null, null, null, null, null],
];
$worksheet->fromArray($criteria, null, 'A1');
$worksheet->fromArray($database, null, 'A4');
$worksheet->setCellValue('A12', 'The height of the Apple tree between 10\' and 16\' tall');
$worksheet->setCellValue('B12', '=DGET(A4:E10,"Height",A1:F2)');
echo '<hr />';
echo '<h4>Database</h4>';
$databaseData = $worksheet->rangeToArray('A4:E10', null, true, true, true);
var_dump($databaseData);
echo '<hr />';
// Test the formulae
echo '<h4>Criteria</h4>';
echo 'ALL' . '<br /><br />';
echo $worksheet->getCell('A12')->getValue() . '<br />';
echo 'DMAX() Result is ' . $worksheet->getCell('B12')->getCalculatedValue() . '<br /><br />';
echo '<h4>Criteria</h4>';
$criteriaData = $worksheet->rangeToArray('A1:A2', null, true, true, true);
var_dump($criteriaData);
echo $worksheet->getCell('A13')->getValue() . '<br />';
echo 'DMAX() Result is ' . $worksheet->getCell('B13')->getCalculatedValue();
?>
<body>
</html>

View File

@ -1,77 +0,0 @@
<?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
error_reporting(E_ALL);
set_time_limit(0);
date_default_timezone_set('Europe/London');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PhpSpreadsheet Calculation Examples</title>
</head>
<body>
<h1>DMAX</h1>
<h2>Returns the maximum value from selected database entries.</h2>
<?php
require_once __DIR__ . '/../../../../src/Bootstrap.php';
// Create new PhpSpreadsheet object
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
// Add some data
$database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'],
['Apple', 18, 20, 14, 105.00],
['Pear', 12, 12, 10, 96.00],
['Cherry', 13, 14, 9, 105.00],
['Apple', 14, 15, 10, 75.00],
['Pear', 9, 8, 8, 76.80],
['Apple', 8, 9, 6, 45.00],
];
$criteria = [['Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height'],
['="=Apple"', '>10', null, null, null, '<16'],
['="=Pear"', null, null, null, null, null],
];
$worksheet->fromArray($criteria, null, 'A1');
$worksheet->fromArray($database, null, 'A4');
$worksheet->setCellValue('A12', 'The tallest tree in the orchard');
$worksheet->setCellValue('B12', '=DMAX(A4:E10,"Height",A4:E10)');
$worksheet->setCellValue('A13', 'The Oldest apple tree in the orchard');
$worksheet->setCellValue('B13', '=DMAX(A4:E10,3,A1:A2)');
echo '<hr />';
echo '<h4>Database</h4>';
$databaseData = $worksheet->rangeToArray('A4:E10', null, true, true, true);
var_dump($databaseData);
echo '<hr />';
// Test the formulae
echo '<h4>Criteria</h4>';
echo 'ALL' . '<br /><br />';
echo $worksheet->getCell('A12')->getValue() . '<br />';
echo 'DMAX() Result is ' . $worksheet->getCell('B12')->getCalculatedValue() . '<br /><br />';
echo '<h4>Criteria</h4>';
$criteriaData = $worksheet->rangeToArray('A1:A2', null, true, true, true);
var_dump($criteriaData);
echo $worksheet->getCell('A13')->getValue() . '<br />';
echo 'DMAX() Result is ' . $worksheet->getCell('B13')->getCalculatedValue();
?>
<body>
</html>

View File

@ -1,77 +0,0 @@
<?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
error_reporting(E_ALL);
set_time_limit(0);
date_default_timezone_set('Europe/London');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PhpSpreadsheet Calculation Examples</title>
</head>
<body>
<h1>DMIN</h1>
<h2>Returns the minimum value from selected database entries.</h2>
<?php
require_once __DIR__ . '/../../../../src/Bootstrap.php';
// Create new PhpSpreadsheet object
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
// Add some data
$database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'],
['Apple', 18, 20, 14, 105.00],
['Pear', 12, 12, 10, 96.00],
['Cherry', 13, 14, 9, 105.00],
['Apple', 14, 15, 10, 75.00],
['Pear', 9, 8, 8, 76.80],
['Apple', 8, 9, 6, 45.00],
];
$criteria = [['Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height'],
['="=Apple"', '>10', null, null, null, '<16'],
['="=Pear"', null, null, null, null, null],
];
$worksheet->fromArray($criteria, null, 'A1');
$worksheet->fromArray($database, null, 'A4');
$worksheet->setCellValue('A12', 'The shortest tree in the orchard');
$worksheet->setCellValue('B12', '=DMIN(A4:E10,"Height",A4:E10)');
$worksheet->setCellValue('A13', 'The Youngest apple tree in the orchard');
$worksheet->setCellValue('B13', '=DMIN(A4:E10,3,A1:A2)');
echo '<hr />';
echo '<h4>Database</h4>';
$databaseData = $worksheet->rangeToArray('A4:E10', null, true, true, true);
var_dump($databaseData);
echo '<hr />';
// Test the formulae
echo '<h4>Criteria</h4>';
echo 'ALL' . '<br /><br />';
echo $worksheet->getCell('A12')->getValue() . '<br />';
echo 'DMIN() Result is ' . $worksheet->getCell('B12')->getCalculatedValue() . '<br /><br />';
echo '<h4>Criteria</h4>';
$criteriaData = $worksheet->rangeToArray('A1:A2', null, true, true, true);
var_dump($criteriaData);
echo $worksheet->getCell('A13')->getValue() . '<br />';
echo 'DMIN() Result is ' . $worksheet->getCell('B13')->getCalculatedValue();
?>
<body>
</html>

View File

@ -1,74 +0,0 @@
<?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
error_reporting(E_ALL);
set_time_limit(0);
date_default_timezone_set('Europe/London');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PhpSpreadsheet Calculation Examples</title>
</head>
<body>
<h1>DPRODUCT</h1>
<h2>Multiplies the values in a column of a list or database that match conditions that you specify.</h2>
<?php
require_once __DIR__ . '/../../../../src/Bootstrap.php';
// Create new PhpSpreadsheet object
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
// Add some data
$database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'],
['Apple', 18, 20, 14, 105.00],
['Pear', 12, 12, 10, 96.00],
['Cherry', 13, 14, 9, 105.00],
['Apple', 14, 15, 10, 75.00],
['Pear', 9, 8, 8, 76.80],
['Apple', 8, 9, 6, 45.00],
];
$criteria = [['Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height'],
['="=Apple"', '>10', null, null, null, '<16'],
['="=Pear"', null, null, null, null, null],
];
$worksheet->fromArray($criteria, null, 'A1');
$worksheet->fromArray($database, null, 'A4');
$worksheet->setCellValue('A12', 'The product of the yields of all Apple trees over 10\' in the orchard');
$worksheet->setCellValue('B12', '=DPRODUCT(A4:E10,"Yield",A1:B2)');
echo '<hr />';
echo '<h4>Database</h4>';
$databaseData = $worksheet->rangeToArray('A4:E10', null, true, true, true);
var_dump($databaseData);
echo '<hr />';
// Test the formulae
echo '<h4>Criteria</h4>';
echo 'ALL' . '<br /><br />';
echo $worksheet->getCell('A12')->getValue() . '<br />';
echo 'DMAX() Result is ' . $worksheet->getCell('B12')->getCalculatedValue() . '<br /><br />';
echo '<h4>Criteria</h4>';
$criteriaData = $worksheet->rangeToArray('A1:A2', null, true, true, true);
var_dump($criteriaData);
echo $worksheet->getCell('A13')->getValue() . '<br />';
echo 'DMAX() Result is ' . $worksheet->getCell('B13')->getCalculatedValue();
?>
<body>
</html>

View File

@ -1,78 +0,0 @@
<?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
error_reporting(E_ALL);
set_time_limit(0);
date_default_timezone_set('Europe/London');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PhpSpreadsheet Calculation Examples</title>
</head>
<body>
<h1>DSTDEV</h1>
<h2>Estimates the standard deviation based on a sample of selected database entries.</h2>
<?php
require_once __DIR__ . '/../../../../src/Bootstrap.php';
// Create new PhpSpreadsheet object
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
// Add some data
$database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'],
['Apple', 18, 20, 14, 105.00],
['Pear', 12, 12, 10, 96.00],
['Cherry', 13, 14, 9, 105.00],
['Apple', 14, 15, 10, 75.00],
['Pear', 9, 8, 8, 76.80],
['Apple', 8, 9, 6, 45.00],
];
$criteria = [['Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height'],
['="=Apple"', '>10', null, null, null, '<16'],
['="=Pear"', null, null, null, null, null],
];
$worksheet->fromArray($criteria, null, 'A1');
$worksheet->fromArray($database, null, 'A4');
$worksheet->setCellValue('A12', 'The estimated standard deviation in the yield of Apple and Pear trees');
$worksheet->setCellValue('B12', '=DSTDEV(A4:E10,"Yield",A1:A3)');
$worksheet->setCellValue('A13', 'The estimated standard deviation in height of Apple and Pear trees');
$worksheet->setCellValue('B13', '=DSTDEV(A4:E10,2,A1:A3)');
echo '<hr />';
echo '<h4>Database</h4>';
$databaseData = $worksheet->rangeToArray('A4:E10', null, true, true, true);
var_dump($databaseData);
echo '<hr />';
// Test the formulae
echo '<h4>Criteria</h4>';
$criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true);
var_dump($criteriaData);
echo $worksheet->getCell('A12')->getValue() . '<br />';
echo 'DSTDEV() Result is ' . $worksheet->getCell('B12')->getCalculatedValue() . '<br /><br />';
echo '<h4>Criteria</h4>';
$criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true);
var_dump($criteriaData);
echo $worksheet->getCell('A13')->getValue() . '<br />';
echo 'DSTDEV() Result is ' . $worksheet->getCell('B13')->getCalculatedValue();
?>
<body>
</html>

View File

@ -1,78 +0,0 @@
<?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
error_reporting(E_ALL);
set_time_limit(0);
date_default_timezone_set('Europe/London');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PhpSpreadsheet Calculation Examples</title>
</head>
<body>
<h1>DSTDEVP</h1>
<h2>Calculates the standard deviation based on the entire population of selected database entries.</h2>
<?php
require_once __DIR__ . '/../../../../src/Bootstrap.php';
// Create new PhpSpreadsheet object
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
// Add some data
$database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'],
['Apple', 18, 20, 14, 105.00],
['Pear', 12, 12, 10, 96.00],
['Cherry', 13, 14, 9, 105.00],
['Apple', 14, 15, 10, 75.00],
['Pear', 9, 8, 8, 76.80],
['Apple', 8, 9, 6, 45.00],
];
$criteria = [['Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height'],
['="=Apple"', '>10', null, null, null, '<16'],
['="=Pear"', null, null, null, null, null],
];
$worksheet->fromArray($criteria, null, 'A1');
$worksheet->fromArray($database, null, 'A4');
$worksheet->setCellValue('A12', 'The standard deviation in the yield of Apple and Pear trees');
$worksheet->setCellValue('B12', '=DSTDEVP(A4:E10,"Yield",A1:A3)');
$worksheet->setCellValue('A13', 'The standard deviation in height of Apple and Pear trees');
$worksheet->setCellValue('B13', '=DSTDEVP(A4:E10,2,A1:A3)');
echo '<hr />';
echo '<h4>Database</h4>';
$databaseData = $worksheet->rangeToArray('A4:E10', null, true, true, true);
var_dump($databaseData);
echo '<hr />';
// Test the formulae
echo '<h4>Criteria</h4>';
$criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true);
var_dump($criteriaData);
echo $worksheet->getCell('A12')->getValue() . '<br />';
echo 'DSTDEVP() Result is ' . $worksheet->getCell('B12')->getCalculatedValue() . '<br /><br />';
echo '<h4>Criteria</h4>';
$criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true);
var_dump($criteriaData);
echo $worksheet->getCell('A13')->getValue() . '<br />';
echo 'DSTDEVP() Result is ' . $worksheet->getCell('B13')->getCalculatedValue();
?>
<body>
</html>

View File

@ -1,78 +0,0 @@
<?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
error_reporting(E_ALL);
set_time_limit(0);
date_default_timezone_set('Europe/London');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PhpSpreadsheet Calculation Examples</title>
</head>
<body>
<h1>DVAR</h1>
<h2>Estimates variance based on a sample from selected database entries.</h2>
<?php
require_once __DIR__ . '/../../../../src/Bootstrap.php';
// Create new PhpSpreadsheet object
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
// Add some data
$database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'],
['Apple', 18, 20, 14, 105.00],
['Pear', 12, 12, 10, 96.00],
['Cherry', 13, 14, 9, 105.00],
['Apple', 14, 15, 10, 75.00],
['Pear', 9, 8, 8, 76.80],
['Apple', 8, 9, 6, 45.00],
];
$criteria = [['Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height'],
['="=Apple"', '>10', null, null, null, '<16'],
['="=Pear"', null, null, null, null, null],
];
$worksheet->fromArray($criteria, null, 'A1');
$worksheet->fromArray($database, null, 'A4');
$worksheet->setCellValue('A12', 'The estimated variance in the yield of Apple and Pear trees');
$worksheet->setCellValue('B12', '=DVAR(A4:E10,"Yield",A1:A3)');
$worksheet->setCellValue('A13', 'The estimated variance in height of Apple and Pear trees');
$worksheet->setCellValue('B13', '=DVAR(A4:E10,2,A1:A3)');
echo '<hr />';
echo '<h4>Database</h4>';
$databaseData = $worksheet->rangeToArray('A4:E10', null, true, true, true);
var_dump($databaseData);
echo '<hr />';
// Test the formulae
echo '<h4>Criteria</h4>';
$criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true);
var_dump($criteriaData);
echo $worksheet->getCell('A12')->getValue() . '<br />';
echo 'DVAR() Result is ' . $worksheet->getCell('B12')->getCalculatedValue() . '<br /><br />';
echo '<h4>Criteria</h4>';
$criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true);
var_dump($criteriaData);
echo $worksheet->getCell('A13')->getValue() . '<br />';
echo 'DVAR() Result is ' . $worksheet->getCell('B13')->getCalculatedValue();
?>
<body>
</html>

View File

@ -1,78 +0,0 @@
<?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
error_reporting(E_ALL);
set_time_limit(0);
date_default_timezone_set('Europe/London');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PhpSpreadsheet Calculation Examples</title>
</head>
<body>
<h1>DVARP</h1>
<h2>Calculates variance based on the entire population of selected database entries,</h2>
<?php
require_once __DIR__ . '/../../../../src/Bootstrap.php';
// Create new PhpSpreadsheet object
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
// Add some data
$database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'],
['Apple', 18, 20, 14, 105.00],
['Pear', 12, 12, 10, 96.00],
['Cherry', 13, 14, 9, 105.00],
['Apple', 14, 15, 10, 75.00],
['Pear', 9, 8, 8, 76.80],
['Apple', 8, 9, 6, 45.00],
];
$criteria = [['Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height'],
['="=Apple"', '>10', null, null, null, '<16'],
['="=Pear"', null, null, null, null, null],
];
$worksheet->fromArray($criteria, null, 'A1');
$worksheet->fromArray($database, null, 'A4');
$worksheet->setCellValue('A12', 'The variance in the yield of Apple and Pear trees');
$worksheet->setCellValue('B12', '=DVARP(A4:E10,"Yield",A1:A3)');
$worksheet->setCellValue('A13', 'The variance in height of Apple and Pear trees');
$worksheet->setCellValue('B13', '=DVARP(A4:E10,2,A1:A3)');
echo '<hr />';
echo '<h4>Database</h4>';
$databaseData = $worksheet->rangeToArray('A4:E10', null, true, true, true);
var_dump($databaseData);
echo '<hr />';
// Test the formulae
echo '<h4>Criteria</h4>';
$criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true);
var_dump($criteriaData);
echo $worksheet->getCell('A12')->getValue() . '<br />';
echo 'DVARP() Result is ' . $worksheet->getCell('B12')->getCalculatedValue() . '<br /><br />';
echo '<h4>Criteria</h4>';
$criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true);
var_dump($criteriaData);
echo $worksheet->getCell('A13')->getValue() . '<br />';
echo 'DVARP() Result is ' . $worksheet->getCell('B13')->getCalculatedValue();
?>
<body>
</html>

View File

@ -1,77 +0,0 @@
<?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
error_reporting(E_ALL);
set_time_limit(0);
date_default_timezone_set('Europe/London');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PhpSpreadsheet Calculation Examples</title>
</head>
<body>
<h1>DATE</h1>
<h2>Returns the serial number of a particular date.</h2>
<?php
require_once __DIR__ . '/../../../../src/Bootstrap.php';
// Create new PhpSpreadsheet object
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
// Add some data
$testDates = [[2012, 3, 26], [2012, 2, 29], [2012, 4, 1], [2012, 12, 25],
[2012, 10, 31], [2012, 11, 5], [2012, 1, 1], [2012, 3, 17],
[2011, 2, 29], [7, 5, 3], [2012, 13, 1], [2012, 11, 45],
[2012, 0, 0], [2012, 1, 0], [2012, 0, 1],
[2012, -2, 2], [2012, 2, -2], [2012, -2, -2],
];
$testDateCount = count($testDates);
$worksheet->fromArray($testDates, null, 'A1', true);
for ($row = 1; $row <= $testDateCount; ++$row) {
$worksheet->setCellValue('D' . $row, '=DATE(A' . $row . ',B' . $row . ',C' . $row . ')');
$worksheet->setCellValue('E' . $row, '=D' . $row);
}
$worksheet->getStyle('E1:E' . $testDateCount)
->getNumberFormat()
->setFormatCode('yyyy-mmm-dd');
echo '<hr />';
// Test the formulae
?>
<table border="1" cellspacing="0">
<tr>
<th colspan="3">Date Value</th>
<th rowspan="2" valign="bottom">Formula</th>
<th rowspan="2" valign="bottom">Excel DateStamp</th>
<th rowspan="2" valign="bottom">Formatted DateStamp</th>
</tr>
<tr>
<th>Year</th>
<th>Month</th>
<th>Day</th>
<tr>
<?php
for ($row = 1; $row <= $testDateCount; ++$row) {
echo '<tr>';
echo '<td>', $worksheet->getCell('A' . $row)->getFormattedValue(), '</td>';
echo '<td>', $worksheet->getCell('B' . $row)->getFormattedValue(), '</td>';
echo '<td>', $worksheet->getCell('C' . $row)->getFormattedValue(), '</td>';
echo '<td>', $worksheet->getCell('D' . $row)->getValue(), '</td>';
echo '<td>', $worksheet->getCell('D' . $row)->getFormattedValue(), '</td>';
echo '<td>', $worksheet->getCell('E' . $row)->getFormattedValue(), '</td>';
echo '</tr>';
}
?>
</table>
</body>
</html>

View File

@ -1,70 +0,0 @@
<?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
error_reporting(E_ALL);
set_time_limit(0);
date_default_timezone_set('Europe/London');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PhpSpreadsheet Calculation Examples</title>
</head>
<body>
<h1>DATEVALUE</h1>
<h2>Converts a date in the form of text to a serial number.</h2>
<?php
require_once __DIR__ . '/../../../../src/Bootstrap.php';
// Create new PhpSpreadsheet object
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
// Add some data
$testDates = ['26 March 2012', '29 Feb 2012', 'April 1, 2012', '25/12/2012',
'2012-Oct-31', '5th November', 'January 1st', 'April 2012',
'17-03', '03-2012', '29 Feb 2011', '03-05-07',
'03-MAY-07', '03-13-07',
];
$testDateCount = count($testDates);
for ($row = 1; $row <= $testDateCount; ++$row) {
$worksheet->setCellValue('A' . $row, $testDates[$row - 1]);
$worksheet->setCellValue('B' . $row, '=DATEVALUE(A' . $row . ')');
$worksheet->setCellValue('C' . $row, '=B' . $row);
}
$worksheet->getStyle('C1:C' . $testDateCount)
->getNumberFormat()
->setFormatCode('yyyy-mmm-dd');
echo '<hr />';
// Test the formulae
?>
<p><strong>Warning: </strong>The PhpSpreadsheet DATEVALUE() function accepts a wider range of date formats than MS Excel's DATEFORMAT() function.</p>
<table border="1" cellspacing="0">
<tr>
<th>Date String</th>
<th>Formula</th>
<th>Excel DateStamp</th>
<th>Formatted DateStamp</th>
</tr>
<?php
for ($row = 1; $row <= $testDateCount; ++$row) {
echo '<tr>';
echo '<td>', $worksheet->getCell('A' . $row)->getFormattedValue(), '</td>';
echo '<td>', $worksheet->getCell('B' . $row)->getValue(), '</td>';
echo '<td>', $worksheet->getCell('B' . $row)->getFormattedValue(), '</td>';
echo '<td>', $worksheet->getCell('C' . $row)->getFormattedValue(), '</td>';
echo '</tr>';
}
?>
</table>
</body>
</html>

View File

@ -1,75 +0,0 @@
<?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
error_reporting(E_ALL);
set_time_limit(0);
date_default_timezone_set('Europe/London');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PhpSpreadsheet Calculation Examples</title>
</head>
<body>
<h1>TIME</h1>
<h2>Returns the serial number of a particular time.</h2>
<?php
require_once __DIR__ . '/../../../../src/Bootstrap.php';
// Create new PhpSpreadsheet object
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
// Add some data
$testDates = [[3, 15], [13, 15], [15, 15, 15], [3, 15, 30],
[15, 15, 15], [5], [9, 15, 0], [9, 15, -1],
[13, -14, -15], [0, 0, -1],
];
$testDateCount = count($testDates);
$worksheet->fromArray($testDates, null, 'A1', true);
for ($row = 1; $row <= $testDateCount; ++$row) {
$worksheet->setCellValue('D' . $row, '=TIME(A' . $row . ',B' . $row . ',C' . $row . ')');
$worksheet->setCellValue('E' . $row, '=D' . $row);
}
$worksheet->getStyle('E1:E' . $testDateCount)
->getNumberFormat()
->setFormatCode('hh:mm:ss');
echo '<hr />';
// Test the formulae
?>
<table border="1" cellspacing="0">
<tr>
<th colspan="3">Date Value</th>
<th rowspan="2" valign="bottom">Formula</th>
<th rowspan="2" valign="bottom">Excel TimeStamp</th>
<th rowspan="2" valign="bottom">Formatted TimeStamp</th>
</tr>
<tr>
<th>Hour</th>
<th>Minute</th>
<th>Second</th>
<tr>
<?php
for ($row = 1; $row <= $testDateCount; ++$row) {
echo '<tr>';
echo '<td>', $worksheet->getCell('A' . $row)->getFormattedValue(), '</td>';
echo '<td>', $worksheet->getCell('B' . $row)->getFormattedValue(), '</td>';
echo '<td>', $worksheet->getCell('C' . $row)->getFormattedValue(), '</td>';
echo '<td>', $worksheet->getCell('D' . $row)->getValue(), '</td>';
echo '<td>', $worksheet->getCell('D' . $row)->getFormattedValue(), '</td>';
echo '<td>', $worksheet->getCell('E' . $row)->getFormattedValue(), '</td>';
echo '</tr>';
}
?>
</table>
</body>
</html>

View File

@ -1,66 +0,0 @@
<?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
error_reporting(E_ALL);
set_time_limit(0);
date_default_timezone_set('Europe/London');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PhpSpreadsheet Calculation Examples</title>
</head>
<body>
<h1>TIMEVALUE</h1>
<h2>Converts a time in the form of text to a serial number.</h2>
<?php
require_once __DIR__ . '/../../../../src/Bootstrap.php';
// Create new PhpSpreadsheet object
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
// Add some data
$testDates = ['3:15', '13:15', '15:15:15', '3:15 AM', '3:15 PM', '5PM', '9:15AM', '13:15AM',
];
$testDateCount = count($testDates);
for ($row = 1; $row <= $testDateCount; ++$row) {
$worksheet->setCellValue('A' . $row, $testDates[$row - 1]);
$worksheet->setCellValue('B' . $row, '=TIMEVALUE(A' . $row . ')');
$worksheet->setCellValue('C' . $row, '=B' . $row);
}
$worksheet->getStyle('C1:C' . $testDateCount)
->getNumberFormat()
->setFormatCode('hh:mm:ss');
echo '<hr />';
// Test the formulae
?>
<table border="1" cellspacing="0">
<tr>
<th>Time String</th>
<th>Formula</th>
<th>Excel TimeStamp</th>
<th>Formatted TimeStamp</th>
</tr>
<?php
for ($row = 1; $row <= $testDateCount; ++$row) {
echo '<tr>';
echo '<td>', $worksheet->getCell('A' . $row)->getFormattedValue(), '</td>';
echo '<td>', $worksheet->getCell('B' . $row)->getValue(), '</td>';
echo '<td>', $worksheet->getCell('B' . $row)->getFormattedValue(), '</td>';
echo '<td>', $worksheet->getCell('C' . $row)->getFormattedValue(), '</td>';
echo '</tr>';
}
?>
</table>
</body>
</html>

View File

@ -1,45 +0,0 @@
<?php
error_reporting(E_ALL);
set_time_limit(0);
date_default_timezone_set('Europe/London');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PhpSpreadsheet Calculation Function Examples</title>
</head>
<body>
<?php
echo '<h1>PhpSpreadsheet Calculation Function Examples</h1>';
$exampleTypeList = glob('./*', GLOB_ONLYDIR);
foreach ($exampleTypeList as $exampleType) {
echo '<h2>' . pathinfo($exampleType, PATHINFO_BASENAME) . ' Function Examples</h2>';
$exampleList = glob('./' . $exampleType . '/*.php');
foreach ($exampleList as $exampleFile) {
$fileData = file_get_contents($exampleFile);
$h1Pattern = '#<h1>(.*?)</h1>#';
$h2Pattern = '#<h2>(.*?)</h2>#';
if (preg_match($h1Pattern, $fileData, $out)) {
$h1Text = $out[1];
$h2Text = (preg_match($h2Pattern, $fileData, $out)) ? $out[1] : '';
echo '<a href="', $exampleFile, '">', $h1Text, '</a><br />';
if ($h2Text > '') {
echo $h2Text, '<br />';
}
}
}
}
?>
<body>
</html>

View File

@ -1,34 +0,0 @@
<?php
use PhpOffice\PhpSpreadsheet\IOFactory;
error_reporting(E_ALL);
set_time_limit(0);
date_default_timezone_set('Europe/London');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PhpSpreadsheet Reader Example #01</title>
</head>
<body>
<h1>PhpSpreadsheet Reader Example #01</h1>
<h2>Simple File Reader using IOFactory::load()</h2>
<?php
require_once __DIR__ . '/../../../src/Bootstrap.php';
$inputFileName = './sampleData/example1.xls';
echo 'Loading file ', pathinfo($inputFileName, PATHINFO_BASENAME), ' using IOFactory to identify the format<br />';
$spreadsheet = IOFactory::load($inputFileName);
echo '<hr />';
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
var_dump($sheetData);
?>
<body>
</html>

View File

@ -1,36 +0,0 @@
<?php
use PhpOffice\PhpSpreadsheet\Reader\Xls;
error_reporting(E_ALL);
set_time_limit(0);
date_default_timezone_set('Europe/London');
require_once __DIR__ . '/../../../src/Bootstrap.php';
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PhpSpreadsheet Reader Example #02</title>
</head>
<body>
<h1>PhpSpreadsheet Reader Example #02</h1>
<h2>Simple File Reader using a Specified Reader</h2>
<?php
$inputFileName = './sampleData/example1.xls';
echo 'Loading file ', pathinfo($inputFileName, PATHINFO_BASENAME), ' using \PhpOffice\PhpSpreadsheet\Reader\Xls<br />';
$reader = new Xls();
$spreadsheet = $reader->load($inputFileName);
echo '<hr />';
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
var_dump($sheetData);
?>
<body>
</html>

View File

@ -1,37 +0,0 @@
<?php
use PhpOffice\PhpSpreadsheet\IOFactory;
error_reporting(E_ALL);
set_time_limit(0);
date_default_timezone_set('Europe/London');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PhpSpreadsheet Reader Example #03</title>
</head>
<body>
<h1>PhpSpreadsheet Reader Example #03</h1>
<h2>Simple File Reader using the IOFactory to Return a Reader</h2>
<?php
require_once __DIR__ . '/../../../src/Bootstrap.php';
$inputFileType = 'Xls';
$inputFileName = './sampleData/example1.xls';
echo 'Loading file ', pathinfo($inputFileName, PATHINFO_BASENAME), ' using IOFactory with a defined reader type of ', $inputFileType, '<br />';
$reader = IOFactory::createReader($inputFileType);
$spreadsheet = $reader->load($inputFileName);
echo '<hr />';
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
var_dump($sheetData);
?>
<body>
</html>

View File

@ -1,39 +0,0 @@
<?php
use PhpOffice\PhpSpreadsheet\IOFactory;
error_reporting(E_ALL);
set_time_limit(0);
date_default_timezone_set('Europe/London');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PhpSpreadsheet Reader Example #04</title>
</head>
<body>
<h1>PhpSpreadsheet Reader Example #04</h1>
<h2>Simple File Reader using the IOFactory to Identify a Reader to Use</h2>
<?php
require_once __DIR__ . '/../../../src/Bootstrap.php';
$inputFileName = './sampleData/example1.xls';
$inputFileType = IOFactory::identify($inputFileName);
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 />';
$reader = IOFactory::createReader($inputFileType);
$spreadsheet = $reader->load($inputFileName);
echo '<hr />';
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
var_dump($sheetData);
?>
<body>
</html>

View File

@ -1,39 +0,0 @@
<?php
use PhpOffice\PhpSpreadsheet\IOFactory;
error_reporting(E_ALL);
set_time_limit(0);
date_default_timezone_set('Europe/London');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PhpSpreadsheet Reader Example #05</title>
</head>
<body>
<h1>PhpSpreadsheet Reader Example #05</h1>
<h2>Simple File Reader using the "Read Data Only" Option</h2>
<?php
require_once __DIR__ . '/../../../src/Bootstrap.php';
$inputFileType = 'Xls';
$inputFileName = './sampleData/example1.xls';
echo 'Loading file ', pathinfo($inputFileName, PATHINFO_BASENAME), ' using IOFactory with a defined reader type of ', $inputFileType, '<br />';
$reader = IOFactory::createReader($inputFileType);
echo 'Turning Formatting off for Load<br />';
$reader->setReadDataOnly(true);
$spreadsheet = $reader->load($inputFileName);
echo '<hr />';
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
var_dump($sheetData);
?>
<body>
</html>

View File

@ -1,42 +0,0 @@
<?php
use PhpOffice\PhpSpreadsheet\IOFactory;
error_reporting(E_ALL);
set_time_limit(0);
date_default_timezone_set('Europe/London');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PhpSpreadsheet Reader Example #06</title>
</head>
<body>
<h1>PhpSpreadsheet Reader Example #06</h1>
<h2>Simple File Reader Loading All WorkSheets</h2>
<?php
require_once __DIR__ . '/../../../src/Bootstrap.php';
$inputFileType = 'Xls';
$inputFileName = './sampleData/example1.xls';
echo 'Loading file ', pathinfo($inputFileName, PATHINFO_BASENAME), ' using IOFactory with a defined reader type of ', $inputFileType, '<br />';
$reader = IOFactory::createReader($inputFileType);
echo 'Loading all WorkSheets<br />';
$reader->setLoadAllSheets();
$spreadsheet = $reader->load($inputFileName);
echo '<hr />';
echo $spreadsheet->getSheetCount(), ' worksheet', (($spreadsheet->getSheetCount() == 1) ? '' : 's'), ' loaded<br /><br />';
$loadedSheetNames = $spreadsheet->getSheetNames();
foreach ($loadedSheetNames as $sheetIndex => $loadedSheetName) {
echo $sheetIndex, ' -> ', $loadedSheetName, '<br />';
}
?>
<body>
</html>

View File

@ -1,43 +0,0 @@
<?php
use PhpOffice\PhpSpreadsheet\IOFactory;
error_reporting(E_ALL);
set_time_limit(0);
date_default_timezone_set('Europe/London');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PhpSpreadsheet Reader Example #07</title>
</head>
<body>
<h1>PhpSpreadsheet Reader Example #07</h1>
<h2>Simple File Reader Loading a Single Named WorkSheet</h2>
<?php
require_once __DIR__ . '/../../../src/Bootstrap.php';
$inputFileType = 'Xls';
$inputFileName = './sampleData/example1.xls';
$sheetname = 'Data Sheet #2';
echo 'Loading file ', pathinfo($inputFileName, PATHINFO_BASENAME), ' using IOFactory with a defined reader type of ', $inputFileType, '<br />';
$reader = IOFactory::createReader($inputFileType);
echo 'Loading Sheet "', $sheetname, '" only<br />';
$reader->setLoadSheetsOnly($sheetname);
$spreadsheet = $reader->load($inputFileName);
echo '<hr />';
echo $spreadsheet->getSheetCount(), ' worksheet', (($spreadsheet->getSheetCount() == 1) ? '' : 's'), ' loaded<br /><br />';
$loadedSheetNames = $spreadsheet->getSheetNames();
foreach ($loadedSheetNames as $sheetIndex => $loadedSheetName) {
echo $sheetIndex, ' -> ', $loadedSheetName, '<br />';
}
?>
<body>
</html>

View File

@ -1,43 +0,0 @@
<?php
use PhpOffice\PhpSpreadsheet\IOFactory;
error_reporting(E_ALL);
set_time_limit(0);
date_default_timezone_set('Europe/London');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PhpSpreadsheet Reader Example #08</title>
</head>
<body>
<h1>PhpSpreadsheet Reader Example #08</h1>
<h2>Simple File Reader Loading Several Named WorkSheets</h2>
<?php
require_once __DIR__ . '/../../../src/Bootstrap.php';
$inputFileType = 'Xls';
$inputFileName = './sampleData/example1.xls';
$sheetnames = ['Data Sheet #1', 'Data Sheet #3'];
echo 'Loading file ', pathinfo($inputFileName, PATHINFO_BASENAME), ' using IOFactory with a defined reader type of ', $inputFileType, '<br />';
$reader = IOFactory::createReader($inputFileType);
echo 'Loading Sheet', ((count($sheetnames) == 1) ? '' : 's'), ' "', implode('" and "', $sheetnames), '" only<br />';
$reader->setLoadSheetsOnly($sheetnames);
$spreadsheet = $reader->load($inputFileName);
echo '<hr />';
echo $spreadsheet->getSheetCount(), ' worksheet', (($spreadsheet->getSheetCount() == 1) ? '' : 's'), ' loaded<br /><br />';
$loadedSheetNames = $spreadsheet->getSheetNames();
foreach ($loadedSheetNames as $sheetIndex => $loadedSheetName) {
echo $sheetIndex, ' -> ', $loadedSheetName, '<br />';
}
?>
<body>
</html>

View File

@ -1,61 +0,0 @@
<?php
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Reader\IReadFilter;
error_reporting(E_ALL);
set_time_limit(0);
date_default_timezone_set('Europe/London');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PhpSpreadsheet Reader Example #09</title>
</head>
<body>
<h1>PhpSpreadsheet Reader Example #09</h1>
<h2>Simple File Reader Using a Read Filter</h2>
<?php
require_once __DIR__ . '/../../../src/Bootstrap.php';
$inputFileType = 'Xls';
$inputFileName = './sampleData/example1.xls';
$sheetname = 'Data Sheet #3';
class MyReadFilter implements IReadFilter
{
public function readCell($column, $row, $worksheetName = '')
{
// Read rows 1 to 7 and columns A to E only
if ($row >= 1 && $row <= 7) {
if (in_array($column, range('A', 'E'))) {
return true;
}
}
return false;
}
}
$filterSubset = new MyReadFilter();
echo 'Loading file ', pathinfo($inputFileName, PATHINFO_BASENAME), ' using IOFactory with a defined reader type of ', $inputFileType, '<br />';
$reader = IOFactory::createReader($inputFileType);
echo 'Loading Sheet "', $sheetname, '" only<br />';
$reader->setLoadSheetsOnly($sheetname);
echo 'Loading Sheet using filter<br />';
$reader->setReadFilter($filterSubset);
$spreadsheet = $reader->load($inputFileName);
echo '<hr />';
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
var_dump($sheetData);
?>
<body>
</html>

View File

@ -1,72 +0,0 @@
<?php
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Reader\IReadFilter;
error_reporting(E_ALL);
set_time_limit(0);
date_default_timezone_set('Europe/London');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PhpSpreadsheet Reader Example #10</title>
</head>
<body>
<h1>PhpSpreadsheet Reader Example #10</h1>
<h2>Simple File Reader Using a Configurable Read Filter</h2>
<?php
require_once __DIR__ . '/../../../src/Bootstrap.php';
$inputFileType = 'Xls';
$inputFileName = './sampleData/example1.xls';
$sheetname = 'Data Sheet #3';
class MyReadFilter implements IReadFilter
{
private $_startRow = 0;
private $_endRow = 0;
private $_columns = [];
public function __construct($startRow, $endRow, $columns)
{
$this->_startRow = $startRow;
$this->_endRow = $endRow;
$this->_columns = $columns;
}
public function readCell($column, $row, $worksheetName = '')
{
if ($row >= $this->_startRow && $row <= $this->_endRow) {
if (in_array($column, $this->_columns)) {
return true;
}
}
return false;
}
}
$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 />';
$reader = IOFactory::createReader($inputFileType);
echo 'Loading Sheet "', $sheetname, '" only<br />';
$reader->setLoadSheetsOnly($sheetname);
echo 'Loading Sheet using configurable filter<br />';
$reader->setReadFilter($filterSubset);
$spreadsheet = $reader->load($inputFileName);
echo '<hr />';
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
var_dump($sheetData);
?>
<body>
</html>

View File

@ -1,86 +0,0 @@
<?php
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Reader\IReadFilter;
error_reporting(E_ALL);
set_time_limit(0);
date_default_timezone_set('Europe/London');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PhpSpreadsheet Reader Example #11</title>
</head>
<body>
<h1>PhpSpreadsheet Reader Example #11</h1>
<h2>Reading a Workbook in "Chunks" Using a Configurable Read Filter (Version 1)</h2>
<?php
require_once __DIR__ . '/../../../src/Bootstrap.php';
$inputFileType = 'Xls';
$inputFileName = './sampleData/example2.xls';
/** Define a Read Filter class implementing IReadFilter */
class chunkReadFilter implements IReadFilter
{
private $_startRow = 0;
private $_endRow = 0;
/**
* We expect a list of the rows that we want to read to be passed into the constructor.
*
* @param mixed $startRow
* @param mixed $chunkSize
*/
public function __construct($startRow, $chunkSize)
{
$this->_startRow = $startRow;
$this->_endRow = $startRow + $chunkSize;
}
public function readCell($column, $row, $worksheetName = '')
{
// Only read the heading row, and the rows that were configured in the constructor
if (($row == 1) || ($row >= $this->_startRow && $row < $this->_endRow)) {
return true;
}
return false;
}
}
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 * */
$reader = IOFactory::createReader($inputFileType);
echo '<hr />';
/* Define how many rows we want for each "chunk" * */
$chunkSize = 20;
/* Loop to read our worksheet in "chunk size" blocks * */
for ($startRow = 2; $startRow <= 240; $startRow += $chunkSize) {
echo 'Loading WorkSheet using configurable filter for headings row 1 and for rows ', $startRow, ' to ', ($startRow + $chunkSize - 1), '<br />';
/* Create a new Instance of our Read Filter, passing in the limits on which rows we want to read * */
$chunkFilter = new chunkReadFilter($startRow, $chunkSize);
/* Tell the Reader that we want to use the new Read Filter that we've just Instantiated * */
$reader->setReadFilter($chunkFilter);
/* Load only the rows that match our filter from $inputFileName to a PhpSpreadsheet Object * */
$spreadsheet = $reader->load($inputFileName);
// Do some processing here
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
var_dump($sheetData);
echo '<br /><br />';
}
?>
<body>
</html>

View File

@ -1,89 +0,0 @@
<?php
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Reader\IReadFilter;
error_reporting(E_ALL);
set_time_limit(0);
date_default_timezone_set('Europe/London');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PhpSpreadsheet Reader Example #12</title>
</head>
<body>
<h1>PhpSpreadsheet Reader Example #12</h1>
<h2>Reading a Workbook in "Chunks" Using a Configurable Read Filter (Version 2)</h2>
<?php
require_once __DIR__ . '/../../../src/Bootstrap.php';
$inputFileType = 'Xls';
$inputFileName = './sampleData/example2.xls';
/** Define a Read Filter class implementing IReadFilter */
class chunkReadFilter implements IReadFilter
{
private $_startRow = 0;
private $_endRow = 0;
/**
* Set the list of rows that we want to read.
*
* @param mixed $startRow
* @param mixed $chunkSize
*/
public function setRows($startRow, $chunkSize)
{
$this->_startRow = $startRow;
$this->_endRow = $startRow + $chunkSize;
}
public function readCell($column, $row, $worksheetName = '')
{
// Only read the heading row, and the rows that are configured in $this->_startRow and $this->_endRow
if (($row == 1) || ($row >= $this->_startRow && $row < $this->_endRow)) {
return true;
}
return false;
}
}
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 * */
$reader = IOFactory::createReader($inputFileType);
echo '<hr />';
/* Define how many rows we want to read for each "chunk" * */
$chunkSize = 20;
/* Create a new Instance of our Read Filter * */
$chunkFilter = new chunkReadFilter();
/* Tell the Reader that we want to use the Read Filter that we've Instantiated * */
$reader->setReadFilter($chunkFilter);
/* Loop to read our worksheet in "chunk size" blocks * */
for ($startRow = 2; $startRow <= 240; $startRow += $chunkSize) {
echo 'Loading WorkSheet using configurable filter for headings row 1 and for rows ', $startRow, ' to ', ($startRow + $chunkSize - 1), '<br />';
/* Tell the Read Filter, the limits on which rows we want to read this iteration * */
$chunkFilter->setRows($startRow, $chunkSize);
/* Load only the rows that match our filter from $inputFileName to a PhpSpreadsheet Object * */
$spreadsheet = $reader->load($inputFileName);
// Do some processing here
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
var_dump($sheetData);
echo '<br /><br />';
}
?>
<body>
</html>

View File

@ -1,52 +0,0 @@
<?php
use PhpOffice\PhpSpreadsheet\IOFactory;
error_reporting(E_ALL);
set_time_limit(0);
date_default_timezone_set('Europe/London');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PhpSpreadsheet Reader Example #13</title>
</head>
<body>
<h1>PhpSpreadsheet Reader Example #13</h1>
<h2>Simple File Reader for Multiple CSV Files</h2>
<?php
require_once __DIR__ . '/../../../src/Bootstrap.php';
$inputFileType = 'Csv';
$inputFileNames = ['./sampleData/example1.csv', './sampleData/example2.csv'];
$reader = IOFactory::createReader($inputFileType);
$inputFileName = array_shift($inputFileNames);
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->getActiveSheet()->setTitle(pathinfo($inputFileName, PATHINFO_BASENAME));
foreach ($inputFileNames as $sheet => $inputFileName) {
echo 'Loading file ', pathinfo($inputFileName, PATHINFO_BASENAME), ' into WorkSheet #', ($sheet + 2), ' using IOFactory with a defined reader type of ', $inputFileType, '<br />';
$reader->setSheetIndex($sheet + 1);
$reader->loadIntoExisting($inputFileName, $spreadsheet);
$spreadsheet->getActiveSheet()->setTitle(pathinfo($inputFileName, PATHINFO_BASENAME));
}
echo '<hr />';
echo $spreadsheet->getSheetCount(), ' worksheet', (($spreadsheet->getSheetCount() == 1) ? '' : 's'), ' loaded<br /><br />';
$loadedSheetNames = $spreadsheet->getSheetNames();
foreach ($loadedSheetNames as $sheetIndex => $loadedSheetName) {
echo '<b>Worksheet #', $sheetIndex, ' -> ', $loadedSheetName, '</b><br />';
$spreadsheet->setActiveSheetIndexByName($loadedSheetName);
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
var_dump($sheetData);
echo '<br /><br />';
}
?>
<body>
</html>

View File

@ -1,110 +0,0 @@
<?php
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Reader\IReadFilter;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
error_reporting(E_ALL);
set_time_limit(0);
date_default_timezone_set('Europe/London');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PhpSpreadsheet Reader Example #14</title>
</head>
<body>
<h1>PhpSpreadsheet Reader Example #14</h1>
<h2>Reading a Large CSV file in "Chunks" to split across multiple Worksheets</h2>
<?php
require_once __DIR__ . '/../../../src/Bootstrap.php';
$inputFileType = 'Csv';
$inputFileName = './sampleData/example2.csv';
/** Define a Read Filter class implementing IReadFilter */
class chunkReadFilter implements IReadFilter
{
private $_startRow = 0;
private $_endRow = 0;
/**
* Set the list of rows that we want to read.
*
* @param mixed $startRow
* @param mixed $chunkSize
*/
public function setRows($startRow, $chunkSize)
{
$this->_startRow = $startRow;
$this->_endRow = $startRow + $chunkSize;
}
public function readCell($column, $row, $worksheetName = '')
{
// Only read the heading row, and the rows that are configured in $this->_startRow and $this->_endRow
if (($row == 1) || ($row >= $this->_startRow && $row < $this->_endRow)) {
return true;
}
return false;
}
}
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 * */
$reader = IOFactory::createReader($inputFileType);
echo '<hr />';
/* Define how many rows we want to read for each "chunk" * */
$chunkSize = 100;
/* Create a new Instance of our Read Filter * */
$chunkFilter = new chunkReadFilter();
/* Tell the Reader that we want to use the Read Filter that we've Instantiated * */
/* and that we want to store it in contiguous rows/columns * */
$reader->setReadFilter($chunkFilter)
->setContiguous(true);
/* Instantiate a new PhpSpreadsheet object manually * */
$spreadsheet = new Spreadsheet();
/* Set a sheet index * */
$sheet = 0;
/* Loop to read our worksheet in "chunk size" blocks * */
/** $startRow is set to 2 initially because we always read the headings in row #1 * */
for ($startRow = 2; $startRow <= 240; $startRow += $chunkSize) {
echo 'Loading WorkSheet #', ($sheet + 1), ' using configurable filter for headings row 1 and for rows ', $startRow, ' to ', ($startRow + $chunkSize - 1), '<br />';
/* Tell the Read Filter, the limits on which rows we want to read this iteration * */
$chunkFilter->setRows($startRow, $chunkSize);
/* Increment the worksheet index pointer for the Reader * */
$reader->setSheetIndex($sheet);
/* Load only the rows that match our filter into a new worksheet in the PhpSpreadsheet Object * */
$reader->loadIntoExisting($inputFileName, $spreadsheet);
/* Set the worksheet title (to reference the "sheet" of data that we've loaded) * */
/* and increment the sheet index as well * */
$spreadsheet->getActiveSheet()->setTitle('Country Data #' . ( ++$sheet));
}
echo '<hr />';
echo $spreadsheet->getSheetCount(), ' worksheet', (($spreadsheet->getSheetCount() == 1) ? '' : 's'), ' loaded<br /><br />';
$loadedSheetNames = $spreadsheet->getSheetNames();
foreach ($loadedSheetNames as $sheetIndex => $loadedSheetName) {
echo '<b>Worksheet #', $sheetIndex, ' -> ', $loadedSheetName, '</b><br />';
$spreadsheet->setActiveSheetIndexByName($loadedSheetName);
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, false, false, true);
var_dump($sheetData);
echo '<br />';
}
?>
<body>
</html>

View File

@ -1,69 +0,0 @@
<?php
use PhpOffice\PhpSpreadsheet\Cell;
use PhpOffice\PhpSpreadsheet\IOFactory;
error_reporting(E_ALL);
set_time_limit(0);
date_default_timezone_set('Europe/London');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PhpSpreadsheet Reader Example #15</title>
</head>
<body>
<h1>PhpSpreadsheet Reader Example #15</h1>
<h2>Simple File Reader for Tab-Separated Value File using the Advanced Value Binder</h2>
<?php
require_once __DIR__ . '/../../../src/Bootstrap.php';
Cell::setValueBinder(new Cell\AdvancedValueBinder());
$inputFileType = 'Csv';
$inputFileName = './sampleData/example1.tsv';
$reader = IOFactory::createReader($inputFileType);
echo 'Loading file ', pathinfo($inputFileName, PATHINFO_BASENAME), ' into WorkSheet #1 using IOFactory with a defined reader type of ', $inputFileType, '<br />';
$reader->setDelimiter("\t");
$spreadsheet = $reader->load($inputFileName);
$spreadsheet->getActiveSheet()->setTitle(pathinfo($inputFileName, PATHINFO_BASENAME));
echo '<hr />';
echo $spreadsheet->getSheetCount(), ' worksheet', (($spreadsheet->getSheetCount() == 1) ? '' : 's'), ' loaded<br /><br />';
$loadedSheetNames = $spreadsheet->getSheetNames();
foreach ($loadedSheetNames as $sheetIndex => $loadedSheetName) {
echo '<b>Worksheet #', $sheetIndex, ' -> ', $loadedSheetName, ' (Formatted)</b><br />';
$spreadsheet->setActiveSheetIndexByName($loadedSheetName);
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
var_dump($sheetData);
echo '<br />';
}
echo '<hr />';
foreach ($loadedSheetNames as $sheetIndex => $loadedSheetName) {
echo '<b>Worksheet #', $sheetIndex, ' -> ', $loadedSheetName, ' (Unformatted)</b><br />';
$spreadsheet->setActiveSheetIndexByName($loadedSheetName);
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, false, true);
var_dump($sheetData);
echo '<br />';
}
echo '<hr />';
foreach ($loadedSheetNames as $sheetIndex => $loadedSheetName) {
echo '<b>Worksheet #', $sheetIndex, ' -> ', $loadedSheetName, ' (Raw)</b><br />';
$spreadsheet->setActiveSheetIndexByName($loadedSheetName);
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, false, false, true);
var_dump($sheetData);
echo '<br />';
}
?>
<body>
</html>

View File

@ -1,39 +0,0 @@
<?php
use InvalidArgumentException;
use PhpOffice\PhpSpreadsheet\IOFactory;
error_reporting(E_ALL);
set_time_limit(0);
date_default_timezone_set('Europe/London');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PhpSpreadsheet Reader Example #16</title>
</head>
<body>
<h1>PhpSpreadsheet Reader Example #16</h1>
<h2>Handling Loader Exceptions using Try/Catch</h2>
<?php
require_once __DIR__ . '/../../../src/Bootstrap.php';
$inputFileName = './sampleData/example_1.xls';
echo 'Loading file ', pathinfo($inputFileName, PATHINFO_BASENAME), ' using IOFactory to identify the format<br />';
try {
$spreadsheet = IOFactory::load($inputFileName);
} catch (InvalidArgumentException $e) {
die('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' . $e->getMessage());
}
echo '<hr />';
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
var_dump($sheetData);
?>
<body>
</html>

View File

@ -1,40 +0,0 @@
<?php
use PhpOffice\PhpSpreadsheet\IOFactory;
error_reporting(E_ALL);
set_time_limit(0);
date_default_timezone_set('Europe/London');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PhpSpreadsheet Reader Example #17</title>
</head>
<body>
<h1>PhpSpreadsheet Reader Example #17</h1>
<h2>Simple File Reader Loading Several Named WorkSheets</h2>
<?php
require_once __DIR__ . '/../../../src/Bootstrap.php';
$inputFileType = 'Xls';
$inputFileName = './sampleData/example1.xls';
echo 'Loading file ', pathinfo($inputFileName, PATHINFO_BASENAME), ' using IOFactory with a defined reader type of ', $inputFileType, '<br />';
$reader = IOFactory::createReader($inputFileType);
/* Read the list of Worksheet Names from the Workbook file * */
echo 'Read the list of Worksheets in the WorkBook<br />';
$worksheetNames = $reader->listWorksheetNames($inputFileName);
echo 'There are ', count($worksheetNames), ' worksheet', ((count($worksheetNames) == 1) ? '' : 's'), ' in the workbook<br /><br />';
foreach ($worksheetNames as $worksheetName) {
echo $worksheetName, '<br />';
}
?>
<body>
</html>

View File

@ -1,40 +0,0 @@
<?php
use PhpOffice\PhpSpreadsheet\IOFactory;
error_reporting(E_ALL);
set_time_limit(0);
date_default_timezone_set('Europe/London');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PhpSpreadsheet Reader Example #18</title>
</head>
<body>
<h1>PhpSpreadsheet Reader Example #18</h1>
<h2>Reading list of WorkSheets without loading entire file</h2>
<?php
require_once __DIR__ . '/../../../src/Bootstrap.php';
$inputFileType = 'Xls';
$inputFileName = './sampleData/example1.xls';
echo 'Loading file ', pathinfo($inputFileName, PATHINFO_BASENAME), ' information using IOFactory with a defined reader type of ', $inputFileType, '<br />';
$reader = IOFactory::createReader($inputFileType);
$worksheetNames = $reader->listWorksheetNames($inputFileName);
echo '<h3>Worksheet Names</h3>';
echo '<ol>';
foreach ($worksheetNames as $worksheetName) {
echo '<li>', $worksheetName, '</li>';
}
echo '</ol>';
?>
<body>
</html>

View File

@ -1,43 +0,0 @@
<?php
use PhpOffice\PhpSpreadsheet\IOFactory;
error_reporting(E_ALL);
set_time_limit(0);
date_default_timezone_set('Europe/London');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PhpSpreadsheet Reader Example #19</title>
</head>
<body>
<h1>PhpSpreadsheet Reader Example #19</h1>
<h2>Reading WorkSheet information without loading entire file</h2>
<?php
require_once __DIR__ . '/../../../src/Bootstrap.php';
$inputFileType = 'Xls';
$inputFileName = './sampleData/example1.xls';
echo 'Loading file ', pathinfo($inputFileName, PATHINFO_BASENAME), ' information using IOFactory with a defined reader type of ', $inputFileType, '<br />';
$reader = IOFactory::createReader($inputFileType);
$worksheetData = $reader->listWorksheetInfo($inputFileName);
echo '<h3>Worksheet Information</h3>';
echo '<ol>';
foreach ($worksheetData as $worksheet) {
echo '<li>', $worksheet['worksheetName'], '<br />';
echo 'Rows: ', $worksheet['totalRows'], ' Columns: ', $worksheet['totalColumns'], '<br />';
echo 'Cell Range: A1:', $worksheet['lastColumnLetter'], $worksheet['totalRows'];
echo '</li>';
}
echo '</ol>';
?>
<body>
</html>

View File

@ -1,85 +0,0 @@
<?php
use PhpOffice\PhpSpreadsheet\IOFactory;
error_reporting(E_ALL);
set_time_limit(0);
date_default_timezone_set('Europe/London');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PhpSpreadsheet Reading WorkBook Data Example #01</title>
</head>
<body>
<h1>PhpSpreadsheet Reading WorkBook Data Example #01</h1>
<h2>Read the WorkBook Properties</h2>
<?php
require_once __DIR__ . '/../../../src/Bootstrap.php';
$inputFileType = 'Xls';
$inputFileName = './sampleData/example1.xls';
/* Create a new Reader of the type defined in $inputFileType * */
$reader = IOFactory::createReader($inputFileType);
/* Load $inputFileName to a PhpSpreadsheet Object * */
$spreadsheet = $reader->load($inputFileName);
echo '<hr />';
/* Read the document's creator property * */
$creator = $spreadsheet->getProperties()->getCreator();
echo '<b>Document Creator: </b>', $creator, '<br />';
/* Read the Date when the workbook was created (as a PHP timestamp value) * */
$creationDatestamp = $spreadsheet->getProperties()->getCreated();
/* Format the date and time using the standard PHP date() function * */
$creationDate = date('l, d<\s\up>S</\s\up> F Y', $creationDatestamp);
$creationTime = date('g:i A', $creationDatestamp);
echo '<b>Created On: </b>', $creationDate, ' at ', $creationTime, '<br />';
/* Read the name of the last person to modify this workbook * */
$modifiedBy = $spreadsheet->getProperties()->getLastModifiedBy();
echo '<b>Last Modified By: </b>', $modifiedBy, '<br />';
/* Read the Date when the workbook was last modified (as a PHP timestamp value) * */
$modifiedDatestamp = $spreadsheet->getProperties()->getModified();
/* Format the date and time using the standard PHP date() function * */
$modifiedDate = date('l, d<\s\up>S</\s\up> F Y', $modifiedDatestamp);
$modifiedTime = date('g:i A', $modifiedDatestamp);
echo '<b>Last Modified On: </b>', $modifiedDate, ' at ', $modifiedTime, '<br />';
/* Read the workbook title property * */
$workbookTitle = $spreadsheet->getProperties()->getTitle();
echo '<b>Title: </b>', $workbookTitle, '<br />';
/* Read the workbook description property * */
$description = $spreadsheet->getProperties()->getDescription();
echo '<b>Description: </b>', $description, '<br />';
/* Read the workbook subject property * */
$subject = $spreadsheet->getProperties()->getSubject();
echo '<b>Subject: </b>', $subject, '<br />';
/* Read the workbook keywords property * */
$keywords = $spreadsheet->getProperties()->getKeywords();
echo '<b>Keywords: </b>', $keywords, '<br />';
/* Read the workbook category property * */
$category = $spreadsheet->getProperties()->getCategory();
echo '<b>Category: </b>', $category, '<br />';
/* Read the workbook company property * */
$company = $spreadsheet->getProperties()->getCompany();
echo '<b>Company: </b>', $company, '<br />';
/* Read the workbook manager property * */
$manager = $spreadsheet->getProperties()->getManager();
echo '<b>Manager: </b>', $manager, '<br />';
?>
<body>
</html>

View File

@ -1,43 +0,0 @@
<?php
use PhpOffice\PhpSpreadsheet\IOFactory;
error_reporting(E_ALL);
set_time_limit(0);
date_default_timezone_set('Europe/London');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PhpSpreadsheet Reading WorkBook Data Example #02</title>
</head>
<body>
<h1>PhpSpreadsheet Reading WorkBook Data Example #02</h1>
<h2>Read a list of Custom Properties for a WorkBook</h2>
<?php
require_once __DIR__ . '/../../../src/Bootstrap.php';
$inputFileType = 'Xlsx';
$inputFileName = './sampleData/example1.xlsx';
/* Create a new Reader of the type defined in $inputFileType * */
$reader = IOFactory::createReader($inputFileType);
/* Load $inputFileName to a PhpSpreadsheet Object * */
$spreadsheet = $reader->load($inputFileName);
echo '<hr />';
/* Read an array list of any custom properties for this document * */
$customPropertyList = $spreadsheet->getProperties()->getCustomProperties();
echo '<b>Custom Property names: </b><br />';
foreach ($customPropertyList as $customPropertyName) {
echo $customPropertyName, '<br />';
}
?>
<body>
</html>

View File

@ -1,71 +0,0 @@
<?php
use PhpOffice\PhpSpreadsheet\IOFactory;
error_reporting(E_ALL);
set_time_limit(0);
date_default_timezone_set('Europe/London');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PhpSpreadsheet Reading WorkBook Data Example #03</title>
</head>
<body>
<h1>PhpSpreadsheet Reading WorkBook Data Example #03</h1>
<h2>Read Custom Property Values for a WorkBook</h2>
<?php
require_once __DIR__ . '/../../../src/Bootstrap.php';
$inputFileType = 'Xlsx';
$inputFileName = './sampleData/example1.xlsx';
/* Create a new Reader of the type defined in $inputFileType * */
$reader = IOFactory::createReader($inputFileType);
/* Load $inputFileName to a PhpSpreadsheet Object * */
$spreadsheet = $reader->load($inputFileName);
echo '<hr />';
/* Read an array list of any custom properties for this document * */
$customPropertyList = $spreadsheet->getProperties()->getCustomProperties();
echo '<b>Custom Properties: </b><br />';
/* Loop through the list of custom properties * */
foreach ($customPropertyList as $customPropertyName) {
echo '<b>', $customPropertyName, ': </b>';
/* Retrieve the property value * */
$propertyValue = $spreadsheet->getProperties()->getCustomPropertyValue($customPropertyName);
/* Retrieve the property type * */
$propertyType = $spreadsheet->getProperties()->getCustomPropertyType($customPropertyName);
/* Manipulate properties as appropriate for display purposes * */
switch ($propertyType) {
case 'i': // integer
$propertyType = 'integer number';
break;
case 'f': // float
$propertyType = 'floating point number';
break;
case 's': // string
$propertyType = 'string';
break;
case 'd': // date
$propertyValue = date('l, d<\s\up>S</\s\up> F Y g:i A', $propertyValue);
$propertyType = 'date';
break;
case 'b': // boolean
$propertyValue = ($propertyValue) ? 'TRUE' : 'FALSE';
$propertyType = 'boolean';
break;
}
echo $propertyValue, ' (', $propertyType, ')<br />';
}
?>
<body>
</html>

View File

@ -1,47 +0,0 @@
<?php
use PhpOffice\PhpSpreadsheet\IOFactory;
error_reporting(E_ALL);
set_time_limit(0);
date_default_timezone_set('Europe/London');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PhpSpreadsheet Reading WorkBook Data Example #04</title>
</head>
<body>
<h1>PhpSpreadsheet Reading WorkBook Data Example #04</h1>
<h2>Get a List of the Worksheets in a WorkBook</h2>
<?php
require_once __DIR__ . '/../../../src/Bootstrap.php';
$inputFileType = 'Xls';
$inputFileName = './sampleData/example2.xls';
/* Create a new Reader of the type defined in $inputFileType * */
$reader = IOFactory::createReader($inputFileType);
/* Load $inputFileName to a PhpSpreadsheet Object * */
$spreadsheet = $reader->load($inputFileName);
echo '<hr />';
echo 'Reading the number of Worksheets in the WorkBook<br />';
/* Use the PhpSpreadsheet object's getSheetCount() method to get a count of the number of WorkSheets in the WorkBook */
$sheetCount = $spreadsheet->getSheetCount();
echo 'There ', (($sheetCount == 1) ? 'is' : 'are'), ' ', $sheetCount, ' WorkSheet', (($sheetCount == 1) ? '' : 's'), ' in the WorkBook<br /><br />';
echo 'Reading the names of Worksheets in the WorkBook<br />';
/* Use the PhpSpreadsheet object's getSheetNames() method to get an array listing the names/titles of the WorkSheets in the WorkBook */
$sheetNames = $spreadsheet->getSheetNames();
foreach ($sheetNames as $sheetIndex => $sheetName) {
echo 'WorkSheet #', $sheetIndex, ' is named "', $sheetName, '"<br />';
}
?>
<body>
</html>

View File

@ -1,44 +0,0 @@
<?php
error_reporting(E_ALL);
set_time_limit(0);
date_default_timezone_set('Europe/London');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PhpSpreadsheet Examples</title>
</head>
<body>
<?php
$exampleTypeList = glob('./*', GLOB_ONLYDIR);
foreach ($exampleTypeList as $exampleType) {
echo '<h1>PhpSpreadsheet ' . pathinfo($exampleType, PATHINFO_BASENAME) . ' Examples</h1>';
$exampleList = glob('./' . $exampleType . '/*.php');
foreach ($exampleList as $exampleFile) {
$fileData = file_get_contents($exampleFile);
$h1Pattern = '#<h1>(.*?)</h1>#';
$h2Pattern = '#<h2>(.*?)</h2>#';
if (preg_match($h1Pattern, $fileData, $out)) {
$h1Text = $out[1];
$h2Text = (preg_match($h2Pattern, $fileData, $out)) ? $out[1] : '';
echo '<a href="', $exampleFile, '">', $h1Text, '</a><br />';
if (($h2Text > '') &&
(pathinfo($exampleType, PATHINFO_BASENAME) != 'Calculations')) {
echo $h2Text, '<br />';
}
}
}
}
?>
<body>
</html>

View File

@ -519,7 +519,7 @@ foreach ($spreadsheet->getActiveSheet()->getRowIterator() as $row) {
->getCell( ->getCell(
'D'.$row->getRowIndex() 'D'.$row->getRowIndex()
)->getFormattedValue(), ' '; )->getFormattedValue(), ' ';
echo EOL; echo PHP_EOL;
} }
} }
``` ```

View File

@ -27,8 +27,8 @@ $inputFileName = './sampleData/example1.xls';
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($inputFileName); $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($inputFileName);
``` ```
> See Examples/Reader/exampleReader01.php for a working example of this See `samples/Reader/01_Simple_file_reader_using_IOFactory.php` for a working
> code. example of this code.
The `load()` method will attempt to identify the file type, and The `load()` method will attempt to identify the file type, and
instantiate a loader for that file type; using it to load the file and instantiate a loader for that file type; using it to load the file and
@ -72,8 +72,8 @@ $reader = new \PhpOffice\PhpSpreadsheet\Reader\Xls();
$spreadsheet = $reader->load($inputFileName); $spreadsheet = $reader->load($inputFileName);
``` ```
> See Examples/Reader/exampleReader02.php for a working example of this See `samples/Reader/02_Simple_file_reader_using_a_specified_reader.php`
> code. for a working example of this code.
Alternatively, you can use the IO Factory's `createReader()` method to Alternatively, you can use the IO Factory's `createReader()` method to
instantiate the reader object for you, simply telling it the file type instantiate the reader object for you, simply telling it the file type
@ -95,8 +95,8 @@ $reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
$spreadsheet = $reader->load($inputFileName); $spreadsheet = $reader->load($inputFileName);
``` ```
> See Examples/Reader/exampleReader03.php for a working example of this See `samples/Reader/03_Simple_file_reader_using_the_IOFactory_to_return_a_reader.php`
> code. for a working example of this code.
If you're uncertain of the filetype, you can use the IO Factory's If you're uncertain of the filetype, you can use the IO Factory's
identify() method to identify the reader that you need, before using the identify() method to identify the reader that you need, before using the
@ -113,8 +113,8 @@ $reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
$spreadsheet = $reader->load($inputFileName); $spreadsheet = $reader->load($inputFileName);
``` ```
> See Examples/Reader/exampleReader04.php for a working example of this See `samples/Reader/04_Simple_file_reader_using_the_IOFactory_to_identify_a_reader_to_use.php`
> code. for a working example of this code.
## Spreadsheet Reader Options ## Spreadsheet Reader Options
@ -141,8 +141,8 @@ $reader->setReadDataOnly(true);
$spreadsheet = $reader->load($inputFileName); $spreadsheet = $reader->load($inputFileName);
``` ```
> See Examples/Reader/exampleReader05.php for a working example of this See `samples/Reader/05_Simple_file_reader_using_the_read_data_only_option.php`
> code. for a working example of this code.
It is important to note that Workbooks (and PhpSpreadsheet) store dates It is important to note that Workbooks (and PhpSpreadsheet) store dates
and times as simple numeric values: they can only be distinguished from and times as simple numeric values: they can only be distinguished from
@ -187,8 +187,8 @@ $reader->setLoadSheetsOnly($sheetname);
$spreadsheet = $reader->load($inputFileName); $spreadsheet = $reader->load($inputFileName);
``` ```
> See Examples/Reader/exampleReader07.php for a working example of this See `samples/Reader/07_Simple_file_reader_loading_a_single_named_worksheet.php`
> code. for a working example of this code.
If you want to read more than just a single sheet, you can pass a list If you want to read more than just a single sheet, you can pass a list
of sheet names as an array parameter to the `setLoadSheetsOnly()` method. of sheet names as an array parameter to the `setLoadSheetsOnly()` method.
@ -206,8 +206,8 @@ $reader->setLoadSheetsOnly($sheetnames);
$spreadsheet = $reader->load($inputFileName); $spreadsheet = $reader->load($inputFileName);
``` ```
> See Examples/Reader/exampleReader08.php for a working example of this See `samples/Reader/08_Simple_file_reader_loading_several_named_worksheets.php`
> code. for a working example of this code.
To reset this option to the default, you can call the `setLoadAllSheets()` To reset this option to the default, you can call the `setLoadAllSheets()`
method. method.
@ -224,8 +224,8 @@ $reader->setLoadAllSheets();
$spreadsheet = $reader->load($inputFileName); $spreadsheet = $reader->load($inputFileName);
``` ```
> See Examples/Reader/exampleReader06.php for a working example of this See `samples/Reader/06_Simple_file_reader_loading_all_worksheets.php` for a
> code. working example of this code.
Reading Only Named WorkSheets from a File applies to Readers: Reading Only Named WorkSheets from a File applies to Readers:
@ -277,8 +277,8 @@ $reader->setReadFilter($filterSubset);
$spreadsheet = $reader->load($inputFileName); $spreadsheet = $reader->load($inputFileName);
``` ```
> See Examples/Reader/exampleReader09.php for a working example of this See `samples/Reader/09_Simple_file_reader_using_a_read_filter.php` for a
> code. working example of this code.
This example is not particularly useful, because it can only be used in This example is not particularly useful, because it can only be used in
a very specific circumstance (when you only want cells in the range a very specific circumstance (when you only want cells in the range
@ -315,8 +315,8 @@ class MyReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter
$filterSubset = new MyReadFilter(9,15,range('G','K')); $filterSubset = new MyReadFilter(9,15,range('G','K'));
``` ```
> See Examples/Reader/exampleReader10.php for a working example of this See `samples/Reader/10_Simple_file_reader_using_a_configurable_read_filter.php`
> code. for a working example of this code.
This can be particularly useful for conserving memory, by allowing you This can be particularly useful for conserving memory, by allowing you
to read and process a large workbook in "chunks": an example of this to read and process a large workbook in "chunks": an example of this
@ -329,7 +329,7 @@ $inputFileName = './sampleData/example2.xls';
/** Define a Read Filter class implementing \PhpOffice\PhpSpreadsheet\Reader\IReadFilter */ /** Define a Read Filter class implementing \PhpOffice\PhpSpreadsheet\Reader\IReadFilter */
class chunkReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter class ChunkReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter
{ {
private $_startRow = 0; private $_startRow = 0;
private $_endRow = 0; private $_endRow = 0;
@ -357,7 +357,7 @@ $reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
/** Define how many rows we want to read for each "chunk" **/ /** Define how many rows we want to read for each "chunk" **/
$chunkSize = 2048; $chunkSize = 2048;
/** Create a new Instance of our Read Filter **/ /** Create a new Instance of our Read Filter **/
$chunkFilter = new chunkReadFilter(); $chunkFilter = new ChunkReadFilter();
/** Tell the Reader that we want to use the Read Filter **/ /** Tell the Reader that we want to use the Read Filter **/
$reader->setReadFilter($chunkFilter); $reader->setReadFilter($chunkFilter);
@ -372,8 +372,8 @@ for ($startRow = 2; $startRow <= 65536; $startRow += $chunkSize) {
} }
``` ```
> See Examples/Reader/exampleReader12.php for a working example of this See `samples/Reader/12_Reading_a_workbook_in_chunks_using_a_configurable_read_filter_`
> code. for a working example of this code.
Using Read Filters applies to: Using Read Filters applies to:
@ -427,8 +427,8 @@ foreach($inputFileNames as $sheet => $inputFileName) {
} }
``` ```
> See Examples/Reader/exampleReader13.php for a working example of this See `samples/Reader/13_Simple_file_reader_for_multiple_CSV_files.php` for a
> code. working example of this code.
Note that using the same sheet index for multiple sheets won't append Note that using the same sheet index for multiple sheets won't append
files into the same sheet, but overwrite the results of the previous files into the same sheet, but overwrite the results of the previous
@ -450,7 +450,7 @@ Xlsx Microsoft Office Open XML SpreadsheetML .xlsx file is limited to
by available disk space. This means that we wouldnt ordinarily be able by available disk space. This means that we wouldnt ordinarily be able
to read all the rows from a very large CSV file that exceeded those to read all the rows from a very large CSV file that exceeded those
limits, and save it as an Xls or Xlsx file. However, by using Read limits, and save it as an Xls or Xlsx file. However, by using Read
Filters to read the CSV file in "chunks" (using the chunkReadFilter Filters to read the CSV file in "chunks" (using the ChunkReadFilter
Class that we defined in [the above section](#reading-only-specific-columns-and-rows-from-a-file-read-filters), Class that we defined in [the above section](#reading-only-specific-columns-and-rows-from-a-file-read-filters),
and the `setSheetIndex()` method of the `$reader`, we can split the CSV and the `setSheetIndex()` method of the `$reader`, we can split the CSV
file across several individual worksheets. file across several individual worksheets.
@ -468,7 +468,7 @@ $reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
/** Define how many rows we want to read for each "chunk" **/ /** Define how many rows we want to read for each "chunk" **/
$chunkSize = 65530; $chunkSize = 65530;
/** Create a new Instance of our Read Filter **/ /** Create a new Instance of our Read Filter **/
$chunkFilter = new chunkReadFilter(); $chunkFilter = new ChunkReadFilter();
/** Tell the Reader that we want to use the Read Filter **/ /** Tell the Reader that we want to use the Read Filter **/
/** and that we want to store it in contiguous rows/columns **/ /** and that we want to store it in contiguous rows/columns **/
@ -497,8 +497,8 @@ for ($startRow = 2; $startRow <= 1000000; $startRow += $chunkSize) {
} }
``` ```
> See Examples/Reader/exampleReader14.php for a working example of this See `samples/Reader/14_Reading_a_large_CSV_file_in_chunks_to_split_across_multiple_worksheets.php`
> code. for a working example of this code.
This code will read 65,530 rows at a time from the CSV file that were This code will read 65,530 rows at a time from the CSV file that were
loading, and store each "chunk" in a new worksheet. loading, and store each "chunk" in a new worksheet.
@ -542,8 +542,8 @@ $reader->setDelimiter("\t");
$spreadsheet = $reader->load($inputFileName); $spreadsheet = $reader->load($inputFileName);
``` ```
> See Examples/Reader/exampleReader15.php for a working example of this See `samples/Reader/15_Simple_file_reader_for_tab_separated_value_file_using_the_Advanced_Value_Binder.php`
> code. for a working example of this code.
In addition to the delimiter, you can also use the following methods to In addition to the delimiter, you can also use the following methods to
set other attributes for the data load: set other attributes for the data load:
@ -603,8 +603,8 @@ $reader->setDelimiter("\t");
$spreadsheet = $reader->load($inputFileName); $spreadsheet = $reader->load($inputFileName);
``` ```
> See Examples/Reader/exampleReader15.php for a working example of this See `samples/Reader/15_Simple_file_reader_for_tab_separated_value_file_using_the_Advanced_Value_Binder.php`
> code. for a working example of this code.
Loading using a Value Binder applies to: Loading using a Value Binder applies to:
@ -636,8 +636,8 @@ try {
} }
``` ```
> See Examples/Reader/exampleReader16.php for a working example of this See `samples/Reader/16_Handling_loader_exceptions_using_TryCatch.php` for a
> code. working example of this code.
## Helper Methods ## Helper Methods
@ -665,8 +665,8 @@ foreach ($worksheetNames as $worksheetName) {
echo '</ol>'; echo '</ol>';
``` ```
> See Examples/Reader/exampleReader18.php for a working example of this See `samples/Reader/18_Reading_list_of_worksheets_without_loading_entire_file.php`
> code. for a working example of this code.
### listWorksheetInfo ### listWorksheetInfo
@ -691,5 +691,5 @@ foreach ($worksheetData as $worksheet) {
echo '</ol>'; echo '</ol>';
``` ```
> See Examples/Reader/exampleReader19.php for a working example of this See `samples/Reader/19_Reading_worksheet_information_without_loading_entire_file.php`
> code. for a working example of this code.

View File

@ -1,7 +0,0 @@
<?php
require __DIR__ . '/Header.php';
$spreadsheet = require __DIR__ . '/templates/sampleSpreadsheet.php';
// Save
$helper->write($spreadsheet, __FILE__);

View File

@ -1,8 +0,0 @@
<?php
require __DIR__ . '/Header.php';
$spreadsheet = require __DIR__ . '/templates/largeSpreadsheet.php';
// Save
$helper->write($spreadsheet, __FILE__);

View File

@ -1,178 +0,0 @@
<?php
use PhpOffice\PhpSpreadsheet\Calculation;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
mt_srand(1234567890);
require __DIR__ . '/Header.php';
// List functions
$helper->log('List implemented functions');
$calc = Calculation::getInstance();
print_r($calc->getImplementedFunctionNames());
// Create new Spreadsheet object
$helper->log('Create new Spreadsheet object');
$spreadsheet = new Spreadsheet();
// Add some data, we will use some formulas here
$helper->log('Add some data and formulas');
$spreadsheet->getActiveSheet()->setCellValue('A14', 'Count:')
->setCellValue('A15', 'Sum:')
->setCellValue('A16', 'Max:')
->setCellValue('A17', 'Min:')
->setCellValue('A18', 'Average:')
->setCellValue('A19', 'Median:')
->setCellValue('A20', 'Mode:');
$spreadsheet->getActiveSheet()->setCellValue('A22', 'CountA:')
->setCellValue('A23', 'MaxA:')
->setCellValue('A24', 'MinA:');
$spreadsheet->getActiveSheet()->setCellValue('A26', 'StDev:')
->setCellValue('A27', 'StDevA:')
->setCellValue('A28', 'StDevP:')
->setCellValue('A29', 'StDevPA:');
$spreadsheet->getActiveSheet()->setCellValue('A31', 'DevSq:')
->setCellValue('A32', 'Var:')
->setCellValue('A33', 'VarA:')
->setCellValue('A34', 'VarP:')
->setCellValue('A35', 'VarPA:');
$spreadsheet->getActiveSheet()->setCellValue('A37', 'Date:');
$spreadsheet->getActiveSheet()->setCellValue('B1', 'Range 1')
->setCellValue('B2', 2)
->setCellValue('B3', 8)
->setCellValue('B4', 10)
->setCellValue('B5', true)
->setCellValue('B6', false)
->setCellValue('B7', 'Text String')
->setCellValue('B9', '22')
->setCellValue('B10', 4)
->setCellValue('B11', 6)
->setCellValue('B12', 12);
$spreadsheet->getActiveSheet()->setCellValue('B14', '=COUNT(B2:B12)')
->setCellValue('B15', '=SUM(B2:B12)')
->setCellValue('B16', '=MAX(B2:B12)')
->setCellValue('B17', '=MIN(B2:B12)')
->setCellValue('B18', '=AVERAGE(B2:B12)')
->setCellValue('B19', '=MEDIAN(B2:B12)')
->setCellValue('B20', '=MODE(B2:B12)');
$spreadsheet->getActiveSheet()->setCellValue('B22', '=COUNTA(B2:B12)')
->setCellValue('B23', '=MAXA(B2:B12)')
->setCellValue('B24', '=MINA(B2:B12)');
$spreadsheet->getActiveSheet()->setCellValue('B26', '=STDEV(B2:B12)')
->setCellValue('B27', '=STDEVA(B2:B12)')
->setCellValue('B28', '=STDEVP(B2:B12)')
->setCellValue('B29', '=STDEVPA(B2:B12)');
$spreadsheet->getActiveSheet()->setCellValue('B31', '=DEVSQ(B2:B12)')
->setCellValue('B32', '=VAR(B2:B12)')
->setCellValue('B33', '=VARA(B2:B12)')
->setCellValue('B34', '=VARP(B2:B12)')
->setCellValue('B35', '=VARPA(B2:B12)');
$spreadsheet->getActiveSheet()->setCellValue('B37', '=DATE(2007, 12, 21)')
->setCellValue('B38', '=DATEDIF( DATE(2007, 12, 21), DATE(2007, 12, 22), "D" )')
->setCellValue('B39', '=DATEVALUE("01-Feb-2006 10:06 AM")')
->setCellValue('B40', '=DAY( DATE(2006, 1, 2) )')
->setCellValue('B41', '=DAYS360( DATE(2002, 2, 3), DATE(2005, 5, 31) )');
$spreadsheet->getActiveSheet()->setCellValue('C1', 'Range 2')
->setCellValue('C2', 1)
->setCellValue('C3', 2)
->setCellValue('C4', 2)
->setCellValue('C5', 3)
->setCellValue('C6', 3)
->setCellValue('C7', 3)
->setCellValue('C8', '0')
->setCellValue('C9', 4)
->setCellValue('C10', 4)
->setCellValue('C11', 4)
->setCellValue('C12', 4);
$spreadsheet->getActiveSheet()->setCellValue('C14', '=COUNT(C2:C12)')
->setCellValue('C15', '=SUM(C2:C12)')
->setCellValue('C16', '=MAX(C2:C12)')
->setCellValue('C17', '=MIN(C2:C12)')
->setCellValue('C18', '=AVERAGE(C2:C12)')
->setCellValue('C19', '=MEDIAN(C2:C12)')
->setCellValue('C20', '=MODE(C2:C12)');
$spreadsheet->getActiveSheet()->setCellValue('C22', '=COUNTA(C2:C12)')
->setCellValue('C23', '=MAXA(C2:C12)')
->setCellValue('C24', '=MINA(C2:C12)');
$spreadsheet->getActiveSheet()->setCellValue('C26', '=STDEV(C2:C12)')
->setCellValue('C27', '=STDEVA(C2:C12)')
->setCellValue('C28', '=STDEVP(C2:C12)')
->setCellValue('C29', '=STDEVPA(C2:C12)');
$spreadsheet->getActiveSheet()->setCellValue('C31', '=DEVSQ(C2:C12)')
->setCellValue('C32', '=VAR(C2:C12)')
->setCellValue('C33', '=VARA(C2:C12)')
->setCellValue('C34', '=VARP(C2:C12)')
->setCellValue('C35', '=VARPA(C2:C12)');
$spreadsheet->getActiveSheet()->setCellValue('D1', 'Range 3')
->setCellValue('D2', 2)
->setCellValue('D3', 3)
->setCellValue('D4', 4);
$spreadsheet->getActiveSheet()->setCellValue('D14', '=((D2 * D3) + D4) & " should be 10"');
$spreadsheet->getActiveSheet()->setCellValue('E12', 'Other functions')
->setCellValue('E14', '=PI()')
->setCellValue('E15', '=RAND()')
->setCellValue('E16', '=RANDBETWEEN(5, 10)');
$spreadsheet->getActiveSheet()->setCellValue('E17', 'Count of both ranges:')
->setCellValue('F17', '=COUNT(B2:C12)');
$spreadsheet->getActiveSheet()->setCellValue('E18', 'Total of both ranges:')
->setCellValue('F18', '=SUM(B2:C12)');
$spreadsheet->getActiveSheet()->setCellValue('E19', 'Maximum of both ranges:')
->setCellValue('F19', '=MAX(B2:C12)');
$spreadsheet->getActiveSheet()->setCellValue('E20', 'Minimum of both ranges:')
->setCellValue('F20', '=MIN(B2:C12)');
$spreadsheet->getActiveSheet()->setCellValue('E21', 'Average of both ranges:')
->setCellValue('F21', '=AVERAGE(B2:C12)');
$spreadsheet->getActiveSheet()->setCellValue('E22', 'Median of both ranges:')
->setCellValue('F22', '=MEDIAN(B2:C12)');
$spreadsheet->getActiveSheet()->setCellValue('E23', 'Mode of both ranges:')
->setCellValue('F23', '=MODE(B2:C12)');
// Calculated data
$helper->log('Calculated data');
for ($col = 'B'; $col != 'G'; ++$col) {
for ($row = 14; $row <= 41; ++$row) {
if ((!is_null($formula = $spreadsheet->getActiveSheet()->getCell($col . $row)->getValue())) &&
($formula[0] == '=')) {
echo 'Value of ', $col, $row, ' [', $formula, ']: ',
$spreadsheet->getActiveSheet()->getCell($col . $row)->getCalculatedValue() . EOL;
}
}
}
//
// If we set Pre Calculated Formulas to true then PhpSpreadsheet will calculate all formulae in the
// workbook before saving. This adds time and memory overhead, and can cause some problems with formulae
// using functions or features (such as array formulae) that aren't yet supported by the calculation engine
// If the value is false (the default) for the Xlsx Writer, then MS Excel (or the application used to
// open the file) will need to recalculate values itself to guarantee that the correct results are available.
//
//$writer->setPreCalculateFormulas(true);
// Save
$helper->write($spreadsheet, __FILE__);

View File

@ -2,7 +2,7 @@
use PhpOffice\PhpSpreadsheet\Spreadsheet; 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');

View File

@ -6,7 +6,7 @@ use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column; use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column;
use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule; 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');

View File

@ -6,7 +6,7 @@ use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column; use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column;
use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule; 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');

View File

@ -6,7 +6,7 @@ use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column; use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column;
use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule; 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');
@ -163,9 +163,8 @@ $spreadsheet->setActiveSheetIndex(0);
$helper->log('Display filtered rows'); $helper->log('Display filtered rows');
foreach ($spreadsheet->getActiveSheet()->getRowIterator() as $row) { foreach ($spreadsheet->getActiveSheet()->getRowIterator() as $row) {
if ($spreadsheet->getActiveSheet()->getRowDimension($row->getRowIndex())->getVisible()) { if ($spreadsheet->getActiveSheet()->getRowDimension($row->getRowIndex())->getVisible()) {
echo ' Row number - ', $row->getRowIndex(), ' '; $helper->log(' Row number - ' . $row->getRowIndex());
echo $spreadsheet->getActiveSheet()->getCell('C' . $row->getRowIndex())->getValue(), ' '; $helper->log($spreadsheet->getActiveSheet()->getCell('C' . $row->getRowIndex())->getValue());
echo $spreadsheet->getActiveSheet()->getCell('D' . $row->getRowIndex())->getFormattedValue(), ' '; $helper->log($spreadsheet->getActiveSheet()->getCell('D' . $row->getRowIndex())->getFormattedValue());
echo EOL;
} }
} }

View File

@ -2,7 +2,7 @@
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
require __DIR__ . '/Header.php'; require __DIR__ . '/../Header.php';
$spreadsheet = new Spreadsheet(); $spreadsheet = new Spreadsheet();
$helper->log('Create new Spreadsheet object'); $helper->log('Create new Spreadsheet object');

View File

@ -4,11 +4,11 @@ use PhpOffice\PhpSpreadsheet\Helper\Sample;
use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
require_once __DIR__ . '/../src/Bootstrap.php'; require_once __DIR__ . '/../../src/Bootstrap.php';
$helper = new Sample(); $helper = new Sample();
if ($helper->isCli()) { if ($helper->isCli()) {
echo 'This example should only be run from a Web Browser' . PHP_EOL; $helper->log('This example should only be run from a Web Browser' . PHP_EOL);
return; return;
} }

View File

@ -5,11 +5,11 @@ use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Settings; use PhpOffice\PhpSpreadsheet\Settings;
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
require_once __DIR__ . '/../src/Bootstrap.php'; require_once __DIR__ . '/../../src/Bootstrap.php';
$helper = new Sample(); $helper = new Sample();
if ($helper->isCli()) { if ($helper->isCli()) {
echo 'This example should only be run from a Web Browser' . PHP_EOL; $helper->log('This example should only be run from a Web Browser' . PHP_EOL);
return; return;
} }

View File

@ -4,11 +4,11 @@ use PhpOffice\PhpSpreadsheet\Helper\Sample;
use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
require_once __DIR__ . '/../src/Bootstrap.php'; require_once __DIR__ . '/../../src/Bootstrap.php';
$helper = new Sample(); $helper = new Sample();
if ($helper->isCli()) { if ($helper->isCli()) {
echo 'This example should only be run from a Web Browser' . PHP_EOL; $helper->log('This example should only be run from a Web Browser' . PHP_EOL);
return; return;
} }

View File

@ -4,11 +4,11 @@ use PhpOffice\PhpSpreadsheet\Helper\Sample;
use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
require_once __DIR__ . '/../src/Bootstrap.php'; require_once __DIR__ . '/../../src/Bootstrap.php';
$helper = new Sample(); $helper = new Sample();
if ($helper->isCli()) { if ($helper->isCli()) {
echo 'This example should only be run from a Web Browser' . PHP_EOL; $helper->log('This example should only be run from a Web Browser' . PHP_EOL);
return; return;
} }

View File

@ -6,7 +6,7 @@ use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Style\Color; use PhpOffice\PhpSpreadsheet\Style\Color;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat; 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');

View File

@ -2,7 +2,7 @@
use PhpOffice\PhpSpreadsheet\Spreadsheet; 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');
@ -35,31 +35,31 @@ $spreadsheet->getActiveSheet()->setCellValue('C1', 'Range #2')
->setCellValue('C3', 11) ->setCellValue('C3', 11)
->setCellValue('C4', 17) ->setCellValue('C4', 17)
->setCellValue('C5', '=SUM(C2:C4)'); ->setCellValue('C5', '=SUM(C2:C4)');
$helper->log('Sum of Range #2 is ', $spreadsheet->getActiveSheet()->getCell('C5')->getCalculatedValue()); $helper->log('Sum of Range #2 is ' . $spreadsheet->getActiveSheet()->getCell('C5')->getCalculatedValue());
$spreadsheet->getActiveSheet() $spreadsheet->getActiveSheet()
->setCellValue('A7', 'Total of both ranges:'); ->setCellValue('A7', 'Total of both ranges:');
$spreadsheet->getActiveSheet() $spreadsheet->getActiveSheet()
->setCellValue('B7', '=SUM(B5:C5)'); ->setCellValue('B7', '=SUM(B5:C5)');
$helper->log('Sum of both Ranges is ', $spreadsheet->getActiveSheet()->getCell('B7')->getCalculatedValue()); $helper->log('Sum of both Ranges is ' . $spreadsheet->getActiveSheet()->getCell('B7')->getCalculatedValue());
$spreadsheet->getActiveSheet() $spreadsheet->getActiveSheet()
->setCellValue('A8', 'Minimum of both ranges:'); ->setCellValue('A8', 'Minimum of both ranges:');
$spreadsheet->getActiveSheet() $spreadsheet->getActiveSheet()
->setCellValue('B8', '=MIN(B2:C4)'); ->setCellValue('B8', '=MIN(B2:C4)');
$helper->log('Minimum value in either Range is ', $spreadsheet->getActiveSheet()->getCell('B8')->getCalculatedValue()); $helper->log('Minimum value in either Range is ' . $spreadsheet->getActiveSheet()->getCell('B8')->getCalculatedValue());
$spreadsheet->getActiveSheet() $spreadsheet->getActiveSheet()
->setCellValue('A9', 'Maximum of both ranges:'); ->setCellValue('A9', 'Maximum of both ranges:');
$spreadsheet->getActiveSheet() $spreadsheet->getActiveSheet()
->setCellValue('B9', '=MAX(B2:C4)'); ->setCellValue('B9', '=MAX(B2:C4)');
$helper->log('Maximum value in either Range is ', $spreadsheet->getActiveSheet()->getCell('B9')->getCalculatedValue()); $helper->log('Maximum value in either Range is ' . $spreadsheet->getActiveSheet()->getCell('B9')->getCalculatedValue());
$spreadsheet->getActiveSheet() $spreadsheet->getActiveSheet()
->setCellValue('A10', 'Average of both ranges:'); ->setCellValue('A10', 'Average of both ranges:');
$spreadsheet->getActiveSheet() $spreadsheet->getActiveSheet()
->setCellValue('B10', '=AVERAGE(B2:C4)'); ->setCellValue('B10', '=AVERAGE(B2:C4)');
$helper->log('Average value of both Ranges is ', $spreadsheet->getActiveSheet()->getCell('B10')->getCalculatedValue()); $helper->log('Average value of both Ranges is ' . $spreadsheet->getActiveSheet()->getCell('B10')->getCalculatedValue());
$spreadsheet->getActiveSheet() $spreadsheet->getActiveSheet()
->getColumnDimension('A') ->getColumnDimension('A')
->setAutoSize(true); ->setAutoSize(true);

View File

@ -5,7 +5,7 @@ use PhpOffice\PhpSpreadsheet\Worksheet\HeaderFooter;
use PhpOffice\PhpSpreadsheet\Worksheet\HeaderFooterDrawing; use PhpOffice\PhpSpreadsheet\Worksheet\HeaderFooterDrawing;
use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup; 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');
@ -41,7 +41,7 @@ $spreadsheet->getActiveSheet()
$helper->log('Add a drawing to the header'); $helper->log('Add a drawing to the header');
$drawing = new 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()

View File

@ -0,0 +1,7 @@
<?php
require __DIR__ . '/../Header.php';
$spreadsheet = require __DIR__ . '/../templates/sampleSpreadsheet.php';
// Save
$helper->write($spreadsheet, __FILE__);

View File

@ -0,0 +1,8 @@
<?php
require __DIR__ . '/../Header.php';
$spreadsheet = require __DIR__ . '/../templates/largeSpreadsheet.php';
// Save
$helper->write($spreadsheet, __FILE__);

View File

@ -3,10 +3,10 @@
use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx; 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 Xlsx($sampleSpreadsheet); $writer = new Xlsx($sampleSpreadsheet);
$writer->save($filename); $writer->save($filename);

View File

@ -6,7 +6,7 @@ use PhpOffice\PhpSpreadsheet\Style\Conditional;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat; use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup; 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');

View File

@ -5,7 +5,7 @@ use PhpOffice\PhpSpreadsheet\Style\Color;
use PhpOffice\PhpSpreadsheet\Style\Conditional; use PhpOffice\PhpSpreadsheet\Style\Conditional;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat; 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');

View File

@ -3,7 +3,7 @@
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Worksheet; 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');

View File

@ -2,7 +2,7 @@
use PhpOffice\PhpSpreadsheet\Spreadsheet; 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');

View File

@ -3,7 +3,7 @@
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Style\Protection; 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');

View File

@ -0,0 +1,176 @@
<?php
use PhpOffice\PhpSpreadsheet\Calculation;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
mt_srand(1234567890);
require __DIR__ . '/../Header.php';
// List functions
$helper->log('List implemented functions');
$calc = Calculation::getInstance();
print_r($calc->getImplementedFunctionNames());
// Create new Spreadsheet object
$helper->log('Create new Spreadsheet object');
$spreadsheet = new Spreadsheet();
// Add some data, we will use some formulas here
$helper->log('Add some data and formulas');
$spreadsheet->getActiveSheet()->setCellValue('A14', 'Count:')
->setCellValue('A15', 'Sum:')
->setCellValue('A16', 'Max:')
->setCellValue('A17', 'Min:')
->setCellValue('A18', 'Average:')
->setCellValue('A19', 'Median:')
->setCellValue('A20', 'Mode:');
$spreadsheet->getActiveSheet()->setCellValue('A22', 'CountA:')
->setCellValue('A23', 'MaxA:')
->setCellValue('A24', 'MinA:');
$spreadsheet->getActiveSheet()->setCellValue('A26', 'StDev:')
->setCellValue('A27', 'StDevA:')
->setCellValue('A28', 'StDevP:')
->setCellValue('A29', 'StDevPA:');
$spreadsheet->getActiveSheet()->setCellValue('A31', 'DevSq:')
->setCellValue('A32', 'Var:')
->setCellValue('A33', 'VarA:')
->setCellValue('A34', 'VarP:')
->setCellValue('A35', 'VarPA:');
$spreadsheet->getActiveSheet()->setCellValue('A37', 'Date:');
$spreadsheet->getActiveSheet()->setCellValue('B1', 'Range 1')
->setCellValue('B2', 2)
->setCellValue('B3', 8)
->setCellValue('B4', 10)
->setCellValue('B5', true)
->setCellValue('B6', false)
->setCellValue('B7', 'Text String')
->setCellValue('B9', '22')
->setCellValue('B10', 4)
->setCellValue('B11', 6)
->setCellValue('B12', 12);
$spreadsheet->getActiveSheet()->setCellValue('B14', '=COUNT(B2:B12)')
->setCellValue('B15', '=SUM(B2:B12)')
->setCellValue('B16', '=MAX(B2:B12)')
->setCellValue('B17', '=MIN(B2:B12)')
->setCellValue('B18', '=AVERAGE(B2:B12)')
->setCellValue('B19', '=MEDIAN(B2:B12)')
->setCellValue('B20', '=MODE(B2:B12)');
$spreadsheet->getActiveSheet()->setCellValue('B22', '=COUNTA(B2:B12)')
->setCellValue('B23', '=MAXA(B2:B12)')
->setCellValue('B24', '=MINA(B2:B12)');
$spreadsheet->getActiveSheet()->setCellValue('B26', '=STDEV(B2:B12)')
->setCellValue('B27', '=STDEVA(B2:B12)')
->setCellValue('B28', '=STDEVP(B2:B12)')
->setCellValue('B29', '=STDEVPA(B2:B12)');
$spreadsheet->getActiveSheet()->setCellValue('B31', '=DEVSQ(B2:B12)')
->setCellValue('B32', '=VAR(B2:B12)')
->setCellValue('B33', '=VARA(B2:B12)')
->setCellValue('B34', '=VARP(B2:B12)')
->setCellValue('B35', '=VARPA(B2:B12)');
$spreadsheet->getActiveSheet()->setCellValue('B37', '=DATE(2007, 12, 21)')
->setCellValue('B38', '=DATEDIF( DATE(2007, 12, 21), DATE(2007, 12, 22), "D" )')
->setCellValue('B39', '=DATEVALUE("01-Feb-2006 10:06 AM")')
->setCellValue('B40', '=DAY( DATE(2006, 1, 2) )')
->setCellValue('B41', '=DAYS360( DATE(2002, 2, 3), DATE(2005, 5, 31) )');
$spreadsheet->getActiveSheet()->setCellValue('C1', 'Range 2')
->setCellValue('C2', 1)
->setCellValue('C3', 2)
->setCellValue('C4', 2)
->setCellValue('C5', 3)
->setCellValue('C6', 3)
->setCellValue('C7', 3)
->setCellValue('C8', '0')
->setCellValue('C9', 4)
->setCellValue('C10', 4)
->setCellValue('C11', 4)
->setCellValue('C12', 4);
$spreadsheet->getActiveSheet()->setCellValue('C14', '=COUNT(C2:C12)')
->setCellValue('C15', '=SUM(C2:C12)')
->setCellValue('C16', '=MAX(C2:C12)')
->setCellValue('C17', '=MIN(C2:C12)')
->setCellValue('C18', '=AVERAGE(C2:C12)')
->setCellValue('C19', '=MEDIAN(C2:C12)')
->setCellValue('C20', '=MODE(C2:C12)');
$spreadsheet->getActiveSheet()->setCellValue('C22', '=COUNTA(C2:C12)')
->setCellValue('C23', '=MAXA(C2:C12)')
->setCellValue('C24', '=MINA(C2:C12)');
$spreadsheet->getActiveSheet()->setCellValue('C26', '=STDEV(C2:C12)')
->setCellValue('C27', '=STDEVA(C2:C12)')
->setCellValue('C28', '=STDEVP(C2:C12)')
->setCellValue('C29', '=STDEVPA(C2:C12)');
$spreadsheet->getActiveSheet()->setCellValue('C31', '=DEVSQ(C2:C12)')
->setCellValue('C32', '=VAR(C2:C12)')
->setCellValue('C33', '=VARA(C2:C12)')
->setCellValue('C34', '=VARP(C2:C12)')
->setCellValue('C35', '=VARPA(C2:C12)');
$spreadsheet->getActiveSheet()->setCellValue('D1', 'Range 3')
->setCellValue('D2', 2)
->setCellValue('D3', 3)
->setCellValue('D4', 4);
$spreadsheet->getActiveSheet()->setCellValue('D14', '=((D2 * D3) + D4) & " should be 10"');
$spreadsheet->getActiveSheet()->setCellValue('E12', 'Other functions')
->setCellValue('E14', '=PI()')
->setCellValue('E15', '=RAND()')
->setCellValue('E16', '=RANDBETWEEN(5, 10)');
$spreadsheet->getActiveSheet()->setCellValue('E17', 'Count of both ranges:')
->setCellValue('F17', '=COUNT(B2:C12)');
$spreadsheet->getActiveSheet()->setCellValue('E18', 'Total of both ranges:')
->setCellValue('F18', '=SUM(B2:C12)');
$spreadsheet->getActiveSheet()->setCellValue('E19', 'Maximum of both ranges:')
->setCellValue('F19', '=MAX(B2:C12)');
$spreadsheet->getActiveSheet()->setCellValue('E20', 'Minimum of both ranges:')
->setCellValue('F20', '=MIN(B2:C12)');
$spreadsheet->getActiveSheet()->setCellValue('E21', 'Average of both ranges:')
->setCellValue('F21', '=AVERAGE(B2:C12)');
$spreadsheet->getActiveSheet()->setCellValue('E22', 'Median of both ranges:')
->setCellValue('F22', '=MEDIAN(B2:C12)');
$spreadsheet->getActiveSheet()->setCellValue('E23', 'Mode of both ranges:')
->setCellValue('F23', '=MODE(B2:C12)');
// Calculated data
$helper->log('Calculated data');
for ($col = 'B'; $col != 'G'; ++$col) {
for ($row = 14; $row <= 41; ++$row) {
if ((!is_null($formula = $spreadsheet->getActiveSheet()->getCell($col . $row)->getValue())) &&
($formula[0] == '=')) {
$helper->log('Value of ' . $col . $row . ' [' . $formula . ']: ' . $spreadsheet->getActiveSheet()->getCell($col . $row)->getCalculatedValue());
}
}
}
//
// If we set Pre Calculated Formulas to true then PhpSpreadsheet will calculate all formulae in the
// workbook before saving. This adds time and memory overhead, and can cause some problems with formulae
// using functions or features (such as array formulae) that aren't yet supported by the calculation engine
// If the value is false (the default) for the Xlsx Writer, then MS Excel (or the application used to
// open the file) will need to recalculate values itself to guarantee that the correct results are available.
//
//$writer->setPreCalculateFormulas(true);
// Save
$helper->write($spreadsheet, __FILE__);

View File

@ -3,7 +3,7 @@
use PhpOffice\PhpSpreadsheet\Calculation; use PhpOffice\PhpSpreadsheet\Calculation;
use PhpOffice\PhpSpreadsheet\Spreadsheet; 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');
@ -24,8 +24,7 @@ for ($row = 1; $row <= 2; ++$row) {
for ($col = 'A'; $col != 'C'; ++$col) { for ($col = 'A'; $col != 'C'; ++$col) {
if ((!is_null($formula = $spreadsheet->getActiveSheet()->getCell($col . $row)->getValue())) && if ((!is_null($formula = $spreadsheet->getActiveSheet()->getCell($col . $row)->getValue())) &&
($formula[0] == '=')) { ($formula[0] == '=')) {
echo 'Value of ', $col, $row, ' [', $formula, ']: ', $helper->log('Value of ' . $col . $row . ' [' . $formula . ']: ' . $spreadsheet->getActiveSheet()->getCell($col . $row)->getCalculatedValue());
$spreadsheet->getActiveSheet()->getCell($col . $row)->getCalculatedValue() . EOL;
} }
} }
} }

View File

@ -2,8 +2,8 @@
use PhpOffice\PhpSpreadsheet\IOFactory; 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 = IOFactory::createWriter($spreadsheet, 'Xls'); $writer = IOFactory::createWriter($spreadsheet, 'Xls');

View File

@ -3,7 +3,7 @@
use PhpOffice\PhpSpreadsheet\Cell\DataValidation; use PhpOffice\PhpSpreadsheet\Cell\DataValidation;
use PhpOffice\PhpSpreadsheet\Spreadsheet; 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');

View File

@ -2,8 +2,8 @@
use PhpOffice\PhpSpreadsheet\IOFactory; 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 = IOFactory::createWriter($spreadsheet, 'Csv')->setDelimiter(',') $writer = IOFactory::createWriter($spreadsheet, 'Csv')->setDelimiter(',')

View File

@ -2,8 +2,8 @@
use PhpOffice\PhpSpreadsheet\IOFactory; 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 = IOFactory::createWriter($spreadsheet, 'Html'); $writer = IOFactory::createWriter($spreadsheet, 'Html');

View File

@ -3,7 +3,7 @@
use PhpOffice\PhpSpreadsheet\Calculation; use PhpOffice\PhpSpreadsheet\Calculation;
use PhpOffice\PhpSpreadsheet\Spreadsheet; 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');
@ -64,6 +64,6 @@ $spreadsheet->getActiveSheet()->setCellValue('F14', '=COUNT(B2:C12)');
// Calculated data // Calculated data
$helper->log('Calculated data'); $helper->log('Calculated data');
echo 'Value of B14 [=COUNT(B2:B12)]: ' . $spreadsheet->getActiveSheet()->getCell('B14')->getCalculatedValue() . "\r\n"; $helper->log('Value of B14 [=COUNT(B2:B12)]: ' . $spreadsheet->getActiveSheet()->getCell('B14')->getCalculatedValue());
$helper->logEndingNotes(); $helper->logEndingNotes();

View File

@ -3,7 +3,7 @@
use PhpOffice\PhpSpreadsheet\NamedRange; use PhpOffice\PhpSpreadsheet\NamedRange;
use PhpOffice\PhpSpreadsheet\Spreadsheet; 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');

View File

@ -2,9 +2,9 @@
use PhpOffice\PhpSpreadsheet\IOFactory; 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 = IOFactory::load($filename); $spreadsheet = IOFactory::load($filename);
$helper->logRead('Xml', $filename, $callStartTime); $helper->logRead('Xml', $filename, $callStartTime);

View File

@ -2,9 +2,9 @@
use PhpOffice\PhpSpreadsheet\IOFactory; 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 = IOFactory::load($filename); $spreadsheet = IOFactory::load($filename);
$helper->logRead('Gnumeric', $filename, $callStartTime); $helper->logRead('Gnumeric', $filename, $callStartTime);

View File

@ -2,9 +2,9 @@
use PhpOffice\PhpSpreadsheet\IOFactory; 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 = IOFactory::load($filename); $spreadsheet = IOFactory::load($filename);
$helper->logRead('Ods', $filename, $callStartTime); $helper->logRead('Ods', $filename, $callStartTime);

View File

@ -2,9 +2,9 @@
use PhpOffice\PhpSpreadsheet\IOFactory; 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 = IOFactory::load($filename); $spreadsheet = IOFactory::load($filename);
$helper->logRead('Slk', $filename, $callStartTime); $helper->logRead('Slk', $filename, $callStartTime);

View File

@ -2,9 +2,9 @@
use PhpOffice\PhpSpreadsheet\IOFactory; 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');

View File

@ -4,7 +4,7 @@ use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Style\Border; use PhpOffice\PhpSpreadsheet\Style\Border;
use PhpOffice\PhpSpreadsheet\Style\Fill; 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');

View File

@ -5,7 +5,7 @@ use PhpOffice\PhpSpreadsheet\Style;
use PhpOffice\PhpSpreadsheet\Style\Border; use PhpOffice\PhpSpreadsheet\Style\Border;
use PhpOffice\PhpSpreadsheet\Style\Fill; 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');

View File

@ -5,10 +5,10 @@ namespace PhpOffice\PhpSpreadsheet;
use PhpOffice\PhpSpreadsheet\Reader\IReadFilter; use PhpOffice\PhpSpreadsheet\Reader\IReadFilter;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx; 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 Xlsx($largeSpreadsheet); $writer = new Xlsx($largeSpreadsheet);
$filename = $helper->getTemporaryFilename(); $filename = $helper->getTemporaryFilename();
$callStartTime = microtime(true); $callStartTime = microtime(true);

View File

@ -3,7 +3,7 @@
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing; 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');

View File

@ -3,7 +3,7 @@
use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Settings; 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
@ -14,7 +14,7 @@ $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 = 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 */
$helper->write($spreadsheet, __FILE__, ['Xlsx', 'Xls', 'Html']); $helper->write($spreadsheet, __FILE__, ['Xlsx', 'Xls', 'Html']);

View File

@ -2,12 +2,12 @@
use PhpOffice\PhpSpreadsheet\IOFactory; 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 = IOFactory::createReader('Xls'); $reader = IOFactory::createReader('Xls');
$spreadsheet = $reader->load(__DIR__ . '/templates/27template.xls'); $spreadsheet = $reader->load(__DIR__ . '/../templates/27template.xls');
// Save // Save
$helper->write($spreadsheet, __FILE__); $helper->write($spreadsheet, __FILE__);

View File

@ -3,9 +3,9 @@
use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx; 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 Xlsx($sampleSpreadsheet); $writer = new Xlsx($sampleSpreadsheet);
$callStartTime = microtime(true); $callStartTime = microtime(true);

View File

@ -3,7 +3,7 @@
use PhpOffice\PhpSpreadsheet\Cell; use PhpOffice\PhpSpreadsheet\Cell;
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
require __DIR__ . '/Header.php'; require __DIR__ . '/../Header.php';
// Set timezone // Set timezone
$helper->log('Set timezone'); $helper->log('Set timezone');

View File

@ -3,11 +3,11 @@
use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Shared\Date; 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 = 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');
$data = [['title' => 'Excel for dummies', $data = [['title' => 'Excel for dummies',

View File

@ -3,10 +3,10 @@
use PhpOffice\PhpSpreadsheet\Document\Properties; use PhpOffice\PhpSpreadsheet\Document\Properties;
use PhpOffice\PhpSpreadsheet\IOFactory; 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 = IOFactory::createReader($inputFileType); $spreadsheetReader = IOFactory::createReader($inputFileType);
$callStartTime = microtime(true); $callStartTime = microtime(true);
@ -26,7 +26,6 @@ $callStartTime = microtime(true);
$writer->save($filename); $writer->save($filename);
$helper->logWrite($writer, $filename, $callStartTime); $helper->logWrite($writer, $filename, $callStartTime);
// Echo memory peak usage
$helper->logEndingNotes(); $helper->logEndingNotes();
// Reread File // Reread File
@ -38,9 +37,9 @@ $helper->log('Get properties');
$helper->log('Core Properties:'); $helper->log('Core Properties:');
$helper->log(' Created by - ' . $spreadsheet->getProperties()->getCreator()); $helper->log(' Created by - ' . $spreadsheet->getProperties()->getCreator());
$helper->log(' Created on - ' . date('d-M-Y', $spreadsheet->getProperties()->getCreated()) . ' at ' . date('H:i:s', $spreadsheet->getProperties()->getCreated())); $helper->log(' Created on - ' . date('d-M-Y' . $spreadsheet->getProperties()->getCreated()) . ' at ' . date('H:i:s' . $spreadsheet->getProperties()->getCreated()));
$helper->log(' Last Modified by - ' . $spreadsheet->getProperties()->getLastModifiedBy()); $helper->log(' Last Modified by - ' . $spreadsheet->getProperties()->getLastModifiedBy());
$helper->log(' Last Modified on - ' . date('d-M-Y', $spreadsheet->getProperties()->getModified()) . ' at ' . date('H:i:s', $spreadsheet->getProperties()->getModified())); $helper->log(' Last Modified on - ' . date('d-M-Y' . $spreadsheet->getProperties()->getModified()) . ' at ' . date('H:i:s' . $spreadsheet->getProperties()->getModified()));
$helper->log(' Title - ' . $spreadsheet->getProperties()->getTitle()); $helper->log(' Title - ' . $spreadsheet->getProperties()->getTitle());
$helper->log(' Subject - ' . $spreadsheet->getProperties()->getSubject()); $helper->log(' Subject - ' . $spreadsheet->getProperties()->getSubject());
$helper->log(' Description - ' . $spreadsheet->getProperties()->getDescription()); $helper->log(' Description - ' . $spreadsheet->getProperties()->getDescription());
@ -66,5 +65,4 @@ foreach ($customProperties as $customProperty) {
$helper->log(' ' . $customProperty . ' - (' . $propertyType . ') - ' . $formattedValue); $helper->log(' ' . $customProperty . ' - (' . $propertyType . ') - ' . $formattedValue);
} }
// Echo memory peak usage
$helper->logEndingNotes(); $helper->logEndingNotes();

View File

@ -3,10 +3,10 @@
use PhpOffice\PhpSpreadsheet\Document\Properties; use PhpOffice\PhpSpreadsheet\Document\Properties;
use PhpOffice\PhpSpreadsheet\IOFactory; 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 = IOFactory::createReader($inputFileType); $spreadsheetReader = IOFactory::createReader($inputFileType);
$callStartTime = microtime(true); $callStartTime = microtime(true);
@ -26,7 +26,6 @@ $callStartTime = microtime(true);
$writer->save($filename); $writer->save($filename);
$helper->logWrite($writer, $filename, $callStartTime); $helper->logWrite($writer, $filename, $callStartTime);
// Echo memory peak usage
$helper->logEndingNotes(); $helper->logEndingNotes();
// Reread File // Reread File
@ -38,9 +37,9 @@ $helper->log('Get properties');
$helper->log('Core Properties:'); $helper->log('Core Properties:');
$helper->log(' Created by - ' . $spreadsheet->getProperties()->getCreator()); $helper->log(' Created by - ' . $spreadsheet->getProperties()->getCreator());
$helper->log(' Created on - ' . date('d-M-Y', $spreadsheet->getProperties()->getCreated()) . ' at ' . date('H:i:s', $spreadsheet->getProperties()->getCreated())); $helper->log(' Created on - ' . date('d-M-Y' . $spreadsheet->getProperties()->getCreated()) . ' at ' . date('H:i:s' . $spreadsheet->getProperties()->getCreated()));
$helper->log(' Last Modified by - ' . $spreadsheet->getProperties()->getLastModifiedBy()); $helper->log(' Last Modified by - ' . $spreadsheet->getProperties()->getLastModifiedBy());
$helper->log(' Last Modified on - ' . date('d-M-Y', $spreadsheet->getProperties()->getModified()) . ' at ' . date('H:i:s', $spreadsheet->getProperties()->getModified())); $helper->log(' Last Modified on - ' . date('d-M-Y' . $spreadsheet->getProperties()->getModified()) . ' at ' . date('H:i:s' . $spreadsheet->getProperties()->getModified()));
$helper->log(' Title - ' . $spreadsheet->getProperties()->getTitle()); $helper->log(' Title - ' . $spreadsheet->getProperties()->getTitle());
$helper->log(' Subject - ' . $spreadsheet->getProperties()->getSubject()); $helper->log(' Subject - ' . $spreadsheet->getProperties()->getSubject());
$helper->log(' Description - ' . $spreadsheet->getProperties()->getDescription()); $helper->log(' Description - ' . $spreadsheet->getProperties()->getDescription());
@ -66,5 +65,4 @@ foreach ($customProperties as $customProperty) {
$helper->log(' ' . $customProperty . ' - (' . $propertyType . ') - ' . $formattedValue); $helper->log(' ' . $customProperty . ' - (' . $propertyType . ') - ' . $formattedValue);
} }
// Echo memory peak usage
$helper->logEndingNotes(); $helper->logEndingNotes();

View File

@ -3,7 +3,7 @@
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Worksheet\SheetView; use PhpOffice\PhpSpreadsheet\Worksheet\SheetView;
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');

View File

@ -2,7 +2,7 @@
use PhpOffice\PhpSpreadsheet\Spreadsheet; 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');

View File

@ -4,7 +4,7 @@ use PhpOffice\PhpSpreadsheet\Cell\DataValidation;
use PhpOffice\PhpSpreadsheet\NamedRange; use PhpOffice\PhpSpreadsheet\NamedRange;
use PhpOffice\PhpSpreadsheet\Spreadsheet; 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');
@ -30,10 +30,10 @@ $continentColumn = 'D';
$column = 'F'; $column = 'F';
// Set data for dropdowns // Set data for dropdowns
$continents = glob('./data/continents/*'); $continents = glob(__DIR__ . '/data/continents/*');
foreach ($continents as $key => $filename) { foreach ($continents as $key => $filename) {
$continent = pathinfo($filename, PATHINFO_FILENAME); $continent = pathinfo($filename, PATHINFO_FILENAME);
echo "Loading $continent", EOL; $helper->log("Loading $continent");
$continent = str_replace(' ', '_', $continent); $continent = str_replace(' ', '_', $continent);
$countries = file($filename, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); $countries = file($filename, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$countryCount = count($countries); $countryCount = count($countries);

View File

@ -4,7 +4,7 @@ use PhpOffice\PhpSpreadsheet\Cell;
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Style; use PhpOffice\PhpSpreadsheet\Style;
require __DIR__ . '/Header.php'; require __DIR__ . '/../Header.php';
$helper->log('Create new Spreadsheet object'); $helper->log('Create new Spreadsheet object');
$spreadsheet = new Spreadsheet(); $spreadsheet = new Spreadsheet();
@ -30,7 +30,7 @@ for ($col = 0; $col < 50; ++$col) {
} }
} }
$d = microtime(true) - $t; $d = microtime(true) - $t;
$helper->log('Add data (end), time: ' . round($d, 2) . ' s'); $helper->log('Add data (end) . time: ' . round($d . 2) . ' s');
// Save // Save
$helper->write($spreadsheet, __FILE__); $helper->write($spreadsheet, __FILE__);

View File

@ -1,7 +1,7 @@
<?php <?php
require __DIR__ . '/Header.php'; require __DIR__ . '/../Header.php';
$spreadsheet = require __DIR__ . '/templates/sampleSpreadsheet.php'; $spreadsheet = require __DIR__ . '/../templates/sampleSpreadsheet.php';
// Set password against the spreadsheet file // Set password against the spreadsheet file
$spreadsheet->getSecurity()->setLockWindows(true); $spreadsheet->getSecurity()->setLockWindows(true);

View File

@ -3,7 +3,7 @@
use PhpOffice\PhpSpreadsheet\Helper\Html as HtmlHelper; use PhpOffice\PhpSpreadsheet\Helper\Html as HtmlHelper;
use PhpOffice\PhpSpreadsheet\Spreadsheet; 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');

View File

@ -2,16 +2,16 @@
use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\IOFactory;
require __DIR__ . '/Header.php'; require __DIR__ . '/../Header.php';
$helper->log('Load MergeBook1 from Xlsx file'); $helper->log('Load MergeBook1 from Xlsx file');
$filename1 = __DIR__ . '/templates/43mergeBook1.xlsx'; $filename1 = __DIR__ . '/../templates/43mergeBook1.xlsx';
$callStartTime = microtime(true); $callStartTime = microtime(true);
$spreadsheet1 = IOFactory::load($filename1); $spreadsheet1 = IOFactory::load($filename1);
$helper->logRead('Xlsx', $filename1, $callStartTime); $helper->logRead('Xlsx', $filename1, $callStartTime);
$helper->log('Load MergeBook2 from Xlsx file'); $helper->log('Load MergeBook2 from Xlsx file');
$filename2 = __DIR__ . '/templates/43mergeBook2.xlsx'; $filename2 = __DIR__ . '/../templates/43mergeBook2.xlsx';
$callStartTime = microtime(true); $callStartTime = microtime(true);
$spreadsheet2 = IOFactory::load($filename2); $spreadsheet2 = IOFactory::load($filename2);
$helper->logRead('Xlsx', $filename2, $callStartTime); $helper->logRead('Xlsx', $filename2, $callStartTime);

View File

@ -3,10 +3,10 @@
use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx; 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 Xlsx($sampleSpreadsheet); $writer = new Xlsx($sampleSpreadsheet);
$writer->save($filename); $writer->save($filename);

View File

@ -1,7 +1,7 @@
<?php <?php
use PhpOffice\PhpSpreadsheet\Calculation; use PhpOffice\PhpSpreadsheet\Calculation;
require __DIR__ . '/Header.php'; require __DIR__ . '/../Header.php';
?> ?>
<form action="45_Quadratic_equation_solver.php" method="POST"> <form action="45_Quadratic_equation_solver.php" method="POST">
Enter the coefficients for the Ax<sup>2</sup> + Bx + C = 0 Enter the coefficients for the Ax<sup>2</sup> + Bx + C = 0
@ -24,10 +24,10 @@ require __DIR__ . '/Header.php';
/** If the user has submitted the form, then we need to execute a calculation * */ /** If the user has submitted the form, then we need to execute a calculation * */
if (isset($_POST['submit'])) { if (isset($_POST['submit'])) {
if ($_POST['A'] == 0) { if ($_POST['A'] == 0) {
echo 'The equation is not quadratic'; $helper->log('The equation is not quadratic');
} else { } else {
/* Calculate and Display the results * */ /* Calculate and Display the results * */
echo '<hr /><b>Roots:</b><br />'; $helper->log('<hr /><b>Roots:</b><br />');
$discriminantFormula = '=POWER(' . $_POST['B'] . ',2) - (4 * ' . $_POST['A'] . ' * ' . $_POST['C'] . ')'; $discriminantFormula = '=POWER(' . $_POST['B'] . ',2) - (4 * ' . $_POST['A'] . ' * ' . $_POST['C'] . ')';
$discriminant = Calculation::getInstance()->calculateFormula($discriminantFormula); $discriminant = Calculation::getInstance()->calculateFormula($discriminantFormula);
@ -35,8 +35,8 @@ if (isset($_POST['submit'])) {
$r1Formula = '=IMDIV(IMSUM(-' . $_POST['B'] . ',IMSQRT(' . $discriminant . ')),2 * ' . $_POST['A'] . ')'; $r1Formula = '=IMDIV(IMSUM(-' . $_POST['B'] . ',IMSQRT(' . $discriminant . ')),2 * ' . $_POST['A'] . ')';
$r2Formula = '=IF(' . $discriminant . '=0,"Only one root",IMDIV(IMSUB(-' . $_POST['B'] . ',IMSQRT(' . $discriminant . ')),2 * ' . $_POST['A'] . '))'; $r2Formula = '=IF(' . $discriminant . '=0,"Only one root",IMDIV(IMSUB(-' . $_POST['B'] . ',IMSQRT(' . $discriminant . ')),2 * ' . $_POST['A'] . '))';
echo Calculation::getInstance()->calculateFormula($r1Formula) . '<br />'; $helper->log(Calculation::getInstance()->calculateFormula($r1Formula));
echo Calculation::getInstance()->calculateFormula($r2Formula) . '<br />'; $helper->log(Calculation::getInstance()->calculateFormula($r2Formula));
$callEndTime = microtime(true); $callEndTime = microtime(true);
$helper->logEndingNotes(); $helper->logEndingNotes();
} }

View File

@ -5,9 +5,9 @@ error_reporting(0);
use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\IOFactory;
require __DIR__ . '/Header.php'; require __DIR__ . '/../Header.php';
$html = __DIR__ . '/templates/46readHtml.html'; $html = __DIR__ . '/../templates/46readHtml.html';
$callStartTime = microtime(true); $callStartTime = microtime(true);
$objReader = IOFactory::createReader('Html'); $objReader = IOFactory::createReader('Html');

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