Commit Graph

4966 Commits

Author SHA1 Message Date
oleibman 2f445a1ade Change Hash Code for Worksheet
Fix #4192. Although that issue can be dealt with by changing user code, it would be better to fix it within PhpSpreadsheet. A cloned worksheet may have a pointer to a spreadsheet to which it is not attached. Code can assume it does belong to the spreadsheet, and throw an exception when the spreadsheet cannot find the worksheet in question. It may also not throw an exception when it should.

In my comments to the issue, I was concerned that adding in the needed protection would add overhead to an extremely common situation (setting a cell's value) in order to avoid a pretty rare problem. However, there are problems with both the accuracy and efficiency of the existing code, and I think any performance losses caused by the additional checks will be offset by the performance gains and accuracy of the new code.

Spreadsheet `getIndex` attempts to find the index of a worksheet within its spreadsheet collection. It does so by comparing the hash codes of each sheet in its collection with the hash code of the sheet it is looking for. Its major problem problem is performance-related, namely that it recomputes the hash code of the target sheet with each iteration.

A more severe problem is the accuracy of the hash code. It generates this by hashing together the sheet title, the string range of its auto-filter, and a character representation of whether sheet protection is enabled. Title should definitely be part of the calculation (it must be unique for all sheets attached to a spreadsheet), but it is not clear why this subset of the other properties of Worksheet is used. It tries to save some cycles by using a `dirty` property to indicate whether re-hashing is necessary. It sets that property whenever the title changes, or when `setProtection` is called. So, it doesn't set it when auto-filter changes, and you can easily bypass `setProtection` when changing any of the `Protection` properties. Not to mention the many other properties of worksheet that can be changed. Additionally, if you clone a worksheet, the clone and the original will have the same hash code, which can lead to problems:
```php
$clone = clone $original;
$spreadsheet->getSheet($spreadsheet->getIndex($clone))
    ->setCellValue('A1', 100);
```
That code will change the value of A1 in the original, not the clone.

The `hash` property in Worksheet will now be calculated immediately when the object is constructed or cloned or unserialized. It will not be recalculated, and there is no longer a need for the `dirty` property, which is removed. Hash will be generated by spl_object_id, which was designed for this purpose. (So was spl_object_hash, but many online references suggest that \_id performs much better than \_hash.) Our problem example above will now throw an Exception, as it should, rather than changing the wrong cell. `setValueExplicit`, the problem in the original issue, will now test that the worksheet is attached to the spreadsheet before doing any style manipulation. In order that this not be a breaking change, `getHashCode` will continue to return string, but it is deprecated in favor of `getHashInt`, and Worksheet will no longer implement IComparable to facilitate the deprecation.

I had a vague hope that this change might help with issue #641. It doesn't.
2024-10-30 17:25:49 -07:00
oleibman 8799a041a0 Merge pull request #4189 from oleibman/csvphp9
Method to Test Whether Csv Will Be Affected by Php9
2024-10-15 04:32:15 +00:00
oleibman 75ccdb09ad Update CHANGELOG.md 2024-10-14 21:27:22 -07:00
oleibman 753732b5c3 Merge branch 'master' into csvphp9 2024-10-14 21:12:16 -07:00
oleibman 748ef0ab53 Restore Comment
I don't get it. Phpstan should pass this statement in Php8.3, but doesn't.
2024-10-13 20:39:19 -07:00
oleibman 333cb21f6d Eliminate Misleading Comment 2024-10-13 20:25:08 -07:00
oleibman dae5077660 Minor Tweak 2024-10-13 15:40:55 -07:00
oleibman d16407bea8 Make guessEncodingBom Public
It can be used elsewhere.
2024-10-13 15:04:26 -07:00
oleibman d6a367688b Merge pull request #4190 from yingshanghuangqiao/master
chore: remove unnecessary symbol
2024-10-13 20:16:56 +00:00
oleibman 45efe7be08 Merge pull request #4188 from oleibman/issue562
Allow Omitting Chart Border
2024-10-13 20:15:30 +00:00
oleibman f3249bceef Update CHANGELOG.md 2024-10-13 13:13:10 -07:00
yingshanghuangqiao bfb25a320f chore: remove unnecessary symbol 2024-10-13 20:04:19 +08:00
oleibman c14a1e623b Merge branch 'master' into issue562 2024-10-12 23:15:21 -07:00
oleibman 817556b0ac Merge pull request #4187 from oleibman/issue2157
Excel 2003 Allows Html Entities
2024-10-13 05:48:15 +00:00
oleibman 672be54765 Update CHANGELOG.md 2024-10-12 22:45:52 -07:00
oleibman 62a0d40f13 Merge branch 'master' into issue2157 2024-10-12 22:30:13 -07:00
oleibman f4919af1a4 Merge pull request #4118 from oleibman/brkupxlsr2
Refactor Xls Reader
2024-10-13 05:23:46 +00:00
oleibman f981ef95c9 Minor Tweak 2024-10-11 14:06:10 -07:00
oleibman 1326e37007 Update LoadSpreadsheet.php 2024-10-09 21:04:59 -07:00
oleibman 9e173572fe Merge branch 'master' into brkupxlsr2 2024-10-09 20:55:56 -07:00
oleibman 39fc513091 Merge pull request #4185 from oleibman/valuebinder
Add Dynamic valueBinder Property to Spreadsheet and Readers
2024-10-10 03:24:23 +00:00
oleibman fab7818bdb Update CHANGELOG.md 2024-10-09 20:22:04 -07:00
oleibman 9fe3d71518 Merge branch 'master' into valuebinder 2024-10-09 17:34:48 -07:00
oleibman 545b098acd Method to Test Whether Csv Will Be Affected by Php9
See #4161. The best way to future-proof is to set the escape character to null string, and set testAutoDetect to false before reading. However, depending on the file being read, this may lead to different results than expected. This will be unavoidable because Php itself will change. This PR adds a new static method `affectedByPhp9` to Csv Reader. This can be used to identify in advance whether an input file will be affected by the changes. This will allow users to identify problems in advance, and prepare for how they might be handled.
2024-10-09 07:07:16 -07:00
oleibman 7a1370c869 Allow Omitting Chart Border
Fix #562.
2024-10-09 06:37:25 -07:00
oleibman 31947576c9 Merge pull request #4184 from oleibman/issue1107
Invalid Html Due to Cached Filesize
2024-10-09 13:10:32 +00:00
oleibman 5fcce81eed Update CHANGELOG.md 2024-10-09 06:08:09 -07:00
oleibman bd92aebec6 Merge branch 'master' into issue1107 2024-10-09 05:28:29 -07:00
oleibman 88c517f335 Merge pull request #4151 from oleibman/issue1412
Option to Write Hyperlink Rather than Label to Csv
2024-10-08 04:29:17 +00:00
oleibman 7176dcf62e Update CHANGELOG.md 2024-10-07 21:27:12 -07:00
oleibman 7471ca8bf6 Merge branch 'master' into issue1412 2024-10-07 21:09:59 -07:00
oleibman 8a57259141 Merge pull request #4142 from oleibman/imgtransparent
Image Transparency/Opacity Including Html Reader Changes
2024-10-08 03:50:46 +00:00
oleibman cbf7861eb3 Update CHANGELOG.md 2024-10-07 20:48:12 -07:00
oleibman d63ccf9671 Small Error Resolving Merge Conflict 2024-10-07 12:33:56 -07:00
oleibman d2b3a8d5f7 Merge branch 'master' into imgtransparent 2024-10-07 10:50:37 -07:00
oleibman c6ede15401 Merge pull request #4148 from oleibman/stan9again4
Better Definitions for Mixed Parameters and Values Part 4 of Many
2024-10-07 17:31:02 +00:00
oleibman 6ac7d5ffce Merge pull request #4158 from oleibman/stanupgrade
Upgrade Phpstan
2024-10-07 16:08:07 +00:00
oleibman 59532b49a6 Merge branch 'master' into brkupxlsr2 2024-10-06 17:10:49 -07:00
oleibman 95a83a19c5 Merge branch 'master' into stanupgrade 2024-10-06 09:50:16 -07:00
oleibman 32cb9f488f Excel 2003 Allows Html Entities
Fix #2157. Excel 2003 format allows some things which a real Xml parser would reject. In particular, it permits Html entities, and leading whitespace. Change Xml Reader to do likewise.
2024-10-06 09:32:11 -07:00
oleibman 37bb1537c8 Merge pull request #4186 from oleibman/issue4182
SUMIFS Does Not Require _xlfn
2024-10-06 15:54:49 +00:00
oleibman c1ad483670 Merge branch 'master' into issue4182 2024-10-06 08:52:36 -07:00
oleibman d327481b82 Update CHANGELOG.md 2024-10-06 08:51:03 -07:00
oleibman dab6ba83e4 SUMIFS Does Not Require _xlfn
Fix #4182. It was on our list as "introduced in 2019". It was, in fact, available with Excel 2007 (https://support.microsoft.com/en-us/office/excel-functions-alphabetical-b3944572-255d-4efb-bb96-c6d90033e188#bm19), so does not require a prefix when writing it to a spreadsheet.
2024-10-06 08:35:26 -07:00
oleibman 1b64b42481 Add Dynamic valueBinder Property to Spreadsheet and Readers
Fix #1395, a 2020 issue which had been marked stale and is now re-opened. Static valueBinder property of Cell isn't ideal. It would be more flexible to make it a dynamic property of the spreadsheet. Static property will continue to be used, but dynamic property will be used first if it is set. Readers will also be changed to add a valueBinder property which they pass to the spreadsheet; however, it will make a difference only for Csv/Html/Slk, since the other readers use setValueExplicit which ignores valueBinder.

Documentation is updated in several places to note that dynamic property is preferred over static.
2024-10-05 23:59:44 -07:00
oleibman 6382dba985 Invalid Html Due to Cached Filesize
Fix #1107. Clear statcache for file before requesting its size.
2024-10-05 23:15:57 -07:00
oleibman 27d7920c01 Merge pull request #4183 from oleibman/updchglog3
Update Change Log
2024-10-06 06:06:12 +00:00
oleibman c4fd8eca2b Update Change Log 2024-10-05 23:02:02 -07:00
oleibman 13c3ec9692 Merge pull request #4180 from oleibman/issue4179
Xlsx Writer Duplicate ContentTypes Entry for Background Image
2024-10-06 05:31:12 +00:00
oleibman 44014f84ac Merge pull request #4152 from oleibman/issue3185
Xls Writer Conditional Rules Applied to Whole Rows or Columns
2024-10-06 05:21:39 +00:00