Commit Graph

3575 Commits

Author SHA1 Message Date
oleibman faf6d819c6
Keep Calculated String Results Below 32K (#2921)
* Keep Calculated String Results Below 32K

This is the result of an investigation into issue #2884 (see also PR #2913). It is, unfortunately, not a fix for the original problem; see the discussion in that PR for why I don't think there is a practical fix for that specific problem at this time.

Excel limits strings to 32,767 characters. We already truncate strings to that length when added to the spreadsheet. However, we have been able to exceed that length as a result of the concatenation operator (Excel truncates); as a result of the CONCATENATE or TEXTJOIN functions (Excel returns #CALC!); or as a result of the REPLACE, REPT, SUBSTITUTE functions (Excel returns #VALUE!). This PR changes PhpSpreadsheet to return the same value as Excel in these cases. Note that Excel2003 truncates in all those cases; I don't think there is a way to differentiate that behavior in PhpSpreadsheet.

However, LibreOffice and Gnumeric do not have that limit; if they have a limit at all, it is much higher. It would be fairly easy to use existing settings to differentiate between Excel and LibreOffice/Gnumeric in this respect. I have not done so in this PR because I am not sure how useful that is, and I can easily see it leading to problems (read in a LibreOffice spreadsheet with a 33K cell and then output to an Excel spreadsheet). Perhaps it should be handled with an additional opt-in setting.

I changed the maximum size from a literal to a constant in the one place where it was already being enforced (Cell/DataType). I am not sure that is the best place for it to be defined; I am open to suggestions.

* Implement Some Suggestions

... from @MarkBaker.
2022-07-04 08:30:46 -07:00
MarkBaker db12b73f16 Update to ReadMe about PDF and Chart Export installation and configuration 2022-07-03 18:32:42 +02:00
oleibman c3f53854b6
Php/iconv Should Not Treat FFFE/FFFF as Valid (#2910)
Fix #2897. We have been relying on iconv/mb_convert_encoding to detect invalid UTF-8, but all techniques designed to validate UTF-8 seem to accept FFFE and FFFF. This PR explicitly converts those characters to FFFD (Unicode substitution character) before validating the rest of the string. It also substitutes one or more FFFD when it detects invalid UTF-8 character sequences.

A comment in the code being change stated that it doesn't handle surrogates. It is right not to do so. The only case where we should see surrogates is reading UTF-16. Additional tests are added to an existing test reading a UTF-16 Csv to demonstrate that surrogates are handled correctly, and that FFFE/FFFF are handled reasonably.
2022-07-02 08:53:39 -07:00
dependabot[bot] f90adcf28e
Bump phpstan/phpstan from 1.7.7 to 1.8.0 (#2919)
Bumps [phpstan/phpstan](https://github.com/phpstan/phpstan) from 1.7.7 to 1.8.0.
- [Release notes](https://github.com/phpstan/phpstan/releases)
- [Changelog](https://github.com/phpstan/phpstan/blob/1.8.x/CHANGELOG.md)
- [Commits](https://github.com/phpstan/phpstan/compare/1.7.7...1.8.0)

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

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>
2022-07-02 01:29:11 -07:00
oleibman cbc8ed0845
Changes for Phpstan 1.8.0 (#2920)
Dependabot pushed changes. As usual for Phpstan, some changes to code are required.
2022-07-02 01:16:11 -07:00
dependabot[bot] ec01a71c0b
Bump phpunit/phpunit from 9.5.20 to 9.5.21 (#2918)
Bumps [phpunit/phpunit](https://github.com/sebastianbergmann/phpunit) from 9.5.20 to 9.5.21.
- [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.20...9.5.21)

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

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-07-01 05:36:47 -07:00
dependabot[bot] 0719c7cb87
Bump dompdf/dompdf from 1.2.2 to 2.0.0 (#2917)
Bumps [dompdf/dompdf](https://github.com/dompdf/dompdf) from 1.2.2 to 2.0.0.
- [Release notes](https://github.com/dompdf/dompdf/releases)
- [Commits](https://github.com/dompdf/dompdf/compare/v1.2.2...v2.0.0)

---
updated-dependencies:
- dependency-name: dompdf/dompdf
  dependency-type: direct:development
  update-type: version-update:semver-major
...

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-07-01 05:21:24 -07:00
Mark Baker 5b74d1ffca
Merge pull request #2915 from PHPOffice/Performance-Refresh-Row/Column-Dimensions
Minor memory improvement
2022-06-30 17:18:37 +02:00
Mark Baker 01d2d541c5
Merge branch 'master' into Performance-Refresh-Row/Column-Dimensions 2022-06-30 17:15:05 +02:00
oleibman 5d5e550342
Additional Support for Chart DataSeriesValues (#2906)
* Additional Support for Chart DataSeriesValues

Fix #2863. DataSeriesValues now extends Properties, allowing it to share code in common with Axis and Gridlines. This causes some minor breakages; in particular line width is now initialized to null instead of Excel's default value, and is specified in points, as the user would expect from Excel, rather than the value stored in Xml.

This change:
- adds support for 1 or 2 marker colors.
- adds support for `smoothLine` to DataSeriesValues.
- will determine `catAx` or `valAx` for Axis based on what is read from the Xml when available, rather than guessing based on format. (Another minor break.)
- reads `formatCode` and `sourceLinked` for Axis.
- correct 2 uses of `$plotSeriesRef` to `$plotSeriesIndex` in Writer/Xlsx/Chart.
- pushes coverage over 90% for Chart (88.70% overall).

* Update Change Log

I had updated previously but forgot to stage the member.

* Adopt Some Suggestions

Incorporate some changes suggested by @bridgeplayr.

* Use ChartColor for DSV Fill And Font Text

DataSeriesValues Fill could be a scalar or an array, so I saved it till last.

* Some Final Cleanup

No code changes.

Illustrate even more of the new features in existing sample files.

Deprecate *_ARGB in Properties/ChartColors in favor of *_RGB, because it uses only 6 hex digits. The alpha value is stored separately.
2022-06-29 17:52:09 -07:00
MarkBaker 715b50a77c Minor memory improvement 2022-06-29 22:09:16 +02:00
oleibman b5b83abc0e
Adjust Both Coordinates for Two-Cell Anchors (#2909)
Fix #2908. When support for two-cell anchors was added for drawings, we neglected to adjust the second cell address when rows or columns are added or deleted. It also appears that "twoCell" and "oneCell" were introduced as lower-case literals when support for the editAs attribute was subsequently introduced.
2022-06-29 09:20:33 -07:00
oleibman a89572107a
Handling of #REF! Errors in Subtotal, and More (#2902)
* Handling of #REF! Errors in Subtotal, and More

This PR derives from, and supersedes, PR #2870, submitted by @ndench. The problem reported in the original is that SUBTOTAL does not handle #REF! errors in its arguments properly; however, my investigation has enlarged the scope.

The main problem is in Calculation, and it has a simple fix. When the calculation engine finds a reference to an uninitialized cell, it uses `null` as the value. This is appropriate when the cell belongs to a defined sheet; however, for an undefined sheet, #REF! is more appropriate.

With that fix in place, SUBTOTAL still needs a small fix of its own. It tries to parse its cell reference arguments into an array, but, if the reference does not match the expected format (as #REF! will not), this results in referencing undefined array indexes, with attendant messages. That assignment is changed to be more flexible, eliminating the problem and the messages.

Those 2 fixes are sufficient to ensure that the original problem is resolved. It also resolves a similar problem with some other functions (e.g. SUM). However, it does not resolve it for all functions. Or, to be more particular, many functions will return #VALUE! rather than #REF! if this arises, and the same is true for other errors in the function arguments, e.g. #DIV/0!. This PR does not attempt to address all functions; I need to think of a systematic way to pursue that. However, at least for most MathTrig functions, which validate their arguments using a common method, it is relatively easy to get the function to propagate the proper error result.

* Arrange Array The Way call_user_func_array Wants

Problem with Php8.0+ - array passed to call_user_func_array must have int keys before string keys, otherwise Php thinks we are passing positional parameters after keyword parameters.

7 other functions use flattenArrayIndexed, but Subtotal is the only one which uses that result to subsequently pass arguments to call_user_func_array. So the others should not require a change. A specific test is added for SUM to validate that conclusion.

* Change Needed for Hidden Row Filter

Same as change made to Formula Args filter.
2022-06-25 22:08:32 -07:00
oleibman 177a362f38
Have Phpstan Ignore Chart/Renderer/JpGraph (#2901)
This one class consumes a lot of space in Phpstan baseline. The problem is that it is an interface to Jpgraph, which is not maintained in Composer. This means that we have to disable tests involving this module, since we are dealing with very old code in our test suite. This means that we are very unlikely to do any work on this member, so the code error reports are more of a distraction than anything else. Remove them for now, restoring them if we ever solve this problem.
2022-06-19 19:22:10 -07:00
oleibman 6fae406aca
New Class ChartColor and Refactoring (#2898)
* New Class ChartColor and Refactoring

Chart colors are written to Xml in a different manner than font colors, and there are several variations. It will simplify things to create a new class for them. This PR will make use of the new class in Property/Axis/Gridline glow, shadow, and line colors; in Axis fill color; and in Font underline color (used only in charts). It will be used elsewhere in future; in particular, DataSeriesValues, which I will tackle next, will use it for at least one existing and two new properties. This PR is a refactoring; no functionality is added. Some public functions are moved from Properties to ChartColor, but all of these have been introduced after the last release 1.23, so there isn't really any compatibility break. No tests needed to be revised as a result of the source changes.

* Simplify Logic in Xlsx/Writer/Chart

Minor change.
2022-06-19 19:11:40 -07:00
MarkBaker 4ae947ce64 Update php codesniffer 2022-06-19 11:33:09 +02:00
MarkBaker 27f815a9f1 Update change log 2022-06-17 14:10:35 +02:00
Mark Baker 1f85f15cd9
Merge pull request #2899 from PHPOffice/Issue-2874_Calculation-Engine-Quoted-Worksheet-Regexp
Issue 2874 calculation engine quoted worksheet regexp
2022-06-17 14:07:13 +02:00
Mark Baker 9f172733c7
Merge branch 'master' into Issue-2874_Calculation-Engine-Quoted-Worksheet-Regexp 2022-06-17 13:57:28 +02:00
MarkBaker 02c6e8cfa8 Escape double quotes in worksheet names for column range and row range references 2022-06-17 13:34:20 +02:00
MarkBaker 23e207ccb4 Adjust calc engine identification of quoted worksheet names to fix bug with multiple quoted worksheets in formula 2022-06-17 13:08:06 +02:00
oleibman 97381d4307
Complete Support for Chart/Axis and Gridlines (#2881)
Unit testing now results in 100% coverage for Axis and Properties. All the properties in methods in Gridlines were more or less duplicated in Axis, and these duplications are moved to the common ancestor Properties. So, there isn't anything left in Gridlines. PhpSpreadsheet Chart is now over 85% covered (it was below 35% until recently).

Properties are in many cases set to default to null/null-string, rather than the default values they receive from Excel, and are not written to Xml if unchanged. This is consistent with how Excel behaves. A new property `crossBetween` is added to Axis, and, with support for that added to Xlsx Reader and Writer, some minor Sample peculiarities are corrected, in particular, the charts were sometimes slightly truncated on the left and right edges.
2022-06-15 19:00:33 -07:00
oleibman 481cef2def
Php8.2 Deprecation in Reader/Xlsx (#2894)
* Php8.2 Deprecation in Reader/Xlsx

Using `${var}` will be deprecated, with the suggested resolution being to use `{$var}`. This appears to be the only place in PhpSpreadsheet which does this. Some vendor packages will need to change for 8.2 for this and other reasons.

* mb_convert_encoding and HTML_ENTITIES

Also scheduled to be deprecated with 8.2. It appears to have not been needed in PhpSpreadsheet in the first place.
2022-06-15 18:47:35 -07:00
FlameStorm 1829dea91e
Ignore square-$-brackets prefix in format string (#2886)
* Ignore square-$-brackets prefix in format string

* Test for square-$-brackets prefix in format string issue fixed

* Fix for phpstan compliance

* Additional assert for checking number format of tested source cell
2022-06-15 14:55:17 -07:00
Mark Baker 11348a4830
Merge pull request #2890 from PHPOffice/PHP82-Experimental-in-CI-Pipeline
Add PHP 8.2 with allow fail
2022-06-15 15:18:47 +02:00
MarkBaker 0a8c97cf8a Add PHP 8.2 with allow fail 2022-06-15 13:59:58 +02:00
Mark Baker 85fe696236
Merge pull request #2889 from PHPOffice/PHPCS-Update
phpcs update to version 3.7.0
2022-06-15 13:43:48 +02:00
MarkBaker 3b55689ec1 phpcs update to version 3.7.0 to ensure it catches all the PHP 8.1 updates 2022-06-15 13:33:42 +02:00
Mark Baker 1a404e8dcf
Merge pull request #2888 from PHPOffice/ReferenceHelper-Performance-Improvements
Reference helper performance improvements
2022-06-15 13:23:51 +02:00
Mark Baker ec5e46a0ba
Merge branch 'master' into ReferenceHelper-Performance-Improvements 2022-06-15 13:10:40 +02:00
MarkBaker f51f4bc0ea Update change log and documentation 2022-06-15 12:59:38 +02:00
MarkBaker 09c66ab302 Use column address rather than index for remove column loop to eliminate extra math and repeated calls to stringFromColumnIndex() 2022-06-15 12:59:37 +02:00
oleibman 04f4667658
Expand Chart Support for schemeClr and prstClr (#2879)
* Expand Chart Support for schemeClr and prstClr

Fix #2219. Address some, but not all, issues mentioned in #2863.

For Pie Charts, fill color is stored in XML as part of dPt node, which had been ignored by Reader/Xlsx/Chart. Add support for it, including when specified as schemeClr or prstClr rather than srgbClr. Add support for prstClr in other cases where schemeClr is supported.

* Update Change Log

Add this PR.
2022-06-14 08:45:12 -07:00
oleibman 90bdc7c12e
Test For Excel File Saved With Ribbon Data (#2883)
File from https://www.rondebruin.nl/win/s2/win003.htm. I have been in conversation with the author, who has no objection to its use. I have not actually opened the file in Excel (at least not with macros enabled); I am using it merely to demonstrate that the ribbon data is read and written correctly. Test added; no source code changed. This should slightly increase coverage for Reader/Xlsx (moderate), Writer/Xlsx (slight), and Spreadsheet (substantial). Note that this file has no Ribbon Bin objects, so some coverage is still lacking.
2022-06-14 08:33:36 -07:00
MarkBaker 00f570aed5 Merge branch 'master' into ReferenceHelper-Performance-Improvements 2022-06-14 16:00:09 +02:00
Mark Baker ed34a45891
Merge pull request #2875 from dgeppo/master
Add removeCommentByColumnAndRow function
2022-06-14 12:46:51 +02:00
Mark Baker c749cb5e83
Merge branch 'master' into master 2022-06-14 12:34:02 +02:00
MarkBaker 8e31dbaabe Update change log 2022-06-14 12:21:44 +02:00
MarkBaker 4d2b00dafc phpcs fxes 2022-06-14 12:19:54 +02:00
MarkBaker 11a94dabec Potential improvements for insert/delete column/row for performance testing 2022-06-14 12:01:08 +02:00
Dams 7f62fba7ef
Update the method testRemoveComment
Adding test to check if comment exists before delete it
2022-06-14 10:44:42 +02:00
Dams 861b955b3b
Add feature removeComment
Use $cellCoordinate as argument
Return $this to support the fluent interface
2022-06-14 10:12:08 +02:00
Mark Baker 7b7d3bc33c
Merge pull request #2882 from PHPOffice/Datatype-Stricter-Typing
Apply some coercive type-hinting
2022-06-12 19:57:56 +02:00
MarkBaker 09c843427f Apply some coercive type-hinting 2022-06-12 19:21:43 +02:00
Mark Baker 67f87c87c2
Merge pull request #2880 from PHPOffice/Tighten-up-TypeChecking-for-Strings
Apply some coercive type-hinting
2022-06-11 14:46:48 +02:00
MarkBaker 189152ee07 Apply some coercive type-hinting 2022-06-11 14:32:29 +02:00
Mark Baker 5cba6d86e6
Merge pull request #2873 from PHPOffice/Row/Column_isEmpty-check
New functionality to allow checking whether a row or column is "empty"
2022-06-10 17:37:43 +02:00
Mark Baker 0ef98ac044
Merge branch 'master' into Row/Column_isEmpty-check 2022-06-10 17:34:11 +02:00
Mark Baker e3471f8a0f
Merge pull request #2878 from PHPOffice/Issue-2868_Emphasis-Documentation-for-setValueExplict
Update docblock documentation for setting cell values explicit
2022-06-10 14:37:24 +02:00
MarkBaker 8434189336 Update docblock documentation for setting cell values explicit to indicate that value/datatype matching is the responsibility of the end-user developer making this call; and that values may be changed to reflect the specified datatype.
No doubt some developers will complain that it should be the other way round, that datatpe should be modified to match the specified value; but then they should be using setValue() instead; the use of setValueExplicit() is explicit.
2022-06-10 13:38:41 +02:00