Commit Graph

2515 Commits

Author SHA1 Message Date
Mark Baker 1d6f36d8df
Initial Formula Translation tests (#1886)
* Initial Formula Translation tests
2021-02-28 13:18:51 +01:00
Mark Baker ee969fdcfe
Additional conditionals from math trig (#1885)
* Use our new Conditional logic to implement the SUMIF() and SUMIFS() Mathematical functions
2021-02-28 10:24:33 +01:00
Mark Baker 761c84a946
Avoid the performance/memory overheads of "clone on modify" of $args (#1884)
* Avoid the performance/memory overheads of "clone on modify" of $args when building the condition set/database for AVERAGEIFS(), MAXIFS() and MINIFS()
* Avoid the performance/memory overheads of "clone on modify" of $args when building the condition set/database for COUNTIFS()
2021-02-27 23:10:33 +01:00
oleibman 80a20fc991
100% Coverage for Calculation/DateTime (#1870)
* 100% Coverage for Calculation/DateTime

The code in DateTime is now completely covered.
Along the way, some errors were discovered and corrected.
- The tests which have had to be changed at the start of every year are
replaced by more robust equivalents which do not require annual changes.
- Several places in the code where Gnumeric and OpenOffice were thought to differ
from Excel do not appear to have had any justification.
I have left a comment where such code has been removed.
- Use DateTime when possible rather than date, time, or strftime functions to avoid
potential Y2038 problems.
- Some impossible code has been removed, replaced by an explanatory comment.
- NETWORKDAYS had a bug when the start date was Sunday. There had been no tests
of this condition.
- Some functions allow boolean and null arguments where a number is expected.
This is more complicated than the equivalent situations in MathTrig because
the initial date for these calculations can be Day 1 rather than Day 0.
- More testing for dates from 1900-01-01 through the fictitious
everywhere-but-Excel 1900-01-29.
    - This showed that there is an additional Excel bug - Excel evaluates
WEEKNUM(emptycell) as 0, which is not a valid result for
WEEKNUM without a second argument.
PhpSpreadsheet now duplicates this bug.
    - There is a similar and even worse bug for 1904-01-01 in 1904 calculations.
Weeknum returns 0 for this,
but returns the correct value for arguments of 0 or null.
    - DATEVALUE should accept 1900-02-29 (sigh) and relatives.
PhpSpreadsheet now duplicates this bug.
- Testing bootstrap sets default timezone. This appears to be a relic from
the releases of PHP where the unwise decision, subsequenly reversed,
was made to issue messages for
"no default timezone is set" rather than just use a sensible default.
This was a disruptive setting for some of the tests I added.
There is only one test in the entire suite which is default-timezone-dependent.
Setting and resetting of default timezone is moved to that test
(Reader/ODS/ODSTest), and out of bootstrap.
- There had been no testing of NOW() function.
- DATEVALUE test had no tests for 1904 calendar and needs some.
- DATE test changed 1900/1904 calendar in use without restoring it.
- WEEKDAY test had no tests for 1904 calendar and needs some.
    - Which revealed a bug in Shared/Date (excelToDateTimeObject was not
recognizing 1904-01-01 as valid when 1904 calendar is in use).
    - And an additional bug in that legal 1904-calendar values in the 0.0-1.0
range yielded the same "wrong" answers as 1900-calendar (see "One note" below).
Also the comment for one of the calendar-1904 tests was wrong in attempting
to identify what time of day the fraction represented.

I had wanted to break this up into a set of smaller modules, a process already
started for Engineering and MathTrig.
However the number of source code changes was sufficient that I wanted
a clean delta for this request.
If it is merged, I will work on breaking it up afterwards.

One note - Shared/Date/excelToDateTimeObject, when calendar-1900 is in use,
returns an unexpected result if its argument is between 0 and 1,
which is nominally invalid for that calendar.
It uses a base-1970 calendar in that instance. That check is not justifiable
for calendar-1904, where values in that range are legal,
so I made the check specific to calendar-1900,
and adjusted 3 1904 unit test results accordingly. However, I have to admit that
I don't understand why that check should be made even for calendar-1900.
It certainly doesn't match anything that Excel does.
I would recommend scrapping that code altogether.
If agreed, I would do this as part of the break-up into smaller modules.

Another note -
more controversially, it is clear that PhpSpreadsheet needs to support
the Excel and PHP date formats. Although it requires further study,
I am not convinced that it needs to support Unix timestamp format.
Since that is a potential source of Y2038 problems on 32-bit systems,
I would like to open a PR to deprecate the use of that format.
Please let me know if you are aware of a valid reason to continue to support it.
2021-02-27 20:43:22 +01:00
Mark Baker 08673b5820
Initial experiments using the new Database query logic with Conditional Statistical Functions (#1880)
- Refactoring of the Statistical Conditional functions (`AVERAGEIF()`, `AVERAGEIFS()`, `COUNTIF()`, `COUNTIFS()`, `MAXIFS()` and `MINIFS()` to use the new Database functions codebase.
- Extended unit testing
- Fix handling for null values
- Fixes to wildcard text searches

There's still scope for further improvements to memory usage and performance; but for now the code is stable with all unit tests passing
2021-02-27 18:26:12 +01:00
MarkBaker 8dcdf58131 Update change log 2021-02-27 15:22:25 +01:00
oleibman cb23cca3ec
Avoid Duplicate Titles When Reading Multiple HTML Files (#1829)
This issue arose while researching issue #1823. The issue was not a bug;
it just required clarification to the author of how to use the software.
But, while researching, I discovered that loading html into 2
sheets of a spreadsheet has a problem if the html title tag is the same
for the 2 sheets. PhpSpreadsheet would be able to save the resulting file,
but Excel would not be able to read it properly because of the duplicate title.
The worksheet setTitle method allows for disambiguation is such a circumstance.
The html reader passed a parameter indicating "don't disambiguate", but I can't
see any harm in changing that to "disambiguate". An extremely simple fix,
with tests to back it up.
2021-02-27 15:10:04 +01:00
Mark Baker 25f7dcb9fd
Enable support for wildcard text searches in Excel Database functions (#1876)
* Enable support for wildcard text searches in Excel Database functions
2021-02-23 19:26:29 +01:00
Mark Baker 40a6dee0a4
Enable support for dates and percentages in Excel Database functions (#1875)
* Enable support for dates and percentages in Excel Database functions, and CountIf/AverageIf/etc
* Enable support for booleans in Excel Database functions
2021-02-22 20:40:40 +01:00
Mark Baker 3764f30354
Refactor the Excel Database functions; and rewrite the query building (#1871)
* Refactor the Excel Database functions; and rewrite the query building to fix a bug with complex multi-criteria queries that involve both AND and OR conditions
* Fix handling for empty cells and NULL values in searches
* Expand unit tests; and add TODOs for dates, percentages, and wildcard text comparisons
2021-02-22 12:46:57 +01:00
Mark Baker 1318b90330
Bugfix #1858; Apply stricter scoping rules to named range/cell access (#1866)
* Apply stricter scoping rules to named range/cell access via Worksheet object
* Additional unit tests
2021-02-19 22:03:50 +01:00
Mark Baker b0eb272ce1
Bugfix #1858; `getCell()` method should support named cells correctly (#1865)
Resolution for Issue [#1858](https://github.com/PHPOffice/PhpSpreadsheet/issues/1858)
2021-02-19 12:28:07 +01:00
Mark Baker 409c05b542
Additional Unit Test Cases for Convert UoM (#1864)
* Additional Unit Test Cases
2021-02-19 08:41:26 +01:00
Mark Baker b269c26f6e
Advanced Value Binder improvements (#1863)
* Refactor times, and add unit tests
2021-02-18 23:14:14 +01:00
Mark Baker 5afda811c9
Advanced Value Binder Improvements (#1862)
Advanced Value Binder
 - Improved format checking/setting for fractions;
 - Better percentage checking;
 - Some minor refactoring;
 - Improved unit testing
2021-02-18 19:17:47 +01:00
Mark Baker 7c7b229041
Let's see what Scrutinizer makes of these changes (#1859)
* Let's see what Scrutinizer makes of these changes
2021-02-18 12:39:24 +01:00
oleibman 10c9c4cf23
Make Documentation Updates Easier and More Accurate (#1573)
I made a documentation change and noticed that the result when browsed
locally did not quite match what is seen when browsing from the web.
After some research, I found https://github.com/mkdocs/mkdocs/issues/2028
That described my situation well and suggested adding an extra
javascript script to the configuration. This worked exactly as desired
on my local machine. This accounts for the presence of extrajs.js
and mkdocs.yml in this request.

In addition to the display problem, "mkdocs build" generates the
documentation into a directory which is not ignored by git. I added
that directory to .gitignore as part of this request.

Finally, since I don't know how exactly the documentation makes it
to production, I made an insignificant change to one doc file as
a sanity check.
2021-02-15 20:50:20 +01:00
oleibman ef3f8f3070
Use DateTime Rather than gmmktime in Sample Template (#1827)
This avoids a potential Y2038 problem on 32-bit systems - see issue #1826.
2021-02-14 18:54:49 +01:00
MarkBaker 4e1f89d04c Fix coding standards issue 2021-02-14 17:12:01 +01:00
MarkBaker e29600116e Merge branch 'reader-array-formula-bugfix' 2021-02-14 17:10:01 +01:00
MarkBaker 9909af6ccb Fix coding standards issue 2021-02-14 16:47:49 +01:00
Mark Baker f277817955
Update deprecation notices to reflect deprecated from the next release (#1856)
* Update deprecation notices to reflect deprecated from the next release
2021-02-14 16:09:09 +01:00
Mark Baker c407ff6fe7
Start extracting Logical Excel functions into separate groups in dedicated classes (#1855)
* Start extracting Logical Excel functions into separate groups in dedicated classes

* Extracting remaining Logical Excel functions into separate groups in dedicated classes
2021-02-14 11:55:21 +01:00
MarkBaker 8d0692397b Additional Office 365 functions for Excel added in 2020 2021-02-13 22:08:22 +01:00
oleibman a24ca09bd4
Support 'Forms' for ROMAN Function (#1828)
* Support 'Forms' for ROMAN Function

This seems like an exceptionally silly thing for MS to have implemented
(Wikipedia on Roman Numerals: "There is no indication this is anything
other than an invention by the programmer").
Nevertheless, we can, and therefore probably should, implement it.

Not that I can implement it by an algorithm - Excel describes the various extra
styles as "more concise", "more concise", "more concise", and "simplified".
Nevertheless, since the universe of potential calls is relatively small,
it can be implemented as a table of values where the new forms would return
a different value than "classic". This table is relatively large, so I have
put it its own member to avoid overhead when the function is needed.

* Move ROMAN To Its Own Class

See discussion in PR #1837

* PHP 8.1 Deprecations

PHP8.1 Unit tests failed. 1 line fixes are available for
- Shared/Font
- Shared/XMLWriter
- Style/Color
- Writer/HTML

The problem is that an error is also reported for a strcmp at
line 272 of Cell/Cell. Not only does that line not invoke strcmp,
there is no strcmp in all of Cell/Cell, so I don't know what to make
of the error message. Oh well, let's fix what can be fixed.

Still dealing with the mysterious PHP8.1 unit test failure in Cell\Cell,
which seems to have something to do with strcmp. The only uses of
strcmp that I can find in src/ are in Calculation. I can't find any
use of it in test/ or samples/. So, if this doesn't fix the problem,
I may have to give up.
2021-02-13 21:23:58 +01:00
oleibman cabcfaa522
ROUND Accepts null, false, and true as First Parameter (#1837)
* ROUND Accepts null, false, and true as First Parameter

Issue #1789 was addressed by PR #1799. In a follow-up discussion,
it came to light that ROUND was not handling the unexpected case where the
first parameter is an empty cell in the same manner that Excel does.
Subsequent investigation showed that a boolean first parameter is permitted.
I broadened my investigation to include the following related functions.
- ROUNDUP
- ROUNDDOWN
- MROUND
- TRUNC
- INT
- FLOOR
- FLOOR.MATH
- FLOOR.PRECISE
- CEILING
- CEILING.MATH
- CEILING.PRECISE

All of these allow a NULL first parameter, and all except MROUND allow boolean.
For completeness, I will note that all treat null string as invalid.
I suspect there are other functions which permit
similarly unexpected parameters, but I consider them out of scope for this PR.

CEILING.MATH and CEILING.PRECISE were unimplemented, and are now supported
as part of this PR.

The tests for each of these functions have been re-coded, though all the original
test data is still included in the test cases, plus several new cases for each.
The new tests now take place as a user would invoke the functions,
through a spreadsheet cell rather than a
direct call to the appropriate function within Calculation/MathTrig.
Aside from being more realistic, the new tests are also more complete.
For example, FLOOR.MATH can take from 1-3 arguments, and the existing tests
confirmed that the function in Calculation could handle a single argument.
However, the function list in Calculation.php erroneously set the number of
arguments for FLOOR.MATH to exactly 3, so, if a user tried to get the calculated
result of a cell containing FLOOR.MATH(1.2), the result would be an Exception.

Aside from the parameter support, there are a few minor code changes.
Ods, as well as Gnumeric, allows the omission of the second parameter for
FLOAT and CEILING; Excel does not. A potential divide-by-zero error is
avoided in CEILING, FLOOR, and FLOORMATH.

I will note that it would probably be beneficial in terms of maintainability
to break MathTrig up into many individual modules. The same would hold for the
other Calculation modules. I would be willing to look into this if you agree
that it would be worthwhile.
2021-02-13 21:00:08 +01:00
Mark Baker c54e3e9979
Extract DELTA() and GESTEP() functions from the Engineering class into a dedicated Comparison classes (#1853)
* Extract DELTA() and GESTEP() functions from the Engineering class into a dedicated Comparison classes

Retain the original methods in the Engineering class as stubs for BC, but deprecate them. They will be removed for PHPSpreadsheet v2

Note that unit tests still point to the Engineering class stubs; these should be modified to use the Erf and ErfC classes directly when the stubs are removed
2021-02-13 20:52:20 +01:00
MarkBaker 15a5d13aba Update docs 2021-02-13 15:58:06 +01:00
Mark Baker 42ecc270ec
Extract Permutation functions from the Statistical class into a dedicated Permutations class (#1851)
* Extract Permutation functions from the Statistical class into a dedicated Permutations class

Retain the original methods in the Statistical class as stubs for BC, but deprecate them. They will be removed for PHPSpreadsheet v2

Note that unit tests still point to the Statistical class stubs; these should be modified to use the Permutations class directly when the stubs are removed

Also provided a basic implementationof the PERMUTATIONA() Function
2021-02-13 15:35:07 +01:00
MarkBaker e824caf857 Update Changelog 2021-02-13 13:09:49 +01:00
Mark Baker be328c33a5
Extract all Error functions from the Engineering class into a dedicated Erf and ErfC classes (#1850)
* Extract all Error  functions from the Engineering class into a dedicated Erf and ErfC classes

Retain the original methods in the Engineering class as stubs for BC, but deprecate them. They will be removed for PHPSpreadsheet v2

Note that unit tests still point to the Engineering class stubs; these should be modified to use the Erf and ErfC classes directly when the stubs are removed

* Reminder that ERF is used (either directly or Indirectly) in some of the statistical functions as well
2021-02-13 12:55:41 +01:00
Mark Baker 61d2e6dcd3
Extract all Base Conversion functions from the Engineering class into dedicated Base Conversion classes (#1849)
* Extract all Base Conversion functions from the Engineering class into a dedicated Convert<Base> classes extending from a common ConvertBase class

Retain the original methods in the Engineering class as stubs for BC, but deprecate them. They will be removed for PHPSpreadsheet v2

Note that unit tests still point to the Engineering class stubs; these should be modified to use the Convert<Base> classes directly when the stubs are removed

* Split out into separate base conversion classes, with a ConvertBase class for common methods
2021-02-13 11:21:16 +01:00
Mark Baker 69315f0640
Extract all BitWise functions from the Engineering class into a dedicated BitWise class (#1848)
* Extract all BitWise functions from the Engineering class into a dedicated BitWise class

Retain the original methods in the Engineering class as stubs for BC, but deprecate them. They will be removed for PHPSpreadsheet v2

Note that unit tests still point to the Engineering class stubs; these should be modified to use the bessel classes directly when the stubs are removed
2021-02-12 19:19:04 +01:00
MarkBaker 6946bde47e Fix docblocks 2021-02-12 18:12:19 +01:00
ElPopcorn b975fb7ddd
Update PPMT & IPMT implementation to better reflect excel behaviour. Update CUMPRINC & CUMIPMT implementation to prevent a crash while trying to add a string to a number. Update AMORLINC & AMORDEGRC to prevent crash when trying to multiply a string by a number. Update related unit tests. Update changelog to describe what we fixed. (#1840)
Co-authored-by: Obmecha <victor.sonza@nexvia.lu>
2021-02-12 18:04:52 +01:00
Mark Baker 2aa4a28863
Move Bessel function calculations from the Engineering class to a dedicated Engineering\Bessel<x> classes (#1846)
* Move Bessel function calculations from the Engineering class to a dedicated Engineering\Bessel class
Retain the original methods in the Engineering class as stubs for BC, but deprecate them. They will be removed for PHPSpreadsheet v2
* Some refactoring of the Bessel calculation logic
* Fix callable for ConvertUOM()
2021-02-12 17:55:53 +01:00
Mark Baker 17f405cf62
Attempt to provide allow failure for PHP8.1 unit tests (#1847)
* Attempt to provide allow failure for PHP8.1 unit tests
  PHP8.1 Tests show as passed despite the errors, and it requires checking the actual output from the run to see what the rea result is; but I can live with that until github provides functionality for a proper allow_failure option
2021-02-12 14:18:39 +01:00
MarkBaker 6f6a0586d2 Update change log 2021-02-08 19:39:39 +01:00
Mats Sibelius f60f37c362
Fix case where mergeComplexNumberFormatMasks would get stuck in endless-loop (#1793)
* Fix case where mergeComplexNumberFormatMasks would get stuck in endless-loop if $numbers had many decimals
2021-02-08 19:26:11 +01:00
Mark Baker b068639513
Substitute a literal dot inside quotes within number format masks to prevent it being mistaken for a decimal separator (#1830)
* Substitute a literal dot inside quotes within number format masks to prevent it being mistaken for a decimal separator
2021-02-08 15:06:07 +01:00
oleibman 2fac9ee2f7
Stacked Alignment - Use Class Constant Rather than Literal (#1716)
* Stacked Alignment - Use Class Constant Rather than Literal

PR #1580 defined constants for "stacked" alignment in cells.
Using those constants outside of Style/Alignment was beyond the
scope of the original PR, but I said I would get to it.
This PR replaces all uses of literal -165, and appropriate uses of
literal 255, with the named constants, and adds tests to make sure
that the changed code is covered in the test suite.
2021-02-03 23:53:04 +01:00
Adrien Crivelli 30717fd35a
Remove leftover of Sami 2021-02-02 15:16:03 +09:00
MarkBaker ce79f17fa9 Update changelog 2021-02-01 14:27:00 +01:00
MarkBaker a184b0f37b Update changelog 2021-02-01 11:58:40 +01:00
Roland Eigelsreiter fa51a8590b
Fix XLSX reader when having a corrupt numeric cell data type (#1664)
* fix for read xlsx with somewhat corrupt cell data type
2021-02-01 11:56:27 +01:00
Mark Baker d28b7de1fc
Refactoring of ODS Writer to break codebase into smaller components (#1820)
* Refactoring of ODS Writer to break codebase into smaller components
2021-02-01 05:01:00 +01:00
Mark Baker 5f761b6274
Cell alignment for ods Writer (#1819)
* Cell alignment for ods Writer
2021-01-31 23:39:37 +01:00
MarkBaker 8b94a37e23 Update change log 2021-01-31 19:16:42 +01:00
Darren Maczka c82ff2526c
Fix/chart axis titles (#1760)
* use axPos value to determine whether an axis title is mapped to the XaxisLabel or YaxisLabel

* update changelog

* Fix php-cs-fixer violations

Co-authored-by: Darren Maczka <dkm@utk.edu>
Co-authored-by: Mark Baker <mark@lange.demon.co.uk>
2021-01-31 19:13:50 +01:00
Darren Maczka 44248cd04e
Fix/sheets xlsx chart (#1761)
* Add support for Google Sheets Exported XLSX Charts

Google Sheets XLSX charts use oneCellAnchor positioning and the data series
do not have the *Cache elements with cached values.

* update CHANGELOG

* Add support for Google Sheets Exported XLSX Charts

Google Sheets XLSX charts use oneCellAnchor positioning and the data series
do not have the *Cache elements with cached values. Because the reader had been
assuming *Cache elements existed as children of strRef and numRef, errors about
the node being deleted were thrown when reading Xlsx exported from Google Sheets.

Co-authored-by: Darren Maczka <dkm@utk.edu>
2021-01-31 18:53:54 +01:00