Merge branch 'develop' of https://github.com/PHPOffice/PhpSpreadsheet into develop
This commit is contained in:
commit
d576855031
|
@ -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?
|
|
@ -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?
|
|
@ -6,14 +6,11 @@ php:
|
||||||
- 5.6
|
- 5.6
|
||||||
- 7.0
|
- 7.0
|
||||||
- 7.1
|
- 7.1
|
||||||
- hhvm
|
|
||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
- php: 7.0
|
- php: 7.0
|
||||||
env: COVERAGE=1
|
env: COVERAGE=1
|
||||||
allow_failures:
|
|
||||||
- php: hhvm
|
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
directories:
|
directories:
|
||||||
|
|
26
CHANGELOG.md
26
CHANGELOG.md
|
@ -1,4 +1,5 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
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
|
### 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
|
- Initial implementation of SUMIFS() function
|
||||||
- Additional codepages
|
- Additional codepages
|
||||||
- MemoryDrawing not working in HTML writer [#808](https://github.com/PHPOffice/PHPExcel/issues/808)
|
- 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)
|
- 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
|
### Changed
|
||||||
|
|
||||||
- Start following [SemVer](http://semver.org) properly.
|
- Start following [SemVer](http://semver.org) properly.
|
||||||
|
|
||||||
### Bugfixes
|
### Fixed
|
||||||
|
|
||||||
- Fix to getCell() method when cell reference includes a worksheet reference - @MarkBaker
|
- 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)
|
- 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)
|
- 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
|
### 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`
|
- Introduction of namespaces for all classes, eg: `PHPExcel_Calculation_Functions` becomes `PhpOffice\PhpSpreadsheet\Calculation\Functions`
|
||||||
- Some classes were renamed for clarity and/or consistency:
|
- 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_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 `PHPExcel_Settings::setPdfRenderer()` and `PHPExcel_Settings::setPdfRenderer()`. Composer should be used to autoload PDF libs.
|
||||||
|
- Dropped support for HHVM
|
||||||
|
|
||||||
## Previous versions of PHPExcel
|
## Previous versions of PHPExcel
|
||||||
|
|
||||||
|
|
|
@ -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")
|
35
README.md
35
README.md
|
@ -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.
|
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|
|
Read more about it, including install instructions, in the official documentation, either at the online version:
|
||||||
|--------------------------------------------|:-----:|:-----:|
|
|
||||||
|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)| | ✓ |
|
|
||||||
|
|
||||||
## Requirements
|
https://phpspreadsheet.readthedocs.io
|
||||||
|
|
||||||
* PHP version 5.6 or higher
|
Or directly in this repository in the folder `docs/`.
|
||||||
* PHP extension php_zip enabled
|
|
||||||
* PHP extension php_xml enabled
|
|
||||||
* PHP extension php_gd2 enabled (optional, but required for exact column width autocalculation)
|
|
||||||
|
|
||||||
## 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 ?
|
## PHPExcel vs PhpSpreadsheet ?
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#!/usr/bin/env php
|
#!/usr/bin/env php
|
||||||
<?php
|
<?php
|
||||||
|
use PhpOffice\PhpSpreadsheet\Helper\Migrator;
|
||||||
|
|
||||||
require_once __DIR__ . '/../src/Bootstrap.php';
|
require_once __DIR__ . '/../src/Bootstrap.php';
|
||||||
|
|
||||||
$migrator = new \PhpOffice\PhpSpreadsheet\Helper\Migrator();
|
$migrator = new Migrator();
|
||||||
$migrator->migrate();
|
$migrator->migrate();
|
||||||
|
|
|
@ -1,79 +1,78 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
|
|
||||||
date_default_timezone_set('Europe/London');
|
date_default_timezone_set('Europe/London');
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
|
||||||
<title>PhpSpreadsheet Calculation Examples</title>
|
<title>PhpSpreadsheet Calculation Examples</title>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h1>DAVERAGE</h1>
|
<h1>DAVERAGE</h1>
|
||||||
<h2>Returns the average of selected database entries.</h2>
|
<h2>Returns the average of selected database entries.</h2>
|
||||||
<?php
|
<?php
|
||||||
|
require_once __DIR__ . '/../../../../src/Bootstrap.php';
|
||||||
|
|
||||||
require_once __DIR__ . '/../../../../src/Bootstrap.php';
|
// Create new PhpSpreadsheet object
|
||||||
|
$spreadsheet = new Spreadsheet();
|
||||||
|
$worksheet = $spreadsheet->getActiveSheet();
|
||||||
|
|
||||||
// Create new PhpSpreadsheet object
|
// Add some data
|
||||||
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'],
|
||||||
$worksheet = $spreadsheet->getActiveSheet();
|
['Apple', 18, 20, 14, 105.00],
|
||||||
|
['Pear', 12, 12, 10, 96.00],
|
||||||
|
['Cherry', 13, 14, 9, 105.00],
|
||||||
|
['Apple', 14, 15, 10, 75.00],
|
||||||
|
['Pear', 9, 8, 8, 76.80],
|
||||||
|
['Apple', 8, 9, 6, 45.00],
|
||||||
|
];
|
||||||
|
$criteria = [['Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height'],
|
||||||
|
['="=Apple"', '>10', null, null, null, '<16'],
|
||||||
|
['="=Pear"', null, null, null, null, null],
|
||||||
|
];
|
||||||
|
|
||||||
// Add some data
|
$worksheet->fromArray($criteria, null, 'A1');
|
||||||
$database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'],
|
$worksheet->fromArray($database, null, 'A4');
|
||||||
['Apple', 18, 20, 14, 105.00],
|
|
||||||
['Pear', 12, 12, 10, 96.00],
|
|
||||||
['Cherry', 13, 14, 9, 105.00],
|
|
||||||
['Apple', 14, 15, 10, 75.00],
|
|
||||||
['Pear', 9, 8, 8, 76.80],
|
|
||||||
['Apple', 8, 9, 6, 45.00],
|
|
||||||
];
|
|
||||||
$criteria = [['Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height'],
|
|
||||||
['="=Apple"', '>10', null, null, null, '<16'],
|
|
||||||
['="=Pear"', null, null, null, null, null],
|
|
||||||
];
|
|
||||||
|
|
||||||
$worksheet->fromArray($criteria, null, 'A1');
|
$worksheet->setCellValue('A12', 'The Average yield of Apple trees over 10\' in height');
|
||||||
$worksheet->fromArray($database, null, 'A4');
|
$worksheet->setCellValue('B12', '=DAVERAGE(A4:E10,"Yield",A1:B2)');
|
||||||
|
|
||||||
$worksheet->setCellValue('A12', 'The Average yield of Apple trees over 10\' in height');
|
$worksheet->setCellValue('A13', 'The Average age of all Apple and Pear trees in the orchard');
|
||||||
$worksheet->setCellValue('B12', '=DAVERAGE(A4:E10,"Yield",A1:B2)');
|
$worksheet->setCellValue('B13', '=DAVERAGE(A4:E10,3,A1:A3)');
|
||||||
|
|
||||||
$worksheet->setCellValue('A13', 'The Average age of all Apple and Pear trees in the orchard');
|
echo '<hr />';
|
||||||
$worksheet->setCellValue('B13', '=DAVERAGE(A4:E10,3,A1:A3)');
|
|
||||||
|
|
||||||
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);
|
echo '<hr />';
|
||||||
var_dump($databaseData);
|
|
||||||
|
|
||||||
echo '<hr />';
|
// Test the formulae
|
||||||
|
echo '<h4>Criteria</h4>';
|
||||||
|
|
||||||
// Test the formulae
|
$criteriaData = $worksheet->rangeToArray('A1:B2', null, true, true, true);
|
||||||
echo '<h4>Criteria</h4>';
|
var_dump($criteriaData);
|
||||||
|
|
||||||
$criteriaData = $worksheet->rangeToArray('A1:B2', null, true, true, true);
|
echo $worksheet->getCell('A12')->getValue() . '<br />';
|
||||||
var_dump($criteriaData);
|
echo 'DAVERAGE() Result is ' . $worksheet->getCell('B12')->getCalculatedValue() . '<br /><br />';
|
||||||
|
|
||||||
echo $worksheet->getCell('A12')->getValue() . '<br />';
|
echo '<h4>Criteria</h4>';
|
||||||
echo 'DAVERAGE() Result is ' . $worksheet->getCell('B12')->getCalculatedValue() . '<br /><br />';
|
|
||||||
|
|
||||||
echo '<h4>Criteria</h4>';
|
$criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true);
|
||||||
|
var_dump($criteriaData);
|
||||||
|
|
||||||
$criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true);
|
echo $worksheet->getCell('A13')->getValue() . '<br />';
|
||||||
var_dump($criteriaData);
|
echo 'DAVERAGE() Result is ' . $worksheet->getCell('B13')->getCalculatedValue();
|
||||||
|
?>
|
||||||
echo $worksheet->getCell('A13')->getValue() . '<br />';
|
<body>
|
||||||
echo 'DAVERAGE() Result is ' . $worksheet->getCell('B13')->getCalculatedValue();
|
|
||||||
|
|
||||||
?>
|
|
||||||
<body>
|
|
||||||
</html>
|
</html>
|
|
@ -1,79 +1,78 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
|
|
||||||
date_default_timezone_set('Europe/London');
|
date_default_timezone_set('Europe/London');
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
|
||||||
<title>PhpSpreadsheet Calculation Examples</title>
|
<title>PhpSpreadsheet Calculation Examples</title>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h1>DCOUNT</h1>
|
<h1>DCOUNT</h1>
|
||||||
<h2>Counts the cells that contain numbers in a database.</h2>
|
<h2>Counts the cells that contain numbers in a database.</h2>
|
||||||
<?php
|
<?php
|
||||||
|
require_once __DIR__ . '/../../../../src/Bootstrap.php';
|
||||||
|
|
||||||
require_once __DIR__ . '/../../../../src/Bootstrap.php';
|
// Create new PhpSpreadsheet object
|
||||||
|
$spreadsheet = new Spreadsheet();
|
||||||
|
$worksheet = $spreadsheet->getActiveSheet();
|
||||||
|
|
||||||
// Create new PhpSpreadsheet object
|
// Add some data
|
||||||
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'],
|
||||||
$worksheet = $spreadsheet->getActiveSheet();
|
['Apple', 18, 20, 14, 105.00],
|
||||||
|
['Pear', 12, 12, 10, 96.00],
|
||||||
|
['Cherry', 13, 14, 9, 105.00],
|
||||||
|
['Apple', 14, 15, 10, 75.00],
|
||||||
|
['Pear', 9, 8, 8, 76.80],
|
||||||
|
['Apple', 8, 9, 6, 45.00],
|
||||||
|
];
|
||||||
|
$criteria = [['Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height'],
|
||||||
|
['="=Apple"', '>10', null, null, null, '<16'],
|
||||||
|
['="=Pear"', null, null, null, null, null],
|
||||||
|
];
|
||||||
|
|
||||||
// Add some data
|
$worksheet->fromArray($criteria, null, 'A1');
|
||||||
$database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'],
|
$worksheet->fromArray($database, null, 'A4');
|
||||||
['Apple', 18, 20, 14, 105.00],
|
|
||||||
['Pear', 12, 12, 10, 96.00],
|
|
||||||
['Cherry', 13, 14, 9, 105.00],
|
|
||||||
['Apple', 14, 15, 10, 75.00],
|
|
||||||
['Pear', 9, 8, 8, 76.80],
|
|
||||||
['Apple', 8, 9, 6, 45.00],
|
|
||||||
];
|
|
||||||
$criteria = [['Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height'],
|
|
||||||
['="=Apple"', '>10', null, null, null, '<16'],
|
|
||||||
['="=Pear"', null, null, null, null, null],
|
|
||||||
];
|
|
||||||
|
|
||||||
$worksheet->fromArray($criteria, null, 'A1');
|
$worksheet->setCellValue('A12', 'The Number of Apple trees over 10\' in height');
|
||||||
$worksheet->fromArray($database, null, 'A4');
|
$worksheet->setCellValue('B12', '=DCOUNT(A4:E10,"Yield",A1:B2)');
|
||||||
|
|
||||||
$worksheet->setCellValue('A12', 'The Number of Apple trees over 10\' in height');
|
$worksheet->setCellValue('A13', 'The Number of Apple and Pear trees in the orchard');
|
||||||
$worksheet->setCellValue('B12', '=DCOUNT(A4:E10,"Yield",A1:B2)');
|
$worksheet->setCellValue('B13', '=DCOUNT(A4:E10,3,A1:A3)');
|
||||||
|
|
||||||
$worksheet->setCellValue('A13', 'The Number of Apple and Pear trees in the orchard');
|
echo '<hr />';
|
||||||
$worksheet->setCellValue('B13', '=DCOUNT(A4:E10,3,A1:A3)');
|
|
||||||
|
|
||||||
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);
|
echo '<hr />';
|
||||||
var_dump($databaseData);
|
|
||||||
|
|
||||||
echo '<hr />';
|
// Test the formulae
|
||||||
|
echo '<h4>Criteria</h4>';
|
||||||
|
|
||||||
// Test the formulae
|
$criteriaData = $worksheet->rangeToArray('A1:B2', null, true, true, true);
|
||||||
echo '<h4>Criteria</h4>';
|
var_dump($criteriaData);
|
||||||
|
|
||||||
$criteriaData = $worksheet->rangeToArray('A1:B2', null, true, true, true);
|
echo $worksheet->getCell('A12')->getValue() . '<br />';
|
||||||
var_dump($criteriaData);
|
echo 'DCOUNT() Result is ' . $worksheet->getCell('B12')->getCalculatedValue() . '<br /><br />';
|
||||||
|
|
||||||
echo $worksheet->getCell('A12')->getValue() . '<br />';
|
echo '<h4>Criteria</h4>';
|
||||||
echo 'DCOUNT() Result is ' . $worksheet->getCell('B12')->getCalculatedValue() . '<br /><br />';
|
|
||||||
|
|
||||||
echo '<h4>Criteria</h4>';
|
$criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true);
|
||||||
|
var_dump($criteriaData);
|
||||||
|
|
||||||
$criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true);
|
echo $worksheet->getCell('A13')->getValue() . '<br />';
|
||||||
var_dump($criteriaData);
|
echo 'DCOUNT() Result is ' . $worksheet->getCell('B13')->getCalculatedValue();
|
||||||
|
?>
|
||||||
echo $worksheet->getCell('A13')->getValue() . '<br />';
|
<body>
|
||||||
echo 'DCOUNT() Result is ' . $worksheet->getCell('B13')->getCalculatedValue();
|
|
||||||
|
|
||||||
?>
|
|
||||||
<body>
|
|
||||||
</html>
|
</html>
|
|
@ -1,75 +1,74 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
|
|
||||||
date_default_timezone_set('Europe/London');
|
date_default_timezone_set('Europe/London');
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
|
||||||
<title>PhpSpreadsheet Calculation Examples</title>
|
<title>PhpSpreadsheet Calculation Examples</title>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h1>DGET</h1>
|
<h1>DGET</h1>
|
||||||
<h2>Extracts a single value from a column of a list or database that matches conditions that you specify.</h2>
|
<h2>Extracts a single value from a column of a list or database that matches conditions that you specify.</h2>
|
||||||
<?php
|
<?php
|
||||||
|
require_once __DIR__ . '/../../../../src/Bootstrap.php';
|
||||||
|
|
||||||
require_once __DIR__ . '/../../../../src/Bootstrap.php';
|
// Create new PhpSpreadsheet object
|
||||||
|
$spreadsheet = new Spreadsheet();
|
||||||
|
$worksheet = $spreadsheet->getActiveSheet();
|
||||||
|
|
||||||
// Create new PhpSpreadsheet object
|
// Add some data
|
||||||
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'],
|
||||||
$worksheet = $spreadsheet->getActiveSheet();
|
['Apple', 18, 20, 14, 105.00],
|
||||||
|
['Pear', 12, 12, 10, 96.00],
|
||||||
|
['Cherry', 13, 14, 9, 105.00],
|
||||||
|
['Apple', 14, 15, 10, 75.00],
|
||||||
|
['Pear', 9, 8, 8, 76.80],
|
||||||
|
['Apple', 8, 9, 6, 45.00],
|
||||||
|
];
|
||||||
|
$criteria = [['Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height'],
|
||||||
|
['="=Apple"', '>10', null, null, null, '<16'],
|
||||||
|
['="=Pear"', null, null, null, null, null],
|
||||||
|
];
|
||||||
|
|
||||||
// Add some data
|
$worksheet->fromArray($criteria, null, 'A1');
|
||||||
$database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'],
|
$worksheet->fromArray($database, null, 'A4');
|
||||||
['Apple', 18, 20, 14, 105.00],
|
|
||||||
['Pear', 12, 12, 10, 96.00],
|
|
||||||
['Cherry', 13, 14, 9, 105.00],
|
|
||||||
['Apple', 14, 15, 10, 75.00],
|
|
||||||
['Pear', 9, 8, 8, 76.80],
|
|
||||||
['Apple', 8, 9, 6, 45.00],
|
|
||||||
];
|
|
||||||
$criteria = [['Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height'],
|
|
||||||
['="=Apple"', '>10', null, null, null, '<16'],
|
|
||||||
['="=Pear"', null, null, null, null, null],
|
|
||||||
];
|
|
||||||
|
|
||||||
$worksheet->fromArray($criteria, null, 'A1');
|
$worksheet->setCellValue('A12', 'The height of the Apple tree between 10\' and 16\' tall');
|
||||||
$worksheet->fromArray($database, null, 'A4');
|
$worksheet->setCellValue('B12', '=DGET(A4:E10,"Height",A1:F2)');
|
||||||
|
|
||||||
$worksheet->setCellValue('A12', 'The height of the Apple tree between 10\' and 16\' tall');
|
echo '<hr />';
|
||||||
$worksheet->setCellValue('B12', '=DGET(A4:E10,"Height",A1:F2)');
|
|
||||||
|
|
||||||
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);
|
echo '<hr />';
|
||||||
var_dump($databaseData);
|
|
||||||
|
|
||||||
echo '<hr />';
|
// Test the formulae
|
||||||
|
echo '<h4>Criteria</h4>';
|
||||||
|
|
||||||
// Test the formulae
|
echo 'ALL' . '<br /><br />';
|
||||||
echo '<h4>Criteria</h4>';
|
|
||||||
|
|
||||||
echo 'ALL' . '<br /><br />';
|
echo $worksheet->getCell('A12')->getValue() . '<br />';
|
||||||
|
echo 'DMAX() Result is ' . $worksheet->getCell('B12')->getCalculatedValue() . '<br /><br />';
|
||||||
|
|
||||||
echo $worksheet->getCell('A12')->getValue() . '<br />';
|
echo '<h4>Criteria</h4>';
|
||||||
echo 'DMAX() Result is ' . $worksheet->getCell('B12')->getCalculatedValue() . '<br /><br />';
|
|
||||||
|
|
||||||
echo '<h4>Criteria</h4>';
|
$criteriaData = $worksheet->rangeToArray('A1:A2', null, true, true, true);
|
||||||
|
var_dump($criteriaData);
|
||||||
|
|
||||||
$criteriaData = $worksheet->rangeToArray('A1:A2', null, true, true, true);
|
echo $worksheet->getCell('A13')->getValue() . '<br />';
|
||||||
var_dump($criteriaData);
|
echo 'DMAX() Result is ' . $worksheet->getCell('B13')->getCalculatedValue();
|
||||||
|
?>
|
||||||
echo $worksheet->getCell('A13')->getValue() . '<br />';
|
<body>
|
||||||
echo 'DMAX() Result is ' . $worksheet->getCell('B13')->getCalculatedValue();
|
|
||||||
|
|
||||||
?>
|
|
||||||
<body>
|
|
||||||
</html>
|
</html>
|
|
@ -1,78 +1,77 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
|
|
||||||
date_default_timezone_set('Europe/London');
|
date_default_timezone_set('Europe/London');
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
|
||||||
<title>PhpSpreadsheet Calculation Examples</title>
|
<title>PhpSpreadsheet Calculation Examples</title>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h1>DMAX</h1>
|
<h1>DMAX</h1>
|
||||||
<h2>Returns the maximum value from selected database entries.</h2>
|
<h2>Returns the maximum value from selected database entries.</h2>
|
||||||
<?php
|
<?php
|
||||||
|
require_once __DIR__ . '/../../../../src/Bootstrap.php';
|
||||||
|
|
||||||
require_once __DIR__ . '/../../../../src/Bootstrap.php';
|
// Create new PhpSpreadsheet object
|
||||||
|
$spreadsheet = new Spreadsheet();
|
||||||
|
$worksheet = $spreadsheet->getActiveSheet();
|
||||||
|
|
||||||
// Create new PhpSpreadsheet object
|
// Add some data
|
||||||
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'],
|
||||||
$worksheet = $spreadsheet->getActiveSheet();
|
['Apple', 18, 20, 14, 105.00],
|
||||||
|
['Pear', 12, 12, 10, 96.00],
|
||||||
|
['Cherry', 13, 14, 9, 105.00],
|
||||||
|
['Apple', 14, 15, 10, 75.00],
|
||||||
|
['Pear', 9, 8, 8, 76.80],
|
||||||
|
['Apple', 8, 9, 6, 45.00],
|
||||||
|
];
|
||||||
|
$criteria = [['Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height'],
|
||||||
|
['="=Apple"', '>10', null, null, null, '<16'],
|
||||||
|
['="=Pear"', null, null, null, null, null],
|
||||||
|
];
|
||||||
|
|
||||||
// Add some data
|
$worksheet->fromArray($criteria, null, 'A1');
|
||||||
$database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'],
|
$worksheet->fromArray($database, null, 'A4');
|
||||||
['Apple', 18, 20, 14, 105.00],
|
|
||||||
['Pear', 12, 12, 10, 96.00],
|
|
||||||
['Cherry', 13, 14, 9, 105.00],
|
|
||||||
['Apple', 14, 15, 10, 75.00],
|
|
||||||
['Pear', 9, 8, 8, 76.80],
|
|
||||||
['Apple', 8, 9, 6, 45.00],
|
|
||||||
];
|
|
||||||
$criteria = [['Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height'],
|
|
||||||
['="=Apple"', '>10', null, null, null, '<16'],
|
|
||||||
['="=Pear"', null, null, null, null, null],
|
|
||||||
];
|
|
||||||
|
|
||||||
$worksheet->fromArray($criteria, null, 'A1');
|
$worksheet->setCellValue('A12', 'The tallest tree in the orchard');
|
||||||
$worksheet->fromArray($database, null, 'A4');
|
$worksheet->setCellValue('B12', '=DMAX(A4:E10,"Height",A4:E10)');
|
||||||
|
|
||||||
$worksheet->setCellValue('A12', 'The tallest tree in the orchard');
|
$worksheet->setCellValue('A13', 'The Oldest apple tree in the orchard');
|
||||||
$worksheet->setCellValue('B12', '=DMAX(A4:E10,"Height",A4:E10)');
|
$worksheet->setCellValue('B13', '=DMAX(A4:E10,3,A1:A2)');
|
||||||
|
|
||||||
$worksheet->setCellValue('A13', 'The Oldest apple tree in the orchard');
|
echo '<hr />';
|
||||||
$worksheet->setCellValue('B13', '=DMAX(A4:E10,3,A1:A2)');
|
|
||||||
|
|
||||||
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);
|
echo '<hr />';
|
||||||
var_dump($databaseData);
|
|
||||||
|
|
||||||
echo '<hr />';
|
// Test the formulae
|
||||||
|
echo '<h4>Criteria</h4>';
|
||||||
|
|
||||||
// Test the formulae
|
echo 'ALL' . '<br /><br />';
|
||||||
echo '<h4>Criteria</h4>';
|
|
||||||
|
|
||||||
echo 'ALL' . '<br /><br />';
|
echo $worksheet->getCell('A12')->getValue() . '<br />';
|
||||||
|
echo 'DMAX() Result is ' . $worksheet->getCell('B12')->getCalculatedValue() . '<br /><br />';
|
||||||
|
|
||||||
echo $worksheet->getCell('A12')->getValue() . '<br />';
|
echo '<h4>Criteria</h4>';
|
||||||
echo 'DMAX() Result is ' . $worksheet->getCell('B12')->getCalculatedValue() . '<br /><br />';
|
|
||||||
|
|
||||||
echo '<h4>Criteria</h4>';
|
$criteriaData = $worksheet->rangeToArray('A1:A2', null, true, true, true);
|
||||||
|
var_dump($criteriaData);
|
||||||
|
|
||||||
$criteriaData = $worksheet->rangeToArray('A1:A2', null, true, true, true);
|
echo $worksheet->getCell('A13')->getValue() . '<br />';
|
||||||
var_dump($criteriaData);
|
echo 'DMAX() Result is ' . $worksheet->getCell('B13')->getCalculatedValue();
|
||||||
|
?>
|
||||||
echo $worksheet->getCell('A13')->getValue() . '<br />';
|
<body>
|
||||||
echo 'DMAX() Result is ' . $worksheet->getCell('B13')->getCalculatedValue();
|
|
||||||
|
|
||||||
?>
|
|
||||||
<body>
|
|
||||||
</html>
|
</html>
|
|
@ -1,78 +1,77 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
|
|
||||||
date_default_timezone_set('Europe/London');
|
date_default_timezone_set('Europe/London');
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
|
||||||
<title>PhpSpreadsheet Calculation Examples</title>
|
<title>PhpSpreadsheet Calculation Examples</title>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h1>DMIN</h1>
|
<h1>DMIN</h1>
|
||||||
<h2>Returns the minimum value from selected database entries.</h2>
|
<h2>Returns the minimum value from selected database entries.</h2>
|
||||||
<?php
|
<?php
|
||||||
|
require_once __DIR__ . '/../../../../src/Bootstrap.php';
|
||||||
|
|
||||||
require_once __DIR__ . '/../../../../src/Bootstrap.php';
|
// Create new PhpSpreadsheet object
|
||||||
|
$spreadsheet = new Spreadsheet();
|
||||||
|
$worksheet = $spreadsheet->getActiveSheet();
|
||||||
|
|
||||||
// Create new PhpSpreadsheet object
|
// Add some data
|
||||||
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'],
|
||||||
$worksheet = $spreadsheet->getActiveSheet();
|
['Apple', 18, 20, 14, 105.00],
|
||||||
|
['Pear', 12, 12, 10, 96.00],
|
||||||
|
['Cherry', 13, 14, 9, 105.00],
|
||||||
|
['Apple', 14, 15, 10, 75.00],
|
||||||
|
['Pear', 9, 8, 8, 76.80],
|
||||||
|
['Apple', 8, 9, 6, 45.00],
|
||||||
|
];
|
||||||
|
$criteria = [['Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height'],
|
||||||
|
['="=Apple"', '>10', null, null, null, '<16'],
|
||||||
|
['="=Pear"', null, null, null, null, null],
|
||||||
|
];
|
||||||
|
|
||||||
// Add some data
|
$worksheet->fromArray($criteria, null, 'A1');
|
||||||
$database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'],
|
$worksheet->fromArray($database, null, 'A4');
|
||||||
['Apple', 18, 20, 14, 105.00],
|
|
||||||
['Pear', 12, 12, 10, 96.00],
|
|
||||||
['Cherry', 13, 14, 9, 105.00],
|
|
||||||
['Apple', 14, 15, 10, 75.00],
|
|
||||||
['Pear', 9, 8, 8, 76.80],
|
|
||||||
['Apple', 8, 9, 6, 45.00],
|
|
||||||
];
|
|
||||||
$criteria = [['Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height'],
|
|
||||||
['="=Apple"', '>10', null, null, null, '<16'],
|
|
||||||
['="=Pear"', null, null, null, null, null],
|
|
||||||
];
|
|
||||||
|
|
||||||
$worksheet->fromArray($criteria, null, 'A1');
|
$worksheet->setCellValue('A12', 'The shortest tree in the orchard');
|
||||||
$worksheet->fromArray($database, null, 'A4');
|
$worksheet->setCellValue('B12', '=DMIN(A4:E10,"Height",A4:E10)');
|
||||||
|
|
||||||
$worksheet->setCellValue('A12', 'The shortest tree in the orchard');
|
$worksheet->setCellValue('A13', 'The Youngest apple tree in the orchard');
|
||||||
$worksheet->setCellValue('B12', '=DMIN(A4:E10,"Height",A4:E10)');
|
$worksheet->setCellValue('B13', '=DMIN(A4:E10,3,A1:A2)');
|
||||||
|
|
||||||
$worksheet->setCellValue('A13', 'The Youngest apple tree in the orchard');
|
echo '<hr />';
|
||||||
$worksheet->setCellValue('B13', '=DMIN(A4:E10,3,A1:A2)');
|
|
||||||
|
|
||||||
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);
|
echo '<hr />';
|
||||||
var_dump($databaseData);
|
|
||||||
|
|
||||||
echo '<hr />';
|
// Test the formulae
|
||||||
|
echo '<h4>Criteria</h4>';
|
||||||
|
|
||||||
// Test the formulae
|
echo 'ALL' . '<br /><br />';
|
||||||
echo '<h4>Criteria</h4>';
|
|
||||||
|
|
||||||
echo 'ALL' . '<br /><br />';
|
echo $worksheet->getCell('A12')->getValue() . '<br />';
|
||||||
|
echo 'DMIN() Result is ' . $worksheet->getCell('B12')->getCalculatedValue() . '<br /><br />';
|
||||||
|
|
||||||
echo $worksheet->getCell('A12')->getValue() . '<br />';
|
echo '<h4>Criteria</h4>';
|
||||||
echo 'DMIN() Result is ' . $worksheet->getCell('B12')->getCalculatedValue() . '<br /><br />';
|
|
||||||
|
|
||||||
echo '<h4>Criteria</h4>';
|
$criteriaData = $worksheet->rangeToArray('A1:A2', null, true, true, true);
|
||||||
|
var_dump($criteriaData);
|
||||||
|
|
||||||
$criteriaData = $worksheet->rangeToArray('A1:A2', null, true, true, true);
|
echo $worksheet->getCell('A13')->getValue() . '<br />';
|
||||||
var_dump($criteriaData);
|
echo 'DMIN() Result is ' . $worksheet->getCell('B13')->getCalculatedValue();
|
||||||
|
?>
|
||||||
echo $worksheet->getCell('A13')->getValue() . '<br />';
|
<body>
|
||||||
echo 'DMIN() Result is ' . $worksheet->getCell('B13')->getCalculatedValue();
|
|
||||||
|
|
||||||
?>
|
|
||||||
<body>
|
|
||||||
</html>
|
</html>
|
|
@ -1,75 +1,74 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
|
|
||||||
date_default_timezone_set('Europe/London');
|
date_default_timezone_set('Europe/London');
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
|
||||||
<title>PhpSpreadsheet Calculation Examples</title>
|
<title>PhpSpreadsheet Calculation Examples</title>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h1>DPRODUCT</h1>
|
<h1>DPRODUCT</h1>
|
||||||
<h2>Multiplies the values in a column of a list or database that match conditions that you specify.</h2>
|
<h2>Multiplies the values in a column of a list or database that match conditions that you specify.</h2>
|
||||||
<?php
|
<?php
|
||||||
|
require_once __DIR__ . '/../../../../src/Bootstrap.php';
|
||||||
|
|
||||||
require_once __DIR__ . '/../../../../src/Bootstrap.php';
|
// Create new PhpSpreadsheet object
|
||||||
|
$spreadsheet = new Spreadsheet();
|
||||||
|
$worksheet = $spreadsheet->getActiveSheet();
|
||||||
|
|
||||||
// Create new PhpSpreadsheet object
|
// Add some data
|
||||||
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'],
|
||||||
$worksheet = $spreadsheet->getActiveSheet();
|
['Apple', 18, 20, 14, 105.00],
|
||||||
|
['Pear', 12, 12, 10, 96.00],
|
||||||
|
['Cherry', 13, 14, 9, 105.00],
|
||||||
|
['Apple', 14, 15, 10, 75.00],
|
||||||
|
['Pear', 9, 8, 8, 76.80],
|
||||||
|
['Apple', 8, 9, 6, 45.00],
|
||||||
|
];
|
||||||
|
$criteria = [['Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height'],
|
||||||
|
['="=Apple"', '>10', null, null, null, '<16'],
|
||||||
|
['="=Pear"', null, null, null, null, null],
|
||||||
|
];
|
||||||
|
|
||||||
// Add some data
|
$worksheet->fromArray($criteria, null, 'A1');
|
||||||
$database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'],
|
$worksheet->fromArray($database, null, 'A4');
|
||||||
['Apple', 18, 20, 14, 105.00],
|
|
||||||
['Pear', 12, 12, 10, 96.00],
|
|
||||||
['Cherry', 13, 14, 9, 105.00],
|
|
||||||
['Apple', 14, 15, 10, 75.00],
|
|
||||||
['Pear', 9, 8, 8, 76.80],
|
|
||||||
['Apple', 8, 9, 6, 45.00],
|
|
||||||
];
|
|
||||||
$criteria = [['Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height'],
|
|
||||||
['="=Apple"', '>10', null, null, null, '<16'],
|
|
||||||
['="=Pear"', null, null, null, null, null],
|
|
||||||
];
|
|
||||||
|
|
||||||
$worksheet->fromArray($criteria, null, 'A1');
|
$worksheet->setCellValue('A12', 'The product of the yields of all Apple trees over 10\' in the orchard');
|
||||||
$worksheet->fromArray($database, null, 'A4');
|
$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');
|
echo '<hr />';
|
||||||
$worksheet->setCellValue('B12', '=DPRODUCT(A4:E10,"Yield",A1:B2)');
|
|
||||||
|
|
||||||
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);
|
echo '<hr />';
|
||||||
var_dump($databaseData);
|
|
||||||
|
|
||||||
echo '<hr />';
|
// Test the formulae
|
||||||
|
echo '<h4>Criteria</h4>';
|
||||||
|
|
||||||
// Test the formulae
|
echo 'ALL' . '<br /><br />';
|
||||||
echo '<h4>Criteria</h4>';
|
|
||||||
|
|
||||||
echo 'ALL' . '<br /><br />';
|
echo $worksheet->getCell('A12')->getValue() . '<br />';
|
||||||
|
echo 'DMAX() Result is ' . $worksheet->getCell('B12')->getCalculatedValue() . '<br /><br />';
|
||||||
|
|
||||||
echo $worksheet->getCell('A12')->getValue() . '<br />';
|
echo '<h4>Criteria</h4>';
|
||||||
echo 'DMAX() Result is ' . $worksheet->getCell('B12')->getCalculatedValue() . '<br /><br />';
|
|
||||||
|
|
||||||
echo '<h4>Criteria</h4>';
|
$criteriaData = $worksheet->rangeToArray('A1:A2', null, true, true, true);
|
||||||
|
var_dump($criteriaData);
|
||||||
|
|
||||||
$criteriaData = $worksheet->rangeToArray('A1:A2', null, true, true, true);
|
echo $worksheet->getCell('A13')->getValue() . '<br />';
|
||||||
var_dump($criteriaData);
|
echo 'DMAX() Result is ' . $worksheet->getCell('B13')->getCalculatedValue();
|
||||||
|
?>
|
||||||
echo $worksheet->getCell('A13')->getValue() . '<br />';
|
<body>
|
||||||
echo 'DMAX() Result is ' . $worksheet->getCell('B13')->getCalculatedValue();
|
|
||||||
|
|
||||||
?>
|
|
||||||
<body>
|
|
||||||
</html>
|
</html>
|
|
@ -1,79 +1,78 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
|
|
||||||
date_default_timezone_set('Europe/London');
|
date_default_timezone_set('Europe/London');
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
|
||||||
<title>PhpSpreadsheet Calculation Examples</title>
|
<title>PhpSpreadsheet Calculation Examples</title>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h1>DSTDEV</h1>
|
<h1>DSTDEV</h1>
|
||||||
<h2>Estimates the standard deviation based on a sample of selected database entries.</h2>
|
<h2>Estimates the standard deviation based on a sample of selected database entries.</h2>
|
||||||
<?php
|
<?php
|
||||||
|
require_once __DIR__ . '/../../../../src/Bootstrap.php';
|
||||||
|
|
||||||
require_once __DIR__ . '/../../../../src/Bootstrap.php';
|
// Create new PhpSpreadsheet object
|
||||||
|
$spreadsheet = new Spreadsheet();
|
||||||
|
$worksheet = $spreadsheet->getActiveSheet();
|
||||||
|
|
||||||
// Create new PhpSpreadsheet object
|
// Add some data
|
||||||
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'],
|
||||||
$worksheet = $spreadsheet->getActiveSheet();
|
['Apple', 18, 20, 14, 105.00],
|
||||||
|
['Pear', 12, 12, 10, 96.00],
|
||||||
|
['Cherry', 13, 14, 9, 105.00],
|
||||||
|
['Apple', 14, 15, 10, 75.00],
|
||||||
|
['Pear', 9, 8, 8, 76.80],
|
||||||
|
['Apple', 8, 9, 6, 45.00],
|
||||||
|
];
|
||||||
|
$criteria = [['Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height'],
|
||||||
|
['="=Apple"', '>10', null, null, null, '<16'],
|
||||||
|
['="=Pear"', null, null, null, null, null],
|
||||||
|
];
|
||||||
|
|
||||||
// Add some data
|
$worksheet->fromArray($criteria, null, 'A1');
|
||||||
$database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'],
|
$worksheet->fromArray($database, null, 'A4');
|
||||||
['Apple', 18, 20, 14, 105.00],
|
|
||||||
['Pear', 12, 12, 10, 96.00],
|
|
||||||
['Cherry', 13, 14, 9, 105.00],
|
|
||||||
['Apple', 14, 15, 10, 75.00],
|
|
||||||
['Pear', 9, 8, 8, 76.80],
|
|
||||||
['Apple', 8, 9, 6, 45.00],
|
|
||||||
];
|
|
||||||
$criteria = [['Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height'],
|
|
||||||
['="=Apple"', '>10', null, null, null, '<16'],
|
|
||||||
['="=Pear"', null, null, null, null, null],
|
|
||||||
];
|
|
||||||
|
|
||||||
$worksheet->fromArray($criteria, null, 'A1');
|
$worksheet->setCellValue('A12', 'The estimated standard deviation in the yield of Apple and Pear trees');
|
||||||
$worksheet->fromArray($database, null, 'A4');
|
$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('A13', 'The estimated standard deviation in height of Apple and Pear trees');
|
||||||
$worksheet->setCellValue('B12', '=DSTDEV(A4:E10,"Yield",A1:A3)');
|
$worksheet->setCellValue('B13', '=DSTDEV(A4:E10,2,A1:A3)');
|
||||||
|
|
||||||
$worksheet->setCellValue('A13', 'The estimated standard deviation in height of Apple and Pear trees');
|
echo '<hr />';
|
||||||
$worksheet->setCellValue('B13', '=DSTDEV(A4:E10,2,A1:A3)');
|
|
||||||
|
|
||||||
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);
|
echo '<hr />';
|
||||||
var_dump($databaseData);
|
|
||||||
|
|
||||||
echo '<hr />';
|
// Test the formulae
|
||||||
|
echo '<h4>Criteria</h4>';
|
||||||
|
|
||||||
// Test the formulae
|
$criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true);
|
||||||
echo '<h4>Criteria</h4>';
|
var_dump($criteriaData);
|
||||||
|
|
||||||
$criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true);
|
echo $worksheet->getCell('A12')->getValue() . '<br />';
|
||||||
var_dump($criteriaData);
|
echo 'DSTDEV() Result is ' . $worksheet->getCell('B12')->getCalculatedValue() . '<br /><br />';
|
||||||
|
|
||||||
echo $worksheet->getCell('A12')->getValue() . '<br />';
|
echo '<h4>Criteria</h4>';
|
||||||
echo 'DSTDEV() Result is ' . $worksheet->getCell('B12')->getCalculatedValue() . '<br /><br />';
|
|
||||||
|
|
||||||
echo '<h4>Criteria</h4>';
|
$criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true);
|
||||||
|
var_dump($criteriaData);
|
||||||
|
|
||||||
$criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true);
|
echo $worksheet->getCell('A13')->getValue() . '<br />';
|
||||||
var_dump($criteriaData);
|
echo 'DSTDEV() Result is ' . $worksheet->getCell('B13')->getCalculatedValue();
|
||||||
|
?>
|
||||||
echo $worksheet->getCell('A13')->getValue() . '<br />';
|
<body>
|
||||||
echo 'DSTDEV() Result is ' . $worksheet->getCell('B13')->getCalculatedValue();
|
|
||||||
|
|
||||||
?>
|
|
||||||
<body>
|
|
||||||
</html>
|
</html>
|
|
@ -1,79 +1,78 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
|
|
||||||
date_default_timezone_set('Europe/London');
|
date_default_timezone_set('Europe/London');
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
|
||||||
<title>PhpSpreadsheet Calculation Examples</title>
|
<title>PhpSpreadsheet Calculation Examples</title>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h1>DSTDEVP</h1>
|
<h1>DSTDEVP</h1>
|
||||||
<h2>Calculates the standard deviation based on the entire population of selected database entries.</h2>
|
<h2>Calculates the standard deviation based on the entire population of selected database entries.</h2>
|
||||||
<?php
|
<?php
|
||||||
|
require_once __DIR__ . '/../../../../src/Bootstrap.php';
|
||||||
|
|
||||||
require_once __DIR__ . '/../../../../src/Bootstrap.php';
|
// Create new PhpSpreadsheet object
|
||||||
|
$spreadsheet = new Spreadsheet();
|
||||||
|
$worksheet = $spreadsheet->getActiveSheet();
|
||||||
|
|
||||||
// Create new PhpSpreadsheet object
|
// Add some data
|
||||||
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'],
|
||||||
$worksheet = $spreadsheet->getActiveSheet();
|
['Apple', 18, 20, 14, 105.00],
|
||||||
|
['Pear', 12, 12, 10, 96.00],
|
||||||
|
['Cherry', 13, 14, 9, 105.00],
|
||||||
|
['Apple', 14, 15, 10, 75.00],
|
||||||
|
['Pear', 9, 8, 8, 76.80],
|
||||||
|
['Apple', 8, 9, 6, 45.00],
|
||||||
|
];
|
||||||
|
$criteria = [['Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height'],
|
||||||
|
['="=Apple"', '>10', null, null, null, '<16'],
|
||||||
|
['="=Pear"', null, null, null, null, null],
|
||||||
|
];
|
||||||
|
|
||||||
// Add some data
|
$worksheet->fromArray($criteria, null, 'A1');
|
||||||
$database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'],
|
$worksheet->fromArray($database, null, 'A4');
|
||||||
['Apple', 18, 20, 14, 105.00],
|
|
||||||
['Pear', 12, 12, 10, 96.00],
|
|
||||||
['Cherry', 13, 14, 9, 105.00],
|
|
||||||
['Apple', 14, 15, 10, 75.00],
|
|
||||||
['Pear', 9, 8, 8, 76.80],
|
|
||||||
['Apple', 8, 9, 6, 45.00],
|
|
||||||
];
|
|
||||||
$criteria = [['Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height'],
|
|
||||||
['="=Apple"', '>10', null, null, null, '<16'],
|
|
||||||
['="=Pear"', null, null, null, null, null],
|
|
||||||
];
|
|
||||||
|
|
||||||
$worksheet->fromArray($criteria, null, 'A1');
|
$worksheet->setCellValue('A12', 'The standard deviation in the yield of Apple and Pear trees');
|
||||||
$worksheet->fromArray($database, null, 'A4');
|
$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('A13', 'The standard deviation in height of Apple and Pear trees');
|
||||||
$worksheet->setCellValue('B12', '=DSTDEVP(A4:E10,"Yield",A1:A3)');
|
$worksheet->setCellValue('B13', '=DSTDEVP(A4:E10,2,A1:A3)');
|
||||||
|
|
||||||
$worksheet->setCellValue('A13', 'The standard deviation in height of Apple and Pear trees');
|
echo '<hr />';
|
||||||
$worksheet->setCellValue('B13', '=DSTDEVP(A4:E10,2,A1:A3)');
|
|
||||||
|
|
||||||
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);
|
echo '<hr />';
|
||||||
var_dump($databaseData);
|
|
||||||
|
|
||||||
echo '<hr />';
|
// Test the formulae
|
||||||
|
echo '<h4>Criteria</h4>';
|
||||||
|
|
||||||
// Test the formulae
|
$criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true);
|
||||||
echo '<h4>Criteria</h4>';
|
var_dump($criteriaData);
|
||||||
|
|
||||||
$criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true);
|
echo $worksheet->getCell('A12')->getValue() . '<br />';
|
||||||
var_dump($criteriaData);
|
echo 'DSTDEVP() Result is ' . $worksheet->getCell('B12')->getCalculatedValue() . '<br /><br />';
|
||||||
|
|
||||||
echo $worksheet->getCell('A12')->getValue() . '<br />';
|
echo '<h4>Criteria</h4>';
|
||||||
echo 'DSTDEVP() Result is ' . $worksheet->getCell('B12')->getCalculatedValue() . '<br /><br />';
|
|
||||||
|
|
||||||
echo '<h4>Criteria</h4>';
|
$criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true);
|
||||||
|
var_dump($criteriaData);
|
||||||
|
|
||||||
$criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true);
|
echo $worksheet->getCell('A13')->getValue() . '<br />';
|
||||||
var_dump($criteriaData);
|
echo 'DSTDEVP() Result is ' . $worksheet->getCell('B13')->getCalculatedValue();
|
||||||
|
?>
|
||||||
echo $worksheet->getCell('A13')->getValue() . '<br />';
|
<body>
|
||||||
echo 'DSTDEVP() Result is ' . $worksheet->getCell('B13')->getCalculatedValue();
|
|
||||||
|
|
||||||
?>
|
|
||||||
<body>
|
|
||||||
</html>
|
</html>
|
|
@ -1,79 +1,78 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
|
|
||||||
date_default_timezone_set('Europe/London');
|
date_default_timezone_set('Europe/London');
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
|
||||||
<title>PhpSpreadsheet Calculation Examples</title>
|
<title>PhpSpreadsheet Calculation Examples</title>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h1>DVAR</h1>
|
<h1>DVAR</h1>
|
||||||
<h2>Estimates variance based on a sample from selected database entries.</h2>
|
<h2>Estimates variance based on a sample from selected database entries.</h2>
|
||||||
<?php
|
<?php
|
||||||
|
require_once __DIR__ . '/../../../../src/Bootstrap.php';
|
||||||
|
|
||||||
require_once __DIR__ . '/../../../../src/Bootstrap.php';
|
// Create new PhpSpreadsheet object
|
||||||
|
$spreadsheet = new Spreadsheet();
|
||||||
|
$worksheet = $spreadsheet->getActiveSheet();
|
||||||
|
|
||||||
// Create new PhpSpreadsheet object
|
// Add some data
|
||||||
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'],
|
||||||
$worksheet = $spreadsheet->getActiveSheet();
|
['Apple', 18, 20, 14, 105.00],
|
||||||
|
['Pear', 12, 12, 10, 96.00],
|
||||||
|
['Cherry', 13, 14, 9, 105.00],
|
||||||
|
['Apple', 14, 15, 10, 75.00],
|
||||||
|
['Pear', 9, 8, 8, 76.80],
|
||||||
|
['Apple', 8, 9, 6, 45.00],
|
||||||
|
];
|
||||||
|
$criteria = [['Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height'],
|
||||||
|
['="=Apple"', '>10', null, null, null, '<16'],
|
||||||
|
['="=Pear"', null, null, null, null, null],
|
||||||
|
];
|
||||||
|
|
||||||
// Add some data
|
$worksheet->fromArray($criteria, null, 'A1');
|
||||||
$database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'],
|
$worksheet->fromArray($database, null, 'A4');
|
||||||
['Apple', 18, 20, 14, 105.00],
|
|
||||||
['Pear', 12, 12, 10, 96.00],
|
|
||||||
['Cherry', 13, 14, 9, 105.00],
|
|
||||||
['Apple', 14, 15, 10, 75.00],
|
|
||||||
['Pear', 9, 8, 8, 76.80],
|
|
||||||
['Apple', 8, 9, 6, 45.00],
|
|
||||||
];
|
|
||||||
$criteria = [['Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height'],
|
|
||||||
['="=Apple"', '>10', null, null, null, '<16'],
|
|
||||||
['="=Pear"', null, null, null, null, null],
|
|
||||||
];
|
|
||||||
|
|
||||||
$worksheet->fromArray($criteria, null, 'A1');
|
$worksheet->setCellValue('A12', 'The estimated variance in the yield of Apple and Pear trees');
|
||||||
$worksheet->fromArray($database, null, 'A4');
|
$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('A13', 'The estimated variance in height of Apple and Pear trees');
|
||||||
$worksheet->setCellValue('B12', '=DVAR(A4:E10,"Yield",A1:A3)');
|
$worksheet->setCellValue('B13', '=DVAR(A4:E10,2,A1:A3)');
|
||||||
|
|
||||||
$worksheet->setCellValue('A13', 'The estimated variance in height of Apple and Pear trees');
|
echo '<hr />';
|
||||||
$worksheet->setCellValue('B13', '=DVAR(A4:E10,2,A1:A3)');
|
|
||||||
|
|
||||||
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);
|
echo '<hr />';
|
||||||
var_dump($databaseData);
|
|
||||||
|
|
||||||
echo '<hr />';
|
// Test the formulae
|
||||||
|
echo '<h4>Criteria</h4>';
|
||||||
|
|
||||||
// Test the formulae
|
$criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true);
|
||||||
echo '<h4>Criteria</h4>';
|
var_dump($criteriaData);
|
||||||
|
|
||||||
$criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true);
|
echo $worksheet->getCell('A12')->getValue() . '<br />';
|
||||||
var_dump($criteriaData);
|
echo 'DVAR() Result is ' . $worksheet->getCell('B12')->getCalculatedValue() . '<br /><br />';
|
||||||
|
|
||||||
echo $worksheet->getCell('A12')->getValue() . '<br />';
|
echo '<h4>Criteria</h4>';
|
||||||
echo 'DVAR() Result is ' . $worksheet->getCell('B12')->getCalculatedValue() . '<br /><br />';
|
|
||||||
|
|
||||||
echo '<h4>Criteria</h4>';
|
$criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true);
|
||||||
|
var_dump($criteriaData);
|
||||||
|
|
||||||
$criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true);
|
echo $worksheet->getCell('A13')->getValue() . '<br />';
|
||||||
var_dump($criteriaData);
|
echo 'DVAR() Result is ' . $worksheet->getCell('B13')->getCalculatedValue();
|
||||||
|
?>
|
||||||
echo $worksheet->getCell('A13')->getValue() . '<br />';
|
<body>
|
||||||
echo 'DVAR() Result is ' . $worksheet->getCell('B13')->getCalculatedValue();
|
|
||||||
|
|
||||||
?>
|
|
||||||
<body>
|
|
||||||
</html>
|
</html>
|
|
@ -1,79 +1,78 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
|
|
||||||
date_default_timezone_set('Europe/London');
|
date_default_timezone_set('Europe/London');
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
|
||||||
<title>PhpSpreadsheet Calculation Examples</title>
|
<title>PhpSpreadsheet Calculation Examples</title>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h1>DVARP</h1>
|
<h1>DVARP</h1>
|
||||||
<h2>Calculates variance based on the entire population of selected database entries,</h2>
|
<h2>Calculates variance based on the entire population of selected database entries,</h2>
|
||||||
<?php
|
<?php
|
||||||
|
require_once __DIR__ . '/../../../../src/Bootstrap.php';
|
||||||
|
|
||||||
require_once __DIR__ . '/../../../../src/Bootstrap.php';
|
// Create new PhpSpreadsheet object
|
||||||
|
$spreadsheet = new Spreadsheet();
|
||||||
|
$worksheet = $spreadsheet->getActiveSheet();
|
||||||
|
|
||||||
// Create new PhpSpreadsheet object
|
// Add some data
|
||||||
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'],
|
||||||
$worksheet = $spreadsheet->getActiveSheet();
|
['Apple', 18, 20, 14, 105.00],
|
||||||
|
['Pear', 12, 12, 10, 96.00],
|
||||||
|
['Cherry', 13, 14, 9, 105.00],
|
||||||
|
['Apple', 14, 15, 10, 75.00],
|
||||||
|
['Pear', 9, 8, 8, 76.80],
|
||||||
|
['Apple', 8, 9, 6, 45.00],
|
||||||
|
];
|
||||||
|
$criteria = [['Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height'],
|
||||||
|
['="=Apple"', '>10', null, null, null, '<16'],
|
||||||
|
['="=Pear"', null, null, null, null, null],
|
||||||
|
];
|
||||||
|
|
||||||
// Add some data
|
$worksheet->fromArray($criteria, null, 'A1');
|
||||||
$database = [['Tree', 'Height', 'Age', 'Yield', 'Profit'],
|
$worksheet->fromArray($database, null, 'A4');
|
||||||
['Apple', 18, 20, 14, 105.00],
|
|
||||||
['Pear', 12, 12, 10, 96.00],
|
|
||||||
['Cherry', 13, 14, 9, 105.00],
|
|
||||||
['Apple', 14, 15, 10, 75.00],
|
|
||||||
['Pear', 9, 8, 8, 76.80],
|
|
||||||
['Apple', 8, 9, 6, 45.00],
|
|
||||||
];
|
|
||||||
$criteria = [['Tree', 'Height', 'Age', 'Yield', 'Profit', 'Height'],
|
|
||||||
['="=Apple"', '>10', null, null, null, '<16'],
|
|
||||||
['="=Pear"', null, null, null, null, null],
|
|
||||||
];
|
|
||||||
|
|
||||||
$worksheet->fromArray($criteria, null, 'A1');
|
$worksheet->setCellValue('A12', 'The variance in the yield of Apple and Pear trees');
|
||||||
$worksheet->fromArray($database, null, 'A4');
|
$worksheet->setCellValue('B12', '=DVARP(A4:E10,"Yield",A1:A3)');
|
||||||
|
|
||||||
$worksheet->setCellValue('A12', 'The variance in the yield of Apple and Pear trees');
|
$worksheet->setCellValue('A13', 'The variance in height of Apple and Pear trees');
|
||||||
$worksheet->setCellValue('B12', '=DVARP(A4:E10,"Yield",A1:A3)');
|
$worksheet->setCellValue('B13', '=DVARP(A4:E10,2,A1:A3)');
|
||||||
|
|
||||||
$worksheet->setCellValue('A13', 'The variance in height of Apple and Pear trees');
|
echo '<hr />';
|
||||||
$worksheet->setCellValue('B13', '=DVARP(A4:E10,2,A1:A3)');
|
|
||||||
|
|
||||||
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);
|
echo '<hr />';
|
||||||
var_dump($databaseData);
|
|
||||||
|
|
||||||
echo '<hr />';
|
// Test the formulae
|
||||||
|
echo '<h4>Criteria</h4>';
|
||||||
|
|
||||||
// Test the formulae
|
$criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true);
|
||||||
echo '<h4>Criteria</h4>';
|
var_dump($criteriaData);
|
||||||
|
|
||||||
$criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true);
|
echo $worksheet->getCell('A12')->getValue() . '<br />';
|
||||||
var_dump($criteriaData);
|
echo 'DVARP() Result is ' . $worksheet->getCell('B12')->getCalculatedValue() . '<br /><br />';
|
||||||
|
|
||||||
echo $worksheet->getCell('A12')->getValue() . '<br />';
|
echo '<h4>Criteria</h4>';
|
||||||
echo 'DVARP() Result is ' . $worksheet->getCell('B12')->getCalculatedValue() . '<br /><br />';
|
|
||||||
|
|
||||||
echo '<h4>Criteria</h4>';
|
$criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true);
|
||||||
|
var_dump($criteriaData);
|
||||||
|
|
||||||
$criteriaData = $worksheet->rangeToArray('A1:A3', null, true, true, true);
|
echo $worksheet->getCell('A13')->getValue() . '<br />';
|
||||||
var_dump($criteriaData);
|
echo 'DVARP() Result is ' . $worksheet->getCell('B13')->getCalculatedValue();
|
||||||
|
?>
|
||||||
echo $worksheet->getCell('A13')->getValue() . '<br />';
|
<body>
|
||||||
echo 'DVARP() Result is ' . $worksheet->getCell('B13')->getCalculatedValue();
|
|
||||||
|
|
||||||
?>
|
|
||||||
<body>
|
|
||||||
</html>
|
</html>
|
|
@ -1,77 +1,77 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
|
|
||||||
date_default_timezone_set('Europe/London');
|
date_default_timezone_set('Europe/London');
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
|
||||||
<title>PhpSpreadsheet Calculation Examples</title>
|
<title>PhpSpreadsheet Calculation Examples</title>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h1>DATE</h1>
|
<h1>DATE</h1>
|
||||||
<h2>Returns the serial number of a particular date.</h2>
|
<h2>Returns the serial number of a particular date.</h2>
|
||||||
<?php
|
<?php
|
||||||
|
require_once __DIR__ . '/../../../../src/Bootstrap.php';
|
||||||
|
|
||||||
require_once __DIR__ . '/../../../../src/Bootstrap.php';
|
// Create new PhpSpreadsheet object
|
||||||
|
$spreadsheet = new Spreadsheet();
|
||||||
|
$worksheet = $spreadsheet->getActiveSheet();
|
||||||
|
|
||||||
// Create new PhpSpreadsheet object
|
// Add some data
|
||||||
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$testDates = [[2012, 3, 26], [2012, 2, 29], [2012, 4, 1], [2012, 12, 25],
|
||||||
$worksheet = $spreadsheet->getActiveSheet();
|
[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);
|
||||||
|
|
||||||
// Add some data
|
$worksheet->fromArray($testDates, null, 'A1', true);
|
||||||
$testDates = [[2012, 3, 26], [2012, 2, 29], [2012, 4, 1], [2012, 12, 25],
|
|
||||||
[2012, 10, 31], [2012, 11, 5], [2012, 1, 1], [2012, 3, 17],
|
|
||||||
[2011, 2, 29], [7, 5, 3], [2012, 13, 1], [2012, 11, 45],
|
|
||||||
[2012, 0, 0], [2012, 1, 0], [2012, 0, 1],
|
|
||||||
[2012, -2, 2], [2012, 2, -2], [2012, -2, -2],
|
|
||||||
];
|
|
||||||
$testDateCount = count($testDates);
|
|
||||||
|
|
||||||
$worksheet->fromArray($testDates, null, 'A1', true);
|
for ($row = 1; $row <= $testDateCount; ++$row) {
|
||||||
|
$worksheet->setCellValue('D' . $row, '=DATE(A' . $row . ',B' . $row . ',C' . $row . ')');
|
||||||
|
$worksheet->setCellValue('E' . $row, '=D' . $row);
|
||||||
|
}
|
||||||
|
$worksheet->getStyle('E1:E' . $testDateCount)
|
||||||
|
->getNumberFormat()
|
||||||
|
->setFormatCode('yyyy-mmm-dd');
|
||||||
|
|
||||||
for ($row = 1; $row <= $testDateCount; ++$row) {
|
echo '<hr />';
|
||||||
$worksheet->setCellValue('D' . $row, '=DATE(A' . $row . ',B' . $row . ',C' . $row . ')');
|
|
||||||
$worksheet->setCellValue('E' . $row, '=D' . $row);
|
|
||||||
}
|
|
||||||
$worksheet->getStyle('E1:E' . $testDateCount)
|
|
||||||
->getNumberFormat()
|
|
||||||
->setFormatCode('yyyy-mmm-dd');
|
|
||||||
|
|
||||||
echo '<hr />';
|
// Test the formulae
|
||||||
|
?>
|
||||||
// Test the formulae
|
<table border="1" cellspacing="0">
|
||||||
?>
|
<tr>
|
||||||
<table border="1" cellspacing="0">
|
<th colspan="3">Date Value</th>
|
||||||
<tr>
|
<th rowspan="2" valign="bottom">Formula</th>
|
||||||
<th colspan="3">Date Value</th>
|
<th rowspan="2" valign="bottom">Excel DateStamp</th>
|
||||||
<th rowspan="2" valign="bottom">Formula</th>
|
<th rowspan="2" valign="bottom">Formatted DateStamp</th>
|
||||||
<th rowspan="2" valign="bottom">Excel DateStamp</th>
|
</tr>
|
||||||
<th rowspan="2" valign="bottom">Formatted DateStamp</th>
|
<tr>
|
||||||
</tr>
|
<th>Year</th>
|
||||||
<tr>
|
<th>Month</th>
|
||||||
<th>Year</th>
|
<th>Day</th>
|
||||||
<th>Month</th>
|
<tr>
|
||||||
<th>Day</th>
|
<?php
|
||||||
<tr>
|
for ($row = 1; $row <= $testDateCount; ++$row) {
|
||||||
<?php
|
echo '<tr>';
|
||||||
for ($row = 1; $row <= $testDateCount; ++$row) {
|
echo '<td>', $worksheet->getCell('A' . $row)->getFormattedValue(), '</td>';
|
||||||
echo '<tr>';
|
echo '<td>', $worksheet->getCell('B' . $row)->getFormattedValue(), '</td>';
|
||||||
echo '<td>', $worksheet->getCell('A' . $row)->getFormattedValue(), '</td>';
|
echo '<td>', $worksheet->getCell('C' . $row)->getFormattedValue(), '</td>';
|
||||||
echo '<td>', $worksheet->getCell('B' . $row)->getFormattedValue(), '</td>';
|
echo '<td>', $worksheet->getCell('D' . $row)->getValue(), '</td>';
|
||||||
echo '<td>', $worksheet->getCell('C' . $row)->getFormattedValue(), '</td>';
|
echo '<td>', $worksheet->getCell('D' . $row)->getFormattedValue(), '</td>';
|
||||||
echo '<td>', $worksheet->getCell('D' . $row)->getValue(), '</td>';
|
echo '<td>', $worksheet->getCell('E' . $row)->getFormattedValue(), '</td>';
|
||||||
echo '<td>', $worksheet->getCell('D' . $row)->getFormattedValue(), '</td>';
|
echo '</tr>';
|
||||||
echo '<td>', $worksheet->getCell('E' . $row)->getFormattedValue(), '</td>';
|
}
|
||||||
echo '</tr>';
|
?>
|
||||||
}
|
</table>
|
||||||
?>
|
</body>
|
||||||
</table>
|
|
||||||
</body>
|
|
||||||
</html>
|
</html>
|
|
@ -1,70 +1,70 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
|
|
||||||
date_default_timezone_set('Europe/London');
|
date_default_timezone_set('Europe/London');
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
|
||||||
<title>PhpSpreadsheet Calculation Examples</title>
|
<title>PhpSpreadsheet Calculation Examples</title>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h1>DATEVALUE</h1>
|
<h1>DATEVALUE</h1>
|
||||||
<h2>Converts a date in the form of text to a serial number.</h2>
|
<h2>Converts a date in the form of text to a serial number.</h2>
|
||||||
<?php
|
<?php
|
||||||
|
require_once __DIR__ . '/../../../../src/Bootstrap.php';
|
||||||
|
|
||||||
require_once __DIR__ . '/../../../../src/Bootstrap.php';
|
// Create new PhpSpreadsheet object
|
||||||
|
$spreadsheet = new Spreadsheet();
|
||||||
|
$worksheet = $spreadsheet->getActiveSheet();
|
||||||
|
|
||||||
// Create new PhpSpreadsheet object
|
// Add some data
|
||||||
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$testDates = ['26 March 2012', '29 Feb 2012', 'April 1, 2012', '25/12/2012',
|
||||||
$worksheet = $spreadsheet->getActiveSheet();
|
'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);
|
||||||
|
|
||||||
// Add some data
|
for ($row = 1; $row <= $testDateCount; ++$row) {
|
||||||
$testDates = ['26 March 2012', '29 Feb 2012', 'April 1, 2012', '25/12/2012',
|
$worksheet->setCellValue('A' . $row, $testDates[$row - 1]);
|
||||||
'2012-Oct-31', '5th November', 'January 1st', 'April 2012',
|
$worksheet->setCellValue('B' . $row, '=DATEVALUE(A' . $row . ')');
|
||||||
'17-03', '03-2012', '29 Feb 2011', '03-05-07',
|
$worksheet->setCellValue('C' . $row, '=B' . $row);
|
||||||
'03-MAY-07', '03-13-07',
|
}
|
||||||
];
|
|
||||||
$testDateCount = count($testDates);
|
|
||||||
|
|
||||||
for ($row = 1; $row <= $testDateCount; ++$row) {
|
$worksheet->getStyle('C1:C' . $testDateCount)
|
||||||
$worksheet->setCellValue('A' . $row, $testDates[$row - 1]);
|
->getNumberFormat()
|
||||||
$worksheet->setCellValue('B' . $row, '=DATEVALUE(A' . $row . ')');
|
->setFormatCode('yyyy-mmm-dd');
|
||||||
$worksheet->setCellValue('C' . $row, '=B' . $row);
|
|
||||||
}
|
|
||||||
|
|
||||||
$worksheet->getStyle('C1:C' . $testDateCount)
|
echo '<hr />';
|
||||||
->getNumberFormat()
|
|
||||||
->setFormatCode('yyyy-mmm-dd');
|
|
||||||
|
|
||||||
echo '<hr />';
|
// Test the formulae
|
||||||
|
?>
|
||||||
// Test the formulae
|
<p><strong>Warning: </strong>The PhpSpreadsheet DATEVALUE() function accepts a wider range of date formats than MS Excel's DATEFORMAT() function.</p>
|
||||||
?>
|
<table border="1" cellspacing="0">
|
||||||
<p><strong>Warning: </strong>The PhpSpreadsheet DATEVALUE() function accepts a wider range of date formats than MS Excel's DATEFORMAT() function.</p>
|
<tr>
|
||||||
<table border="1" cellspacing="0">
|
<th>Date String</th>
|
||||||
<tr>
|
<th>Formula</th>
|
||||||
<th>Date String</th>
|
<th>Excel DateStamp</th>
|
||||||
<th>Formula</th>
|
<th>Formatted DateStamp</th>
|
||||||
<th>Excel DateStamp</th>
|
</tr>
|
||||||
<th>Formatted DateStamp</th>
|
<?php
|
||||||
</tr>
|
for ($row = 1; $row <= $testDateCount; ++$row) {
|
||||||
<?php
|
echo '<tr>';
|
||||||
for ($row = 1; $row <= $testDateCount; ++$row) {
|
echo '<td>', $worksheet->getCell('A' . $row)->getFormattedValue(), '</td>';
|
||||||
echo '<tr>';
|
echo '<td>', $worksheet->getCell('B' . $row)->getValue(), '</td>';
|
||||||
echo '<td>', $worksheet->getCell('A' . $row)->getFormattedValue(), '</td>';
|
echo '<td>', $worksheet->getCell('B' . $row)->getFormattedValue(), '</td>';
|
||||||
echo '<td>', $worksheet->getCell('B' . $row)->getValue(), '</td>';
|
echo '<td>', $worksheet->getCell('C' . $row)->getFormattedValue(), '</td>';
|
||||||
echo '<td>', $worksheet->getCell('B' . $row)->getFormattedValue(), '</td>';
|
echo '</tr>';
|
||||||
echo '<td>', $worksheet->getCell('C' . $row)->getFormattedValue(), '</td>';
|
}
|
||||||
echo '</tr>';
|
?>
|
||||||
}
|
</table>
|
||||||
?>
|
</body>
|
||||||
</table>
|
|
||||||
</body>
|
|
||||||
</html>
|
</html>
|
|
@ -1,75 +1,75 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
|
|
||||||
date_default_timezone_set('Europe/London');
|
date_default_timezone_set('Europe/London');
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
|
||||||
<title>PhpSpreadsheet Calculation Examples</title>
|
<title>PhpSpreadsheet Calculation Examples</title>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h1>TIME</h1>
|
<h1>TIME</h1>
|
||||||
<h2>Returns the serial number of a particular time.</h2>
|
<h2>Returns the serial number of a particular time.</h2>
|
||||||
<?php
|
<?php
|
||||||
|
require_once __DIR__ . '/../../../../src/Bootstrap.php';
|
||||||
|
|
||||||
require_once __DIR__ . '/../../../../src/Bootstrap.php';
|
// Create new PhpSpreadsheet object
|
||||||
|
$spreadsheet = new Spreadsheet();
|
||||||
|
$worksheet = $spreadsheet->getActiveSheet();
|
||||||
|
|
||||||
// Create new PhpSpreadsheet object
|
// Add some data
|
||||||
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$testDates = [[3, 15], [13, 15], [15, 15, 15], [3, 15, 30],
|
||||||
$worksheet = $spreadsheet->getActiveSheet();
|
[15, 15, 15], [5], [9, 15, 0], [9, 15, -1],
|
||||||
|
[13, -14, -15], [0, 0, -1],
|
||||||
|
];
|
||||||
|
$testDateCount = count($testDates);
|
||||||
|
|
||||||
// Add some data
|
$worksheet->fromArray($testDates, null, 'A1', true);
|
||||||
$testDates = [[3, 15], [13, 15], [15, 15, 15], [3, 15, 30],
|
|
||||||
[15, 15, 15], [5], [9, 15, 0], [9, 15, -1],
|
|
||||||
[13, -14, -15], [0, 0, -1],
|
|
||||||
];
|
|
||||||
$testDateCount = count($testDates);
|
|
||||||
|
|
||||||
$worksheet->fromArray($testDates, null, 'A1', true);
|
for ($row = 1; $row <= $testDateCount; ++$row) {
|
||||||
|
$worksheet->setCellValue('D' . $row, '=TIME(A' . $row . ',B' . $row . ',C' . $row . ')');
|
||||||
|
$worksheet->setCellValue('E' . $row, '=D' . $row);
|
||||||
|
}
|
||||||
|
$worksheet->getStyle('E1:E' . $testDateCount)
|
||||||
|
->getNumberFormat()
|
||||||
|
->setFormatCode('hh:mm:ss');
|
||||||
|
|
||||||
for ($row = 1; $row <= $testDateCount; ++$row) {
|
echo '<hr />';
|
||||||
$worksheet->setCellValue('D' . $row, '=TIME(A' . $row . ',B' . $row . ',C' . $row . ')');
|
|
||||||
$worksheet->setCellValue('E' . $row, '=D' . $row);
|
|
||||||
}
|
|
||||||
$worksheet->getStyle('E1:E' . $testDateCount)
|
|
||||||
->getNumberFormat()
|
|
||||||
->setFormatCode('hh:mm:ss');
|
|
||||||
|
|
||||||
echo '<hr />';
|
// Test the formulae
|
||||||
|
?>
|
||||||
// Test the formulae
|
<table border="1" cellspacing="0">
|
||||||
?>
|
<tr>
|
||||||
<table border="1" cellspacing="0">
|
<th colspan="3">Date Value</th>
|
||||||
<tr>
|
<th rowspan="2" valign="bottom">Formula</th>
|
||||||
<th colspan="3">Date Value</th>
|
<th rowspan="2" valign="bottom">Excel TimeStamp</th>
|
||||||
<th rowspan="2" valign="bottom">Formula</th>
|
<th rowspan="2" valign="bottom">Formatted TimeStamp</th>
|
||||||
<th rowspan="2" valign="bottom">Excel TimeStamp</th>
|
</tr>
|
||||||
<th rowspan="2" valign="bottom">Formatted TimeStamp</th>
|
<tr>
|
||||||
</tr>
|
<th>Hour</th>
|
||||||
<tr>
|
<th>Minute</th>
|
||||||
<th>Hour</th>
|
<th>Second</th>
|
||||||
<th>Minute</th>
|
<tr>
|
||||||
<th>Second</th>
|
<?php
|
||||||
<tr>
|
for ($row = 1; $row <= $testDateCount; ++$row) {
|
||||||
<?php
|
echo '<tr>';
|
||||||
for ($row = 1; $row <= $testDateCount; ++$row) {
|
echo '<td>', $worksheet->getCell('A' . $row)->getFormattedValue(), '</td>';
|
||||||
echo '<tr>';
|
echo '<td>', $worksheet->getCell('B' . $row)->getFormattedValue(), '</td>';
|
||||||
echo '<td>', $worksheet->getCell('A' . $row)->getFormattedValue(), '</td>';
|
echo '<td>', $worksheet->getCell('C' . $row)->getFormattedValue(), '</td>';
|
||||||
echo '<td>', $worksheet->getCell('B' . $row)->getFormattedValue(), '</td>';
|
echo '<td>', $worksheet->getCell('D' . $row)->getValue(), '</td>';
|
||||||
echo '<td>', $worksheet->getCell('C' . $row)->getFormattedValue(), '</td>';
|
echo '<td>', $worksheet->getCell('D' . $row)->getFormattedValue(), '</td>';
|
||||||
echo '<td>', $worksheet->getCell('D' . $row)->getValue(), '</td>';
|
echo '<td>', $worksheet->getCell('E' . $row)->getFormattedValue(), '</td>';
|
||||||
echo '<td>', $worksheet->getCell('D' . $row)->getFormattedValue(), '</td>';
|
echo '</tr>';
|
||||||
echo '<td>', $worksheet->getCell('E' . $row)->getFormattedValue(), '</td>';
|
}
|
||||||
echo '</tr>';
|
?>
|
||||||
}
|
</table>
|
||||||
?>
|
</body>
|
||||||
</table>
|
|
||||||
</body>
|
|
||||||
</html>
|
</html>
|
|
@ -1,66 +1,66 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
|
|
||||||
date_default_timezone_set('Europe/London');
|
date_default_timezone_set('Europe/London');
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
|
||||||
<title>PhpSpreadsheet Calculation Examples</title>
|
<title>PhpSpreadsheet Calculation Examples</title>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h1>TIMEVALUE</h1>
|
<h1>TIMEVALUE</h1>
|
||||||
<h2>Converts a time in the form of text to a serial number.</h2>
|
<h2>Converts a time in the form of text to a serial number.</h2>
|
||||||
<?php
|
<?php
|
||||||
|
require_once __DIR__ . '/../../../../src/Bootstrap.php';
|
||||||
|
|
||||||
require_once __DIR__ . '/../../../../src/Bootstrap.php';
|
// Create new PhpSpreadsheet object
|
||||||
|
$spreadsheet = new Spreadsheet();
|
||||||
|
$worksheet = $spreadsheet->getActiveSheet();
|
||||||
|
|
||||||
// Create new PhpSpreadsheet object
|
// Add some data
|
||||||
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$testDates = ['3:15', '13:15', '15:15:15', '3:15 AM', '3:15 PM', '5PM', '9:15AM', '13:15AM',
|
||||||
$worksheet = $spreadsheet->getActiveSheet();
|
];
|
||||||
|
$testDateCount = count($testDates);
|
||||||
|
|
||||||
// Add some data
|
for ($row = 1; $row <= $testDateCount; ++$row) {
|
||||||
$testDates = ['3:15', '13:15', '15:15:15', '3:15 AM', '3:15 PM', '5PM', '9:15AM', '13:15AM',
|
$worksheet->setCellValue('A' . $row, $testDates[$row - 1]);
|
||||||
];
|
$worksheet->setCellValue('B' . $row, '=TIMEVALUE(A' . $row . ')');
|
||||||
$testDateCount = count($testDates);
|
$worksheet->setCellValue('C' . $row, '=B' . $row);
|
||||||
|
}
|
||||||
|
|
||||||
for ($row = 1; $row <= $testDateCount; ++$row) {
|
$worksheet->getStyle('C1:C' . $testDateCount)
|
||||||
$worksheet->setCellValue('A' . $row, $testDates[$row - 1]);
|
->getNumberFormat()
|
||||||
$worksheet->setCellValue('B' . $row, '=TIMEVALUE(A' . $row . ')');
|
->setFormatCode('hh:mm:ss');
|
||||||
$worksheet->setCellValue('C' . $row, '=B' . $row);
|
|
||||||
}
|
|
||||||
|
|
||||||
$worksheet->getStyle('C1:C' . $testDateCount)
|
echo '<hr />';
|
||||||
->getNumberFormat()
|
|
||||||
->setFormatCode('hh:mm:ss');
|
|
||||||
|
|
||||||
echo '<hr />';
|
// Test the formulae
|
||||||
|
?>
|
||||||
// Test the formulae
|
<table border="1" cellspacing="0">
|
||||||
?>
|
<tr>
|
||||||
<table border="1" cellspacing="0">
|
<th>Time String</th>
|
||||||
<tr>
|
<th>Formula</th>
|
||||||
<th>Time String</th>
|
<th>Excel TimeStamp</th>
|
||||||
<th>Formula</th>
|
<th>Formatted TimeStamp</th>
|
||||||
<th>Excel TimeStamp</th>
|
</tr>
|
||||||
<th>Formatted TimeStamp</th>
|
<?php
|
||||||
</tr>
|
for ($row = 1; $row <= $testDateCount; ++$row) {
|
||||||
<?php
|
echo '<tr>';
|
||||||
for ($row = 1; $row <= $testDateCount; ++$row) {
|
echo '<td>', $worksheet->getCell('A' . $row)->getFormattedValue(), '</td>';
|
||||||
echo '<tr>';
|
echo '<td>', $worksheet->getCell('B' . $row)->getValue(), '</td>';
|
||||||
echo '<td>', $worksheet->getCell('A' . $row)->getFormattedValue(), '</td>';
|
echo '<td>', $worksheet->getCell('B' . $row)->getFormattedValue(), '</td>';
|
||||||
echo '<td>', $worksheet->getCell('B' . $row)->getValue(), '</td>';
|
echo '<td>', $worksheet->getCell('C' . $row)->getFormattedValue(), '</td>';
|
||||||
echo '<td>', $worksheet->getCell('B' . $row)->getFormattedValue(), '</td>';
|
echo '</tr>';
|
||||||
echo '<td>', $worksheet->getCell('C' . $row)->getFormattedValue(), '</td>';
|
}
|
||||||
echo '</tr>';
|
?>
|
||||||
}
|
</table>
|
||||||
?>
|
</body>
|
||||||
</table>
|
|
||||||
</body>
|
|
||||||
</html>
|
</html>
|
|
@ -1,49 +1,45 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
|
|
||||||
date_default_timezone_set('Europe/London');
|
date_default_timezone_set('Europe/London');
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
|
||||||
<title>PhpSpreadsheet Calculation Function Examples</title>
|
<title>PhpSpreadsheet Calculation Function Examples</title>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
|
echo '<h1>PhpSpreadsheet Calculation Function Examples</h1>';
|
||||||
|
|
||||||
echo '<h1>PhpSpreadsheet Calculation Function Examples</h1>';
|
$exampleTypeList = glob('./*', GLOB_ONLYDIR);
|
||||||
|
|
||||||
$exampleTypeList = glob('./*', GLOB_ONLYDIR);
|
foreach ($exampleTypeList as $exampleType) {
|
||||||
|
echo '<h2>' . pathinfo($exampleType, PATHINFO_BASENAME) . ' Function Examples</h2>';
|
||||||
|
|
||||||
foreach ($exampleTypeList as $exampleType) {
|
$exampleList = glob('./' . $exampleType . '/*.php');
|
||||||
echo '<h2>' . pathinfo($exampleType, PATHINFO_BASENAME) . ' Function Examples</h2>';
|
|
||||||
|
|
||||||
$exampleList = glob('./' . $exampleType . '/*.php');
|
foreach ($exampleList as $exampleFile) {
|
||||||
|
$fileData = file_get_contents($exampleFile);
|
||||||
|
|
||||||
foreach ($exampleList as $exampleFile) {
|
$h1Pattern = '#<h1>(.*?)</h1>#';
|
||||||
$fileData = file_get_contents($exampleFile);
|
$h2Pattern = '#<h2>(.*?)</h2>#';
|
||||||
|
|
||||||
$h1Pattern = '#<h1>(.*?)</h1>#';
|
if (preg_match($h1Pattern, $fileData, $out)) {
|
||||||
$h2Pattern = '#<h2>(.*?)</h2>#';
|
$h1Text = $out[1];
|
||||||
|
$h2Text = (preg_match($h2Pattern, $fileData, $out)) ? $out[1] : '';
|
||||||
|
|
||||||
if (preg_match($h1Pattern, $fileData, $out)) {
|
echo '<a href="', $exampleFile, '">', $h1Text, '</a><br />';
|
||||||
$h1Text = $out[1];
|
if ($h2Text > '') {
|
||||||
$h2Text = (preg_match($h2Pattern, $fileData, $out)) ? $out[1] : '';
|
echo $h2Text, '<br />';
|
||||||
|
}
|
||||||
echo '<a href="',$exampleFile,'">',$h1Text,'</a><br />';
|
}
|
||||||
if ($h2Text > '') {
|
|
||||||
echo $h2Text,'<br />';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
?>
|
||||||
}
|
<body>
|
||||||
|
|
||||||
?>
|
|
||||||
<body>
|
|
||||||
</html>
|
</html>
|
|
@ -1,35 +1,34 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
|
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
|
|
||||||
date_default_timezone_set('Europe/London');
|
date_default_timezone_set('Europe/London');
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
|
||||||
<title>PhpSpreadsheet Reader Example #01</title>
|
<title>PhpSpreadsheet Reader Example #01</title>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h1>PhpSpreadsheet Reader Example #01</h1>
|
<h1>PhpSpreadsheet Reader Example #01</h1>
|
||||||
<h2>Simple File Reader using \PhpOffice\PhpSpreadsheet\IOFactory::load()</h2>
|
<h2>Simple File Reader using IOFactory::load()</h2>
|
||||||
<?php
|
<?php
|
||||||
|
require_once __DIR__ . '/../../../src/Bootstrap.php';
|
||||||
|
|
||||||
require_once __DIR__ . '/../../../src/Bootstrap.php';
|
$inputFileName = './sampleData/example1.xls';
|
||||||
|
echo 'Loading file ', pathinfo($inputFileName, PATHINFO_BASENAME), ' using IOFactory to identify the format<br />';
|
||||||
|
$spreadsheet = IOFactory::load($inputFileName);
|
||||||
|
|
||||||
$inputFileName = './sampleData/example1.xls';
|
echo '<hr />';
|
||||||
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory to identify the format<br />';
|
|
||||||
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($inputFileName);
|
|
||||||
|
|
||||||
echo '<hr />';
|
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
|
||||||
|
var_dump($sheetData);
|
||||||
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
|
?>
|
||||||
var_dump($sheetData);
|
<body>
|
||||||
|
|
||||||
?>
|
|
||||||
<body>
|
|
||||||
</html>
|
</html>
|
|
@ -1,43 +1,36 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Reader\Xls;
|
||||||
|
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
|
|
||||||
date_default_timezone_set('Europe/London');
|
date_default_timezone_set('Europe/London');
|
||||||
|
|
||||||
require_once __DIR__ . '/../../../src/Bootstrap.php';
|
require_once __DIR__ . '/../../../src/Bootstrap.php';
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
|
||||||
<title>PhpSpreadsheet Reader Example #02</title>
|
<title>PhpSpreadsheet Reader Example #02</title>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h1>PhpSpreadsheet Reader Example #02</h1>
|
<h1>PhpSpreadsheet Reader Example #02</h1>
|
||||||
<h2>Simple File Reader using a Specified Reader</h2>
|
<h2>Simple File Reader using a Specified Reader</h2>
|
||||||
<?php
|
<?php
|
||||||
|
$inputFileName = './sampleData/example1.xls';
|
||||||
|
|
||||||
$inputFileName = './sampleData/example1.xls';
|
echo 'Loading file ', pathinfo($inputFileName, PATHINFO_BASENAME), ' using \PhpOffice\PhpSpreadsheet\Reader\Xls<br />';
|
||||||
|
$reader = new Xls();
|
||||||
|
$spreadsheet = $reader->load($inputFileName);
|
||||||
|
|
||||||
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using \PhpOffice\PhpSpreadsheet\Reader\Xls<br />';
|
echo '<hr />';
|
||||||
$reader = new \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 />';
|
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
|
||||||
|
var_dump($sheetData);
|
||||||
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
|
?>
|
||||||
var_dump($sheetData);
|
<body>
|
||||||
|
|
||||||
?>
|
|
||||||
<body>
|
|
||||||
</html>
|
</html>
|
|
@ -1,44 +1,37 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
|
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
|
|
||||||
date_default_timezone_set('Europe/London');
|
date_default_timezone_set('Europe/London');
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
|
||||||
<title>PhpSpreadsheet Reader Example #03</title>
|
<title>PhpSpreadsheet Reader Example #03</title>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h1>PhpSpreadsheet Reader Example #03</h1>
|
<h1>PhpSpreadsheet Reader Example #03</h1>
|
||||||
<h2>Simple File Reader using the \PhpOffice\PhpSpreadsheet\IOFactory to Return a Reader</h2>
|
<h2>Simple File Reader using the IOFactory to Return a Reader</h2>
|
||||||
<?php
|
<?php
|
||||||
|
require_once __DIR__ . '/../../../src/Bootstrap.php';
|
||||||
|
|
||||||
require_once __DIR__ . '/../../../src/Bootstrap.php';
|
$inputFileType = 'Xls';
|
||||||
|
$inputFileName = './sampleData/example1.xls';
|
||||||
|
|
||||||
$inputFileType = 'Xls';
|
echo 'Loading file ', pathinfo($inputFileName, PATHINFO_BASENAME), ' using IOFactory with a defined reader type of ', $inputFileType, '<br />';
|
||||||
// $inputFileType = 'Xlsx';
|
$reader = IOFactory::createReader($inputFileType);
|
||||||
// $inputFileType = 'Xml';
|
$spreadsheet = $reader->load($inputFileName);
|
||||||
// $inputFileType = 'Ods';
|
|
||||||
// $inputFileType = 'Slk';
|
|
||||||
// $inputFileType = 'Gnumeric';
|
|
||||||
// $inputFileType = 'Csv';
|
|
||||||
$inputFileName = './sampleData/example1.xls';
|
|
||||||
|
|
||||||
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
echo '<hr />';
|
||||||
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
|
||||||
$spreadsheet = $reader->load($inputFileName);
|
|
||||||
|
|
||||||
echo '<hr />';
|
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
|
||||||
|
var_dump($sheetData);
|
||||||
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
|
?>
|
||||||
var_dump($sheetData);
|
<body>
|
||||||
|
|
||||||
?>
|
|
||||||
<body>
|
|
||||||
</html>
|
</html>
|
|
@ -1,40 +1,39 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
|
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
|
|
||||||
date_default_timezone_set('Europe/London');
|
date_default_timezone_set('Europe/London');
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
|
||||||
<title>PhpSpreadsheet Reader Example #04</title>
|
<title>PhpSpreadsheet Reader Example #04</title>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h1>PhpSpreadsheet Reader Example #04</h1>
|
<h1>PhpSpreadsheet Reader Example #04</h1>
|
||||||
<h2>Simple File Reader using the \PhpOffice\PhpSpreadsheet\IOFactory to Identify a Reader to Use</h2>
|
<h2>Simple File Reader using the IOFactory to Identify a Reader to Use</h2>
|
||||||
<?php
|
<?php
|
||||||
|
require_once __DIR__ . '/../../../src/Bootstrap.php';
|
||||||
|
|
||||||
require_once __DIR__ . '/../../../src/Bootstrap.php';
|
$inputFileName = './sampleData/example1.xls';
|
||||||
|
|
||||||
$inputFileName = './sampleData/example1.xls';
|
$inputFileType = IOFactory::identify($inputFileName);
|
||||||
|
echo 'File ', pathinfo($inputFileName, PATHINFO_BASENAME), ' has been identified as an ', $inputFileType, ' file<br />';
|
||||||
|
|
||||||
$inputFileType = \PhpOffice\PhpSpreadsheet\IOFactory::identify($inputFileName);
|
echo 'Loading file ', pathinfo($inputFileName, PATHINFO_BASENAME), ' using IOFactory with the identified reader type<br />';
|
||||||
echo 'File ',pathinfo($inputFileName, PATHINFO_BASENAME),' has been identified as an ',$inputFileType,' file<br />';
|
$reader = IOFactory::createReader($inputFileType);
|
||||||
|
$spreadsheet = $reader->load($inputFileName);
|
||||||
|
|
||||||
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with the identified reader type<br />';
|
echo '<hr />';
|
||||||
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
|
||||||
$spreadsheet = $reader->load($inputFileName);
|
|
||||||
|
|
||||||
echo '<hr />';
|
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
|
||||||
|
var_dump($sheetData);
|
||||||
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
|
?>
|
||||||
var_dump($sheetData);
|
<body>
|
||||||
|
|
||||||
?>
|
|
||||||
<body>
|
|
||||||
</html>
|
</html>
|
|
@ -1,44 +1,39 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
|
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
|
|
||||||
date_default_timezone_set('Europe/London');
|
date_default_timezone_set('Europe/London');
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
|
||||||
<title>PhpSpreadsheet Reader Example #05</title>
|
<title>PhpSpreadsheet Reader Example #05</title>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h1>PhpSpreadsheet Reader Example #05</h1>
|
<h1>PhpSpreadsheet Reader Example #05</h1>
|
||||||
<h2>Simple File Reader using the "Read Data Only" Option</h2>
|
<h2>Simple File Reader using the "Read Data Only" Option</h2>
|
||||||
<?php
|
<?php
|
||||||
|
require_once __DIR__ . '/../../../src/Bootstrap.php';
|
||||||
|
|
||||||
require_once __DIR__ . '/../../../src/Bootstrap.php';
|
$inputFileType = 'Xls';
|
||||||
|
$inputFileName = './sampleData/example1.xls';
|
||||||
|
|
||||||
$inputFileType = 'Xls';
|
echo 'Loading file ', pathinfo($inputFileName, PATHINFO_BASENAME), ' using IOFactory with a defined reader type of ', $inputFileType, '<br />';
|
||||||
// $inputFileType = 'Xlsx';
|
$reader = IOFactory::createReader($inputFileType);
|
||||||
// $inputFileType = 'Xml';
|
echo 'Turning Formatting off for Load<br />';
|
||||||
// $inputFileType = 'Ods';
|
$reader->setReadDataOnly(true);
|
||||||
// $inputFileType = 'Gnumeric';
|
$spreadsheet = $reader->load($inputFileName);
|
||||||
$inputFileName = './sampleData/example1.xls';
|
|
||||||
|
|
||||||
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
echo '<hr />';
|
||||||
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
|
||||||
echo 'Turning Formatting off for Load<br />';
|
|
||||||
$reader->setReadDataOnly(true);
|
|
||||||
$spreadsheet = $reader->load($inputFileName);
|
|
||||||
|
|
||||||
echo '<hr />';
|
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
|
||||||
|
var_dump($sheetData);
|
||||||
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
|
?>
|
||||||
var_dump($sheetData);
|
<body>
|
||||||
|
|
||||||
?>
|
|
||||||
<body>
|
|
||||||
</html>
|
</html>
|
|
@ -1,47 +1,42 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
|
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
|
|
||||||
date_default_timezone_set('Europe/London');
|
date_default_timezone_set('Europe/London');
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
|
||||||
<title>PhpSpreadsheet Reader Example #06</title>
|
<title>PhpSpreadsheet Reader Example #06</title>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h1>PhpSpreadsheet Reader Example #06</h1>
|
<h1>PhpSpreadsheet Reader Example #06</h1>
|
||||||
<h2>Simple File Reader Loading All WorkSheets</h2>
|
<h2>Simple File Reader Loading All WorkSheets</h2>
|
||||||
<?php
|
<?php
|
||||||
|
require_once __DIR__ . '/../../../src/Bootstrap.php';
|
||||||
|
|
||||||
require_once __DIR__ . '/../../../src/Bootstrap.php';
|
$inputFileType = 'Xls';
|
||||||
|
$inputFileName = './sampleData/example1.xls';
|
||||||
|
|
||||||
$inputFileType = 'Xls';
|
echo 'Loading file ', pathinfo($inputFileName, PATHINFO_BASENAME), ' using IOFactory with a defined reader type of ', $inputFileType, '<br />';
|
||||||
// $inputFileType = 'Xlsx';
|
$reader = IOFactory::createReader($inputFileType);
|
||||||
// $inputFileType = 'Xml';
|
echo 'Loading all WorkSheets<br />';
|
||||||
// $inputFileType = 'Ods';
|
$reader->setLoadAllSheets();
|
||||||
// $inputFileType = 'Gnumeric';
|
$spreadsheet = $reader->load($inputFileName);
|
||||||
$inputFileName = './sampleData/example1.xls';
|
|
||||||
|
|
||||||
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
echo '<hr />';
|
||||||
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
|
||||||
echo 'Loading all WorkSheets<br />';
|
|
||||||
$reader->setLoadAllSheets();
|
|
||||||
$spreadsheet = $reader->load($inputFileName);
|
|
||||||
|
|
||||||
echo '<hr />';
|
echo $spreadsheet->getSheetCount(), ' worksheet', (($spreadsheet->getSheetCount() == 1) ? '' : 's'), ' loaded<br /><br />';
|
||||||
|
$loadedSheetNames = $spreadsheet->getSheetNames();
|
||||||
echo $spreadsheet->getSheetCount(), ' worksheet', (($spreadsheet->getSheetCount() == 1) ? '' : 's'), ' loaded<br /><br />';
|
foreach ($loadedSheetNames as $sheetIndex => $loadedSheetName) {
|
||||||
$loadedSheetNames = $spreadsheet->getSheetNames();
|
echo $sheetIndex, ' -> ', $loadedSheetName, '<br />';
|
||||||
foreach ($loadedSheetNames as $sheetIndex => $loadedSheetName) {
|
}
|
||||||
echo $sheetIndex, ' -> ', $loadedSheetName, '<br />';
|
?>
|
||||||
}
|
<body>
|
||||||
|
|
||||||
?>
|
|
||||||
<body>
|
|
||||||
</html>
|
</html>
|
|
@ -1,48 +1,43 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
|
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
|
|
||||||
date_default_timezone_set('Europe/London');
|
date_default_timezone_set('Europe/London');
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
|
||||||
<title>PhpSpreadsheet Reader Example #07</title>
|
<title>PhpSpreadsheet Reader Example #07</title>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h1>PhpSpreadsheet Reader Example #07</h1>
|
<h1>PhpSpreadsheet Reader Example #07</h1>
|
||||||
<h2>Simple File Reader Loading a Single Named WorkSheet</h2>
|
<h2>Simple File Reader Loading a Single Named WorkSheet</h2>
|
||||||
<?php
|
<?php
|
||||||
|
require_once __DIR__ . '/../../../src/Bootstrap.php';
|
||||||
|
|
||||||
require_once __DIR__ . '/../../../src/Bootstrap.php';
|
$inputFileType = 'Xls';
|
||||||
|
$inputFileName = './sampleData/example1.xls';
|
||||||
|
$sheetname = 'Data Sheet #2';
|
||||||
|
|
||||||
$inputFileType = 'Xls';
|
echo 'Loading file ', pathinfo($inputFileName, PATHINFO_BASENAME), ' using IOFactory with a defined reader type of ', $inputFileType, '<br />';
|
||||||
// $inputFileType = 'Xlsx';
|
$reader = IOFactory::createReader($inputFileType);
|
||||||
// $inputFileType = 'Xml';
|
echo 'Loading Sheet "', $sheetname, '" only<br />';
|
||||||
// $inputFileType = 'Ods';
|
$reader->setLoadSheetsOnly($sheetname);
|
||||||
// $inputFileType = 'Gnumeric';
|
$spreadsheet = $reader->load($inputFileName);
|
||||||
$inputFileName = './sampleData/example1.xls';
|
|
||||||
$sheetname = 'Data Sheet #2';
|
|
||||||
|
|
||||||
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
echo '<hr />';
|
||||||
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
|
||||||
echo 'Loading Sheet "',$sheetname,'" only<br />';
|
|
||||||
$reader->setLoadSheetsOnly($sheetname);
|
|
||||||
$spreadsheet = $reader->load($inputFileName);
|
|
||||||
|
|
||||||
echo '<hr />';
|
echo $spreadsheet->getSheetCount(), ' worksheet', (($spreadsheet->getSheetCount() == 1) ? '' : 's'), ' loaded<br /><br />';
|
||||||
|
$loadedSheetNames = $spreadsheet->getSheetNames();
|
||||||
echo $spreadsheet->getSheetCount(),' worksheet',(($spreadsheet->getSheetCount() == 1) ? '' : 's'),' loaded<br /><br />';
|
foreach ($loadedSheetNames as $sheetIndex => $loadedSheetName) {
|
||||||
$loadedSheetNames = $spreadsheet->getSheetNames();
|
echo $sheetIndex, ' -> ', $loadedSheetName, '<br />';
|
||||||
foreach ($loadedSheetNames as $sheetIndex => $loadedSheetName) {
|
}
|
||||||
echo $sheetIndex,' -> ',$loadedSheetName,'<br />';
|
?>
|
||||||
}
|
<body>
|
||||||
|
|
||||||
?>
|
|
||||||
<body>
|
|
||||||
</html>
|
</html>
|
|
@ -1,48 +1,43 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
|
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
|
|
||||||
date_default_timezone_set('Europe/London');
|
date_default_timezone_set('Europe/London');
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
|
||||||
<title>PhpSpreadsheet Reader Example #08</title>
|
<title>PhpSpreadsheet Reader Example #08</title>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h1>PhpSpreadsheet Reader Example #08</h1>
|
<h1>PhpSpreadsheet Reader Example #08</h1>
|
||||||
<h2>Simple File Reader Loading Several Named WorkSheets</h2>
|
<h2>Simple File Reader Loading Several Named WorkSheets</h2>
|
||||||
<?php
|
<?php
|
||||||
|
require_once __DIR__ . '/../../../src/Bootstrap.php';
|
||||||
|
|
||||||
require_once __DIR__ . '/../../../src/Bootstrap.php';
|
$inputFileType = 'Xls';
|
||||||
|
$inputFileName = './sampleData/example1.xls';
|
||||||
|
$sheetnames = ['Data Sheet #1', 'Data Sheet #3'];
|
||||||
|
|
||||||
$inputFileType = 'Xls';
|
echo 'Loading file ', pathinfo($inputFileName, PATHINFO_BASENAME), ' using IOFactory with a defined reader type of ', $inputFileType, '<br />';
|
||||||
// $inputFileType = 'Xlsx';
|
$reader = IOFactory::createReader($inputFileType);
|
||||||
// $inputFileType = 'Xml';
|
echo 'Loading Sheet', ((count($sheetnames) == 1) ? '' : 's'), ' "', implode('" and "', $sheetnames), '" only<br />';
|
||||||
// $inputFileType = 'Ods';
|
$reader->setLoadSheetsOnly($sheetnames);
|
||||||
// $inputFileType = 'Gnumeric';
|
$spreadsheet = $reader->load($inputFileName);
|
||||||
$inputFileName = './sampleData/example1.xls';
|
|
||||||
$sheetnames = ['Data Sheet #1', 'Data Sheet #3'];
|
|
||||||
|
|
||||||
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
echo '<hr />';
|
||||||
$reader = \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 $spreadsheet->getSheetCount(), ' worksheet', (($spreadsheet->getSheetCount() == 1) ? '' : 's'), ' loaded<br /><br />';
|
||||||
|
$loadedSheetNames = $spreadsheet->getSheetNames();
|
||||||
echo $spreadsheet->getSheetCount(),' worksheet',(($spreadsheet->getSheetCount() == 1) ? '' : 's'),' loaded<br /><br />';
|
foreach ($loadedSheetNames as $sheetIndex => $loadedSheetName) {
|
||||||
$loadedSheetNames = $spreadsheet->getSheetNames();
|
echo $sheetIndex, ' -> ', $loadedSheetName, '<br />';
|
||||||
foreach ($loadedSheetNames as $sheetIndex => $loadedSheetName) {
|
}
|
||||||
echo $sheetIndex,' -> ',$loadedSheetName,'<br />';
|
?>
|
||||||
}
|
<body>
|
||||||
|
|
||||||
?>
|
|
||||||
<body>
|
|
||||||
</html>
|
</html>
|
|
@ -1,64 +1,61 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Reader\IReadFilter;
|
||||||
|
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
|
|
||||||
date_default_timezone_set('Europe/London');
|
date_default_timezone_set('Europe/London');
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
|
||||||
<title>PhpSpreadsheet Reader Example #09</title>
|
<title>PhpSpreadsheet Reader Example #09</title>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h1>PhpSpreadsheet Reader Example #09</h1>
|
<h1>PhpSpreadsheet Reader Example #09</h1>
|
||||||
<h2>Simple File Reader Using a Read Filter</h2>
|
<h2>Simple File Reader Using a Read Filter</h2>
|
||||||
<?php
|
<?php
|
||||||
|
require_once __DIR__ . '/../../../src/Bootstrap.php';
|
||||||
|
|
||||||
require_once __DIR__ . '/../../../src/Bootstrap.php';
|
$inputFileType = 'Xls';
|
||||||
|
$inputFileName = './sampleData/example1.xls';
|
||||||
|
$sheetname = 'Data Sheet #3';
|
||||||
|
|
||||||
$inputFileType = 'Xls';
|
class MyReadFilter implements IReadFilter
|
||||||
// $inputFileType = 'Xlsx';
|
{
|
||||||
// $inputFileType = 'Xml';
|
public function readCell($column, $row, $worksheetName = '')
|
||||||
// $inputFileType = 'Ods';
|
{
|
||||||
// $inputFileType = 'Gnumeric';
|
// Read rows 1 to 7 and columns A to E only
|
||||||
$inputFileName = './sampleData/example1.xls';
|
if ($row >= 1 && $row <= 7) {
|
||||||
$sheetname = 'Data Sheet #3';
|
if (in_array($column, range('A', 'E'))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class MyReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter
|
return false;
|
||||||
{
|
|
||||||
public function readCell($column, $row, $worksheetName = '')
|
|
||||||
{
|
|
||||||
// Read rows 1 to 7 and columns A to E only
|
|
||||||
if ($row >= 1 && $row <= 7) {
|
|
||||||
if (in_array($column, range('A', 'E'))) {
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
$filterSubset = new MyReadFilter();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$filterSubset = new MyReadFilter();
|
echo 'Loading file ', pathinfo($inputFileName, PATHINFO_BASENAME), ' using IOFactory with a defined reader type of ', $inputFileType, '<br />';
|
||||||
|
$reader = IOFactory::createReader($inputFileType);
|
||||||
|
echo 'Loading Sheet "', $sheetname, '" only<br />';
|
||||||
|
$reader->setLoadSheetsOnly($sheetname);
|
||||||
|
echo 'Loading Sheet using filter<br />';
|
||||||
|
$reader->setReadFilter($filterSubset);
|
||||||
|
$spreadsheet = $reader->load($inputFileName);
|
||||||
|
|
||||||
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
echo '<hr />';
|
||||||
$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);
|
|
||||||
|
|
||||||
echo '<hr />';
|
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
|
||||||
|
var_dump($sheetData);
|
||||||
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
|
?>
|
||||||
var_dump($sheetData);
|
<body>
|
||||||
|
|
||||||
?>
|
|
||||||
<body>
|
|
||||||
</html>
|
</html>
|
|
@ -1,76 +1,72 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Reader\IReadFilter;
|
||||||
|
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
|
|
||||||
date_default_timezone_set('Europe/London');
|
date_default_timezone_set('Europe/London');
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
|
||||||
<title>PhpSpreadsheet Reader Example #10</title>
|
<title>PhpSpreadsheet Reader Example #10</title>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h1>PhpSpreadsheet Reader Example #10</h1>
|
<h1>PhpSpreadsheet Reader Example #10</h1>
|
||||||
<h2>Simple File Reader Using a Configurable Read Filter</h2>
|
<h2>Simple File Reader Using a Configurable Read Filter</h2>
|
||||||
<?php
|
<?php
|
||||||
|
require_once __DIR__ . '/../../../src/Bootstrap.php';
|
||||||
|
|
||||||
require_once __DIR__ . '/../../../src/Bootstrap.php';
|
$inputFileType = 'Xls';
|
||||||
|
$inputFileName = './sampleData/example1.xls';
|
||||||
|
$sheetname = 'Data Sheet #3';
|
||||||
|
|
||||||
$inputFileType = 'Xls';
|
class MyReadFilter implements IReadFilter
|
||||||
// $inputFileType = 'Xlsx';
|
{
|
||||||
// $inputFileType = 'Xml';
|
|
||||||
// $inputFileType = 'Ods';
|
|
||||||
// $inputFileType = 'Gnumeric';
|
|
||||||
$inputFileName = './sampleData/example1.xls';
|
|
||||||
$sheetname = 'Data Sheet #3';
|
|
||||||
|
|
||||||
class MyReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter
|
private $_startRow = 0;
|
||||||
{
|
private $_endRow = 0;
|
||||||
private $_startRow = 0;
|
private $_columns = [];
|
||||||
|
|
||||||
private $_endRow = 0;
|
public function __construct($startRow, $endRow, $columns)
|
||||||
|
{
|
||||||
private $_columns = [];
|
$this->_startRow = $startRow;
|
||||||
|
$this->_endRow = $endRow;
|
||||||
public function __construct($startRow, $endRow, $columns)
|
$this->_columns = $columns;
|
||||||
{
|
|
||||||
$this->_startRow = $startRow;
|
|
||||||
$this->_endRow = $endRow;
|
|
||||||
$this->_columns = $columns;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function readCell($column, $row, $worksheetName = '')
|
|
||||||
{
|
|
||||||
if ($row >= $this->_startRow && $row <= $this->_endRow) {
|
|
||||||
if (in_array($column, $this->_columns)) {
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function readCell($column, $row, $worksheetName = '')
|
||||||
|
{
|
||||||
|
if ($row >= $this->_startRow && $row <= $this->_endRow) {
|
||||||
|
if (in_array($column, $this->_columns)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
$filterSubset = new MyReadFilter(9, 15, range('G', 'K'));
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$filterSubset = new MyReadFilter(9, 15, range('G', 'K'));
|
echo 'Loading file ', pathinfo($inputFileName, PATHINFO_BASENAME), ' using IOFactory with a defined reader type of ', $inputFileType, '<br />';
|
||||||
|
$reader = IOFactory::createReader($inputFileType);
|
||||||
|
echo 'Loading Sheet "', $sheetname, '" only<br />';
|
||||||
|
$reader->setLoadSheetsOnly($sheetname);
|
||||||
|
echo 'Loading Sheet using configurable filter<br />';
|
||||||
|
$reader->setReadFilter($filterSubset);
|
||||||
|
$spreadsheet = $reader->load($inputFileName);
|
||||||
|
|
||||||
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
echo '<hr />';
|
||||||
$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);
|
|
||||||
|
|
||||||
echo '<hr />';
|
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
|
||||||
|
var_dump($sheetData);
|
||||||
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
|
?>
|
||||||
var_dump($sheetData);
|
<body>
|
||||||
|
|
||||||
?>
|
|
||||||
<body>
|
|
||||||
</html>
|
</html>
|
|
@ -1,89 +1,86 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Reader\IReadFilter;
|
||||||
|
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
|
|
||||||
date_default_timezone_set('Europe/London');
|
date_default_timezone_set('Europe/London');
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
|
||||||
<title>PhpSpreadsheet Reader Example #11</title>
|
<title>PhpSpreadsheet Reader Example #11</title>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h1>PhpSpreadsheet Reader Example #11</h1>
|
<h1>PhpSpreadsheet Reader Example #11</h1>
|
||||||
<h2>Reading a Workbook in "Chunks" Using a Configurable Read Filter (Version 1)</h2>
|
<h2>Reading a Workbook in "Chunks" Using a Configurable Read Filter (Version 1)</h2>
|
||||||
<?php
|
<?php
|
||||||
|
require_once __DIR__ . '/../../../src/Bootstrap.php';
|
||||||
|
|
||||||
require_once __DIR__ . '/../../../src/Bootstrap.php';
|
$inputFileType = 'Xls';
|
||||||
|
$inputFileName = './sampleData/example2.xls';
|
||||||
|
|
||||||
$inputFileType = 'Xls';
|
/** Define a Read Filter class implementing IReadFilter */
|
||||||
// $inputFileType = 'Xlsx';
|
class chunkReadFilter implements IReadFilter
|
||||||
// $inputFileType = 'Xml';
|
{
|
||||||
// $inputFileType = 'Ods';
|
|
||||||
// $inputFileType = 'Gnumeric';
|
|
||||||
$inputFileName = './sampleData/example2.xls';
|
|
||||||
|
|
||||||
/** Define a Read Filter class implementing \PhpOffice\PhpSpreadsheet\Reader\IReadFilter */
|
private $_startRow = 0;
|
||||||
class chunkReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter
|
private $_endRow = 0;
|
||||||
{
|
|
||||||
private $_startRow = 0;
|
|
||||||
|
|
||||||
private $_endRow = 0;
|
/**
|
||||||
|
* We expect a list of the rows that we want to read to be passed into the constructor.
|
||||||
|
*
|
||||||
|
* @param mixed $startRow
|
||||||
|
* @param mixed $chunkSize
|
||||||
|
*/
|
||||||
|
public function __construct($startRow, $chunkSize)
|
||||||
|
{
|
||||||
|
$this->_startRow = $startRow;
|
||||||
|
$this->_endRow = $startRow + $chunkSize;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
public function readCell($column, $row, $worksheetName = '')
|
||||||
* We expect a list of the rows that we want to read to be passed into the constructor.
|
{
|
||||||
*
|
// Only read the heading row, and the rows that were configured in the constructor
|
||||||
* @param mixed $startRow
|
if (($row == 1) || ($row >= $this->_startRow && $row < $this->_endRow)) {
|
||||||
* @param mixed $chunkSize
|
return true;
|
||||||
*/
|
}
|
||||||
public function __construct($startRow, $chunkSize)
|
|
||||||
{
|
return false;
|
||||||
$this->_startRow = $startRow;
|
}
|
||||||
$this->_endRow = $startRow + $chunkSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function readCell($column, $row, $worksheetName = '')
|
|
||||||
{
|
|
||||||
// Only read the heading row, and the rows that were configured in the constructor
|
|
||||||
if (($row == 1) || ($row >= $this->_startRow && $row < $this->_endRow)) {
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
echo 'Loading file ', pathinfo($inputFileName, PATHINFO_BASENAME), ' using IOFactory with a defined reader type of ', $inputFileType, '<br />';
|
||||||
}
|
/* Create a new Reader of the type defined in $inputFileType * */
|
||||||
}
|
$reader = IOFactory::createReader($inputFileType);
|
||||||
|
|
||||||
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
echo '<hr />';
|
||||||
/* Create a new Reader of the type defined in $inputFileType **/
|
|
||||||
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
|
||||||
|
|
||||||
echo '<hr />';
|
/* Define how many rows we want for each "chunk" * */
|
||||||
|
$chunkSize = 20;
|
||||||
|
|
||||||
/* Define how many rows we want for each "chunk" **/
|
/* Loop to read our worksheet in "chunk size" blocks * */
|
||||||
$chunkSize = 20;
|
for ($startRow = 2; $startRow <= 240; $startRow += $chunkSize) {
|
||||||
|
echo 'Loading WorkSheet using configurable filter for headings row 1 and for rows ', $startRow, ' to ', ($startRow + $chunkSize - 1), '<br />';
|
||||||
|
/* Create a new Instance of our Read Filter, passing in the limits on which rows we want to read * */
|
||||||
|
$chunkFilter = new chunkReadFilter($startRow, $chunkSize);
|
||||||
|
/* Tell the Reader that we want to use the new Read Filter that we've just Instantiated * */
|
||||||
|
$reader->setReadFilter($chunkFilter);
|
||||||
|
/* Load only the rows that match our filter from $inputFileName to a PhpSpreadsheet Object * */
|
||||||
|
$spreadsheet = $reader->load($inputFileName);
|
||||||
|
|
||||||
/* Loop to read our worksheet in "chunk size" blocks **/
|
// Do some processing here
|
||||||
for ($startRow = 2; $startRow <= 240; $startRow += $chunkSize) {
|
|
||||||
echo 'Loading WorkSheet using configurable filter for headings row 1 and for rows ',$startRow,' to ',($startRow + $chunkSize - 1),'<br />';
|
|
||||||
/* Create a new Instance of our Read Filter, passing in the limits on which rows we want to read **/
|
|
||||||
$chunkFilter = new chunkReadFilter($startRow, $chunkSize);
|
|
||||||
/* Tell the Reader that we want to use the new Read Filter that we've just Instantiated **/
|
|
||||||
$reader->setReadFilter($chunkFilter);
|
|
||||||
/* Load only the rows that match our filter from $inputFileName to a PhpSpreadsheet Object **/
|
|
||||||
$spreadsheet = $reader->load($inputFileName);
|
|
||||||
|
|
||||||
// Do some processing here
|
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
|
||||||
|
var_dump($sheetData);
|
||||||
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
|
echo '<br /><br />';
|
||||||
var_dump($sheetData);
|
}
|
||||||
echo '<br /><br />';
|
?>
|
||||||
}
|
<body>
|
||||||
|
|
||||||
?>
|
|
||||||
<body>
|
|
||||||
</html>
|
</html>
|
|
@ -1,92 +1,89 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Reader\IReadFilter;
|
||||||
|
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
|
|
||||||
date_default_timezone_set('Europe/London');
|
date_default_timezone_set('Europe/London');
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
|
||||||
<title>PhpSpreadsheet Reader Example #12</title>
|
<title>PhpSpreadsheet Reader Example #12</title>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h1>PhpSpreadsheet Reader Example #12</h1>
|
<h1>PhpSpreadsheet Reader Example #12</h1>
|
||||||
<h2>Reading a Workbook in "Chunks" Using a Configurable Read Filter (Version 2)</h2>
|
<h2>Reading a Workbook in "Chunks" Using a Configurable Read Filter (Version 2)</h2>
|
||||||
<?php
|
<?php
|
||||||
|
require_once __DIR__ . '/../../../src/Bootstrap.php';
|
||||||
|
|
||||||
require_once __DIR__ . '/../../../src/Bootstrap.php';
|
$inputFileType = 'Xls';
|
||||||
|
$inputFileName = './sampleData/example2.xls';
|
||||||
|
|
||||||
$inputFileType = 'Xls';
|
/** Define a Read Filter class implementing IReadFilter */
|
||||||
// $inputFileType = 'Xlsx';
|
class chunkReadFilter implements IReadFilter
|
||||||
// $inputFileType = 'Xml';
|
{
|
||||||
// $inputFileType = 'Ods';
|
|
||||||
// $inputFileType = 'Gnumeric';
|
|
||||||
$inputFileName = './sampleData/example2.xls';
|
|
||||||
|
|
||||||
/** Define a Read Filter class implementing \PhpOffice\PhpSpreadsheet\Reader\IReadFilter */
|
private $_startRow = 0;
|
||||||
class chunkReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter
|
private $_endRow = 0;
|
||||||
{
|
|
||||||
private $_startRow = 0;
|
|
||||||
|
|
||||||
private $_endRow = 0;
|
/**
|
||||||
|
* Set the list of rows that we want to read.
|
||||||
|
*
|
||||||
|
* @param mixed $startRow
|
||||||
|
* @param mixed $chunkSize
|
||||||
|
*/
|
||||||
|
public function setRows($startRow, $chunkSize)
|
||||||
|
{
|
||||||
|
$this->_startRow = $startRow;
|
||||||
|
$this->_endRow = $startRow + $chunkSize;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
public function readCell($column, $row, $worksheetName = '')
|
||||||
* Set the list of rows that we want to read.
|
{
|
||||||
*
|
// Only read the heading row, and the rows that are configured in $this->_startRow and $this->_endRow
|
||||||
* @param mixed $startRow
|
if (($row == 1) || ($row >= $this->_startRow && $row < $this->_endRow)) {
|
||||||
* @param mixed $chunkSize
|
return true;
|
||||||
*/
|
}
|
||||||
public function setRows($startRow, $chunkSize)
|
|
||||||
{
|
return false;
|
||||||
$this->_startRow = $startRow;
|
}
|
||||||
$this->_endRow = $startRow + $chunkSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function readCell($column, $row, $worksheetName = '')
|
|
||||||
{
|
|
||||||
// Only read the heading row, and the rows that are configured in $this->_startRow and $this->_endRow
|
|
||||||
if (($row == 1) || ($row >= $this->_startRow && $row < $this->_endRow)) {
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
echo 'Loading file ', pathinfo($inputFileName, PATHINFO_BASENAME), ' using IOFactory with a defined reader type of ', $inputFileType, '<br />';
|
||||||
}
|
/* Create a new Reader of the type defined in $inputFileType * */
|
||||||
}
|
$reader = IOFactory::createReader($inputFileType);
|
||||||
|
|
||||||
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
echo '<hr />';
|
||||||
/* Create a new Reader of the type defined in $inputFileType **/
|
|
||||||
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
|
||||||
|
|
||||||
echo '<hr />';
|
/* Define how many rows we want to read for each "chunk" * */
|
||||||
|
$chunkSize = 20;
|
||||||
|
/* Create a new Instance of our Read Filter * */
|
||||||
|
$chunkFilter = new chunkReadFilter();
|
||||||
|
|
||||||
/* Define how many rows we want to read for each "chunk" **/
|
/* Tell the Reader that we want to use the Read Filter that we've Instantiated * */
|
||||||
$chunkSize = 20;
|
$reader->setReadFilter($chunkFilter);
|
||||||
/* Create a new Instance of our Read Filter **/
|
|
||||||
$chunkFilter = new chunkReadFilter();
|
|
||||||
|
|
||||||
/* Tell the Reader that we want to use the Read Filter that we've Instantiated **/
|
/* Loop to read our worksheet in "chunk size" blocks * */
|
||||||
$reader->setReadFilter($chunkFilter);
|
for ($startRow = 2; $startRow <= 240; $startRow += $chunkSize) {
|
||||||
|
echo 'Loading WorkSheet using configurable filter for headings row 1 and for rows ', $startRow, ' to ', ($startRow + $chunkSize - 1), '<br />';
|
||||||
|
/* Tell the Read Filter, the limits on which rows we want to read this iteration * */
|
||||||
|
$chunkFilter->setRows($startRow, $chunkSize);
|
||||||
|
/* Load only the rows that match our filter from $inputFileName to a PhpSpreadsheet Object * */
|
||||||
|
$spreadsheet = $reader->load($inputFileName);
|
||||||
|
|
||||||
/* Loop to read our worksheet in "chunk size" blocks **/
|
// Do some processing here
|
||||||
for ($startRow = 2; $startRow <= 240; $startRow += $chunkSize) {
|
|
||||||
echo 'Loading WorkSheet using configurable filter for headings row 1 and for rows ', $startRow, ' to ', ($startRow + $chunkSize - 1), '<br />';
|
|
||||||
/* Tell the Read Filter, the limits on which rows we want to read this iteration **/
|
|
||||||
$chunkFilter->setRows($startRow, $chunkSize);
|
|
||||||
/* Load only the rows that match our filter from $inputFileName to a PhpSpreadsheet Object **/
|
|
||||||
$spreadsheet = $reader->load($inputFileName);
|
|
||||||
|
|
||||||
// Do some processing here
|
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
|
||||||
|
var_dump($sheetData);
|
||||||
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
|
echo '<br /><br />';
|
||||||
var_dump($sheetData);
|
}
|
||||||
echo '<br /><br />';
|
?>
|
||||||
}
|
<body>
|
||||||
|
|
||||||
?>
|
|
||||||
<body>
|
|
||||||
</html>
|
</html>
|
|
@ -1,53 +1,52 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
|
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
|
|
||||||
date_default_timezone_set('Europe/London');
|
date_default_timezone_set('Europe/London');
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
|
||||||
<title>PhpSpreadsheet Reader Example #13</title>
|
<title>PhpSpreadsheet Reader Example #13</title>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h1>PhpSpreadsheet Reader Example #13</h1>
|
<h1>PhpSpreadsheet Reader Example #13</h1>
|
||||||
<h2>Simple File Reader for Multiple CSV Files</h2>
|
<h2>Simple File Reader for Multiple CSV Files</h2>
|
||||||
<?php
|
<?php
|
||||||
|
require_once __DIR__ . '/../../../src/Bootstrap.php';
|
||||||
|
|
||||||
require_once __DIR__ . '/../../../src/Bootstrap.php';
|
$inputFileType = 'Csv';
|
||||||
|
$inputFileNames = ['./sampleData/example1.csv', './sampleData/example2.csv'];
|
||||||
|
|
||||||
$inputFileType = 'Csv';
|
$reader = IOFactory::createReader($inputFileType);
|
||||||
$inputFileNames = ['./sampleData/example1.csv', './sampleData/example2.csv'];
|
$inputFileName = array_shift($inputFileNames);
|
||||||
|
echo 'Loading file ', pathinfo($inputFileName, PATHINFO_BASENAME), ' into WorkSheet #1 using IOFactory with a defined reader type of ', $inputFileType, '<br />';
|
||||||
|
$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));
|
||||||
|
}
|
||||||
|
|
||||||
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
echo '<hr />';
|
||||||
$inputFileName = array_shift($inputFileNames);
|
|
||||||
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' into WorkSheet #1 using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
|
||||||
$spreadsheet = $reader->load($inputFileName);
|
|
||||||
$spreadsheet->getActiveSheet()->setTitle(pathinfo($inputFileName, PATHINFO_BASENAME));
|
|
||||||
foreach ($inputFileNames as $sheet => $inputFileName) {
|
|
||||||
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' into WorkSheet #',($sheet + 2),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
|
||||||
$reader->setSheetIndex($sheet + 1);
|
|
||||||
$reader->loadIntoExisting($inputFileName, $spreadsheet);
|
|
||||||
$spreadsheet->getActiveSheet()->setTitle(pathinfo($inputFileName, PATHINFO_BASENAME));
|
|
||||||
}
|
|
||||||
|
|
||||||
echo '<hr />';
|
echo $spreadsheet->getSheetCount(), ' worksheet', (($spreadsheet->getSheetCount() == 1) ? '' : 's'), ' loaded<br /><br />';
|
||||||
|
$loadedSheetNames = $spreadsheet->getSheetNames();
|
||||||
echo $spreadsheet->getSheetCount(), ' worksheet', (($spreadsheet->getSheetCount() == 1) ? '' : 's'), ' loaded<br /><br />';
|
foreach ($loadedSheetNames as $sheetIndex => $loadedSheetName) {
|
||||||
$loadedSheetNames = $spreadsheet->getSheetNames();
|
echo '<b>Worksheet #', $sheetIndex, ' -> ', $loadedSheetName, '</b><br />';
|
||||||
foreach ($loadedSheetNames as $sheetIndex => $loadedSheetName) {
|
$spreadsheet->setActiveSheetIndexByName($loadedSheetName);
|
||||||
echo '<b>Worksheet #', $sheetIndex, ' -> ', $loadedSheetName, '</b><br />';
|
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
|
||||||
$spreadsheet->setActiveSheetIndexByName($loadedSheetName);
|
var_dump($sheetData);
|
||||||
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
|
echo '<br /><br />';
|
||||||
var_dump($sheetData);
|
}
|
||||||
echo '<br /><br />';
|
?>
|
||||||
}
|
<body>
|
||||||
|
|
||||||
?>
|
|
||||||
<body>
|
|
||||||
</html>
|
</html>
|
|
@ -1,108 +1,110 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Reader\IReadFilter;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
|
|
||||||
date_default_timezone_set('Europe/London');
|
date_default_timezone_set('Europe/London');
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
|
||||||
<title>PhpSpreadsheet Reader Example #14</title>
|
<title>PhpSpreadsheet Reader Example #14</title>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h1>PhpSpreadsheet Reader Example #14</h1>
|
<h1>PhpSpreadsheet Reader Example #14</h1>
|
||||||
<h2>Reading a Large CSV file in "Chunks" to split across multiple Worksheets</h2>
|
<h2>Reading a Large CSV file in "Chunks" to split across multiple Worksheets</h2>
|
||||||
<?php
|
<?php
|
||||||
|
require_once __DIR__ . '/../../../src/Bootstrap.php';
|
||||||
|
|
||||||
require_once __DIR__ . '/../../../src/Bootstrap.php';
|
$inputFileType = 'Csv';
|
||||||
|
$inputFileName = './sampleData/example2.csv';
|
||||||
|
|
||||||
$inputFileType = 'Csv';
|
/** Define a Read Filter class implementing IReadFilter */
|
||||||
$inputFileName = './sampleData/example2.csv';
|
class chunkReadFilter implements IReadFilter
|
||||||
|
{
|
||||||
|
|
||||||
/** Define a Read Filter class implementing \PhpOffice\PhpSpreadsheet\Reader\IReadFilter */
|
private $_startRow = 0;
|
||||||
class chunkReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter
|
private $_endRow = 0;
|
||||||
{
|
|
||||||
private $_startRow = 0;
|
|
||||||
|
|
||||||
private $_endRow = 0;
|
/**
|
||||||
|
* Set the list of rows that we want to read.
|
||||||
|
*
|
||||||
|
* @param mixed $startRow
|
||||||
|
* @param mixed $chunkSize
|
||||||
|
*/
|
||||||
|
public function setRows($startRow, $chunkSize)
|
||||||
|
{
|
||||||
|
$this->_startRow = $startRow;
|
||||||
|
$this->_endRow = $startRow + $chunkSize;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
public function readCell($column, $row, $worksheetName = '')
|
||||||
* Set the list of rows that we want to read.
|
{
|
||||||
*
|
// Only read the heading row, and the rows that are configured in $this->_startRow and $this->_endRow
|
||||||
* @param mixed $startRow
|
if (($row == 1) || ($row >= $this->_startRow && $row < $this->_endRow)) {
|
||||||
* @param mixed $chunkSize
|
return true;
|
||||||
*/
|
}
|
||||||
public function setRows($startRow, $chunkSize)
|
|
||||||
{
|
return false;
|
||||||
$this->_startRow = $startRow;
|
}
|
||||||
$this->_endRow = $startRow + $chunkSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function readCell($column, $row, $worksheetName = '')
|
|
||||||
{
|
|
||||||
// Only read the heading row, and the rows that are configured in $this->_startRow and $this->_endRow
|
|
||||||
if (($row == 1) || ($row >= $this->_startRow && $row < $this->_endRow)) {
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
echo 'Loading file ', pathinfo($inputFileName, PATHINFO_BASENAME), ' using IOFactory with a defined reader type of ', $inputFileType, '<br />';
|
||||||
}
|
/* Create a new Reader of the type defined in $inputFileType * */
|
||||||
}
|
$reader = IOFactory::createReader($inputFileType);
|
||||||
|
|
||||||
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
echo '<hr />';
|
||||||
/* Create a new Reader of the type defined in $inputFileType **/
|
|
||||||
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
|
||||||
|
|
||||||
echo '<hr />';
|
/* Define how many rows we want to read for each "chunk" * */
|
||||||
|
$chunkSize = 100;
|
||||||
|
/* Create a new Instance of our Read Filter * */
|
||||||
|
$chunkFilter = new chunkReadFilter();
|
||||||
|
|
||||||
/* Define how many rows we want to read for each "chunk" **/
|
/* Tell the Reader that we want to use the Read Filter that we've Instantiated * */
|
||||||
$chunkSize = 100;
|
/* and that we want to store it in contiguous rows/columns * */
|
||||||
/* Create a new Instance of our Read Filter **/
|
$reader->setReadFilter($chunkFilter)
|
||||||
$chunkFilter = new chunkReadFilter();
|
->setContiguous(true);
|
||||||
|
|
||||||
/* Tell the Reader that we want to use the Read Filter that we've Instantiated **/
|
/* Instantiate a new PhpSpreadsheet object manually * */
|
||||||
/* and that we want to store it in contiguous rows/columns **/
|
$spreadsheet = new Spreadsheet();
|
||||||
$reader->setReadFilter($chunkFilter)
|
|
||||||
->setContiguous(true);
|
|
||||||
|
|
||||||
/* Instantiate a new PhpSpreadsheet object manually **/
|
/* Set a sheet index * */
|
||||||
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$sheet = 0;
|
||||||
|
/* Loop to read our worksheet in "chunk size" blocks * */
|
||||||
|
/** $startRow is set to 2 initially because we always read the headings in row #1 * */
|
||||||
|
for ($startRow = 2; $startRow <= 240; $startRow += $chunkSize) {
|
||||||
|
echo 'Loading WorkSheet #', ($sheet + 1), ' using configurable filter for headings row 1 and for rows ', $startRow, ' to ', ($startRow + $chunkSize - 1), '<br />';
|
||||||
|
/* Tell the Read Filter, the limits on which rows we want to read this iteration * */
|
||||||
|
$chunkFilter->setRows($startRow, $chunkSize);
|
||||||
|
|
||||||
/* Set a sheet index **/
|
/* Increment the worksheet index pointer for the Reader * */
|
||||||
$sheet = 0;
|
$reader->setSheetIndex($sheet);
|
||||||
/* Loop to read our worksheet in "chunk size" blocks **/
|
/* Load only the rows that match our filter into a new worksheet in the PhpSpreadsheet Object * */
|
||||||
/** $startRow is set to 2 initially because we always read the headings in row #1 **/
|
$reader->loadIntoExisting($inputFileName, $spreadsheet);
|
||||||
for ($startRow = 2; $startRow <= 240; $startRow += $chunkSize) {
|
/* Set the worksheet title (to reference the "sheet" of data that we've loaded) * */
|
||||||
echo 'Loading WorkSheet #', ($sheet + 1), ' using configurable filter for headings row 1 and for rows ', $startRow, ' to ', ($startRow + $chunkSize - 1), '<br />';
|
/* and increment the sheet index as well * */
|
||||||
/* Tell the Read Filter, the limits on which rows we want to read this iteration **/
|
$spreadsheet->getActiveSheet()->setTitle('Country Data #' . ( ++$sheet));
|
||||||
$chunkFilter->setRows($startRow, $chunkSize);
|
}
|
||||||
|
|
||||||
/* Increment the worksheet index pointer for the Reader **/
|
echo '<hr />';
|
||||||
$reader->setSheetIndex($sheet);
|
|
||||||
/* Load only the rows that match our filter into a new worksheet in the PhpSpreadsheet Object **/
|
|
||||||
$reader->loadIntoExisting($inputFileName, $spreadsheet);
|
|
||||||
/* Set the worksheet title (to reference the "sheet" of data that we've loaded) **/
|
|
||||||
/* and increment the sheet index as well **/
|
|
||||||
$spreadsheet->getActiveSheet()->setTitle('Country Data #' . (++$sheet));
|
|
||||||
}
|
|
||||||
|
|
||||||
echo '<hr />';
|
echo $spreadsheet->getSheetCount(), ' worksheet', (($spreadsheet->getSheetCount() == 1) ? '' : 's'), ' loaded<br /><br />';
|
||||||
|
$loadedSheetNames = $spreadsheet->getSheetNames();
|
||||||
echo $spreadsheet->getSheetCount(), ' worksheet', (($spreadsheet->getSheetCount() == 1) ? '' : 's'), ' loaded<br /><br />';
|
foreach ($loadedSheetNames as $sheetIndex => $loadedSheetName) {
|
||||||
$loadedSheetNames = $spreadsheet->getSheetNames();
|
echo '<b>Worksheet #', $sheetIndex, ' -> ', $loadedSheetName, '</b><br />';
|
||||||
foreach ($loadedSheetNames as $sheetIndex => $loadedSheetName) {
|
$spreadsheet->setActiveSheetIndexByName($loadedSheetName);
|
||||||
echo '<b>Worksheet #', $sheetIndex, ' -> ', $loadedSheetName, '</b><br />';
|
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, false, false, true);
|
||||||
$spreadsheet->setActiveSheetIndexByName($loadedSheetName);
|
var_dump($sheetData);
|
||||||
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, false, false, true);
|
echo '<br />';
|
||||||
var_dump($sheetData);
|
}
|
||||||
echo '<br />';
|
?>
|
||||||
}
|
<body>
|
||||||
|
|
||||||
?>
|
|
||||||
<body>
|
|
||||||
</html>
|
</html>
|
|
@ -1,69 +1,69 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Cell;
|
||||||
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
|
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
|
|
||||||
date_default_timezone_set('Europe/London');
|
date_default_timezone_set('Europe/London');
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
|
||||||
<title>PhpSpreadsheet Reader Example #15</title>
|
<title>PhpSpreadsheet Reader Example #15</title>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h1>PhpSpreadsheet Reader Example #15</h1>
|
<h1>PhpSpreadsheet Reader Example #15</h1>
|
||||||
<h2>Simple File Reader for Tab-Separated Value File using the Advanced Value Binder</h2>
|
<h2>Simple File Reader for Tab-Separated Value File using the Advanced Value Binder</h2>
|
||||||
<?php
|
<?php
|
||||||
|
require_once __DIR__ . '/../../../src/Bootstrap.php';
|
||||||
|
|
||||||
require_once __DIR__ . '/../../../src/Bootstrap.php';
|
Cell::setValueBinder(new Cell\AdvancedValueBinder());
|
||||||
|
|
||||||
\PhpOffice\PhpSpreadsheet\Cell::setValueBinder(new \PhpOffice\PhpSpreadsheet\Cell\AdvancedValueBinder());
|
$inputFileType = 'Csv';
|
||||||
|
$inputFileName = './sampleData/example1.tsv';
|
||||||
|
|
||||||
$inputFileType = 'Csv';
|
$reader = IOFactory::createReader($inputFileType);
|
||||||
$inputFileName = './sampleData/example1.tsv';
|
echo 'Loading file ', pathinfo($inputFileName, PATHINFO_BASENAME), ' into WorkSheet #1 using IOFactory with a defined reader type of ', $inputFileType, '<br />';
|
||||||
|
$reader->setDelimiter("\t");
|
||||||
|
$spreadsheet = $reader->load($inputFileName);
|
||||||
|
$spreadsheet->getActiveSheet()->setTitle(pathinfo($inputFileName, PATHINFO_BASENAME));
|
||||||
|
|
||||||
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
echo '<hr />';
|
||||||
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' into WorkSheet #1 using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
|
||||||
$reader->setDelimiter("\t");
|
|
||||||
$spreadsheet = $reader->load($inputFileName);
|
|
||||||
$spreadsheet->getActiveSheet()->setTitle(pathinfo($inputFileName, PATHINFO_BASENAME));
|
|
||||||
|
|
||||||
echo '<hr />';
|
echo $spreadsheet->getSheetCount(), ' worksheet', (($spreadsheet->getSheetCount() == 1) ? '' : 's'), ' loaded<br /><br />';
|
||||||
|
$loadedSheetNames = $spreadsheet->getSheetNames();
|
||||||
|
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 $spreadsheet->getSheetCount(),' worksheet',(($spreadsheet->getSheetCount() == 1) ? '' : 's'),' loaded<br /><br />';
|
echo '<hr />';
|
||||||
$loadedSheetNames = $spreadsheet->getSheetNames();
|
|
||||||
foreach ($loadedSheetNames as $sheetIndex => $loadedSheetName) {
|
|
||||||
echo '<b>Worksheet #',$sheetIndex,' -> ',$loadedSheetName,' (Formatted)</b><br />';
|
|
||||||
$spreadsheet->setActiveSheetIndexByName($loadedSheetName);
|
|
||||||
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
|
|
||||||
var_dump($sheetData);
|
|
||||||
echo '<br />';
|
|
||||||
}
|
|
||||||
|
|
||||||
echo '<hr />';
|
foreach ($loadedSheetNames as $sheetIndex => $loadedSheetName) {
|
||||||
|
echo '<b>Worksheet #', $sheetIndex, ' -> ', $loadedSheetName, ' (Unformatted)</b><br />';
|
||||||
|
$spreadsheet->setActiveSheetIndexByName($loadedSheetName);
|
||||||
|
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, false, true);
|
||||||
|
var_dump($sheetData);
|
||||||
|
echo '<br />';
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($loadedSheetNames as $sheetIndex => $loadedSheetName) {
|
echo '<hr />';
|
||||||
echo '<b>Worksheet #', $sheetIndex, ' -> ', $loadedSheetName, ' (Unformatted)</b><br />';
|
|
||||||
$spreadsheet->setActiveSheetIndexByName($loadedSheetName);
|
|
||||||
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, false, true);
|
|
||||||
var_dump($sheetData);
|
|
||||||
echo '<br />';
|
|
||||||
}
|
|
||||||
|
|
||||||
echo '<hr />';
|
foreach ($loadedSheetNames as $sheetIndex => $loadedSheetName) {
|
||||||
|
echo '<b>Worksheet #', $sheetIndex, ' -> ', $loadedSheetName, ' (Raw)</b><br />';
|
||||||
foreach ($loadedSheetNames as $sheetIndex => $loadedSheetName) {
|
$spreadsheet->setActiveSheetIndexByName($loadedSheetName);
|
||||||
echo '<b>Worksheet #', $sheetIndex, ' -> ', $loadedSheetName, ' (Raw)</b><br />';
|
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, false, false, true);
|
||||||
$spreadsheet->setActiveSheetIndexByName($loadedSheetName);
|
var_dump($sheetData);
|
||||||
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, false, false, true);
|
echo '<br />';
|
||||||
var_dump($sheetData);
|
}
|
||||||
echo '<br />';
|
?>
|
||||||
}
|
<body>
|
||||||
|
|
||||||
?>
|
|
||||||
<body>
|
|
||||||
</html>
|
</html>
|
|
@ -1,39 +1,39 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use InvalidArgumentException;
|
||||||
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
|
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
|
|
||||||
date_default_timezone_set('Europe/London');
|
date_default_timezone_set('Europe/London');
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
|
||||||
<title>PhpSpreadsheet Reader Example #16</title>
|
<title>PhpSpreadsheet Reader Example #16</title>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h1>PhpSpreadsheet Reader Example #16</h1>
|
<h1>PhpSpreadsheet Reader Example #16</h1>
|
||||||
<h2>Handling Loader Exceptions using Try/Catch</h2>
|
<h2>Handling Loader Exceptions using Try/Catch</h2>
|
||||||
<?php
|
<?php
|
||||||
|
require_once __DIR__ . '/../../../src/Bootstrap.php';
|
||||||
|
|
||||||
require_once __DIR__ . '/../../../src/Bootstrap.php';
|
$inputFileName = './sampleData/example_1.xls';
|
||||||
|
echo 'Loading file ', pathinfo($inputFileName, PATHINFO_BASENAME), ' using IOFactory to identify the format<br />';
|
||||||
|
try {
|
||||||
|
$spreadsheet = IOFactory::load($inputFileName);
|
||||||
|
} catch (InvalidArgumentException $e) {
|
||||||
|
die('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' . $e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
$inputFileName = './sampleData/example_1.xls';
|
echo '<hr />';
|
||||||
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory to identify the format<br />';
|
|
||||||
try {
|
|
||||||
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($inputFileName);
|
|
||||||
} catch (\InvalidArgumentException $e) {
|
|
||||||
die('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' . $e->getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
echo '<hr />';
|
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
|
||||||
|
var_dump($sheetData);
|
||||||
$sheetData = $spreadsheet->getActiveSheet()->toArray(null, true, true, true);
|
?>
|
||||||
var_dump($sheetData);
|
<body>
|
||||||
|
|
||||||
?>
|
|
||||||
<body>
|
|
||||||
</html>
|
</html>
|
|
@ -1,45 +1,40 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
|
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
|
|
||||||
date_default_timezone_set('Europe/London');
|
date_default_timezone_set('Europe/London');
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
|
||||||
<title>PhpSpreadsheet Reader Example #17</title>
|
<title>PhpSpreadsheet Reader Example #17</title>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h1>PhpSpreadsheet Reader Example #17</h1>
|
<h1>PhpSpreadsheet Reader Example #17</h1>
|
||||||
<h2>Simple File Reader Loading Several Named WorkSheets</h2>
|
<h2>Simple File Reader Loading Several Named WorkSheets</h2>
|
||||||
<?php
|
<?php
|
||||||
|
require_once __DIR__ . '/../../../src/Bootstrap.php';
|
||||||
|
|
||||||
require_once __DIR__ . '/../../../src/Bootstrap.php';
|
$inputFileType = 'Xls';
|
||||||
|
$inputFileName = './sampleData/example1.xls';
|
||||||
|
|
||||||
$inputFileType = 'Xls';
|
echo 'Loading file ', pathinfo($inputFileName, PATHINFO_BASENAME), ' using IOFactory with a defined reader type of ', $inputFileType, '<br />';
|
||||||
// $inputFileType = 'Xlsx';
|
$reader = IOFactory::createReader($inputFileType);
|
||||||
// $inputFileType = 'Xml';
|
|
||||||
// $inputFileType = 'Ods';
|
|
||||||
// $inputFileType = 'Gnumeric';
|
|
||||||
$inputFileName = './sampleData/example1.xls';
|
|
||||||
|
|
||||||
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
/* Read the list of Worksheet Names from the Workbook file * */
|
||||||
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
echo 'Read the list of Worksheets in the WorkBook<br />';
|
||||||
|
$worksheetNames = $reader->listWorksheetNames($inputFileName);
|
||||||
|
|
||||||
/* Read the list of Worksheet Names from the Workbook file **/
|
echo 'There are ', count($worksheetNames), ' worksheet', ((count($worksheetNames) == 1) ? '' : 's'), ' in the workbook<br /><br />';
|
||||||
echo 'Read the list of Worksheets in the WorkBook<br />';
|
foreach ($worksheetNames as $worksheetName) {
|
||||||
$worksheetNames = $reader->listWorksheetNames($inputFileName);
|
echo $worksheetName, '<br />';
|
||||||
|
}
|
||||||
echo 'There are ',count($worksheetNames),' worksheet',((count($worksheetNames) == 1) ? '' : 's'),' in the workbook<br /><br />';
|
?>
|
||||||
foreach ($worksheetNames as $worksheetName) {
|
<body>
|
||||||
echo $worksheetName,'<br />';
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
||||||
<body>
|
|
||||||
</html>
|
</html>
|
|
@ -1,45 +1,40 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
|
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
|
|
||||||
date_default_timezone_set('Europe/London');
|
date_default_timezone_set('Europe/London');
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
|
||||||
<title>PhpSpreadsheet Reader Example #18</title>
|
<title>PhpSpreadsheet Reader Example #18</title>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h1>PhpSpreadsheet Reader Example #18</h1>
|
<h1>PhpSpreadsheet Reader Example #18</h1>
|
||||||
<h2>Reading list of WorkSheets without loading entire file</h2>
|
<h2>Reading list of WorkSheets without loading entire file</h2>
|
||||||
<?php
|
<?php
|
||||||
|
require_once __DIR__ . '/../../../src/Bootstrap.php';
|
||||||
|
|
||||||
require_once __DIR__ . '/../../../src/Bootstrap.php';
|
$inputFileType = 'Xls';
|
||||||
|
$inputFileName = './sampleData/example1.xls';
|
||||||
|
|
||||||
$inputFileType = 'Xls';
|
echo 'Loading file ', pathinfo($inputFileName, PATHINFO_BASENAME), ' information using IOFactory with a defined reader type of ', $inputFileType, '<br />';
|
||||||
// $inputFileType = 'Xlsx';
|
|
||||||
// $inputFileType = 'Xml';
|
|
||||||
// $inputFileType = 'Ods';
|
|
||||||
// $inputFileType = 'Gnumeric';
|
|
||||||
$inputFileName = './sampleData/example1.xls';
|
|
||||||
|
|
||||||
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' information using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
$reader = IOFactory::createReader($inputFileType);
|
||||||
|
$worksheetNames = $reader->listWorksheetNames($inputFileName);
|
||||||
|
|
||||||
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
echo '<h3>Worksheet Names</h3>';
|
||||||
$worksheetNames = $reader->listWorksheetNames($inputFileName);
|
echo '<ol>';
|
||||||
|
foreach ($worksheetNames as $worksheetName) {
|
||||||
echo '<h3>Worksheet Names</h3>';
|
echo '<li>', $worksheetName, '</li>';
|
||||||
echo '<ol>';
|
}
|
||||||
foreach ($worksheetNames as $worksheetName) {
|
echo '</ol>';
|
||||||
echo '<li>', $worksheetName, '</li>';
|
?>
|
||||||
}
|
<body>
|
||||||
echo '</ol>';
|
|
||||||
|
|
||||||
?>
|
|
||||||
<body>
|
|
||||||
</html>
|
</html>
|
|
@ -1,48 +1,43 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
|
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
|
|
||||||
date_default_timezone_set('Europe/London');
|
date_default_timezone_set('Europe/London');
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
|
||||||
<title>PhpSpreadsheet Reader Example #19</title>
|
<title>PhpSpreadsheet Reader Example #19</title>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h1>PhpSpreadsheet Reader Example #19</h1>
|
<h1>PhpSpreadsheet Reader Example #19</h1>
|
||||||
<h2>Reading WorkSheet information without loading entire file</h2>
|
<h2>Reading WorkSheet information without loading entire file</h2>
|
||||||
<?php
|
<?php
|
||||||
|
require_once __DIR__ . '/../../../src/Bootstrap.php';
|
||||||
|
|
||||||
require_once __DIR__ . '/../../../src/Bootstrap.php';
|
$inputFileType = 'Xls';
|
||||||
|
$inputFileName = './sampleData/example1.xls';
|
||||||
|
|
||||||
$inputFileType = 'Xls';
|
echo 'Loading file ', pathinfo($inputFileName, PATHINFO_BASENAME), ' information using IOFactory with a defined reader type of ', $inputFileType, '<br />';
|
||||||
// $inputFileType = 'Xlsx';
|
|
||||||
// $inputFileType = 'Xml';
|
|
||||||
// $inputFileType = 'Ods';
|
|
||||||
// $inputFileType = 'Gnumeric';
|
|
||||||
$inputFileName = './sampleData/example1.xls';
|
|
||||||
|
|
||||||
echo 'Loading file ',pathinfo($inputFileName, PATHINFO_BASENAME),' information using IOFactory with a defined reader type of ',$inputFileType,'<br />';
|
$reader = IOFactory::createReader($inputFileType);
|
||||||
|
$worksheetData = $reader->listWorksheetInfo($inputFileName);
|
||||||
|
|
||||||
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
echo '<h3>Worksheet Information</h3>';
|
||||||
$worksheetData = $reader->listWorksheetInfo($inputFileName);
|
echo '<ol>';
|
||||||
|
foreach ($worksheetData as $worksheet) {
|
||||||
echo '<h3>Worksheet Information</h3>';
|
echo '<li>', $worksheet['worksheetName'], '<br />';
|
||||||
echo '<ol>';
|
echo 'Rows: ', $worksheet['totalRows'], ' Columns: ', $worksheet['totalColumns'], '<br />';
|
||||||
foreach ($worksheetData as $worksheet) {
|
echo 'Cell Range: A1:', $worksheet['lastColumnLetter'], $worksheet['totalRows'];
|
||||||
echo '<li>', $worksheet['worksheetName'], '<br />';
|
echo '</li>';
|
||||||
echo 'Rows: ', $worksheet['totalRows'], ' Columns: ', $worksheet['totalColumns'], '<br />';
|
}
|
||||||
echo 'Cell Range: A1:', $worksheet['lastColumnLetter'], $worksheet['totalRows'];
|
echo '</ol>';
|
||||||
echo '</li>';
|
?>
|
||||||
}
|
<body>
|
||||||
echo '</ol>';
|
|
||||||
|
|
||||||
?>
|
|
||||||
<body>
|
|
||||||
</html>
|
</html>
|
|
@ -1,86 +1,85 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
|
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
|
|
||||||
date_default_timezone_set('Europe/London');
|
date_default_timezone_set('Europe/London');
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
|
||||||
<title>PhpSpreadsheet Reading WorkBook Data Example #01</title>
|
<title>PhpSpreadsheet Reading WorkBook Data Example #01</title>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h1>PhpSpreadsheet Reading WorkBook Data Example #01</h1>
|
<h1>PhpSpreadsheet Reading WorkBook Data Example #01</h1>
|
||||||
<h2>Read the WorkBook Properties</h2>
|
<h2>Read the WorkBook Properties</h2>
|
||||||
<?php
|
<?php
|
||||||
|
require_once __DIR__ . '/../../../src/Bootstrap.php';
|
||||||
|
|
||||||
require_once __DIR__ . '/../../../src/Bootstrap.php';
|
$inputFileType = 'Xls';
|
||||||
|
$inputFileName = './sampleData/example1.xls';
|
||||||
|
|
||||||
$inputFileType = 'Xls';
|
/* Create a new Reader of the type defined in $inputFileType * */
|
||||||
$inputFileName = './sampleData/example1.xls';
|
$reader = IOFactory::createReader($inputFileType);
|
||||||
|
/* Load $inputFileName to a PhpSpreadsheet Object * */
|
||||||
|
$spreadsheet = $reader->load($inputFileName);
|
||||||
|
|
||||||
/* Create a new Reader of the type defined in $inputFileType **/
|
echo '<hr />';
|
||||||
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
|
||||||
/* Load $inputFileName to a PhpSpreadsheet Object **/
|
|
||||||
$spreadsheet = $reader->load($inputFileName);
|
|
||||||
|
|
||||||
echo '<hr />';
|
/* Read the document's creator property * */
|
||||||
|
$creator = $spreadsheet->getProperties()->getCreator();
|
||||||
|
echo '<b>Document Creator: </b>', $creator, '<br />';
|
||||||
|
|
||||||
/* Read the document's creator property **/
|
/* Read the Date when the workbook was created (as a PHP timestamp value) * */
|
||||||
$creator = $spreadsheet->getProperties()->getCreator();
|
$creationDatestamp = $spreadsheet->getProperties()->getCreated();
|
||||||
echo '<b>Document Creator: </b>',$creator,'<br />';
|
/* Format the date and time using the standard PHP date() function * */
|
||||||
|
$creationDate = date('l, d<\s\up>S</\s\up> F Y', $creationDatestamp);
|
||||||
|
$creationTime = date('g:i A', $creationDatestamp);
|
||||||
|
echo '<b>Created On: </b>', $creationDate, ' at ', $creationTime, '<br />';
|
||||||
|
|
||||||
/* Read the Date when the workbook was created (as a PHP timestamp value) **/
|
/* Read the name of the last person to modify this workbook * */
|
||||||
$creationDatestamp = $spreadsheet->getProperties()->getCreated();
|
$modifiedBy = $spreadsheet->getProperties()->getLastModifiedBy();
|
||||||
/* Format the date and time using the standard PHP date() function **/
|
echo '<b>Last Modified By: </b>', $modifiedBy, '<br />';
|
||||||
$creationDate = date('l, d<\s\up>S</\s\up> F Y', $creationDatestamp);
|
|
||||||
$creationTime = date('g:i A', $creationDatestamp);
|
|
||||||
echo '<b>Created On: </b>',$creationDate,' at ',$creationTime,'<br />';
|
|
||||||
|
|
||||||
/* Read the name of the last person to modify this workbook **/
|
/* Read the Date when the workbook was last modified (as a PHP timestamp value) * */
|
||||||
$modifiedBy = $spreadsheet->getProperties()->getLastModifiedBy();
|
$modifiedDatestamp = $spreadsheet->getProperties()->getModified();
|
||||||
echo '<b>Last Modified By: </b>',$modifiedBy,'<br />';
|
/* Format the date and time using the standard PHP date() function * */
|
||||||
|
$modifiedDate = date('l, d<\s\up>S</\s\up> F Y', $modifiedDatestamp);
|
||||||
|
$modifiedTime = date('g:i A', $modifiedDatestamp);
|
||||||
|
echo '<b>Last Modified On: </b>', $modifiedDate, ' at ', $modifiedTime, '<br />';
|
||||||
|
|
||||||
/* Read the Date when the workbook was last modified (as a PHP timestamp value) **/
|
/* Read the workbook title property * */
|
||||||
$modifiedDatestamp = $spreadsheet->getProperties()->getModified();
|
$workbookTitle = $spreadsheet->getProperties()->getTitle();
|
||||||
/* Format the date and time using the standard PHP date() function **/
|
echo '<b>Title: </b>', $workbookTitle, '<br />';
|
||||||
$modifiedDate = date('l, d<\s\up>S</\s\up> F Y', $modifiedDatestamp);
|
|
||||||
$modifiedTime = date('g:i A', $modifiedDatestamp);
|
|
||||||
echo '<b>Last Modified On: </b>',$modifiedDate,' at ',$modifiedTime,'<br />';
|
|
||||||
|
|
||||||
/* Read the workbook title property **/
|
/* Read the workbook description property * */
|
||||||
$workbookTitle = $spreadsheet->getProperties()->getTitle();
|
$description = $spreadsheet->getProperties()->getDescription();
|
||||||
echo '<b>Title: </b>',$workbookTitle,'<br />';
|
echo '<b>Description: </b>', $description, '<br />';
|
||||||
|
|
||||||
/* Read the workbook description property **/
|
/* Read the workbook subject property * */
|
||||||
$description = $spreadsheet->getProperties()->getDescription();
|
$subject = $spreadsheet->getProperties()->getSubject();
|
||||||
echo '<b>Description: </b>',$description,'<br />';
|
echo '<b>Subject: </b>', $subject, '<br />';
|
||||||
|
|
||||||
/* Read the workbook subject property **/
|
/* Read the workbook keywords property * */
|
||||||
$subject = $spreadsheet->getProperties()->getSubject();
|
$keywords = $spreadsheet->getProperties()->getKeywords();
|
||||||
echo '<b>Subject: </b>',$subject,'<br />';
|
echo '<b>Keywords: </b>', $keywords, '<br />';
|
||||||
|
|
||||||
/* Read the workbook keywords property **/
|
/* Read the workbook category property * */
|
||||||
$keywords = $spreadsheet->getProperties()->getKeywords();
|
$category = $spreadsheet->getProperties()->getCategory();
|
||||||
echo '<b>Keywords: </b>',$keywords,'<br />';
|
echo '<b>Category: </b>', $category, '<br />';
|
||||||
|
|
||||||
/* Read the workbook category property **/
|
/* Read the workbook company property * */
|
||||||
$category = $spreadsheet->getProperties()->getCategory();
|
$company = $spreadsheet->getProperties()->getCompany();
|
||||||
echo '<b>Category: </b>',$category,'<br />';
|
echo '<b>Company: </b>', $company, '<br />';
|
||||||
|
|
||||||
/* Read the workbook company property **/
|
/* Read the workbook manager property * */
|
||||||
$company = $spreadsheet->getProperties()->getCompany();
|
$manager = $spreadsheet->getProperties()->getManager();
|
||||||
echo '<b>Company: </b>',$company,'<br />';
|
echo '<b>Manager: </b>', $manager, '<br />';
|
||||||
|
?>
|
||||||
/* Read the workbook manager property **/
|
<body>
|
||||||
$manager = $spreadsheet->getProperties()->getManager();
|
|
||||||
echo '<b>Manager: </b>',$manager,'<br />';
|
|
||||||
|
|
||||||
?>
|
|
||||||
<body>
|
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -1,44 +1,43 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
|
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
|
|
||||||
date_default_timezone_set('Europe/London');
|
date_default_timezone_set('Europe/London');
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
|
||||||
<title>PhpSpreadsheet Reading WorkBook Data Example #02</title>
|
<title>PhpSpreadsheet Reading WorkBook Data Example #02</title>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h1>PhpSpreadsheet Reading WorkBook Data Example #02</h1>
|
<h1>PhpSpreadsheet Reading WorkBook Data Example #02</h1>
|
||||||
<h2>Read a list of Custom Properties for a WorkBook</h2>
|
<h2>Read a list of Custom Properties for a WorkBook</h2>
|
||||||
<?php
|
<?php
|
||||||
|
require_once __DIR__ . '/../../../src/Bootstrap.php';
|
||||||
|
|
||||||
require_once __DIR__ . '/../../../src/Bootstrap.php';
|
$inputFileType = 'Xlsx';
|
||||||
|
$inputFileName = './sampleData/example1.xlsx';
|
||||||
|
|
||||||
$inputFileType = 'Xlsx';
|
/* Create a new Reader of the type defined in $inputFileType * */
|
||||||
$inputFileName = './sampleData/example1.xlsx';
|
$reader = IOFactory::createReader($inputFileType);
|
||||||
|
/* Load $inputFileName to a PhpSpreadsheet Object * */
|
||||||
|
$spreadsheet = $reader->load($inputFileName);
|
||||||
|
|
||||||
/* Create a new Reader of the type defined in $inputFileType **/
|
echo '<hr />';
|
||||||
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
|
||||||
/* Load $inputFileName to a PhpSpreadsheet Object **/
|
|
||||||
$spreadsheet = $reader->load($inputFileName);
|
|
||||||
|
|
||||||
echo '<hr />';
|
/* Read an array list of any custom properties for this document * */
|
||||||
|
$customPropertyList = $spreadsheet->getProperties()->getCustomProperties();
|
||||||
|
|
||||||
/* Read an array list of any custom properties for this document **/
|
echo '<b>Custom Property names: </b><br />';
|
||||||
$customPropertyList = $spreadsheet->getProperties()->getCustomProperties();
|
foreach ($customPropertyList as $customPropertyName) {
|
||||||
|
echo $customPropertyName, '<br />';
|
||||||
echo '<b>Custom Property names: </b><br />';
|
}
|
||||||
foreach ($customPropertyList as $customPropertyName) {
|
?>
|
||||||
echo $customPropertyName, '<br />';
|
<body>
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
||||||
<body>
|
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -1,72 +1,71 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
|
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
|
|
||||||
date_default_timezone_set('Europe/London');
|
date_default_timezone_set('Europe/London');
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
|
||||||
<title>PhpSpreadsheet Reading WorkBook Data Example #03</title>
|
<title>PhpSpreadsheet Reading WorkBook Data Example #03</title>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h1>PhpSpreadsheet Reading WorkBook Data Example #03</h1>
|
<h1>PhpSpreadsheet Reading WorkBook Data Example #03</h1>
|
||||||
<h2>Read Custom Property Values for a WorkBook</h2>
|
<h2>Read Custom Property Values for a WorkBook</h2>
|
||||||
<?php
|
<?php
|
||||||
|
require_once __DIR__ . '/../../../src/Bootstrap.php';
|
||||||
|
|
||||||
require_once __DIR__ . '/../../../src/Bootstrap.php';
|
$inputFileType = 'Xlsx';
|
||||||
|
$inputFileName = './sampleData/example1.xlsx';
|
||||||
|
|
||||||
$inputFileType = 'Xlsx';
|
/* Create a new Reader of the type defined in $inputFileType * */
|
||||||
$inputFileName = './sampleData/example1.xlsx';
|
$reader = IOFactory::createReader($inputFileType);
|
||||||
|
/* Load $inputFileName to a PhpSpreadsheet Object * */
|
||||||
|
$spreadsheet = $reader->load($inputFileName);
|
||||||
|
|
||||||
/* Create a new Reader of the type defined in $inputFileType **/
|
echo '<hr />';
|
||||||
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
|
||||||
/* Load $inputFileName to a PhpSpreadsheet Object **/
|
|
||||||
$spreadsheet = $reader->load($inputFileName);
|
|
||||||
|
|
||||||
echo '<hr />';
|
/* Read an array list of any custom properties for this document * */
|
||||||
|
$customPropertyList = $spreadsheet->getProperties()->getCustomProperties();
|
||||||
|
|
||||||
/* Read an array list of any custom properties for this document **/
|
echo '<b>Custom Properties: </b><br />';
|
||||||
$customPropertyList = $spreadsheet->getProperties()->getCustomProperties();
|
/* Loop through the list of custom properties * */
|
||||||
|
foreach ($customPropertyList as $customPropertyName) {
|
||||||
|
echo '<b>', $customPropertyName, ': </b>';
|
||||||
|
/* Retrieve the property value * */
|
||||||
|
$propertyValue = $spreadsheet->getProperties()->getCustomPropertyValue($customPropertyName);
|
||||||
|
/* Retrieve the property type * */
|
||||||
|
$propertyType = $spreadsheet->getProperties()->getCustomPropertyType($customPropertyName);
|
||||||
|
|
||||||
echo '<b>Custom Properties: </b><br />';
|
/* Manipulate properties as appropriate for display purposes * */
|
||||||
/* Loop through the list of custom properties **/
|
switch ($propertyType) {
|
||||||
foreach ($customPropertyList as $customPropertyName) {
|
case 'i': // integer
|
||||||
echo '<b>',$customPropertyName,': </b>';
|
$propertyType = 'integer number';
|
||||||
/* Retrieve the property value **/
|
break;
|
||||||
$propertyValue = $spreadsheet->getProperties()->getCustomPropertyValue($customPropertyName);
|
case 'f': // float
|
||||||
/* Retrieve the property type **/
|
$propertyType = 'floating point number';
|
||||||
$propertyType = $spreadsheet->getProperties()->getCustomPropertyType($customPropertyName);
|
break;
|
||||||
|
case 's': // string
|
||||||
|
$propertyType = 'string';
|
||||||
|
break;
|
||||||
|
case 'd': // date
|
||||||
|
$propertyValue = date('l, d<\s\up>S</\s\up> F Y g:i A', $propertyValue);
|
||||||
|
$propertyType = 'date';
|
||||||
|
break;
|
||||||
|
case 'b': // boolean
|
||||||
|
$propertyValue = ($propertyValue) ? 'TRUE' : 'FALSE';
|
||||||
|
$propertyType = 'boolean';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
/* Manipulate properties as appropriate for display purposes **/
|
echo $propertyValue, ' (', $propertyType, ')<br />';
|
||||||
switch ($propertyType) {
|
}
|
||||||
case 'i': // integer
|
?>
|
||||||
$propertyType = 'integer number';
|
<body>
|
||||||
break;
|
|
||||||
case 'f': // float
|
|
||||||
$propertyType = 'floating point number';
|
|
||||||
break;
|
|
||||||
case 's': // string
|
|
||||||
$propertyType = 'string';
|
|
||||||
break;
|
|
||||||
case 'd': // date
|
|
||||||
$propertyValue = date('l, d<\s\up>S</\s\up> F Y g:i A', $propertyValue);
|
|
||||||
$propertyType = 'date';
|
|
||||||
break;
|
|
||||||
case 'b': // boolean
|
|
||||||
$propertyValue = ($propertyValue) ? 'TRUE' : 'FALSE';
|
|
||||||
$propertyType = 'boolean';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
echo $propertyValue, ' (', $propertyType, ')<br />';
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
||||||
<body>
|
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -1,48 +1,47 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
|
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
|
|
||||||
date_default_timezone_set('Europe/London');
|
date_default_timezone_set('Europe/London');
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
|
||||||
<title>PhpSpreadsheet Reading WorkBook Data Example #04</title>
|
<title>PhpSpreadsheet Reading WorkBook Data Example #04</title>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h1>PhpSpreadsheet Reading WorkBook Data Example #04</h1>
|
<h1>PhpSpreadsheet Reading WorkBook Data Example #04</h1>
|
||||||
<h2>Get a List of the Worksheets in a WorkBook</h2>
|
<h2>Get a List of the Worksheets in a WorkBook</h2>
|
||||||
<?php
|
<?php
|
||||||
|
require_once __DIR__ . '/../../../src/Bootstrap.php';
|
||||||
|
|
||||||
require_once __DIR__ . '/../../../src/Bootstrap.php';
|
$inputFileType = 'Xls';
|
||||||
|
$inputFileName = './sampleData/example2.xls';
|
||||||
|
|
||||||
$inputFileType = 'Xls';
|
/* Create a new Reader of the type defined in $inputFileType * */
|
||||||
$inputFileName = './sampleData/example2.xls';
|
$reader = IOFactory::createReader($inputFileType);
|
||||||
|
/* Load $inputFileName to a PhpSpreadsheet Object * */
|
||||||
|
$spreadsheet = $reader->load($inputFileName);
|
||||||
|
|
||||||
/* Create a new Reader of the type defined in $inputFileType **/
|
echo '<hr />';
|
||||||
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
|
||||||
/* Load $inputFileName to a PhpSpreadsheet Object **/
|
|
||||||
$spreadsheet = $reader->load($inputFileName);
|
|
||||||
|
|
||||||
echo '<hr />';
|
echo 'Reading the number of Worksheets in the WorkBook<br />';
|
||||||
|
/* Use the PhpSpreadsheet object's getSheetCount() method to get a count of the number of WorkSheets in the WorkBook */
|
||||||
|
$sheetCount = $spreadsheet->getSheetCount();
|
||||||
|
echo 'There ', (($sheetCount == 1) ? 'is' : 'are'), ' ', $sheetCount, ' WorkSheet', (($sheetCount == 1) ? '' : 's'), ' in the WorkBook<br /><br />';
|
||||||
|
|
||||||
echo 'Reading the number of Worksheets in the WorkBook<br />';
|
echo 'Reading the names of Worksheets in the WorkBook<br />';
|
||||||
/* Use the PhpSpreadsheet object's getSheetCount() method to get a count of the number of WorkSheets in the WorkBook */
|
/* Use the PhpSpreadsheet object's getSheetNames() method to get an array listing the names/titles of the WorkSheets in the WorkBook */
|
||||||
$sheetCount = $spreadsheet->getSheetCount();
|
$sheetNames = $spreadsheet->getSheetNames();
|
||||||
echo 'There ',(($sheetCount == 1) ? 'is' : 'are'),' ',$sheetCount,' WorkSheet',(($sheetCount == 1) ? '' : 's'),' in the WorkBook<br /><br />';
|
foreach ($sheetNames as $sheetIndex => $sheetName) {
|
||||||
|
echo 'WorkSheet #', $sheetIndex, ' is named "', $sheetName, '"<br />';
|
||||||
echo 'Reading the names of Worksheets in the WorkBook<br />';
|
}
|
||||||
/* Use the PhpSpreadsheet object's getSheetNames() method to get an array listing the names/titles of the WorkSheets in the WorkBook */
|
?>
|
||||||
$sheetNames = $spreadsheet->getSheetNames();
|
<body>
|
||||||
foreach ($sheetNames as $sheetIndex => $sheetName) {
|
|
||||||
echo 'WorkSheet #',$sheetIndex,' is named "',$sheetName,'"<br />';
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
||||||
<body>
|
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -1,48 +1,44 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
|
|
||||||
date_default_timezone_set('Europe/London');
|
date_default_timezone_set('Europe/London');
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
|
|
||||||
<title>PhpSpreadsheet Examples</title>
|
<title>PhpSpreadsheet Examples</title>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
|
$exampleTypeList = glob('./*', GLOB_ONLYDIR);
|
||||||
|
|
||||||
$exampleTypeList = glob('./*', GLOB_ONLYDIR);
|
foreach ($exampleTypeList as $exampleType) {
|
||||||
|
echo '<h1>PhpSpreadsheet ' . pathinfo($exampleType, PATHINFO_BASENAME) . ' Examples</h1>';
|
||||||
|
|
||||||
foreach ($exampleTypeList as $exampleType) {
|
$exampleList = glob('./' . $exampleType . '/*.php');
|
||||||
echo '<h1>PhpSpreadsheet ' . pathinfo($exampleType, PATHINFO_BASENAME) . ' Examples</h1>';
|
|
||||||
|
|
||||||
$exampleList = glob('./' . $exampleType . '/*.php');
|
foreach ($exampleList as $exampleFile) {
|
||||||
|
$fileData = file_get_contents($exampleFile);
|
||||||
|
|
||||||
foreach ($exampleList as $exampleFile) {
|
$h1Pattern = '#<h1>(.*?)</h1>#';
|
||||||
$fileData = file_get_contents($exampleFile);
|
$h2Pattern = '#<h2>(.*?)</h2>#';
|
||||||
|
|
||||||
$h1Pattern = '#<h1>(.*?)</h1>#';
|
if (preg_match($h1Pattern, $fileData, $out)) {
|
||||||
$h2Pattern = '#<h2>(.*?)</h2>#';
|
$h1Text = $out[1];
|
||||||
|
$h2Text = (preg_match($h2Pattern, $fileData, $out)) ? $out[1] : '';
|
||||||
|
|
||||||
if (preg_match($h1Pattern, $fileData, $out)) {
|
echo '<a href="', $exampleFile, '">', $h1Text, '</a><br />';
|
||||||
$h1Text = $out[1];
|
if (($h2Text > '') &&
|
||||||
$h2Text = (preg_match($h2Pattern, $fileData, $out)) ? $out[1] : '';
|
(pathinfo($exampleType, PATHINFO_BASENAME) != 'Calculations')) {
|
||||||
|
echo $h2Text, '<br />';
|
||||||
echo '<a href="', $exampleFile, '">', $h1Text, '</a><br />';
|
}
|
||||||
if (($h2Text > '') &&
|
}
|
||||||
(pathinfo($exampleType, PATHINFO_BASENAME) != 'Calculations')) {
|
|
||||||
echo $h2Text, '<br />';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
?>
|
||||||
}
|
<body>
|
||||||
|
|
||||||
?>
|
|
||||||
<body>
|
|
||||||
</html>
|
</html>
|
|
@ -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;
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}());
|
|
@ -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
|
classes that allow you to read from and to write to different
|
||||||
spreadsheet file formats, like Excel and LibreOffice Calc.
|
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
|
# Getting started
|
||||||
|
|
||||||
## Software requirements
|
## Software requirements
|
||||||
|
@ -17,6 +32,10 @@ The following software is required to develop using PhpSpreadsheet:
|
||||||
- PHP extension php\_xml enabled
|
- PHP extension php\_xml enabled
|
||||||
- PHP extension php\_gd2 enabled (if not compiled in)
|
- 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
|
## Installation
|
||||||
|
|
||||||
Use [composer](https://getcomposer.org/) to install PhpSpreadsheet into your project:
|
Use [composer](https://getcomposer.org/) to install PhpSpreadsheet into your project:
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
- <span style="text-align: center; color: red;">✖</span> Not supported
|
- <span style="text-align: center; color: red;">✖</span> Not supported
|
||||||
- N/A Cannot be supported
|
- N/A Cannot be supported
|
||||||
|
|
||||||
<table>
|
<table class="features-cross-reference">
|
||||||
<tr>
|
<tr>
|
||||||
<th></th>
|
<th></th>
|
||||||
<th colspan="7">Readers</th>
|
<th colspan="7">Readers</th>
|
||||||
|
@ -906,7 +906,7 @@
|
||||||
<td></td>
|
<td></td>
|
||||||
<td></td>
|
<td></td>
|
||||||
<td></td>
|
<td></td>
|
||||||
<td></td>
|
<td style="text-align: center; color: orange;">●</td>
|
||||||
<td></td>
|
<td></td>
|
||||||
<td></td>
|
<td></td>
|
||||||
<td></td>
|
<td></td>
|
||||||
|
|
|
@ -90,7 +90,7 @@ calculated values, or force recalculation in Excel2003.
|
||||||
### Excel functions that return a Date and Time value
|
### Excel functions that return a Date and Time value
|
||||||
|
|
||||||
Any of the Date and Time functions that return a date value in Excel can
|
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
|
It is possible for scripts to change the data type used for returning
|
||||||
date values by calling the
|
date values by calling the
|
||||||
|
@ -103,9 +103,9 @@ method:
|
||||||
|
|
||||||
where the following constants can be used for `$returnDateType`:
|
where the following constants can be used for `$returnDateType`:
|
||||||
|
|
||||||
- `\PhpOffice\PhpSpreadsheet\Calculation\Functions::RETURNDATE_PHP_NUMERIC`
|
- `\PhpOffice\PhpSpreadsheet\Calculation\Functions::RETURNDATE_PHP_NUMERIC`
|
||||||
- `\PhpOffice\PhpSpreadsheet\Calculation\Functions::RETURNDATE_PHP_OBJECT`
|
- `\PhpOffice\PhpSpreadsheet\Calculation\Functions::RETURNDATE_PHP_OBJECT`
|
||||||
- `\PhpOffice\PhpSpreadsheet\Calculation\Functions::RETURNDATE_EXCEL`
|
- `\PhpOffice\PhpSpreadsheet\Calculation\Functions::RETURNDATE_EXCEL`
|
||||||
|
|
||||||
The method will return a Boolean True on success, False on failure (e.g.
|
The method will return a Boolean True on success, False on failure (e.g.
|
||||||
if an invalid value is passed in for the return date type).
|
if an invalid value is passed in for the return date type).
|
||||||
|
@ -117,11 +117,11 @@ method can be used to determine the current value of this setting:
|
||||||
$returnDateType = \PhpOffice\PhpSpreadsheet\Calculation\Functions::getReturnDateType();
|
$returnDateType = \PhpOffice\PhpSpreadsheet\Calculation\Functions::getReturnDateType();
|
||||||
```
|
```
|
||||||
|
|
||||||
The default is RETURNDATE\_PHP\_NUMERIC.
|
The default is `RETURNDATE_PHP_NUMERIC`.
|
||||||
|
|
||||||
#### PHP Timestamps
|
#### 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
|
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
|
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
|
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
|
gives PHP a date range of between 14th December 1901 and 19th January
|
||||||
2038.
|
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
|
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
|
#### 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
|
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
|
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
|
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`:
|
where the following constants can be used for `$baseDate`:
|
||||||
|
|
||||||
- \PhpOffice\PhpSpreadsheet\Shared\Date::CALENDAR\_WINDOWS\_1900
|
- `\PhpOffice\PhpSpreadsheet\Shared\Date::CALENDAR_WINDOWS_1900`
|
||||||
- \PhpOffice\PhpSpreadsheet\Shared\Date::CALENDAR\_MAC\_1904
|
- `\PhpOffice\PhpSpreadsheet\Shared\Date::CALENDAR_MAC_1904`
|
||||||
|
|
||||||
The method will return a Boolean True on success, False on failure (e.g.
|
The method will return a Boolean True on success, False on failure (e.g.
|
||||||
if an invalid value is passed in).
|
if an invalid value is passed in).
|
||||||
|
@ -170,31 +170,31 @@ be used to determine the current value of this setting:
|
||||||
$baseDate = \PhpOffice\PhpSpreadsheet\Shared\Date::getExcelCalendar();
|
$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
|
#### Functions that return a Date/Time Value
|
||||||
|
|
||||||
- DATE
|
- DATE
|
||||||
- DATEVALUE
|
- DATEVALUE
|
||||||
- EDATE
|
- EDATE
|
||||||
- EOMONTH
|
- EOMONTH
|
||||||
- NOW
|
- NOW
|
||||||
- TIME
|
- TIME
|
||||||
- TIMEVALUE
|
- TIMEVALUE
|
||||||
- TODAY
|
- TODAY
|
||||||
|
|
||||||
### Excel functions that accept Date and Time values as parameters
|
### Excel functions that accept Date and Time values as parameters
|
||||||
|
|
||||||
Date values passed in as parameters to a function can be an Excel
|
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
|
date value (e.g. '1-Jan-2009'). PhpSpreadsheet will attempt to identify
|
||||||
their type based on the PHP datatype:
|
their type based on the PHP datatype:
|
||||||
|
|
||||||
An integer numeric value will be treated as a PHP/Unix timestamp. A real
|
An integer numeric value will be treated as a PHP/Unix timestamp. A real
|
||||||
(floating point) numeric value will be treated as an Excel
|
(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)
|
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
|
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
|
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.
|
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,
|
considered an error by a US-based server, but which is not ambiguous,
|
||||||
then PhpSpreadsheet will attempt to correct this to 31st December 2008.
|
then PhpSpreadsheet will attempt to correct this to 31st December 2008.
|
||||||
If the content of the string doesn’t match any of the formats recognised
|
If the content of the string doesn’t 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),
|
handle a wider range of formats than the normal `strtotime()` function),
|
||||||
then the function will return a `#VALUE` error. However, Excel
|
then the function will return a `#VALUE` error. However, Excel
|
||||||
recommends that you should always use date/timestamps for your date
|
recommends that you should always use date/timestamps for your date
|
||||||
|
@ -213,28 +213,28 @@ The same principle applies when data is being written to Excel. Cells
|
||||||
containing date actual values (rather than Excel functions that return a
|
containing date actual values (rather than Excel functions that return a
|
||||||
date value) are always written as Excel dates, converting where
|
date value) are always written as Excel dates, converting where
|
||||||
necessary. If a cell formatted as a date contains an integer or
|
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
|
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
|
conversion is required. Note that string values are written as strings
|
||||||
rather than converted to Excel date timestamp values.
|
rather than converted to Excel date timestamp values.
|
||||||
|
|
||||||
#### Functions that expect a Date/Time Value
|
#### Functions that expect a Date/Time Value
|
||||||
|
|
||||||
- DATEDIF
|
- DATEDIF
|
||||||
- DAY
|
- DAY
|
||||||
- DAYS360
|
- DAYS360
|
||||||
- EDATE
|
- EDATE
|
||||||
- EOMONTH
|
- EOMONTH
|
||||||
- HOUR
|
- HOUR
|
||||||
- MINUTE
|
- MINUTE
|
||||||
- MONTH
|
- MONTH
|
||||||
- NETWORKDAYS
|
- NETWORKDAYS
|
||||||
- SECOND
|
- SECOND
|
||||||
- WEEKDAY
|
- WEEKDAY
|
||||||
- WEEKNUM
|
- WEEKNUM
|
||||||
- WORKDAY
|
- WORKDAY
|
||||||
- YEAR
|
- YEAR
|
||||||
- YEARFRAC
|
- YEARFRAC
|
||||||
|
|
||||||
### Helper Methods
|
### Helper Methods
|
||||||
|
|
||||||
|
@ -243,7 +243,7 @@ number of other methods are available in the
|
||||||
\PhpOffice\PhpSpreadsheet\Shared\Date class that can help when working
|
\PhpOffice\PhpSpreadsheet\Shared\Date class that can help when working
|
||||||
with dates:
|
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
|
Converts a date/time from an Excel date timestamp to return a PHP
|
||||||
serialized date/timestamp.
|
serialized date/timestamp.
|
||||||
|
@ -251,17 +251,17 @@ serialized date/timestamp.
|
||||||
Note that this method does not trap for Excel dates that fall outside of
|
Note that this method does not trap for Excel dates that fall outside of
|
||||||
the valid range for a PHP date timestamp.
|
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.
|
object.
|
||||||
|
|
||||||
#### \PhpOffice\PhpSpreadsheet\Shared\Date::PHPToExcel($PHPDate)
|
#### \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.
|
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
|
Takes year, month and day values (and optional hour, minute and second
|
||||||
values) and returns an Excel date timestamp value.
|
values) and returns an Excel date timestamp value.
|
||||||
|
@ -979,7 +979,7 @@ Excel and in PHP.
|
||||||
|
|
||||||
#### DATE
|
#### 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.
|
object representing the date that is referenced by the parameters.
|
||||||
|
|
||||||
##### Syntax
|
##### Syntax
|
||||||
|
@ -1025,7 +1025,7 @@ February 27, 2008.
|
||||||
|
|
||||||
**mixed** A date/time stamp that corresponds to the given date.
|
**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
|
or an Excel timestamp value (real), depending on the value of
|
||||||
\PhpOffice\PhpSpreadsheet\Calculation\Functions::getReturnDateType().
|
\PhpOffice\PhpSpreadsheet\Calculation\Functions::getReturnDateType().
|
||||||
|
|
||||||
|
@ -1093,12 +1093,12 @@ variety of different intervals, such number of years, months, or days.
|
||||||
|
|
||||||
**date1** First Date.
|
**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.
|
represented as a string.
|
||||||
|
|
||||||
**date2** Second Date.
|
**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.
|
represented as a string.
|
||||||
|
|
||||||
**unit** The interval type to use for the calculation
|
**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.
|
**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
|
or an Excel timestamp value (real), depending on the value of
|
||||||
\PhpOffice\PhpSpreadsheet\Calculation\Functions::getReturnDateType().
|
\PhpOffice\PhpSpreadsheet\Calculation\Functions::getReturnDateType().
|
||||||
|
|
||||||
|
@ -1290,7 +1290,7 @@ $retVal = call_user_func_array(
|
||||||
|
|
||||||
##### Notes
|
##### 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()`
|
(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
|
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.
|
date functions (such as DATEDIF) when the parameter value is a string.
|
||||||
|
@ -1317,7 +1317,7 @@ integer ranging from 1 to 31.
|
||||||
|
|
||||||
**datetime** 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.
|
represented as a string.
|
||||||
|
|
||||||
##### Return Value
|
##### Return Value
|
||||||
|
@ -1371,12 +1371,12 @@ accounting systems.
|
||||||
|
|
||||||
**date1** First Date.
|
**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.
|
represented as a string.
|
||||||
|
|
||||||
**date2** Second Date.
|
**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.
|
represented as a string.
|
||||||
|
|
||||||
**method** A boolean flag (TRUE or FALSE)
|
**method** A boolean flag (TRUE or FALSE)
|
||||||
|
@ -1453,7 +1453,7 @@ Excel `TRUE()` and `FALSE()` functions are used instead.
|
||||||
|
|
||||||
#### EDATE
|
#### 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
|
object representing the date that is the indicated number of months
|
||||||
before or after a specified date (the start\_date). Use EDATE to
|
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
|
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.
|
**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.
|
represented as a string.
|
||||||
|
|
||||||
**months** Number of months to add.
|
**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.
|
**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
|
or an Excel timestamp value (real), depending on the value of
|
||||||
\PhpOffice\PhpSpreadsheet\Calculation\Functions::getReturnDateType().
|
\PhpOffice\PhpSpreadsheet\Calculation\Functions::getReturnDateType().
|
||||||
|
|
||||||
|
@ -1526,7 +1526,7 @@ the Analysis ToolPak.
|
||||||
#### EOMONTH
|
#### EOMONTH
|
||||||
|
|
||||||
The EOMONTH function returns an Excel timestamp or a PHP timestamp or
|
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
|
the indicated number of months before or after a specified date (the
|
||||||
start\_date). Use EOMONTH to calculate maturity dates or due dates that
|
start\_date). Use EOMONTH to calculate maturity dates or due dates that
|
||||||
fall on the last day of the month.
|
fall on the last day of the month.
|
||||||
|
@ -1539,7 +1539,7 @@ fall on the last day of the month.
|
||||||
|
|
||||||
**baseDate** Start Date.
|
**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.
|
represented as a string.
|
||||||
|
|
||||||
**months** Number of months to add.
|
**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
|
**mixed** A date/time stamp that corresponds to the last day of basedate
|
||||||
+ months.
|
+ 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
|
or an Excel timestamp value (real), depending on the value of
|
||||||
\PhpOffice\PhpSpreadsheet\Calculation\Functions::getReturnDateType().
|
\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.
|
**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.
|
date/time represented as a string.
|
||||||
|
|
||||||
##### Return Value
|
##### Return Value
|
||||||
|
@ -1665,7 +1665,7 @@ given as an integer, ranging from 0 to 59.
|
||||||
|
|
||||||
**datetime** Time.
|
**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.
|
date/time represented as a string.
|
||||||
|
|
||||||
##### Return Value
|
##### Return Value
|
||||||
|
@ -1723,7 +1723,7 @@ integer ranging from 1 to 12.
|
||||||
|
|
||||||
**datetime** 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.
|
represented as a string.
|
||||||
|
|
||||||
##### Return Value
|
##### Return Value
|
||||||
|
@ -1779,12 +1779,12 @@ a specific term.
|
||||||
|
|
||||||
**startDate** Start Date of the period.
|
**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.
|
represented as a string.
|
||||||
|
|
||||||
**endDate** End Date of the period.
|
**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.
|
represented as a string.
|
||||||
|
|
||||||
**holidays** Optional array of Holiday dates.
|
**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
|
**mixed** A date/time stamp that corresponds to the current date and
|
||||||
time.
|
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
|
or an Excel timestamp value (real), depending on the value of
|
||||||
\PhpOffice\PhpSpreadsheet\Calculation\Functions::getReturnDateType().
|
\PhpOffice\PhpSpreadsheet\Calculation\Functions::getReturnDateType().
|
||||||
|
|
||||||
|
@ -1862,7 +1862,7 @@ given as an integer, ranging from 0 to 59.
|
||||||
|
|
||||||
**datetime** Time.
|
**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.
|
date/time represented as a string.
|
||||||
|
|
||||||
##### Return Value
|
##### Return Value
|
||||||
|
@ -1934,7 +1934,7 @@ modified to return a value between 0 and 6.
|
||||||
|
|
||||||
**datetime** 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.
|
represented as a string.
|
||||||
|
|
||||||
**method** An integer flag (values 0, 1 or 2)
|
**method** An integer flag (values 0, 1 or 2)
|
||||||
|
@ -2012,7 +2012,7 @@ The YEAR function returns the year of a date.
|
||||||
|
|
||||||
**datetime** 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.
|
represented as a string.
|
||||||
|
|
||||||
##### Return Value
|
##### Return Value
|
||||||
|
|
|
@ -192,3 +192,74 @@ $cell = $worksheet->setCellValue('A1', 'value', true);
|
||||||
// After
|
// After
|
||||||
$cell = $worksheet->getCell('A1')->setValue('value');
|
$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',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
```
|
||||||
|
|
|
@ -558,16 +558,16 @@ $styleArray = array(
|
||||||
),
|
),
|
||||||
'borders' => array(
|
'borders' => array(
|
||||||
'top' => array(
|
'top' => array(
|
||||||
'style' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
|
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
'fill' => array(
|
'fill' => array(
|
||||||
'type' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_GRADIENT_LINEAR,
|
'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_GRADIENT_LINEAR,
|
||||||
'rotation' => 90,
|
'rotation' => 90,
|
||||||
'startcolor' => array(
|
'startColor' => array(
|
||||||
'argb' => 'FFA0A0A0',
|
'argb' => 'FFA0A0A0',
|
||||||
),
|
),
|
||||||
'endcolor' => array(
|
'endColor' => array(
|
||||||
'argb' => 'FFFFFFFF',
|
'argb' => 'FFFFFFFF',
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -693,7 +693,7 @@ B2:G8.
|
||||||
$styleArray = array(
|
$styleArray = array(
|
||||||
'borders' => array(
|
'borders' => array(
|
||||||
'outline' => array(
|
'outline' => array(
|
||||||
'style' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THICK,
|
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THICK,
|
||||||
'color' => array('argb' => 'FFFF0000'),
|
'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.
|
Additional shortcut borders come in handy like in the example above.
|
||||||
These are the shortcut borders available:
|
These are the shortcut borders available:
|
||||||
|
|
||||||
- allborders
|
- allBorders
|
||||||
- outline
|
- outline
|
||||||
- inside
|
- inside
|
||||||
- vertical
|
- 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)
|
![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
|
"overlapping" borders, and one of the components has to win over the
|
||||||
other where there is border overlap. In PhpSpreadsheet, from weakest to
|
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.
|
vertical/horizontal, left/right/top/bottom/diagonal.
|
||||||
|
|
||||||
This border hierarchy can be utilized to achieve various effects in an
|
This border hierarchy can be utilized to achieve various effects in an
|
||||||
|
@ -757,17 +757,17 @@ fill | getFill()
|
||||||
font | getFont()
|
font | getFont()
|
||||||
borders | getBorders()
|
borders | getBorders()
|
||||||
alignment | getAlignment()
|
alignment | getAlignment()
|
||||||
numberformat | getNumberFormat()
|
numberFormat | getNumberFormat()
|
||||||
protection | getProtection()
|
protection | getProtection()
|
||||||
|
|
||||||
**\PhpOffice\PhpSpreadsheet\Style\Fill**
|
**\PhpOffice\PhpSpreadsheet\Style\Fill**
|
||||||
|
|
||||||
Array key | Maps to property
|
Array key | Maps to property
|
||||||
-----------|-------------------
|
-----------|-------------------
|
||||||
type | setFillType()
|
fillType | setFillType()
|
||||||
rotation | setRotation()
|
rotation | setRotation()
|
||||||
startcolor | getStartColor()
|
startColor | getStartColor()
|
||||||
endcolor | getEndColor()
|
endColor | getEndColor()
|
||||||
color | getStartColor()
|
color | getStartColor()
|
||||||
|
|
||||||
|
|
||||||
|
@ -779,17 +779,17 @@ name | setName()
|
||||||
bold | setBold()
|
bold | setBold()
|
||||||
italic | setItalic()
|
italic | setItalic()
|
||||||
underline | setUnderline()
|
underline | setUnderline()
|
||||||
strike | setStrikethrough()
|
strikethrough | setStrikethrough()
|
||||||
color | getColor()
|
color | getColor()
|
||||||
size | setSize()
|
size | setSize()
|
||||||
superScript | setSuperScript()
|
superscript | setSuperscript()
|
||||||
subScript | setSubScript()
|
subscript | setSubscript()
|
||||||
|
|
||||||
**\PhpOffice\PhpSpreadsheet\Style\Borders**
|
**\PhpOffice\PhpSpreadsheet\Style\Borders**
|
||||||
|
|
||||||
Array key | Maps to property
|
Array key | Maps to property
|
||||||
------------------|-------------------
|
------------------|-------------------
|
||||||
allborders | getLeft(); getRight(); getTop(); getBottom()
|
allBorders | getLeft(); getRight(); getTop(); getBottom()
|
||||||
left | getLeft()
|
left | getLeft()
|
||||||
right | getRight()
|
right | getRight()
|
||||||
top | getTop()
|
top | getTop()
|
||||||
|
@ -797,7 +797,7 @@ bottom | getBottom()
|
||||||
diagonal | getDiagonal()
|
diagonal | getDiagonal()
|
||||||
vertical | getVertical()
|
vertical | getVertical()
|
||||||
horizontal | getHorizontal()
|
horizontal | getHorizontal()
|
||||||
diagonaldirection | setDiagonalDirection()
|
diagonalDirection | setDiagonalDirection()
|
||||||
outline | setOutline()
|
outline | setOutline()
|
||||||
|
|
||||||
**\PhpOffice\PhpSpreadsheet\Style\Border**
|
**\PhpOffice\PhpSpreadsheet\Style\Border**
|
||||||
|
@ -813,8 +813,8 @@ Array key | Maps to property
|
||||||
------------|-------------------
|
------------|-------------------
|
||||||
horizontal | setHorizontal()
|
horizontal | setHorizontal()
|
||||||
vertical | setVertical()
|
vertical | setVertical()
|
||||||
rotation | setTextRotation()
|
textRotation| setTextRotation()
|
||||||
wrap | setWrapText()
|
wrapText | setWrapText()
|
||||||
shrinkToFit | setShrinkToFit()
|
shrinkToFit | setShrinkToFit()
|
||||||
indent | setIndent()
|
indent | setIndent()
|
||||||
|
|
||||||
|
@ -822,7 +822,7 @@ indent | setIndent()
|
||||||
|
|
||||||
Array key | Maps to property
|
Array key | Maps to property
|
||||||
----------|-------------------
|
----------|-------------------
|
||||||
code | setFormatCode()
|
formatCode | setFormatCode()
|
||||||
|
|
||||||
**\PhpOffice\PhpSpreadsheet\Style\Protection**
|
**\PhpOffice\PhpSpreadsheet\Style\Protection**
|
||||||
|
|
||||||
|
@ -910,15 +910,18 @@ practice...
|
||||||
|
|
||||||
## Setting security on a spreadsheet
|
## Setting security on a spreadsheet
|
||||||
|
|
||||||
Excel offers 3 levels of "protection": document security, sheet security
|
Excel offers 3 levels of "protection":
|
||||||
and cell security.
|
|
||||||
|
|
||||||
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
|
spreadsheet, allowing changes to be made only when that password is
|
||||||
entered.Worksheet security offers other security options: you can
|
entered.
|
||||||
disallow inserting rows on a specific sheet, disallow sorting, ... Cell
|
- Worksheet: offers other security options: you can
|
||||||
security offers the option to lock/unlock a cell as well as show/hide
|
disallow inserting rows on a specific sheet, disallow sorting, ...
|
||||||
the internal formulaAn example on setting document security:
|
- Cell: offers the option to lock/unlock a cell as well as show/hide
|
||||||
|
the internal formula.
|
||||||
|
|
||||||
|
|
||||||
|
An example on setting document security:
|
||||||
|
|
||||||
``` php
|
``` php
|
||||||
$spreadsheet->getSecurity()->setLockWindows(true);
|
$spreadsheet->getSecurity()->setLockWindows(true);
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
|
||||||
require __DIR__ . '/Header.php';
|
require __DIR__ . '/Header.php';
|
||||||
|
|
||||||
// Create new Spreadsheet object
|
$spreadsheet = new Spreadsheet();
|
||||||
$helper->log('Create new Spreadsheet object');
|
$helper->log('Create new Spreadsheet object');
|
||||||
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$spreadsheet = new Spreadsheet();
|
||||||
|
|
||||||
// Set document properties
|
// Set document properties
|
||||||
$helper->log('Set document properties');
|
$helper->log('Set document properties');
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Helper\Sample;
|
||||||
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
|
||||||
require_once __DIR__ . '/../src/Bootstrap.php';
|
require_once __DIR__ . '/../src/Bootstrap.php';
|
||||||
|
|
||||||
$helper = new \PhpOffice\PhpSpreadsheet\Helper\Sample();
|
$helper = new Sample();
|
||||||
if ($helper->isCli()) {
|
if ($helper->isCli()) {
|
||||||
echo 'This example should only be run from a Web Browser' . PHP_EOL;
|
echo 'This example should only be run from a Web Browser' . PHP_EOL;
|
||||||
|
|
||||||
|
@ -10,7 +14,7 @@ if ($helper->isCli()) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create new Spreadsheet object
|
// Create new Spreadsheet object
|
||||||
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$spreadsheet = new Spreadsheet();
|
||||||
|
|
||||||
// Set document properties
|
// Set document properties
|
||||||
$spreadsheet->getProperties()->setCreator('Maarten Balliauw')
|
$spreadsheet->getProperties()->setCreator('Maarten Balliauw')
|
||||||
|
@ -52,6 +56,6 @@ header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modifie
|
||||||
header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
|
header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
|
||||||
header('Pragma: public'); // HTTP/1.0
|
header('Pragma: public'); // HTTP/1.0
|
||||||
|
|
||||||
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Ods');
|
$writer = IOFactory::createWriter($spreadsheet, 'Ods');
|
||||||
$writer->save('php://output');
|
$writer->save('php://output');
|
||||||
exit;
|
exit;
|
||||||
|
|
|
@ -1,8 +1,13 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Helper\Sample;
|
||||||
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Settings;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
|
||||||
require_once __DIR__ . '/../src/Bootstrap.php';
|
require_once __DIR__ . '/../src/Bootstrap.php';
|
||||||
|
|
||||||
$helper = new \PhpOffice\PhpSpreadsheet\Helper\Sample();
|
$helper = new Sample();
|
||||||
if ($helper->isCli()) {
|
if ($helper->isCli()) {
|
||||||
echo 'This example should only be run from a Web Browser' . PHP_EOL;
|
echo 'This example should only be run from a Web Browser' . PHP_EOL;
|
||||||
|
|
||||||
|
@ -12,11 +17,11 @@ if ($helper->isCli()) {
|
||||||
// Change these values to select the Rendering library that you wish to use
|
// Change these values to select the Rendering library that you wish to use
|
||||||
// and its directory location on your server
|
// and its directory location on your server
|
||||||
//$rendererName = \PhpOffice\PhpSpreadsheet\Settings::PDF_RENDERER_TCPDF;
|
//$rendererName = \PhpOffice\PhpSpreadsheet\Settings::PDF_RENDERER_TCPDF;
|
||||||
$rendererName = \PhpOffice\PhpSpreadsheet\Settings::PDF_RENDERER_MPDF;
|
$rendererName = Settings::PDF_RENDERER_MPDF;
|
||||||
//$rendererName = \PhpOffice\PhpSpreadsheet\Settings::PDF_RENDERER_DOMPDF;
|
//$rendererName = \PhpOffice\PhpSpreadsheet\Settings::PDF_RENDERER_DOMPDF;
|
||||||
|
|
||||||
// Create new Spreadsheet object
|
// Create new Spreadsheet object
|
||||||
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$spreadsheet = new Spreadsheet();
|
||||||
|
|
||||||
// Set document properties
|
// Set document properties
|
||||||
$spreadsheet->getProperties()->setCreator('Maarten Balliauw')
|
$spreadsheet->getProperties()->setCreator('Maarten Balliauw')
|
||||||
|
@ -46,13 +51,13 @@ $spreadsheet->getActiveSheet()->setShowGridLines(false);
|
||||||
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
|
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
|
||||||
$spreadsheet->setActiveSheetIndex(0);
|
$spreadsheet->setActiveSheetIndex(0);
|
||||||
|
|
||||||
\PhpOffice\PhpSpreadsheet\Settings::setPdfRendererName($rendererName);
|
Settings::setPdfRendererName($rendererName);
|
||||||
|
|
||||||
// Redirect output to a client’s web browser (PDF)
|
// Redirect output to a client’s web browser (PDF)
|
||||||
header('Content-Type: application/pdf');
|
header('Content-Type: application/pdf');
|
||||||
header('Content-Disposition: attachment;filename="01simple.pdf"');
|
header('Content-Disposition: attachment;filename="01simple.pdf"');
|
||||||
header('Cache-Control: max-age=0');
|
header('Cache-Control: max-age=0');
|
||||||
|
|
||||||
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Pdf');
|
$writer = IOFactory::createWriter($spreadsheet, 'Pdf');
|
||||||
$writer->save('php://output');
|
$writer->save('php://output');
|
||||||
exit;
|
exit;
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Helper\Sample;
|
||||||
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
|
||||||
require_once __DIR__ . '/../src/Bootstrap.php';
|
require_once __DIR__ . '/../src/Bootstrap.php';
|
||||||
|
|
||||||
$helper = new \PhpOffice\PhpSpreadsheet\Helper\Sample();
|
$helper = new Sample();
|
||||||
if ($helper->isCli()) {
|
if ($helper->isCli()) {
|
||||||
echo 'This example should only be run from a Web Browser' . PHP_EOL;
|
echo 'This example should only be run from a Web Browser' . PHP_EOL;
|
||||||
|
|
||||||
|
@ -10,7 +14,7 @@ if ($helper->isCli()) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create new Spreadsheet object
|
// Create new Spreadsheet object
|
||||||
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$spreadsheet = new Spreadsheet();
|
||||||
|
|
||||||
// Set document properties
|
// Set document properties
|
||||||
$spreadsheet->getProperties()->setCreator('Maarten Balliauw')
|
$spreadsheet->getProperties()->setCreator('Maarten Balliauw')
|
||||||
|
@ -52,6 +56,6 @@ header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modifie
|
||||||
header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
|
header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
|
||||||
header('Pragma: public'); // HTTP/1.0
|
header('Pragma: public'); // HTTP/1.0
|
||||||
|
|
||||||
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xls');
|
$writer = IOFactory::createWriter($spreadsheet, 'Xls');
|
||||||
$writer->save('php://output');
|
$writer->save('php://output');
|
||||||
exit;
|
exit;
|
||||||
|
|
|
@ -1,15 +1,19 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Helper\Sample;
|
||||||
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
|
||||||
require_once __DIR__ . '/../src/Bootstrap.php';
|
require_once __DIR__ . '/../src/Bootstrap.php';
|
||||||
|
|
||||||
$helper = new \PhpOffice\PhpSpreadsheet\Helper\Sample();
|
$helper = new Sample();
|
||||||
if ($helper->isCli()) {
|
if ($helper->isCli()) {
|
||||||
echo 'This example should only be run from a Web Browser' . PHP_EOL;
|
echo 'This example should only be run from a Web Browser' . PHP_EOL;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Create new Spreadsheet object
|
// Create new Spreadsheet object
|
||||||
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$spreadsheet = new Spreadsheet();
|
||||||
|
|
||||||
// Set document properties
|
// Set document properties
|
||||||
$spreadsheet->getProperties()->setCreator('Maarten Balliauw')
|
$spreadsheet->getProperties()->setCreator('Maarten Balliauw')
|
||||||
|
@ -51,6 +55,6 @@ header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modifie
|
||||||
header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
|
header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
|
||||||
header('Pragma: public'); // HTTP/1.0
|
header('Pragma: public'); // HTTP/1.0
|
||||||
|
|
||||||
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx');
|
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
|
||||||
$writer->save('php://output');
|
$writer->save('php://output');
|
||||||
exit;
|
exit;
|
||||||
|
|
|
@ -1,10 +1,16 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\RichText;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Shared\Date;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Style\Color;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
|
||||||
|
|
||||||
require __DIR__ . '/Header.php';
|
require __DIR__ . '/Header.php';
|
||||||
|
|
||||||
// Create new Spreadsheet object
|
// Create new Spreadsheet object
|
||||||
$helper->log('Create new Spreadsheet object');
|
$helper->log('Create new Spreadsheet object');
|
||||||
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$spreadsheet = new Spreadsheet();
|
||||||
|
|
||||||
// Set document properties
|
// Set document properties
|
||||||
$helper->log('Set document properties');
|
$helper->log('Set document properties');
|
||||||
|
@ -70,41 +76,41 @@ $dateTimeNow = time();
|
||||||
$spreadsheet->getActiveSheet()
|
$spreadsheet->getActiveSheet()
|
||||||
->setCellValue('A9', 'Date/Time')
|
->setCellValue('A9', 'Date/Time')
|
||||||
->setCellValue('B9', 'Date')
|
->setCellValue('B9', 'Date')
|
||||||
->setCellValue('C9', \PhpOffice\PhpSpreadsheet\Shared\Date::PHPToExcel($dateTimeNow));
|
->setCellValue('C9', Date::PHPToExcel($dateTimeNow));
|
||||||
$spreadsheet->getActiveSheet()
|
$spreadsheet->getActiveSheet()
|
||||||
->getStyle('C9')
|
->getStyle('C9')
|
||||||
->getNumberFormat()
|
->getNumberFormat()
|
||||||
->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_YYYYMMDD2);
|
->setFormatCode(NumberFormat::FORMAT_DATE_YYYYMMDD2);
|
||||||
|
|
||||||
$spreadsheet->getActiveSheet()
|
$spreadsheet->getActiveSheet()
|
||||||
->setCellValue('A10', 'Date/Time')
|
->setCellValue('A10', 'Date/Time')
|
||||||
->setCellValue('B10', 'Time')
|
->setCellValue('B10', 'Time')
|
||||||
->setCellValue('C10', \PhpOffice\PhpSpreadsheet\Shared\Date::PHPToExcel($dateTimeNow));
|
->setCellValue('C10', Date::PHPToExcel($dateTimeNow));
|
||||||
$spreadsheet->getActiveSheet()
|
$spreadsheet->getActiveSheet()
|
||||||
->getStyle('C10')
|
->getStyle('C10')
|
||||||
->getNumberFormat()
|
->getNumberFormat()
|
||||||
->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_TIME4);
|
->setFormatCode(NumberFormat::FORMAT_DATE_TIME4);
|
||||||
|
|
||||||
$spreadsheet->getActiveSheet()
|
$spreadsheet->getActiveSheet()
|
||||||
->setCellValue('A11', 'Date/Time')
|
->setCellValue('A11', 'Date/Time')
|
||||||
->setCellValue('B11', 'Date and Time')
|
->setCellValue('B11', 'Date and Time')
|
||||||
->setCellValue('C11', \PhpOffice\PhpSpreadsheet\Shared\Date::PHPToExcel($dateTimeNow));
|
->setCellValue('C11', Date::PHPToExcel($dateTimeNow));
|
||||||
$spreadsheet->getActiveSheet()
|
$spreadsheet->getActiveSheet()
|
||||||
->getStyle('C11')
|
->getStyle('C11')
|
||||||
->getNumberFormat()
|
->getNumberFormat()
|
||||||
->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_DATETIME);
|
->setFormatCode(NumberFormat::FORMAT_DATE_DATETIME);
|
||||||
|
|
||||||
$spreadsheet->getActiveSheet()
|
$spreadsheet->getActiveSheet()
|
||||||
->setCellValue('A12', 'NULL')
|
->setCellValue('A12', 'NULL')
|
||||||
->setCellValue('C12', null);
|
->setCellValue('C12', null);
|
||||||
|
|
||||||
$richText = new \PhpOffice\PhpSpreadsheet\RichText();
|
$richText = new RichText();
|
||||||
$richText->createText('你好 ');
|
$richText->createText('你好 ');
|
||||||
|
|
||||||
$payable = $richText->createTextRun('你 好 吗?');
|
$payable = $richText->createTextRun('你 好 吗?');
|
||||||
$payable->getFont()->setBold(true);
|
$payable->getFont()->setBold(true);
|
||||||
$payable->getFont()->setItalic(true);
|
$payable->getFont()->setItalic(true);
|
||||||
$payable->getFont()->setColor(new \PhpOffice\PhpSpreadsheet\Style\Color(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_DARKGREEN));
|
$payable->getFont()->setColor(new Color(Color::COLOR_DARKGREEN));
|
||||||
|
|
||||||
$richText->createText(', unless specified otherwise on the invoice.');
|
$richText->createText(', unless specified otherwise on the invoice.');
|
||||||
|
|
||||||
|
@ -112,11 +118,11 @@ $spreadsheet->getActiveSheet()
|
||||||
->setCellValue('A13', 'Rich Text')
|
->setCellValue('A13', 'Rich Text')
|
||||||
->setCellValue('C13', $richText);
|
->setCellValue('C13', $richText);
|
||||||
|
|
||||||
$richText2 = new \PhpOffice\PhpSpreadsheet\RichText();
|
$richText2 = new RichText();
|
||||||
$richText2->createText("black text\n");
|
$richText2->createText("black text\n");
|
||||||
|
|
||||||
$red = $richText2->createTextRun('red text');
|
$red = $richText2->createTextRun('red text');
|
||||||
$red->getFont()->setColor(new \PhpOffice\PhpSpreadsheet\Style\Color(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_RED));
|
$red->getFont()->setColor(new Color(Color::COLOR_RED));
|
||||||
|
|
||||||
$spreadsheet->getActiveSheet()
|
$spreadsheet->getActiveSheet()
|
||||||
->getCell('C14')
|
->getCell('C14')
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
|
||||||
require __DIR__ . '/Header.php';
|
require __DIR__ . '/Header.php';
|
||||||
|
|
||||||
// Create new Spreadsheet object
|
// Create new Spreadsheet object
|
||||||
$helper->log('Create new Spreadsheet object');
|
$helper->log('Create new Spreadsheet object');
|
||||||
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$spreadsheet = new Spreadsheet();
|
||||||
|
|
||||||
// Set document properties
|
// Set document properties
|
||||||
$helper->log('Set document properties');
|
$helper->log('Set document properties');
|
||||||
|
|
|
@ -1,10 +1,15 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Worksheet\HeaderFooter;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Worksheet\HeaderFooterDrawing;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup;
|
||||||
|
|
||||||
require __DIR__ . '/Header.php';
|
require __DIR__ . '/Header.php';
|
||||||
|
|
||||||
// Create new Spreadsheet object
|
// Create new Spreadsheet object
|
||||||
$helper->log('Create new Spreadsheet object');
|
$helper->log('Create new Spreadsheet object');
|
||||||
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$spreadsheet = new Spreadsheet();
|
||||||
|
|
||||||
// Set document properties
|
// Set document properties
|
||||||
$helper->log('Set document properties');
|
$helper->log('Set document properties');
|
||||||
|
@ -34,22 +39,22 @@ $spreadsheet->getActiveSheet()
|
||||||
|
|
||||||
// Add a drawing to the header
|
// Add a drawing to the header
|
||||||
$helper->log('Add a drawing to the header');
|
$helper->log('Add a drawing to the header');
|
||||||
$drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\HeaderFooterDrawing();
|
$drawing = new HeaderFooterDrawing();
|
||||||
$drawing->setName('PhpSpreadsheet logo');
|
$drawing->setName('PhpSpreadsheet logo');
|
||||||
$drawing->setPath(__DIR__ . '/images/PhpSpreadsheet_logo.png');
|
$drawing->setPath(__DIR__ . '/images/PhpSpreadsheet_logo.png');
|
||||||
$drawing->setHeight(36);
|
$drawing->setHeight(36);
|
||||||
$spreadsheet->getActiveSheet()
|
$spreadsheet->getActiveSheet()
|
||||||
->getHeaderFooter()
|
->getHeaderFooter()
|
||||||
->addImage($drawing, \PhpOffice\PhpSpreadsheet\Worksheet\HeaderFooter::IMAGE_HEADER_LEFT);
|
->addImage($drawing, HeaderFooter::IMAGE_HEADER_LEFT);
|
||||||
|
|
||||||
// Set page orientation and size
|
// Set page orientation and size
|
||||||
$helper->log('Set page orientation and size');
|
$helper->log('Set page orientation and size');
|
||||||
$spreadsheet->getActiveSheet()
|
$spreadsheet->getActiveSheet()
|
||||||
->getPageSetup()
|
->getPageSetup()
|
||||||
->setOrientation(\PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_LANDSCAPE);
|
->setOrientation(PageSetup::ORIENTATION_LANDSCAPE);
|
||||||
$spreadsheet->getActiveSheet()
|
$spreadsheet->getActiveSheet()
|
||||||
->getPageSetup()
|
->getPageSetup()
|
||||||
->setPaperSize(\PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_A4);
|
->setPaperSize(PageSetup::PAPERSIZE_A4);
|
||||||
|
|
||||||
// Rename worksheet
|
// Rename worksheet
|
||||||
$helper->log('Rename worksheet');
|
$helper->log('Rename worksheet');
|
||||||
|
|
|
@ -1,15 +1,18 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
||||||
|
|
||||||
require __DIR__ . '/Header.php';
|
require __DIR__ . '/Header.php';
|
||||||
|
|
||||||
// Create temporary file that will be read
|
// Create temporary file that will be read
|
||||||
$sampleSpreadsheet = require __DIR__ . '/templates/sampleSpreadsheet.php';
|
$sampleSpreadsheet = require __DIR__ . '/templates/sampleSpreadsheet.php';
|
||||||
$filename = $helper->getTemporaryFilename();
|
$filename = $helper->getTemporaryFilename();
|
||||||
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($sampleSpreadsheet);
|
$writer = new Xlsx($sampleSpreadsheet);
|
||||||
$writer->save($filename);
|
$writer->save($filename);
|
||||||
|
|
||||||
$callStartTime = microtime(true);
|
$callStartTime = microtime(true);
|
||||||
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($filename);
|
$spreadsheet = IOFactory::load($filename);
|
||||||
$helper->logRead('Xlsx', $filename, $callStartTime);
|
$helper->logRead('Xlsx', $filename, $callStartTime);
|
||||||
|
|
||||||
// Save
|
// Save
|
||||||
|
|
|
@ -1,10 +1,16 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Style\Color;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Style\Conditional;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup;
|
||||||
|
|
||||||
require __DIR__ . '/Header.php';
|
require __DIR__ . '/Header.php';
|
||||||
|
|
||||||
// Create new Spreadsheet object
|
// Create new Spreadsheet object
|
||||||
$helper->log('Create new Spreadsheet object');
|
$helper->log('Create new Spreadsheet object');
|
||||||
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$spreadsheet = new Spreadsheet();
|
||||||
|
|
||||||
// Set document properties
|
// Set document properties
|
||||||
$helper->log('Set document properties');
|
$helper->log('Set document properties');
|
||||||
|
@ -47,30 +53,30 @@ $spreadsheet->getActiveSheet()->getColumnDimension('B')->setWidth(12);
|
||||||
|
|
||||||
// Add conditional formatting
|
// Add conditional formatting
|
||||||
$helper->log('Add conditional formatting');
|
$helper->log('Add conditional formatting');
|
||||||
$conditional1 = new \PhpOffice\PhpSpreadsheet\Style\Conditional();
|
$conditional1 = new Conditional();
|
||||||
$conditional1->setConditionType(\PhpOffice\PhpSpreadsheet\Style\Conditional::CONDITION_CELLIS)
|
$conditional1->setConditionType(Conditional::CONDITION_CELLIS)
|
||||||
->setOperatorType(\PhpOffice\PhpSpreadsheet\Style\Conditional::OPERATOR_BETWEEN)
|
->setOperatorType(Conditional::OPERATOR_BETWEEN)
|
||||||
->addCondition('200')
|
->addCondition('200')
|
||||||
->addCondition('400');
|
->addCondition('400');
|
||||||
$conditional1->getStyle()->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_YELLOW);
|
$conditional1->getStyle()->getFont()->getColor()->setARGB(Color::COLOR_YELLOW);
|
||||||
$conditional1->getStyle()->getFont()->setBold(true);
|
$conditional1->getStyle()->getFont()->setBold(true);
|
||||||
$conditional1->getStyle()->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
|
$conditional1->getStyle()->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
|
||||||
|
|
||||||
$conditional2 = new \PhpOffice\PhpSpreadsheet\Style\Conditional();
|
$conditional2 = new Conditional();
|
||||||
$conditional2->setConditionType(\PhpOffice\PhpSpreadsheet\Style\Conditional::CONDITION_CELLIS)
|
$conditional2->setConditionType(Conditional::CONDITION_CELLIS)
|
||||||
->setOperatorType(\PhpOffice\PhpSpreadsheet\Style\Conditional::OPERATOR_LESSTHAN)
|
->setOperatorType(Conditional::OPERATOR_LESSTHAN)
|
||||||
->addCondition('0');
|
->addCondition('0');
|
||||||
$conditional2->getStyle()->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_RED);
|
$conditional2->getStyle()->getFont()->getColor()->setARGB(Color::COLOR_RED);
|
||||||
$conditional2->getStyle()->getFont()->setItalic(true);
|
$conditional2->getStyle()->getFont()->setItalic(true);
|
||||||
$conditional2->getStyle()->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
|
$conditional2->getStyle()->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
|
||||||
|
|
||||||
$conditional3 = new \PhpOffice\PhpSpreadsheet\Style\Conditional();
|
$conditional3 = new Conditional();
|
||||||
$conditional3->setConditionType(\PhpOffice\PhpSpreadsheet\Style\Conditional::CONDITION_CELLIS)
|
$conditional3->setConditionType(Conditional::CONDITION_CELLIS)
|
||||||
->setOperatorType(\PhpOffice\PhpSpreadsheet\Style\Conditional::OPERATOR_GREATERTHANOREQUAL)
|
->setOperatorType(Conditional::OPERATOR_GREATERTHANOREQUAL)
|
||||||
->addCondition('0');
|
->addCondition('0');
|
||||||
$conditional3->getStyle()->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_GREEN);
|
$conditional3->getStyle()->getFont()->getColor()->setARGB(Color::COLOR_GREEN);
|
||||||
$conditional3->getStyle()->getFont()->setItalic(true);
|
$conditional3->getStyle()->getFont()->setItalic(true);
|
||||||
$conditional3->getStyle()->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
|
$conditional3->getStyle()->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_CURRENCY_EUR_SIMPLE);
|
||||||
|
|
||||||
$conditionalStyles = $spreadsheet->getActiveSheet()->getStyle('B2')->getConditionalStyles();
|
$conditionalStyles = $spreadsheet->getActiveSheet()->getStyle('B2')->getConditionalStyles();
|
||||||
array_push($conditionalStyles, $conditional1);
|
array_push($conditionalStyles, $conditional1);
|
||||||
|
@ -98,8 +104,8 @@ $spreadsheet->getActiveSheet()->getHeaderFooter()->setOddFooter('&L&B' . $spread
|
||||||
|
|
||||||
// Set page orientation and size
|
// Set page orientation and size
|
||||||
$helper->log('Set page orientation and size');
|
$helper->log('Set page orientation and size');
|
||||||
$spreadsheet->getActiveSheet()->getPageSetup()->setOrientation(\PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_PORTRAIT);
|
$spreadsheet->getActiveSheet()->getPageSetup()->setOrientation(PageSetup::ORIENTATION_PORTRAIT);
|
||||||
$spreadsheet->getActiveSheet()->getPageSetup()->setPaperSize(\PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_A4);
|
$spreadsheet->getActiveSheet()->getPageSetup()->setPaperSize(PageSetup::PAPERSIZE_A4);
|
||||||
|
|
||||||
// Rename worksheet
|
// Rename worksheet
|
||||||
$helper->log('Rename worksheet');
|
$helper->log('Rename worksheet');
|
||||||
|
|
|
@ -1,10 +1,15 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Style\Color;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Style\Conditional;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
|
||||||
|
|
||||||
require __DIR__ . '/Header.php';
|
require __DIR__ . '/Header.php';
|
||||||
|
|
||||||
// Create new Spreadsheet object
|
// Create new Spreadsheet object
|
||||||
$helper->log('Create new Spreadsheet object');
|
$helper->log('Create new Spreadsheet object');
|
||||||
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$spreadsheet = new Spreadsheet();
|
||||||
|
|
||||||
// Set document properties
|
// Set document properties
|
||||||
$helper->log('Set document properties');
|
$helper->log('Set document properties');
|
||||||
|
@ -32,22 +37,22 @@ $spreadsheet->getActiveSheet()
|
||||||
$spreadsheet->getActiveSheet()->getStyle('A1:A8')
|
$spreadsheet->getActiveSheet()->getStyle('A1:A8')
|
||||||
->getNumberFormat()
|
->getNumberFormat()
|
||||||
->setFormatCode(
|
->setFormatCode(
|
||||||
\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_PERCENTAGE_00
|
NumberFormat::FORMAT_PERCENTAGE_00
|
||||||
);
|
);
|
||||||
|
|
||||||
// Add conditional formatting
|
// Add conditional formatting
|
||||||
$helper->log('Add conditional formatting');
|
$helper->log('Add conditional formatting');
|
||||||
$conditional1 = new \PhpOffice\PhpSpreadsheet\Style\Conditional();
|
$conditional1 = new Conditional();
|
||||||
$conditional1->setConditionType(\PhpOffice\PhpSpreadsheet\Style\Conditional::CONDITION_CELLIS)
|
$conditional1->setConditionType(Conditional::CONDITION_CELLIS)
|
||||||
->setOperatorType(\PhpOffice\PhpSpreadsheet\Style\Conditional::OPERATOR_LESSTHAN)
|
->setOperatorType(Conditional::OPERATOR_LESSTHAN)
|
||||||
->addCondition('0');
|
->addCondition('0');
|
||||||
$conditional1->getStyle()->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_RED);
|
$conditional1->getStyle()->getFont()->getColor()->setARGB(Color::COLOR_RED);
|
||||||
|
|
||||||
$conditional3 = new \PhpOffice\PhpSpreadsheet\Style\Conditional();
|
$conditional3 = new Conditional();
|
||||||
$conditional3->setConditionType(\PhpOffice\PhpSpreadsheet\Style\Conditional::CONDITION_CELLIS)
|
$conditional3->setConditionType(Conditional::CONDITION_CELLIS)
|
||||||
->setOperatorType(\PhpOffice\PhpSpreadsheet\Style\Conditional::OPERATOR_GREATERTHANOREQUAL)
|
->setOperatorType(Conditional::OPERATOR_GREATERTHANOREQUAL)
|
||||||
->addCondition('1');
|
->addCondition('1');
|
||||||
$conditional3->getStyle()->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_GREEN);
|
$conditional3->getStyle()->getFont()->getColor()->setARGB(Color::COLOR_GREEN);
|
||||||
|
|
||||||
$conditionalStyles = $spreadsheet->getActiveSheet()->getStyle('A1')->getConditionalStyles();
|
$conditionalStyles = $spreadsheet->getActiveSheet()->getStyle('A1')->getConditionalStyles();
|
||||||
array_push($conditionalStyles, $conditional1);
|
array_push($conditionalStyles, $conditional1);
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Worksheet;
|
||||||
|
|
||||||
require __DIR__ . '/Header.php';
|
require __DIR__ . '/Header.php';
|
||||||
|
|
||||||
// Create new Spreadsheet object
|
// Create new Spreadsheet object
|
||||||
$helper->log('Create new Spreadsheet object');
|
$helper->log('Create new Spreadsheet object');
|
||||||
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$spreadsheet = new Spreadsheet();
|
||||||
|
|
||||||
// Set document properties
|
// Set document properties
|
||||||
$helper->log('Set document properties');
|
$helper->log('Set document properties');
|
||||||
|
@ -36,7 +39,7 @@ for ($i = 2; $i <= 50; ++$i) {
|
||||||
// Add page breaks every 10 rows
|
// Add page breaks every 10 rows
|
||||||
if ($i % 10 == 0) {
|
if ($i % 10 == 0) {
|
||||||
// Add a page break
|
// Add a page break
|
||||||
$spreadsheet->getActiveSheet()->setBreak('A' . $i, \PhpOffice\PhpSpreadsheet\Worksheet::BREAK_ROW);
|
$spreadsheet->getActiveSheet()->setBreak('A' . $i, Worksheet::BREAK_ROW);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
|
||||||
require __DIR__ . '/Header.php';
|
require __DIR__ . '/Header.php';
|
||||||
|
|
||||||
// Create new Spreadsheet object
|
// Create new Spreadsheet object
|
||||||
$helper->log('Create new Spreadsheet object');
|
$helper->log('Create new Spreadsheet object');
|
||||||
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$spreadsheet = new Spreadsheet();
|
||||||
|
|
||||||
// Set document properties
|
// Set document properties
|
||||||
$helper->log('Set document properties');
|
$helper->log('Set document properties');
|
||||||
|
|
|
@ -1,10 +1,16 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Shared\Date;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule;
|
||||||
|
|
||||||
require __DIR__ . '/Header.php';
|
require __DIR__ . '/Header.php';
|
||||||
|
|
||||||
// Create new Spreadsheet object
|
// Create new Spreadsheet object
|
||||||
$helper->log('Create new Spreadsheet object');
|
$helper->log('Create new Spreadsheet object');
|
||||||
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$spreadsheet = new Spreadsheet();
|
||||||
|
|
||||||
// Set document properties
|
// Set document properties
|
||||||
$helper->log('Set document properties');
|
$helper->log('Set document properties');
|
||||||
|
@ -48,7 +54,7 @@ foreach ($years as $year) {
|
||||||
foreach ($countries as $country) {
|
foreach ($countries as $country) {
|
||||||
$endDays = date('t', mktime(0, 0, 0, $period, 1, $year));
|
$endDays = date('t', mktime(0, 0, 0, $period, 1, $year));
|
||||||
for ($i = 1; $i <= $endDays; ++$i) {
|
for ($i = 1; $i <= $endDays; ++$i) {
|
||||||
$eDate = \PhpOffice\PhpSpreadsheet\Shared\Date::formattedPHPToExcel(
|
$eDate = Date::formattedPHPToExcel(
|
||||||
$year,
|
$year,
|
||||||
$period,
|
$period,
|
||||||
$i
|
$i
|
||||||
|
@ -86,8 +92,8 @@ $spreadsheet->getActiveSheet()->getStyle('A1:F1')->getFont()->setBold(true);
|
||||||
$spreadsheet->getActiveSheet()->getStyle('A1:F1')->getAlignment()->setWrapText(true);
|
$spreadsheet->getActiveSheet()->getStyle('A1:F1')->getAlignment()->setWrapText(true);
|
||||||
$spreadsheet->getActiveSheet()->getColumnDimension('C')->setWidth(12.5);
|
$spreadsheet->getActiveSheet()->getColumnDimension('C')->setWidth(12.5);
|
||||||
$spreadsheet->getActiveSheet()->getColumnDimension('D')->setWidth(10.5);
|
$spreadsheet->getActiveSheet()->getColumnDimension('D')->setWidth(10.5);
|
||||||
$spreadsheet->getActiveSheet()->getStyle('D2:D' . $row)->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_YYYYMMDD2);
|
$spreadsheet->getActiveSheet()->getStyle('D2:D' . $row)->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_DATE_YYYYMMDD2);
|
||||||
$spreadsheet->getActiveSheet()->getStyle('E2:F' . $row)->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_CURRENCY_USD_SIMPLE);
|
$spreadsheet->getActiveSheet()->getStyle('E2:F' . $row)->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_CURRENCY_USD_SIMPLE);
|
||||||
$spreadsheet->getActiveSheet()->getColumnDimension('F')->setWidth(14);
|
$spreadsheet->getActiveSheet()->getColumnDimension('F')->setWidth(14);
|
||||||
$spreadsheet->getActiveSheet()->freezePane('A2');
|
$spreadsheet->getActiveSheet()->freezePane('A2');
|
||||||
|
|
||||||
|
@ -104,45 +110,45 @@ $helper->log('Set active filters');
|
||||||
// Filter the Country column on a filter value of countries beginning with the letter U (or Japan)
|
// Filter the Country column on a filter value of countries beginning with the letter U (or Japan)
|
||||||
// We use * as a wildcard, so specify as U* and using a wildcard requires customFilter
|
// We use * as a wildcard, so specify as U* and using a wildcard requires customFilter
|
||||||
$autoFilter->getColumn('C')
|
$autoFilter->getColumn('C')
|
||||||
->setFilterType(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column::AUTOFILTER_FILTERTYPE_CUSTOMFILTER)
|
->setFilterType(Column::AUTOFILTER_FILTERTYPE_CUSTOMFILTER)
|
||||||
->createRule()
|
->createRule()
|
||||||
->setRule(
|
->setRule(
|
||||||
\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_COLUMN_RULE_EQUAL,
|
Rule::AUTOFILTER_COLUMN_RULE_EQUAL,
|
||||||
'u*'
|
'u*'
|
||||||
)
|
)
|
||||||
->setRuleType(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_RULETYPE_CUSTOMFILTER);
|
->setRuleType(Rule::AUTOFILTER_RULETYPE_CUSTOMFILTER);
|
||||||
$autoFilter->getColumn('C')
|
$autoFilter->getColumn('C')
|
||||||
->createRule()
|
->createRule()
|
||||||
->setRule(
|
->setRule(
|
||||||
\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_COLUMN_RULE_EQUAL,
|
Rule::AUTOFILTER_COLUMN_RULE_EQUAL,
|
||||||
'japan'
|
'japan'
|
||||||
)
|
)
|
||||||
->setRuleType(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_RULETYPE_CUSTOMFILTER);
|
->setRuleType(Rule::AUTOFILTER_RULETYPE_CUSTOMFILTER);
|
||||||
// Filter the Date column on a filter value of the first day of every period of the current year
|
// Filter the Date column on a filter value of the first day of every period of the current year
|
||||||
// We us a dateGroup ruletype for this, although it is still a standard filter
|
// We us a dateGroup ruletype for this, although it is still a standard filter
|
||||||
foreach ($periods as $period) {
|
foreach ($periods as $period) {
|
||||||
$endDate = date('t', mktime(0, 0, 0, $period, 1, $currentYear));
|
$endDate = date('t', mktime(0, 0, 0, $period, 1, $currentYear));
|
||||||
|
|
||||||
$autoFilter->getColumn('D')
|
$autoFilter->getColumn('D')
|
||||||
->setFilterType(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column::AUTOFILTER_FILTERTYPE_FILTER)
|
->setFilterType(Column::AUTOFILTER_FILTERTYPE_FILTER)
|
||||||
->createRule()
|
->createRule()
|
||||||
->setRule(
|
->setRule(
|
||||||
\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_COLUMN_RULE_EQUAL,
|
Rule::AUTOFILTER_COLUMN_RULE_EQUAL,
|
||||||
[
|
[
|
||||||
'year' => $currentYear,
|
'year' => $currentYear,
|
||||||
'month' => $period,
|
'month' => $period,
|
||||||
'day' => $endDate,
|
'day' => $endDate,
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
->setRuleType(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_RULETYPE_DATEGROUP);
|
->setRuleType(Rule::AUTOFILTER_RULETYPE_DATEGROUP);
|
||||||
}
|
}
|
||||||
// Display only sales values that are blank
|
// Display only sales values that are blank
|
||||||
// Standard filter, operator equals, and value of NULL
|
// Standard filter, operator equals, and value of NULL
|
||||||
$autoFilter->getColumn('E')
|
$autoFilter->getColumn('E')
|
||||||
->setFilterType(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column::AUTOFILTER_FILTERTYPE_FILTER)
|
->setFilterType(Column::AUTOFILTER_FILTERTYPE_FILTER)
|
||||||
->createRule()
|
->createRule()
|
||||||
->setRule(
|
->setRule(
|
||||||
\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_COLUMN_RULE_EQUAL,
|
Rule::AUTOFILTER_COLUMN_RULE_EQUAL,
|
||||||
''
|
''
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,16 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Shared\Date;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule;
|
||||||
|
|
||||||
require __DIR__ . '/Header.php';
|
require __DIR__ . '/Header.php';
|
||||||
|
|
||||||
// Create new Spreadsheet object
|
// Create new Spreadsheet object
|
||||||
$helper->log('Create new Spreadsheet object');
|
$helper->log('Create new Spreadsheet object');
|
||||||
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$spreadsheet = new Spreadsheet();
|
||||||
|
|
||||||
// Set document properties
|
// Set document properties
|
||||||
$helper->log('Set document properties');
|
$helper->log('Set document properties');
|
||||||
|
@ -48,7 +54,7 @@ foreach ($years as $year) {
|
||||||
foreach ($countries as $country) {
|
foreach ($countries as $country) {
|
||||||
$endDays = date('t', mktime(0, 0, 0, $period, 1, $year));
|
$endDays = date('t', mktime(0, 0, 0, $period, 1, $year));
|
||||||
for ($i = 1; $i <= $endDays; ++$i) {
|
for ($i = 1; $i <= $endDays; ++$i) {
|
||||||
$eDate = \PhpOffice\PhpSpreadsheet\Shared\Date::formattedPHPToExcel(
|
$eDate = Date::formattedPHPToExcel(
|
||||||
$year,
|
$year,
|
||||||
$period,
|
$period,
|
||||||
$i
|
$i
|
||||||
|
@ -86,8 +92,8 @@ $spreadsheet->getActiveSheet()->getStyle('A1:F1')->getFont()->setBold(true);
|
||||||
$spreadsheet->getActiveSheet()->getStyle('A1:F1')->getAlignment()->setWrapText(true);
|
$spreadsheet->getActiveSheet()->getStyle('A1:F1')->getAlignment()->setWrapText(true);
|
||||||
$spreadsheet->getActiveSheet()->getColumnDimension('C')->setWidth(12.5);
|
$spreadsheet->getActiveSheet()->getColumnDimension('C')->setWidth(12.5);
|
||||||
$spreadsheet->getActiveSheet()->getColumnDimension('D')->setWidth(10.5);
|
$spreadsheet->getActiveSheet()->getColumnDimension('D')->setWidth(10.5);
|
||||||
$spreadsheet->getActiveSheet()->getStyle('D2:D' . $row)->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_YYYYMMDD2);
|
$spreadsheet->getActiveSheet()->getStyle('D2:D' . $row)->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_DATE_YYYYMMDD2);
|
||||||
$spreadsheet->getActiveSheet()->getStyle('E2:F' . $row)->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_CURRENCY_USD_SIMPLE);
|
$spreadsheet->getActiveSheet()->getStyle('E2:F' . $row)->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_CURRENCY_USD_SIMPLE);
|
||||||
$spreadsheet->getActiveSheet()->getColumnDimension('F')->setWidth(14);
|
$spreadsheet->getActiveSheet()->getColumnDimension('F')->setWidth(14);
|
||||||
$spreadsheet->getActiveSheet()->freezePane('A2');
|
$spreadsheet->getActiveSheet()->freezePane('A2');
|
||||||
|
|
||||||
|
@ -104,39 +110,39 @@ $helper->log('Set active filters');
|
||||||
// Filter the Country column on a filter value of Germany
|
// Filter the Country column on a filter value of Germany
|
||||||
// As it's just a simple value filter, we can use FILTERTYPE_FILTER
|
// As it's just a simple value filter, we can use FILTERTYPE_FILTER
|
||||||
$autoFilter->getColumn('C')
|
$autoFilter->getColumn('C')
|
||||||
->setFilterType(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column::AUTOFILTER_FILTERTYPE_FILTER)
|
->setFilterType(Column::AUTOFILTER_FILTERTYPE_FILTER)
|
||||||
->createRule()
|
->createRule()
|
||||||
->setRule(
|
->setRule(
|
||||||
\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_COLUMN_RULE_EQUAL,
|
Rule::AUTOFILTER_COLUMN_RULE_EQUAL,
|
||||||
'Germany'
|
'Germany'
|
||||||
);
|
);
|
||||||
// Filter the Date column on a filter value of the year to date
|
// Filter the Date column on a filter value of the year to date
|
||||||
$autoFilter->getColumn('D')
|
$autoFilter->getColumn('D')
|
||||||
->setFilterType(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column::AUTOFILTER_FILTERTYPE_DYNAMICFILTER)
|
->setFilterType(Column::AUTOFILTER_FILTERTYPE_DYNAMICFILTER)
|
||||||
->createRule()
|
->createRule()
|
||||||
->setRule(
|
->setRule(
|
||||||
\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_COLUMN_RULE_EQUAL,
|
Rule::AUTOFILTER_COLUMN_RULE_EQUAL,
|
||||||
null,
|
null,
|
||||||
\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_RULETYPE_DYNAMIC_YEARTODATE
|
Rule::AUTOFILTER_RULETYPE_DYNAMIC_YEARTODATE
|
||||||
)
|
)
|
||||||
->setRuleType(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_RULETYPE_DYNAMICFILTER);
|
->setRuleType(Rule::AUTOFILTER_RULETYPE_DYNAMICFILTER);
|
||||||
// Display only sales values that are between 400 and 600
|
// Display only sales values that are between 400 and 600
|
||||||
$autoFilter->getColumn('E')
|
$autoFilter->getColumn('E')
|
||||||
->setFilterType(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column::AUTOFILTER_FILTERTYPE_CUSTOMFILTER)
|
->setFilterType(Column::AUTOFILTER_FILTERTYPE_CUSTOMFILTER)
|
||||||
->createRule()
|
->createRule()
|
||||||
->setRule(
|
->setRule(
|
||||||
\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_COLUMN_RULE_GREATERTHANOREQUAL,
|
Rule::AUTOFILTER_COLUMN_RULE_GREATERTHANOREQUAL,
|
||||||
400
|
400
|
||||||
)
|
)
|
||||||
->setRuleType(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_RULETYPE_CUSTOMFILTER);
|
->setRuleType(Rule::AUTOFILTER_RULETYPE_CUSTOMFILTER);
|
||||||
$autoFilter->getColumn('E')
|
$autoFilter->getColumn('E')
|
||||||
->setJoin(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column::AUTOFILTER_COLUMN_JOIN_AND)
|
->setJoin(Column::AUTOFILTER_COLUMN_JOIN_AND)
|
||||||
->createRule()
|
->createRule()
|
||||||
->setRule(
|
->setRule(
|
||||||
\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_COLUMN_RULE_LESSTHANOREQUAL,
|
Rule::AUTOFILTER_COLUMN_RULE_LESSTHANOREQUAL,
|
||||||
600
|
600
|
||||||
)
|
)
|
||||||
->setRuleType(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_RULETYPE_CUSTOMFILTER);
|
->setRuleType(Rule::AUTOFILTER_RULETYPE_CUSTOMFILTER);
|
||||||
|
|
||||||
// Save
|
// Save
|
||||||
$helper->write($spreadsheet, __FILE__);
|
$helper->write($spreadsheet, __FILE__);
|
||||||
|
|
|
@ -1,10 +1,16 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Shared\Date;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule;
|
||||||
|
|
||||||
require __DIR__ . '/Header.php';
|
require __DIR__ . '/Header.php';
|
||||||
|
|
||||||
// Create new Spreadsheet object
|
// Create new Spreadsheet object
|
||||||
$helper->log('Create new Spreadsheet object');
|
$helper->log('Create new Spreadsheet object');
|
||||||
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$spreadsheet = new Spreadsheet();
|
||||||
|
|
||||||
// Set document properties
|
// Set document properties
|
||||||
$helper->log('Set document properties');
|
$helper->log('Set document properties');
|
||||||
|
@ -48,7 +54,7 @@ foreach ($years as $year) {
|
||||||
foreach ($countries as $country) {
|
foreach ($countries as $country) {
|
||||||
$endDays = date('t', mktime(0, 0, 0, $period, 1, $year));
|
$endDays = date('t', mktime(0, 0, 0, $period, 1, $year));
|
||||||
for ($i = 1; $i <= $endDays; ++$i) {
|
for ($i = 1; $i <= $endDays; ++$i) {
|
||||||
$eDate = \PhpOffice\PhpSpreadsheet\Shared\Date::formattedPHPToExcel(
|
$eDate = Date::formattedPHPToExcel(
|
||||||
$year,
|
$year,
|
||||||
$period,
|
$period,
|
||||||
$i
|
$i
|
||||||
|
@ -86,8 +92,8 @@ $spreadsheet->getActiveSheet()->getStyle('A1:F1')->getFont()->setBold(true);
|
||||||
$spreadsheet->getActiveSheet()->getStyle('A1:F1')->getAlignment()->setWrapText(true);
|
$spreadsheet->getActiveSheet()->getStyle('A1:F1')->getAlignment()->setWrapText(true);
|
||||||
$spreadsheet->getActiveSheet()->getColumnDimension('C')->setWidth(12.5);
|
$spreadsheet->getActiveSheet()->getColumnDimension('C')->setWidth(12.5);
|
||||||
$spreadsheet->getActiveSheet()->getColumnDimension('D')->setWidth(10.5);
|
$spreadsheet->getActiveSheet()->getColumnDimension('D')->setWidth(10.5);
|
||||||
$spreadsheet->getActiveSheet()->getStyle('D2:D' . $row)->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_YYYYMMDD2);
|
$spreadsheet->getActiveSheet()->getStyle('D2:D' . $row)->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_DATE_YYYYMMDD2);
|
||||||
$spreadsheet->getActiveSheet()->getStyle('E2:F' . $row)->getNumberFormat()->setFormatCode(\PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_CURRENCY_USD_SIMPLE);
|
$spreadsheet->getActiveSheet()->getStyle('E2:F' . $row)->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_CURRENCY_USD_SIMPLE);
|
||||||
$spreadsheet->getActiveSheet()->getColumnDimension('F')->setWidth(14);
|
$spreadsheet->getActiveSheet()->getColumnDimension('F')->setWidth(14);
|
||||||
$spreadsheet->getActiveSheet()->freezePane('A2');
|
$spreadsheet->getActiveSheet()->freezePane('A2');
|
||||||
|
|
||||||
|
@ -104,45 +110,45 @@ $helper->log('Set active filters');
|
||||||
// Filter the Country column on a filter value of countries beginning with the letter U (or Japan)
|
// Filter the Country column on a filter value of countries beginning with the letter U (or Japan)
|
||||||
// We use * as a wildcard, so specify as U* and using a wildcard requires customFilter
|
// We use * as a wildcard, so specify as U* and using a wildcard requires customFilter
|
||||||
$autoFilter->getColumn('C')
|
$autoFilter->getColumn('C')
|
||||||
->setFilterType(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column::AUTOFILTER_FILTERTYPE_CUSTOMFILTER)
|
->setFilterType(Column::AUTOFILTER_FILTERTYPE_CUSTOMFILTER)
|
||||||
->createRule()
|
->createRule()
|
||||||
->setRule(
|
->setRule(
|
||||||
\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_COLUMN_RULE_EQUAL,
|
Rule::AUTOFILTER_COLUMN_RULE_EQUAL,
|
||||||
'u*'
|
'u*'
|
||||||
)
|
)
|
||||||
->setRuleType(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_RULETYPE_CUSTOMFILTER);
|
->setRuleType(Rule::AUTOFILTER_RULETYPE_CUSTOMFILTER);
|
||||||
$autoFilter->getColumn('C')
|
$autoFilter->getColumn('C')
|
||||||
->createRule()
|
->createRule()
|
||||||
->setRule(
|
->setRule(
|
||||||
\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_COLUMN_RULE_EQUAL,
|
Rule::AUTOFILTER_COLUMN_RULE_EQUAL,
|
||||||
'japan'
|
'japan'
|
||||||
)
|
)
|
||||||
->setRuleType(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_RULETYPE_CUSTOMFILTER);
|
->setRuleType(Rule::AUTOFILTER_RULETYPE_CUSTOMFILTER);
|
||||||
// Filter the Date column on a filter value of the first day of every period of the current year
|
// Filter the Date column on a filter value of the first day of every period of the current year
|
||||||
// We us a dateGroup ruletype for this, although it is still a standard filter
|
// We us a dateGroup ruletype for this, although it is still a standard filter
|
||||||
foreach ($periods as $period) {
|
foreach ($periods as $period) {
|
||||||
$endDate = date('t', mktime(0, 0, 0, $period, 1, $currentYear));
|
$endDate = date('t', mktime(0, 0, 0, $period, 1, $currentYear));
|
||||||
|
|
||||||
$autoFilter->getColumn('D')
|
$autoFilter->getColumn('D')
|
||||||
->setFilterType(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column::AUTOFILTER_FILTERTYPE_FILTER)
|
->setFilterType(Column::AUTOFILTER_FILTERTYPE_FILTER)
|
||||||
->createRule()
|
->createRule()
|
||||||
->setRule(
|
->setRule(
|
||||||
\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_COLUMN_RULE_EQUAL,
|
Rule::AUTOFILTER_COLUMN_RULE_EQUAL,
|
||||||
[
|
[
|
||||||
'year' => $currentYear,
|
'year' => $currentYear,
|
||||||
'month' => $period,
|
'month' => $period,
|
||||||
'day' => $endDate,
|
'day' => $endDate,
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
->setRuleType(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_RULETYPE_DATEGROUP);
|
->setRuleType(Rule::AUTOFILTER_RULETYPE_DATEGROUP);
|
||||||
}
|
}
|
||||||
// Display only sales values that are blank
|
// Display only sales values that are blank
|
||||||
// Standard filter, operator equals, and value of NULL
|
// Standard filter, operator equals, and value of NULL
|
||||||
$autoFilter->getColumn('E')
|
$autoFilter->getColumn('E')
|
||||||
->setFilterType(\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column::AUTOFILTER_FILTERTYPE_FILTER)
|
->setFilterType(Column::AUTOFILTER_FILTERTYPE_FILTER)
|
||||||
->createRule()
|
->createRule()
|
||||||
->setRule(
|
->setRule(
|
||||||
\PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule::AUTOFILTER_COLUMN_RULE_EQUAL,
|
Rule::AUTOFILTER_COLUMN_RULE_EQUAL,
|
||||||
''
|
''
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
|
||||||
require __DIR__ . '/Header.php';
|
require __DIR__ . '/Header.php';
|
||||||
|
|
||||||
// Create new Spreadsheet object
|
// Create new Spreadsheet object
|
||||||
$helper->log('Create new Spreadsheet object');
|
$helper->log('Create new Spreadsheet object');
|
||||||
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$spreadsheet = new Spreadsheet();
|
||||||
|
|
||||||
// Set document properties
|
// Set document properties
|
||||||
$helper->log('Set document properties');
|
$helper->log('Set document properties');
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Style\Protection;
|
||||||
|
|
||||||
require __DIR__ . '/Header.php';
|
require __DIR__ . '/Header.php';
|
||||||
|
|
||||||
// Create new Spreadsheet object
|
// Create new Spreadsheet object
|
||||||
$helper->log('Create new Spreadsheet object');
|
$helper->log('Create new Spreadsheet object');
|
||||||
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$spreadsheet = new Spreadsheet();
|
||||||
|
|
||||||
// Set document properties
|
// Set document properties
|
||||||
$helper->log('Set document properties');
|
$helper->log('Set document properties');
|
||||||
|
@ -37,7 +40,7 @@ $spreadsheet->getActiveSheet()->getProtection()->setSheet(true);
|
||||||
$spreadsheet->getActiveSheet()
|
$spreadsheet->getActiveSheet()
|
||||||
->getStyle('A2:B2')
|
->getStyle('A2:B2')
|
||||||
->getProtection()->setLocked(
|
->getProtection()->setLocked(
|
||||||
\PhpOffice\PhpSpreadsheet\Style\Protection::PROTECTION_UNPROTECTED
|
Protection::PROTECTION_UNPROTECTED
|
||||||
);
|
);
|
||||||
|
|
||||||
// Save
|
// Save
|
||||||
|
|
|
@ -1,17 +1,20 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
|
||||||
mt_srand(1234567890);
|
mt_srand(1234567890);
|
||||||
|
|
||||||
require __DIR__ . '/Header.php';
|
require __DIR__ . '/Header.php';
|
||||||
|
|
||||||
// List functions
|
// List functions
|
||||||
$helper->log('List implemented functions');
|
$helper->log('List implemented functions');
|
||||||
$calc = \PhpOffice\PhpSpreadsheet\Calculation::getInstance();
|
$calc = Calculation::getInstance();
|
||||||
print_r($calc->getImplementedFunctionNames());
|
print_r($calc->getImplementedFunctionNames());
|
||||||
|
|
||||||
// Create new Spreadsheet object
|
// Create new Spreadsheet object
|
||||||
$helper->log('Create new Spreadsheet object');
|
$helper->log('Create new Spreadsheet object');
|
||||||
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$spreadsheet = new Spreadsheet();
|
||||||
|
|
||||||
// Add some data, we will use some formulas here
|
// Add some data, we will use some formulas here
|
||||||
$helper->log('Add some data and formulas');
|
$helper->log('Add some data and formulas');
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
|
||||||
require __DIR__ . '/Header.php';
|
require __DIR__ . '/Header.php';
|
||||||
|
|
||||||
// Create new Spreadsheet object
|
// Create new Spreadsheet object
|
||||||
$helper->log('Create new Spreadsheet object');
|
$helper->log('Create new Spreadsheet object');
|
||||||
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$spreadsheet = new Spreadsheet();
|
||||||
|
|
||||||
// Add some data, we will use some formulas here
|
// Add some data, we will use some formulas here
|
||||||
$helper->log('Add some data and formulas');
|
$helper->log('Add some data and formulas');
|
||||||
|
@ -13,7 +16,7 @@ $spreadsheet->getActiveSheet()->setCellValue('A1', '=B1')
|
||||||
->setCellValue('B1', '=A1+1')
|
->setCellValue('B1', '=A1+1')
|
||||||
->setCellValue('B2', '=A2');
|
->setCellValue('B2', '=A2');
|
||||||
|
|
||||||
\PhpOffice\PhpSpreadsheet\Calculation::getInstance($spreadsheet)->cyclicFormulaCount = 100;
|
Calculation::getInstance($spreadsheet)->cyclicFormulaCount = 100;
|
||||||
|
|
||||||
// Calculated data
|
// Calculated data
|
||||||
$helper->log('Calculated data');
|
$helper->log('Calculated data');
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
|
|
||||||
require __DIR__ . '/Header.php';
|
require __DIR__ . '/Header.php';
|
||||||
$spreadsheet = require __DIR__ . '/templates/sampleSpreadsheet.php';
|
$spreadsheet = require __DIR__ . '/templates/sampleSpreadsheet.php';
|
||||||
|
|
||||||
$filename = $helper->getFilename(__FILE__, 'xls');
|
$filename = $helper->getFilename(__FILE__, 'xls');
|
||||||
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xls');
|
$writer = IOFactory::createWriter($spreadsheet, 'Xls');
|
||||||
|
|
||||||
$callStartTime = microtime(true);
|
$callStartTime = microtime(true);
|
||||||
$writer->save($filename);
|
$writer->save($filename);
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Cell\DataValidation;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
|
||||||
require __DIR__ . '/Header.php';
|
require __DIR__ . '/Header.php';
|
||||||
|
|
||||||
// Create new Spreadsheet object
|
// Create new Spreadsheet object
|
||||||
$helper->log('Create new Spreadsheet object');
|
$helper->log('Create new Spreadsheet object');
|
||||||
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$spreadsheet = new Spreadsheet();
|
||||||
|
|
||||||
// Set document properties
|
// Set document properties
|
||||||
$helper->log('Set document properties');
|
$helper->log('Set document properties');
|
||||||
|
@ -35,8 +38,8 @@ $spreadsheet->getActiveSheet()->setCellValue('A1', 'Cell B3 and B5 contain data
|
||||||
// Set data validation
|
// Set data validation
|
||||||
$helper->log('Set data validation');
|
$helper->log('Set data validation');
|
||||||
$validation = $spreadsheet->getActiveSheet()->getCell('B3')->getDataValidation();
|
$validation = $spreadsheet->getActiveSheet()->getCell('B3')->getDataValidation();
|
||||||
$validation->setType(\PhpOffice\PhpSpreadsheet\Cell\DataValidation::TYPE_WHOLE);
|
$validation->setType(DataValidation::TYPE_WHOLE);
|
||||||
$validation->setErrorStyle(\PhpOffice\PhpSpreadsheet\Cell\DataValidation::STYLE_STOP);
|
$validation->setErrorStyle(DataValidation::STYLE_STOP);
|
||||||
$validation->setAllowBlank(true);
|
$validation->setAllowBlank(true);
|
||||||
$validation->setShowInputMessage(true);
|
$validation->setShowInputMessage(true);
|
||||||
$validation->setShowErrorMessage(true);
|
$validation->setShowErrorMessage(true);
|
||||||
|
@ -48,8 +51,8 @@ $validation->setFormula1(10);
|
||||||
$validation->setFormula2(20);
|
$validation->setFormula2(20);
|
||||||
|
|
||||||
$validation = $spreadsheet->getActiveSheet()->getCell('B5')->getDataValidation();
|
$validation = $spreadsheet->getActiveSheet()->getCell('B5')->getDataValidation();
|
||||||
$validation->setType(\PhpOffice\PhpSpreadsheet\Cell\DataValidation::TYPE_LIST);
|
$validation->setType(DataValidation::TYPE_LIST);
|
||||||
$validation->setErrorStyle(\PhpOffice\PhpSpreadsheet\Cell\DataValidation::STYLE_INFORMATION);
|
$validation->setErrorStyle(DataValidation::STYLE_INFORMATION);
|
||||||
$validation->setAllowBlank(false);
|
$validation->setAllowBlank(false);
|
||||||
$validation->setShowInputMessage(true);
|
$validation->setShowInputMessage(true);
|
||||||
$validation->setShowErrorMessage(true);
|
$validation->setShowErrorMessage(true);
|
||||||
|
@ -61,8 +64,8 @@ $validation->setPrompt('Please pick a value from the drop-down list.');
|
||||||
$validation->setFormula1('"Item A,Item B,Item C"'); // Make sure to put the list items between " and " if your list is simply a comma-separated list of values !!!
|
$validation->setFormula1('"Item A,Item B,Item C"'); // Make sure to put the list items between " and " if your list is simply a comma-separated list of values !!!
|
||||||
|
|
||||||
$validation = $spreadsheet->getActiveSheet()->getCell('B7')->getDataValidation();
|
$validation = $spreadsheet->getActiveSheet()->getCell('B7')->getDataValidation();
|
||||||
$validation->setType(\PhpOffice\PhpSpreadsheet\Cell\DataValidation::TYPE_LIST);
|
$validation->setType(DataValidation::TYPE_LIST);
|
||||||
$validation->setErrorStyle(\PhpOffice\PhpSpreadsheet\Cell\DataValidation::STYLE_INFORMATION);
|
$validation->setErrorStyle(DataValidation::STYLE_INFORMATION);
|
||||||
$validation->setAllowBlank(false);
|
$validation->setAllowBlank(false);
|
||||||
$validation->setShowInputMessage(true);
|
$validation->setShowInputMessage(true);
|
||||||
$validation->setShowErrorMessage(true);
|
$validation->setShowErrorMessage(true);
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
|
|
||||||
require __DIR__ . '/Header.php';
|
require __DIR__ . '/Header.php';
|
||||||
$spreadsheet = require __DIR__ . '/templates/sampleSpreadsheet.php';
|
$spreadsheet = require __DIR__ . '/templates/sampleSpreadsheet.php';
|
||||||
|
|
||||||
$helper->log('Write to CSV format');
|
$helper->log('Write to CSV format');
|
||||||
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Csv')->setDelimiter(',')
|
$writer = IOFactory::createWriter($spreadsheet, 'Csv')->setDelimiter(',')
|
||||||
->setEnclosure('"')
|
->setEnclosure('"')
|
||||||
->setSheetIndex(0);
|
->setSheetIndex(0);
|
||||||
|
|
||||||
|
@ -15,7 +17,7 @@ $helper->logWrite($writer, $filename, $callStartTime);
|
||||||
|
|
||||||
$helper->log('Read from CSV format');
|
$helper->log('Read from CSV format');
|
||||||
|
|
||||||
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Csv')->setDelimiter(',')
|
$reader = IOFactory::createReader('Csv')->setDelimiter(',')
|
||||||
->setEnclosure('"')
|
->setEnclosure('"')
|
||||||
->setSheetIndex(0);
|
->setSheetIndex(0);
|
||||||
|
|
||||||
|
@ -28,7 +30,7 @@ $helper->write($spreadsheetFromCSV, __FILE__, ['Xlsx']);
|
||||||
|
|
||||||
// Write CSV
|
// Write CSV
|
||||||
$filenameCSV = $helper->getFilename(__FILE__, 'csv');
|
$filenameCSV = $helper->getFilename(__FILE__, 'csv');
|
||||||
$writerCSV = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheetFromCSV, 'Csv');
|
$writerCSV = IOFactory::createWriter($spreadsheetFromCSV, 'Csv');
|
||||||
$writerCSV->setExcelCompatibility(true);
|
$writerCSV->setExcelCompatibility(true);
|
||||||
|
|
||||||
$callStartTime = microtime(true);
|
$callStartTime = microtime(true);
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
|
|
||||||
require __DIR__ . '/Header.php';
|
require __DIR__ . '/Header.php';
|
||||||
$spreadsheet = require __DIR__ . '/templates/sampleSpreadsheet.php';
|
$spreadsheet = require __DIR__ . '/templates/sampleSpreadsheet.php';
|
||||||
|
|
||||||
$filename = $helper->getFilename(__FILE__, 'html');
|
$filename = $helper->getFilename(__FILE__, 'html');
|
||||||
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Html');
|
$writer = IOFactory::createWriter($spreadsheet, 'Html');
|
||||||
|
|
||||||
$callStartTime = microtime(true);
|
$callStartTime = microtime(true);
|
||||||
$writer->save($filename);
|
$writer->save($filename);
|
||||||
|
|
|
@ -1,16 +1,18 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
|
||||||
require __DIR__ . '/Header.php';
|
require __DIR__ . '/Header.php';
|
||||||
|
|
||||||
// List functions
|
// List functions
|
||||||
$helper->log('List implemented functions');
|
$helper->log('List implemented functions');
|
||||||
$calc = \PhpOffice\PhpSpreadsheet\Calculation::getInstance();
|
$calc = Calculation::getInstance();
|
||||||
print_r($calc->getImplementedFunctionNames());
|
print_r($calc->getImplementedFunctionNames());
|
||||||
|
|
||||||
// Create new Spreadsheet object
|
// Create new Spreadsheet object
|
||||||
$helper->log('Create new Spreadsheet object');
|
$helper->log('Create new Spreadsheet object');
|
||||||
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$spreadsheet = new Spreadsheet();
|
||||||
|
|
||||||
// Add some data, we will use some formulas here
|
// Add some data, we will use some formulas here
|
||||||
$helper->log('Add some data');
|
$helper->log('Add some data');
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\NamedRange;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
|
||||||
require __DIR__ . '/Header.php';
|
require __DIR__ . '/Header.php';
|
||||||
|
|
||||||
// Create new Spreadsheet object
|
// Create new Spreadsheet object
|
||||||
$helper->log('Create new Spreadsheet object');
|
$helper->log('Create new Spreadsheet object');
|
||||||
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$spreadsheet = new Spreadsheet();
|
||||||
|
|
||||||
// Set document properties
|
// Set document properties
|
||||||
$helper->log('Set document properties');
|
$helper->log('Set document properties');
|
||||||
|
@ -28,8 +31,8 @@ $spreadsheet->getActiveSheet()->setCellValue('A1', 'Firstname:')
|
||||||
|
|
||||||
// Define named ranges
|
// Define named ranges
|
||||||
$helper->log('Define named ranges');
|
$helper->log('Define named ranges');
|
||||||
$spreadsheet->addNamedRange(new \PhpOffice\PhpSpreadsheet\NamedRange('PersonName', $spreadsheet->getActiveSheet(), 'B1'));
|
$spreadsheet->addNamedRange(new NamedRange('PersonName', $spreadsheet->getActiveSheet(), 'B1'));
|
||||||
$spreadsheet->addNamedRange(new \PhpOffice\PhpSpreadsheet\NamedRange('PersonLN', $spreadsheet->getActiveSheet(), 'B2'));
|
$spreadsheet->addNamedRange(new NamedRange('PersonLN', $spreadsheet->getActiveSheet(), 'B2'));
|
||||||
|
|
||||||
// Rename named ranges
|
// Rename named ranges
|
||||||
$helper->log('Rename named ranges');
|
$helper->log('Rename named ranges');
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
|
|
||||||
require __DIR__ . '/Header.php';
|
require __DIR__ . '/Header.php';
|
||||||
|
|
||||||
$filename = __DIR__ . '/templates/Excel2003XMLTest.xml';
|
$filename = __DIR__ . '/templates/Excel2003XMLTest.xml';
|
||||||
$callStartTime = microtime(true);
|
$callStartTime = microtime(true);
|
||||||
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($filename);
|
$spreadsheet = IOFactory::load($filename);
|
||||||
$helper->logRead('Xml', $filename, $callStartTime);
|
$helper->logRead('Xml', $filename, $callStartTime);
|
||||||
|
|
||||||
// Save
|
// Save
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
|
|
||||||
require __DIR__ . '/Header.php';
|
require __DIR__ . '/Header.php';
|
||||||
|
|
||||||
$filename = __DIR__ . '/templates/GnumericTest.gnumeric';
|
$filename = __DIR__ . '/templates/GnumericTest.gnumeric';
|
||||||
$callStartTime = microtime(true);
|
$callStartTime = microtime(true);
|
||||||
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($filename);
|
$spreadsheet = IOFactory::load($filename);
|
||||||
$helper->logRead('Gnumeric', $filename, $callStartTime);
|
$helper->logRead('Gnumeric', $filename, $callStartTime);
|
||||||
|
|
||||||
// Save
|
// Save
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
|
|
||||||
require __DIR__ . '/Header.php';
|
require __DIR__ . '/Header.php';
|
||||||
|
|
||||||
$filename = __DIR__ . '/templates/OOCalcTest.ods';
|
$filename = __DIR__ . '/templates/OOCalcTest.ods';
|
||||||
$callStartTime = microtime(true);
|
$callStartTime = microtime(true);
|
||||||
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($filename);
|
$spreadsheet = IOFactory::load($filename);
|
||||||
$helper->logRead('Ods', $filename, $callStartTime);
|
$helper->logRead('Ods', $filename, $callStartTime);
|
||||||
|
|
||||||
// Save
|
// Save
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
|
|
||||||
require __DIR__ . '/Header.php';
|
require __DIR__ . '/Header.php';
|
||||||
|
|
||||||
$filename = __DIR__ . '/templates/SylkTest.slk';
|
$filename = __DIR__ . '/templates/SylkTest.slk';
|
||||||
$callStartTime = microtime(true);
|
$callStartTime = microtime(true);
|
||||||
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($filename);
|
$spreadsheet = IOFactory::load($filename);
|
||||||
$helper->logRead('Slk', $filename, $callStartTime);
|
$helper->logRead('Slk', $filename, $callStartTime);
|
||||||
|
|
||||||
// Save
|
// Save
|
||||||
|
|
|
@ -1,19 +1,21 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
|
|
||||||
require __DIR__ . '/Header.php';
|
require __DIR__ . '/Header.php';
|
||||||
|
|
||||||
$spreadsheet = require __DIR__ . '/templates/sampleSpreadsheet.php';
|
$spreadsheet = require __DIR__ . '/templates/sampleSpreadsheet.php';
|
||||||
|
|
||||||
// Write temporary file
|
// Write temporary file
|
||||||
$filename = $helper->getTemporaryFilename('xls');
|
$filename = $helper->getTemporaryFilename('xls');
|
||||||
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xls');
|
$writer = IOFactory::createWriter($spreadsheet, 'Xls');
|
||||||
$callStartTime = microtime(true);
|
$callStartTime = microtime(true);
|
||||||
$writer->save($filename);
|
$writer->save($filename);
|
||||||
$helper->logWrite($writer, $filename, $callStartTime);
|
$helper->logWrite($writer, $filename, $callStartTime);
|
||||||
|
|
||||||
// Read Xls file
|
// Read Xls file
|
||||||
$callStartTime = microtime(true);
|
$callStartTime = microtime(true);
|
||||||
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($filename);
|
$spreadsheet = IOFactory::load($filename);
|
||||||
$helper->logRead('Xls', $filename, $callStartTime);
|
$helper->logRead('Xls', $filename, $callStartTime);
|
||||||
|
|
||||||
// Save
|
// Save
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Settings;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup;
|
||||||
|
|
||||||
require __DIR__ . '/Header.php';
|
require __DIR__ . '/Header.php';
|
||||||
$spreadsheet = require __DIR__ . '/templates/sampleSpreadsheet.php';
|
$spreadsheet = require __DIR__ . '/templates/sampleSpreadsheet.php';
|
||||||
|
|
||||||
|
@ -7,11 +10,11 @@ $helper->log('Hide grid lines');
|
||||||
$spreadsheet->getActiveSheet()->setShowGridLines(false);
|
$spreadsheet->getActiveSheet()->setShowGridLines(false);
|
||||||
|
|
||||||
$helper->log('Set orientation to landscape');
|
$helper->log('Set orientation to landscape');
|
||||||
$spreadsheet->getActiveSheet()->getPageSetup()->setOrientation(\PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_LANDSCAPE);
|
$spreadsheet->getActiveSheet()->getPageSetup()->setOrientation(PageSetup::ORIENTATION_LANDSCAPE);
|
||||||
|
|
||||||
$rendererName = \PhpOffice\PhpSpreadsheet\Settings::PDF_RENDERER_DOMPDF;
|
$rendererName = Settings::PDF_RENDERER_DOMPDF;
|
||||||
$helper->log("Write to PDF format using {$rendererName}");
|
$helper->log("Write to PDF format using {$rendererName}");
|
||||||
\PhpOffice\PhpSpreadsheet\Settings::setPdfRendererName($rendererName);
|
Settings::setPdfRendererName($rendererName);
|
||||||
|
|
||||||
// Save
|
// Save
|
||||||
$helper->write($spreadsheet, __FILE__, ['Pdf']);
|
$helper->write($spreadsheet, __FILE__, ['Pdf']);
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Settings;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup;
|
||||||
|
|
||||||
require __DIR__ . '/Header.php';
|
require __DIR__ . '/Header.php';
|
||||||
$spreadsheet = require __DIR__ . '/templates/sampleSpreadsheet.php';
|
$spreadsheet = require __DIR__ . '/templates/sampleSpreadsheet.php';
|
||||||
|
|
||||||
|
@ -7,11 +10,11 @@ $helper->log('Hide grid lines');
|
||||||
$spreadsheet->getActiveSheet()->setShowGridLines(false);
|
$spreadsheet->getActiveSheet()->setShowGridLines(false);
|
||||||
|
|
||||||
$helper->log('Set orientation to landscape');
|
$helper->log('Set orientation to landscape');
|
||||||
$spreadsheet->getActiveSheet()->getPageSetup()->setOrientation(\PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_LANDSCAPE);
|
$spreadsheet->getActiveSheet()->getPageSetup()->setOrientation(PageSetup::ORIENTATION_LANDSCAPE);
|
||||||
|
|
||||||
$rendererName = \PhpOffice\PhpSpreadsheet\Settings::PDF_RENDERER_TCPDF;
|
$rendererName = Settings::PDF_RENDERER_TCPDF;
|
||||||
$helper->log("Write to PDF format using {$rendererName}");
|
$helper->log("Write to PDF format using {$rendererName}");
|
||||||
\PhpOffice\PhpSpreadsheet\Settings::setPdfRendererName($rendererName);
|
Settings::setPdfRendererName($rendererName);
|
||||||
|
|
||||||
// Save
|
// Save
|
||||||
$helper->write($spreadsheet, __FILE__, ['Pdf']);
|
$helper->write($spreadsheet, __FILE__, ['Pdf']);
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Settings;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup;
|
||||||
|
|
||||||
require __DIR__ . '/Header.php';
|
require __DIR__ . '/Header.php';
|
||||||
$spreadsheet = require __DIR__ . '/templates/sampleSpreadsheet.php';
|
$spreadsheet = require __DIR__ . '/templates/sampleSpreadsheet.php';
|
||||||
|
|
||||||
|
@ -7,11 +10,11 @@ $helper->log('Hide grid lines');
|
||||||
$spreadsheet->getActiveSheet()->setShowGridLines(false);
|
$spreadsheet->getActiveSheet()->setShowGridLines(false);
|
||||||
|
|
||||||
$helper->log('Set orientation to landscape');
|
$helper->log('Set orientation to landscape');
|
||||||
$spreadsheet->getActiveSheet()->getPageSetup()->setOrientation(\PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_LANDSCAPE);
|
$spreadsheet->getActiveSheet()->getPageSetup()->setOrientation(PageSetup::ORIENTATION_LANDSCAPE);
|
||||||
|
|
||||||
$rendererName = \PhpOffice\PhpSpreadsheet\Settings::PDF_RENDERER_MPDF;
|
$rendererName = Settings::PDF_RENDERER_MPDF;
|
||||||
$helper->log("Write to PDF format using {$rendererName}");
|
$helper->log("Write to PDF format using {$rendererName}");
|
||||||
\PhpOffice\PhpSpreadsheet\Settings::setPdfRendererName($rendererName);
|
Settings::setPdfRendererName($rendererName);
|
||||||
|
|
||||||
// Save
|
// Save
|
||||||
$helper->write($spreadsheet, __FILE__, ['Pdf']);
|
$helper->write($spreadsheet, __FILE__, ['Pdf']);
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Style\Border;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Style\Fill;
|
||||||
|
|
||||||
require __DIR__ . '/Header.php';
|
require __DIR__ . '/Header.php';
|
||||||
|
|
||||||
// Create new Spreadsheet object
|
// Create new Spreadsheet object
|
||||||
$helper->log('Create new Spreadsheet object');
|
$helper->log('Create new Spreadsheet object');
|
||||||
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$spreadsheet = new Spreadsheet();
|
||||||
|
|
||||||
// Set document properties
|
// Set document properties
|
||||||
$helper->log('Set document properties');
|
$helper->log('Set document properties');
|
||||||
|
@ -22,19 +26,19 @@ $spreadsheet->setActiveSheetIndex(0);
|
||||||
|
|
||||||
$spreadsheet->getActiveSheet()->getStyle('A1:T100')->applyFromArray(
|
$spreadsheet->getActiveSheet()->getStyle('A1:T100')->applyFromArray(
|
||||||
['fill' => [
|
['fill' => [
|
||||||
'type' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
|
'fillType' => Fill::FILL_SOLID,
|
||||||
'color' => ['argb' => 'FFCCFFCC'],
|
'color' => ['argb' => 'FFCCFFCC'],
|
||||||
],
|
],
|
||||||
'borders' => [
|
'borders' => [
|
||||||
'bottom' => ['style' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN],
|
'bottom' => ['borderStyle' => Border::BORDER_THIN],
|
||||||
'right' => ['style' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUM],
|
'right' => ['borderStyle' => Border::BORDER_MEDIUM],
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
$spreadsheet->getActiveSheet()->getStyle('C5:R95')->applyFromArray(
|
$spreadsheet->getActiveSheet()->getStyle('C5:R95')->applyFromArray(
|
||||||
['fill' => [
|
['fill' => [
|
||||||
'type' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
|
'fillType' => Fill::FILL_SOLID,
|
||||||
'color' => ['argb' => 'FFFFFF00'],
|
'color' => ['argb' => 'FFFFFF00'],
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,10 +1,15 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Style;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Style\Border;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Style\Fill;
|
||||||
|
|
||||||
require __DIR__ . '/Header.php';
|
require __DIR__ . '/Header.php';
|
||||||
|
|
||||||
// Create new Spreadsheet object
|
// Create new Spreadsheet object
|
||||||
$helper->log('Create new Spreadsheet object');
|
$helper->log('Create new Spreadsheet object');
|
||||||
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$spreadsheet = new Spreadsheet();
|
||||||
|
|
||||||
// Set document properties
|
// Set document properties
|
||||||
$helper->log('Set document properties');
|
$helper->log('Set document properties');
|
||||||
|
@ -20,29 +25,29 @@ $spreadsheet->getProperties()->setCreator('Maarten Balliauw')
|
||||||
$helper->log('Add some data');
|
$helper->log('Add some data');
|
||||||
$spreadsheet->setActiveSheetIndex(0);
|
$spreadsheet->setActiveSheetIndex(0);
|
||||||
|
|
||||||
$sharedStyle1 = new \PhpOffice\PhpSpreadsheet\Style();
|
$sharedStyle1 = new Style();
|
||||||
$sharedStyle2 = new \PhpOffice\PhpSpreadsheet\Style();
|
$sharedStyle2 = new Style();
|
||||||
|
|
||||||
$sharedStyle1->applyFromArray(
|
$sharedStyle1->applyFromArray(
|
||||||
['fill' => [
|
['fill' => [
|
||||||
'type' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
|
'fillType' => Fill::FILL_SOLID,
|
||||||
'color' => ['argb' => 'FFCCFFCC'],
|
'color' => ['argb' => 'FFCCFFCC'],
|
||||||
],
|
],
|
||||||
'borders' => [
|
'borders' => [
|
||||||
'bottom' => ['style' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN],
|
'bottom' => ['borderStyle' => Border::BORDER_THIN],
|
||||||
'right' => ['style' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUM],
|
'right' => ['borderStyle' => Border::BORDER_MEDIUM],
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
$sharedStyle2->applyFromArray(
|
$sharedStyle2->applyFromArray(
|
||||||
['fill' => [
|
['fill' => [
|
||||||
'type' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
|
'fillType' => Fill::FILL_SOLID,
|
||||||
'color' => ['argb' => 'FFFFFF00'],
|
'color' => ['argb' => 'FFFFFF00'],
|
||||||
],
|
],
|
||||||
'borders' => [
|
'borders' => [
|
||||||
'bottom' => ['style' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN],
|
'bottom' => ['borderStyle' => Border::BORDER_THIN],
|
||||||
'right' => ['style' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_MEDIUM],
|
'right' => ['borderStyle' => Border::BORDER_MEDIUM],
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
|
@ -2,17 +2,20 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpSpreadsheet;
|
namespace PhpOffice\PhpSpreadsheet;
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Reader\IReadFilter;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
||||||
|
|
||||||
require __DIR__ . '/Header.php';
|
require __DIR__ . '/Header.php';
|
||||||
|
|
||||||
// Write temporary file
|
// Write temporary file
|
||||||
$largeSpreadsheet = require __DIR__ . '/templates/largeSpreadsheet.php';
|
$largeSpreadsheet = require __DIR__ . '/templates/largeSpreadsheet.php';
|
||||||
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($largeSpreadsheet);
|
$writer = new Xlsx($largeSpreadsheet);
|
||||||
$filename = $helper->getTemporaryFilename();
|
$filename = $helper->getTemporaryFilename();
|
||||||
$callStartTime = microtime(true);
|
$callStartTime = microtime(true);
|
||||||
$writer->save($filename);
|
$writer->save($filename);
|
||||||
$helper->logWrite($writer, $filename, $callStartTime);
|
$helper->logWrite($writer, $filename, $callStartTime);
|
||||||
|
|
||||||
class MyReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter
|
class MyReadFilter implements IReadFilter
|
||||||
{
|
{
|
||||||
public function readCell($column, $row, $worksheetName = '')
|
public function readCell($column, $row, $worksheetName = '')
|
||||||
{
|
{
|
||||||
|
@ -26,7 +29,7 @@ class MyReadFilter implements \PhpOffice\PhpSpreadsheet\Reader\IReadFilter
|
||||||
}
|
}
|
||||||
|
|
||||||
$helper->log('Load from Xlsx file');
|
$helper->log('Load from Xlsx file');
|
||||||
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xlsx');
|
$reader = IOFactory::createReader('Xlsx');
|
||||||
$reader->setReadFilter(new MyReadFilter());
|
$reader->setReadFilter(new MyReadFilter());
|
||||||
$callStartTime = microtime(true);
|
$callStartTime = microtime(true);
|
||||||
$spreadsheet = $reader->load($filename);
|
$spreadsheet = $reader->load($filename);
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing;
|
||||||
|
|
||||||
require __DIR__ . '/Header.php';
|
require __DIR__ . '/Header.php';
|
||||||
|
|
||||||
// Create new Spreadsheet object
|
// Create new Spreadsheet object
|
||||||
$helper->log('Create new Spreadsheet object');
|
$helper->log('Create new Spreadsheet object');
|
||||||
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$spreadsheet = new Spreadsheet();
|
||||||
|
|
||||||
// Set document properties
|
// Set document properties
|
||||||
$helper->log('Set document properties');
|
$helper->log('Set document properties');
|
||||||
|
@ -24,12 +27,12 @@ imagestring($gdImage, 1, 5, 5, 'Created with PhpSpreadsheet', $textColor);
|
||||||
|
|
||||||
// Add a drawing to the worksheet
|
// Add a drawing to the worksheet
|
||||||
$helper->log('Add a drawing to the worksheet');
|
$helper->log('Add a drawing to the worksheet');
|
||||||
$drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing();
|
$drawing = new MemoryDrawing();
|
||||||
$drawing->setName('Sample image');
|
$drawing->setName('Sample image');
|
||||||
$drawing->setDescription('Sample image');
|
$drawing->setDescription('Sample image');
|
||||||
$drawing->setImageResource($gdImage);
|
$drawing->setImageResource($gdImage);
|
||||||
$drawing->setRenderingFunction(\PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing::RENDERING_JPEG);
|
$drawing->setRenderingFunction(MemoryDrawing::RENDERING_JPEG);
|
||||||
$drawing->setMimeType(\PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing::MIMETYPE_DEFAULT);
|
$drawing->setMimeType(MemoryDrawing::MIMETYPE_DEFAULT);
|
||||||
$drawing->setHeight(36);
|
$drawing->setHeight(36);
|
||||||
$drawing->setWorksheet($spreadsheet->getActiveSheet());
|
$drawing->setWorksheet($spreadsheet->getActiveSheet());
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,19 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Settings;
|
||||||
|
|
||||||
require __DIR__ . '/Header.php';
|
require __DIR__ . '/Header.php';
|
||||||
|
|
||||||
// Change these values to select the PDF Rendering library that you wish to use
|
// Change these values to select the PDF Rendering library that you wish to use
|
||||||
// and its directory location on your server
|
// and its directory location on your server
|
||||||
//$rendererName = \PhpOffice\PhpSpreadsheet\Settings::PDF_RENDERER_TCPDF;
|
//$rendererName = \PhpOffice\PhpSpreadsheet\Settings::PDF_RENDERER_TCPDF;
|
||||||
//$rendererName = \PhpOffice\PhpSpreadsheet\Settings::PDF_RENDERER_MPDF;
|
//$rendererName = \PhpOffice\PhpSpreadsheet\Settings::PDF_RENDERER_MPDF;
|
||||||
$rendererName = \PhpOffice\PhpSpreadsheet\Settings::PDF_RENDERER_DOMPDF;
|
$rendererName = Settings::PDF_RENDERER_DOMPDF;
|
||||||
|
|
||||||
// Read from Xlsx (.xlsx) template
|
// Read from Xlsx (.xlsx) template
|
||||||
$helper->log('Load Xlsx template file');
|
$helper->log('Load Xlsx template file');
|
||||||
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xlsx');
|
$reader = IOFactory::createReader('Xlsx');
|
||||||
$spreadsheet = $reader->load(__DIR__ . '/templates/26template.xlsx');
|
$spreadsheet = $reader->load(__DIR__ . '/templates/26template.xlsx');
|
||||||
|
|
||||||
/* at this point, we could do some manipulations with the template, but we skip this step */
|
/* at this point, we could do some manipulations with the template, but we skip this step */
|
||||||
|
@ -18,7 +21,7 @@ $helper->write($spreadsheet, __FILE__, ['Xlsx', 'Xls', 'Html']);
|
||||||
|
|
||||||
// Export to PDF (.pdf)
|
// Export to PDF (.pdf)
|
||||||
$helper->log('Write to PDF format');
|
$helper->log('Write to PDF format');
|
||||||
\PhpOffice\PhpSpreadsheet\Settings::setPdfRendererName($rendererName);
|
Settings::setPdfRendererName($rendererName);
|
||||||
$helper->write($spreadsheet, __FILE__, ['Pdf']);
|
$helper->write($spreadsheet, __FILE__, ['Pdf']);
|
||||||
|
|
||||||
// Remove first two rows with field headers before exporting to CSV
|
// Remove first two rows with field headers before exporting to CSV
|
||||||
|
@ -28,7 +31,7 @@ $worksheet->removeRow(1, 2);
|
||||||
|
|
||||||
// Export to CSV (.csv)
|
// Export to CSV (.csv)
|
||||||
$helper->log('Write to CSV format');
|
$helper->log('Write to CSV format');
|
||||||
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Csv');
|
$writer = IOFactory::createWriter($spreadsheet, 'Csv');
|
||||||
$filename = $helper->getFilename(__FILE__, 'csv');
|
$filename = $helper->getFilename(__FILE__, 'csv');
|
||||||
$callStartTime = microtime(true);
|
$callStartTime = microtime(true);
|
||||||
$writer->save($filename);
|
$writer->save($filename);
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
|
|
||||||
require __DIR__ . '/Header.php';
|
require __DIR__ . '/Header.php';
|
||||||
|
|
||||||
// Read from Xls (.xls) template
|
// Read from Xls (.xls) template
|
||||||
$helper->log('Load Xlsx template file');
|
$helper->log('Load Xlsx template file');
|
||||||
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xls');
|
$reader = IOFactory::createReader('Xls');
|
||||||
$spreadsheet = $reader->load(__DIR__ . '/templates/27template.xls');
|
$spreadsheet = $reader->load(__DIR__ . '/templates/27template.xls');
|
||||||
|
|
||||||
// Save
|
// Save
|
||||||
|
|
|
@ -1,16 +1,19 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
||||||
|
|
||||||
require __DIR__ . '/Header.php';
|
require __DIR__ . '/Header.php';
|
||||||
|
|
||||||
$sampleSpreadsheet = require __DIR__ . '/templates/sampleSpreadsheet.php';
|
$sampleSpreadsheet = require __DIR__ . '/templates/sampleSpreadsheet.php';
|
||||||
$filename = $helper->getTemporaryFilename();
|
$filename = $helper->getTemporaryFilename();
|
||||||
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($sampleSpreadsheet);
|
$writer = new Xlsx($sampleSpreadsheet);
|
||||||
$callStartTime = microtime(true);
|
$callStartTime = microtime(true);
|
||||||
$writer->save($filename);
|
$writer->save($filename);
|
||||||
$helper->logWrite($writer, $filename, $callStartTime);
|
$helper->logWrite($writer, $filename, $callStartTime);
|
||||||
|
|
||||||
$callStartTime = microtime(true);
|
$callStartTime = microtime(true);
|
||||||
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xlsx');
|
$reader = IOFactory::createReader('Xlsx');
|
||||||
$spreadsheet = $reader->load($filename);
|
$spreadsheet = $reader->load($filename);
|
||||||
$helper->logRead('Xlsx', $filename, $callStartTime);
|
$helper->logRead('Xlsx', $filename, $callStartTime);
|
||||||
$helper->log('Iterate worksheets');
|
$helper->log('Iterate worksheets');
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Cell;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
|
||||||
require __DIR__ . '/Header.php';
|
require __DIR__ . '/Header.php';
|
||||||
|
|
||||||
|
@ -9,11 +11,11 @@ date_default_timezone_set('UTC');
|
||||||
|
|
||||||
// Set value binder
|
// Set value binder
|
||||||
$helper->log('Set value binder');
|
$helper->log('Set value binder');
|
||||||
\PhpOffice\PhpSpreadsheet\Cell::setValueBinder(new \PhpOffice\PhpSpreadsheet\Cell\AdvancedValueBinder());
|
Cell::setValueBinder(new Cell\AdvancedValueBinder());
|
||||||
|
|
||||||
// Create new Spreadsheet object
|
// Create new Spreadsheet object
|
||||||
$helper->log('Create new Spreadsheet object');
|
$helper->log('Create new Spreadsheet object');
|
||||||
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$spreadsheet = new Spreadsheet();
|
||||||
|
|
||||||
// Set document properties
|
// Set document properties
|
||||||
$helper->log('Set document properties');
|
$helper->log('Set document properties');
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Shared\Date;
|
||||||
|
|
||||||
require __DIR__ . '/Header.php';
|
require __DIR__ . '/Header.php';
|
||||||
|
|
||||||
$helper->log('Load from Xls template');
|
$helper->log('Load from Xls template');
|
||||||
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xls');
|
$reader = IOFactory::createReader('Xls');
|
||||||
$spreadsheet = $reader->load(__DIR__ . '/templates/30template.xls');
|
$spreadsheet = $reader->load(__DIR__ . '/templates/30template.xls');
|
||||||
|
|
||||||
$helper->log('Add new data to the template');
|
$helper->log('Add new data to the template');
|
||||||
|
@ -21,7 +24,7 @@ $data = [['title' => 'Excel for dummies',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
$spreadsheet->getActiveSheet()->setCellValue('D1', \PhpOffice\PhpSpreadsheet\Shared\Date::PHPToExcel(time()));
|
$spreadsheet->getActiveSheet()->setCellValue('D1', Date::PHPToExcel(time()));
|
||||||
|
|
||||||
$baseRow = 5;
|
$baseRow = 5;
|
||||||
foreach ($data as $r => $dataRow) {
|
foreach ($data as $r => $dataRow) {
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Document\Properties;
|
||||||
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
|
|
||||||
require __DIR__ . '/Header.php';
|
require __DIR__ . '/Header.php';
|
||||||
|
|
||||||
$inputFileType = 'Xlsx';
|
$inputFileType = 'Xlsx';
|
||||||
$inputFileName = __DIR__ . '/templates/31docproperties.xlsx';
|
$inputFileName = __DIR__ . '/templates/31docproperties.xlsx';
|
||||||
|
|
||||||
$spreadsheetReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
$spreadsheetReader = IOFactory::createReader($inputFileType);
|
||||||
$callStartTime = microtime(true);
|
$callStartTime = microtime(true);
|
||||||
$spreadsheet = $spreadsheetReader->load($inputFileName);
|
$spreadsheet = $spreadsheetReader->load($inputFileName);
|
||||||
$helper->logRead($inputFileType, $inputFileName, $callStartTime);
|
$helper->logRead($inputFileType, $inputFileName, $callStartTime);
|
||||||
|
@ -18,7 +21,7 @@ $spreadsheet->getProperties()->setTitle('Office 2007 XLSX Test Document')
|
||||||
|
|
||||||
// Save Excel 2007 file
|
// Save Excel 2007 file
|
||||||
$filename = $helper->getFilename(__FILE__);
|
$filename = $helper->getFilename(__FILE__);
|
||||||
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx');
|
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
|
||||||
$callStartTime = microtime(true);
|
$callStartTime = microtime(true);
|
||||||
$writer->save($filename);
|
$writer->save($filename);
|
||||||
$helper->logWrite($writer, $filename, $callStartTime);
|
$helper->logWrite($writer, $filename, $callStartTime);
|
||||||
|
@ -28,7 +31,7 @@ $helper->logEndingNotes();
|
||||||
|
|
||||||
// Reread File
|
// Reread File
|
||||||
$helper->log('Reread Xlsx file');
|
$helper->log('Reread Xlsx file');
|
||||||
$spreadsheetRead = \PhpOffice\PhpSpreadsheet\IOFactory::load($filename);
|
$spreadsheetRead = IOFactory::load($filename);
|
||||||
|
|
||||||
// Set properties
|
// Set properties
|
||||||
$helper->log('Get properties');
|
$helper->log('Get properties');
|
||||||
|
@ -53,9 +56,9 @@ $customProperties = $spreadsheet->getProperties()->getCustomProperties();
|
||||||
foreach ($customProperties as $customProperty) {
|
foreach ($customProperties as $customProperty) {
|
||||||
$propertyValue = $spreadsheet->getProperties()->getCustomPropertyValue($customProperty);
|
$propertyValue = $spreadsheet->getProperties()->getCustomPropertyValue($customProperty);
|
||||||
$propertyType = $spreadsheet->getProperties()->getCustomPropertyType($customProperty);
|
$propertyType = $spreadsheet->getProperties()->getCustomPropertyType($customProperty);
|
||||||
if ($propertyType == \PhpOffice\PhpSpreadsheet\Document\Properties::PROPERTY_TYPE_DATE) {
|
if ($propertyType == Properties::PROPERTY_TYPE_DATE) {
|
||||||
$formattedValue = date('d-M-Y H:i:s', $propertyValue);
|
$formattedValue = date('d-M-Y H:i:s', $propertyValue);
|
||||||
} elseif ($propertyType == \PhpOffice\PhpSpreadsheet\Document\Properties::PROPERTY_TYPE_BOOLEAN) {
|
} elseif ($propertyType == Properties::PROPERTY_TYPE_BOOLEAN) {
|
||||||
$formattedValue = $propertyValue ? 'TRUE' : 'FALSE';
|
$formattedValue = $propertyValue ? 'TRUE' : 'FALSE';
|
||||||
} else {
|
} else {
|
||||||
$formattedValue = $propertyValue;
|
$formattedValue = $propertyValue;
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Document\Properties;
|
||||||
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
|
|
||||||
require __DIR__ . '/Header.php';
|
require __DIR__ . '/Header.php';
|
||||||
|
|
||||||
$inputFileType = 'Xls';
|
$inputFileType = 'Xls';
|
||||||
$inputFileName = __DIR__ . '/templates/31docproperties.xls';
|
$inputFileName = __DIR__ . '/templates/31docproperties.xls';
|
||||||
|
|
||||||
$spreadsheetReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
$spreadsheetReader = IOFactory::createReader($inputFileType);
|
||||||
$callStartTime = microtime(true);
|
$callStartTime = microtime(true);
|
||||||
$spreadsheet = $spreadsheetReader->load($inputFileName);
|
$spreadsheet = $spreadsheetReader->load($inputFileName);
|
||||||
$helper->logRead($inputFileType, $inputFileName, $callStartTime);
|
$helper->logRead($inputFileType, $inputFileName, $callStartTime);
|
||||||
|
@ -18,7 +21,7 @@ $spreadsheet->getProperties()->setTitle('Office 95 XLS Test Document')
|
||||||
|
|
||||||
// Save Excel 95 file
|
// Save Excel 95 file
|
||||||
$filename = $helper->getFilename(__FILE__, 'xls');
|
$filename = $helper->getFilename(__FILE__, 'xls');
|
||||||
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xls');
|
$writer = IOFactory::createWriter($spreadsheet, 'Xls');
|
||||||
$callStartTime = microtime(true);
|
$callStartTime = microtime(true);
|
||||||
$writer->save($filename);
|
$writer->save($filename);
|
||||||
$helper->logWrite($writer, $filename, $callStartTime);
|
$helper->logWrite($writer, $filename, $callStartTime);
|
||||||
|
@ -28,7 +31,7 @@ $helper->logEndingNotes();
|
||||||
|
|
||||||
// Reread File
|
// Reread File
|
||||||
$helper->log('Reread Xls file');
|
$helper->log('Reread Xls file');
|
||||||
$spreadsheetRead = \PhpOffice\PhpSpreadsheet\IOFactory::load($filename);
|
$spreadsheetRead = IOFactory::load($filename);
|
||||||
|
|
||||||
// Set properties
|
// Set properties
|
||||||
$helper->log('Get properties');
|
$helper->log('Get properties');
|
||||||
|
@ -53,9 +56,9 @@ $customProperties = $spreadsheet->getProperties()->getCustomProperties();
|
||||||
foreach ($customProperties as $customProperty) {
|
foreach ($customProperties as $customProperty) {
|
||||||
$propertyValue = $spreadsheet->getProperties()->getCustomPropertyValue($customProperty);
|
$propertyValue = $spreadsheet->getProperties()->getCustomPropertyValue($customProperty);
|
||||||
$propertyType = $spreadsheet->getProperties()->getCustomPropertyType($customProperty);
|
$propertyType = $spreadsheet->getProperties()->getCustomPropertyType($customProperty);
|
||||||
if ($propertyType == \PhpOffice\PhpSpreadsheet\Document\Properties::PROPERTY_TYPE_DATE) {
|
if ($propertyType == Properties::PROPERTY_TYPE_DATE) {
|
||||||
$formattedValue = date('d-M-Y H:i:s', $propertyValue);
|
$formattedValue = date('d-M-Y H:i:s', $propertyValue);
|
||||||
} elseif ($propertyType == \PhpOffice\PhpSpreadsheet\Document\Properties::PROPERTY_TYPE_BOOLEAN) {
|
} elseif ($propertyType == Properties::PROPERTY_TYPE_BOOLEAN) {
|
||||||
$formattedValue = $propertyValue ? 'TRUE' : 'FALSE';
|
$formattedValue = $propertyValue ? 'TRUE' : 'FALSE';
|
||||||
} else {
|
} else {
|
||||||
$formattedValue = $propertyValue;
|
$formattedValue = $propertyValue;
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
|
|
||||||
require __DIR__ . '/Header.php';
|
require __DIR__ . '/Header.php';
|
||||||
|
|
||||||
$inputFileType = 'Xlsx';
|
$inputFileType = 'Xlsx';
|
||||||
|
@ -20,7 +22,7 @@ foreach ($inputFileNames as $inputFileName) {
|
||||||
$helper->log('File ' . $inputFileNameShort . ' does not exist');
|
$helper->log('File ' . $inputFileNameShort . ' does not exist');
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
|
$reader = IOFactory::createReader($inputFileType);
|
||||||
$reader->setIncludeCharts(true);
|
$reader->setIncludeCharts(true);
|
||||||
$callStartTime = microtime(true);
|
$callStartTime = microtime(true);
|
||||||
$spreadsheet = $reader->load($inputFileName);
|
$spreadsheet = $reader->load($inputFileName);
|
||||||
|
@ -69,7 +71,7 @@ foreach ($inputFileNames as $inputFileName) {
|
||||||
}
|
}
|
||||||
|
|
||||||
$outputFileName = $helper->getFilename($inputFileName);
|
$outputFileName = $helper->getFilename($inputFileName);
|
||||||
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx');
|
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
|
||||||
$writer->setIncludeCharts(true);
|
$writer->setIncludeCharts(true);
|
||||||
$callStartTime = microtime(true);
|
$callStartTime = microtime(true);
|
||||||
$writer->save($outputFileName);
|
$writer->save($outputFileName);
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue