Code style partially according to Scrutinizer

This commit is contained in:
Adrien Crivelli 2017-08-03 12:03:24 +02:00
parent 31daed0048
commit 4a47a32953
No known key found for this signature in database
GPG Key ID: B182FD79DC6DE92E
46 changed files with 1532 additions and 1706 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -6,51 +6,49 @@ error_reporting(E_ALL);
set_time_limit(0); set_time_limit(0);
date_default_timezone_set('Europe/London'); date_default_timezone_set('Europe/London');
?> ?>
<html> <html>
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PhpSpreadsheet Calculation Examples</title> <title>PhpSpreadsheet Calculation Examples</title>
</head> </head>
<body> <body>
<h1>DATEVALUE</h1> <h1>DATEVALUE</h1>
<h2>Converts a date in the form of text to a serial number.</h2> <h2>Converts a date in the form of text to a serial number.</h2>
<?php <?php
require_once __DIR__ . '/../../../../src/Bootstrap.php';
require_once __DIR__ . '/../../../../src/Bootstrap.php'; // Create new PhpSpreadsheet object
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
// Create new PhpSpreadsheet object // Add some data
$spreadsheet = new Spreadsheet(); $testDates = ['26 March 2012', '29 Feb 2012', 'April 1, 2012', '25/12/2012',
$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', '2012-Oct-31', '5th November', 'January 1st', 'April 2012',
'17-03', '03-2012', '29 Feb 2011', '03-05-07', '17-03', '03-2012', '29 Feb 2011', '03-05-07',
'03-MAY-07', '03-13-07', '03-MAY-07', '03-13-07',
]; ];
$testDateCount = count($testDates); $testDateCount = count($testDates);
for ($row = 1; $row <= $testDateCount; ++$row) { for ($row = 1; $row <= $testDateCount; ++$row) {
$worksheet->setCellValue('A' . $row, $testDates[$row - 1]); $worksheet->setCellValue('A' . $row, $testDates[$row - 1]);
$worksheet->setCellValue('B' . $row, '=DATEVALUE(A' . $row . ')'); $worksheet->setCellValue('B' . $row, '=DATEVALUE(A' . $row . ')');
$worksheet->setCellValue('C' . $row, '=B' . $row); $worksheet->setCellValue('C' . $row, '=B' . $row);
} }
$worksheet->getStyle('C1:C' . $testDateCount) $worksheet->getStyle('C1:C' . $testDateCount)
->getNumberFormat() ->getNumberFormat()
->setFormatCode('yyyy-mmm-dd'); ->setFormatCode('yyyy-mmm-dd');
echo '<hr />'; echo '<hr />';
// Test the formulae // 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> <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"> <table border="1" cellspacing="0">
<tr> <tr>
<th>Date String</th> <th>Date String</th>
<th>Formula</th> <th>Formula</th>
@ -67,6 +65,6 @@ echo '<hr />';
echo '</tr>'; echo '</tr>';
} }
?> ?>
</table> </table>
</body> </body>
</html> </html>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -7,37 +7,30 @@ error_reporting(E_ALL);
set_time_limit(0); set_time_limit(0);
date_default_timezone_set('Europe/London'); date_default_timezone_set('Europe/London');
?> ?>
<html> <html>
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PhpSpreadsheet Reader Example #10</title> <title>PhpSpreadsheet Reader Example #10</title>
</head> </head>
<body> <body>
<h1>PhpSpreadsheet Reader Example #10</h1> <h1>PhpSpreadsheet Reader Example #10</h1>
<h2>Simple File Reader Using a Configurable Read Filter</h2> <h2>Simple File Reader Using a Configurable Read Filter</h2>
<?php <?php
require_once __DIR__ . '/../../../src/Bootstrap.php';
require_once __DIR__ . '/../../../src/Bootstrap.php'; $inputFileType = 'Xls';
$inputFileName = './sampleData/example1.xls';
$sheetname = 'Data Sheet #3';
$inputFileType = 'Xls'; class MyReadFilter implements IReadFilter
// $inputFileType = 'Xlsx'; {
// $inputFileType = 'Xml';
// $inputFileType = 'Ods';
// $inputFileType = 'Gnumeric';
$inputFileName = './sampleData/example1.xls';
$sheetname = 'Data Sheet #3';
class MyReadFilter implements IReadFilter
{
private $_startRow = 0; private $_startRow = 0;
private $_endRow = 0; private $_endRow = 0;
private $_columns = []; private $_columns = [];
public function __construct($startRow, $endRow, $columns) public function __construct($startRow, $endRow, $columns)
@ -57,23 +50,23 @@ class MyReadFilter implements IReadFilter
return false; 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 />'; $filterSubset = new MyReadFilter(9, 15, range('G', 'K'));
$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 />'; 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);
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true); echo '<hr />';
var_dump($sheetData);
?> $sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
<body> var_dump($sheetData);
?>
<body>
</html> </html>

