Commit Graph

864 Commits

Author SHA1 Message Date
MarkBaker f3bb61f3e4 Initial work implementing the FILTER() Lookup/Reference function
Tighten up on vector formats; and provide a couple of helper methods for testing row/column vectors
2022-03-20 18:01:30 +01:00
MarkBaker 0a9d15407f Suport fill style and color for reading CF Formats 2022-03-19 19:47:14 +01:00
Mark Baker 23e2d702ff
Merge branch 'master' into Xls-Reader-Conditional-Formatting 2022-03-19 16:21:14 +01:00
MarkBaker be8c444951 More minor tweaks 2022-03-19 16:15:48 +01:00
MarkBaker c73bb612e0 Unit tests for Xls Reader DataValidation 2022-03-19 12:04:14 +01:00
MarkBaker 45c08d6cd4 Initial work on reading conditional styles for the Xls Reader
Successfully reading the CF ranges and CF rules; not yet reading the styles
2022-03-18 21:09:32 +01:00
MarkBaker 21b784f200 Add basic support for Error functions when the error is #SPILL! or #CALC! 2022-03-18 17:44:26 +01:00
MarkBaker 75e45057f3 Fix scrutinizer issue complaint 2022-03-18 15:07:13 +01:00
MarkBaker c8cf193301 Initial work implementing the new UNIQUE() Lookup/Reference array function 2022-03-18 14:18:37 +01:00
MarkBaker f6fcc4de87 More unit testing for inserting/deleting rows/columns with DataValidation, ConditionalFormatting and PrintArea 2022-03-17 15:48:30 +01:00
MarkBaker 9b3c3f4adf Merge branch 'master' into Xls-Reader-Conditional-Formatting 2022-03-17 12:11:19 +01:00
Mark Baker 6a190d650c
Merge branch 'master' into Issue-2678_Update-CF-Ranges-and-Conditions-on-Insert/Delete 2022-03-17 11:52:57 +01:00
MarkBaker 6faf828db7 Fix issues with updating Conditional Formatting when inserting/deleting rows/columns
- Update existing ranges, expanding if necessary, rather than trying to clone for each individual cell
 - Update conditions, so that cell references and formulae are maintained correctly

