1127 Commits

Author SHA1 Message Date
MarkBaker 0ebbb3297d Allow use of # and 0 digit placeholders in fraction masks 2023-02-25 12:48:53 +01:00
oleibman 324e19035f Xls Reader Conditional Styles (#3400)
The code currently allocates the style object as a non-conditional style, leading to corruption when the spreadsheet is written out.

That being said, Font Color is the only Conditional Formatting I have gotten to work for Xls for read or write. Use of other styles will essentially continue to be ignored, but will at least no longer result in corrupt spreadsheets.
2023-02-24 18:11:38 -08:00
MarkBaker 6409af4dcc When a Worksheet has an AutoFilter, make allowance for Center Alignment in the filter heading when calculating AutoFit column widths. 2023-02-24 21:24:46 +01:00
oleibman ab420f4499 Coerce Bool to Int for Mathematical Operators on Arrays (#3392)
* Coerce Bool to Int for Unary Operation on Arrays

Fix #3389. It seems some functionality was left behind when JAMA was eliminated (PR #3260). In particular, it is apparently a known trick to use double negation on boolean values as arguments to functions like SUMPRODUCT.

* Fix 3396

Treat booleans in arrays as int for mathematical operators as well.

* Edge Case

When array operand was neither numeric nor boolean, PhpSpreadsheet had always been evaluating the operand as #NUM!. It will now propagate an error string like #DIV/0!, and treat non-error strings as #VALUE!, consistent with Excel.
2023-02-23 23:11:22 -08:00
oleibman 6925b7f621 Conditional Formatting Improvements for Xlsx (#3372)
* WIP Conditional Formatting Improvements for Xlsx

Fix #3370. Conditional styles are always generated with 5 borders (right, left, top, bottom, diagonal) even though the border style is none in each case. For the spreadsheet in question, top and bottom were inappropriate and interfered with the desired formatting. A new border style, BORDER_OMIT is added which will cause the Xlsx Writer to not generate that style. All conditional borders will be initialized with that value. Any border included in the Xml will, of course, change it to the specified type.

Fix #3202. User wants a condition to use "No format set" as you can in Excel. A new boolean property `$noFormatSet`, along with setter and getter, is added to Style/Conditional. It is initialized to false. User can call setter to change it. More importantly for the issue in question, if the Xlsx Reader encounters a `cfRule` tag which does not have a `dxfId` attribute (i.e. no style is associated with the rule), it will set noFormatSet to true. Similarly, the Xlsx writer will not generate a `dfxId` tag when noFormatSet is true.

This change is applicable only to Xlsx. Html, Csv, and Ods do not have support for Conditional Formatting. Limited support was added to Xls with PR #2696 in April 2022 and PR #2702 about a month later. However, with the current release code, Xls equivalents of the two new test spreadsheets in this PR are too complicated to be handled correctly by PhpSpreadsheet - loading and then saving them as Xls results in Excel complaining of corruption, and the results don't meet expectations. Since I have no idea how BIFF works, and since the problems with those spreadsheets are not caused by this PR, I am not planning to address those problems at this time.

* Update Documentation, Write Alignment and Font Less Often

It doesn't cause any particular harm except for small increases in file size and run time, but Alignment tags are written even when (a) all its attributes are null for Conditional Formatting, and (b) when the xml specifically indicates that Alignment should not be applied. Similarly, Font is written even when all its attributes are null for Conditional Formatting.

There are some errors in the Conditional Formatting documentation. Specifying a solid fill color in a Conditional Style requires the use of endColor, not StartColor. The discussion of Order of Evaluating is not entirely accurate. I have changed it to what I believe is an accurate explanation of how Excel works; and also added a mention that other spreadsheet programs might not work the same way, adding a couple of illustrations of the difference. The description of the multiple conditions did not quite match the diagram. 'Stop if true' was a blank paragraph; it is now described, and the new 'No format set' option is described in that paragraph since (I think) it would be used most often in conjunction with 'Stop if true'.

* Xlsx Writer Allow StartColor for Conditional Solid Fill

To set a solid fill in a non-conditional style, you set StartColor (xml will use that value as fgColor and a default value as bgColor). If you instead set EndColor (xml will use that value as bgColor and a default value as fgColor), the styling will not work as expected.

However, for conditional styles, if you set StartColor (xml will use that value as fgColor and not specify bgColor), the styling will not work as expected. If you instead set EndColor (xml will use that value as bgColor and not specify fgColor), the styling will work as expected.

Together, this means that you need to use different methods for non-conditional style fill than for conditional style fill. This isn't a big problem, but it is a bit weird. This PR changes Xlsx Writer so that if (a) fill is olid and (b) startColor is specified and (c) endColor is null, the xml will be written as bgColor without specifying fgColor. This means that you can set StartColor for both conditional and non-conditional and get the expected styling. You may, of course, continue to specify EndColor instead for conditional.

* Fix Some (Not Many) Xls Problems

I will open an issue for the (pre-existing) remainder.
2023-02-23 22:28:22 -08:00
oleibman 378beac8f2 Xls Writer Parser Handle Boolean Literals as Function Arguments (#3391)
Fix #3369. The parser had failed to account for `TRUE` and `FALSE` when supplied as arguments to a function.

I had hoped to be able to do something about its inability to handle defined names as well. I failed. I think another section might need to be added to the Writer output which specifies the defined names. I haven't yet located any suitable documentation.
2023-02-23 10:54:54 -08:00
MarkBaker f468e78b66 Improved handling for ? placeholder in Number Format Masks 2023-02-22 12:55:21 +01:00
MarkBaker e812b49bb6 Additional unit tests for scaling values in Number Format Masks 2023-02-21 13:20:23 +01:00
MarkBaker 5cf4e2cca1 Fix handling for a # symbol in quotes inside a number format mask 2023-02-21 03:17:08 +01:00
oleibman ac1172810e Another Xls Coverage Change (#3385)
I hadn't noticed some minor corruption in a file. It is fixed. Xls now supports BAHTTEXT as _xlfn.BAHTTEXT, not as an index to a list of built-in functions, so it is no longer suitable for this test and is removed from the spreadsheet. TRANSPOSE changes, e.g. A1:B2 to {1,2;3,4}, and the Xls Writer Parser has trouble with that, so its test is also removed from the test spreadsheet.
2023-02-20 12:15:22 -08:00
MarkBaker 207d029c26 Allow use of an explicit 0 for a decimals value when using Currency and Accounting Number Format Wizards with a locale, to indicate whole currency units only, no minor units 2023-02-20 18:34:59 +01:00
oleibman 33eefe7c9d Resolve Phpstan Messages - FINALE - Shared/OLE (#3364)
* Resolve Phpstan Messages - FINALE - Shared/OLE

Reduce number of Phpstan messages by addressing their issues. This is the last of a series of related tickets to achieve that end. Only a handful of messages will be left in Phpstan baseline after this change is merged.

Shared/Ole.php and Shared/Ole/ChainedBlockStream.php were completely uncovered in the test suite. So I wrote some tests and found they didn't work at all. There were 2 problems. The first was that ChainedBlockStream checks for a mode of `r`, but Ole invokes it with mode `rb`. ChainedBlockStream will now just check the first character of the mode.

The second was a more interesting problem. Ole was reading "an *unsigned* long". However, what it should have been reading was "a 32-bit *signed* long". The irony of this mismatch is that, once the mode problem was corrected, 32-bit Php handled Ole and ChainedBlockStream correctly, but 64-bit Php did not. The code is corrected to work properly for both 32- and 64-bit.

* Scrutinizer

2 dead assignments - sufficient to just make calls which are expected to fail.
2023-02-20 06:40:02 -08:00
oleibman 28fb962cdb Complete Functions Coverage for Xls (except GETPIVOTDATA) (#3383)
Finish the work started in PR #3371 and PR #3340.
2023-02-20 06:07:12 -08:00
MarkBaker c0b60fcb76 Issue 3381 - Fix decimal precision for Scientific Number Format Mask 2023-02-20 12:20:49 +01:00
MarkBaker 431bd5178e Adjust identifier for Date Format Masking to prevent it picking out currencies with locales containing the letters h, m, s, d and y as dates 2023-02-18 17:46:23 +01:00
MarkBaker 292dd9073f Adjust CURRENCY_USD and CURRENCY_EUR constants to rationalise and eliminate quoted currency symbols in favour of bracketed symbols 2023-02-18 01:39:29 +01:00
MarkBaker f9ef1e0e7d Additional unit tests 2023-02-17 13:29:21 +01:00
MarkBaker 6ca7ec5d5b Make boolean check case-insensitive 2023-02-17 13:14:20 +01:00
MarkBaker 5072ffb23a Improve support for locale settings and currency identification in the Advanced Value Binder 2023-02-17 12:37:18 +01:00
MarkBaker 3d7964f568 Improve support for locale settings in the Calculation Engine formatted number matcher 2023-02-17 08:03:28 +01:00
MarkBaker 4aaf1f61b9 Allow a range of different potential currency codes (including the locale code) in the currency matcher regexp
(dollar, euro, pound sterling and yen)
2023-02-17 06:16:10 +01:00
oleibman df9e0da514 Additional Functions Coverage for Reader Xls (#3371)
PR #3340 increased coverage in Reader Xls for most functions. Some of the omissions from that PR (see below) were intended from the start. However, the set of (BINOMDIST, EXPONDIST, GAMMADIST, NORMDIST, POISSON, WEIBULL, and FIXED) were not intended to be omitted; they just did not seem to work. Having had time to research, it appears that the problem is not those functions themselves, but rather the use of Boolean constants as function arguments (see issue #3369). Knowing that, it is possible to add those missing functions back in, just taking care to use `0` or `1` or `TRUE()` or `FALSE()` rather than boolean constants as arguments. No update to source or test code; just adding a few new cells to an Xls spreadsheet.

Functions still omitted because they return array results:
- GROWTH
- LINEST
- LOGEST
- MINVERSE
- MMULT
- TRANSPOSE
- TREND

Functions still omitted because they are not implemented in PhpSpreadsheet:
- BAHTTEXT
- CELL
- FREQUENCY
- GETPIVOTDATA
2023-02-15 22:21:15 -08:00
oleibman 8df86e4236 Add Tests for Shared XmlWriter (#3365)
Fill in some very minor coverage gaps.
2023-02-14 21:38:06 -08:00
MarkBaker b40e131b78 Allow override of the Value Binder when setting a Cell value 2023-02-14 10:13:35 +01:00
Mark Baker 1bcb86c450 Merge branch 'master' into Issue-3356_AutoFit-for-Table-AutoFilter 2023-02-12 02:42:27 +01:00
MarkBaker afa64508cc Unit Tests for AutoSizing columns 2023-02-12 02:29:02 +01:00
oleibman 545fc89d8f Resolve Phpstan Messages Reader/Xls Shared/Escher (#3355)
* Resolve Phpstan Messages Reader/Xls Shared/Escher

Reduce number of Phpstan messages by addressing their issues.

* Scrutinizer

Hyperactivity.

* More Scrutinizer

Getting close.

* Even More Scrutinizer

Closer and closer.
2023-02-11 17:21:19 -08:00
MarkBaker 6b1538f9f0 Let column width calculation return a float 2023-02-11 21:23:22 +01:00
oleibman 4e09fd407d Permit Max Column for Row Breaks (#3345)
* Permit Max Column for Row Breaks

Fix #3143. Page break was dropped. Difference between good and bad was the use of attribute `max` in `brk` tag in the good spreadsheet. However, `max` was *not* required in a similar spreadsheet. So the reason for the problem isn't completely explained. Nevertheless, it can't really hurt to capture the `max` value on read (if present) and generate it on write. This resolves the issue. User is also permitted to specify max column when setting a row break programatically. I am not yet in position to document when that might be a good idea.

* Case-sensitive Directory Name

Not a problem on my Windows system.

* Update Documentation and Add Tests

Change is necessitated by probable Excel bug.

* Unhappy With Initial Implementation

I kind of shoe-horned it in. Better to create a new PageBreak class, which will make it easier to accomodate any future surprises about page break handling. The only difficulty with the new approach is making sure getBreaks maintains backwards compatibility. New tests will ensure that.
2023-02-11 07:44:14 -08:00
oleibman b1c754f04b Correct Some Scrutinizer Messages (#3354)
They have crept in recently.
2023-02-09 23:12:22 -08:00
MarkBaker a6083e7a64 Additional Unit Tests 2023-02-09 18:03:17 +01:00
MarkBaker 598890be6c Resolve cs issues 2023-02-09 12:20:29 +01:00
Mark Baker 159e7c5997 Merge branch 'master' into master 2023-02-09 11:52:47 +01:00
MarkBaker 8c91bd6942 Additional exception handling to prevent a cell containing an invalid formula from breaking isDateTime() 2023-02-07 18:04:37 +01:00
fjohnston@avatarasoftware.com 67dd292028 Unit tests for issue #3337
Added two unit tests for issue #3337: one that includes the xlfn prefix, and one that does not.  These tests will ensure that the prefix is being added, when appropriate, within an array formula.
2023-02-06 14:15:56 -05:00
oleibman 590e4c7af1 Allow More Fonts/Fontnames for Exact Width Calculation (#3326)
* Allow More Fonts/Fontnames for Exact Width Calculation

Fix #3190. A limited set of explicitly-named font files can be used when an exact width calculation is required. User noted that font files are named differently on Mac than on Windows (if the fonts are installed on Linux, the font names probably match Windows). Since the algorithm for generating the Mac file name from the font name seems easy, that algorithm is invoked when the Windows-named file is not found.

Moving on from there, it seems odd that only a small set of fonts are supported. It is, of course, impossible to support all possible fonts out of the box. However, it is possible to allow the user to supply additional mappings from font name to file name (or override existing mappings if neither the Windows nor Mac name matches the user's system), and doing so is permitted with this change:
```php
        \PhpOffice\PhpSpreadsheet\Shared\Font::setExtraFontArray([
            'fontname' => [ /* More than 1 can be specified */
                'x' => 'fontfilenamefornormal.ttf',
                'xb' => 'fontfilenameforbold.ttf',
                'xi' => 'fontfilenameforitalic.ttf',
                'xbi' => 'fontfilenameforbolditalic.ttf',
            ],
        ]);
```

* Unexpected Test Difference

... between Windows and Linux.
2023-02-04 07:25:31 -08:00
MarkBaker edc003ad16 Improved handling of @ format mask
Note that it still doesn't work fully if in section 4
2023-02-04 12:54:19 +01:00
Mark Baker 777a230765 Merge branch 'master' into NumberFormat_Wizards 2023-02-03 17:29:43 +01:00
MarkBaker e2c5014c43 Wizards for defining Number Format masks for Numbers, Percentages, Scientific, Currency, and Accounting 2023-02-03 17:14:28 +01:00
oleibman a2282ecb79 Additional Coverage for Reader Xls (#3340)
* Additional Coverage for Reader Xls

More than 750 lines are newly covered, increasing overall coverage on my machine from 91.14% to 93.09%.

* Update FormulasTest.php
2023-02-03 07:42:43 -08:00
MarkBaker c47af2a344 Support for fixed value divisor in fractional Number Format Masks 2023-02-02 12:00:50 +01:00
MarkBaker ea3be3b53b Unit tests for evaluation of defined name with a quote-prefixed cell 2023-02-01 21:10:19 +01:00
oleibman 889ad85b84 Resolve Phpstan Messages in Reader Ods (#3324)
* Resolve Phpstan Messages in Reader Ods

Reduce number of Phpstan messages by addressing their issues.

* Update HiddenMergeCellsTest.php
2023-02-01 08:52:26 -08:00
oleibman cc347fd1c8 Resolve Phpstan Messages in IOFactory and Several Readers (#3319)
Reduce number of Phpstan messages by addressing their issues. Reader/Ods will require a separate ticket. Reader/Xls will require many separate tickets.
2023-01-31 15:19:58 -08:00
Jonathan Goode fc8966e38d Support for configuring a Chart Title's overlay (#3325)
* Update PR template

* Trim trailing space

* Support for configuring a Chart Title's overlay

* Provide test coverage for getting/setting a Chart Legend's overlay
Add missing docblock
2023-01-30 18:37:18 -08:00
oleibman 1cdc6cd2fb Breaking Change to toFormattedString and 3 toArray Methods (#3304)
* Breaking Change to toFormattedString and 3 toArray Methods

DocBlock says `toFormattedString` returns string, but code can return int, float, bool, null, or RichText. I think the DocBlock is correct (function name clearly indicates "to string"), and the code needs to change to match it. This is not that big a deal on its own. However, some methods in `Worksheet` call this function by default - `rangeToArray`, `toArray`, and `namedRangeToArray`. All 3 can be called with a parameter so that they don't call `toFormattedString`, but, by default, they do call, and so are affected by this change. Some unit test results are changed as a result of this code change. In all those cases, an additional test is added which would match the previous result.

* Update Change Log

I often skip this till later, but, since it's a breaking change ...

* Scrutinizer, Plus Strange Cast to -0

Avoid Scrutinizer complaint by casting string to float, but ... Php decides resulted should sometimes be `-0`? That caused test failures. Very odd.
2023-01-30 00:54:48 -08:00
oleibman a0e6e09557 Resolve Phpstan Messages LookupRef TextData Coordinate ReferenceHelpe… (#3298)
* Resolve Phpstan Messages LookupRef TextData Coordinate ReferenceHelper RichText

Reduce number of Phpstan messages by addressing their issues.

* Scrutinizer

One legitimate observation, one unfathomable false positive.

* Scrutinizer (legitimate)

Reasonable simplification suggestion.
2023-01-27 09:15:08 -08:00
oleibman 8d3097517e Additional Unit Tests for XIRR and XNPV (#3307)
* Additional Unit Tests for XIRR and XNPV

See discussion in issue #3297. Excel result disagreed with PhpSpreadsheet, but it seems apparent that the error is Excel's. Although we have other test cases where Excel and PhpSpreadsheet disagree, those have so far been cases where Excel cannot give an answer because its algorithm does not converge, which is possible for any algorithm. In the issue in question, Excel seems to converge to a different answer; this is different than the other exceptions, and so deserves documentation with a formal test case. The discussion also mentions some cases where XNPV seems to give the wrong result in Excel, and those cases are added for XNPV.

* Scrutinizer

Whatever.
2023-01-24 19:06:22 -08:00
MarkBaker 4b72546050 Option to specify a range of columns/rows for the Row/Column isEmpty() methods 2023-01-23 11:35:19 +01:00
MarkBaker 9a752ef5b3 Provide an option that determines whether Cell Iterators should create a new cell or return a null when they try to access a cell that does not exist 2023-01-21 17:40:30 +01:00