View File

@ -7,35 +7,29 @@ error_reporting(E_ALL);
set_time_limit(0); set_time_limit(0);
date_default_timezone_set('Europe/London'); date_default_timezone_set('Europe/London');
?> ?>
<html> <html>
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PhpSpreadsheet Reader Example #11</title> <title>PhpSpreadsheet Reader Example #11</title>
</head> </head>
<body> <body>
<h1>PhpSpreadsheet Reader Example #11</h1> <h1>PhpSpreadsheet Reader Example #11</h1>
<h2>Reading a Workbook in "Chunks" Using a Configurable Read Filter (Version 1)</h2> <h2>Reading a Workbook in "Chunks" Using a Configurable Read Filter (Version 1)</h2>
<?php <?php
require_once __DIR__ . '/../../../src/Bootstrap.php';
require_once __DIR__ . '/../../../src/Bootstrap.php'; $inputFileType = 'Xls';
$inputFileName = './sampleData/example2.xls';
$inputFileType = 'Xls'; /** Define a Read Filter class implementing IReadFilter */
// $inputFileType = 'Xlsx'; class chunkReadFilter implements IReadFilter
// $inputFileType = 'Xml'; {
// $inputFileType = 'Ods';
// $inputFileType = 'Gnumeric';
$inputFileName = './sampleData/example2.xls';
/** Define a Read Filter class implementing IReadFilter */
class chunkReadFilter implements IReadFilter
{
private $_startRow = 0; private $_startRow = 0;
private $_endRow = 0; private $_endRow = 0;
/** /**
@ -59,25 +53,26 @@ class chunkReadFilter implements IReadFilter
return false; 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 />'; 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);
/* Define how many rows we want for each "chunk" **/ echo '<hr />';
$chunkSize = 20;
/* Loop to read our worksheet in "chunk size" blocks **/ /* Define how many rows we want for each "chunk" * */
for ($startRow = 2; $startRow <= 240; $startRow += $chunkSize) { $chunkSize = 20;
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 **/ /* 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); $chunkFilter = new chunkReadFilter($startRow, $chunkSize);
/* Tell the Reader that we want to use the new Read Filter that we've just Instantiated **/ /* Tell the Reader that we want to use the new Read Filter that we've just Instantiated * */
$reader->setReadFilter($chunkFilter); $reader->setReadFilter($chunkFilter);
/* Load only the rows that match our filter from $inputFileName to a PhpSpreadsheet Object **/ /* Load only the rows that match our filter from $inputFileName to a PhpSpreadsheet Object * */
$spreadsheet = $reader->load($inputFileName); $spreadsheet = $reader->load($inputFileName);
// Do some processing here // Do some processing here
@ -85,8 +80,7 @@ for ($startRow = 2; $startRow <= 240; $startRow += $chunkSize) {
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true); $sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
var_dump($sheetData); var_dump($sheetData);
echo '<br /><br />'; echo '<br /><br />';
} }
?>
?> <body>
<body>
</html> </html>

View File

