Commit Graph

3170 Commits

Author SHA1 Message Date
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
oleibman a8e179d5d9
Scrutinizer Complains Some Samples Class Name Conflict with Jpgraph (#2684)
Jpgraph does not use namespaces. Neither do the Samples members of this project. As a result, Scrutinizer complains about 13 cases of `use PhpOffice\PhpSpreadsheet\Chart\Legend;`, since this theoretically could cause the use of two different Legend classes in the empty namespace. It suggests using a class alias for Legend, which this PR does in every applicable case. It is a regrettable problem, but it is easy to fix.
2022-03-16 15:59:53 -07:00
oleibman f2f626e02c
Tweak to php-cs-fixer Parameters (#2683)
For a recent change, I removed some errors from Phpstan baseline and instead added annotations in the source members. I did this work incrementally, and was surprised when php-cs-fixer required a change from `// @phpstan-ignore-next-line` to `/** @phpstan-ignore-next-line */`. No problem thinks I, and continue to modify several members using the new convention until php-cs-fixer required a change from `/** @phpstan-ignore-next-line */` to `// @phpstan-ignore-next-line`??? I did as directed, and continued to be surprised for the rest of that ticket.

Having had time to research, the problem is due to two options in the php-cs-fixer config file `'comment_to_phpdoc' => true` and `'phpdoc_to_comment' => true`. It seems that php-cs-fixer is treating these annotations the same as doc-blocks, expecting `/**` before a `structural element`, and `//` otherwise. For the statements where I had questions, it expects `/**` before a statement which you might be able to precede with `/** @var`, and `//` where you would not be able to precede it with `/** @var`. However, in this case, what it is doing is forcing what appear to be inconsistencies between otherwise identical statements, whereas php-cs-fixer is supposed to be supporting consistent syntax throughout the project. This PR changes both options to false, allowing (but not requiring) a consistent syntax for these examples. It contains an example of a change from each format to the other, changes which php-cs-fixer would previously have flagged.

An added bonus for this change is that Scrutinizer annotations can now be added to the code; these were often rejected by php-cs-fixer. These should, of course, be used very conservatively, but there are cases where Scrutinizer's analysis is either faulty or not helpful. This PR takes advantage of the change by adding annotations to eliminate the two existing problems which Scrutinizer classifies as 'Security', problems for which there is no sensible way to satisfy Scrutinizer's complaint.

No executable code is changed by this PR.
2022-03-16 15:34:40 -07:00
Mark Baker 78c27c03ca
Merge pull request #2687 from PHPOffice/Bugfix_Support-Row/Column-Ranges-in-INDIRECT()-Function
Allow `INDIRECT()` to accept row/column ranges as well as cell ranges
2022-03-16 23:16:50 +01:00
MarkBaker ec15c7a6de more minor tweaks 2022-03-16 23:03:19 +01:00
Mark Baker 0b9207a522
Merge pull request #2686 from PHPOffice/Additional-Validations-for-Lookup-Arrays
Validate that lookup arrays are actually arrays
2022-03-16 21:44:24 +01:00
MarkBaker 4881e2ae9e Validte that lookup arrays are actually arrays 2022-03-16 21:30:19 +01:00
Mark Baker 4c1d953897
Merge pull request #2685 from PHPOffice/Refactoring-ReferenceHelper-allow-absolute-cellreference-updates
Provide $includeAbsoluteReferences option for the CellReferenceHelper when updating cell addresses
2022-03-16 19:25:43 +01:00
MarkBaker 4bc3ed9cc1 Provide $includeAbsoluteReferences option for the CellReferenceHelper when updating cell addresses 2022-03-16 19:14:50 +01:00
Mark Baker 251605f9b2
Merge pull request #2682 from PHPOffice/Refactoring-Work-on-ReferenceHelper
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.

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).

Plus some additional unit tests for the ReferenceHelper.
2022-03-16 16:54:00 +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
Mark Baker 09cf6abded
Merge pull request #2675 from PHPOffice/Refactoring-ReferenceHelper
Refactoring work on the ReferenceHelper
2022-03-13 21:26:37 +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
MarkBaker a8d9cd700e Allow deleting of columns beyond the end of data in a worksheet to update references (print area, etc) before early exiting the method 2022-03-13 18:10:28 +01:00
MarkBaker 092f90220e Minor refactoring work
Extact some processes into their own methods, and eliminate some occrrences of multiple duplicated method calls
2022-03-13 13:16:55 +01:00
Mark Baker 004de10f54
Merge pull request #2673 from PHPOffice/Resolve-CF-Issues-with-Xls-Writer
Resolve Conditional Formatting issues with Xls writer
2022-03-13 11:30:25 +01:00
MarkBaker 7101da80a5 Update Change Log 2022-03-13 11:12:59 +01:00
MarkBaker a6e792082b Handle the case of an invalid formula by defaulting to ptgInt + 0, which will avoid breaking the file 2022-03-13 10:53:07 +01:00
MarkBaker 83161de91e Some refactoring to extract the logic for calculating the CF operand tokens and size, to reduce duplicated code 2022-03-13 04:02:05 +01:00
MarkBaker 9ca9d741fe Resolve saving cell references, string literals and formula as values for conditional formatting rules in the Xls file save
The code is ugly as sin; but it works... I'll do some refactoring and cleaning later (once I've had some sleep, because I'm stupidly still working on this at 3am)

The main remaining issue is formulae that can't be parsed in BIFF8 files; e.g. formulae that use functions that aren't available. In this case, all CF in that worksheet is corrupted, and the file errors when opened, so it is a serious issue. The ISODD()/ISEVEN example in 07_Expression_Comparisons.php uses these, so I've temporarily commented out setting that CF range until I've solved that problem. There are other limitations listed in the BIFF documentation; but they're harder to detect.
I've also left a couple of debug statements in the code to display these formula errors: I'll remove them once I've resolved the issue.
2022-03-13 03:05:57 +01:00
MarkBaker 7e89d3397e Resolve problems with writing the CF Header for each group of rules 2022-03-12 21:13:40 +01:00
MarkBaker 762300da47 Ensure that some CF style is displayed in Xls samples, even while background colour is still a problem, so that it's easy to verify that the rule is beng written correctly 2022-03-12 20:54:48 +01:00
oleibman 2cdffeb8ad
WIP Remove + From Mode in BaseWriter (#2657)
BaseWriter openFileHandle opens its output file with mode `wb+`. We don't appear to attempt any reads on the file after it is opened in write mode, so `wb` should be sufficient. This may have been a factor in the need for PR #2326, and is likely to be responsible for issue #2372.
2022-03-11 23:51:59 -08:00
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
Mark Baker c0ea894c27
Merge pull request #2669 from PHPOffice/Issue-2666_Active-Sheet-Index-from-Google-Sheets
Fix for setting Active Sheet to the first loaded worksheet when `bookViews` element isn't defined
2022-03-11 21:50:31 +01:00
MarkBaker b208c52107 Fix for setting Active Sheet to the first loaded worksheet when `bookViews` element isn't defined (e.g. when file is created from Google Sheets) 2022-03-11 21:31:17 +01:00
MarkBaker 1801f582f5 Correction to Change Log 2022-03-10 10:24:28 +01:00
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 ce5f91e6a1
Fix Sample39 (#2664)
Sample39 was not adjusted when Defined Name support was changed to include both relative and absolute addresses. As a result, the Xlsx output is currently incorrect. The Xls output is in even worse shape, since PhpSpreadsheet 'Cannot yet write formulae with defined names to Xls' (see Writer/Xls/Parser.php). (Working around that restriction was the reason for my first contribution to this project.) The sample is changed to define its named ranges properly, and to produce only Xlsx output.
2022-03-09 18:55:31 -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
oleibman 0d5d9eb0ff
Php8.1/Phpstan Problems (#2649)
I made some changes to make our code ready when Phpstan is configured to run on Php8. These were regressed. I reinstalled. All was good for an hour or so till Dependabot pushed a version change for Phpstan. Checking that out, it runs clean on Php7, has 3 errors on Php8.0, and 100 errors on Php8.1. Although that number seems alarming, most of these were caused because Phpstan was reporting the same problem in a trait everywhere it was used, and a single change sufficed to eliminate most of those.

The remainder, some of which caused run-time problems with Php8.1 on my system but which are not yet showing up on Github, are mostly the usual "null supplied where string expected". However, a new problem showed up - `float % 2` gets an "implicit conversion from float to int" warning (and Phpunit issues an extraordinarily long message when this happens). There was also a totally undocumented Php change where `array_combine` throws an exception in Php8 when it would have returned `false` as it does in Php7. These problems are all addressed with very minor changes in this PR.
2022-03-09 18:05:36 -08:00
Mark Baker ee1e56d8e7
Merge pull request #2653 from PHPOffice/CalcEngine-Debug-Log-Test
Unit test for the Calculation Engine debug log; and switch to using `sprintf()` rather than concatenation for debug messages
2022-03-06 11:12:53 +01:00
MarkBaker a8f473e9f4 Switch to using sprintf() rather than concatenation for all calculation engine debug logging 2022-03-06 10:51:54 +01:00
MarkBaker 044836b426 Unit test for the Calculation Engine debug log 2022-03-06 09:47:17 +01:00
Mark Baker ac33bd9010
Merge pull request #2652 from PHPOffice/Gnumeric-Selected-Cells-in-Worksheet
Set Selected Cells for Worksheets in Gnumeric Loader
2022-03-05 19:41:54 +01:00
MarkBaker dbf25f0721 Set Selected Cells for Worksheets in Gnumeric Loader 2022-03-05 19:24:21 +01:00
Mark Baker 86f2684615
Merge pull request #2651 from PHPOffice/Issue-1971_Failing-to-correctly-escape-double-quotes-in-subformulae
Escape double quotes in a string value unless it's an empty string value
2022-03-05 12:50:24 +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 51453db41e
Merge pull request #2650 from PHPOffice/Changelog-Updates
Minor updates to the change log
2022-03-05 11:14:09 +01:00
MarkBaker 16ad02bca8 Minor updates to te change log 2022-03-05 10:56:14 +01:00
Mark Baker 7f79e7a17c
Merge pull request #2644 from PHPOffice/CalcEngine-Refactor-Branch-Pruning
Initial work on refactoring branch pruning logic
2022-03-04 14:53:46 +01:00
Mark Baker c4f79af56d
Merge branch 'master' into CalcEngine-Refactor-Branch-Pruning 2022-03-04 14:40:34 +01:00
Mark Baker 39bba33d00
Merge pull request #2640 from PHPOffice/CSV-Reader-Dataype-casting-improvements
Csv reader dataype casting improvements
2022-03-04 14:39:00 +01:00
Mark Baker dd981a3d77
Merge branch 'master' into CSV-Reader-Dataype-casting-improvements 2022-03-04 14:25:37 +01:00
MarkBaker e243476f77 Initial work on refactoring branch pruning logic 2022-03-04 13:55:06 +01:00
Paul Weidner 23631cb9e5
Correct fill color example in conditional formatting docs. (#2646) 2022-03-04 01:41:21 -08:00
oleibman dade9cc063
Corrupt Sample Output for 20 and 30 (#2648)
Xls Reader can read drawing offsetX and offsetY as float. However, Excel Xlsx (and PhpSpreadsheet) wants them only as int. This leads 20_Read_Xls and 30_Template to produce corrupt Xlsx files for any Php release. Change Xls Reader to treat values as int, eliminating the corrupt files.
2022-03-04 00:51:11 -08:00