Commit Graph

4005 Commits

Author SHA1 Message Date
MarkBaker 9c2deb125f Scrutinizer really sucks!!!
Stop a few of scrutinizers complaints about 100% valid use of PHP variadics.
Hopefully, this issue will cease to be an issue when we can specify mixed datatype for variadic arguments in the tests
2023-03-10 04:43:11 +01:00
MarkBaker a91dd60a98 Refactor unit tests to ensure that assertions are in the actual test, and not in an abstract class; and that setup/teardown are in the test and not an abstract. This means that assertions and setup/teardown are always in the file when reviewing PRs.
Also enforce more rigorous Excel Function implementation by testing the underlying implementation, call via the Calc Engine, and execution from in a worksheet.
Separate out unhappy path (exception) checks into a separate test, so that a single test isn't made overcomplex checking for every potentiality.

Scrutinizer may dislike variadics, for variable number of arguments of mixed type; but tough. It's 100% valid PHP, accepted by phpstan, and makes life a lot easier.

Initial work here covers all the database and datetime unit tests for Excel function implementations.
2023-03-10 04:15:12 +01:00
oleibman 20348642ed More Display Options for Chart Axis and Legend (#3434)
* Allow Color and Effects on Data Points on Chart Axis

Fix #3414. There had been no way to do this. It is now supported via a new AxisText class, which derives from Properties, and has FillColor and effects (glow/shadow/softEdges) properties. The code changes in chart sample 33_Chart_create_scatter2 illustrate usage.

* Minor Performance Improvement

May also get rid of Scrutinizer complaint.

* Eliminate New Spacing Patch

No need for it.

* Add Legend Formatting to Change

Much in common with Data Point formatting.
2023-03-09 10:15:24 -08:00
Mark Baker 64f32d8c75 Merge pull request #3441 from PHPOffice/Documentation-Updates
Update recipe docs for Spreadsheet Properties.
2023-03-09 17:52:08 +01:00
MarkBaker d73d063556 Update contributor notes and related composer scripts 2023-03-09 17:38:20 +01:00
MarkBaker 202964ee26 Minor update to documentation index 2023-03-09 17:37:50 +01:00
MarkBaker 15044fd20d Formats for custom date properties 2023-03-09 01:47:06 +01:00
MarkBaker 68873e632d Update recipe docs for Worksheets 101, and setting the Active Worksheet. 2023-03-08 21:23:54 +01:00
MarkBaker b5b64ebe6e Update recipe docs for Spreadsheet Properties. 2023-03-08 20:07:07 +01:00
oleibman 73f880ff19 Correct Xlsx Parsing of quotePrefix="0" (#3438)
* Correct Xlsx Parsing of quotePrefix="0"

Fix #3435. Mis-parsed attribute is not normally generated by Excel or PhpSpreadsheet, but some 3rd-party software (correctly) generates it.

* Update Issue3435Test.php
2023-03-07 07:51:20 -08:00
Mark Baker cba1f07235 Merge pull request #3437 from PHPOffice/Issue-3436_EDATE-EOMONTH-Rounding-to-Date
Fix for Issue #3436 - Result from Excel's EDATE() and EOMONTH() should always be rounded to 0 decimal
2023-03-06 17:40:55 +01:00
MarkBaker 9006d2a3f4 Fix for Issue #3436 - Result from Excel's EDATE() and EOMONTH() should always be rounded to 0 decimal 2023-03-06 17:22:30 +01:00
oleibman bb54c89cde Xlsx Column Autosize Approximate for CJK (#3416)
Fix #3405. Autosize is definitely not working well with CJK characters (column is not wide enough). User reports a workaround using `mb_strwidth` to calculate and set the column width. PhpSpreadsheet uses `mb_strlen` for width calculations. Change it to use mb_strwidth instead. For non-CJK strings, the results will be identical (and there are already unit tests on such strings which assert the expected results, and these tests did not need to change). For CJK strings, the results will be wider. The string I'm using to test comes from the issue. It currently results in a column width of 30.564. When I open the resulting sheet in Excel and auto-fit the column width, the width winds up as 43.00. So, as long as the computed width exceeds 43.00, the spreadsheet will show the full cell. With the new calculation, the computed width is 55.2722, satisfying our condition. This is wider than expected, but that is generally true for this type of computation. For example, for 'abcdefghijklmnopqrstuvwxyz', the computed width (before and after this change) is 31.7065, but Excel auto-fit actually uses 24.73.

Disappointingly, "exact width calculation" does not solve this problem. It does seem to do a little better than "approximate" for non-CJK, but its CJK calculation is not wide enough. This might or might not indicate a bug in Php function `imagegetttfbbox`; I do not know enough about it to report a bug. Anyhow, since we're dependent on that result, there is no equivalent in this case for swapping mb_strlen out for mb_strwidth.
2023-03-04 07:37:52 -08:00
Mark Baker 0610e57c48 Merge pull request #3429 from PHPOffice/RichText_Update-Recipe-in-docs
Update to Docs for RichText
2023-03-02 16:15:05 +01:00
MarkBaker aa374fde4c Update to Docs for RichText 2023-03-02 16:09:59 +01:00
oleibman 66221bfcb2 TEXT Function Ignores Time in DateTimeStamp (#3411)
Fix #3409. Calculate both the date and time portions when a date/time format is supplied for the TEXT function.
2023-03-01 19:57:49 -08:00
oleibman bef3a0066b Misplaced Xml Writing Chart Label FillColor (#3404)
* Misplaced Xml Writing Chart Label FillColor

Fix #3397. Move code to correct location.

* Update Issue3397Test.php

No need for spacing patch - just fix it now.

* Minor Fix

See discussion at bottom of PR #2856.
2023-03-01 19:19:41 -08:00
MarkBaker 79d817fcdf Update to ReadMe 2023-03-01 19:24:22 +01:00
Mark Baker 51026a4807 Merge pull request #3424 from PHPOffice/ReferenceHelper_Stricter-TypingCasting
Stricter typing for ReferenceHelper methods
2023-03-01 18:55:45 +01:00
Mark Baker 6d5af9338f Merge branch 'master' into ReferenceHelper_Stricter-TypingCasting 2023-03-01 18:50:25 +01:00
oleibman 1fc9728818 PhpStan 10.3 (#3425)
Address the usual collection of new messages. This will supersede PR #3417 and PR #3421.
2023-03-01 09:28:58 -08:00
MarkBaker 09acdab939 Stricter typing for ReferenceHelper methods; and performance improvements for cell sorting in ReferenceHelper callbacks
Scrutinizer can only be appeased by adding extra code to pre-define variables that don't need to be pre-defined, and that makes for additional code overhead in a routine that needs to be as performant as possible; so "scrutinizer be damned!"
2023-03-01 18:09:12 +01:00
dependabot[bot] 9a4c6a1d2b Bump squizlabs/php_codesniffer from 3.7.1 to 3.7.2 (#3420)
Bumps [squizlabs/php_codesniffer](https://github.com/squizlabs/PHP_CodeSniffer) from 3.7.1 to 3.7.2.
- [Release notes](https://github.com/squizlabs/PHP_CodeSniffer/releases)
- [Commits](https://github.com/squizlabs/PHP_CodeSniffer/compare/3.7.1...3.7.2)

---
updated-dependencies:
- dependency-name: squizlabs/php_codesniffer
  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>
2023-03-01 08:33:32 -08:00
dependabot[bot] fe62c40048 Bump friendsofphp/php-cs-fixer from 3.14.3 to 3.14.4 (#3422)
Bumps [friendsofphp/php-cs-fixer](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer) from 3.14.3 to 3.14.4.
- [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.14.3...v3.14.4)

---
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>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-01 07:10:11 -08:00
dependabot[bot] 99dbf040cf Bump mitoteam/jpgraph from 10.2.4 to 10.2.5 (#3419)
Bumps [mitoteam/jpgraph](https://github.com/mitoteam/jpgraph) from 10.2.4 to 10.2.5.
- [Release notes](https://github.com/mitoteam/jpgraph/releases)
- [Commits](https://github.com/mitoteam/jpgraph/compare/10.2.4...10.2.5)

---
updated-dependencies:
- dependency-name: mitoteam/jpgraph
  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>
2023-03-01 06:52:45 -08:00
dependabot[bot] 8b62e799ec Bump phpunit/phpunit from 9.6.3 to 9.6.4 (#3418)
Bumps [phpunit/phpunit](https://github.com/sebastianbergmann/phpunit) from 9.6.3 to 9.6.4.
- [Release notes](https://github.com/sebastianbergmann/phpunit/releases)
- [Changelog](https://github.com/sebastianbergmann/phpunit/blob/main/ChangeLog-9.6.md)
- [Commits](https://github.com/sebastianbergmann/phpunit/compare/9.6.3...9.6.4)

---
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>
2023-03-01 06:43:00 -08:00
Mark Baker 717a44ae1d Merge pull request #3413 from PHPOffice/Issue-3412_Date-Format-with_decimals-interpreted-as-Number-Format
Modify Date/Time check in the NumberFormatter for decimal/fractional times
2023-02-28 12:56:05 +01:00
MarkBaker c71aedeb56 Modify Date/Time check in the NumberFormatter so that masks with a decimal/fractional time aren't misinterpreted as number masks, while still ensuring that durations are interpreted as date/time masks, and locale currency masks are still treated as numbers
A date/time with a decimal time shouldn't have a digit placeholder __before__ the decimal point, only after
2023-02-28 12:34:00 +01:00
MarkBaker d01577dfeb Update Change log 2023-02-27 17:28:35 +01:00
Mark Baker e87e0b44b9 Merge pull request #3407 from PHPOffice/Fix-docs-typo
Documentation updates
2023-02-27 17:28:00 +01:00
MarkBaker e24b9a542d Documentation updates 2023-02-27 17:07:45 +01:00
Mark Baker e1c66a5d31 Merge pull request #3402 from PHPOffice/Issue-3368_Absolute-Cell-References-on-Insert-Delete
Absolute References in Cell Formulae should always be updated when inserting/deleting rows/columns
2023-02-27 16:44:02 +01:00
MarkBaker 2daef6d2f2 Issue 3368 - Absolute References in Defined Names should always be updated when inserting/deleting rows/columns
Note: If we delete the entire range that is referenced by a Named Formula, MS Excel sets the value to #REF! PhpSpreadsheet still only does a basic adjustment, so the Named Formula will still reference Cells.
2023-02-27 15:40:56 +01:00
MarkBaker 09fc1eb9e7 Issue 3368 - Absolute References in Cell Formulae should always be updated when inserting/deleting rows/columns 2023-02-26 01:21:37 +01:00
MarkBaker 03275330e6 Prepare Change Log for next release 2023-02-25 13:31:04 +01:00
MarkBaker 6e81cf39bb Update Change Log for release 1.28.0 2023-02-25 13:24:49 +01:00
Mark Baker 69e942a9b7 Merge pull request #3401 from PHPOffice/NumberFormatter-Improved-Fractions
Allow use of # and 0 digit placeholders in fraction masks
2023-02-25 13:11:20 +01:00
MarkBaker 0ebbb3297d Allow use of # and 0 digit placeholders in fraction masks 2023-02-25 12:48:53 +01:00
oleibman 324e19035f Xls Reader Conditional Styles (#3400)
The code currently allocates the style object as a non-conditional style, leading to corruption when the spreadsheet is written out.

That being said, Font Color is the only Conditional Formatting I have gotten to work for Xls for read or write. Use of other styles will essentially continue to be ignored, but will at least no longer result in corrupt spreadsheets.
2023-02-24 18:11:38 -08:00
Mark Baker 006e5ddf9a Merge pull request #3399 from PHPOffice/Issue-3395_AutoFit-AutoFilter-Header-Centre-Aligned
Allow for Table AutoFilter Header Center Alignment for AutoFit column sizing
2023-02-24 21:44:58 +01:00
MarkBaker 6409af4dcc When a Worksheet has an AutoFilter, make allowance for Center Alignment in the filter heading when calculating AutoFit column widths. 2023-02-24 21:24:46 +01:00
oleibman 4e2bca19ff Update Change Log (#3398)
Add some recent changes.
2023-02-24 07:48:47 -08:00
oleibman ab420f4499 Coerce Bool to Int for Mathematical Operators on Arrays (#3392)
* Coerce Bool to Int for Unary Operation on Arrays

Fix #3389. It seems some functionality was left behind when JAMA was eliminated (PR #3260). In particular, it is apparently a known trick to use double negation on boolean values as arguments to functions like SUMPRODUCT.

* Fix 3396

Treat booleans in arrays as int for mathematical operators as well.

* Edge Case

When array operand was neither numeric nor boolean, PhpSpreadsheet had always been evaluating the operand as #NUM!. It will now propagate an error string like #DIV/0!, and treat non-error strings as #VALUE!, consistent with Excel.
2023-02-23 23:11:22 -08:00
oleibman 6925b7f621 Conditional Formatting Improvements for Xlsx (#3372)
* WIP Conditional Formatting Improvements for Xlsx

Fix #3370. Conditional styles are always generated with 5 borders (right, left, top, bottom, diagonal) even though the border style is none in each case. For the spreadsheet in question, top and bottom were inappropriate and interfered with the desired formatting. A new border style, BORDER_OMIT is added which will cause the Xlsx Writer to not generate that style. All conditional borders will be initialized with that value. Any border included in the Xml will, of course, change it to the specified type.

Fix #3202. User wants a condition to use "No format set" as you can in Excel. A new boolean property `$noFormatSet`, along with setter and getter, is added to Style/Conditional. It is initialized to false. User can call setter to change it. More importantly for the issue in question, if the Xlsx Reader encounters a `cfRule` tag which does not have a `dxfId` attribute (i.e. no style is associated with the rule), it will set noFormatSet to true. Similarly, the Xlsx writer will not generate a `dfxId` tag when noFormatSet is true.

This change is applicable only to Xlsx. Html, Csv, and Ods do not have support for Conditional Formatting. Limited support was added to Xls with PR #2696 in April 2022 and PR #2702 about a month later. However, with the current release code, Xls equivalents of the two new test spreadsheets in this PR are too complicated to be handled correctly by PhpSpreadsheet - loading and then saving them as Xls results in Excel complaining of corruption, and the results don't meet expectations. Since I have no idea how BIFF works, and since the problems with those spreadsheets are not caused by this PR, I am not planning to address those problems at this time.

* Update Documentation, Write Alignment and Font Less Often

It doesn't cause any particular harm except for small increases in file size and run time, but Alignment tags are written even when (a) all its attributes are null for Conditional Formatting, and (b) when the xml specifically indicates that Alignment should not be applied. Similarly, Font is written even when all its attributes are null for Conditional Formatting.

There are some errors in the Conditional Formatting documentation. Specifying a solid fill color in a Conditional Style requires the use of endColor, not StartColor. The discussion of Order of Evaluating is not entirely accurate. I have changed it to what I believe is an accurate explanation of how Excel works; and also added a mention that other spreadsheet programs might not work the same way, adding a couple of illustrations of the difference. The description of the multiple conditions did not quite match the diagram. 'Stop if true' was a blank paragraph; it is now described, and the new 'No format set' option is described in that paragraph since (I think) it would be used most often in conjunction with 'Stop if true'.

* Xlsx Writer Allow StartColor for Conditional Solid Fill

To set a solid fill in a non-conditional style, you set StartColor (xml will use that value as fgColor and a default value as bgColor). If you instead set EndColor (xml will use that value as bgColor and a default value as fgColor), the styling will not work as expected.

However, for conditional styles, if you set StartColor (xml will use that value as fgColor and not specify bgColor), the styling will not work as expected. If you instead set EndColor (xml will use that value as bgColor and not specify fgColor), the styling will work as expected.

Together, this means that you need to use different methods for non-conditional style fill than for conditional style fill. This isn't a big problem, but it is a bit weird. This PR changes Xlsx Writer so that if (a) fill is olid and (b) startColor is specified and (c) endColor is null, the xml will be written as bgColor without specifying fgColor. This means that you can set StartColor for both conditional and non-conditional and get the expected styling. You may, of course, continue to specify EndColor instead for conditional.

* Fix Some (Not Many) Xls Problems

I will open an issue for the (pre-existing) remainder.
2023-02-23 22:28:22 -08:00
oleibman 378beac8f2 Xls Writer Parser Handle Boolean Literals as Function Arguments (#3391)
Fix #3369. The parser had failed to account for `TRUE` and `FALSE` when supplied as arguments to a function.

I had hoped to be able to do something about its inability to handle defined names as well. I failed. I think another section might need to be added to the Writer output which specifies the defined names. I haven't yet located any suitable documentation.
2023-02-23 10:54:54 -08:00
Mark Baker 014a120b4e Merge pull request #3394 from PHPOffice/NumberFormat_decimal-placing-with-question-mark
Improved handling for ? placeholder in Number Format Masks
2023-02-22 20:41:40 +01:00
MarkBaker acdcb0b0a2 Refactoring and simplification of replacement code 2023-02-22 20:14:47 +01:00
MarkBaker f468e78b66 Improved handling for ? placeholder in Number Format Masks 2023-02-22 12:55:21 +01:00
Mark Baker 4cefd7a889 Merge pull request #3388 from PHPOffice/NumberFormat_Scaling-Unit-Tests
Additional unit tests for scaling values in Number Format Masks
2023-02-21 13:40:07 +01:00
MarkBaker e812b49bb6 Additional unit tests for scaling values in Number Format Masks 2023-02-21 13:20:23 +01:00