Commit Graph

4517 Commits

Author SHA1 Message Date
oleibman f64e0ecd79 Merge branch 'master' into issue3951 2024-03-24 17:40:54 -07:00
oleibman 891180e13d Protect Sheet But Allow Sort
Fix #3951. When an Excel sheet is protected, even when sorting is explicitly allowed without a password, sorts are permitted only on "protected ranges" within the sheet. PhpSpreadsheet already supports protected ranges, and only minor tinkering is necessary for that (e.g. the protected range can have, but does not require, a password). The more important part of this change is documenting the far-from-intuitive way that Excel handles this. To that end, documentation is updated, and a new sample is added.

A new class, `Worksheet\ProtectedRange` is added in place of the string array which had been used. `Worksheet::getProtectedCells` is deprecated in favor of the new `Worksheet::getProtectedCellRanges`.
2024-03-20 07:04:24 -07:00
oleibman a6ef9a7b28 Merge pull request #3945 from oleibman/hidecol
Hidden Rows and Columns - Tcpdf and Mpdf
2024-03-19 21:09:54 +00:00
oleibman 8a1d424056 Merge pull request #3942 from oleibman/issue3935
Invalid Builtin Defined Name in Xls Reader
2024-03-19 21:05:40 +00:00
oleibman 2a8345dde9 Merge pull request #3940 from oleibman/issue3923
Unallocated Cells Affected by Column/Row Insert/Delete
2024-03-15 22:53:40 +00:00
oleibman fbcd68ce87 Update CHANGELOG.md 2024-03-15 15:49:29 -07:00
oleibman 44e8b4886c Merge branch 'master' into issue3923 2024-03-15 14:07:25 -07:00
oleibman 9b3f205528 Merge pull request #3939 from oleibman/sysformats2
Additional Support for Date/Time Styles
2024-03-15 18:49:01 +00:00
oleibman 26882fed90 Allow Scrutinizer C
I am tired of complexity warnings for non-complex code.
2024-03-11 19:34:57 -07:00
oleibman 47012ba228 Hidden Rows and Columns - Tcpdf and Mpdf
Tcpdf issues warnings when processing hidden rows. Some time ago, Mpdf was having problems in the same situation; this was resolved by not writing out hidden rows in the html which Mpdf uses to generate its file. The same solution can be easily applied to Tcpdf.

Neither Tcpdf nor Mpdf handles hidden columns. Dompdf doesn't have a problem with either rows or columns. At any rate, the solution for Tcpdf/Mpdf is to not write out the data in the hidden columns. It is more difficult to implement this for columns than for rows, but this PR should do the trick.

Html writer generally uses `display:none` for the data in suppressed columns. This works, but is technically incorrect - the "approved" method is `visibility:collapse` on the col element. However, Firefox doesn't handle that correctly (open bug was filed over a decade ago), and, since all browsers seem to handle the existing implementation, it is left alone.

