diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 87d933e2..754a463b 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -124,6 +124,37 @@ jobs:
- name: Code style with PHP_CodeSniffer
run: ./vendor/bin/phpcs -q --report=checkstyle | cs2pr
+ versions:
+ runs-on: ubuntu-latest
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v2
+
+ - name: Setup PHP, with composer and extensions
+ uses: shivammathur/setup-php@v2
+ with:
+ php-version: 7.4
+ extensions: ctype, dom, gd, iconv, fileinfo, libxml, mbstring, simplexml, xml, xmlreader, xmlwriter, zip, zlib
+ coverage: none
+ tools: cs2pr
+
+ - name: Get composer cache directory
+ id: composer-cache
+ run: echo "::set-output name=dir::$(composer config cache-files-dir)"
+
+ - name: Cache composer dependencies
+ uses: actions/cache@v2
+ with:
+ path: ${{ steps.composer-cache.outputs.dir }}
+ key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
+ restore-keys: ${{ runner.os }}-composer-
+
+ - name: Install dependencies
+ run: composer install --no-progress --prefer-dist --optimize-autoloader
+
+ - name: Code Version Compatibility check with PHP_CodeSniffer
+ run: ./vendor/bin/phpcs -q --report-width=200 --report=summary,full src/ --standard=PHPCompatibility --runtime-set testVersion 7.2-
+
phpstan:
runs-on: ubuntu-latest
steps:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index bb09f628..de7283bb 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,8 +9,13 @@ and this project adheres to [Semantic Versioning](https://semver.org).
### Added
+- Implemented basic AutoFiltering for Ods Reader and Writer [PR #2053](https://github.com/PHPOffice/PhpSpreadsheet/pull/2053)
+- Implemented basic AutoFiltering for Gnumeric Reader [PR #2055](https://github.com/PHPOffice/PhpSpreadsheet/pull/2055)
+- Improved support for Row and Column ranges in formulae [Issue #1755](https://github.com/PHPOffice/PhpSpreadsheet/issues/1755) [PR #2028](https://github.com/PHPOffice/PhpSpreadsheet/pull/2028)
+- Implemented URLENCODE() Web Function
- Implemented the CHITEST(), CHISQ.DIST() and CHISQ.INV() and equivalent Statistical functions, for both left- and right-tailed distributions.
- Support for ActiveSheet and SelectedCells in the ODS Reader and Writer. [PR #1908](https://github.com/PHPOffice/PhpSpreadsheet/pull/1908)
+- Support for notContainsText Conditional Style in xlsx [Issue #984](https://github.com/PHPOffice/PhpSpreadsheet/issues/984)
### Changed
@@ -18,14 +23,15 @@ and this project adheres to [Semantic Versioning](https://semver.org).
### Deprecated
-- Nothing.
+- All Excel Function implementations in `Calculation\Database`, `Calculation\DateTime`, `Calculation\Engineering`, `Calculation\Financial`, `Calculation\Logical`, `Calculation\LookupRef`, `Calculation\MathTrig`, `Calculation\Statistical`, `Calculation\TextData` and `Calculation\Web` have been moved to dedicated classes for individual functions or groups of related functions. See the docblocks against all the deprecated methods for details of the new methods to call instead. At some point, these old classes will be deleted.
### Removed
- Nothing.
### Fixed
-
+- Correctly handle absolute A1 references when converting to R1C1 format [PR #2060](https://github.com/PHPOffice/PhpSpreadsheet/pull/2060)
+- Correct default fill style for conditional without a pattern defined [Issue #2035](https://github.com/PHPOffice/PhpSpreadsheet/issues/2035) [PR #2050](https://github.com/PHPOffice/PhpSpreadsheet/pull/2050)
- Fixed issue where array key check for existince before accessing arrays in Xlsx.php. [PR #1970](https://github.com/PHPOffice/PhpSpreadsheet/pull/1970)
- Fixed issue with quoted strings in number format mask rendered with toFormattedString() [Issue 1972#](https://github.com/PHPOffice/PhpSpreadsheet/issues/1972) [PR #1978](https://github.com/PHPOffice/PhpSpreadsheet/pull/1978)
- Fixed issue with percentage formats in number format mask rendered with toFormattedString() [Issue 1929#](https://github.com/PHPOffice/PhpSpreadsheet/issues/1929) [PR #1928](https://github.com/PHPOffice/PhpSpreadsheet/pull/1928)
diff --git a/composer.json b/composer.json
index 6cd65021..314f21cd 100644
--- a/composer.json
+++ b/composer.json
@@ -53,7 +53,6 @@
},
"require": {
"php": "^7.2 || ^8.0",
- "ext-simplexml": "*",
"ext-ctype": "*",
"ext-dom": "*",
"ext-fileinfo": "*",
@@ -61,6 +60,7 @@
"ext-iconv": "*",
"ext-libxml": "*",
"ext-mbstring": "*",
+ "ext-simplexml": "*",
"ext-xml": "*",
"ext-xmlreader": "*",
"ext-xmlwriter": "*",
@@ -75,6 +75,7 @@
"psr/simple-cache": "^1.0"
},
"require-dev": {
+ "dealerdirect/phpcodesniffer-composer-installer": "dev-master",
"dompdf/dompdf": "^1.0",
"friendsofphp/php-cs-fixer": "^2.18",
"jpgraph/jpgraph": "^4.0",
diff --git a/composer.lock b/composer.lock
index 3670f857..4921cc8f 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "3be2673a6367d296c616bf9c34b77953",
+ "content-hash": "9158fcde13425499acaf0da201637737",
"packages": [
{
"name": "ezyang/htmlpurifier",
@@ -802,6 +802,77 @@
],
"time": "2021-03-25T17:01:18+00:00"
},
+ {
+ "name": "dealerdirect/phpcodesniffer-composer-installer",
+ "version": "dev-master",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/Dealerdirect/phpcodesniffer-composer-installer.git",
+ "reference": "c960cf4629fab7155caca18c038ca7257b7595e3"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/Dealerdirect/phpcodesniffer-composer-installer/zipball/c960cf4629fab7155caca18c038ca7257b7595e3",
+ "reference": "c960cf4629fab7155caca18c038ca7257b7595e3",
+ "shasum": ""
+ },
+ "require": {
+ "composer-plugin-api": "^1.0 || ^2.0",
+ "php": ">=5.3",
+ "squizlabs/php_codesniffer": "^2.0 || ^3.0 || ^4.0"
+ },
+ "require-dev": {
+ "composer/composer": "*",
+ "enlightn/security-checker": "^1.2",
+ "phpcompatibility/php-compatibility": "^9.0"
+ },
+ "default-branch": true,
+ "type": "composer-plugin",
+ "extra": {
+ "class": "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin"
+ },
+ "autoload": {
+ "psr-4": {
+ "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\": "src/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Franck Nijhof",
+ "email": "franck.nijhof@dealerdirect.com",
+ "homepage": "http://www.frenck.nl",
+ "role": "Developer / IT Manager"
+ }
+ ],
+ "description": "PHP_CodeSniffer Standards Composer Installer Plugin",
+ "homepage": "http://www.dealerdirect.com",
+ "keywords": [
+ "PHPCodeSniffer",
+ "PHP_CodeSniffer",
+ "code quality",
+ "codesniffer",
+ "composer",
+ "installer",
+ "phpcs",
+ "plugin",
+ "qa",
+ "quality",
+ "standard",
+ "standards",
+ "style guide",
+ "stylecheck",
+ "tests"
+ ],
+ "support": {
+ "issues": "https://github.com/dealerdirect/phpcodesniffer-composer-installer/issues",
+ "source": "https://github.com/dealerdirect/phpcodesniffer-composer-installer"
+ },
+ "time": "2021-03-14T13:49:41+00:00"
+ },
{
"name": "doctrine/annotations",
"version": "1.12.1",
@@ -5065,12 +5136,13 @@
],
"aliases": [],
"minimum-stability": "stable",
- "stability-flags": [],
+ "stability-flags": {
+ "dealerdirect/phpcodesniffer-composer-installer": 20
+ },
"prefer-stable": false,
"prefer-lowest": false,
"platform": {
"php": "^7.2 || ^8.0",
- "ext-simplexml": "*",
"ext-ctype": "*",
"ext-dom": "*",
"ext-fileinfo": "*",
@@ -5078,6 +5150,7 @@
"ext-iconv": "*",
"ext-libxml": "*",
"ext-mbstring": "*",
+ "ext-simplexml": "*",
"ext-xml": "*",
"ext-xmlreader": "*",
"ext-xmlwriter": "*",
diff --git a/docs/references/features-cross-reference.md b/docs/references/features-cross-reference.md
index 716a3787..c836a99a 100644
--- a/docs/references/features-cross-reference.md
+++ b/docs/references/features-cross-reference.md
@@ -1220,13 +1220,13 @@
| Merged Cells |
- |
- |
- |
- |
+ ✔ |
✔ |
|
- |
+ ✔ |
+ ✔ |
+ N/A |
+ N/A |
|
|
|
@@ -1313,13 +1313,13 @@
● |
● |
|
- |
- |
+ ● |
+ ● |
|
|
● |
● |
- |
+ ● |
|
|
|
diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon
index 6390e0fc..b209e822 100644
--- a/phpstan-baseline.neon
+++ b/phpstan-baseline.neon
@@ -340,141 +340,6 @@ parameters:
count: 1
path: src/PhpSpreadsheet/Calculation/Database/DatabaseAbstract.php
- -
- message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\DateTime\\:\\:NETWORKDAYS\\(\\) has parameter \\$dateArgs with no typehint specified\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Calculation/DateTime.php
-
- -
- message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\DateTime\\:\\:WORKDAY\\(\\) has parameter \\$dateArgs with no typehint specified\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Calculation/DateTime.php
-
- -
- message: "#^Parameter \\#3 \\$subject of function str_replace expects array\\|string, string\\|null given\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Calculation/DateTimeExcel/DateValue.php
-
- -
- message: "#^Parameter \\#1 \\$haystack of function strpos expects string, float\\|int\\|string given\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Calculation/DateTimeExcel/DateValue.php
-
- -
- message: "#^Parameter \\#1 \\$PHPDateArray of static method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\DateTimeExcel\\\\DateValue\\:\\:finalResults\\(\\) expects array\\|false, array\\|bool given\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Calculation/DateTimeExcel/DateValue.php
-
- -
- message: "#^Parameter \\#1 \\$testVal1 of static method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\DateTimeExcel\\\\Helpers\\:\\:adjustYear\\(\\) expects string, string\\|false given\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Calculation/DateTimeExcel/DateValue.php
-
- -
- message: "#^Parameter \\#2 \\$testVal2 of static method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\DateTimeExcel\\\\Helpers\\:\\:adjustYear\\(\\) expects string, string\\|false given\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Calculation/DateTimeExcel/DateValue.php
-
- -
- message: "#^Parameter \\#1 \\$value of static method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\StringHelper\\:\\:testStringAsNumeric\\(\\) expects string, float\\|int\\|string given\\.$#"
- count: 2
- path: src/PhpSpreadsheet/Calculation/DateTimeExcel/Datefunc.php
-
- -
- message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\DateTimeExcel\\\\Day\\:\\:weirdCondition\\(\\) has parameter \\$dateValue with no typehint specified\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Calculation/DateTimeExcel/Day.php
-
- -
- message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\DateTimeExcel\\\\Helpers\\:\\:adjustDateByMonths\\(\\) has no return typehint specified\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Calculation/DateTimeExcel/Helpers.php
-
- -
- message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\DateTimeExcel\\\\Helpers\\:\\:adjustDateByMonths\\(\\) has parameter \\$adjustmentMonths with no typehint specified\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Calculation/DateTimeExcel/Helpers.php
-
- -
- message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\DateTimeExcel\\\\Helpers\\:\\:adjustDateByMonths\\(\\) has parameter \\$dateValue with no typehint specified\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Calculation/DateTimeExcel/Helpers.php
-
- -
- message: "#^Parameter \\#1 \\$excelTimestamp of static method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Date\\:\\:excelToTimestamp\\(\\) expects float\\|int, bool\\|float given\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Calculation/DateTimeExcel/Helpers.php
-
- -
- message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\DateTimeExcel\\\\Helpers\\:\\:validateNumericNull\\(\\) should return float\\|int but returns float\\|int\\|string\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Calculation/DateTimeExcel/Helpers.php
-
- -
- message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\DateTimeExcel\\\\IsoWeekNum\\:\\:apparentBug\\(\\) has parameter \\$dateValue with no typehint specified\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Calculation/DateTimeExcel/IsoWeekNum.php
-
- -
- message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\DateTimeExcel\\\\NetworkDays\\:\\:funcNetworkDays\\(\\) has parameter \\$dateArgs with no typehint specified\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Calculation/DateTimeExcel/NetworkDays.php
-
- -
- message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\DateTimeExcel\\\\NetworkDays\\:\\:applySign\\(\\) has no return typehint specified\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Calculation/DateTimeExcel/NetworkDays.php
-
- -
- message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\DateTimeExcel\\\\Time\\:\\:toIntWithNullBool\\(\\) has parameter \\$value with no typehint specified\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Calculation/DateTimeExcel/Time.php
-
- -
- message: "#^Cannot access offset 0 on array\\\\|false\\.$#"
- count: 3
- path: src/PhpSpreadsheet/Calculation/DateTimeExcel/TimeValue.php
-
- -
- message: "#^Parameter \\#1 \\$var of function count expects array\\|Countable, array\\\\|false given\\.$#"
- count: 2
- path: src/PhpSpreadsheet/Calculation/DateTimeExcel/TimeValue.php
-
- -
- message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\DateTimeExcel\\\\WeekDay\\:\\:validateStyle\\(\\) has parameter \\$style with no typehint specified\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Calculation/DateTimeExcel/WeekDay.php
-
- -
- message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\DateTimeExcel\\\\WorkDay\\:\\:funcWorkDay\\(\\) has parameter \\$dateArgs with no typehint specified\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Calculation/DateTimeExcel/WorkDay.php
-
- -
- message: "#^Binary operation \"\\-\" between 7 and int\\|string results in an error\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Calculation/DateTimeExcel/WorkDay.php
-
- -
- message: "#^Binary operation \"\\-\" between 7 and int\\<5, max\\>\\|string results in an error\\.$#"
- count: 2
- path: src/PhpSpreadsheet/Calculation/DateTimeExcel/WorkDay.php
-
- -
- message: "#^Binary operation \"\\-\" between 4 and int\\<5, max\\>\\|string results in an error\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Calculation/DateTimeExcel/WorkDay.php
-
- -
- message: "#^Binary operation \"\\-\" between int\\|string and int\\|string results in an error\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Calculation/DateTimeExcel/YearFrac.php
-
- -
- message: "#^Binary operation \"\\*\" between 100 and int\\|string results in an error\\.$#"
- count: 2
- path: src/PhpSpreadsheet/Calculation/DateTimeExcel/YearFrac.php
-
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Engine\\\\Logger\\:\\:writeDebugLog\\(\\) has parameter \\$args with no typehint specified\\.$#"
count: 1
@@ -960,16 +825,6 @@ parameters:
count: 1
path: src/PhpSpreadsheet/Calculation/LookupRef.php
- -
- message: "#^Call to function is_bool\\(\\) with float\\|int\\|\\(string&numeric\\) will always evaluate to false\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Calculation/LookupRef.php
-
- -
- message: "#^Cannot call method getCell\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Worksheet\\|null\\.$#"
- count: 2
- path: src/PhpSpreadsheet/Calculation/LookupRef.php
-
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\LookupRef\\\\Address\\:\\:sheetName\\(\\) has no return typehint specified\\.$#"
count: 1
@@ -1120,11 +975,6 @@ parameters:
count: 1
path: src/PhpSpreadsheet/Calculation/LookupRef/LookupBase.php
- -
- message: "#^Parameter \\#3 \\$rowNum of static method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\LookupRef\\\\Matrix\\:\\:extractRowValue\\(\\) expects int, float\\|int\\<0, max\\>\\|string given\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Calculation/LookupRef/Matrix.php
-
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\LookupRef\\\\Matrix\\:\\:extractRowValue\\(\\) has no return typehint specified\\.$#"
count: 1
@@ -1230,141 +1080,6 @@ parameters:
count: 1
path: src/PhpSpreadsheet/Calculation/LookupRef/VLookup.php
- -
- message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\MathTrig\\:\\:COMBIN\\(\\) should return int\\|string but returns float\\|int\\|string\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Calculation/MathTrig.php
-
- -
- message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\MathTrig\\:\\:EVEN\\(\\) should return int\\|string but returns float\\|string\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Calculation/MathTrig.php
-
- -
- message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\MathTrig\\:\\:FACT\\(\\) should return int\\|string but returns float\\|int\\|string\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Calculation/MathTrig.php
-
- -
- message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\MathTrig\\:\\:FACTDOUBLE\\(\\) should return int\\|string but returns float\\|int\\|string\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Calculation/MathTrig.php
-
- -
- message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\MathTrig\\:\\:MOD\\(\\) should return int\\|string but returns float\\|int\\|string\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Calculation/MathTrig.php
-
- -
- message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\MathTrig\\:\\:ODD\\(\\) should return int\\|string but returns float\\|string\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Calculation/MathTrig.php
-
- -
- message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\MathTrig\\:\\:SUMIFS\\(\\) should return float\\|string but returns float\\|string\\|null\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Calculation/MathTrig.php
-
- -
- message: "#^Else branch is unreachable because ternary operator condition is always true\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Calculation/MathTrig/Arabic.php
-
- -
- message: "#^Parameter \\#1 \\$number of function base_convert expects string, int\\<0, 9007199254740991\\> given\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Calculation/MathTrig/Base.php
-
- -
- message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\MathTrig\\\\Helpers\\:\\:validateNumericNullBool\\(\\) should return float\\|int but returns float\\|int\\|string\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Calculation/MathTrig/Helpers.php
-
- -
- message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\MathTrig\\\\Helpers\\:\\:validateNumericNullSubstitution\\(\\) should return float\\|int but returns float\\|int\\|string\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Calculation/MathTrig/Helpers.php
-
- -
- message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\MathTrig\\\\Lcm\\:\\:factors\\(\\) has no return typehint specified\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Calculation/MathTrig/Lcm.php
-
- -
- message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\MathTrig\\\\Lcm\\:\\:factors\\(\\) has parameter \\$value with no typehint specified\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Calculation/MathTrig/Lcm.php
-
- -
- message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\MathTrig\\\\Roman\\:\\:romanCut\\(\\) has no return typehint specified\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Calculation/MathTrig/Roman.php
-
- -
- message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\MathTrig\\\\Roman\\:\\:romanCut\\(\\) has parameter \\$n with no typehint specified\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Calculation/MathTrig/Roman.php
-
- -
- message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\MathTrig\\\\Roman\\:\\:romanCut\\(\\) has parameter \\$num with no typehint specified\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Calculation/MathTrig/Roman.php
-
- -
- message: "#^Parameter \\#2 \\$precision of function round expects int, float\\|int given\\.$#"
- count: 2
- path: src/PhpSpreadsheet/Calculation/MathTrig/RoundDown.php
-
- -
- message: "#^Parameter \\#2 \\$precision of function round expects int, float\\|int given\\.$#"
- count: 2
- path: src/PhpSpreadsheet/Calculation/MathTrig/RoundUp.php
-
- -
- message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\MathTrig\\\\Subtotal\\:\\:filterHiddenArgs\\(\\) has no return typehint specified\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Calculation/MathTrig/Subtotal.php
-
- -
- message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\MathTrig\\\\Subtotal\\:\\:filterHiddenArgs\\(\\) has parameter \\$args with no typehint specified\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Calculation/MathTrig/Subtotal.php
-
- -
- message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\MathTrig\\\\Subtotal\\:\\:filterHiddenArgs\\(\\) has parameter \\$cellReference with no typehint specified\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Calculation/MathTrig/Subtotal.php
-
- -
- message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\MathTrig\\\\Subtotal\\:\\:filterFormulaArgs\\(\\) has no return typehint specified\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Calculation/MathTrig/Subtotal.php
-
- -
- message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\MathTrig\\\\Subtotal\\:\\:filterFormulaArgs\\(\\) has parameter \\$args with no typehint specified\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Calculation/MathTrig/Subtotal.php
-
- -
- message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\MathTrig\\\\Subtotal\\:\\:filterFormulaArgs\\(\\) has parameter \\$cellReference with no typehint specified\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Calculation/MathTrig/Subtotal.php
-
- -
- message: "#^Parameter \\#1 \\$function of function call_user_func_array expects callable\\(\\)\\: mixed, array\\('PhpOffice…'\\|'PhpOffice…'\\|'PhpOffice…'\\|'PhpOffice…'\\|'PhpOffice…'\\|'PhpOffice…'\\|'PhpOffice…'\\|'PhpOffice…', string\\) given\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Calculation/MathTrig/Subtotal.php
-
- -
- message: "#^Parameter \\#1 \\$str of function rtrim expects string, int given\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Calculation/MathTrig/Trunc.php
-
- -
- message: "#^Binary operation \"\\-\" between float\\|int and float\\|string results in an error\\.$#"
- count: 4
- path: src/PhpSpreadsheet/Calculation/Statistical.php
-
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\:\\:MAXIFS\\(\\) should return float but returns float\\|string\\|null\\.$#"
count: 1
@@ -2825,91 +2540,6 @@ parameters:
count: 1
path: src/PhpSpreadsheet/Reader/Csv/Delimiter.php
- -
- message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Gnumeric\\:\\:\\$referenceHelper has no typehint specified\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Reader/Gnumeric.php
-
- -
- message: "#^Parameter \\#1 \\$fp of function fread expects resource, resource\\|false given\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Reader/Gnumeric.php
-
- -
- message: "#^Parameter \\#1 \\$fp of function fclose expects resource, resource\\|false given\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Reader/Gnumeric.php
-
- -
- message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Gnumeric\\:\\:\\$mappings has no typehint specified\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Reader/Gnumeric.php
-
- -
- message: "#^Offset 'No' does not exist on SimpleXMLElement\\|null\\.$#"
- count: 2
- path: src/PhpSpreadsheet/Reader/Gnumeric.php
-
- -
- message: "#^Offset 'Unit' does not exist on SimpleXMLElement\\|null\\.$#"
- count: 2
- path: src/PhpSpreadsheet/Reader/Gnumeric.php
-
- -
- message: "#^Cannot call method setWidth\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\ColumnDimension\\|null\\.$#"
- count: 3
- path: src/PhpSpreadsheet/Reader/Gnumeric.php
-
- -
- message: "#^Cannot call method setVisible\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\ColumnDimension\\|null\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Reader/Gnumeric.php
-
- -
- message: "#^Offset 'DefaultSizePts' does not exist on SimpleXMLElement\\|null\\.$#"
- count: 2
- path: src/PhpSpreadsheet/Reader/Gnumeric.php
-
- -
- message: "#^Cannot call method setRowHeight\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\RowDimension\\|null\\.$#"
- count: 2
- path: src/PhpSpreadsheet/Reader/Gnumeric.php
-
- -
- message: "#^Cannot call method setVisible\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\RowDimension\\|null\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Reader/Gnumeric.php
-
- -
- message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Gnumeric\\:\\:parseBorderAttributes\\(\\) has no return typehint specified\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Reader/Gnumeric.php
-
- -
- message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Gnumeric\\:\\:parseBorderAttributes\\(\\) has parameter \\$borderAttributes with no typehint specified\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Reader/Gnumeric.php
-
- -
- message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Gnumeric\\:\\:parseRichText\\(\\) has no return typehint specified\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Reader/Gnumeric.php
-
- -
- message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Gnumeric\\:\\:parseRichText\\(\\) has parameter \\$is with no typehint specified\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Reader/Gnumeric.php
-
- -
- message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Gnumeric\\:\\:parseGnumericColour\\(\\) has no return typehint specified\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Reader/Gnumeric.php
-
- -
- message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Gnumeric\\:\\:parseGnumericColour\\(\\) has parameter \\$gnmColour with no typehint specified\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Reader/Gnumeric.php
-
-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Html\\:\\:\\$rowspan has no typehint specified\\.$#"
count: 1
@@ -3025,16 +2655,6 @@ parameters:
count: 1
path: src/PhpSpreadsheet/Reader/Html.php
- -
- message: "#^Cannot call method setRowHeight\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\RowDimension\\|null\\.$#"
- count: 4
- path: src/PhpSpreadsheet/Reader/Html.php
-
- -
- message: "#^Cannot call method setWidth\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\ColumnDimension\\|null\\.$#"
- count: 3
- path: src/PhpSpreadsheet/Reader/Html.php
-
-
message: "#^Parameter \\#2 \\$styleValue of method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Html\\:\\:setBorderStyle\\(\\) expects string, string\\|null given\\.$#"
count: 5
@@ -3120,21 +2740,6 @@ parameters:
count: 1
path: src/PhpSpreadsheet/Reader/Ods.php
- -
- message: "#^Parameter \\#3 \\$subject of function preg_replace expects array\\|string, string\\|null given\\.$#"
- count: 7
- path: src/PhpSpreadsheet/Reader/Ods.php
-
- -
- message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Ods\\:\\:convertToExcelAddressValue\\(\\) should return string but returns string\\|null\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Reader/Ods.php
-
- -
- message: "#^Parameter \\#3 \\$formula of static method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Calculation\\:\\:translateSeparator\\(\\) expects string, string\\|null given\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Reader/Ods.php
-
-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Ods\\\\PageSettings\\:\\:\\$officeNs has no typehint specified\\.$#"
count: 1
@@ -3285,11 +2890,6 @@ parameters:
count: 3
path: src/PhpSpreadsheet/Reader/Slk.php
- -
- message: "#^Cannot call method setWidth\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\ColumnDimension\\|null\\.$#"
- count: 3
- path: src/PhpSpreadsheet/Reader/Slk.php
-
-
message: "#^Call to an undefined method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Escher\\|PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Escher\\\\DgContainer\\|PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Escher\\\\DgContainer\\\\SpgrContainer\\|PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Escher\\\\DgContainer\\\\SpgrContainer\\\\SpContainer\\|PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Escher\\\\DggContainer\\|PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Escher\\\\DggContainer\\\\BstoreContainer\\|PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Escher\\\\DggContainer\\\\BstoreContainer\\\\BSE\\:\\:getDgContainer\\(\\)\\.$#"
count: 1
@@ -3490,56 +3090,6 @@ parameters:
count: 1
path: src/PhpSpreadsheet/Reader/Xls.php
- -
- message: "#^Cannot call method setWidth\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\ColumnDimension\\|null\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Reader/Xls.php
-
- -
- message: "#^Cannot call method setVisible\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\ColumnDimension\\|null\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Reader/Xls.php
-
- -
- message: "#^Cannot call method setOutlineLevel\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\ColumnDimension\\|null\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Reader/Xls.php
-
- -
- message: "#^Cannot call method setCollapsed\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\ColumnDimension\\|null\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Reader/Xls.php
-
- -
- message: "#^Cannot call method setXfIndex\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\ColumnDimension\\|null\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Reader/Xls.php
-
- -
- message: "#^Cannot call method setRowHeight\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\RowDimension\\|null\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Reader/Xls.php
-
- -
- message: "#^Cannot call method setOutlineLevel\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\RowDimension\\|null\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Reader/Xls.php
-
- -
- message: "#^Cannot call method setCollapsed\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\RowDimension\\|null\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Reader/Xls.php
-
- -
- message: "#^Cannot call method setVisible\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\RowDimension\\|null\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Reader/Xls.php
-
- -
- message: "#^Cannot call method setXfIndex\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\RowDimension\\|null\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Reader/Xls.php
-
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xls\\:\\:includeCellRangeFiltered\\(\\) has no return typehint specified\\.$#"
count: 1
@@ -3725,16 +3275,6 @@ parameters:
count: 1
path: src/PhpSpreadsheet/Reader/Xls/RC4.php
- -
- message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xls\\\\Style\\\\Border\\:\\:\\$map has no typehint specified\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Reader/Xls/Style/Border.php
-
- -
- message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xls\\\\Style\\\\FillPattern\\:\\:\\$map has no typehint specified\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Reader/Xls/Style/FillPattern.php
-
-
message: "#^Cannot access property \\$Relationship on SimpleXMLElement\\|false\\.$#"
count: 12
@@ -3940,31 +3480,6 @@ parameters:
count: 1
path: src/PhpSpreadsheet/Reader/Xlsx.php
- -
- message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\:\\:readColor\\(\\) has no return typehint specified\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Reader/Xlsx.php
-
- -
- message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\:\\:readColor\\(\\) has parameter \\$background with no typehint specified\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Reader/Xlsx.php
-
- -
- message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xlsx\\:\\:readColor\\(\\) has parameter \\$color with no typehint specified\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Reader/Xlsx.php
-
- -
- message: "#^Parameter \\#1 \\$hex of static method PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\Color\\:\\:changeBrightness\\(\\) expects string, string\\|null given\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Reader/Xlsx.php
-
- -
- message: "#^Parameter \\#1 \\$pValue of method PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\Font\\:\\:setSize\\(\\) expects float, string given\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Reader/Xlsx.php
-
-
message: "#^Cannot access property \\$r on SimpleXMLElement\\|null\\.$#"
count: 2
@@ -4740,16 +4255,6 @@ parameters:
count: 1
path: src/PhpSpreadsheet/Reader/Xml.php
- -
- message: "#^Cannot call method setWidth\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\ColumnDimension\\|null\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Reader/Xml.php
-
- -
- message: "#^Cannot call method setRowHeight\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\RowDimension\\|null\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Reader/Xml.php
-
-
message: "#^Parameter \\#2 \\$cmp_function of function uksort expects callable\\(mixed, mixed\\)\\: int, array\\('self', 'cellReverseSort'\\) given\\.$#"
count: 4
@@ -4760,61 +4265,11 @@ parameters:
count: 4
path: src/PhpSpreadsheet/ReferenceHelper.php
- -
- message: "#^Parameter \\#2 \\$pPassword of method PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Worksheet\\:\\:protectCells\\(\\) expects string, array given\\.$#"
- count: 1
- path: src/PhpSpreadsheet/ReferenceHelper.php
-
-
message: "#^Parameter \\#1 \\$index of method PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\RowDimension\\:\\:setRowIndex\\(\\) expects int, string given\\.$#"
count: 1
path: src/PhpSpreadsheet/ReferenceHelper.php
- -
- message: "#^Cannot call method getRowHeight\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\RowDimension\\|null\\.$#"
- count: 1
- path: src/PhpSpreadsheet/ReferenceHelper.php
-
- -
- message: "#^Cannot call method setRowHeight\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\RowDimension\\|null\\.$#"
- count: 1
- path: src/PhpSpreadsheet/ReferenceHelper.php
-
- -
- message: "#^Cannot call method getVisible\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\RowDimension\\|null\\.$#"
- count: 1
- path: src/PhpSpreadsheet/ReferenceHelper.php
-
- -
- message: "#^Cannot call method setVisible\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\RowDimension\\|null\\.$#"
- count: 1
- path: src/PhpSpreadsheet/ReferenceHelper.php
-
- -
- message: "#^Cannot call method getOutlineLevel\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\RowDimension\\|null\\.$#"
- count: 1
- path: src/PhpSpreadsheet/ReferenceHelper.php
-
- -
- message: "#^Cannot call method setOutlineLevel\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\RowDimension\\|null\\.$#"
- count: 1
- path: src/PhpSpreadsheet/ReferenceHelper.php
-
- -
- message: "#^Cannot call method getCollapsed\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\RowDimension\\|null\\.$#"
- count: 1
- path: src/PhpSpreadsheet/ReferenceHelper.php
-
- -
- message: "#^Cannot call method setCollapsed\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\RowDimension\\|null\\.$#"
- count: 1
- path: src/PhpSpreadsheet/ReferenceHelper.php
-
- -
- message: "#^Cannot call method setXfIndex\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Cell\\\\Cell\\|null\\.$#"
- count: 1
- path: src/PhpSpreadsheet/ReferenceHelper.php
-
-
message: "#^Parameter \\#1 \\$columnIndex of static method PhpOffice\\\\PhpSpreadsheet\\\\Cell\\\\Coordinate\\:\\:stringFromColumnIndex\\(\\) expects int, float\\|int given\\.$#"
count: 1
@@ -6230,36 +5685,6 @@ parameters:
count: 1
path: src/PhpSpreadsheet/Style/Style.php
- -
- message: "#^Cannot call method getXfIndex\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\ColumnDimension\\|null\\.$#"
- count: 2
- path: src/PhpSpreadsheet/Style/Style.php
-
- -
- message: "#^Cannot call method setXfIndex\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\ColumnDimension\\|null\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Style/Style.php
-
- -
- message: "#^Cannot call method getXfIndex\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\RowDimension\\|null\\.$#"
- count: 3
- path: src/PhpSpreadsheet/Style/Style.php
-
- -
- message: "#^Cannot call method setXfIndex\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\RowDimension\\|null\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Style/Style.php
-
- -
- message: "#^Cannot call method getXfIndex\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Cell\\\\Cell\\|null\\.$#"
- count: 2
- path: src/PhpSpreadsheet/Style/Style.php
-
- -
- message: "#^Cannot call method setXfIndex\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Cell\\\\Cell\\|null\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Style/Style.php
-
-
message: "#^Result of && is always true\\.$#"
count: 1
@@ -6350,11 +5775,6 @@ parameters:
count: 2
path: src/PhpSpreadsheet/Worksheet/AutoFilter.php
- -
- message: "#^Cannot call method setVisible\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\RowDimension\\|null\\.$#"
- count: 2
- path: src/PhpSpreadsheet/Worksheet/AutoFilter.php
-
-
message: "#^Cannot assign offset 'year' to array\\\\|string\\.$#"
count: 1
@@ -6500,16 +5920,6 @@ parameters:
count: 1
path: src/PhpSpreadsheet/Worksheet/Iterator.php
- -
- message: "#^Parameter \\#1 \\$im of function imagesx expects resource, GdImage\\|resource given\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Worksheet/MemoryDrawing.php
-
- -
- message: "#^Parameter \\#1 \\$im of function imagesy expects resource, GdImage\\|resource given\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Worksheet/MemoryDrawing.php
-
-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\PageSetup\\:\\:\\$pageOrder has no typehint specified\\.$#"
count: 1
@@ -6630,11 +6040,6 @@ parameters:
count: 1
path: src/PhpSpreadsheet/Worksheet/Worksheet.php
- -
- message: "#^Cannot call method setWidth\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\ColumnDimension\\|null\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Worksheet/Worksheet.php
-
-
message: "#^If condition is always true\\.$#"
count: 2
@@ -6650,26 +6055,11 @@ parameters:
count: 1
path: src/PhpSpreadsheet/Worksheet/Worksheet.php
- -
- message: "#^Cannot call method setValue\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Cell\\\\Cell\\|null\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Worksheet/Worksheet.php
-
- -
- message: "#^Cannot call method setValueExplicit\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Cell\\\\Cell\\|null\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Worksheet/Worksheet.php
-
-
message: "#^Parameter \\#2 \\$start of function substr expects int, int\\<0, max\\>\\|false given\\.$#"
count: 2
path: src/PhpSpreadsheet/Worksheet/Worksheet.php
- -
- message: "#^Parameter \\#1 \\$pRow of method PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Worksheet\\:\\:getRowDimension\\(\\) expects int, string given\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Worksheet/Worksheet.php
-
-
message: "#^Result of && is always true\\.$#"
count: 1
@@ -7430,16 +6820,6 @@ parameters:
count: 1
path: src/PhpSpreadsheet/Writer/Xls/Worksheet.php
- -
- message: "#^Parameter \\#2 \\$height of method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Xls\\\\Worksheet\\:\\:writeRow\\(\\) expects int, float given\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Writer/Xls/Worksheet.php
-
- -
- message: "#^Parameter \\#4 \\$hidden of method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Xls\\\\Worksheet\\:\\:writeRow\\(\\) expects bool, string given\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Writer/Xls/Worksheet.php
-
-
message: "#^Cannot call method getHashCode\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\Font\\|null\\.$#"
count: 1
@@ -7470,11 +6850,6 @@ parameters:
count: 1
path: src/PhpSpreadsheet/Writer/Xls/Worksheet.php
- -
- message: "#^Parameter \\#1 \\$hexadecimal_number of function hexdec expects string, array given\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Writer/Xls/Worksheet.php
-
-
message: "#^Parameter \\#1 \\$coordinates of static method PhpOffice\\\\PhpSpreadsheet\\\\Cell\\\\Coordinate\\:\\:indexesFromString\\(\\) expects string, string\\|null given\\.$#"
count: 1
@@ -7575,26 +6950,6 @@ parameters:
count: 1
path: src/PhpSpreadsheet/Writer/Xls/Worksheet.php
- -
- message: "#^Parameter \\#1 \\$value of static method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\StringHelper\\:\\:UTF8toBIFF8UnicodeLong\\(\\) expects string, string\\|null given\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Writer/Xls/Worksheet.php
-
- -
- message: "#^Parameter \\#1 \\$fillType of static method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Xls\\\\Xf\\:\\:mapFillType\\(\\) expects string, string\\|null given\\.$#"
- count: 2
- path: src/PhpSpreadsheet/Writer/Xls/Xf.php
-
- -
- message: "#^Parameter \\#1 \\$hAlign of method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Xls\\\\Xf\\:\\:mapHAlign\\(\\) expects string, string\\|null given\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Writer/Xls/Xf.php
-
- -
- message: "#^Parameter \\#1 \\$vAlign of static method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Xls\\\\Xf\\:\\:mapVAlign\\(\\) expects string, string\\|null given\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Writer/Xls/Xf.php
-
-
message: "#^Parameter \\#1 \\$textRotation of static method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Xls\\\\Xf\\:\\:mapTextRotation\\(\\) expects int, int\\|null given\\.$#"
count: 1
@@ -8105,11 +7460,6 @@ parameters:
count: 2
path: src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php
- -
- message: "#^Parameter \\#2 \\$value of method XMLWriter\\:\\:writeAttribute\\(\\) expects string, array given\\.$#"
- count: 1
- path: src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php
-
-
message: "#^Parameter \\#2 \\$value of method XMLWriter\\:\\:writeAttribute\\(\\) expects string, array\\\\|string given\\.$#"
count: 2
@@ -8120,31 +7470,6 @@ parameters:
count: 1
path: src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php
- -
- message: "#^Cannot call method getCollapsed\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\RowDimension\\|null\\.$#"
- count: 2
- path: src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php
-
- -
- message: "#^Cannot call method getOutlineLevel\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\RowDimension\\|null\\.$#"
- count: 3
- path: src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php
-
- -
- message: "#^Cannot call method getRowHeight\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\RowDimension\\|null\\.$#"
- count: 3
- path: src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php
-
- -
- message: "#^Cannot call method getVisible\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\RowDimension\\|null\\.$#"
- count: 2
- path: src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php
-
- -
- message: "#^Cannot call method getXfIndex\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\RowDimension\\|null\\.$#"
- count: 3
- path: src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php
-
-
message: "#^Parameter \\#2 \\$content of method XMLWriter\\:\\:writeElement\\(\\) expects string\\|null, int\\|string given\\.$#"
count: 1
@@ -8165,21 +7490,6 @@ parameters:
count: 1
path: tests/PhpSpreadsheetTests/Calculation/Engine/RangeTest.php
- -
- message: "#^Cannot call method setVisible\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\ColumnDimension\\|null\\.$#"
- count: 1
- path: tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SubTotalTest.php
-
- -
- message: "#^Cannot call method setVisible\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\RowDimension\\|null\\.$#"
- count: 1
- path: tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SubTotalTest.php
-
- -
- message: "#^Cannot call method setAutoSize\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\ColumnDimension\\|null\\.$#"
- count: 1
- path: tests/PhpSpreadsheetTests/Calculation/XlfnFunctionsTest.php
-
-
message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertSame\\(\\) with arguments PhpOffice\\\\PhpSpreadsheet\\\\Cell\\\\Cell, null and 'should get exact…' will always evaluate to false\\.$#"
count: 1
@@ -8205,16 +7515,6 @@ parameters:
count: 1
path: tests/PhpSpreadsheetTests/Functional/ColumnWidthTest.php
- -
- message: "#^Cannot call method setWidth\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\ColumnDimension\\|null\\.$#"
- count: 1
- path: tests/PhpSpreadsheetTests/Functional/ColumnWidthTest.php
-
- -
- message: "#^Cannot call method getWidth\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\ColumnDimension\\|null\\.$#"
- count: 1
- path: tests/PhpSpreadsheetTests/Functional/ColumnWidthTest.php
-
-
message: "#^Method PhpOffice\\\\PhpSpreadsheetTests\\\\Functional\\\\CommentsTest\\:\\:testComments\\(\\) has parameter \\$format with no typehint specified\\.$#"
count: 1
@@ -8225,11 +7525,6 @@ parameters:
count: 2
path: tests/PhpSpreadsheetTests/Functional/ConditionalStopIfTrueTest.php
- -
- message: "#^Cannot call method setAutoSize\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\ColumnDimension\\|null\\.$#"
- count: 1
- path: tests/PhpSpreadsheetTests/Functional/ConditionalTextTest.php
-
-
message: "#^Parameter \\#1 \\$im of function imagecolorallocate expects resource, resource\\|false given\\.$#"
count: 1
@@ -8325,26 +7620,6 @@ parameters:
count: 1
path: tests/PhpSpreadsheetTests/Reader/CsvTest.php
- -
- message: "#^Cannot call method getVisible\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\RowDimension\\|null\\.$#"
- count: 1
- path: tests/PhpSpreadsheetTests/Reader/Gnumeric/GnumericLoadTest.php
-
- -
- message: "#^Cannot call method getRowHeight\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\RowDimension\\|null\\.$#"
- count: 2
- path: tests/PhpSpreadsheetTests/Reader/Html/HtmlTagsTest.php
-
- -
- message: "#^Cannot call method getWidth\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\ColumnDimension\\|null\\.$#"
- count: 2
- path: tests/PhpSpreadsheetTests/Reader/Html/HtmlTest.php
-
- -
- message: "#^Cannot call method getRowHeight\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\RowDimension\\|null\\.$#"
- count: 2
- path: tests/PhpSpreadsheetTests/Reader/Html/HtmlTest.php
-
-
message: "#^Unreachable statement \\- code above always terminates\\.$#"
count: 1
@@ -8435,26 +7710,6 @@ parameters:
count: 1
path: tests/PhpSpreadsheetTests/Reader/Xlsx/ConditionalFormattingDataBarXlsxTest.php
- -
- message: "#^Cannot call method getRowHeight\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\RowDimension\\|null\\.$#"
- count: 1
- path: tests/PhpSpreadsheetTests/Reader/XlsxTest.php
-
- -
- message: "#^Cannot call method getVisible\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\RowDimension\\|null\\.$#"
- count: 1
- path: tests/PhpSpreadsheetTests/Reader/XlsxTest.php
-
- -
- message: "#^Cannot call method getWidth\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\ColumnDimension\\|null\\.$#"
- count: 1
- path: tests/PhpSpreadsheetTests/Reader/XlsxTest.php
-
- -
- message: "#^Cannot call method getVisible\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\ColumnDimension\\|null\\.$#"
- count: 1
- path: tests/PhpSpreadsheetTests/Reader/XlsxTest.php
-
-
message: "#^Method PhpOffice\\\\PhpSpreadsheetTests\\\\Reader\\\\XlsxTest\\:\\:testStripsWhiteSpaceFromStyleString\\(\\) has parameter \\$string with no typehint specified\\.$#"
count: 1
@@ -8610,21 +7865,6 @@ parameters:
count: 1
path: tests/PhpSpreadsheetTests/Writer/Html/ImagesRootTest.php
- -
- message: "#^Cannot call method setVisible\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\ColumnDimension\\|null\\.$#"
- count: 2
- path: tests/PhpSpreadsheetTests/Writer/Html/VisibilityTest.php
-
- -
- message: "#^Cannot call method setVisible\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\RowDimension\\|null\\.$#"
- count: 3
- path: tests/PhpSpreadsheetTests/Writer/Html/VisibilityTest.php
-
- -
- message: "#^Cannot call method setRowHeight\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\RowDimension\\|null\\.$#"
- count: 1
- path: tests/PhpSpreadsheetTests/Writer/Html/VisibilityTest.php
-
-
message: "#^Parameter \\#1 \\$options of static method PhpOffice\\\\PhpSpreadsheet\\\\Settings\\:\\:setLibXmlLoaderOptions\\(\\) expects int, null given\\.$#"
count: 1
diff --git a/phpstan.neon.dist b/phpstan.neon.dist
index dd39aa34..b7a4fca8 100644
--- a/phpstan.neon.dist
+++ b/phpstan.neon.dist
@@ -16,6 +16,8 @@ parameters:
- '~^Return typehint of method .* has invalid type GdImage\.$~'
- '~^Property .* has unknown class GdImage as its type\.$~'
- '~^Parameter .* of method .* has invalid typehint type GdImage\.$~'
+ - '~^Parameter \#1 \$im of function (imagedestroy|imageistruecolor|imagealphablending|imagesavealpha|imagecolortransparent|imagecolorsforindex|imagesavealpha|imagesx|imagesy) expects resource, GdImage\|resource given\.$~'
+ - '~^Parameter \#2 \$src_im of function imagecopy expects resource, GdImage\|resource given\.$~'
# Accept a bit anything for assert methods
- '~^Parameter \#2 .* of static method PHPUnit\\Framework\\Assert\:\:assert\w+\(\) expects .*, .* given\.$~'
- '~^Method PhpOffice\\PhpSpreadsheetTests\\.*\:\:test.*\(\) has parameter \$args with no typehint specified\.$~'
diff --git a/samples/Basic/16_Csv.php b/samples/Basic/16_Csv.php
index 15bbf0d4..137f6469 100644
--- a/samples/Basic/16_Csv.php
+++ b/samples/Basic/16_Csv.php
@@ -38,7 +38,8 @@ $helper->write($spreadsheetFromCSV, __FILE__, ['Xlsx']);
$filenameCSV = $helper->getFilename(__FILE__, 'csv');
/** @var \PhpOffice\PhpSpreadsheet\Writer\Csv $writerCSV */
$writerCSV = new CsvWriter($spreadsheetFromCSV);
-$writerCSV->setExcelCompatibility(true);
+//$writerCSV->setExcelCompatibility(true);
+$writerCSV->setUseBom(true); // because of non-ASCII chars
$callStartTime = microtime(true);
$writerCSV->save($filenameCSV);
diff --git a/src/PhpSpreadsheet/Calculation/Calculation.php b/src/PhpSpreadsheet/Calculation/Calculation.php
index ec85df69..c4473498 100644
--- a/src/PhpSpreadsheet/Calculation/Calculation.php
+++ b/src/PhpSpreadsheet/Calculation/Calculation.php
@@ -30,6 +30,9 @@ class Calculation
const CALCULATION_REGEXP_CELLREF = '((([^\s,!&%^\/\*\+<>=-]*)|(\'[^\']*\')|(\"[^\"]*\"))!)?\$?\b([a-z]{1,3})\$?(\d{1,7})(?![\w.])';
// Cell reference (with or without a sheet reference) ensuring absolute/relative
const CALCULATION_REGEXP_CELLREF_RELATIVE = '((([^\s\(,!&%^\/\*\+<>=-]*)|(\'[^\']*\')|(\"[^\"]*\"))!)?(\$?\b[a-z]{1,3})(\$?\d{1,7})(?![\w.])';
+ const CALCULATION_REGEXP_COLUMN_RANGE = '(((([^\s\(,!&%^\/\*\+<>=-]*)|(\'[^\']*\')|(\"[^\"]*\"))!)?(\$?[a-z]{1,3})):(?![.*])';
+ const CALCULATION_REGEXP_ROW_RANGE = '(((([^\s\(,!&%^\/\*\+<>=-]*)|(\'[^\']*\')|(\"[^\"]*\"))!)?(\$?[1-9][0-9]{0,6})):(?![.*])';
+ // Cell reference (with or without a sheet reference) ensuring absolute/relative
// Cell ranges ensuring absolute/relative
const CALCULATION_REGEXP_COLUMNRANGE_RELATIVE = '(\$?[a-z]{1,3}):(\$?[a-z]{1,3})';
const CALCULATION_REGEXP_ROWRANGE_RELATIVE = '(\$?\d{1,7}):(\$?\d{1,7})';
@@ -243,22 +246,22 @@ class Calculation
],
'ACOS' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Acos::class, 'evaluate'],
+ 'functionCall' => [MathTrig\Trig\Cosine::class, 'acos'],
'argumentCount' => '1',
],
'ACOSH' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Acosh::class, 'evaluate'],
+ 'functionCall' => [MathTrig\Trig\Cosine::class, 'acosh'],
'argumentCount' => '1',
],
'ACOT' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Acot::class, 'evaluate'],
+ 'functionCall' => [MathTrig\Trig\Cotangent::class, 'acot'],
'argumentCount' => '1',
],
'ACOTH' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Acoth::class, 'evaluate'],
+ 'functionCall' => [MathTrig\Trig\Cotangent::class, 'acoth'],
'argumentCount' => '1',
],
'ADDRESS' => [
@@ -303,27 +306,27 @@ class Calculation
],
'ASIN' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Asin::class, 'evaluate'],
+ 'functionCall' => [MathTrig\Trig\Sine::class, 'asin'],
'argumentCount' => '1',
],
'ASINH' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Asinh::class, 'evaluate'],
+ 'functionCall' => [MathTrig\Trig\Sine::class, 'asinh'],
'argumentCount' => '1',
],
'ATAN' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Atan::class, 'evaluate'],
+ 'functionCall' => [MathTrig\Trig\Tangent::class, 'atan'],
'argumentCount' => '1',
],
'ATAN2' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Atan2::class, 'evaluate'],
+ 'functionCall' => [MathTrig\Trig\Tangent::class, 'atan2'],
'argumentCount' => '2',
],
'ATANH' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Atanh::class, 'evaluate'],
+ 'functionCall' => [MathTrig\Trig\Tangent::class, 'atanh'],
'argumentCount' => '1',
],
'AVEDEV' => [
@@ -463,17 +466,17 @@ class Calculation
],
'CEILING' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Ceiling::class, 'evaluate'],
+ 'functionCall' => [MathTrig\Ceiling::class, 'ceiling'],
'argumentCount' => '1-2', // 2 for Excel, 1-2 for Ods/Gnumeric
],
'CEILING.MATH' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\CeilingMath::class, 'evaluate'],
+ 'functionCall' => [MathTrig\Ceiling::class, 'math'],
'argumentCount' => '1-3',
],
'CEILING.PRECISE' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\CeilingPrecise::class, 'evaluate'],
+ 'functionCall' => [MathTrig\Ceiling::class, 'precise'],
'argumentCount' => '1,2',
],
'CELL' => [
@@ -528,7 +531,7 @@ class Calculation
],
'CHOOSE' => [
'category' => Category::CATEGORY_LOOKUP_AND_REFERENCE,
- 'functionCall' => [LookupRef::class, 'CHOOSE'],
+ 'functionCall' => [LookupRef\Selection::class, 'CHOOSE'],
'argumentCount' => '2+',
],
'CLEAN' => [
@@ -605,22 +608,22 @@ class Calculation
],
'COS' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Cos::class, 'evaluate'],
+ 'functionCall' => [MathTrig\Trig\Cosine::class, 'cos'],
'argumentCount' => '1',
],
'COSH' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Cosh::class, 'evaluate'],
+ 'functionCall' => [MathTrig\Trig\Cosine::class, 'cosh'],
'argumentCount' => '1',
],
'COT' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Cot::class, 'evaluate'],
+ 'functionCall' => [MathTrig\Trig\Cotangent::class, 'cot'],
'argumentCount' => '1',
],
'COTH' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Coth::class, 'evaluate'],
+ 'functionCall' => [MathTrig\Trig\Cotangent::class, 'coth'],
'argumentCount' => '1',
],
'COUNT' => [
@@ -700,12 +703,12 @@ class Calculation
],
'CSC' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Csc::class, 'evaluate'],
+ 'functionCall' => [MathTrig\Trig\Cosecant::class, 'csc'],
'argumentCount' => '1',
],
'CSCH' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Csch::class, 'evaluate'],
+ 'functionCall' => [MathTrig\Trig\Cosecant::class, 'csch'],
'argumentCount' => '1',
],
'CUBEKPIMEMBER' => [
@@ -755,17 +758,17 @@ class Calculation
],
'DATE' => [
'category' => Category::CATEGORY_DATE_AND_TIME,
- 'functionCall' => [DateTimeExcel\Datefunc::class, 'funcDate'],
+ 'functionCall' => [DateTimeExcel\Date::class, 'fromYMD'],
'argumentCount' => '3',
],
'DATEDIF' => [
'category' => Category::CATEGORY_DATE_AND_TIME,
- 'functionCall' => [DateTimeExcel\DateDif::class, 'funcDateDif'],
+ 'functionCall' => [DateTimeExcel\Difference::class, 'interval'],
'argumentCount' => '2,3',
],
'DATEVALUE' => [
'category' => Category::CATEGORY_DATE_AND_TIME,
- 'functionCall' => [DateTimeExcel\DateValue::class, 'funcDateValue'],
+ 'functionCall' => [DateTimeExcel\DateValue::class, 'fromString'],
'argumentCount' => '1',
],
'DAVERAGE' => [
@@ -775,22 +778,22 @@ class Calculation
],
'DAY' => [
'category' => Category::CATEGORY_DATE_AND_TIME,
- 'functionCall' => [DateTimeExcel\Day::class, 'funcDay'],
+ 'functionCall' => [DateTimeExcel\DateParts::class, 'day'],
'argumentCount' => '1',
],
'DAYS' => [
'category' => Category::CATEGORY_DATE_AND_TIME,
- 'functionCall' => [DateTimeExcel\Days::class, 'funcDays'],
+ 'functionCall' => [DateTimeExcel\Days::class, 'between'],
'argumentCount' => '2',
],
'DAYS360' => [
'category' => Category::CATEGORY_DATE_AND_TIME,
- 'functionCall' => [DateTimeExcel\Days360::class, 'funcDays360'],
+ 'functionCall' => [DateTimeExcel\Days360::class, 'between'],
'argumentCount' => '2,3',
],
'DB' => [
'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Financial::class, 'DB'],
+ 'functionCall' => [Financial\Depreciation::class, 'DB'],
'argumentCount' => '4,5',
],
'DBCS' => [
@@ -810,7 +813,7 @@ class Calculation
],
'DDB' => [
'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Financial::class, 'DDB'],
+ 'functionCall' => [Financial\Depreciation::class, 'DDB'],
'argumentCount' => '4,5',
],
'DEC2BIN' => [
@@ -835,7 +838,7 @@ class Calculation
],
'DEGREES' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Degrees::class, 'evaluate'],
+ 'functionCall' => [MathTrig\Angle::class, 'toDegrees'],
'argumentCount' => '1',
],
'DELTA' => [
@@ -845,7 +848,7 @@ class Calculation
],
'DEVSQ' => [
'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical::class, 'DEVSQ'],
+ 'functionCall' => [Statistical\Deviations::class, 'sumSquares'],
'argumentCount' => '1+',
],
'DGET' => [
@@ -920,7 +923,7 @@ class Calculation
],
'EDATE' => [
'category' => Category::CATEGORY_DATE_AND_TIME,
- 'functionCall' => [DateTimeExcel\EDate::class, 'funcEDate'],
+ 'functionCall' => [DateTimeExcel\Month::class, 'adjust'],
'argumentCount' => '2',
],
'EFFECT' => [
@@ -930,12 +933,12 @@ class Calculation
],
'ENCODEURL' => [
'category' => Category::CATEGORY_WEB,
- 'functionCall' => [Functions::class, 'DUMMY'],
+ 'functionCall' => [Web\Service::class, 'urlEncode'],
'argumentCount' => '1',
],
'EOMONTH' => [
'category' => Category::CATEGORY_DATE_AND_TIME,
- 'functionCall' => [DateTimeExcel\EoMonth::class, 'funcEoMonth'],
+ 'functionCall' => [DateTimeExcel\Month::class, 'lastDay'],
'argumentCount' => '2',
],
'ERF' => [
@@ -965,7 +968,7 @@ class Calculation
],
'EVEN' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Even::class, 'evaluate'],
+ 'functionCall' => [MathTrig\Round::class, 'even'],
'argumentCount' => '1',
],
'EXACT' => [
@@ -990,12 +993,12 @@ class Calculation
],
'FACT' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Fact::class, 'evaluate'],
+ 'functionCall' => [MathTrig\Factorial::class, 'fact'],
'argumentCount' => '1',
],
'FACTDOUBLE' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\FactDouble::class, 'evaluate'],
+ 'functionCall' => [MathTrig\Factorial::class, 'factDouble'],
'argumentCount' => '1',
],
'FALSE' => [
@@ -1070,17 +1073,17 @@ class Calculation
],
'FLOOR' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Floor::class, 'evaluate'],
+ 'functionCall' => [MathTrig\Floor::class, 'floor'],
'argumentCount' => '1-2', // Excel requries 2, Ods/Gnumeric 1-2
],
'FLOOR.MATH' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\FloorMath::class, 'evaluate'],
+ 'functionCall' => [MathTrig\Floor::class, 'math'],
'argumentCount' => '1-3',
],
'FLOOR.PRECISE' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\FloorPrecise::class, 'evaluate'],
+ 'functionCall' => [MathTrig\Floor::class, 'precise'],
'argumentCount' => '1-2',
],
'FORECAST' => [
@@ -1115,7 +1118,7 @@ class Calculation
],
'FORMULATEXT' => [
'category' => Category::CATEGORY_LOOKUP_AND_REFERENCE,
- 'functionCall' => [LookupRef::class, 'FORMULATEXT'],
+ 'functionCall' => [LookupRef\Formula::class, 'text'],
'argumentCount' => '1',
'passCellReference' => true,
'passByReference' => [true],
@@ -1182,7 +1185,7 @@ class Calculation
],
'GAUSS' => [
'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical::class, 'GAUSS'],
+ 'functionCall' => [Statistical\Distributions\StandardNormal::class, 'gauss'],
'argumentCount' => '1',
],
'GCD' => [
@@ -1192,7 +1195,7 @@ class Calculation
],
'GEOMEAN' => [
'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical::class, 'GEOMEAN'],
+ 'functionCall' => [Statistical\Averages\Mean::class, 'geometric'],
'argumentCount' => '1+',
],
'GESTEP' => [
@@ -1212,7 +1215,7 @@ class Calculation
],
'HARMEAN' => [
'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical::class, 'HARMEAN'],
+ 'functionCall' => [Statistical\Averages\Mean::class, 'harmonic'],
'argumentCount' => '1+',
],
'HEX2BIN' => [
@@ -1237,12 +1240,12 @@ class Calculation
],
'HOUR' => [
'category' => Category::CATEGORY_DATE_AND_TIME,
- 'functionCall' => [DateTimeExcel\Hour::class, 'funcHour'],
+ 'functionCall' => [DateTimeExcel\TimeParts::class, 'hour'],
'argumentCount' => '1',
],
'HYPERLINK' => [
'category' => Category::CATEGORY_LOOKUP_AND_REFERENCE,
- 'functionCall' => [LookupRef::class, 'HYPERLINK'],
+ 'functionCall' => [LookupRef\Hyperlink::class, 'set'],
'argumentCount' => '1,2',
'passCellReference' => true,
],
@@ -1403,7 +1406,7 @@ class Calculation
],
'INDEX' => [
'category' => Category::CATEGORY_LOOKUP_AND_REFERENCE,
- 'functionCall' => [LookupRef::class, 'INDEX'],
+ 'functionCall' => [LookupRef\Matrix::class, 'index'],
'argumentCount' => '1-4',
],
'INDIRECT' => [
@@ -1501,7 +1504,7 @@ class Calculation
],
'ISOWEEKNUM' => [
'category' => Category::CATEGORY_DATE_AND_TIME,
- 'functionCall' => [DateTimeExcel\IsoWeekNum::class, 'funcIsoWeekNum'],
+ 'functionCall' => [DateTimeExcel\Week::class, 'isoWeekNumber'],
'argumentCount' => '1',
],
'ISPMT' => [
@@ -1526,12 +1529,12 @@ class Calculation
],
'KURT' => [
'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical::class, 'KURT'],
+ 'functionCall' => [Statistical\Deviations::class, 'kurtosis'],
'argumentCount' => '1+',
],
'LARGE' => [
'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical::class, 'LARGE'],
+ 'functionCall' => [Statistical\Size::class, 'large'],
'argumentCount' => '2',
],
'LCM' => [
@@ -1621,12 +1624,12 @@ class Calculation
],
'MAX' => [
'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Maximum::class, 'MAX'],
+ 'functionCall' => [Statistical\Maximum::class, 'max'],
'argumentCount' => '1+',
],
'MAXA' => [
'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Maximum::class, 'MAXA'],
+ 'functionCall' => [Statistical\Maximum::class, 'maxA'],
'argumentCount' => '1+',
],
'MAXIFS' => [
@@ -1666,12 +1669,12 @@ class Calculation
],
'MIN' => [
'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Minimum::class, 'MIN'],
+ 'functionCall' => [Statistical\Minimum::class, 'min'],
'argumentCount' => '1+',
],
'MINA' => [
'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical\Minimum::class, 'MINA'],
+ 'functionCall' => [Statistical\Minimum::class, 'minA'],
'argumentCount' => '1+',
],
'MINIFS' => [
@@ -1681,7 +1684,7 @@ class Calculation
],
'MINUTE' => [
'category' => Category::CATEGORY_DATE_AND_TIME,
- 'functionCall' => [DateTimeExcel\Minute::class, 'funcMinute'],
+ 'functionCall' => [DateTimeExcel\TimeParts::class, 'minute'],
'argumentCount' => '1',
],
'MINVERSE' => [
@@ -1701,7 +1704,7 @@ class Calculation
],
'MOD' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Mod::class, 'evaluate'],
+ 'functionCall' => [MathTrig\Operations::class, 'mod'],
'argumentCount' => '2',
],
'MODE' => [
@@ -1721,17 +1724,17 @@ class Calculation
],
'MONTH' => [
'category' => Category::CATEGORY_DATE_AND_TIME,
- 'functionCall' => [DateTimeExcel\Month::class, 'funcMonth'],
+ 'functionCall' => [DateTimeExcel\DateParts::class, 'month'],
'argumentCount' => '1',
],
'MROUND' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Mround::class, 'evaluate'],
+ 'functionCall' => [MathTrig\Round::class, 'multiple'],
'argumentCount' => '2',
],
'MULTINOMIAL' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Multinomial::class, 'evaluate'],
+ 'functionCall' => [MathTrig\Factorial::class, 'multinomial'],
'argumentCount' => '1+',
],
'MUNIT' => [
@@ -1761,7 +1764,7 @@ class Calculation
],
'NETWORKDAYS' => [
'category' => Category::CATEGORY_DATE_AND_TIME,
- 'functionCall' => [DateTimeExcel\NetworkDays::class, 'funcNetworkDays'],
+ 'functionCall' => [DateTimeExcel\NetworkDays::class, 'count'],
'argumentCount' => '2-3',
],
'NETWORKDAYS.INTL' => [
@@ -1821,7 +1824,7 @@ class Calculation
],
'NOW' => [
'category' => Category::CATEGORY_DATE_AND_TIME,
- 'functionCall' => [DateTimeExcel\Now::class, 'funcNow'],
+ 'functionCall' => [DateTimeExcel\Current::class, 'now'],
'argumentCount' => '0',
],
'NPER' => [
@@ -1856,7 +1859,7 @@ class Calculation
],
'ODD' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Odd::class, 'evaluate'],
+ 'functionCall' => [MathTrig\Round::class, 'odd'],
'argumentCount' => '1',
],
'ODDFPRICE' => [
@@ -1973,7 +1976,7 @@ class Calculation
],
'POWER' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Power::class, 'evaluate'],
+ 'functionCall' => [MathTrig\Operations::class, 'power'],
'argumentCount' => '2',
],
'PPMT' => [
@@ -2003,7 +2006,7 @@ class Calculation
],
'PRODUCT' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Product::class, 'evaluate'],
+ 'functionCall' => [MathTrig\Operations::class, 'product'],
'argumentCount' => '1+',
],
'PROPER' => [
@@ -2033,17 +2036,17 @@ class Calculation
],
'QUOTIENT' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Quotient::class, 'evaluate'],
+ 'functionCall' => [MathTrig\Operations::class, 'quotient'],
'argumentCount' => '2',
],
'RADIANS' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Radians::class, 'evaluate'],
+ 'functionCall' => [MathTrig\Angle::class, 'toRadians'],
'argumentCount' => '1',
],
'RAND' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Random::class, 'randNoArgs'],
+ 'functionCall' => [MathTrig\Random::class, 'rand'],
'argumentCount' => '0',
],
'RANDARRAY' => [
@@ -2068,7 +2071,7 @@ class Calculation
],
'RANK.EQ' => [
'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical::class, 'RANK'],
+ 'functionCall' => [Statistical\Percentiles::class, 'RANK'],
'argumentCount' => '2,3',
],
'RATE' => [
@@ -2113,17 +2116,17 @@ class Calculation
],
'ROUND' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Round::class, 'evaluate'],
+ 'functionCall' => [MathTrig\Round::class, 'round'],
'argumentCount' => '2',
],
'ROUNDDOWN' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\RoundDown::class, 'evaluate'],
+ 'functionCall' => [MathTrig\Round::class, 'down'],
'argumentCount' => '2',
],
'ROUNDUP' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\RoundUp::class, 'evaluate'],
+ 'functionCall' => [MathTrig\Round::class, 'up'],
'argumentCount' => '2',
],
'ROW' => [
@@ -2165,17 +2168,17 @@ class Calculation
],
'SEC' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Sec::class, 'evaluate'],
+ 'functionCall' => [MathTrig\Trig\Secant::class, 'sec'],
'argumentCount' => '1',
],
'SECH' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Sech::class, 'evaluate'],
+ 'functionCall' => [MathTrig\Trig\Secant::class, 'sech'],
'argumentCount' => '1',
],
'SECOND' => [
'category' => Category::CATEGORY_DATE_AND_TIME,
- 'functionCall' => [DateTimeExcel\Second::class, 'funcSecond'],
+ 'functionCall' => [DateTimeExcel\TimeParts::class, 'second'],
'argumentCount' => '1',
],
'SEQUENCE' => [
@@ -2205,17 +2208,17 @@ class Calculation
],
'SIN' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Sin::class, 'evaluate'],
+ 'functionCall' => [MathTrig\Trig\Sine::class, 'sin'],
'argumentCount' => '1',
],
'SINH' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Sinh::class, 'evaluate'],
+ 'functionCall' => [MathTrig\Trig\Sine::class, 'sinh'],
'argumentCount' => '1',
],
'SKEW' => [
'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical::class, 'SKEW'],
+ 'functionCall' => [Statistical\Deviations::class, 'skew'],
'argumentCount' => '1+',
],
'SKEW.P' => [
@@ -2235,7 +2238,7 @@ class Calculation
],
'SMALL' => [
'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical::class, 'SMALL'],
+ 'functionCall' => [Statistical\Size::class, 'small'],
'argumentCount' => '2',
],
'SORT' => [
@@ -2250,17 +2253,17 @@ class Calculation
],
'SQRT' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Sqrt::class, 'evaluate'],
+ 'functionCall' => [MathTrig\Sqrt::class, 'sqrt'],
'argumentCount' => '1',
],
'SQRTPI' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\SqrtPi::class, 'evaluate'],
+ 'functionCall' => [MathTrig\Sqrt::class, 'pi'],
'argumentCount' => '1',
],
'STANDARDIZE' => [
'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical::class, 'STANDARDIZE'],
+ 'functionCall' => [Statistical\Standardize::class, 'execute'],
'argumentCount' => '3',
],
'STDEV' => [
@@ -2285,12 +2288,12 @@ class Calculation
],
'STDEVP' => [
'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical::class, 'STDEVP'],
+ 'functionCall' => [Statistical\StandardDeviations::class, 'STDEVP'],
'argumentCount' => '1+',
],
'STDEVPA' => [
'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical::class, 'STDEVPA'],
+ 'functionCall' => [Statistical\StandardDeviations::class, 'STDEVPA'],
'argumentCount' => '1+',
],
'STEYX' => [
@@ -2311,7 +2314,7 @@ class Calculation
],
'SUM' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Sum::class, 'funcSumNoStrings'],
+ 'functionCall' => [MathTrig\Sum::class, 'sumErroringStrings'],
'argumentCount' => '1+',
],
'SUMIF' => [
@@ -2326,7 +2329,7 @@ class Calculation
],
'SUMPRODUCT' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\SumProduct::class, 'evaluate'],
+ 'functionCall' => [MathTrig\Sum::class, 'product'],
'argumentCount' => '1+',
],
'SUMSQ' => [
@@ -2366,12 +2369,12 @@ class Calculation
],
'TAN' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Tan::class, 'evaluate'],
+ 'functionCall' => [MathTrig\Trig\Tangent::class, 'tan'],
'argumentCount' => '1',
],
'TANH' => [
'category' => Category::CATEGORY_MATH_AND_TRIG,
- 'functionCall' => [MathTrig\Tanh::class, 'evaluate'],
+ 'functionCall' => [MathTrig\Trig\Tangent::class, 'tanh'],
'argumentCount' => '1',
],
'TBILLEQ' => [
@@ -2416,17 +2419,17 @@ class Calculation
],
'TEXTJOIN' => [
'category' => Category::CATEGORY_TEXT_AND_DATA,
- 'functionCall' => [TextData::class, 'TEXTJOIN'],
+ 'functionCall' => [TextData\Concatenate::class, 'TEXTJOIN'],
'argumentCount' => '3+',
],
'TIME' => [
'category' => Category::CATEGORY_DATE_AND_TIME,
- 'functionCall' => [DateTimeExcel\Time::class, 'funcTime'],
+ 'functionCall' => [DateTimeExcel\Time::class, 'fromHMS'],
'argumentCount' => '3',
],
'TIMEVALUE' => [
'category' => Category::CATEGORY_DATE_AND_TIME,
- 'functionCall' => [DateTimeExcel\TimeValue::class, 'funcTimeValue'],
+ 'functionCall' => [DateTimeExcel\TimeValue::class, 'fromString'],
'argumentCount' => '1',
],
'TINV' => [
@@ -2446,7 +2449,7 @@ class Calculation
],
'TODAY' => [
'category' => Category::CATEGORY_DATE_AND_TIME,
- 'functionCall' => [DateTimeExcel\Today::class, 'funcToday'],
+ 'functionCall' => [DateTimeExcel\Current::class, 'today'],
'argumentCount' => '0',
],
'TRANSPOSE' => [
@@ -2466,7 +2469,7 @@ class Calculation
],
'TRIMMEAN' => [
'category' => Category::CATEGORY_STATISTICAL,
- 'functionCall' => [Statistical::class, 'TRIMMEAN'],
+ 'functionCall' => [Statistical\Averages\Mean::class, 'trim'],
'argumentCount' => '2',
],
'TRUE' => [
@@ -2566,17 +2569,17 @@ class Calculation
],
'WEBSERVICE' => [
'category' => Category::CATEGORY_WEB,
- 'functionCall' => [Web::class, 'WEBSERVICE'],
+ 'functionCall' => [Web\Service::class, 'webService'],
'argumentCount' => '1',
],
'WEEKDAY' => [
'category' => Category::CATEGORY_DATE_AND_TIME,
- 'functionCall' => [DateTimeExcel\WeekDay::class, 'funcWeekDay'],
+ 'functionCall' => [DateTimeExcel\Week::class, 'day'],
'argumentCount' => '1,2',
],
'WEEKNUM' => [
'category' => Category::CATEGORY_DATE_AND_TIME,
- 'functionCall' => [DateTimeExcel\WeekNum::class, 'funcWeekNum'],
+ 'functionCall' => [DateTimeExcel\Week::class, 'number'],
'argumentCount' => '1,2',
],
'WEIBULL' => [
@@ -2591,7 +2594,7 @@ class Calculation
],
'WORKDAY' => [
'category' => Category::CATEGORY_DATE_AND_TIME,
- 'functionCall' => [DateTimeExcel\WorkDay::class, 'funcWorkDay'],
+ 'functionCall' => [DateTimeExcel\WorkDay::class, 'date'],
'argumentCount' => '2-3',
],
'WORKDAY.INTL' => [
@@ -2601,7 +2604,7 @@ class Calculation
],
'XIRR' => [
'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Financial::class, 'XIRR'],
+ 'functionCall' => [Financial\CashFlow\Variable\NonPeriodic::class, 'rate'],
'argumentCount' => '2,3',
],
'XLOOKUP' => [
@@ -2611,7 +2614,7 @@ class Calculation
],
'XNPV' => [
'category' => Category::CATEGORY_FINANCIAL,
- 'functionCall' => [Financial::class, 'XNPV'],
+ 'functionCall' => [Financial\CashFlow\Variable\NonPeriodic::class, 'presentValue'],
'argumentCount' => '3',
],
'XMATCH' => [
@@ -2626,12 +2629,12 @@ class Calculation
],
'YEAR' => [
'category' => Category::CATEGORY_DATE_AND_TIME,
- 'functionCall' => [DateTimeExcel\Year::class, 'funcYear'],
+ 'functionCall' => [DateTimeExcel\DateParts::class, 'year'],
'argumentCount' => '1',
],
'YEARFRAC' => [
'category' => Category::CATEGORY_DATE_AND_TIME,
- 'functionCall' => [DateTimeExcel\YearFrac::class, 'funcYearFrac'],
+ 'functionCall' => [DateTimeExcel\YearFrac::class, 'fraction'],
'argumentCount' => '2,3',
],
'YIELD' => [
@@ -3798,6 +3801,8 @@ class Calculation
$regexpMatchString = '/^(' . self::CALCULATION_REGEXP_FUNCTION .
'|' . self::CALCULATION_REGEXP_CELLREF .
+ '|' . self::CALCULATION_REGEXP_COLUMN_RANGE .
+ '|' . self::CALCULATION_REGEXP_ROW_RANGE .
'|' . self::CALCULATION_REGEXP_NUMBER .
'|' . self::CALCULATION_REGEXP_STRING .
'|' . self::CALCULATION_REGEXP_OPENBRACE .
@@ -3866,7 +3871,8 @@ class Calculation
$opCharacter .= $formula[++$index];
}
// Find out if we're currently at the beginning of a number, variable, cell reference, function, parenthesis or operand
- $isOperandOrFunction = preg_match($regexpMatchString, substr($formula, $index), $match);
+ $isOperandOrFunction = (bool) preg_match($regexpMatchString, substr($formula, $index), $match);
+
if ($opCharacter == '-' && !$expectingOperator) { // Is it a negation instead of a minus?
// Put a negation on the stack
$stack->push('Unary Operator', '~', null, $currentCondition, $currentOnlyIf, $currentOnlyIfNot);
@@ -4038,6 +4044,7 @@ class Calculation
$expectingOperand = false;
$val = $match[1];
$length = strlen($val);
+
if (preg_match('/^' . self::CALCULATION_REGEXP_FUNCTION . '$/miu', $val, $matches)) {
$val = preg_replace('/\s/u', '', $val);
if (isset(self::$phpSpreadsheetFunctions[strtoupper($matches[1])]) || isset(self::$controlFunctions[strtoupper($matches[1])])) { // it's a function
@@ -4074,7 +4081,7 @@ class Calculation
// Should only be applied to the actual cell column, not the worksheet name
// If the last entry on the stack was a : operator, then we have a cell range reference
$testPrevOp = $stack->last(1);
- if ($testPrevOp !== null && $testPrevOp['value'] == ':') {
+ if ($testPrevOp !== null && $testPrevOp['value'] === ':') {
// If we have a worksheet reference, then we're playing with a 3D reference
if ($matches[2] == '') {
// Otherwise, we 'inherit' the worksheet reference from the start cell reference
@@ -4091,62 +4098,57 @@ class Calculation
return $this->raiseFormulaError('3D Range references are not yet supported');
}
}
+ } elseif (strpos($val, '!') === false && $pCellParent !== null) {
+ $worksheet = $pCellParent->getTitle();
+ $val = "'{$worksheet}'!{$val}";
}
$outputItem = $stack->getStackItem('Cell Reference', $val, $val, $currentCondition, $currentOnlyIf, $currentOnlyIfNot);
$output[] = $outputItem;
} else { // it's a variable, constant, string, number or boolean
+ $localeConstant = false;
+ $stackItemType = 'Value';
+ $stackItemReference = null;
+
// If the last entry on the stack was a : operator, then we may have a row or column range reference
$testPrevOp = $stack->last(1);
if ($testPrevOp !== null && $testPrevOp['value'] === ':') {
+ $stackItemType = 'Cell Reference';
$startRowColRef = $output[count($output) - 1]['value'];
[$rangeWS1, $startRowColRef] = Worksheet::extractSheetTitle($startRowColRef, true);
$rangeSheetRef = $rangeWS1;
- if ($rangeWS1 != '') {
+ if ($rangeWS1 !== '') {
$rangeWS1 .= '!';
}
+ $rangeSheetRef = trim($rangeSheetRef, "'");
[$rangeWS2, $val] = Worksheet::extractSheetTitle($val, true);
- if ($rangeWS2 != '') {
+ if ($rangeWS2 !== '') {
$rangeWS2 .= '!';
} else {
$rangeWS2 = $rangeWS1;
}
+
$refSheet = $pCellParent;
- if ($pCellParent !== null && $rangeSheetRef !== $pCellParent->getTitle()) {
+ if ($pCellParent !== null && $rangeSheetRef !== '' && $rangeSheetRef !== $pCellParent->getTitle()) {
$refSheet = $pCellParent->getParent()->getSheetByName($rangeSheetRef);
}
- if (
- (is_int($startRowColRef)) && (ctype_digit($val)) &&
- ($startRowColRef <= 1048576) && ($val <= 1048576)
- ) {
- // Row range
- $endRowColRef = ($refSheet !== null) ? $refSheet->getHighestColumn() : 'XFD'; // Max 16,384 columns for Excel2007
- $output[count($output) - 1]['value'] = $rangeWS1 . 'A' . $startRowColRef;
- $val = $rangeWS2 . $endRowColRef . $val;
- } elseif (
- (ctype_alpha($startRowColRef)) && (ctype_alpha($val)) &&
- (strlen($startRowColRef) <= 3) && (strlen($val) <= 3)
- ) {
- // Column range
- $endRowColRef = ($refSheet !== null) ? $refSheet->getHighestRow() : 1048576; // Max 1,048,576 rows for Excel2007
- $output[count($output) - 1]['value'] = $rangeWS1 . strtoupper($startRowColRef) . '1';
- $val = $rangeWS2 . $val . $endRowColRef;
- }
- }
- $localeConstant = false;
- $stackItemType = 'Value';
- $stackItemReference = null;
- if ($opCharacter == self::FORMULA_STRING_QUOTE) {
+ if (ctype_digit($val) && $val <= 1048576) {
+ // Row range
+ $stackItemType = 'Row Reference';
+ $endRowColRef = ($refSheet !== null) ? $refSheet->getHighestDataColumn($val) : 'XFD'; // Max 16,384 columns for Excel2007
+ $val = "{$rangeWS2}{$endRowColRef}{$val}";
+ } elseif (ctype_alpha($val) && strlen($val) <= 3) {
+ // Column range
+ $stackItemType = 'Column Reference';
+ $endRowColRef = ($refSheet !== null) ? $refSheet->getHighestDataRow($val) : 1048576; // Max 1,048,576 rows for Excel2007
+ $val = "{$rangeWS2}{$val}{$endRowColRef}";
+ }
+ $stackItemReference = $val;
+ } elseif ($opCharacter == self::FORMULA_STRING_QUOTE) {
// UnEscape any quotes within the string
$val = self::wrapResult(str_replace('""', self::FORMULA_STRING_QUOTE, self::unwrapResult($val)));
- } elseif (is_numeric($val)) {
- if ((strpos($val, '.') !== false) || (stripos($val, 'e') !== false) || ($val > PHP_INT_MAX) || ($val < -PHP_INT_MAX)) {
- $val = (float) $val;
- } else {
- $val = (int) $val;
- }
} elseif (isset(self::$excelConstants[trim(strtoupper($val))])) {
$stackItemType = 'Constant';
$excelConstant = trim(strtoupper($val));
@@ -4154,10 +4156,41 @@ class Calculation
} elseif (($localeConstant = array_search(trim(strtoupper($val)), self::$localeBoolean)) !== false) {
$stackItemType = 'Constant';
$val = self::$excelConstants[$localeConstant];
+ } elseif (
+ preg_match('/^' . self::CALCULATION_REGEXP_ROW_RANGE . '/miu', substr($formula, $index), $rowRangeReference)
+ ) {
+ $val = $rowRangeReference[1];
+ $length = strlen($rowRangeReference[1]);
+ $stackItemType = 'Row Reference';
+ $column = 'A';
+ if (($testPrevOp !== null && $testPrevOp['value'] === ':') && $pCellParent !== null) {
+ $column = $pCellParent->getHighestDataColumn($val);
+ }
+ $val = "{$rowRangeReference[2]}{$column}{$rowRangeReference[7]}";
+ $stackItemReference = $val;
+ } elseif (
+ preg_match('/^' . self::CALCULATION_REGEXP_COLUMN_RANGE . '/miu', substr($formula, $index), $columnRangeReference)
+ ) {
+ $val = $columnRangeReference[1];
+ $length = strlen($val);
+ $stackItemType = 'Column Reference';
+ $row = '1';
+ if (($testPrevOp !== null && $testPrevOp['value'] === ':') && $pCellParent !== null) {
+ $row = $pCellParent->getHighestDataRow($val);
+ }
+ $val = "{$val}{$row}";
+ $stackItemReference = $val;
} elseif (preg_match('/^' . self::CALCULATION_REGEXP_DEFINEDNAME . '.*/miu', $val, $match)) {
$stackItemType = 'Defined Name';
$stackItemReference = $val;
+ } elseif (is_numeric($val)) {
+ if ((strpos($val, '.') !== false) || (stripos($val, 'e') !== false) || ($val > PHP_INT_MAX) || ($val < -PHP_INT_MAX)) {
+ $val = (float) $val;
+ } else {
+ $val = (int) $val;
+ }
}
+
$details = $stack->getStackItem($stackItemType, $val, $stackItemReference, $currentCondition, $currentOnlyIf, $currentOnlyIfNot);
if ($localeConstant) {
$details['localeValue'] = $localeConstant;
@@ -4431,6 +4464,7 @@ class Calculation
} else {
return $this->raiseFormulaError('Unable to access Cell Reference');
}
+
$stack->push('Cell Reference', $cellValue, $cellRef);
} else {
$stack->push('Error', Functions::REF(), null);
@@ -4564,6 +4598,7 @@ class Calculation
}
} elseif (preg_match('/^' . self::CALCULATION_REGEXP_CELLREF . '$/i', $token, $matches)) {
$cellRef = null;
+
if (isset($matches[8])) {
if ($pCell === null) {
// We can't access the range, so return a REF error
@@ -4596,7 +4631,7 @@ class Calculation
}
} else {
if ($pCell === null) {
- // We can't access the cell, so return a REF error
+ // We can't access the cell, so return a REF error
$cellValue = Functions::REF();
} else {
$cellRef = $matches[6] . $matches[7];
@@ -4613,6 +4648,7 @@ class Calculation
$cellValue = $this->extractCellRange($cellRef, $this->spreadsheet->getSheetByName($matches[2]), false);
$pCell->attach($pCellParent);
} else {
+ $cellRef = ($cellSheet !== null) ? "{$matches[2]}!{$cellRef}" : $cellRef;
$cellValue = null;
}
} else {
@@ -4631,7 +4667,8 @@ class Calculation
}
}
}
- $stack->push('Value', $cellValue, $cellRef);
+
+ $stack->push('Cell Value', $cellValue, $cellRef);
if (isset($storeKey)) {
$branchStore[$storeKey] = $cellValue;
}
@@ -5116,6 +5153,7 @@ class Calculation
if ($pSheet !== null) {
$pSheetName = $pSheet->getTitle();
+
if (strpos($pRange, '!') !== false) {
[$pSheetName, $pRange] = Worksheet::extractSheetTitle($pRange, true);
$pSheet = $this->spreadsheet->getSheetByName($pSheetName);
diff --git a/src/PhpSpreadsheet/Calculation/Database.php b/src/PhpSpreadsheet/Calculation/Database.php
index a4c4d7d2..65031674 100644
--- a/src/PhpSpreadsheet/Calculation/Database.php
+++ b/src/PhpSpreadsheet/Calculation/Database.php
@@ -17,7 +17,8 @@ class Database
*
* @Deprecated 1.17.0
*
- * @see Use the evaluate() method in the Database\DAverage class instead
+ * @see Database\DAverage::evaluate()
+ * Use the evaluate() method in the Database\DAverage class instead
*
* @param mixed[] $database The range of cells that makes up the list or database.
* A database is a list of related data in which rows of related
@@ -52,7 +53,8 @@ class Database
*
* @Deprecated 1.17.0
*
- * @see Use the evaluate() method in the Database\DCount class instead
+ * @see Database\DCount::evaluate()
+ * Use the evaluate() method in the Database\DCount class instead
*
* @param mixed[] $database The range of cells that makes up the list or database.
* A database is a list of related data in which rows of related
@@ -89,7 +91,8 @@ class Database
*
* @Deprecated 1.17.0
*
- * @see Use the evaluate() method in the Database\DCountA class instead
+ * @see Database\DCountA::evaluate()
+ * Use the evaluate() method in the Database\DCountA class instead
*
* @param mixed[] $database The range of cells that makes up the list or database.
* A database is a list of related data in which rows of related
@@ -124,7 +127,8 @@ class Database
*
* @Deprecated 1.17.0
*
- * @see Use the evaluate() method in the Database\DGet class instead
+ * @see Database\DGet::evaluate()
+ * Use the evaluate() method in the Database\DGet class instead
*
* @param mixed[] $database The range of cells that makes up the list or database.
* A database is a list of related data in which rows of related
@@ -159,7 +163,8 @@ class Database
*
* @Deprecated 1.17.0
*
- * @see Use the evaluate() method in the Database\DMax class instead
+ * @see Database\DMax::evaluate()
+ * Use the evaluate() method in the Database\DMax class instead
*
* @param mixed[] $database The range of cells that makes up the list or database.
* A database is a list of related data in which rows of related
@@ -194,7 +199,8 @@ class Database
*
* @Deprecated 1.17.0
*
- * @see Use the evaluate() method in the Database\DMin class instead
+ * @see Database\DMin::evaluate()
+ * Use the evaluate() method in the Database\DMin class instead
*
* @param mixed[] $database The range of cells that makes up the list or database.
* A database is a list of related data in which rows of related
@@ -228,7 +234,8 @@ class Database
*
* @Deprecated 1.17.0
*
- * @see Use the evaluate() method in the Database\DProduct class instead
+ * @see Database\DProduct::evaluate()
+ * Use the evaluate() method in the Database\DProduct class instead
*
* @param mixed[] $database The range of cells that makes up the list or database.
* A database is a list of related data in which rows of related
@@ -263,7 +270,8 @@ class Database
*
* @Deprecated 1.17.0
*
- * @see Use the evaluate() method in the Database\DStDev class instead
+ * @see Database\DStDev::evaluate()
+ * Use the evaluate() method in the Database\DStDev class instead
*
* @param mixed[] $database The range of cells that makes up the list or database.
* A database is a list of related data in which rows of related
@@ -298,7 +306,8 @@ class Database
*
* @Deprecated 1.17.0
*
- * @see Use the evaluate() method in the Database\DStDevP class instead
+ * @see Database\DStDevP::evaluate()
+ * Use the evaluate() method in the Database\DStDevP class instead
*
* @param mixed[] $database The range of cells that makes up the list or database.
* A database is a list of related data in which rows of related
@@ -332,7 +341,8 @@ class Database
*
* @Deprecated 1.17.0
*
- * @see Use the evaluate() method in the Database\DSum class instead
+ * @see Database\DSum::evaluate()
+ * Use the evaluate() method in the Database\DSum class instead
*
* @param mixed[] $database The range of cells that makes up the list or database.
* A database is a list of related data in which rows of related
@@ -367,7 +377,8 @@ class Database
*
* @Deprecated 1.17.0
*
- * @see Use the evaluate() method in the Database\DVar class instead
+ * @see Database\DVar::evaluate()
+ * Use the evaluate() method in the Database\DVar class instead
*
* @param mixed[] $database The range of cells that makes up the list or database.
* A database is a list of related data in which rows of related
@@ -402,7 +413,8 @@ class Database
*
* @Deprecated 1.17.0
*
- * @see Use the evaluate() method in the Database\DVarP class instead
+ * @see Database\DVarP::evaluate()
+ * Use the evaluate() method in the Database\DVarP class instead
*
* @param mixed[] $database The range of cells that makes up the list or database.
* A database is a list of related data in which rows of related
diff --git a/src/PhpSpreadsheet/Calculation/Database/DMax.php b/src/PhpSpreadsheet/Calculation/Database/DMax.php
index e84a0bfc..9c5c7301 100644
--- a/src/PhpSpreadsheet/Calculation/Database/DMax.php
+++ b/src/PhpSpreadsheet/Calculation/Database/DMax.php
@@ -39,7 +39,7 @@ class DMax extends DatabaseAbstract
return null;
}
- return Maximum::MAX(
+ return Maximum::max(
self::getFilteredColumn($database, $field, $criteria)
);
}
diff --git a/src/PhpSpreadsheet/Calculation/Database/DMin.php b/src/PhpSpreadsheet/Calculation/Database/DMin.php
index 4398a7c3..e7b473a7 100644
--- a/src/PhpSpreadsheet/Calculation/Database/DMin.php
+++ b/src/PhpSpreadsheet/Calculation/Database/DMin.php
@@ -39,7 +39,7 @@ class DMin extends DatabaseAbstract
return null;
}
- return Minimum::MIN(
+ return Minimum::min(
self::getFilteredColumn($database, $field, $criteria)
);
}
diff --git a/src/PhpSpreadsheet/Calculation/Database/DProduct.php b/src/PhpSpreadsheet/Calculation/Database/DProduct.php
index 2e10fb5f..35e3d479 100644
--- a/src/PhpSpreadsheet/Calculation/Database/DProduct.php
+++ b/src/PhpSpreadsheet/Calculation/Database/DProduct.php
@@ -38,7 +38,7 @@ class DProduct extends DatabaseAbstract
return null;
}
- return MathTrig\Product::evaluate(
+ return MathTrig\Operations::product(
self::getFilteredColumn($database, $field, $criteria)
);
}
diff --git a/src/PhpSpreadsheet/Calculation/Database/DSum.php b/src/PhpSpreadsheet/Calculation/Database/DSum.php
index e7e28a4a..03841c4e 100644
--- a/src/PhpSpreadsheet/Calculation/Database/DSum.php
+++ b/src/PhpSpreadsheet/Calculation/Database/DSum.php
@@ -38,7 +38,7 @@ class DSum extends DatabaseAbstract
return null;
}
- return MathTrig\Sum::funcSum(
+ return MathTrig\Sum::sumIgnoringStrings(
self::getFilteredColumn($database, $field, $criteria)
);
}
diff --git a/src/PhpSpreadsheet/Calculation/DateTime.php b/src/PhpSpreadsheet/Calculation/DateTime.php
index 7643ed0b..44a38c19 100644
--- a/src/PhpSpreadsheet/Calculation/DateTime.php
+++ b/src/PhpSpreadsheet/Calculation/DateTime.php
@@ -4,12 +4,18 @@ namespace PhpOffice\PhpSpreadsheet\Calculation;
use DateTimeInterface;
+/**
+ * @deprecated 1.18.0
+ */
class DateTime
{
/**
* Identify if a year is a leap year or not.
*
- * @Deprecated 2.0.0 Use the method isLeapYear in the DateTimeExcel\Helpers class instead
+ * @Deprecated 1.18.0
+ *
+ * @See DateTimeExcel\Helpers::isLeapYear()
+ * Use the isLeapYear method in the DateTimeExcel\Helpers class instead
*
* @param int|string $year The year to test
*
@@ -23,7 +29,10 @@ class DateTime
/**
* getDateValue.
*
- * @Deprecated 2.0.0 Use the method getDateValue in the DateTimeExcel\Helpers class instead
+ * @Deprecated 1.18.0
+ *
+ * @See DateTimeExcel\Helpers::getDateValue()
+ * Use the getDateValue method in the DateTimeExcel\Helpers class instead
*
* @param mixed $dateValue
*
@@ -49,17 +58,20 @@ class DateTime
* NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the date
* and time format of your regional settings. PhpSpreadsheet does not change cell formatting in this way.
*
- * @Deprecated 2.0.0 Use the funcNow method in the DateTimeExcel\Now class instead
- *
* Excel Function:
* NOW()
*
+ * @Deprecated 1.18.0
+ *
+ * @See DateTimeExcel\Current::now()
+ * Use the now method in the DateTimeExcel\Current class instead
+ *
* @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
* depending on the value of the ReturnDateType flag
*/
public static function DATETIMENOW()
{
- return DateTimeExcel\Now::funcNow();
+ return DateTimeExcel\Current::now();
}
/**
@@ -73,17 +85,20 @@ class DateTime
* NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the date
* and time format of your regional settings. PhpSpreadsheet does not change cell formatting in this way.
*
- * @Deprecated 2.0.0 Use the funcToday method in the DateTimeExcel\Today class instead
- *
* Excel Function:
* TODAY()
*
+ * @Deprecated 1.18.0
+ *
+ * @See DateTimeExcel\Current::today()
+ * Use the today method in the DateTimeExcel\Current class instead
+ *
* @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
* depending on the value of the ReturnDateType flag
*/
public static function DATENOW()
{
- return DateTimeExcel\Today::funcToday();
+ return DateTimeExcel\Current::today();
}
/**
@@ -94,11 +109,15 @@ class DateTime
* NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the date
* format of your regional settings. PhpSpreadsheet does not change cell formatting in this way.
*
- * @Deprecated 2.0.0 Use the funcDate method in the DateTimeExcel\Date class instead
*
* Excel Function:
* DATE(year,month,day)
*
+ * @Deprecated 1.18.0
+ *
+ * @See DateTimeExcel\Date::fromYMD()
+ * Use the fromYMD method in the DateTimeExcel\Date class instead
+ *
* PhpSpreadsheet is a lot more forgiving than MS Excel when passing non numeric values to this function.
* A Month name or abbreviation (English only at this point) such as 'January' or 'Jan' will still be accepted,
* as will a day value with a suffix (e.g. '21st' rather than simply 21); again only English language.
@@ -139,7 +158,7 @@ class DateTime
*/
public static function DATE($year = 0, $month = 1, $day = 1)
{
- return DateTimeExcel\Datefunc::funcDate($year, $month, $day);
+ return DateTimeExcel\Date::fromYMD($year, $month, $day);
}
/**
@@ -150,11 +169,14 @@ class DateTime
* NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the time
* format of your regional settings. PhpSpreadsheet does not change cell formatting in this way.
*
- * @Deprecated 2.0.0 Use the funcTime method in the DateTimeExcel\Time class instead
- *
* Excel Function:
* TIME(hour,minute,second)
*
+ * @Deprecated 1.18.0
+ *
+ * @See DateTimeExcel\Time::fromHMS()
+ * Use the fromHMS method in the DateTimeExcel\Time class instead
+ *
* @param int $hour A number from 0 (zero) to 32767 representing the hour.
* Any value greater than 23 will be divided by 24 and the remainder
* will be treated as the hour value. For example, TIME(27,0,0) =
@@ -172,7 +194,7 @@ class DateTime
*/
public static function TIME($hour = 0, $minute = 0, $second = 0)
{
- return DateTimeExcel\Time::funcTime($hour, $minute, $second);
+ return DateTimeExcel\Time::fromHMS($hour, $minute, $second);
}
/**
@@ -185,11 +207,14 @@ class DateTime
* NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the date
* format of your regional settings. PhpSpreadsheet does not change cell formatting in this way.
*
- * @Deprecated 2.0.0 Use the funcDateValue method in the DateTimeExcel\DateValue class instead
- *
* Excel Function:
* DATEVALUE(dateValue)
*
+ * @Deprecated 1.18.0
+ *
+ * @See DateTimeExcel\DateValue::fromString()
+ * Use the fromString method in the DateTimeExcel\DateValue class instead
+ *
* @param string $dateValue Text that represents a date in a Microsoft Excel date format.
* For example, "1/30/2008" or "30-Jan-2008" are text strings within
* quotation marks that represent dates. Using the default date
@@ -204,7 +229,7 @@ class DateTime
*/
public static function DATEVALUE($dateValue)
{
- return DateTimeExcel\DateValue::funcDateValue($dateValue);
+ return DateTimeExcel\DateValue::fromString($dateValue);
}
/**
@@ -217,11 +242,14 @@ class DateTime
* NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the time
* format of your regional settings. PhpSpreadsheet does not change cell formatting in this way.
*
- * @Deprecated 2.0.0 Use the funcTimeValue method in the DateTimeExcel\TimeValue class instead
- *
* Excel Function:
* TIMEVALUE(timeValue)
*
+ * @Deprecated 1.18.0
+ *
+ * @See DateTimeExcel\TimeValue::fromString()
+ * Use the fromString method in the DateTimeExcel\TimeValue class instead
+ *
* @param string $timeValue A text string that represents a time in any one of the Microsoft
* Excel time formats; for example, "6:45 PM" and "18:45" text strings
* within quotation marks that represent time.
@@ -232,13 +260,19 @@ class DateTime
*/
public static function TIMEVALUE($timeValue)
{
- return DateTimeExcel\TimeValue::funcTimeValue($timeValue);
+ return DateTimeExcel\TimeValue::fromString($timeValue);
}
/**
* DATEDIF.
*
- * @Deprecated 2.0.0 Use the funcDateDif method in the DateTimeExcel\DateDif class instead
+ * Excel Function:
+ * DATEDIF(startdate, enddate, unit)
+ *
+ * @Deprecated 1.18.0
+ *
+ * @See DateTimeExcel\Difference::interval()
+ * Use the interval method in the DateTimeExcel\Difference class instead
*
* @param mixed $startDate Excel date serial value, PHP date/time stamp, PHP DateTime object
* or a standard date string
@@ -250,7 +284,7 @@ class DateTime
*/
public static function DATEDIF($startDate = 0, $endDate = 0, $unit = 'D')
{
- return DateTimeExcel\DateDif::funcDateDif($startDate, $endDate, $unit);
+ return DateTimeExcel\Difference::interval($startDate, $endDate, $unit);
}
/**
@@ -258,11 +292,14 @@ class DateTime
*
* Returns the number of days between two dates
*
- * @Deprecated 2.0.0 Use the funcDays method in the DateTimeExcel\Days class instead
- *
* Excel Function:
* DAYS(endDate, startDate)
*
+ * @Deprecated 1.18.0
+ *
+ * @See DateTimeExcel\Days::between()
+ * Use the between method in the DateTimeExcel\Days class instead
+ *
* @param DateTimeInterface|float|int|string $endDate Excel date serial value (float),
* PHP date timestamp (integer), PHP DateTime object, or a standard date string
* @param DateTimeInterface|float|int|string $startDate Excel date serial value (float),
@@ -272,7 +309,7 @@ class DateTime
*/
public static function DAYS($endDate = 0, $startDate = 0)
{
- return DateTimeExcel\Days::funcDays($endDate, $startDate);
+ return DateTimeExcel\Days::between($endDate, $startDate);
}
/**
@@ -282,11 +319,14 @@ class DateTime
* which is used in some accounting calculations. Use this function to help compute payments if
* your accounting system is based on twelve 30-day months.
*
- * @Deprecated 2.0.0 Use the funcDays360 method in the DateTimeExcel\Days360 class instead
- *
* Excel Function:
* DAYS360(startDate,endDate[,method])
*
+ * @Deprecated 1.18.0
+ *
+ * @See DateTimeExcel\Days360::between()
+ * Use the between method in the DateTimeExcel\Days360 class instead
+ *
* @param mixed $startDate Excel date serial value (float), PHP date timestamp (integer),
* PHP DateTime object, or a standard date string
* @param mixed $endDate Excel date serial value (float), PHP date timestamp (integer),
@@ -307,7 +347,7 @@ class DateTime
*/
public static function DAYS360($startDate = 0, $endDate = 0, $method = false)
{
- return DateTimeExcel\Days360::funcDays360($startDate, $endDate, $method);
+ return DateTimeExcel\Days360::between($startDate, $endDate, $method);
}
/**
@@ -318,10 +358,14 @@ class DateTime
* Use the YEARFRAC worksheet function to identify the proportion of a whole year's benefits or
* obligations to assign to a specific term.
*
- * @Deprecated 2.0.0 Use the funcYearFrac method in the DateTimeExcel\YearFrac class instead
- *
* Excel Function:
* YEARFRAC(startDate,endDate[,method])
+ *
+ * @Deprecated 1.18.0
+ *
+ * @See DateTimeExcel\YearFrac::fraction()
+ * Use the fraction method in the DateTimeExcel\YearFrac class instead
+ *
* See https://lists.oasis-open.org/archives/office-formula/200806/msg00039.html
* for description of algorithm used in Excel
*
@@ -340,7 +384,7 @@ class DateTime
*/
public static function YEARFRAC($startDate = 0, $endDate = 0, $method = 0)
{
- return DateTimeExcel\YearFrac::funcYearFrac($startDate, $endDate, $method);
+ return DateTimeExcel\YearFrac::fraction($startDate, $endDate, $method);
}
/**
@@ -351,21 +395,25 @@ class DateTime
* Use NETWORKDAYS to calculate employee benefits that accrue based on the number of days
* worked during a specific term.
*
- * @Deprecated 2.0.0 Use the funcNetworkDays method in the DateTimeExcel\NetworkDays class instead
- *
* Excel Function:
* NETWORKDAYS(startDate,endDate[,holidays[,holiday[,...]]])
*
+ * @Deprecated 1.18.0
+ *
+ * @See DateTimeExcel\NetworkDays::count()
+ * Use the count method in the DateTimeExcel\NetworkDays class instead
+ *
* @param mixed $startDate Excel date serial value (float), PHP date timestamp (integer),
* PHP DateTime object, or a standard date string
* @param mixed $endDate Excel date serial value (float), PHP date timestamp (integer),
* PHP DateTime object, or a standard date string
+ * @param mixed $dateArgs
*
* @return int|string Interval between the dates
*/
public static function NETWORKDAYS($startDate, $endDate, ...$dateArgs)
{
- return DateTimeExcel\NetworkDays::funcNetworkDays($startDate, $endDate, ...$dateArgs);
+ return DateTimeExcel\NetworkDays::count($startDate, $endDate, ...$dateArgs);
}
/**
@@ -376,23 +424,27 @@ class DateTime
* Use WORKDAY to exclude weekends or holidays when you calculate invoice due dates, expected
* delivery times, or the number of days of work performed.
*
- * @Deprecated 2.0.0 Use the funcWorkDay method in the DateTimeExcel\WorkDay class instead
- *
* Excel Function:
* WORKDAY(startDate,endDays[,holidays[,holiday[,...]]])
*
+ * @Deprecated 1.18.0
+ *
+ * @See DateTimeExcel\WorkDay::date()
+ * Use the date method in the DateTimeExcel\WorkDay class instead
+ *
* @param mixed $startDate Excel date serial value (float), PHP date timestamp (integer),
* PHP DateTime object, or a standard date string
* @param int $endDays The number of nonweekend and nonholiday days before or after
* startDate. A positive value for days yields a future date; a
* negative value yields a past date.
+ * @param mixed $dateArgs
*
* @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
* depending on the value of the ReturnDateType flag
*/
public static function WORKDAY($startDate, $endDays, ...$dateArgs)
{
- return DateTimeExcel\WorkDay::funcWorkDay($startDate, $endDays, ...$dateArgs);
+ return DateTimeExcel\WorkDay::date($startDate, $endDays, ...$dateArgs);
}
/**
@@ -401,11 +453,14 @@ class DateTime
* Returns the day of the month, for a specified date. The day is given as an integer
* ranging from 1 to 31.
*
- * @Deprecated 2.0.0 Use the funcDay method in the DateTimeExcel\Day class instead
- *
* Excel Function:
* DAY(dateValue)
*
+ * @Deprecated 1.18.0
+ *
+ * @See DateTimeExcel\DateParts::day()
+ * Use the day method in the DateTimeExcel\DateParts class instead
+ *
* @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer),
* PHP DateTime object, or a standard date string
*
@@ -413,7 +468,7 @@ class DateTime
*/
public static function DAYOFMONTH($dateValue = 1)
{
- return DateTimeExcel\Day::funcDay($dateValue);
+ return DateTimeExcel\DateParts::day($dateValue);
}
/**
@@ -422,11 +477,14 @@ class DateTime
* Returns the day of the week for a specified date. The day is given as an integer
* ranging from 0 to 7 (dependent on the requested style).
*
- * @Deprecated 2.0.0 Use the funcWeekDay method in the DateTimeExcel\WeekDay class instead
- *
* Excel Function:
* WEEKDAY(dateValue[,style])
*
+ * @Deprecated 1.18.0
+ *
+ * @See DateTimeExcel\Week::day()
+ * Use the day method in the DateTimeExcel\Week class instead
+ *
* @param float|int|string $dateValue Excel date serial value (float), PHP date timestamp (integer),
* PHP DateTime object, or a standard date string
* @param int $style A number that determines the type of return value
@@ -438,13 +496,13 @@ class DateTime
*/
public static function WEEKDAY($dateValue = 1, $style = 1)
{
- return DateTimeExcel\WeekDay::funcWeekDay($dateValue, $style);
+ return DateTimeExcel\Week::day($dateValue, $style);
}
/**
* STARTWEEK_SUNDAY.
*
- * @Deprecated 2.0.0
+ * @Deprecated 1.18.0
*
* @see Use DateTimeExcel\Constants\STARTWEEK_SUNDAY instead
*/
@@ -453,7 +511,7 @@ class DateTime
/**
* STARTWEEK_MONDAY.
*
- * @Deprecated 2.0.0
+ * @Deprecated 1.18.0
*
* @see Use DateTimeExcel\Constants\STARTWEEK_MONDAY instead
*/
@@ -462,7 +520,7 @@ class DateTime
/**
* STARTWEEK_MONDAY_ALT.
*
- * @Deprecated 2.0.0
+ * @Deprecated 1.18.0
*
* @see Use DateTimeExcel\Constants\STARTWEEK_MONDAY_ALT instead
*/
@@ -471,7 +529,7 @@ class DateTime
/**
* STARTWEEK_TUESDAY.
*
- * @Deprecated 2.0.0
+ * @Deprecated 1.18.0
*
* @see Use DateTimeExcel\Constants\STARTWEEK_TUESDAY instead
*/
@@ -480,7 +538,7 @@ class DateTime
/**
* STARTWEEK_WEDNESDAY.
*
- * @Deprecated 2.0.0
+ * @Deprecated 1.18.0
*
* @see Use DateTimeExcel\Constants\STARTWEEK_WEDNESDAY instead
*/
@@ -489,7 +547,7 @@ class DateTime
/**
* STARTWEEK_THURSDAY.
*
- * @Deprecated 2.0.0
+ * @Deprecated 1.18.0
*
* @see Use DateTimeExcel\Constants\STARTWEEK_THURSDAY instead
*/
@@ -498,7 +556,7 @@ class DateTime
/**
* STARTWEEK_FRIDAY.
*
- * @Deprecated 2.0.0
+ * @Deprecated 1.18.0
*
* @see Use DateTimeExcel\Constants\STARTWEEK_FRIDAY instead
*/
@@ -507,7 +565,7 @@ class DateTime
/**
* STARTWEEK_SATURDAY.
*
- * @Deprecated 2.0.0
+ * @Deprecated 1.18.0
*
* @see Use DateTimeExcel\Constants\STARTWEEK_SATURDAY instead
*/
@@ -516,7 +574,7 @@ class DateTime
/**
* STARTWEEK_SUNDAY_ALT.
*
- * @Deprecated 2.0.0
+ * @Deprecated 1.18.0
*
* @see Use DateTimeExcel\Constants\STARTWEEK_SUNDAY_ALT instead
*/
@@ -525,7 +583,7 @@ class DateTime
/**
* DOW_SUNDAY.
*
- * @Deprecated 2.0.0
+ * @Deprecated 1.18.0
*
* @see Use DateTimeExcel\Constants\DOW_SUNDAY instead
*/
@@ -534,7 +592,7 @@ class DateTime
/**
* DOW_MONDAY.
*
- * @Deprecated 2.0.0
+ * @Deprecated 1.18.0
*
* @see Use DateTimeExcel\Constants\DOW_MONDAY instead
*/
@@ -543,7 +601,7 @@ class DateTime
/**
* DOW_TUESDAY.
*
- * @Deprecated 2.0.0
+ * @Deprecated 1.18.0
*
* @see Use DateTimeExcel\Constants\DOW_TUESDAY instead
*/
@@ -552,7 +610,7 @@ class DateTime
/**
* DOW_WEDNESDAY.
*
- * @Deprecated 2.0.0
+ * @Deprecated 1.18.0
*
* @see Use DateTimeExcel\Constants\DOW_WEDNESDAY instead
*/
@@ -561,7 +619,7 @@ class DateTime
/**
* DOW_THURSDAY.
*
- * @Deprecated 2.0.0
+ * @Deprecated 1.18.0
*
* @see Use DateTimeExcel\Constants\DOW_THURSDAY instead
*/
@@ -570,7 +628,7 @@ class DateTime
/**
* DOW_FRIDAY.
*
- * @Deprecated 2.0.0
+ * @Deprecated 1.18.0
*
* @see Use DateTimeExcel\Constants\DOW_FRIDAY instead
*/
@@ -579,7 +637,7 @@ class DateTime
/**
* DOW_SATURDAY.
*
- * @Deprecated 2.0.0
+ * @Deprecated 1.18.0
*
* @see Use DateTimeExcel\Constants\DOW_SATURDAY instead
*/
@@ -588,7 +646,7 @@ class DateTime
/**
* STARTWEEK_MONDAY_ISO.
*
- * @Deprecated 2.0.0
+ * @Deprecated 1.18.0
*
* @see Use DateTimeExcel\Constants\STARTWEEK_MONDAY_ISO instead
*/
@@ -597,7 +655,7 @@ class DateTime
/**
* METHODARR.
*
- * @Deprecated 2.0.0
+ * @Deprecated 1.18.0
*
* @see Use DateTimeExcel\Constants\METHODARR instead
*/
@@ -624,11 +682,14 @@ class DateTime
* three days or less in the first week of January, the WEEKNUM function returns week numbers
* that are incorrect according to the European standard.
*
- * @Deprecated 2.0.0 Use the funcWeekNum method in the DateTimeExcel\WeekNum class instead
- *
* Excel Function:
* WEEKNUM(dateValue[,style])
*
+ * @Deprecated 1.18.0
+ *
+ * @See DateTimeExcel\Week::number(()
+ * Use the number method in the DateTimeExcel\Week class instead
+ *
* @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer),
* PHP DateTime object, or a standard date string
* @param int $method Week begins on Sunday or Monday
@@ -647,7 +708,7 @@ class DateTime
*/
public static function WEEKNUM($dateValue = 1, $method = self::STARTWEEK_SUNDAY)
{
- return DateTimeExcel\WeekNum::funcWeekNum($dateValue, $method);
+ return DateTimeExcel\Week::number($dateValue, $method);
}
/**
@@ -655,11 +716,14 @@ class DateTime
*
* Returns the ISO 8601 week number of the year for a specified date.
*
- * @Deprecated 2.0.0 Use the funcIsoWeeknum method in the DateTimeExcel\IsoWeekNum class instead
- *
* Excel Function:
* ISOWEEKNUM(dateValue)
*
+ * @Deprecated 1.18.0
+ *
+ * @See DateTimeExcel\Week::isoWeekNumber()
+ * Use the isoWeekNumber method in the DateTimeExcel\Week class instead
+ *
* @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer),
* PHP DateTime object, or a standard date string
*
@@ -667,7 +731,7 @@ class DateTime
*/
public static function ISOWEEKNUM($dateValue = 1)
{
- return DateTimeExcel\IsoWeekNum::funcIsoWeekNum($dateValue);
+ return DateTimeExcel\Week::isoWeekNumber($dateValue);
}
/**
@@ -676,11 +740,14 @@ class DateTime
* Returns the month of a date represented by a serial number.
* The month is given as an integer, ranging from 1 (January) to 12 (December).
*
- * @Deprecated 2.0.0 Use the funcMonth method in the DateTimeExcel\Month class instead
- *
* Excel Function:
* MONTH(dateValue)
*
+ * @Deprecated 1.18.0
+ *
+ * @See DateTimeExcel\DateParts::month()
+ * Use the month method in the DateTimeExcel\DateParts class instead
+ *
* @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer),
* PHP DateTime object, or a standard date string
*
@@ -688,7 +755,7 @@ class DateTime
*/
public static function MONTHOFYEAR($dateValue = 1)
{
- return DateTimeExcel\Month::funcMonth($dateValue);
+ return DateTimeExcel\DateParts::month($dateValue);
}
/**
@@ -697,11 +764,14 @@ class DateTime
* Returns the year corresponding to a date.
* The year is returned as an integer in the range 1900-9999.
*
- * @Deprecated 2.0.0 Use the funcYear method in the DateTimeExcel\Year class instead
- *
* Excel Function:
* YEAR(dateValue)
*
+ * @Deprecated 1.18.0
+ *
+ * @See DateTimeExcel\DateParts::year()
+ * Use the ear method in the DateTimeExcel\DateParts class instead
+ *
* @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer),
* PHP DateTime object, or a standard date string
*
@@ -709,7 +779,7 @@ class DateTime
*/
public static function YEAR($dateValue = 1)
{
- return DateTimeExcel\Year::funcYear($dateValue);
+ return DateTimeExcel\DateParts::year($dateValue);
}
/**
@@ -718,11 +788,14 @@ class DateTime
* Returns the hour of a time value.
* The hour is given as an integer, ranging from 0 (12:00 A.M.) to 23 (11:00 P.M.).
*
- * @Deprecated 2.0.0 Use the funcHour method in the DateTimeExcel\Hour class instead
- *
* Excel Function:
* HOUR(timeValue)
*
+ * @Deprecated 1.18.0
+ *
+ * @See DateTimeExcel\TimeParts::hour()
+ * Use the hour method in the DateTimeExcel\TimeParts class instead
+ *
* @param mixed $timeValue Excel date serial value (float), PHP date timestamp (integer),
* PHP DateTime object, or a standard time string
*
@@ -730,7 +803,7 @@ class DateTime
*/
public static function HOUROFDAY($timeValue = 0)
{
- return DateTimeExcel\Hour::funcHour($timeValue);
+ return DateTimeExcel\TimeParts::hour($timeValue);
}
/**
@@ -739,11 +812,14 @@ class DateTime
* Returns the minutes of a time value.
* The minute is given as an integer, ranging from 0 to 59.
*
- * @Deprecated 2.0.0 Use the funcMinute method in the DateTimeExcel\Minute class instead
- *
* Excel Function:
* MINUTE(timeValue)
*
+ * @Deprecated 1.18.0
+ *
+ * @See DateTimeExcel\TimeParts::minute()
+ * Use the minute method in the DateTimeExcel\TimeParts class instead
+ *
* @param mixed $timeValue Excel date serial value (float), PHP date timestamp (integer),
* PHP DateTime object, or a standard time string
*
@@ -751,7 +827,7 @@ class DateTime
*/
public static function MINUTE($timeValue = 0)
{
- return DateTimeExcel\Minute::funcMinute($timeValue);
+ return DateTimeExcel\TimeParts::minute($timeValue);
}
/**
@@ -760,11 +836,14 @@ class DateTime
* Returns the seconds of a time value.
* The second is given as an integer in the range 0 (zero) to 59.
*
- * @Deprecated 2.0.0 Use the funcSecond method in the DateTimeExcel\Second class instead
- *
* Excel Function:
* SECOND(timeValue)
*
+ * @Deprecated 1.18.0
+ *
+ * @See DateTimeExcel\TimeParts::second()
+ * Use the second method in the DateTimeExcel\TimeParts class instead
+ *
* @param mixed $timeValue Excel date serial value (float), PHP date timestamp (integer),
* PHP DateTime object, or a standard time string
*
@@ -772,7 +851,7 @@ class DateTime
*/
public static function SECOND($timeValue = 0)
{
- return DateTimeExcel\Second::funcSecond($timeValue);
+ return DateTimeExcel\TimeParts::second($timeValue);
}
/**
@@ -783,11 +862,14 @@ class DateTime
* Use EDATE to calculate maturity dates or due dates that fall on the same day of the month
* as the date of issue.
*
- * @Deprecated 2.0.0 Use the funcEDate method in the DateTimeExcel\EDate class instead
- *
* Excel Function:
* EDATE(dateValue,adjustmentMonths)
*
+ * @Deprecated 1.18.0
+ *
+ * @See DateTimeExcel\Month::adjust()
+ * Use the adjust method in the DateTimeExcel\Edate class instead
+ *
* @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer),
* PHP DateTime object, or a standard date string
* @param int $adjustmentMonths The number of months before or after start_date.
@@ -799,7 +881,7 @@ class DateTime
*/
public static function EDATE($dateValue = 1, $adjustmentMonths = 0)
{
- return DateTimeExcel\EDate::funcEDate($dateValue, $adjustmentMonths);
+ return DateTimeExcel\Month::adjust($dateValue, $adjustmentMonths);
}
/**
@@ -809,11 +891,14 @@ class DateTime
* before or after start_date.
* Use EOMONTH to calculate maturity dates or due dates that fall on the last day of the month.
*
- * @Deprecated 2.0.0 Use the funcEoMonth method in the DateTimeExcel\EoMonth class instead
- *
* Excel Function:
* EOMONTH(dateValue,adjustmentMonths)
*
+ * @Deprecated 1.18.0
+ *
+ * @See DateTimeExcel\Month::lastDay()
+ * Use the lastDay method in the DateTimeExcel\EoMonth class instead
+ *
* @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer),
* PHP DateTime object, or a standard date string
* @param int $adjustmentMonths The number of months before or after start_date.
@@ -825,6 +910,6 @@ class DateTime
*/
public static function EOMONTH($dateValue = 1, $adjustmentMonths = 0)
{
- return DateTimeExcel\EoMonth::funcEoMonth($dateValue, $adjustmentMonths);
+ return DateTimeExcel\Month::lastDay($dateValue, $adjustmentMonths);
}
}
diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Constants.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Constants.php
index da1b81c1..1165eb1f 100644
--- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Constants.php
+++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Constants.php
@@ -22,6 +22,7 @@ class Constants
const DOW_FRIDAY = 6;
const DOW_SATURDAY = 7;
const STARTWEEK_MONDAY_ISO = 21;
+
const METHODARR = [
self::STARTWEEK_SUNDAY => self::DOW_SUNDAY,
self::DOW_MONDAY,
diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Now.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Current.php
similarity index 51%
rename from src/PhpSpreadsheet/Calculation/DateTimeExcel/Now.php
rename to src/PhpSpreadsheet/Calculation/DateTimeExcel/Current.php
index 6e6bd171..7a70978e 100644
--- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Now.php
+++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Current.php
@@ -5,8 +5,33 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
use DateTimeImmutable;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
-class Now
+class Current
{
+ /**
+ * DATENOW.
+ *
+ * Returns the current date.
+ * The NOW function is useful when you need to display the current date and time on a worksheet or
+ * calculate a value based on the current date and time, and have that value updated each time you
+ * open the worksheet.
+ *
+ * NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the date
+ * and time format of your regional settings. PhpSpreadsheet does not change cell formatting in this way.
+ *
+ * Excel Function:
+ * TODAY()
+ *
+ * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
+ * depending on the value of the ReturnDateType flag
+ */
+ public static function today()
+ {
+ $dti = new DateTimeImmutable();
+ $dateArray = date_parse($dti->format('c'));
+
+ return is_array($dateArray) ? Helpers::returnIn3FormatsArray($dateArray, true) : Functions::VALUE();
+ }
+
/**
* DATETIMENOW.
*
@@ -24,7 +49,7 @@ class Now
* @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
* depending on the value of the ReturnDateType flag
*/
- public static function funcNow()
+ public static function now()
{
$dti = new DateTimeImmutable();
$dateArray = date_parse($dti->format('c'));
diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Datefunc.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Date.php
similarity index 92%
rename from src/PhpSpreadsheet/Calculation/DateTimeExcel/Datefunc.php
rename to src/PhpSpreadsheet/Calculation/DateTimeExcel/Date.php
index ec8be2df..d18e2371 100644
--- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Datefunc.php
+++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Date.php
@@ -2,12 +2,12 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
-use Exception;
+use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
-use PhpOffice\PhpSpreadsheet\Shared\Date;
+use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
-class Datefunc
+class Date
{
/**
* DATE.
@@ -58,9 +58,9 @@ class Datefunc
* @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
* depending on the value of the ReturnDateType flag
*/
- public static function funcDate($year, $month, $day)
+ public static function fromYMD($year, $month, $day)
{
- $baseYear = Date::getExcelCalendar();
+ $baseYear = SharedDateHelper::getExcelCalendar();
try {
$year = self::getYear($year, $baseYear);
@@ -72,7 +72,7 @@ class Datefunc
}
// Execute function
- $excelDateValue = Date::formattedPHPToExcel($year, $month, $day);
+ $excelDateValue = SharedDateHelper::formattedPHPToExcel($year, $month, $day);
return Helpers::returnIn3FormatsFloat($excelDateValue);
}
@@ -85,7 +85,7 @@ class Datefunc
private static function getYear($year, int $baseYear): int
{
$year = Functions::flattenSingleValue($year);
- $year = ($year !== null) ? StringHelper::testStringAsNumeric($year) : 0;
+ $year = ($year !== null) ? StringHelper::testStringAsNumeric((string) $year) : 0;
if (!is_numeric($year)) {
throw new Exception(Functions::VALUE());
}
@@ -102,7 +102,7 @@ class Datefunc
$year += 1900;
}
- return $year;
+ return (int) $year;
}
/**
@@ -115,10 +115,10 @@ class Datefunc
$month = Functions::flattenSingleValue($month);
if (($month !== null) && (!is_numeric($month))) {
- $month = Date::monthStringToNumber($month);
+ $month = SharedDateHelper::monthStringToNumber($month);
}
- $month = ($month !== null) ? StringHelper::testStringAsNumeric($month) : 0;
+ $month = ($month !== null) ? StringHelper::testStringAsNumeric((string) $month) : 0;
if (!is_numeric($month)) {
throw new Exception(Functions::VALUE());
}
@@ -136,10 +136,10 @@ class Datefunc
$day = Functions::flattenSingleValue($day);
if (($day !== null) && (!is_numeric($day))) {
- $day = Date::dayStringToNumber($day);
+ $day = SharedDateHelper::dayStringToNumber($day);
}
- $day = ($day !== null) ? StringHelper::testStringAsNumeric($day) : 0;
+ $day = ($day !== null) ? StringHelper::testStringAsNumeric((string) $day) : 0;
if (!is_numeric($day)) {
throw new Exception(Functions::VALUE());
}
diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/DateParts.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/DateParts.php
new file mode 100644
index 00000000..37ea0315
--- /dev/null
+++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/DateParts.php
@@ -0,0 +1,127 @@
+= 0) {
+ return $weirdResult;
+ }
+
+ try {
+ $dateValue = Helpers::getDateValue($dateValue);
+ } catch (Exception $e) {
+ return $e->getMessage();
+ }
+
+ // Execute function
+ $PHPDateObject = SharedDateHelper::excelToDateTimeObject($dateValue);
+
+ return (int) $PHPDateObject->format('j');
+ }
+
+ /**
+ * MONTHOFYEAR.
+ *
+ * Returns the month of a date represented by a serial number.
+ * The month is given as an integer, ranging from 1 (January) to 12 (December).
+ *
+ * Excel Function:
+ * MONTH(dateValue)
+ *
+ * @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer),
+ * PHP DateTime object, or a standard date string
+ *
+ * @return int|string Month of the year
+ */
+ public static function month($dateValue)
+ {
+ try {
+ $dateValue = Helpers::getDateValue($dateValue);
+ } catch (Exception $e) {
+ return $e->getMessage();
+ }
+ if ($dateValue < 1 && SharedDateHelper::getExcelCalendar() === SharedDateHelper::CALENDAR_WINDOWS_1900) {
+ return 1;
+ }
+
+ // Execute function
+ $PHPDateObject = SharedDateHelper::excelToDateTimeObject($dateValue);
+
+ return (int) $PHPDateObject->format('n');
+ }
+
+ /**
+ * YEAR.
+ *
+ * Returns the year corresponding to a date.
+ * The year is returned as an integer in the range 1900-9999.
+ *
+ * Excel Function:
+ * YEAR(dateValue)
+ *
+ * @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer),
+ * PHP DateTime object, or a standard date string
+ *
+ * @return int|string Year
+ */
+ public static function year($dateValue)
+ {
+ try {
+ $dateValue = Helpers::getDateValue($dateValue);
+ } catch (Exception $e) {
+ return $e->getMessage();
+ }
+
+ if ($dateValue < 1 && SharedDateHelper::getExcelCalendar() === SharedDateHelper::CALENDAR_WINDOWS_1900) {
+ return 1900;
+ }
+ // Execute function
+ $PHPDateObject = SharedDateHelper::excelToDateTimeObject($dateValue);
+
+ return (int) $PHPDateObject->format('Y');
+ }
+
+ /**
+ * @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer),
+ * PHP DateTime object, or a standard date string
+ */
+ private static function weirdCondition($dateValue): int
+ {
+ // Excel does not treat 0 consistently for DAY vs. (MONTH or YEAR)
+ if (SharedDateHelper::getExcelCalendar() === SharedDateHelper::CALENDAR_WINDOWS_1900 && Functions::getCompatibilityMode() == Functions::COMPATIBILITY_EXCEL) {
+ if (is_bool($dateValue)) {
+ return (int) $dateValue;
+ }
+ if ($dateValue === null) {
+ return 0;
+ }
+ if (is_numeric($dateValue) && $dateValue < 1 && $dateValue >= 0) {
+ return 0;
+ }
+ }
+
+ return -1;
+ }
+}
diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/DateValue.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/DateValue.php
index 86b8d3d9..de767fca 100644
--- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/DateValue.php
+++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/DateValue.php
@@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
use DateTimeImmutable;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
-use PhpOffice\PhpSpreadsheet\Shared\Date;
+use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper;
class DateValue
{
@@ -33,13 +33,13 @@ class DateValue
* @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
* depending on the value of the ReturnDateType flag
*/
- public static function funcDateValue($dateValue)
+ public static function fromString($dateValue)
{
$dti = new DateTimeImmutable();
- $baseYear = Date::getExcelCalendar();
+ $baseYear = SharedDateHelper::getExcelCalendar();
$dateValue = trim(Functions::flattenSingleValue($dateValue), '"');
// Strip any ordinals because they're allowed in Excel (English only)
- $dateValue = preg_replace('/(\d)(st|nd|rd|th)([ -\/])/Ui', '$1$3', $dateValue);
+ $dateValue = preg_replace('/(\d)(st|nd|rd|th)([ -\/])/Ui', '$1$3', $dateValue) ?? '';
// Convert separators (/ . or space) to hyphens (should also handle dot used for ordinals in some countries, e.g. Denmark, Germany)
$dateValue = str_replace(['/', '.', '-', ' '], ' ', $dateValue);
@@ -59,7 +59,7 @@ class DateValue
}
if (count($t1) === 1) {
// We've been fed a time value without any date
- return ((strpos($t, ':') === false)) ? Functions::Value() : 0.0;
+ return ((strpos((string) $t, ':') === false)) ? Functions::Value() : 0.0;
}
unset($t);
@@ -105,7 +105,7 @@ class DateValue
$testVal1 = strtok($dateValue, '- ');
$testVal2 = strtok('- ');
$testVal3 = strtok('- ') ?: $dti->format('Y');
- Helpers::adjustYear($testVal1, $testVal2, $testVal3);
+ Helpers::adjustYear((string) $testVal1, (string) $testVal2, $testVal3);
$PHPDateArray = date_parse($testVal1 . '-' . $testVal2 . '-' . $testVal3);
if (($PHPDateArray === false) || ($PHPDateArray['error_count'] > 0)) {
$PHPDateArray = date_parse($testVal2 . '-' . $testVal1 . '-' . $testVal3);
@@ -118,7 +118,7 @@ class DateValue
/**
* Final results.
*
- * @param array|false $PHPDateArray
+ * @param array|bool $PHPDateArray
*
* @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
* depending on the value of the ReturnDateType flag
@@ -126,7 +126,7 @@ class DateValue
private static function finalResults($PHPDateArray, DateTimeImmutable $dti, int $baseYear)
{
$retValue = Functions::Value();
- if (($PHPDateArray !== false) && ($PHPDateArray['error_count'] == 0)) {
+ if (is_array($PHPDateArray) && $PHPDateArray['error_count'] == 0) {
// Execute function
Helpers::replaceIfEmpty($PHPDateArray['year'], $dti->format('Y'));
if ($PHPDateArray['year'] < $baseYear) {
diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Day.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Day.php
deleted file mode 100644
index 6ab27184..00000000
--- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Day.php
+++ /dev/null
@@ -1,61 +0,0 @@
-= 0) {
- return $weirdResult;
- }
-
- try {
- $dateValue = Helpers::getDateValue($dateValue);
- } catch (Exception $e) {
- return $e->getMessage();
- }
-
- // Execute function
- $PHPDateObject = Date::excelToDateTimeObject($dateValue);
-
- return (int) $PHPDateObject->format('j');
- }
-
- private static function weirdCondition($dateValue): int
- {
- // Excel does not treat 0 consistently for DAY vs. (MONTH or YEAR)
- if (Date::getExcelCalendar() === DATE::CALENDAR_WINDOWS_1900 && Functions::getCompatibilityMode() == Functions::COMPATIBILITY_EXCEL) {
- if (is_bool($dateValue)) {
- return (int) $dateValue;
- }
- if ($dateValue === null) {
- return 0;
- }
- if (is_numeric($dateValue) && $dateValue < 1 && $dateValue >= 0) {
- return 0;
- }
- }
-
- return -1;
- }
-}
diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Days.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Days.php
index 2c814e8e..5a97d8df 100644
--- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Days.php
+++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Days.php
@@ -3,9 +3,9 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
use DateTimeInterface;
-use Exception;
+use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
-use PhpOffice\PhpSpreadsheet\Shared\Date;
+use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper;
class Days
{
@@ -24,7 +24,7 @@ class Days
*
* @return int|string Number of days between start date and end date or an error
*/
- public static function funcDays($endDate, $startDate)
+ public static function between($endDate, $startDate)
{
try {
$startDate = Helpers::getDateValue($startDate);
@@ -34,8 +34,8 @@ class Days
}
// Execute function
- $PHPStartDateObject = Date::excelToDateTimeObject($startDate);
- $PHPEndDateObject = Date::excelToDateTimeObject($endDate);
+ $PHPStartDateObject = SharedDateHelper::excelToDateTimeObject($startDate);
+ $PHPEndDateObject = SharedDateHelper::excelToDateTimeObject($endDate);
$days = Functions::VALUE();
$diff = $PHPStartDateObject->diff($PHPEndDateObject);
diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Days360.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Days360.php
index 47de02c3..bbc5d16a 100644
--- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Days360.php
+++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Days360.php
@@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
-use PhpOffice\PhpSpreadsheet\Shared\Date;
+use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper;
class Days360
{
@@ -36,7 +36,7 @@ class Days360
*
* @return int|string Number of days between start date and end date
*/
- public static function funcDays360($startDate = 0, $endDate = 0, $method = false)
+ public static function between($startDate = 0, $endDate = 0, $method = false)
{
try {
$startDate = Helpers::getDateValue($startDate);
@@ -50,12 +50,12 @@ class Days360
}
// Execute function
- $PHPStartDateObject = Date::excelToDateTimeObject($startDate);
+ $PHPStartDateObject = SharedDateHelper::excelToDateTimeObject($startDate);
$startDay = $PHPStartDateObject->format('j');
$startMonth = $PHPStartDateObject->format('n');
$startYear = $PHPStartDateObject->format('Y');
- $PHPEndDateObject = Date::excelToDateTimeObject($endDate);
+ $PHPEndDateObject = SharedDateHelper::excelToDateTimeObject($endDate);
$endDay = $PHPEndDateObject->format('j');
$endMonth = $PHPEndDateObject->format('n');
$endYear = $PHPEndDateObject->format('Y');
diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/DateDif.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Difference.php
similarity index 93%
rename from src/PhpSpreadsheet/Calculation/DateTimeExcel/DateDif.php
rename to src/PhpSpreadsheet/Calculation/DateTimeExcel/Difference.php
index c0d1fa4b..6adeca17 100644
--- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/DateDif.php
+++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Difference.php
@@ -4,11 +4,11 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
use DateInterval;
use DateTime;
-use Exception;
+use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
-use PhpOffice\PhpSpreadsheet\Shared\Date;
+use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper;
-class DateDif
+class Difference
{
/**
* DATEDIF.
@@ -21,7 +21,7 @@ class DateDif
*
* @return int|string Interval between the dates
*/
- public static function funcDateDif($startDate, $endDate, $unit = 'D')
+ public static function interval($startDate, $endDate, $unit = 'D')
{
try {
$startDate = Helpers::getDateValue($startDate);
@@ -33,12 +33,12 @@ class DateDif
}
// Execute function
- $PHPStartDateObject = Date::excelToDateTimeObject($startDate);
+ $PHPStartDateObject = SharedDateHelper::excelToDateTimeObject($startDate);
$startDays = (int) $PHPStartDateObject->format('j');
$startMonths = (int) $PHPStartDateObject->format('n');
$startYears = (int) $PHPStartDateObject->format('Y');
- $PHPEndDateObject = Date::excelToDateTimeObject($endDate);
+ $PHPEndDateObject = SharedDateHelper::excelToDateTimeObject($endDate);
$endDays = (int) $PHPEndDateObject->format('j');
$endMonths = (int) $PHPEndDateObject->format('n');
$endYears = (int) $PHPEndDateObject->format('Y');
diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/EDate.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/EDate.php
deleted file mode 100644
index 43af694f..00000000
--- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/EDate.php
+++ /dev/null
@@ -1,45 +0,0 @@
-getMessage();
- }
- $adjustmentMonths = floor($adjustmentMonths);
-
- // Execute function
- $PHPDateObject = Helpers::adjustDateByMonths($dateValue, $adjustmentMonths);
-
- return Helpers::returnIn3FormatsObject($PHPDateObject);
- }
-}
diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/EoMonth.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/EoMonth.php
deleted file mode 100644
index 6b39a609..00000000
--- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/EoMonth.php
+++ /dev/null
@@ -1,47 +0,0 @@
-getMessage();
- }
- $adjustmentMonths = floor($adjustmentMonths);
-
- // Execute function
- $PHPDateObject = Helpers::adjustDateByMonths($dateValue, $adjustmentMonths + 1);
- $adjustDays = (int) $PHPDateObject->format('d');
- $adjustDaysString = '-' . $adjustDays . ' days';
- $PHPDateObject->modify($adjustDaysString);
-
- return Helpers::returnIn3FormatsObject($PHPDateObject);
- }
-}
diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Helpers.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Helpers.php
index 5b3a8067..9503401c 100644
--- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Helpers.php
+++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Helpers.php
@@ -5,7 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
use DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
-use PhpOffice\PhpSpreadsheet\Shared\Date;
+use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper;
class Helpers
{
@@ -31,7 +31,7 @@ class Helpers
public static function getDateValue($dateValue, bool $allowBool = true): float
{
if (is_object($dateValue)) {
- $retval = Date::PHPToExcel($dateValue);
+ $retval = SharedDateHelper::PHPToExcel($dateValue);
if (is_bool($retval)) {
throw new Exception(Functions::VALUE());
}
@@ -43,7 +43,7 @@ class Helpers
if (!is_numeric($dateValue)) {
$saveReturnDateType = Functions::getReturnDateType();
Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
- $dateValue = DateValue::funcDateValue($dateValue);
+ $dateValue = DateValue::fromString($dateValue);
Functions::setReturnDateType($saveReturnDateType);
if (!is_numeric($dateValue)) {
throw new Exception(Functions::VALUE());
@@ -67,16 +67,21 @@ class Helpers
{
$saveReturnDateType = Functions::getReturnDateType();
Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
- $timeValue = TimeValue::funcTimeValue($timeValue);
+ $timeValue = TimeValue::fromString($timeValue);
Functions::setReturnDateType($saveReturnDateType);
return $timeValue;
}
- public static function adjustDateByMonths($dateValue = 0, $adjustmentMonths = 0)
+ /**
+ * Adjust date by given months.
+ *
+ * @param mixed $dateValue
+ */
+ public static function adjustDateByMonths($dateValue = 0, float $adjustmentMonths = 0): DateTime
{
// Execute function
- $PHPDateObject = Date::excelToDateTimeObject($dateValue);
+ $PHPDateObject = SharedDateHelper::excelToDateTimeObject($dateValue);
$oMonth = (int) $PHPDateObject->format('m');
$oYear = (int) $PHPDateObject->format('Y');
@@ -144,7 +149,7 @@ class Helpers
);
}
$excelDateValue =
- Date::formattedPHPToExcel(
+ SharedDateHelper::formattedPHPToExcel(
$dateArray['year'],
$dateArray['month'],
$dateArray['day'],
@@ -157,7 +162,7 @@ class Helpers
}
// RETURNDATE_UNIX_TIMESTAMP)
- return (int) Date::excelToTimestamp($excelDateValue);
+ return (int) SharedDateHelper::excelToTimestamp($excelDateValue);
}
/**
@@ -172,11 +177,11 @@ class Helpers
return $excelDateValue;
}
if ($retType === Functions::RETURNDATE_UNIX_TIMESTAMP) {
- return (int) Date::excelToTimestamp($excelDateValue);
+ return (int) SharedDateHelper::excelToTimestamp($excelDateValue);
}
// RETURNDATE_PHP_DATETIME_OBJECT
- return Date::excelToDateTimeObject($excelDateValue);
+ return SharedDateHelper::excelToDateTimeObject($excelDateValue);
}
/**
@@ -191,11 +196,13 @@ class Helpers
return $PHPDateObject;
}
if ($retType === Functions::RETURNDATE_EXCEL) {
- return (float) Date::PHPToExcel($PHPDateObject);
+ return (float) SharedDateHelper::PHPToExcel($PHPDateObject);
}
// RETURNDATE_UNIX_TIMESTAMP
+ $stamp = SharedDateHelper::PHPToExcel($PHPDateObject);
+ $stamp = is_bool($stamp) ? ((int) $stamp) : $stamp;
- return (int) Date::excelToTimestamp(Date::PHPToExcel($PHPDateObject));
+ return (int) SharedDateHelper::excelToTimestamp($stamp);
}
private static function baseDate(): int
@@ -203,7 +210,7 @@ class Helpers
if (Functions::getCompatibilityMode() === Functions::COMPATIBILITY_OPENOFFICE) {
return 0;
}
- if (Date::getExcelCalendar() === Date::CALENDAR_MAC_1904) {
+ if (SharedDateHelper::getExcelCalendar() === SharedDateHelper::CALENDAR_MAC_1904) {
return 0;
}
@@ -239,9 +246,12 @@ class Helpers
if ($number === null) {
return 0;
}
- if (is_numeric($number)) {
+ if (is_int($number)) {
return $number;
}
+ if (is_numeric($number)) {
+ return (float) $number;
+ }
throw new Exception(Functions::VALUE());
}
diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Hour.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Hour.php
deleted file mode 100644
index 98d4570d..00000000
--- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Hour.php
+++ /dev/null
@@ -1,44 +0,0 @@
-getMessage();
- }
-
- // Execute function
- $timeValue = fmod($timeValue, 1);
- $timeValue = Date::excelToDateTimeObject($timeValue);
-
- return (int) $timeValue->format('H');
- }
-}
diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/IsoWeekNum.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/IsoWeekNum.php
deleted file mode 100644
index 41959d9a..00000000
--- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/IsoWeekNum.php
+++ /dev/null
@@ -1,55 +0,0 @@
-getMessage();
- }
-
- // Execute function
- $PHPDateObject = Date::excelToDateTimeObject($dateValue);
- Helpers::silly1900($PHPDateObject);
-
- return (int) $PHPDateObject->format('W');
- }
-
- private static function apparentBug($dateValue): bool
- {
- if (Date::getExcelCalendar() !== DATE::CALENDAR_MAC_1904) {
- if (is_bool($dateValue)) {
- return true;
- }
- if (is_numeric($dateValue) && !((int) $dateValue)) {
- return true;
- }
- }
-
- return false;
- }
-}
diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Minute.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Minute.php
deleted file mode 100644
index a1747ec9..00000000
--- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Minute.php
+++ /dev/null
@@ -1,44 +0,0 @@
-getMessage();
- }
-
- // Execute function
- $timeValue = fmod($timeValue, 1);
- $timeValue = Date::excelToDateTimeObject($timeValue);
-
- return (int) $timeValue->format('i');
- }
-}
diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Month.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Month.php
index a9fb8ece..560b7a80 100644
--- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Month.php
+++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Month.php
@@ -2,39 +2,81 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
-use Exception;
-use PhpOffice\PhpSpreadsheet\Shared\Date;
+use PhpOffice\PhpSpreadsheet\Calculation\Exception;
class Month
{
/**
- * MONTHOFYEAR.
+ * EDATE.
*
- * Returns the month of a date represented by a serial number.
- * The month is given as an integer, ranging from 1 (January) to 12 (December).
+ * Returns the serial number that represents the date that is the indicated number of months
+ * before or after a specified date (the start_date).
+ * Use EDATE to calculate maturity dates or due dates that fall on the same day of the month
+ * as the date of issue.
*
* Excel Function:
- * MONTH(dateValue)
+ * EDATE(dateValue,adjustmentMonths)
*
* @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer),
- * PHP DateTime object, or a standard date string
+ * PHP DateTime object, or a standard date string
+ * @param int $adjustmentMonths The number of months before or after start_date.
+ * A positive value for months yields a future date;
+ * a negative value yields a past date.
*
- * @return int|string Month of the year
+ * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
+ * depending on the value of the ReturnDateType flag
*/
- public static function funcMonth($dateValue)
+ public static function adjust($dateValue, $adjustmentMonths)
{
try {
- $dateValue = Helpers::getDateValue($dateValue);
+ $dateValue = Helpers::getDateValue($dateValue, false);
+ $adjustmentMonths = Helpers::validateNumericNull($adjustmentMonths);
} catch (Exception $e) {
return $e->getMessage();
}
- if ($dateValue < 1 && Date::getExcelCalendar() === DATE::CALENDAR_WINDOWS_1900) {
- return 1;
- }
+ $adjustmentMonths = floor($adjustmentMonths);
// Execute function
- $PHPDateObject = Date::excelToDateTimeObject($dateValue);
+ $PHPDateObject = Helpers::adjustDateByMonths($dateValue, $adjustmentMonths);
- return (int) $PHPDateObject->format('n');
+ return Helpers::returnIn3FormatsObject($PHPDateObject);
+ }
+
+ /**
+ * EOMONTH.
+ *
+ * Returns the date value for the last day of the month that is the indicated number of months
+ * before or after start_date.
+ * Use EOMONTH to calculate maturity dates or due dates that fall on the last day of the month.
+ *
+ * Excel Function:
+ * EOMONTH(dateValue,adjustmentMonths)
+ *
+ * @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer),
+ * PHP DateTime object, or a standard date string
+ * @param int $adjustmentMonths The number of months before or after start_date.
+ * A positive value for months yields a future date;
+ * a negative value yields a past date.
+ *
+ * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
+ * depending on the value of the ReturnDateType flag
+ */
+ public static function lastDay($dateValue, $adjustmentMonths)
+ {
+ try {
+ $dateValue = Helpers::getDateValue($dateValue, false);
+ $adjustmentMonths = Helpers::validateNumericNull($adjustmentMonths);
+ } catch (Exception $e) {
+ return $e->getMessage();
+ }
+ $adjustmentMonths = floor($adjustmentMonths);
+
+ // Execute function
+ $PHPDateObject = Helpers::adjustDateByMonths($dateValue, $adjustmentMonths + 1);
+ $adjustDays = (int) $PHPDateObject->format('d');
+ $adjustDaysString = '-' . $adjustDays . ' days';
+ $PHPDateObject->modify($adjustDaysString);
+
+ return Helpers::returnIn3FormatsObject($PHPDateObject);
}
}
diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/NetworkDays.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/NetworkDays.php
index c700c834..d0f53cf3 100644
--- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/NetworkDays.php
+++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/NetworkDays.php
@@ -2,9 +2,8 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
-use Exception;
+use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
-use PhpOffice\PhpSpreadsheet\Shared\Date;
class NetworkDays
{
@@ -23,10 +22,11 @@ class NetworkDays
* PHP DateTime object, or a standard date string
* @param mixed $endDate Excel date serial value (float), PHP date timestamp (integer),
* PHP DateTime object, or a standard date string
+ * @param mixed $dateArgs
*
* @return int|string Interval between the dates
*/
- public static function funcNetworkDays($startDate, $endDate, ...$dateArgs)
+ public static function count($startDate, $endDate, ...$dateArgs)
{
try {
// Retrieve the mandatory start and end date that are referenced in the function definition
@@ -55,7 +55,7 @@ class NetworkDays
$holidayCountedArray = [];
foreach ($holidayArray as $holidayDate) {
if (($holidayDate >= $startDate) && ($holidayDate <= $endDate)) {
- if ((WeekDay::funcWeekDay($holidayDate, 2) < 6) && (!in_array($holidayDate, $holidayCountedArray))) {
+ if ((Week::day($holidayDate, 2) < 6) && (!in_array($holidayDate, $holidayCountedArray))) {
--$partWeekDays;
$holidayCountedArray[] = $holidayDate;
}
@@ -67,7 +67,7 @@ class NetworkDays
private static function calcStartDow(float $startDate): int
{
- $startDow = 6 - (int) WeekDay::funcWeekDay($startDate, 2);
+ $startDow = 6 - (int) Week::day($startDate, 2);
if ($startDow < 0) {
$startDow = 5;
}
@@ -77,7 +77,7 @@ class NetworkDays
private static function calcEndDow(float $endDate): int
{
- $endDow = (int) WeekDay::funcWeekDay($endDate, 2);
+ $endDow = (int) Week::day($endDate, 2);
if ($endDow >= 6) {
$endDow = 0;
}
@@ -95,7 +95,7 @@ class NetworkDays
return $partWeekDays;
}
- private static function applySign(int $result, float $sDate, float $eDate)
+ private static function applySign(int $result, float $sDate, float $eDate): int
{
return ($sDate > $eDate) ? -$result : $result;
}
diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Second.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Second.php
deleted file mode 100644
index c4749993..00000000
--- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Second.php
+++ /dev/null
@@ -1,44 +0,0 @@
-getMessage();
- }
-
- // Execute function
- $timeValue = fmod($timeValue, 1);
- $timeValue = Date::excelToDateTimeObject($timeValue);
-
- return (int) $timeValue->format('s');
- }
-}
diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Time.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Time.php
index 450f9d50..fb5e4965 100644
--- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Time.php
+++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Time.php
@@ -5,7 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
use DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
-use PhpOffice\PhpSpreadsheet\Shared\Date;
+use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper;
class Time
{
@@ -20,14 +20,14 @@ class Time
* Excel Function:
* TIME(hour,minute,second)
*
- * @param int $hour A number from 0 (zero) to 32767 representing the hour.
+ * @param mixed $hour A number from 0 (zero) to 32767 representing the hour.
* Any value greater than 23 will be divided by 24 and the remainder
* will be treated as the hour value. For example, TIME(27,0,0) =
* TIME(3,0,0) = .125 or 3:00 AM.
- * @param int $minute A number from 0 to 32767 representing the minute.
+ * @param mixed $minute A number from 0 to 32767 representing the minute.
* Any value greater than 59 will be converted to hours and minutes.
* For example, TIME(0,750,0) = TIME(12,30,0) = .520833 or 12:30 PM.
- * @param int $second A number from 0 to 32767 representing the second.
+ * @param mixed $second A number from 0 to 32767 representing the second.
* Any value greater than 59 will be converted to hours, minutes,
* and seconds. For example, TIME(0,0,2000) = TIME(0,33,22) = .023148
* or 12:33:20 AM
@@ -35,7 +35,7 @@ class Time
* @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
* depending on the value of the ReturnDateType flag
*/
- public static function funcTime($hour, $minute, $second)
+ public static function fromHMS($hour, $minute, $second)
{
try {
$hour = self::toIntWithNullBool($hour);
@@ -57,13 +57,13 @@ class Time
// Execute function
$retType = Functions::getReturnDateType();
if ($retType === Functions::RETURNDATE_EXCEL) {
- $calendar = Date::getExcelCalendar();
- $date = (int) ($calendar !== Date::CALENDAR_WINDOWS_1900);
+ $calendar = SharedDateHelper::getExcelCalendar();
+ $date = (int) ($calendar !== SharedDateHelper::CALENDAR_WINDOWS_1900);
- return (float) Date::formattedPHPToExcel($calendar, 1, $date, $hour, $minute, $second);
+ return (float) SharedDateHelper::formattedPHPToExcel($calendar, 1, $date, $hour, $minute, $second);
}
if ($retType === Functions::RETURNDATE_UNIX_TIMESTAMP) {
- return (int) Date::excelToTimestamp(Date::formattedPHPToExcel(1970, 1, 1, $hour, $minute, $second)); // -2147468400; // -2147472000 + 3600
+ return (int) SharedDateHelper::excelToTimestamp(SharedDateHelper::formattedPHPToExcel(1970, 1, 1, $hour, $minute, $second)); // -2147468400; // -2147472000 + 3600
}
// RETURNDATE_PHP_DATETIME_OBJECT
// Hour has already been normalized (0-23) above
@@ -100,6 +100,9 @@ class Time
}
}
+ /**
+ * @param mixed $value expect int
+ */
private static function toIntWithNullBool($value): int
{
$value = Functions::flattenSingleValue($value);
diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/TimeParts.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/TimeParts.php
new file mode 100644
index 00000000..49cd983d
--- /dev/null
+++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/TimeParts.php
@@ -0,0 +1,112 @@
+getMessage();
+ }
+
+ // Execute function
+ $timeValue = fmod($timeValue, 1);
+ $timeValue = SharedDateHelper::excelToDateTimeObject($timeValue);
+
+ return (int) $timeValue->format('H');
+ }
+
+ /**
+ * MINUTE.
+ *
+ * Returns the minutes of a time value.
+ * The minute is given as an integer, ranging from 0 to 59.
+ *
+ * Excel Function:
+ * MINUTE(timeValue)
+ *
+ * @param mixed $timeValue Excel date serial value (float), PHP date timestamp (integer),
+ * PHP DateTime object, or a standard time string
+ *
+ * @return int|string Minute
+ */
+ public static function minute($timeValue)
+ {
+ try {
+ $timeValue = Functions::flattenSingleValue($timeValue);
+ Helpers::nullFalseTrueToNumber($timeValue);
+ if (!is_numeric($timeValue)) {
+ $timeValue = Helpers::getTimeValue($timeValue);
+ }
+ Helpers::validateNotNegative($timeValue);
+ } catch (Exception $e) {
+ return $e->getMessage();
+ }
+
+ // Execute function
+ $timeValue = fmod($timeValue, 1);
+ $timeValue = SharedDateHelper::excelToDateTimeObject($timeValue);
+
+ return (int) $timeValue->format('i');
+ }
+
+ /**
+ * SECOND.
+ *
+ * Returns the seconds of a time value.
+ * The minute is given as an integer, ranging from 0 to 59.
+ *
+ * Excel Function:
+ * SECOND(timeValue)
+ *
+ * @param mixed $timeValue Excel date serial value (float), PHP date timestamp (integer),
+ * PHP DateTime object, or a standard time string
+ *
+ * @return int|string Second
+ */
+ public static function second($timeValue)
+ {
+ try {
+ $timeValue = Functions::flattenSingleValue($timeValue);
+ Helpers::nullFalseTrueToNumber($timeValue);
+ if (!is_numeric($timeValue)) {
+ $timeValue = Helpers::getTimeValue($timeValue);
+ }
+ Helpers::validateNotNegative($timeValue);
+ } catch (Exception $e) {
+ return $e->getMessage();
+ }
+
+ // Execute function
+ $timeValue = fmod($timeValue, 1);
+ $timeValue = SharedDateHelper::excelToDateTimeObject($timeValue);
+
+ return (int) $timeValue->format('s');
+ }
+}
diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/TimeValue.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/TimeValue.php
index 2366b1d6..73b7ba91 100644
--- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/TimeValue.php
+++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/TimeValue.php
@@ -4,7 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
use Datetime;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
-use PhpOffice\PhpSpreadsheet\Shared\Date;
+use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper;
class TimeValue
{
@@ -29,12 +29,12 @@ class TimeValue
* @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
* depending on the value of the ReturnDateType flag
*/
- public static function funcTimeValue($timeValue)
+ public static function fromString($timeValue)
{
$timeValue = trim(Functions::flattenSingleValue($timeValue), '"');
$timeValue = str_replace(['/', '.'], '-', $timeValue);
- $arraySplit = preg_split('/[\/:\-\s]/', $timeValue);
+ $arraySplit = preg_split('/[\/:\-\s]/', $timeValue) ?: [];
if ((count($arraySplit) == 2 || count($arraySplit) == 3) && $arraySplit[0] > 24) {
$arraySplit[0] = ($arraySplit[0] % 24);
$timeValue = implode(':', $arraySplit);
@@ -44,13 +44,13 @@ class TimeValue
$retValue = Functions::VALUE();
if (($PHPDateArray !== false) && ($PHPDateArray['error_count'] == 0)) {
// OpenOffice-specific code removed - it works just like Excel
- $excelDateValue = Date::formattedPHPToExcel(1900, 1, 1, $PHPDateArray['hour'], $PHPDateArray['minute'], $PHPDateArray['second']) - 1;
+ $excelDateValue = SharedDateHelper::formattedPHPToExcel(1900, 1, 1, $PHPDateArray['hour'], $PHPDateArray['minute'], $PHPDateArray['second']) - 1;
$retType = Functions::getReturnDateType();
if ($retType === Functions::RETURNDATE_EXCEL) {
$retValue = (float) $excelDateValue;
} elseif ($retType === Functions::RETURNDATE_UNIX_TIMESTAMP) {
- $retValue = (int) $phpDateValue = Date::excelToTimestamp($excelDateValue + 25569) - 3600;
+ $retValue = (int) $phpDateValue = SharedDateHelper::excelToTimestamp($excelDateValue + 25569) - 3600;
} else {
$retValue = new DateTime('1900-01-01 ' . $PHPDateArray['hour'] . ':' . $PHPDateArray['minute'] . ':' . $PHPDateArray['second']);
}
diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Today.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Today.php
deleted file mode 100644
index 5e459410..00000000
--- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Today.php
+++ /dev/null
@@ -1,34 +0,0 @@
-format('c'));
-
- return is_array($dateArray) ? Helpers::returnIn3FormatsArray($dateArray, true) : Functions::VALUE();
- }
-}
diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Week.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Week.php
new file mode 100644
index 00000000..66362221
--- /dev/null
+++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Week.php
@@ -0,0 +1,254 @@
+getMessage();
+ }
+
+ // Execute function
+ $PHPDateObject = SharedDateHelper::excelToDateTimeObject($dateValue);
+ if ($method == Constants::STARTWEEK_MONDAY_ISO) {
+ Helpers::silly1900($PHPDateObject);
+
+ return (int) $PHPDateObject->format('W');
+ }
+ if (self::buggyWeekNum1904($method, $origDateValueNull, $PHPDateObject)) {
+ return 0;
+ }
+ Helpers::silly1900($PHPDateObject, '+ 5 years'); // 1905 calendar matches
+ $dayOfYear = (int) $PHPDateObject->format('z');
+ $PHPDateObject->modify('-' . $dayOfYear . ' days');
+ $firstDayOfFirstWeek = (int) $PHPDateObject->format('w');
+ $daysInFirstWeek = (6 - $firstDayOfFirstWeek + $method) % 7;
+ $daysInFirstWeek += 7 * !$daysInFirstWeek;
+ $endFirstWeek = $daysInFirstWeek - 1;
+ $weekOfYear = floor(($dayOfYear - $endFirstWeek + 13) / 7);
+
+ return (int) $weekOfYear;
+ }
+
+ /**
+ * ISOWEEKNUM.
+ *
+ * Returns the ISO 8601 week number of the year for a specified date.
+ *
+ * Excel Function:
+ * ISOWEEKNUM(dateValue)
+ *
+ * @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer),
+ * PHP DateTime object, or a standard date string
+ *
+ * @return int|string Week Number
+ */
+ public static function isoWeekNumber($dateValue)
+ {
+ if (self::apparentBug($dateValue)) {
+ return 52;
+ }
+
+ try {
+ $dateValue = Helpers::getDateValue($dateValue);
+ } catch (Exception $e) {
+ return $e->getMessage();
+ }
+
+ // Execute function
+ $PHPDateObject = SharedDateHelper::excelToDateTimeObject($dateValue);
+ Helpers::silly1900($PHPDateObject);
+
+ return (int) $PHPDateObject->format('W');
+ }
+
+ /**
+ * WEEKDAY.
+ *
+ * Returns the day of the week for a specified date. The day is given as an integer
+ * ranging from 0 to 7 (dependent on the requested style).
+ *
+ * Excel Function:
+ * WEEKDAY(dateValue[,style])
+ *
+ * @param null|float|int|string $dateValue Excel date serial value (float), PHP date timestamp (integer),
+ * PHP DateTime object, or a standard date string
+ * @param mixed $style A number that determines the type of return value
+ * 1 or omitted Numbers 1 (Sunday) through 7 (Saturday).
+ * 2 Numbers 1 (Monday) through 7 (Sunday).
+ * 3 Numbers 0 (Monday) through 6 (Sunday).
+ *
+ * @return int|string Day of the week value
+ */
+ public static function day($dateValue, $style = 1)
+ {
+ try {
+ $dateValue = Helpers::getDateValue($dateValue);
+ $style = self::validateStyle($style);
+ } catch (Exception $e) {
+ return $e->getMessage();
+ }
+
+ // Execute function
+ $PHPDateObject = SharedDateHelper::excelToDateTimeObject($dateValue);
+ Helpers::silly1900($PHPDateObject);
+ $DoW = (int) $PHPDateObject->format('w');
+
+ switch ($style) {
+ case 1:
+ ++$DoW;
+
+ break;
+ case 2:
+ $DoW = self::dow0Becomes7($DoW);
+
+ break;
+ case 3:
+ $DoW = self::dow0Becomes7($DoW) - 1;
+
+ break;
+ }
+
+ return $DoW;
+ }
+
+ /**
+ * @param mixed $style expect int
+ */
+ private static function validateStyle($style): int
+ {
+ $style = Functions::flattenSingleValue($style);
+
+ if (!is_numeric($style)) {
+ throw new Exception(Functions::VALUE());
+ }
+ $style = (int) $style;
+ if (($style < 1) || ($style > 3)) {
+ throw new Exception(Functions::NAN());
+ }
+
+ return $style;
+ }
+
+ private static function dow0Becomes7(int $DoW): int
+ {
+ return ($DoW === 0) ? 7 : $DoW;
+ }
+
+ /**
+ * @param mixed $dateValue Excel date serial value (float), PHP date timestamp (integer),
+ * PHP DateTime object, or a standard date string
+ */
+ private static function apparentBug($dateValue): bool
+ {
+ if (SharedDateHelper::getExcelCalendar() !== SharedDateHelper::CALENDAR_MAC_1904) {
+ if (is_bool($dateValue)) {
+ return true;
+ }
+ if (is_numeric($dateValue) && !((int) $dateValue)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Validate dateValue parameter.
+ *
+ * @param mixed $dateValue
+ */
+ private static function validateDateValue($dateValue): float
+ {
+ if (is_bool($dateValue)) {
+ throw new Exception(Functions::VALUE());
+ }
+
+ return Helpers::getDateValue($dateValue);
+ }
+
+ /**
+ * Validate method parameter.
+ *
+ * @param mixed $method
+ */
+ private static function validateMethod($method): int
+ {
+ if ($method === null) {
+ $method = Constants::STARTWEEK_SUNDAY;
+ }
+ $method = Functions::flattenSingleValue($method);
+ if (!is_numeric($method)) {
+ throw new Exception(Functions::VALUE());
+ }
+
+ $method = (int) $method;
+ if (!array_key_exists($method, Constants::METHODARR)) {
+ throw new Exception(Functions::NAN());
+ }
+ $method = Constants::METHODARR[$method];
+
+ return $method;
+ }
+
+ private static function buggyWeekNum1900(int $method): bool
+ {
+ return $method === Constants::DOW_SUNDAY && SharedDateHelper::getExcelCalendar() === SharedDateHelper::CALENDAR_WINDOWS_1900;
+ }
+
+ private static function buggyWeekNum1904(int $method, bool $origNull, DateTime $dateObject): bool
+ {
+ // This appears to be another Excel bug.
+
+ return $method === Constants::DOW_SUNDAY && SharedDateHelper::getExcelCalendar() === SharedDateHelper::CALENDAR_MAC_1904 &&
+ !$origNull && $dateObject->format('Y-m-d') === '1904-01-01';
+ }
+}
diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/WeekDay.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/WeekDay.php
deleted file mode 100644
index ea4fe340..00000000
--- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/WeekDay.php
+++ /dev/null
@@ -1,80 +0,0 @@
-getMessage();
- }
-
- // Execute function
- $PHPDateObject = Date::excelToDateTimeObject($dateValue);
- Helpers::silly1900($PHPDateObject);
- $DoW = (int) $PHPDateObject->format('w');
-
- switch ($style) {
- case 1:
- ++$DoW;
-
- break;
- case 2:
- $DoW = self::dow0Becomes7($DoW);
-
- break;
- case 3:
- $DoW = self::dow0Becomes7($DoW) - 1;
-
- break;
- }
-
- return $DoW;
- }
-
- private static function validateStyle($style): int
- {
- $style = Functions::flattenSingleValue($style);
-
- if (!is_numeric($style)) {
- throw new Exception(Functions::VALUE());
- }
- $style = (int) $style;
- if (($style < 1) || ($style > 3)) {
- throw new Exception(Functions::NAN());
- }
-
- return $style;
- }
-
- private static function dow0Becomes7(int $DoW): int
- {
- return ($DoW === 0) ? 7 : $DoW;
- }
-}
diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/WeekNum.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/WeekNum.php
deleted file mode 100644
index 9b2de4d0..00000000
--- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/WeekNum.php
+++ /dev/null
@@ -1,130 +0,0 @@
-getMessage();
- }
-
- // Execute function
- $PHPDateObject = Date::excelToDateTimeObject($dateValue);
- if ($method == Constants::STARTWEEK_MONDAY_ISO) {
- Helpers::silly1900($PHPDateObject);
-
- return (int) $PHPDateObject->format('W');
- }
- if (self::buggyWeekNum1904($method, $origDateValueNull, $PHPDateObject)) {
- return 0;
- }
- Helpers::silly1900($PHPDateObject, '+ 5 years'); // 1905 calendar matches
- $dayOfYear = (int) $PHPDateObject->format('z');
- $PHPDateObject->modify('-' . $dayOfYear . ' days');
- $firstDayOfFirstWeek = (int) $PHPDateObject->format('w');
- $daysInFirstWeek = (6 - $firstDayOfFirstWeek + $method) % 7;
- $daysInFirstWeek += 7 * !$daysInFirstWeek;
- $endFirstWeek = $daysInFirstWeek - 1;
- $weekOfYear = floor(($dayOfYear - $endFirstWeek + 13) / 7);
-
- return (int) $weekOfYear;
- }
-
- /**
- * Validate dateValue parameter.
- *
- * @param mixed $dateValue
- */
- private static function validateDateValue($dateValue): float
- {
- if (is_bool($dateValue)) {
- throw new Exception(Functions::VALUE());
- }
-
- return Helpers::getDateValue($dateValue);
- }
-
- /**
- * Validate method parameter.
- *
- * @param mixed $method
- */
- private static function validateMethod($method): int
- {
- if ($method === null) {
- $method = Constants::STARTWEEK_SUNDAY;
- }
- $method = Functions::flattenSingleValue($method);
- if (!is_numeric($method)) {
- throw new Exception(Functions::VALUE());
- }
-
- $method = (int) $method;
- if (!array_key_exists($method, Constants::METHODARR)) {
- throw new Exception(Functions::NAN());
- }
- $method = Constants::METHODARR[$method];
-
- return $method;
- }
-
- private static function buggyWeekNum1900(int $method): bool
- {
- return $method === Constants::DOW_SUNDAY && Date::getExcelCalendar() === Date::CALENDAR_WINDOWS_1900;
- }
-
- private static function buggyWeekNum1904(int $method, bool $origNull, DateTime $dateObject): bool
- {
- // This appears to be another Excel bug.
-
- return $method === Constants::DOW_SUNDAY && Date::getExcelCalendar() === Date::CALENDAR_MAC_1904 && !$origNull && $dateObject->format('Y-m-d') === '1904-01-01';
- }
-}
diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/WorkDay.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/WorkDay.php
index 09816d33..89e47b96 100644
--- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/WorkDay.php
+++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/WorkDay.php
@@ -2,9 +2,8 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
-use Exception;
+use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
-use PhpOffice\PhpSpreadsheet\Shared\Date;
class WorkDay
{
@@ -24,11 +23,12 @@ class WorkDay
* @param int $endDays The number of nonweekend and nonholiday days before or after
* startDate. A positive value for days yields a future date; a
* negative value yields a past date.
+ * @param mixed $dateArgs
*
* @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
* depending on the value of the ReturnDateType flag
*/
- public static function funcWorkDay($startDate, $endDays, ...$dateArgs)
+ public static function date($startDate, $endDays, ...$dateArgs)
{
// Retrieve the mandatory start date and days that are referenced in the function definition
try {
@@ -65,8 +65,8 @@ class WorkDay
{
// Adjust the start date if it falls over a weekend
- $startDoW = WeekDay::funcWeekDay($startDate, 3);
- if (WeekDay::funcWeekDay($startDate, 3) >= 5) {
+ $startDoW = self::getWeekDay($startDate, 3);
+ if (self::getWeekDay($startDate, 3) >= 5) {
$startDate += 7 - $startDoW;
--$endDays;
}
@@ -77,7 +77,7 @@ class WorkDay
while ($endDays > 0) {
++$endDate;
// Adjust the calculated end date if it falls over a weekend
- $endDow = WeekDay::funcWeekDay($endDate, 3);
+ $endDow = self::getWeekDay($endDate, 3);
if ($endDow >= 5) {
$endDate += 7 - $endDow;
}
@@ -96,7 +96,7 @@ class WorkDay
{
$holidayCountedArray = $holidayDates = [];
foreach ($holidayArray as $holidayDate) {
- if (WeekDay::funcWeekDay($holidayDate, 3) < 5) {
+ if (self::getWeekDay($holidayDate, 3) < 5) {
$holidayDates[] = $holidayDate;
}
}
@@ -109,7 +109,7 @@ class WorkDay
}
}
// Adjust the calculated end date if it falls over a weekend
- $endDoW = WeekDay::funcWeekDay($endDate, 3);
+ $endDoW = self::getWeekDay($endDate, 3);
if ($endDoW >= 5) {
$endDate += 7 - $endDoW;
}
@@ -127,9 +127,8 @@ class WorkDay
{
// Adjust the start date if it falls over a weekend
- $startDoW = WeekDay::funcWeekDay($startDate, 3);
- if (WeekDay::funcWeekDay($startDate, 3) >= 5) {
- // @phpstan-ignore-next-line
+ $startDoW = self::getWeekDay($startDate, 3);
+ if (self::getWeekDay($startDate, 3) >= 5) {
$startDate += -$startDoW + 4;
++$endDays;
}
@@ -140,7 +139,7 @@ class WorkDay
while ($endDays < 0) {
--$endDate;
// Adjust the calculated end date if it falls over a weekend
- $endDow = WeekDay::funcWeekDay($endDate, 3);
+ $endDow = self::getWeekDay($endDate, 3);
if ($endDow >= 5) {
$endDate += 4 - $endDow;
}
@@ -159,7 +158,7 @@ class WorkDay
{
$holidayCountedArray = $holidayDates = [];
foreach ($holidayArray as $holidayDate) {
- if (WeekDay::funcWeekDay($holidayDate, 3) < 5) {
+ if (self::getWeekDay($holidayDate, 3) < 5) {
$holidayDates[] = $holidayDate;
}
}
@@ -172,13 +171,19 @@ class WorkDay
}
}
// Adjust the calculated end date if it falls over a weekend
- $endDoW = WeekDay::funcWeekDay($endDate, 3);
+ $endDoW = self::getWeekDay($endDate, 3);
if ($endDoW >= 5) {
- // @phpstan-ignore-next-line
$endDate += -$endDoW + 4;
}
}
return $endDate;
}
+
+ private static function getWeekDay(float $date, int $wd): int
+ {
+ $result = Week::day($date, $wd);
+
+ return is_string($result) ? -1 : $result;
+ }
}
diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Year.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/Year.php
deleted file mode 100644
index 5fcac739..00000000
--- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/Year.php
+++ /dev/null
@@ -1,40 +0,0 @@
-getMessage();
- }
-
- if ($dateValue < 1 && Date::getExcelCalendar() === DATE::CALENDAR_WINDOWS_1900) {
- return 1900;
- }
- // Execute function
- $PHPDateObject = Date::excelToDateTimeObject($dateValue);
-
- return (int) $PHPDateObject->format('Y');
- }
-}
diff --git a/src/PhpSpreadsheet/Calculation/DateTimeExcel/YearFrac.php b/src/PhpSpreadsheet/Calculation/DateTimeExcel/YearFrac.php
index a99b1c7f..da2ac12f 100644
--- a/src/PhpSpreadsheet/Calculation/DateTimeExcel/YearFrac.php
+++ b/src/PhpSpreadsheet/Calculation/DateTimeExcel/YearFrac.php
@@ -2,9 +2,9 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
-use Exception;
+use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
-use PhpOffice\PhpSpreadsheet\Shared\Date;
+use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDateHelper;
class YearFrac
{
@@ -34,7 +34,7 @@ class YearFrac
*
* @return float|string fraction of the year, or a string containing an error
*/
- public static function funcYearFrac($startDate, $endDate, $method = 0)
+ public static function fraction($startDate, $endDate, $method = 0)
{
try {
$method = (int) Helpers::validateNumericNull($method);
@@ -50,15 +50,15 @@ class YearFrac
switch ($method) {
case 0:
- return Days360::funcDays360($startDate, $endDate) / 360;
+ return Days360::between($startDate, $endDate) / 360;
case 1:
return self::method1($startDate, $endDate);
case 2:
- return DateDif::funcDateDif($startDate, $endDate) / 360;
+ return Difference::interval($startDate, $endDate) / 360;
case 3:
- return DateDif::funcDateDif($startDate, $endDate) / 365;
+ return Difference::interval($startDate, $endDate) / 365;
case 4:
- return Days360::funcDays360($startDate, $endDate, true) / 360;
+ return Days360::between($startDate, $endDate, true) / 360;
}
return Functions::NAN();
@@ -72,9 +72,9 @@ class YearFrac
*/
private static function excelBug(float $sDate, $startDate, $endDate, int $method): float
{
- if (Functions::getCompatibilityMode() !== Functions::COMPATIBILITY_OPENOFFICE && Date::getExcelCalendar() !== Date::CALENDAR_MAC_1904) {
+ if (Functions::getCompatibilityMode() !== Functions::COMPATIBILITY_OPENOFFICE && SharedDateHelper::getExcelCalendar() !== SharedDateHelper::CALENDAR_MAC_1904) {
if ($endDate === null && $startDate !== null) {
- if (Month::funcMonth($sDate) == 12 && Day::funcDay($sDate) === 31 && $method === 0) {
+ if (DateParts::month($sDate) == 12 && DateParts::day($sDate) === 31 && $method === 0) {
$sDate += 2;
} else {
++$sDate;
@@ -87,14 +87,14 @@ class YearFrac
private static function method1(float $startDate, float $endDate): float
{
- $days = DateDif::funcDateDif($startDate, $endDate);
- $startYear = Year::funcYear($startDate);
- $endYear = Year::funcYear($endDate);
+ $days = Difference::interval($startDate, $endDate);
+ $startYear = (int) DateParts::year($startDate);
+ $endYear = (int) DateParts::year($endDate);
$years = $endYear - $startYear + 1;
- $startMonth = Month::funcMonth($startDate);
- $startDay = Day::funcDay($startDate);
- $endMonth = Month::funcMonth($endDate);
- $endDay = Day::funcDay($endDate);
+ $startMonth = (int) DateParts::month($startDate);
+ $startDay = (int) DateParts::day($startDate);
+ $endMonth = (int) DateParts::month($endDate);
+ $endDay = (int) DateParts::day($endDate);
$startMonthDay = 100 * $startMonth + $startDay;
$endMonthDay = 100 * $endMonth + $endDay;
if ($years == 1) {
diff --git a/src/PhpSpreadsheet/Calculation/Financial/Amortization.php b/src/PhpSpreadsheet/Calculation/Financial/Amortization.php
index 2ea0f4fe..ba7fb521 100644
--- a/src/PhpSpreadsheet/Calculation/Financial/Amortization.php
+++ b/src/PhpSpreadsheet/Calculation/Financial/Amortization.php
@@ -70,7 +70,7 @@ class Amortization
return $e->getMessage();
}
- $yearFrac = DateTimeExcel\YearFrac::funcYearFrac($purchased, $firstPeriod, $basis);
+ $yearFrac = DateTimeExcel\YearFrac::fraction($purchased, $firstPeriod, $basis);
if (is_string($yearFrac)) {
return $yearFrac;
}
@@ -160,8 +160,8 @@ class Amortization
$fOneRate = $cost * $rate;
$fCostDelta = $cost - $salvage;
// Note, quirky variation for leap years on the YEARFRAC for this function
- $purchasedYear = DateTimeExcel\Year::funcYear($purchased);
- $yearFrac = DateTimeExcel\YearFrac::funcYearFrac($purchased, $firstPeriod, $basis);
+ $purchasedYear = DateTimeExcel\DateParts::year($purchased);
+ $yearFrac = DateTimeExcel\YearFrac::fraction($purchased, $firstPeriod, $basis);
if (is_string($yearFrac)) {
return $yearFrac;
}
diff --git a/src/PhpSpreadsheet/Calculation/Financial/CashFlow/Variable/NonPeriodic.php b/src/PhpSpreadsheet/Calculation/Financial/CashFlow/Variable/NonPeriodic.php
index 40df776f..6a32bdfc 100644
--- a/src/PhpSpreadsheet/Calculation/Financial/CashFlow/Variable/NonPeriodic.php
+++ b/src/PhpSpreadsheet/Calculation/Financial/CashFlow/Variable/NonPeriodic.php
@@ -196,10 +196,9 @@ class NonPeriodic
return $e->getMessage();
}
if ($date0 > $datei) {
- /** @phpstan-ignore-next-line */
- $dif = $ordered ? Functions::NAN() : -DateTimeExcel\DateDif::funcDateDif($datei, $date0, 'd');
+ $dif = $ordered ? Functions::NAN() : -((int) DateTimeExcel\Difference::interval($datei, $date0, 'd'));
} else {
- $dif = DateTimeExcel\DateDif::funcDateDif($date0, $datei, 'd');
+ $dif = DateTimeExcel\Difference::interval($date0, $datei, 'd');
}
if (!is_numeric($dif)) {
return $dif;
diff --git a/src/PhpSpreadsheet/Calculation/Financial/Coupons.php b/src/PhpSpreadsheet/Calculation/Financial/Coupons.php
index b95625cf..5620c327 100644
--- a/src/PhpSpreadsheet/Calculation/Financial/Coupons.php
+++ b/src/PhpSpreadsheet/Calculation/Financial/Coupons.php
@@ -63,17 +63,17 @@ class Coupons
return $e->getMessage();
}
- $daysPerYear = Helpers::daysPerYear(DateTimeExcel\Year::funcYear($settlement), $basis);
+ $daysPerYear = Helpers::daysPerYear(DateTimeExcel\DateParts::year($settlement), $basis);
if (is_string($daysPerYear)) {
return Functions::VALUE();
}
$prev = self::couponFirstPeriodDate($settlement, $maturity, $frequency, self::PERIOD_DATE_PREVIOUS);
if ($basis === FinancialConstants::BASIS_DAYS_PER_YEAR_ACTUAL) {
- return abs(DateTimeExcel\Days::funcDays($prev, $settlement));
+ return abs((float) DateTimeExcel\Days::between($prev, $settlement));
}
- return DateTimeExcel\YearFrac::funcYearFrac($prev, $settlement, $basis) * $daysPerYear;
+ return DateTimeExcel\YearFrac::fraction($prev, $settlement, $basis) * $daysPerYear;
}
/**
@@ -133,7 +133,7 @@ class Coupons
case FinancialConstants::BASIS_DAYS_PER_YEAR_ACTUAL:
// Actual/actual
if ($frequency == FinancialConstants::FREQUENCY_ANNUAL) {
- $daysPerYear = Helpers::daysPerYear(DateTimeExcel\Year::funcYear($settlement), $basis);
+ $daysPerYear = Helpers::daysPerYear(DateTimeExcel\DateParts::year($settlement), $basis);
return $daysPerYear / $frequency;
}
@@ -197,7 +197,7 @@ class Coupons
return $e->getMessage();
}
- $daysPerYear = Helpers::daysPerYear(DateTimeExcel\Year::funcYear($settlement), $basis);
+ $daysPerYear = Helpers::daysPerYear(DateTimeExcel\DateParts::year($settlement), $basis);
$next = self::couponFirstPeriodDate($settlement, $maturity, $frequency, self::PERIOD_DATE_NEXT);
if ($basis === FinancialConstants::BASIS_DAYS_PER_YEAR_NASD) {
@@ -208,7 +208,7 @@ class Coupons
}
}
- return DateTimeExcel\YearFrac::funcYearFrac($settlement, $next, $basis) * $daysPerYear;
+ return DateTimeExcel\YearFrac::fraction($settlement, $next, $basis) * $daysPerYear;
}
/**
@@ -316,7 +316,7 @@ class Coupons
return $e->getMessage();
}
- $yearsBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::funcYearFrac(
+ $yearsBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::fraction(
$settlement,
$maturity,
FinancialConstants::BASIS_DAYS_PER_YEAR_NASD
diff --git a/src/PhpSpreadsheet/Calculation/Financial/Securities/AccruedInterest.php b/src/PhpSpreadsheet/Calculation/Financial/Securities/AccruedInterest.php
index 004b47f3..e167429b 100644
--- a/src/PhpSpreadsheet/Calculation/Financial/Securities/AccruedInterest.php
+++ b/src/PhpSpreadsheet/Calculation/Financial/Securities/AccruedInterest.php
@@ -78,12 +78,12 @@ class AccruedInterest
return $e->getMessage();
}
- $daysBetweenIssueAndSettlement = YearFrac::funcYearFrac($issue, $settlement, $basis);
+ $daysBetweenIssueAndSettlement = YearFrac::fraction($issue, $settlement, $basis);
if (!is_numeric($daysBetweenIssueAndSettlement)) {
// return date error
return $daysBetweenIssueAndSettlement;
}
- $daysBetweenFirstInterestAndSettlement = YearFrac::funcYearFrac($firstInterest, $settlement, $basis);
+ $daysBetweenFirstInterestAndSettlement = YearFrac::fraction($firstInterest, $settlement, $basis);
if (!is_numeric($daysBetweenFirstInterestAndSettlement)) {
// return date error
return $daysBetweenFirstInterestAndSettlement;
@@ -140,7 +140,7 @@ class AccruedInterest
return $e->getMessage();
}
- $daysBetweenIssueAndSettlement = YearFrac::funcYearFrac($issue, $settlement, $basis);
+ $daysBetweenIssueAndSettlement = YearFrac::fraction($issue, $settlement, $basis);
if (!is_numeric($daysBetweenIssueAndSettlement)) {
// return date error
return $daysBetweenIssueAndSettlement;
diff --git a/src/PhpSpreadsheet/Calculation/Financial/Securities/Price.php b/src/PhpSpreadsheet/Calculation/Financial/Securities/Price.php
index 158347e7..7d8d5a32 100644
--- a/src/PhpSpreadsheet/Calculation/Financial/Securities/Price.php
+++ b/src/PhpSpreadsheet/Calculation/Financial/Securities/Price.php
@@ -134,7 +134,7 @@ class Price
return $e->getMessage();
}
- $daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::funcYearFrac($settlement, $maturity, $basis);
+ $daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::fraction($settlement, $maturity, $basis);
if (!is_numeric($daysBetweenSettlementAndMaturity)) {
// return date error
return $daysBetweenSettlementAndMaturity;
@@ -194,23 +194,23 @@ class Price
return $e->getMessage();
}
- $daysPerYear = Helpers::daysPerYear(DateTimeExcel\Year::funcYear($settlement), $basis);
+ $daysPerYear = Helpers::daysPerYear(DateTimeExcel\DateParts::year($settlement), $basis);
if (!is_numeric($daysPerYear)) {
return $daysPerYear;
}
- $daysBetweenIssueAndSettlement = DateTimeExcel\YearFrac::funcYearFrac($issue, $settlement, $basis);
+ $daysBetweenIssueAndSettlement = DateTimeExcel\YearFrac::fraction($issue, $settlement, $basis);
if (!is_numeric($daysBetweenIssueAndSettlement)) {
// return date error
return $daysBetweenIssueAndSettlement;
}
$daysBetweenIssueAndSettlement *= $daysPerYear;
- $daysBetweenIssueAndMaturity = DateTimeExcel\YearFrac::funcYearFrac($issue, $maturity, $basis);
+ $daysBetweenIssueAndMaturity = DateTimeExcel\YearFrac::fraction($issue, $maturity, $basis);
if (!is_numeric($daysBetweenIssueAndMaturity)) {
// return date error
return $daysBetweenIssueAndMaturity;
}
$daysBetweenIssueAndMaturity *= $daysPerYear;
- $daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::funcYearFrac($settlement, $maturity, $basis);
+ $daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::fraction($settlement, $maturity, $basis);
if (!is_numeric($daysBetweenSettlementAndMaturity)) {
// return date error
return $daysBetweenSettlementAndMaturity;
@@ -272,7 +272,7 @@ class Price
if ($investment <= 0) {
return Functions::NAN();
}
- $daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::funcYearFrac($settlement, $maturity, $basis);
+ $daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::fraction($settlement, $maturity, $basis);
if (!is_numeric($daysBetweenSettlementAndMaturity)) {
// return date error
return $daysBetweenSettlementAndMaturity;
diff --git a/src/PhpSpreadsheet/Calculation/Financial/Securities/Rates.php b/src/PhpSpreadsheet/Calculation/Financial/Securities/Rates.php
index 5a32d1d1..c5c5211b 100644
--- a/src/PhpSpreadsheet/Calculation/Financial/Securities/Rates.php
+++ b/src/PhpSpreadsheet/Calculation/Financial/Securities/Rates.php
@@ -63,7 +63,7 @@ class Rates
return Functions::NAN();
}
- $daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::funcYearFrac($settlement, $maturity, $basis);
+ $daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::fraction($settlement, $maturity, $basis);
if (!is_numeric($daysBetweenSettlementAndMaturity)) {
// return date error
return $daysBetweenSettlementAndMaturity;
@@ -126,7 +126,7 @@ class Rates
return Functions::NAN();
}
- $daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::funcYearFrac($settlement, $maturity, $basis);
+ $daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::fraction($settlement, $maturity, $basis);
if (!is_numeric($daysBetweenSettlementAndMaturity)) {
// return date error
return $daysBetweenSettlementAndMaturity;
diff --git a/src/PhpSpreadsheet/Calculation/Financial/Securities/Yields.php b/src/PhpSpreadsheet/Calculation/Financial/Securities/Yields.php
index bdd638fa..aa626935 100644
--- a/src/PhpSpreadsheet/Calculation/Financial/Securities/Yields.php
+++ b/src/PhpSpreadsheet/Calculation/Financial/Securities/Yields.php
@@ -57,11 +57,11 @@ class Yields
return $e->getMessage();
}
- $daysPerYear = Helpers::daysPerYear(DateTimeExcel\Year::funcYear($settlement), $basis);
+ $daysPerYear = Helpers::daysPerYear(DateTimeExcel\DateParts::year($settlement), $basis);
if (!is_numeric($daysPerYear)) {
return $daysPerYear;
}
- $daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::funcYearFrac($settlement, $maturity, $basis);
+ $daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::fraction($settlement, $maturity, $basis);
if (!is_numeric($daysBetweenSettlementAndMaturity)) {
// return date error
return $daysBetweenSettlementAndMaturity;
@@ -122,23 +122,23 @@ class Yields
return $e->getMessage();
}
- $daysPerYear = Helpers::daysPerYear(DateTimeExcel\Year::funcYear($settlement), $basis);
+ $daysPerYear = Helpers::daysPerYear(DateTimeExcel\DateParts::year($settlement), $basis);
if (!is_numeric($daysPerYear)) {
return $daysPerYear;
}
- $daysBetweenIssueAndSettlement = DateTimeExcel\YearFrac::funcYearFrac($issue, $settlement, $basis);
+ $daysBetweenIssueAndSettlement = DateTimeExcel\YearFrac::fraction($issue, $settlement, $basis);
if (!is_numeric($daysBetweenIssueAndSettlement)) {
// return date error
return $daysBetweenIssueAndSettlement;
}
$daysBetweenIssueAndSettlement *= $daysPerYear;
- $daysBetweenIssueAndMaturity = DateTimeExcel\YearFrac::funcYearFrac($issue, $maturity, $basis);
+ $daysBetweenIssueAndMaturity = DateTimeExcel\YearFrac::fraction($issue, $maturity, $basis);
if (!is_numeric($daysBetweenIssueAndMaturity)) {
// return date error
return $daysBetweenIssueAndMaturity;
}
$daysBetweenIssueAndMaturity *= $daysPerYear;
- $daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::funcYearFrac($settlement, $maturity, $basis);
+ $daysBetweenSettlementAndMaturity = DateTimeExcel\YearFrac::fraction($settlement, $maturity, $basis);
if (!is_numeric($daysBetweenSettlementAndMaturity)) {
// return date error
return $daysBetweenSettlementAndMaturity;
diff --git a/src/PhpSpreadsheet/Calculation/Financial/TreasuryBill.php b/src/PhpSpreadsheet/Calculation/Financial/TreasuryBill.php
index 31146c31..c60af0b0 100644
--- a/src/PhpSpreadsheet/Calculation/Financial/TreasuryBill.php
+++ b/src/PhpSpreadsheet/Calculation/Financial/TreasuryBill.php
@@ -43,7 +43,7 @@ class TreasuryBill
$daysBetweenSettlementAndMaturity = $maturity - $settlement;
$daysPerYear = Helpers::daysPerYear(
- DateTimeExcel\Year::funcYear($maturity),
+ DateTimeExcel\DateParts::year($maturity),
FinancialConstants::BASIS_DAYS_PER_YEAR_ACTUAL
);
@@ -88,7 +88,7 @@ class TreasuryBill
$daysBetweenSettlementAndMaturity = $maturity - $settlement;
$daysPerYear = Helpers::daysPerYear(
- DateTimeExcel\Year::funcYear($maturity),
+ DateTimeExcel\DateParts::year($maturity),
FinancialConstants::BASIS_DAYS_PER_YEAR_ACTUAL
);
@@ -134,7 +134,7 @@ class TreasuryBill
$daysBetweenSettlementAndMaturity = $maturity - $settlement;
$daysPerYear = Helpers::daysPerYear(
- DateTimeExcel\Year::funcYear($maturity),
+ DateTimeExcel\DateParts::year($maturity),
FinancialConstants::BASIS_DAYS_PER_YEAR_ACTUAL
);
diff --git a/src/PhpSpreadsheet/Calculation/LookupRef.php b/src/PhpSpreadsheet/Calculation/LookupRef.php
index 5adf4f09..c213396d 100644
--- a/src/PhpSpreadsheet/Calculation/LookupRef.php
+++ b/src/PhpSpreadsheet/Calculation/LookupRef.php
@@ -13,6 +13,9 @@ use PhpOffice\PhpSpreadsheet\Calculation\LookupRef\VLookup;
use PhpOffice\PhpSpreadsheet\Cell\Cell;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
+/**
+ * @deprecated 1.18.0
+ */
class LookupRef
{
/**
@@ -25,7 +28,8 @@ class LookupRef
*
* @Deprecated 1.18.0
*
- * @see Use the cell() method in the LookupRef\Address class instead
+ * @see LookupRef\Address::cell()
+ * Use the cell() method in the LookupRef\Address class instead
*
* @param mixed $row Row number to use in the cell reference
* @param mixed $column Column number to use in the cell reference
@@ -61,11 +65,12 @@ class LookupRef
*
* @Deprecated 1.18.0
*
- * @see Use the COLUMN() method in the LookupRef\RowColumnInformation class instead
+ * @see LookupRef\RowColumnInformation::COLUMN()
+ * Use the COLUMN() method in the LookupRef\RowColumnInformation class instead
*
* @param null|array|string $cellAddress A reference to a range of cells for which you want the column numbers
*
- * @return int|int[]
+ * @return int|int[]|string
*/
public static function COLUMN($cellAddress = null, ?Cell $cell = null)
{
@@ -82,7 +87,8 @@ class LookupRef
*
* @Deprecated 1.18.0
*
- * @see Use the COLUMNS() method in the LookupRef\RowColumnInformation class instead
+ * @see LookupRef\RowColumnInformation::COLUMNS()
+ * Use the COLUMNS() method in the LookupRef\RowColumnInformation class instead
*
* @param null|array|string $cellAddress An array or array formula, or a reference to a range of cells
* for which you want the number of columns
@@ -109,7 +115,8 @@ class LookupRef
*
* @Deprecated 1.18.0
*
- * @see Use the ROW() method in the LookupRef\RowColumnInformation class instead
+ * @see LookupRef\RowColumnInformation::ROW()
+ * Use the ROW() method in the LookupRef\RowColumnInformation class instead
*
* @param null|array|string $cellAddress A reference to a range of cells for which you want the row numbers
*
@@ -130,7 +137,8 @@ class LookupRef
*
* @Deprecated 1.18.0
*
- * @see Use the ROWS() method in the LookupRef\RowColumnInformation class instead
+ * @see LookupRef\RowColumnInformation::ROWS()
+ * Use the ROWS() method in the LookupRef\RowColumnInformation class instead
*
* @param null|array|string $cellAddress An array or array formula, or a reference to a range of cells
* for which you want the number of rows
@@ -148,29 +156,20 @@ class LookupRef
* Excel Function:
* =HYPERLINK(linkURL,displayName)
*
+ * @Deprecated 1.18.0
+ *
+ * @see LookupRef\Hyperlink::set()
+ * Use the set() method in the LookupRef\Hyperlink class instead
+ *
* @param mixed $linkURL Expect string. Value to check, is also the value returned when no error
* @param mixed $displayName Expect string. Value to return when testValue is an error condition
* @param Cell $pCell The cell to set the hyperlink in
*
- * @return mixed The value of $displayName (or $linkURL if $displayName was blank)
+ * @return string The value of $displayName (or $linkURL if $displayName was blank)
*/
public static function HYPERLINK($linkURL = '', $displayName = null, ?Cell $pCell = null)
{
- $linkURL = ($linkURL === null) ? '' : Functions::flattenSingleValue($linkURL);
- $displayName = ($displayName === null) ? '' : Functions::flattenSingleValue($displayName);
-
- if ((!is_object($pCell)) || (trim($linkURL) == '')) {
- return Functions::REF();
- }
-
- if ((is_object($displayName)) || trim($displayName) == '') {
- $displayName = $linkURL;
- }
-
- $pCell->getHyperlink()->setUrl($linkURL);
- $pCell->getHyperlink()->setTooltip($displayName);
-
- return $displayName;
+ return LookupRef\Hyperlink::set($linkURL, $displayName, $pCell);
}
/**
@@ -184,7 +183,8 @@ class LookupRef
*
* @Deprecated 1.18.0
*
- * @see Use the INDIRECT() method in the LookupRef\Indirect class instead
+ * @see LookupRef\Indirect::INDIRECT()
+ * Use the INDIRECT() method in the LookupRef\Indirect class instead
*
* NOTE - INDIRECT() does not yet support the optional a1 parameter introduced in Excel 2010
*
@@ -192,8 +192,6 @@ class LookupRef
* @param Cell $pCell The current cell (containing this formula)
*
* @return array|string An array containing a cell or range of cells, or a string on error
- *
- * @TODO Support for the optional a1 parameter introduced in Excel 2010
*/
public static function INDIRECT($cellAddress, Cell $pCell)
{
@@ -212,7 +210,8 @@ class LookupRef
*
* @Deprecated 1.18.0
*
- * @see Use the OFFSET() method in the LookupRef\Offset class instead
+ * @see LookupRef\Offset::OFFSET()
+ * Use the OFFSET() method in the LookupRef\Offset class instead
*
* @param null|string $cellAddress The reference from which you want to base the offset.
* Reference must refer to a cell or range of adjacent cells;
@@ -248,31 +247,16 @@ class LookupRef
* Excel Function:
* =CHOOSE(index_num, value1, [value2], ...)
*
+ * @Deprecated 1.18.0
+ *
+ * @see LookupRef\Selection::choose()
+ * Use the choose() method in the LookupRef\Selection class instead
+ *
* @return mixed The selected value
*/
public static function CHOOSE(...$chooseArgs)
{
- $chosenEntry = Functions::flattenArray(array_shift($chooseArgs));
- $entryCount = count($chooseArgs) - 1;
-
- if (is_array($chosenEntry)) {
- $chosenEntry = array_shift($chosenEntry);
- }
- if ((is_numeric($chosenEntry)) && (!is_bool($chosenEntry))) {
- --$chosenEntry;
- } else {
- return Functions::VALUE();
- }
- $chosenEntry = floor($chosenEntry);
- if (($chosenEntry < 0) || ($chosenEntry > $entryCount)) {
- return Functions::VALUE();
- }
-
- if (is_array($chooseArgs[$chosenEntry])) {
- return Functions::flattenArray($chooseArgs[$chosenEntry]);
- }
-
- return $chooseArgs[$chosenEntry];
+ return LookupRef\Selection::choose(...$chooseArgs);
}
/**
@@ -285,7 +269,8 @@ class LookupRef
*
* @Deprecated 1.18.0
*
- * @see Use the MATCH() method in the LookupRef\ExcelMatch class instead
+ * @see LookupRef\ExcelMatch::MATCH()
+ * Use the MATCH() method in the LookupRef\ExcelMatch class instead
*
* @param mixed $lookupValue The value that you want to match in lookup_array
* @param mixed $lookupArray The range of cells being searched
@@ -309,7 +294,8 @@ class LookupRef
*
* @Deprecated 1.18.0
*
- * @see Use the index() method in the LookupRef\Matrix class instead
+ * @see LookupRef\Matrix::index()
+ * Use the index() method in the LookupRef\Matrix class instead
*
* @param mixed $rowNum The row in the array or range from which to return a value.
* If row_num is omitted, column_num is required.
@@ -329,7 +315,8 @@ class LookupRef
*
* @Deprecated 1.18.0
*
- * @see Use the transpose() method in the LookupRef\Matrix class instead
+ * @see LookupRef\Matrix::transpose()
+ * Use the transpose() method in the LookupRef\Matrix class instead
*
* @param array $matrixData A matrix of values
*
@@ -350,7 +337,8 @@ class LookupRef
*
* @Deprecated 1.18.0
*
- * @see Use the lookup() method in the LookupRef\VLookup class instead
+ * @see LookupRef\VLookup::lookup()
+ * Use the lookup() method in the LookupRef\VLookup class instead
*
* @param mixed $lookup_value The value that you want to match in lookup_array
* @param mixed $lookup_array The range of cells being searched
@@ -372,7 +360,8 @@ class LookupRef
*
* @Deprecated 1.18.0
*
- * @see Use the lookup() method in the LookupRef\HLookup class instead
+ * @see LookupRef\HLookup::lookup()
+ * Use the lookup() method in the LookupRef\HLookup class instead
*
* @param mixed $lookup_value The value that you want to match in lookup_array
* @param mixed $lookup_array The range of cells being searched
@@ -393,7 +382,8 @@ class LookupRef
*
* @Deprecated 1.18.0
*
- * @see Use the lookup() method in the LookupRef\Lookup class instead
+ * @see LookupRef\Lookup::lookup()
+ * Use the lookup() method in the LookupRef\Lookup class instead
*
* @param mixed $lookup_value The value that you want to match in lookup_array
* @param mixed $lookup_vector The range of cells being searched
@@ -409,6 +399,11 @@ class LookupRef
/**
* FORMULATEXT.
*
+ * @Deprecated 1.18.0
+ *
+ * @see LookupRef\Formula::text()
+ * Use the text() method in the LookupRef\Formula class instead
+ *
* @param mixed $cellReference The cell to check
* @param Cell $pCell The current cell (containing this formula)
*
@@ -416,22 +411,6 @@ class LookupRef
*/
public static function FORMULATEXT($cellReference = '', ?Cell $pCell = null)
{
- if ($pCell === null) {
- return Functions::REF();
- }
-
- preg_match('/^' . Calculation::CALCULATION_REGEXP_CELLREF . '$/i', $cellReference, $matches);
-
- $cellReference = $matches[6] . $matches[7];
- $worksheetName = trim($matches[3], "'");
- $worksheet = (!empty($worksheetName))
- ? $pCell->getWorksheet()->getParent()->getSheetByName($worksheetName)
- : $pCell->getWorksheet();
-
- if (!$worksheet->getCell($cellReference)->isFormula()) {
- return Functions::NA();
- }
-
- return $worksheet->getCell($cellReference)->getValue();
+ return LookupRef\Formula::text($cellReference, $pCell);
}
}
diff --git a/src/PhpSpreadsheet/Calculation/LookupRef/Formula.php b/src/PhpSpreadsheet/Calculation/LookupRef/Formula.php
new file mode 100644
index 00000000..d96b5040
--- /dev/null
+++ b/src/PhpSpreadsheet/Calculation/LookupRef/Formula.php
@@ -0,0 +1,43 @@
+getWorksheet()->getParent()->getSheetByName($worksheetName)
+ : $pCell->getWorksheet();
+
+ if (
+ $worksheet === null ||
+ !$worksheet->cellExists($cellReference) ||
+ !$worksheet->getCell($cellReference)->isFormula()
+ ) {
+ return Functions::NA();
+ }
+
+ return $worksheet->getCell($cellReference)->getValue();
+ }
+}
diff --git a/src/PhpSpreadsheet/Calculation/LookupRef/Hyperlink.php b/src/PhpSpreadsheet/Calculation/LookupRef/Hyperlink.php
new file mode 100644
index 00000000..823d70c6
--- /dev/null
+++ b/src/PhpSpreadsheet/Calculation/LookupRef/Hyperlink.php
@@ -0,0 +1,40 @@
+getHyperlink()->setUrl($linkURL);
+ $pCell->getHyperlink()->setTooltip($displayName);
+
+ return $displayName;
+ }
+}
diff --git a/src/PhpSpreadsheet/Calculation/LookupRef/LookupRefValidations.php b/src/PhpSpreadsheet/Calculation/LookupRef/LookupRefValidations.php
new file mode 100644
index 00000000..b0739eb3
--- /dev/null
+++ b/src/PhpSpreadsheet/Calculation/LookupRef/LookupRefValidations.php
@@ -0,0 +1,39 @@
+getMessage();
}
if (!is_array($matrix) || ($rowNum > count($matrix))) {
@@ -69,12 +75,12 @@ class Matrix
return Functions::REF();
}
- if ($columnNum == 0) {
+ if ($columnNum === 0) {
return self::extractRowValue($matrix, $rowKeys, $rowNum);
}
$columnNum = $columnKeys[--$columnNum];
- if ($rowNum == 0) {
+ if ($rowNum === 0) {
return array_map(
function ($value) {
return [$value];
@@ -89,7 +95,7 @@ class Matrix
private static function extractRowValue(array $matrix, array $rowKeys, int $rowNum)
{
- if ($rowNum == 0) {
+ if ($rowNum === 0) {
return $matrix;
}
diff --git a/src/PhpSpreadsheet/Calculation/LookupRef/Selection.php b/src/PhpSpreadsheet/Calculation/LookupRef/Selection.php
new file mode 100644
index 00000000..6c18d73b
--- /dev/null
+++ b/src/PhpSpreadsheet/Calculation/LookupRef/Selection.php
@@ -0,0 +1,46 @@
+ $entryCount)) {
+ return Functions::VALUE();
+ }
+
+ if (is_array($chooseArgs[$chosenEntry])) {
+ return Functions::flattenArray($chooseArgs[$chosenEntry]);
+ }
+
+ return $chooseArgs[$chosenEntry];
+ }
+}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig.php b/src/PhpSpreadsheet/Calculation/MathTrig.php
index 121efde5..ec251f6d 100644
--- a/src/PhpSpreadsheet/Calculation/MathTrig.php
+++ b/src/PhpSpreadsheet/Calculation/MathTrig.php
@@ -2,6 +2,9 @@
namespace PhpOffice\PhpSpreadsheet\Calculation;
+/**
+ * @deprecated 1.18.0
+ */
class MathTrig
{
/**
@@ -44,8 +47,8 @@ class MathTrig
*
* @Deprecated 1.18.0
*
- * @See MathTrig\Atan2::evaluate()
- * Use the evaluate method in the MathTrig\Atan2 class instead
+ * @See MathTrig\Trig\Tangent::atan2()
+ * Use the atan2 method in the MathTrig\Trig\Tangent class instead
*
* @param float $xCoordinate the x-coordinate of the point
* @param float $yCoordinate the y-coordinate of the point
@@ -54,7 +57,7 @@ class MathTrig
*/
public static function ATAN2($xCoordinate = null, $yCoordinate = null)
{
- return MathTrig\Atan2::evaluate($xCoordinate, $yCoordinate);
+ return MathTrig\Trig\Tangent::atan2($xCoordinate, $yCoordinate);
}
/**
@@ -94,17 +97,17 @@ class MathTrig
*
* @Deprecated 1.17.0
*
- * @see MathTrig\Ceiling::evaluate()
- * Use the evaluate() method in the MathTrig\Ceiling class instead
- *
* @param float $number the number you want to round
* @param float $significance the multiple to which you want to round
*
* @return float|string Rounded Number, or a string containing an error
+ *
+ * @see MathTrig\Ceiling::ceiling()
+ * Use the ceiling() method in the MathTrig\Ceiling class instead
*/
public static function CEILING($number, $significance = null)
{
- return MathTrig\Ceiling::evaluate($number, $significance);
+ return MathTrig\Ceiling::ceiling($number, $significance);
}
/**
@@ -124,7 +127,7 @@ class MathTrig
* @param int $numObjs Number of different objects
* @param int $numInSet Number of objects in each combination
*
- * @return int|string Number of combinations, or a string containing an error
+ * @return float|int|string Number of combinations, or a string containing an error
*/
public static function COMBIN($numObjs, $numInSet)
{
@@ -145,16 +148,16 @@ class MathTrig
*
* @Deprecated 1.18.0
*
- * @see MathTrig\Even::evaluate()
- * Use the evaluate() method in the MathTrig\Even class instead
+ * @see MathTrig\Round::even()
+ * Use the even() method in the MathTrig\Round class instead
*
* @param float $number Number to round
*
- * @return int|string Rounded Number, or a string containing an error
+ * @return float|int|string Rounded Number, or a string containing an error
*/
public static function EVEN($number)
{
- return MathTrig\Even::evaluate($number);
+ return MathTrig\Round::even($number);
}
/**
@@ -181,16 +184,16 @@ class MathTrig
*
* @Deprecated 1.18.0
*
- * @see MathTrig\Fact::evaluate()
- * Use the evaluate() method in the MathTrig\Fact class instead
- *
* @param float $factVal Factorial Value
*
- * @return int|string Factorial, or a string containing an error
+ * @return float|int|string Factorial, or a string containing an error
+ *
+ *@see MathTrig\Factorial::fact()
+ * Use the fact() method in the MathTrig\Factorial class instead
*/
public static function FACT($factVal)
{
- return MathTrig\Fact::evaluate($factVal);
+ return MathTrig\Factorial::fact($factVal);
}
/**
@@ -203,16 +206,16 @@ class MathTrig
*
* @Deprecated 1.18.0
*
- * @see MathTrig\FactDouble::evaluate()
- * Use the evaluate() method in the MathTrig\FactDouble class instead
- *
* @param float $factVal Factorial Value
*
- * @return int|string Double Factorial, or a string containing an error
+ * @return float|int|string Double Factorial, or a string containing an error
+ *
+ *@see MathTrig\Factorial::factDouble()
+ * Use the factDouble() method in the MathTrig\Factorial class instead
*/
public static function FACTDOUBLE($factVal)
{
- return MathTrig\FactDouble::evaluate($factVal);
+ return MathTrig\Factorial::factDouble($factVal);
}
/**
@@ -225,17 +228,17 @@ class MathTrig
*
* @Deprecated 1.17.0
*
- * @see MathTrig\Floor::evaluate()
- * Use the evaluate() method in the MathTrig\Floor class instead
- *
* @param float $number Number to round
* @param float $significance Significance
*
* @return float|string Rounded Number, or a string containing an error
+ *
+ *@see MathTrig\Floor::floor()
+ * Use the floor() method in the MathTrig\Floor class instead
*/
public static function FLOOR($number, $significance = null)
{
- return MathTrig\Floor::evaluate($number, $significance);
+ return MathTrig\Floor::floor($number, $significance);
}
/**
@@ -248,18 +251,18 @@ class MathTrig
*
* @Deprecated 1.17.0
*
- * @see MathTrig\FloorMath::evaluate()
- * Use the evaluate() method in the MathTrig\FloorMath class instead
- *
* @param float $number Number to round
* @param float $significance Significance
* @param int $mode direction to round negative numbers
*
* @return float|string Rounded Number, or a string containing an error
+ *
+ *@see MathTrig\Floor::math()
+ * Use the math() method in the MathTrig\Floor class instead
*/
public static function FLOORMATH($number, $significance = null, $mode = 0)
{
- return MathTrig\FloorMath::evaluate($number, $significance, $mode);
+ return MathTrig\Floor::math($number, $significance, $mode);
}
/**
@@ -272,17 +275,17 @@ class MathTrig
*
* @Deprecated 1.17.0
*
- * @see MathTrig\FloorPrecise::evaluate()
- * Use the evaluate() method in the MathTrig\FloorPrecise class instead
- *
* @param float $number Number to round
* @param float $significance Significance
*
* @return float|string Rounded Number, or a string containing an error
+ *
+ *@see MathTrig\Floor::precise()
+ * Use the precise() method in the MathTrig\Floor class instead
*/
public static function FLOORPRECISE($number, $significance = 1)
{
- return MathTrig\FloorPrecise::evaluate($number, $significance);
+ return MathTrig\Floor::precise($number, $significance);
}
/**
@@ -446,17 +449,17 @@ class MathTrig
*
* @Deprecated 1.18.0
*
- * @see MathTrig\Mod::evaluate()
- * Use the evaluate() method in the MathTrig\Mod class instead
+ * @see MathTrig\Operations::mod()
+ * Use the mod() method in the MathTrig\Operations class instead
*
* @param int $a Dividend
* @param int $b Divisor
*
- * @return int|string Remainder, or a string containing an error
+ * @return float|int|string Remainder, or a string containing an error
*/
public static function MOD($a = 1, $b = 1)
{
- return MathTrig\Mod::evaluate($a, $b);
+ return MathTrig\Operations::mod($a, $b);
}
/**
@@ -466,17 +469,17 @@ class MathTrig
*
* @Deprecated 1.17.0
*
- * @see MathTrig\Mround::evaluate()
- * Use the evaluate() method in the MathTrig\Mround class instead
- *
* @param float $number Number to round
* @param int $multiple Multiple to which you want to round $number
*
* @return float|string Rounded Number, or a string containing an error
+ *
+ *@see MathTrig\Round::multiple()
+ * Use the multiple() method in the MathTrig\Mround class instead
*/
public static function MROUND($number, $multiple)
{
- return MathTrig\Mround::evaluate($number, $multiple);
+ return MathTrig\Round::multiple($number, $multiple);
}
/**
@@ -486,8 +489,8 @@ class MathTrig
*
* @Deprecated 1.18.0
*
- * @See MathTrig\Multinomial::evaluate()
- * Use the evaluate method in the MathTrig\Multinomial class instead
+ * @See MathTrig\Factorial::multinomial()
+ * Use the multinomial method in the MathTrig\Factorial class instead
*
* @param mixed[] $args An array of mixed values for the Data Series
*
@@ -495,7 +498,7 @@ class MathTrig
*/
public static function MULTINOMIAL(...$args)
{
- return MathTrig\Multinomial::evaluate(...$args);
+ return MathTrig\Factorial::multinomial(...$args);
}
/**
@@ -505,16 +508,16 @@ class MathTrig
*
* @Deprecated 1.18.0
*
- * @See MathTrig\Odd::evaluate()
- * Use the evaluate method in the MathTrig\Odd class instead
+ * @See MathTrig\Round::odd()
+ * Use the odd method in the MathTrig\Round class instead
*
* @param float $number Number to round
*
- * @return int|string Rounded Number, or a string containing an error
+ * @return float|int|string Rounded Number, or a string containing an error
*/
public static function ODD($number)
{
- return MathTrig\Odd::evaluate($number);
+ return MathTrig\Round::odd($number);
}
/**
@@ -524,7 +527,7 @@ class MathTrig
*
* @Deprecated 1.18.0
*
- * @See MathTrig\Power::evaluate()
+ * @See MathTrig\Operations::power()
* Use the evaluate method in the MathTrig\Power class instead
*
* @param float $x
@@ -534,7 +537,7 @@ class MathTrig
*/
public static function POWER($x = 0, $y = 2)
{
- return MathTrig\Power::evaluate($x, $y);
+ return MathTrig\Operations::power($x, $y);
}
/**
@@ -544,8 +547,8 @@ class MathTrig
*
* @Deprecated 1.18.0
*
- * @See MathTrig\Product::evaluate()
- * Use the evaluate method in the MathTrig\Product class instead
+ * @See MathTrig\Operations::product()
+ * Use the product method in the MathTrig\Operations class instead
*
* Excel Function:
* PRODUCT(value1[,value2[, ...]])
@@ -556,7 +559,7 @@ class MathTrig
*/
public static function PRODUCT(...$args)
{
- return MathTrig\Product::evaluate(...$args);
+ return MathTrig\Operations::product(...$args);
}
/**
@@ -567,8 +570,8 @@ class MathTrig
*
* @Deprecated 1.18.0
*
- * @See MathTrig\Quotient::evaluate()
- * Use the evaluate method in the MathTrig\Quotient class instead
+ * @See MathTrig\Operations::quotient()
+ * Use the quotient method in the MathTrig\Operations class instead
*
* Excel Function:
* QUOTIENT(value1[,value2[, ...]])
@@ -580,7 +583,7 @@ class MathTrig
*/
public static function QUOTIENT($numerator, $denominator)
{
- return MathTrig\Quotient::evaluate($numerator, $denominator);
+ return MathTrig\Operations::quotient($numerator, $denominator);
}
/**
@@ -628,8 +631,8 @@ class MathTrig
*
* @Deprecated 1.17.0
*
- * @See MathTrig\RoundUp::evaluate()
- * Use the evaluate() method in the MathTrig\RoundUp class instead
+ * @See MathTrig\Round::up()
+ * Use the up() method in the MathTrig\Round class instead
*
* @param float $number Number to round
* @param int $digits Number of digits to which you want to round $number
@@ -638,7 +641,7 @@ class MathTrig
*/
public static function ROUNDUP($number, $digits)
{
- return MathTrig\RoundUp::evaluate($number, $digits);
+ return MathTrig\Round::up($number, $digits);
}
/**
@@ -648,8 +651,8 @@ class MathTrig
*
* @Deprecated 1.17.0
*
- * @See MathTrig\RoundDown::evaluate()
- * Use the evaluate() method in the MathTrig\RoundDown class instead
+ * @See MathTrig\Round::down()
+ * Use the down() method in the MathTrig\Round class instead
*
* @param float $number Number to round
* @param int $digits Number of digits to which you want to round $number
@@ -658,7 +661,7 @@ class MathTrig
*/
public static function ROUNDDOWN($number, $digits)
{
- return MathTrig\RoundDown::evaluate($number, $digits);
+ return MathTrig\Round::down($number, $digits);
}
/**
@@ -723,8 +726,8 @@ class MathTrig
*
* @Deprecated 1.18.0
*
- * @See MathTrig\SqrtPi::evaluate()
- * Use the evaluate method in the MathTrig\SqrtPi class instead
+ * @See MathTrig\Sqrt::sqrt()
+ * Use the pi method in the MathTrig\Sqrt class instead
*
* @param float $number Number
*
@@ -732,7 +735,7 @@ class MathTrig
*/
public static function SQRTPI($number)
{
- return MathTrig\SqrtPi::evaluate($number);
+ return MathTrig\Sqrt::pi($number);
}
/**
@@ -768,8 +771,8 @@ class MathTrig
*
* @Deprecated 1.18.0
*
- * @See MathTrig\Sum::funcSumNoStrings()
- * Use the funcSumNoStrings method in the MathTrig\Sum class instead
+ * @See MathTrig\Sum::sumErroringStrings()
+ * Use the sumErroringStrings method in the MathTrig\Sum class instead
*
* Excel Function:
* SUM(value1[,value2[, ...]])
@@ -780,7 +783,7 @@ class MathTrig
*/
public static function SUM(...$args)
{
- return MathTrig\Sum::funcSum(...$args);
+ return MathTrig\Sum::sumIgnoringStrings(...$args);
}
/**
@@ -822,7 +825,7 @@ class MathTrig
*
* @param mixed $args Data values
*
- * @return float|string
+ * @return null|float|string
*/
public static function SUMIFS(...$args)
{
@@ -837,8 +840,8 @@ class MathTrig
*
* @Deprecated 1.18.0
*
- * @See MathTrig\SumProduct::evaluate()
- * Use the evaluate method in the MathTrig\SumProduct class instead
+ * @See MathTrig\Sum::product()
+ * Use the product method in the MathTrig\Sum class instead
*
* @param mixed ...$args Data values
*
@@ -846,7 +849,7 @@ class MathTrig
*/
public static function SUMPRODUCT(...$args)
{
- return MathTrig\SumProduct::evaluate(...$args);
+ return MathTrig\Sum::product(...$args);
}
/**
@@ -952,8 +955,8 @@ class MathTrig
*
* @Deprecated 1.18.0
*
- * @See MathTrig\Sec::evaluate()
- * Use the evaluate method in the MathTrig\Sec class instead
+ * @See MathTrig\Trig\Secant::sec()
+ * Use the sec method in the MathTrig\Trig\Secant class instead
*
* @param float $angle Number
*
@@ -961,7 +964,7 @@ class MathTrig
*/
public static function SEC($angle)
{
- return MathTrig\Sec::evaluate($angle);
+ return MathTrig\Trig\Secant::sec($angle);
}
/**
@@ -971,8 +974,8 @@ class MathTrig
*
* @Deprecated 1.18.0
*
- * @See MathTrig\SecH::evaluate()
- * Use the evaluate method in the MathTrig\Sech class instead
+ * @See MathTrig\Trig\Secant::sech()
+ * Use the sech method in the MathTrig\Trig\Secant class instead
*
* @param float $angle Number
*
@@ -980,7 +983,7 @@ class MathTrig
*/
public static function SECH($angle)
{
- return MathTrig\Sech::evaluate($angle);
+ return MathTrig\Trig\Secant::sech($angle);
}
/**
@@ -990,8 +993,8 @@ class MathTrig
*
* @Deprecated 1.18.0
*
- * @See MathTrig\Csc::evaluate()
- * Use the evaluate method in the MathTrig\Csc class instead
+ * @See MathTrig\Trig\Cosecant::csc()
+ * Use the csc method in the MathTrig\Trig\Cosecant class instead
*
* @param float $angle Number
*
@@ -999,7 +1002,7 @@ class MathTrig
*/
public static function CSC($angle)
{
- return MathTrig\Csc::evaluate($angle);
+ return MathTrig\Trig\Cosecant::csc($angle);
}
/**
@@ -1009,8 +1012,8 @@ class MathTrig
*
* @Deprecated 1.18.0
*
- * @See MathTrig\Csch::evaluate()
- * Use the evaluate method in the MathTrig\Csch class instead
+ * @See MathTrig\Trig\Cosecant::csch()
+ * Use the csch method in the MathTrig\Trig\Cosecant class instead
*
* @param float $angle Number
*
@@ -1018,7 +1021,7 @@ class MathTrig
*/
public static function CSCH($angle)
{
- return MathTrig\Csch::evaluate($angle);
+ return MathTrig\Trig\Cosecant::csch($angle);
}
/**
@@ -1028,8 +1031,8 @@ class MathTrig
*
* @Deprecated 1.18.0
*
- * @See MathTrig\Cot::evaluate()
- * Use the evaluate method in the MathTrig\Cot class instead
+ * @See MathTrig\Trig\Cotangent::cot()
+ * Use the cot method in the MathTrig\Trig\Cotangent class instead
*
* @param float $angle Number
*
@@ -1037,7 +1040,7 @@ class MathTrig
*/
public static function COT($angle)
{
- return MathTrig\Cot::evaluate($angle);
+ return MathTrig\Trig\Cotangent::cot($angle);
}
/**
@@ -1047,8 +1050,8 @@ class MathTrig
*
* @Deprecated 1.18.0
*
- * @See MathTrig\Coth::evaluate()
- * Use the evaluate method in the MathTrig\Coth class instead
+ * @See MathTrig\Trig\Cotangent::coth()
+ * Use the coth method in the MathTrig\Trig\Cotangent class instead
*
* @param float $angle Number
*
@@ -1056,7 +1059,7 @@ class MathTrig
*/
public static function COTH($angle)
{
- return MathTrig\Coth::evaluate($angle);
+ return MathTrig\Trig\Cotangent::coth($angle);
}
/**
@@ -1066,8 +1069,8 @@ class MathTrig
*
* @Deprecated 1.18.0
*
- * @See MathTrig\Acot::evaluate()
- * Use the evaluate method in the MathTrig\Acot class instead
+ * @See MathTrig\Trig\Cotangent::acot()
+ * Use the acot method in the MathTrig\Trig\Cotangent class instead
*
* @param float $number Number
*
@@ -1075,7 +1078,7 @@ class MathTrig
*/
public static function ACOT($number)
{
- return MathTrig\Acot::evaluate($number);
+ return MathTrig\Trig\Cotangent::acot($number);
}
/**
@@ -1102,8 +1105,8 @@ class MathTrig
*
* @Deprecated 1.18.0
*
- * @See MathTrig\Acoth::evaluate()
- * Use the evaluate method in the MathTrig\Acoth class instead
+ * @See MathTrig\Trig\Cotangent::acoth()
+ * Use the acoth method in the MathTrig\Trig\Cotangent class instead
*
* @param float $number Number
*
@@ -1111,7 +1114,7 @@ class MathTrig
*/
public static function ACOTH($number)
{
- return MathTrig\Acoth::evaluate($number);
+ return MathTrig\Trig\Cotangent::acoth($number);
}
/**
@@ -1121,8 +1124,8 @@ class MathTrig
*
* @Deprecated 1.17.0
*
- * @See MathTrig\Round::evaluate()
- * Use the evaluate() method in the MathTrig\Round class instead
+ * @See MathTrig\Round::round()
+ * Use the round() method in the MathTrig\Round class instead
*
* @param mixed $number Should be numeric
* @param mixed $precision Should be int
@@ -1131,7 +1134,7 @@ class MathTrig
*/
public static function builtinROUND($number, $precision)
{
- return MathTrig\Round::evaluate($number, $precision);
+ return MathTrig\Round::round($number, $precision);
}
/**
@@ -1158,8 +1161,8 @@ class MathTrig
*
* @Deprecated 1.18.0
*
- * @See MathTrig\Acos::evaluate()
- * Use the evaluate method in the MathTrig\Acos class instead
+ * @See MathTrig\Trig\Cosine::acos()
+ * Use the acos method in the MathTrig\Trig\Cosine class instead
*
* Returns the result of builtin function acos after validating args.
*
@@ -1169,7 +1172,7 @@ class MathTrig
*/
public static function builtinACOS($number)
{
- return MathTrig\Acos::evaluate($number);
+ return MathTrig\Trig\Cosine::acos($number);
}
/**
@@ -1179,8 +1182,8 @@ class MathTrig
*
* @Deprecated 1.18.0
*
- * @See MathTrig\Acosh::evaluate()
- * Use the evaluate method in the MathTrig\Acosh class instead
+ * @See MathTrig\Trig\Cosine::acosh()
+ * Use the acosh method in the MathTrig\Trig\Cosine class instead
*
* @param mixed $number Should be numeric
*
@@ -1188,7 +1191,7 @@ class MathTrig
*/
public static function builtinACOSH($number)
{
- return MathTrig\Acosh::evaluate($number);
+ return MathTrig\Trig\Cosine::acosh($number);
}
/**
@@ -1198,8 +1201,8 @@ class MathTrig
*
* @Deprecated 1.18.0
*
- * @See MathTrig\Asin::evaluate()
- * Use the evaluate method in the MathTrig\Asin class instead
+ * @See MathTrig\Trig\Sine::asin()
+ * Use the asin method in the MathTrig\Trig\Sine class instead
*
* @param mixed $number Should be numeric
*
@@ -1207,7 +1210,7 @@ class MathTrig
*/
public static function builtinASIN($number)
{
- return MathTrig\Asin::evaluate($number);
+ return MathTrig\Trig\Sine::asin($number);
}
/**
@@ -1217,8 +1220,8 @@ class MathTrig
*
* @Deprecated 1.18.0
*
- * @See MathTrig\Asinh::evaluate()
- * Use the evaluate method in the MathTrig\Asinh class instead
+ * @See MathTrig\Trig\Sine::asinh()
+ * Use the asinh method in the MathTrig\Trig\Sine class instead
*
* @param mixed $number Should be numeric
*
@@ -1226,7 +1229,7 @@ class MathTrig
*/
public static function builtinASINH($number)
{
- return MathTrig\Asinh::evaluate($number);
+ return MathTrig\Trig\Sine::asinh($number);
}
/**
@@ -1236,8 +1239,8 @@ class MathTrig
*
* @Deprecated 1.18.0
*
- * @See MathTrig\Atan::evaluate()
- * Use the evaluate method in the MathTrig\Atan class instead
+ * @See MathTrig\Trig\Tangent::atan()
+ * Use the atan method in the MathTrig\Trig\Tangent class instead
*
* @param mixed $number Should be numeric
*
@@ -1245,7 +1248,7 @@ class MathTrig
*/
public static function builtinATAN($number)
{
- return MathTrig\Atan::evaluate($number);
+ return MathTrig\Trig\Tangent::atan($number);
}
/**
@@ -1255,8 +1258,8 @@ class MathTrig
*
* @Deprecated 1.18.0
*
- * @See MathTrig\Atanh::evaluate()
- * Use the evaluate method in the MathTrig\Atanh class instead
+ * @See MathTrig\Trig\Tangent::atanh()
+ * Use the atanh method in the MathTrig\Trig\Tangent class instead
*
* @param mixed $number Should be numeric
*
@@ -1264,7 +1267,7 @@ class MathTrig
*/
public static function builtinATANH($number)
{
- return MathTrig\Atanh::evaluate($number);
+ return MathTrig\Trig\Tangent::atanh($number);
}
/**
@@ -1274,8 +1277,8 @@ class MathTrig
*
* @Deprecated 1.18.0
*
- * @See MathTrig\Cos::evaluate()
- * Use the evaluate method in the MathTrig\Cos class instead
+ * @See MathTrig\Trig\Cosine::cos()
+ * Use the cos method in the MathTrig\Trig\Cosine class instead
*
* @param mixed $number Should be numeric
*
@@ -1283,7 +1286,7 @@ class MathTrig
*/
public static function builtinCOS($number)
{
- return MathTrig\Cos::evaluate($number);
+ return MathTrig\Trig\Cosine::cos($number);
}
/**
@@ -1293,8 +1296,8 @@ class MathTrig
*
* @Deprecated 1.18.0
*
- * @See MathTrig\Cosh::evaluate()
- * Use the evaluate method in the MathTrig\Cosh class instead
+ * @See MathTrig\Trig\Cosine::cosh()
+ * Use the cosh method in the MathTrig\Trig\Cosine class instead
*
* @param mixed $number Should be numeric
*
@@ -1302,7 +1305,7 @@ class MathTrig
*/
public static function builtinCOSH($number)
{
- return MathTrig\Cosh::evaluate($number);
+ return MathTrig\Trig\Cosine::cosh($number);
}
/**
@@ -1312,8 +1315,8 @@ class MathTrig
*
* @Deprecated 1.18.0
*
- * @See MathTrig\Degrees::evaluate()
- * Use the evaluate method in the MathTrig\Degrees class instead
+ * @See MathTrig\Angle::toDegrees()
+ * Use the toDegrees method in the MathTrig\Angle class instead
*
* @param mixed $number Should be numeric
*
@@ -1321,7 +1324,7 @@ class MathTrig
*/
public static function builtinDEGREES($number)
{
- return MathTrig\Degrees::evaluate($number);
+ return MathTrig\Angle::toDegrees($number);
}
/**
@@ -1388,8 +1391,8 @@ class MathTrig
*
* @Deprecated 1.18.0
*
- * @See MathTrig\Radians::evaluate()
- * Use the evaluate method in the MathTrig\Radians class instead
+ * @See MathTrig\Angle::toRadians()
+ * Use the toRadians method in the MathTrig\Angle class instead
*
* @param mixed $number Should be numeric
*
@@ -1397,7 +1400,7 @@ class MathTrig
*/
public static function builtinRADIANS($number)
{
- return MathTrig\Radians::evaluate($number);
+ return MathTrig\Angle::toRadians($number);
}
/**
@@ -1407,16 +1410,16 @@ class MathTrig
*
* @Deprecated 1.18.0
*
- * @See MathTrig\Sin::evaluate()
- * Use the evaluate method in the MathTrig\Sin class instead
+ * @See MathTrig\Trig\Sine::evaluate()
+ * Use the sin method in the MathTrig\Trig\Sine class instead
*
* @param mixed $number Should be numeric
*
- * @return float|string Rounded number
+ * @return float|string sine
*/
public static function builtinSIN($number)
{
- return MathTrig\Sin::evaluate($number);
+ return MathTrig\Trig\Sine::sin($number);
}
/**
@@ -1426,8 +1429,8 @@ class MathTrig
*
* @Deprecated 1.18.0
*
- * @See MathTrig\Sinh::evaluate()
- * Use the evaluate method in the MathTrig\Sinh class instead
+ * @See MathTrig\Trig\Sine::sinh()
+ * Use the sinh method in the MathTrig\Trig\Sine class instead
*
* @param mixed $number Should be numeric
*
@@ -1435,7 +1438,7 @@ class MathTrig
*/
public static function builtinSINH($number)
{
- return MathTrig\Sinh::evaluate($number);
+ return MathTrig\Trig\Sine::sinh($number);
}
/**
@@ -1445,8 +1448,8 @@ class MathTrig
*
* @Deprecated 1.18.0
*
- * @See MathTrig\Sqrt::evaluate()
- * Use the evaluate method in the MathTrig\Sqrt class instead
+ * @See MathTrig\Sqrt::sqrt()
+ * Use the sqrt method in the MathTrig\Sqrt class instead
*
* @param mixed $number Should be numeric
*
@@ -1454,7 +1457,7 @@ class MathTrig
*/
public static function builtinSQRT($number)
{
- return MathTrig\Sqrt::evaluate($number);
+ return MathTrig\Sqrt::sqrt($number);
}
/**
@@ -1464,8 +1467,8 @@ class MathTrig
*
* @Deprecated 1.18.0
*
- * @See MathTrig\Tan::evaluate()
- * Use the evaluate method in the MathTrig\Tan class instead
+ * @See MathTrig\Trig\Tangent::tan()
+ * Use the tan method in the MathTrig\Trig\Tangent class instead
*
* @param mixed $number Should be numeric
*
@@ -1473,7 +1476,7 @@ class MathTrig
*/
public static function builtinTAN($number)
{
- return MathTrig\Tan::evaluate($number);
+ return MathTrig\Trig\Tangent::tan($number);
}
/**
@@ -1483,8 +1486,8 @@ class MathTrig
*
* @Deprecated 1.18.0
*
- * @See MathTrig\Tan::evaluate()
- * Use the evaluate method in the MathTrig\Tanh class instead
+ * @See MathTrig\Trig\Tangent::tanh()
+ * Use the tanh method in the MathTrig\Trig\Tangent class instead
*
* @param mixed $number Should be numeric
*
@@ -1492,7 +1495,7 @@ class MathTrig
*/
public static function builtinTANH($number)
{
- return MathTrig\Tanh::evaluate($number);
+ return MathTrig\Trig\Tangent::tanh($number);
}
/**
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Absolute.php b/src/PhpSpreadsheet/Calculation/MathTrig/Absolute.php
index c2dc579f..9f1bd804 100644
--- a/src/PhpSpreadsheet/Calculation/MathTrig/Absolute.php
+++ b/src/PhpSpreadsheet/Calculation/MathTrig/Absolute.php
@@ -2,7 +2,7 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
-use Exception;
+use PhpOffice\PhpSpreadsheet\Calculation\Exception;
class Absolute
{
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Acos.php b/src/PhpSpreadsheet/Calculation/MathTrig/Acos.php
deleted file mode 100644
index 889c7593..00000000
--- a/src/PhpSpreadsheet/Calculation/MathTrig/Acos.php
+++ /dev/null
@@ -1,28 +0,0 @@
-getMessage();
- }
-
- return Helpers::numberOrNan(acos($number));
- }
-}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Acosh.php b/src/PhpSpreadsheet/Calculation/MathTrig/Acosh.php
deleted file mode 100644
index 34fb97f4..00000000
--- a/src/PhpSpreadsheet/Calculation/MathTrig/Acosh.php
+++ /dev/null
@@ -1,28 +0,0 @@
-getMessage();
- }
-
- return Helpers::numberOrNan(acosh($number));
- }
-}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Acot.php b/src/PhpSpreadsheet/Calculation/MathTrig/Acot.php
deleted file mode 100644
index 5817407b..00000000
--- a/src/PhpSpreadsheet/Calculation/MathTrig/Acot.php
+++ /dev/null
@@ -1,28 +0,0 @@
-getMessage();
- }
-
- return (M_PI / 2) - atan($number);
- }
-}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Acoth.php b/src/PhpSpreadsheet/Calculation/MathTrig/Acoth.php
deleted file mode 100644
index 17fe618d..00000000
--- a/src/PhpSpreadsheet/Calculation/MathTrig/Acoth.php
+++ /dev/null
@@ -1,30 +0,0 @@
-getMessage();
- }
-
- $result = ($number === 1) ? NAN : (log(($number + 1) / ($number - 1)) / 2);
-
- return Helpers::numberOrNan($result);
- }
-}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Angle.php b/src/PhpSpreadsheet/Calculation/MathTrig/Angle.php
new file mode 100644
index 00000000..3062481f
--- /dev/null
+++ b/src/PhpSpreadsheet/Calculation/MathTrig/Angle.php
@@ -0,0 +1,48 @@
+getMessage();
+ }
+
+ return rad2deg($number);
+ }
+
+ /**
+ * RADIANS.
+ *
+ * Returns the result of builtin function deg2rad after validating args.
+ *
+ * @param mixed $number Should be numeric
+ *
+ * @return float|string Rounded number
+ */
+ public static function toRadians($number)
+ {
+ try {
+ $number = Helpers::validateNumericNullBool($number);
+ } catch (Exception $e) {
+ return $e->getMessage();
+ }
+
+ return deg2rad($number);
+ }
+}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Arabic.php b/src/PhpSpreadsheet/Calculation/MathTrig/Arabic.php
index 320856b9..b852eeac 100644
--- a/src/PhpSpreadsheet/Calculation/MathTrig/Arabic.php
+++ b/src/PhpSpreadsheet/Calculation/MathTrig/Arabic.php
@@ -2,7 +2,7 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
-use Exception;
+use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class Arabic
@@ -47,11 +47,19 @@ class Arabic
return $sum;
}
+ /**
+ * @param mixed $value
+ */
+ private static function mollifyScrutinizer($value): array
+ {
+ return is_array($value) ? $value : [];
+ }
+
private static function strSplit(string $roman): array
{
$rslt = str_split($roman);
- return is_array($rslt) ? $rslt : [];
+ return self::mollifyScrutinizer($rslt);
}
/**
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Asin.php b/src/PhpSpreadsheet/Calculation/MathTrig/Asin.php
deleted file mode 100644
index 1db25122..00000000
--- a/src/PhpSpreadsheet/Calculation/MathTrig/Asin.php
+++ /dev/null
@@ -1,28 +0,0 @@
-getMessage();
- }
-
- return Helpers::numberOrNan(asin($number));
- }
-}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Asinh.php b/src/PhpSpreadsheet/Calculation/MathTrig/Asinh.php
deleted file mode 100644
index 2cc0b5c9..00000000
--- a/src/PhpSpreadsheet/Calculation/MathTrig/Asinh.php
+++ /dev/null
@@ -1,28 +0,0 @@
-getMessage();
- }
-
- return Helpers::numberOrNan(asinh($number));
- }
-}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Atan.php b/src/PhpSpreadsheet/Calculation/MathTrig/Atan.php
deleted file mode 100644
index 1b4cf43d..00000000
--- a/src/PhpSpreadsheet/Calculation/MathTrig/Atan.php
+++ /dev/null
@@ -1,28 +0,0 @@
-getMessage();
- }
-
- return Helpers::numberOrNan(atan($number));
- }
-}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Atan2.php b/src/PhpSpreadsheet/Calculation/MathTrig/Atan2.php
deleted file mode 100644
index b2cf8bf5..00000000
--- a/src/PhpSpreadsheet/Calculation/MathTrig/Atan2.php
+++ /dev/null
@@ -1,46 +0,0 @@
-getMessage();
- }
-
- if (($xCoordinate == 0) && ($yCoordinate == 0)) {
- return Functions::DIV0();
- }
-
- return atan2($yCoordinate, $xCoordinate);
- }
-}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Atanh.php b/src/PhpSpreadsheet/Calculation/MathTrig/Atanh.php
deleted file mode 100644
index 83045441..00000000
--- a/src/PhpSpreadsheet/Calculation/MathTrig/Atanh.php
+++ /dev/null
@@ -1,28 +0,0 @@
-getMessage();
- }
-
- return Helpers::numberOrNan(atanh($number));
- }
-}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Base.php b/src/PhpSpreadsheet/Calculation/MathTrig/Base.php
index 6f44a122..becba9a2 100644
--- a/src/PhpSpreadsheet/Calculation/MathTrig/Base.php
+++ b/src/PhpSpreadsheet/Calculation/MathTrig/Base.php
@@ -2,7 +2,7 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
-use Exception;
+use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class Base
@@ -36,7 +36,7 @@ class Base
return Functions::NAN(); // Numeric range constraints
}
- $outcome = strtoupper((string) base_convert($number, 10, $radix));
+ $outcome = strtoupper((string) base_convert((string) $number, 10, $radix));
if ($minLength !== null) {
$outcome = str_pad($outcome, (int) $minLength, '0', STR_PAD_LEFT); // String padding
}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Ceiling.php b/src/PhpSpreadsheet/Calculation/MathTrig/Ceiling.php
index 8dde1e74..73f54a52 100644
--- a/src/PhpSpreadsheet/Calculation/MathTrig/Ceiling.php
+++ b/src/PhpSpreadsheet/Calculation/MathTrig/Ceiling.php
@@ -2,7 +2,7 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
-use Exception;
+use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class Ceiling
@@ -23,7 +23,7 @@ class Ceiling
*
* @return float|string Rounded Number, or a string containing an error
*/
- public static function evaluate($number, $significance = null)
+ public static function ceiling($number, $significance = null)
{
if ($significance === null) {
self::floorCheck1Arg();
@@ -39,6 +39,78 @@ class Ceiling
return self::argumentsOk((float) $number, (float) $significance);
}
+ /**
+ * CEILING.MATH.
+ *
+ * Round a number down to the nearest integer or to the nearest multiple of significance.
+ *
+ * Excel Function:
+ * CEILING.MATH(number[,significance[,mode]])
+ *
+ * @param mixed $number Number to round
+ * @param mixed $significance Significance
+ * @param int $mode direction to round negative numbers
+ *
+ * @return float|string Rounded Number, or a string containing an error
+ */
+ public static function math($number, $significance = null, $mode = 0)
+ {
+ try {
+ $number = Helpers::validateNumericNullBool($number);
+ $significance = Helpers::validateNumericNullSubstitution($significance, ($number < 0) ? -1 : 1);
+ $mode = Helpers::validateNumericNullSubstitution($mode, null);
+ } catch (Exception $e) {
+ return $e->getMessage();
+ }
+
+ if (empty($significance * $number)) {
+ return 0.0;
+ }
+ if (self::ceilingMathTest((float) $significance, (float) $number, (int) $mode)) {
+ return floor($number / $significance) * $significance;
+ }
+
+ return ceil($number / $significance) * $significance;
+ }
+
+ /**
+ * CEILING.PRECISE.
+ *
+ * Rounds number up, away from zero, to the nearest multiple of significance.
+ *
+ * Excel Function:
+ * CEILING.PRECISE(number[,significance])
+ *
+ * @param mixed $number the number you want to round
+ * @param float $significance the multiple to which you want to round
+ *
+ * @return float|string Rounded Number, or a string containing an error
+ */
+ public static function precise($number, $significance = 1)
+ {
+ try {
+ $number = Helpers::validateNumericNullBool($number);
+ $significance = Helpers::validateNumericNullSubstitution($significance, null);
+ } catch (Exception $e) {
+ return $e->getMessage();
+ }
+
+ if (!$significance) {
+ return 0.0;
+ }
+ $result = $number / abs($significance);
+
+ return ceil($result) * $significance * (($significance < 0) ? -1 : 1);
+ }
+
+ /**
+ * Let CEILINGMATH complexity pass Scrutinizer.
+ */
+ private static function ceilingMathTest(float $significance, float $number, int $mode): bool
+ {
+ return ((float) $significance < 0) || ((float) $number < 0 && !empty($mode));
+ }
+
/**
* Avoid Scrutinizer problems concerning complexity.
*
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/CeilingMath.php b/src/PhpSpreadsheet/Calculation/MathTrig/CeilingMath.php
deleted file mode 100644
index 7214b3c5..00000000
--- a/src/PhpSpreadsheet/Calculation/MathTrig/CeilingMath.php
+++ /dev/null
@@ -1,50 +0,0 @@
-getMessage();
- }
-
- if (empty($significance * $number)) {
- return 0.0;
- }
- if (self::ceilingMathTest((float) $significance, (float) $number, (int) $mode)) {
- return floor($number / $significance) * $significance;
- }
-
- return ceil($number / $significance) * $significance;
- }
-
- /**
- * Let CEILINGMATH complexity pass Scrutinizer.
- */
- private static function ceilingMathTest(float $significance, float $number, int $mode): bool
- {
- return ((float) $significance < 0) || ((float) $number < 0 && !empty($mode));
- }
-}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/CeilingPrecise.php b/src/PhpSpreadsheet/Calculation/MathTrig/CeilingPrecise.php
deleted file mode 100644
index 1573af5a..00000000
--- a/src/PhpSpreadsheet/Calculation/MathTrig/CeilingPrecise.php
+++ /dev/null
@@ -1,38 +0,0 @@
-getMessage();
- }
-
- if (!$significance) {
- return 0.0;
- }
- $result = $number / abs($significance);
-
- return ceil($result) * $significance * (($significance < 0) ? -1 : 1);
- }
-}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Combinations.php b/src/PhpSpreadsheet/Calculation/MathTrig/Combinations.php
index 7e7b26ee..97508bb1 100644
--- a/src/PhpSpreadsheet/Calculation/MathTrig/Combinations.php
+++ b/src/PhpSpreadsheet/Calculation/MathTrig/Combinations.php
@@ -2,7 +2,7 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
-use Exception;
+use PhpOffice\PhpSpreadsheet\Calculation\Exception;
class Combinations
{
@@ -31,7 +31,7 @@ class Combinations
return $e->getMessage();
}
- return round(Fact::evaluate($numObjs) / Fact::evaluate($numObjs - $numInSet)) / Fact::evaluate($numInSet);
+ return round(Factorial::fact($numObjs) / Factorial::fact($numObjs - $numInSet)) / Factorial::fact($numInSet);
}
/**
@@ -69,6 +69,6 @@ class Combinations
return $e->getMessage();
}
- return round(Fact::evaluate($numObjs + $numInSet - 1) / Fact::evaluate($numObjs - 1)) / Fact::evaluate($numInSet);
+ return round(Factorial::fact($numObjs + $numInSet - 1) / Factorial::fact($numObjs - 1)) / Factorial::fact($numInSet);
}
}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Cos.php b/src/PhpSpreadsheet/Calculation/MathTrig/Cos.php
deleted file mode 100644
index 798cc5da..00000000
--- a/src/PhpSpreadsheet/Calculation/MathTrig/Cos.php
+++ /dev/null
@@ -1,28 +0,0 @@
-getMessage();
- }
-
- return cos($number);
- }
-}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Cosh.php b/src/PhpSpreadsheet/Calculation/MathTrig/Cosh.php
deleted file mode 100644
index d17bd676..00000000
--- a/src/PhpSpreadsheet/Calculation/MathTrig/Cosh.php
+++ /dev/null
@@ -1,28 +0,0 @@
-getMessage();
- }
-
- return cosh($number);
- }
-}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Cot.php b/src/PhpSpreadsheet/Calculation/MathTrig/Cot.php
deleted file mode 100644
index 53973444..00000000
--- a/src/PhpSpreadsheet/Calculation/MathTrig/Cot.php
+++ /dev/null
@@ -1,28 +0,0 @@
-getMessage();
- }
-
- return Helpers::verySmallDenominator(cos($angle), sin($angle));
- }
-}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Coth.php b/src/PhpSpreadsheet/Calculation/MathTrig/Coth.php
deleted file mode 100644
index 41e08f85..00000000
--- a/src/PhpSpreadsheet/Calculation/MathTrig/Coth.php
+++ /dev/null
@@ -1,28 +0,0 @@
-getMessage();
- }
-
- return Helpers::verySmallDenominator(1.0, tanh($angle));
- }
-}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Csc.php b/src/PhpSpreadsheet/Calculation/MathTrig/Csc.php
deleted file mode 100644
index 125963ef..00000000
--- a/src/PhpSpreadsheet/Calculation/MathTrig/Csc.php
+++ /dev/null
@@ -1,28 +0,0 @@
-getMessage();
- }
-
- return Helpers::verySmallDenominator(1.0, sin($angle));
- }
-}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Csch.php b/src/PhpSpreadsheet/Calculation/MathTrig/Csch.php
deleted file mode 100644
index b1543ec3..00000000
--- a/src/PhpSpreadsheet/Calculation/MathTrig/Csch.php
+++ /dev/null
@@ -1,28 +0,0 @@
-getMessage();
- }
-
- return Helpers::verySmallDenominator(1.0, sinh($angle));
- }
-}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Degrees.php b/src/PhpSpreadsheet/Calculation/MathTrig/Degrees.php
deleted file mode 100644
index 501817be..00000000
--- a/src/PhpSpreadsheet/Calculation/MathTrig/Degrees.php
+++ /dev/null
@@ -1,28 +0,0 @@
-getMessage();
- }
-
- return rad2deg($number);
- }
-}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Even.php b/src/PhpSpreadsheet/Calculation/MathTrig/Even.php
deleted file mode 100644
index 59951f31..00000000
--- a/src/PhpSpreadsheet/Calculation/MathTrig/Even.php
+++ /dev/null
@@ -1,35 +0,0 @@
-getMessage();
- }
-
- return Helpers::getEven($number);
- }
-}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Exp.php b/src/PhpSpreadsheet/Calculation/MathTrig/Exp.php
index f3f8af59..ce930a83 100644
--- a/src/PhpSpreadsheet/Calculation/MathTrig/Exp.php
+++ b/src/PhpSpreadsheet/Calculation/MathTrig/Exp.php
@@ -2,7 +2,7 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
-use Exception;
+use PhpOffice\PhpSpreadsheet\Calculation\Exception;
class Exp
{
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Fact.php b/src/PhpSpreadsheet/Calculation/MathTrig/Fact.php
deleted file mode 100644
index 2aa3d349..00000000
--- a/src/PhpSpreadsheet/Calculation/MathTrig/Fact.php
+++ /dev/null
@@ -1,47 +0,0 @@
-getMessage();
- }
-
- $factLoop = floor($factVal);
- if ($factVal > $factLoop) {
- if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_GNUMERIC) {
- return Statistical\Distributions\Gamma::gammaValue($factVal + 1);
- }
- }
-
- $factorial = 1;
- while ($factLoop > 1) {
- $factorial *= $factLoop--;
- }
-
- return $factorial;
- }
-}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/FactDouble.php b/src/PhpSpreadsheet/Calculation/MathTrig/FactDouble.php
deleted file mode 100644
index 4b760144..00000000
--- a/src/PhpSpreadsheet/Calculation/MathTrig/FactDouble.php
+++ /dev/null
@@ -1,39 +0,0 @@
-getMessage();
- }
-
- $factLoop = floor($factVal);
- $factorial = 1;
- while ($factLoop > 1) {
- $factorial *= $factLoop;
- $factLoop -= 2;
- }
-
- return $factorial;
- }
-}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Factorial.php b/src/PhpSpreadsheet/Calculation/MathTrig/Factorial.php
new file mode 100644
index 00000000..f443f8e5
--- /dev/null
+++ b/src/PhpSpreadsheet/Calculation/MathTrig/Factorial.php
@@ -0,0 +1,110 @@
+getMessage();
+ }
+
+ $factLoop = floor($factVal);
+ if ($factVal > $factLoop) {
+ if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_GNUMERIC) {
+ return Statistical\Distributions\Gamma::gammaValue($factVal + 1);
+ }
+ }
+
+ $factorial = 1;
+ while ($factLoop > 1) {
+ $factorial *= $factLoop--;
+ }
+
+ return $factorial;
+ }
+
+ /**
+ * FACTDOUBLE.
+ *
+ * Returns the double factorial of a number.
+ *
+ * Excel Function:
+ * FACTDOUBLE(factVal)
+ *
+ * @param float $factVal Factorial Value
+ *
+ * @return float|int|string Double Factorial, or a string containing an error
+ */
+ public static function factDouble($factVal)
+ {
+ try {
+ $factVal = Helpers::validateNumericNullSubstitution($factVal, 0);
+ Helpers::validateNotNegative($factVal);
+ } catch (Exception $e) {
+ return $e->getMessage();
+ }
+
+ $factLoop = floor($factVal);
+ $factorial = 1;
+ while ($factLoop > 1) {
+ $factorial *= $factLoop;
+ $factLoop -= 2;
+ }
+
+ return $factorial;
+ }
+
+ /**
+ * MULTINOMIAL.
+ *
+ * Returns the ratio of the factorial of a sum of values to the product of factorials.
+ *
+ * @param mixed[] $args An array of mixed values for the Data Series
+ *
+ * @return float|string The result, or a string containing an error
+ */
+ public static function multinomial(...$args)
+ {
+ $summer = 0;
+ $divisor = 1;
+
+ try {
+ // Loop through arguments
+ foreach (Functions::flattenArray($args) as $argx) {
+ $arg = Helpers::validateNumericNullSubstitution($argx, null);
+ Helpers::validateNotNegative($arg);
+ $arg = (int) $arg;
+ $summer += $arg;
+ $divisor *= self::fact($arg);
+ }
+ } catch (Exception $e) {
+ return $e->getMessage();
+ }
+
+ $summer = self::fact($summer);
+
+ return $summer / $divisor;
+ }
+}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Floor.php b/src/PhpSpreadsheet/Calculation/MathTrig/Floor.php
index b3db0adf..04e12205 100644
--- a/src/PhpSpreadsheet/Calculation/MathTrig/Floor.php
+++ b/src/PhpSpreadsheet/Calculation/MathTrig/Floor.php
@@ -2,7 +2,7 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
-use Exception;
+use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class Floor
@@ -28,7 +28,7 @@ class Floor
*
* @return float|string Rounded Number, or a string containing an error
*/
- public static function evaluate($number, $significance = null)
+ public static function floor($number, $significance = null)
{
if ($significance === null) {
self::floorCheck1Arg();
@@ -44,6 +44,103 @@ class Floor
return self::argumentsOk((float) $number, (float) $significance);
}
+ /**
+ * FLOOR.MATH.
+ *
+ * Round a number down to the nearest integer or to the nearest multiple of significance.
+ *
+ * Excel Function:
+ * FLOOR.MATH(number[,significance[,mode]])
+ *
+ * @param mixed $number Number to round
+ * @param mixed $significance Significance
+ * @param mixed $mode direction to round negative numbers
+ *
+ * @return float|string Rounded Number, or a string containing an error
+ */
+ public static function math($number, $significance = null, $mode = 0)
+ {
+ try {
+ $number = Helpers::validateNumericNullBool($number);
+ $significance = Helpers::validateNumericNullSubstitution($significance, ($number < 0) ? -1 : 1);
+ $mode = Helpers::validateNumericNullSubstitution($mode, null);
+ } catch (Exception $e) {
+ return $e->getMessage();
+ }
+
+ return self::argsOk((float) $number, (float) $significance, (int) $mode);
+ }
+
+ /**
+ * FLOOR.PRECISE.
+ *
+ * Rounds number down, toward zero, to the nearest multiple of significance.
+ *
+ * Excel Function:
+ * FLOOR.PRECISE(number[,significance])
+ *
+ * @param float $number Number to round
+ * @param float $significance Significance
+ *
+ * @return float|string Rounded Number, or a string containing an error
+ */
+ public static function precise($number, $significance = 1)
+ {
+ try {
+ $number = Helpers::validateNumericNullBool($number);
+ $significance = Helpers::validateNumericNullSubstitution($significance, null);
+ } catch (Exception $e) {
+ return $e->getMessage();
+ }
+
+ return self::argumentsOkPrecise((float) $number, (float) $significance);
+ }
+
+ /**
+ * Avoid Scrutinizer problems concerning complexity.
+ *
+ * @return float|string
+ */
+ private static function argumentsOkPrecise(float $number, float $significance)
+ {
+ if ($significance == 0.0) {
+ return Functions::DIV0();
+ }
+ if ($number == 0.0) {
+ return 0.0;
+ }
+
+ return floor($number / abs($significance)) * abs($significance);
+ }
+
+ /**
+ * Avoid Scrutinizer complexity problems.
+ *
+ * @return float|string Rounded Number, or a string containing an error
+ */
+ private static function argsOk(float $number, float $significance, int $mode)
+ {
+ if (!$significance) {
+ return Functions::DIV0();
+ }
+ if (!$number) {
+ return 0.0;
+ }
+ if (self::floorMathTest($number, $significance, $mode)) {
+ return ceil($number / $significance) * $significance;
+ }
+
+ return floor($number / $significance) * $significance;
+ }
+
+ /**
+ * Let FLOORMATH complexity pass Scrutinizer.
+ */
+ private static function floorMathTest(float $number, float $significance, int $mode): bool
+ {
+ return Helpers::returnSign($significance) == -1 || (Helpers::returnSign($number) == -1 && !empty($mode));
+ }
+
/**
* Avoid Scrutinizer problems concerning complexity.
*
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/FloorMath.php b/src/PhpSpreadsheet/Calculation/MathTrig/FloorMath.php
deleted file mode 100644
index 75a99cb2..00000000
--- a/src/PhpSpreadsheet/Calculation/MathTrig/FloorMath.php
+++ /dev/null
@@ -1,64 +0,0 @@
-getMessage();
- }
-
- return self::argsOk((float) $number, (float) $significance, (int) $mode);
- }
-
- /**
- * Avoid Scrutinizer complexity problems.
- *
- * @return float|string Rounded Number, or a string containing an error
- */
- private static function argsOk(float $number, float $significance, int $mode)
- {
- if (!$significance) {
- return Functions::DIV0();
- }
- if (!$number) {
- return 0.0;
- }
- if (self::floorMathTest($number, $significance, $mode)) {
- return ceil($number / $significance) * $significance;
- }
-
- return floor($number / $significance) * $significance;
- }
-
- /**
- * Let FLOORMATH complexity pass Scrutinizer.
- */
- private static function floorMathTest(float $number, float $significance, int $mode): bool
- {
- return Helpers::returnSign($significance) == -1 || (Helpers::returnSign($number) == -1 && !empty($mode));
- }
-}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/FloorPrecise.php b/src/PhpSpreadsheet/Calculation/MathTrig/FloorPrecise.php
deleted file mode 100644
index 1c719d39..00000000
--- a/src/PhpSpreadsheet/Calculation/MathTrig/FloorPrecise.php
+++ /dev/null
@@ -1,51 +0,0 @@
-getMessage();
- }
-
- return self::argumentsOk((float) $number, (float) $significance);
- }
-
- /**
- * Avoid Scrutinizer problems concerning complexity.
- *
- * @return float|string
- */
- private static function argumentsOk(float $number, float $significance)
- {
- if ($significance == 0.0) {
- return Functions::DIV0();
- }
- if ($number == 0.0) {
- return 0.0;
- }
-
- return floor($number / abs($significance)) * abs($significance);
- }
-}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Gcd.php b/src/PhpSpreadsheet/Calculation/MathTrig/Gcd.php
index 21c22699..1dd52faa 100644
--- a/src/PhpSpreadsheet/Calculation/MathTrig/Gcd.php
+++ b/src/PhpSpreadsheet/Calculation/MathTrig/Gcd.php
@@ -2,7 +2,7 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
-use Exception;
+use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class Gcd
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Helpers.php b/src/PhpSpreadsheet/Calculation/MathTrig/Helpers.php
index 26716467..b89644a9 100644
--- a/src/PhpSpreadsheet/Calculation/MathTrig/Helpers.php
+++ b/src/PhpSpreadsheet/Calculation/MathTrig/Helpers.php
@@ -34,7 +34,7 @@ class Helpers
return (int) $number;
}
if (is_numeric($number)) {
- return $number;
+ return 0 + $number;
}
throw new Exception(Functions::VALUE());
@@ -55,7 +55,7 @@ class Helpers
return $substitute;
}
if (is_numeric($number)) {
- return $number;
+ return 0 + $number;
}
throw new Exception(Functions::VALUE());
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/IntClass.php b/src/PhpSpreadsheet/Calculation/MathTrig/IntClass.php
index c8f35e48..7aa3d06a 100644
--- a/src/PhpSpreadsheet/Calculation/MathTrig/IntClass.php
+++ b/src/PhpSpreadsheet/Calculation/MathTrig/IntClass.php
@@ -2,7 +2,7 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
-use Exception;
+use PhpOffice\PhpSpreadsheet\Calculation\Exception;
class IntClass
{
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Lcm.php b/src/PhpSpreadsheet/Calculation/MathTrig/Lcm.php
index 5c28684f..46e9816d 100644
--- a/src/PhpSpreadsheet/Calculation/MathTrig/Lcm.php
+++ b/src/PhpSpreadsheet/Calculation/MathTrig/Lcm.php
@@ -2,7 +2,7 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
-use Exception;
+use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class Lcm
@@ -10,7 +10,7 @@ class Lcm
//
// Private method to return an array of the factors of the input value
//
- private static function factors($value)
+ private static function factors(float $value): array
{
$startVal = floor(sqrt($value));
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Logarithms.php b/src/PhpSpreadsheet/Calculation/MathTrig/Logarithms.php
index 169a74b0..d6878d88 100644
--- a/src/PhpSpreadsheet/Calculation/MathTrig/Logarithms.php
+++ b/src/PhpSpreadsheet/Calculation/MathTrig/Logarithms.php
@@ -2,7 +2,7 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
-use Exception;
+use PhpOffice\PhpSpreadsheet\Calculation\Exception;
class Logarithms
{
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/MatrixFunctions.php b/src/PhpSpreadsheet/Calculation/MathTrig/MatrixFunctions.php
index 290700c6..1e3224ea 100644
--- a/src/PhpSpreadsheet/Calculation/MathTrig/MatrixFunctions.php
+++ b/src/PhpSpreadsheet/Calculation/MathTrig/MatrixFunctions.php
@@ -2,10 +2,10 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
-use Exception;
use Matrix\Builder;
use Matrix\Exception as MatrixException;
use Matrix\Matrix;
+use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class MatrixFunctions
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Mod.php b/src/PhpSpreadsheet/Calculation/MathTrig/Mod.php
deleted file mode 100644
index 04267ee9..00000000
--- a/src/PhpSpreadsheet/Calculation/MathTrig/Mod.php
+++ /dev/null
@@ -1,36 +0,0 @@
-getMessage();
- }
-
- if (($dividend < 0.0) && ($divisor > 0.0)) {
- return $divisor - fmod(abs($dividend), $divisor);
- }
- if (($dividend > 0.0) && ($divisor < 0.0)) {
- return $divisor + fmod($dividend, abs($divisor));
- }
-
- return fmod($dividend, $divisor);
- }
-}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Mround.php b/src/PhpSpreadsheet/Calculation/MathTrig/Mround.php
deleted file mode 100644
index 5f3c4c05..00000000
--- a/src/PhpSpreadsheet/Calculation/MathTrig/Mround.php
+++ /dev/null
@@ -1,40 +0,0 @@
-getMessage();
- }
-
- if ($number == 0 || $multiple == 0) {
- return 0;
- }
- if ((Helpers::returnSign($number)) == (Helpers::returnSign($multiple))) {
- $multiplier = 1 / $multiple;
-
- return round($number * $multiplier) / $multiplier;
- }
-
- return Functions::NAN();
- }
-}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Multinomial.php b/src/PhpSpreadsheet/Calculation/MathTrig/Multinomial.php
deleted file mode 100644
index 98b7d522..00000000
--- a/src/PhpSpreadsheet/Calculation/MathTrig/Multinomial.php
+++ /dev/null
@@ -1,41 +0,0 @@
-getMessage();
- }
-
- $summer = Fact::evaluate($summer);
-
- return $summer / $divisor;
- }
-}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Odd.php b/src/PhpSpreadsheet/Calculation/MathTrig/Odd.php
deleted file mode 100644
index c50d2a76..00000000
--- a/src/PhpSpreadsheet/Calculation/MathTrig/Odd.php
+++ /dev/null
@@ -1,38 +0,0 @@
-getMessage();
- }
-
- $significance = Helpers::returnSign($number);
- if ($significance == 0) {
- return 1;
- }
-
- $result = ceil($number / $significance) * $significance;
- if ($result == Helpers::getEven($result)) {
- $result += $significance;
- }
-
- return $result;
- }
-}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Operations.php b/src/PhpSpreadsheet/Calculation/MathTrig/Operations.php
new file mode 100644
index 00000000..595c7fdc
--- /dev/null
+++ b/src/PhpSpreadsheet/Calculation/MathTrig/Operations.php
@@ -0,0 +1,136 @@
+getMessage();
+ }
+
+ if (($dividend < 0.0) && ($divisor > 0.0)) {
+ return $divisor - fmod(abs($dividend), $divisor);
+ }
+ if (($dividend > 0.0) && ($divisor < 0.0)) {
+ return $divisor + fmod($dividend, abs($divisor));
+ }
+
+ return fmod($dividend, $divisor);
+ }
+
+ /**
+ * POWER.
+ *
+ * Computes x raised to the power y.
+ *
+ * @param float|int $x
+ * @param float|int $y
+ *
+ * @return float|int|string The result, or a string containing an error
+ */
+ public static function power($x, $y)
+ {
+ try {
+ $x = Helpers::validateNumericNullBool($x);
+ $y = Helpers::validateNumericNullBool($y);
+ } catch (Exception $e) {
+ return $e->getMessage();
+ }
+
+ // Validate parameters
+ if (!$x && !$y) {
+ return Functions::NAN();
+ }
+ if (!$x && $y < 0.0) {
+ return Functions::DIV0();
+ }
+
+ // Return
+ $result = $x ** $y;
+
+ return Helpers::numberOrNan($result);
+ }
+
+ /**
+ * PRODUCT.
+ *
+ * PRODUCT returns the product of all the values and cells referenced in the argument list.
+ *
+ * Excel Function:
+ * PRODUCT(value1[,value2[, ...]])
+ *
+ * @param mixed ...$args Data values
+ *
+ * @return float|string
+ */
+ public static function product(...$args)
+ {
+ // Return value
+ $returnValue = null;
+
+ // Loop through arguments
+ foreach (Functions::flattenArray($args) as $arg) {
+ // Is it a numeric value?
+ if (is_numeric($arg)) {
+ if ($returnValue === null) {
+ $returnValue = $arg;
+ } else {
+ $returnValue *= $arg;
+ }
+ } else {
+ return Functions::VALUE();
+ }
+ }
+
+ // Return
+ if ($returnValue === null) {
+ return 0;
+ }
+
+ return $returnValue;
+ }
+
+ /**
+ * QUOTIENT.
+ *
+ * QUOTIENT function returns the integer portion of a division. Numerator is the divided number
+ * and denominator is the divisor.
+ *
+ * Excel Function:
+ * QUOTIENT(value1,value2)
+ *
+ * @param mixed $numerator Expect float|int
+ * @param mixed $denominator Expect float|int
+ *
+ * @return int|string
+ */
+ public static function quotient($numerator, $denominator)
+ {
+ try {
+ $numerator = Helpers::validateNumericNullSubstitution($numerator, 0);
+ $denominator = Helpers::validateNumericNullSubstitution($denominator, 0);
+ Helpers::validateNotZero($denominator);
+ } catch (Exception $e) {
+ return $e->getMessage();
+ }
+
+ return (int) ($numerator / $denominator);
+ }
+}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Power.php b/src/PhpSpreadsheet/Calculation/MathTrig/Power.php
deleted file mode 100644
index 70d177cd..00000000
--- a/src/PhpSpreadsheet/Calculation/MathTrig/Power.php
+++ /dev/null
@@ -1,42 +0,0 @@
-getMessage();
- }
-
- // Validate parameters
- if (!$x && !$y) {
- return Functions::NAN();
- }
- if (!$x && $y < 0.0) {
- return Functions::DIV0();
- }
-
- // Return
- $result = $x ** $y;
-
- return Helpers::numberOrNan($result);
- }
-}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Product.php b/src/PhpSpreadsheet/Calculation/MathTrig/Product.php
deleted file mode 100644
index 79c3f192..00000000
--- a/src/PhpSpreadsheet/Calculation/MathTrig/Product.php
+++ /dev/null
@@ -1,47 +0,0 @@
-getMessage();
- }
-
- return (int) ($numerator / $denominator);
- }
-}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Radians.php b/src/PhpSpreadsheet/Calculation/MathTrig/Radians.php
deleted file mode 100644
index 15e97011..00000000
--- a/src/PhpSpreadsheet/Calculation/MathTrig/Radians.php
+++ /dev/null
@@ -1,28 +0,0 @@
-getMessage();
- }
-
- return deg2rad($number);
- }
-}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Random.php b/src/PhpSpreadsheet/Calculation/MathTrig/Random.php
index 1a384fe9..963a789a 100644
--- a/src/PhpSpreadsheet/Calculation/MathTrig/Random.php
+++ b/src/PhpSpreadsheet/Calculation/MathTrig/Random.php
@@ -2,7 +2,7 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
-use Exception;
+use PhpOffice\PhpSpreadsheet\Calculation\Exception;
class Random
{
@@ -11,7 +11,7 @@ class Random
*
* @return float Random number
*/
- public static function randNoArgs()
+ public static function rand()
{
return (mt_rand(0, 10000000)) / 10000000;
}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Roman.php b/src/PhpSpreadsheet/Calculation/MathTrig/Roman.php
index 0ee7a919..71a6df3a 100644
--- a/src/PhpSpreadsheet/Calculation/MathTrig/Roman.php
+++ b/src/PhpSpreadsheet/Calculation/MathTrig/Roman.php
@@ -2,7 +2,7 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
-use Exception;
+use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class Roman
@@ -769,6 +769,7 @@ class Roman
3998 => ['MMMLMVLIII', 'MMMXMVIII', 'MMMVMIII'],
3999 => ['MMMLMVLIV', 'MMMXMIX', 'MMMVMIV', 'MMMIM'],
];
+
private const THOUSANDS = ['', 'M', 'MM', 'MMM'];
private const HUNDREDS = ['', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM'];
private const TENS = ['', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC'];
@@ -776,19 +777,14 @@ class Roman
const MAX_ROMAN_VALUE = 3999;
const MAX_ROMAN_STYLE = 4;
- private static function romanCut($num, $n)
- {
- return ($num - ($num % $n)) / $n;
- }
-
private static function valueOk(int $aValue, int $style): string
{
$origValue = $aValue;
- $m = self::romanCut($aValue, 1000);
+ $m = \intdiv($aValue, 1000);
$aValue %= 1000;
- $c = self::romanCut($aValue, 100);
+ $c = \intdiv($aValue, 100);
$aValue %= 100;
- $t = self::romanCut($aValue, 10);
+ $t = \intdiv($aValue, 10);
$aValue %= 10;
$result = self::THOUSANDS[$m] . self::HUNDREDS[$c] . self::TENS[$t] . self::ONES[$aValue];
if ($style > 0) {
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Round.php b/src/PhpSpreadsheet/Calculation/MathTrig/Round.php
index a6552321..2ddde900 100644
--- a/src/PhpSpreadsheet/Calculation/MathTrig/Round.php
+++ b/src/PhpSpreadsheet/Calculation/MathTrig/Round.php
@@ -2,7 +2,8 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
-use Exception;
+use PhpOffice\PhpSpreadsheet\Calculation\Exception;
+use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class Round
{
@@ -16,7 +17,7 @@ class Round
*
* @return float|string Rounded number
*/
- public static function evaluate($number, $precision)
+ public static function round($number, $precision)
{
try {
$number = Helpers::validateNumericNullBool($number);
@@ -27,4 +28,152 @@ class Round
return round($number, (int) $precision);
}
+
+ /**
+ * ROUNDUP.
+ *
+ * Rounds a number up to a specified number of decimal places
+ *
+ * @param float $number Number to round
+ * @param int $digits Number of digits to which you want to round $number
+ *
+ * @return float|string Rounded Number, or a string containing an error
+ */
+ public static function up($number, $digits)
+ {
+ try {
+ $number = Helpers::validateNumericNullBool($number);
+ $digits = (int) Helpers::validateNumericNullSubstitution($digits, null);
+ } catch (Exception $e) {
+ return $e->getMessage();
+ }
+
+ if ($number == 0.0) {
+ return 0.0;
+ }
+
+ if ($number < 0.0) {
+ return round($number - 0.5 * 0.1 ** $digits, $digits, PHP_ROUND_HALF_DOWN);
+ }
+
+ return round($number + 0.5 * 0.1 ** $digits, $digits, PHP_ROUND_HALF_DOWN);
+ }
+
+ /**
+ * ROUNDDOWN.
+ *
+ * Rounds a number down to a specified number of decimal places
+ *
+ * @param float $number Number to round
+ * @param int $digits Number of digits to which you want to round $number
+ *
+ * @return float|string Rounded Number, or a string containing an error
+ */
+ public static function down($number, $digits)
+ {
+ try {
+ $number = Helpers::validateNumericNullBool($number);
+ $digits = (int) Helpers::validateNumericNullSubstitution($digits, null);
+ } catch (Exception $e) {
+ return $e->getMessage();
+ }
+
+ if ($number == 0.0) {
+ return 0.0;
+ }
+
+ if ($number < 0.0) {
+ return round($number + 0.5 * 0.1 ** $digits, $digits, PHP_ROUND_HALF_UP);
+ }
+
+ return round($number - 0.5 * 0.1 ** $digits, $digits, PHP_ROUND_HALF_UP);
+ }
+
+ /**
+ * MROUND.
+ *
+ * Rounds a number to the nearest multiple of a specified value
+ *
+ * @param mixed $number Expect float. Number to round.
+ * @param mixed $multiple Expect int. Multiple to which you want to round.
+ *
+ * @return float|string Rounded Number, or a string containing an error
+ */
+ public static function multiple($number, $multiple)
+ {
+ try {
+ $number = Helpers::validateNumericNullSubstitution($number, 0);
+ $multiple = Helpers::validateNumericNullSubstitution($multiple, null);
+ } catch (Exception $e) {
+ return $e->getMessage();
+ }
+
+ if ($number == 0 || $multiple == 0) {
+ return 0;
+ }
+ if ((Helpers::returnSign($number)) == (Helpers::returnSign($multiple))) {
+ $multiplier = 1 / $multiple;
+
+ return round($number * $multiplier) / $multiplier;
+ }
+
+ return Functions::NAN();
+ }
+
+ /**
+ * EVEN.
+ *
+ * Returns number rounded up to the nearest even integer.
+ * You can use this function for processing items that come in twos. For example,
+ * a packing crate accepts rows of one or two items. The crate is full when
+ * the number of items, rounded up to the nearest two, matches the crate's
+ * capacity.
+ *
+ * Excel Function:
+ * EVEN(number)
+ *
+ * @param float $number Number to round
+ *
+ * @return float|string Rounded Number, or a string containing an error
+ */
+ public static function even($number)
+ {
+ try {
+ $number = Helpers::validateNumericNullBool($number);
+ } catch (Exception $e) {
+ return $e->getMessage();
+ }
+
+ return Helpers::getEven($number);
+ }
+
+ /**
+ * ODD.
+ *
+ * Returns number rounded up to the nearest odd integer.
+ *
+ * @param float $number Number to round
+ *
+ * @return float|string Rounded Number, or a string containing an error
+ */
+ public static function odd($number)
+ {
+ try {
+ $number = Helpers::validateNumericNullBool($number);
+ } catch (Exception $e) {
+ return $e->getMessage();
+ }
+
+ $significance = Helpers::returnSign($number);
+ if ($significance == 0) {
+ return 1;
+ }
+
+ $result = ceil($number / $significance) * $significance;
+ if ($result == Helpers::getEven($result)) {
+ $result += $significance;
+ }
+
+ return $result;
+ }
}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/RoundDown.php b/src/PhpSpreadsheet/Calculation/MathTrig/RoundDown.php
deleted file mode 100644
index e843a6f9..00000000
--- a/src/PhpSpreadsheet/Calculation/MathTrig/RoundDown.php
+++ /dev/null
@@ -1,38 +0,0 @@
-getMessage();
- }
-
- if ($number == 0.0) {
- return 0.0;
- }
-
- if ($number < 0.0) {
- return round($number + 0.5 * 0.1 ** $digits, $digits, PHP_ROUND_HALF_UP);
- }
-
- return round($number - 0.5 * 0.1 ** $digits, $digits, PHP_ROUND_HALF_UP);
- }
-}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/RoundUp.php b/src/PhpSpreadsheet/Calculation/MathTrig/RoundUp.php
deleted file mode 100644
index c6704ad2..00000000
--- a/src/PhpSpreadsheet/Calculation/MathTrig/RoundUp.php
+++ /dev/null
@@ -1,38 +0,0 @@
-getMessage();
- }
-
- if ($number == 0.0) {
- return 0.0;
- }
-
- if ($number < 0.0) {
- return round($number - 0.5 * 0.1 ** $digits, $digits, PHP_ROUND_HALF_DOWN);
- }
-
- return round($number + 0.5 * 0.1 ** $digits, $digits, PHP_ROUND_HALF_DOWN);
- }
-}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Sec.php b/src/PhpSpreadsheet/Calculation/MathTrig/Sec.php
deleted file mode 100644
index d20b6375..00000000
--- a/src/PhpSpreadsheet/Calculation/MathTrig/Sec.php
+++ /dev/null
@@ -1,28 +0,0 @@
-getMessage();
- }
-
- return Helpers::verySmallDenominator(1.0, cos($angle));
- }
-}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Sech.php b/src/PhpSpreadsheet/Calculation/MathTrig/Sech.php
deleted file mode 100644
index 6bb0469f..00000000
--- a/src/PhpSpreadsheet/Calculation/MathTrig/Sech.php
+++ /dev/null
@@ -1,28 +0,0 @@
-getMessage();
- }
-
- return Helpers::verySmallDenominator(1.0, cosh($angle));
- }
-}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/SeriesSum.php b/src/PhpSpreadsheet/Calculation/MathTrig/SeriesSum.php
index 73238214..2ada9df4 100644
--- a/src/PhpSpreadsheet/Calculation/MathTrig/SeriesSum.php
+++ b/src/PhpSpreadsheet/Calculation/MathTrig/SeriesSum.php
@@ -2,7 +2,7 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
-use Exception;
+use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class SeriesSum
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Sign.php b/src/PhpSpreadsheet/Calculation/MathTrig/Sign.php
index 1b955a80..a48cf0f9 100644
--- a/src/PhpSpreadsheet/Calculation/MathTrig/Sign.php
+++ b/src/PhpSpreadsheet/Calculation/MathTrig/Sign.php
@@ -2,7 +2,7 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
-use Exception;
+use PhpOffice\PhpSpreadsheet\Calculation\Exception;
class Sign
{
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Sin.php b/src/PhpSpreadsheet/Calculation/MathTrig/Sin.php
deleted file mode 100644
index 9ca4acb0..00000000
--- a/src/PhpSpreadsheet/Calculation/MathTrig/Sin.php
+++ /dev/null
@@ -1,28 +0,0 @@
-getMessage();
- }
-
- return sin($angle);
- }
-}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Sinh.php b/src/PhpSpreadsheet/Calculation/MathTrig/Sinh.php
deleted file mode 100644
index 933b7d6d..00000000
--- a/src/PhpSpreadsheet/Calculation/MathTrig/Sinh.php
+++ /dev/null
@@ -1,28 +0,0 @@
-getMessage();
- }
-
- return sinh($angle);
- }
-}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Sqrt.php b/src/PhpSpreadsheet/Calculation/MathTrig/Sqrt.php
index aeb38234..8ead578e 100644
--- a/src/PhpSpreadsheet/Calculation/MathTrig/Sqrt.php
+++ b/src/PhpSpreadsheet/Calculation/MathTrig/Sqrt.php
@@ -2,7 +2,7 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
-use Exception;
+use PhpOffice\PhpSpreadsheet\Calculation\Exception;
class Sqrt
{
@@ -13,9 +13,9 @@ class Sqrt
*
* @param mixed $number Should be numeric
*
- * @return float|string Rounded number
+ * @return float|string square roor
*/
- public static function evaluate($number)
+ public static function sqrt($number)
{
try {
$number = Helpers::validateNumericNullBool($number);
@@ -25,4 +25,25 @@ class Sqrt
return Helpers::numberOrNan(sqrt($number));
}
+
+ /**
+ * SQRTPI.
+ *
+ * Returns the square root of (number * pi).
+ *
+ * @param float $number Number
+ *
+ * @return float|string Square Root of Number * Pi, or a string containing an error
+ */
+ public static function pi($number)
+ {
+ try {
+ $number = Helpers::validateNumericNullSubstitution($number, 0);
+ Helpers::validateNotNegative($number);
+ } catch (Exception $e) {
+ return $e->getMessage();
+ }
+
+ return sqrt($number * M_PI);
+ }
}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/SqrtPi.php b/src/PhpSpreadsheet/Calculation/MathTrig/SqrtPi.php
deleted file mode 100644
index 6ff79203..00000000
--- a/src/PhpSpreadsheet/Calculation/MathTrig/SqrtPi.php
+++ /dev/null
@@ -1,29 +0,0 @@
-getMessage();
- }
-
- return sqrt($number * M_PI);
- }
-}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Subtotal.php b/src/PhpSpreadsheet/Calculation/MathTrig/Subtotal.php
index 5477d936..2edb86f7 100644
--- a/src/PhpSpreadsheet/Calculation/MathTrig/Subtotal.php
+++ b/src/PhpSpreadsheet/Calculation/MathTrig/Subtotal.php
@@ -2,13 +2,17 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
-use Exception;
+use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\Statistical;
class Subtotal
{
- protected static function filterHiddenArgs($cellReference, $args)
+ /**
+ * @param mixed $cellReference
+ * @param mixed $args
+ */
+ protected static function filterHiddenArgs($cellReference, $args): array
{
return array_filter(
$args,
@@ -21,7 +25,11 @@ class Subtotal
);
}
- protected static function filterFormulaArgs($cellReference, $args)
+ /**
+ * @param mixed $cellReference
+ * @param mixed $args
+ */
+ protected static function filterFormulaArgs($cellReference, $args): array
{
return array_filter(
$args,
@@ -42,16 +50,17 @@ class Subtotal
);
}
+ /** @var callable[] */
private const CALL_FUNCTIONS = [
- 1 => [Statistical\Averages::class, 'AVERAGE'],
+ 1 => [Statistical\Averages::class, 'average'],
[Statistical\Counts::class, 'COUNT'], // 2
[Statistical\Counts::class, 'COUNTA'], // 3
- [Statistical\Maximum::class, 'MAX'], // 4
- [Statistical\Minimum::class, 'MIN'], // 5
- [Product::class, 'evaluate'], // 6
+ [Statistical\Maximum::class, 'max'], // 4
+ [Statistical\Minimum::class, 'min'], // 5
+ [Operations::class, 'product'], // 6
[Statistical\StandardDeviations::class, 'STDEV'], // 7
[Statistical\StandardDeviations::class, 'STDEVP'], // 8
- [Sum::class, 'funcSum'], // 9
+ [Sum::class, 'sumIgnoringStrings'], // 9
[Statistical\Variances::class, 'VAR'], // 10
[Statistical\Variances::class, 'VARP'], // 11
];
@@ -67,7 +76,7 @@ class Subtotal
* list
* Numbers 101 to 111 shadow the functions of 1 to 11
* but ignore any values in the range that are
- * in hidden rows or columns
+ * in hidden rows
* @param mixed[] $args A mixed data series of values
*
* @return float|string
@@ -91,7 +100,10 @@ class Subtotal
$aArgs = self::filterFormulaArgs($cellReference, $aArgs);
if (array_key_exists($subtotal, self::CALL_FUNCTIONS)) {
- return call_user_func_array(self::CALL_FUNCTIONS[$subtotal], $aArgs);
+ /** @var callable */
+ $call = self::CALL_FUNCTIONS[$subtotal];
+
+ return call_user_func_array($call, $aArgs);
}
return Functions::VALUE();
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Sum.php b/src/PhpSpreadsheet/Calculation/MathTrig/Sum.php
index cd29248b..741734d9 100644
--- a/src/PhpSpreadsheet/Calculation/MathTrig/Sum.php
+++ b/src/PhpSpreadsheet/Calculation/MathTrig/Sum.php
@@ -18,7 +18,7 @@ class Sum
*
* @return float|string
*/
- public static function funcSum(...$args)
+ public static function sumIgnoringStrings(...$args)
{
$returnValue = 0;
@@ -47,22 +47,69 @@ class Sum
*
* @return float|string
*/
- public static function funcSumNoStrings(...$args)
+ public static function sumErroringStrings(...$args)
{
$returnValue = 0;
-
// Loop through the arguments
- foreach (Functions::flattenArray($args) as $arg) {
+ $aArgs = Functions::flattenArrayIndexed($args);
+ foreach ($aArgs as $k => $arg) {
// Is it a numeric value?
- if (is_numeric($arg)) {
+ if (is_numeric($arg) || empty($arg)) {
+ if (is_string($arg)) {
+ $arg = (int) $arg;
+ }
$returnValue += $arg;
+ } elseif (is_bool($arg)) {
+ $returnValue += (int) $arg;
} elseif (Functions::isError($arg)) {
return $arg;
- } else {
+ // ignore non-numerics from cell, but fail as literals (except null)
+ } elseif ($arg !== null && !Functions::isCellValue($k)) {
return Functions::VALUE();
}
}
return $returnValue;
}
+
+ /**
+ * SUMPRODUCT.
+ *
+ * Excel Function:
+ * SUMPRODUCT(value1[,value2[, ...]])
+ *
+ * @param mixed ...$args Data values
+ *
+ * @return float|string The result, or a string containing an error
+ */
+ public static function product(...$args)
+ {
+ $arrayList = $args;
+
+ $wrkArray = Functions::flattenArray(array_shift($arrayList));
+ $wrkCellCount = count($wrkArray);
+
+ for ($i = 0; $i < $wrkCellCount; ++$i) {
+ if ((!is_numeric($wrkArray[$i])) || (is_string($wrkArray[$i]))) {
+ $wrkArray[$i] = 0;
+ }
+ }
+
+ foreach ($arrayList as $matrixData) {
+ $array2 = Functions::flattenArray($matrixData);
+ $count = count($array2);
+ if ($wrkCellCount != $count) {
+ return Functions::VALUE();
+ }
+
+ foreach ($array2 as $i => $val) {
+ if ((!is_numeric($val)) || (is_string($val))) {
+ $val = 0;
+ }
+ $wrkArray[$i] *= $val;
+ }
+ }
+
+ return array_sum($wrkArray);
+ }
}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/SumProduct.php b/src/PhpSpreadsheet/Calculation/MathTrig/SumProduct.php
deleted file mode 100644
index 7700d008..00000000
--- a/src/PhpSpreadsheet/Calculation/MathTrig/SumProduct.php
+++ /dev/null
@@ -1,49 +0,0 @@
- $val) {
- if ((!is_numeric($val)) || (is_string($val))) {
- $val = 0;
- }
- $wrkArray[$i] *= $val;
- }
- }
-
- return array_sum($wrkArray);
- }
-}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/SumSquares.php b/src/PhpSpreadsheet/Calculation/MathTrig/SumSquares.php
index a750b149..49fa6381 100644
--- a/src/PhpSpreadsheet/Calculation/MathTrig/SumSquares.php
+++ b/src/PhpSpreadsheet/Calculation/MathTrig/SumSquares.php
@@ -2,7 +2,7 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
-use Exception;
+use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class SumSquares
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Tan.php b/src/PhpSpreadsheet/Calculation/MathTrig/Tan.php
deleted file mode 100644
index 2b1a0ac0..00000000
--- a/src/PhpSpreadsheet/Calculation/MathTrig/Tan.php
+++ /dev/null
@@ -1,28 +0,0 @@
-getMessage();
- }
-
- return Helpers::verySmallDenominator(sin($angle), cos($angle));
- }
-}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Tanh.php b/src/PhpSpreadsheet/Calculation/MathTrig/Tanh.php
deleted file mode 100644
index f07f8748..00000000
--- a/src/PhpSpreadsheet/Calculation/MathTrig/Tanh.php
+++ /dev/null
@@ -1,28 +0,0 @@
-getMessage();
- }
-
- return tanh($angle);
- }
-}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Trig/Cosecant.php b/src/PhpSpreadsheet/Calculation/MathTrig/Trig/Cosecant.php
new file mode 100644
index 00000000..3038e6cc
--- /dev/null
+++ b/src/PhpSpreadsheet/Calculation/MathTrig/Trig/Cosecant.php
@@ -0,0 +1,49 @@
+getMessage();
+ }
+
+ return Helpers::verySmallDenominator(1.0, sin($angle));
+ }
+
+ /**
+ * CSCH.
+ *
+ * Returns the hyperbolic cosecant of an angle.
+ *
+ * @param float $angle Number
+ *
+ * @return float|string The hyperbolic cosecant of the angle
+ */
+ public static function csch($angle)
+ {
+ try {
+ $angle = Helpers::validateNumericNullBool($angle);
+ } catch (Exception $e) {
+ return $e->getMessage();
+ }
+
+ return Helpers::verySmallDenominator(1.0, sinh($angle));
+ }
+}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Trig/Cosine.php b/src/PhpSpreadsheet/Calculation/MathTrig/Trig/Cosine.php
new file mode 100644
index 00000000..6c69e126
--- /dev/null
+++ b/src/PhpSpreadsheet/Calculation/MathTrig/Trig/Cosine.php
@@ -0,0 +1,89 @@
+getMessage();
+ }
+
+ return cos($number);
+ }
+
+ /**
+ * COSH.
+ *
+ * Returns the result of builtin function cosh after validating args.
+ *
+ * @param mixed $number Should be numeric
+ *
+ * @return float|string hyperbolic cosine
+ */
+ public static function cosh($number)
+ {
+ try {
+ $number = Helpers::validateNumericNullBool($number);
+ } catch (Exception $e) {
+ return $e->getMessage();
+ }
+
+ return cosh($number);
+ }
+
+ /**
+ * ACOS.
+ *
+ * Returns the arccosine of a number.
+ *
+ * @param float $number Number
+ *
+ * @return float|string The arccosine of the number
+ */
+ public static function acos($number)
+ {
+ try {
+ $number = Helpers::validateNumericNullBool($number);
+ } catch (Exception $e) {
+ return $e->getMessage();
+ }
+
+ return Helpers::numberOrNan(acos($number));
+ }
+
+ /**
+ * ACOSH.
+ *
+ * Returns the arc inverse hyperbolic cosine of a number.
+ *
+ * @param float $number Number
+ *
+ * @return float|string The inverse hyperbolic cosine of the number, or an error string
+ */
+ public static function acosh($number)
+ {
+ try {
+ $number = Helpers::validateNumericNullBool($number);
+ } catch (Exception $e) {
+ return $e->getMessage();
+ }
+
+ return Helpers::numberOrNan(acosh($number));
+ }
+}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Trig/Cotangent.php b/src/PhpSpreadsheet/Calculation/MathTrig/Trig/Cotangent.php
new file mode 100644
index 00000000..1b796f50
--- /dev/null
+++ b/src/PhpSpreadsheet/Calculation/MathTrig/Trig/Cotangent.php
@@ -0,0 +1,91 @@
+getMessage();
+ }
+
+ return Helpers::verySmallDenominator(cos($angle), sin($angle));
+ }
+
+ /**
+ * COTH.
+ *
+ * Returns the hyperbolic cotangent of an angle.
+ *
+ * @param float $angle Number
+ *
+ * @return float|string The hyperbolic cotangent of the angle
+ */
+ public static function coth($angle)
+ {
+ try {
+ $angle = Helpers::validateNumericNullBool($angle);
+ } catch (Exception $e) {
+ return $e->getMessage();
+ }
+
+ return Helpers::verySmallDenominator(1.0, tanh($angle));
+ }
+
+ /**
+ * ACOT.
+ *
+ * Returns the arccotangent of a number.
+ *
+ * @param float $number Number
+ *
+ * @return float|string The arccotangent of the number
+ */
+ public static function acot($number)
+ {
+ try {
+ $number = Helpers::validateNumericNullBool($number);
+ } catch (Exception $e) {
+ return $e->getMessage();
+ }
+
+ return (M_PI / 2) - atan($number);
+ }
+
+ /**
+ * ACOTH.
+ *
+ * Returns the hyperbolic arccotangent of a number.
+ *
+ * @param float $number Number
+ *
+ * @return float|string The hyperbolic arccotangent of the number
+ */
+ public static function acoth($number)
+ {
+ try {
+ $number = Helpers::validateNumericNullBool($number);
+ } catch (Exception $e) {
+ return $e->getMessage();
+ }
+
+ $result = ($number === 1) ? NAN : (log(($number + 1) / ($number - 1)) / 2);
+
+ return Helpers::numberOrNan($result);
+ }
+}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Trig/Secant.php b/src/PhpSpreadsheet/Calculation/MathTrig/Trig/Secant.php
new file mode 100644
index 00000000..70299cb7
--- /dev/null
+++ b/src/PhpSpreadsheet/Calculation/MathTrig/Trig/Secant.php
@@ -0,0 +1,49 @@
+getMessage();
+ }
+
+ return Helpers::verySmallDenominator(1.0, cos($angle));
+ }
+
+ /**
+ * SECH.
+ *
+ * Returns the hyperbolic secant of an angle.
+ *
+ * @param float $angle Number
+ *
+ * @return float|string The hyperbolic secant of the angle
+ */
+ public static function sech($angle)
+ {
+ try {
+ $angle = Helpers::validateNumericNullBool($angle);
+ } catch (Exception $e) {
+ return $e->getMessage();
+ }
+
+ return Helpers::verySmallDenominator(1.0, cosh($angle));
+ }
+}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Trig/Sine.php b/src/PhpSpreadsheet/Calculation/MathTrig/Trig/Sine.php
new file mode 100644
index 00000000..2c6a8a07
--- /dev/null
+++ b/src/PhpSpreadsheet/Calculation/MathTrig/Trig/Sine.php
@@ -0,0 +1,89 @@
+getMessage();
+ }
+
+ return sin($angle);
+ }
+
+ /**
+ * SINH.
+ *
+ * Returns the result of builtin function sinh after validating args.
+ *
+ * @param mixed $angle Should be numeric
+ *
+ * @return float|string hyperbolic sine
+ */
+ public static function sinh($angle)
+ {
+ try {
+ $angle = Helpers::validateNumericNullBool($angle);
+ } catch (Exception $e) {
+ return $e->getMessage();
+ }
+
+ return sinh($angle);
+ }
+
+ /**
+ * ASIN.
+ *
+ * Returns the arcsine of a number.
+ *
+ * @param float $number Number
+ *
+ * @return float|string The arcsine of the number
+ */
+ public static function asin($number)
+ {
+ try {
+ $number = Helpers::validateNumericNullBool($number);
+ } catch (Exception $e) {
+ return $e->getMessage();
+ }
+
+ return Helpers::numberOrNan(asin($number));
+ }
+
+ /**
+ * ASINH.
+ *
+ * Returns the inverse hyperbolic sine of a number.
+ *
+ * @param float $number Number
+ *
+ * @return float|string The inverse hyperbolic sine of the number
+ */
+ public static function asinh($number)
+ {
+ try {
+ $number = Helpers::validateNumericNullBool($number);
+ } catch (Exception $e) {
+ return $e->getMessage();
+ }
+
+ return Helpers::numberOrNan(asinh($number));
+ }
+}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Trig/Tangent.php b/src/PhpSpreadsheet/Calculation/MathTrig/Trig/Tangent.php
new file mode 100644
index 00000000..6cd235fb
--- /dev/null
+++ b/src/PhpSpreadsheet/Calculation/MathTrig/Trig/Tangent.php
@@ -0,0 +1,127 @@
+getMessage();
+ }
+
+ return Helpers::verySmallDenominator(sin($angle), cos($angle));
+ }
+
+ /**
+ * TANH.
+ *
+ * Returns the result of builtin function sinh after validating args.
+ *
+ * @param mixed $angle Should be numeric
+ *
+ * @return float|string hyperbolic tangent
+ */
+ public static function tanh($angle)
+ {
+ try {
+ $angle = Helpers::validateNumericNullBool($angle);
+ } catch (Exception $e) {
+ return $e->getMessage();
+ }
+
+ return tanh($angle);
+ }
+
+ /**
+ * ATAN.
+ *
+ * Returns the arctangent of a number.
+ *
+ * @param float $number Number
+ *
+ * @return float|string The arctangent of the number
+ */
+ public static function atan($number)
+ {
+ try {
+ $number = Helpers::validateNumericNullBool($number);
+ } catch (Exception $e) {
+ return $e->getMessage();
+ }
+
+ return Helpers::numberOrNan(atan($number));
+ }
+
+ /**
+ * ATANH.
+ *
+ * Returns the inverse hyperbolic tangent of a number.
+ *
+ * @param float $number Number
+ *
+ * @return float|string The inverse hyperbolic tangent of the number
+ */
+ public static function atanh($number)
+ {
+ try {
+ $number = Helpers::validateNumericNullBool($number);
+ } catch (Exception $e) {
+ return $e->getMessage();
+ }
+
+ return Helpers::numberOrNan(atanh($number));
+ }
+
+ /**
+ * ATAN2.
+ *
+ * This function calculates the arc tangent of the two variables x and y. It is similar to
+ * calculating the arc tangent of y ÷ x, except that the signs of both arguments are used
+ * to determine the quadrant of the result.
+ * The arctangent is the angle from the x-axis to a line containing the origin (0, 0) and a
+ * point with coordinates (xCoordinate, yCoordinate). The angle is given in radians between
+ * -pi and pi, excluding -pi.
+ *
+ * Note that the Excel ATAN2() function accepts its arguments in the reverse order to the standard
+ * PHP atan2() function, so we need to reverse them here before calling the PHP atan() function.
+ *
+ * Excel Function:
+ * ATAN2(xCoordinate,yCoordinate)
+ *
+ * @param mixed $xCoordinate should be float, the x-coordinate of the point
+ * @param mixed $yCoordinate should be float, the y-coordinate of the point
+ *
+ * @return float|string the inverse tangent of the specified x- and y-coordinates, or a string containing an error
+ */
+ public static function atan2($xCoordinate, $yCoordinate)
+ {
+ try {
+ $xCoordinate = Helpers::validateNumericNullBool($xCoordinate);
+ $yCoordinate = Helpers::validateNumericNullBool($yCoordinate);
+ } catch (Exception $e) {
+ return $e->getMessage();
+ }
+
+ if (($xCoordinate == 0) && ($yCoordinate == 0)) {
+ return Functions::DIV0();
+ }
+
+ return atan2($yCoordinate, $xCoordinate);
+ }
+}
diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Trunc.php b/src/PhpSpreadsheet/Calculation/MathTrig/Trunc.php
index 57c389e6..4b3670f6 100644
--- a/src/PhpSpreadsheet/Calculation/MathTrig/Trunc.php
+++ b/src/PhpSpreadsheet/Calculation/MathTrig/Trunc.php
@@ -2,7 +2,7 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
-use Exception;
+use PhpOffice\PhpSpreadsheet\Calculation\Exception;
class Trunc
{
@@ -30,7 +30,7 @@ class Trunc
// Truncate
$adjust = 10 ** $digits;
- if (($digits > 0) && (rtrim((int) ((abs($value) - abs((int) $value)) * $adjust), '0') < $adjust / 10)) {
+ if (($digits > 0) && (rtrim((string) (int) ((abs($value) - abs((int) $value)) * $adjust), '0') < $adjust / 10)) {
return $value;
}
diff --git a/src/PhpSpreadsheet/Calculation/Statistical.php b/src/PhpSpreadsheet/Calculation/Statistical.php
index 0f5355b9..6c184f56 100644
--- a/src/PhpSpreadsheet/Calculation/Statistical.php
+++ b/src/PhpSpreadsheet/Calculation/Statistical.php
@@ -13,12 +13,14 @@ use PhpOffice\PhpSpreadsheet\Calculation\Statistical\StandardDeviations;
use PhpOffice\PhpSpreadsheet\Calculation\Statistical\Trends;
use PhpOffice\PhpSpreadsheet\Calculation\Statistical\Variances;
+/**
+ * @deprecated 1.18.0
+ */
class Statistical
{
const LOG_GAMMA_X_MAX_VALUE = 2.55e305;
const EPS = 2.22e-16;
const MAX_VALUE = 1.2e308;
- const MAX_ITERATIONS = 256;
const SQRT2PI = 2.5066282746310005024157652848110452530069867406099;
/**
@@ -428,48 +430,18 @@ class Statistical
* Excel Function:
* DEVSQ(value1[,value2[, ...]])
*
+ * @Deprecated 1.18.0
+ *
+ * @see Statistical\Deviations::sumSquares()
+ * Use the sumSquares() method in the Statistical\Deviations class instead
+ *
* @param mixed ...$args Data values
*
* @return float|string
*/
public static function DEVSQ(...$args)
{
- $aArgs = Functions::flattenArrayIndexed($args);
-
- // Return value
- $returnValue = null;
-
- $aMean = Averages::average($aArgs);
- if ($aMean != Functions::DIV0()) {
- $aCount = -1;
- foreach ($aArgs as $k => $arg) {
- // Is it a numeric value?
- if (
- (is_bool($arg)) &&
- ((!Functions::isCellValue($k)) ||
- (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_OPENOFFICE))
- ) {
- $arg = (int) $arg;
- }
- if ((is_numeric($arg)) && (!is_string($arg))) {
- if ($returnValue === null) {
- $returnValue = ($arg - $aMean) ** 2;
- } else {
- $returnValue += ($arg - $aMean) ** 2;
- }
- ++$aCount;
- }
- }
-
- // Return
- if ($returnValue === null) {
- return Functions::NAN();
- }
-
- return $returnValue;
- }
-
- return Functions::NA();
+ return Statistical\Deviations::sumSquares(...$args);
}
/**
@@ -671,18 +643,18 @@ class Statistical
* Calculates the probability that a member of a standard normal population will fall between
* the mean and z standard deviations from the mean.
*
+ * @Deprecated 1.18.0
+ *
+ * @see Statistical\Distributions\StandardNormal::gauss()
+ * Use the gauss() method in the Statistical\Distributions\StandardNormal class instead
+ *
* @param float $value
*
* @return float|string The result, or a string containing an error
*/
public static function GAUSS($value)
{
- $value = Functions::flattenSingleValue($value);
- if (!is_numeric($value)) {
- return Functions::VALUE();
- }
-
- return Statistical\Distributions\Normal::distribution($value, 0, 1, true) - 0.5;
+ return Statistical\Distributions\StandardNormal::gauss($value);
}
/**
@@ -695,23 +667,18 @@ class Statistical
* Excel Function:
* GEOMEAN(value1[,value2[, ...]])
*
+ * @Deprecated 1.18.0
+ *
+ * @see Statistical\Averages\Mean::geometric()
+ * Use the geometric() method in the Statistical\Averages\Mean class instead
+ *
* @param mixed ...$args Data values
*
* @return float|string
*/
public static function GEOMEAN(...$args)
{
- $aArgs = Functions::flattenArray($args);
-
- $aMean = MathTrig\Product::evaluate($aArgs);
- if (is_numeric($aMean) && ($aMean > 0)) {
- $aCount = Counts::COUNT($aArgs);
- if (Minimum::MIN($aArgs) > 0) {
- return $aMean ** (1 / $aCount);
- }
- }
-
- return Functions::NAN();
+ return Statistical\Averages\Mean::geometric(...$args);
}
/**
@@ -745,38 +712,18 @@ class Statistical
* Excel Function:
* HARMEAN(value1[,value2[, ...]])
*
+ * @Deprecated 1.18.0
+ *
+ * @see Statistical\Averages\Mean::harmonic()
+ * Use the harmonic() method in the Statistical\Averages\Mean class instead
+ *
* @param mixed ...$args Data values
*
* @return float|string
*/
public static function HARMEAN(...$args)
{
- // Return value
- $returnValue = 0;
-
- // Loop through arguments
- $aArgs = Functions::flattenArray($args);
- if (Minimum::MIN($aArgs) < 0) {
- return Functions::NAN();
- }
- $aCount = 0;
- foreach ($aArgs as $arg) {
- // Is it a numeric value?
- if ((is_numeric($arg)) && (!is_string($arg))) {
- if ($arg <= 0) {
- return Functions::NAN();
- }
- $returnValue += (1 / $arg);
- ++$aCount;
- }
- }
-
- // Return
- if ($aCount > 0) {
- return 1 / ($returnValue / $aCount);
- }
-
- return Functions::NA();
+ return Statistical\Averages\Mean::harmonic(...$args);
}
/**
@@ -835,40 +782,18 @@ class Statistical
* kurtosis indicates a relatively peaked distribution. Negative kurtosis indicates a
* relatively flat distribution.
*
+ * @Deprecated 1.18.0
+ *
+ * @see Statistical\Deviations::kurtosis()
+ * Use the kurtosis() method in the Statistical\Deviations class instead
+ *
* @param array ...$args Data Series
*
* @return float|string
*/
public static function KURT(...$args)
{
- $aArgs = Functions::flattenArrayIndexed($args);
- $mean = Averages::average($aArgs);
- $stdDev = StandardDeviations::STDEV($aArgs);
-
- if ($stdDev > 0) {
- $count = $summer = 0;
- // Loop through arguments
- foreach ($aArgs as $k => $arg) {
- if (
- (is_bool($arg)) &&
- (!Functions::isMatrixValue($k))
- ) {
- } else {
- // Is it a numeric value?
- if ((is_numeric($arg)) && (!is_string($arg))) {
- $summer += (($arg - $mean) / $stdDev) ** 4;
- ++$count;
- }
- }
- }
-
- // Return
- if ($count > 3) {
- return $summer * ($count * ($count + 1) / (($count - 1) * ($count - 2) * ($count - 3))) - (3 * ($count - 1) ** 2 / (($count - 2) * ($count - 3)));
- }
- }
-
- return Functions::DIV0();
+ return Statistical\Deviations::kurtosis(...$args);
}
/**
@@ -880,37 +805,18 @@ class Statistical
* Excel Function:
* LARGE(value1[,value2[, ...]],entry)
*
+ * @Deprecated 1.18.0
+ *
+ * @see Statistical\Size::large()
+ * Use the large() method in the Statistical\Size class instead
+ *
* @param mixed $args Data values
*
* @return float|string The result, or a string containing an error
*/
public static function LARGE(...$args)
{
- $aArgs = Functions::flattenArray($args);
- $entry = array_pop($aArgs);
-
- if ((is_numeric($entry)) && (!is_string($entry))) {
- $entry = (int) floor($entry);
-
- // Calculate
- $mArgs = [];
- foreach ($aArgs as $arg) {
- // Is it a numeric value?
- if ((is_numeric($arg)) && (!is_string($arg))) {
- $mArgs[] = $arg;
- }
- }
- $count = Counts::COUNT($mArgs);
- --$entry;
- if (($entry < 0) || ($entry >= $count) || ($count == 0)) {
- return Functions::NAN();
- }
- rsort($mArgs);
-
- return $mArgs[$entry];
- }
-
- return Functions::VALUE();
+ return Statistical\Size::large(...$args);
}
/**
@@ -1036,20 +942,20 @@ class Statistical
* with negative numbers considered smaller than positive numbers.
*
* Excel Function:
- * MAX(value1[,value2[, ...]])
+ * max(value1[,value2[, ...]])
*
* @Deprecated 1.17.0
*
- * @see Statistical\Maximum::MAX()
- * Use the MAX() method in the Statistical\Maximum class instead
- *
* @param mixed ...$args Data values
*
* @return float
+ *
+ *@see Statistical\Maximum::max()
+ * Use the MAX() method in the Statistical\Maximum class instead
*/
public static function MAX(...$args)
{
- return Maximum::MAX(...$args);
+ return Maximum::max(...$args);
}
/**
@@ -1058,20 +964,20 @@ class Statistical
* Returns the greatest value in a list of arguments, including numbers, text, and logical values
*
* Excel Function:
- * MAXA(value1[,value2[, ...]])
+ * maxA(value1[,value2[, ...]])
*
* @Deprecated 1.17.0
*
- * @see Statistical\Maximum::MAXA()
- * Use the MAXA() method in the Statistical\Maximum class instead
- *
* @param mixed ...$args Data values
*
* @return float
+ *
+ *@see Statistical\Maximum::maxA()
+ * Use the MAXA() method in the Statistical\Maximum class instead
*/
public static function MAXA(...$args)
{
- return Maximum::MAXA(...$args);
+ return Maximum::maxA(...$args);
}
/**
@@ -1129,16 +1035,16 @@ class Statistical
*
* @Deprecated 1.17.0
*
- * @see Statistical\Minimum::MIN()
- * Use the MIN() method in the Statistical\Minimum class instead
- *
* @param mixed ...$args Data values
*
* @return float
+ *
+ *@see Statistical\Minimum::min()
+ * Use the min() method in the Statistical\Minimum class instead
*/
public static function MIN(...$args)
{
- return Minimum::MIN(...$args);
+ return Minimum::min(...$args);
}
/**
@@ -1151,16 +1057,16 @@ class Statistical
*
* @Deprecated 1.17.0
*
- * @see Statistical\Minimum::MINA()
- * Use the MINA() method in the Statistical\Minimum class instead
- *
* @param mixed ...$args Data values
*
* @return float
+ *
+ *@see Statistical\Minimum::minA()
+ * Use the minA() method in the Statistical\Minimum class instead
*/
public static function MINA(...$args)
{
- return Minimum::MINA(...$args);
+ return Minimum::minA(...$args);
}
/**
@@ -1503,40 +1409,18 @@ class Statistical
* asymmetric tail extending toward more positive values. Negative skewness indicates a
* distribution with an asymmetric tail extending toward more negative values.
*
+ * @Deprecated 1.18.0
+ *
+ * @see Statistical\Deviations::skew()
+ * Use the skew() method in the Statistical\Deviations class instead
+ *
* @param array ...$args Data Series
*
* @return float|string The result, or a string containing an error
*/
public static function SKEW(...$args)
{
- $aArgs = Functions::flattenArrayIndexed($args);
- $mean = Averages::average($aArgs);
- $stdDev = StandardDeviations::STDEV($aArgs);
-
- if ($stdDev === 0.0 || is_string($stdDev)) {
- return Functions::DIV0();
- }
-
- $count = $summer = 0;
- // Loop through arguments
- foreach ($aArgs as $k => $arg) {
- if ((is_bool($arg)) && (!Functions::isMatrixValue($k))) {
- } elseif (!is_numeric($arg)) {
- return Functions::VALUE();
- } else {
- // Is it a numeric value?
- if ((is_numeric($arg)) && (!is_string($arg))) {
- $summer += (($arg - $mean) / $stdDev) ** 3;
- ++$count;
- }
- }
- }
-
- if ($count > 2) {
- return $summer * ($count / (($count - 1) * ($count - 2)));
- }
-
- return Functions::DIV0();
+ return Statistical\Deviations::skew(...$args);
}
/**
@@ -1568,38 +1452,18 @@ class Statistical
* Excel Function:
* SMALL(value1[,value2[, ...]],entry)
*
+ * @Deprecated 1.18.0
+ *
+ * @see Statistical\Size::small()
+ * Use the small() method in the Statistical\Size class instead
+ *
* @param mixed $args Data values
*
* @return float|string The result, or a string containing an error
*/
public static function SMALL(...$args)
{
- $aArgs = Functions::flattenArray($args);
-
- // Calculate
- $entry = array_pop($aArgs);
-
- if ((is_numeric($entry)) && (!is_string($entry))) {
- $entry = (int) floor($entry);
-
- $mArgs = [];
- foreach ($aArgs as $arg) {
- // Is it a numeric value?
- if ((is_numeric($arg)) && (!is_string($arg))) {
- $mArgs[] = $arg;
- }
- }
- $count = Counts::COUNT($mArgs);
- --$entry;
- if (($entry < 0) || ($entry >= $count) || ($count == 0)) {
- return Functions::NAN();
- }
- sort($mArgs);
-
- return $mArgs[$entry];
- }
-
- return Functions::VALUE();
+ return Statistical\Size::small(...$args);
}
/**
@@ -1607,6 +1471,11 @@ class Statistical
*
* Returns a normalized value from a distribution characterized by mean and standard_dev.
*
+ * @Deprecated 1.18.0
+ *
+ * @see Statistical\Standardize::execute()
+ * Use the execute() method in the Statistical\Standardize class instead
+ *
* @param float $value Value to normalize
* @param float $mean Mean Value
* @param float $stdDev Standard Deviation
@@ -1615,19 +1484,7 @@ class Statistical
*/
public static function STANDARDIZE($value, $mean, $stdDev)
{
- $value = Functions::flattenSingleValue($value);
- $mean = Functions::flattenSingleValue($mean);
- $stdDev = Functions::flattenSingleValue($stdDev);
-
- if ((is_numeric($value)) && (is_numeric($mean)) && (is_numeric($stdDev))) {
- if ($stdDev <= 0) {
- return Functions::NAN();
- }
-
- return ($value - $mean) / $stdDev;
- }
-
- return Functions::VALUE();
+ return Statistical\Standardize::execute($value, $mean, $stdDev);
}
/**
@@ -1812,42 +1669,18 @@ class Statistical
* Excel Function:
* TRIMEAN(value1[,value2[, ...]], $discard)
*
+ * @Deprecated 1.18.0
+ *
+ *@see Statistical\Averages\Mean::trim()
+ * Use the trim() method in the Statistical\Averages\Mean class instead
+ *
* @param mixed $args Data values
*
* @return float|string
*/
public static function TRIMMEAN(...$args)
{
- $aArgs = Functions::flattenArray($args);
-
- // Calculate
- $percent = array_pop($aArgs);
-
- if ((is_numeric($percent)) && (!is_string($percent))) {
- if (($percent < 0) || ($percent > 1)) {
- return Functions::NAN();
- }
-
- $mArgs = [];
- foreach ($aArgs as $arg) {
- // Is it a numeric value?
- if ((is_numeric($arg)) && (!is_string($arg))) {
- $mArgs[] = $arg;
- }
- }
-
- $discard = floor(Counts::COUNT($mArgs) * $percent / 2);
- sort($mArgs);
-
- for ($i = 0; $i < $discard; ++$i) {
- array_pop($mArgs);
- array_shift($mArgs);
- }
-
- return Averages::average($mArgs);
- }
-
- return Functions::VALUE();
+ return Statistical\Averages\Mean::trim(...$args);
}
/**
@@ -1860,12 +1693,12 @@ class Statistical
*
* @Deprecated 1.17.0
*
+ *@see Statistical\Variances::VAR()
+ * Use the VAR() method in the Statistical\Variances class instead
+ *
* @param mixed ...$args Data values
*
* @return float|string (string if result is an error)
- *
- *@see Statistical\Variances::VAR()
- * Use the VAR() method in the Statistical\Variances class instead
*/
public static function VARFunc(...$args)
{
diff --git a/src/PhpSpreadsheet/Calculation/Statistical/Averages/Mean.php b/src/PhpSpreadsheet/Calculation/Statistical/Averages/Mean.php
new file mode 100644
index 00000000..d4d0c7ee
--- /dev/null
+++ b/src/PhpSpreadsheet/Calculation/Statistical/Averages/Mean.php
@@ -0,0 +1,131 @@
+ 0)) {
+ $aCount = Counts::COUNT($aArgs);
+ if (Minimum::min($aArgs) > 0) {
+ return $aMean ** (1 / $aCount);
+ }
+ }
+
+ return Functions::NAN();
+ }
+
+ /**
+ * HARMEAN.
+ *
+ * Returns the harmonic mean of a data set. The harmonic mean is the reciprocal of the
+ * arithmetic mean of reciprocals.
+ *
+ * Excel Function:
+ * HARMEAN(value1[,value2[, ...]])
+ *
+ * @param mixed ...$args Data values
+ *
+ * @return float|string
+ */
+ public static function harmonic(...$args)
+ {
+ // Loop through arguments
+ $aArgs = Functions::flattenArray($args);
+ if (Minimum::min($aArgs) < 0) {
+ return Functions::NAN();
+ }
+
+ $returnValue = 0;
+ $aCount = 0;
+ foreach ($aArgs as $arg) {
+ // Is it a numeric value?
+ if ((is_numeric($arg)) && (!is_string($arg))) {
+ if ($arg <= 0) {
+ return Functions::NAN();
+ }
+ $returnValue += (1 / $arg);
+ ++$aCount;
+ }
+ }
+
+ // Return
+ if ($aCount > 0) {
+ return 1 / ($returnValue / $aCount);
+ }
+
+ return Functions::NA();
+ }
+
+ /**
+ * TRIMMEAN.
+ *
+ * Returns the mean of the interior of a data set. TRIMMEAN calculates the mean
+ * taken by excluding a percentage of data points from the top and bottom tails
+ * of a data set.
+ *
+ * Excel Function:
+ * TRIMEAN(value1[,value2[, ...]], $discard)
+ *
+ * @param mixed $args Data values
+ *
+ * @return float|string
+ */
+ public static function trim(...$args)
+ {
+ $aArgs = Functions::flattenArray($args);
+
+ // Calculate
+ $percent = array_pop($aArgs);
+
+ if ((is_numeric($percent)) && (!is_string($percent))) {
+ if (($percent < 0) || ($percent > 1)) {
+ return Functions::NAN();
+ }
+
+ $mArgs = [];
+ foreach ($aArgs as $arg) {
+ // Is it a numeric value?
+ if ((is_numeric($arg)) && (!is_string($arg))) {
+ $mArgs[] = $arg;
+ }
+ }
+
+ $discard = floor(Counts::COUNT($mArgs) * $percent / 2);
+ sort($mArgs);
+
+ for ($i = 0; $i < $discard; ++$i) {
+ array_pop($mArgs);
+ array_shift($mArgs);
+ }
+
+ return Averages::average($mArgs);
+ }
+
+ return Functions::VALUE();
+ }
+}
diff --git a/src/PhpSpreadsheet/Calculation/Statistical/Deviations.php b/src/PhpSpreadsheet/Calculation/Statistical/Deviations.php
new file mode 100644
index 00000000..1b64fe2c
--- /dev/null
+++ b/src/PhpSpreadsheet/Calculation/Statistical/Deviations.php
@@ -0,0 +1,141 @@
+ $arg) {
+ // Is it a numeric value?
+ if (
+ (is_bool($arg)) &&
+ ((!Functions::isCellValue($k)) ||
+ (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_OPENOFFICE))
+ ) {
+ $arg = (int) $arg;
+ }
+ if ((is_numeric($arg)) && (!is_string($arg))) {
+ $returnValue += ($arg - $aMean) ** 2;
+ ++$aCount;
+ }
+ }
+
+ return $aCount === 0 ? Functions::VALUE() : $returnValue;
+ }
+
+ /**
+ * KURT.
+ *
+ * Returns the kurtosis of a data set. Kurtosis characterizes the relative peakedness
+ * or flatness of a distribution compared with the normal distribution. Positive
+ * kurtosis indicates a relatively peaked distribution. Negative kurtosis indicates a
+ * relatively flat distribution.
+ *
+ * @param array ...$args Data Series
+ *
+ * @return float|string
+ */
+ public static function kurtosis(...$args)
+ {
+ $aArgs = Functions::flattenArrayIndexed($args);
+ $mean = Averages::average($aArgs);
+ if (!is_numeric($mean)) {
+ return Functions::DIV0();
+ }
+ $stdDev = StandardDeviations::STDEV($aArgs);
+
+ if ($stdDev > 0) {
+ $count = $summer = 0;
+
+ foreach ($aArgs as $k => $arg) {
+ if ((is_bool($arg)) && (!Functions::isMatrixValue($k))) {
+ } else {
+ // Is it a numeric value?
+ if ((is_numeric($arg)) && (!is_string($arg))) {
+ $summer += (($arg - $mean) / $stdDev) ** 4;
+ ++$count;
+ }
+ }
+ }
+
+ if ($count > 3) {
+ return $summer * ($count * ($count + 1) /
+ (($count - 1) * ($count - 2) * ($count - 3))) - (3 * ($count - 1) ** 2 /
+ (($count - 2) * ($count - 3)));
+ }
+ }
+
+ return Functions::DIV0();
+ }
+
+ /**
+ * SKEW.
+ *
+ * Returns the skewness of a distribution. Skewness characterizes the degree of asymmetry
+ * of a distribution around its mean. Positive skewness indicates a distribution with an
+ * asymmetric tail extending toward more positive values. Negative skewness indicates a
+ * distribution with an asymmetric tail extending toward more negative values.
+ *
+ * @param array ...$args Data Series
+ *
+ * @return float|string The result, or a string containing an error
+ */
+ public static function skew(...$args)
+ {
+ $aArgs = Functions::flattenArrayIndexed($args);
+ $mean = Averages::average($aArgs);
+ if (!is_numeric($mean)) {
+ return Functions::DIV0();
+ }
+ $stdDev = StandardDeviations::STDEV($aArgs);
+ if ($stdDev === 0.0 || is_string($stdDev)) {
+ return Functions::DIV0();
+ }
+
+ $count = $summer = 0;
+ // Loop through arguments
+ foreach ($aArgs as $k => $arg) {
+ if ((is_bool($arg)) && (!Functions::isMatrixValue($k))) {
+ } elseif (!is_numeric($arg)) {
+ return Functions::VALUE();
+ } else {
+ // Is it a numeric value?
+ if ((is_numeric($arg)) && (!is_string($arg))) {
+ $summer += (($arg - $mean) / $stdDev) ** 3;
+ ++$count;
+ }
+ }
+ }
+
+ if ($count > 2) {
+ return $summer * ($count / (($count - 1) * ($count - 2)));
+ }
+
+ return Functions::DIV0();
+ }
+}
diff --git a/src/PhpSpreadsheet/Calculation/Statistical/Distributions/Poisson.php b/src/PhpSpreadsheet/Calculation/Statistical/Distributions/Poisson.php
index 3456efcc..e7252e02 100644
--- a/src/PhpSpreadsheet/Calculation/Statistical/Distributions/Poisson.php
+++ b/src/PhpSpreadsheet/Calculation/Statistical/Distributions/Poisson.php
@@ -42,12 +42,12 @@ class Poisson
$summer = 0;
$floor = floor($value);
for ($i = 0; $i <= $floor; ++$i) {
- $summer += $mean ** $i / MathTrig\Fact::evaluate($i);
+ $summer += $mean ** $i / MathTrig\Factorial::fact($i);
}
return exp(0 - $mean) * $summer;
}
- return (exp(0 - $mean) * $mean ** $value) / MathTrig\Fact::evaluate($value);
+ return (exp(0 - $mean) * $mean ** $value) / MathTrig\Factorial::fact($value);
}
}
diff --git a/src/PhpSpreadsheet/Calculation/Statistical/Distributions/StandardNormal.php b/src/PhpSpreadsheet/Calculation/Statistical/Distributions/StandardNormal.php
index 0dde2006..d10f02a5 100644
--- a/src/PhpSpreadsheet/Calculation/Statistical/Distributions/StandardNormal.php
+++ b/src/PhpSpreadsheet/Calculation/Statistical/Distributions/StandardNormal.php
@@ -55,6 +55,26 @@ class StandardNormal
return Normal::inverse($value, 0, 1);
}
+ /**
+ * GAUSS.
+ *
+ * Calculates the probability that a member of a standard normal population will fall between
+ * the mean and z standard deviations from the mean.
+ *
+ * @param mixed $value
+ *
+ * @return float|string The result, or a string containing an error
+ */
+ public static function gauss($value)
+ {
+ $value = Functions::flattenSingleValue($value);
+ if (!is_numeric($value)) {
+ return Functions::VALUE();
+ }
+
+ return self::distribution($value, true) - 0.5;
+ }
+
/**
* ZTEST.
*
diff --git a/src/PhpSpreadsheet/Calculation/Statistical/Maximum.php b/src/PhpSpreadsheet/Calculation/Statistical/Maximum.php
index 6d361e03..3f8436ff 100644
--- a/src/PhpSpreadsheet/Calculation/Statistical/Maximum.php
+++ b/src/PhpSpreadsheet/Calculation/Statistical/Maximum.php
@@ -19,7 +19,7 @@ class Maximum extends MaxMinBase
*
* @return float
*/
- public static function MAX(...$args)
+ public static function max(...$args)
{
$returnValue = null;
@@ -53,7 +53,7 @@ class Maximum extends MaxMinBase
*
* @return float
*/
- public static function MAXA(...$args)
+ public static function maxA(...$args)
{
$returnValue = null;
diff --git a/src/PhpSpreadsheet/Calculation/Statistical/Minimum.php b/src/PhpSpreadsheet/Calculation/Statistical/Minimum.php
index bd46882e..596aad78 100644
--- a/src/PhpSpreadsheet/Calculation/Statistical/Minimum.php
+++ b/src/PhpSpreadsheet/Calculation/Statistical/Minimum.php
@@ -19,7 +19,7 @@ class Minimum extends MaxMinBase
*
* @return float
*/
- public static function MIN(...$args)
+ public static function min(...$args)
{
$returnValue = null;
@@ -53,7 +53,7 @@ class Minimum extends MaxMinBase
*
* @return float
*/
- public static function MINA(...$args)
+ public static function minA(...$args)
{
$returnValue = null;
diff --git a/src/PhpSpreadsheet/Calculation/Statistical/Permutations.php b/src/PhpSpreadsheet/Calculation/Statistical/Permutations.php
index ab2e14dd..0bad2a88 100644
--- a/src/PhpSpreadsheet/Calculation/Statistical/Permutations.php
+++ b/src/PhpSpreadsheet/Calculation/Statistical/Permutations.php
@@ -38,7 +38,7 @@ class Permutations
return Functions::NAN();
}
- return (int) round(MathTrig\Fact::evaluate($numObjs) / MathTrig\Fact::evaluate($numObjs - $numInSet));
+ return (int) round(MathTrig\Factorial::fact($numObjs) / MathTrig\Factorial::fact($numObjs - $numInSet));
}
/**
diff --git a/src/PhpSpreadsheet/Calculation/Statistical/Size.php b/src/PhpSpreadsheet/Calculation/Statistical/Size.php
new file mode 100644
index 00000000..de4b6d6c
--- /dev/null
+++ b/src/PhpSpreadsheet/Calculation/Statistical/Size.php
@@ -0,0 +1,96 @@
+= $count) || ($count == 0)) {
+ return Functions::NAN();
+ }
+ rsort($mArgs);
+
+ return $mArgs[$entry];
+ }
+
+ return Functions::VALUE();
+ }
+
+ /**
+ * SMALL.
+ *
+ * Returns the nth smallest value in a data set. You can use this function to
+ * select a value based on its relative standing.
+ *
+ * Excel Function:
+ * SMALL(value1[,value2[, ...]],entry)
+ *
+ * @param mixed $args Data values
+ *
+ * @return float|string The result, or a string containing an error
+ */
+ public static function small(...$args)
+ {
+ $aArgs = Functions::flattenArray($args);
+
+ $entry = array_pop($aArgs);
+
+ if ((is_numeric($entry)) && (!is_string($entry))) {
+ $entry = (int) floor($entry);
+
+ $mArgs = self::filter($aArgs);
+ $count = Counts::COUNT($mArgs);
+ --$entry;
+ if (($entry < 0) || ($entry >= $count) || ($count == 0)) {
+ return Functions::NAN();
+ }
+ sort($mArgs);
+
+ return $mArgs[$entry];
+ }
+
+ return Functions::VALUE();
+ }
+
+ /**
+ * @param mixed[] $args Data values
+ */
+ protected static function filter(array $args): array
+ {
+ $mArgs = [];
+
+ foreach ($args as $arg) {
+ // Is it a numeric value?
+ if ((is_numeric($arg)) && (!is_string($arg))) {
+ $mArgs[] = $arg;
+ }
+ }
+
+ return $mArgs;
+ }
+}
diff --git a/src/PhpSpreadsheet/Calculation/Statistical/Standardize.php b/src/PhpSpreadsheet/Calculation/Statistical/Standardize.php
new file mode 100644
index 00000000..2f3c58e7
--- /dev/null
+++ b/src/PhpSpreadsheet/Calculation/Statistical/Standardize.php
@@ -0,0 +1,41 @@
+getMessage();
+ }
+
+ if ($stdDev <= 0) {
+ return Functions::NAN();
+ }
+
+ return ($value - $mean) / $stdDev;
+ }
+}
diff --git a/src/PhpSpreadsheet/Calculation/TextData/Format.php b/src/PhpSpreadsheet/Calculation/TextData/Format.php
index 7b0e6efa..d352c917 100644
--- a/src/PhpSpreadsheet/Calculation/TextData/Format.php
+++ b/src/PhpSpreadsheet/Calculation/TextData/Format.php
@@ -42,7 +42,7 @@ class Format
if ($value < 0) {
$round = 0 - $round;
}
- $value = MathTrig\Mround::evaluate($value, $round);
+ $value = MathTrig\Round::multiple($value, $round);
}
$mask = "$mask;($mask)";
@@ -98,7 +98,7 @@ class Format
$format = Functions::flattenSingleValue($format);
if ((is_string($value)) && (!is_numeric($value)) && Date::isDateTimeFormatCode($format)) {
- $value = DateTimeExcel\DateValue::funcDateValue($value);
+ $value = DateTimeExcel\DateValue::fromString($value);
}
return (string) NumberFormat::toFormattedString($value, $format);
@@ -129,14 +129,14 @@ class Format
Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
if (strpos($value, ':') !== false) {
- $timeValue = DateTimeExcel\TimeValue::funcTimeValue($value);
+ $timeValue = DateTimeExcel\TimeValue::fromString($value);
if ($timeValue !== Functions::VALUE()) {
Functions::setReturnDateType($dateSetting);
return $timeValue;
}
}
- $dateValue = DateTimeExcel\DateValue::funcDateValue($value);
+ $dateValue = DateTimeExcel\DateValue::fromString($value);
if ($dateValue !== Functions::VALUE()) {
Functions::setReturnDateType($dateSetting);
diff --git a/src/PhpSpreadsheet/Calculation/Web.php b/src/PhpSpreadsheet/Calculation/Web.php
index 5cfd2ea8..3f3d945d 100644
--- a/src/PhpSpreadsheet/Calculation/Web.php
+++ b/src/PhpSpreadsheet/Calculation/Web.php
@@ -2,9 +2,9 @@
namespace PhpOffice\PhpSpreadsheet\Calculation;
-use PhpOffice\PhpSpreadsheet\Settings;
-use Psr\Http\Client\ClientExceptionInterface;
-
+/**
+ * @deprecated 1.18.0
+ */
class Web
{
/**
@@ -15,39 +15,13 @@ class Web
* Excel Function:
* Webservice(url)
*
+ * @see Web\Service::webService()
+ * Use the webService() method in the Web\Service class instead
+ *
* @return string the output resulting from a call to the webservice
*/
public static function WEBSERVICE(string $url)
{
- $url = trim($url);
- if (strlen($url) > 2048) {
- return Functions::VALUE(); // Invalid URL length
- }
-
- if (!preg_match('/^http[s]?:\/\//', $url)) {
- return Functions::VALUE(); // Invalid protocol
- }
-
- // Get results from the the webservice
- $client = Settings::getHttpClient();
- $requestFactory = Settings::getRequestFactory();
- $request = $requestFactory->createRequest('GET', $url);
-
- try {
- $response = $client->sendRequest($request);
- } catch (ClientExceptionInterface $e) {
- return Functions::VALUE(); // cURL error
- }
-
- if ($response->getStatusCode() != 200) {
- return Functions::VALUE(); // cURL error
- }
-
- $output = $response->getBody()->getContents();
- if (strlen($output) > 32767) {
- return Functions::VALUE(); // Output not a string or too long
- }
-
- return $output;
+ return Web\Service::webService($url);
}
}
diff --git a/src/PhpSpreadsheet/Calculation/Web/Service.php b/src/PhpSpreadsheet/Calculation/Web/Service.php
new file mode 100644
index 00000000..05e04bf9
--- /dev/null
+++ b/src/PhpSpreadsheet/Calculation/Web/Service.php
@@ -0,0 +1,75 @@
+ 2048) {
+ return Functions::VALUE(); // Invalid URL length
+ }
+
+ if (!preg_match('/^http[s]?:\/\//', $url)) {
+ return Functions::VALUE(); // Invalid protocol
+ }
+
+ // Get results from the the webservice
+ $client = Settings::getHttpClient();
+ $requestFactory = Settings::getRequestFactory();
+ $request = $requestFactory->createRequest('GET', $url);
+
+ try {
+ $response = $client->sendRequest($request);
+ } catch (ClientExceptionInterface $e) {
+ return Functions::VALUE(); // cURL error
+ }
+
+ if ($response->getStatusCode() != 200) {
+ return Functions::VALUE(); // cURL error
+ }
+
+ $output = $response->getBody()->getContents();
+ if (strlen($output) > 32767) {
+ return Functions::VALUE(); // Output not a string or too long
+ }
+
+ return $output;
+ }
+
+ /**
+ * URLENCODE.
+ *
+ * Returns data from a web service on the Internet or Intranet.
+ *
+ * Excel Function:
+ * urlEncode(text)
+ *
+ * @param mixed $text
+ *
+ * @return string the url encoded output
+ */
+ public static function urlEncode($text)
+ {
+ if (!is_string($text)) {
+ return Functions::VALUE();
+ }
+
+ return str_replace('+', '%20', urlencode($text));
+ }
+}
diff --git a/src/PhpSpreadsheet/Calculation/locale/fr/functions b/src/PhpSpreadsheet/Calculation/locale/fr/functions
index 7f40d5fd..b28b4a70 100644
--- a/src/PhpSpreadsheet/Calculation/locale/fr/functions
+++ b/src/PhpSpreadsheet/Calculation/locale/fr/functions
@@ -47,6 +47,7 @@ DVARP = BDVARP ## Calcule la variance pour l’ensemble d’une population d
DATE = DATE ## Renvoie le numéro de série d’une date précise.
DATEVALUE = DATEVAL ## Convertit une date représentée sous forme de texte en numéro de série.
DAY = JOUR ## Convertit un numéro de série en jour du mois.
+DAYS = JOURS ## Calcule le nombre de jours qui séparent deux dates.
DAYS360 = JOURS360 ## Calcule le nombre de jours qui séparent deux dates sur la base d’une année de 360 jours.
EDATE = MOIS.DECALER ## Renvoie le numéro séquentiel de la date qui représente une date spécifiée (l’argument date_départ), corrigée en plus ou en moins du nombre de mois indiqué.
EOMONTH = FIN.MOIS ## Renvoie le numéro séquentiel de la date du dernier jour du mois précédant ou suivant la date_départ du nombre de mois indiqué.
diff --git a/src/PhpSpreadsheet/Cell/AddressHelper.php b/src/PhpSpreadsheet/Cell/AddressHelper.php
index b0e34e25..632c046f 100644
--- a/src/PhpSpreadsheet/Cell/AddressHelper.php
+++ b/src/PhpSpreadsheet/Cell/AddressHelper.php
@@ -102,14 +102,23 @@ class AddressHelper
?int $currentRowNumber = null,
?int $currentColumnNumber = null
): string {
- $validityCheck = preg_match('/^\$?([A-Z]{1,3})\$?(\d{1,7})$/i', $address, $cellReference);
+ $validityCheck = preg_match(Coordinate::A1_COORDINATE_REGEX, $address, $cellReference);
if ($validityCheck === 0) {
throw new Exception('Invalid A1-format Cell Reference');
}
- $columnId = Coordinate::columnIndexFromString($cellReference[1]);
- $rowId = (int) $cellReference[2];
+ $columnId = Coordinate::columnIndexFromString($cellReference['col_ref']);
+ if ($cellReference['absolute_col'] === '$') {
+ // Column must be absolute address
+ $currentColumnNumber = null;
+ }
+
+ $rowId = (int) $cellReference['row_ref'];
+ if ($cellReference['absolute_row'] === '$') {
+ // Row must be absolute address
+ $currentRowNumber = null;
+ }
if ($currentRowNumber !== null) {
if ($rowId === $currentRowNumber) {
diff --git a/src/PhpSpreadsheet/Cell/Coordinate.php b/src/PhpSpreadsheet/Cell/Coordinate.php
index 0b3917f2..58d2573e 100644
--- a/src/PhpSpreadsheet/Cell/Coordinate.php
+++ b/src/PhpSpreadsheet/Cell/Coordinate.php
@@ -13,6 +13,8 @@ use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
*/
abstract class Coordinate
{
+ public const A1_COORDINATE_REGEX = '/^(?\$?)(?[A-Z]{1,3})(?\$?)(?\d{1,7})$/i';
+
/**
* Default range variable constant.
*
@@ -29,8 +31,8 @@ abstract class Coordinate
*/
public static function coordinateFromString($pCoordinateString)
{
- if (preg_match('/^([$]?[A-Z]{1,3})([$]?\\d{1,7})$/', $pCoordinateString, $matches)) {
- return [$matches[1], $matches[2]];
+ if (preg_match(self::A1_COORDINATE_REGEX, $pCoordinateString, $matches)) {
+ return [$matches['absolute_col'] . $matches['col_ref'], $matches['absolute_row'] . $matches['row_ref']];
} elseif (self::coordinateIsRange($pCoordinateString)) {
throw new Exception('Cell coordinate string can not be a range of cells');
} elseif ($pCoordinateString == '') {
diff --git a/src/PhpSpreadsheet/Helper/Sample.php b/src/PhpSpreadsheet/Helper/Sample.php
index c84c3930..257a02a8 100644
--- a/src/PhpSpreadsheet/Helper/Sample.php
+++ b/src/PhpSpreadsheet/Helper/Sample.php
@@ -5,7 +5,6 @@ namespace PhpOffice\PhpSpreadsheet\Helper;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\IWriter;
-use PhpOffice\PhpSpreadsheet\Writer\Pdf;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use RecursiveRegexIterator;
@@ -119,11 +118,6 @@ class Sample
foreach ($writers as $writerType) {
$path = $this->getFilename($filename, mb_strtolower($writerType));
$writer = IOFactory::createWriter($spreadsheet, $writerType);
- if ($writer instanceof Pdf) {
- // PDF writer needs temporary directory
- $tempDir = $this->getTemporaryFolder();
- $writer->setTempDir($tempDir);
- }
$callStartTime = microtime(true);
$writer->save($path);
$this->logWrite($writer, $path, $callStartTime);
diff --git a/src/PhpSpreadsheet/Reader/Gnumeric.php b/src/PhpSpreadsheet/Reader/Gnumeric.php
index d3cdf1b0..85bae6f8 100644
--- a/src/PhpSpreadsheet/Reader/Gnumeric.php
+++ b/src/PhpSpreadsheet/Reader/Gnumeric.php
@@ -7,25 +7,32 @@ use PhpOffice\PhpSpreadsheet\Cell\DataType;
use PhpOffice\PhpSpreadsheet\DefinedName;
use PhpOffice\PhpSpreadsheet\Reader\Gnumeric\PageSetup;
use PhpOffice\PhpSpreadsheet\Reader\Gnumeric\Properties;
+use PhpOffice\PhpSpreadsheet\Reader\Gnumeric\Styles;
use PhpOffice\PhpSpreadsheet\Reader\Security\XmlScanner;
use PhpOffice\PhpSpreadsheet\ReferenceHelper;
use PhpOffice\PhpSpreadsheet\RichText\RichText;
use PhpOffice\PhpSpreadsheet\Settings;
-use PhpOffice\PhpSpreadsheet\Shared\Date;
use PhpOffice\PhpSpreadsheet\Shared\File;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
-use PhpOffice\PhpSpreadsheet\Style\Alignment;
-use PhpOffice\PhpSpreadsheet\Style\Border;
-use PhpOffice\PhpSpreadsheet\Style\Borders;
-use PhpOffice\PhpSpreadsheet\Style\Fill;
-use PhpOffice\PhpSpreadsheet\Style\Font;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
use SimpleXMLElement;
use XMLReader;
class Gnumeric extends BaseReader
{
- private const UOM_CONVERSION_POINTS_TO_CENTIMETERS = 0.03527777778;
+ const NAMESPACE_GNM = 'http://www.gnumeric.org/v10.dtd'; // gmr in old sheets
+
+ const NAMESPACE_XSI = 'http://www.w3.org/2001/XMLSchema-instance';
+
+ const NAMESPACE_OFFICE = 'urn:oasis:names:tc:opendocument:xmlns:office:1.0';
+
+ const NAMESPACE_XLINK = 'http://www.w3.org/1999/xlink';
+
+ const NAMESPACE_DC = 'http://purl.org/dc/elements/1.1/';
+
+ const NAMESPACE_META = 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0';
+
+ const NAMESPACE_OOO = 'http://openoffice.org/2004/office';
/**
* Shared Expressions.
@@ -41,15 +48,22 @@ class Gnumeric extends BaseReader
*/
private $spreadsheet;
+ /** @var ReferenceHelper */
private $referenceHelper;
- /**
- * Namespace shared across all functions.
- * It is 'gnm', except for really old sheets which use 'gmr'.
- *
- * @var string
- */
- private $gnm = 'gnm';
+ /** @var array */
+ public static $mappings = [
+ 'dataType' => [
+ '10' => DataType::TYPE_NULL,
+ '20' => DataType::TYPE_BOOL,
+ '30' => DataType::TYPE_NUMERIC, // Integer doesn't exist in Excel
+ '40' => DataType::TYPE_NUMERIC, // Float
+ '50' => DataType::TYPE_ERROR,
+ '60' => DataType::TYPE_STRING,
+ //'70': // Cell Range
+ //'80': // Array
+ ],
+ ];
/**
* Create a new Gnumeric.
@@ -77,16 +91,20 @@ class Gnumeric extends BaseReader
if (function_exists('gzread')) {
// Read signature data (first 3 bytes)
$fh = fopen($pFilename, 'rb');
- $data = fread($fh, 2);
- fclose($fh);
+ if ($fh !== false) {
+ $data = fread($fh, 2);
+ fclose($fh);
+ }
}
- return $data == chr(0x1F) . chr(0x8B);
+ return $data === chr(0x1F) . chr(0x8B);
}
- private static function matchXml(string $name, string $field): bool
+ private static function matchXml(XMLReader $xml, string $expectedLocalName): bool
{
- return 1 === preg_match("/^(gnm|gmr):$field$/", $name);
+ return $xml->namespaceURI === self::NAMESPACE_GNM
+ && $xml->localName === $expectedLocalName
+ && $xml->nodeType === XMLReader::ELEMENT;
}
/**
@@ -106,10 +124,10 @@ class Gnumeric extends BaseReader
$worksheetNames = [];
while ($xml->read()) {
- if (self::matchXml($xml->name, 'SheetName') && $xml->nodeType == XMLReader::ELEMENT) {
+ if (self::matchXml($xml, 'SheetName')) {
$xml->read(); // Move onto the value node
$worksheetNames[] = (string) $xml->value;
- } elseif (self::matchXml($xml->name, 'Sheets')) {
+ } elseif (self::matchXml($xml, 'Sheets')) {
// break out of the loop once we've got our sheet names rather than parse the entire file
break;
}
@@ -135,7 +153,7 @@ class Gnumeric extends BaseReader
$worksheetInfo = [];
while ($xml->read()) {
- if (self::matchXml($xml->name, 'Sheet') && $xml->nodeType == XMLReader::ELEMENT) {
+ if (self::matchXml($xml, 'Sheet')) {
$tmpInfo = [
'worksheetName' => '',
'lastColumnLetter' => 'A',
@@ -145,20 +163,18 @@ class Gnumeric extends BaseReader
];
while ($xml->read()) {
- if ($xml->nodeType == XMLReader::ELEMENT) {
- if (self::matchXml($xml->name, 'Name')) {
- $xml->read(); // Move onto the value node
- $tmpInfo['worksheetName'] = (string) $xml->value;
- } elseif (self::matchXml($xml->name, 'MaxCol')) {
- $xml->read(); // Move onto the value node
- $tmpInfo['lastColumnIndex'] = (int) $xml->value;
- $tmpInfo['totalColumns'] = (int) $xml->value + 1;
- } elseif (self::matchXml($xml->name, 'MaxRow')) {
- $xml->read(); // Move onto the value node
- $tmpInfo['totalRows'] = (int) $xml->value + 1;
+ if (self::matchXml($xml, 'Name')) {
+ $xml->read(); // Move onto the value node
+ $tmpInfo['worksheetName'] = (string) $xml->value;
+ } elseif (self::matchXml($xml, 'MaxCol')) {
+ $xml->read(); // Move onto the value node
+ $tmpInfo['lastColumnIndex'] = (int) $xml->value;
+ $tmpInfo['totalColumns'] = (int) $xml->value + 1;
+ } elseif (self::matchXml($xml, 'MaxRow')) {
+ $xml->read(); // Move onto the value node
+ $tmpInfo['totalRows'] = (int) $xml->value + 1;
- break;
- }
+ break;
}
}
$tmpInfo['lastColumnLetter'] = Coordinate::stringFromColumnIndex($tmpInfo['lastColumnIndex'] + 1);
@@ -188,94 +204,34 @@ class Gnumeric extends BaseReader
return $data;
}
- private static $mappings = [
- 'borderStyle' => [
- '0' => Border::BORDER_NONE,
- '1' => Border::BORDER_THIN,
- '2' => Border::BORDER_MEDIUM,
- '3' => Border::BORDER_SLANTDASHDOT,
- '4' => Border::BORDER_DASHED,
- '5' => Border::BORDER_THICK,
- '6' => Border::BORDER_DOUBLE,
- '7' => Border::BORDER_DOTTED,
- '8' => Border::BORDER_MEDIUMDASHED,
- '9' => Border::BORDER_DASHDOT,
- '10' => Border::BORDER_MEDIUMDASHDOT,
- '11' => Border::BORDER_DASHDOTDOT,
- '12' => Border::BORDER_MEDIUMDASHDOTDOT,
- '13' => Border::BORDER_MEDIUMDASHDOTDOT,
- ],
- 'dataType' => [
- '10' => DataType::TYPE_NULL,
- '20' => DataType::TYPE_BOOL,
- '30' => DataType::TYPE_NUMERIC, // Integer doesn't exist in Excel
- '40' => DataType::TYPE_NUMERIC, // Float
- '50' => DataType::TYPE_ERROR,
- '60' => DataType::TYPE_STRING,
- //'70': // Cell Range
- //'80': // Array
- ],
- 'fillType' => [
- '1' => Fill::FILL_SOLID,
- '2' => Fill::FILL_PATTERN_DARKGRAY,
- '3' => Fill::FILL_PATTERN_MEDIUMGRAY,
- '4' => Fill::FILL_PATTERN_LIGHTGRAY,
- '5' => Fill::FILL_PATTERN_GRAY125,
- '6' => Fill::FILL_PATTERN_GRAY0625,
- '7' => Fill::FILL_PATTERN_DARKHORIZONTAL, // horizontal stripe
- '8' => Fill::FILL_PATTERN_DARKVERTICAL, // vertical stripe
- '9' => Fill::FILL_PATTERN_DARKDOWN, // diagonal stripe
- '10' => Fill::FILL_PATTERN_DARKUP, // reverse diagonal stripe
- '11' => Fill::FILL_PATTERN_DARKGRID, // diagoanl crosshatch
- '12' => Fill::FILL_PATTERN_DARKTRELLIS, // thick diagonal crosshatch
- '13' => Fill::FILL_PATTERN_LIGHTHORIZONTAL,
- '14' => Fill::FILL_PATTERN_LIGHTVERTICAL,
- '15' => Fill::FILL_PATTERN_LIGHTUP,
- '16' => Fill::FILL_PATTERN_LIGHTDOWN,
- '17' => Fill::FILL_PATTERN_LIGHTGRID, // thin horizontal crosshatch
- '18' => Fill::FILL_PATTERN_LIGHTTRELLIS, // thin diagonal crosshatch
- ],
- 'horizontal' => [
- '1' => Alignment::HORIZONTAL_GENERAL,
- '2' => Alignment::HORIZONTAL_LEFT,
- '4' => Alignment::HORIZONTAL_RIGHT,
- '8' => Alignment::HORIZONTAL_CENTER,
- '16' => Alignment::HORIZONTAL_CENTER_CONTINUOUS,
- '32' => Alignment::HORIZONTAL_JUSTIFY,
- '64' => Alignment::HORIZONTAL_CENTER_CONTINUOUS,
- ],
- 'underline' => [
- '1' => Font::UNDERLINE_SINGLE,
- '2' => Font::UNDERLINE_DOUBLE,
- '3' => Font::UNDERLINE_SINGLEACCOUNTING,
- '4' => Font::UNDERLINE_DOUBLEACCOUNTING,
- ],
- 'vertical' => [
- '1' => Alignment::VERTICAL_TOP,
- '2' => Alignment::VERTICAL_BOTTOM,
- '4' => Alignment::VERTICAL_CENTER,
- '8' => Alignment::VERTICAL_JUSTIFY,
- ],
- ];
-
public static function gnumericMappings(): array
{
- return self::$mappings;
+ return array_merge(self::$mappings, Styles::$mappings);
}
private function processComments(SimpleXMLElement $sheet): void
{
if ((!$this->readDataOnly) && (isset($sheet->Objects))) {
- foreach ($sheet->Objects->children($this->gnm, true) as $key => $comment) {
+ foreach ($sheet->Objects->children(self::NAMESPACE_GNM) as $key => $comment) {
$commentAttributes = $comment->attributes();
// Only comment objects are handled at the moment
if ($commentAttributes->Text) {
- $this->spreadsheet->getActiveSheet()->getComment((string) $commentAttributes->ObjectBound)->setAuthor((string) $commentAttributes->Author)->setText($this->parseRichText((string) $commentAttributes->Text));
+ $this->spreadsheet->getActiveSheet()->getComment((string) $commentAttributes->ObjectBound)
+ ->setAuthor((string) $commentAttributes->Author)
+ ->setText($this->parseRichText((string) $commentAttributes->Text));
}
}
}
}
+ /**
+ * @param mixed $value
+ */
+ private static function testSimpleXml($value): SimpleXMLElement
+ {
+ return ($value instanceof SimpleXMLElement) ? $value : new SimpleXMLElement('');
+ }
+
/**
* Loads Spreadsheet from file.
*
@@ -304,12 +260,10 @@ class Gnumeric extends BaseReader
$gFileData = $this->gzfileGetContents($pFilename);
$xml2 = simplexml_load_string($this->securityScanner->scan($gFileData), 'SimpleXMLElement', Settings::getLibXmlLoaderOptions());
- $xml = ($xml2 !== false) ? $xml2 : new SimpleXMLElement('');
- $namespacesMeta = $xml->getNamespaces(true);
- $this->gnm = array_key_exists('gmr', $namespacesMeta) ? 'gmr' : 'gnm';
+ $xml = self::testSimpleXml($xml2);
- $gnmXML = $xml->children($namespacesMeta[$this->gnm]);
- (new Properties($this->spreadsheet))->readProperties($xml, $gnmXML, $namespacesMeta);
+ $gnmXML = $xml->children(self::NAMESPACE_GNM);
+ (new Properties($this->spreadsheet))->readProperties($xml, $gnmXML);
$worksheetID = 0;
foreach ($gnmXML->Sheets->Sheet as $sheet) {
@@ -329,7 +283,7 @@ class Gnumeric extends BaseReader
$this->spreadsheet->getActiveSheet()->setTitle($worksheetName, false, false);
if (!$this->readDataOnly) {
- (new PageSetup($this->spreadsheet, $this->gnm))
+ (new PageSetup($this->spreadsheet))
->printInformation($sheet)
->sheetMargins($sheet);
}
@@ -382,90 +336,22 @@ class Gnumeric extends BaseReader
if (array_key_exists($vtype, self::$mappings['dataType'])) {
$type = self::$mappings['dataType'][$vtype];
}
- if ($vtype == '20') { // Boolean
+ if ($vtype === '20') { // Boolean
$cell = $cell == 'TRUE';
}
}
$this->spreadsheet->getActiveSheet()->getCell($column . $row)->setValueExplicit((string) $cell, $type);
}
- $this->processComments($sheet);
-
- foreach ($sheet->Styles->StyleRegion as $styleRegion) {
- $styleAttributes = $styleRegion->attributes();
- if (
- ($styleAttributes['startRow'] <= $maxRow) &&
- ($styleAttributes['startCol'] <= $maxCol)
- ) {
- $startColumn = Coordinate::stringFromColumnIndex((int) $styleAttributes['startCol'] + 1);
- $startRow = $styleAttributes['startRow'] + 1;
-
- $endColumn = ($styleAttributes['endCol'] > $maxCol) ? $maxCol : (int) $styleAttributes['endCol'];
- $endColumn = Coordinate::stringFromColumnIndex($endColumn + 1);
-
- $endRow = 1 + (($styleAttributes['endRow'] > $maxRow) ? $maxRow : (int) $styleAttributes['endRow']);
- $cellRange = $startColumn . $startRow . ':' . $endColumn . $endRow;
-
- $styleAttributes = $styleRegion->Style->attributes();
-
- $styleArray = [];
- // We still set the number format mask for date/time values, even if readDataOnly is true
- $formatCode = (string) $styleAttributes['Format'];
- if (Date::isDateTimeFormatCode($formatCode)) {
- $styleArray['numberFormat']['formatCode'] = $formatCode;
- }
- if (!$this->readDataOnly) {
- // If readDataOnly is false, we set all formatting information
- $styleArray['numberFormat']['formatCode'] = $formatCode;
-
- self::addStyle2($styleArray, 'alignment', 'horizontal', $styleAttributes['HAlign']);
- self::addStyle2($styleArray, 'alignment', 'vertical', $styleAttributes['VAlign']);
- $styleArray['alignment']['wrapText'] = $styleAttributes['WrapText'] == '1';
- $styleArray['alignment']['textRotation'] = $this->calcRotation($styleAttributes);
- $styleArray['alignment']['shrinkToFit'] = $styleAttributes['ShrinkToFit'] == '1';
- $styleArray['alignment']['indent'] = ((int) ($styleAttributes['Indent']) > 0) ? $styleAttributes['indent'] : 0;
-
- $this->addColors($styleArray, $styleAttributes);
-
- $fontAttributes = $styleRegion->Style->Font->attributes();
- $styleArray['font']['name'] = (string) $styleRegion->Style->Font;
- $styleArray['font']['size'] = (int) ($fontAttributes['Unit']);
- $styleArray['font']['bold'] = $fontAttributes['Bold'] == '1';
- $styleArray['font']['italic'] = $fontAttributes['Italic'] == '1';
- $styleArray['font']['strikethrough'] = $fontAttributes['StrikeThrough'] == '1';
- self::addStyle2($styleArray, 'font', 'underline', $fontAttributes['Underline']);
-
- switch ($fontAttributes['Script']) {
- case '1':
- $styleArray['font']['superscript'] = true;
-
- break;
- case '-1':
- $styleArray['font']['subscript'] = true;
-
- break;
- }
-
- if (isset($styleRegion->Style->StyleBorder)) {
- $srssb = $styleRegion->Style->StyleBorder;
- $this->addBorderStyle($srssb, $styleArray, 'top');
- $this->addBorderStyle($srssb, $styleArray, 'bottom');
- $this->addBorderStyle($srssb, $styleArray, 'left');
- $this->addBorderStyle($srssb, $styleArray, 'right');
- $this->addBorderDiagonal($srssb, $styleArray);
- }
- if (isset($styleRegion->Style->HyperLink)) {
- // TO DO
- $hyperlink = $styleRegion->Style->HyperLink->attributes();
- }
- }
- $this->spreadsheet->getActiveSheet()->getStyle($cellRange)->applyFromArray($styleArray);
- }
+ if ($sheet->Styles !== null) {
+ (new Styles($this->spreadsheet, $this->readDataOnly))->read($sheet, $maxRow, $maxCol);
}
+ $this->processComments($sheet);
$this->processColumnWidths($sheet, $maxCol);
$this->processRowHeights($sheet, $maxRow);
$this->processMergedCells($sheet);
+ $this->processAutofilter($sheet);
++$worksheetID;
}
@@ -476,32 +362,10 @@ class Gnumeric extends BaseReader
return $this->spreadsheet;
}
- private function addBorderDiagonal(SimpleXMLElement $srssb, array &$styleArray): void
- {
- if (isset($srssb->Diagonal, $srssb->{'Rev-Diagonal'})) {
- $styleArray['borders']['diagonal'] = self::parseBorderAttributes($srssb->Diagonal->attributes());
- $styleArray['borders']['diagonalDirection'] = Borders::DIAGONAL_BOTH;
- } elseif (isset($srssb->Diagonal)) {
- $styleArray['borders']['diagonal'] = self::parseBorderAttributes($srssb->Diagonal->attributes());
- $styleArray['borders']['diagonalDirection'] = Borders::DIAGONAL_UP;
- } elseif (isset($srssb->{'Rev-Diagonal'})) {
- $styleArray['borders']['diagonal'] = self::parseBorderAttributes($srssb->{'Rev-Diagonal'}->attributes());
- $styleArray['borders']['diagonalDirection'] = Borders::DIAGONAL_DOWN;
- }
- }
-
- private function addBorderStyle(SimpleXMLElement $srssb, array &$styleArray, string $direction): void
- {
- $ucDirection = ucfirst($direction);
- if (isset($srssb->$ucDirection)) {
- $styleArray['borders'][$direction] = self::parseBorderAttributes($srssb->$ucDirection->attributes());
- }
- }
-
- private function processMergedCells(SimpleXMLElement $sheet): void
+ private function processMergedCells(?SimpleXMLElement $sheet): void
{
// Handle Merged Cells in this worksheet
- if (isset($sheet->MergedRegions)) {
+ if ($sheet !== null && isset($sheet->MergedRegions)) {
foreach ($sheet->MergedRegions->Merge as $mergeCells) {
if (strpos($mergeCells, ':') !== false) {
$this->spreadsheet->getActiveSheet()->mergeCells($mergeCells);
@@ -510,92 +374,144 @@ class Gnumeric extends BaseReader
}
}
- private function processColumnLoop(int $c, int $maxCol, SimpleXMLElement $columnOverride, float $defaultWidth): int
+ private function processAutofilter(?SimpleXMLElement $sheet): void
{
- $columnAttributes = $columnOverride->attributes();
+ if ($sheet !== null && isset($sheet->Filters)) {
+ foreach ($sheet->Filters->Filter as $autofilter) {
+ if ($autofilter !== null) {
+ $attributes = $autofilter->attributes();
+ if (isset($attributes['Area'])) {
+ $this->spreadsheet->getActiveSheet()->setAutoFilter((string) $attributes['Area']);
+ }
+ }
+ }
+ }
+ }
+
+ private function setColumnWidth(int $whichColumn, float $defaultWidth): void
+ {
+ $columnDimension = $this->spreadsheet->getActiveSheet()->getColumnDimension(Coordinate::stringFromColumnIndex($whichColumn + 1));
+ if ($columnDimension !== null) {
+ $columnDimension->setWidth($defaultWidth);
+ }
+ }
+
+ private function setColumnInvisible(int $whichColumn): void
+ {
+ $columnDimension = $this->spreadsheet->getActiveSheet()->getColumnDimension(Coordinate::stringFromColumnIndex($whichColumn + 1));
+ if ($columnDimension !== null) {
+ $columnDimension->setVisible(false);
+ }
+ }
+
+ private function processColumnLoop(int $whichColumn, int $maxCol, SimpleXMLElement $columnOverride, float $defaultWidth): int
+ {
+ $columnAttributes = self::testSimpleXml($columnOverride->attributes());
$column = $columnAttributes['No'];
$columnWidth = ((float) $columnAttributes['Unit']) / 5.4;
$hidden = (isset($columnAttributes['Hidden'])) && ((string) $columnAttributes['Hidden'] == '1');
$columnCount = (int) ($columnAttributes['Count'] ?? 1);
- while ($c < $column) {
- $this->spreadsheet->getActiveSheet()->getColumnDimension(Coordinate::stringFromColumnIndex($c + 1))->setWidth($defaultWidth);
- ++$c;
+ while ($whichColumn < $column) {
+ $this->setColumnWidth($whichColumn, $defaultWidth);
+ ++$whichColumn;
}
- while (($c < ($column + $columnCount)) && ($c <= $maxCol)) {
- $this->spreadsheet->getActiveSheet()->getColumnDimension(Coordinate::stringFromColumnIndex($c + 1))->setWidth($columnWidth);
+ while (($whichColumn < ($column + $columnCount)) && ($whichColumn <= $maxCol)) {
+ $this->setColumnWidth($whichColumn, $columnWidth);
if ($hidden) {
- $this->spreadsheet->getActiveSheet()->getColumnDimension(Coordinate::stringFromColumnIndex($c + 1))->setVisible(false);
+ $this->setColumnInvisible($whichColumn);
}
- ++$c;
+ ++$whichColumn;
}
- return $c;
+ return $whichColumn;
}
- private function processColumnWidths(SimpleXMLElement $sheet, int $maxCol): void
+ private function processColumnWidths(?SimpleXMLElement $sheet, int $maxCol): void
{
- if ((!$this->readDataOnly) && (isset($sheet->Cols))) {
+ if ((!$this->readDataOnly) && $sheet !== null && (isset($sheet->Cols))) {
// Column Widths
+ $defaultWidth = 0;
$columnAttributes = $sheet->Cols->attributes();
- $defaultWidth = $columnAttributes['DefaultSizePts'] / 5.4;
- $c = 0;
- foreach ($sheet->Cols->ColInfo as $columnOverride) {
- $c = $this->processColumnLoop($c, $maxCol, $columnOverride, $defaultWidth);
+ if ($columnAttributes !== null) {
+ $defaultWidth = $columnAttributes['DefaultSizePts'] / 5.4;
}
- while ($c <= $maxCol) {
- $this->spreadsheet->getActiveSheet()->getColumnDimension(Coordinate::stringFromColumnIndex($c + 1))->setWidth($defaultWidth);
- ++$c;
+ $whichColumn = 0;
+ foreach ($sheet->Cols->ColInfo as $columnOverride) {
+ $whichColumn = $this->processColumnLoop($whichColumn, $maxCol, $columnOverride, $defaultWidth);
+ }
+ while ($whichColumn <= $maxCol) {
+ $this->setColumnWidth($whichColumn, $defaultWidth);
+ ++$whichColumn;
}
}
}
- private function processRowLoop(int $r, int $maxRow, SimpleXMLElement $rowOverride, float $defaultHeight): int
+ private function setRowHeight(int $whichRow, float $defaultHeight): void
{
- $rowAttributes = $rowOverride->attributes();
+ $rowDimension = $this->spreadsheet->getActiveSheet()->getRowDimension($whichRow);
+ if ($rowDimension !== null) {
+ $rowDimension->setRowHeight($defaultHeight);
+ }
+ }
+
+ private function setRowInvisible(int $whichRow): void
+ {
+ $rowDimension = $this->spreadsheet->getActiveSheet()->getRowDimension($whichRow);
+ if ($rowDimension !== null) {
+ $rowDimension->setVisible(false);
+ }
+ }
+
+ private function processRowLoop(int $whichRow, int $maxRow, SimpleXMLElement $rowOverride, float $defaultHeight): int
+ {
+ $rowAttributes = self::testSimpleXml($rowOverride->attributes());
$row = $rowAttributes['No'];
$rowHeight = (float) $rowAttributes['Unit'];
$hidden = (isset($rowAttributes['Hidden'])) && ((string) $rowAttributes['Hidden'] == '1');
$rowCount = (int) ($rowAttributes['Count'] ?? 1);
- while ($r < $row) {
- ++$r;
- $this->spreadsheet->getActiveSheet()->getRowDimension($r)->setRowHeight($defaultHeight);
+ while ($whichRow < $row) {
+ ++$whichRow;
+ $this->setRowHeight($whichRow, $defaultHeight);
}
- while (($r < ($row + $rowCount)) && ($r < $maxRow)) {
- ++$r;
- $this->spreadsheet->getActiveSheet()->getRowDimension($r)->setRowHeight($rowHeight);
+ while (($whichRow < ($row + $rowCount)) && ($whichRow < $maxRow)) {
+ ++$whichRow;
+ $this->setRowHeight($whichRow, $rowHeight);
if ($hidden) {
- $this->spreadsheet->getActiveSheet()->getRowDimension($r)->setVisible(false);
+ $this->setRowInvisible($whichRow);
}
}
- return $r;
+ return $whichRow;
}
- private function processRowHeights(SimpleXMLElement $sheet, int $maxRow): void
+ private function processRowHeights(?SimpleXMLElement $sheet, int $maxRow): void
{
- if ((!$this->readDataOnly) && (isset($sheet->Rows))) {
+ if ((!$this->readDataOnly) && $sheet !== null && (isset($sheet->Rows))) {
// Row Heights
+ $defaultHeight = 0;
$rowAttributes = $sheet->Rows->attributes();
- $defaultHeight = (float) $rowAttributes['DefaultSizePts'];
- $r = 0;
+ if ($rowAttributes !== null) {
+ $defaultHeight = (float) $rowAttributes['DefaultSizePts'];
+ }
+ $whichRow = 0;
foreach ($sheet->Rows->RowInfo as $rowOverride) {
- $r = $this->processRowLoop($r, $maxRow, $rowOverride, $defaultHeight);
+ $whichRow = $this->processRowLoop($whichRow, $maxRow, $rowOverride, $defaultHeight);
}
// never executed, I can't figure out any circumstances
// under which it would be executed, and, even if
// such exist, I'm not convinced this is needed.
- //while ($r < $maxRow) {
- // ++$r;
- // $this->spreadsheet->getActiveSheet()->getRowDimension($r)->setRowHeight($defaultHeight);
+ //while ($whichRow < $maxRow) {
+ // ++$whichRow;
+ // $this->spreadsheet->getActiveSheet()->getRowDimension($whichRow)->setRowHeight($defaultHeight);
//}
}
}
- private function processDefinedNames(SimpleXMLElement $gnmXML): void
+ private function processDefinedNames(?SimpleXMLElement $gnmXML): void
{
// Loop through definedNames (global named ranges)
- if (isset($gnmXML->Names)) {
+ if ($gnmXML !== null && isset($gnmXML->Names)) {
foreach ($gnmXML->Names->Name as $definedName) {
$name = (string) $definedName->name;
$value = (string) $definedName->value;
@@ -614,77 +530,11 @@ class Gnumeric extends BaseReader
}
}
- private function calcRotation(SimpleXMLElement $styleAttributes): int
- {
- $rotation = (int) $styleAttributes->Rotation;
- if ($rotation >= 270 && $rotation <= 360) {
- $rotation -= 360;
- }
- $rotation = (abs($rotation) > 90) ? 0 : $rotation;
-
- return $rotation;
- }
-
- private static function addStyle(array &$styleArray, string $key, string $value): void
- {
- if (array_key_exists($value, self::$mappings[$key])) {
- $styleArray[$key] = self::$mappings[$key][$value];
- }
- }
-
- private static function addStyle2(array &$styleArray, string $key1, string $key, string $value): void
- {
- if (array_key_exists($value, self::$mappings[$key])) {
- $styleArray[$key1][$key] = self::$mappings[$key][$value];
- }
- }
-
- private static function parseBorderAttributes($borderAttributes)
- {
- $styleArray = [];
- if (isset($borderAttributes['Color'])) {
- $styleArray['color']['rgb'] = self::parseGnumericColour($borderAttributes['Color']);
- }
-
- self::addStyle($styleArray, 'borderStyle', $borderAttributes['Style']);
-
- return $styleArray;
- }
-
- private function parseRichText($is)
+ private function parseRichText(string $is): RichText
{
$value = new RichText();
$value->createText($is);
return $value;
}
-
- private static function parseGnumericColour($gnmColour)
- {
- [$gnmR, $gnmG, $gnmB] = explode(':', $gnmColour);
- $gnmR = substr(str_pad($gnmR, 4, '0', STR_PAD_RIGHT), 0, 2);
- $gnmG = substr(str_pad($gnmG, 4, '0', STR_PAD_RIGHT), 0, 2);
- $gnmB = substr(str_pad($gnmB, 4, '0', STR_PAD_RIGHT), 0, 2);
-
- return $gnmR . $gnmG . $gnmB;
- }
-
- private function addColors(array &$styleArray, SimpleXMLElement $styleAttributes): void
- {
- $RGB = self::parseGnumericColour($styleAttributes['Fore']);
- $styleArray['font']['color']['rgb'] = $RGB;
- $RGB = self::parseGnumericColour($styleAttributes['Back']);
- $shade = (string) $styleAttributes['Shade'];
- if (($RGB != '000000') || ($shade != '0')) {
- $RGB2 = self::parseGnumericColour($styleAttributes['PatternColor']);
- if ($shade == '1') {
- $styleArray['fill']['startColor']['rgb'] = $RGB;
- $styleArray['fill']['endColor']['rgb'] = $RGB2;
- } else {
- $styleArray['fill']['endColor']['rgb'] = $RGB;
- $styleArray['fill']['startColor']['rgb'] = $RGB2;
- }
- self::addStyle2($styleArray, 'fill', 'fillType', $shade);
- }
- }
}
diff --git a/src/PhpSpreadsheet/Reader/Gnumeric/PageSetup.php b/src/PhpSpreadsheet/Reader/Gnumeric/PageSetup.php
index 0fe73005..accc2716 100644
--- a/src/PhpSpreadsheet/Reader/Gnumeric/PageSetup.php
+++ b/src/PhpSpreadsheet/Reader/Gnumeric/PageSetup.php
@@ -2,6 +2,7 @@
namespace PhpOffice\PhpSpreadsheet\Reader\Gnumeric;
+use PhpOffice\PhpSpreadsheet\Reader\Gnumeric;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Worksheet\PageMargins;
use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup as WorksheetPageSetup;
@@ -14,15 +15,9 @@ class PageSetup
*/
private $spreadsheet;
- /**
- * @var string
- */
- private $gnm;
-
- public function __construct(Spreadsheet $spreadsheet, string $gnm)
+ public function __construct(Spreadsheet $spreadsheet)
{
$this->spreadsheet = $spreadsheet;
- $this->gnm = $gnm;
}
public function printInformation(SimpleXMLElement $sheet): self
@@ -68,7 +63,7 @@ class PageSetup
private function buildMarginSet(SimpleXMLElement $sheet, array $marginSet): array
{
- foreach ($sheet->PrintInformation->Margins->children($this->gnm, true) as $key => $margin) {
+ foreach ($sheet->PrintInformation->Margins->children(Gnumeric::NAMESPACE_GNM) as $key => $margin) {
$marginAttributes = $margin->attributes();
$marginSize = ($marginAttributes['Points']) ?? 72; // Default is 72pt
// Convert value in points to inches
diff --git a/src/PhpSpreadsheet/Reader/Gnumeric/Properties.php b/src/PhpSpreadsheet/Reader/Gnumeric/Properties.php
index 16d9c2e0..c466a859 100644
--- a/src/PhpSpreadsheet/Reader/Gnumeric/Properties.php
+++ b/src/PhpSpreadsheet/Reader/Gnumeric/Properties.php
@@ -2,6 +2,7 @@
namespace PhpOffice\PhpSpreadsheet\Reader\Gnumeric;
+use PhpOffice\PhpSpreadsheet\Reader\Gnumeric;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use SimpleXMLElement;
@@ -91,74 +92,72 @@ class Properties
}
}
- private function docPropertiesMeta(SimpleXMLElement $officePropertyMeta, array $namespacesMeta): void
+ private function docPropertiesMeta(SimpleXMLElement $officePropertyMeta): void
{
$docProps = $this->spreadsheet->getProperties();
foreach ($officePropertyMeta as $propertyName => $propertyValue) {
- if ($propertyValue === null) {
- continue;
- }
+ if ($propertyValue !== null) {
+ $attributes = $propertyValue->attributes(Gnumeric::NAMESPACE_META);
+ $propertyValue = trim((string) $propertyValue);
+ switch ($propertyName) {
+ case 'keyword':
+ $docProps->setKeywords($propertyValue);
- $attributes = $propertyValue->attributes($namespacesMeta['meta']);
- $propertyValue = trim((string) $propertyValue);
- switch ($propertyName) {
- case 'keyword':
- $docProps->setKeywords($propertyValue);
+ break;
+ case 'initial-creator':
+ $docProps->setCreator($propertyValue);
+ $docProps->setLastModifiedBy($propertyValue);
- break;
- case 'initial-creator':
- $docProps->setCreator($propertyValue);
- $docProps->setLastModifiedBy($propertyValue);
+ break;
+ case 'creation-date':
+ $creationDate = strtotime($propertyValue);
+ $creationDate = $creationDate === false ? time() : $creationDate;
+ $docProps->setCreated($creationDate);
+ $docProps->setModified($creationDate);
- break;
- case 'creation-date':
- $creationDate = strtotime($propertyValue);
- $creationDate = $creationDate === false ? time() : $creationDate;
- $docProps->setCreated($creationDate);
- $docProps->setModified($creationDate);
+ break;
+ case 'user-defined':
+ [, $attrName] = explode(':', $attributes['name']);
+ $this->userDefinedProperties($attrName, $propertyValue);
- break;
- case 'user-defined':
- [, $attrName] = explode(':', $attributes['name']);
- switch ($attrName) {
- case 'publisher':
- $docProps->setCompany($propertyValue);
-
- break;
- case 'category':
- $docProps->setCategory($propertyValue);
-
- break;
- case 'manager':
- $docProps->setManager($propertyValue);
-
- break;
- }
-
- break;
+ break;
+ }
}
}
}
- public function readProperties(SimpleXMLElement $xml, SimpleXMLElement $gnmXML, array $namespacesMeta): void
+ private function userDefinedProperties(string $attrName, string $propertyValue): void
{
- if (isset($namespacesMeta['office'])) {
- $officeXML = $xml->children($namespacesMeta['office']);
+ $docProps = $this->spreadsheet->getProperties();
+ switch ($attrName) {
+ case 'publisher':
+ $docProps->setCompany($propertyValue);
+
+ break;
+ case 'category':
+ $docProps->setCategory($propertyValue);
+
+ break;
+ case 'manager':
+ $docProps->setManager($propertyValue);
+
+ break;
+ }
+ }
+
+ public function readProperties(SimpleXMLElement $xml, SimpleXMLElement $gnmXML): void
+ {
+ $officeXML = $xml->children(Gnumeric::NAMESPACE_OFFICE);
+ if (!empty($officeXML)) {
$officeDocXML = $officeXML->{'document-meta'};
$officeDocMetaXML = $officeDocXML->meta;
foreach ($officeDocMetaXML as $officePropertyData) {
- $officePropertyDC = [];
- if (isset($namespacesMeta['dc'])) {
- $officePropertyDC = $officePropertyData->children($namespacesMeta['dc']);
- }
+ $officePropertyDC = $officePropertyData->children(Gnumeric::NAMESPACE_DC);
$this->docPropertiesDC($officePropertyDC);
- $officePropertyMeta = [];
- if (isset($namespacesMeta['meta'])) {
- $officePropertyMeta = $officePropertyData->children($namespacesMeta['meta']);
- }
- $this->docPropertiesMeta($officePropertyMeta, $namespacesMeta);
+ $officePropertyMeta = $officePropertyData->children(Gnumeric::NAMESPACE_META);
+ $this->docPropertiesMeta($officePropertyMeta);
}
} elseif (isset($gnmXML->Summary)) {
$this->docPropertiesOld($gnmXML);
diff --git a/src/PhpSpreadsheet/Reader/Gnumeric/Styles.php b/src/PhpSpreadsheet/Reader/Gnumeric/Styles.php
new file mode 100644
index 00000000..9998448e
--- /dev/null
+++ b/src/PhpSpreadsheet/Reader/Gnumeric/Styles.php
@@ -0,0 +1,282 @@
+ [
+ '0' => Border::BORDER_NONE,
+ '1' => Border::BORDER_THIN,
+ '2' => Border::BORDER_MEDIUM,
+ '3' => Border::BORDER_SLANTDASHDOT,
+ '4' => Border::BORDER_DASHED,
+ '5' => Border::BORDER_THICK,
+ '6' => Border::BORDER_DOUBLE,
+ '7' => Border::BORDER_DOTTED,
+ '8' => Border::BORDER_MEDIUMDASHED,
+ '9' => Border::BORDER_DASHDOT,
+ '10' => Border::BORDER_MEDIUMDASHDOT,
+ '11' => Border::BORDER_DASHDOTDOT,
+ '12' => Border::BORDER_MEDIUMDASHDOTDOT,
+ '13' => Border::BORDER_MEDIUMDASHDOTDOT,
+ ],
+ 'fillType' => [
+ '1' => Fill::FILL_SOLID,
+ '2' => Fill::FILL_PATTERN_DARKGRAY,
+ '3' => Fill::FILL_PATTERN_MEDIUMGRAY,
+ '4' => Fill::FILL_PATTERN_LIGHTGRAY,
+ '5' => Fill::FILL_PATTERN_GRAY125,
+ '6' => Fill::FILL_PATTERN_GRAY0625,
+ '7' => Fill::FILL_PATTERN_DARKHORIZONTAL, // horizontal stripe
+ '8' => Fill::FILL_PATTERN_DARKVERTICAL, // vertical stripe
+ '9' => Fill::FILL_PATTERN_DARKDOWN, // diagonal stripe
+ '10' => Fill::FILL_PATTERN_DARKUP, // reverse diagonal stripe
+ '11' => Fill::FILL_PATTERN_DARKGRID, // diagoanl crosshatch
+ '12' => Fill::FILL_PATTERN_DARKTRELLIS, // thick diagonal crosshatch
+ '13' => Fill::FILL_PATTERN_LIGHTHORIZONTAL,
+ '14' => Fill::FILL_PATTERN_LIGHTVERTICAL,
+ '15' => Fill::FILL_PATTERN_LIGHTUP,
+ '16' => Fill::FILL_PATTERN_LIGHTDOWN,
+ '17' => Fill::FILL_PATTERN_LIGHTGRID, // thin horizontal crosshatch
+ '18' => Fill::FILL_PATTERN_LIGHTTRELLIS, // thin diagonal crosshatch
+ ],
+ 'horizontal' => [
+ '1' => Alignment::HORIZONTAL_GENERAL,
+ '2' => Alignment::HORIZONTAL_LEFT,
+ '4' => Alignment::HORIZONTAL_RIGHT,
+ '8' => Alignment::HORIZONTAL_CENTER,
+ '16' => Alignment::HORIZONTAL_CENTER_CONTINUOUS,
+ '32' => Alignment::HORIZONTAL_JUSTIFY,
+ '64' => Alignment::HORIZONTAL_CENTER_CONTINUOUS,
+ ],
+ 'underline' => [
+ '1' => Font::UNDERLINE_SINGLE,
+ '2' => Font::UNDERLINE_DOUBLE,
+ '3' => Font::UNDERLINE_SINGLEACCOUNTING,
+ '4' => Font::UNDERLINE_DOUBLEACCOUNTING,
+ ],
+ 'vertical' => [
+ '1' => Alignment::VERTICAL_TOP,
+ '2' => Alignment::VERTICAL_BOTTOM,
+ '4' => Alignment::VERTICAL_CENTER,
+ '8' => Alignment::VERTICAL_JUSTIFY,
+ ],
+ ];
+
+ public function __construct(Spreadsheet $spreadsheet, bool $readDataOnly)
+ {
+ $this->spreadsheet = $spreadsheet;
+ $this->readDataOnly = $readDataOnly;
+ }
+
+ public function read(SimpleXMLElement $sheet, int $maxRow, int $maxCol): void
+ {
+ if ($sheet->Styles->StyleRegion !== null) {
+ $this->readStyles($sheet->Styles->StyleRegion, $maxRow, $maxCol);
+ }
+ }
+
+ private function readStyles(SimpleXMLElement $styleRegion, int $maxRow, int $maxCol): void
+ {
+ foreach ($styleRegion as $style) {
+ if ($style === null) {
+ continue;
+ }
+
+ $styleAttributes = $style->attributes();
+ if ($styleAttributes !== null && ($styleAttributes['startRow'] <= $maxRow) && ($styleAttributes['startCol'] <= $maxCol)) {
+ $cellRange = $this->readStyleRange($styleAttributes, $maxCol, $maxRow);
+
+ $styleAttributes = $style->Style->attributes();
+
+ $styleArray = [];
+ // We still set the number format mask for date/time values, even if readDataOnly is true
+ // so that we can identify whether a float is a float or a date value
+ $formatCode = (string) $styleAttributes['Format'];
+ if (Date::isDateTimeFormatCode($formatCode)) {
+ $styleArray['numberFormat']['formatCode'] = $formatCode;
+ }
+ if ($this->readDataOnly === false && $styleAttributes !== null) {
+ // If readDataOnly is false, we set all formatting information
+ $styleArray['numberFormat']['formatCode'] = $formatCode;
+ $styleArray = $this->readStyle($styleArray, $styleAttributes, $style);
+ }
+ $this->spreadsheet->getActiveSheet()->getStyle($cellRange)->applyFromArray($styleArray);
+ }
+ }
+ }
+
+ private function addBorderDiagonal(SimpleXMLElement $srssb, array &$styleArray): void
+ {
+ if (isset($srssb->Diagonal, $srssb->{'Rev-Diagonal'})) {
+ $styleArray['borders']['diagonal'] = self::parseBorderAttributes($srssb->Diagonal->attributes());
+ $styleArray['borders']['diagonalDirection'] = Borders::DIAGONAL_BOTH;
+ } elseif (isset($srssb->Diagonal)) {
+ $styleArray['borders']['diagonal'] = self::parseBorderAttributes($srssb->Diagonal->attributes());
+ $styleArray['borders']['diagonalDirection'] = Borders::DIAGONAL_UP;
+ } elseif (isset($srssb->{'Rev-Diagonal'})) {
+ $styleArray['borders']['diagonal'] = self::parseBorderAttributes($srssb->{'Rev-Diagonal'}->attributes());
+ $styleArray['borders']['diagonalDirection'] = Borders::DIAGONAL_DOWN;
+ }
+ }
+
+ private function addBorderStyle(SimpleXMLElement $srssb, array &$styleArray, string $direction): void
+ {
+ $ucDirection = ucfirst($direction);
+ if (isset($srssb->$ucDirection)) {
+ $styleArray['borders'][$direction] = self::parseBorderAttributes($srssb->$ucDirection->attributes());
+ }
+ }
+
+ private function calcRotation(SimpleXMLElement $styleAttributes): int
+ {
+ $rotation = (int) $styleAttributes->Rotation;
+ if ($rotation >= 270 && $rotation <= 360) {
+ $rotation -= 360;
+ }
+ $rotation = (abs($rotation) > 90) ? 0 : $rotation;
+
+ return $rotation;
+ }
+
+ private static function addStyle(array &$styleArray, string $key, string $value): void
+ {
+ if (array_key_exists($value, self::$mappings[$key])) {
+ $styleArray[$key] = self::$mappings[$key][$value];
+ }
+ }
+
+ private static function addStyle2(array &$styleArray, string $key1, string $key, string $value): void
+ {
+ if (array_key_exists($value, self::$mappings[$key])) {
+ $styleArray[$key1][$key] = self::$mappings[$key][$value];
+ }
+ }
+
+ private static function parseBorderAttributes(?SimpleXMLElement $borderAttributes): array
+ {
+ $styleArray = [];
+ if ($borderAttributes !== null) {
+ if (isset($borderAttributes['Color'])) {
+ $styleArray['color']['rgb'] = self::parseGnumericColour($borderAttributes['Color']);
+ }
+
+ self::addStyle($styleArray, 'borderStyle', $borderAttributes['Style']);
+ }
+
+ return $styleArray;
+ }
+
+ private static function parseGnumericColour(string $gnmColour): string
+ {
+ [$gnmR, $gnmG, $gnmB] = explode(':', $gnmColour);
+ $gnmR = substr(str_pad($gnmR, 4, '0', STR_PAD_RIGHT), 0, 2);
+ $gnmG = substr(str_pad($gnmG, 4, '0', STR_PAD_RIGHT), 0, 2);
+ $gnmB = substr(str_pad($gnmB, 4, '0', STR_PAD_RIGHT), 0, 2);
+
+ return $gnmR . $gnmG . $gnmB;
+ }
+
+ private function addColors(array &$styleArray, SimpleXMLElement $styleAttributes): void
+ {
+ $RGB = self::parseGnumericColour($styleAttributes['Fore']);
+ $styleArray['font']['color']['rgb'] = $RGB;
+ $RGB = self::parseGnumericColour($styleAttributes['Back']);
+ $shade = (string) $styleAttributes['Shade'];
+ if (($RGB !== '000000') || ($shade !== '0')) {
+ $RGB2 = self::parseGnumericColour($styleAttributes['PatternColor']);
+ if ($shade === '1') {
+ $styleArray['fill']['startColor']['rgb'] = $RGB;
+ $styleArray['fill']['endColor']['rgb'] = $RGB2;
+ } else {
+ $styleArray['fill']['endColor']['rgb'] = $RGB;
+ $styleArray['fill']['startColor']['rgb'] = $RGB2;
+ }
+ self::addStyle2($styleArray, 'fill', 'fillType', $shade);
+ }
+ }
+
+ private function readStyleRange(SimpleXMLElement $styleAttributes, int $maxCol, int $maxRow): string
+ {
+ $startColumn = Coordinate::stringFromColumnIndex((int) $styleAttributes['startCol'] + 1);
+ $startRow = $styleAttributes['startRow'] + 1;
+
+ $endColumn = ($styleAttributes['endCol'] > $maxCol) ? $maxCol : (int) $styleAttributes['endCol'];
+ $endColumn = Coordinate::stringFromColumnIndex($endColumn + 1);
+
+ $endRow = 1 + (($styleAttributes['endRow'] > $maxRow) ? $maxRow : (int) $styleAttributes['endRow']);
+ $cellRange = $startColumn . $startRow . ':' . $endColumn . $endRow;
+
+ return $cellRange;
+ }
+
+ private function readStyle(array $styleArray, SimpleXMLElement $styleAttributes, SimpleXMLElement $style): array
+ {
+ self::addStyle2($styleArray, 'alignment', 'horizontal', $styleAttributes['HAlign']);
+ self::addStyle2($styleArray, 'alignment', 'vertical', $styleAttributes['VAlign']);
+ $styleArray['alignment']['wrapText'] = $styleAttributes['WrapText'] == '1';
+ $styleArray['alignment']['textRotation'] = $this->calcRotation($styleAttributes);
+ $styleArray['alignment']['shrinkToFit'] = $styleAttributes['ShrinkToFit'] == '1';
+ $styleArray['alignment']['indent'] = ((int) ($styleAttributes['Indent']) > 0) ? $styleAttributes['indent'] : 0;
+
+ $this->addColors($styleArray, $styleAttributes);
+
+ $fontAttributes = $style->Style->Font->attributes();
+ if ($fontAttributes !== null) {
+ $styleArray['font']['name'] = (string) $style->Style->Font;
+ $styleArray['font']['size'] = (int) ($fontAttributes['Unit']);
+ $styleArray['font']['bold'] = $fontAttributes['Bold'] == '1';
+ $styleArray['font']['italic'] = $fontAttributes['Italic'] == '1';
+ $styleArray['font']['strikethrough'] = $fontAttributes['StrikeThrough'] == '1';
+ self::addStyle2($styleArray, 'font', 'underline', $fontAttributes['Underline']);
+
+ switch ($fontAttributes['Script']) {
+ case '1':
+ $styleArray['font']['superscript'] = true;
+
+ break;
+ case '-1':
+ $styleArray['font']['subscript'] = true;
+
+ break;
+ }
+ }
+
+ if (isset($style->Style->StyleBorder)) {
+ $srssb = $style->Style->StyleBorder;
+ $this->addBorderStyle($srssb, $styleArray, 'top');
+ $this->addBorderStyle($srssb, $styleArray, 'bottom');
+ $this->addBorderStyle($srssb, $styleArray, 'left');
+ $this->addBorderStyle($srssb, $styleArray, 'right');
+ $this->addBorderDiagonal($srssb, $styleArray);
+ }
+ if (isset($style->Style->HyperLink)) {
+ // TO DO
+ $hyperlink = $style->Style->HyperLink->attributes();
+ }
+
+ return $styleArray;
+ }
+}
diff --git a/src/PhpSpreadsheet/Reader/Html.php b/src/PhpSpreadsheet/Reader/Html.php
index f235f9b1..b7faac87 100644
--- a/src/PhpSpreadsheet/Reader/Html.php
+++ b/src/PhpSpreadsheet/Reader/Html.php
@@ -220,13 +220,13 @@ class Html extends BaseReader
/**
* Set input encoding.
*
- * @deprecated no use is made of this property
- *
* @param string $pValue Input encoding, eg: 'ANSI'
*
* @return $this
*
* @codeCoverageIgnore
+ *
+ * @deprecated no use is made of this property
*/
public function setInputEncoding($pValue)
{
@@ -238,11 +238,11 @@ class Html extends BaseReader
/**
* Get input encoding.
*
- * @deprecated no use is made of this property
- *
* @return string
*
* @codeCoverageIgnore
+ *
+ * @deprecated no use is made of this property
*/
public function getInputEncoding()
{
@@ -469,7 +469,7 @@ class Html extends BaseReader
if ($child->nodeName === 'table') {
$this->flushCell($sheet, $column, $row, $cellContent);
$column = $this->setTableStartColumn($column);
- if ($this->tableLevel > 1) {
+ if ($this->tableLevel > 1 && $row > 1) {
--$row;
}
$this->processDomElement($child, $sheet, $row, $column, $cellContent);
@@ -620,7 +620,7 @@ class Html extends BaseReader
$cellContent .= $domText;
}
// but if we have a rich text run instead, we need to append it correctly
- // TODO
+ // TODO
} elseif ($child instanceof DOMElement) {
$this->processDomElementBody($sheet, $row, $column, $cellContent, $child);
}
@@ -878,14 +878,14 @@ class Html extends BaseReader
case 'width':
$sheet->getColumnDimension($column)->setWidth(
- str_replace('px', '', $styleValue)
+ (float) str_replace(['px', 'pt'], '', $styleValue)
);
break;
case 'height':
$sheet->getRowDimension($row)->setRowHeight(
- str_replace('px', '', $styleValue)
+ (float) str_replace(['px', 'pt'], '', $styleValue)
);
break;
@@ -922,8 +922,8 @@ class Html extends BaseReader
}
/**
- * @param string $column
- * @param int $row
+ * @param string $column
+ * @param int $row
*/
private function insertImage(Worksheet $sheet, $column, $row, array $attributes): void
{
@@ -990,7 +990,7 @@ class Html extends BaseReader
/**
* Map html border style to PhpSpreadsheet border style.
*
- * @param string $style
+ * @param string $style
*
* @return null|string
*/
@@ -1009,7 +1009,15 @@ class Html extends BaseReader
$borderStyle = Border::BORDER_NONE;
$color = null;
} else {
- [, $borderStyle, $color] = explode(' ', $styleValue);
+ $borderArray = explode(' ', $styleValue);
+ $borderCount = count($borderArray);
+ if ($borderCount >= 3) {
+ $borderStyle = $borderArray[1];
+ $color = $borderArray[2];
+ } else {
+ $borderStyle = $borderArray[0];
+ $color = $borderArray[1] ?? null;
+ }
}
$cellStyle->applyFromArray([
diff --git a/src/PhpSpreadsheet/Reader/Ods.php b/src/PhpSpreadsheet/Reader/Ods.php
index 1a4d7ca3..26151cdc 100644
--- a/src/PhpSpreadsheet/Reader/Ods.php
+++ b/src/PhpSpreadsheet/Reader/Ods.php
@@ -11,8 +11,9 @@ use DOMNode;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\Cell\DataType;
-use PhpOffice\PhpSpreadsheet\DefinedName;
use PhpOffice\PhpSpreadsheet\Reader\Exception as ReaderException;
+use PhpOffice\PhpSpreadsheet\Reader\Ods\AutoFilter;
+use PhpOffice\PhpSpreadsheet\Reader\Ods\DefinedNames;
use PhpOffice\PhpSpreadsheet\Reader\Ods\PageSettings;
use PhpOffice\PhpSpreadsheet\Reader\Ods\Properties as DocumentProperties;
use PhpOffice\PhpSpreadsheet\Reader\Security\XmlScanner;
@@ -22,7 +23,6 @@ use PhpOffice\PhpSpreadsheet\Shared\Date;
use PhpOffice\PhpSpreadsheet\Shared\File;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
-use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
use Throwable;
use XMLReader;
use ZipArchive;
@@ -304,8 +304,10 @@ class Ods extends BaseReader
$pageSettings->readStyleCrossReferences($dom);
- // Content
+ $autoFilterReader = new AutoFilter($spreadsheet, $tableNs);
+ $definedNameReader = new DefinedNames($spreadsheet, $tableNs);
+ // Content
$spreadsheets = $dom->getElementsByTagNameNS($officeNs, 'body')
->item(0)
->getElementsByTagNameNS($officeNs, 'spreadsheet');
@@ -642,8 +644,8 @@ class Ods extends BaseReader
++$worksheetID;
}
- $this->readDefinedRanges($spreadsheet, $workbookData, $tableNs);
- $this->readDefinedExpressions($spreadsheet, $workbookData, $tableNs);
+ $autoFilterReader->read($workbookData);
+ $definedNameReader->read($workbookData);
}
$spreadsheet->setActiveSheetIndex(0);
@@ -771,26 +773,6 @@ class Ods extends BaseReader
return $value;
}
- private function convertToExcelAddressValue(string $openOfficeAddress): string
- {
- $excelAddress = $openOfficeAddress;
-
- // Cell range 3-d reference
- // As we don't support 3-d ranges, we're just going to take a quick and dirty approach
- // and assume that the second worksheet reference is the same as the first
- $excelAddress = preg_replace('/\$?([^\.]+)\.([^\.]+):\$?([^\.]+)\.([^\.]+)/miu', '$1!$2:$4', $excelAddress);
- // Cell range reference in another sheet
- $excelAddress = preg_replace('/\$?([^\.]+)\.([^\.]+):\.([^\.]+)/miu', '$1!$2:$3', $excelAddress);
- // Cell reference in another sheet
- $excelAddress = preg_replace('/\$?([^\.]+)\.([^\.]+)/miu', '$1!$2', $excelAddress);
- // Cell range reference
- $excelAddress = preg_replace('/\.([^\.]+):\.([^\.]+)/miu', '$1:$2', $excelAddress);
- // Simple cell reference
- $excelAddress = preg_replace('/\.([^\.]+)/miu', '$1', $excelAddress);
-
- return $excelAddress;
- }
-
private function convertToExcelFormulaValue(string $openOfficeFormula): string
{
$temp = explode('"', $openOfficeFormula);
@@ -801,11 +783,13 @@ class Ods extends BaseReader
// Cell range reference in another sheet
$value = preg_replace('/\[\$?([^\.]+)\.([^\.]+):\.([^\.]+)\]/miu', '$1!$2:$3', $value);
// Cell reference in another sheet
- $value = preg_replace('/\[\$?([^\.]+)\.([^\.]+)\]/miu', '$1!$2', $value);
+ $value = preg_replace('/\[\$?([^\.]+)\.([^\.]+)\]/miu', '$1!$2', $value ?? '');
// Cell range reference
- $value = preg_replace('/\[\.([^\.]+):\.([^\.]+)\]/miu', '$1:$2', $value);
+ $value = preg_replace('/\[\.([^\.]+):\.([^\.]+)\]/miu', '$1:$2', $value ?? '');
// Simple cell reference
- $value = preg_replace('/\[\.([^\.]+)\]/miu', '$1', $value);
+ $value = preg_replace('/\[\.([^\.]+)\]/miu', '$1', $value ?? '');
+ // Convert references to defined names/formulae
+ $value = str_replace('$$', '', $value ?? '');
$value = Calculation::translateSeparator(';', ',', $value, $inBraces);
}
@@ -816,53 +800,4 @@ class Ods extends BaseReader
return $excelFormula;
}
-
- /**
- * Read any Named Ranges that are defined in this spreadsheet.
- */
- private function readDefinedRanges(Spreadsheet $spreadsheet, DOMElement $workbookData, string $tableNs): void
- {
- $namedRanges = $workbookData->getElementsByTagNameNS($tableNs, 'named-range');
- foreach ($namedRanges as $definedNameElement) {
- $definedName = $definedNameElement->getAttributeNS($tableNs, 'name');
- $baseAddress = $definedNameElement->getAttributeNS($tableNs, 'base-cell-address');
- $range = $definedNameElement->getAttributeNS($tableNs, 'cell-range-address');
-
- $baseAddress = $this->convertToExcelAddressValue($baseAddress);
- $range = $this->convertToExcelAddressValue($range);
-
- $this->addDefinedName($spreadsheet, $baseAddress, $definedName, $range);
- }
- }
-
- /**
- * Read any Named Formulae that are defined in this spreadsheet.
- */
- private function readDefinedExpressions(Spreadsheet $spreadsheet, DOMElement $workbookData, string $tableNs): void
- {
- $namedExpressions = $workbookData->getElementsByTagNameNS($tableNs, 'named-expression');
- foreach ($namedExpressions as $definedNameElement) {
- $definedName = $definedNameElement->getAttributeNS($tableNs, 'name');
- $baseAddress = $definedNameElement->getAttributeNS($tableNs, 'base-cell-address');
- $expression = $definedNameElement->getAttributeNS($tableNs, 'expression');
-
- $baseAddress = $this->convertToExcelAddressValue($baseAddress);
- $expression = $this->convertToExcelFormulaValue($expression);
-
- $this->addDefinedName($spreadsheet, $baseAddress, $definedName, $expression);
- }
- }
-
- /**
- * Assess scope and store the Defined Name.
- */
- private function addDefinedName(Spreadsheet $spreadsheet, string $baseAddress, string $definedName, string $value): void
- {
- [$sheetReference] = Worksheet::extractSheetTitle($baseAddress, true);
- $worksheet = $spreadsheet->getSheetByName($sheetReference);
- // Worksheet might still be null if we're only loading selected sheets rather than the full spreadsheet
- if ($worksheet !== null) {
- $spreadsheet->addDefinedName(DefinedName::createInstance((string) $definedName, $worksheet, $value));
- }
- }
}
diff --git a/src/PhpSpreadsheet/Reader/Ods/AutoFilter.php b/src/PhpSpreadsheet/Reader/Ods/AutoFilter.php
new file mode 100644
index 00000000..bdc8b3ff
--- /dev/null
+++ b/src/PhpSpreadsheet/Reader/Ods/AutoFilter.php
@@ -0,0 +1,45 @@
+readAutoFilters($workbookData);
+ }
+
+ protected function readAutoFilters(DOMElement $workbookData): void
+ {
+ $databases = $workbookData->getElementsByTagNameNS($this->tableNs, 'database-ranges');
+
+ foreach ($databases as $autofilters) {
+ foreach ($autofilters->childNodes as $autofilter) {
+ $autofilterRange = $this->getAttributeValue($autofilter, 'target-range-address');
+ if ($autofilterRange !== null) {
+ $baseAddress = $this->convertToExcelAddressValue($autofilterRange);
+ $this->spreadsheet->getActiveSheet()->setAutoFilter($baseAddress);
+ }
+ }
+ }
+ }
+
+ protected function getAttributeValue(?DOMNode $node, string $attributeName): ?string
+ {
+ if ($node !== null && $node->attributes !== null) {
+ $attribute = $node->attributes->getNamedItemNS(
+ $this->tableNs,
+ $attributeName
+ );
+
+ if ($attribute !== null) {
+ return $attribute->nodeValue;
+ }
+ }
+
+ return null;
+ }
+}
diff --git a/src/PhpSpreadsheet/Reader/Ods/BaseReader.php b/src/PhpSpreadsheet/Reader/Ods/BaseReader.php
new file mode 100644
index 00000000..17e2d4d5
--- /dev/null
+++ b/src/PhpSpreadsheet/Reader/Ods/BaseReader.php
@@ -0,0 +1,77 @@
+spreadsheet = $spreadsheet;
+ $this->tableNs = $tableNs;
+ }
+
+ abstract public function read(DOMElement $workbookData): void;
+
+ protected function convertToExcelAddressValue(string $openOfficeAddress): string
+ {
+ $excelAddress = $openOfficeAddress;
+
+ // Cell range 3-d reference
+ // As we don't support 3-d ranges, we're just going to take a quick and dirty approach
+ // and assume that the second worksheet reference is the same as the first
+ $excelAddress = preg_replace('/\$?([^\.]+)\.([^\.]+):\$?([^\.]+)\.([^\.]+)/miu', '$1!$2:$4', $excelAddress);
+ // Cell range reference in another sheet
+ $excelAddress = preg_replace('/\$?([^\.]+)\.([^\.]+):\.([^\.]+)/miu', '$1!$2:$3', $excelAddress ?? '');
+ // Cell reference in another sheet
+ $excelAddress = preg_replace('/\$?([^\.]+)\.([^\.]+)/miu', '$1!$2', $excelAddress ?? '');
+ // Cell range reference
+ $excelAddress = preg_replace('/\.([^\.]+):\.([^\.]+)/miu', '$1:$2', $excelAddress ?? '');
+ // Simple cell reference
+ $excelAddress = preg_replace('/\.([^\.]+)/miu', '$1', $excelAddress ?? '');
+
+ return $excelAddress ?? '';
+ }
+
+ protected function convertToExcelFormulaValue(string $openOfficeFormula): string
+ {
+ $temp = explode('"', $openOfficeFormula);
+ $tKey = false;
+ foreach ($temp as &$value) {
+ // @var string $value
+ // Only replace in alternate array entries (i.e. non-quoted blocks)
+ if ($tKey = !$tKey) {
+ // Cell range reference in another sheet
+ $value = preg_replace('/\[\$?([^\.]+)\.([^\.]+):\.([^\.]+)\]/miu', '$1!$2:$3', $value);
+ // Cell reference in another sheet
+ $value = preg_replace('/\[\$?([^\.]+)\.([^\.]+)\]/miu', '$1!$2', $value ?? '');
+ // Cell range reference
+ $value = preg_replace('/\[\.([^\.]+):\.([^\.]+)\]/miu', '$1:$2', $value ?? '');
+ // Simple cell reference
+ $value = preg_replace('/\[\.([^\.]+)\]/miu', '$1', $value ?? '');
+ // Convert references to defined names/formulae
+ $value = str_replace('$$', '', $value ?? '');
+
+ $value = Calculation::translateSeparator(';', ',', $value, $inBraces);
+ }
+ }
+
+ // Then rebuild the formula string
+ $excelFormula = implode('"', $temp);
+
+ return $excelFormula;
+ }
+}
diff --git a/src/PhpSpreadsheet/Reader/Ods/DefinedNames.php b/src/PhpSpreadsheet/Reader/Ods/DefinedNames.php
new file mode 100644
index 00000000..6810a3c7
--- /dev/null
+++ b/src/PhpSpreadsheet/Reader/Ods/DefinedNames.php
@@ -0,0 +1,66 @@
+readDefinedRanges($workbookData);
+ $this->readDefinedExpressions($workbookData);
+ }
+
+ /**
+ * Read any Named Ranges that are defined in this spreadsheet.
+ */
+ protected function readDefinedRanges(DOMElement $workbookData): void
+ {
+ $namedRanges = $workbookData->getElementsByTagNameNS($this->tableNs, 'named-range');
+ foreach ($namedRanges as $definedNameElement) {
+ $definedName = $definedNameElement->getAttributeNS($this->tableNs, 'name');
+ $baseAddress = $definedNameElement->getAttributeNS($this->tableNs, 'base-cell-address');
+ $range = $definedNameElement->getAttributeNS($this->tableNs, 'cell-range-address');
+
+ $baseAddress = $this->convertToExcelAddressValue($baseAddress);
+ $range = $this->convertToExcelAddressValue($range);
+
+ $this->addDefinedName($baseAddress, $definedName, $range);
+ }
+ }
+
+ /**
+ * Read any Named Formulae that are defined in this spreadsheet.
+ */
+ protected function readDefinedExpressions(DOMElement $workbookData): void
+ {
+ $namedExpressions = $workbookData->getElementsByTagNameNS($this->tableNs, 'named-expression');
+ foreach ($namedExpressions as $definedNameElement) {
+ $definedName = $definedNameElement->getAttributeNS($this->tableNs, 'name');
+ $baseAddress = $definedNameElement->getAttributeNS($this->tableNs, 'base-cell-address');
+ $expression = $definedNameElement->getAttributeNS($this->tableNs, 'expression');
+
+ $baseAddress = $this->convertToExcelAddressValue($baseAddress);
+ $expression = substr($expression, strpos($expression, ':=') + 1);
+ $expression = $this->convertToExcelFormulaValue($expression);
+
+ $this->addDefinedName($baseAddress, $definedName, $expression);
+ }
+ }
+
+ /**
+ * Assess scope and store the Defined Name.
+ */
+ private function addDefinedName(string $baseAddress, string $definedName, string $value): void
+ {
+ [$sheetReference] = Worksheet::extractSheetTitle($baseAddress, true);
+ $worksheet = $this->spreadsheet->getSheetByName($sheetReference);
+ // Worksheet might still be null if we're only loading selected sheets rather than the full spreadsheet
+ if ($worksheet !== null) {
+ $this->spreadsheet->addDefinedName(DefinedName::createInstance((string) $definedName, $worksheet, $value));
+ }
+ }
+}
diff --git a/src/PhpSpreadsheet/Reader/Security/XmlScanner.php b/src/PhpSpreadsheet/Reader/Security/XmlScanner.php
index a65797c1..c9c3ecc0 100644
--- a/src/PhpSpreadsheet/Reader/Security/XmlScanner.php
+++ b/src/PhpSpreadsheet/Reader/Security/XmlScanner.php
@@ -18,6 +18,11 @@ class XmlScanner
private static $libxmlDisableEntityLoaderValue;
+ /**
+ * @var bool
+ */
+ private static $shutdownRegistered = false;
+
public function __construct($pattern = 'pattern = $pattern;
@@ -25,7 +30,10 @@ class XmlScanner
$this->disableEntityLoaderCheck();
// A fatal error will bypass the destructor, so we register a shutdown here
- register_shutdown_function([__CLASS__, 'shutdown']);
+ if (!self::$shutdownRegistered) {
+ self::$shutdownRegistered = true;
+ register_shutdown_function([__CLASS__, 'shutdown']);
+ }
}
public static function getInstance(Reader\IReader $reader)
diff --git a/src/PhpSpreadsheet/Reader/Xls.php b/src/PhpSpreadsheet/Reader/Xls.php
index c389105b..470bbacc 100644
--- a/src/PhpSpreadsheet/Reader/Xls.php
+++ b/src/PhpSpreadsheet/Reader/Xls.php
@@ -7,6 +7,7 @@ use PhpOffice\PhpSpreadsheet\Cell\DataType;
use PhpOffice\PhpSpreadsheet\Cell\DataValidation;
use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException;
use PhpOffice\PhpSpreadsheet\NamedRange;
+use PhpOffice\PhpSpreadsheet\Reader\Xls\Style\CellFont;
use PhpOffice\PhpSpreadsheet\RichText\RichText;
use PhpOffice\PhpSpreadsheet\Shared\CodePage;
use PhpOffice\PhpSpreadsheet\Shared\Date;
@@ -2067,39 +2068,11 @@ class Xls extends BaseReader
// offset: 8; size: 2; escapement type
$escapement = self::getUInt2d($recordData, 8);
- switch ($escapement) {
- case 0x0001:
- $objFont->setSuperscript(true);
-
- break;
- case 0x0002:
- $objFont->setSubscript(true);
-
- break;
- }
+ CellFont::escapement($objFont, $escapement);
// offset: 10; size: 1; underline type
$underlineType = ord($recordData[10]);
- switch ($underlineType) {
- case 0x00:
- break; // no underline
- case 0x01:
- $objFont->setUnderline(Font::UNDERLINE_SINGLE);
-
- break;
- case 0x02:
- $objFont->setUnderline(Font::UNDERLINE_DOUBLE);
-
- break;
- case 0x21:
- $objFont->setUnderline(Font::UNDERLINE_SINGLEACCOUNTING);
-
- break;
- case 0x22:
- $objFont->setUnderline(Font::UNDERLINE_DOUBLEACCOUNTING);
-
- break;
- }
+ CellFont::underline($objFont, $underlineType);
// offset: 11; size: 1; font family
// offset: 12; size: 1; character set
@@ -2219,68 +2192,15 @@ class Xls extends BaseReader
// offset: 6; size: 1; Alignment and text break
// bit 2-0, mask 0x07; horizontal alignment
$horAlign = (0x07 & ord($recordData[6])) >> 0;
- switch ($horAlign) {
- case 0:
- $objStyle->getAlignment()->setHorizontal(Alignment::HORIZONTAL_GENERAL);
+ Xls\Style\CellAlignment::horizontal($objStyle->getAlignment(), $horAlign);
- break;
- case 1:
- $objStyle->getAlignment()->setHorizontal(Alignment::HORIZONTAL_LEFT);
-
- break;
- case 2:
- $objStyle->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
-
- break;
- case 3:
- $objStyle->getAlignment()->setHorizontal(Alignment::HORIZONTAL_RIGHT);
-
- break;
- case 4:
- $objStyle->getAlignment()->setHorizontal(Alignment::HORIZONTAL_FILL);
-
- break;
- case 5:
- $objStyle->getAlignment()->setHorizontal(Alignment::HORIZONTAL_JUSTIFY);
-
- break;
- case 6:
- $objStyle->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER_CONTINUOUS);
-
- break;
- }
// bit 3, mask 0x08; wrap text
$wrapText = (0x08 & ord($recordData[6])) >> 3;
- switch ($wrapText) {
- case 0:
- $objStyle->getAlignment()->setWrapText(false);
+ Xls\Style\CellAlignment::wrap($objStyle->getAlignment(), $wrapText);
- break;
- case 1:
- $objStyle->getAlignment()->setWrapText(true);
-
- break;
- }
// bit 6-4, mask 0x70; vertical alignment
$vertAlign = (0x70 & ord($recordData[6])) >> 4;
- switch ($vertAlign) {
- case 0:
- $objStyle->getAlignment()->setVertical(Alignment::VERTICAL_TOP);
-
- break;
- case 1:
- $objStyle->getAlignment()->setVertical(Alignment::VERTICAL_CENTER);
-
- break;
- case 2:
- $objStyle->getAlignment()->setVertical(Alignment::VERTICAL_BOTTOM);
-
- break;
- case 3:
- $objStyle->getAlignment()->setVertical(Alignment::VERTICAL_JUSTIFY);
-
- break;
- }
+ Xls\Style\CellAlignment::vertical($objStyle->getAlignment(), $vertAlign);
if ($this->version == self::XLS_BIFF8) {
// offset: 7; size: 1; XF_ROTATION: Text rotation angle
@@ -3634,7 +3554,7 @@ class Xls extends BaseReader
$level = (0x0700 & self::getUInt2d($recordData, 8)) >> 8;
// bit: 12; mask: 0x1000; 1 = collapsed
- $isCollapsed = (0x1000 & self::getUInt2d($recordData, 8)) >> 12;
+ $isCollapsed = (bool) ((0x1000 & self::getUInt2d($recordData, 8)) >> 12);
// offset: 10; size: 2; not used
@@ -3704,7 +3624,7 @@ class Xls extends BaseReader
$this->phpSheet->getRowDimension($r + 1)->setOutlineLevel($level);
// bit: 4; mask: 0x00000010; 1 = outline group start or ends here... and is collapsed
- $isCollapsed = (0x00000010 & self::getInt4d($recordData, 12)) >> 4;
+ $isCollapsed = (bool) ((0x00000010 & self::getInt4d($recordData, 12)) >> 4);
$this->phpSheet->getRowDimension($r + 1)->setCollapsed($isCollapsed);
// bit: 5; mask: 0x00000020; 1 = row is hidden
diff --git a/src/PhpSpreadsheet/Reader/Xls/Color/BIFF8.php b/src/PhpSpreadsheet/Reader/Xls/Color/BIFF8.php
index 5c109fb0..5d8b5ab8 100644
--- a/src/PhpSpreadsheet/Reader/Xls/Color/BIFF8.php
+++ b/src/PhpSpreadsheet/Reader/Xls/Color/BIFF8.php
@@ -5,62 +5,62 @@ namespace PhpOffice\PhpSpreadsheet\Reader\Xls\Color;
class BIFF8
{
protected static $map = [
- 0x08 => '000000',
- 0x09 => 'FFFFFF',
- 0x0A => 'FF0000',
- 0x0B => '00FF00',
- 0x0C => '0000FF',
- 0x0D => 'FFFF00',
- 0x0E => 'FF00FF',
- 0x0F => '00FFFF',
- 0x10 => '800000',
- 0x11 => '008000',
- 0x12 => '000080',
- 0x13 => '808000',
- 0x14 => '800080',
- 0x15 => '008080',
- 0x16 => 'C0C0C0',
- 0x17 => '808080',
- 0x18 => '9999FF',
- 0x19 => '993366',
- 0x1A => 'FFFFCC',
- 0x1B => 'CCFFFF',
- 0x1C => '660066',
- 0x1D => 'FF8080',
- 0x1E => '0066CC',
- 0x1F => 'CCCCFF',
- 0x20 => '000080',
- 0x21 => 'FF00FF',
- 0x22 => 'FFFF00',
- 0x23 => '00FFFF',
- 0x24 => '800080',
- 0x25 => '800000',
- 0x26 => '008080',
- 0x27 => '0000FF',
- 0x28 => '00CCFF',
- 0x29 => 'CCFFFF',
- 0x2A => 'CCFFCC',
- 0x2B => 'FFFF99',
- 0x2C => '99CCFF',
- 0x2D => 'FF99CC',
- 0x2E => 'CC99FF',
- 0x2F => 'FFCC99',
- 0x30 => '3366FF',
- 0x31 => '33CCCC',
- 0x32 => '99CC00',
- 0x33 => 'FFCC00',
- 0x34 => 'FF9900',
- 0x35 => 'FF6600',
- 0x36 => '666699',
- 0x37 => '969696',
- 0x38 => '003366',
- 0x39 => '339966',
- 0x3A => '003300',
- 0x3B => '333300',
- 0x3C => '993300',
- 0x3D => '993366',
- 0x3E => '333399',
- 0x3F => '333333',
+ '000000' => 0x08,
+ 'FFFFFF' => 0x09,
+ 'FF0000' => 0x0A,
+ '00FF00' => 0x0B,
+ '0000FF' => 0x0C,
+ 'FFFF00' => 0x0D,
+ 'FF00FF' => 0x0E,
+ '00FFFF' => 0x0F,
+ '800000' => 0x10,
+ '008000' => 0x11,
+ '000080' => 0x12,
+ '808000' => 0x13,
+ '800080' => 0x14,
+ '008080' => 0x15,
+ 'C0C0C0' => 0x16,
+ '808080' => 0x17,
+ '9999FF' => 0x18,
+ '993366' => 0x19,
+ 'FFFFCC' => 0x1A,
+ 'CCFFFF' => 0x1B,
+ '660066' => 0x1C,
+ 'FF8080' => 0x1D,
+ '0066CC' => 0x1E,
+ 'CCCCFF' => 0x1F,
+ // '000080' => 0x20,
+ // 'FF00FF' => 0x21,
+ // 'FFFF00' => 0x22,
+ // '00FFFF' => 0x23,
+ // '800080' => 0x24,
+ // '800000' => 0x25,
+ // '008080' => 0x26,
+ // '0000FF' => 0x27,
+ '00CCFF' => 0x28,
+ // 'CCFFFF' => 0x29,
+ 'CCFFCC' => 0x2A,
+ 'FFFF99' => 0x2B,
+ '99CCFF' => 0x2C,
+ 'FF99CC' => 0x2D,
+ 'CC99FF' => 0x2E,
+ 'FFCC99' => 0x2F,
+ '3366FF' => 0x30,
+ '33CCCC' => 0x31,
+ '99CC00' => 0x32,
+ 'FFCC00' => 0x33,
+ 'FF9900' => 0x34,
+ 'FF6600' => 0x35,
+ '666699' => 0x36,
+ '969696' => 0x37,
+ '003366' => 0x38,
+ '339966' => 0x39,
+ '003300' => 0x3A,
+ '333300' => 0x3B,
+ '993300' => 0x3C,
+ // '993366' => 0x3D,
+ '333399' => 0x3E,
+ '333333' => 0x3F,
];
/**
diff --git a/src/PhpSpreadsheet/Reader/Xls/Style/Border.php b/src/PhpSpreadsheet/Reader/Xls/Style/Border.php
index 91cbe36f..d832eb02 100644
--- a/src/PhpSpreadsheet/Reader/Xls/Style/Border.php
+++ b/src/PhpSpreadsheet/Reader/Xls/Style/Border.php
@@ -6,7 +6,10 @@ use PhpOffice\PhpSpreadsheet\Style\Border as StyleBorder;
class Border
{
- protected static $map = [
+ /**
+ * @var array
+ */
+ protected static $borderStyleMap = [
0x00 => StyleBorder::BORDER_NONE,
0x01 => StyleBorder::BORDER_THIN,
0x02 => StyleBorder::BORDER_MEDIUM,
@@ -23,18 +26,10 @@ class Border
0x0D => StyleBorder::BORDER_SLANTDASHDOT,
];
- /**
- * Map border style
- * OpenOffice documentation: 2.5.11.
- *
- * @param int $index
- *
- * @return string
- */
- public static function lookup($index)
+ public static function lookup(int $index): string
{
- if (isset(self::$map[$index])) {
- return self::$map[$index];
+ if (isset(self::$borderStyleMap[$index])) {
+ return self::$borderStyleMap[$index];
}
return StyleBorder::BORDER_NONE;
diff --git a/src/PhpSpreadsheet/Reader/Xls/Style/CellAlignment.php b/src/PhpSpreadsheet/Reader/Xls/Style/CellAlignment.php
new file mode 100644
index 00000000..f03d47fa
--- /dev/null
+++ b/src/PhpSpreadsheet/Reader/Xls/Style/CellAlignment.php
@@ -0,0 +1,50 @@
+
+ */
+ protected static $horizontalAlignmentMap = [
+ 0 => Alignment::HORIZONTAL_GENERAL,
+ 1 => Alignment::HORIZONTAL_LEFT,
+ 2 => Alignment::HORIZONTAL_CENTER,
+ 3 => Alignment::HORIZONTAL_RIGHT,
+ 4 => Alignment::HORIZONTAL_FILL,
+ 5 => Alignment::HORIZONTAL_JUSTIFY,
+ 6 => Alignment::HORIZONTAL_CENTER_CONTINUOUS,
+ ];
+
+ /**
+ * @var array
+ */
+ protected static $verticalAlignmentMap = [
+ 0 => Alignment::VERTICAL_TOP,
+ 1 => Alignment::VERTICAL_CENTER,
+ 2 => Alignment::VERTICAL_BOTTOM,
+ 3 => Alignment::VERTICAL_JUSTIFY,
+ ];
+
+ public static function horizontal(Alignment $alignment, int $horizontal): void
+ {
+ if (array_key_exists($horizontal, self::$horizontalAlignmentMap)) {
+ $alignment->setHorizontal(self::$horizontalAlignmentMap[$horizontal]);
+ }
+ }
+
+ public static function vertical(Alignment $alignment, int $vertical): void
+ {
+ if (array_key_exists($vertical, self::$verticalAlignmentMap)) {
+ $alignment->setVertical(self::$verticalAlignmentMap[$vertical]);
+ }
+ }
+
+ public static function wrap(Alignment $alignment, int $wrap): void
+ {
+ $alignment->setWrapText((bool) $wrap);
+ }
+}
diff --git a/src/PhpSpreadsheet/Reader/Xls/Style/CellFont.php b/src/PhpSpreadsheet/Reader/Xls/Style/CellFont.php
new file mode 100644
index 00000000..e975be4d
--- /dev/null
+++ b/src/PhpSpreadsheet/Reader/Xls/Style/CellFont.php
@@ -0,0 +1,39 @@
+setSuperscript(true);
+
+ break;
+ case 0x0002:
+ $font->setSubscript(true);
+
+ break;
+ }
+ }
+
+ /**
+ * @var array
+ */
+ protected static $underlineMap = [
+ 0x01 => Font::UNDERLINE_SINGLE,
+ 0x02 => Font::UNDERLINE_DOUBLE,
+ 0x21 => Font::UNDERLINE_SINGLEACCOUNTING,
+ 0x22 => Font::UNDERLINE_DOUBLEACCOUNTING,
+ ];
+
+ public static function underline(Font $font, int $underline): void
+ {
+ if (array_key_exists($underline, self::$underlineMap)) {
+ $font->setUnderline(self::$underlineMap[$underline]);
+ }
+ }
+}
diff --git a/src/PhpSpreadsheet/Reader/Xls/Style/FillPattern.php b/src/PhpSpreadsheet/Reader/Xls/Style/FillPattern.php
index 7b85c088..32ab5c85 100644
--- a/src/PhpSpreadsheet/Reader/Xls/Style/FillPattern.php
+++ b/src/PhpSpreadsheet/Reader/Xls/Style/FillPattern.php
@@ -6,7 +6,10 @@ use PhpOffice\PhpSpreadsheet\Style\Fill;
class FillPattern
{
- protected static $map = [
+ /**
+ * @var array
+ */
+ protected static $fillPatternMap = [
0x00 => Fill::FILL_NONE,
0x01 => Fill::FILL_SOLID,
0x02 => Fill::FILL_PATTERN_MEDIUMGRAY,
@@ -38,8 +41,8 @@ class FillPattern
*/
public static function lookup($index)
{
- if (isset(self::$map[$index])) {
- return self::$map[$index];
+ if (isset(self::$fillPatternMap[$index])) {
+ return self::$fillPatternMap[$index];
}
return Fill::FILL_NONE;
diff --git a/src/PhpSpreadsheet/Reader/Xlsx.php b/src/PhpSpreadsheet/Reader/Xlsx.php
index a7c71c73..f07ac008 100644
--- a/src/PhpSpreadsheet/Reader/Xlsx.php
+++ b/src/PhpSpreadsheet/Reader/Xlsx.php
@@ -27,12 +27,8 @@ use PhpOffice\PhpSpreadsheet\Shared\File;
use PhpOffice\PhpSpreadsheet\Shared\Font;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
-use PhpOffice\PhpSpreadsheet\Style\Border;
-use PhpOffice\PhpSpreadsheet\Style\Borders;
use PhpOffice\PhpSpreadsheet\Style\Color;
-use PhpOffice\PhpSpreadsheet\Style\Fill;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
-use PhpOffice\PhpSpreadsheet\Style\Protection;
use PhpOffice\PhpSpreadsheet\Style\Style;
use PhpOffice\PhpSpreadsheet\Worksheet\HeaderFooterDrawing;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
@@ -634,6 +630,12 @@ class Xlsx extends BaseReader
}
if ($xmlSheet) {
+ // Setting Conditional Styles adjusts selected cells, so we need to execute this
+ // before reading the sheet view data to get the actual selected cells
+ if (!$this->readDataOnly && $xmlSheet->conditionalFormatting) {
+ (new ConditionalStyles($docSheet, $xmlSheet, $dxfs))->load();
+ }
+
if (isset($xmlSheet->sheetViews, $xmlSheet->sheetViews->sheetView)) {
$sheetViews = new SheetViews($xmlSheet->sheetViews->sheetView, $docSheet);
$sheetViews->load();
@@ -767,10 +769,6 @@ class Xlsx extends BaseReader
}
}
- if (!$this->readDataOnly && $xmlSheet && $xmlSheet->conditionalFormatting) {
- (new ConditionalStyles($docSheet, $xmlSheet, $dxfs))->load();
- }
-
$aKeys = ['sheet', 'objects', 'scenarios', 'formatCells', 'formatColumns', 'formatRows', 'insertColumns', 'insertRows', 'insertHyperlinks', 'deleteColumns', 'deleteRows', 'selectLockedCells', 'sort', 'autoFilter', 'pivotTables', 'selectUnlockedCells'];
if (!$this->readDataOnly && $xmlSheet && $xmlSheet->sheetProtection) {
foreach ($aKeys as $key) {
@@ -1570,31 +1568,6 @@ class Xlsx extends BaseReader
return $excel;
}
- private static function readColor($color, $background = false)
- {
- if (isset($color['rgb'])) {
- return (string) $color['rgb'];
- } elseif (isset($color['indexed'])) {
- return Color::indexedColor($color['indexed'] - 7, $background)->getARGB();
- } elseif (isset($color['theme'])) {
- if (self::$theme !== null) {
- $returnColour = self::$theme->getColourByIndex((int) $color['theme']);
- if (isset($color['tint'])) {
- $tintAdjust = (float) $color['tint'];
- $returnColour = Color::changeBrightness($returnColour, $tintAdjust);
- }
-
- return 'FF' . $returnColour;
- }
- }
-
- if ($background) {
- return 'FFFFFFFF';
- }
-
- return 'FF000000';
- }
-
/**
* @param SimpleXMLElement|stdClass $style
*/
@@ -1604,134 +1577,33 @@ class Xlsx extends BaseReader
// font
if (isset($style->font)) {
- $docStyle->getFont()->setName((string) $style->font->name['val']);
- $docStyle->getFont()->setSize((string) $style->font->sz['val']);
- if (isset($style->font->b)) {
- $docStyle->getFont()->setBold(!isset($style->font->b['val']) || self::boolean((string) $style->font->b['val']));
- }
- if (isset($style->font->i)) {
- $docStyle->getFont()->setItalic(!isset($style->font->i['val']) || self::boolean((string) $style->font->i['val']));
- }
- if (isset($style->font->strike)) {
- $docStyle->getFont()->setStrikethrough(!isset($style->font->strike['val']) || self::boolean((string) $style->font->strike['val']));
- }
- $docStyle->getFont()->getColor()->setARGB(self::readColor($style->font->color));
-
- if (isset($style->font->u) && !isset($style->font->u['val'])) {
- $docStyle->getFont()->setUnderline(\PhpOffice\PhpSpreadsheet\Style\Font::UNDERLINE_SINGLE);
- } elseif (isset($style->font->u, $style->font->u['val'])) {
- $docStyle->getFont()->setUnderline((string) $style->font->u['val']);
- }
-
- if (isset($style->font->vertAlign, $style->font->vertAlign['val'])) {
- $vertAlign = strtolower((string) $style->font->vertAlign['val']);
- if ($vertAlign == 'superscript') {
- $docStyle->getFont()->setSuperscript(true);
- }
- if ($vertAlign == 'subscript') {
- $docStyle->getFont()->setSubscript(true);
- }
- }
+ Styles::readFontStyle($docStyle->getFont(), $style->font);
}
// fill
if (isset($style->fill)) {
- if ($style->fill->gradientFill) {
- /** @var SimpleXMLElement $gradientFill */
- $gradientFill = $style->fill->gradientFill[0];
- if (!empty($gradientFill['type'])) {
- $docStyle->getFill()->setFillType((string) $gradientFill['type']);
- }
- $docStyle->getFill()->setRotation((float) ($gradientFill['degree']));
- $gradientFill->registerXPathNamespace('sml', 'http://schemas.openxmlformats.org/spreadsheetml/2006/main');
- $docStyle->getFill()->getStartColor()->setARGB(self::readColor(self::getArrayItem($gradientFill->xpath('sml:stop[@position=0]'))->color));
- $docStyle->getFill()->getEndColor()->setARGB(self::readColor(self::getArrayItem($gradientFill->xpath('sml:stop[@position=1]'))->color));
- } elseif ($style->fill->patternFill) {
- $patternType = (string) $style->fill->patternFill['patternType'] != '' ? (string) $style->fill->patternFill['patternType'] : Fill::FILL_NONE;
- $docStyle->getFill()->setFillType($patternType);
- if ($style->fill->patternFill->fgColor) {
- $docStyle->getFill()->getStartColor()->setARGB(self::readColor($style->fill->patternFill->fgColor, true));
- }
- if ($style->fill->patternFill->bgColor) {
- $docStyle->getFill()->getEndColor()->setARGB(self::readColor($style->fill->patternFill->bgColor, true));
- }
- }
+ Styles::readFillStyle($docStyle->getFill(), $style->fill);
}
// border
if (isset($style->border)) {
- $diagonalUp = self::boolean((string) $style->border['diagonalUp']);
- $diagonalDown = self::boolean((string) $style->border['diagonalDown']);
- if (!$diagonalUp && !$diagonalDown) {
- $docStyle->getBorders()->setDiagonalDirection(Borders::DIAGONAL_NONE);
- } elseif ($diagonalUp && !$diagonalDown) {
- $docStyle->getBorders()->setDiagonalDirection(Borders::DIAGONAL_UP);
- } elseif (!$diagonalUp && $diagonalDown) {
- $docStyle->getBorders()->setDiagonalDirection(Borders::DIAGONAL_DOWN);
- } else {
- $docStyle->getBorders()->setDiagonalDirection(Borders::DIAGONAL_BOTH);
- }
- self::readBorder($docStyle->getBorders()->getLeft(), $style->border->left);
- self::readBorder($docStyle->getBorders()->getRight(), $style->border->right);
- self::readBorder($docStyle->getBorders()->getTop(), $style->border->top);
- self::readBorder($docStyle->getBorders()->getBottom(), $style->border->bottom);
- self::readBorder($docStyle->getBorders()->getDiagonal(), $style->border->diagonal);
+ Styles::readBorderStyle($docStyle->getBorders(), $style->border);
}
// alignment
if (isset($style->alignment)) {
- $docStyle->getAlignment()->setHorizontal((string) $style->alignment['horizontal']);
- $docStyle->getAlignment()->setVertical((string) $style->alignment['vertical']);
-
- $textRotation = 0;
- if ((int) $style->alignment['textRotation'] <= 90) {
- $textRotation = (int) $style->alignment['textRotation'];
- } elseif ((int) $style->alignment['textRotation'] > 90) {
- $textRotation = 90 - (int) $style->alignment['textRotation'];
- }
-
- $docStyle->getAlignment()->setTextRotation((int) $textRotation);
- $docStyle->getAlignment()->setWrapText(self::boolean((string) $style->alignment['wrapText']));
- $docStyle->getAlignment()->setShrinkToFit(self::boolean((string) $style->alignment['shrinkToFit']));
- $docStyle->getAlignment()->setIndent((int) ((string) $style->alignment['indent']) > 0 ? (int) ((string) $style->alignment['indent']) : 0);
- $docStyle->getAlignment()->setReadOrder((int) ((string) $style->alignment['readingOrder']) > 0 ? (int) ((string) $style->alignment['readingOrder']) : 0);
+ Styles::readAlignmentStyle($docStyle->getAlignment(), $style->alignment);
}
// protection
if (isset($style->protection)) {
- if (isset($style->protection['locked'])) {
- if (self::boolean((string) $style->protection['locked'])) {
- $docStyle->getProtection()->setLocked(Protection::PROTECTION_PROTECTED);
- } else {
- $docStyle->getProtection()->setLocked(Protection::PROTECTION_UNPROTECTED);
- }
- }
-
- if (isset($style->protection['hidden'])) {
- if (self::boolean((string) $style->protection['hidden'])) {
- $docStyle->getProtection()->setHidden(Protection::PROTECTION_PROTECTED);
- } else {
- $docStyle->getProtection()->setHidden(Protection::PROTECTION_UNPROTECTED);
- }
- }
+ Styles::readProtectionLocked($docStyle, $style->protection);
+ Styles::readProtectionHidden($docStyle, $style->protection);
}
// top-level style settings
if (isset($style->quotePrefix)) {
- $docStyle->setQuotePrefix($style->quotePrefix);
- }
- }
-
- /**
- * @param SimpleXMLElement $eleBorder
- */
- private static function readBorder(Border $docBorder, $eleBorder): void
- {
- if (isset($eleBorder['style'])) {
- $docBorder->setBorderStyle((string) $eleBorder['style']);
- }
- if (isset($eleBorder->color)) {
- $docBorder->getColor()->setARGB(self::readColor($eleBorder->color));
+ $docStyle->setQuotePrefix((bool) $style->quotePrefix);
}
}
@@ -1763,7 +1635,7 @@ class Xlsx extends BaseReader
$objText->getFont()->setSize((float) $run->rPr->sz['val']);
}
if (isset($run->rPr->color)) {
- $objText->getFont()->setColor(new Color(self::readColor($run->rPr->color)));
+ $objText->getFont()->setColor(new Color(Styles::readColor($run->rPr->color)));
}
if (
(isset($run->rPr->b['val']) && self::boolean((string) $run->rPr->b['val'])) ||
@@ -1949,11 +1821,17 @@ class Xlsx extends BaseReader
}
if ($xmlWorkbook->workbookProtection['revisionsPassword']) {
- $excel->getSecurity()->setRevisionsPassword((string) $xmlWorkbook->workbookProtection['revisionsPassword'], true);
+ $excel->getSecurity()->setRevisionsPassword(
+ (string) $xmlWorkbook->workbookProtection['revisionsPassword'],
+ true
+ );
}
if ($xmlWorkbook->workbookProtection['workbookPassword']) {
- $excel->getSecurity()->setWorkbookPassword((string) $xmlWorkbook->workbookProtection['workbookPassword'], true);
+ $excel->getSecurity()->setWorkbookPassword(
+ (string) $xmlWorkbook->workbookProtection['workbookPassword'],
+ true
+ );
}
}
diff --git a/src/PhpSpreadsheet/Reader/Xlsx/ConditionalStyles.php b/src/PhpSpreadsheet/Reader/Xlsx/ConditionalStyles.php
index 7f96956f..dcd7ad12 100644
--- a/src/PhpSpreadsheet/Reader/Xlsx/ConditionalStyles.php
+++ b/src/PhpSpreadsheet/Reader/Xlsx/ConditionalStyles.php
@@ -2,7 +2,6 @@
namespace PhpOffice\PhpSpreadsheet\Reader\Xlsx;
-use PhpOffice\PhpSpreadsheet\Style\Color;
use PhpOffice\PhpSpreadsheet\Style\Conditional;
use PhpOffice\PhpSpreadsheet\Style\ConditionalFormatting\ConditionalDataBar;
use PhpOffice\PhpSpreadsheet\Style\ConditionalFormatting\ConditionalFormattingRuleExtension;
@@ -39,15 +38,7 @@ class ConditionalStyles
$conditionals = [];
foreach ($xmlSheet->conditionalFormatting as $conditional) {
foreach ($conditional->cfRule as $cfRule) {
- if (
- ((string) $cfRule['type'] == Conditional::CONDITION_NONE
- || (string) $cfRule['type'] == Conditional::CONDITION_CELLIS
- || (string) $cfRule['type'] == Conditional::CONDITION_CONTAINSTEXT
- || (string) $cfRule['type'] == Conditional::CONDITION_CONTAINSBLANKS
- || (string) $cfRule['type'] == Conditional::CONDITION_NOTCONTAINSBLANKS
- || (string) $cfRule['type'] == Conditional::CONDITION_EXPRESSION)
- && isset($this->dxfs[(int) ($cfRule['dxfId'])])
- ) {
+ if (Conditional::isValidConditionType((string) $cfRule['type']) && isset($this->dxfs[(int) ($cfRule['dxfId'])])) {
$conditionals[(string) $conditional['sqref']][(int) ($cfRule['priority'])] = $cfRule;
} elseif ((string) $cfRule['type'] == Conditional::CONDITION_DATABAR) {
$conditionals[(string) $conditional['sqref']][(int) ($cfRule['priority'])] = $cfRule;
@@ -98,7 +89,9 @@ class ConditionalStyles
}
if (isset($cfRule->dataBar)) {
- $objConditional->setDataBar($this->readDataBarOfConditionalRule($cfRule, $conditionalFormattingRuleExtensions));
+ $objConditional->setDataBar(
+ $this->readDataBarOfConditionalRule($cfRule, $conditionalFormattingRuleExtensions)
+ );
} else {
$objConditional->setStyle(clone $this->dxfs[(int) ($cfRule['dxfId'])]);
}
diff --git a/src/PhpSpreadsheet/Reader/Xlsx/Styles.php b/src/PhpSpreadsheet/Reader/Xlsx/Styles.php
index c43ccc97..80c32065 100644
--- a/src/PhpSpreadsheet/Reader/Xlsx/Styles.php
+++ b/src/PhpSpreadsheet/Reader/Xlsx/Styles.php
@@ -40,11 +40,14 @@ class Styles extends BaseParserClass
$this->cellStyles = $cellStyles;
}
- private static function readFontStyle(Font $fontStyle, SimpleXMLElement $fontStyleXml): void
+ public static function readFontStyle(Font $fontStyle, SimpleXMLElement $fontStyleXml): void
{
- $fontStyle->setName((string) $fontStyleXml->name['val']);
- $fontStyle->setSize((float) $fontStyleXml->sz['val']);
-
+ if (isset($fontStyleXml->name, $fontStyleXml->name['val'])) {
+ $fontStyle->setName((string) $fontStyleXml->name['val']);
+ }
+ if (isset($fontStyleXml->sz, $fontStyleXml->sz['val'])) {
+ $fontStyle->setSize((float) $fontStyleXml->sz['val']);
+ }
if (isset($fontStyleXml->b)) {
$fontStyle->setBold(!isset($fontStyleXml->b['val']) || self::boolean((string) $fontStyleXml->b['val']));
}
@@ -52,7 +55,9 @@ class Styles extends BaseParserClass
$fontStyle->setItalic(!isset($fontStyleXml->i['val']) || self::boolean((string) $fontStyleXml->i['val']));
}
if (isset($fontStyleXml->strike)) {
- $fontStyle->setStrikethrough(!isset($fontStyleXml->strike['val']) || self::boolean((string) $fontStyleXml->strike['val']));
+ $fontStyle->setStrikethrough(
+ !isset($fontStyleXml->strike['val']) || self::boolean((string) $fontStyleXml->strike['val'])
+ );
}
$fontStyle->getColor()->setARGB(self::readColor($fontStyleXml->color));
@@ -66,8 +71,7 @@ class Styles extends BaseParserClass
$verticalAlign = strtolower((string) $fontStyleXml->vertAlign['val']);
if ($verticalAlign === 'superscript') {
$fontStyle->setSuperscript(true);
- }
- if ($verticalAlign === 'subscript') {
+ } elseif ($verticalAlign === 'subscript') {
$fontStyle->setSubscript(true);
}
}
@@ -84,7 +88,7 @@ class Styles extends BaseParserClass
}
}
- private static function readFillStyle(Fill $fillStyle, SimpleXMLElement $fillStyleXml): void
+ public static function readFillStyle(Fill $fillStyle, SimpleXMLElement $fillStyleXml): void
{
if ($fillStyleXml->gradientFill) {
/** @var SimpleXMLElement $gradientFill */
@@ -94,23 +98,32 @@ class Styles extends BaseParserClass
}
$fillStyle->setRotation((float) ($gradientFill['degree']));
$gradientFill->registerXPathNamespace('sml', 'http://schemas.openxmlformats.org/spreadsheetml/2006/main');
- $fillStyle->getStartColor()->setARGB(self::readColor(self::getArrayItem($gradientFill->xpath('sml:stop[@position=0]'))->color));
- $fillStyle->getEndColor()->setARGB(self::readColor(self::getArrayItem($gradientFill->xpath('sml:stop[@position=1]'))->color));
+ $fillStyle->getStartColor()->setARGB(
+ self::readColor(self::getArrayItem($gradientFill->xpath('sml:stop[@position=0]'))->color)
+ );
+ $fillStyle->getEndColor()->setARGB(
+ self::readColor(self::getArrayItem($gradientFill->xpath('sml:stop[@position=1]'))->color)
+ );
} elseif ($fillStyleXml->patternFill) {
- $patternType = (string) $fillStyleXml->patternFill['patternType'] != '' ? (string) $fillStyleXml->patternFill['patternType'] : Fill::FILL_NONE;
- $fillStyle->setFillType($patternType);
+ $defaultFillStyle = Fill::FILL_NONE;
if ($fillStyleXml->patternFill->fgColor) {
$fillStyle->getStartColor()->setARGB(self::readColor($fillStyleXml->patternFill->fgColor, true));
- } else {
- $fillStyle->getStartColor()->setARGB('FF000000');
+ $defaultFillStyle = Fill::FILL_SOLID;
}
if ($fillStyleXml->patternFill->bgColor) {
$fillStyle->getEndColor()->setARGB(self::readColor($fillStyleXml->patternFill->bgColor, true));
+ $defaultFillStyle = Fill::FILL_SOLID;
}
+
+ $patternType = (string) $fillStyleXml->patternFill['patternType'] != ''
+ ? (string) $fillStyleXml->patternFill['patternType']
+ : $defaultFillStyle;
+
+ $fillStyle->setFillType($patternType);
}
}
- private static function readBorderStyle(Borders $borderStyle, SimpleXMLElement $borderStyleXml): void
+ public static function readBorderStyle(Borders $borderStyle, SimpleXMLElement $borderStyleXml): void
{
$diagonalUp = self::boolean((string) $borderStyleXml['diagonalUp']);
$diagonalDown = self::boolean((string) $borderStyleXml['diagonalDown']);
@@ -141,7 +154,7 @@ class Styles extends BaseParserClass
}
}
- private static function readAlignmentStyle(Alignment $alignment, SimpleXMLElement $alignmentXml): void
+ public static function readAlignmentStyle(Alignment $alignment, SimpleXMLElement $alignmentXml): void
{
$alignment->setHorizontal((string) $alignmentXml['horizontal']);
$alignment->setVertical((string) $alignmentXml['vertical']);
@@ -156,8 +169,12 @@ class Styles extends BaseParserClass
$alignment->setTextRotation((int) $textRotation);
$alignment->setWrapText(self::boolean((string) $alignmentXml['wrapText']));
$alignment->setShrinkToFit(self::boolean((string) $alignmentXml['shrinkToFit']));
- $alignment->setIndent((int) ((string) $alignmentXml['indent']) > 0 ? (int) ((string) $alignmentXml['indent']) : 0);
- $alignment->setReadOrder((int) ((string) $alignmentXml['readingOrder']) > 0 ? (int) ((string) $alignmentXml['readingOrder']) : 0);
+ $alignment->setIndent(
+ (int) ((string) $alignmentXml['indent']) > 0 ? (int) ((string) $alignmentXml['indent']) : 0
+ );
+ $alignment->setReadOrder(
+ (int) ((string) $alignmentXml['readingOrder']) > 0 ? (int) ((string) $alignmentXml['readingOrder']) : 0
+ );
}
private function readStyle(Style $docStyle, $style): void
@@ -186,8 +203,8 @@ class Styles extends BaseParserClass
// protection
if (isset($style->protection)) {
- $this->readProtectionLocked($docStyle, $style);
- $this->readProtectionHidden($docStyle, $style);
+ self::readProtectionLocked($docStyle, $style);
+ self::readProtectionHidden($docStyle, $style);
}
// top-level style settings
@@ -196,7 +213,7 @@ class Styles extends BaseParserClass
}
}
- private function readProtectionLocked(Style $docStyle, $style): void
+ public static function readProtectionLocked(Style $docStyle, $style): void
{
if (isset($style->protection['locked'])) {
if (self::boolean((string) $style->protection['locked'])) {
@@ -207,7 +224,7 @@ class Styles extends BaseParserClass
}
}
- private function readProtectionHidden(Style $docStyle, $style): void
+ public static function readProtectionHidden(Style $docStyle, $style): void
{
if (isset($style->protection['hidden'])) {
if (self::boolean((string) $style->protection['hidden'])) {
@@ -218,7 +235,7 @@ class Styles extends BaseParserClass
}
}
- private static function readColor($color, $background = false)
+ public static function readColor($color, $background = false)
{
if (isset($color['rgb'])) {
return (string) $color['rgb'];
diff --git a/src/PhpSpreadsheet/Reader/Xml.php b/src/PhpSpreadsheet/Reader/Xml.php
index 282cd528..4ef4efe7 100644
--- a/src/PhpSpreadsheet/Reader/Xml.php
+++ b/src/PhpSpreadsheet/Reader/Xml.php
@@ -284,7 +284,7 @@ class Xml extends BaseReader
$worksheet_ss = self::getAttributes($worksheet, $namespaces['ss']);
if (
- (isset($this->loadSheetsOnly)) && (isset($worksheet_ss['Name'])) &&
+ isset($this->loadSheetsOnly, $worksheet_ss['Name']) &&
(!in_array($worksheet_ss['Name'], $this->loadSheetsOnly))
) {
continue;
diff --git a/src/PhpSpreadsheet/Shared/Date.php b/src/PhpSpreadsheet/Shared/Date.php
index 898dd523..3b4c635d 100644
--- a/src/PhpSpreadsheet/Shared/Date.php
+++ b/src/PhpSpreadsheet/Shared/Date.php
@@ -437,14 +437,14 @@ class Date
return false;
}
- $dateValueNew = DateTimeExcel\DateValue::funcDateValue($dateValue);
+ $dateValueNew = DateTimeExcel\DateValue::fromString($dateValue);
if ($dateValueNew === Functions::VALUE()) {
return false;
}
if (strpos($dateValue, ':') !== false) {
- $timeValue = DateTimeExcel\TimeValue::funcTimeValue($dateValue);
+ $timeValue = DateTimeExcel\TimeValue::fromString($dateValue);
if ($timeValue === Functions::VALUE()) {
return false;
}
diff --git a/src/PhpSpreadsheet/Spreadsheet.php b/src/PhpSpreadsheet/Spreadsheet.php
index fb945399..db617ef6 100644
--- a/src/PhpSpreadsheet/Spreadsheet.php
+++ b/src/PhpSpreadsheet/Spreadsheet.php
@@ -505,6 +505,8 @@ class Spreadsheet
{
$this->disconnectWorksheets();
$this->calculationEngine = null;
+ $this->cellXfCollection = [];
+ $this->cellStyleXfCollection = [];
}
/**
diff --git a/src/PhpSpreadsheet/Style/Conditional.php b/src/PhpSpreadsheet/Style/Conditional.php
index b008c9f2..4cbc2746 100644
--- a/src/PhpSpreadsheet/Style/Conditional.php
+++ b/src/PhpSpreadsheet/Style/Conditional.php
@@ -15,6 +15,18 @@ class Conditional implements IComparable
const CONDITION_CONTAINSBLANKS = 'containsBlanks';
const CONDITION_NOTCONTAINSBLANKS = 'notContainsBlanks';
const CONDITION_DATABAR = 'dataBar';
+ const CONDITION_NOTCONTAINSTEXT = 'notContainsText';
+
+ private const CONDITION_TYPES = [
+ self::CONDITION_CELLIS,
+ self::CONDITION_CONTAINSBLANKS,
+ self::CONDITION_CONTAINSTEXT,
+ self::CONDITION_DATABAR,
+ self::CONDITION_EXPRESSION,
+ self::CONDITION_NONE,
+ self::CONDITION_NOTCONTAINSBLANKS,
+ self::CONDITION_NOTCONTAINSTEXT,
+ ];
// Operator types
const OPERATOR_NONE = '';
@@ -300,4 +312,12 @@ class Conditional implements IComparable
}
}
}
+
+ /**
+ * Verify if param is valid condition type.
+ */
+ public static function isValidConditionType(string $type): bool
+ {
+ return in_array($type, self::CONDITION_TYPES);
+ }
}
diff --git a/src/PhpSpreadsheet/Style/ConditionalFormatting/ConditionalFormattingRuleExtension.php b/src/PhpSpreadsheet/Style/ConditionalFormatting/ConditionalFormattingRuleExtension.php
index 899bbe43..0797c2e8 100644
--- a/src/PhpSpreadsheet/Style/ConditionalFormatting/ConditionalFormattingRuleExtension.php
+++ b/src/PhpSpreadsheet/Style/ConditionalFormatting/ConditionalFormattingRuleExtension.php
@@ -2,6 +2,7 @@
namespace PhpOffice\PhpSpreadsheet\Style\ConditionalFormatting;
+use PhpOffice\PhpSpreadsheet\Style\Conditional;
use SimpleXMLElement;
class ConditionalFormattingRuleExtension
@@ -62,19 +63,23 @@ class ConditionalFormattingRuleExtension
$conditionalFormattingRuleExtensionXml = $extLst->ext;
}
}
+
if ($conditionalFormattingRuleExtensionXml) {
$ns = $conditionalFormattingRuleExtensionXml->getNamespaces(true);
$extFormattingsXml = $conditionalFormattingRuleExtensionXml->children($ns['x14']);
foreach ($extFormattingsXml->children($ns['x14']) as $extFormattingXml) {
$extCfRuleXml = $extFormattingXml->cfRule;
+ if (((string) $extCfRuleXml->attributes()->type) !== Conditional::CONDITION_DATABAR) {
+ continue;
+ }
+
$extFormattingRuleObj = new self((string) $extCfRuleXml->attributes()->id);
$extFormattingRuleObj->setSqref((string) $extFormattingXml->children($ns['xm'])->sqref);
$conditionalFormattingRuleExtensions[$extFormattingRuleObj->getId()] = $extFormattingRuleObj;
$extDataBarObj = new ConditionalDataBarExtension();
$extFormattingRuleObj->setDataBarExt($extDataBarObj);
-
$dataBarXml = $extCfRuleXml->dataBar;
self::parseExtDataBarAttributesFromXml($extDataBarObj, $dataBarXml);
self::parseExtDataBarElementChildrenFromXml($extDataBarObj, $dataBarXml, $ns);
@@ -85,8 +90,10 @@ class ConditionalFormattingRuleExtension
return $conditionalFormattingRuleExtensions;
}
- private static function parseExtDataBarAttributesFromXml(ConditionalDataBarExtension $extDataBarObj, SimpleXMLElement $dataBarXml): void
- {
+ private static function parseExtDataBarAttributesFromXml(
+ ConditionalDataBarExtension $extDataBarObj,
+ SimpleXMLElement $dataBarXml
+ ): void {
$dataBarAttribute = $dataBarXml->attributes();
if ($dataBarAttribute->minLength) {
$extDataBarObj->setMinLength((int) $dataBarAttribute->minLength);
diff --git a/src/PhpSpreadsheet/Style/NumberFormat/Formatter.php b/src/PhpSpreadsheet/Style/NumberFormat/Formatter.php
index ef756d7b..01407e64 100644
--- a/src/PhpSpreadsheet/Style/NumberFormat/Formatter.php
+++ b/src/PhpSpreadsheet/Style/NumberFormat/Formatter.php
@@ -130,7 +130,7 @@ class Formatter
// In Excel formats, "_" is used to add spacing,
// The following character indicates the size of the spacing, which we can't do in HTML, so we just use a standard space
- $format = preg_replace('/_/ui', ' ', $format);
+ $format = preg_replace('/_.?/ui', ' ', $format);
// Let's begin inspecting the format and converting the value to a formatted string
diff --git a/src/PhpSpreadsheet/Style/NumberFormat/NumberFormatter.php b/src/PhpSpreadsheet/Style/NumberFormat/NumberFormatter.php
index 9a4f32ac..0a94c333 100644
--- a/src/PhpSpreadsheet/Style/NumberFormat/NumberFormatter.php
+++ b/src/PhpSpreadsheet/Style/NumberFormat/NumberFormatter.php
@@ -3,6 +3,7 @@
namespace PhpOffice\PhpSpreadsheet\Style\NumberFormat;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
+use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
class NumberFormatter
{
@@ -145,7 +146,6 @@ class NumberFormatter
$format = preg_replace('/0,+/', '0', $format);
$format = preg_replace('/#,+/', '#', $format);
}
-
if (preg_match('/#?.*\?\/\?/', $format, $m)) {
if ($value != (int) $value) {
$value = FractionFormatter::format($value, $format);
@@ -163,7 +163,12 @@ class NumberFormatter
$n = '/\\[[^\\]]+\\]/';
$m = preg_replace($n, '', $format);
if (preg_match(self::NUMBER_REGEX, $m, $matches)) {
+ // There are placeholders for digits, so inject digits from the value into the mask
$value = self::formatStraightNumericValue($value, $format, $matches, $useThousands);
+ } elseif ($format !== NumberFormat::FORMAT_GENERAL) {
+ // Yes, I know that this is basically just a hack;
+ // if there's no placeholders for digits, just return the format mask "as is"
+ $value = str_replace('?', '', $format ?? '');
}
}
diff --git a/src/PhpSpreadsheet/Worksheet/AutoFilter.php b/src/PhpSpreadsheet/Worksheet/AutoFilter.php
index 1a710e40..b846f7b6 100644
--- a/src/PhpSpreadsheet/Worksheet/AutoFilter.php
+++ b/src/PhpSpreadsheet/Worksheet/AutoFilter.php
@@ -472,7 +472,7 @@ class AutoFilter
$val = $maxVal = null;
$ruleValues = [];
- $baseDate = DateTimeExcel\Now::funcNow();
+ $baseDate = DateTimeExcel\Current::now();
// Calculate start/end dates for the required date range based on current date
switch ($dynamicRuleType) {
case AutoFilter\Column\Rule::AUTOFILTER_RULETYPE_DYNAMIC_LASTWEEK:
diff --git a/src/PhpSpreadsheet/Worksheet/MemoryDrawing.php b/src/PhpSpreadsheet/Worksheet/MemoryDrawing.php
index cde23c96..7789543a 100644
--- a/src/PhpSpreadsheet/Worksheet/MemoryDrawing.php
+++ b/src/PhpSpreadsheet/Worksheet/MemoryDrawing.php
@@ -3,6 +3,7 @@
namespace PhpOffice\PhpSpreadsheet\Worksheet;
use GdImage;
+use PhpOffice\PhpSpreadsheet\Exception;
class MemoryDrawing extends BaseDrawing
{
@@ -21,7 +22,7 @@ class MemoryDrawing extends BaseDrawing
/**
* Image resource.
*
- * @var GdImage|resource
+ * @var null|GdImage|resource
*/
private $imageResource;
@@ -60,10 +61,71 @@ class MemoryDrawing extends BaseDrawing
parent::__construct();
}
+ public function __destruct()
+ {
+ if ($this->imageResource) {
+ imagedestroy($this->imageResource);
+ $this->imageResource = null;
+ }
+ }
+
+ public function __clone()
+ {
+ parent::__clone();
+ $this->cloneResource();
+ }
+
+ private function cloneResource(): void
+ {
+ if (!$this->imageResource) {
+ return;
+ }
+
+ $width = imagesx($this->imageResource);
+ $height = imagesy($this->imageResource);
+
+ if (imageistruecolor($this->imageResource)) {
+ $clone = imagecreatetruecolor($width, $height);
+ if (!$clone) {
+ throw new Exception('Could not clone image resource');
+ }
+
+ imagealphablending($clone, false);
+ imagesavealpha($clone, true);
+ } else {
+ $clone = imagecreate($width, $height);
+ if (!$clone) {
+ throw new Exception('Could not clone image resource');
+ }
+
+ // If the image has transparency...
+ $transparent = imagecolortransparent($this->imageResource);
+ if ($transparent >= 0) {
+ $rgb = imagecolorsforindex($this->imageResource, $transparent);
+ if ($rgb === false) {
+ throw new Exception('Could not get image colors');
+ }
+
+ imagesavealpha($clone, true);
+ $color = imagecolorallocatealpha($clone, $rgb['red'], $rgb['green'], $rgb['blue'], $rgb['alpha']);
+ if ($color === false) {
+ throw new Exception('Could not get image alpha color');
+ }
+
+ imagefill($clone, 0, 0, $color);
+ }
+ }
+
+ //Create the Clone!!
+ imagecopy($clone, $this->imageResource, 0, 0, 0, 0, $width, $height);
+
+ $this->imageResource = $clone;
+ }
+
/**
* Get image resource.
*
- * @return GdImage|resource
+ * @return null|GdImage|resource
*/
public function getImageResource()
{
diff --git a/src/PhpSpreadsheet/Worksheet/Worksheet.php b/src/PhpSpreadsheet/Worksheet/Worksheet.php
index 2ecd210c..0f260291 100644
--- a/src/PhpSpreadsheet/Worksheet/Worksheet.php
+++ b/src/PhpSpreadsheet/Worksheet/Worksheet.php
@@ -194,7 +194,7 @@ class Worksheet implements IComparable
/**
* Collection of protected cell ranges.
*
- * @var array
+ * @var string[]
*/
private $protectedCells = [];
@@ -399,6 +399,7 @@ class Worksheet implements IComparable
Calculation::getInstance($this->parent)->clearCalculationCacheForWorksheet($this->title);
$this->disconnectCells();
+ $this->rowDimensions = [];
}
/**
@@ -1263,22 +1264,23 @@ class Worksheet implements IComparable
*
* @param int $columnIndex Numeric column coordinate of the cell
* @param int $row Numeric row coordinate of the cell
- * @param bool $createIfNotExists Flag indicating whether a new cell should be created if it doesn't
- * already exist, or a null should be returned instead
*
- * @return null|Cell Cell that was found/created or null
+ * @return Cell Cell that was found/created or null
*/
- public function getCellByColumnAndRow($columnIndex, $row, $createIfNotExists = true)
+ public function getCellByColumnAndRow($columnIndex, $row): Cell
{
$columnLetter = Coordinate::stringFromColumnIndex($columnIndex);
$coordinate = $columnLetter . $row;
if ($this->cellCollection->has($coordinate)) {
- return $this->cellCollection->get($coordinate);
+ /** @var Cell $cell */
+ $cell = $this->cellCollection->get($coordinate);
+
+ return $cell;
}
// Create new cell object, if required
- return $createIfNotExists ? $this->createNewCell($coordinate) : null;
+ return $this->createNewCell($coordinate);
}
/**
@@ -1295,7 +1297,7 @@ class Worksheet implements IComparable
$this->cellCollectionIsSorted = false;
// Coordinates
- $aCoordinates = Coordinate::coordinateFromString($pCoordinate);
+ [$column, $row] = Coordinate::coordinateFromString($pCoordinate);
$aIndexes = Coordinate::indexesFromString($pCoordinate);
if ($this->cachedHighestColumn < $aIndexes[0]) {
$this->cachedHighestColumn = $aIndexes[0];
@@ -1306,8 +1308,8 @@ class Worksheet implements IComparable
// Cell needs appropriate xfIndex from dimensions records
// but don't create dimension records if they don't already exist
- $rowDimension = $this->getRowDimension($aCoordinates[1], false);
- $columnDimension = $this->getColumnDimension($aCoordinates[0], false);
+ $rowDimension = $this->rowDimensions[$row] ?? null;
+ $columnDimension = $this->columnDimensions[$column] ?? null;
if ($rowDimension !== null && $rowDimension->getXfIndex() > 0) {
// then there is a row dimension with explicit style, assign it to the cell
@@ -1352,20 +1354,11 @@ class Worksheet implements IComparable
* Get row dimension at a specific row.
*
* @param int $pRow Numeric index of the row
- * @param bool $create
- *
- * @return null|RowDimension
*/
- public function getRowDimension($pRow, $create = true)
+ public function getRowDimension(int $pRow): RowDimension
{
- // Found
- $found = null;
-
// Get row dimension
if (!isset($this->rowDimensions[$pRow])) {
- if (!$create) {
- return null;
- }
$this->rowDimensions[$pRow] = new RowDimension($pRow);
$this->cachedHighestRow = max($this->cachedHighestRow, $pRow);
@@ -1378,20 +1371,14 @@ class Worksheet implements IComparable
* Get column dimension at a specific column.
*
* @param string $pColumn String index of the column eg: 'A'
- * @param bool $create
- *
- * @return null|ColumnDimension
*/
- public function getColumnDimension($pColumn, $create = true)
+ public function getColumnDimension(string $pColumn): ColumnDimension
{
// Uppercase coordinate
$pColumn = strtoupper($pColumn);
// Fetch dimensions
if (!isset($this->columnDimensions[$pColumn])) {
- if (!$create) {
- return null;
- }
$this->columnDimensions[$pColumn] = new ColumnDimension($pColumn);
$columnIndex = Coordinate::columnIndexFromString($pColumn);
@@ -1407,10 +1394,8 @@ class Worksheet implements IComparable
* Get column dimension at a specific column by using numeric cell coordinates.
*
* @param int $columnIndex Numeric column coordinate of the cell
- *
- * @return null|ColumnDimension
*/
- public function getColumnDimensionByColumn($columnIndex)
+ public function getColumnDimensionByColumn(int $columnIndex): ColumnDimension
{
return $this->getColumnDimension(Coordinate::stringFromColumnIndex($columnIndex));
}
@@ -1871,7 +1856,7 @@ class Worksheet implements IComparable
/**
* Get protected cells.
*
- * @return array[]
+ * @return string[]
*/
public function getProtectedCells()
{
diff --git a/src/PhpSpreadsheet/Writer/Html.php b/src/PhpSpreadsheet/Writer/Html.php
index 4ee94114..b694d4ef 100644
--- a/src/PhpSpreadsheet/Writer/Html.php
+++ b/src/PhpSpreadsheet/Writer/Html.php
@@ -690,18 +690,21 @@ class Html extends BaseWriter
$drawing->getWidth() . 'px; height: ' . $drawing->getHeight() . 'px;" src="' .
$imageData . '" alt="' . $filedesc . '" />';
} elseif ($drawing instanceof MemoryDrawing) {
- ob_start(); // Let's start output buffering.
- imagepng($drawing->getImageResource()); // This will normally output the image, but because of ob_start(), it won't.
- $contents = ob_get_contents(); // Instead, output above is saved to $contents
- ob_end_clean(); // End the output buffer.
+ $imageResource = $drawing->getImageResource();
+ if ($imageResource) {
+ ob_start(); // Let's start output buffering.
+ imagepng($imageResource); // This will normally output the image, but because of ob_start(), it won't.
+ $contents = ob_get_contents(); // Instead, output above is saved to $contents
+ ob_end_clean(); // End the output buffer.
- $dataUri = 'data:image/jpeg;base64,' . base64_encode($contents);
+ $dataUri = 'data:image/jpeg;base64,' . base64_encode($contents);
- // Because of the nature of tables, width is more important than height.
- // max-width: 100% ensures that image doesnt overflow containing cell
- // width: X sets width of supplied image.
- // As a result, images bigger than cell will be contained and images smaller will not get stretched
- $html .= '
';
+ // Because of the nature of tables, width is more important than height.
+ // max-width: 100% ensures that image doesnt overflow containing cell
+ // width: X sets width of supplied image.
+ // As a result, images bigger than cell will be contained and images smaller will not get stretched
+ $html .= '
';
+ }
}
}
diff --git a/src/PhpSpreadsheet/Writer/Ods/AutoFilters.php b/src/PhpSpreadsheet/Writer/Ods/AutoFilters.php
new file mode 100644
index 00000000..cf0450f1
--- /dev/null
+++ b/src/PhpSpreadsheet/Writer/Ods/AutoFilters.php
@@ -0,0 +1,63 @@
+objWriter = $objWriter;
+ $this->spreadsheet = $spreadsheet;
+ }
+
+ public function write(): void
+ {
+ $wrapperWritten = false;
+ $sheetCount = $this->spreadsheet->getSheetCount();
+ for ($i = 0; $i < $sheetCount; ++$i) {
+ $worksheet = $this->spreadsheet->getSheet($i);
+ $autofilter = $worksheet->getAutoFilter();
+ if ($autofilter !== null && !empty($autofilter->getRange())) {
+ if ($wrapperWritten === false) {
+ $this->objWriter->startElement('table:database-ranges');
+ $wrapperWritten = true;
+ }
+ $this->objWriter->startElement('table:database-range');
+ $this->objWriter->writeAttribute('table:orientation', 'column');
+ $this->objWriter->writeAttribute('table:display-filter-buttons', 'true');
+ $this->objWriter->writeAttribute(
+ 'table:target-range-address',
+ $this->formatRange($worksheet, $autofilter)
+ );
+ $this->objWriter->endElement();
+ }
+ }
+
+ if ($wrapperWritten === true) {
+ $this->objWriter->endElement();
+ }
+ }
+
+ protected function formatRange(Worksheet $worksheet, Autofilter $autofilter): string
+ {
+ $title = $worksheet->getTitle();
+ $range = $autofilter->getRange();
+
+ return "'{$title}'.{$range}";
+ }
+}
diff --git a/src/PhpSpreadsheet/Writer/Ods/Content.php b/src/PhpSpreadsheet/Writer/Ods/Content.php
index e4bd1793..a589e549 100644
--- a/src/PhpSpreadsheet/Writer/Ods/Content.php
+++ b/src/PhpSpreadsheet/Writer/Ods/Content.php
@@ -101,6 +101,7 @@ class Content extends WriterPart
$this->writeSheets($objWriter);
+ (new AutoFilters($objWriter, $this->getParentWriter()->getSpreadsheet()))->write();
// Defined names (ranges and formulae)
(new NamedExpressions($objWriter, $this->getParentWriter()->getSpreadsheet(), $this->formulaConvertor))->write();
diff --git a/src/PhpSpreadsheet/Writer/Xls.php b/src/PhpSpreadsheet/Writer/Xls.php
index a1b477bf..4bece774 100644
--- a/src/PhpSpreadsheet/Writer/Xls.php
+++ b/src/PhpSpreadsheet/Writer/Xls.php
@@ -219,7 +219,8 @@ class Xls extends BaseWriter
$arrRootData[] = $OLE_DocumentSummaryInformation;
}
- $root = new Root(time(), time(), $arrRootData);
+ $time = $this->spreadsheet->getProperties()->getModified();
+ $root = new Root($time, $time, $arrRootData);
// save the OLE file
$this->openFileHandle($pFilename);
$root->save($this->fileHandle);
diff --git a/src/PhpSpreadsheet/Writer/Xls/CellDataValidation.php b/src/PhpSpreadsheet/Writer/Xls/CellDataValidation.php
new file mode 100644
index 00000000..7e9b3cfa
--- /dev/null
+++ b/src/PhpSpreadsheet/Writer/Xls/CellDataValidation.php
@@ -0,0 +1,78 @@
+
+ */
+ protected static $validationTypeMap = [
+ DataValidation::TYPE_NONE => 0x00,
+ DataValidation::TYPE_WHOLE => 0x01,
+ DataValidation::TYPE_DECIMAL => 0x02,
+ DataValidation::TYPE_LIST => 0x03,
+ DataValidation::TYPE_DATE => 0x04,
+ DataValidation::TYPE_TIME => 0x05,
+ DataValidation::TYPE_TEXTLENGTH => 0x06,
+ DataValidation::TYPE_CUSTOM => 0x07,
+ ];
+
+ /**
+ * @var array
+ */
+ protected static $errorStyleMap = [
+ DataValidation::STYLE_STOP => 0x00,
+ DataValidation::STYLE_WARNING => 0x01,
+ DataValidation::STYLE_INFORMATION => 0x02,
+ ];
+
+ /**
+ * @var array
+ */
+ protected static $operatorMap = [
+ DataValidation::OPERATOR_BETWEEN => 0x00,
+ DataValidation::OPERATOR_NOTBETWEEN => 0x01,
+ DataValidation::OPERATOR_EQUAL => 0x02,
+ DataValidation::OPERATOR_NOTEQUAL => 0x03,
+ DataValidation::OPERATOR_GREATERTHAN => 0x04,
+ DataValidation::OPERATOR_LESSTHAN => 0x05,
+ DataValidation::OPERATOR_GREATERTHANOREQUAL => 0x06,
+ DataValidation::OPERATOR_LESSTHANOREQUAL => 0x07,
+ ];
+
+ public static function type(DataValidation $dataValidation): int
+ {
+ $validationType = $dataValidation->getType();
+
+ if (is_string($validationType) && array_key_exists($validationType, self::$validationTypeMap)) {
+ return self::$validationTypeMap[$validationType];
+ }
+
+ return self::$validationTypeMap[DataValidation::TYPE_NONE];
+ }
+
+ public static function errorStyle(DataValidation $dataValidation): int
+ {
+ $errorStyle = $dataValidation->getErrorStyle();
+
+ if (is_string($errorStyle) && array_key_exists($errorStyle, self::$errorStyleMap)) {
+ return self::$errorStyleMap[$errorStyle];
+ }
+
+ return self::$errorStyleMap[DataValidation::STYLE_STOP];
+ }
+
+ public static function operator(DataValidation $dataValidation): int
+ {
+ $operator = $dataValidation->getOperator();
+
+ if (is_string($operator) && array_key_exists($operator, self::$operatorMap)) {
+ return self::$operatorMap[$operator];
+ }
+
+ return self::$operatorMap[DataValidation::OPERATOR_BETWEEN];
+ }
+}
diff --git a/src/PhpSpreadsheet/Writer/Xls/ErrorCode.php b/src/PhpSpreadsheet/Writer/Xls/ErrorCode.php
new file mode 100644
index 00000000..7a864f50
--- /dev/null
+++ b/src/PhpSpreadsheet/Writer/Xls/ErrorCode.php
@@ -0,0 +1,28 @@
+
+ */
+ protected static $errorCodeMap = [
+ '#NULL!' => 0x00,
+ '#DIV/0!' => 0x07,
+ '#VALUE!' => 0x0F,
+ '#REF!' => 0x17,
+ '#NAME?' => 0x1D,
+ '#NUM!' => 0x24,
+ '#N/A' => 0x2A,
+ ];
+
+ public static function error(string $errorCode): int
+ {
+ if (array_key_exists($errorCode, self::$errorCodeMap)) {
+ return self::$errorCodeMap[$errorCode];
+ }
+
+ return 0;
+ }
+}
diff --git a/src/PhpSpreadsheet/Writer/Xls/Style/CellAlignment.php b/src/PhpSpreadsheet/Writer/Xls/Style/CellAlignment.php
new file mode 100644
index 00000000..711d88d2
--- /dev/null
+++ b/src/PhpSpreadsheet/Writer/Xls/Style/CellAlignment.php
@@ -0,0 +1,59 @@
+
+ */
+ private static $horizontalMap = [
+ Alignment::HORIZONTAL_GENERAL => 0,
+ Alignment::HORIZONTAL_LEFT => 1,
+ Alignment::HORIZONTAL_RIGHT => 3,
+ Alignment::HORIZONTAL_CENTER => 2,
+ Alignment::HORIZONTAL_CENTER_CONTINUOUS => 6,
+ Alignment::HORIZONTAL_JUSTIFY => 5,
+ ];
+
+ /**
+ * @var array
+ */
+ private static $verticalMap = [
+ Alignment::VERTICAL_BOTTOM => 2,
+ Alignment::VERTICAL_TOP => 0,
+ Alignment::VERTICAL_CENTER => 1,
+ Alignment::VERTICAL_JUSTIFY => 3,
+ ];
+
+ public static function horizontal(Alignment $alignment): int
+ {
+ $horizontalAlignment = $alignment->getHorizontal();
+
+ if (is_string($horizontalAlignment) && array_key_exists($horizontalAlignment, self::$horizontalMap)) {
+ return self::$horizontalMap[$horizontalAlignment];
+ }
+
+ return self::$horizontalMap[Alignment::HORIZONTAL_GENERAL];
+ }
+
+ public static function wrap(Alignment $alignment): int
+ {
+ $wrap = $alignment->getWrapText();
+
+ return ($wrap === true) ? 1 : 0;
+ }
+
+ public static function vertical(Alignment $alignment): int
+ {
+ $verticalAlignment = $alignment->getVertical();
+
+ if (is_string($verticalAlignment) && array_key_exists($verticalAlignment, self::$verticalMap)) {
+ return self::$verticalMap[$verticalAlignment];
+ }
+
+ return self::$verticalMap[Alignment::VERTICAL_BOTTOM];
+ }
+}
diff --git a/src/PhpSpreadsheet/Writer/Xls/Style/CellBorder.php b/src/PhpSpreadsheet/Writer/Xls/Style/CellBorder.php
new file mode 100644
index 00000000..8d47d6aa
--- /dev/null
+++ b/src/PhpSpreadsheet/Writer/Xls/Style/CellBorder.php
@@ -0,0 +1,39 @@
+
+ */
+ protected static $styleMap = [
+ Border::BORDER_NONE => 0x00,
+ Border::BORDER_THIN => 0x01,
+ Border::BORDER_MEDIUM => 0x02,
+ Border::BORDER_DASHED => 0x03,
+ Border::BORDER_DOTTED => 0x04,
+ Border::BORDER_THICK => 0x05,
+ Border::BORDER_DOUBLE => 0x06,
+ Border::BORDER_HAIR => 0x07,
+ Border::BORDER_MEDIUMDASHED => 0x08,
+ Border::BORDER_DASHDOT => 0x09,
+ Border::BORDER_MEDIUMDASHDOT => 0x0A,
+ Border::BORDER_DASHDOTDOT => 0x0B,
+ Border::BORDER_MEDIUMDASHDOTDOT => 0x0C,
+ Border::BORDER_SLANTDASHDOT => 0x0D,
+ ];
+
+ public static function style(Border $border): int
+ {
+ $borderStyle = $border->getBorderStyle();
+
+ if (is_string($borderStyle) && array_key_exists($borderStyle, self::$styleMap)) {
+ return self::$styleMap[$borderStyle];
+ }
+
+ return self::$styleMap[Border::BORDER_NONE];
+ }
+}
diff --git a/src/PhpSpreadsheet/Writer/Xls/Style/CellFill.php b/src/PhpSpreadsheet/Writer/Xls/Style/CellFill.php
new file mode 100644
index 00000000..f5a8c470
--- /dev/null
+++ b/src/PhpSpreadsheet/Writer/Xls/Style/CellFill.php
@@ -0,0 +1,46 @@
+
+ */
+ protected static $fillStyleMap = [
+ Fill::FILL_NONE => 0x00,
+ Fill::FILL_SOLID => 0x01,
+ Fill::FILL_PATTERN_MEDIUMGRAY => 0x02,
+ Fill::FILL_PATTERN_DARKGRAY => 0x03,
+ Fill::FILL_PATTERN_LIGHTGRAY => 0x04,
+ Fill::FILL_PATTERN_DARKHORIZONTAL => 0x05,
+ Fill::FILL_PATTERN_DARKVERTICAL => 0x06,
+ Fill::FILL_PATTERN_DARKDOWN => 0x07,
+ Fill::FILL_PATTERN_DARKUP => 0x08,
+ Fill::FILL_PATTERN_DARKGRID => 0x09,
+ Fill::FILL_PATTERN_DARKTRELLIS => 0x0A,
+ Fill::FILL_PATTERN_LIGHTHORIZONTAL => 0x0B,
+ Fill::FILL_PATTERN_LIGHTVERTICAL => 0x0C,
+ Fill::FILL_PATTERN_LIGHTDOWN => 0x0D,
+ Fill::FILL_PATTERN_LIGHTUP => 0x0E,
+ Fill::FILL_PATTERN_LIGHTGRID => 0x0F,
+ Fill::FILL_PATTERN_LIGHTTRELLIS => 0x10,
+ Fill::FILL_PATTERN_GRAY125 => 0x11,
+ Fill::FILL_PATTERN_GRAY0625 => 0x12,
+ Fill::FILL_GRADIENT_LINEAR => 0x00, // does not exist in BIFF8
+ Fill::FILL_GRADIENT_PATH => 0x00, // does not exist in BIFF8
+ ];
+
+ public static function style(Fill $fill): int
+ {
+ $fillStyle = $fill->getFillType();
+
+ if (is_string($fillStyle) && array_key_exists($fillStyle, self::$fillStyleMap)) {
+ return self::$fillStyleMap[$fillStyle];
+ }
+
+ return self::$fillStyleMap[Fill::FILL_NONE];
+ }
+}
diff --git a/src/PhpSpreadsheet/Writer/Xls/Style/ColorMap.php b/src/PhpSpreadsheet/Writer/Xls/Style/ColorMap.php
new file mode 100644
index 00000000..caf85c04
--- /dev/null
+++ b/src/PhpSpreadsheet/Writer/Xls/Style/ColorMap.php
@@ -0,0 +1,90 @@
+
+ */
+ private static $colorMap = [
+ '#000000' => 0x08,
+ '#FFFFFF' => 0x09,
+ '#FF0000' => 0x0A,
+ '#00FF00' => 0x0B,
+ '#0000FF' => 0x0C,
+ '#FFFF00' => 0x0D,
+ '#FF00FF' => 0x0E,
+ '#00FFFF' => 0x0F,
+ '#800000' => 0x10,
+ '#008000' => 0x11,
+ '#000080' => 0x12,
+ '#808000' => 0x13,
+ '#800080' => 0x14,
+ '#008080' => 0x15,
+ '#C0C0C0' => 0x16,
+ '#808080' => 0x17,
+ '#9999FF' => 0x18,
+ '#993366' => 0x19,
+ '#FFFFCC' => 0x1A,
+ '#CCFFFF' => 0x1B,
+ '#660066' => 0x1C,
+ '#FF8080' => 0x1D,
+ '#0066CC' => 0x1E,
+ '#CCCCFF' => 0x1F,
+ // '#000080' => 0x20,
+ // '#FF00FF' => 0x21,
+ // '#FFFF00' => 0x22,
+ // '#00FFFF' => 0x23,
+ // '#800080' => 0x24,
+ // '#800000' => 0x25,
+ // '#008080' => 0x26,
+ // '#0000FF' => 0x27,
+ '#00CCFF' => 0x28,
+ // '#CCFFFF' => 0x29,
+ '#CCFFCC' => 0x2A,
+ '#FFFF99' => 0x2B,
+ '#99CCFF' => 0x2C,
+ '#FF99CC' => 0x2D,
+ '#CC99FF' => 0x2E,
+ '#FFCC99' => 0x2F,
+ '#3366FF' => 0x30,
+ '#33CCCC' => 0x31,
+ '#99CC00' => 0x32,
+ '#FFCC00' => 0x33,
+ '#FF9900' => 0x34,
+ '#FF6600' => 0x35,
+ '#666699' => 0x36,
+ '#969696' => 0x37,
+ '#003366' => 0x38,
+ '#339966' => 0x39,
+ '#003300' => 0x3A,
+ '#333300' => 0x3B,
+ '#993300' => 0x3C,
+ // '#993366' => 0x3D,
+ '#333399' => 0x3E,
+ '#333333' => 0x3F,
+ ];
+
+ public static function lookup(Color $color, int $defaultIndex = 0x00): int
+ {
+ $colorRgb = $color->getRGB();
+ if (is_string($colorRgb) && array_key_exists("#{$colorRgb}", self::$colorMap)) {
+ return self::$colorMap["#{$colorRgb}"];
+ }
+
+// TODO Try and map RGB value to nearest colour within the define pallette
+// $red = Color::getRed($colorRgb, false);
+// $green = Color::getGreen($colorRgb, false);
+// $blue = Color::getBlue($colorRgb, false);
+
+// $paletteSpace = 3;
+// $newColor = ($red * $paletteSpace / 256) * ($paletteSpace * $paletteSpace) +
+// ($green * $paletteSpace / 256) * $paletteSpace +
+// ($blue * $paletteSpace / 256);
+
+ return $defaultIndex;
+ }
+}
diff --git a/src/PhpSpreadsheet/Writer/Xls/Worksheet.php b/src/PhpSpreadsheet/Writer/Xls/Worksheet.php
index 7051ab2d..894ce03a 100644
--- a/src/PhpSpreadsheet/Writer/Xls/Worksheet.php
+++ b/src/PhpSpreadsheet/Writer/Xls/Worksheet.php
@@ -5,17 +5,14 @@ namespace PhpOffice\PhpSpreadsheet\Writer\Xls;
use GdImage;
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\Cell\DataType;
-use PhpOffice\PhpSpreadsheet\Cell\DataValidation;
use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException;
use PhpOffice\PhpSpreadsheet\RichText\RichText;
use PhpOffice\PhpSpreadsheet\RichText\Run;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
use PhpOffice\PhpSpreadsheet\Shared\Xls;
-use PhpOffice\PhpSpreadsheet\Style\Alignment;
use PhpOffice\PhpSpreadsheet\Style\Border;
use PhpOffice\PhpSpreadsheet\Style\Color;
use PhpOffice\PhpSpreadsheet\Style\Conditional;
-use PhpOffice\PhpSpreadsheet\Style\Fill;
use PhpOffice\PhpSpreadsheet\Style\Protection;
use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup;
use PhpOffice\PhpSpreadsheet\Worksheet\SheetView;
@@ -259,12 +256,12 @@ class Worksheet extends BIFFwriter
$maxC = $this->phpSheet->getHighestColumn();
// Determine lowest and highest column and row
+ $this->firstRowIndex = $minR;
$this->lastRowIndex = ($maxR > 65535) ? 65535 : $maxR;
$this->firstColumnIndex = Coordinate::columnIndexFromString($minC);
$this->lastColumnIndex = Coordinate::columnIndexFromString($maxC);
-// if ($this->firstColumnIndex > 255) $this->firstColumnIndex = 255;
if ($this->lastColumnIndex > 255) {
$this->lastColumnIndex = 255;
}
@@ -393,7 +390,13 @@ class Worksheet extends BIFFwriter
// Row dimensions
foreach ($phpSheet->getRowDimensions() as $rowDimension) {
$xfIndex = $rowDimension->getXfIndex() + 15; // there are 15 cellXfs
- $this->writeRow($rowDimension->getRowIndex() - 1, $rowDimension->getRowHeight(), $xfIndex, ($rowDimension->getVisible() ? '0' : '1'), $rowDimension->getOutlineLevel());
+ $this->writeRow(
+ $rowDimension->getRowIndex() - 1,
+ (int) $rowDimension->getRowHeight(),
+ $xfIndex,
+ !$rowDimension->getVisible(),
+ $rowDimension->getOutlineLevel()
+ );
}
// Write Cells
@@ -413,7 +416,6 @@ class Worksheet extends BIFFwriter
$cVal = $cell->getValue();
if ($cVal instanceof RichText) {
$arrcRun = [];
- $str_len = StringHelper::countCharacters($cVal->getPlainText(), 'UTF-8');
$str_pos = 0;
$elements = $cVal->getRichTextElements();
foreach ($elements as $element) {
@@ -476,7 +478,7 @@ class Worksheet extends BIFFwriter
break;
case DataType::TYPE_ERROR:
- $this->writeBoolErr($row, $column, self::mapErrorCode($cVal), 1, $xfIndex);
+ $this->writeBoolErr($row, $column, ErrorCode::error($cVal), 1, $xfIndex);
break;
}
@@ -539,16 +541,21 @@ class Worksheet extends BIFFwriter
$arrConditionalStyles = $phpSheet->getConditionalStylesCollection();
if (!empty($arrConditionalStyles)) {
$arrConditional = [];
- // @TODO CFRule & CFHeader
- // Write CFHEADER record
- $this->writeCFHeader();
+
+ $cfHeaderWritten = false;
// Write ConditionalFormattingTable records
foreach ($arrConditionalStyles as $cellCoordinate => $conditionalStyles) {
foreach ($conditionalStyles as $conditional) {
+ /** @var Conditional $conditional */
if (
- $conditional->getConditionType() == Conditional::CONDITION_EXPRESSION
- || $conditional->getConditionType() == Conditional::CONDITION_CELLIS
+ $conditional->getConditionType() == Conditional::CONDITION_EXPRESSION ||
+ $conditional->getConditionType() == Conditional::CONDITION_CELLIS
) {
+ // Write CFHEADER record (only if there are Conditional Styles that we are able to write)
+ if ($cfHeaderWritten === false) {
+ $this->writeCFHeader();
+ $cfHeaderWritten = true;
+ }
if (!isset($arrConditional[$conditional->getHashCode()])) {
// This hash code has been handled
$arrConditional[$conditional->getHashCode()] = true;
@@ -836,7 +843,7 @@ class Worksheet extends BIFFwriter
$errorCodes = DataType::getErrorCodes();
if (isset($errorCodes[$calculatedValue])) {
// Error value
- $num = pack('CCCvCv', 0x02, 0x00, self::mapErrorCode($calculatedValue), 0x00, 0x00, 0xFFFF);
+ $num = pack('CCCvCv', 0x02, 0x00, ErrorCode::error($calculatedValue), 0x00, 0x00, 0xFFFF);
} elseif ($calculatedValue === '') {
// Empty string (and BIFF8)
$num = pack('CCCvCv', 0x03, 0x00, 0x00, 0x00, 0x00, 0xFFFF);
@@ -868,7 +875,7 @@ class Worksheet extends BIFFwriter
// Parse the formula using the parser in Parser.php
try {
- $error = $this->parser->parse($formula);
+ $this->parser->parse($formula);
$formula = $this->parser->toReversePolish();
$formlen = strlen($formula); // Length of the binary string
@@ -1167,7 +1174,7 @@ class Worksheet extends BIFFwriter
}
// Use writeRow($row, null, $XF) to set XF format without setting height
- if ($height != null) {
+ if ($height !== null) {
$miyRw = $height * 20; // row height
} else {
$miyRw = 0xff; // default row height is 256
@@ -1180,7 +1187,7 @@ class Worksheet extends BIFFwriter
// collapsed. The zero height flag, 0x20, is used to collapse a row.
$grbit |= $level;
- if ($hidden) {
+ if ($hidden === true) {
$grbit |= 0x0030;
}
if ($height !== null) {
@@ -1519,7 +1526,7 @@ class Worksheet extends BIFFwriter
/**
* Write BIFF record RANGEPROTECTION.
*
- * Openoffice.org's Documentaion of the Microsoft Excel File Format uses term RANGEPROTECTION for these records
+ * Openoffice.org's Documentation of the Microsoft Excel File Format uses term RANGEPROTECTION for these records
* Microsoft Office Excel 97-2007 Binary File Format Specification uses term FEAT for these records
*/
private function writeRangeProtection(): void
@@ -2159,7 +2166,9 @@ class Worksheet extends BIFFwriter
*/
public function insertBitmap($row, $col, $bitmap, $x = 0, $y = 0, $scale_x = 1, $scale_y = 1): void
{
- $bitmap_array = (is_resource($bitmap) || $bitmap instanceof GdImage ? $this->processBitmapGd($bitmap) : $this->processBitmap($bitmap));
+ $bitmap_array = (is_resource($bitmap) || $bitmap instanceof GdImage
+ ? $this->processBitmapGd($bitmap)
+ : $this->processBitmap($bitmap));
[$width, $height, $size, $data] = $bitmap_array;
// Scale the frame of the image.
@@ -2628,67 +2637,16 @@ class Worksheet extends BIFFwriter
$record = 0x01BE; // Record identifier
foreach ($dataValidationCollection as $cellCoordinate => $dataValidation) {
- // initialize record data
- $data = '';
-
// options
$options = 0x00000000;
// data type
- $type = 0x00;
- switch ($dataValidation->getType()) {
- case DataValidation::TYPE_NONE:
- $type = 0x00;
-
- break;
- case DataValidation::TYPE_WHOLE:
- $type = 0x01;
-
- break;
- case DataValidation::TYPE_DECIMAL:
- $type = 0x02;
-
- break;
- case DataValidation::TYPE_LIST:
- $type = 0x03;
-
- break;
- case DataValidation::TYPE_DATE:
- $type = 0x04;
-
- break;
- case DataValidation::TYPE_TIME:
- $type = 0x05;
-
- break;
- case DataValidation::TYPE_TEXTLENGTH:
- $type = 0x06;
-
- break;
- case DataValidation::TYPE_CUSTOM:
- $type = 0x07;
-
- break;
- }
+ $type = CellDataValidation::type($dataValidation);
$options |= $type << 0;
// error style
- $errorStyle = 0x00;
- switch ($dataValidation->getErrorStyle()) {
- case DataValidation::STYLE_STOP:
- $errorStyle = 0x00;
-
- break;
- case DataValidation::STYLE_WARNING:
- $errorStyle = 0x01;
-
- break;
- case DataValidation::STYLE_INFORMATION:
- $errorStyle = 0x02;
-
- break;
- }
+ $errorStyle = CellDataValidation::errorStyle($dataValidation);
$options |= $errorStyle << 4;
@@ -2710,41 +2668,7 @@ class Worksheet extends BIFFwriter
$options |= $dataValidation->getShowErrorMessage() << 19;
// condition operator
- $operator = 0x00;
- switch ($dataValidation->getOperator()) {
- case DataValidation::OPERATOR_BETWEEN:
- $operator = 0x00;
-
- break;
- case DataValidation::OPERATOR_NOTBETWEEN:
- $operator = 0x01;
-
- break;
- case DataValidation::OPERATOR_EQUAL:
- $operator = 0x02;
-
- break;
- case DataValidation::OPERATOR_NOTEQUAL:
- $operator = 0x03;
-
- break;
- case DataValidation::OPERATOR_GREATERTHAN:
- $operator = 0x04;
-
- break;
- case DataValidation::OPERATOR_LESSTHAN:
- $operator = 0x05;
-
- break;
- case DataValidation::OPERATOR_GREATERTHANOREQUAL:
- $operator = 0x06;
-
- break;
- case DataValidation::OPERATOR_LESSTHANOREQUAL:
- $operator = 0x07;
-
- break;
- }
+ $operator = CellDataValidation::operator($dataValidation);
$options |= $operator << 20;
@@ -2814,35 +2738,6 @@ class Worksheet extends BIFFwriter
}
}
- /**
- * Map Error code.
- *
- * @param string $errorCode
- *
- * @return int
- */
- private static function mapErrorCode($errorCode)
- {
- switch ($errorCode) {
- case '#NULL!':
- return 0x00;
- case '#DIV/0!':
- return 0x07;
- case '#VALUE!':
- return 0x0F;
- case '#REF!':
- return 0x17;
- case '#NAME?':
- return 0x1D;
- case '#NUM!':
- return 0x24;
- case '#N/A':
- return 0x2A;
- }
-
- return 0;
- }
-
/**
* Write PLV Record.
*/
@@ -2949,12 +2844,12 @@ class Worksheet extends BIFFwriter
// $flags : Option flags
// Alignment
- $bAlignHz = ($conditional->getStyle()->getAlignment()->getHorizontal() == null ? 1 : 0);
- $bAlignVt = ($conditional->getStyle()->getAlignment()->getVertical() == null ? 1 : 0);
- $bAlignWrapTx = ($conditional->getStyle()->getAlignment()->getWrapText() == false ? 1 : 0);
- $bTxRotation = ($conditional->getStyle()->getAlignment()->getTextRotation() == null ? 1 : 0);
- $bIndent = ($conditional->getStyle()->getAlignment()->getIndent() == 0 ? 1 : 0);
- $bShrinkToFit = ($conditional->getStyle()->getAlignment()->getShrinkToFit() == false ? 1 : 0);
+ $bAlignHz = ($conditional->getStyle()->getAlignment()->getHorizontal() === null ? 1 : 0);
+ $bAlignVt = ($conditional->getStyle()->getAlignment()->getVertical() === null ? 1 : 0);
+ $bAlignWrapTx = ($conditional->getStyle()->getAlignment()->getWrapText() === false ? 1 : 0);
+ $bTxRotation = ($conditional->getStyle()->getAlignment()->getTextRotation() === null ? 1 : 0);
+ $bIndent = ($conditional->getStyle()->getAlignment()->getIndent() === 0 ? 1 : 0);
+ $bShrinkToFit = ($conditional->getStyle()->getAlignment()->getShrinkToFit() === false ? 1 : 0);
if ($bAlignHz == 0 || $bAlignVt == 0 || $bAlignWrapTx == 0 || $bTxRotation == 0 || $bIndent == 0 || $bShrinkToFit == 0) {
$bFormatAlign = 1;
} else {
@@ -2983,7 +2878,7 @@ class Worksheet extends BIFFwriter
$bFormatBorder = 0;
}
// Pattern
- $bFillStyle = ($conditional->getStyle()->getFill()->getFillType() == null ? 0 : 1);
+ $bFillStyle = ($conditional->getStyle()->getFill()->getFillType() === null ? 0 : 1);
$bFillColor = ($conditional->getStyle()->getFill()->getStartColor()->getARGB() == null ? 0 : 1);
$bFillColorBg = ($conditional->getStyle()->getFill()->getEndColor()->getARGB() == null ? 0 : 1);
if ($bFillStyle == 0 || $bFillColor == 0 || $bFillColorBg == 0) {
@@ -2993,14 +2888,14 @@ class Worksheet extends BIFFwriter
}
// Font
if (
- $conditional->getStyle()->getFont()->getName() != null
- || $conditional->getStyle()->getFont()->getSize() != null
- || $conditional->getStyle()->getFont()->getBold() != null
- || $conditional->getStyle()->getFont()->getItalic() != null
- || $conditional->getStyle()->getFont()->getSuperscript() != null
- || $conditional->getStyle()->getFont()->getSubscript() != null
- || $conditional->getStyle()->getFont()->getUnderline() != null
- || $conditional->getStyle()->getFont()->getStrikethrough() != null
+ $conditional->getStyle()->getFont()->getName() !== null
+ || $conditional->getStyle()->getFont()->getSize() !== null
+ || $conditional->getStyle()->getFont()->getBold() !== null
+ || $conditional->getStyle()->getFont()->getItalic() !== null
+ || $conditional->getStyle()->getFont()->getSuperscript() !== null
+ || $conditional->getStyle()->getFont()->getSubscript() !== null
+ || $conditional->getStyle()->getFont()->getUnderline() !== null
+ || $conditional->getStyle()->getFont()->getStrikethrough() !== null
|| $conditional->getStyle()->getFont()->getColor()->getARGB() != null
) {
$bFormatFont = 1;
@@ -3055,14 +2950,14 @@ class Worksheet extends BIFFwriter
// Data Blocks
if ($bFormatFont == 1) {
// Font Name
- if ($conditional->getStyle()->getFont()->getName() == null) {
+ if ($conditional->getStyle()->getFont()->getName() === null) {
$dataBlockFont = pack('VVVVVVVV', 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000);
$dataBlockFont .= pack('VVVVVVVV', 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000);
} else {
$dataBlockFont = StringHelper::UTF8toBIFF8UnicodeLong($conditional->getStyle()->getFont()->getName());
}
// Font Size
- if ($conditional->getStyle()->getFont()->getSize() == null) {
+ if ($conditional->getStyle()->getFont()->getSize() === null) {
$dataBlockFont .= pack('V', 20 * 11);
} else {
$dataBlockFont .= pack('V', 20 * $conditional->getStyle()->getFont()->getSize());
@@ -3070,16 +2965,16 @@ class Worksheet extends BIFFwriter
// Font Options
$dataBlockFont .= pack('V', 0);
// Font weight
- if ($conditional->getStyle()->getFont()->getBold() == true) {
+ if ($conditional->getStyle()->getFont()->getBold() === true) {
$dataBlockFont .= pack('v', 0x02BC);
} else {
$dataBlockFont .= pack('v', 0x0190);
}
// Escapement type
- if ($conditional->getStyle()->getFont()->getSubscript() == true) {
+ if ($conditional->getStyle()->getFont()->getSubscript() === true) {
$dataBlockFont .= pack('v', 0x02);
$fontEscapement = 0;
- } elseif ($conditional->getStyle()->getFont()->getSuperscript() == true) {
+ } elseif ($conditional->getStyle()->getFont()->getSuperscript() === true) {
$dataBlockFont .= pack('v', 0x01);
$fontEscapement = 0;
} else {
@@ -3122,242 +3017,14 @@ class Worksheet extends BIFFwriter
// Not used (3)
$dataBlockFont .= pack('vC', 0x0000, 0x00);
// Font color index
- switch ($conditional->getStyle()->getFont()->getColor()->getRGB()) {
- case '000000':
- $colorIdx = 0x08;
+ $colorIdx = Style\ColorMap::lookup($conditional->getStyle()->getFont()->getColor(), 0x00);
- break;
- case 'FFFFFF':
- $colorIdx = 0x09;
-
- break;
- case 'FF0000':
- $colorIdx = 0x0A;
-
- break;
- case '00FF00':
- $colorIdx = 0x0B;
-
- break;
- case '0000FF':
- $colorIdx = 0x0C;
-
- break;
- case 'FFFF00':
- $colorIdx = 0x0D;
-
- break;
- case 'FF00FF':
- $colorIdx = 0x0E;
-
- break;
- case '00FFFF':
- $colorIdx = 0x0F;
-
- break;
- case '800000':
- $colorIdx = 0x10;
-
- break;
- case '008000':
- $colorIdx = 0x11;
-
- break;
- case '000080':
- $colorIdx = 0x12;
-
- break;
- case '808000':
- $colorIdx = 0x13;
-
- break;
- case '800080':
- $colorIdx = 0x14;
-
- break;
- case '008080':
- $colorIdx = 0x15;
-
- break;
- case 'C0C0C0':
- $colorIdx = 0x16;
-
- break;
- case '808080':
- $colorIdx = 0x17;
-
- break;
- case '9999FF':
- $colorIdx = 0x18;
-
- break;
- case '993366':
- $colorIdx = 0x19;
-
- break;
- case 'FFFFCC':
- $colorIdx = 0x1A;
-
- break;
- case 'CCFFFF':
- $colorIdx = 0x1B;
-
- break;
- case '660066':
- $colorIdx = 0x1C;
-
- break;
- case 'FF8080':
- $colorIdx = 0x1D;
-
- break;
- case '0066CC':
- $colorIdx = 0x1E;
-
- break;
- case 'CCCCFF':
- $colorIdx = 0x1F;
-
- break;
- case '000080':
- $colorIdx = 0x20;
-
- break;
- case 'FF00FF':
- $colorIdx = 0x21;
-
- break;
- case 'FFFF00':
- $colorIdx = 0x22;
-
- break;
- case '00FFFF':
- $colorIdx = 0x23;
-
- break;
- case '800080':
- $colorIdx = 0x24;
-
- break;
- case '800000':
- $colorIdx = 0x25;
-
- break;
- case '008080':
- $colorIdx = 0x26;
-
- break;
- case '0000FF':
- $colorIdx = 0x27;
-
- break;
- case '00CCFF':
- $colorIdx = 0x28;
-
- break;
- case 'CCFFFF':
- $colorIdx = 0x29;
-
- break;
- case 'CCFFCC':
- $colorIdx = 0x2A;
-
- break;
- case 'FFFF99':
- $colorIdx = 0x2B;
-
- break;
- case '99CCFF':
- $colorIdx = 0x2C;
-
- break;
- case 'FF99CC':
- $colorIdx = 0x2D;
-
- break;
- case 'CC99FF':
- $colorIdx = 0x2E;
-
- break;
- case 'FFCC99':
- $colorIdx = 0x2F;
-
- break;
- case '3366FF':
- $colorIdx = 0x30;
-
- break;
- case '33CCCC':
- $colorIdx = 0x31;
-
- break;
- case '99CC00':
- $colorIdx = 0x32;
-
- break;
- case 'FFCC00':
- $colorIdx = 0x33;
-
- break;
- case 'FF9900':
- $colorIdx = 0x34;
-
- break;
- case 'FF6600':
- $colorIdx = 0x35;
-
- break;
- case '666699':
- $colorIdx = 0x36;
-
- break;
- case '969696':
- $colorIdx = 0x37;
-
- break;
- case '003366':
- $colorIdx = 0x38;
-
- break;
- case '339966':
- $colorIdx = 0x39;
-
- break;
- case '003300':
- $colorIdx = 0x3A;
-
- break;
- case '333300':
- $colorIdx = 0x3B;
-
- break;
- case '993300':
- $colorIdx = 0x3C;
-
- break;
- case '993366':
- $colorIdx = 0x3D;
-
- break;
- case '333399':
- $colorIdx = 0x3E;
-
- break;
- case '333333':
- $colorIdx = 0x3F;
-
- break;
- default:
- $colorIdx = 0x00;
-
- break;
- }
$dataBlockFont .= pack('V', $colorIdx);
// Not used (4)
$dataBlockFont .= pack('V', 0x00000000);
// Options flags for modified font attributes
$optionsFlags = 0;
- $optionsFlagsBold = ($conditional->getStyle()->getFont()->getBold() == null ? 1 : 0);
+ $optionsFlagsBold = ($conditional->getStyle()->getFont()->getBold() === null ? 1 : 0);
$optionsFlags |= (1 == $optionsFlagsBold ? 0x00000002 : 0);
$optionsFlags |= (1 == 1 ? 0x00000008 : 0);
$optionsFlags |= (1 == 1 ? 0x00000010 : 0);
@@ -3377,58 +3044,11 @@ class Worksheet extends BIFFwriter
// Always
$dataBlockFont .= pack('v', 0x0001);
}
- if ($bFormatAlign == 1) {
- $blockAlign = 0;
+ if ($bFormatAlign === 1) {
// Alignment and text break
- switch ($conditional->getStyle()->getAlignment()->getHorizontal()) {
- case Alignment::HORIZONTAL_GENERAL:
- $blockAlign = 0;
-
- break;
- case Alignment::HORIZONTAL_LEFT:
- $blockAlign = 1;
-
- break;
- case Alignment::HORIZONTAL_RIGHT:
- $blockAlign = 3;
-
- break;
- case Alignment::HORIZONTAL_CENTER:
- $blockAlign = 2;
-
- break;
- case Alignment::HORIZONTAL_CENTER_CONTINUOUS:
- $blockAlign = 6;
-
- break;
- case Alignment::HORIZONTAL_JUSTIFY:
- $blockAlign = 5;
-
- break;
- }
- if ($conditional->getStyle()->getAlignment()->getWrapText() == true) {
- $blockAlign |= 1 << 3;
- } else {
- $blockAlign |= 0 << 3;
- }
- switch ($conditional->getStyle()->getAlignment()->getVertical()) {
- case Alignment::VERTICAL_BOTTOM:
- $blockAlign = 2 << 4;
-
- break;
- case Alignment::VERTICAL_TOP:
- $blockAlign = 0 << 4;
-
- break;
- case Alignment::VERTICAL_CENTER:
- $blockAlign = 1 << 4;
-
- break;
- case Alignment::VERTICAL_JUSTIFY:
- $blockAlign = 3 << 4;
-
- break;
- }
+ $blockAlign = Style\CellAlignment::horizontal($conditional->getStyle()->getAlignment());
+ $blockAlign |= Style\CellAlignment::wrap($conditional->getStyle()->getAlignment()) << 3;
+ $blockAlign |= Style\CellAlignment::vertical($conditional->getStyle()->getAlignment()) << 4;
$blockAlign |= 0 << 7;
// Text rotation angle
@@ -3436,7 +3056,7 @@ class Worksheet extends BIFFwriter
// Indentation
$blockIndent = $conditional->getStyle()->getAlignment()->getIndent();
- if ($conditional->getStyle()->getAlignment()->getShrinkToFit() == true) {
+ if ($conditional->getStyle()->getAlignment()->getShrinkToFit() === true) {
$blockIndent |= 1 << 4;
} else {
$blockIndent |= 0 << 4;
@@ -3448,240 +3068,11 @@ class Worksheet extends BIFFwriter
$dataBlockAlign = pack('CCvvv', $blockAlign, $blockRotation, $blockIndent, $blockIndentRelative, 0x0000);
}
- if ($bFormatBorder == 1) {
- $blockLineStyle = 0;
- switch ($conditional->getStyle()->getBorders()->getLeft()->getBorderStyle()) {
- case Border::BORDER_NONE:
- $blockLineStyle |= 0x00;
-
- break;
- case Border::BORDER_THIN:
- $blockLineStyle |= 0x01;
-
- break;
- case Border::BORDER_MEDIUM:
- $blockLineStyle |= 0x02;
-
- break;
- case Border::BORDER_DASHED:
- $blockLineStyle |= 0x03;
-
- break;
- case Border::BORDER_DOTTED:
- $blockLineStyle |= 0x04;
-
- break;
- case Border::BORDER_THICK:
- $blockLineStyle |= 0x05;
-
- break;
- case Border::BORDER_DOUBLE:
- $blockLineStyle |= 0x06;
-
- break;
- case Border::BORDER_HAIR:
- $blockLineStyle |= 0x07;
-
- break;
- case Border::BORDER_MEDIUMDASHED:
- $blockLineStyle |= 0x08;
-
- break;
- case Border::BORDER_DASHDOT:
- $blockLineStyle |= 0x09;
-
- break;
- case Border::BORDER_MEDIUMDASHDOT:
- $blockLineStyle |= 0x0A;
-
- break;
- case Border::BORDER_DASHDOTDOT:
- $blockLineStyle |= 0x0B;
-
- break;
- case Border::BORDER_MEDIUMDASHDOTDOT:
- $blockLineStyle |= 0x0C;
-
- break;
- case Border::BORDER_SLANTDASHDOT:
- $blockLineStyle |= 0x0D;
-
- break;
- }
- switch ($conditional->getStyle()->getBorders()->getRight()->getBorderStyle()) {
- case Border::BORDER_NONE:
- $blockLineStyle |= 0x00 << 4;
-
- break;
- case Border::BORDER_THIN:
- $blockLineStyle |= 0x01 << 4;
-
- break;
- case Border::BORDER_MEDIUM:
- $blockLineStyle |= 0x02 << 4;
-
- break;
- case Border::BORDER_DASHED:
- $blockLineStyle |= 0x03 << 4;
-
- break;
- case Border::BORDER_DOTTED:
- $blockLineStyle |= 0x04 << 4;
-
- break;
- case Border::BORDER_THICK:
- $blockLineStyle |= 0x05 << 4;
-
- break;
- case Border::BORDER_DOUBLE:
- $blockLineStyle |= 0x06 << 4;
-
- break;
- case Border::BORDER_HAIR:
- $blockLineStyle |= 0x07 << 4;
-
- break;
- case Border::BORDER_MEDIUMDASHED:
- $blockLineStyle |= 0x08 << 4;
-
- break;
- case Border::BORDER_DASHDOT:
- $blockLineStyle |= 0x09 << 4;
-
- break;
- case Border::BORDER_MEDIUMDASHDOT:
- $blockLineStyle |= 0x0A << 4;
-
- break;
- case Border::BORDER_DASHDOTDOT:
- $blockLineStyle |= 0x0B << 4;
-
- break;
- case Border::BORDER_MEDIUMDASHDOTDOT:
- $blockLineStyle |= 0x0C << 4;
-
- break;
- case Border::BORDER_SLANTDASHDOT:
- $blockLineStyle |= 0x0D << 4;
-
- break;
- }
- switch ($conditional->getStyle()->getBorders()->getTop()->getBorderStyle()) {
- case Border::BORDER_NONE:
- $blockLineStyle |= 0x00 << 8;
-
- break;
- case Border::BORDER_THIN:
- $blockLineStyle |= 0x01 << 8;
-
- break;
- case Border::BORDER_MEDIUM:
- $blockLineStyle |= 0x02 << 8;
-
- break;
- case Border::BORDER_DASHED:
- $blockLineStyle |= 0x03 << 8;
-
- break;
- case Border::BORDER_DOTTED:
- $blockLineStyle |= 0x04 << 8;
-
- break;
- case Border::BORDER_THICK:
- $blockLineStyle |= 0x05 << 8;
-
- break;
- case Border::BORDER_DOUBLE:
- $blockLineStyle |= 0x06 << 8;
-
- break;
- case Border::BORDER_HAIR:
- $blockLineStyle |= 0x07 << 8;
-
- break;
- case Border::BORDER_MEDIUMDASHED:
- $blockLineStyle |= 0x08 << 8;
-
- break;
- case Border::BORDER_DASHDOT:
- $blockLineStyle |= 0x09 << 8;
-
- break;
- case Border::BORDER_MEDIUMDASHDOT:
- $blockLineStyle |= 0x0A << 8;
-
- break;
- case Border::BORDER_DASHDOTDOT:
- $blockLineStyle |= 0x0B << 8;
-
- break;
- case Border::BORDER_MEDIUMDASHDOTDOT:
- $blockLineStyle |= 0x0C << 8;
-
- break;
- case Border::BORDER_SLANTDASHDOT:
- $blockLineStyle |= 0x0D << 8;
-
- break;
- }
- switch ($conditional->getStyle()->getBorders()->getBottom()->getBorderStyle()) {
- case Border::BORDER_NONE:
- $blockLineStyle |= 0x00 << 12;
-
- break;
- case Border::BORDER_THIN:
- $blockLineStyle |= 0x01 << 12;
-
- break;
- case Border::BORDER_MEDIUM:
- $blockLineStyle |= 0x02 << 12;
-
- break;
- case Border::BORDER_DASHED:
- $blockLineStyle |= 0x03 << 12;
-
- break;
- case Border::BORDER_DOTTED:
- $blockLineStyle |= 0x04 << 12;
-
- break;
- case Border::BORDER_THICK:
- $blockLineStyle |= 0x05 << 12;
-
- break;
- case Border::BORDER_DOUBLE:
- $blockLineStyle |= 0x06 << 12;
-
- break;
- case Border::BORDER_HAIR:
- $blockLineStyle |= 0x07 << 12;
-
- break;
- case Border::BORDER_MEDIUMDASHED:
- $blockLineStyle |= 0x08 << 12;
-
- break;
- case Border::BORDER_DASHDOT:
- $blockLineStyle |= 0x09 << 12;
-
- break;
- case Border::BORDER_MEDIUMDASHDOT:
- $blockLineStyle |= 0x0A << 12;
-
- break;
- case Border::BORDER_DASHDOTDOT:
- $blockLineStyle |= 0x0B << 12;
-
- break;
- case Border::BORDER_MEDIUMDASHDOTDOT:
- $blockLineStyle |= 0x0C << 12;
-
- break;
- case Border::BORDER_SLANTDASHDOT:
- $blockLineStyle |= 0x0D << 12;
-
- break;
- }
+ if ($bFormatBorder === 1) {
+ $blockLineStyle = Style\CellBorder::style($conditional->getStyle()->getBorders()->getLeft());
+ $blockLineStyle |= Style\CellBorder::style($conditional->getStyle()->getBorders()->getRight()) << 4;
+ $blockLineStyle |= Style\CellBorder::style($conditional->getStyle()->getBorders()->getTop()) << 8;
+ $blockLineStyle |= Style\CellBorder::style($conditional->getStyle()->getBorders()->getBottom()) << 12;
// TODO writeCFRule() => $blockLineStyle => Index Color for left line
// TODO writeCFRule() => $blockLineStyle => Index Color for right line
@@ -3691,636 +3082,32 @@ class Worksheet extends BIFFwriter
// TODO writeCFRule() => $blockColor => Index Color for top line
// TODO writeCFRule() => $blockColor => Index Color for bottom line
// TODO writeCFRule() => $blockColor => Index Color for diagonal line
- switch ($conditional->getStyle()->getBorders()->getDiagonal()->getBorderStyle()) {
- case Border::BORDER_NONE:
- $blockColor |= 0x00 << 21;
-
- break;
- case Border::BORDER_THIN:
- $blockColor |= 0x01 << 21;
-
- break;
- case Border::BORDER_MEDIUM:
- $blockColor |= 0x02 << 21;
-
- break;
- case Border::BORDER_DASHED:
- $blockColor |= 0x03 << 21;
-
- break;
- case Border::BORDER_DOTTED:
- $blockColor |= 0x04 << 21;
-
- break;
- case Border::BORDER_THICK:
- $blockColor |= 0x05 << 21;
-
- break;
- case Border::BORDER_DOUBLE:
- $blockColor |= 0x06 << 21;
-
- break;
- case Border::BORDER_HAIR:
- $blockColor |= 0x07 << 21;
-
- break;
- case Border::BORDER_MEDIUMDASHED:
- $blockColor |= 0x08 << 21;
-
- break;
- case Border::BORDER_DASHDOT:
- $blockColor |= 0x09 << 21;
-
- break;
- case Border::BORDER_MEDIUMDASHDOT:
- $blockColor |= 0x0A << 21;
-
- break;
- case Border::BORDER_DASHDOTDOT:
- $blockColor |= 0x0B << 21;
-
- break;
- case Border::BORDER_MEDIUMDASHDOTDOT:
- $blockColor |= 0x0C << 21;
-
- break;
- case Border::BORDER_SLANTDASHDOT:
- $blockColor |= 0x0D << 21;
-
- break;
- }
+ $blockColor |= Style\CellBorder::style($conditional->getStyle()->getBorders()->getDiagonal()) << 21;
$dataBlockBorder = pack('vv', $blockLineStyle, $blockColor);
}
- if ($bFormatFill == 1) {
- // Fill Patern Style
- $blockFillPatternStyle = 0;
- switch ($conditional->getStyle()->getFill()->getFillType()) {
- case Fill::FILL_NONE:
- $blockFillPatternStyle = 0x00;
+ if ($bFormatFill === 1) {
+ // Fill Pattern Style
+ $blockFillPatternStyle = Style\CellFill::style($conditional->getStyle()->getFill());
+ // Background Color
+ $colorIdxBg = Style\ColorMap::lookup($conditional->getStyle()->getFill()->getStartColor(), 0x41);
+ // Foreground Color
+ $colorIdxFg = Style\ColorMap::lookup($conditional->getStyle()->getFill()->getEndColor(), 0x40);
- break;
- case Fill::FILL_SOLID:
- $blockFillPatternStyle = 0x01;
-
- break;
- case Fill::FILL_PATTERN_MEDIUMGRAY:
- $blockFillPatternStyle = 0x02;
-
- break;
- case Fill::FILL_PATTERN_DARKGRAY:
- $blockFillPatternStyle = 0x03;
-
- break;
- case Fill::FILL_PATTERN_LIGHTGRAY:
- $blockFillPatternStyle = 0x04;
-
- break;
- case Fill::FILL_PATTERN_DARKHORIZONTAL:
- $blockFillPatternStyle = 0x05;
-
- break;
- case Fill::FILL_PATTERN_DARKVERTICAL:
- $blockFillPatternStyle = 0x06;
-
- break;
- case Fill::FILL_PATTERN_DARKDOWN:
- $blockFillPatternStyle = 0x07;
-
- break;
- case Fill::FILL_PATTERN_DARKUP:
- $blockFillPatternStyle = 0x08;
-
- break;
- case Fill::FILL_PATTERN_DARKGRID:
- $blockFillPatternStyle = 0x09;
-
- break;
- case Fill::FILL_PATTERN_DARKTRELLIS:
- $blockFillPatternStyle = 0x0A;
-
- break;
- case Fill::FILL_PATTERN_LIGHTHORIZONTAL:
- $blockFillPatternStyle = 0x0B;
-
- break;
- case Fill::FILL_PATTERN_LIGHTVERTICAL:
- $blockFillPatternStyle = 0x0C;
-
- break;
- case Fill::FILL_PATTERN_LIGHTDOWN:
- $blockFillPatternStyle = 0x0D;
-
- break;
- case Fill::FILL_PATTERN_LIGHTUP:
- $blockFillPatternStyle = 0x0E;
-
- break;
- case Fill::FILL_PATTERN_LIGHTGRID:
- $blockFillPatternStyle = 0x0F;
-
- break;
- case Fill::FILL_PATTERN_LIGHTTRELLIS:
- $blockFillPatternStyle = 0x10;
-
- break;
- case Fill::FILL_PATTERN_GRAY125:
- $blockFillPatternStyle = 0x11;
-
- break;
- case Fill::FILL_PATTERN_GRAY0625:
- $blockFillPatternStyle = 0x12;
-
- break;
- case Fill::FILL_GRADIENT_LINEAR:
- $blockFillPatternStyle = 0x00;
-
- break; // does not exist in BIFF8
- case Fill::FILL_GRADIENT_PATH:
- $blockFillPatternStyle = 0x00;
-
- break; // does not exist in BIFF8
- default:
- $blockFillPatternStyle = 0x00;
-
- break;
- }
- // Color
- switch ($conditional->getStyle()->getFill()->getStartColor()->getRGB()) {
- case '000000':
- $colorIdxBg = 0x08;
-
- break;
- case 'FFFFFF':
- $colorIdxBg = 0x09;
-
- break;
- case 'FF0000':
- $colorIdxBg = 0x0A;
-
- break;
- case '00FF00':
- $colorIdxBg = 0x0B;
-
- break;
- case '0000FF':
- $colorIdxBg = 0x0C;
-
- break;
- case 'FFFF00':
- $colorIdxBg = 0x0D;
-
- break;
- case 'FF00FF':
- $colorIdxBg = 0x0E;
-
- break;
- case '00FFFF':
- $colorIdxBg = 0x0F;
-
- break;
- case '800000':
- $colorIdxBg = 0x10;
-
- break;
- case '008000':
- $colorIdxBg = 0x11;
-
- break;
- case '000080':
- $colorIdxBg = 0x12;
-
- break;
- case '808000':
- $colorIdxBg = 0x13;
-
- break;
- case '800080':
- $colorIdxBg = 0x14;
-
- break;
- case '008080':
- $colorIdxBg = 0x15;
-
- break;
- case 'C0C0C0':
- $colorIdxBg = 0x16;
-
- break;
- case '808080':
- $colorIdxBg = 0x17;
-
- break;
- case '9999FF':
- $colorIdxBg = 0x18;
-
- break;
- case '993366':
- $colorIdxBg = 0x19;
-
- break;
- case 'FFFFCC':
- $colorIdxBg = 0x1A;
-
- break;
- case 'CCFFFF':
- $colorIdxBg = 0x1B;
-
- break;
- case '660066':
- $colorIdxBg = 0x1C;
-
- break;
- case 'FF8080':
- $colorIdxBg = 0x1D;
-
- break;
- case '0066CC':
- $colorIdxBg = 0x1E;
-
- break;
- case 'CCCCFF':
- $colorIdxBg = 0x1F;
-
- break;
- case '000080':
- $colorIdxBg = 0x20;
-
- break;
- case 'FF00FF':
- $colorIdxBg = 0x21;
-
- break;
- case 'FFFF00':
- $colorIdxBg = 0x22;
-
- break;
- case '00FFFF':
- $colorIdxBg = 0x23;
-
- break;
- case '800080':
- $colorIdxBg = 0x24;
-
- break;
- case '800000':
- $colorIdxBg = 0x25;
-
- break;
- case '008080':
- $colorIdxBg = 0x26;
-
- break;
- case '0000FF':
- $colorIdxBg = 0x27;
-
- break;
- case '00CCFF':
- $colorIdxBg = 0x28;
-
- break;
- case 'CCFFFF':
- $colorIdxBg = 0x29;
-
- break;
- case 'CCFFCC':
- $colorIdxBg = 0x2A;
-
- break;
- case 'FFFF99':
- $colorIdxBg = 0x2B;
-
- break;
- case '99CCFF':
- $colorIdxBg = 0x2C;
-
- break;
- case 'FF99CC':
- $colorIdxBg = 0x2D;
-
- break;
- case 'CC99FF':
- $colorIdxBg = 0x2E;
-
- break;
- case 'FFCC99':
- $colorIdxBg = 0x2F;
-
- break;
- case '3366FF':
- $colorIdxBg = 0x30;
-
- break;
- case '33CCCC':
- $colorIdxBg = 0x31;
-
- break;
- case '99CC00':
- $colorIdxBg = 0x32;
-
- break;
- case 'FFCC00':
- $colorIdxBg = 0x33;
-
- break;
- case 'FF9900':
- $colorIdxBg = 0x34;
-
- break;
- case 'FF6600':
- $colorIdxBg = 0x35;
-
- break;
- case '666699':
- $colorIdxBg = 0x36;
-
- break;
- case '969696':
- $colorIdxBg = 0x37;
-
- break;
- case '003366':
- $colorIdxBg = 0x38;
-
- break;
- case '339966':
- $colorIdxBg = 0x39;
-
- break;
- case '003300':
- $colorIdxBg = 0x3A;
-
- break;
- case '333300':
- $colorIdxBg = 0x3B;
-
- break;
- case '993300':
- $colorIdxBg = 0x3C;
-
- break;
- case '993366':
- $colorIdxBg = 0x3D;
-
- break;
- case '333399':
- $colorIdxBg = 0x3E;
-
- break;
- case '333333':
- $colorIdxBg = 0x3F;
-
- break;
- default:
- $colorIdxBg = 0x41;
-
- break;
- }
- // Fg Color
- switch ($conditional->getStyle()->getFill()->getEndColor()->getRGB()) {
- case '000000':
- $colorIdxFg = 0x08;
-
- break;
- case 'FFFFFF':
- $colorIdxFg = 0x09;
-
- break;
- case 'FF0000':
- $colorIdxFg = 0x0A;
-
- break;
- case '00FF00':
- $colorIdxFg = 0x0B;
-
- break;
- case '0000FF':
- $colorIdxFg = 0x0C;
-
- break;
- case 'FFFF00':
- $colorIdxFg = 0x0D;
-
- break;
- case 'FF00FF':
- $colorIdxFg = 0x0E;
-
- break;
- case '00FFFF':
- $colorIdxFg = 0x0F;
-
- break;
- case '800000':
- $colorIdxFg = 0x10;
-
- break;
- case '008000':
- $colorIdxFg = 0x11;
-
- break;
- case '000080':
- $colorIdxFg = 0x12;
-
- break;
- case '808000':
- $colorIdxFg = 0x13;
-
- break;
- case '800080':
- $colorIdxFg = 0x14;
-
- break;
- case '008080':
- $colorIdxFg = 0x15;
-
- break;
- case 'C0C0C0':
- $colorIdxFg = 0x16;
-
- break;
- case '808080':
- $colorIdxFg = 0x17;
-
- break;
- case '9999FF':
- $colorIdxFg = 0x18;
-
- break;
- case '993366':
- $colorIdxFg = 0x19;
-
- break;
- case 'FFFFCC':
- $colorIdxFg = 0x1A;
-
- break;
- case 'CCFFFF':
- $colorIdxFg = 0x1B;
-
- break;
- case '660066':
- $colorIdxFg = 0x1C;
-
- break;
- case 'FF8080':
- $colorIdxFg = 0x1D;
-
- break;
- case '0066CC':
- $colorIdxFg = 0x1E;
-
- break;
- case 'CCCCFF':
- $colorIdxFg = 0x1F;
-
- break;
- case '000080':
- $colorIdxFg = 0x20;
-
- break;
- case 'FF00FF':
- $colorIdxFg = 0x21;
-
- break;
- case 'FFFF00':
- $colorIdxFg = 0x22;
-
- break;
- case '00FFFF':
- $colorIdxFg = 0x23;
-
- break;
- case '800080':
- $colorIdxFg = 0x24;
-
- break;
- case '800000':
- $colorIdxFg = 0x25;
-
- break;
- case '008080':
- $colorIdxFg = 0x26;
-
- break;
- case '0000FF':
- $colorIdxFg = 0x27;
-
- break;
- case '00CCFF':
- $colorIdxFg = 0x28;
-
- break;
- case 'CCFFFF':
- $colorIdxFg = 0x29;
-
- break;
- case 'CCFFCC':
- $colorIdxFg = 0x2A;
-
- break;
- case 'FFFF99':
- $colorIdxFg = 0x2B;
-
- break;
- case '99CCFF':
- $colorIdxFg = 0x2C;
-
- break;
- case 'FF99CC':
- $colorIdxFg = 0x2D;
-
- break;
- case 'CC99FF':
- $colorIdxFg = 0x2E;
-
- break;
- case 'FFCC99':
- $colorIdxFg = 0x2F;
-
- break;
- case '3366FF':
- $colorIdxFg = 0x30;
-
- break;
- case '33CCCC':
- $colorIdxFg = 0x31;
-
- break;
- case '99CC00':
- $colorIdxFg = 0x32;
-
- break;
- case 'FFCC00':
- $colorIdxFg = 0x33;
-
- break;
- case 'FF9900':
- $colorIdxFg = 0x34;
-
- break;
- case 'FF6600':
- $colorIdxFg = 0x35;
-
- break;
- case '666699':
- $colorIdxFg = 0x36;
-
- break;
- case '969696':
- $colorIdxFg = 0x37;
-
- break;
- case '003366':
- $colorIdxFg = 0x38;
-
- break;
- case '339966':
- $colorIdxFg = 0x39;
-
- break;
- case '003300':
- $colorIdxFg = 0x3A;
-
- break;
- case '333300':
- $colorIdxFg = 0x3B;
-
- break;
- case '993300':
- $colorIdxFg = 0x3C;
-
- break;
- case '993366':
- $colorIdxFg = 0x3D;
-
- break;
- case '333399':
- $colorIdxFg = 0x3E;
-
- break;
- case '333333':
- $colorIdxFg = 0x3F;
-
- break;
- default:
- $colorIdxFg = 0x40;
-
- break;
- }
$dataBlockFill = pack('v', $blockFillPatternStyle);
$dataBlockFill .= pack('v', $colorIdxFg | ($colorIdxBg << 7));
}
$data = pack('CCvvVv', $type, $operatorType, $szValue1, $szValue2, $flags, 0x0000);
- if ($bFormatFont == 1) { // Block Formatting : OK
+ if ($bFormatFont === 1) { // Block Formatting : OK
$data .= $dataBlockFont;
}
- if ($bFormatAlign == 1) {
+ if ($bFormatAlign === 1) {
$data .= $dataBlockAlign;
}
- if ($bFormatBorder == 1) {
+ if ($bFormatBorder === 1) {
$data .= $dataBlockBorder;
}
- if ($bFormatFill == 1) { // Block Formatting : OK
+ if ($bFormatFill === 1) { // Block Formatting : OK
$data .= $dataBlockFill;
}
if ($bFormatProt == 1) {
@@ -4352,25 +3139,25 @@ class Worksheet extends BIFFwriter
foreach ($this->phpSheet->getConditionalStylesCollection() as $cellCoordinate => $conditionalStyles) {
foreach ($conditionalStyles as $conditional) {
if (
- $conditional->getConditionType() == Conditional::CONDITION_EXPRESSION
- || $conditional->getConditionType() == Conditional::CONDITION_CELLIS
+ $conditional->getConditionType() == Conditional::CONDITION_EXPRESSION ||
+ $conditional->getConditionType() == Conditional::CONDITION_CELLIS
) {
if (!in_array($conditional->getHashCode(), $arrConditional)) {
$arrConditional[] = $conditional->getHashCode();
}
// Cells
- $arrCoord = Coordinate::indexesFromString($cellCoordinate);
- if ($numColumnMin === null || ($numColumnMin > $arrCoord[0])) {
- $numColumnMin = $arrCoord[0];
+ $rangeCoordinates = Coordinate::rangeBoundaries($cellCoordinate);
+ if ($numColumnMin === null || ($numColumnMin > $rangeCoordinates[0][0])) {
+ $numColumnMin = $rangeCoordinates[0][0];
}
- if ($numColumnMax === null || ($numColumnMax < $arrCoord[0])) {
- $numColumnMax = $arrCoord[0];
+ if ($numColumnMax === null || ($numColumnMax < $rangeCoordinates[1][0])) {
+ $numColumnMax = $rangeCoordinates[1][0];
}
- if ($numRowMin === null || ($numRowMin > $arrCoord[1])) {
- $numRowMin = $arrCoord[1];
+ if ($numRowMin === null || ($numRowMin > $rangeCoordinates[0][1])) {
+ $numRowMin = (int) $rangeCoordinates[0][1];
}
- if ($numRowMax === null || ($numRowMax < $arrCoord[1])) {
- $numRowMax = $arrCoord[1];
+ if ($numRowMax === null || ($numRowMax < $rangeCoordinates[1][1])) {
+ $numRowMax = (int) $rangeCoordinates[1][1];
}
}
}
diff --git a/src/PhpSpreadsheet/Writer/Xls/Xf.php b/src/PhpSpreadsheet/Writer/Xls/Xf.php
index 6f1d1cb2..b2dbc67a 100644
--- a/src/PhpSpreadsheet/Writer/Xls/Xf.php
+++ b/src/PhpSpreadsheet/Writer/Xls/Xf.php
@@ -3,11 +3,12 @@
namespace PhpOffice\PhpSpreadsheet\Writer\Xls;
use PhpOffice\PhpSpreadsheet\Style\Alignment;
-use PhpOffice\PhpSpreadsheet\Style\Border;
use PhpOffice\PhpSpreadsheet\Style\Borders;
-use PhpOffice\PhpSpreadsheet\Style\Fill;
use PhpOffice\PhpSpreadsheet\Style\Protection;
use PhpOffice\PhpSpreadsheet\Style\Style;
+use PhpOffice\PhpSpreadsheet\Writer\Xls\Style\CellAlignment;
+use PhpOffice\PhpSpreadsheet\Writer\Xls\Style\CellBorder;
+use PhpOffice\PhpSpreadsheet\Writer\Xls\Style\CellFill;
// Original file header of PEAR::Spreadsheet_Excel_Writer_Format (used as the base for this class):
// -----------------------------------------------------------------------------------------
@@ -176,30 +177,30 @@ class Xf
$atr_num = ($this->numberFormatIndex != 0) ? 1 : 0;
$atr_fnt = ($this->fontIndex != 0) ? 1 : 0;
$atr_alc = ((int) $this->style->getAlignment()->getWrapText()) ? 1 : 0;
- $atr_bdr = (self::mapBorderStyle($this->style->getBorders()->getBottom()->getBorderStyle()) ||
- self::mapBorderStyle($this->style->getBorders()->getTop()->getBorderStyle()) ||
- self::mapBorderStyle($this->style->getBorders()->getLeft()->getBorderStyle()) ||
- self::mapBorderStyle($this->style->getBorders()->getRight()->getBorderStyle())) ? 1 : 0;
+ $atr_bdr = (CellBorder::style($this->style->getBorders()->getBottom()) ||
+ CellBorder::style($this->style->getBorders()->getTop()) ||
+ CellBorder::style($this->style->getBorders()->getLeft()) ||
+ CellBorder::style($this->style->getBorders()->getRight())) ? 1 : 0;
$atr_pat = ($this->foregroundColor != 0x40) ? 1 : 0;
$atr_pat = ($this->backgroundColor != 0x41) ? 1 : $atr_pat;
- $atr_pat = self::mapFillType($this->style->getFill()->getFillType()) ? 1 : $atr_pat;
+ $atr_pat = CellFill::style($this->style->getFill()) ? 1 : $atr_pat;
$atr_prot = self::mapLocked($this->style->getProtection()->getLocked())
| self::mapHidden($this->style->getProtection()->getHidden());
// Zero the default border colour if the border has not been set.
- if (self::mapBorderStyle($this->style->getBorders()->getBottom()->getBorderStyle()) == 0) {
+ if (CellBorder::style($this->style->getBorders()->getBottom()) == 0) {
$this->bottomBorderColor = 0;
}
- if (self::mapBorderStyle($this->style->getBorders()->getTop()->getBorderStyle()) == 0) {
+ if (CellBorder::style($this->style->getBorders()->getTop()) == 0) {
$this->topBorderColor = 0;
}
- if (self::mapBorderStyle($this->style->getBorders()->getRight()->getBorderStyle()) == 0) {
+ if (CellBorder::style($this->style->getBorders()->getRight()) == 0) {
$this->rightBorderColor = 0;
}
- if (self::mapBorderStyle($this->style->getBorders()->getLeft()->getBorderStyle()) == 0) {
+ if (CellBorder::style($this->style->getBorders()->getLeft()) == 0) {
$this->leftBorderColor = 0;
}
- if (self::mapBorderStyle($this->style->getBorders()->getDiagonal()->getBorderStyle()) == 0) {
+ if (CellBorder::style($this->style->getBorders()->getDiagonal()) == 0) {
$this->diagColor = 0;
}
@@ -209,9 +210,10 @@ class Xf
$ifnt = $this->fontIndex; // Index to FONT record
$ifmt = $this->numberFormatIndex; // Index to FORMAT record
- $align = $this->mapHAlign($this->style->getAlignment()->getHorizontal()); // Alignment
- $align |= (int) $this->style->getAlignment()->getWrapText() << 3;
- $align |= self::mapVAlign($this->style->getAlignment()->getVertical()) << 4;
+ // Alignment
+ $align = CellAlignment::horizontal($this->style->getAlignment());
+ $align |= CellAlignment::wrap($this->style->getAlignment()) << 3;
+ $align |= CellAlignment::vertical($this->style->getAlignment()) << 4;
$align |= $this->textJustLast << 7;
$used_attrib = $atr_num << 2;
@@ -224,10 +226,10 @@ class Xf
$icv = $this->foregroundColor; // fg and bg pattern colors
$icv |= $this->backgroundColor << 7;
- $border1 = self::mapBorderStyle($this->style->getBorders()->getLeft()->getBorderStyle()); // Border line style and color
- $border1 |= self::mapBorderStyle($this->style->getBorders()->getRight()->getBorderStyle()) << 4;
- $border1 |= self::mapBorderStyle($this->style->getBorders()->getTop()->getBorderStyle()) << 8;
- $border1 |= self::mapBorderStyle($this->style->getBorders()->getBottom()->getBorderStyle()) << 12;
+ $border1 = CellBorder::style($this->style->getBorders()->getLeft()); // Border line style and color
+ $border1 |= CellBorder::style($this->style->getBorders()->getRight()) << 4;
+ $border1 |= CellBorder::style($this->style->getBorders()->getTop()) << 8;
+ $border1 |= CellBorder::style($this->style->getBorders()->getBottom()) << 12;
$border1 |= $this->leftBorderColor << 16;
$border1 |= $this->rightBorderColor << 23;
@@ -242,8 +244,8 @@ class Xf
$border2 = $this->topBorderColor; // Border color
$border2 |= $this->bottomBorderColor << 7;
$border2 |= $this->diagColor << 14;
- $border2 |= self::mapBorderStyle($this->style->getBorders()->getDiagonal()->getBorderStyle()) << 21;
- $border2 |= self::mapFillType($this->style->getFill()->getFillType()) << 26;
+ $border2 |= CellBorder::style($this->style->getBorders()->getDiagonal()) << 21;
+ $border2 |= CellFill::style($this->style->getFill()) << 26;
$header = pack('vv', $record, $length);
@@ -359,132 +361,6 @@ class Xf
$this->fontIndex = $value;
}
- /**
- * Map of BIFF2-BIFF8 codes for border styles.
- *
- * @var int[]
- */
- private static $mapBorderStyles = [
- Border::BORDER_NONE => 0x00,
- Border::BORDER_THIN => 0x01,
- Border::BORDER_MEDIUM => 0x02,
- Border::BORDER_DASHED => 0x03,
- Border::BORDER_DOTTED => 0x04,
- Border::BORDER_THICK => 0x05,
- Border::BORDER_DOUBLE => 0x06,
- Border::BORDER_HAIR => 0x07,
- Border::BORDER_MEDIUMDASHED => 0x08,
- Border::BORDER_DASHDOT => 0x09,
- Border::BORDER_MEDIUMDASHDOT => 0x0A,
- Border::BORDER_DASHDOTDOT => 0x0B,
- Border::BORDER_MEDIUMDASHDOTDOT => 0x0C,
- Border::BORDER_SLANTDASHDOT => 0x0D,
- ];
-
- /**
- * Map border style.
- *
- * @param string $borderStyle
- *
- * @return int
- */
- private static function mapBorderStyle($borderStyle)
- {
- return self::$mapBorderStyles[$borderStyle] ?? 0;
- }
-
- /**
- * Map of BIFF2-BIFF8 codes for fill types.
- *
- * @var int[]
- */
- private static $mapFillTypes = [
- Fill::FILL_NONE => 0x00,
- Fill::FILL_SOLID => 0x01,
- Fill::FILL_PATTERN_MEDIUMGRAY => 0x02,
- Fill::FILL_PATTERN_DARKGRAY => 0x03,
- Fill::FILL_PATTERN_LIGHTGRAY => 0x04,
- Fill::FILL_PATTERN_DARKHORIZONTAL => 0x05,
- Fill::FILL_PATTERN_DARKVERTICAL => 0x06,
- Fill::FILL_PATTERN_DARKDOWN => 0x07,
- Fill::FILL_PATTERN_DARKUP => 0x08,
- Fill::FILL_PATTERN_DARKGRID => 0x09,
- Fill::FILL_PATTERN_DARKTRELLIS => 0x0A,
- Fill::FILL_PATTERN_LIGHTHORIZONTAL => 0x0B,
- Fill::FILL_PATTERN_LIGHTVERTICAL => 0x0C,
- Fill::FILL_PATTERN_LIGHTDOWN => 0x0D,
- Fill::FILL_PATTERN_LIGHTUP => 0x0E,
- Fill::FILL_PATTERN_LIGHTGRID => 0x0F,
- Fill::FILL_PATTERN_LIGHTTRELLIS => 0x10,
- Fill::FILL_PATTERN_GRAY125 => 0x11,
- Fill::FILL_PATTERN_GRAY0625 => 0x12,
- Fill::FILL_GRADIENT_LINEAR => 0x00, // does not exist in BIFF8
- Fill::FILL_GRADIENT_PATH => 0x00, // does not exist in BIFF8
- ];
-
- /**
- * Map fill type.
- *
- * @param string $fillType
- *
- * @return int
- */
- private static function mapFillType($fillType)
- {
- return self::$mapFillTypes[$fillType] ?? 0;
- }
-
- /**
- * Map of BIFF2-BIFF8 codes for horizontal alignment.
- *
- * @var int[]
- */
- private static $mapHAlignments = [
- Alignment::HORIZONTAL_GENERAL => 0,
- Alignment::HORIZONTAL_LEFT => 1,
- Alignment::HORIZONTAL_CENTER => 2,
- Alignment::HORIZONTAL_RIGHT => 3,
- Alignment::HORIZONTAL_FILL => 4,
- Alignment::HORIZONTAL_JUSTIFY => 5,
- Alignment::HORIZONTAL_CENTER_CONTINUOUS => 6,
- ];
-
- /**
- * Map to BIFF2-BIFF8 codes for horizontal alignment.
- *
- * @param string $hAlign
- *
- * @return int
- */
- private function mapHAlign($hAlign)
- {
- return self::$mapHAlignments[$hAlign] ?? 0;
- }
-
- /**
- * Map of BIFF2-BIFF8 codes for vertical alignment.
- *
- * @var int[]
- */
- private static $mapVAlignments = [
- Alignment::VERTICAL_TOP => 0,
- Alignment::VERTICAL_CENTER => 1,
- Alignment::VERTICAL_BOTTOM => 2,
- Alignment::VERTICAL_JUSTIFY => 3,
- ];
-
- /**
- * Map to BIFF2-BIFF8 codes for vertical alignment.
- *
- * @param string $vAlign
- *
- * @return int
- */
- private static function mapVAlign($vAlign)
- {
- return self::$mapVAlignments[$vAlign] ?? 2;
- }
-
/**
* Map to BIFF8 codes for text rotation angle.
*
diff --git a/src/PhpSpreadsheet/Writer/Xlsx/Chart.php b/src/PhpSpreadsheet/Writer/Xlsx/Chart.php
index eefae529..56b890bb 100644
--- a/src/PhpSpreadsheet/Writer/Xlsx/Chart.php
+++ b/src/PhpSpreadsheet/Writer/Xlsx/Chart.php
@@ -318,10 +318,10 @@ class Chart extends WriterPart
if ($chartType === DataSeries::TYPE_BUBBLECHART) {
$this->writeValueAxis($objWriter, $xAxisLabel, $chartType, $id1, $id2, $catIsMultiLevelSeries, $xAxis, $majorGridlines, $minorGridlines);
} else {
- $this->writeCategoryAxis($objWriter, $xAxisLabel, $id1, $id2, $catIsMultiLevelSeries, $yAxis);
+ $this->writeCategoryAxis($objWriter, $xAxisLabel, $id1, $id2, $catIsMultiLevelSeries, $xAxis);
}
- $this->writeValueAxis($objWriter, $yAxisLabel, $chartType, $id1, $id2, $valIsMultiLevelSeries, $xAxis, $majorGridlines, $minorGridlines);
+ $this->writeValueAxis($objWriter, $yAxisLabel, $chartType, $id1, $id2, $valIsMultiLevelSeries, $yAxis, $majorGridlines, $minorGridlines);
}
$objWriter->endElement();
diff --git a/src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php b/src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php
index 3978eb6f..38dead4f 100644
--- a/src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php
+++ b/src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php
@@ -634,15 +634,21 @@ class Worksheet extends WriterPart
self::writeAttributeif(
$objWriter,
- ($conditional->getConditionType() == Conditional::CONDITION_CELLIS || $conditional->getConditionType() == Conditional::CONDITION_CONTAINSTEXT)
- && $conditional->getOperatorType() != Conditional::OPERATOR_NONE,
+ (
+ $conditional->getConditionType() === Conditional::CONDITION_CELLIS
+ || $conditional->getConditionType() === Conditional::CONDITION_CONTAINSTEXT
+ || $conditional->getConditionType() === Conditional::CONDITION_NOTCONTAINSTEXT
+ ) && $conditional->getOperatorType() !== Conditional::OPERATOR_NONE,
'operator',
$conditional->getOperatorType()
);
self::writeAttributeIf($objWriter, $conditional->getStopIfTrue(), 'stopIfTrue', '1');
- if ($conditional->getConditionType() == Conditional::CONDITION_CONTAINSTEXT) {
+ if (
+ $conditional->getConditionType() === Conditional::CONDITION_CONTAINSTEXT
+ || $conditional->getConditionType() === Conditional::CONDITION_NOTCONTAINSTEXT
+ ) {
self::writeTextCondElements($objWriter, $conditional, $cellCoordinate);
} else {
self::writeOtherCondElements($objWriter, $conditional, $cellCoordinate);
@@ -1230,6 +1236,7 @@ class Worksheet extends WriterPart
$objWriter->writeAttribute('t', 'str');
} elseif (is_bool($calculatedValue)) {
$objWriter->writeAttribute('t', 'b');
+ $calculatedValue = (int) $calculatedValue;
}
// array values are not yet supported
//$attributes = $pCell->getFormulaAttributes();
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/AllSetupTeardown.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/AllSetupTeardown.php
index 414670c4..9fb5dfa5 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/AllSetupTeardown.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/AllSetupTeardown.php
@@ -27,22 +27,20 @@ class AllSetupTeardown extends TestCase
private $returnDateType;
/**
- * @var Spreadsheet
+ * @var ?Spreadsheet
*/
- protected $spreadsheet;
+ private $spreadsheet;
/**
- * @var Worksheet
+ * @var ?Worksheet
*/
- protected $sheet;
+ private $sheet;
protected function setUp(): void
{
$this->compatibilityMode = Functions::getCompatibilityMode();
$this->excelCalendar = Date::getExcelCalendar();
$this->returnDateType = Functions::getReturnDateType();
- $this->spreadsheet = new Spreadsheet();
- $this->sheet = $this->spreadsheet->getActiveSheet();
}
protected function tearDown(): void
@@ -50,7 +48,11 @@ class AllSetupTeardown extends TestCase
Date::setExcelCalendar($this->excelCalendar);
Functions::setCompatibilityMode($this->compatibilityMode);
Functions::setReturnDateType($this->returnDateType);
- $this->spreadsheet->disconnectWorksheets();
+ $this->sheet = null;
+ if ($this->spreadsheet !== null) {
+ $this->spreadsheet->disconnectWorksheets();
+ $this->spreadsheet = null;
+ }
}
protected static function setMac1904(): void
@@ -82,4 +84,24 @@ class AllSetupTeardown extends TestCase
$this->expectException(CalcException::class);
}
}
+
+ protected function getSpreadsheet(): Spreadsheet
+ {
+ if ($this->spreadsheet !== null) {
+ return $this->spreadsheet;
+ }
+ $this->spreadsheet = new Spreadsheet();
+
+ return $this->spreadsheet;
+ }
+
+ protected function getSheet(): Worksheet
+ {
+ if ($this->sheet !== null) {
+ return $this->sheet;
+ }
+ $this->sheet = $this->getSpreadsheet()->getActiveSheet();
+
+ return $this->sheet;
+ }
}
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DateDifTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DateDifTest.php
index 3aa9446d..d7d69376 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DateDifTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DateDifTest.php
@@ -12,7 +12,7 @@ class DateDifTest extends AllSetupTeardown
public function testDATEDIF($expectedResult, string $formula): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->getCell('B1')->setValue('1954-11-23');
$sheet->getCell('A1')->setValue("=DATEDIF($formula)");
self::assertSame($expectedResult, $sheet->getCell('A1')->getCalculatedValue());
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DateTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DateTest.php
index d790777b..5e884707 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DateTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DateTest.php
@@ -2,7 +2,7 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
-use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\Datefunc;
+use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\Date;
class DateTest extends AllSetupTeardown
{
@@ -14,7 +14,7 @@ class DateTest extends AllSetupTeardown
public function testDATE($expectedResult, string $formula): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->getCell('B1')->setValue('1954-11-23');
$sheet->getCell('A1')->setValue("=DATE($formula)");
self::assertEquals($expectedResult, $sheet->getCell('A1')->getCalculatedValue());
@@ -29,7 +29,7 @@ class DateTest extends AllSetupTeardown
{
self::setUnixReturn();
- $result = Datefunc::funcDate(2012, 1, 31); // 32-bit safe
+ $result = Date::fromYMD(2012, 1, 31); // 32-bit safe
self::assertEquals(1327968000, $result);
}
@@ -37,7 +37,7 @@ class DateTest extends AllSetupTeardown
{
self::setObjectReturn();
- $result = Datefunc::funcDate(2012, 1, 31);
+ $result = Date::fromYMD(2012, 1, 31);
// Must return an object...
self::assertIsObject($result);
// ... of the correct type
@@ -50,10 +50,10 @@ class DateTest extends AllSetupTeardown
{
self::setMac1904();
- $result = Datefunc::funcDate(1918, 11, 11);
+ $result = Date::fromYMD(1918, 11, 11);
self::assertEquals($result, 5428);
- $result = Datefunc::funcDate(1901, 1, 31);
+ $result = Date::fromYMD(1901, 1, 31);
self::assertEquals($result, '#NUM!');
}
}
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DateValueTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DateValueTest.php
index 2d422e0a..521bde1f 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DateValueTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DateValueTest.php
@@ -15,7 +15,7 @@ class DateValueTest extends AllSetupTeardown
*/
public function testDATEVALUE($expectedResult, string $dateValue): void
{
- $this->sheet->getCell('B1')->setValue('1954-07-20');
+ $this->getSheet()->getCell('B1')->setValue('1954-07-20');
// Loop to avoid extraordinarily rare edge case where first calculation
// and second do not take place on same day.
$row = 0;
@@ -26,11 +26,11 @@ class DateValueTest extends AllSetupTeardown
if (is_string($expectedResult)) {
$replYMD = str_replace('Y', date('Y'), $expectedResult);
if ($replYMD !== $expectedResult) {
- $expectedResult = DateValue::funcDateValue($replYMD);
+ $expectedResult = DateValue::fromString($replYMD);
}
}
- $this->sheet->getCell("A$row")->setValue("=DATEVALUE($dateValue)");
- $result = $this->sheet->getCell("A$row")->getCalculatedValue();
+ $this->getSheet()->getCell("A$row")->setValue("=DATEVALUE($dateValue)");
+ $result = $this->getSheet()->getCell("A$row")->getCalculatedValue();
$dtEnd = new DateTimeImmutable();
$endDay = $dtEnd->format('d');
} while ($startDay !== $endDay);
@@ -46,7 +46,7 @@ class DateValueTest extends AllSetupTeardown
{
self::setUnixReturn();
- $result = DateValue::funcDateValue('2012-1-31');
+ $result = DateValue::fromString('2012-1-31');
self::assertEquals(1327968000, $result);
self::assertEqualsWithDelta(1327968000, $result, 1E-8);
}
@@ -55,7 +55,7 @@ class DateValueTest extends AllSetupTeardown
{
self::setObjectReturn();
- $result = DateValue::funcDateValue('2012-1-31');
+ $result = DateValue::fromString('2012-1-31');
// Must return an object...
self::assertIsObject($result);
// ... of the correct type
@@ -67,9 +67,9 @@ class DateValueTest extends AllSetupTeardown
public function testDATEVALUEwith1904Calendar(): void
{
self::setMac1904();
- self::assertEquals(5428, DateValue::funcDateValue('1918-11-11'));
- self::assertEquals(0, DateValue::funcDateValue('1904-01-01'));
- self::assertEquals('#VALUE!', DateValue::funcDateValue('1903-12-31'));
- self::assertEquals('#VALUE!', DateValue::funcDateValue('1900-02-29'));
+ self::assertEquals(5428, DateValue::fromString('1918-11-11'));
+ self::assertEquals(0, DateValue::fromString('1904-01-01'));
+ self::assertEquals('#VALUE!', DateValue::fromString('1903-12-31'));
+ self::assertEquals('#VALUE!', DateValue::fromString('1900-02-29'));
}
}
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DayTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DayTest.php
index dc8adf11..af196050 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DayTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DayTest.php
@@ -12,7 +12,7 @@ class DayTest extends AllSetupTeardown
public function testDAY($expectedResultExcel, string $dateTimeValue): void
{
$this->mightHaveException($expectedResultExcel);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->getCell('B1')->setValue('1954-11-23');
$sheet->getCell('A1')->setValue("=DAY($dateTimeValue)");
self::assertSame($expectedResultExcel, $sheet->getCell('A1')->getCalculatedValue());
@@ -32,7 +32,7 @@ class DayTest extends AllSetupTeardown
{
self::setOpenOffice();
$this->mightHaveException($expectedResultOpenOffice);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->getCell('A2')->setValue("=DAY($dateTimeValue)");
self::assertSame($expectedResultOpenOffice, $sheet->getCell('A2')->getCalculatedValue());
}
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/Days360Test.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/Days360Test.php
index bd3a0283..5a3e235d 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/Days360Test.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/Days360Test.php
@@ -12,7 +12,7 @@ class Days360Test extends AllSetupTeardown
public function testDAYS360($expectedResult, string $formula): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->getCell('B1')->setValue('2000-02-29');
$sheet->getCell('C1')->setValue('2000-03-31');
$sheet->getCell('A1')->setValue("=DAYS360($formula)");
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DaysTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DaysTest.php
index 8c65622a..a63e45cc 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DaysTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DaysTest.php
@@ -17,7 +17,7 @@ class DaysTest extends AllSetupTeardown
public function testDAYS($expectedResult, string $formula): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->getCell('B1')->setValue('1954-11-23');
$sheet->getCell('C1')->setValue('1954-11-30');
$sheet->getCell('A1')->setValue("=DAYS($formula)");
@@ -33,13 +33,13 @@ class DaysTest extends AllSetupTeardown
{
$obj1 = new DateTime('2000-3-31');
$obj2 = new DateTimeImmutable('2000-2-29');
- self::assertSame(31, Days::funcDays($obj1, $obj2));
+ self::assertSame(31, Days::between($obj1, $obj2));
}
public function testNonDateObject(): void
{
$obj1 = new Exception();
$obj2 = new DateTimeImmutable('2000-2-29');
- self::assertSame('#VALUE!', Days::funcDays($obj1, $obj2));
+ self::assertSame('#VALUE!', Days::between($obj1, $obj2));
}
}
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/EDateTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/EDateTest.php
index efb34d0d..22613fe5 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/EDateTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/EDateTest.php
@@ -2,7 +2,7 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
-use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\EDate;
+use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\Month;
class EDateTest extends AllSetupTeardown
{
@@ -14,7 +14,7 @@ class EDateTest extends AllSetupTeardown
public function testEDATE($expectedResult, string $formula): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->getCell('A1')->setValue("=EDATE($formula)");
$sheet->getCell('B1')->setValue('1954-11-23');
self::assertEquals($expectedResult, $sheet->getCell('A1')->getCalculatedValue());
@@ -29,7 +29,7 @@ class EDateTest extends AllSetupTeardown
{
self::setUnixReturn();
- $result = EDate::funcEDate('2012-1-26', -1);
+ $result = Month::adjust('2012-1-26', -1);
self::assertEquals(1324857600, $result);
self::assertEqualsWithDelta(1324857600, $result, 1E-8);
}
@@ -38,7 +38,7 @@ class EDateTest extends AllSetupTeardown
{
self::setObjectReturn();
- $result = EDate::funcEDate('2012-1-26', -1);
+ $result = Month::adjust('2012-1-26', -1);
// Must return an object...
self::assertIsObject($result);
// ... of the correct type
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/EoMonthTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/EoMonthTest.php
index 6db76f58..3c39fbbc 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/EoMonthTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/EoMonthTest.php
@@ -2,7 +2,7 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
-use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\EoMonth;
+use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\Month;
class EoMonthTest extends AllSetupTeardown
{
@@ -14,7 +14,7 @@ class EoMonthTest extends AllSetupTeardown
public function testEOMONTH($expectedResult, string $formula): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->getCell('A1')->setValue("=EOMONTH($formula)");
$sheet->getCell('B1')->setValue('1954-11-23');
self::assertEquals($expectedResult, $sheet->getCell('A1')->getCalculatedValue());
@@ -29,7 +29,7 @@ class EoMonthTest extends AllSetupTeardown
{
self::setUnixReturn();
- $result = EoMonth::funcEomonth('2012-1-26', -1);
+ $result = Month::lastDay('2012-1-26', -1);
self::assertEquals(1325289600, $result);
}
@@ -37,7 +37,7 @@ class EoMonthTest extends AllSetupTeardown
{
self::setObjectReturn();
- $result = EoMonth::funcEomonth('2012-1-26', -1);
+ $result = Month::lastDay('2012-1-26', -1);
// Must return an object...
self::assertIsObject($result);
// ... of the correct type
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/HourTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/HourTest.php
index 93afbb5d..c1e4f29c 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/HourTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/HourTest.php
@@ -12,7 +12,7 @@ class HourTest extends AllSetupTeardown
public function testHOUR($expectedResult, string $dateTimeValue): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->getCell('A1')->setValue("=HOUR($dateTimeValue)");
$sheet->getCell('B1')->setValue('1954-11-23 2:23:46');
self::assertSame($expectedResult, $sheet->getCell('A1')->getCalculatedValue());
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/IsoWeekNumTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/IsoWeekNumTest.php
index 6be2e1af..29e35b38 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/IsoWeekNumTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/IsoWeekNumTest.php
@@ -13,7 +13,7 @@ class IsoWeekNumTest extends AllSetupTeardown
public function testISOWEEKNUM($expectedResult, $dateValue): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->getCell('A1')->setValue("=ISOWEEKNUM($dateValue)");
$sheet->getCell('B1')->setValue('1954-11-23');
self::assertSame($expectedResult, $sheet->getCell('A1')->getCalculatedValue());
@@ -34,7 +34,7 @@ class IsoWeekNumTest extends AllSetupTeardown
{
$this->mightHaveException($expectedResult);
self::setMac1904();
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->getCell('A1')->setValue("=ISOWEEKNUM($dateValue)");
$sheet->getCell('B1')->setValue('1954-11-23');
self::assertSame($expectedResult, $sheet->getCell('A1')->getCalculatedValue());
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/MinuteTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/MinuteTest.php
index 57d7a77e..b5207d7e 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/MinuteTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/MinuteTest.php
@@ -12,7 +12,7 @@ class MinuteTest extends AllSetupTeardown
public function testMINUTE($expectedResult, string $dateTimeValue): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->getCell('A1')->setValue("=MINUTE($dateTimeValue)");
$sheet->getCell('B1')->setValue('1954-11-23 2:23:46');
self::assertSame($expectedResult, $sheet->getCell('A1')->getCalculatedValue());
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/MonthTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/MonthTest.php
index ed09a993..30465e87 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/MonthTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/MonthTest.php
@@ -12,7 +12,7 @@ class MonthTest extends AllSetupTeardown
public function testMONTH($expectedResult, string $dateTimeValue): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->getCell('A1')->setValue("=MONTH($dateTimeValue)");
$sheet->getCell('B1')->setValue('1954-11-23');
self::assertSame($expectedResult, $sheet->getCell('A1')->getCalculatedValue());
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/NetworkDaysTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/NetworkDaysTest.php
index b121f7bf..d6b1a89f 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/NetworkDaysTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/NetworkDaysTest.php
@@ -14,7 +14,7 @@ class NetworkDaysTest extends AllSetupTeardown
public function testNETWORKDAYS($expectedResult, $arg1 = 'omitted', $arg2 = 'omitted', ?array $arg3 = null): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
if ($arg1 !== null) {
$sheet->getCell('A1')->setValue($arg1);
}
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/NowTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/NowTest.php
index e0f68c24..42362b99 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/NowTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/NowTest.php
@@ -8,7 +8,7 @@ class NowTest extends AllSetupTeardown
{
public function testNow(): void
{
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
// Loop to avoid rare edge case where first calculation
// and second do not take place in same second.
do {
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/SecondTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/SecondTest.php
index 6c264a57..1a411d45 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/SecondTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/SecondTest.php
@@ -12,7 +12,7 @@ class SecondTest extends AllSetupTeardown
public function testSECOND($expectedResult, string $dateTimeValue): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->getCell('A1')->setValue("=SECOND($dateTimeValue)");
$sheet->getCell('B1')->setValue('1954-11-23 2:23:46');
self::assertSame($expectedResult, $sheet->getCell('A1')->getCalculatedValue());
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/TimeTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/TimeTest.php
index d6910024..3ee1aa55 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/TimeTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/TimeTest.php
@@ -14,7 +14,7 @@ class TimeTest extends AllSetupTeardown
public function testTIME($expectedResult, string $formula): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->getCell('B1')->setValue('15');
$sheet->getCell('B2')->setValue('32');
$sheet->getCell('B3')->setValue('50');
@@ -31,7 +31,7 @@ class TimeTest extends AllSetupTeardown
{
self::setUnixReturn();
- $result = Time::funcTime(7, 30, 20);
+ $result = Time::fromHMS(7, 30, 20);
self::assertEqualsWithDelta(27020, $result, 1E-8);
}
@@ -39,7 +39,7 @@ class TimeTest extends AllSetupTeardown
{
self::setObjectReturn();
- $result = Time::funcTime(7, 30, 20);
+ $result = Time::fromHMS(7, 30, 20);
// Must return an object...
self::assertIsObject($result);
// ... of the correct type
@@ -51,13 +51,13 @@ class TimeTest extends AllSetupTeardown
public function testTIME1904(): void
{
self::setMac1904();
- $result = Time::funcTime(0, 0, 0);
+ $result = Time::fromHMS(0, 0, 0);
self::assertEquals(0, $result);
}
public function testTIME1900(): void
{
- $result = Time::funcTime(0, 0, 0);
+ $result = Time::fromHMS(0, 0, 0);
self::assertEquals(0, $result);
}
}
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/TimeValueTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/TimeValueTest.php
index ac4d3dbd..6995c312 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/TimeValueTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/TimeValueTest.php
@@ -15,7 +15,7 @@ class TimeValueTest extends AllSetupTeardown
public function testTIMEVALUE($expectedResult, $timeValue): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->getCell('B1')->setValue('03:45:52');
$sheet->getCell('A1')->setValue("=TIMEVALUE($timeValue)");
$result = $sheet->getCell('A1')->getCalculatedValue();
@@ -31,7 +31,7 @@ class TimeValueTest extends AllSetupTeardown
{
self::setUnixReturn();
- $result = TimeValue::funcTimeValue('7:30:20');
+ $result = TimeValue::fromString('7:30:20');
self::assertEquals(23420, $result);
self::assertEqualsWithDelta(23420, $result, 1E-8);
}
@@ -40,7 +40,7 @@ class TimeValueTest extends AllSetupTeardown
{
self::setObjectReturn();
- $result = TimeValue::funcTimeValue('7:30:20');
+ $result = TimeValue::fromString('7:30:20');
// Must return an object...
self::assertIsObject($result);
// ... of the correct type
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/TodayTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/TodayTest.php
index 6ce82bfd..b7108f75 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/TodayTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/TodayTest.php
@@ -8,7 +8,7 @@ class TodayTest extends AllSetupTeardown
{
public function testToday(): void
{
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
// Loop to avoid rare edge case where first calculation
// and second do not take place in same second.
do {
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/WeekDayTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/WeekDayTest.php
index c95ce9cc..3c7f682d 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/WeekDayTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/WeekDayTest.php
@@ -2,7 +2,7 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
-use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\WeekDay;
+use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\Week;
class WeekDayTest extends AllSetupTeardown
{
@@ -14,7 +14,7 @@ class WeekDayTest extends AllSetupTeardown
public function testWEEKDAY($expectedResult, string $formula): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->getCell('B1')->setValue('1954-11-23');
$sheet->getCell('A1')->setValue("=WEEKDAY($formula)");
self::assertSame($expectedResult, $sheet->getCell('A1')->getCalculatedValue());
@@ -28,8 +28,8 @@ class WeekDayTest extends AllSetupTeardown
public function testWEEKDAYwith1904Calendar(): void
{
self::setMac1904();
- self::assertEquals(7, WeekDay::funcWeekDay('1904-01-02'));
- self::assertEquals(6, WeekDay::funcWeekDay('1904-01-01'));
- self::assertEquals(6, WeekDay::funcWeekDay(null));
+ self::assertEquals(7, Week::day('1904-01-02'));
+ self::assertEquals(6, Week::day('1904-01-01'));
+ self::assertEquals(6, Week::day(null));
}
}
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/WeekNumTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/WeekNumTest.php
index cf8ac65b..caa71f17 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/WeekNumTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/WeekNumTest.php
@@ -12,7 +12,7 @@ class WeekNumTest extends AllSetupTeardown
public function testWEEKNUM($expectedResult, string $formula): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->getCell('B1')->setValue('1954-11-23');
$sheet->getCell('A1')->setValue("=WEEKNUM($formula)");
self::assertSame($expectedResult, $sheet->getCell('A1')->getCalculatedValue());
@@ -32,7 +32,7 @@ class WeekNumTest extends AllSetupTeardown
{
$this->mightHaveException($expectedResult);
self::setMac1904();
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->getCell('B1')->setValue('1954-11-23');
$sheet->getCell('A1')->setValue("=WEEKNUM($formula)");
self::assertSame($expectedResult, $sheet->getCell('A1')->getCalculatedValue());
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/WorkDayTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/WorkDayTest.php
index 80829699..3cfa9219 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/WorkDayTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/WorkDayTest.php
@@ -14,7 +14,7 @@ class WorkDayTest extends AllSetupTeardown
public function testWORKDAY($expectedResult, $arg1 = 'omitted', $arg2 = 'omitted', ?array $arg3 = null): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
if ($arg1 !== null) {
$sheet->getCell('A1')->setValue($arg1);
}
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/YearFracTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/YearFracTest.php
index e16ce697..d7427bfd 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/YearFracTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/YearFracTest.php
@@ -15,7 +15,7 @@ class YearFracTest extends AllSetupTeardown
public function testYEARFRAC($expectedResult, $arg1 = 'omitted', $arg2 = 'omitted', $arg3 = 'omitted'): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
if ($arg1 !== null) {
$sheet->getCell('A1')->setValue($arg1);
}
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/YearTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/YearTest.php
index 74b3bed0..a31ac7aa 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/YearTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/YearTest.php
@@ -12,7 +12,7 @@ class YearTest extends AllSetupTeardown
public function testYEAR($expectedResult, string $dateTimeValue): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->getCell('A1')->setValue("=YEAR($dateTimeValue)");
$sheet->getCell('B1')->setValue('1954-11-23');
self::assertSame($expectedResult, $sheet->getCell('A1')->getCalculatedValue());
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/AllSetupTeardown.php b/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/AllSetupTeardown.php
index 9374ce32..52f561e1 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/AllSetupTeardown.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/AllSetupTeardown.php
@@ -17,26 +17,28 @@ class AllSetupTeardown extends TestCase
protected $compatibilityMode;
/**
- * @var Spreadsheet
+ * @var ?Spreadsheet
*/
- protected $spreadsheet;
+ private $spreadsheet;
/**
- * @var Worksheet
+ * @var ?Worksheet
*/
- protected $sheet;
+ private $sheet;
protected function setUp(): void
{
$this->compatibilityMode = Functions::getCompatibilityMode();
- $this->spreadsheet = new Spreadsheet();
- $this->sheet = $this->spreadsheet->getActiveSheet();
}
protected function tearDown(): void
{
Functions::setCompatibilityMode($this->compatibilityMode);
- $this->spreadsheet->disconnectWorksheets();
+ $this->sheet = null;
+ if ($this->spreadsheet !== null) {
+ $this->spreadsheet->disconnectWorksheets();
+ $this->spreadsheet = null;
+ }
}
protected static function setOpenOffice(): void
@@ -66,10 +68,30 @@ class AllSetupTeardown extends TestCase
{
if ($value !== null) {
if (is_string($value) && is_numeric($value)) {
- $this->sheet->getCell($cell)->setValueExplicit($value, DataType::TYPE_STRING);
+ $this->getSheet()->getCell($cell)->setValueExplicit($value, DataType::TYPE_STRING);
} else {
- $this->sheet->getCell($cell)->setValue($value);
+ $this->getSheet()->getCell($cell)->setValue($value);
}
}
}
+
+ protected function getSpreadsheet(): Spreadsheet
+ {
+ if ($this->spreadsheet !== null) {
+ return $this->spreadsheet;
+ }
+ $this->spreadsheet = new Spreadsheet();
+
+ return $this->spreadsheet;
+ }
+
+ protected function getSheet(): Worksheet
+ {
+ if ($this->sheet !== null) {
+ return $this->sheet;
+ }
+ $this->sheet = $this->getSpreadsheet()->getActiveSheet();
+
+ return $this->sheet;
+ }
}
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/ColumnOnSpreadsheetTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/ColumnOnSpreadsheetTest.php
index 8b89a671..0c43f00f 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/ColumnOnSpreadsheetTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/ColumnOnSpreadsheetTest.php
@@ -15,12 +15,12 @@ class ColumnOnSpreadsheetTest extends AllSetupTeardown
public function testColumnOnSpreadsheet($expectedResult, $cellReference = 'omitted'): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
- $this->spreadsheet->addNamedRange(new NamedRange('namedrangex', $sheet, '$E$2:$E$6'));
- $this->spreadsheet->addNamedRange(new NamedRange('namedrangey', $sheet, '$F$2:$H$2'));
- $this->spreadsheet->addNamedRange(new NamedRange('namedrange3', $sheet, '$F$4:$H$4'));
+ $sheet = $this->getSheet();
+ $this->getSpreadsheet()->addNamedRange(new NamedRange('namedrangex', $sheet, '$E$2:$E$6'));
+ $this->getSpreadsheet()->addNamedRange(new NamedRange('namedrangey', $sheet, '$F$2:$H$2'));
+ $this->getSpreadsheet()->addNamedRange(new NamedRange('namedrange3', $sheet, '$F$4:$H$4'));
- $sheet1 = $this->spreadsheet->createSheet();
+ $sheet1 = $this->getSpreadsheet()->createSheet();
$sheet1->setTitle('OtherSheet');
if ($cellReference === 'omitted') {
@@ -40,11 +40,11 @@ class ColumnOnSpreadsheetTest extends AllSetupTeardown
public function testCOLUMNLocalDefinedName(): void
{
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
- $sheet1 = $this->spreadsheet->createSheet();
+ $sheet1 = $this->getSpreadsheet()->createSheet();
$sheet1->setTitle('OtherSheet');
- $this->spreadsheet->addNamedRange(new NamedRange('newnr', $sheet1, '$F$5:$H$5', true)); // defined locally, only usable on sheet1
+ $this->getSpreadsheet()->addNamedRange(new NamedRange('newnr', $sheet1, '$F$5:$H$5', true)); // defined locally, only usable on sheet1
$sheet1->getCell('B3')->setValue('=COLUMN(newnr)');
$result = $sheet1->getCell('B3')->getCalculatedValue();
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/ColumnsOnSpreadsheetTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/ColumnsOnSpreadsheetTest.php
index 93b09449..332b5ced 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/ColumnsOnSpreadsheetTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/ColumnsOnSpreadsheetTest.php
@@ -15,16 +15,16 @@ class ColumnsOnSpreadsheetTest extends AllSetupTeardown
public function testColumnsOnSpreadsheet($expectedResult, $cellReference = 'omitted'): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->setTitle('ThisSheet');
- $this->spreadsheet->addNamedRange(new NamedRange('namedrangex', $sheet, '$E$2:$E$6'));
- $this->spreadsheet->addNamedRange(new NamedRange('namedrangey', $sheet, '$F$2:$H$2'));
- $this->spreadsheet->addNamedRange(new NamedRange('namedrange3', $sheet, '$F$4:$H$4'));
- $this->spreadsheet->addNamedRange(new NamedRange('namedrange5', $sheet, '$F$5:$I$5', true));
+ $this->getSpreadsheet()->addNamedRange(new NamedRange('namedrangex', $sheet, '$E$2:$E$6'));
+ $this->getSpreadsheet()->addNamedRange(new NamedRange('namedrangey', $sheet, '$F$2:$H$2'));
+ $this->getSpreadsheet()->addNamedRange(new NamedRange('namedrange3', $sheet, '$F$4:$H$4'));
+ $this->getSpreadsheet()->addNamedRange(new NamedRange('namedrange5', $sheet, '$F$5:$I$5', true));
- $sheet1 = $this->spreadsheet->createSheet();
+ $sheet1 = $this->getSpreadsheet()->createSheet();
$sheet1->setTitle('OtherSheet');
- $this->spreadsheet->addNamedRange(new NamedRange('localname', $sheet1, '$F$6:$H$6', true));
+ $this->getSpreadsheet()->addNamedRange(new NamedRange('localname', $sheet1, '$F$6:$H$6', true));
if ($cellReference === 'omitted') {
$sheet->getCell('B3')->setValue('=COLUMNS()');
@@ -43,11 +43,11 @@ class ColumnsOnSpreadsheetTest extends AllSetupTeardown
public function testCOLUMNSLocalDefinedName(): void
{
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
- $sheet1 = $this->spreadsheet->createSheet();
+ $sheet1 = $this->getSpreadsheet()->createSheet();
$sheet1->setTitle('OtherSheet');
- $this->spreadsheet->addNamedRange(new NamedRange('newnr', $sheet1, '$F$5:$H$5', true)); // defined locally, only usable on sheet1
+ $this->getSpreadsheet()->addNamedRange(new NamedRange('newnr', $sheet1, '$F$5:$H$5', true)); // defined locally, only usable on sheet1
$sheet1->getCell('B3')->setValue('=COLUMNS(newnr)');
$result = $sheet1->getCell('B3')->getCalculatedValue();
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/HyperlinkTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/HyperlinkTest.php
new file mode 100644
index 00000000..e71992ed
--- /dev/null
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/HyperlinkTest.php
@@ -0,0 +1,51 @@
+getMockBuilder(Cell::class)
+ ->onlyMethods(['getHyperlink'])
+ ->disableOriginalConstructor()
+ ->getMock();
+ $cell->method('getHyperlink')
+ ->willReturn($hyperlink);
+
+ $result = LookupRef::HYPERLINK($linkUrl, $description, $cell);
+ if (!is_array($expectedResult)) {
+ self::assertSame($expectedResult, $result);
+ } else {
+ self::assertSame($expectedResult[1], $result);
+ self::assertSame($expectedResult[0], $hyperlink->getUrl());
+ self::assertSame($expectedResult[1], $hyperlink->getTooltip());
+ }
+ }
+
+ public function providerHYPERLINK(): array
+ {
+ return require 'tests/data/Calculation/LookupRef/HYPERLINK.php';
+ }
+
+ public function testHYPERLINKwithoutCell(): void
+ {
+ $result = LookupRef::HYPERLINK('https://phpspreadsheet.readthedocs.io/en/latest/', 'Read the Docs');
+ self::assertSame(Functions::REF(), $result);
+ }
+}
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/IndirectTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/IndirectTest.php
index c53dce5c..7601e336 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/IndirectTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/IndirectTest.php
@@ -17,7 +17,7 @@ class IndirectTest extends AllSetupTeardown
public function testINDIRECT($expectedResult, $cellReference = 'omitted', $a1 = 'omitted'): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->getCell('A1')->setValue(100);
$sheet->getCell('A2')->setValue(200);
$sheet->getCell('A3')->setValue(300);
@@ -25,7 +25,7 @@ class IndirectTest extends AllSetupTeardown
$sheet->getCell('A5')->setValue(500);
$sheet->setTitle('ThisSheet');
- $sheet1 = $this->spreadsheet->createSheet();
+ $sheet1 = $this->getSpreadsheet()->createSheet();
$sheet1->getCell('A1')->setValue(10);
$sheet1->getCell('A2')->setValue(20);
$sheet1->getCell('A3')->setValue(30);
@@ -37,8 +37,8 @@ class IndirectTest extends AllSetupTeardown
$sheet1->getCell('B4')->setValue(4);
$sheet1->getCell('B5')->setValue(5);
$sheet1->setTitle('OtherSheet');
- $this->spreadsheet->addNamedRange(new NamedRange('newnr', $sheet1, '$A$2:$A$4'));
- $this->spreadsheet->addNamedRange(new NamedRange('localname', $sheet1, '$B$2:$B$4', true));
+ $this->getSpreadsheet()->addNamedRange(new NamedRange('newnr', $sheet1, '$A$2:$A$4'));
+ $this->getSpreadsheet()->addNamedRange(new NamedRange('localname', $sheet1, '$B$2:$B$4', true));
$this->setCell('B1', $cellReference);
$this->setCell('B2', $a1);
@@ -61,14 +61,14 @@ class IndirectTest extends AllSetupTeardown
public function testINDIRECTEurUsd(): void
{
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->getCell('A1')->setValue('EUR');
$sheet->getCell('A2')->setValue('USD');
$sheet->getCell('B1')->setValue(360);
$sheet->getCell('B2')->setValue(300);
- $this->spreadsheet->addNamedRange(new NamedRange('EUR', $sheet, '$B$1'));
- $this->spreadsheet->addNamedRange(new NamedRange('USD', $sheet, '$B$2'));
+ $this->getSpreadsheet()->addNamedRange(new NamedRange('EUR', $sheet, '$B$1'));
+ $this->getSpreadsheet()->addNamedRange(new NamedRange('USD', $sheet, '$B$2'));
$this->setCell('E1', '=INDIRECT("USD")');
@@ -78,14 +78,14 @@ class IndirectTest extends AllSetupTeardown
public function testINDIRECTLeadingEquals(): void
{
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->getCell('A1')->setValue('EUR');
$sheet->getCell('A2')->setValue('USD');
$sheet->getCell('B1')->setValue(360);
$sheet->getCell('B2')->setValue(300);
- $this->spreadsheet->addNamedRange(new NamedRange('EUR', $sheet, '=$B$1'));
- $this->spreadsheet->addNamedRange(new NamedRange('USD', $sheet, '=$B$2'));
+ $this->getSpreadsheet()->addNamedRange(new NamedRange('EUR', $sheet, '=$B$1'));
+ $this->getSpreadsheet()->addNamedRange(new NamedRange('USD', $sheet, '=$B$2'));
$this->setCell('E1', '=INDIRECT("USD")');
@@ -125,7 +125,7 @@ class IndirectTest extends AllSetupTeardown
public function testDeprecatedCall(): void
{
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->getCell('A1')->setValue('A2');
$sheet->getCell('A2')->setValue('This is it');
$result = \PhpOffice\PhpSpreadsheet\Calculation\LookupRef::INDIRECT('A2', $sheet->getCell('A1'));
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/RowOnSpreadsheetTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/RowOnSpreadsheetTest.php
index 724349f2..3fed7add 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/RowOnSpreadsheetTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/RowOnSpreadsheetTest.php
@@ -15,16 +15,16 @@ class RowOnSpreadsheetTest extends AllSetupTeardown
public function testRowOnSpreadsheet($expectedResult, $cellReference = 'omitted'): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->setTitle('ThisSheet');
- $this->spreadsheet->addNamedRange(new NamedRange('namedrangex', $sheet, '$E$2:$E$6'));
- $this->spreadsheet->addNamedRange(new NamedRange('namedrangey', $sheet, '$F$2:$H$2'));
- $this->spreadsheet->addNamedRange(new NamedRange('namedrange3', $sheet, '$F$4:$H$4'));
- $this->spreadsheet->addNamedRange(new NamedRange('namedrange5', $sheet, '$F$5:$H$5', true));
+ $this->getSpreadsheet()->addNamedRange(new NamedRange('namedrangex', $sheet, '$E$2:$E$6'));
+ $this->getSpreadsheet()->addNamedRange(new NamedRange('namedrangey', $sheet, '$F$2:$H$2'));
+ $this->getSpreadsheet()->addNamedRange(new NamedRange('namedrange3', $sheet, '$F$4:$H$4'));
+ $this->getSpreadsheet()->addNamedRange(new NamedRange('namedrange5', $sheet, '$F$5:$H$5', true));
- $sheet1 = $this->spreadsheet->createSheet();
+ $sheet1 = $this->getSpreadsheet()->createSheet();
$sheet1->setTitle('OtherSheet');
- $this->spreadsheet->addNamedRange(new NamedRange('localname', $sheet1, '$F$6:$H$6', true));
+ $this->getSpreadsheet()->addNamedRange(new NamedRange('localname', $sheet1, '$F$6:$H$6', true));
if ($cellReference === 'omitted') {
$sheet->getCell('B3')->setValue('=ROW()');
@@ -43,11 +43,11 @@ class RowOnSpreadsheetTest extends AllSetupTeardown
public function testINDIRECTLocalDefinedName(): void
{
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
- $sheet1 = $this->spreadsheet->createSheet();
+ $sheet1 = $this->getSpreadsheet()->createSheet();
$sheet1->setTitle('OtherSheet');
- $this->spreadsheet->addNamedRange(new NamedRange('newnr', $sheet1, '$F$5:$H$5', true)); // defined locally, only usable on sheet1
+ $this->getSpreadsheet()->addNamedRange(new NamedRange('newnr', $sheet1, '$F$5:$H$5', true)); // defined locally, only usable on sheet1
$sheet1->getCell('B3')->setValue('=ROW(newnr)');
$result = $sheet1->getCell('B3')->getCalculatedValue();
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/RowsOnSpreadsheetTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/RowsOnSpreadsheetTest.php
index ba9ea518..ce5bd5ee 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/RowsOnSpreadsheetTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/RowsOnSpreadsheetTest.php
@@ -15,16 +15,16 @@ class RowsOnSpreadsheetTest extends AllSetupTeardown
public function testRowsOnSpreadsheet($expectedResult, $cellReference = 'omitted'): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->setTitle('ThisSheet');
- $this->spreadsheet->addNamedRange(new NamedRange('namedrangex', $sheet, '$E$2:$E$6'));
- $this->spreadsheet->addNamedRange(new NamedRange('namedrangey', $sheet, '$F$2:$H$2'));
- $this->spreadsheet->addNamedRange(new NamedRange('namedrange3', $sheet, '$F$4:$H$4'));
- $this->spreadsheet->addNamedRange(new NamedRange('namedrange5', $sheet, '$F$5:$H$5', true));
+ $this->getSpreadsheet()->addNamedRange(new NamedRange('namedrangex', $sheet, '$E$2:$E$6'));
+ $this->getSpreadsheet()->addNamedRange(new NamedRange('namedrangey', $sheet, '$F$2:$H$2'));
+ $this->getSpreadsheet()->addNamedRange(new NamedRange('namedrange3', $sheet, '$F$4:$H$4'));
+ $this->getSpreadsheet()->addNamedRange(new NamedRange('namedrange5', $sheet, '$F$5:$H$5', true));
- $sheet1 = $this->spreadsheet->createSheet();
+ $sheet1 = $this->getSpreadsheet()->createSheet();
$sheet1->setTitle('OtherSheet');
- $this->spreadsheet->addNamedRange(new NamedRange('localname', $sheet1, '$F$6:$H$6', true));
+ $this->getSpreadsheet()->addNamedRange(new NamedRange('localname', $sheet1, '$F$6:$H$6', true));
if ($cellReference === 'omitted') {
$sheet->getCell('B3')->setValue('=ROWS()');
@@ -43,11 +43,11 @@ class RowsOnSpreadsheetTest extends AllSetupTeardown
public function testRowsLocalDefinedName(): void
{
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
- $sheet1 = $this->spreadsheet->createSheet();
+ $sheet1 = $this->getSpreadsheet()->createSheet();
$sheet1->setTitle('OtherSheet');
- $this->spreadsheet->addNamedRange(new NamedRange('newnr', $sheet1, '$F$5:$H$10', true)); // defined locally, only usable on sheet1
+ $this->getSpreadsheet()->addNamedRange(new NamedRange('newnr', $sheet1, '$F$5:$H$10', true)); // defined locally, only usable on sheet1
$sheet1->getCell('B3')->setValue('=ROWS(newnr)');
$result = $sheet1->getCell('B3')->getCalculatedValue();
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AbsTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AbsTest.php
index 5dc97e15..b6871905 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AbsTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AbsTest.php
@@ -12,7 +12,7 @@ class AbsTest extends AllSetupTeardown
*/
public function testRound($expectedResult, $number = 'omitted'): void
{
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$this->mightHaveException($expectedResult);
$this->setCell('A1', $number);
if ($number === 'omitted') {
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AcosTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AcosTest.php
index c6372ddb..4b71a541 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AcosTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AcosTest.php
@@ -12,7 +12,7 @@ class AcosTest extends AllSetupTeardown
public function testAcos($expectedResult, string $formula): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->getCell('A2')->setValue(0.5);
$sheet->getCell('A1')->setValue("=ACOS($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AcoshTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AcoshTest.php
index 557da135..c2116009 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AcoshTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AcoshTest.php
@@ -12,7 +12,7 @@ class AcoshTest extends AllSetupTeardown
public function testAcosh($expectedResult, string $formula): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->getCell('A2')->setValue('1.5');
$sheet->getCell('A1')->setValue("=ACOSH($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AcotTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AcotTest.php
index d94d4dec..8aa5541f 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AcotTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AcotTest.php
@@ -13,7 +13,7 @@ class AcotTest extends AllSetupTeardown
public function testACOT($expectedResult, $number): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->setCellValue('A2', 1.3);
$sheet->setCellValue('A3', 2.7);
$sheet->setCellValue('A4', -3.8);
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AcothTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AcothTest.php
index a065b496..173d27b5 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AcothTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AcothTest.php
@@ -13,7 +13,7 @@ class AcothTest extends AllSetupTeardown
public function testACOTH($expectedResult, $number): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->setCellValue('A2', 1.3);
$sheet->setCellValue('A3', 2.7);
$sheet->setCellValue('A4', -3.8);
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AllSetupTeardown.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AllSetupTeardown.php
index a8630727..f54ecaad 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AllSetupTeardown.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AllSetupTeardown.php
@@ -17,26 +17,28 @@ class AllSetupTeardown extends TestCase
private $compatibilityMode;
/**
- * @var Spreadsheet
+ * @var ?Spreadsheet
*/
private $spreadsheet;
/**
- * @var Worksheet
+ * @var ?Worksheet
*/
- protected $sheet;
+ private $sheet;
protected function setUp(): void
{
$this->compatibilityMode = Functions::getCompatibilityMode();
- $this->spreadsheet = new Spreadsheet();
- $this->sheet = $this->spreadsheet->getActiveSheet();
}
protected function tearDown(): void
{
Functions::setCompatibilityMode($this->compatibilityMode);
- $this->spreadsheet->disconnectWorksheets();
+ $this->sheet = null;
+ if ($this->spreadsheet !== null) {
+ $this->spreadsheet->disconnectWorksheets();
+ $this->spreadsheet = null;
+ }
}
protected static function setOpenOffice(): void
@@ -66,10 +68,30 @@ class AllSetupTeardown extends TestCase
{
if ($value !== null) {
if (is_string($value) && is_numeric($value)) {
- $this->sheet->getCell($cell)->setValueExplicit($value, DataType::TYPE_STRING);
+ $this->getSheet()->getCell($cell)->setValueExplicit($value, DataType::TYPE_STRING);
} else {
- $this->sheet->getCell($cell)->setValue($value);
+ $this->getSheet()->getCell($cell)->setValue($value);
}
}
}
+
+ protected function getSpreadsheet(): Spreadsheet
+ {
+ if ($this->spreadsheet !== null) {
+ return $this->spreadsheet;
+ }
+ $this->spreadsheet = new Spreadsheet();
+
+ return $this->spreadsheet;
+ }
+
+ protected function getSheet(): Worksheet
+ {
+ if ($this->sheet !== null) {
+ return $this->sheet;
+ }
+ $this->sheet = $this->getSpreadsheet()->getActiveSheet();
+
+ return $this->sheet;
+ }
}
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/ArabicTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/ArabicTest.php
index c9dbbcce..7921e85d 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/ArabicTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/ArabicTest.php
@@ -13,7 +13,7 @@ class ArabicTest extends AllSetupTeardown
public function testARABIC($expectedResult, $romanNumeral): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->getCell('A1')->setValue($romanNumeral);
$sheet->getCell('B1')->setValue('=ARABIC(A1)');
$result = $sheet->getCell('B1')->getCalculatedValue();
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AsinTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AsinTest.php
index b3612d01..73500d9a 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AsinTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AsinTest.php
@@ -12,7 +12,7 @@ class AsinTest extends AllSetupTeardown
public function testAsin($expectedResult, string $formula): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->getCell('A2')->setValue(0.5);
$sheet->getCell('A1')->setValue("=ASIN($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AsinhTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AsinhTest.php
index e8f21142..4337a394 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AsinhTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AsinhTest.php
@@ -12,7 +12,7 @@ class AsinhTest extends AllSetupTeardown
public function testAsinh($expectedResult, string $formula): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->getCell('A2')->setValue(0.5);
$sheet->getCell('A1')->setValue("=ASINH($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/Atan2Test.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/Atan2Test.php
index a22d6ad3..dcf35ad1 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/Atan2Test.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/Atan2Test.php
@@ -12,7 +12,7 @@ class Atan2Test extends AllSetupTeardown
public function testATAN2($expectedResult, string $formula): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->getCell('A2')->setValue(5);
$sheet->getCell('A3')->setValue(6);
$sheet->getCell('A1')->setValue("=ATAN2($formula)");
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AtanTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AtanTest.php
index 69f4ed53..4eefd922 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AtanTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AtanTest.php
@@ -12,7 +12,7 @@ class AtanTest extends AllSetupTeardown
public function testAtan($expectedResult, string $formula): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->getCell('A2')->setValue(5);
$sheet->getCell('A1')->setValue("=ATAN($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AtanhTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AtanhTest.php
index 20a3e9c0..d790b526 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AtanhTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AtanhTest.php
@@ -12,7 +12,7 @@ class AtanhTest extends AllSetupTeardown
public function testAtanh($expectedResult, string $formula): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->getCell('A2')->setValue(0.8);
$sheet->getCell('A1')->setValue("=ATANH($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/BaseTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/BaseTest.php
index 8bf0f4b2..02f895cb 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/BaseTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/BaseTest.php
@@ -15,7 +15,7 @@ class BaseTest extends AllSetupTeardown
public function testBASE($expectedResult, $arg1 = 'omitted', $arg2 = 'omitted', $arg3 = 'omitted'): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
if ($arg1 !== null) {
$sheet->getCell('A1')->setValue($arg1);
}
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CeilingMathTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CeilingMathTest.php
index f4039458..8622ad62 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CeilingMathTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CeilingMathTest.php
@@ -13,7 +13,7 @@ class CeilingMathTest extends AllSetupTeardown
public function testCEILINGMATH($expectedResult, $formula): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->setCellValue('A2', 1.3);
$sheet->setCellValue('A3', 2.7);
$sheet->setCellValue('A4', -3.8);
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CeilingPreciseTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CeilingPreciseTest.php
index c859646b..f7b0cc28 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CeilingPreciseTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CeilingPreciseTest.php
@@ -13,7 +13,7 @@ class CeilingPreciseTest extends AllSetupTeardown
public function testCEILINGPRECISE($expectedResult, $formula): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->setCellValue('A2', 1.3);
$sheet->setCellValue('A3', 2.7);
$sheet->setCellValue('A4', -3.8);
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CeilingTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CeilingTest.php
index d65ac6e9..3ac38b0d 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CeilingTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CeilingTest.php
@@ -13,7 +13,7 @@ class CeilingTest extends AllSetupTeardown
public function testCEILING($expectedResult, $formula): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->setCellValue('A2', 1.3);
$sheet->setCellValue('A3', 2.7);
$sheet->setCellValue('A4', -3.8);
@@ -31,7 +31,7 @@ class CeilingTest extends AllSetupTeardown
public function testCEILINGGnumeric1Arg(): void
{
self::setGnumeric();
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->getCell('A1')->setValue('=CEILING(5.1)');
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta(6, $result, 1E-12);
@@ -40,7 +40,7 @@ class CeilingTest extends AllSetupTeardown
public function testCELINGOpenOffice1Arg(): void
{
self::setOpenOffice();
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->getCell('A1')->setValue('=CEILING(5.1)');
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta(6, $result, 1E-12);
@@ -49,7 +49,7 @@ class CeilingTest extends AllSetupTeardown
public function testCEILINGExcel1Arg(): void
{
$this->mightHaveException('exception');
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->getCell('A1')->setValue('=CEILING(5.1)');
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta(6, $result, 1E-12);
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CombinATest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CombinATest.php
index 45ad8b29..0bc70de1 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CombinATest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CombinATest.php
@@ -14,7 +14,7 @@ class CombinATest extends AllSetupTeardown
public function testCOMBINA($expectedResult, $numObjs, $numInSet): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
if ($numObjs !== null) {
$sheet->getCell('A1')->setValue($numObjs);
}
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CombinTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CombinTest.php
index 408b60fe..8680dee6 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CombinTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CombinTest.php
@@ -14,7 +14,7 @@ class CombinTest extends AllSetupTeardown
public function testCOMBIN($expectedResult, $numObjs, $numInSet): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
if ($numObjs !== null) {
$sheet->getCell('A1')->setValue($numObjs);
}
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CosTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CosTest.php
index 5bb3427e..2024c6b2 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CosTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CosTest.php
@@ -12,7 +12,7 @@ class CosTest extends AllSetupTeardown
public function testCos($expectedResult, string $formula): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->setCellValue('A2', 2);
$sheet->getCell('A1')->setValue("=COS($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CoshTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CoshTest.php
index c408338f..1a87f72e 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CoshTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CoshTest.php
@@ -12,7 +12,7 @@ class CoshTest extends AllSetupTeardown
public function testCosh($expectedResult, string $formula): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->setCellValue('A2', 2);
$sheet->getCell('A1')->setValue("=COSH($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CotTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CotTest.php
index d096d0da..db9c17d1 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CotTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CotTest.php
@@ -13,7 +13,7 @@ class CotTest extends AllSetupTeardown
public function testCOT($expectedResult, $angle): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->setCellValue('A2', 1.3);
$sheet->setCellValue('A3', 2.7);
$sheet->setCellValue('A4', -3.8);
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CothTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CothTest.php
index 11949c43..ed0bf13e 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CothTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CothTest.php
@@ -13,7 +13,7 @@ class CothTest extends AllSetupTeardown
public function testCOTH($expectedResult, $angle): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->setCellValue('A2', 1.3);
$sheet->setCellValue('A3', 2.7);
$sheet->setCellValue('A4', -3.8);
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CscTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CscTest.php
index ea5a74bf..ff4067a7 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CscTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CscTest.php
@@ -13,7 +13,7 @@ class CscTest extends AllSetupTeardown
public function testCSC($expectedResult, $angle): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->setCellValue('A2', 1.3);
$sheet->setCellValue('A3', 2.7);
$sheet->setCellValue('A4', -3.8);
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CschTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CschTest.php
index 071f7497..9f6a87e7 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CschTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CschTest.php
@@ -13,7 +13,7 @@ class CschTest extends AllSetupTeardown
public function testCSCH($expectedResult, $angle): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->setCellValue('A2', 1.3);
$sheet->setCellValue('A3', 2.7);
$sheet->setCellValue('A4', -3.8);
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/DegreesTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/DegreesTest.php
index 10eb3b10..c931be2b 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/DegreesTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/DegreesTest.php
@@ -12,7 +12,7 @@ class DegreesTest extends AllSetupTeardown
*/
public function testDegrees($expectedResult, $number = 'omitted'): void
{
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$this->mightHaveException($expectedResult);
$this->setCell('A1', $number);
if ($number === 'omitted') {
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/EvenTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/EvenTest.php
index 12bca051..933737b4 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/EvenTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/EvenTest.php
@@ -13,7 +13,7 @@ class EvenTest extends AllSetupTeardown
public function testEVEN($expectedResult, $value): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->getCell('A1')->setValue("=EVEN($value)");
$sheet->getCell('A2')->setValue(3.7);
self::assertEquals($expectedResult, $sheet->getCell('A1')->getCalculatedValue());
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/ExpTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/ExpTest.php
index 70e7c650..c1c88bb1 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/ExpTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/ExpTest.php
@@ -13,7 +13,7 @@ class ExpTest extends AllSetupTeardown
public function testEXP($expectedResult, $number = 'omitted'): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
if ($number !== null) {
$sheet->getCell('A1')->setValue($number);
}
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/FactDoubleTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/FactDoubleTest.php
index 70f06f11..7a620655 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/FactDoubleTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/FactDoubleTest.php
@@ -13,7 +13,7 @@ class FactDoubleTest extends AllSetupTeardown
public function testFACTDOUBLE($expectedResult, $value): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->getCell('A1')->setValue($value);
$sheet->getCell('B1')->setValue('=FACTDOUBLE(A1)');
$result = $sheet->getCell('B1')->getCalculatedValue();
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/FactTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/FactTest.php
index 379b382c..5dca45ff 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/FactTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/FactTest.php
@@ -13,7 +13,7 @@ class FactTest extends AllSetupTeardown
public function testFACT($expectedResult, $arg1): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
if ($arg1 !== null) {
$sheet->getCell('A1')->setValue($arg1);
}
@@ -41,7 +41,7 @@ class FactTest extends AllSetupTeardown
{
$this->mightHaveException($expectedResult);
self::setGnumeric();
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
if ($arg1 !== null) {
$sheet->getCell('A1')->setValue($arg1);
}
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/FloorMathTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/FloorMathTest.php
index ecf4c73a..c5235569 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/FloorMathTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/FloorMathTest.php
@@ -13,7 +13,7 @@ class FloorMathTest extends AllSetupTeardown
public function testFLOORMATH($expectedResult, $formula): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->setCellValue('A2', 1.3);
$sheet->setCellValue('A3', 2.7);
$sheet->setCellValue('A4', -3.8);
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/FloorPreciseTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/FloorPreciseTest.php
index 22dd72ad..7db80d7a 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/FloorPreciseTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/FloorPreciseTest.php
@@ -13,7 +13,7 @@ class FloorPreciseTest extends AllSetupTeardown
public function testFLOORPRECISE($expectedResult, $formula): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->setCellValue('A2', 1.3);
$sheet->setCellValue('A3', 2.7);
$sheet->setCellValue('A4', -3.8);
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/FloorTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/FloorTest.php
index b981b26a..a106a91d 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/FloorTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/FloorTest.php
@@ -13,7 +13,7 @@ class FloorTest extends AllSetupTeardown
public function testFLOOR($expectedResult, $formula): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->setCellValue('A2', 1.3);
$sheet->setCellValue('A3', 2.7);
$sheet->setCellValue('A4', -3.8);
@@ -31,7 +31,7 @@ class FloorTest extends AllSetupTeardown
public function testFLOORGnumeric1Arg(): void
{
self::setGnumeric();
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->getCell('A1')->setValue('=FLOOR(5.1)');
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta(5, $result, 1E-12);
@@ -40,7 +40,7 @@ class FloorTest extends AllSetupTeardown
public function testFLOOROpenOffice1Arg(): void
{
self::setOpenOffice();
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->getCell('A1')->setValue('=FLOOR(5.1)');
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta(5, $result, 1E-12);
@@ -49,7 +49,7 @@ class FloorTest extends AllSetupTeardown
public function testFLOORExcel1Arg(): void
{
$this->mightHaveException('exception');
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->getCell('A1')->setValue('=FLOOR(5.1)');
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta(5, $result, 1E-12);
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/GcdTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/GcdTest.php
index aaa641d7..8c79e0fa 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/GcdTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/GcdTest.php
@@ -12,7 +12,7 @@ class GcdTest extends AllSetupTeardown
public function testGCD($expectedResult, ...$args): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$row = 0;
foreach ($args as $arg) {
++$row;
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/IntTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/IntTest.php
index 29abbf41..e121decb 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/IntTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/IntTest.php
@@ -13,7 +13,7 @@ class IntTest extends AllSetupTeardown
public function testINT($expectedResult, $formula): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->setCellValue('A2', 1.3);
$sheet->setCellValue('A3', 2.7);
$sheet->setCellValue('A4', -3.8);
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/LcmTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/LcmTest.php
index 5d0ebb58..ec51e3a0 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/LcmTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/LcmTest.php
@@ -11,7 +11,7 @@ class LcmTest extends AllSetupTeardown
*/
public function testLCM($expectedResult, ...$args): void
{
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$row = 0;
foreach ($args as $arg) {
++$row;
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/LnTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/LnTest.php
index 3fe35a3c..991af46d 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/LnTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/LnTest.php
@@ -13,7 +13,7 @@ class LnTest extends AllSetupTeardown
public function testLN($expectedResult, $number = 'omitted'): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
if ($number !== null) {
$sheet->getCell('A1')->setValue($number);
}
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/Log10Test.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/Log10Test.php
index 61cade1d..be095c9b 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/Log10Test.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/Log10Test.php
@@ -13,7 +13,7 @@ class Log10Test extends AllSetupTeardown
public function testLN($expectedResult, $number = 'omitted'): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
if ($number !== null) {
$sheet->getCell('A1')->setValue($number);
}
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/LogTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/LogTest.php
index 8c45a840..ba1823b1 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/LogTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/LogTest.php
@@ -14,7 +14,7 @@ class LogTest extends AllSetupTeardown
public function testLOG($expectedResult, $number = 'omitted', $base = 'omitted'): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
if ($number !== null) {
$sheet->getCell('A1')->setValue($number);
}
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/MInverseTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/MInverseTest.php
index b629d466..f059ab48 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/MInverseTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/MInverseTest.php
@@ -25,7 +25,7 @@ class MInverseTest extends AllSetupTeardown
public function testOnSpreadsheet(): void
{
// very limited ability to test this in the absence of dynamic arrays
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->getCell('A1')->setValue('=MINVERSE({1,2,3})'); // not square
self::assertSame('#VALUE!', $sheet->getCell('A1')->getCalculatedValue());
}
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/MMultTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/MMultTest.php
index e27922c2..7e15b94c 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/MMultTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/MMultTest.php
@@ -25,7 +25,7 @@ class MMultTest extends AllSetupTeardown
public function testOnSpreadsheet(): void
{
// very limited ability to test this in the absence of dynamic arrays
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->getCell('A1')->setValue('=MMULT({1,2,3}, {1,2,3})'); // incompatible dimensions
self::assertSame('#VALUE!', $sheet->getCell('A1')->getCalculatedValue());
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/MRoundTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/MRoundTest.php
index e7aa0f41..80a3d4ba 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/MRoundTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/MRoundTest.php
@@ -13,7 +13,7 @@ class MRoundTest extends AllSetupTeardown
public function testMROUND($expectedResult, $formula): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->setCellValue('A2', 1.3);
$sheet->setCellValue('A3', 2.7);
$sheet->setCellValue('A4', -3.8);
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/MdeTermTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/MdeTermTest.php
index b2cb4bb2..ddd39616 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/MdeTermTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/MdeTermTest.php
@@ -13,7 +13,7 @@ class MdeTermTest extends AllSetupTeardown
public function testMDETERM2($expectedResult, $matrix): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
if (is_array($matrix)) {
$sheet->fromArray($matrix, null, 'A1', true);
$maxCol = $sheet->getHighestColumn();
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/ModTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/ModTest.php
index ff35657f..2035d26f 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/ModTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/ModTest.php
@@ -14,7 +14,7 @@ class ModTest extends AllSetupTeardown
public function testMOD($expectedResult, $dividend = 'omitted', $divisor = 'omitted'): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
if ($dividend !== null) {
$sheet->getCell('A1')->setValue($dividend);
}
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/MultinomialTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/MultinomialTest.php
index 3fea7651..f511792a 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/MultinomialTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/MultinomialTest.php
@@ -12,7 +12,7 @@ class MultinomialTest extends AllSetupTeardown
public function testMULTINOMIAL($expectedResult, ...$args): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$row = 0;
$excelArg = '';
foreach ($args as $arg) {
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/OddTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/OddTest.php
index 37042743..4f6b0cab 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/OddTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/OddTest.php
@@ -13,7 +13,7 @@ class OddTest extends AllSetupTeardown
public function testODD($expectedResult, $value): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->getCell('A1')->setValue("=ODD($value)");
$sheet->getCell('A2')->setValue(3.7);
self::assertEquals($expectedResult, $sheet->getCell('A1')->getCalculatedValue());
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/PowerTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/PowerTest.php
index 4d6ba7e2..179f7ea9 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/PowerTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/PowerTest.php
@@ -14,7 +14,7 @@ class PowerTest extends AllSetupTeardown
public function testPOWER($expectedResult, $base = 'omitted', $exponent = 'omitted'): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
if ($base !== null) {
$sheet->getCell('A1')->setValue($base);
}
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/ProductTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/ProductTest.php
index 4e63ae91..8ce39310 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/ProductTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/ProductTest.php
@@ -11,7 +11,7 @@ class ProductTest extends AllSetupTeardown
*/
public function testPRODUCT($expectedResult, ...$args): void
{
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$row = 0;
foreach ($args as $arg) {
++$row;
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/QuotientTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/QuotientTest.php
index c8cd13b7..f5bced1e 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/QuotientTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/QuotientTest.php
@@ -14,7 +14,7 @@ class QuotientTest extends AllSetupTeardown
public function testQUOTIENT($expectedResult, $arg1 = 'omitted', $arg2 = 'omitted'): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
if ($arg1 !== null) {
$sheet->getCell('A1')->setValue($arg1);
}
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/RadiansTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/RadiansTest.php
index 03cceaac..82df95f4 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/RadiansTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/RadiansTest.php
@@ -12,7 +12,7 @@ class RadiansTest extends AllSetupTeardown
*/
public function testRADIANS($expectedResult, $number = 'omitted'): void
{
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$this->mightHaveException($expectedResult);
$this->setCell('A1', $number);
if ($number === 'omitted') {
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/RandBetweenTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/RandBetweenTest.php
index 2e1ba676..54d2c8d4 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/RandBetweenTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/RandBetweenTest.php
@@ -14,7 +14,7 @@ class RandBetweenTest extends AllSetupTeardown
public function testRANDBETWEEN($expectedResult, $min = 'omitted', $max = 'omitted'): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$lower = (int) $min;
$upper = (int) $max;
if ($min !== null) {
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/RandTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/RandTest.php
index e5e2e107..989c4883 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/RandTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/RandTest.php
@@ -6,7 +6,7 @@ class RandTest extends AllSetupTeardown
{
public function testRand(): void
{
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->getCell('B1')->setValue('=RAND()');
$result = $sheet->getCell('B1')->getCalculatedValue();
self::assertGreaterThanOrEqual(0, $result);
@@ -16,7 +16,7 @@ class RandTest extends AllSetupTeardown
public function testRandException(): void
{
$this->mightHaveException('exception');
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->getCell('B1')->setValue('=RAND(A1)');
$result = $sheet->getCell('B1')->getCalculatedValue();
self::assertEquals(0, $result);
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/RomanTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/RomanTest.php
index 417656c0..2690c8d2 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/RomanTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/RomanTest.php
@@ -13,7 +13,7 @@ class RomanTest extends AllSetupTeardown
public function testROMAN($expectedResult, $formula): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->setCellValue('A3', 49);
$sheet->getCell('A1')->setValue("=ROMAN($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/RoundDownTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/RoundDownTest.php
index 97058102..7adc8258 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/RoundDownTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/RoundDownTest.php
@@ -13,7 +13,7 @@ class RoundDownTest extends AllSetupTeardown
public function testRoundDown($expectedResult, $formula): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->setCellValue('A2', 1.3);
$sheet->setCellValue('A3', 2.7);
$sheet->setCellValue('A4', -3.8);
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/RoundTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/RoundTest.php
index 960f4740..72f57580 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/RoundTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/RoundTest.php
@@ -13,7 +13,7 @@ class RoundTest extends AllSetupTeardown
public function testRound($expectedResult, $formula): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->setCellValue('A2', 1.3);
$sheet->setCellValue('A3', 2.7);
$sheet->setCellValue('A4', -3.8);
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/RoundUpTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/RoundUpTest.php
index f9ba44e0..b12ddec4 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/RoundUpTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/RoundUpTest.php
@@ -13,7 +13,7 @@ class RoundUpTest extends AllSetupTeardown
public function testRoundUp($expectedResult, $formula): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->setCellValue('A2', 1.3);
$sheet->setCellValue('A3', 2.7);
$sheet->setCellValue('A4', -3.8);
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SecTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SecTest.php
index ad52cee2..395a2fee 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SecTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SecTest.php
@@ -13,7 +13,7 @@ class SecTest extends AllSetupTeardown
public function testSEC($expectedResult, $angle): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->setCellValue('A2', 1.3);
$sheet->setCellValue('A3', 2.7);
$sheet->setCellValue('A4', -3.8);
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SechTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SechTest.php
index 7dabf291..51b5ff6e 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SechTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SechTest.php
@@ -13,7 +13,7 @@ class SechTest extends AllSetupTeardown
public function testSECH($expectedResult, $angle): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->setCellValue('A2', 1.3);
$sheet->setCellValue('A3', 2.7);
$sheet->setCellValue('A4', -3.8);
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SeriesSumTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SeriesSumTest.php
index 9070f60b..df7bb213 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SeriesSumTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SeriesSumTest.php
@@ -16,7 +16,7 @@ class SeriesSumTest extends AllSetupTeardown
*/
public function testSERIESSUM($expectedResult, $arg1, $arg2, $arg3, ...$args): void
{
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
if ($arg1 !== null) {
$sheet->getCell('C1')->setValue($arg1);
}
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SignTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SignTest.php
index fd1a3e6c..d5f65f4a 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SignTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SignTest.php
@@ -13,7 +13,7 @@ class SignTest extends AllSetupTeardown
public function testSIGN($expectedResult, $value): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->setCellValue('A2', 1.3);
$sheet->setCellValue('A3', 0);
$sheet->setCellValue('A4', -3.8);
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SinTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SinTest.php
index c2d0afe5..24f6ea78 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SinTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SinTest.php
@@ -12,7 +12,7 @@ class SinTest extends AllSetupTeardown
public function testSin($expectedResult, string $formula): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->setCellValue('A2', 2);
$sheet->getCell('A1')->setValue("=SIN($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SinhTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SinhTest.php
index bb680f08..d25560f5 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SinhTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SinhTest.php
@@ -12,7 +12,7 @@ class SinhTest extends AllSetupTeardown
public function testSinh($expectedResult, string $formula): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->setCellValue('A2', 2);
$sheet->getCell('A1')->setValue("=SINH($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SqrtPiTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SqrtPiTest.php
index 1a879056..8dd66f5f 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SqrtPiTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SqrtPiTest.php
@@ -13,7 +13,7 @@ class SqrtPiTest extends AllSetupTeardown
public function testSQRTPI($expectedResult, $number): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
if ($number !== null) {
$sheet->getCell('A1')->setValue($number);
}
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SqrtTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SqrtTest.php
index 8ce557bd..733de874 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SqrtTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SqrtTest.php
@@ -12,7 +12,7 @@ class SqrtTest extends AllSetupTeardown
*/
public function testSQRT($expectedResult, $number = 'omitted'): void
{
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$this->mightHaveException($expectedResult);
$this->setCell('A1', $number);
if ($number === 'omitted') {
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SubTotalTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SubTotalTest.php
index fde1d16e..2a54e459 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SubTotalTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SubTotalTest.php
@@ -13,7 +13,7 @@ class SubTotalTest extends AllSetupTeardown
public function testSubtotal($expectedResult, $type): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->fromArray([[0], [1], [1], [2], [3], [5], [8], [13], [21], [34], [55], [89]], null, 'A1', true);
$maxCol = $sheet->getHighestColumn();
$maxRow = $sheet->getHighestRow();
@@ -37,7 +37,7 @@ class SubTotalTest extends AllSetupTeardown
{
// Hidden columns don't affect calculation, only hidden rows
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->fromArray([0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89], null, 'A1', true);
$maxCol = $sheet->getHighestColumn();
$maxRow = $sheet->getHighestRow();
@@ -56,7 +56,8 @@ class SubTotalTest extends AllSetupTeardown
'L' => false,
];
foreach ($hiddenColumns as $col => $hidden) {
- $sheet->getColumnDimension($col)->setVisible($hidden);
+ $columnDimension = $sheet->getColumnDimension($col);
+ $columnDimension->setVisible($hidden);
}
$sheet->getCell('D2')->setValue("=SUBTOTAL($type, A1:$maxCol$maxRow)");
$result = $sheet->getCell('D2')->getCalculatedValue();
@@ -72,7 +73,7 @@ class SubTotalTest extends AllSetupTeardown
public function testSubtotalRowHidden($expectedResult, $type): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->fromArray([[0], [1], [1], [2], [3], [5], [8], [13], [21], [34], [55], [89]], null, 'A1', true);
$maxCol = $sheet->getHighestColumn();
$maxRow = $sheet->getHighestRow();
@@ -91,7 +92,8 @@ class SubTotalTest extends AllSetupTeardown
'12' => false,
];
foreach ($visibleRows as $row => $visible) {
- $sheet->getRowDimension($row)->setVisible($visible);
+ $rowDimension = $sheet->getRowDimension($row);
+ $rowDimension->setVisible($visible);
}
$sheet->getCell('D2')->setValue("=SUBTOTAL($type, A1:$maxCol$maxRow)");
$result = $sheet->getCell('D2')->getCalculatedValue();
@@ -105,7 +107,7 @@ class SubTotalTest extends AllSetupTeardown
public function testSubtotalNested(): void
{
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->fromArray(
[
[123],
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SumIfTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SumIfTest.php
index ad560423..39ac9a66 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SumIfTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SumIfTest.php
@@ -16,7 +16,7 @@ class SumIfTest extends AllSetupTeardown
if ($expectedResult === 'incomplete') {
self::markTestIncomplete('Raises formula error - researching solution');
}
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->fromArray($array1, null, 'A1', true);
$maxARow = count($array1);
$firstArg = "A1:A$maxARow";
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SumProductTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SumProductTest.php
index b2cdb379..9bc197f7 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SumProductTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SumProductTest.php
@@ -13,7 +13,7 @@ class SumProductTest extends AllSetupTeardown
*/
public function testSUMPRODUCT($expectedResult, ...$args): void
{
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$row = 0;
$arrayArg = '';
foreach ($args as $arr) {
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SumSqTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SumSqTest.php
index 162c578a..4de3f551 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SumSqTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SumSqTest.php
@@ -14,7 +14,7 @@ class SumSqTest extends AllSetupTeardown
$this->mightHaveException($expectedResult);
$maxRow = 0;
$funcArg = '';
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
foreach ($args as $arg) {
++$maxRow;
$funcArg = "A1:A$maxRow";
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SumTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SumTest.php
index a9ea7f29..3f80b8ec 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SumTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SumTest.php
@@ -11,7 +11,7 @@ class SumTest extends AllSetupTeardown
*/
public function testSUM($expectedResult, ...$args): void
{
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$row = 0;
foreach ($args as $arg) {
++$row;
@@ -26,4 +26,22 @@ class SumTest extends AllSetupTeardown
{
return require 'tests/data/Calculation/MathTrig/SUM.php';
}
+
+ /**
+ * @dataProvider providerSUMLiterals
+ *
+ * @param mixed $expectedResult
+ */
+ public function testSUMLiterals($expectedResult, string $args): void
+ {
+ $sheet = $this->getSheet();
+ $sheet->getCell('B1')->setValue("=SUM($args)");
+ $result = $sheet->getCell('B1')->getCalculatedValue();
+ self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
+ }
+
+ public function providerSUMLiterals(): array
+ {
+ return require 'tests/data/Calculation/MathTrig/SUMLITERALS.php';
+ }
}
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SumX2MY2Test.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SumX2MY2Test.php
index 427e5c85..3fbe79bf 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SumX2MY2Test.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SumX2MY2Test.php
@@ -14,7 +14,7 @@ class SumX2MY2Test extends AllSetupTeardown
public function testSUMX2MY2($expectedResult, array $matrixData1, array $matrixData2): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$maxRow = 0;
$funcArg1 = '';
foreach (Functions::flattenArray($matrixData1) as $arg) {
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SumX2PY2Test.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SumX2PY2Test.php
index 100b8566..f3ba1826 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SumX2PY2Test.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SumX2PY2Test.php
@@ -14,7 +14,7 @@ class SumX2PY2Test extends AllSetupTeardown
public function testSUMX2PY2($expectedResult, array $matrixData1, array $matrixData2): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$maxRow = 0;
$funcArg1 = '';
foreach (Functions::flattenArray($matrixData1) as $arg) {
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SumXMY2Test.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SumXMY2Test.php
index 43acd4a0..8291d34c 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SumXMY2Test.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SumXMY2Test.php
@@ -14,7 +14,7 @@ class SumXMY2Test extends AllSetupTeardown
public function testSUMXMY2($expectedResult, array $matrixData1, array $matrixData2): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$maxRow = 0;
$funcArg1 = '';
foreach (Functions::flattenArray($matrixData1) as $arg) {
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/TanTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/TanTest.php
index 80dd7eff..c34a756c 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/TanTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/TanTest.php
@@ -12,7 +12,7 @@ class TanTest extends AllSetupTeardown
public function testTan($expectedResult, string $formula): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->setCellValue('A2', 1);
$sheet->getCell('A1')->setValue("=TAN($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/TanhTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/TanhTest.php
index 9a55e9b4..d9d2741a 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/TanhTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/TanhTest.php
@@ -12,7 +12,7 @@ class TanhTest extends AllSetupTeardown
public function testTanh($expectedResult, string $formula): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->setCellValue('A2', 1);
$sheet->getCell('A1')->setValue("=TANH($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/TruncTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/TruncTest.php
index 7d7a4b55..0430d4c0 100644
--- a/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/TruncTest.php
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/TruncTest.php
@@ -13,7 +13,7 @@ class TruncTest extends AllSetupTeardown
public function testTRUNC($expectedResult, $formula): void
{
$this->mightHaveException($expectedResult);
- $sheet = $this->sheet;
+ $sheet = $this->getSheet();
$sheet->setCellValue('A2', 1.3);
$sheet->setCellValue('A3', 2.7);
$sheet->setCellValue('A4', -3.8);
diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/DevSqTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/DevSqTest.php
new file mode 100644
index 00000000..2db29300
--- /dev/null
+++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/DevSqTest.php
@@ -0,0 +1,31 @@
+getMockBuilder(Worksheet::class)
->disableOriginalConstructor()
->getMock();
+ $remoteSheet->method('cellExists')
+ ->willReturn(true);
$remoteSheet->method('getCell')
->willReturn($remoteCell);
@@ -53,6 +55,8 @@ class LookupRefTest extends TestCase
$sheet = $this->getMockBuilder(Worksheet::class)
->disableOriginalConstructor()
->getMock();
+ $sheet->method('cellExists')
+ ->willReturn(true);
$sheet->method('getCell')
->willReturn($remoteCell);
$sheet->method('getParent')
diff --git a/tests/PhpSpreadsheetTests/Calculation/RowColumnReferenceTest.php b/tests/PhpSpreadsheetTests/Calculation/RowColumnReferenceTest.php
new file mode 100644
index 00000000..8c9d23f7
--- /dev/null
+++ b/tests/PhpSpreadsheetTests/Calculation/RowColumnReferenceTest.php
@@ -0,0 +1,84 @@
+spreadSheet = new Spreadsheet();
+
+ $dataSheet = new Worksheet($this->spreadSheet, 'data sheet');
+ $this->spreadSheet->addSheet($dataSheet, 0);
+ $dataSheet->setCellValue('B1', 1.1);
+ $dataSheet->setCellValue('B2', 2.2);
+ $dataSheet->setCellValue('B3', 4.4);
+ $dataSheet->setCellValue('C3', 8.8);
+ $dataSheet->setCellValue('D3', 16.16);
+
+ $calcSheet = new Worksheet($this->spreadSheet, 'summary sheet');
+ $this->spreadSheet->addSheet($calcSheet, 1);
+ $calcSheet->setCellValue('B1', 2.2);
+ $calcSheet->setCellValue('B2', 4.4);
+ $calcSheet->setCellValue('B3', 8.8);
+ $calcSheet->setCellValue('C3', 16.16);
+ $calcSheet->setCellValue('D3', 32.32);
+
+ $this->spreadSheet->setActiveSheetIndexByName('summary sheet');
+ }
+
+ /**
+ * @dataProvider providerCurrentWorksheetFormulae
+ */
+ public function testCurrentWorksheet(string $formula, float $expectedResult): void
+ {
+ $worksheet = $this->spreadSheet->getActiveSheet();
+
+ $worksheet->setCellValue('A1', $formula);
+
+ $result = $worksheet->getCell('A1')->getCalculatedValue();
+ self::assertSame($expectedResult, $result);
+ }
+
+ public function providerCurrentWorksheetFormulae(): array
+ {
+ return [
+ 'relative range in active worksheet' => ['=SUM(B1:B3)', 15.4],
+ 'range with absolute columns in active worksheet' => ['=SUM($B1:$B3)', 15.4],
+ 'range with absolute rows in active worksheet' => ['=SUM(B$1:B$3)', 15.4],
+ 'range with absolute columns and rows in active worksheet' => ['=SUM($B$1:$B$3)', 15.4],
+ 'another relative range in active worksheet' => ['=SUM(B3:D3)', 57.28],
+ 'relative column range in active worksheet' => ['=SUM(B:B)', 15.4],
+ 'absolute column range in active worksheet' => ['=SUM($B:$B)', 15.4],
+ 'relative row range in active worksheet' => ['=SUM(3:3)', 57.28],
+ 'absolute row range in active worksheet' => ['=SUM($3:$3)', 57.28],
+ 'relative range in specified active worksheet' => ['=SUM(\'summary sheet\'!B1:B3)', 15.4],
+ 'range with absolute columns in specified active worksheet' => ['=SUM(\'summary sheet\'!$B1:$B3)', 15.4],
+ 'range with absolute rows in specified active worksheet' => ['=SUM(\'summary sheet\'!B$1:B$3)', 15.4],
+ 'range with absolute columns and rows in specified active worksheet' => ['=SUM(\'summary sheet\'!$B$1:$B$3)', 15.4],
+ 'another relative range in specified active worksheet' => ['=SUM(\'summary sheet\'!B3:D3)', 57.28],
+ 'relative column range in specified active worksheet' => ['=SUM(\'summary sheet\'!B:B)', 15.4],
+ 'absolute column range in specified active worksheet' => ['=SUM(\'summary sheet\'!$B:$B)', 15.4],
+ 'relative row range in specified active worksheet' => ['=SUM(\'summary sheet\'!3:3)', 57.28],
+ 'absolute row range in specified active worksheet' => ['=SUM(\'summary sheet\'!$3:$3)', 57.28],
+ 'relative range in specified other worksheet' => ['=SUM(\'data sheet\'!B1:B3)', 7.7],
+ 'range with absolute columns in specified other worksheet' => ['=SUM(\'data sheet\'!$B1:$B3)', 7.7],
+ 'range with absolute rows in specified other worksheet' => ['=SUM(\'data sheet\'!B$1:B$3)', 7.7],
+ 'range with absolute columns and rows in specified other worksheet' => ['=SUM(\'data sheet\'!$B$1:$B$3)', 7.7],
+ 'another relative range in specified other worksheet' => ['=SUM(\'data sheet\'!B3:D3)', 29.36],
+ 'relative column range in specified other worksheet' => ['=SUM(\'data sheet\'!B:B)', 7.7],
+ 'absolute column range in specified other worksheet' => ['=SUM(\'data sheet\'!$B:$B)', 7.7],
+ 'relative row range in specified other worksheet' => ['=SUM(\'data sheet\'!3:3)', 29.36],
+ 'absolute row range in specified other worksheet' => ['=SUM(\'data sheet\'!$3:$3)', 29.36],
+ ];
+ }
+}
diff --git a/tests/PhpSpreadsheetTests/Functional/ColumnWidthTest.php b/tests/PhpSpreadsheetTests/Functional/ColumnWidthTest.php
index 38117059..41122885 100644
--- a/tests/PhpSpreadsheetTests/Functional/ColumnWidthTest.php
+++ b/tests/PhpSpreadsheetTests/Functional/ColumnWidthTest.php
@@ -3,6 +3,7 @@
namespace PhpOffice\PhpSpreadsheetTests\Functional;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
+use PhpOffice\PhpSpreadsheet\Worksheet\ColumnDimension;
class ColumnWidthTest extends AbstractFunctional
{
@@ -36,6 +37,7 @@ class ColumnWidthTest extends AbstractFunctional
self::assertArrayHasKey('A', $columnDimensions);
$column = array_shift($columnDimensions);
+ self::assertInstanceOf(ColumnDimension::class, $column);
self::assertEquals(20, $column->getWidth());
}
}
diff --git a/tests/PhpSpreadsheetTests/Reader/Gnumeric/AutoFilterTest.php b/tests/PhpSpreadsheetTests/Reader/Gnumeric/AutoFilterTest.php
new file mode 100644
index 00000000..18dde473
--- /dev/null
+++ b/tests/PhpSpreadsheetTests/Reader/Gnumeric/AutoFilterTest.php
@@ -0,0 +1,31 @@
+spreadsheet = $reader->load($filename);
+ }
+
+ public function testAutoFilterRange(): void
+ {
+ $worksheet = $this->spreadsheet->getActiveSheet();
+
+ $autoFilterRange = $worksheet->getAutoFilter()->getRange();
+
+ self::assertSame('A1:D57', $autoFilterRange);
+ }
+}
diff --git a/tests/PhpSpreadsheetTests/Reader/Gnumeric/GnumericLoadTest.php b/tests/PhpSpreadsheetTests/Reader/Gnumeric/GnumericLoadTest.php
index e24178e5..9544fc3a 100644
--- a/tests/PhpSpreadsheetTests/Reader/Gnumeric/GnumericLoadTest.php
+++ b/tests/PhpSpreadsheetTests/Reader/Gnumeric/GnumericLoadTest.php
@@ -115,7 +115,8 @@ class GnumericLoadTest extends TestCase
self::assertEquals(Font::UNDERLINE_DOUBLE, $sheet->getCell('A24')->getStyle()->getFont()->getUnderline());
self::assertTrue($sheet->getCell('B23')->getStyle()->getFont()->getSubScript());
self::assertTrue($sheet->getCell('B24')->getStyle()->getFont()->getSuperScript());
- self::assertFalse($sheet->getRowDimension(30)->getVisible());
+ $rowDimension = $sheet->getRowDimension(30);
+ self::assertFalse($rowDimension->getVisible());
}
public function testLoadFilter(): void
diff --git a/tests/PhpSpreadsheetTests/Reader/Html/Issue2029Test.php b/tests/PhpSpreadsheetTests/Reader/Html/Issue2029Test.php
new file mode 100644
index 00000000..08cdbc25
--- /dev/null
+++ b/tests/PhpSpreadsheetTests/Reader/Html/Issue2029Test.php
@@ -0,0 +1,115 @@
+
+
+
+
+ Declaracion en Linea
+
+
+
+
+
+
+
+
+
+
+
+ | CUIT: |
+ |
+
+
+ | Período |
+ |
+
+
+ | Secuencia: |
+ |
+
+
+ | Contribuyente: |
+ |
+ |
+
+
+
+ |
+
+
+ |
+
+
+
+
+ |
+ CUIL
+ |
+
+ Apellido y Nombre
+ |
+
+ Obra Social
+ |
+
+ Corresponde Reducción?
+ |
+
+
+
+ |
+ 12345678901
+ |
+
+ EMILIANO ZAPATA SALAZAR
+ |
+
+ 101208
+ |
+
+ Yes
+ |
+
+
+
+ |
+ 23456789012
+ |
+
+ FRANCISCO PANCHO VILLA
+ |
+
+ 101208
+ |
+
+ No
+ |
+
+
+
+
+
+EOF;
+ $reader = new Html();
+ $spreadsheet = $reader->loadFromString($content);
+ $sheet = $spreadsheet->getActiveSheet();
+ self::assertSame('CUIT:', $sheet->getCell('A1')->getValue());
+ self::assertSame('30-53914190-9', $sheet->getCell('B1')->getValue());
+ self::assertSame('Contribuyente:', $sheet->getCell('A4')->getValue());
+ self::assertSame('Apellido y Nombre', $sheet->getCell('B9')->getValue());
+ self::assertEquals('101208', $sheet->getCell('C10')->getValue());
+ self::assertEquals('Yes', $sheet->getCell('D10')->getValue());
+ self::assertEquals('23456789012', $sheet->getCell('A11')->getValue());
+ self::assertEquals('No', $sheet->getCell('D11')->getValue());
+ }
+}
diff --git a/tests/PhpSpreadsheetTests/Reader/Ods/AutoFilterTest.php b/tests/PhpSpreadsheetTests/Reader/Ods/AutoFilterTest.php
new file mode 100644
index 00000000..47c7ee6a
--- /dev/null
+++ b/tests/PhpSpreadsheetTests/Reader/Ods/AutoFilterTest.php
@@ -0,0 +1,31 @@
+spreadsheet = $reader->load($filename);
+ }
+
+ public function testAutoFilterRange(): void
+ {
+ $worksheet = $this->spreadsheet->getActiveSheet();
+
+ $autoFilterRange = $worksheet->getAutoFilter()->getRange();
+
+ self::assertSame('A1:C9', $autoFilterRange);
+ }
+}
diff --git a/tests/PhpSpreadsheetTests/Reader/Ods/DefinedNamesTest.php b/tests/PhpSpreadsheetTests/Reader/Ods/DefinedNamesTest.php
new file mode 100644
index 00000000..760421ce
--- /dev/null
+++ b/tests/PhpSpreadsheetTests/Reader/Ods/DefinedNamesTest.php
@@ -0,0 +1,35 @@
+spreadsheet = $reader->load($filename);
+ }
+
+ public function testDefinedNames(): void
+ {
+ $worksheet = $this->spreadsheet->getActiveSheet();
+
+ $firstDefinedNameValue = $worksheet->getCell('First')->getValue();
+ $secondDefinedNameValue = $worksheet->getCell('Second')->getValue();
+ $calculatedFormulaValue = $worksheet->getCell('B2')->getCalculatedValue();
+
+ self::assertSame(3, $firstDefinedNameValue);
+ self::assertSame(4, $secondDefinedNameValue);
+ self::assertSame(12, $calculatedFormulaValue);
+ }
+}
diff --git a/tests/PhpSpreadsheetTests/Reader/Xlsx/ConditionalTest.php b/tests/PhpSpreadsheetTests/Reader/Xlsx/ConditionalTest.php
new file mode 100644
index 00000000..8108d988
--- /dev/null
+++ b/tests/PhpSpreadsheetTests/Reader/Xlsx/ConditionalTest.php
@@ -0,0 +1,30 @@
+load($filename);
+ $worksheet = $spreadsheet->getActiveSheet();
+ $styles = $worksheet->getConditionalStyles('A1:A5');
+
+ self::assertCount(1, $styles);
+
+ /** @var Conditional $notContainsTextStyle */
+ $notContainsTextStyle = $styles[0];
+ self::assertEquals('A', $notContainsTextStyle->getText());
+ self::assertEquals(Conditional::CONDITION_NOTCONTAINSTEXT, $notContainsTextStyle->getConditionType());
+ self::assertEquals(Conditional::OPERATOR_NOTCONTAINS, $notContainsTextStyle->getOperatorType());
+ }
+}
diff --git a/tests/PhpSpreadsheetTests/Reader/Xlsx/DefaultFillTest.php b/tests/PhpSpreadsheetTests/Reader/Xlsx/DefaultFillTest.php
index 88d666b2..dc61b953 100644
--- a/tests/PhpSpreadsheetTests/Reader/Xlsx/DefaultFillTest.php
+++ b/tests/PhpSpreadsheetTests/Reader/Xlsx/DefaultFillTest.php
@@ -1,6 +1,6 @@
getCell('J16')->getStyle()->getFill()->getFillType());
self::assertSame('solid', $sheet->getCell('C2')->getStyle()->getFill()->getFillType());
}
+
+ public function testDefaultConditionalFill(): void
+ {
+ // default fill pattern for a conditional style where the filltype is not defined
+ $filename = 'tests/data/Reader/XLSX/pr2050cf-fill.xlsx';
+ $reader = IOFactory::createReader('Xlsx');
+ $spreadsheet = $reader->load($filename);
+
+ $style = $spreadsheet->getActiveSheet()->getConditionalStyles('A1')[0]->getStyle();
+ self::assertSame('solid', $style->getFill()->getFillType());
+ }
}
diff --git a/tests/PhpSpreadsheetTests/Reader/Xlsx/DefaultFontTest.php b/tests/PhpSpreadsheetTests/Reader/Xlsx/DefaultFontTest.php
new file mode 100644
index 00000000..a4e94804
--- /dev/null
+++ b/tests/PhpSpreadsheetTests/Reader/Xlsx/DefaultFontTest.php
@@ -0,0 +1,22 @@
+load($filename);
+
+ $style = $spreadsheet->getActiveSheet()->getConditionalStyles('A1')[0]->getStyle();
+ self::assertSame('9C0006', $style->getFont()->getColor()->getRGB());
+ self::assertNull($style->getFont()->getName());
+ self::assertNull($style->getFont()->getSize());
+ }
+}
diff --git a/tests/PhpSpreadsheetTests/Writer/Csv/CsvExcelCompatibilityTest.php b/tests/PhpSpreadsheetTests/Writer/Csv/CsvExcelCompatibilityTest.php
new file mode 100644
index 00000000..9b7d16aa
--- /dev/null
+++ b/tests/PhpSpreadsheetTests/Writer/Csv/CsvExcelCompatibilityTest.php
@@ -0,0 +1,49 @@
+getActiveSheet();
+ $sheet->setCellValue('A1', '1');
+ $sheet->setCellValue('B1', '2');
+ $sheet->setCellValue('C1', '3');
+ $sheet->setCellValue('A2', '4');
+ $sheet->setCellValue('B2', '5');
+ $sheet->setCellValue('C2', '6');
+ $writer = new CsvWriter($spreadsheet);
+ $writer->setExcelCompatibility(true);
+ self::assertSame('', $writer->getOutputEncoding());
+ $filename = File::temporaryFilename();
+ $writer->save($filename);
+ $reader = new CsvReader();
+ $spreadsheet2 = $reader->load($filename);
+ $contents = file_get_contents($filename);
+ unlink($filename);
+ self::assertEquals(1, $spreadsheet2->getActiveSheet()->getCell('A1')->getValue());
+ self::assertEquals(6, $spreadsheet2->getActiveSheet()->getCell('C2')->getValue());
+ self::assertStringContainsString(CsvReader::UTF8_BOM, $contents);
+ self::assertStringContainsString("\r\n", $contents);
+ self::assertStringContainsString('sep=;', $contents);
+ self::assertStringContainsString('"1";"2";"3"', $contents);
+ self::assertStringContainsString('"4";"5";"6"', $contents);
+ }
+}
diff --git a/tests/PhpSpreadsheetTests/Writer/Ods/AutoFilterTest.php b/tests/PhpSpreadsheetTests/Writer/Ods/AutoFilterTest.php
new file mode 100644
index 00000000..4368ef76
--- /dev/null
+++ b/tests/PhpSpreadsheetTests/Writer/Ods/AutoFilterTest.php
@@ -0,0 +1,33 @@
+getActiveSheet();
+
+ $dataSet = [
+ ['Year', 'Quarter', 'Sales'],
+ [2020, 'Q1', 100],
+ [2020, 'Q2', 120],
+ [2020, 'Q3', 140],
+ [2020, 'Q4', 160],
+ [2021, 'Q1', 180],
+ [2021, 'Q2', 75],
+ [2021, 'Q3', 0],
+ [2021, 'Q4', 0],
+ ];
+ $worksheet->fromArray($dataSet, null, 'A1');
+ $worksheet->getAutoFilter()->setRange('A1:C9');
+
+ $reloaded = $this->writeAndReload($spreadsheet, 'Ods');
+
+ self::assertSame('A1:C9', $reloaded->getActiveSheet()->getAutoFilter()->getRange());
+ }
+}
diff --git a/tests/PhpSpreadsheetTests/Writer/Ods/DefinedNamesTest.php b/tests/PhpSpreadsheetTests/Writer/Ods/DefinedNamesTest.php
new file mode 100644
index 00000000..1b2e30b2
--- /dev/null
+++ b/tests/PhpSpreadsheetTests/Writer/Ods/DefinedNamesTest.php
@@ -0,0 +1,33 @@
+getActiveSheet();
+
+ $dataSet = [
+ [7, 'x', 5],
+ ['=', '=FORMULA'],
+ ];
+ $worksheet->fromArray($dataSet, null, 'A1');
+
+ $spreadsheet->addDefinedName(new NamedRange('FIRST', $worksheet, '$A$1'));
+ $spreadsheet->addDefinedName(new NamedRange('SECOND', $worksheet, '$C$1'));
+ $spreadsheet->addDefinedName(new NamedFormula('FORMULA', $worksheet, '=FIRST*SECOND'));
+
+ $reloaded = $this->writeAndReload($spreadsheet, 'Ods');
+
+ self::assertSame(7, $reloaded->getActiveSheet()->getCell('FIRST')->getValue());
+ self::assertSame(5, $reloaded->getActiveSheet()->getCell('SECOND')->getValue());
+ self::assertSame(35, $reloaded->getActiveSheet()->getCell('B2')->getCalculatedValue());
+ }
+}
diff --git a/tests/PhpSpreadsheetTests/Writer/Xls/VisibilityTest.php b/tests/PhpSpreadsheetTests/Writer/Xls/VisibilityTest.php
new file mode 100644
index 00000000..7de39328
--- /dev/null
+++ b/tests/PhpSpreadsheetTests/Writer/Xls/VisibilityTest.php
@@ -0,0 +1,99 @@
+getActiveSheet();
+ foreach ($visibleRows as $row => $visibility) {
+ $worksheet->setCellValue("A{$row}", $row);
+ $worksheet->getRowDimension($row)->setVisible($visibility);
+ }
+
+ $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xls');
+ $reloadedWorksheet = $reloadedSpreadsheet->getActiveSheet();
+ foreach ($visibleRows as $row => $visibility) {
+ self::assertSame($visibility, $reloadedWorksheet->getRowDimension($row)->getVisible());
+ }
+ }
+
+ public function dataProviderRowVisibility(): array
+ {
+ return [
+ [
+ [1 => true, 2 => false, 3 => false, 4 => true, 5 => true, 6 => false],
+ ],
+ ];
+ }
+
+ /**
+ * @dataProvider dataProviderColumnVisibility
+ */
+ public function testColumnVisibility(array $visibleColumns): void
+ {
+ $spreadsheet = new Spreadsheet();
+ $worksheet = $spreadsheet->getActiveSheet();
+ foreach ($visibleColumns as $column => $visibility) {
+ $worksheet->setCellValue("{$column}1", $column);
+ $worksheet->getColumnDimension($column)->setVisible($visibility);
+ }
+
+ $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xls');
+ $reloadedWorksheet = $reloadedSpreadsheet->getActiveSheet();
+ foreach ($visibleColumns as $column => $visibility) {
+ self::assertSame($visibility, $reloadedWorksheet->getColumnDimension($column)->getVisible());
+ }
+ }
+
+ public function dataProviderColumnVisibility(): array
+ {
+ return [
+ [
+ ['A' => true, 'B' => false, 'C' => false, 'D' => true, 'E' => true, 'F' => false],
+ ],
+ ];
+ }
+
+ /**
+ * @dataProvider dataProviderSheetVisibility
+ */
+ public function testSheetVisibility(array $visibleSheets): void
+ {
+ $spreadsheet = new Spreadsheet();
+ $spreadsheet->removeSheetByIndex(0);
+ foreach ($visibleSheets as $sheetName => $visibility) {
+ $worksheet = $spreadsheet->addSheet(new Worksheet($spreadsheet, $sheetName));
+ $worksheet->setCellValue('A1', $sheetName);
+ $worksheet->setSheetState($visibility);
+ }
+
+ $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xls');
+ foreach ($visibleSheets as $sheetName => $visibility) {
+ $reloadedWorksheet = $reloadedSpreadsheet->getSheetByName($sheetName) ?? new Worksheet();
+ self::assertSame($visibility, $reloadedWorksheet->getSheetState());
+ }
+ }
+
+ public function dataProviderSheetVisibility(): array
+ {
+ return [
+ [
+ [
+ 'Worksheet 1' => Worksheet::SHEETSTATE_HIDDEN,
+ 'Worksheet 2' => Worksheet::SHEETSTATE_VERYHIDDEN,
+ 'Worksheet 3' => Worksheet::SHEETSTATE_VISIBLE,
+ ],
+ ],
+ ];
+ }
+}
diff --git a/tests/PhpSpreadsheetTests/Writer/Xlsx/ConditionalTest.php b/tests/PhpSpreadsheetTests/Writer/Xlsx/ConditionalTest.php
new file mode 100644
index 00000000..21df6ed6
--- /dev/null
+++ b/tests/PhpSpreadsheetTests/Writer/Xlsx/ConditionalTest.php
@@ -0,0 +1,60 @@
+prevValue = Settings::getLibXmlLoaderOptions();
+
+ // Disable validating XML with the DTD
+ Settings::setLibXmlLoaderOptions($this->prevValue & ~LIBXML_DTDVALID & ~LIBXML_DTDATTR & ~LIBXML_DTDLOAD);
+ }
+
+ protected function tearDown(): void
+ {
+ Settings::setLibXmlLoaderOptions($this->prevValue);
+ }
+
+ /**
+ * Test check if conditional style with type 'notContainsText' works on xlsx.
+ */
+ public function testConditionalNotContainsText(): void
+ {
+ $spreadsheet = new Spreadsheet();
+ $worksheet = $spreadsheet->getActiveSheet();
+
+ $condition = new Conditional();
+ $condition->setConditionType(Conditional::CONDITION_NOTCONTAINSTEXT);
+ $condition->setOperatorType(Conditional::OPERATOR_NOTCONTAINS);
+ $condition->setText('C');
+ $condition->getStyle()->applyFromArray([
+ 'fill' => [
+ 'color' => ['argb' => 'FFFFC000'],
+ 'fillType' => Fill::FILL_SOLID,
+ ],
+ ]);
+ $worksheet->setConditionalStyles('A1:A5', [$condition]);
+
+ $writer = new Xlsx($spreadsheet);
+ $writerWorksheet = new Xlsx\Worksheet($writer);
+ $data = $writerWorksheet->writeWorksheet($worksheet, []);
+ $needle = <<ISERROR(SEARCH("C",A1:A5))
+xml;
+ self::assertStringContainsString($needle, $data);
+ }
+}
diff --git a/tests/PhpSpreadsheetTests/Writer/Xlsx/Issue2082Test.php b/tests/PhpSpreadsheetTests/Writer/Xlsx/Issue2082Test.php
new file mode 100644
index 00000000..1f72a382
--- /dev/null
+++ b/tests/PhpSpreadsheetTests/Writer/Xlsx/Issue2082Test.php
@@ -0,0 +1,40 @@
+getActiveSheet();
+ $worksheet->fromArray(['A', 'B', 'C', 'D']);
+ $worksheet->getCell('A2')->setValue('=A1<>"A"');
+ $worksheet->getCell('A3')->setValue('=A1="A"');
+ $worksheet->getCell('B2')->setValue('=LEFT(B1, 0)');
+ $worksheet->getCell('B3')->setValue('=B2=""');
+
+ $writer = new Writer($spreadsheet);
+ $writer->save($outputFilename);
+ $zipfile = "zip://$outputFilename#xl/worksheets/sheet1.xml";
+ $contents = file_get_contents($zipfile);
+ unlink($outputFilename);
+ if ($contents === false) {
+ self::fail('Unable to open file');
+ } else {
+ self::assertStringContainsString('A1<>"A"0', $contents);
+ self::assertStringContainsString('A1="A"1', $contents);
+ self::assertStringContainsString('LEFT(B1, 0)', $contents);
+ self::assertStringContainsString('B2=""1', $contents);
+ }
+ }
+}
diff --git a/tests/PhpSpreadsheetTests/Writer/Xlsx/VisibilityTest.php b/tests/PhpSpreadsheetTests/Writer/Xlsx/VisibilityTest.php
new file mode 100644
index 00000000..7e1ca967
--- /dev/null
+++ b/tests/PhpSpreadsheetTests/Writer/Xlsx/VisibilityTest.php
@@ -0,0 +1,99 @@
+getActiveSheet();
+ foreach ($visibleRows as $row => $visibility) {
+ $worksheet->setCellValue("A{$row}", $row);
+ $worksheet->getRowDimension($row)->setVisible($visibility);
+ }
+
+ $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx');
+ $reloadedWorksheet = $reloadedSpreadsheet->getActiveSheet();
+ foreach ($visibleRows as $row => $visibility) {
+ self::assertSame($visibility, $reloadedWorksheet->getRowDimension($row)->getVisible());
+ }
+ }
+
+ public function dataProviderRowVisibility(): array
+ {
+ return [
+ [
+ [1 => false, 2 => false, 3 => true, 4 => false, 5 => true, 6 => false],
+ ],
+ ];
+ }
+
+ /**
+ * @dataProvider dataProviderColumnVisibility
+ */
+ public function testColumnVisibility(array $visibleColumns): void
+ {
+ $spreadsheet = new Spreadsheet();
+ $worksheet = $spreadsheet->getActiveSheet();
+ foreach ($visibleColumns as $column => $visibility) {
+ $worksheet->setCellValue("{$column}1", $column);
+ $worksheet->getColumnDimension($column)->setVisible($visibility);
+ }
+
+ $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx');
+ $reloadedWorksheet = $reloadedSpreadsheet->getActiveSheet();
+ foreach ($visibleColumns as $column => $visibility) {
+ self::assertSame($visibility, $reloadedWorksheet->getColumnDimension($column)->getVisible());
+ }
+ }
+
+ public function dataProviderColumnVisibility(): array
+ {
+ return [
+ [
+ ['A' => false, 'B' => false, 'C' => true, 'D' => false, 'E' => true, 'F' => false],
+ ],
+ ];
+ }
+
+ /**
+ * @dataProvider dataProviderSheetVisibility
+ */
+ public function testSheetVisibility(array $visibleSheets): void
+ {
+ $spreadsheet = new Spreadsheet();
+ $spreadsheet->removeSheetByIndex(0);
+ foreach ($visibleSheets as $sheetName => $visibility) {
+ $worksheet = $spreadsheet->addSheet(new Worksheet($spreadsheet, $sheetName));
+ $worksheet->setCellValue('A1', $sheetName);
+ $worksheet->setSheetState($visibility);
+ }
+
+ $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx');
+ foreach ($visibleSheets as $sheetName => $visibility) {
+ $reloadedWorksheet = $reloadedSpreadsheet->getSheetByName($sheetName) ?? new Worksheet();
+ self::assertSame($visibility, $reloadedWorksheet->getSheetState());
+ }
+ }
+
+ public function dataProviderSheetVisibility(): array
+ {
+ return [
+ [
+ [
+ 'Worksheet 1' => Worksheet::SHEETSTATE_HIDDEN,
+ 'Worksheet 2' => Worksheet::SHEETSTATE_VERYHIDDEN,
+ 'Worksheet 3' => Worksheet::SHEETSTATE_VISIBLE,
+ ],
+ ],
+ ];
+ }
+}
diff --git a/tests/data/Calculation/LookupRef/CHOOSE.php b/tests/data/Calculation/LookupRef/CHOOSE.php
index 06371c79..96c29780 100644
--- a/tests/data/Calculation/LookupRef/CHOOSE.php
+++ b/tests/data/Calculation/LookupRef/CHOOSE.php
@@ -25,4 +25,12 @@ return [
'#VALUE!',
0, 'red', 'blue', 'green', 'brown',
],
+ [
+ '#VALUE!',
+ 'NaN', 'red', 'blue', 'green', 'brown',
+ ],
+ [
+ ['blue', 'purple'],
+ 3, ['red', 'orange'], ['yellow', 'green'], ['blue', 'purple'],
+ ],
];
diff --git a/tests/data/Calculation/LookupRef/HLOOKUP.php b/tests/data/Calculation/LookupRef/HLOOKUP.php
index d2a8a446..61cb7e06 100644
--- a/tests/data/Calculation/LookupRef/HLOOKUP.php
+++ b/tests/data/Calculation/LookupRef/HLOOKUP.php
@@ -328,4 +328,28 @@ return [
2,
false,
],
+ [
+ 0.61,
+ 'Ed',
+ [
+ [null, 'Ann', 'Cara', 'Colin', 'Ed', 'Frank'],
+ ['Math', 0.58, 0.90, 0.67, 0.76, 0.80],
+ ['French', 0.61, 0.71, 0.59, 0.59, 0.76],
+ ['Physics', 0.75, 0.45, 0.39, 0.52, 0.69],
+ ['Bioogy', 0.39, 0.55, 0.77, 0.61, 0.45],
+ ],
+ 5,
+ false,
+ ],
+ [
+ 'Normal Weight',
+ 23.5,
+ [
+ [null, 'Min', 0.0, 18.5, 25.0, 30.0],
+ ['BMI', 'Max', 18.4, 24.9, 29.9, null],
+ [null, 'Body Type', 'Underweight', 'Normal Weight', 'Overweight', 'Obese'],
+ ],
+ 3,
+ true,
+ ],
];
diff --git a/tests/data/Calculation/LookupRef/HYPERLINK.php b/tests/data/Calculation/LookupRef/HYPERLINK.php
new file mode 100644
index 00000000..9a5e4c2e
--- /dev/null
+++ b/tests/data/Calculation/LookupRef/HYPERLINK.php
@@ -0,0 +1,26 @@
+ ['R' => 1]],
],
- [
+ 'Negative Row' => [
'#VALUE!', // Expected
// Input
[
@@ -15,7 +15,7 @@ return [
],
-1,
],
- [
+ 'Row > matrix rows' => [
'#REF!', // Expected
// Input
[
@@ -24,7 +24,25 @@ return [
],
10,
],
- [
+ 'Row is not a number' => [
+ '#VALUE!', // Expected
+ // Input
+ [
+ 20 => ['R' => 1],
+ 21 => ['R' => 2],
+ ],
+ 'NaN',
+ ],
+ 'Row is Error' => [
+ '#N/A', // Expected
+ // Input
+ [
+ 20 => ['R' => 1],
+ 21 => ['R' => 2],
+ ],
+ '#N/A',
+ ],
+ 'Return row 2' => [
[21 => ['R' => 2]], // Expected
// Input
[
@@ -33,7 +51,7 @@ return [
],
2,
],
- [
+ 'Return row 2 from larger matrix' => [
[21 => ['R' => 2, 'S' => 4]], // Expected
// Input
[
@@ -43,17 +61,17 @@ return [
2,
0,
],
- [
+ 'Negative Column' => [
'#VALUE!', // Expected
// Input
[
'20' => ['R' => 1, 'S' => 3],
'21' => ['R' => 2, 'S' => 4],
],
- 2,
+ 0,
-1,
],
- [
+ 'Column > matrix columns' => [
'#REF!', // Expected
// Input
[
@@ -63,15 +81,25 @@ return [
2,
10,
],
- [
- '#REF!', // Expected
+ 'Column is not a number' => [
+ '#VALUE!', // Expected
// Input
[
- '20' => ['R' => 1, 'S' => 3],
- '21' => ['R' => 2, 'S' => 4],
+ 20 => ['R' => 1],
+ 21 => ['R' => 2],
],
- 10,
- 2,
+ 1,
+ 'NaN',
+ ],
+ 'Column is Error' => [
+ '#N/A', // Expected
+ // Input
+ [
+ 20 => ['R' => 1],
+ 21 => ['R' => 2],
+ ],
+ 1,
+ '#N/A',
],
[
4, // Expected
@@ -115,6 +143,15 @@ return [
2,
1,
],
+ [
+ [1 => ['Bananas', 'Pears']],
+ [
+ ['Apples', 'Lemons'],
+ ['Bananas', 'Pears'],
+ ],
+ 2,
+ 0,
+ ],
[
3,
[
diff --git a/tests/data/Calculation/LookupRef/VLOOKUP.php b/tests/data/Calculation/LookupRef/VLOOKUP.php
index a5d6f615..0a059048 100644
--- a/tests/data/Calculation/LookupRef/VLOOKUP.php
+++ b/tests/data/Calculation/LookupRef/VLOOKUP.php
@@ -349,4 +349,35 @@ return [
],
2.0,
],
+ [
+ 3.50,
+ 'Cornflakes',
+ [
+ ['Item Description', 'Price'],
+ ['Tinned Tomatoes', 0.90],
+ ['Tinned Tuna', 1.50],
+ ['Cornflakes', 3.50],
+ ['Shortcake Biscuits', 1.00],
+ ['Toothpaste', 4.10],
+ ['Tinned Baked Beans', 0.99],
+ ['White Sliced Bread', 0.80],
+ ],
+ 2,
+ false,
+ ],
+ [
+ 'E',
+ 0.52,
+ [
+ ['Lower', 'Upper', 'Grade'],
+ [0.00, 0.44, 'F'],
+ [0.45, 0.54, 'E'],
+ [0.55, 0.64, 'D'],
+ [0.65, 0.74, 'C'],
+ [0.75, 0.84, 'B'],
+ [0.85, 1.00, 'A'],
+ ],
+ 3,
+ true,
+ ],
];
diff --git a/tests/data/Calculation/MathTrig/SUM.php b/tests/data/Calculation/MathTrig/SUM.php
index a8219076..0c54613e 100644
--- a/tests/data/Calculation/MathTrig/SUM.php
+++ b/tests/data/Calculation/MathTrig/SUM.php
@@ -4,5 +4,9 @@ return [
[50, 5, 15, 30],
[52, 5, 15, 30, 2],
[53.1, 5.7, 15, 30, 2.4],
- ['#VALUE!', 5.7, 'X', 30, 2.4], // error here conflicts with SUMIF
+ [52.1, 5.7, '14', 30, 2.4],
+ [38.1, 5.7, 'X', 30, 2.4], // error if entered in formula, but not in cell
+ [38.1, 5.7, null, 30, 2.4],
+ [38.1, 5.7, false, 30, 2.4],
+ [39.1, 5.7, true, 30, 2.4],
];
diff --git a/tests/data/Calculation/MathTrig/SUMLITERALS.php b/tests/data/Calculation/MathTrig/SUMLITERALS.php
new file mode 100644
index 00000000..fd184ebd
--- /dev/null
+++ b/tests/data/Calculation/MathTrig/SUMLITERALS.php
@@ -0,0 +1,12 @@
+ [
'826.00 €',
826,
- '#,##0.00 _€',
+ '#,##0.00 __€',
],
[
'5.68',
@@ -263,7 +263,7 @@ return [
[
'( 12.30% )',
-0.123,
- '_0.00%_;( 0.00% )',
+ '_(0.00%_;( 0.00% )',
],
// Fraction
[
@@ -374,15 +374,35 @@ return [
'[$-1010409]#,##0.00;-#,##0.00',
],
[
- ' ($ 23.06 )',
+ ' $ 23.06 ',
23.0597,
'_("$"* #,##0.00_);_("$"* \(#,##0.00\);_("$"* "-"??_);_(@_)',
],
[
- ' (€ 13.03 )',
- 13.0316,
+ ' € (13.03)',
+ -13.0316,
'_("€"* #,##0.00_);_("€"* \(#,##0.00\);_("€"* "-"??_);_(@_)',
],
+ [
+ ' € 11.70 ',
+ 11.7,
+ '_-€* #,##0.00_-;"-€"* #,##0.00_-;_-€* -??_-;_-@_-',
+ ],
+ [
+ '-€ 12.14 ',
+ -12.14,
+ '_-€* #,##0.00_-;"-€"* #,##0.00_-;_-€* -??_-;_-@_-',
+ ],
+ [
+ ' € - ',
+ 0,
+ '_-€* #,##0.00_-;"-€"* #,##0.00_-;_-€* -??_-;_-@_-',
+ ],
+ [
+ 'test',
+ 'test',
+ '_-€* #,##0.00_-;"-€"* #,##0.00_-;_-€* -??_-;_-@_-',
+ ],
// Named colours
// Simple color
[