Commit Graph

4282 Commits

Author SHA1 Message Date
oleibman fe4750b034 Update LocaleFloatsTest.php
Directory name was inadvertently left case-insensitive.
2023-12-07 22:58:01 -08:00
oleibman 9bef9c90ce Tests Involving Decimal and Currency Separators
This was suggested by the investigation of issue #3811. No fix is necessary for the issue. However, two possible code solutions (Php setlocale, which comes with certain design flaws, and StringHelper set(Decimal/Thousands)Separator were suggested, and neither is adequately tested. This PR adds such tests.

Unusually, getting StringHelper Decimal Separator, Thousands Separator, and Currency Code can result in a change to those properties. So, the existing design in several tests where those properties are captured in Setup and restored in Teardown do not work quite as designed. Instead, the ability to set those properties to their default value (null) is added, and the tests re-done to restore the default in Teardown.

The two methods yield the same results when parsing input. However, they diverge when examining output fields through `getFormattedValue`. Such output is currently correct (usually) when using setlocale, but not when using StringHelper. The former works through the 'trick' of using `sprintf(%f)`, which generates a locale-aware string. However, using non-locale-aware `sprintf(%F)` followed by `str_replace` will produce the correct result for both setlocale and StringHelper. One place in the code uses a cast to string, which is incorrect for both methods. Following that up with the same str_replace makes it correct for both. These changes permit, but do not require, the user to avoid setlocale altogether.