Among other considerations, this PR is a necessary precursor for supporting printArea in Html/Pdf should we decide to do that (issue #3941).

Writer/Html protected property `$isMPdf` is deprecated with this PR in favor of testing for `instanceof Mpdf`.
2024-03-11 18:54:48 -07:00
Mark Baker d01575416a Merge pull request #3937 from PHPOffice/Looping_the_Loop
Documentation about Iterating through Cells
2024-03-11 15:24:53 +00:00
Mark Baker a1e1af697c Merge pull request #3936 from PHPOffice/Behind_the_Mask
Documentation about Number Format Masking
2024-03-11 15:17:14 +00:00
Mark Baker 7b55c61552 Merge pull request #3938 from PHPOffice/The_Dating_Game
Documentation about Date Handling
2024-03-11 15:13:54 +00:00
oleibman 5fb1fb48b5 Invalid Builtin Defined Name in Xls Reader
Fix #3935. Xls Reader cannot parse user's spreadsheet, failing on a token of 3d. I believe that, according to https://msopenspecs.azureedge.net/files/MS-XLS/%5bMS-XLS%5d.pdf, this represents a PtgAreaErr3d, i.e. an invalid reference. User cannot provide spreadsheet, but was quite forthcoming in providing additional debugging information. I am usually reluctant to make changes without a test case, however, in this case, the action being taken (treat "builtin" defined name as "not builtin" when it cannot be parsed) makes sense, and it satisfies the user's processing.
2024-03-09 12:56:21 -08:00
oleibman 7893942a72 Unallocated Cells Affected by Column/Row Insert/Delete
Fix #3923. Cells which have not yet been allocated cause problems when they need to be moved due to a column/row insert/delete. Code had been added in ReferenceHelper earlier to create missing cells, but only in the last data column. It needs to change to create the missing cells:
- for columns, in rows 1 to "highest data row" for columns "before column" to "highest data column".
- for rows, in columns A to "highest data column" for rows "before row" to "highest data row".
2024-03-09 11:05:50 -08:00
oleibman accb321197 Additional Support for Date/Time Styles
Excel supports the following notations for cell styles:
- `[$-F800]` and `[$-x-sysdate]` will format the date according to what appears to be the user's system long date format.
- `[$-F400]` and `[$-x-systime]`, will format the time according to what appears to be the user's system long time format.
- Builtin style 14 will format date according to what appears to be the user's system short date format.
- Builtin style 22 will format date and time according to the user's preference. It appears that the date portion is formatted according to the user's system short date format, but the time portion is formatted according to a format which is neither system short time format nor system long time format, so I'm not sure how this preference is set.

For F800, sysdate, F400, and systime, any other characters in the style are ignored, except that, if you have more than one of this type of block in the style, Excel will treat it as corrupt (error message on open and style changed to General).

Support is added for the new codes. In addition, note that the value displayed in the cell may differ in different environments. To give the PhpSpreadsheet programmer an opportunity to emulate what the intended audience will most often see, properties `shortDateFormat` (default value is builtin 14), `longDateFormat` (default value is `dddd, mmmm d, yyyy`), `dateTimeFormat` (defaults to builtin 22), and `timeFormat` (default is `FORMAT_DATE_TIME2`), with corresponding setters and getters, are added to Style/NumberFormat. Note that, if these properties are set to some other value in PhpSpreadsheet, it will not affect the values in the cell or the style - it is merely a convenience for the programmer. It will, however, affect column width if autosize is specified for the column. If the programmer does not alter any of the new properties, the output should be unchanged from before for builtins 14 and 22.

The new styles are also recognized by the `TEXT` function. In this case, the cell's calculated value may differ from user to user.

Note that this is a small subset of adding locale information to styles. No attempt is made to support any of the other possibilities - locale data will continue to be passed through to the spreadsheet, but PhpSpreadsheet will discard it before attempting to generate the formatted value of a cell.
2024-03-08 21:13:56 -08:00
oleibman 9a94aea7ad Merge pull request #3924 from oleibman/issue3918
Default Style Alignment
2024-03-09 04:23:01 +00:00
oleibman 280c18e8ee Update CHANGELOG.md 2024-03-08 20:17:13 -08:00
oleibman 5587ca0cd5 Merge branch 'master' into issue3918 2024-03-08 19:14:49 -08:00
oleibman 9c5bf341be Merge pull request #3923 from oleibman/issue3730
Unexpected Absolute Address in Xlsx Rels File
2024-03-08 06:28:25 +00:00
MarkBaker 3435faeca5 Documentation about Date Handling 2024-03-07 12:38:38 +01:00
MarkBaker 868f6d4abe Documentation about Iterating through Cells 2024-03-07 12:37:40 +01:00
MarkBaker 790f489fe2 Documentation about Number Format Masking 2024-03-07 12:35:20 +01:00
oleibman bea48f068c Merge pull request #3929 from PHPOffice/dependabot/composer/squizlabs/php_codesniffer-3.9.0
Bump squizlabs/php_codesniffer from 3.8.1 to 3.9.0
2024-03-01 17:08:05 +00:00
oleibman d1378929c2 Merge pull request #3928 from PHPOffice/dependabot/composer/phpstan/phpstan-phpunit-1.3.16
Bump phpstan/phpstan-phpunit from 1.3.15 to 1.3.16
2024-03-01 17:07:38 +00:00
oleibman 95b9125206 Merge pull request #3927 from PHPOffice/dependabot/composer/phpstan/phpstan-1.10.59
Bump phpstan/phpstan from 1.10.57 to 1.10.59
2024-03-01 17:07:14 +00:00
oleibman 89f996ad95 Merge pull request #3926 from PHPOffice/dependabot/composer/phpunit/phpunit-9.6.17
Bump phpunit/phpunit from 9.6.16 to 9.6.17
2024-03-01 17:06:44 +00:00
oleibman 617393291f Merge pull request #3925 from PHPOffice/dependabot/composer/friendsofphp/php-cs-fixer-3.51.0
Bump friendsofphp/php-cs-fixer from 3.48.0 to 3.51.0
2024-03-01 17:06:06 +00:00
dependabot[bot] a749480a42 Bump squizlabs/php_codesniffer from 3.8.1 to 3.9.0
Bumps [squizlabs/php_codesniffer](https://github.com/PHPCSStandards/PHP_CodeSniffer) from 3.8.1 to 3.9.0.
- [Release notes](https://github.com/PHPCSStandards/PHP_CodeSniffer/releases)
- [Changelog](https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/CHANGELOG.md)
- [Commits](https://github.com/PHPCSStandards/PHP_CodeSniffer/compare/3.8.1...3.9.0)

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

Signed-off-by: dependabot[bot] <support@github.com>
2024-03-01 11:58:44 +00:00
dependabot[bot] e4ff49566e Bump phpstan/phpstan-phpunit from 1.3.15 to 1.3.16
Bumps [phpstan/phpstan-phpunit](https://github.com/phpstan/phpstan-phpunit) from 1.3.15 to 1.3.16.
- [Release notes](https://github.com/phpstan/phpstan-phpunit/releases)
- [Commits](https://github.com/phpstan/phpstan-phpunit/compare/1.3.15...1.3.16)

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

Signed-off-by: dependabot[bot] <support@github.com>
2024-03-01 11:58:38 +00:00
dependabot[bot] d62172a35d Bump phpstan/phpstan from 1.10.57 to 1.10.59
Bumps [phpstan/phpstan](https://github.com/phpstan/phpstan) from 1.10.57 to 1.10.59.
- [Release notes](https://github.com/phpstan/phpstan/releases)
- [Changelog](https://github.com/phpstan/phpstan/blob/1.11.x/CHANGELOG.md)
- [Commits](https://github.com/phpstan/phpstan/compare/1.10.57...1.10.59)

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

Signed-off-by: dependabot[bot] <support@github.com>
2024-03-01 11:58:33 +00:00
dependabot[bot] 35c6111a23 Bump phpunit/phpunit from 9.6.16 to 9.6.17
Bumps [phpunit/phpunit](https://github.com/sebastianbergmann/phpunit) from 9.6.16 to 9.6.17.
- [Changelog](https://github.com/sebastianbergmann/phpunit/blob/9.6.17/ChangeLog-9.6.md)
- [Commits](https://github.com/sebastianbergmann/phpunit/compare/9.6.16...9.6.17)

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

Signed-off-by: dependabot[bot] <support@github.com>
2024-03-01 11:58:22 +00:00
dependabot[bot] ee1fd8b9aa Bump friendsofphp/php-cs-fixer from 3.48.0 to 3.51.0
Bumps [friendsofphp/php-cs-fixer](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer) from 3.48.0 to 3.51.0.
- [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.48.0...v3.51.0)

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

Signed-off-by: dependabot[bot] <support@github.com>
2024-03-01 11:58:14 +00:00
oleibman 76b2dc70ea Merge pull request #3915 from oleibman/issue3907
Formula Misidentifying Text as Cell After Insertion/Deletion
2024-03-01 01:19:03 +00:00
oleibman c51ec67327 Update CHANGELOG.md 2024-02-29 17:15:36 -08:00
oleibman 4a459e0558 Merge branch 'master' into issue3907 2024-02-29 17:05:04 -08:00
oleibman b020c208c2 Merge pull request #3916 from oleibman/issue3909
Incorrect SUMPRODUCT Calculation
2024-02-29 21:09:04 +00:00
oleibman d418762a33 Win For Scrutinizer
It pointed out a problem that I would have thought should result in test failure. Code corrected, and documentation updated to describe the unexpected behavior.
2024-02-29 12:18:34 -08:00
oleibman d46b7b3e9d Default Style Alignment
Fix #3918, sort of. Xlsx cells use the default style when they omit the `s` tag, or when `s="0"` is specified. LibreOffice does not honor Alignment in the default Style unless the cell explicitly uses the second form, even though it honors other default Styles (e.g. bold font) when `s` is omitted. Gnumeric seems to have the same problem. A bug report has been filed with LibreOffice.

In the meantime, this PR adds to Xlsx Writer an optional boolean property `explicitStyle0` with setter and getter. Default is false, which will continue the current behavior by adding an `s` tag only when the cell uses a non-default style (this is how Excel itself behaves). When set to true, Xlsx Writer will explicity write `s="0"` for all cells using default style. This will allow users to create an Xlsx spreadsheet with default alignment of cells that will show up correctly when the spreadsheet is viewed with LibreOffice. Technically speaking, it is *probably* safe to always use `true`, except that the spreadsheet size will be a bit larger. However, my hope is that this is a temporary measure which can go away when the vendors have had a chance to fix their problems, hence the `false` default.
2024-02-29 11:11:00 -08:00
oleibman 41dd6c373d Unexpected Absolute Address in Xlsx Rels File
Fix #3730. File workbook.xml.rels in test file specified absolute addressing for shared strings, styles, and worksheets. Previous changes had addressed absolute addressing for worksheets, but shared strings and styles had not yet been addressed.
2024-02-29 07:38:38 -08:00
oleibman d09120d209 Merge pull request #3921 from rdey/hotfix/prepending-zero-prc
Fix issue with prepending zero in percentage -10<n<-9
2024-02-28 15:41:43 +00:00
Nicholas Ruunu c1d141bea3 Fix issue with prepending zero in percentage
Before it was a bug when flooring negative numbers added to the length of
the number for the sprintf mask.
For example -0.091 becomes -9.1 in percentage, floors to -10 which is going to
increase $wholePartSize by 1 and add a leading zero to the result: -09.1% with
format 0.0%.
This happened for negative ranges where floor will increse the length of
the original number.
2024-02-27 23:31:16 +01:00
oleibman dc84a51f74 Merge pull request #3906 from oleibman/issue3904c
Improve Performance of Csv Writer
2024-02-23 05:05:15 +00:00
oleibman 3dd40ee634 Update CHANGELOG.md 2024-02-22 20:59:05 -08:00
oleibman 9a685e378a Merge branch 'master' into issue3904c 2024-02-22 20:42:18 -08:00
oleibman 64bdc6424c Incorrect SUMPRODUCT Calculation
Fix #3909. SUMPRODUCT is mishandling multi-row ranges. In Calculation/Calculation, `checkMatrixOperands` will often resize its operands. When it does so, it needs to recalculate the dimensions of each. This fixes the reported problem.

Likely cause was PR #3260. That ticket noted the poor coverage of the code being replaced. Tests of the problem in this ticket were absent and are now added. Despite this, I note that `resizeMatricesShrink` is virtually uncovered, and `resizeMatricesExpand` has substantial gaps in its coverage. I have covered some, but not all, of the Expand gaps. I am struggling to come up with examples to fill its remaining gaps and those for Shrink. However, I will merge this fix in about a week even if I don't succeed.
2024-02-21 22:32:30 -08:00
oleibman a096fcc77d Formula Misidentifying Text as Cell After Insertion/Deletion
Fix #3907. After row/column insertion/deletion, PhpSpreadsheet updates formulas which include cells which have moved. However, it can mis-identify cell addresses within the formula. Examples:
- `=SUM(A2,'F1 (SETTINGS)'!A1:B1)` It identifes F1 as a cell address.
- `=SUM(A2,'x F1 (SETTINGS)'!A1:B1)` It identifes F1 as a cell address. (This looks the same as the above, but, for technical reasons, it's different.)
- `=SUM(A2,definedname1A1)` It identifes A1 as a cell address.
- Sheet names in formulas are compared case-sensitively, and should be compared insensitively. This can make a difference if the formula includes its own sheet name, e.g. on sheet `Data`, formula `=SUM(DATA!A1:A2)` might have to change, but it will not do so with the existing logic.

The defined name part is fairly straightforward. The regular expressions that identify a cell address just have to be a bit more robust. It was doing a negative look-behind for an alphabetic character or dollar sign; underscore, period, and digits, all of which can be part of a defined name, need to be added to that list.

The other situations need a bit of a kludge, but not one so bad that I'm ashamed of it. The formulas will be altered before analysis so that sheet names are replaced with Unicode FFFD (sheetname does not match current sheet), FFFC (sheetname, enclosed in apostrophes, matches current sheet), and FFFB (sheetname, not enclosed in apostrophes, matches current sheet). This prevents the existing regular expressions from finding a cell address within a sheet name, and makes it easy to restore the original, with or without apostrophes, when the sheet name matches the current sheet and the cell(s) which it qualifies have to be changed.

Tests are added for all the situations mentioned above. No existing tests required changes.
2024-02-21 22:10:58 -08:00
oleibman d0393a2eed Merge pull request #3903 from oleibman/issue3900
Handling of User-supplied Decimal and Thousands Separators
2024-02-22 06:04:20 +00:00
oleibman 0c8a80e834 Merge pull request #3914 from PHPOffice/dependabot/composer/phenx/php-svg-lib-0.5.2
Bump phenx/php-svg-lib from 0.5.1 to 0.5.2
2024-02-21 22:36:25 +00:00
dependabot[bot] d0895c65de Bump phenx/php-svg-lib from 0.5.1 to 0.5.2
Bumps [phenx/php-svg-lib](https://github.com/PhenX/php-svg-lib) from 0.5.1 to 0.5.2.
- [Release notes](https://github.com/PhenX/php-svg-lib/releases)
- [Commits](https://github.com/PhenX/php-svg-lib/compare/0.5.1...0.5.2)

---
updated-dependencies:
- dependency-name: phenx/php-svg-lib
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-02-21 18:29:46 +00:00