Commit Graph

3850 Commits

Author SHA1 Message Date
oleibman 84e4896192 Catch Up Change Log (#3313)
Prior to release 1.27.
2023-01-20 17:41:30 -08:00
oleibman 6443416828 Xls Reader Vertical Break and Writer Page Order (#3306)
Fix #3055. Xls Reader can set vertical break specifying row 0, causing an exception. It is doubtful that Excel needs a row for a vertical break; code is changed to use row 1 if the input file specifies row 0 (or lower). Code in question has not been exercised in unit test suite. Similarly, code to set horizontal break (which probably does not have a bug) is not exercised in test suite. Finally, page order in Writer incorrectly uses value in opposite way that Reader does. A new sample is added to illustrate that these are all handled correctly; it is easier to verify this by visually comparing the source spreadsheet and the copy made from it. A unit test is also added for the same spreadsheet to formally assert that the 3 properties in question are both read and written correctly.
2023-01-20 17:33:19 -08:00
Mark Baker 1194b25575 Merge pull request #3309 from PHPOffice/RowIterator_Destructor
Add destructor for RowIterator to ensure disconnection from worksheet
2023-01-20 12:48:52 +01:00
MarkBaker 89c67431a8 Add destructor for RowIterator to ensure disconnection from worksheet 2023-01-20 12:30:57 +01:00
Mark Baker da3bcc3fe4 Merge pull request #3302 from PHPOffice/Iterator_Method-Synonyms
getColumnIterator() and getRowIterator() synonyms for getCellIterator() methods
2023-01-19 13:43:07 +01:00
MarkBaker 7127c73108 getColumnIterator() getRowIterator() synonyms for getCellIterator() methods in Row and Column objects 2023-01-19 12:56:45 +01:00
Mark Baker 80e270b2a3 Merge pull request #3300 from PHPOffice/Reader-Options_Docblock-Updates
Update to docblocks
2023-01-18 09:23:37 +01:00
Mark Baker ce81ca8862 Merge branch 'master' into Reader-Options_Docblock-Updates 2023-01-17 23:24:01 +01:00
MarkBaker c9d9207b12 Update to docblocks 2023-01-17 18:09:57 +01:00
oleibman 8497a320ea Resolve Phpstan Messages in Calculation Statistical (#3290)
* Resolve Phpstan Messages in Calculation Statistical

Reduce number of Phpstan messages by addressing their issues.

I did not eliminate the messages for Trends, because I did not understand why it is working as it does, so felt it was better to leave it alone.

* Scrutinizer

A new false positive.
2023-01-16 07:19:39 -08:00
oleibman c93d2a53db Resolve Phpstan Messages in Calculation Functions Internal and MathTrig (#3288)
Reduce number of Phpstan messages by addressing their issues.
2023-01-16 06:15:02 -08:00
oleibman ac5299b5df Minor Fix for AND/OR/XOR (#3287)
* Minor Fix for AND/OR/XOR

These 3 fall into the set of functions where Excel treats string literals differently depending on whether they are passed to the function directly or as a cell reference. PhpSpreadsheet is updated to try to duplicate that logic. New tests are added. Some existing test results had to change as a result of this code change.

* Adopt A Suggestion From Mark Baker

Reduce if statements by adding functions.
2023-01-16 05:35:28 -08:00
Jonathan Goode b043a01055 RE: #3294 - provide a sample that sets the X-axis as type "value" (#3295) 2023-01-15 08:59:00 -08:00
oleibman a5f1de02e3 Resolve Phpstan Messages in Calculation Financial (#3284)
Reduce number of Phpstan messages by addressing their issues.
2023-01-15 08:18:33 -08:00
oleibman 811406ba7a Resolve Phpstan Messages in Calculation Engineering and DateTime (#3283)
Reduce number of Phpstan messages by addressing their issues.
2023-01-14 07:29:51 -08:00
oleibman a3f3d2c9ad Clean Up Documentation for Worksheet (#3281)
* Clean Up Documentation for Worksheet

This PR was intended to clean up Phpstan/Scrutinizer messages regarding Worksheet. It is, for the most part, straightforward, but there is one problem which complicates things. The frequently-called public method `getParent` returns `Worksheet` or `null` but is documented to return only `Worksheet`. This can be addressed in either of two ways - change the code to match the documentation (smaller number of changes but a backwards compatibility break), or change the documentation to match the code (larger number of changes but no compatibility break). I have prepared a PR for each approach, but avoiding a compatibility break seems better, so I am pushing the latter. I can switch to the other if preferred. Most existing internal calls to `getParent` are changed to use a new method `getParentOrThrow`, which will throw an exception if parent is null. These calls would all have thrown a null pointer exception anyhow in that situation, so this should not cause any new breaks.

* Scrutinizer

One false positive, and one message leading to a minor code improvement.
2023-01-11 23:34:52 -08:00
oleibman e742bf2294 Attempt To Honor Fit to 1-Page Height for Html/Pdf (#3279)
* Attempt To Honor Fit to 1-Page Height for Html/Pdf

Fix #3266. Each sheet in a spreadsheet can specify that it be set to fit width or height to a fixed number of pages. Mpdf and most browsers already handle the common case of fit to 1 page wide; I am unable to find a solution for Dompdf or Tcpdf. Code is added for the common case of fit to 1 page high when possible; this will usually work in Mpdf, Dompdf, and most browsers. I am not able to come up with a way to handle fit to more than 1 page wide or high.

* Synchronizer

Remove one unused assignment in test.
2023-01-11 12:02:21 -08:00
oleibman d5b13f64d5 Change Test To Avoid Bug in Latest Php (#3289)
Unit tests were failing at Github, having nothing to do with PhpSpreadsheet. Change test to avoid bug, which is reported at https://github.com/php/php-src/issues/10285
2023-01-10 20:19:57 -08:00
Mark Baker 9f0ec1cb35 Merge pull request #3282 from PHPOffice/Reader_Minor-Flag-Modifications
IGNORE_EMPTY_CELLS flag
2023-01-07 11:59:59 +01:00
MarkBaker 8406cc6176 IGNORE_EMPTY_CELLS flag 2023-01-07 11:16:32 +01:00
Mark Baker 4b16f36bf4 Merge pull request #3278 from kbond/issue-3277-reproducer
Reproducer for #3277
2023-01-04 11:43:06 +01:00
Mark Baker 8602496fcb Merge branch 'master' into issue-3277-reproducer 2023-01-04 11:37:19 +01:00
MarkBaker 6f29e9ea49 Fix for single row/column tables... though very weird to create manually in MS Excel, because creating a single row table always creates a two row table (1 row headers and 1 row data). But subsequently hiding the header row; and then deleting that row will create such a table. 2023-01-04 11:17:46 +01:00
oleibman 46fdc87bf8 Update Change Log (#3280)
Add changes from last month not already included.
2023-01-03 19:27:54 -08:00
Kevin Bond 9366c3ea8f add reproducer 2023-01-03 11:52:46 -05:00
Mark Baker e980f97298 Merge pull request #3276 from PHPOffice/Structured-Reference_Unhappy-Path
Use exception code rather than exception message for #Headers Structured Reference Exception
2023-01-03 12:57:06 +01:00
MarkBaker 0e3f1f187d Use exception code rather than exception message to identify whether the Calc Engine should throw an exception or push to stack for Structured Reference Exceptions 2023-01-03 12:27:20 +01:00
Mark Baker 7e345ad012 Merge pull request #3275 from PHPOffice/Structured-Reference_Header-Reference-when-Disabled
Unhappy path for Structured References
2023-01-03 02:45:46 +01:00
Mark Baker 23c7b952c5 Merge branch 'master' into Structured-Reference_Header-Reference-when-Disabled 2023-01-02 22:22:44 +01:00
MarkBaker 1bb0d56b15 Unhappy path for Structured References (referencing #Headers when headers are hidden) 2023-01-02 22:01:10 +01:00
oleibman 644547fb86 Update Column Reference for Columns Beginning with Y and Z (#3264)
Fix #3263. Code was comparing column string to max column (XFD), but comparison was done by strings so that any column beginning with Y or Z would seem to exceed the max and would be handled incorrectly. Change to compare to maximum integer index of column (16384) instead.
2023-01-01 15:29:04 -08:00
oleibman d2938477d9 Xlsx Reader/Writer Composite Charts (#3265)
Fix #2333. Thanks to @SSI-johnnypops for discovering the problem and formulating most of the solution. The classes involved in setting up composite charts made it relatively easy to code them; however, there can be problems when reading a spreadsheet with such a chart and then saving a copy of it. In  particular, the ordering conventions when reading the chart may not match the expectations when writing. The original attempt to resolve this worked for read/write but broke one of our samples (33_Chart_create_composite), which probably means that it would break other code which is now working in the wild. It has now been refined so that it (hopefully) makes adjustments to the ordering if and only if they are required. The new code works with the failing spreadsheet reported in the issue, with the unchanged sample code, and with an alternate version of the sample which contains what is probably a better model for people to use when coding such a chart.
2023-01-01 15:08:14 -08:00
dependabot[bot] 43da1c9965 Bump mpdf/mpdf from 8.1.2 to 8.1.4 (#3273)
Bumps [mpdf/mpdf](https://github.com/mpdf/mpdf) from 8.1.2 to 8.1.4.
- [Release notes](https://github.com/mpdf/mpdf/releases)
- [Changelog](https://github.com/mpdf/mpdf/blob/development/CHANGELOG.md)
- [Commits](https://github.com/mpdf/mpdf/compare/v8.1.2...v8.1.4)

---
updated-dependencies:
- dependency-name: mpdf/mpdf
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: oleibman <10341515+oleibman@users.noreply.github.com>
2023-01-01 13:56:03 -08:00
dependabot[bot] 797c861b32 Bump friendsofphp/php-cs-fixer from 3.13.0 to 3.13.1 (#3272)
Bumps [friendsofphp/php-cs-fixer](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer) from 3.13.0 to 3.13.1.
- [Release notes](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/releases)
- [Changelog](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/master/CHANGELOG.md)
- [Commits](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/compare/v3.13.0...v3.13.1)

---
updated-dependencies:
- dependency-name: friendsofphp/php-cs-fixer
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-01-01 13:34:09 -08:00
dependabot[bot] 38e8e5fff3 Bump phpunit/phpunit from 9.5.26 to 9.5.27 (#3271)
Bumps [phpunit/phpunit](https://github.com/sebastianbergmann/phpunit) from 9.5.26 to 9.5.27.
- [Release notes](https://github.com/sebastianbergmann/phpunit/releases)
- [Changelog](https://github.com/sebastianbergmann/phpunit/blob/main/ChangeLog-9.5.md)
- [Commits](https://github.com/sebastianbergmann/phpunit/compare/9.5.26...9.5.27)

---
updated-dependencies:
- dependency-name: phpunit/phpunit
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-01-01 13:14:38 -08:00
dependabot[bot] 98d696a78a Bump markbaker/matrix from 3.0.0 to 3.0.1 (#3269)
Bumps [markbaker/matrix](https://github.com/MarkBaker/PHPMatrix) from 3.0.0 to 3.0.1.
- [Release notes](https://github.com/MarkBaker/PHPMatrix/releases)
- [Commits](https://github.com/MarkBaker/PHPMatrix/compare/3.0.0...3.0.1)

---
updated-dependencies:
- dependency-name: markbaker/matrix
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-01-01 12:46:15 -08:00
dependabot[bot] 79f612674a Bump markbaker/complex from 3.0.1 to 3.0.2 (#3268)
Bumps [markbaker/complex](https://github.com/MarkBaker/PHPComplex) from 3.0.1 to 3.0.2.
- [Release notes](https://github.com/MarkBaker/PHPComplex/releases)
- [Commits](https://github.com/MarkBaker/PHPComplex/compare/3.0.1...3.0.2)

---
updated-dependencies:
- dependency-name: markbaker/complex
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-01-01 12:17:27 -08:00
dependabot[bot] 4aa169e4ad Bump tecnickcom/tcpdf from 6.5.0 to 6.6.2 (#3267)
Bumps [tecnickcom/tcpdf](https://github.com/tecnickcom/TCPDF) from 6.5.0 to 6.6.2.
- [Release notes](https://github.com/tecnickcom/TCPDF/releases)
- [Changelog](https://github.com/tecnickcom/TCPDF/blob/main/CHANGELOG.TXT)
- [Commits](https://github.com/tecnickcom/TCPDF/compare/6.5.0...6.6.2)

---
updated-dependencies:
- dependency-name: tecnickcom/tcpdf
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-01-01 11:58:03 -08:00
oleibman 4adafecea9 Eliminate Shared\JAMA (#3260)
* Eliminate Shared\JAMA

The code under `Shared\JAMA` is called from exactly 3 places in Calculation, and exactly 1 other place (see next paragraph). These places are inadequately covered in the test suite, so it is not clear that the existing code works. In addition, see PR #2964 for commentary decrying the continued used of JAMA. I will also note that it has a pitiful 8.20% coverage in the test suite. There seems to already be a perfectly adequate equivalent in Calculation for those parts of JAMA which are used (e.g. we don't use any decompositions, so the fact that no decomposition code is present in Calculation is not a problem). This PR replaces the uses of JAMA within Calculation with `checkMatrixOperands`, and deletes Shared/JAMA entirely (which, among other thing, makes many Phpstan reported problems go away). The test suite is enhanced to ensure coverage of all the changed statements. A side benefit of deleting Shared/Jama is that the only function which PhpSpreadsheet has added to the global namespace (hypo in Maths.php) goes away.

There is one additional use in Shared/Trend/PolynomialBestFit. That use is best replaced with Matrix/Matrix, which is already a requirement for PhpSpreadsheet. PolynomialBestFit has zero test coverage, and I didn't add any for this change. There seem to be existing errors which both Phpstan and Scrutinizer complain about, and I am quite convinced that they are not false positives. Fixing those problems will be a project for another day.

Calculation has many calls to `Information\ErrorValue` and `Information\ExcelError`. It is inconsistent in how it does so - most invoke `Information\E...` but a small number take advantage of additional `use` statements to just invoke `E...`. I have made the usage consistent by changing the small number to act like the majority and eliminating the `use` statements.

Some of the test cases exposed the fact that MAX, MAXA, MIN, and MINA do not properly handle error strings in their input. For example, if cell A1 contains 2, and A2 contains `=5/0`, `=MAX(A1, A2)` should return `#DIV/0!`. They are changed to handle them properly.

`Shared\JAMA` was normally omitted from code coverage. Since it is being deleted, there is no longer a reason to explicitly exclude it. `Writer\PDF` was also on the exclude list, probably for historical reasons, but there is no reason to exclude it now (it is, in fact, 100% covered), so it will no longer be excluded.

* Scrutinizer

Eliminate some newly dead code.
2022-12-30 07:22:58 -08:00
MarkBaker de9c46168a Merge remote-tracking branch 'origin/master'
# Conflicts:
#	src/PhpSpreadsheet/Calculation/Calculation.php
#	src/PhpSpreadsheet/Calculation/Engine/Operands/StructuredReference.php
2022-12-29 18:05:38 +01:00
Mark Baker cff73fb836 Merge pull request #3261 from PHPOffice/CalcEngine_Structured-References
Handling Structured References in the Calculation Engine
2022-12-29 18:02:56 +01:00
Mark Baker 5649541a68 Merge branch 'master' into CalcEngine_Structured-References 2022-12-29 17:38:13 +01:00
MarkBaker e9540d9291 Minor refactoring 2022-12-29 17:17:03 +01:00
MarkBaker 3ac5155c84 Make Structured Reference parsing case-insensitive, by switching from strpos to preg_match, allowing re-use of the pattern in preg_replace for convenience 2022-12-29 16:25:21 +01:00
oleibman e7a0e8092d Limited Support for Form Controls V2 (ListBox, Buttons, etc.) (#3130)
* WIP Limited Support for Form Controls V2 (ListBox, Buttons, etc.)

This is a replacement for draft PR #2455 and draft PR #3127. There is some useful commentary in those PRs which I have mostly, but not entirely, duplicated below. Fix #2396. Fix #1770. Fix #2388.

A related problem is that the vml files used for the form controls sometimes contain invalid xml. Fix #3125 (rejected previous PR #1181 as too risky, issue was also reported as #170). Vml file should be valid Xml, but Excel can generate unclosed `<br>` tags, preventing Xlsx reader from reading file correctly. I believe a very narrowly targeted fix, changing `<br>` to `<br/>`, and only when reading vml files, probably mitigates the risk. The sample file formscomments.xlsx which is part of this change shows this problem with `Button 1` on sheet `Forms`; the spreadsheet was created with Excel 365, so the problem is not restricted to Excel 2013 as originally reported. A comment on PR 3127 indicates that other tags might be involved, but, without a file demonstrating that, I will restrict this change to br tags for now.

I am starting this out in draft status, and will probably leave it that way for some time. I'm not sure where we want to go with this. It fixes some problems, but in a limited manner, and creates some others. I'm not sure the pain of the others is balanced considering the limitations of the fix. If enough interest is generated as a result of this ticket being out there, we can proceed; if not, it probably isn't worth it.

This fix allows form control elements to be read in and written out. It does not allow you to add such elements, nor even to locate them or determine their properties (so you can't modify or delete them). Although it handles reading and writing of sheets containing both form controls and comments, it will probably create a corrupt spreadsheet if you try adding a new comment to a sheet with form controls - probably quite difficult to solve. Cloning the sheet probably won't work either - probably easier than the other. It is conceivable that we want to add a new property to the Xlsx Reader which turns the reading of form elements on or off (default=off), so that negative effects will be limited to those who have explictly opted in. The change in its current form does not implement such a property.

Because of its limitations, the change isn't really testable. As in some other recent installs, I have added a sample to demonstrate that it works correctly.

As it turns out, if we have a worksheet which contains both form controls and comments (see formscomments.xlsx which is part of this PR), PhpSpreadsheet already creates a corrupt file when it tries to load and save the spreadsheet with such a worksheet. With this change, the file is saved without corruption. This tilts things in favor of proceeding. I'm still not ready, but this will be an important consideration.

A sample file for issue #2621 illustrated a problem with shape files. Since they are involved here, I took a look at how the sample worked with this code. In master, and with this change, a corrupt file results. Fixing that is probably easier than the general problem of handling shape files, but it's an argument against moving this forward until the corruption problem can be addressed.

Fix #2661. A template including checkboxes was leading to file corruption solved by this PR. Another argument for moving forward.

* Improved Sample File, and Documentation

Add more realistic worksheet to spreadsheet. Document new feature, adding caveats to how it can be used.
2022-12-28 08:01:53 -08:00
MarkBaker adbc981a2c Unit tests for calculations with Structured References 2022-12-27 21:49:22 +01:00
MarkBaker 41c15fd2d1 More work on handling Structured References in the Calculation Engine 2022-12-27 21:49:21 +01:00
oleibman ec96ef3a6c Add Additional Method to XIRR if Newton-Raphson Does Not Converge (#3262)
Fix #689. XIRR is calculated by making guesses which are hopefully better with each iteration. It is not guaranteed to succeed for Excel, PhpSpreadsheet, or any other implementation. PhpSpreadsheet uses the Newton-Raphson method for its guesses. So does Python package xirr (https://github.com/tarioch/xirr/), but, if Newton-Raphson fails to converge, Python tries Brent's method as an alternative. Two sets of non-converging data are noted in 689. For both, a solution does converge in Excel. For the first of the problems, a solution converges in Python with Newton-Raphson; but, for the second, a solution converges which requires Brent. For the Java package https://github.com/RayDeCampo/java-xirr on which Python was based, and which uses only Newton-Raphson, a solution converges for the first, and does not converge for the second.

To try to match the good results of the others, I added an alternate algorithm if Newton-Raphson fails. Brent's algorithm seems difficult to implement to me. I might have gone there regardless, but I first tried a slightly simpler alternative, bisection. This solved the problem for both of the cases in 689. Perhaps someone will one day report a problem that doesn't converge for Newton-Raphson or bisection, but does for Brent. We can review this decision then.

The new code causes 3 changes in the unit test. In all 3 tests, Excel and PhpSpreadsheet had not converged, but Python and/or Java had. I now believe that Python/Java is correct in those cases, and Excel is not. The new code aligns PhpSpreadsheet with Python/Java for those tests. It is, of course, impossible to know when Excel's implementation doesn't converge, so we aren't guaranteed to match its results in those hopefully rare situations.
2022-12-27 08:49:17 -08:00
MarkBaker fda996e192 Initial work on handling Structured References in the Calculation Engine 2022-12-24 00:20:10 +01:00
MarkBaker 8d7130cbc8 Initial work on handling Structured References in the Calculation Engine 2022-12-23 23:41:15 +01:00