Note that absolute as well as relative cell references should be updated in conditions
2022-03-17 11:37:15 +01:00
oleibman 9428552d94
Add editAs Property for 2-cell Anchor Drawings (#2674)
* Add editAs Property for 2-cell Anchor Drawings

This change builds on PR #2532 (@naotake51 as PR #2532), using ideas from PR #2237 (@AdamGaskins), which has had changes requested for several months. It covers a lot of the same ground as 2532. In Excel, two-cell anchor drawings can be edited as "twocell", "onecell", or "absolute". This PR adds support for those options, with a sample file that demonstrates the difference in addition to unit tests. Several other tests are added to improve the spotty coverage for Drawings.

There have been several other tickets referencing two cell anchors, including issue #1159 and PR #1160 (@sgarwood, who also added support for editAs), PR #643, and issue #126, all now closed but not necessarily entirely resolved. I will try to ensure that those tickets are addressed with this one.

And, in trying to make sure 1160 is covered, I stumbled upon a bug. If you use the same image resource to create two+ memory drawings, the MemoryDrawing destructor for the first will cause the rest to generate a very long warning message. This is not a problem for Php8+, only for Php7-. I have suppressed the message in the MemoryDrawing constructor. 1160 went stale due to an unresolved test error, but I don't think this was the problem. At any rate, its test works now.

* Scrutinizer

It reported 1 minor issue (fixed normally), and 2 major. One is fixed with a kludge. The other is a case where Scrutinizer's analysis is just wrong, and I can't figure out a kludge. But I was able to add an annotation (the first time I've managed to get one past phpcs/php-cs-fixer). We'll see.
2022-03-16 16:12:38 -07:00
MarkBaker ec15c7a6de more minor tweaks 2022-03-16 23:03:19 +01:00
MarkBaker 4881e2ae9e Validte that lookup arrays are actually arrays 2022-03-16 21:30:19 +01:00
MarkBaker 4bc3ed9cc1 Provide $includeAbsoluteReferences option for the CellReferenceHelper when updating cell addresses 2022-03-16 19:14:50 +01:00
MarkBaker bbe6b8082e Some additional unit tests for the ReferenceHelper
And a bugfix when deleting cells that contain hyperlinks (the hperlinks weren't being deleted, so were being "inherited" by whatever cell moved to that address)
2022-03-16 16:38:08 +01:00
MarkBaker 6f84780bb9 Some work on refactoring the ReferenceHelper to extract the logic for updating cell references. This is a preliminary step toward allowing updates to absolute cell references, required to update Conditional Formatting rules. 2022-03-16 14:07:13 +01:00
MarkBaker cb5a451aaf Initial work on Reading Conditional Formatting from Xls files 2022-03-15 13:25:23 +01:00
MarkBaker 750e42c024 More refactoring of the reference helper; and unit tests to validate insertion/removal of rows/columns from an autofilter range 2022-03-13 21:13:24 +01:00
aswinkumar863 d82c01e729
Merge branch 'PHPOffice:master' into Table-for-Xlsx 2022-03-12 15:28:51 +05:30
oleibman 68158c8120
Phpstan Differences from Php7 to Php8, Again (#2665)
These changes have already been implemented twice, and been regressed twice. I'll try once more (with a different approach), then give up ...

As configured, Phpstan running under Php7 reports no errors. However, running under Php8, it reports 100 (!) errors. The vast majority of these are due to two reasons:
- renaming parameters in Php builtin functions in preparation for named parameters.
- using the new class GdImage rather than type resource as the argument type for many image-based functions.

Regardless of the cause, this will be a problem sooner or later. This PR is an attempt to get ahead of that problem. For source members, it mostly adds annotations or updates doc-blocks. Only 2 members have changes to executable code, and these are very minor - BitWise and Writer/Xlsx. For test members, all baseline errors are deleted and the code is fixed. Php7 and Php8 both report no errors with this configuration.
2022-03-11 23:28:30 -08:00
aswinkumar863 92a50d134f
Format as Table for Xlsx
Initial implementation of Excel's tables feature (i.e. Select Home >
Format as Table in Excel App).

Tables are similar to AutoFilter but tables have other advantages like
named ranges, easy formatting, totals row and header row with filter.
Tables can also be converted to charts and pivot tables easily.

Usage:
$table = new Table();
$table->setName('Sales_Data');
$table->setRange('A1:D17');
$spreadsheet->getActiveSheet()->addTable($table);

In this Commit:
- Added Table API with initial support for header and totals row.
- Added complete styling options for Table.
- Added Xlsx Writer for Table.
- Added samples.
- Covered with unit tests.

To be done:
- Filter expressions similar to AutoFilter.
- Precalucate formulas for totals row (Check sample 2).
- Table named ranges in formulas and calculation.
2022-03-10 19:54:45 +05:30
naotake51 572f4e94bd
Add two cell anchor drawing (#2532)
* Add two cell anhor drawing.

* Add "Support for two cell anchor drawing of images." to CHANGELOG.md

* Add pull-request link to "Support for two cell anchor drawing of images." of CHANGELOG.md
2022-03-09 19:21:47 -08:00
oleibman bd2e7b64a6
Handle Booleans in Conditional Styles (#2654)
You can set up a conditional style to, say, apply to cells equal to boolean values. For such conditions, the Excel XML specifies `TRUE` or `FALSE`. It is noteworthy that false matches empty cells as well as FALSE, but not 0; similarly TRUE does not match 1. The Xlsx Writer just casts these values to string, which will not work properly. The Xlsx Reader treats the values as strings, so it won't work properly either. This PR corrects both. Also the doc blocks in Style/Conditional allow bool in some places, but not in others; these are corrected but no executable code is changed there.
2022-03-09 18:30:57 -08:00
MarkBaker 044836b426 Unit test for the Calculation Engine debug log 2022-03-06 09:47:17 +01:00
MarkBaker dbf25f0721 Set Selected Cells for Worksheets in Gnumeric Loader 2022-03-05 19:24:21 +01:00
MarkBaker cba0e13b2a Escape double quotes in a string value unless it's an empty string value 2022-03-05 12:44:44 +01:00
Mark Baker dd981a3d77
Merge branch 'master' into CSV-Reader-Dataype-casting-improvements 2022-03-04 14:25:37 +01:00
oleibman e87be5e16d
Failing Test Requiring Too Much Precision (#2647)
The new array tests for IMCSC fail on my system because of a rounding error in the 14th (!) decimal position. This is not a real failure. Change the test to use only the first 8 decimal positions.
2022-03-04 00:11:04 -08:00
MarkBaker aad91f1d25 Merge branch 'master' into CSV-Reader-Dataype-casting-improvements
# Conflicts:
#	src/PhpSpreadsheet/Reader/Csv.php
2022-03-02 12:43:19 +01:00
MarkBaker f3d5028518 Work on setting up locale-aware formatted number conversion for the Csv Reader
Unit tests for locale-aware boolean conversion for Csv Reader
2022-03-02 08:53:29 +01:00
oleibman f575d2b8b2
Add Ability to Suppress Mac Line Ending Check for CSV Reader (#2623)
With the deprecation of `auto_detect_line_endings` in Php8.1, there have been some tickets (issue #2609 and PR #2438). Although the deprecation message is suppressed, users with a homegrown error handler may still see it. I am not very concerned about that symptom, but I imagine that there will be more similar tickets in future. This PR adds a new property/method to Reader/CSV to allow the user to avoid the deprecated code, at the negligible cost of being unable to read a CSV with Mac line endings even on a Php version that could support it.
2022-03-01 02:01:37 -08:00
oleibman 8258919d72
Phpstan Differences from Php7 to Php8 (#2631)
These changes were already implemented as PR #2428. They were, alas, regressed by PR #2585. If at first you don't succeed ...

As configured, Phpstan running under Php7 reports no errors. However, running under Php8, it reports 100 (!) errors. The vast majority of these are due to two reasons:
- renaming parameters in Php builtin functions in preparation for named parameters.
- using the new class GdImage rather than type resource as the argument type for many image-based functions.

Regardless of the cause, this will be a problem sooner or later. This PR is an attempt to get ahead of that problem. For source members, it tweaks only the Phpstan configuration files, without changing any PhpSpreadsheet code. For the small number of test members involved, the code is fixed. Php7 and Php8 both report no errors with this configuration.

Because this involves no changes to code, and because Phpstan baseline is a common cause of merge difficulties, I will probably merge this in a day or two, more quickly than I customarily do.
2022-03-01 01:53:12 -08:00
MarkBaker 99f488efc6 Resolve `translateSeparator()` method to handle separators (row and column) for array functions as well as for function argument separators; and cleanly handle nesting levels
Note that this method is used when translating Excel functions between en and other locale languages, as well as when converting formulae between different spreadsheet formats (e.g. Ods to Excel)

Nor is this a perfect solution, as there may still be issues when function calls have array arguments that themselves contain function calls; but it's still better than the current logic
2022-02-27 13:01:09 +01:00
MarkBaker 444d0fd77c Unit tests for merge ranges for Ods Reader/Writer 2022-02-26 22:51:15 +01:00
MarkBaker ef4029df63 Refactor ISO data type validation from cell to shared date; add extra checks for invalid dates; and appropriate unit tests 2022-02-26 14:13:12 +01:00
oleibman 9cf526a920
Reading Xlsx With Supplied Palette (#2595)
Fix #2499, which see for details of an obscure problem affecting both PhpSpreadsheet and Excel. Add support for palette contained in workbook styles. This seems to be a very rare occurrence, so allow it only when the palette contains exactly 64 entries. If there are other possibilities, we'll presumably have a new workbook to guide us how to handle them. Also add some tests for specification of indexed color without palette, another rarity (no in-range examples amongst our current files). Also change one private static array, initialized once at run-time and never changed, to a constant.
2022-02-23 22:09:22 -08:00
Thorsten Ho 0cb60a5098
Fix XLSX broken vertical align font style (#2619)
* Fix XLSX broken vertical align font style

* Add fix information to changelog

* Fix phpcs issues
2022-02-23 20:23:59 -08:00
Mark Baker 579145eb3c
Wrap actual file loading in protected methods, while just providing a stub `load()` method in the BaseReader abstract. This is to allow a wrapper in the file loader logic across all Readers, with a try/catch block that can be used to handle special loader settings. (#2620) 2022-02-23 21:31:57 +01:00
Mark Baker 16953e27d8
Adjust Cell Reference regexp in Calculation Engine to handle worksheet names containing quotes (#2617)
* Capture of worksheet name in Calculation Engine cell references modified to handle apostrophe and quote marks, and made non-greedy to avoid ensure that multiple quoted worksheet names in a formula aren't all captured in one go

* Split some of the unit tests into separate test classes
2022-02-22 15:55:59 +01:00
Mark Baker 3c57d9e291
Fix for issue #2614 (#2615)
* Fix for issue #2614

* Unit test (in ISREF() tests) that covers issue #2614
2022-02-22 09:06:10 +01:00
Mark Baker c9f948bd91
Initial work on implementing Array-enabled for the HLOOKUP() and VLOOKUP() functions (#2611)
* Initial work on implementing Array-enabled for the HLOOKUP() and VLOOKUP() functions

* In the MATCH() function, we should also use `evaluateArrayArgumentsIgnore()` because the lookupvalue and matchType arguments can be array arguments, but lookupArray is always a dataset matrix
2022-02-21 19:56:21 +01:00
Mark Baker db21d043fe
Implementation of the ISREF() information function (#2613) 2022-02-21 18:47:23 +01:00
Mark Baker 0ee4d96576
Array-enable the ISFORMULA() function (#2610)
Implement Array-enabled for  ERROR.TYPE() function
Extract ERROR.TYPE() function tests into separate test file
Extract error function tests into separate test files

And thus complete the implemented Information functions
2022-02-20 19:32:13 +01:00
Mark Baker 35b65bef8c
First steps toward array-enabling the information functions (#2608)
* First steps toward array-enabling the information functions

Also includes moving unit tests out from Functions and into a separate, dedicated Information folder

* Resolve issue with IF(), branch pruning and calculation cache (ensure that we don't convert the if condition to a bool before we've tested to see if it evaluates to an error)
More refactoring
2022-02-20 16:46:25 +01:00
oleibman 9893926ff9
Add Test For NULL=0 (#2607)
Fix #2523. This isn't actually a fix; the problem was reported and confirmed for 1.21, but had already been fixed in master (and remains fixed in 1.22). This PR just adds a unit test for the original problem.
2022-02-19 13:12:44 -08:00
Mark Baker 71927f5591
Issue 2551 array enable lookup ref functions (#2606)
* Start work on array-enabling the Lookup and Reference functions

Requires a new method (`evaluateArrayArgumentsSubsetFrom()`) in the `ArrayEnabled` Trait to handle functions where the arguments that need special array handling are trailing rather than leading arguments
2022-02-19 18:49:01 +01:00
Mark Baker c10d86eb9c
Start work on array-enabling the Lookup and Reference functions (#2602)
* Start work on array-enabling the Lookup and Reference functions

Requires a new method (`evaluateArrayArgumentsSubsetFrom()`) in the `ArrayEnabled` Trait to handle functions where the arguments that need special array handling are trailing rather than leading arguments
2022-02-19 18:36:50 +01:00
Mark Baker d5dc58d20e
Extract information functions (#2605)
* Split Information functions into a dedicated class and namespace and categorise as Value or Error
* Refactor all error functions into the new ExcelError class
2022-02-19 13:53:17 +01:00
Mark Baker 9c473682bc
Set precision for Database function unit tests, for RowColumnReference and Dimension Helper unit tests (#2604) 2022-02-18 21:37:26 +01:00
Mark Baker 0371ccb686
Convert all relevant Logical functions to support array arguments (#2600) 2022-02-18 02:56:23 +01:00
Mark Baker e580f10c46
Unit test some basic arra-formula chaining (#2599) 2022-02-17 19:37:40 +01:00
Mark Baker 03993bce05
The last big block of Engineering functions; those involving complex numbers (#2597) 2022-02-17 15:17:33 +01:00
Mark Baker ef839f56be
Get started with array-enabling the Engineering functions - Erf, Bessel, bitwise, comparisons Unit of Measure and Number base conversions first (#2594) 2022-02-16 18:32:07 +01:00
Mark Baker cdbe5c7c9b
Converting Statistical functions to be array-enabled (phase #2) (#2593) 2022-02-15 20:34:39 +01:00
Mark Baker f1cb75eaec
Start work on Array-enabling the Statistical functions (#2588) 2022-02-15 14:41:17 +01:00
Mark Baker e3b7cb5f9d
I'm ignoring SUMIF() and SUMIFS() for the moment; so this should complete all the applicable Math/Trig functions;so the subset SERIESSUM() function and RANDBETWEEN() should complete Math/Trig (#2586) 2022-02-13 12:50:05 +01:00
Mark Baker 8f3c52a3cf
Enable array-readiness for more Math/Trig functions (#2584)
* Enable array-readiness for more Math/Trig functions; CEILING() FLOOR() (and variants), TRUNC(), BASE() and the various Logarithms
* Minor refactoring
2022-02-12 20:47:47 +01:00
Mark Baker 5d88c6b534
Merge branch 'master' into Issue-2551_Enable-Array-Readiness-for-Functions-Maths 2022-02-12 17:11:45 +01:00
MarkBaker 75213f5ee1 Enable array-readiness for more Math/Trig functions 2022-02-12 16:56:06 +01:00
Orkhan Ahmadov 0eeba6dc0c
`ReferenceHelper@insertNewBefore` checks for missing coordinates before replacing values (#2541)
* ReferenceHelper@insertNewBefore now changes for missing columns before replacing and deleting columns

* Changelog updated

* Fixed code style

* Added assertion for all cells. Change bugfix implementation to use `createNewCell` on Worksheet

* Additional assertions
2022-02-12 07:08:11 -08:00
oleibman 5bf0656e92
Xlsx Reader Warning When No sz Tag for RichText (#2550)
Fix #2542. Xlsx Reader is expecting a `sz` tag when reading RichText, but it is not required, and PhpSpreadsheet issues a warning message when it is missing.
2022-02-12 06:43:29 -08:00
MarkBaker b3ff2e347f All Text functions made array-ready 2022-02-12 12:22:31 +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
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
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 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
Mark Baker d0965298d5
Additional unit tests for RANDARRAY() Math/Trig function implementation (#2563) 2022-02-07 10:19:19 +01: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
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
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 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 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
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
oleibman 1509097e84
Recalibrate Row/Column Dimensions After removeRow/Col (#2486)
Fix #2442. Although data and styles are handled correctly after removing row(s) or column(s), the dimensions of the removed rows and columns remain behind to afflict their replacements. This PR will take care of removing the dimensions as well.

Dimensions has a _clone method for a deep clone, but all of its properties, as well as the properties of RowDimensions and ColumnDimensions, are scalars, and do not require a deep clone. The method is deleted.
2022-01-13 19:06:22 -08:00
oleibman 8ab834520d
Handle Explicit "Date" Type for Cell (#2485)
Fix #2373. Excel can handle DateTime/Date/Time as a string if the datatype of the cell is set to "d". The string is, apparently, supposed to follow the ISO8601 spec. Openpyxl can be configured to generate a file with such values, so I've added support and set up unit tests. Excel, naturally, converts such a string input into its numeric representation of the date/time stamp. So will PhpSpreadsheet, so a call to setValueExplicit specifying Date format will actually see the cell wind up with Numeric format - there is no way (and no reason) for the Date type to 'stick'.
2022-01-13 18:40:18 -08:00
Mark Baker b13b2a0d59
Allow single-cell checks on conditional styles, even when the style is configured for a range of cells (#2483)
* Allow single-cell checks on conditional styles, even when the style is configured for a range of cells
2022-01-05 13:39:50 +01:00
oleibman 7d71a7ca54
New Error Reported with Phpstan 1.3 (#2481)
* New Error Reported with Phpstan 1.3

Dependabot opened a number of PRs. Most are successful, but this change is necessary to allow PR #2477 to complete successfully, and that is apparently a necessity for PR #2479.

Phpstan 1.3 objected to:
```php
trigger_error($errorMessage, E_USER_ERROR);
return false;
```
It claims the return statement is unreachable. This isn't precisely true - an error handler might allow the return to be reached. At any rate, I have slightly restructured the code so that Phpstan will not object either with 1.2 or 1.3, which should allow the blocked PRs to succeed. There had been no previous tests for what happens when there is a formula error when suppressFormulaErrors is true.

* Scrutinizer

Didn't like effect of changes which Phpstan liked. Hopefully this will work better.

* Improvement

Eliminate added function.
2022-01-03 17:32:52 -08:00
oleibman f24dcc7911
Another Undefined Index in Xls Reader (#2470)
Fix #2463. These continue to dribble in regularly.
2021-12-31 13:43:59 -08:00
oleibman 5d1ab39def
Replace Tests With Unneeded Mocking (#2465)
Replace mock tests with real ones when possible. The original tests are all still present; they just take place in a more representative scenario.

After this, there will be 4 remaining uses of mocking. Of these, 3 are needed for scenarios which are otherwise hard to test - WebServiceTest, CellsTest, and SampleCoverageTest. For the other one, AutoFilterTest, I just can't figure out what it's trying to accomplish, so have left it alone.

This change is almost entirely restricted to tests. There is a one-line change in src. When the first argument passed to OFFSET is null or nullstring, the returned value is currently 0. However, according to the documentation for Excel, it should be `#VALUE!`. The code is changed accordingly.
2021-12-31 13:24:43 -08:00
oleibman 07271c83aa
Rename Two Test Files (#2459)
* Rename Two Test Files

When I run unit tests only for Reader/Xlsx, phpunit is issuing a deprecation message because the names of 2 files have an extra dot in them and thus don't match the class name in the file. I do not see these warnings when I run the entire test suite.

* Remove Phpstan Annotations

It was a bit difficult to handle a cast from mixed to string.

* Fix Same Phpstan Problem in One Other Test

This is the only other test case that tries to cast mixed to string.
2021-12-25 09:05:54 -08:00
oleibman f2b2f07ec3
Null Passed to AutoFilter SetRange (#2454)
* Null Passed to AutoFilter SetRange

Fix #2281. Delete auto filter set range to null, but should set it to null string. This causes a deprecation warning in Php8.1.

* Constructor Call Also Sets Range to Null

Should set it to null string.
2021-12-25 08:45:10 -08:00
oleibman 3a6558625d
General Style Specified in Uppercase in Input Xlsx (#2451)
* General Style Specified in Uppercase in Input Xlsx

Fix #2450. Treat input style GENERAL as if it were expected upper/lowercase.

* Declare Method as Static

Surprised neither Phpstan nor Scrutinizer flagged this.

* Remove Duplicated Statement

Don't know why Scrutinizer didn't flag this the first time.
2021-12-18 09:25:08 -08:00