@ -7,35 +7,29 @@ error_reporting(E_ALL);
set_time_limit(0); set_time_limit(0);
date_default_timezone_set('Europe/London'); date_default_timezone_set('Europe/London');
?> ?>
<html> <html>
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PhpSpreadsheet Reader Example #12</title> <title>PhpSpreadsheet Reader Example #12</title>
</head> </head>
<body> <body>
<h1>PhpSpreadsheet Reader Example #12</h1> <h1>PhpSpreadsheet Reader Example #12</h1>
<h2>Reading a Workbook in "Chunks" Using a Configurable Read Filter (Version 2)</h2> <h2>Reading a Workbook in "Chunks" Using a Configurable Read Filter (Version 2)</h2>
<?php <?php
require_once __DIR__ . '/../../../src/Bootstrap.php';
require_once __DIR__ . '/../../../src/Bootstrap.php'; $inputFileType = 'Xls';
$inputFileName = './sampleData/example2.xls';
$inputFileType = 'Xls'; /** Define a Read Filter class implementing IReadFilter */
// $inputFileType = 'Xlsx'; class chunkReadFilter implements IReadFilter
// $inputFileType = 'Xml'; {
// $inputFileType = 'Ods';
// $inputFileType = 'Gnumeric';
$inputFileName = './sampleData/example2.xls';
/** Define a Read Filter class implementing IReadFilter */
class chunkReadFilter implements IReadFilter
{
private $_startRow = 0; private $_startRow = 0;
private $_endRow = 0; private $_endRow = 0;
/** /**
@ -59,28 +53,29 @@ class chunkReadFilter implements IReadFilter
return false; 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 />'; 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);
/* Define how many rows we want to read for each "chunk" **/ echo '<hr />';
$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 **/ /* Define how many rows we want to read for each "chunk" * */
$reader->setReadFilter($chunkFilter); $chunkSize = 20;
/* Create a new Instance of our Read Filter * */
$chunkFilter = new chunkReadFilter();
/* Loop to read our worksheet in "chunk size" blocks **/ /* Tell the Reader that we want to use the Read Filter that we've Instantiated * */
for ($startRow = 2; $startRow <= 240; $startRow += $chunkSize) { $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 />'; 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 **/ /* Tell the Read Filter, the limits on which rows we want to read this iteration * */
$chunkFilter->setRows($startRow, $chunkSize); $chunkFilter->setRows($startRow, $chunkSize);
/* Load only the rows that match our filter from $inputFileName to a PhpSpreadsheet Object **/ /* Load only the rows that match our filter from $inputFileName to a PhpSpreadsheet Object * */
$spreadsheet = $reader->load($inputFileName); $spreadsheet = $reader->load($inputFileName);
// Do some processing here // Do some processing here
@ -88,8 +83,7 @@ for ($startRow = 2; $startRow <= 240; $startRow += $chunkSize) {
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true); $sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
var_dump($sheetData); var_dump($sheetData);
echo '<br /><br />'; echo '<br /><br />';
} }
?>
?> <body>
<body>
</html> </html>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -6,46 +6,44 @@ error_reporting(E_ALL);
set_time_limit(0); set_time_limit(0);
date_default_timezone_set('Europe/London'); date_default_timezone_set('Europe/London');
?> ?>
<html> <html>
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PhpSpreadsheet Reading WorkBook Data Example #03</title> <title>PhpSpreadsheet Reading WorkBook Data Example #03</title>
</head> </head>
<body> <body>
<h1>PhpSpreadsheet Reading WorkBook Data Example #03</h1> <h1>PhpSpreadsheet Reading WorkBook Data Example #03</h1>
<h2>Read Custom Property Values for a WorkBook</h2> <h2>Read Custom Property Values for a WorkBook</h2>
<?php <?php
require_once __DIR__ . '/../../../src/Bootstrap.php';
require_once __DIR__ . '/../../../src/Bootstrap.php'; $inputFileType = 'Xlsx';
$inputFileName = './sampleData/example1.xlsx';
$inputFileType = 'Xlsx'; /* Create a new Reader of the type defined in $inputFileType * */
$inputFileName = './sampleData/example1.xlsx'; $reader = IOFactory::createReader($inputFileType);
/* Load $inputFileName to a PhpSpreadsheet Object * */
$spreadsheet = $reader->load($inputFileName);
/* Create a new Reader of the type defined in $inputFileType **/ echo '<hr />';
$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();
/* Read an array list of any custom properties for this document **/ echo '<b>Custom Properties: </b><br />';
$customPropertyList = $spreadsheet->getProperties()->getCustomProperties(); /* Loop through the list of custom properties * */
foreach ($customPropertyList as $customPropertyName) {
echo '<b>Custom Properties: </b><br />'; echo '<b>', $customPropertyName, ': </b>';
/* Loop through the list of custom properties **/ /* Retrieve the property value * */
foreach ($customPropertyList as $customPropertyName) {
echo '<b>',$customPropertyName,': </b>';
/* Retrieve the property value **/
$propertyValue = $spreadsheet->getProperties()->getCustomPropertyValue($customPropertyName); $propertyValue = $spreadsheet->getProperties()->getCustomPropertyValue($customPropertyName);
/* Retrieve the property type **/ /* Retrieve the property type * */
$propertyType = $spreadsheet->getProperties()->getCustomPropertyType($customPropertyName); $propertyType = $spreadsheet->getProperties()->getCustomPropertyType($customPropertyName);
/* Manipulate properties as appropriate for display purposes **/ /* Manipulate properties as appropriate for display purposes * */
switch ($propertyType) { switch ($propertyType) {
case 'i': // integer case 'i': // integer
$propertyType = 'integer number'; $propertyType = 'integer number';
@ -67,8 +65,7 @@ foreach ($customPropertyList as $customPropertyName) {
} }
echo $propertyValue, ' (', $propertyType, ')<br />'; echo $propertyValue, ' (', $propertyType, ')<br />';
} }
?>
?> <body>
<body>
</html> </html>

View File

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

View File

@ -1,25 +1,22 @@
<?php <?php
error_reporting(E_ALL); error_reporting(E_ALL);
set_time_limit(0); set_time_limit(0);
date_default_timezone_set('Europe/London'); date_default_timezone_set('Europe/London');
?> ?>
<html> <html>
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PhpSpreadsheet Examples</title> <title>PhpSpreadsheet Examples</title>
</head> </head>
<body> <body>
<?php <?php
$exampleTypeList = glob('./*', GLOB_ONLYDIR);
$exampleTypeList = glob('./*', GLOB_ONLYDIR); foreach ($exampleTypeList as $exampleType) {
foreach ($exampleTypeList as $exampleType) {
echo '<h1>PhpSpreadsheet ' . pathinfo($exampleType, PATHINFO_BASENAME) . ' Examples</h1>'; echo '<h1>PhpSpreadsheet ' . pathinfo($exampleType, PATHINFO_BASENAME) . ' Examples</h1>';
$exampleList = glob('./' . $exampleType . '/*.php'); $exampleList = glob('./' . $exampleType . '/*.php');
@ -41,8 +38,7 @@ foreach ($exampleTypeList as $exampleType) {
} }
} }
} }
} }
?>
?> <body>
<body>
</html> </html>

