Commit Graph

3211 Commits

Author SHA1 Message Date
Mark Baker b300e186fe
Merge pull request #2582 from PHPOffice/Issue-2551_Array-ready-Functions-Text-Phase-2
Issue 2551 - Array-ready Functions - Text Phase 2
2022-02-12 12:41:59 +01:00
MarkBaker b3ff2e347f All Text functions made array-ready 2022-02-12 12:22:31 +01:00
Mark Baker 6a2905a34c
Merge pull request #2580 from PHPOffice/Issue-2551-Array-Ready-Function-Financial
Issue 2551 - array ready functions - Text (phase #1)
2022-02-11 19:19:03 +01:00
Mark Baker d2473441c3
Merge branch 'master' into Issue-2551-Array-Ready-Function-Financial 2022-02-11 19:07:33 +01:00
MarkBaker c41dd0afae FIND(), SEARCH(), LEFT(), RIGHT, MID(), CLEAN(), TRIM(), TEXTJOIN() and REPT() functions 2022-02-11 18:56:21 +01:00
oleibman ad5532e2f4
Namespacing Phase 2 - Styles (#2471)
* WIP Namespacing Phase 2 - Styles

This is part 2 of a several-phase process to permit PhpSpreadsheet to handle input Xlsx files which use unexpected namespacing. The first phase, introduced as part of release 1.19.0, essentially handled the reading of data. This phase handles the reading of styles. More phases are planned.

It is my intention to leave this in draft status for at least a month. This will give time for additional testing, by me and, I hope, others who might be interested.

This fixes the same problem addressed by PR #2458, if it reaches mergeable status before I am ready to take this out of draft status. I do not anticipate any difficult merge conflicts if the other change is merged first.

This change is more difficult than I'd hoped. I can't get xpath to work properly with the namespaced style file, even though I don't have difficulties with others. Normally we expect:
```xml
<stylesheet xmlns="http://whatever" ...
```
In the namespaced files, we typically see:
```xml
<x:stylesheet xmlns:x="http://whatever" ...
```

Simplexml_load_file specifying a namespace handles the two situations the same, as expected. But, for some reason that I cannot figure out, there are significant differences when xpath processes the result. However, I can manipulate the xml if necessary; I'm not proud of doing that, and will gladly accept any suggestions. In the meantime, it seems to work.

My major non-standard unit test file had disabled any style-related tests when phase 1 was installed. These are now all enabled.

* Scrutinizer

Its analysis is wrong, but the "errors" it pointed out are easy to fix.

* Eliminate XML Source Manipulation

Original solution required XML manipulation to overcome what appears to be an xpath problem. This version replaces xpath with iteration, eliminating the need to manipulate the XML.

* Handle Some Edge Cases

For example, Style file without a Fills section.

* Restore RGB/ARGB Interchangeability

Fix #2494. Apparently EPPlus outputs fill colors as `<fgColor rgb="BFBFBF">` while most output fill colors as `<fgColor rgb="FFBFBFBF">`. EPPlus actually makes more sense. Regardless, validating length of rgb/argb is a recent development for PhpSpreadsheet, under the assumption that an incorrect length is a user error. This development invalidates that assumption, so restore the previous behavior.

In addition, a comment in Colors.php says that the supplied color is "the ARGB value for the colour, or named colour". However, although named colors are accepted, nothing sensible is done with them - they are passed unchanged to the ARGB value, where Excel treats them as black. The routine should either reject the named color, or convert it to the appropriate ARGB value. This change implements the latter.
2022-02-11 06:42:04 -08:00
MarkBaker c9886127c0 Style and phpstan cleanups 2022-02-11 13:55:52 +01:00
MarkBaker 8818a7d620 Merge branch 'master' into Issue-2551-Array-Ready-Function-Financial
# Conflicts:
#	phpstan-baseline.neon
#	src/PhpSpreadsheet/Calculation/Financial/Dollar.php
2022-02-11 13:36:35 +01:00
Mark Baker 88da4e17e5
Merge pull request #2579 from PHPOffice/Issue-2578_Negative-dollar-values-for-DOLLARDE()-and-DOLLARFR()-Functions
Fix for DOLLARDE() and DOLLARFR() with negative dollar values
2022-02-11 13:30:43 +01:00
MarkBaker f577dde178 Fix for DOLLARDE() and DOLLARFR() with negative dollar values
Additional argument validations
2022-02-11 13:19:44 +01:00
MarkBaker df12b06c59 Text function array value tests, plus some cleanup 2022-02-11 12:34:29 +01:00
Mark Baker 5ab3cbc8db
Merge pull request #2573 from PHPOffice/Issue-2551_Array-Enabled-DateTime-Functions
Enable most of the Date/Time functions to accept array arguments
2022-02-10 21:32:58 +01:00
MarkBaker dfc19dba58 Regenerate phpstan baseline 2022-02-10 21:08:53 +01:00
MarkBaker b741193184 Refactoring of the processor 2022-02-10 20:53:58 +01:00
MarkBaker 1e59b9113f Last of the work on array-enabling Date/Time functions; all completed in this category 2022-02-10 20:53:58 +01:00
MarkBaker ca81991728 phpcs cleanup 2022-02-10 15:40:30 +01:00
MarkBaker ec2ca1764f The `WORKDAY()` function accepts 2 "static" arguments that could be passed as arrays; but also accepts a set of trailing date arguments that are accepted as an array by the splat operator. Only the first two arguments should be tested for returning array values; but the logic still needs to work with the full argument set.
Provide a separate "subset" method in the `ArrayEnabled` Trait, that allows a subset of arguments to be tested for array returns.

Set up basic tests for `WORKDAY()`
2022-02-10 15:37:45 +01:00
MarkBaker 782644684b Fix error in handling cell reference when operand is a 1-d array 2022-02-10 15:37:45 +01:00
MarkBaker 83ff74b97e Enable most of the Date/Time functions to accept array arguments 2022-02-10 15:37:45 +01:00
Mark Baker 291ea88a6c
Initial work enabling Excel function implementations for handling arrays as arguments when used in "array formulae". (#2562)
* Initial work enabling Excel function implementations for handling arrays as aguments when used in "array formulae".

So far:
 - handling for single argument functions
 - for functions where only one of the arguments is an array (a matrix or a row/column vector)
 - for when there are two array arguments, and one is a row vector, the other a column vector
 - for when there are either 2 row vectors, or 2 column vectors
 - for a matrix and either a row or column vector 

Will work ok, as long as there are no more than two array arguments; still need to identify the logic to apply when there are more than two arrays; or there are two that aren't an already supported row vector/column vector pairing (ie two matrices).

* Throw an exception if we have three or more array arguments (after flattening) passed to a supported function until we can identify the abstruse non-euclidian logic behind how Excel handles building, using and presenting those n-dimensional result arrays

* Implement array arguments for the DATE() function so that we can verify that paired arrays/vectors work with functions that support more than 2 arguments

* Implement array arguments for the many of the Math/Trig functions

* Update change log
2022-02-09 15:12:54 +01:00
Sebastian Nohn 0ff0187f1f
fix most recent changes to the changelog: (#2561)
- fix indentation
- add links to PRs
- put latest changes to the bottom of each section
2022-02-07 09:17:29 -08:00
JRK d0c9ea340e
Fix documentation, instantiation example (#2564) 2022-02-07 17:37:07 +01:00
Mark Baker d0965298d5
Additional unit tests for RANDARRAY() Math/Trig function implementation (#2563) 2022-02-07 10:19:19 +01:00
dependabot[bot] 69fe30a135
Bump phpstan/phpstan from 1.3.0 to 1.4.5 (#2548)
Bumps [phpstan/phpstan](https://github.com/phpstan/phpstan) from 1.3.0 to 1.4.5.
- [Release notes](https://github.com/phpstan/phpstan/releases)
- [Changelog](https://github.com/phpstan/phpstan/blob/master/CHANGELOG.md)
- [Commits](https://github.com/phpstan/phpstan/compare/1.3.0...1.4.5)

---
updated-dependencies:
- dependency-name: phpstan/phpstan
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: oleibman <10341515+oleibman@users.noreply.github.com>
2022-02-05 20:01:52 -08:00
oleibman af8948b558
3 New Phpstan 1.4.5 Changes (#2559)
* 3 New Phpstan 1.4.5 Changes

It requires evidence that second parameter to array_chunk > 0.

* Try to Get Github Going

Everything showed "waiting for status to be reported" after several hours. Let's see if a comment change kicks things off properly.
2022-02-05 19:50:41 -08:00
oleibman 59ae5e20b5
Changes Required For Phpstan 1.4.5 (#2549)
Dependabot pushed Phpstan 1.4.4 and then 1.4.5 (PR #2548). Because of some incompatible error messages between the current and new release, changes are required in order to be compatible with current and new releases.
2022-02-05 12:58:56 -08:00
Sebastian Nohn 454c01be51
Add support for one digit decimals (FORMAT_NUMBER_0, FORMAT_PERCENTAGE_0) (#2525)
* Add support for one digit decimals (FORMAT_NUMBER_0)

* Add support for one digit decimals (FORMAT_NUMBER_0, FORMAT_PERCENTAGE_0)

* adding tests for one digit numbers

* cleanup

* add failing test to block merge of this PR until #2555 has been merged

* fix code style

* fix test
2022-02-05 12:46:50 -08:00
Sebastian Nohn b5c03fc61f
Fix error in PercentageFormatter rounding (#2555)
* fix error in rounding percentages

* add tests for FORMAT_PERCENTAGE

* fix code style
2022-02-05 12:19:05 -08:00
Sebastian Nohn fe169dcd0a
Improve test coverage for NumberFormat (#2556)
* add tests for NumberFormat::FORMAT_NUMBER

* add tests for NumberFormat::FORMAT_NUMBER_00

* add tests for FORMAT_NUMBER_COMMA_SEPARATED1

* add tests for FORMAT_NUMBER_COMMA_SEPARATED2

* add tests for FORMAT_CURRENCY_USD_SIMPLE

* add tests for FORMAT_CURRENCY_USD

* add tests for FORMAT_CURRENCY_EUR, FORMAT_CURRENCY_EUR_SIMPLE

* add tests for FORMAT_ACCOUNTING_EUR, FORMAT_ACCOUNTING_USD
2022-02-05 12:05:26 -08:00
oleibman 239cd492d7
Update Russian Functions Text File (#2557)
PR #2554 introduced some new Russian translations into Translations.xlsx. As part of the unit tests, file Calclation/locale/ru/functions is changed to reflect the Translations.xlsx values. This will appear to be a file change to git until the text file is formally changed, which this PR does.
2022-02-05 11:55:14 -08:00
Mark Baker 394b504050
Additional russian function translations (#2554)
* Additional Russian translations for Excel functions

* Update change log
2022-02-04 18:18:21 +01:00
Mark Baker 4d82df2bc6
Add unit test for erroneous translations from Russian to English, and a quick/dirty fix (#2534)
* Add unit test for erroneous translations from Russian to English, and a quick/dirty fix
* Additional translation unit tests with accented characters from Spanish, Bulgarian, Czech and Turkish
* Update Change Log
2022-02-04 16:22:22 +01:00
Mark Baker 6b746dc05f
Extract some methods from the Calculation Engine into dedicated classes (#2537)
* Move binary comparisons out into a dedicated class
2022-02-04 16:02:29 +01:00
Florian Weber 0aed245fbc
Update definition for FILTER() (#2538) 2022-02-02 21:26:41 -08:00
dependabot[bot] 35dfdc617e
Bump phpunit/phpunit from 9.5.11 to 9.5.13 (#2544)
Bumps [phpunit/phpunit](https://github.com/sebastianbergmann/phpunit) from 9.5.11 to 9.5.13.
- [Release notes](https://github.com/sebastianbergmann/phpunit/releases)
- [Changelog](https://github.com/sebastianbergmann/phpunit/blob/master/ChangeLog-9.5.md)
- [Commits](https://github.com/sebastianbergmann/phpunit/compare/9.5.11...9.5.13)

---
updated-dependencies:
- dependency-name: phpunit/phpunit
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-02-02 18:26:05 -08:00
dependabot[bot] 9e591d8540
Bump mpdf/mpdf from 8.0.15 to 8.0.17 (#2543)
Bumps [mpdf/mpdf](https://github.com/mpdf/mpdf) from 8.0.15 to 8.0.17.
- [Release notes](https://github.com/mpdf/mpdf/releases)
- [Changelog](https://github.com/mpdf/mpdf/blob/development/CHANGELOG.md)
- [Commits](https://github.com/mpdf/mpdf/compare/v8.0.15...v8.0.17)

---
updated-dependencies:
- dependency-name: mpdf/mpdf
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-02-02 18:15:07 -08:00
oleibman 76388349d1
Update composer.lock (#2527)
Probably as a consequence of the merging of PR #2502,
Composer is complaining:
"Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. Run update to update them."
There doesn't appear to be any harm;
nevertheless, this PR implements the result of `composer update --lock`.
2022-02-02 18:04:20 -08:00
Mark Baker ebeed87db5
Initial implementation of the MS Excel RANDARRAY() MathTrig function (#2540)
* Initial implementation of the MS Excel RANDARRAY() MathTrig function
Update Change Log

* Unit Tests for RANDARRAY()
2022-01-31 22:29:03 +01:00
Mark Baker 26079174a0
Implementation of the SEQUENCE() Excel365 function (#2536)
* Implementation of the SEQUENCE() Excel365 function

Note that the Calculation Engine does not yet support the Spill operator, or spilling functions

* Handle the use-case of step = 0; and tests for exception handling for invalid arguments

* Update Change Log
2022-01-29 14:32:40 +01:00
mix5003 e7b0497237
fix warning when open xlsx file with thumbnail (#2517) 2022-01-24 14:17:53 -08:00
oleibman aa29947e0d
Update Change Log (#2522)
Document a number of PRs merged since V21.
2022-01-23 14:55:59 -08:00
oleibman b6bd822b9c
Xlsx Reader Merge Range For Entire Column(s) or Row(s) (#2504)
* Xlsx Reader Merge Range For Entire Column(s) or Row(s)

Fix #2501. Merge range can be supplied as entire rows or columns, e.g. `1:1` or `A:C`. PhpSpreadsheet is expecting a row and a column to be specified for both parts of the range, and fails when the unexpected format shows up.

The code to clear cells within the merge range is very inefficient in terms of both memory and time, especially when the range is large (e.g. for an entire row or column). More efficient code is substituted. It is possible that we can get even more efficient by deleting the cleared cells rather than setting them to null. However, that needs more research, and there is no reason to delay this fix while I am researching.

When Xlsx Writer encounters a null cell, it writes it to the output file. For cell merges (especially involving whole rows or columns), this results in a lot of useless output. It is changed to skip the output of null cells when (a) the cell style matches its row's style, or (b) the row style is not specified and the cell style matches its column's style.

* Scrutinizer

See if these changes appease it.

* Improved CellIterators

Finally figured out how to improve efficiency here, meaning that there is no longer a reason to change Writer/Xlsx, so restore that.

* No Change for CellIterator

I had thought a change was needed for CellIterator, but it isn't.
2022-01-23 10:44:09 -08:00
Mark Baker 3b81917760
Fix discrepancy between the way markdown tables are rendered in ReadTheDocs and in PHPStorm (#2520) 2022-01-22 21:00:22 +01:00
Mark Baker 4a04499bff
Read conditional styling for cell (#2491)
* Allow single-cell checks on conditional styles, even when the style is configured for a range of cells
* Work on the CellMatcher logic to evaluate Conditionals for a cell based on its value, and identify which conditional styles should be applied
* Refactor style merging and cell matching for conditional formatting into separate classes; this should make it easier to test, and easier to extend for other CF expressions subsequently
* Added support for containsErrors and notContainsErrors
* Initial work on a wizard to help simplify created Conditional Formatting rules, to ensure that the correct expressions are set
* Further work on extending the Conditional Formatting rules to cover more of the options that are available in MS Excel
* Prevent phpcs-fixer from removing class @method annotations, used to identify the signature for magic methods used in Wizard classes
* Implement `fromConditional()`` method to allow the creation of a CF Wizard from an existing Conditional
* Ensure that xlsx Reader picks up the timePeriod attribute for DatesOccurring CF Rules
* Allow Duplicates/Uniques CF Rules to be recognised in the Xlsx Reader
* Basic Xlsx reading of CF Rules/Styles from <extLst><ext><ConditinalFormattings> element, and not just the <ConditinalFormatting> element of the worksheet

* Add some validation for operands passed to the CF Wizards
 - remove any leading ``=` from formulae, because they'll be embedded into other formulae
 - unwrap any string literals from quotes, because that's also handled internally

Handle cross-worksheet cell references in cellReferences and Formulae/Expressions

* re-baseline phpstan

* Update Change Log with details of the CF Improvements
2022-01-22 19:18:26 +01:00
MarkBaker dee098b3d2 Prepare Change Log for next release 2022-01-22 18:39:14 +01:00
oleibman 2f0668017b
Plugin in composer.json (#2502)
Per https://getcomposer.org/doc/06-config.md#allow-plugins, Composer has added an extra layer of security in V2.2, and will start enforcing it in July of this year. Phpcodesniffer uses a plugin and will be affected if composer.json isn't updated before that date.

Co-authored-by: Mark Baker <mark@lange.demon.co.uk>
2022-01-20 12:03:21 +01:00
Mark Baker 0df5daaa8b
Fix mpdf to version 8.0.15, as 8.0.16 has logger signature issues (#2514) 2022-01-20 11:48:44 +01:00
Igor dbaafba6c6
Fix loading drawing size (#2492) 2022-01-16 21:59:31 -08:00
oleibman 06ea9ead2b
Xlsx Reader Cell DataType Numeric or Boolean Without Value (#2489)
Fix #2488. When Excel sees this situation, it leaves the value of the cell as null rather than casting to the specified DataType. It doesn't really make sense to change setValueExplicit to adopt this convention; it should be sufficient to recognize the situation in the Reader and act there. The same sort of situation might apply to strings, but I don't see any practical difference between null string and null even if so.
2022-01-16 21:19:09 -08:00
oleibman 95d9cc965d
Refinement for XIRR (#2487)
* Refinement for XIRR

Fix #2469. The algorithm used for XIRR is known not to converge in some cases, some of which are because the value is legitimately unsolvable; for others, using a different guess might help.

The algorithm uses continual guesses at a rate to hopefully converge on the solution. The code in Python package xirr (https://github.com/tarioch/xirr/) suggests a refinement when this rate falls below -1. Adopting this refinement solves the problem for the data in issue 2469 without any adverse effect on the existing tests. My thanks to @tarioch for that refinement.

The data from 2469 is, of course, added to the test cases. The user also mentions that an initial guess equal to the actual result doesn't converge either. A test is also added to confirm that that case now works.

The test cases are changed to run in the context of a spreadsheet rather than by direct calls to XIRR calculation routine. This revealed some data validation errors which are also cleaned up with this PR. This suggests that other financial tests might benefit from the same change; I will look into that.

* More Unit Tests

From https://github.com/RayDeCampo/java-xirr/blob/master/src/test/java/org/decampo/xirr/XirrTest.java
https://github.com/tarioch/xirr/blob/master/tests/test_math.py

Note that there are some cases where the PHP tests do not converge, but the non-PHP tests do. I have confirmed in each of those cases that Excel does not converge, so the PhpSpreadsheet results are good, at least for now. The discrepancies are noted in comments in the test member.
2022-01-13 19:31:46 -08:00