init
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
date_default_timezone_set('Europe/London');
|
||||
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Calculation Examples</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>DAVERAGE</h1>
|
||||
<h2>Returns the average of selected database entries.</h2>
|
||||
<?php
|
||||
|
||||
/** Include path **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../../Classes/');
|
||||
|
||||
/** Include PHPExcel */
|
||||
include 'PHPExcel.php';
|
||||
|
||||
|
||||
// Create new PHPExcel object
|
||||
$objPHPExcel = new PHPExcel();
|
||||
$worksheet = $objPHPExcel->getActiveSheet();
|
||||
|
||||
// Add some data
|
||||
$database = array( array( 'Tree', 'Height', 'Age', 'Yield', 'Profit' ),
|
||||
array( 'Apple', 18, 20, 14, 105.00 ),
|
||||
array( 'Pear', 12, 12, 10, 96.00 ),
|
||||
array( 'Cherry', 13, 14, 9, 105.00 ),
|
||||
array( 'Apple', 14, 15, 10, 75.00 ),
|
||||
array( 'Pear', 9, 8, 8, 76.80 ),
|
||||
array( 'Apple', 8, 9, 6, 45.00 ),
|
||||
);
|
||||
$criteria = array( array( 'Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height' ),
|
||||
array( '="=Apple"', '>10', NULL, NULL, NULL, '<16' ),
|
||||
array( '="=Pear"', NULL, NULL, NULL, NULL, NULL )
|
||||
);
|
||||
|
||||
$worksheet->fromArray( $criteria, NULL, 'A1' );
|
||||
$worksheet->fromArray( $database, NULL, 'A4' );
|
||||
|
||||
$worksheet->setCellValue('A12', 'The Average yield of Apple trees over 10\' in height');
|
||||
$worksheet->setCellValue('B12', '=DAVERAGE(A4:E10,"Yield",A1:B2)');
|
||||
|
||||
$worksheet->setCellValue('A13', 'The Average age of all Apple and Pear trees in the orchard');
|
||||
$worksheet->setCellValue('B13', '=DAVERAGE(A4:E10,3,A1:A3)');
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
|
||||
echo '<h4>Database</h4>';
|
||||
|
||||
$databaseData = $worksheet->rangeToArray('A4:E10',null,true,true,true);
|
||||
var_dump($databaseData);
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
|
||||
// Test the formulae
|
||||
echo '<h4>Criteria</h4>';
|
||||
|
||||
$criteriaData = $worksheet->rangeToArray('A1:B2',null,true,true,true);
|
||||
var_dump($criteriaData);
|
||||
|
||||
echo $worksheet->getCell("A12")->getValue() .'<br />';
|
||||
echo 'DAVERAGE() Result is ' . $worksheet->getCell("B12")->getCalculatedValue() .'<br /><br />';
|
||||
|
||||
echo '<h4>Criteria</h4>';
|
||||
|
||||
$criteriaData = $worksheet->rangeToArray('A1:A3',null,true,true,true);
|
||||
var_dump($criteriaData);
|
||||
|
||||
echo $worksheet->getCell("A13")->getValue() .'<br />';
|
||||
echo 'DAVERAGE() Result is ' . $worksheet->getCell("B13")->getCalculatedValue();
|
||||
|
||||
|
||||
?>
|
||||
<body>
|
||||
</html>
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
date_default_timezone_set('Europe/London');
|
||||
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Calculation Examples</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>DCOUNT</h1>
|
||||
<h2>Counts the cells that contain numbers in a database.</h2>
|
||||
<?php
|
||||
|
||||
/** Include path **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../../Classes/');
|
||||
|
||||
/** Include PHPExcel */
|
||||
include 'PHPExcel.php';
|
||||
|
||||
|
||||
// Create new PHPExcel object
|
||||
$objPHPExcel = new PHPExcel();
|
||||
$worksheet = $objPHPExcel->getActiveSheet();
|
||||
|
||||
// Add some data
|
||||
$database = array( array( 'Tree', 'Height', 'Age', 'Yield', 'Profit' ),
|
||||
array( 'Apple', 18, 20, 14, 105.00 ),
|
||||
array( 'Pear', 12, 12, 10, 96.00 ),
|
||||
array( 'Cherry', 13, 14, 9, 105.00 ),
|
||||
array( 'Apple', 14, 15, 10, 75.00 ),
|
||||
array( 'Pear', 9, 8, 8, 76.80 ),
|
||||
array( 'Apple', 8, 9, 6, 45.00 ),
|
||||
);
|
||||
$criteria = array( array( 'Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height' ),
|
||||
array( '="=Apple"', '>10', NULL, NULL, NULL, '<16' ),
|
||||
array( '="=Pear"', NULL, NULL, NULL, NULL, NULL )
|
||||
);
|
||||
|
||||
$worksheet->fromArray( $criteria, NULL, 'A1' );
|
||||
$worksheet->fromArray( $database, NULL, 'A4' );
|
||||
|
||||
$worksheet->setCellValue('A12', 'The Number of Apple trees over 10\' in height');
|
||||
$worksheet->setCellValue('B12', '=DCOUNT(A4:E10,"Yield",A1:B2)');
|
||||
|
||||
$worksheet->setCellValue('A13', 'The Number of Apple and Pear trees in the orchard');
|
||||
$worksheet->setCellValue('B13', '=DCOUNT(A4:E10,3,A1:A3)');
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
|
||||
echo '<h4>Database</h4>';
|
||||
|
||||
$databaseData = $worksheet->rangeToArray('A4:E10',null,true,true,true);
|
||||
var_dump($databaseData);
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
|
||||
// Test the formulae
|
||||
echo '<h4>Criteria</h4>';
|
||||
|
||||
$criteriaData = $worksheet->rangeToArray('A1:B2',null,true,true,true);
|
||||
var_dump($criteriaData);
|
||||
|
||||
echo $worksheet->getCell("A12")->getValue() .'<br />';
|
||||
echo 'DCOUNT() Result is ' . $worksheet->getCell("B12")->getCalculatedValue() .'<br /><br />';
|
||||
|
||||
echo '<h4>Criteria</h4>';
|
||||
|
||||
$criteriaData = $worksheet->rangeToArray('A1:A3',null,true,true,true);
|
||||
var_dump($criteriaData);
|
||||
|
||||
echo $worksheet->getCell("A13")->getValue() .'<br />';
|
||||
echo 'DCOUNT() Result is ' . $worksheet->getCell("B13")->getCalculatedValue();
|
||||
|
||||
|
||||
?>
|
||||
<body>
|
||||
</html>
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
date_default_timezone_set('Europe/London');
|
||||
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Calculation Examples</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>DGET</h1>
|
||||
<h2>Extracts a single value from a column of a list or database that matches conditions that you specify.</h2>
|
||||
<?php
|
||||
|
||||
/** Include path **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../../Classes/');
|
||||
|
||||
/** Include PHPExcel */
|
||||
include 'PHPExcel.php';
|
||||
|
||||
|
||||
// Create new PHPExcel object
|
||||
$objPHPExcel = new PHPExcel();
|
||||
$worksheet = $objPHPExcel->getActiveSheet();
|
||||
|
||||
// Add some data
|
||||
$database = array( array( 'Tree', 'Height', 'Age', 'Yield', 'Profit' ),
|
||||
array( 'Apple', 18, 20, 14, 105.00 ),
|
||||
array( 'Pear', 12, 12, 10, 96.00 ),
|
||||
array( 'Cherry', 13, 14, 9, 105.00 ),
|
||||
array( 'Apple', 14, 15, 10, 75.00 ),
|
||||
array( 'Pear', 9, 8, 8, 76.80 ),
|
||||
array( 'Apple', 8, 9, 6, 45.00 ),
|
||||
);
|
||||
$criteria = array( array( 'Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height' ),
|
||||
array( '="=Apple"', '>10', NULL, NULL, NULL, '<16' ),
|
||||
array( '="=Pear"', NULL, NULL, NULL, NULL, NULL )
|
||||
);
|
||||
|
||||
$worksheet->fromArray( $criteria, NULL, 'A1' );
|
||||
$worksheet->fromArray( $database, NULL, 'A4' );
|
||||
|
||||
$worksheet->setCellValue('A12', 'The height of the Apple tree between 10\' and 16\' tall');
|
||||
$worksheet->setCellValue('B12', '=DGET(A4:E10,"Height",A1:F2)');
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
|
||||
echo '<h4>Database</h4>';
|
||||
|
||||
$databaseData = $worksheet->rangeToArray('A4:E10',null,true,true,true);
|
||||
var_dump($databaseData);
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
|
||||
// Test the formulae
|
||||
echo '<h4>Criteria</h4>';
|
||||
|
||||
echo 'ALL' . '<br /><br />';
|
||||
|
||||
echo $worksheet->getCell("A12")->getValue() .'<br />';
|
||||
echo 'DMAX() Result is ' . $worksheet->getCell("B12")->getCalculatedValue() .'<br /><br />';
|
||||
|
||||
echo '<h4>Criteria</h4>';
|
||||
|
||||
$criteriaData = $worksheet->rangeToArray('A1:A2',null,true,true,true);
|
||||
var_dump($criteriaData);
|
||||
|
||||
echo $worksheet->getCell("A13")->getValue() .'<br />';
|
||||
echo 'DMAX() Result is ' . $worksheet->getCell("B13")->getCalculatedValue();
|
||||
|
||||
|
||||
?>
|
||||
<body>
|
||||
</html>
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
date_default_timezone_set('Europe/London');
|
||||
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Calculation Examples</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>DMAX</h1>
|
||||
<h2>Returns the maximum value from selected database entries.</h2>
|
||||
<?php
|
||||
|
||||
/** Include path **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../../Classes/');
|
||||
|
||||
/** Include PHPExcel */
|
||||
include 'PHPExcel.php';
|
||||
|
||||
|
||||
// Create new PHPExcel object
|
||||
$objPHPExcel = new PHPExcel();
|
||||
$worksheet = $objPHPExcel->getActiveSheet();
|
||||
|
||||
// Add some data
|
||||
$database = array( array( 'Tree', 'Height', 'Age', 'Yield', 'Profit' ),
|
||||
array( 'Apple', 18, 20, 14, 105.00 ),
|
||||
array( 'Pear', 12, 12, 10, 96.00 ),
|
||||
array( 'Cherry', 13, 14, 9, 105.00 ),
|
||||
array( 'Apple', 14, 15, 10, 75.00 ),
|
||||
array( 'Pear', 9, 8, 8, 76.80 ),
|
||||
array( 'Apple', 8, 9, 6, 45.00 ),
|
||||
);
|
||||
$criteria = array( array( 'Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height' ),
|
||||
array( '="=Apple"', '>10', NULL, NULL, NULL, '<16' ),
|
||||
array( '="=Pear"', NULL, NULL, NULL, NULL, NULL )
|
||||
);
|
||||
|
||||
$worksheet->fromArray( $criteria, NULL, 'A1' );
|
||||
$worksheet->fromArray( $database, NULL, 'A4' );
|
||||
|
||||
$worksheet->setCellValue('A12', 'The tallest tree in the orchard');
|
||||
$worksheet->setCellValue('B12', '=DMAX(A4:E10,"Height",A4:E10)');
|
||||
|
||||
$worksheet->setCellValue('A13', 'The Oldest apple tree in the orchard');
|
||||
$worksheet->setCellValue('B13', '=DMAX(A4:E10,3,A1:A2)');
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
|
||||
echo '<h4>Database</h4>';
|
||||
|
||||
$databaseData = $worksheet->rangeToArray('A4:E10',null,true,true,true);
|
||||
var_dump($databaseData);
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
|
||||
// Test the formulae
|
||||
echo '<h4>Criteria</h4>';
|
||||
|
||||
echo 'ALL' . '<br /><br />';
|
||||
|
||||
echo $worksheet->getCell("A12")->getValue() .'<br />';
|
||||
echo 'DMAX() Result is ' . $worksheet->getCell("B12")->getCalculatedValue() .'<br /><br />';
|
||||
|
||||
echo '<h4>Criteria</h4>';
|
||||
|
||||
$criteriaData = $worksheet->rangeToArray('A1:A2',null,true,true,true);
|
||||
var_dump($criteriaData);
|
||||
|
||||
echo $worksheet->getCell("A13")->getValue() .'<br />';
|
||||
echo 'DMAX() Result is ' . $worksheet->getCell("B13")->getCalculatedValue();
|
||||
|
||||
|
||||
?>
|
||||
<body>
|
||||
</html>
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
date_default_timezone_set('Europe/London');
|
||||
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Calculation Examples</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>DMIN</h1>
|
||||
<h2>Returns the minimum value from selected database entries.</h2>
|
||||
<?php
|
||||
|
||||
/** Include path **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../../Classes/');
|
||||
|
||||
/** Include PHPExcel */
|
||||
include 'PHPExcel.php';
|
||||
|
||||
|
||||
// Create new PHPExcel object
|
||||
$objPHPExcel = new PHPExcel();
|
||||
$worksheet = $objPHPExcel->getActiveSheet();
|
||||
|
||||
// Add some data
|
||||
$database = array( array( 'Tree', 'Height', 'Age', 'Yield', 'Profit' ),
|
||||
array( 'Apple', 18, 20, 14, 105.00 ),
|
||||
array( 'Pear', 12, 12, 10, 96.00 ),
|
||||
array( 'Cherry', 13, 14, 9, 105.00 ),
|
||||
array( 'Apple', 14, 15, 10, 75.00 ),
|
||||
array( 'Pear', 9, 8, 8, 76.80 ),
|
||||
array( 'Apple', 8, 9, 6, 45.00 ),
|
||||
);
|
||||
$criteria = array( array( 'Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height' ),
|
||||
array( '="=Apple"', '>10', NULL, NULL, NULL, '<16' ),
|
||||
array( '="=Pear"', NULL, NULL, NULL, NULL, NULL )
|
||||
);
|
||||
|
||||
$worksheet->fromArray( $criteria, NULL, 'A1' );
|
||||
$worksheet->fromArray( $database, NULL, 'A4' );
|
||||
|
||||
$worksheet->setCellValue('A12', 'The shortest tree in the orchard');
|
||||
$worksheet->setCellValue('B12', '=DMIN(A4:E10,"Height",A4:E10)');
|
||||
|
||||
$worksheet->setCellValue('A13', 'The Youngest apple tree in the orchard');
|
||||
$worksheet->setCellValue('B13', '=DMIN(A4:E10,3,A1:A2)');
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
|
||||
echo '<h4>Database</h4>';
|
||||
|
||||
$databaseData = $worksheet->rangeToArray('A4:E10',null,true,true,true);
|
||||
var_dump($databaseData);
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
|
||||
// Test the formulae
|
||||
echo '<h4>Criteria</h4>';
|
||||
|
||||
echo 'ALL' . '<br /><br />';
|
||||
|
||||
echo $worksheet->getCell("A12")->getValue() .'<br />';
|
||||
echo 'DMIN() Result is ' . $worksheet->getCell("B12")->getCalculatedValue() .'<br /><br />';
|
||||
|
||||
echo '<h4>Criteria</h4>';
|
||||
|
||||
$criteriaData = $worksheet->rangeToArray('A1:A2',null,true,true,true);
|
||||
var_dump($criteriaData);
|
||||
|
||||
echo $worksheet->getCell("A13")->getValue() .'<br />';
|
||||
echo 'DMIN() Result is ' . $worksheet->getCell("B13")->getCalculatedValue();
|
||||
|
||||
|
||||
?>
|
||||
<body>
|
||||
</html>
|
||||
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
date_default_timezone_set('Europe/London');
|
||||
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Calculation Examples</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>DPRODUCT</h1>
|
||||
<h2>Multiplies the values in a column of a list or database that match conditions that you specify.</h2>
|
||||
<?php
|
||||
|
||||
/** Include path **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../../Classes/');
|
||||
|
||||
/** Include PHPExcel */
|
||||
include 'PHPExcel.php';
|
||||
|
||||
|
||||
// Create new PHPExcel object
|
||||
$objPHPExcel = new PHPExcel();
|
||||
$worksheet = $objPHPExcel->getActiveSheet();
|
||||
|
||||
// Add some data
|
||||
$database = array( array( 'Tree', 'Height', 'Age', 'Yield', 'Profit' ),
|
||||
array( 'Apple', 18, 20, 14, 105.00 ),
|
||||
array( 'Pear', 12, 12, 10, 96.00 ),
|
||||
array( 'Cherry', 13, 14, 9, 105.00 ),
|
||||
array( 'Apple', 14, 15, 10, 75.00 ),
|
||||
array( 'Pear', 9, 8, 8, 76.80 ),
|
||||
array( 'Apple', 8, 9, 6, 45.00 ),
|
||||
);
|
||||
$criteria = array( array( 'Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height' ),
|
||||
array( '="=Apple"', '>10', NULL, NULL, NULL, '<16' ),
|
||||
array( '="=Pear"', NULL, NULL, NULL, NULL, NULL )
|
||||
);
|
||||
|
||||
$worksheet->fromArray( $criteria, NULL, 'A1' );
|
||||
$worksheet->fromArray( $database, NULL, 'A4' );
|
||||
|
||||
$worksheet->setCellValue('A12', 'The product of the yields of all Apple trees over 10\' in the orchard');
|
||||
$worksheet->setCellValue('B12', '=DPRODUCT(A4:E10,"Yield",A1:B2)');
|
||||
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
|
||||
echo '<h4>Database</h4>';
|
||||
|
||||
$databaseData = $worksheet->rangeToArray('A4:E10',null,true,true,true);
|
||||
var_dump($databaseData);
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
|
||||
// Test the formulae
|
||||
echo '<h4>Criteria</h4>';
|
||||
|
||||
echo 'ALL' . '<br /><br />';
|
||||
|
||||
echo $worksheet->getCell("A12")->getValue() .'<br />';
|
||||
echo 'DMAX() Result is ' . $worksheet->getCell("B12")->getCalculatedValue() .'<br /><br />';
|
||||
|
||||
echo '<h4>Criteria</h4>';
|
||||
|
||||
$criteriaData = $worksheet->rangeToArray('A1:A2',null,true,true,true);
|
||||
var_dump($criteriaData);
|
||||
|
||||
echo $worksheet->getCell("A13")->getValue() .'<br />';
|
||||
echo 'DMAX() Result is ' . $worksheet->getCell("B13")->getCalculatedValue();
|
||||
|
||||
|
||||
?>
|
||||
<body>
|
||||
</html>
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
date_default_timezone_set('Europe/London');
|
||||
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Calculation Examples</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>DSTDEV</h1>
|
||||
<h2>Estimates the standard deviation based on a sample of selected database entries.</h2>
|
||||
<?php
|
||||
|
||||
/** Include path **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../../Classes/');
|
||||
|
||||
/** Include PHPExcel */
|
||||
include 'PHPExcel.php';
|
||||
|
||||
|
||||
// Create new PHPExcel object
|
||||
$objPHPExcel = new PHPExcel();
|
||||
$worksheet = $objPHPExcel->getActiveSheet();
|
||||
|
||||
// Add some data
|
||||
$database = array( array( 'Tree', 'Height', 'Age', 'Yield', 'Profit' ),
|
||||
array( 'Apple', 18, 20, 14, 105.00 ),
|
||||
array( 'Pear', 12, 12, 10, 96.00 ),
|
||||
array( 'Cherry', 13, 14, 9, 105.00 ),
|
||||
array( 'Apple', 14, 15, 10, 75.00 ),
|
||||
array( 'Pear', 9, 8, 8, 76.80 ),
|
||||
array( 'Apple', 8, 9, 6, 45.00 ),
|
||||
);
|
||||
$criteria = array( array( 'Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height' ),
|
||||
array( '="=Apple"', '>10', NULL, NULL, NULL, '<16' ),
|
||||
array( '="=Pear"', NULL, NULL, NULL, NULL, NULL )
|
||||
);
|
||||
|
||||
$worksheet->fromArray( $criteria, NULL, 'A1' );
|
||||
$worksheet->fromArray( $database, NULL, 'A4' );
|
||||
|
||||
$worksheet->setCellValue('A12', 'The estimated standard deviation in the yield of Apple and Pear trees');
|
||||
$worksheet->setCellValue('B12', '=DSTDEV(A4:E10,"Yield",A1:A3)');
|
||||
|
||||
$worksheet->setCellValue('A13', 'The estimated standard deviation in height of Apple and Pear trees');
|
||||
$worksheet->setCellValue('B13', '=DSTDEV(A4:E10,2,A1:A3)');
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
|
||||
echo '<h4>Database</h4>';
|
||||
|
||||
$databaseData = $worksheet->rangeToArray('A4:E10',null,true,true,true);
|
||||
var_dump($databaseData);
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
|
||||
// Test the formulae
|
||||
echo '<h4>Criteria</h4>';
|
||||
|
||||
$criteriaData = $worksheet->rangeToArray('A1:A3',null,true,true,true);
|
||||
var_dump($criteriaData);
|
||||
|
||||
echo $worksheet->getCell("A12")->getValue() .'<br />';
|
||||
echo 'DSTDEV() Result is ' . $worksheet->getCell("B12")->getCalculatedValue() .'<br /><br />';
|
||||
|
||||
echo '<h4>Criteria</h4>';
|
||||
|
||||
$criteriaData = $worksheet->rangeToArray('A1:A3',null,true,true,true);
|
||||
var_dump($criteriaData);
|
||||
|
||||
echo $worksheet->getCell("A13")->getValue() .'<br />';
|
||||
echo 'DSTDEV() Result is ' . $worksheet->getCell("B13")->getCalculatedValue();
|
||||
|
||||
|
||||
?>
|
||||
<body>
|
||||
</html>
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
date_default_timezone_set('Europe/London');
|
||||
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Calculation Examples</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>DSTDEVP</h1>
|
||||
<h2>Calculates the standard deviation based on the entire population of selected database entries.</h2>
|
||||
<?php
|
||||
|
||||
/** Include path **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../../Classes/');
|
||||
|
||||
/** Include PHPExcel */
|
||||
include 'PHPExcel.php';
|
||||
|
||||
|
||||
// Create new PHPExcel object
|
||||
$objPHPExcel = new PHPExcel();
|
||||
$worksheet = $objPHPExcel->getActiveSheet();
|
||||
|
||||
// Add some data
|
||||
$database = array( array( 'Tree', 'Height', 'Age', 'Yield', 'Profit' ),
|
||||
array( 'Apple', 18, 20, 14, 105.00 ),
|
||||
array( 'Pear', 12, 12, 10, 96.00 ),
|
||||
array( 'Cherry', 13, 14, 9, 105.00 ),
|
||||
array( 'Apple', 14, 15, 10, 75.00 ),
|
||||
array( 'Pear', 9, 8, 8, 76.80 ),
|
||||
array( 'Apple', 8, 9, 6, 45.00 ),
|
||||
);
|
||||
$criteria = array( array( 'Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height' ),
|
||||
array( '="=Apple"', '>10', NULL, NULL, NULL, '<16' ),
|
||||
array( '="=Pear"', NULL, NULL, NULL, NULL, NULL )
|
||||
);
|
||||
|
||||
$worksheet->fromArray( $criteria, NULL, 'A1' );
|
||||
$worksheet->fromArray( $database, NULL, 'A4' );
|
||||
|
||||
$worksheet->setCellValue('A12', 'The standard deviation in the yield of Apple and Pear trees');
|
||||
$worksheet->setCellValue('B12', '=DSTDEVP(A4:E10,"Yield",A1:A3)');
|
||||
|
||||
$worksheet->setCellValue('A13', 'The standard deviation in height of Apple and Pear trees');
|
||||
$worksheet->setCellValue('B13', '=DSTDEVP(A4:E10,2,A1:A3)');
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
|
||||
echo '<h4>Database</h4>';
|
||||
|
||||
$databaseData = $worksheet->rangeToArray('A4:E10',null,true,true,true);
|
||||
var_dump($databaseData);
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
|
||||
// Test the formulae
|
||||
echo '<h4>Criteria</h4>';
|
||||
|
||||
$criteriaData = $worksheet->rangeToArray('A1:A3',null,true,true,true);
|
||||
var_dump($criteriaData);
|
||||
|
||||
echo $worksheet->getCell("A12")->getValue() .'<br />';
|
||||
echo 'DSTDEVP() Result is ' . $worksheet->getCell("B12")->getCalculatedValue() .'<br /><br />';
|
||||
|
||||
echo '<h4>Criteria</h4>';
|
||||
|
||||
$criteriaData = $worksheet->rangeToArray('A1:A3',null,true,true,true);
|
||||
var_dump($criteriaData);
|
||||
|
||||
echo $worksheet->getCell("A13")->getValue() .'<br />';
|
||||
echo 'DSTDEVP() Result is ' . $worksheet->getCell("B13")->getCalculatedValue();
|
||||
|
||||
|
||||
?>
|
||||
<body>
|
||||
</html>
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
date_default_timezone_set('Europe/London');
|
||||
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Calculation Examples</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>DVAR</h1>
|
||||
<h2>Estimates variance based on a sample from selected database entries.</h2>
|
||||
<?php
|
||||
|
||||
/** Include path **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../../Classes/');
|
||||
|
||||
/** Include PHPExcel */
|
||||
include 'PHPExcel.php';
|
||||
|
||||
|
||||
// Create new PHPExcel object
|
||||
$objPHPExcel = new PHPExcel();
|
||||
$worksheet = $objPHPExcel->getActiveSheet();
|
||||
|
||||
// Add some data
|
||||
$database = array( array( 'Tree', 'Height', 'Age', 'Yield', 'Profit' ),
|
||||
array( 'Apple', 18, 20, 14, 105.00 ),
|
||||
array( 'Pear', 12, 12, 10, 96.00 ),
|
||||
array( 'Cherry', 13, 14, 9, 105.00 ),
|
||||
array( 'Apple', 14, 15, 10, 75.00 ),
|
||||
array( 'Pear', 9, 8, 8, 76.80 ),
|
||||
array( 'Apple', 8, 9, 6, 45.00 ),
|
||||
);
|
||||
$criteria = array( array( 'Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height' ),
|
||||
array( '="=Apple"', '>10', NULL, NULL, NULL, '<16' ),
|
||||
array( '="=Pear"', NULL, NULL, NULL, NULL, NULL )
|
||||
);
|
||||
|
||||
$worksheet->fromArray( $criteria, NULL, 'A1' );
|
||||
$worksheet->fromArray( $database, NULL, 'A4' );
|
||||
|
||||
$worksheet->setCellValue('A12', 'The estimated variance in the yield of Apple and Pear trees');
|
||||
$worksheet->setCellValue('B12', '=DVAR(A4:E10,"Yield",A1:A3)');
|
||||
|
||||
$worksheet->setCellValue('A13', 'The estimated variance in height of Apple and Pear trees');
|
||||
$worksheet->setCellValue('B13', '=DVAR(A4:E10,2,A1:A3)');
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
|
||||
echo '<h4>Database</h4>';
|
||||
|
||||
$databaseData = $worksheet->rangeToArray('A4:E10',null,true,true,true);
|
||||
var_dump($databaseData);
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
|
||||
// Test the formulae
|
||||
echo '<h4>Criteria</h4>';
|
||||
|
||||
$criteriaData = $worksheet->rangeToArray('A1:A3',null,true,true,true);
|
||||
var_dump($criteriaData);
|
||||
|
||||
echo $worksheet->getCell("A12")->getValue() .'<br />';
|
||||
echo 'DVAR() Result is ' . $worksheet->getCell("B12")->getCalculatedValue() .'<br /><br />';
|
||||
|
||||
echo '<h4>Criteria</h4>';
|
||||
|
||||
$criteriaData = $worksheet->rangeToArray('A1:A3',null,true,true,true);
|
||||
var_dump($criteriaData);
|
||||
|
||||
echo $worksheet->getCell("A13")->getValue() .'<br />';
|
||||
echo 'DVAR() Result is ' . $worksheet->getCell("B13")->getCalculatedValue();
|
||||
|
||||
|
||||
?>
|
||||
<body>
|
||||
</html>
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
date_default_timezone_set('Europe/London');
|
||||
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Calculation Examples</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>DVARP</h1>
|
||||
<h2>Calculates variance based on the entire population of selected database entries,</h2>
|
||||
<?php
|
||||
|
||||
/** Include path **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../../Classes/');
|
||||
|
||||
/** Include PHPExcel */
|
||||
include 'PHPExcel.php';
|
||||
|
||||
|
||||
// Create new PHPExcel object
|
||||
$objPHPExcel = new PHPExcel();
|
||||
$worksheet = $objPHPExcel->getActiveSheet();
|
||||
|
||||
// Add some data
|
||||
$database = array( array( 'Tree', 'Height', 'Age', 'Yield', 'Profit' ),
|
||||
array( 'Apple', 18, 20, 14, 105.00 ),
|
||||
array( 'Pear', 12, 12, 10, 96.00 ),
|
||||
array( 'Cherry', 13, 14, 9, 105.00 ),
|
||||
array( 'Apple', 14, 15, 10, 75.00 ),
|
||||
array( 'Pear', 9, 8, 8, 76.80 ),
|
||||
array( 'Apple', 8, 9, 6, 45.00 ),
|
||||
);
|
||||
$criteria = array( array( 'Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height' ),
|
||||
array( '="=Apple"', '>10', NULL, NULL, NULL, '<16' ),
|
||||
array( '="=Pear"', NULL, NULL, NULL, NULL, NULL )
|
||||
);
|
||||
|
||||
$worksheet->fromArray( $criteria, NULL, 'A1' );
|
||||
$worksheet->fromArray( $database, NULL, 'A4' );
|
||||
|
||||
$worksheet->setCellValue('A12', 'The variance in the yield of Apple and Pear trees');
|
||||
$worksheet->setCellValue('B12', '=DVARP(A4:E10,"Yield",A1:A3)');
|
||||
|
||||
$worksheet->setCellValue('A13', 'The variance in height of Apple and Pear trees');
|
||||
$worksheet->setCellValue('B13', '=DVARP(A4:E10,2,A1:A3)');
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
|
||||
echo '<h4>Database</h4>';
|
||||
|
||||
$databaseData = $worksheet->rangeToArray('A4:E10',null,true,true,true);
|
||||
var_dump($databaseData);
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
|
||||
// Test the formulae
|
||||
echo '<h4>Criteria</h4>';
|
||||
|
||||
$criteriaData = $worksheet->rangeToArray('A1:A3',null,true,true,true);
|
||||
var_dump($criteriaData);
|
||||
|
||||
echo $worksheet->getCell("A12")->getValue() .'<br />';
|
||||
echo 'DVARP() Result is ' . $worksheet->getCell("B12")->getCalculatedValue() .'<br /><br />';
|
||||
|
||||
echo '<h4>Criteria</h4>';
|
||||
|
||||
$criteriaData = $worksheet->rangeToArray('A1:A3',null,true,true,true);
|
||||
var_dump($criteriaData);
|
||||
|
||||
echo $worksheet->getCell("A13")->getValue() .'<br />';
|
||||
echo 'DVARP() Result is ' . $worksheet->getCell("B13")->getCalculatedValue();
|
||||
|
||||
|
||||
?>
|
||||
<body>
|
||||
</html>
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
date_default_timezone_set('Europe/London');
|
||||
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Calculation Examples</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>DATE</h1>
|
||||
<h2>Returns the serial number of a particular date.</h2>
|
||||
<?php
|
||||
|
||||
/** Include path **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../../Classes/');
|
||||
|
||||
/** Include PHPExcel */
|
||||
include 'PHPExcel.php';
|
||||
|
||||
|
||||
// Create new PHPExcel object
|
||||
$objPHPExcel = new PHPExcel();
|
||||
$worksheet = $objPHPExcel->getActiveSheet();
|
||||
|
||||
// Add some data
|
||||
$testDates = array( array(2012,3,26), array(2012,2,29), array(2012,4,1), array(2012,12,25),
|
||||
array(2012,10,31), array(2012,11,5), array(2012,1,1), array(2012,3,17),
|
||||
array(2011,2,29), array(7,5,3), array(2012,13,1), array(2012,11,45),
|
||||
array(2012,0,0), array(2012,1,0), array(2012,0,1),
|
||||
array(2012,-2,2), array(2012,2,-2), array(2012,-2,-2),
|
||||
);
|
||||
$testDateCount = count($testDates);
|
||||
|
||||
$worksheet->fromArray($testDates,NULL,'A1',true);
|
||||
|
||||
for ($row = 1; $row <= $testDateCount; ++$row) {
|
||||
$worksheet->setCellValue('D'.$row, '=DATE(A'.$row.',B'.$row.',C'.$row.')');
|
||||
$worksheet->setCellValue('E'.$row, '=D'.$row);
|
||||
}
|
||||
$worksheet->getStyle('E1:E'.$testDateCount)
|
||||
->getNumberFormat()
|
||||
->setFormatCode('yyyy-mmm-dd');
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
|
||||
// Test the formulae
|
||||
?>
|
||||
<table border="1" cellspacing="0">
|
||||
<tr>
|
||||
<th colspan="3">Date Value</th>
|
||||
<th rowspan="2" valign="bottom">Formula</th>
|
||||
<th rowspan="2" valign="bottom">Excel DateStamp</th>
|
||||
<th rowspan="2" valign="bottom">Formatted DateStamp</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Year</th>
|
||||
<th>Month</th>
|
||||
<th>Day</th>
|
||||
<tr>
|
||||
<?php
|
||||
for ($row = 1; $row <= $testDateCount; ++$row) {
|
||||
echo '<tr>';
|
||||
echo '<td>' , $worksheet->getCell('A'.$row)->getFormattedValue() , '</td>';
|
||||
echo '<td>' , $worksheet->getCell('B'.$row)->getFormattedValue() , '</td>';
|
||||
echo '<td>' , $worksheet->getCell('C'.$row)->getFormattedValue() , '</td>';
|
||||
echo '<td>' , $worksheet->getCell('D'.$row)->getValue() , '</td>';
|
||||
echo '<td>' , $worksheet->getCell('D'.$row)->getFormattedValue() , '</td>';
|
||||
echo '<td>' , $worksheet->getCell('E'.$row)->getFormattedValue() , '</td>';
|
||||
echo '</tr>';
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
date_default_timezone_set('Europe/London');
|
||||
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Calculation Examples</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>DATEVALUE</h1>
|
||||
<h2>Converts a date in the form of text to a serial number.</h2>
|
||||
<?php
|
||||
|
||||
/** Include path **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../../Classes/');
|
||||
|
||||
/** Include PHPExcel */
|
||||
include 'PHPExcel.php';
|
||||
|
||||
|
||||
// Create new PHPExcel object
|
||||
$objPHPExcel = new PHPExcel();
|
||||
$worksheet = $objPHPExcel->getActiveSheet();
|
||||
|
||||
// Add some data
|
||||
$testDates = array( '26 March 2012', '29 Feb 2012', 'April 1, 2012', '25/12/2012',
|
||||
'2012-Oct-31', '5th November', 'January 1st', 'April 2012',
|
||||
'17-03', '03-2012', '29 Feb 2011', '03-05-07',
|
||||
'03-MAY-07', '03-13-07',
|
||||
);
|
||||
$testDateCount = count($testDates);
|
||||
|
||||
for($row = 1; $row <= $testDateCount; ++$row) {
|
||||
$worksheet->setCellValue('A'.$row, $testDates[$row-1]);
|
||||
$worksheet->setCellValue('B'.$row, '=DATEVALUE(A'.$row.')');
|
||||
$worksheet->setCellValue('C'.$row, '=B'.$row);
|
||||
}
|
||||
|
||||
$worksheet->getStyle('C1:C'.$testDateCount)
|
||||
->getNumberFormat()
|
||||
->setFormatCode('yyyy-mmm-dd');
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
|
||||
// Test the formulae
|
||||
?>
|
||||
<p><strong>Warning: </strong>The PHPExcel DATEVALUE() function accepts a wider range of date formats than MS Excel's DATEFORMAT() function.</p>
|
||||
<table border="1" cellspacing="0">
|
||||
<tr>
|
||||
<th>Date String</th>
|
||||
<th>Formula</th>
|
||||
<th>Excel DateStamp</th>
|
||||
<th>Formatted DateStamp</th>
|
||||
</tr>
|
||||
<?php
|
||||
for ($row = 1; $row <= $testDateCount; ++$row) {
|
||||
echo '<tr>';
|
||||
echo '<td>' , $worksheet->getCell('A'.$row)->getFormattedValue() , '</td>';
|
||||
echo '<td>' , $worksheet->getCell('B'.$row)->getValue() , '</td>';
|
||||
echo '<td>' , $worksheet->getCell('B'.$row)->getFormattedValue() , '</td>';
|
||||
echo '<td>' , $worksheet->getCell('C'.$row)->getFormattedValue() , '</td>';
|
||||
echo '</tr>';
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
date_default_timezone_set('Europe/London');
|
||||
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Calculation Examples</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>TIME</h1>
|
||||
<h2>Returns the serial number of a particular time.</h2>
|
||||
<?php
|
||||
|
||||
/** Include path **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../../Classes/');
|
||||
|
||||
/** Include PHPExcel */
|
||||
include 'PHPExcel.php';
|
||||
|
||||
|
||||
// Create new PHPExcel object
|
||||
$objPHPExcel = new PHPExcel();
|
||||
$worksheet = $objPHPExcel->getActiveSheet();
|
||||
|
||||
// Add some data
|
||||
$testDates = array( array(3,15), array(13,15), array(15,15,15), array(3,15,30),
|
||||
array(15,15,15), array(5), array(9,15,0), array(9,15,-1),
|
||||
array(13,-14,-15), array(0,0,-1)
|
||||
);
|
||||
$testDateCount = count($testDates);
|
||||
|
||||
$worksheet->fromArray($testDates,NULL,'A1',true);
|
||||
|
||||
for ($row = 1; $row <= $testDateCount; ++$row) {
|
||||
$worksheet->setCellValue('D'.$row, '=TIME(A'.$row.',B'.$row.',C'.$row.')');
|
||||
$worksheet->setCellValue('E'.$row, '=D'.$row);
|
||||
}
|
||||
$worksheet->getStyle('E1:E'.$testDateCount)
|
||||
->getNumberFormat()
|
||||
->setFormatCode('hh:mm:ss');
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
|
||||
// Test the formulae
|
||||
?>
|
||||
<table border="1" cellspacing="0">
|
||||
<tr>
|
||||
<th colspan="3">Date Value</th>
|
||||
<th rowspan="2" valign="bottom">Formula</th>
|
||||
<th rowspan="2" valign="bottom">Excel TimeStamp</th>
|
||||
<th rowspan="2" valign="bottom">Formatted TimeStamp</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Hour</th>
|
||||
<th>Minute</th>
|
||||
<th>Second</th>
|
||||
<tr>
|
||||
<?php
|
||||
for ($row = 1; $row <= $testDateCount; ++$row) {
|
||||
echo '<tr>';
|
||||
echo '<td>' , $worksheet->getCell('A'.$row)->getFormattedValue() , '</td>';
|
||||
echo '<td>' , $worksheet->getCell('B'.$row)->getFormattedValue() , '</td>';
|
||||
echo '<td>' , $worksheet->getCell('C'.$row)->getFormattedValue() , '</td>';
|
||||
echo '<td>' , $worksheet->getCell('D'.$row)->getValue() , '</td>';
|
||||
echo '<td>' , $worksheet->getCell('D'.$row)->getFormattedValue() , '</td>';
|
||||
echo '<td>' , $worksheet->getCell('E'.$row)->getFormattedValue() , '</td>';
|
||||
echo '</tr>';
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
date_default_timezone_set('Europe/London');
|
||||
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Calculation Examples</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>TIMEVALUE</h1>
|
||||
<h2>Converts a time in the form of text to a serial number.</h2>
|
||||
<?php
|
||||
|
||||
/** Include path **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../../Classes/');
|
||||
|
||||
/** Include PHPExcel */
|
||||
include 'PHPExcel.php';
|
||||
|
||||
|
||||
// Create new PHPExcel object
|
||||
$objPHPExcel = new PHPExcel();
|
||||
$worksheet = $objPHPExcel->getActiveSheet();
|
||||
|
||||
// Add some data
|
||||
$testDates = array( '3:15', '13:15', '15:15:15', '3:15 AM', '3:15 PM', '5PM', '9:15AM', '13:15AM'
|
||||
);
|
||||
$testDateCount = count($testDates);
|
||||
|
||||
for($row = 1; $row <= $testDateCount; ++$row) {
|
||||
$worksheet->setCellValue('A'.$row, $testDates[$row-1]);
|
||||
$worksheet->setCellValue('B'.$row, '=TIMEVALUE(A'.$row.')');
|
||||
$worksheet->setCellValue('C'.$row, '=B'.$row);
|
||||
}
|
||||
|
||||
$worksheet->getStyle('C1:C'.$testDateCount)
|
||||
->getNumberFormat()
|
||||
->setFormatCode('hh:mm:ss');
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
|
||||
// Test the formulae
|
||||
?>
|
||||
<table border="1" cellspacing="0">
|
||||
<tr>
|
||||
<th>Time String</th>
|
||||
<th>Formula</th>
|
||||
<th>Excel TimeStamp</th>
|
||||
<th>Formatted TimeStamp</th>
|
||||
</tr>
|
||||
<?php
|
||||
for ($row = 1; $row <= $testDateCount; ++$row) {
|
||||
echo '<tr>';
|
||||
echo '<td>' , $worksheet->getCell('A'.$row)->getFormattedValue() , '</td>';
|
||||
echo '<td>' , $worksheet->getCell('B'.$row)->getValue() , '</td>';
|
||||
echo '<td>' , $worksheet->getCell('B'.$row)->getFormattedValue() , '</td>';
|
||||
echo '<td>' , $worksheet->getCell('C'.$row)->getFormattedValue() , '</td>';
|
||||
echo '</tr>';
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
date_default_timezone_set('Europe/London');
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Calculation Function Examples</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<?php
|
||||
|
||||
echo '<h1>PHPExcel Calculation Function Examples</h1>';
|
||||
|
||||
$exampleTypeList = glob('./*',GLOB_ONLYDIR);
|
||||
|
||||
foreach($exampleTypeList as $exampleType) {
|
||||
|
||||
echo '<h2>' . pathinfo($exampleType,PATHINFO_BASENAME) . ' Function Examples</h2>';
|
||||
|
||||
$exampleList = glob('./'.$exampleType.'/*.php');
|
||||
|
||||
foreach($exampleList as $exampleFile) {
|
||||
$fileData = file_get_contents($exampleFile);
|
||||
|
||||
$h1Pattern = '#<h1>(.*?)</h1>#';
|
||||
$h2Pattern = '#<h2>(.*?)</h2>#';
|
||||
|
||||
if (preg_match($h1Pattern, $fileData, $out)) {
|
||||
$h1Text = $out[1];
|
||||
$h2Text = (preg_match($h2Pattern, $fileData, $out)) ? $out[1] : '';
|
||||
|
||||
echo '<a href="',$exampleFile,'">',$h1Text,'</a><br />';
|
||||
if ($h2Text > '') {
|
||||
echo $h2Text,'<br />';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
<body>
|
||||
</html>
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
date_default_timezone_set('Europe/London');
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Reader Example #01</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>PHPExcel Reader Example #01</h1>
|
||||
<h2>Simple File Reader using PHPExcel_IOFactory::load()</h2>
|
||||
<?php
|
||||
|
||||
/** Include path **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../Classes/');
|
||||
|
||||
/** PHPExcel_IOFactory */
|
||||
include 'PHPExcel/IOFactory.php';
|
||||
|
||||
|
||||
$inputFileName = './sampleData/example1.xls';
|
||||
echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using IOFactory to identify the format<br />';
|
||||
$objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
$sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
|
||||
var_dump($sheetData);
|
||||
|
||||
|
||||
?>
|
||||
<body>
|
||||
</html>
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
date_default_timezone_set('Europe/London');
|
||||
|
||||
|
||||
/** Include path **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../Classes/');
|
||||
|
||||
/** PHPExcel_IOFactory */
|
||||
include 'PHPExcel/IOFactory.php';
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Reader Example #02</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>PHPExcel Reader Example #02</h1>
|
||||
<h2>Simple File Reader using a Specified Reader</h2>
|
||||
<?php
|
||||
|
||||
$inputFileName = './sampleData/example1.xls';
|
||||
|
||||
echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using PHPExcel_Reader_Excel5<br />';
|
||||
$objReader = new PHPExcel_Reader_Excel5();
|
||||
// $objReader = new PHPExcel_Reader_Excel2007();
|
||||
// $objReader = new PHPExcel_Reader_Excel2003XML();
|
||||
// $objReader = new PHPExcel_Reader_OOCalc();
|
||||
// $objReader = new PHPExcel_Reader_SYLK();
|
||||
// $objReader = new PHPExcel_Reader_Gnumeric();
|
||||
// $objReader = new PHPExcel_Reader_CSV();
|
||||
$objPHPExcel = $objReader->load($inputFileName);
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
$sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
|
||||
var_dump($sheetData);
|
||||
|
||||
|
||||
?>
|
||||
<body>
|
||||
</html>
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
date_default_timezone_set('Europe/London');
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Reader Example #03</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>PHPExcel Reader Example #03</h1>
|
||||
<h2>Simple File Reader using the PHPExcel_IOFactory to Return a Reader</h2>
|
||||
<?php
|
||||
|
||||
/** Include path **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../Classes/');
|
||||
|
||||
/** PHPExcel_IOFactory */
|
||||
include 'PHPExcel/IOFactory.php';
|
||||
|
||||
|
||||
$inputFileType = 'Excel5';
|
||||
// $inputFileType = 'Excel2007';
|
||||
// $inputFileType = 'Excel2003XML';
|
||||
// $inputFileType = 'OOCalc';
|
||||
// $inputFileType = 'SYLK';
|
||||
// $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 />';
|
||||
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
|
||||
$objPHPExcel = $objReader->load($inputFileName);
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
$sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
|
||||
var_dump($sheetData);
|
||||
|
||||
|
||||
?>
|
||||
<body>
|
||||
</html>
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
date_default_timezone_set('Europe/London');
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Reader Example #04</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>PHPExcel Reader Example #04</h1>
|
||||
<h2>Simple File Reader using the PHPExcel_IOFactory to Identify a Reader to Use</h2>
|
||||
<?php
|
||||
|
||||
/** Include path **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../Classes/');
|
||||
|
||||
/** PHPExcel_IOFactory */
|
||||
include 'PHPExcel/IOFactory.php';
|
||||
|
||||
|
||||
$inputFileName = './sampleData/example1.xls';
|
||||
|
||||
$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
|
||||
echo 'File ',pathinfo($inputFileName,PATHINFO_BASENAME),' has been identified as an ',$inputFileType,' file<br />';
|
||||
|
||||
echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using IOFactory with the identified reader type<br />';
|
||||
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
|
||||
$objPHPExcel = $objReader->load($inputFileName);
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
$sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
|
||||
var_dump($sheetData);
|
||||
|
||||
|
||||
?>
|
||||
<body>
|
||||
</html>
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
date_default_timezone_set('Europe/London');
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Reader Example #05</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>PHPExcel Reader Example #05</h1>
|
||||
<h2>Simple File Reader using the "Read Data Only" Option</h2>
|
||||
<?php
|
||||
|
||||
/** Include path **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../Classes/');
|
||||
|
||||
/** PHPExcel_IOFactory */
|
||||
include 'PHPExcel/IOFactory.php';
|
||||
|
||||
|
||||
$inputFileType = 'Excel5';
|
||||
// $inputFileType = 'Excel2007';
|
||||
// $inputFileType = 'Excel2003XML';
|
||||
// $inputFileType = 'OOCalc';
|
||||
// $inputFileType = 'Gnumeric';
|
||||
$inputFileName = './sampleData/example1.xls';
|
||||
|
||||
echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
||||
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
|
||||
echo 'Turning Formatting off for Load<br />';
|
||||
$objReader->setReadDataOnly(true);
|
||||
$objPHPExcel = $objReader->load($inputFileName);
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
$sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
|
||||
var_dump($sheetData);
|
||||
|
||||
|
||||
?>
|
||||
<body>
|
||||
</html>
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
date_default_timezone_set('Europe/London');
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Reader Example #06</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>PHPExcel Reader Example #06</h1>
|
||||
<h2>Simple File Reader Loading All WorkSheets</h2>
|
||||
<?php
|
||||
|
||||
/** Include path **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../Classes/');
|
||||
|
||||
/** PHPExcel_IOFactory */
|
||||
include 'PHPExcel/IOFactory.php';
|
||||
|
||||
|
||||
$inputFileType = 'Excel5';
|
||||
// $inputFileType = 'Excel2007';
|
||||
// $inputFileType = 'Excel2003XML';
|
||||
// $inputFileType = 'OOCalc';
|
||||
// $inputFileType = 'Gnumeric';
|
||||
$inputFileName = './sampleData/example1.xls';
|
||||
|
||||
echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
||||
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
|
||||
echo 'Loading all WorkSheets<br />';
|
||||
$objReader->setLoadAllSheets();
|
||||
$objPHPExcel = $objReader->load($inputFileName);
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
echo $objPHPExcel->getSheetCount(),' worksheet',(($objPHPExcel->getSheetCount() == 1) ? '' : 's'),' loaded<br /><br />';
|
||||
$loadedSheetNames = $objPHPExcel->getSheetNames();
|
||||
foreach($loadedSheetNames as $sheetIndex => $loadedSheetName) {
|
||||
echo $sheetIndex,' -> ',$loadedSheetName,'<br />';
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
<body>
|
||||
</html>
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
date_default_timezone_set('Europe/London');
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Reader Example #07</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>PHPExcel Reader Example #07</h1>
|
||||
<h2>Simple File Reader Loading a Single Named WorkSheet</h2>
|
||||
<?php
|
||||
|
||||
/** Include path **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../Classes/');
|
||||
|
||||
/** PHPExcel_IOFactory */
|
||||
include 'PHPExcel/IOFactory.php';
|
||||
|
||||
|
||||
$inputFileType = 'Excel5';
|
||||
// $inputFileType = 'Excel2007';
|
||||
// $inputFileType = 'Excel2003XML';
|
||||
// $inputFileType = 'OOCalc';
|
||||
// $inputFileType = 'Gnumeric';
|
||||
$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 />';
|
||||
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
|
||||
echo 'Loading Sheet "',$sheetname,'" only<br />';
|
||||
$objReader->setLoadSheetsOnly($sheetname);
|
||||
$objPHPExcel = $objReader->load($inputFileName);
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
echo $objPHPExcel->getSheetCount(),' worksheet',(($objPHPExcel->getSheetCount() == 1) ? '' : 's'),' loaded<br /><br />';
|
||||
$loadedSheetNames = $objPHPExcel->getSheetNames();
|
||||
foreach($loadedSheetNames as $sheetIndex => $loadedSheetName) {
|
||||
echo $sheetIndex,' -> ',$loadedSheetName,'<br />';
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
<body>
|
||||
</html>
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
date_default_timezone_set('Europe/London');
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Reader Example #08</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>PHPExcel Reader Example #08</h1>
|
||||
<h2>Simple File Reader Loading Several Named WorkSheets</h2>
|
||||
<?php
|
||||
|
||||
/** Include path **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../Classes/');
|
||||
|
||||
/** PHPExcel_IOFactory */
|
||||
include 'PHPExcel/IOFactory.php';
|
||||
|
||||
|
||||
$inputFileType = 'Excel5';
|
||||
// $inputFileType = 'Excel2007';
|
||||
// $inputFileType = 'Excel2003XML';
|
||||
// $inputFileType = 'OOCalc';
|
||||
// $inputFileType = 'Gnumeric';
|
||||
$inputFileName = './sampleData/example1.xls';
|
||||
$sheetnames = array('Data Sheet #1','Data Sheet #3');
|
||||
|
||||
echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
||||
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
|
||||
echo 'Loading Sheet',((count($sheetnames) == 1) ? '' : 's'),' "',implode('" and "',$sheetnames),'" only<br />';
|
||||
$objReader->setLoadSheetsOnly($sheetnames);
|
||||
$objPHPExcel = $objReader->load($inputFileName);
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
echo $objPHPExcel->getSheetCount(),' worksheet',(($objPHPExcel->getSheetCount() == 1) ? '' : 's'),' loaded<br /><br />';
|
||||
$loadedSheetNames = $objPHPExcel->getSheetNames();
|
||||
foreach($loadedSheetNames as $sheetIndex => $loadedSheetName) {
|
||||
echo $sheetIndex,' -> ',$loadedSheetName,'<br />';
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
<body>
|
||||
</html>
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
date_default_timezone_set('Europe/London');
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Reader Example #09</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>PHPExcel Reader Example #09</h1>
|
||||
<h2>Simple File Reader Using a Read Filter</h2>
|
||||
<?php
|
||||
|
||||
/** Include path **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../Classes/');
|
||||
|
||||
/** PHPExcel_IOFactory */
|
||||
include 'PHPExcel/IOFactory.php';
|
||||
|
||||
|
||||
$inputFileType = 'Excel5';
|
||||
// $inputFileType = 'Excel2007';
|
||||
// $inputFileType = 'Excel2003XML';
|
||||
// $inputFileType = 'OOCalc';
|
||||
// $inputFileType = 'Gnumeric';
|
||||
$inputFileName = './sampleData/example1.xls';
|
||||
$sheetname = 'Data Sheet #3';
|
||||
|
||||
|
||||
class MyReadFilter implements PHPExcel_Reader_IReadFilter
|
||||
{
|
||||
public function readCell($column, $row, $worksheetName = '') {
|
||||
// Read rows 1 to 7 and columns A to E only
|
||||
if ($row >= 1 && $row <= 7) {
|
||||
if (in_array($column,range('A','E'))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$filterSubset = new MyReadFilter();
|
||||
|
||||
|
||||
echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
||||
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
|
||||
echo 'Loading Sheet "',$sheetname,'" only<br />';
|
||||
$objReader->setLoadSheetsOnly($sheetname);
|
||||
echo 'Loading Sheet using filter<br />';
|
||||
$objReader->setReadFilter($filterSubset);
|
||||
$objPHPExcel = $objReader->load($inputFileName);
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
$sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
|
||||
var_dump($sheetData);
|
||||
|
||||
|
||||
?>
|
||||
<body>
|
||||
</html>
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
date_default_timezone_set('Europe/London');
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Reader Example #10</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>PHPExcel Reader Example #10</h1>
|
||||
<h2>Simple File Reader Using a Configurable Read Filter</h2>
|
||||
<?php
|
||||
|
||||
/** Include path **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../Classes/');
|
||||
|
||||
/** PHPExcel_IOFactory */
|
||||
include 'PHPExcel/IOFactory.php';
|
||||
|
||||
|
||||
$inputFileType = 'Excel5';
|
||||
// $inputFileType = 'Excel2007';
|
||||
// $inputFileType = 'Excel2003XML';
|
||||
// $inputFileType = 'OOCalc';
|
||||
// $inputFileType = 'Gnumeric';
|
||||
$inputFileName = './sampleData/example1.xls';
|
||||
$sheetname = 'Data Sheet #3';
|
||||
|
||||
|
||||
class MyReadFilter implements PHPExcel_Reader_IReadFilter
|
||||
{
|
||||
private $_startRow = 0;
|
||||
|
||||
private $_endRow = 0;
|
||||
|
||||
private $_columns = array();
|
||||
|
||||
public function __construct($startRow, $endRow, $columns) {
|
||||
$this->_startRow = $startRow;
|
||||
$this->_endRow = $endRow;
|
||||
$this->_columns = $columns;
|
||||
}
|
||||
|
||||
public function readCell($column, $row, $worksheetName = '') {
|
||||
if ($row >= $this->_startRow && $row <= $this->_endRow) {
|
||||
if (in_array($column,$this->_columns)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$filterSubset = new MyReadFilter(9,15,range('G','K'));
|
||||
|
||||
|
||||
echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
||||
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
|
||||
echo 'Loading Sheet "',$sheetname,'" only<br />';
|
||||
$objReader->setLoadSheetsOnly($sheetname);
|
||||
echo 'Loading Sheet using configurable filter<br />';
|
||||
$objReader->setReadFilter($filterSubset);
|
||||
$objPHPExcel = $objReader->load($inputFileName);
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
$sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
|
||||
var_dump($sheetData);
|
||||
|
||||
|
||||
?>
|
||||
<body>
|
||||
</html>
|
||||
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
date_default_timezone_set('Europe/London');
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Reader Example #11</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>PHPExcel Reader Example #11</h1>
|
||||
<h2>Reading a Workbook in "Chunks" Using a Configurable Read Filter (Version 1)</h2>
|
||||
<?php
|
||||
|
||||
/** Include path **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../Classes/');
|
||||
|
||||
/** PHPExcel_IOFactory */
|
||||
include 'PHPExcel/IOFactory.php';
|
||||
|
||||
|
||||
$inputFileType = 'Excel5';
|
||||
// $inputFileType = 'Excel2007';
|
||||
// $inputFileType = 'Excel2003XML';
|
||||
// $inputFileType = 'OOCalc';
|
||||
// $inputFileType = 'Gnumeric';
|
||||
$inputFileName = './sampleData/example2.xls';
|
||||
|
||||
|
||||
/** Define a Read Filter class implementing PHPExcel_Reader_IReadFilter */
|
||||
class chunkReadFilter implements PHPExcel_Reader_IReadFilter
|
||||
{
|
||||
private $_startRow = 0;
|
||||
|
||||
private $_endRow = 0;
|
||||
|
||||
/** We expect a list of the rows that we want to read to be passed into the constructor */
|
||||
public function __construct($startRow, $chunkSize) {
|
||||
$this->_startRow = $startRow;
|
||||
$this->_endRow = $startRow + $chunkSize;
|
||||
}
|
||||
|
||||
public function readCell($column, $row, $worksheetName = '') {
|
||||
// Only read the heading row, and the rows that were configured in the constructor
|
||||
if (($row == 1) || ($row >= $this->_startRow && $row < $this->_endRow)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
||||
/** Create a new Reader of the type defined in $inputFileType **/
|
||||
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
|
||||
/** Define how many rows we want for each "chunk" **/
|
||||
$chunkSize = 20;
|
||||
|
||||
/** Loop to read our worksheet in "chunk size" blocks **/
|
||||
for ($startRow = 2; $startRow <= 240; $startRow += $chunkSize) {
|
||||
echo 'Loading WorkSheet using configurable filter for headings row 1 and for rows ',$startRow,' to ',($startRow+$chunkSize-1),'<br />';
|
||||
/** Create a new Instance of our Read Filter, passing in the limits on which rows we want to read **/
|
||||
$chunkFilter = new chunkReadFilter($startRow,$chunkSize);
|
||||
/** Tell the Reader that we want to use the new Read Filter that we've just Instantiated **/
|
||||
$objReader->setReadFilter($chunkFilter);
|
||||
/** Load only the rows that match our filter from $inputFileName to a PHPExcel Object **/
|
||||
$objPHPExcel = $objReader->load($inputFileName);
|
||||
|
||||
// Do some processing here
|
||||
|
||||
$sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
|
||||
var_dump($sheetData);
|
||||
echo '<br /><br />';
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
<body>
|
||||
</html>
|
||||
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
date_default_timezone_set('Europe/London');
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Reader Example #12</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>PHPExcel Reader Example #12</h1>
|
||||
<h2>Reading a Workbook in "Chunks" Using a Configurable Read Filter (Version 2)</h2>
|
||||
<?php
|
||||
|
||||
/** Set Include path to point at the PHPExcel Classes folder **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../Classes/');
|
||||
|
||||
/** Include PHPExcel_IOFactory **/
|
||||
include 'PHPExcel/IOFactory.php';
|
||||
|
||||
|
||||
$inputFileType = 'Excel5';
|
||||
// $inputFileType = 'Excel2007';
|
||||
// $inputFileType = 'Excel2003XML';
|
||||
// $inputFileType = 'OOCalc';
|
||||
// $inputFileType = 'Gnumeric';
|
||||
$inputFileName = './sampleData/example2.xls';
|
||||
|
||||
|
||||
/** Define a Read Filter class implementing PHPExcel_Reader_IReadFilter */
|
||||
class chunkReadFilter implements PHPExcel_Reader_IReadFilter
|
||||
{
|
||||
private $_startRow = 0;
|
||||
|
||||
private $_endRow = 0;
|
||||
|
||||
/** Set the list of rows that we want to read */
|
||||
public function setRows($startRow, $chunkSize) {
|
||||
$this->_startRow = $startRow;
|
||||
$this->_endRow = $startRow + $chunkSize;
|
||||
}
|
||||
|
||||
public function readCell($column, $row, $worksheetName = '') {
|
||||
// Only read the heading row, and the rows that are configured in $this->_startRow and $this->_endRow
|
||||
if (($row == 1) || ($row >= $this->_startRow && $row < $this->_endRow)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
||||
/** Create a new Reader of the type defined in $inputFileType **/
|
||||
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
|
||||
/** Define how many rows we want to read for each "chunk" **/
|
||||
$chunkSize = 20;
|
||||
/** Create a new Instance of our Read Filter **/
|
||||
$chunkFilter = new chunkReadFilter();
|
||||
|
||||
/** Tell the Reader that we want to use the Read Filter that we've Instantiated **/
|
||||
$objReader->setReadFilter($chunkFilter);
|
||||
|
||||
/** Loop to read our worksheet in "chunk size" blocks **/
|
||||
for ($startRow = 2; $startRow <= 240; $startRow += $chunkSize) {
|
||||
echo 'Loading WorkSheet using configurable filter for headings row 1 and for rows ',$startRow,' to ',($startRow+$chunkSize-1),'<br />';
|
||||
/** Tell the Read Filter, the limits on which rows we want to read this iteration **/
|
||||
$chunkFilter->setRows($startRow,$chunkSize);
|
||||
/** Load only the rows that match our filter from $inputFileName to a PHPExcel Object **/
|
||||
$objPHPExcel = $objReader->load($inputFileName);
|
||||
|
||||
// Do some processing here
|
||||
|
||||
$sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
|
||||
var_dump($sheetData);
|
||||
echo '<br /><br />';
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
<body>
|
||||
</html>
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
date_default_timezone_set('Europe/London');
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Reader Example #13</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>PHPExcel Reader Example #13</h1>
|
||||
<h2>Simple File Reader for Multiple CSV Files</h2>
|
||||
<?php
|
||||
|
||||
/** Include path **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../Classes/');
|
||||
|
||||
/** PHPExcel_IOFactory */
|
||||
include 'PHPExcel/IOFactory.php';
|
||||
|
||||
|
||||
$inputFileType = 'CSV';
|
||||
$inputFileNames = array('./sampleData/example1.csv','./sampleData/example2.csv');
|
||||
|
||||
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
|
||||
$inputFileName = array_shift($inputFileNames);
|
||||
echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' into WorkSheet #1 using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
||||
$objPHPExcel = $objReader->load($inputFileName);
|
||||
$objPHPExcel->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 />';
|
||||
$objReader->setSheetIndex($sheet+1);
|
||||
$objReader->loadIntoExisting($inputFileName,$objPHPExcel);
|
||||
$objPHPExcel->getActiveSheet()->setTitle(pathinfo($inputFileName,PATHINFO_BASENAME));
|
||||
}
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
echo $objPHPExcel->getSheetCount(),' worksheet',(($objPHPExcel->getSheetCount() == 1) ? '' : 's'),' loaded<br /><br />';
|
||||
$loadedSheetNames = $objPHPExcel->getSheetNames();
|
||||
foreach($loadedSheetNames as $sheetIndex => $loadedSheetName) {
|
||||
echo '<b>Worksheet #',$sheetIndex,' -> ',$loadedSheetName,'</b><br />';
|
||||
$objPHPExcel->setActiveSheetIndexByName($loadedSheetName);
|
||||
$sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
|
||||
var_dump($sheetData);
|
||||
echo '<br /><br />';
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
<body>
|
||||
</html>
|
||||
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Reader Example #15</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>PHPExcel Reader Example #14</h1>
|
||||
<h2>Reading a Large CSV file in "Chunks" to split across multiple Worksheets</h2>
|
||||
<?php
|
||||
|
||||
/** Include path **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../Classes/');
|
||||
|
||||
/** PHPExcel_IOFactory */
|
||||
include 'PHPExcel/IOFactory.php';
|
||||
|
||||
|
||||
$inputFileType = 'CSV';
|
||||
$inputFileName = './sampleData/example2.csv';
|
||||
|
||||
/** Define a Read Filter class implementing PHPExcel_Reader_IReadFilter */
|
||||
class chunkReadFilter implements PHPExcel_Reader_IReadFilter
|
||||
{
|
||||
private $_startRow = 0;
|
||||
|
||||
private $_endRow = 0;
|
||||
|
||||
/** Set the list of rows that we want to read */
|
||||
public function setRows($startRow, $chunkSize) {
|
||||
$this->_startRow = $startRow;
|
||||
$this->_endRow = $startRow + $chunkSize;
|
||||
}
|
||||
|
||||
public function readCell($column, $row, $worksheetName = '') {
|
||||
// Only read the heading row, and the rows that are configured in $this->_startRow and $this->_endRow
|
||||
if (($row == 1) || ($row >= $this->_startRow && $row < $this->_endRow)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
||||
/** Create a new Reader of the type defined in $inputFileType **/
|
||||
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
|
||||
/** Define how many rows we want to read for each "chunk" **/
|
||||
$chunkSize = 100;
|
||||
/** Create a new Instance of our Read Filter **/
|
||||
$chunkFilter = new chunkReadFilter();
|
||||
|
||||
/** Tell the Reader that we want to use the Read Filter that we've Instantiated **/
|
||||
/** and that we want to store it in contiguous rows/columns **/
|
||||
$objReader->setReadFilter($chunkFilter)
|
||||
->setContiguous(true);
|
||||
|
||||
|
||||
/** Instantiate a new PHPExcel object manually **/
|
||||
$objPHPExcel = new PHPExcel();
|
||||
|
||||
/** Set a sheet index **/
|
||||
$sheet = 0;
|
||||
/** Loop to read our worksheet in "chunk size" blocks **/
|
||||
/** $startRow is set to 2 initially because we always read the headings in row #1 **/
|
||||
for ($startRow = 2; $startRow <= 240; $startRow += $chunkSize) {
|
||||
echo 'Loading WorkSheet #',($sheet+1),' using configurable filter for headings row 1 and for rows ',$startRow,' to ',($startRow+$chunkSize-1),'<br />';
|
||||
/** Tell the Read Filter, the limits on which rows we want to read this iteration **/
|
||||
$chunkFilter->setRows($startRow,$chunkSize);
|
||||
|
||||
/** Increment the worksheet index pointer for the Reader **/
|
||||
$objReader->setSheetIndex($sheet);
|
||||
/** Load only the rows that match our filter into a new worksheet in the PHPExcel Object **/
|
||||
$objReader->loadIntoExisting($inputFileName,$objPHPExcel);
|
||||
/** Set the worksheet title (to reference the "sheet" of data that we've loaded) **/
|
||||
/** and increment the sheet index as well **/
|
||||
$objPHPExcel->getActiveSheet()->setTitle('Country Data #'.(++$sheet));
|
||||
}
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
echo $objPHPExcel->getSheetCount(),' worksheet',(($objPHPExcel->getSheetCount() == 1) ? '' : 's'),' loaded<br /><br />';
|
||||
$loadedSheetNames = $objPHPExcel->getSheetNames();
|
||||
foreach($loadedSheetNames as $sheetIndex => $loadedSheetName) {
|
||||
echo '<b>Worksheet #',$sheetIndex,' -> ',$loadedSheetName,'</b><br />';
|
||||
$objPHPExcel->setActiveSheetIndexByName($loadedSheetName);
|
||||
$sheetData = $objPHPExcel->getActiveSheet()->toArray(null,false,false,true);
|
||||
var_dump($sheetData);
|
||||
echo '<br />';
|
||||
}
|
||||
|
||||
?>
|
||||
<body>
|
||||
</html>
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Reader Example #15</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>PHPExcel Reader Example #15</h1>
|
||||
<h2>Simple File Reader for Tab-Separated Value File using the Advanced Value Binder</h2>
|
||||
<?php
|
||||
|
||||
/** Include path **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../Classes/');
|
||||
|
||||
/** PHPExcel_IOFactory */
|
||||
include 'PHPExcel/IOFactory.php';
|
||||
|
||||
|
||||
PHPExcel_Cell::setValueBinder( new PHPExcel_Cell_AdvancedValueBinder() );
|
||||
|
||||
|
||||
$inputFileType = 'CSV';
|
||||
$inputFileName = './sampleData/example1.tsv';
|
||||
|
||||
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
|
||||
echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' into WorkSheet #1 using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
||||
$objReader->setDelimiter("\t");
|
||||
$objPHPExcel = $objReader->load($inputFileName);
|
||||
$objPHPExcel->getActiveSheet()->setTitle(pathinfo($inputFileName,PATHINFO_BASENAME));
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
echo $objPHPExcel->getSheetCount(),' worksheet',(($objPHPExcel->getSheetCount() == 1) ? '' : 's'),' loaded<br /><br />';
|
||||
$loadedSheetNames = $objPHPExcel->getSheetNames();
|
||||
foreach($loadedSheetNames as $sheetIndex => $loadedSheetName) {
|
||||
echo '<b>Worksheet #',$sheetIndex,' -> ',$loadedSheetName,' (Formatted)</b><br />';
|
||||
$objPHPExcel->setActiveSheetIndexByName($loadedSheetName);
|
||||
$sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
|
||||
var_dump($sheetData);
|
||||
echo '<br />';
|
||||
}
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
foreach($loadedSheetNames as $sheetIndex => $loadedSheetName) {
|
||||
echo '<b>Worksheet #',$sheetIndex,' -> ',$loadedSheetName,' (Unformatted)</b><br />';
|
||||
$objPHPExcel->setActiveSheetIndexByName($loadedSheetName);
|
||||
$sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,false,true);
|
||||
var_dump($sheetData);
|
||||
echo '<br />';
|
||||
}
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
foreach($loadedSheetNames as $sheetIndex => $loadedSheetName) {
|
||||
echo '<b>Worksheet #',$sheetIndex,' -> ',$loadedSheetName,' (Raw)</b><br />';
|
||||
$objPHPExcel->setActiveSheetIndexByName($loadedSheetName);
|
||||
$sheetData = $objPHPExcel->getActiveSheet()->toArray(null,false,false,true);
|
||||
var_dump($sheetData);
|
||||
echo '<br />';
|
||||
}
|
||||
|
||||
?>
|
||||
<body>
|
||||
</html>
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
date_default_timezone_set('Europe/London');
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Reader Example #16</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>PHPExcel Reader Example #16</h1>
|
||||
<h2>Handling Loader Exceptions using Try/Catch</h2>
|
||||
<?php
|
||||
|
||||
/** Include path **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../Classes/');
|
||||
|
||||
/** PHPExcel_IOFactory */
|
||||
include 'PHPExcel/IOFactory.php';
|
||||
|
||||
|
||||
$inputFileName = './sampleData/example_1.xls';
|
||||
echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using IOFactory to identify the format<br />';
|
||||
try {
|
||||
$objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
|
||||
} catch(PHPExcel_Reader_Exception $e) {
|
||||
die('Error loading file "'.pathinfo($inputFileName,PATHINFO_BASENAME).'": '.$e->getMessage());
|
||||
}
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
$sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
|
||||
var_dump($sheetData);
|
||||
|
||||
|
||||
?>
|
||||
<body>
|
||||
</html>
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
date_default_timezone_set('Europe/London');
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Reader Example #17</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>PHPExcel Reader Example #17</h1>
|
||||
<h2>Simple File Reader Loading Several Named WorkSheets</h2>
|
||||
<?php
|
||||
|
||||
/** Include path **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../Classes/');
|
||||
|
||||
/** PHPExcel_IOFactory */
|
||||
include 'PHPExcel/IOFactory.php';
|
||||
|
||||
|
||||
$inputFileType = 'Excel5';
|
||||
// $inputFileType = 'Excel2007';
|
||||
// $inputFileType = 'Excel2003XML';
|
||||
// $inputFileType = 'OOCalc';
|
||||
// $inputFileType = 'Gnumeric';
|
||||
$inputFileName = './sampleData/example1.xls';
|
||||
|
||||
echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
||||
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
|
||||
|
||||
|
||||
/** Read the list of Worksheet Names from the Workbook file **/
|
||||
echo 'Read the list of Worksheets in the WorkBook<br />';
|
||||
$worksheetNames = $objReader->listWorksheetNames($inputFileName);
|
||||
|
||||
echo 'There are ',count($worksheetNames),' worksheet',((count($worksheetNames) == 1) ? '' : 's'),' in the workbook<br /><br />';
|
||||
foreach($worksheetNames as $worksheetName) {
|
||||
echo $worksheetName,'<br />';
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
<body>
|
||||
</html>
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
date_default_timezone_set('Europe/London');
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Reader Example #18</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>PHPExcel Reader Example #18</h1>
|
||||
<h2>Reading list of WorkSheets without loading entire file</h2>
|
||||
<?php
|
||||
|
||||
/** Include path **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../Classes/');
|
||||
|
||||
/** PHPExcel_IOFactory */
|
||||
include 'PHPExcel/IOFactory.php';
|
||||
|
||||
|
||||
$inputFileType = 'Excel5';
|
||||
// $inputFileType = 'Excel2007';
|
||||
// $inputFileType = 'Excel2003XML';
|
||||
// $inputFileType = 'OOCalc';
|
||||
// $inputFileType = 'Gnumeric';
|
||||
$inputFileName = './sampleData/example1.xls';
|
||||
|
||||
echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' information using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
||||
|
||||
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
|
||||
$worksheetNames = $objReader->listWorksheetNames($inputFileName);
|
||||
|
||||
echo '<h3>Worksheet Names</h3>';
|
||||
echo '<ol>';
|
||||
foreach ($worksheetNames as $worksheetName) {
|
||||
echo '<li>', $worksheetName, '</li>';
|
||||
}
|
||||
echo '</ol>';
|
||||
|
||||
?>
|
||||
<body>
|
||||
</html>
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
date_default_timezone_set('Europe/London');
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Reader Example #19</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>PHPExcel Reader Example #19</h1>
|
||||
<h2>Reading WorkSheet information without loading entire file</h2>
|
||||
<?php
|
||||
|
||||
/** Include path **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../Classes/');
|
||||
|
||||
/** PHPExcel_IOFactory */
|
||||
include 'PHPExcel/IOFactory.php';
|
||||
|
||||
|
||||
$inputFileType = 'Excel5';
|
||||
// $inputFileType = 'Excel2007';
|
||||
// $inputFileType = 'Excel2003XML';
|
||||
// $inputFileType = 'OOCalc';
|
||||
// $inputFileType = 'Gnumeric';
|
||||
$inputFileName = './sampleData/example1.xls';
|
||||
|
||||
echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' information using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
||||
|
||||
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
|
||||
$worksheetData = $objReader->listWorksheetInfo($inputFileName);
|
||||
|
||||
echo '<h3>Worksheet Information</h3>';
|
||||
echo '<ol>';
|
||||
foreach ($worksheetData as $worksheet) {
|
||||
echo '<li>', $worksheet['worksheetName'], '<br />';
|
||||
echo 'Rows: ', $worksheet['totalRows'], ' Columns: ', $worksheet['totalColumns'], '<br />';
|
||||
echo 'Cell Range: A1:', $worksheet['lastColumnLetter'], $worksheet['totalRows'];
|
||||
echo '</li>';
|
||||
}
|
||||
echo '</ol>';
|
||||
|
||||
?>
|
||||
<body>
|
||||
</html>
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
date_default_timezone_set('Europe/London');
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Reading WorkBook Data Example #01</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>PHPExcel Reading WorkBook Data Example #01</h1>
|
||||
<h2>Read the WorkBook Properties</h2>
|
||||
<?php
|
||||
|
||||
/** Include path **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../Classes/');
|
||||
|
||||
/** PHPExcel_IOFactory */
|
||||
include 'PHPExcel/IOFactory.php';
|
||||
|
||||
|
||||
$inputFileType = 'Excel5';
|
||||
$inputFileName = './sampleData/example1.xls';
|
||||
|
||||
/** Create a new Reader of the type defined in $inputFileType **/
|
||||
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
|
||||
/** Load $inputFileName to a PHPExcel Object **/
|
||||
$objPHPExcel = $objReader->load($inputFileName);
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
/** Read the document's creator property **/
|
||||
$creator = $objPHPExcel->getProperties()->getCreator();
|
||||
echo '<b>Document Creator: </b>',$creator,'<br />';
|
||||
|
||||
/** Read the Date when the workbook was created (as a PHP timestamp value) **/
|
||||
$creationDatestamp = $objPHPExcel->getProperties()->getCreated();
|
||||
/** Format the date and time using the standard PHP date() function **/
|
||||
$creationDate = date('l, d<\s\up>S</\s\up> F Y',$creationDatestamp);
|
||||
$creationTime = date('g:i A',$creationDatestamp);
|
||||
echo '<b>Created On: </b>',$creationDate,' at ',$creationTime,'<br />';
|
||||
|
||||
/** Read the name of the last person to modify this workbook **/
|
||||
$modifiedBy = $objPHPExcel->getProperties()->getLastModifiedBy();
|
||||
echo '<b>Last Modified By: </b>',$modifiedBy,'<br />';
|
||||
|
||||
/** Read the Date when the workbook was last modified (as a PHP timestamp value) **/
|
||||
$modifiedDatestamp = $objPHPExcel->getProperties()->getModified();
|
||||
/** Format the date and time using the standard PHP date() function **/
|
||||
$modifiedDate = date('l, d<\s\up>S</\s\up> F Y',$modifiedDatestamp);
|
||||
$modifiedTime = date('g:i A',$modifiedDatestamp);
|
||||
echo '<b>Last Modified On: </b>',$modifiedDate,' at ',$modifiedTime,'<br />';
|
||||
|
||||
/** Read the workbook title property **/
|
||||
$workbookTitle = $objPHPExcel->getProperties()->getTitle();
|
||||
echo '<b>Title: </b>',$workbookTitle,'<br />';
|
||||
|
||||
/** Read the workbook description property **/
|
||||
$description = $objPHPExcel->getProperties()->getDescription();
|
||||
echo '<b>Description: </b>',$description,'<br />';
|
||||
|
||||
/** Read the workbook subject property **/
|
||||
$subject = $objPHPExcel->getProperties()->getSubject();
|
||||
echo '<b>Subject: </b>',$subject,'<br />';
|
||||
|
||||
/** Read the workbook keywords property **/
|
||||
$keywords = $objPHPExcel->getProperties()->getKeywords();
|
||||
echo '<b>Keywords: </b>',$keywords,'<br />';
|
||||
|
||||
/** Read the workbook category property **/
|
||||
$category = $objPHPExcel->getProperties()->getCategory();
|
||||
echo '<b>Category: </b>',$category,'<br />';
|
||||
|
||||
/** Read the workbook company property **/
|
||||
$company = $objPHPExcel->getProperties()->getCompany();
|
||||
echo '<b>Company: </b>',$company,'<br />';
|
||||
|
||||
/** Read the workbook manager property **/
|
||||
$manager = $objPHPExcel->getProperties()->getManager();
|
||||
echo '<b>Manager: </b>',$manager,'<br />';
|
||||
|
||||
|
||||
?>
|
||||
<body>
|
||||
</html>
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
date_default_timezone_set('Europe/London');
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Reading WorkBook Data Example #02</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>PHPExcel Reading WorkBook Data Example #02</h1>
|
||||
<h2>Read a list of Custom Properties for a WorkBook</h2>
|
||||
<?php
|
||||
|
||||
/** Include path **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../Classes/');
|
||||
|
||||
/** PHPExcel_IOFactory */
|
||||
include 'PHPExcel/IOFactory.php';
|
||||
|
||||
|
||||
$inputFileType = 'Excel2007';
|
||||
$inputFileName = './sampleData/example1.xlsx';
|
||||
|
||||
/** Create a new Reader of the type defined in $inputFileType **/
|
||||
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
|
||||
/** Load $inputFileName to a PHPExcel Object **/
|
||||
$objPHPExcel = $objReader->load($inputFileName);
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
/** Read an array list of any custom properties for this document **/
|
||||
$customPropertyList = $objPHPExcel->getProperties()->getCustomProperties();
|
||||
|
||||
echo '<b>Custom Property names: </b><br />';
|
||||
foreach($customPropertyList as $customPropertyName) {
|
||||
echo $customPropertyName,'<br />';
|
||||
}
|
||||
|
||||
|
||||
|
||||
?>
|
||||
<body>
|
||||
</html>
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
date_default_timezone_set('Europe/London');
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Reading WorkBook Data Example #03</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>PHPExcel Reading WorkBook Data Example #03</h1>
|
||||
<h2>Read Custom Property Values for a WorkBook</h2>
|
||||
<?php
|
||||
|
||||
/** Include path **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../Classes/');
|
||||
|
||||
/** PHPExcel_IOFactory */
|
||||
include 'PHPExcel/IOFactory.php';
|
||||
|
||||
|
||||
$inputFileType = 'Excel2007';
|
||||
$inputFileName = './sampleData/example1.xlsx';
|
||||
|
||||
/** Create a new Reader of the type defined in $inputFileType **/
|
||||
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
|
||||
/** Load $inputFileName to a PHPExcel Object **/
|
||||
$objPHPExcel = $objReader->load($inputFileName);
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
/** Read an array list of any custom properties for this document **/
|
||||
$customPropertyList = $objPHPExcel->getProperties()->getCustomProperties();
|
||||
|
||||
echo '<b>Custom Properties: </b><br />';
|
||||
/** Loop through the list of custom properties **/
|
||||
foreach($customPropertyList as $customPropertyName) {
|
||||
echo '<b>',$customPropertyName,': </b>';
|
||||
/** Retrieve the property value **/
|
||||
$propertyValue = $objPHPExcel->getProperties()->getCustomPropertyValue($customPropertyName);
|
||||
/** Retrieve the property type **/
|
||||
$propertyType = $objPHPExcel->getProperties()->getCustomPropertyType($customPropertyName);
|
||||
|
||||
/** Manipulate properties as appropriate for display purposes **/
|
||||
switch($propertyType) {
|
||||
case 'i' : // integer
|
||||
$propertyType = 'integer number';
|
||||
break;
|
||||
case 'f' : // float
|
||||
$propertyType = 'floating point number';
|
||||
break;
|
||||
case 's' : // string
|
||||
$propertyType = 'string';
|
||||
break;
|
||||
case 'd' : // date
|
||||
$propertyValue = date('l, d<\s\up>S</\s\up> F Y g:i A',$propertyValue);
|
||||
$propertyType = 'date';
|
||||
break;
|
||||
case 'b' : // boolean
|
||||
$propertyValue = ($propertyValue) ? 'TRUE' : 'FALSE';
|
||||
$propertyType = 'boolean';
|
||||
break;
|
||||
}
|
||||
|
||||
echo $propertyValue,' (',$propertyType,')<br />';
|
||||
}
|
||||
|
||||
|
||||
|
||||
?>
|
||||
<body>
|
||||
</html>
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
date_default_timezone_set('Europe/London');
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Reading WorkBook Data Example #04</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>PHPExcel Reading WorkBook Data Example #04</h1>
|
||||
<h2>Get a List of the Worksheets in a WorkBook</h2>
|
||||
<?php
|
||||
|
||||
/** Include path **/
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../Classes/');
|
||||
|
||||
/** PHPExcel_IOFactory */
|
||||
include 'PHPExcel/IOFactory.php';
|
||||
|
||||
|
||||
$inputFileType = 'Excel5';
|
||||
$inputFileName = './sampleData/example2.xls';
|
||||
|
||||
/** Create a new Reader of the type defined in $inputFileType **/
|
||||
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
|
||||
/** Load $inputFileName to a PHPExcel Object **/
|
||||
$objPHPExcel = $objReader->load($inputFileName);
|
||||
|
||||
|
||||
echo '<hr />';
|
||||
|
||||
echo 'Reading the number of Worksheets in the WorkBook<br />';
|
||||
/** Use the PHPExcel object's getSheetCount() method to get a count of the number of WorkSheets in the WorkBook */
|
||||
$sheetCount = $objPHPExcel->getSheetCount();
|
||||
echo 'There ',(($sheetCount == 1) ? 'is' : 'are'),' ',$sheetCount,' WorkSheet',(($sheetCount == 1) ? '' : 's'),' in the WorkBook<br /><br />';
|
||||
|
||||
echo 'Reading the names of Worksheets in the WorkBook<br />';
|
||||
/** Use the PHPExcel object's getSheetNames() method to get an array listing the names/titles of the WorkSheets in the WorkBook */
|
||||
$sheetNames = $objPHPExcel->getSheetNames();
|
||||
foreach($sheetNames as $sheetIndex => $sheetName) {
|
||||
echo 'WorkSheet #',$sheetIndex,' is named "',$sheetName,'"<br />';
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
<body>
|
||||
</html>
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
set_time_limit(0);
|
||||
|
||||
date_default_timezone_set('Europe/London');
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
<title>PHPExcel Examples</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<?php
|
||||
|
||||
$exampleTypeList = glob('./*',GLOB_ONLYDIR);
|
||||
|
||||
foreach($exampleTypeList as $exampleType) {
|
||||
|
||||
echo '<h1>PHPExcel ' . pathinfo($exampleType,PATHINFO_BASENAME) . ' Examples</h1>';
|
||||
|
||||
$exampleList = glob('./'.$exampleType.'/*.php');
|
||||
|
||||
foreach($exampleList as $exampleFile) {
|
||||
$fileData = file_get_contents($exampleFile);
|
||||
|
||||
$h1Pattern = '#<h1>(.*?)</h1>#';
|
||||
$h2Pattern = '#<h2>(.*?)</h2>#';
|
||||
|
||||
if (preg_match($h1Pattern, $fileData, $out)) {
|
||||
$h1Text = $out[1];
|
||||
$h2Text = (preg_match($h2Pattern, $fileData, $out)) ? $out[1] : '';
|
||||
|
||||
echo '<a href="',$exampleFile,'">',$h1Text,'</a><br />';
|
||||
if (($h2Text > '') &&
|
||||
(pathinfo($exampleType,PATHINFO_BASENAME) != 'Calculations')) {
|
||||
echo $h2Text,'<br />';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
<body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user