Merge branch 'develop' of https://github.com/PHPOffice/PhpSpreadsheet into develop

This commit is contained in:
MarkBaker 2017-09-10 22:27:50 +01:00
commit d576855031
325 changed files with 7062 additions and 5568 deletions

29
.github/ISSUE_TEMPLATE.md vendored Normal file
View File

@ -0,0 +1,29 @@
This is:
- [ ] a bug report
- [ ] a feature request
- [ ] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)
### What is the expected behavior?
### What is the current behavior?
### What are the steps to reproduce?
Please provide a [Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) of code that exhibits the issue without relying on an external Excel file or a web server:
```php
<?php
require __DIR__ . '/vendor/autoload.php';
// Create new Spreadsheet object
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
// add code that show the issue here...
```
### Which versions of PhpSpreadsheet and PHP are affected?

14
.github/PULL_REQUEST_TEMPLATE.md vendored Normal file
View File

@ -0,0 +1,14 @@
This is:
- [ ] a bugfix
- [ ] a new feature
Checklist:
- [ ] Changes are covered by unit tests
- [ ] Code style is respected
- [ ] Commit message explains **why** the change is made (see https://github.com/erlang/otp/wiki/Writing-good-commit-messages)
- [ ] CHANGELOG.md contains a short summary of the change
- [ ] Documentation is updated as necessary
What does it change?

View File

@ -6,14 +6,11 @@ php:
- 5.6
- 7.0
- 7.1
- hhvm
matrix:
include:
- php: 7.0
env: COVERAGE=1
allow_failures:
- php: hhvm
cache:
directories:

View File

@ -1,4 +1,5 @@
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
@ -8,20 +9,40 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Added
- Support for chart fill color - @CrazyBite [#158](https://github.com/PHPOffice/PhpSpreadsheet/pull/158)
### Changed
- Merge data-validations to reduce written worksheet size - @billblume [#131](https://github.com/PHPOffice/PhpSpreadSheet/issues/131)
### Fixed
- Control characters in cell values are automatically escaped [#212](https://github.com/PHPOffice/PhpSpreadsheet/issues/212)
### BREAKING CHANGE
- Standardization of array keys used for style, see the [migration guide](./docs/topics/migration-from-PHPExcel.md).
## [1.0.0-beta] - 2017-08-17
### Added
- Initial implementation of SUMIFS() function
- Additional codepages
- MemoryDrawing not working in HTML writer [#808](https://github.com/PHPOffice/PHPExcel/issues/808)
- CSV Reader can auto-detect the separator used in file [#141](https://github.com/PHPOffice/PhpSpreadsheet/pull/141)
- HTML Reader supports some basic inline styles [#180](https://github.com/PHPOffice/PhpSpreadsheet/pull/180)
### Changed
- Start following [SemVer](http://semver.org) properly.
### Bugfixes
### Fixed
- Fix to getCell() method when cell reference includes a worksheet reference - @MarkBaker
- Ignore inlineStr type if formula element exists - @ncrypthic [#570](https://github.com/PHPOffice/PHPExcel/issues/570)
- Excel 2007 Reader freezes because of conditional formatting - @rentalhost [#575](https://github.com/PHPOffice/PHPExcel/issues/575)
- Readers will now parse files containing worksheet titles over 31 characters [#176](https://github.com/PHPOffice/PhpSpreadsheet/pull/176)
### General
@ -35,10 +56,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Introduction of namespaces for all classes, eg: `PHPExcel_Calculation_Functions` becomes `PhpOffice\PhpSpreadsheet\Calculation\Functions`
- Some classes were renamed for clarity and/or consistency:
For a comprehensive list of all class changes, and a semi-automated migration path, read the [migration guide](./docs/Migration-from-PHPExcel.md).
For a comprehensive list of all class changes, and a semi-automated migration path, read the [migration guide](./docs/topics/migration-from-PHPExcel.md).
- Dropped `PHPExcel_Calculation_Functions::VERSION()`. Composer or git should be used to know the version.
- Dropped `PHPExcel_Settings::setPdfRenderer()` and `PHPExcel_Settings::setPdfRenderer()`. Composer should be used to autoload PDF libs.
- Dropped support for HHVM
## Previous versions of PHPExcel

10
CONTRIBUTING.md Normal file
View File

@ -0,0 +1,10 @@
# Want to contribute?
If you would like to contribute, here are some notes and guidelines:
- All new development happens on feature/fix branches referenced with the GitHub issue number, and are then merged to the develop branch; so the develop branch is always the most up-to-date, working code
- The master branch only contains tagged releases
- If you are going to be submitting a pull request, please fork from develop, and submit your pull request back as a fix/feature branch referencing the GitHub issue number
- Code changes must be validated by PHP-CS-Fixer and PHP_CodeSniffer (via `./vendor/bin/php-cs-fixer fix --verbose && ./vendor/bin/phpcs samples/ src/ tests/ --standard=PSR2 -n`)
- [Helpful article about forking](https://help.github.com/articles/fork-a-repo/ "Forking a GitHub repository")
- [Helpful article about pull requests](https://help.github.com/articles/using-pull-requests/ "Pull Requests")

View File

@ -16,41 +16,14 @@ Develop:
PhpSpreadsheet is a library written in pure PHP and providing a set of classes that allow you to read from and to write to different spreadsheet file formats, like Excel and LibreOffice Calc.
## File formats supported
## Documentation
|Format |Reading|Writing|
|--------------------------------------------|:-----:|:-----:|
|Open Document Format/OASIS (.ods) | ✓ | ✓ |
|Office Open XML (.xlsx) Excel 2007 and above| ✓ | ✓ |
|BIFF 8 (.xls) Excel 97 and above | ✓ | ✓ |
|BIFF 5 (.xls) Excel 95 | ✓ | |
|SpreadsheetML (.xml) Excel 2003 | ✓ | |
|Gnumeric | ✓ | |
|HTML | ✓ | ✓ |
|SYLK | ✓ | |
|CSV | ✓ | ✓ |
|PDF (using either the tcPDF, DomPDF or mPDF libraries, which need to be installed separately)| | ✓ |
Read more about it, including install instructions, in the official documentation, either at the online version:
## Requirements
https://phpspreadsheet.readthedocs.io
* PHP version 5.6 or higher
* PHP extension php_zip enabled
* PHP extension php_xml enabled
* PHP extension php_gd2 enabled (optional, but required for exact column width autocalculation)
Or directly in this repository in the folder `docs/`.
## PHP version support
Support for PHP versions will only be maintained for a period of six months beyond the end-of-life of that PHP version
## Want to contribute?
If you would like to contribute, here are some notes and guidelines:
- All new development happens on feature/fix branches referenced with the GitHub issue number, and are then merged to the develop branch; so the develop branch is always the most up-to-date, working code
- The master branch only contains tagged releases
- If you are going to be submitting a pull request, please fork from develop, and submit your pull request back as a fix/feature branch referencing the GitHub issue number
- Code changes must be validated by PHP-CS-Fixer and PHP_CodeSniffer (via `./vendor/bin/php-cs-fixer fix --verbose && ./vendor/bin/phpcs samples/ src/ tests/ --standard=PSR2 -n`)
- [Helpful article about forking](https://help.github.com/articles/fork-a-repo/ "Forking a GitHub repository")
- [Helpful article about pull requests](https://help.github.com/articles/using-pull-requests/ "Pull Requests")
## PHPExcel vs PhpSpreadsheet ?

View File

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

View File

@ -1,32 +1,32 @@
<?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
error_reporting(E_ALL);
set_time_limit(0);
date_default_timezone_set('Europe/London');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PhpSpreadsheet Calculation Examples</title>
<title>PhpSpreadsheet Calculation Examples</title>
</head>
<body>
</head>
<body>
<h1>DAVERAGE</h1>
<h2>Returns the average of selected database entries.</h2>
<?php
<h1>DAVERAGE</h1>
<h2>Returns the average of selected database entries.</h2>
<?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
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
// Add some data
$database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'],
// Add some data
$database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'],
['Apple', 18, 20, 14, 105.00],
['Pear', 12, 12, 10, 96.00],
['Cherry', 13, 14, 9, 105.00],
@ -34,46 +34,45 @@ $database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'],
['Pear', 9, 8, 8, 76.80],
['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'],
['="=Pear"', null, null, null, null, null],
];
$worksheet->fromArray($criteria, null, 'A1');
$worksheet->fromArray($database, null, 'A4');
$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('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)');
$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 '<hr />';
echo '<h4>Database</h4>';
echo '<h4>Database</h4>';
$databaseData = $worksheet->rangeToArray('A4:E10', null, true, true, true);
var_dump($databaseData);
$databaseData = $worksheet->rangeToArray('A4:E10', null, true, true, true);
var_dump($databaseData);
echo '<hr />';
echo '<hr />';
// Test the formulae
echo '<h4>Criteria</h4>';
// Test the formulae
echo '<h4>Criteria</h4>';
$criteriaData = $worksheet->rangeToArray('A1:B2', null, true, true, true);
var_dump($criteriaData);
$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 $worksheet->getCell('A12')->getValue() . '<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);
var_dump($criteriaData);
$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>
echo $worksheet->getCell('A13')->getValue() . '<br />';
echo 'DAVERAGE() Result is ' . $worksheet->getCell('B13')->getCalculatedValue();
?>
<body>
</html>

View File

@ -1,32 +1,32 @@
<?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
error_reporting(E_ALL);
set_time_limit(0);
date_default_timezone_set('Europe/London');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PhpSpreadsheet Calculation Examples</title>
<title>PhpSpreadsheet Calculation Examples</title>
</head>
<body>
</head>
<body>
<h1>DCOUNT</h1>
<h2>Counts the cells that contain numbers in a database.</h2>
<?php
<h1>DCOUNT</h1>
<h2>Counts the cells that contain numbers in a database.</h2>
<?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
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
// Add some data
$database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'],
// Add some data
$database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'],
['Apple', 18, 20, 14, 105.00],
['Pear', 12, 12, 10, 96.00],
['Cherry', 13, 14, 9, 105.00],
@ -34,46 +34,45 @@ $database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'],
['Pear', 9, 8, 8, 76.80],
['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'],
['="=Pear"', null, null, null, null, null],
];
$worksheet->fromArray($criteria, null, 'A1');
$worksheet->fromArray($database, null, 'A4');
$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('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)');
$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 '<hr />';
echo '<h4>Database</h4>';
echo '<h4>Database</h4>';
$databaseData = $worksheet->rangeToArray('A4:E10', null, true, true, true);
var_dump($databaseData);
$databaseData = $worksheet->rangeToArray('A4:E10', null, true, true, true);
var_dump($databaseData);
echo '<hr />';
echo '<hr />';
// Test the formulae
echo '<h4>Criteria</h4>';
// Test the formulae
echo '<h4>Criteria</h4>';
$criteriaData = $worksheet->rangeToArray('A1:B2', null, true, true, true);
var_dump($criteriaData);
$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 $worksheet->getCell('A12')->getValue() . '<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);
var_dump($criteriaData);
$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>
echo $worksheet->getCell('A13')->getValue() . '<br />';
echo 'DCOUNT() Result is ' . $worksheet->getCell('B13')->getCalculatedValue();
?>
<body>
</html>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,27 +1,24 @@
<?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" />
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PhpSpreadsheet Calculation Function Examples</title>
<title>PhpSpreadsheet Calculation Function Examples</title>
</head>
<body>
</head>
<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>';
$exampleList = glob('./' . $exampleType . '/*.php');
@ -36,14 +33,13 @@ foreach ($exampleTypeList as $exampleType) {
$h1Text = $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 > '') {
echo $h2Text,'<br />';
echo $h2Text, '<br />';
}
}
}
}
?>
<body>
}
?>
<body>
</html>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,40 +1,36 @@
<?php
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Reader\IReadFilter;
error_reporting(E_ALL);
set_time_limit(0);
date_default_timezone_set('Europe/London');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PhpSpreadsheet Reader Example #10</title>
<title>PhpSpreadsheet Reader Example #10</title>
</head>
<body>
</head>
<body>
<h1>PhpSpreadsheet Reader Example #10</h1>
<h2>Simple File Reader Using a Configurable Read Filter</h2>
<?php
<h1>PhpSpreadsheet Reader Example #10</h1>
<h2>Simple File Reader Using a Configurable Read Filter</h2>
<?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';
// $inputFileType = 'Xlsx';
// $inputFileType = 'Xml';
// $inputFileType = 'Ods';
// $inputFileType = 'Gnumeric';
$inputFileName = './sampleData/example1.xls';
$sheetname = 'Data Sheet #3';
class MyReadFilter implements IReadFilter
{
class MyReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter
{
private $_startRow = 0;
private $_endRow = 0;
private $_columns = [];
public function __construct($startRow, $endRow, $columns)
@ -54,23 +50,23 @@ class MyReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter
return false;
}
}
$filterSubset = new MyReadFilter(9, 15, range('G', 'K'));
}
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
$reader = \PhpOffice\PhpSpreadsheet\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);
$filterSubset = new MyReadFilter(9, 15, range('G', 'K'));
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);
var_dump($sheetData);
echo '<hr />';
?>
<body>
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
var_dump($sheetData);
?>
<body>
</html>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,48 +1,43 @@
<?php
use PhpOffice\PhpSpreadsheet\IOFactory;
error_reporting(E_ALL);
set_time_limit(0);
date_default_timezone_set('Europe/London');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PhpSpreadsheet Reader Example #19</title>
<title>PhpSpreadsheet Reader Example #19</title>
</head>
<body>
</head>
<body>
<h1>PhpSpreadsheet Reader Example #19</h1>
<h2>Reading WorkSheet information without loading entire file</h2>
<?php
<h1>PhpSpreadsheet Reader Example #19</h1>
<h2>Reading WorkSheet information without loading entire file</h2>
<?php
require_once __DIR__ . '/../../../src/Bootstrap.php';
require_once __DIR__ . '/../../../src/Bootstrap.php';
$inputFileType = 'Xls';
$inputFileName = './sampleData/example1.xls';
$inputFileType = 'Xls';
// $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 />';
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 = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
$worksheetData = $reader->listWorksheetInfo($inputFileName);
echo '<h3>Worksheet Information</h3>';
echo '<ol>';
foreach ($worksheetData as $worksheet) {
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>
}
echo '</ol>';
?>
<body>
</html>

View File

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

View File

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

View File

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

View File

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

View File

@ -1,25 +1,22 @@
<?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" />
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PhpSpreadsheet Examples</title>
<title>PhpSpreadsheet Examples</title>
</head>
<body>
</head>
<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>';
$exampleList = glob('./' . $exampleType . '/*.php');
@ -41,8 +38,7 @@ foreach ($exampleTypeList as $exampleType) {
}
}
}
}
?>
<body>
}
?>
<body>
</html>

8
docs/extra/extra.css Normal file
View File

@ -0,0 +1,8 @@
/* Make the huge table always visible */
table.features-cross-reference {
overflow: visible !important;
}
.rst-content table.features-cross-reference.docutils th,
.rst-content table.features-cross-reference.docutils td {
background-color: white;
}

57
docs/extra/extra.js Normal file
View File

@ -0,0 +1,57 @@
var nodemcu = nodemcu || {};
(function () {
'use strict';
$(document).ready(function () {
fixSearch();
});
/*
* RTD messes up MkDocs' search feature by tinkering with the search box defined in the theme, see
* https://github.com/rtfd/readthedocs.org/issues/1088. This function sets up a DOM4 MutationObserver
* to react to changes to the search form (triggered by RTD on doc ready). It then reverts everything
* the RTD JS code modified.
*/
function fixSearch() {
var target = document.getElementById('rtd-search-form');
var config = {attributes: true, childList: true};
var observer = new MutationObserver(function (mutations) {
// if it isn't disconnected it'll loop infinitely because the observed element is modified
observer.disconnect();
var form = $('#rtd-search-form');
form.empty();
form.attr('action', 'https://' + window.location.hostname + '/en/' + determineSelectedBranch() + '/search.html');
$('<input>').attr({
type: "text",
name: "q",
placeholder: "Search docs"
}).appendTo(form);
});
if (window.location.origin.indexOf('readthedocs') > -1) {
observer.observe(target, config);
}
}
/**
* Analyzes the URL of the current page to find out what the selected GitHub branch is. It's usually
* part of the location path. The code needs to distinguish between running MkDocs standalone
* and docs served from RTD. If no valid branch could be determined 'dev' returned.
*
* @returns GitHub branch name
*/
function determineSelectedBranch() {
var branch = 'dev', path = window.location.pathname;
if (window.location.origin.indexOf('readthedocs') > -1) {
// path is like /en/<branch>/<lang>/build/ -> extract 'lang'
// split[0] is an '' because the path starts with the separator
var thirdPathSegment = path.split('/')[2];
// 'latest' is an alias on RTD for the 'dev' branch - which is the default for 'branch' here
if (thirdPathSegment !== 'latest') {
branch = thirdPathSegment;
}
}
return branch;
}
}());

View File

@ -6,6 +6,21 @@ PhpSpreadsheet is a library written in pure PHP and providing a set of
classes that allow you to read from and to write to different
spreadsheet file formats, like Excel and LibreOffice Calc.
## File formats supported
|Format |Reading|Writing|
|--------------------------------------------|:-----:|:-----:|
|Open Document Format/OASIS (.ods) | ✓ | ✓ |
|Office Open XML (.xlsx) Excel 2007 and above| ✓ | ✓ |
|BIFF 8 (.xls) Excel 97 and above | ✓ | ✓ |
|BIFF 5 (.xls) Excel 95 | ✓ | |
|SpreadsheetML (.xml) Excel 2003 | ✓ | |
|Gnumeric | ✓ | |
|HTML | ✓ | ✓ |
|SYLK | ✓ | |
|CSV | ✓ | ✓ |
|PDF (using either the tcPDF, DomPDF or mPDF libraries, which need to be installed separately)| | ✓ |
# Getting started
## Software requirements
@ -17,6 +32,10 @@ The following software is required to develop using PhpSpreadsheet:
- PHP extension php\_xml enabled
- PHP extension php\_gd2 enabled (if not compiled in)
### PHP version support
Support for PHP versions will only be maintained for a period of six months beyond the end-of-life of that PHP version
## Installation
Use [composer](https://getcomposer.org/) to install PhpSpreadsheet into your project:

View File

@ -5,7 +5,7 @@
- <span style="text-align: center; color: red;"></span> Not supported
- N/A Cannot be supported
<table>
<table class="features-cross-reference">
<tr>
<th></th>
<th colspan="7">Readers</th>
@ -906,7 +906,7 @@
<td></td>
<td></td>
<td></td>
<td></td>
<td style="text-align: center; color: orange;"></td>
<td></td>
<td></td>
<td></td>

View File

@ -90,7 +90,7 @@ calculated values, or force recalculation in Excel2003.
### Excel functions that return a Date and Time value
Any of the Date and Time functions that return a date value in Excel can
return either an Excel timestamp or a PHP timestamp or date object.
return either an Excel timestamp or a PHP timestamp or `DateTime` object.
It is possible for scripts to change the data type used for returning
date values by calling the
@ -117,11 +117,11 @@ method can be used to determine the current value of this setting:
$returnDateType = \PhpOffice\PhpSpreadsheet\Calculation\Functions::getReturnDateType();
```
The default is RETURNDATE\_PHP\_NUMERIC.
The default is `RETURNDATE_PHP_NUMERIC`.
#### PHP Timestamps
If RETURNDATE\_PHP\_NUMERIC is set for the Return Date Type, then any
If `RETURNDATE_PHP_NUMERIC` is set for the Return Date Type, then any
date value returned to the calling script by any access to the Date and
Time functions in Excel will be an integer value that represents the
number of seconds from the PHP/Unix base date. The PHP/Unix base date
@ -131,15 +131,15 @@ while a value of +3600 would be 01:00 hrs on 1st January 1970. This
gives PHP a date range of between 14th December 1901 and 19th January
2038.
#### PHP DateTime Objects
#### PHP `DateTime` Objects
If the Return Date Type is set for RETURNDATE\_PHP\_NUMERIC, then any
If the Return Date Type is set for `RETURNDATE_PHP_OBJECT`, then any
date value returned to the calling script by any access to the Date and
Time functions in Excel will be a PHP date/time object.
Time functions in Excel will be a PHP `DateTime` object.
#### Excel Timestamps
If RETURNDATE\_EXCEL is set for the Return Date Type, then the returned
If `RETURNDATE_EXCEL` is set for the Return Date Type, then the returned
date value by any access to the Date and Time functions in Excel will be
a floating point value that represents a number of days from the Excel
base date. The Excel base date is determined by which calendar Excel
@ -157,8 +157,8 @@ Excel date values by calling the
where the following constants can be used for `$baseDate`:
- \PhpOffice\PhpSpreadsheet\Shared\Date::CALENDAR\_WINDOWS\_1900
- \PhpOffice\PhpSpreadsheet\Shared\Date::CALENDAR\_MAC\_1904
- `\PhpOffice\PhpSpreadsheet\Shared\Date::CALENDAR_WINDOWS_1900`
- `\PhpOffice\PhpSpreadsheet\Shared\Date::CALENDAR_MAC_1904`
The method will return a Boolean True on success, False on failure (e.g.
if an invalid value is passed in).
@ -170,7 +170,7 @@ be used to determine the current value of this setting:
$baseDate = \PhpOffice\PhpSpreadsheet\Shared\Date::getExcelCalendar();
```
The default is CALENDAR\_WINDOWS\_1900.
The default is `CALENDAR_WINDOWS_1900`.
#### Functions that return a Date/Time Value
@ -186,15 +186,15 @@ The default is CALENDAR\_WINDOWS\_1900.
### Excel functions that accept Date and Time values as parameters
Date values passed in as parameters to a function can be an Excel
timestamp or a PHP timestamp; or date object; or a string containing a
timestamp or a PHP timestamp; or `DateTime` object; or a string containing a
date value (e.g. '1-Jan-2009'). PhpSpreadsheet will attempt to identify
their type based on the PHP datatype:
An integer numeric value will be treated as a PHP/Unix timestamp. A real
(floating point) numeric value will be treated as an Excel
date/timestamp. Any PHP DateTime object will be treated as a DateTime
date/timestamp. Any PHP `DateTime` object will be treated as a `DateTime`
object. Any string value (even one containing straight numeric data)
will be converted to a date/time object for validation as a date value
will be converted to a `DateTime` object for validation as a date value
based on the server locale settings, so passing through an ambiguous
value of '07/08/2008' will be treated as 7th August 2008 if your server
settings are UK, but as 8th July 2008 if your server settings are US.
@ -202,7 +202,7 @@ However, if you pass through a value such as '31/12/2008' that would be
considered an error by a US-based server, but which is not ambiguous,
then PhpSpreadsheet will attempt to correct this to 31st December 2008.
If the content of the string doesnt match any of the formats recognised
by the php date/time object implementation of `strtotime()` (which can
by the php `DateTime` object implementation of `strtotime()` (which can
handle a wider range of formats than the normal `strtotime()` function),
then the function will return a `#VALUE` error. However, Excel
recommends that you should always use date/timestamps for your date
@ -213,7 +213,7 @@ The same principle applies when data is being written to Excel. Cells
containing date actual values (rather than Excel functions that return a
date value) are always written as Excel dates, converting where
necessary. If a cell formatted as a date contains an integer or
date/time object value, then it is converted to an Excel value for
`DateTime` object value, then it is converted to an Excel value for
writing: if a cell formatted as a date contains a real value, then no
conversion is required. Note that string values are written as strings
rather than converted to Excel date timestamp values.
@ -243,7 +243,7 @@ number of other methods are available in the
\PhpOffice\PhpSpreadsheet\Shared\Date class that can help when working
with dates:
#### \PhpOffice\PhpSpreadsheet\Shared\Date::ExcelToPHP($excelDate)
#### \PhpOffice\PhpSpreadsheet\Shared\Date::excelToTimestamp($excelDate)
Converts a date/time from an Excel date timestamp to return a PHP
serialized date/timestamp.
@ -251,17 +251,17 @@ serialized date/timestamp.
Note that this method does not trap for Excel dates that fall outside of
the valid range for a PHP date timestamp.
#### \PhpOffice\PhpSpreadsheet\Shared\Date::ExcelToPHPObject($excelDate)
#### \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($excelDate)
Converts a date from an Excel date/timestamp to return a PHP DateTime
Converts a date from an Excel date/timestamp to return a PHP `DateTime`
object.
#### \PhpOffice\PhpSpreadsheet\Shared\Date::PHPToExcel($PHPDate)
Converts a PHP serialized date/timestamp or a PHP DateTime object to
Converts a PHP serialized date/timestamp or a PHP `DateTime` object to
return an Excel date timestamp.
#### \PhpOffice\PhpSpreadsheet\Shared\Date::FormattedPHPToExcel($year, $month, $day, $hours=0, $minutes=0, $seconds=0)
#### \PhpOffice\PhpSpreadsheet\Shared\Date::formattedPHPToExcel($year, $month, $day, $hours=0, $minutes=0, $seconds=0)
Takes year, month and day values (and optional hour, minute and second
values) and returns an Excel date timestamp value.
@ -979,7 +979,7 @@ Excel and in PHP.
#### DATE
The DATE function returns an Excel timestamp or a PHP timestamp or date
The DATE function returns an Excel timestamp or a PHP timestamp or `DateTime`
object representing the date that is referenced by the parameters.
##### Syntax
@ -1025,7 +1025,7 @@ February 27, 2008.
**mixed** A date/time stamp that corresponds to the given date.
This could be a PHP timestamp value (integer), a PHP date/time object,
This could be a PHP timestamp value (integer), a PHP `DateTime` object,
or an Excel timestamp value (real), depending on the value of
\PhpOffice\PhpSpreadsheet\Calculation\Functions::getReturnDateType().
@ -1093,12 +1093,12 @@ variety of different intervals, such number of years, months, or days.
**date1** First Date.
An Excel date value, PHP date timestamp, PHP date object, or a date
An Excel date value, PHP date timestamp, PHP `DateTime` object, or a date
represented as a string.
**date2** Second Date.
An Excel date value, PHP date timestamp, PHP date object, or a date
An Excel date value, PHP date timestamp, PHP `DateTime` object, or a date
represented as a string.
**unit** The interval type to use for the calculation
@ -1230,7 +1230,7 @@ A string, representing a date value.
**mixed** A date/time stamp that corresponds to the given date.
This could be a PHP timestamp value (integer), a PHP date/time object,
This could be a PHP timestamp value (integer), a PHP `DateTime` object,
or an Excel timestamp value (real), depending on the value of
\PhpOffice\PhpSpreadsheet\Calculation\Functions::getReturnDateType().
@ -1290,7 +1290,7 @@ $retVal = call_user_func_array(
##### Notes
DATEVALUE uses the php date/time object implementation of `strtotime()`
DATEVALUE uses the php `DateTime` object implementation of `strtotime()`
(which can handle a wider range of formats than the normal `strtotime()`
function), and it is also called for any date parameter passed to other
date functions (such as DATEDIF) when the parameter value is a string.
@ -1317,7 +1317,7 @@ integer ranging from 1 to 31.
**datetime** Date.
An Excel date value, PHP date timestamp, PHP date object, or a date
An Excel date value, PHP date timestamp, PHP `DateTime` object, or a date
represented as a string.
##### Return Value
@ -1371,12 +1371,12 @@ accounting systems.
**date1** First Date.
An Excel date value, PHP date timestamp, PHP date object, or a date
An Excel date value, PHP date timestamp, PHP `DateTime` object, or a date
represented as a string.
**date2** Second Date.
An Excel date value, PHP date timestamp, PHP date object, or a date
An Excel date value, PHP date timestamp, PHP `DateTime` object, or a date
represented as a string.
**method** A boolean flag (TRUE or FALSE)
@ -1453,7 +1453,7 @@ Excel `TRUE()` and `FALSE()` functions are used instead.
#### EDATE
The EDATE function returns an Excel timestamp or a PHP timestamp or date
The EDATE function returns an Excel timestamp or a PHP timestamp or `DateTime`
object representing the date that is the indicated number of months
before or after a specified date (the start\_date). Use EDATE to
calculate maturity dates or due dates that fall on the same day of the
@ -1467,7 +1467,7 @@ month as the date of issue.
**baseDate** Start Date.
An Excel date value, PHP date timestamp, PHP date object, or a date
An Excel date value, PHP date timestamp, PHP `DateTime` object, or a date
represented as a string.
**months** Number of months to add.
@ -1480,7 +1480,7 @@ value yields a past date.
**mixed** A date/time stamp that corresponds to the basedate + months.
This could be a PHP timestamp value (integer), a PHP date/time object,
This could be a PHP timestamp value (integer), a PHP `DateTime` object,
or an Excel timestamp value (real), depending on the value of
\PhpOffice\PhpSpreadsheet\Calculation\Functions::getReturnDateType().
@ -1526,7 +1526,7 @@ the Analysis ToolPak.
#### EOMONTH
The EOMONTH function returns an Excel timestamp or a PHP timestamp or
date object representing the date of the last day of the month that is
`DateTime` object representing the date of the last day of the month that is
the indicated number of months before or after a specified date (the
start\_date). Use EOMONTH to calculate maturity dates or due dates that
fall on the last day of the month.
@ -1539,7 +1539,7 @@ fall on the last day of the month.
**baseDate** Start Date.
An Excel date value, PHP date timestamp, PHP date object, or a date
An Excel date value, PHP date timestamp, PHP `DateTime` object, or a date
represented as a string.
**months** Number of months to add.
@ -1553,7 +1553,7 @@ value yields a past date.
**mixed** A date/time stamp that corresponds to the last day of basedate
+ months.
This could be a PHP timestamp value (integer), a PHP date/time object,
This could be a PHP timestamp value (integer), a PHP `DateTime` object,
or an Excel timestamp value (real), depending on the value of
\PhpOffice\PhpSpreadsheet\Calculation\Functions::getReturnDateType().
@ -1607,7 +1607,7 @@ an integer, ranging from 0 (12:00 A.M.) to 23 (11:00 P.M.).
**datetime** Time.
An Excel date/time value, PHP date timestamp, PHP date object, or a
An Excel date/time value, PHP date timestamp, PHP `DateTime` object, or a
date/time represented as a string.
##### Return Value
@ -1665,7 +1665,7 @@ given as an integer, ranging from 0 to 59.
**datetime** Time.
An Excel date/time value, PHP date timestamp, PHP date object, or a
An Excel date/time value, PHP date timestamp, PHP `DateTime` object, or a
date/time represented as a string.
##### Return Value
@ -1723,7 +1723,7 @@ integer ranging from 1 to 12.
**datetime** Date.
An Excel date value, PHP date timestamp, PHP date object, or a date
An Excel date value, PHP date timestamp, PHP `DateTime` object, or a date
represented as a string.
##### Return Value
@ -1779,12 +1779,12 @@ a specific term.
**startDate** Start Date of the period.
An Excel date value, PHP date timestamp, PHP date object, or a date
An Excel date value, PHP date timestamp, PHP `DateTime` object, or a date
represented as a string.
**endDate** End Date of the period.
An Excel date value, PHP date timestamp, PHP date object, or a date
An Excel date value, PHP date timestamp, PHP `DateTime` object, or a date
represented as a string.
**holidays** Optional array of Holiday dates.
@ -1831,7 +1831,7 @@ There are no parameters for the `NOW()` function.
**mixed** A date/time stamp that corresponds to the current date and
time.
This could be a PHP timestamp value (integer), a PHP date/time object,
This could be a PHP timestamp value (integer), a PHP `DateTime` object,
or an Excel timestamp value (real), depending on the value of
\PhpOffice\PhpSpreadsheet\Calculation\Functions::getReturnDateType().
@ -1862,7 +1862,7 @@ given as an integer, ranging from 0 to 59.
**datetime** Time.
An Excel date/time value, PHP date timestamp, PHP date object, or a
An Excel date/time value, PHP date timestamp, PHP `DateTime` object, or a
date/time represented as a string.
##### Return Value
@ -1934,7 +1934,7 @@ modified to return a value between 0 and 6.
**datetime** Date.
An Excel date value, PHP date timestamp, PHP date object, or a date
An Excel date value, PHP date timestamp, PHP `DateTime` object, or a date
represented as a string.
**method** An integer flag (values 0, 1 or 2)
@ -2012,7 +2012,7 @@ The YEAR function returns the year of a date.
**datetime** Date.
An Excel date value, PHP date timestamp, PHP date object, or a date
An Excel date value, PHP date timestamp, PHP `DateTime` object, or a date
represented as a string.
##### Return Value

View File

@ -192,3 +192,74 @@ $cell = $worksheet->setCellValue('A1', 'value', true);
// After
$cell = $worksheet->getCell('A1')->setValue('value');
```
## Standardized keys for styling
Array keys used for styling have been standardized for a more coherent experience.
It now uses the same wording and casing as the getter and setter:
```php
// Before
$style = [
'numberformat' => [
'code' => NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE,
],
'font' => [
'strike' => true,
'superScript' => true,
'subScript' => true,
],
'alignment' => [
'rotation' => 90,
'readorder' => Alignment::READORDER_RTL,
'wrap' => true,
],
'borders' => [
'diagonaldirection' => Borders::DIAGONAL_BOTH,
'allborders' => [
'style' => Border::BORDER_THIN,
],
],
'fill' => [
'type' => Fill::FILL_GRADIENT_LINEAR,
'startcolor' => [
'argb' => 'FFA0A0A0',
],
'endcolor' => [
'argb' => 'FFFFFFFF',
],
],
];
// After
$style = [
'numberFormat' => [
'formatCode' => NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE,
],
'font' => [
'strikethrough' => true,
'superscript' => true,
'subscript' => true,
],
'alignment' => [
'textRotation' => 90,
'readOrder' => Alignment::READORDER_RTL,
'wrapText' => true,
],
'borders' => [
'diagonalDirection' => Borders::DIAGONAL_BOTH,
'allBorders' => [
'borderStyle' => Border::BORDER_THIN,
],
],
'fill' => [
'fillType' => Fill::FILL_GRADIENT_LINEAR,
'startColor' => [
'argb' => 'FFA0A0A0',
],
'endColor' => [
'argb' => 'FFFFFFFF',
],
],
];
```

View File

@ -558,16 +558,16 @@ $styleArray = array(
),
'borders' => array(
'top' => array(
'style' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
),
),
'fill' => array(
'type' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_GRADIENT_LINEAR,
'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_GRADIENT_LINEAR,
'rotation' => 90,
'startcolor' => array(
'startColor' => array(
'argb' => 'FFA0A0A0',
),
'endcolor' => array(
'endColor' => array(
'argb' => 'FFFFFFFF',
),
),
@ -693,7 +693,7 @@ B2:G8.
$styleArray = array(
'borders' => array(
'outline' => array(
'style' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THICK,
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THICK,
'color' => array('argb' => 'FFFF0000'),
),
),
@ -721,7 +721,7 @@ operating on a single cell at a time:
Additional shortcut borders come in handy like in the example above.
These are the shortcut borders available:
- allborders
- allBorders
- outline
- inside
- vertical
@ -731,10 +731,10 @@ An overview of all border shortcuts can be seen in the following image:
![08-styling-border-options.png](./images/08-styling-border-options.png)
If you simultaneously set e.g. allborders and vertical, then we have
If you simultaneously set e.g. allBorders and vertical, then we have
"overlapping" borders, and one of the components has to win over the
other where there is border overlap. In PhpSpreadsheet, from weakest to
strongest borders, the list is as follows: allborders, outline/inside,
strongest borders, the list is as follows: allBorders, outline/inside,
vertical/horizontal, left/right/top/bottom/diagonal.
This border hierarchy can be utilized to achieve various effects in an
@ -757,17 +757,17 @@ fill | getFill()
font | getFont()
borders | getBorders()
alignment | getAlignment()
numberformat | getNumberFormat()
numberFormat | getNumberFormat()
protection | getProtection()
**\PhpOffice\PhpSpreadsheet\Style\Fill**
Array key | Maps to property
-----------|-------------------
type | setFillType()
fillType | setFillType()
rotation | setRotation()
startcolor | getStartColor()
endcolor | getEndColor()
startColor | getStartColor()
endColor | getEndColor()
color | getStartColor()
@ -779,17 +779,17 @@ name | setName()
bold | setBold()
italic | setItalic()
underline | setUnderline()
strike | setStrikethrough()
strikethrough | setStrikethrough()
color | getColor()
size | setSize()
superScript | setSuperScript()
subScript | setSubScript()
superscript | setSuperscript()
subscript | setSubscript()
**\PhpOffice\PhpSpreadsheet\Style\Borders**
Array key | Maps to property
------------------|-------------------
allborders | getLeft(); getRight(); getTop(); getBottom()
allBorders | getLeft(); getRight(); getTop(); getBottom()
left | getLeft()
right | getRight()
top | getTop()
@ -797,7 +797,7 @@ bottom | getBottom()
diagonal | getDiagonal()
vertical | getVertical()
horizontal | getHorizontal()
diagonaldirection | setDiagonalDirection()
diagonalDirection | setDiagonalDirection()
outline | setOutline()
**\PhpOffice\PhpSpreadsheet\Style\Border**
@ -813,8 +813,8 @@ Array key | Maps to property
------------|-------------------
horizontal | setHorizontal()
vertical | setVertical()
rotation | setTextRotation()
wrap | setWrapText()
textRotation| setTextRotation()
wrapText | setWrapText()
shrinkToFit | setShrinkToFit()
indent | setIndent()
@ -822,7 +822,7 @@ indent | setIndent()
Array key | Maps to property
----------|-------------------
code | setFormatCode()
formatCode | setFormatCode()
**\PhpOffice\PhpSpreadsheet\Style\Protection**
@ -910,15 +910,18 @@ practice...
## Setting security on a spreadsheet
Excel offers 3 levels of "protection": document security, sheet security
and cell security.
Excel offers 3 levels of "protection":
Document security allows you to set a password on a complete
- Document: allows you to set a password on a complete
spreadsheet, allowing changes to be made only when that password is
entered.Worksheet security offers other security options: you can
disallow inserting rows on a specific sheet, disallow sorting, ... Cell
security offers the option to lock/unlock a cell as well as show/hide
the internal formulaAn example on setting document security:
entered.
- Worksheet: offers other security options: you can
disallow inserting rows on a specific sheet, disallow sorting, ...
- Cell: offers the option to lock/unlock a cell as well as show/hide
the internal formula.
An example on setting document security:
``` php
$spreadsheet->getSecurity()->setLockWindows(true);

11
mkdocs.yml Normal file
View File

@ -0,0 +1,11 @@
site_name: PhpSpreadsheet Documentation
repo_url: https://github.com/PHPOffice/phpspreadsheet
edit_uri: edit/develop/docs/
theme: readthedocs
extra_css:
- extra/extra.css
extra_javascript:
- extra/extra.js

View File

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

View File

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

View File

@ -1,8 +1,13 @@
<?php
use PhpOffice\PhpSpreadsheet\Helper\Sample;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Settings;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require_once __DIR__ . '/../src/Bootstrap.php';
$helper = new \PhpOffice\PhpSpreadsheet\Helper\Sample();
$helper = new Sample();
if ($helper->isCli()) {
echo 'This example should only be run from a Web Browser' . PHP_EOL;
@ -12,11 +17,11 @@ if ($helper->isCli()) {
// Change these values to select the Rendering library that you wish to use
// and its directory location on your server
//$rendererName = \PhpOffice\PhpSpreadsheet\Settings::PDF_RENDERER_TCPDF;
$rendererName = \PhpOffice\PhpSpreadsheet\Settings::PDF_RENDERER_MPDF;
$rendererName = Settings::PDF_RENDERER_MPDF;
//$rendererName = \PhpOffice\PhpSpreadsheet\Settings::PDF_RENDERER_DOMPDF;
// Create new Spreadsheet object
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
$spreadsheet = new Spreadsheet();
// Set document properties
$spreadsheet->getProperties()->setCreator('Maarten Balliauw')
@ -46,13 +51,13 @@ $spreadsheet->getActiveSheet()->setShowGridLines(false);
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$spreadsheet->setActiveSheetIndex(0);
\PhpOffice\PhpSpreadsheet\Settings::setPdfRendererName($rendererName);
Settings::setPdfRendererName($rendererName);
// Redirect output to a clients web browser (PDF)
header('Content-Type: application/pdf');
header('Content-Disposition: attachment;filename="01simple.pdf"');
header('Cache-Control: max-age=0');
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Pdf');
$writer = IOFactory::createWriter($spreadsheet, 'Pdf');
$writer->save('php://output');
exit;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

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