It remains an open question whether Settings/Calculation::setLocale should set DecimalSeparator, CurrencySeparator, and CurrencyCode. That makes logical sense, but it would be a breaking change, and having to explicitly set those values when using setLocale does not seem especially burdensome. For now, such a change will not be made.
2023-12-07 22:49:43 -08:00
oleibman 9fcfa4b7ec Xlsx Support Flipping of Image (#3801)
* Xlsx Support Flipping of Image

Fix #731. Opened over 5 years ago, probably the second oldest problem I've worked on. Images attached to an Xlsx spreadsheet can be rotated, which is supported by PhpSpreadsheet. They can also be flipped along their horizontal and/or vertical axes, and that has not been supported. This PR adds that support.

* Update CHANGELOG.md
2023-11-30 08:46:43 -08:00
oleibman 009e009811 Chart Dynamic Title and Special Font Properties (#3800)
* Chart Dynamic Title and Special Font Properties

Fix #3797. Excel allows a Chart Title to be a formula, albeit a very rigidly limited one. It can only be a reference to a single cell, and the worksheet name must be specified, and the column and row must be absolute. Methods are added to Chart/Title to accommodate this (and styling for it). This will be handled for input/output for Xlsx, and for output for Html.

The sample file which was submitted with this issue demonstrated that something else was missing. When setting the font for a chart title in Excel, you can specify all-caps or small-caps, options not available for most cell formatting. These are now added.

The sample file also fell into the category of spreadsheets which lose one or more charts when converted to Html. I have redone the "extend rows and charts" logic in Html Writer. It is now clearer (I hope) and more efficient, and hopefully this problem will not arise again.

* Scrutinizer 50/50

One false positive, one correct "unused parameter".
2023-11-30 08:01:56 -08:00
oleibman 7fbf5c494f Anticipate Dependabot (#3805)
These changes will be suggested tomorrow. It's better to take care of them in advance.
2023-11-30 07:31:42 -08:00
oleibman 5a60ba45ab Sheet Background Images (#3795)
* Sheet Background Images

Fix #1649, a 3-year-old issue long marked "stale". Excel supports background images on sheets; now PhpSpreadsheet will as well. Support is limited to Xlsx (read and write) and Html (write only). As far as I can tell, Excel Xml and Gnumeric do not support this, nor, of course, do Csv and Slk; Excel Xls does, but, as usual, how to handle it in BIFF format is a mystery; LibreOffice ODS supports it differently than Excel, and this is just another of many ODS style properties not currently supported by PhpSpreadsheet.

* Update CHANGELOG.md
2023-11-21 07:06:12 -08:00
Pinchon Karim 96fb273b6d Use case insentive comparison to get sheet name (#3791) 2023-11-18 06:24:18 -08:00
Adrian 276f7813d5 check if coordinate is inside range (#3779)
* check if coordinate is inside range

* Added coordinateIsInsideRange tests

* fix coordinateIsInsideRange error throwing

* fix coordinateIsInsideRange error throwing

* add support to worksheet name

* validateReferenceAndGetData type

* change validate and add tests data

* fix tests data reference

* fix absolute reference error

* fix boundaries to get range

* fix scrutinizer erros

* Additional Test Cases

---------

Co-authored-by: oleibman <10341515+oleibman@users.noreply.github.com>
2023-11-17 06:56:22 -08:00
oleibman f9eb35d8d1 Two Problems with Html Chart Rendering - Minor Break (#3787)
* Two Problems with Html Chart Rendering - Minor Break

Several problems are noted in #3783. This PR addresses those problems which make the rendering unsatisfactory (see following paragraphs). It does not address some items where the rendering is IMO satisfactory although it doesn't match Excel. In particular, the use of a different color palette and the rotation of charts are not addressed. I will leave the issue open for now because of those.

As for the items which are addressed, in some cases the Html was omitting a chart altogether. This is because it had been extending the column range for charts only when it decided that extending the row range was needed. The code is changed to now extend the column range whenever the chart begins beyond the current column range of the sheet.

Also, the rendering always produced a fixed-size image, so saving as Html could result in charts overlaying each other or other parts of the spreadsheet. New properties `renderedWidth` and `renderedHeight` are added to Chart, along with setters and getters. Writer/Html is changed to set these values using the chart's top left and bottom right cells to try to determine the actual size that is needed. Users can also set these properties outside of Writer/Html if they wish. Thanks to @f1mishutka for determining the source of this problem and suggesting an approach to resolving it.

Because the size of the rendered image in Html/Pdf is changed, this could be considered a breaking change. To restore the prior behavior, do the following for all charts before saving as Html:
```php
$chart->setRenderedWidth(640.0);
$chart->setRenderedHeight(480.0);
```

* Update CHANGELOG.md
2023-11-13 06:53:03 -08:00
Serhii Petrov 5b2708207c Test against php 8.3 in not experimental mode 2023-11-13 09:57:40 +09:00
oleibman 656a7164e1 Address Some Chart Problems (#3771)
* Address Some Chart Problems

Fix #3767. The basic problem in that issue was user error, but it exposed a couple of problems in code which are being addressed.

When a spreadsheet with charts is loaded without the includeCharts option and then saved, a corrupt spreadsheet is created. I believe this has been the case for quite some time. Nothing in the test suite covers this scenario. It is, in fact, a difficult thing to test, since the problem is exposed only when the file is opened through Excel. The specific problem is that a rels file generated by the output writer continues to refer to the drawing file which described the chart, but that file is not included (and not needed) in the output spreadsheet. The resolution is kludgey. The information that the file will not be needed is not available when the rels file is written. But, when it comes time to write the drawing file, it is known whether the rels file included it. So, if nothing else has caused the file to be generated, it is written out as a basically empty xml file after all. This solves the problem, but I will continue to search for a less kludgey solution. This solution is, at least, testable; if a different solution is applied later on, the test being introduced here is likely to break so a new one will be needed.

When the provided spreadsheet is loaded with the includeCharts option and then saved, an error is exposed in processing the Chart Title caption when it doesn't exist. The change to Writer/Xlsx/Chart is simple and clearly justifiable. What is peculiar is that the error does not arise with release 1.29, but does arise with master. It is not at all clear to me what has changed since the release to expose the error - the code in question certainly hasn't changed. It is difficult to isolate changes because of the extensive number of changes following on the elimination of Php7.4 as a supported platform.

The provided spreadsheet is unusual in at least two senses. When opened in Excel, it will show a clearly default value for the chart title, namely 'Chart Title'. I cannot find anything in the xml corresponding to that text. Since I have no idea why Excel is using that title, I will not try to duplicate its behavior, so that loading and saving the provided spreadsheet will omit the chart title. I will continue to investigate.

The other sense in which it is unusual is that it includes some style files in the same directory as the chart. I doubt that PhpSpreadsheet looks at these. The styling after load and save seems to mostly match the original, although there is at least one color in the graph which does not match. I imagine it would be pretty complicated to formally support these files.

* Unused Assignment
2023-11-09 13:15:38 -08:00
oleibman ef3890aad3 Integrate Exceptions Better with PhpStorm (#3765)
Fix #3754. Because `PhpSpreadsheetException` extends `Exception`, PhpStorm warns that calls to `setValueExplicit` and `setValue`, among others, do not handle the exception, because PhpStorm treats `Exception`, by default, as "checked". On the other hand, PhpStorm treats `RunTimeException` as "unchecked" so won't flag such calls. It is reasonable to let `PhpSpreadsheetException` extend `RuntTimeException`, and will eliminate the problem, without having to wrap code in all-but-useless try-catch blocks (e.g. for `setValue`, the code would raise an exception only if you try to set the cell's value to an unstringable object).
2023-11-07 09:07:11 -08:00
oleibman 98b5c77424 Anticipate Dependabot November 2023 (#3780) 2023-10-31 09:08:15 -07:00
oleibman 64a1d1ab02 Slk Shared Formulas (#3776)
* Slk Shared Formulas

Fix #2267. The Slk format has a way to express a "shared formula", but the Slk reader does not yet understand it. Thanks to @SheetJSDev for documenting the problem and pointing the way towards a solution. It has taken a long time to get there. Part of the problem is that I have not been successful in getting Excel to use this type of construction when saving a Slk file. So I have resorted to saving a Slk file where shared formulas *could* be used, and then editing it by hand to actually use them. It would not surprise me in the least to have neglected one or more possible ways to specify a shared formula; but, at least the issue as documented is resolved, and if new issues arise, we'll probably be in better shape to deal with them.

* Update CHANGELOG.md
2023-10-30 09:35:02 -07:00
oleibman dcccd63ee3 Theme File Missing But Referenced in Spreadsheet (#3772)
* Theme File Missing But Referenced in Spreadsheet

Fix #3770. A rels file points to a non-existent theme file in the spreadsheet. In other similar cases (e.g. PR #3771), Excel opens such a spreadsheet, but with an error pop-up. Not so with this file; it just opens the spreadsheet without the pop-up. PhpSpreadsheet will now account for this unusual situation as well.

* Update CHANGELOG.md
2023-10-26 12:06:36 -07:00
oleibman 1282f3d67c Performance Improvements for Csv Reader (#3769)
* Performance Improvements for Csv Reader

Investigating issue #381, a means was suggested to duplicated a problem, but no problem occurred ... except for performance. This involved a spreadsheet with a large number of cells, definitely not PhpSpreadsheet's strong point; even so, the program (entirely available in the issue) took a disastrous two or so hours to complete on my system. Looking at the Csv Reader code, several opportunities to cache results and avoid function calls jumped out, none of which seem to materially add to the maintenance burden of the program. Testing these changes resulted in a run time of about 20 minutes, still hardly a thing of beauty, but a huge improvement over the original and therefore worth proceeding with.

* Redo CsvIssue2232Test

Test cases included duplicates, and didn't account for some things (e.g. French locale will treat both 'vrai' and 'true' as true).

* Additional Optimization
2023-10-18 14:02:44 -07:00
oleibman bc9ca28deb Use DateTime::format Rather than cal_days_in_month in Sample (#3764)
Fix #3760. That problem actually was easily fixed, by enabling calendar extension in user's environment. Astonishingly, however, this is the only use of calendar in the entire project. Since the same functionality is available in DateTime, which is used throughout the project, use that instead to eliminate the dependency on calendar.
2023-10-13 23:41:08 -07:00
oleibman db35a4127d Upgrades in Advance of Dependabot (#3757)
More convenient to handle it today than tomorrow. Phpstan flags 1 new statement, but it is incorrect - annotate it.
2023-09-30 13:16:06 -07:00
oleibman d0fae3f57a Eliminate Some Phpstan Annotations (#3746)
* Eliminate Some Phpstan Annotations

Some changes are possible due to Php8+ features like null-safe operators and Stringable.

* Possible Uninitialized Variable

Scrutinizer might be technically correct.

* CellAddress Static -> Self

I don't understand the use case for extending it, which would be the reason for using static rather than self.

* Update Worksheet.php
2023-09-30 08:48:02 -07:00
oleibman e53e44d8cc Allow Users to Support Additional Tags in Helper/Html (#3752)
* Allow Users to Support Additional Tags in Helper/Html

Fix #3751. User wants to add bullets for list items, and possibly handle table rows and other currently unsupported tags where one size might not fit all.

* Update CHANGELOG.md
2023-09-30 07:46:28 -07:00
redtailmatt a713e153aa Added Conditional Formatting: ColorScale for Xlsx (#3738)
* Added Conditional Formatting: ColorScale for Xlsx

* Add Reader Support, Tests, Sample

Also correct Phpstan and phpcs problems.

* Update cond08_colorscale.php

* Improve Coverage

* More Coverage Improvements

* Use StyleReader for Colors for ColorScale and DataBar

The implementation of DataBar looks for an rgb attribute, but the color may be provided via theme attribute instead. The initial implementation for ColorScale did the same. Change both to use the existing code in Reader\Xlsx\Styles to parse the color.

* Change Some Doc Blocks to Type Declarations

---------

Co-authored-by: oleibman <10341515+oleibman@users.noreply.github.com>
2023-09-30 07:23:42 -07:00
Adrien Crivelli 7328e1ed61 Drop dead code 2023-09-26 16:14:56 +08:00
Adrien Crivelli 2da85155bd Fix PHPStan errors 2023-09-21 11:14:48 +08:00
Adrien Crivelli 7079e58054 Declare our minimum PHP version
So that composer will not update our dependencies to something that
would not work with PHP 8.0. And so that PHPStan analyzes assuming we
are running 8.0
2023-09-21 11:14:47 +08:00
Adrien Crivelli cbffcbcbbc Drop some tricks used for Scrutinizer false positives 2023-09-21 11:14:47 +08:00
Adrien Crivelli 2a0a53cd6a Drop all Scrutinizer annotations
Because they tend to clutter our code a lot and unfortunately, there are
lots of false positives. Instead, it would probably be better to deal
with false positives out of band, via the Scrutinizer web UI.
2023-09-21 11:14:47 +08:00
oleibman 07c60bac4a Clear Output Buffering Only When It's Been Started (#3741)
Fix #3739. User is seeing an intermittent notice when running samples using a web browser. The notice is comming from ob_clean, complaining that there is no buffer to delete. I frankly do not understand what the ob_clean is supposed to be paired with, nor why I cannot duplicate this result. Possibly, a better solution would be to eliminate the ob_clean; but using ob_get_length beforehand to see if there is anything to clean up seems safer, and I can't think of a downside.

The code in question is never executed when a sample is run from the command line. Consequently, no formal unit test is possible. The user reporting the problem was asked to test the change, and confirmed that the problem went away; no new problem arose on my system.
2023-09-20 15:42:37 -07:00
Adrien Crivelli 23b95e24c7 Stronger typing for ranges 2023-09-20 17:49:22 +08:00
jenasnic b2d572c8bb Fix missing font index with some XLS files (#3734)
* Fix missing font index with some XLS files

* Add test case

* Improve Test

---------

Co-authored-by: JC <jcopin@nodevo.com>
Co-authored-by: jenasnic
2023-09-18 01:33:33 -07:00
oleibman 7872602136 Properly Document Breaking Change from 1.28.0 (#3737)
See issue #3736.
2023-09-15 02:17:08 -07:00
Progi1984 f085c85339 Writer ODS : Writer Border Style for cells (#3693)
* Writer ODS : Write Border Style for cells

* Writer ODS : Write Border Style for cells (Replaced protected by private && Added Unit Test)

---------
2023-09-14 06:29:04 -07:00
Kevin Verschaeve 6fbf474642 fix: Load tables when flag IReader::READ_DATA_ONLY is used (#3726)
* fix: Load tables when flag IReader::READ_DATA_ONLY is used

* Add test for table read when IReader:::READ_DATA_ONLY is used

---------

Co-authored-by: Kevin Verschaeve <kevin.verschaeve@exotec.com>
2023-09-14 05:58:52 -07:00
oleibman 1b01b7d1ec Scrutinizer Samples/Tests (#3733)
* Scrutinizer Samples/Tests

A great many statements recently flagged. Attend to those in Samples and Tests.

* Missed a Few

* Update XlsTest.php
2023-09-13 22:45:06 -07:00
oleibman c74255cfa6 Update Changelog 2023-09-13 (#3731)
* Update Changelog 2023-09-13

* Update XssVulnerabilityTest.php
2023-09-13 00:51:17 -07:00
dmytromikhieiev1985 4e54ed389b Replace ezyang/htmlpurifier with voku/anti-xss (#3724)
* Replace ezyang/htmlpurifier with voku/anti-xss

* Update XssVulnerabilityTest
2023-09-13 00:29:01 -07:00
oleibman f17e16653d Break Some More Circular References (#3716)
* Break Some More Circular References

After identifying a circular reference between Worksheet and Table, which could lead to memory leaks, I identified several other similar relationships. I have added a destructor, or added added code to an existing destructor, for those possibilities. This didn't actually lead to any lowering of the memory usage of the unit test suite, so maybe there's no practical benefit, but it does seem like it should be theoretically useful. I am not aware of any practical way to unit test a destructor, although the added code will be exercised many times in most of our unit tests.

The only change here not involving a destructor is to `Worksheet::addChart` (it came to my attention because Worksheet and Chart have a circular reference). It is currently defined with two arguments, the second allowing you to place the chart in a specific location in the containing ArrayObject. However, as Phpstan and Scrutinizer both warn, the code to support this option will fail if it is ever executed (can't use array_splice on an ArrayObject); needless to say, this possibility is not exercised when executing the test suite. It could be made to work, but I really can't see any kind of use case to support this parameter. So I'm removing the second parameter. In theory, this is a breaking change, but, since the code can never work, in practice it won't be.

* Update Worksheet.php

* Update Worksheet.php
2023-09-12 22:56:15 -07:00
oleibman 72b77020e4 Add iterateOnlyExistingCells to Constructors (#3727)
* Add iterateOnlyExistingCells to Constructors

Fix #3721. That issue can already be handled, but requires several statements when one ought to suffice. Adding an extra parameter to the RowCellIterator and ColumnCellIterator constructors is useful, easy, and becomes especially practical now that our supported Php releases all support named parameters (see new test Issue3721Test).

* Update Column.php

* Update .php-cs-fixer.dist.php

* Update Row.php

* Update Column.php

* Update ByColumnAndRowTest.php
2023-09-12 22:28:09 -07:00
Adrien Crivelli 5029e8147e Update coding style 2023-09-13 10:26:51 +08:00
oleibman c5527ba534 Unexpected Namespacing in rels File (#3722)
* Unexpected Namespacing in rels File

Fix #3720. Third-party product created a spreadsheet which PhpSpreadsheet could not read because of unexpected namespacing in workbook.xml.rels.

The file which demonstrated the problem was attached to #3423, however I do not believe it was related to the original problem. Nevertheless, the original issue specifically called out Protection, so I put some Protection tests in the validation test for the fix. In doing so, I found that Style/Protection is particularly confusing. Its properties will often have the value `inherit`, which isn't all that helpful; and, even when the `locked` value is `protected`, the cell won't actually be locked unless the sheet is protected as well. The `hidden` property is even more obscure - it applies only to formulas, and refers to hiding the property on the formula bar, not in the cell. I have added methods `isLocked` and `isHiddenOnFormulaBar` to `Cell`. I corrected the docs to explain this. And, as long as I was looking at the docs, I corrected some examples to use `getHighestDataRow/Column` rather than `getHighestRow/Column`, a frequent problem for users (e.g. #3721).

As a side note, the change to Cell.php is my first use of the nullsafe operator. This is one of many new options available now that we require Php8.0+.

* Minor Simplifications

* Scrutinizer

It's being silly again. In many tests, we test a variable for non-null, then use that variable later and Scrutinizer knows it's not null. Not here. Oh well.

* Add Methods

Test if protected without allocating cell if it doesn't exist.
2023-09-12 19:13:03 -07:00
Adrien Crivelli 7712d5561b Check PHPDoc types of the PR's last commit 2023-09-13 10:06:58 +08:00
Adrien Crivelli ebda3fdda1 Drop dead code 2023-09-13 10:06:58 +08:00
Adrien Crivelli bb6ae9ce7d Prevent adding PHPDoc types instead of native types
PHPDoc types can sometimes be entirely expressed as PHP native types. It
is better because it avoids code duplication and enables type runtime
check.

This will help us slowly migrate away from PHPDoc typing to PHP native typing.
2023-09-13 10:06:58 +08:00
Adrien Crivelli 2a9f2f57b9 Rector MixedTypeRector 2023-09-13 10:06:58 +08:00
Adrien Crivelli f4c1519869 Rector ChangeSwitchToMatchRector 2023-09-13 10:06:58 +08:00
Adrien Crivelli de658b44e1 Rector RemoveUnusedVariableInCatchRector 2023-09-13 10:06:58 +08:00
Adrien Crivelli f6f1e27f98 Rector ClassOnObjectRector 2023-09-13 10:06:58 +08:00
Adrien Crivelli e65e46db43 Rector StringableForToStringRector 2023-09-13 10:06:58 +08:00
Adrien Crivelli b881309496 Rector StrContainsRector, StrStartsWithRector, StrEndsWithRector 2023-09-13 10:06:58 +08:00
Adrien Crivelli bf462986f2 Update changelog 2023-09-12 13:59:19 +08:00
Adrien Crivelli 1b27d9c95d Stronger typing for newly introduced methods 2023-09-12 11:24:02 +08:00