View File

@ -3770,9 +3770,6 @@ class Calculation
$output = $stack->pop(); $output = $stack->pop();
$output = $output['value']; $output = $output['value'];
// if ((is_array($output)) && (self::$returnArrayAsType != self::RETURN_ARRAY_AS_ARRAY)) {
// return array_shift(Calculation\Functions::flattenArray($output));
// }
return $output; return $output;
} }

View File

@ -436,8 +436,6 @@ class SingularValueDecomposition
} // end while } // end while
} }
// end constructor
/** /**
* Return the left singular vectors. * Return the left singular vectors.
* *

View File

@ -306,7 +306,6 @@ class Worksheet extends WriterPart
} }
// Selection // Selection
// if ($pane != '') {
// Only need to write selection element if we have a split pane // Only need to write selection element if we have a split pane
// We cheat a little by over-riding the active cell selection, setting it to the split cell // We cheat a little by over-riding the active cell selection, setting it to the split cell
$objWriter->startElement('selection'); $objWriter->startElement('selection');
@ -316,7 +315,6 @@ class Worksheet extends WriterPart
$objWriter->writeAttribute('activeCell', $activeCell); $objWriter->writeAttribute('activeCell', $activeCell);
$objWriter->writeAttribute('sqref', $activeCell); $objWriter->writeAttribute('sqref', $activeCell);
$objWriter->endElement(); $objWriter->endElement();
// }
$objWriter->endElement(); $objWriter->endElement();