Commit Graph

286 Commits

Author SHA1 Message Date
MarkBaker 4089aede0a Resolve default values when a null argument is passed for HLOOKUP(), VLOOKUP() and ADDRESS() functions 2021-05-27 12:02:38 +02:00
MarkBaker 60ade80c0f Resolve Issue with float values losing their decimal when read from SpreadsheetML 2021-05-20 23:29:57 +02:00
Nathan Dench e6a4442d9a Use named data provider in AddressHelper tests 2021-05-20 21:26:20 +02:00
Nathan Dench 1a78ecfb10 Track down bug in AddressHelper::convertFormulaToA1 2021-05-20 21:26:20 +02:00
Nathan Dench 03ba547f5a Test convertFormulaToA1FromR1C1 2021-05-20 21:26:20 +02:00
Nathan Dench 62d3a56a57 Add AddressHelper::convertFormulaToA1 tests for SpreadsheetXML 2021-05-20 21:26:20 +02:00
MarkBaker f89bfc9e02 Additional language data, and improved automated build of translation files for Calculation Engine locale 2021-05-20 20:41:09 +02:00
MarkBaker b01a485f4f A couple of extra unit tests 2021-05-14 14:35:23 +02:00
oleibman d5492ac8ed
Merge branch 'master' into #984 2021-05-11 14:44:33 -07:00
Mark Baker d2e6db71fa
Lookup functions additional unit tests (#2074)
* Additional unit tests for VLOOKUP() and HLOOKUP()
* Additional unit tests for CHOOSE()
* Unit tests for HYPERLINK() function
* Fix CHOOSE() test for spillage
2021-05-07 23:40:30 +02:00
Nathan Dench 76ac008911 R1C1 conversion should handle absolute A1 references 2021-05-07 14:34:05 +02:00
Mark Baker 115e39ae0c
Issue 2066, highlighting more validation needed for LookupRef Functions (#2069)
* Issue 2066, highlighting more validation needed for LookupRef Functions
* Additional test cases
2021-05-07 11:20:38 +02:00
Mark Baker 5ee4fbf090
Implement basic autofilter ranges with Gnumeric Reader (#2057)
* Load basic autofilter ranges with Gnumeric Reader
* Handle null values passed to row height/column with/merged cells/autofilters
2021-05-04 22:32:12 +02:00
oleibman 346bad1b1d
Fix for Issue 2042 (SUM Partially Broken) (#2045)
As issue #2042 documents, SUM behaves differently with invalid strings depending on whether they come from a cell or are used as literals in the formula. SUM is not alone in this regard; COUNTA is another function within this behavior, and the solution to this one is modeled on COUNTA. New tests are added for SUM, and the resulting tests are duplicated to confirm correct behavior for both cells and literals.

Samples 16 (CSV), 17 (Html), and 21 (PDF) were adversely affected by this problem. 17 and 21 were immediately fixed, but 16 had another problem - Excel was not interpreting the UTF8 currency symbols correctly, even though the file was saved with a BOM. After some experimenting, it appears that the `sep=;` line generated by setExcelCompatibility(true) causes Excel to mis-handle the file. This seems like a bug - there is apparently no way to save a UTF-8 CSV with non-ASCII characters which specifies a non-standard separator which Excel will open correctly. I don't know if this is a recent change or if it is just the case that nobody noticed this problem till now. So, I changed Sample 16 to use setUseBom rather than setExcelCompatibility, which solved its problem. I then added new tests for setExcelCompatibility, with documentation of this problem.
2021-05-03 18:31:01 +02:00
Mark Baker fd14da1675
Ods defined names unit tests (#2054)
* Defined names/formulae in ODS are prefixed by $$ when used in a formula; so we need to strip this out to fully convert them to an Excel formula

* Test for ODS Writer for DefinedNames
2021-05-03 08:39:42 +02:00
xandros15 a757692992 #984 add support notContainsText for conditional styles in xlsx reader 2021-05-02 22:09:38 +02:00
Mark Baker 83e55cffcc
First steps in the implementation of AutoFilters for ODS Reader and Writer (#2053)
* First steps in the implementation of AutoFilters for ODS Reader and Writer, starting with reading a basic AutoFilter range (ignoring row visibility, filter types and active filters for the moment).

And also some additional refactoring to extract the DefinedNames Reader into its own dedicated class as a part of overall code improvement... on the principle of "when working on a class, always try to leave the library codebase in a better state than you found it"

* Provide a basic Ods Writer implementation for AutoFilters
* AutoFilter Reader Test
* AutoFilter Writer Test
* Update Change Log
2021-05-02 22:00:48 +02:00
Mark Baker d555b5d312
Pattern Fill style should default to 'solid' if there is a pattern fill with colour but no style (#2050)
* Pattern Fill style should default to 'solid' if there is a pattern fill style for a conditional; though may need to check if there are defined fg/bg colours as well; and only set a fill style if there are defined colurs
2021-04-30 20:05:45 +02:00
Mark Baker e4973fa041
Start work on refactoring the last of the Excel Statistical functions (#2033)
* Refactoring the last of the Excel Statistical functions
2021-04-29 14:34:50 +02:00
Mark Baker 160ae59751
Resolve problem where underscore placeholder in a number format masks (#2038)
* Resolve problem where underscore placeholder in a number format mask was being replaced, but leaving the sizing character as part of the mask
2021-04-29 14:15:45 +02:00
Mark Baker 475874bed3
Initial implementation of the URLENCODE() web function (#2031)
* Initial implementation of the URLENCODE() web function
2021-04-28 17:10:36 +02:00
oleibman c79a9a8e21
Improved Support for INDIRECT, ROW, and COLUMN Functions (#2004)
* Improved Support for INDIRECT, ROW, and COLUMN Functions

This should address issues #1913 and #1993. INDIRECT had heretofore not supported an optional parameter intended to support addresses in R1C1 format which was introduced with Excel 2010. It also had not supported the use of defined names as an argument. This PR is a replacement for #1995, which is currently in draft status and which I will close in a day or two.

The ROW and COLUMN functions also should support defined names. I have added that, and test cases, with the latest push. ROWS and COLUMNS already supported it correctly, but there had been no test cases. Because ROW and COLUMN can return arrays, and PhpSpreadsheet does not support dynamic arrays, I left the existing direct-call tests unchanged to demonstrate those capabilities.

The unit tests for INDIRECT had used mocking, and were sorely lacking (tested only error conditions). They have been replaced with normal, and hopefully adequate, tests. This includes testing globally defined names, as well as locally defined names, both in and out of scope.

The test case in 1913 was too complicated for me to add as a unit test. The main impediments to it are now removed, and its complex situation will, I hope, be corrected with this fix.

INDIRECT can also support a reference of the form Sheetname!localName when localName on its own would be out of scope. That functionality is added. It is also added, in theory, for ROW and COLUMN, however such a construction is rejected by the Calculation engine before passing control to ROW or COLUMN. It might be possible to change the engine to allow this, and I may want to look into that later, but it seems much too risky, and not nearly useful enough, to attempt to address that as part of this change.

Several unusual test cases (leading equals sign, not-quite-as-expected name definition in file, complex indirection involving concatenation and a dropdown list) were suggested by @MarkBaker and are included in this request.
2021-04-20 22:16:21 +02:00
oleibman aeccdb35e2
XLSX Reader and Empty Fill Tag (#2011)
Openpyxl can generate the xml tag `<patternFill/>`, possibly even as a default style. Excel has no problem with this, treating it as "fill none", but PhpSpreadsheet has a glitch because it treats it as "fill solid white". So, when PhpSpreadsheet loads and saves such a file, the result at first appears as if gridlines are disabled; in fact, the gridlines are merely invisible behind the cells with their solid white fill. This PR makes PhpSpreadsheet behave the same as Excel in this circumstance.

Co-authored-by: Mark Baker <mark@lange.demon.co.uk>
2021-04-20 17:20:59 +02:00
Mark Baker 6282035c96
Extract Property and Style readers from the XML Reader into separate classes (#2009)
* Extract Property and Style readers from the XML Reader into separate classes
2021-04-20 15:27:44 +02:00
Tiago Fernandes 11f8a02194
Merge branch 'master' into issue-907-absolute-path-in-Target 2021-04-19 14:32:20 +01:00
Tiago Fernandes 559c0761df Remove unnecessary changes. Added test 2021-04-19 11:25:48 +01:00
Mark Baker ddd07ee504
Use validation classes rather than traits for Statistical functions, … (#1999)
* Use validation classes rather than traits for Statistical functions, and some verification of nullable arguments
* Eliminate more of the issues resolved in phpstan baseline
2021-04-13 16:56:21 +02:00
Mark Baker a34695e0f9
Financial functions more rationalization (#1990)
* Additional unit tests and rationalisation for Financial Functions
* Providing a series of sample files for Financial functions
* Refactor the last of the existing Financial functions
* Some more unit tests with default assignments from null arguments

Co-authored-by: Adrien Crivelli <adrien.crivelli@gmail.com>
2021-04-12 22:08:58 +02:00
Adrien Crivelli 49f87de165
Reduce PHPStan error in tests 2021-04-12 11:10:23 +09:00
Mark Baker bc18fb7e77
more extraction of Excel Financial functions (#1989)
* More Financial function extracts, this time looking at the Periodic Cashflow functions
* Initial extract of Constant Periodic Interest and Payment functions
2021-04-06 12:45:37 +02:00
Vivek 93d858a064
Merge branch 'master' into fix_excel_overwrite 2021-04-06 08:19:44 +05:30
oleibman 95b8c4d59b
Continue MathTrig Breakup - Completion! (#1985)
* Continue MathTrig Breakup - Completion!

Continuing the process of breaking MathTrip.php up into smaller classes. This round takes care of everything that was left:
- ABS
- DEGREES
- EXP
- RADIANS
- SQRT
- SQRTPI
- SUMSQ, SUMX2MY2, SUMX2PY2, SUMXMY2

The only notable logic change was that the 3 SUMX* functions had accepted arrays of unlike length; in that condition, they now return N/A, as Excel does. There had been no tests for this condition.

All the functions in MathTrig.php are now deprecated. Except for COMBIN, the test suite executes them only from MathTrig MovedFunctionsTest. COMBIN is still directly called by some Statistics Binomial functions which have not yet had the opportunity to be re-coded for the new location.


Co-authored-by: Mark Baker <mark@lange.demon.co.uk>
2021-04-05 16:39:03 +02:00
Vivek Kumar 5e96f4292b Merge remote-tracking branch 'master' into fix_excel_overwrite 2021-04-05 12:42:43 +05:30
Adrien Crivelli d02352845c
PHPStan Level 2 2021-04-04 22:06:00 +09:00
Mark Baker 42761f90b7
Financial start refactoring cash flow functions (#1986)
* Start extracting CashFlow functions from Financial, beginning with the simple Single Rate flows
* Extracting Variable Periodic and NonPeriodic CashFlow functions from Financial
* Some more unit tests for exception cases
2021-04-04 14:44:06 +02:00
Mark Baker a2bb825bc5
Extract Normal and Standard Normal Distributions from the Statistical Class (#1981)
* Extract Normal and Standard Normal Distributions from the Statistical Class
* Extract ZTest from the Statistical Class, and move it to the Standard Normal Distribution class
Additional unit tests for NORMINV()
* Extract LogNormal distribution functions from Statistical
2021-04-02 20:17:03 +02:00
oleibman a4982fd9fe
Continue MathTrig Breakup - Penultimate? (#1973)
* Continue MathTrig Breakup - Penultimate?

Continuing the process of breaking MathTrip.php up into smaller classes. This round takes care of about half of what is left, so perhaps one round after this one will finish the job:
- ARABIC
- COMBIN; also implemented COMBINA
- FACTDOUBLE
- GCD (which accepts and ignores empty cells as arguments, but returns VALUE if all the arguments are that way; LCM does the same)
- LOG_BASE, LOG10, LN
- implemented MUNIT
- MOD
- POWER
- RAND, RANDBETWEEN (RANDARRAY is too complicated to implement with this ticket)

As you can see from the description, there are some functions which were combined in a single class. When not combined, I adopted PowerKiki's suggestion of using "execute" as the function name.

Co-authored-by: Mark Baker <mark@lange.demon.co.uk>
2021-04-02 14:35:34 +02:00
Mark Baker 0c403efe60
Resolution for [#Issue 1972](https://github.com/PHPOffice/PhpSpreadsheet/issues/1972) (#1978)
* Resolution for [#Issue 1972](https://github.com/PHPOffice/PhpSpreadsheet/issues/1972) where format masks with a leading and trailing quote were always treated as literal strings, even when they masks containing quoted characters.

Also resolves issue with colour name case-sensitivity
2021-04-01 13:25:05 +02:00
Mark Baker 17af13281b
Extract a few more Distribution functions from Statistical (#1975)
* Extract a few more Distribution functions from Statistical; this time EXPONDIST() and HYPGEOMDIST()

* Extract the F Distribution (although only F.DIST() is implemented so far

* Updae docblocks

* PHPCS
2021-03-31 21:45:06 +02:00
Mark Baker 029f345987
Extract Binomial Distribution functions from Statistical (#1974)
* Extract Binomial Distribution functions from Statistical
Replace the old MS algorithm for CRITBINOM() (which has now been replaced with te BINOM.INV() function) with a brute force approach - I'll look to refine it later. The MS algorithm is no longer documented, and the implementation produced erroneous results anyway

* Exract the NEGBINOMDIST() function as well; still need to add a cumulative flag to support the additional argument for the newer NEGBINOM.DIST() function
* Rationalise validation of probability arguments
2021-03-30 22:49:10 +02:00
Mark Baker 1c92b7611a
Extract Percentile-type functions from Statistics (#1966)
* Extract Percentile-type functions from Statistics (e.g. PERCENTILE(), PERCENTRANK(), QUARTILE(), and RANK())
* Unit test for PERCENTILE() with an empty (of numbers) dataset
2021-03-29 12:59:46 +02:00
Mark Baker e68978f1c7
Chi squared inverse left tailed (#1964)
* Implementation of the CHISQ.INV() method for ChiSquared distribution left-tail
2021-03-28 19:12:45 +02:00
Mark Baker e2ff14fe89
Implemented the CHISQ.DIST() Statistical function. (#1961)
* Implementation of the CHISQ.DIST() statistical function for left tail distribution
2021-03-28 16:13:00 +02:00
Mark Baker 67fec4e3fc
Implementation of the CHITEST() statistical function (#1960)
* Implementation of the CHITEST() statistical function

* A couple of additional edge case tests (rows = 1, columns = 1)
2021-03-27 22:04:05 +01:00
Mark Baker a34dd71cce
Difference in variance calculations between Excel/Gnumeric and Open/LibreOffice (#1959)
* Difference in variance calculations between Excel/Gnumeric and Open/LibreOffice
* Simplify STDEV() function logic by remembering that STDEV() is simply the square root of VAR(), so we can simply use the VAR() calculaion rather than duplicating the basic logic... and also allow for the differences between Excel/Gnumeric and Open/LibreOffice
2021-03-27 18:31:24 +01:00
Mark Baker ec2531411d
Start implementing Newton-Raphson for the inverse of Statistical Distributions (#1958)
* Start implementing Newton-Raphson for the inverse of Statistical Distributions, starting with the two-tailed Student-T
* Additional unit tests and validations
* Use the new Newton Raphson class for calculating the Inverse of ChiSquared
* Extract Weibull distribution, and provide unit tests
2021-03-27 13:29:58 +01:00
Mark Baker c699d144e2
Extract ACCRINT() and ACCRINTM() Financial functions into their own class (#1956)
* Extract ACCRINT() and ACCRINTM() Financial functions into their own class
Implement additional validations, with additional unit tests
Add support for the new calculation method argument for ACCRINT()
* Additional tests for Amortization functions
2021-03-26 22:49:16 +01:00
oleibman 9239b3deca
Continue MathTrig Breakup - Problem Children (#1954)
Continuing the process of breaking MathTrip.php up into smaller classes. This round takes care of all functions which might be an impediment to installing due to either uncovered code or "complexity":
- BASE
- FACT
- LCM
- MDETERM, MINVERSE, MMULT
- MULTINOMIAL
- PRODUCT
- QUOTIENT
- SERIESSUM
- SUM
- SUMPRODUCT

MathTrig and the members in directory MathTrig are now 100% covered. Many tests have been added, and some edge-case bugs are corrected. Some cases where PhpSpreadsheet had rejected numeric values stored as strings have been changed to accept them whenever Excel does; there had been no tests for that condition.

Boolean arguments are now accepted as arguments wherever Excel accpets them. Taking a cue from what has been done in Engineering, the parameter validation now happens in a routine which issues Exceptions for invalid values; this simplifies the code in the functions themselves. Thank you for doing that; I did not foresee how useful that was when I first looked at it.

Consistent with earlier changes of this nature, the versions in the MathTrig class remain, with a doc block indicating deprecation, and a stub call to the new routines.

All tests except for MINVERSE and MMULT are now handled in the context of a spreadsheet rather than a direct call to the calculation function which implements it. PhpSpreadsheet would need to handle dynamic arrays in order to test MINVERSE and MMULT in a spreadsheet context. Implementing that looks like it might be *very* challenging. It is not something I plan to look at, at least not in the near future.

One parsing problem turned up in the test conversion. It is in one of the SUMIF tests. It takes me to an area in Calculation where the comment says "I don't even want to know what you did to get here". It did not show up in the previous incarnation because, by using a direct call, the previous test managed to bypass the parsing. I have confirmed that this problem shows up in earlier releases of PhpSpreadsheet, so the changes in this PR did not cause it - they merely exposed it. I have left the test intact, but marked it "incomplete" for documentation purposes. I have not been able to get a handle on what's going wrong yet. I will probably open an issue on it if I can't resolve it soon. However, the test in question isn't a "real world" issue, and the error wasn't caused by this change, so I see no reason to delay this pending a resolution of the problem.

SUM had an idiosyncratic moment of its own. It had been ignoring non-numeric values, but Excel returns VALUE in that situation. So I changed it and wrote some new tests, which worked, but ... SUMIF uses several levels of indirection to get to SUM, and SUMIF *does* ignore non-numeric values, so a SUMIF test broke. SUM is a really simple function; the most practical approach seemed to be to clone it, with the string-accepting version being used by the Legacy version (which is called by SUMIF), and the non-string-accepting version being used in the Calculation Function table. That seems far easier and more practical than, for instance, adding a boolean parameter to the variable parameter list. As a follow-up, I will change SUMIF to explicitly call the appropriate new version, but I did not want to add that to this already large change.

SUM again - although it was fully covered beforehand, there was not a specific test member for it. There is now.

FACT had been coded to fail Gnumeric requests where the numeric argument has a decimal portion. However, Gnumeric does accept such an argument, and, unlike Excel and ODS, does not truncate it, but returns the result of a Gamma function call instead. This has been corrected.

When LCM included arguments which contained both 0 and a negative number, it returned 0 or NUM, whichever it found first. It is changed to always return NUM in that circumstance, as Excel does.

QUOTIENT had been documented as taking a variadic list of arguments. In fact, it takes exactly 2 - numerator and denominator - and the docblock and signature is fixed, even in the deprecated version.

The SERIESSUM docbock and signature are more accurate, even in the deprecated version. It is changed to ignore nulls, as Excel does, rather than return VALUE, and is one of the routines which previously rejected numbers in string form.

SUBTOTAL tests had used mocking for some reason. These are replaced with normal tests. And SUBTOTAL had a big surprise in store. That part of it which deals with hidden cells cares only whether the row is hidden, and doesn't care about the column's visibility.

I struggled with whether it should be SubTotal or Subtotal. I think the latter is correct, so that's how I proceeded. I don't think there are likely to be any other capitalization controversies.
2021-03-26 17:35:30 +09:00
Mark Baker c380b25d3c
Extract Poisson distribution into its own class (#1953) 2021-03-26 09:08:23 +01:00
Mark Baker f51c19c125
First steps toward refactoring Excel's Statistical Distributions (#1949)
* First steps toward refactoring Statistical Distributions into smaller classes: BETA() and GAMMA() (and related functions) to start with... they all need a lot of tidying up, and more testing; but it's a start

* Add basic datatype validations to Beta and Gamma Excel function implementations
* Switch to using a trait with the validation methods to provide easier sharing between distribution classes
* Additional unit tests for Beta and Gamma functions, including unhappy path for validations

* Extract ChiSquared functions
* Additional argument validation checks with unit tests for Chi Squared functions

* Extract Fisher

* Move MEDIAN() and MODE() to the Averages class
* Extract filters for Median and Mode for common usage
2021-03-25 20:54:55 +01:00